ParaFlow - PowerPoint PPT Presentation

About This Presentation
Title:

ParaFlow

Description:

string background = 'images/gears.jpg'; print(quote to ENDOFHTML HTML ... String, file, html fetch libraries. Reference counting/auto freeing of objects ... – PowerPoint PPT presentation

Number of Views:33
Avg rating:3.0/5.0
Slides: 18
Provided by: jimk88
Category:
Tags: paraflow

less

Transcript and Presenter's Notes

Title: ParaFlow


1
ParaFlow
  • A practical, easy to use, parallel processing
    language.

2
Parallel programming constructs
  • Para executes in parallel on all items in a
    collection.
  • Flow marks a function as having no side effects.

3
Simplicity
  • No objects or even functions are required. Hello
    world program is just
  • print(Hello world.)
  • Built in string type is easy and powerful.
  • Memory for strings and objects is automatically
    freed. Files are automatically closed.
  • Syntax is simple and readable. Generally very
    like C or Java.
  • No threads to synchronize.

4
Example Flow Function
  • flow polar(double angle,rad) into (double x,y)
  • x rad math.cos(angle)
  • y rad math.sin(angle)
  • (double a,r) polar(4.0, 5.0)
  • // The compiler would report an error if
  • // the polar function modified any
  • // global variables since it is declared as
  • // flow. Functions with side effects must be
  • // declared with the to keyword instead.

5
Para expression constructs
  • // Make an array to work on.
  • array of int a (1,2,3,4,5,6)
  • // Get array of all elements squared
  • array of int aSquared para (x in a) get xx
  • // Get maximum value in array
  • int maxA para (x in a) max x
  • // Get array just containing odd numbers
  • array of int odd para (x in a) filter x1

6
The parado construct
  • // Declare a 2-D point class
  • class point double x,y
  • // function to scale an array of points
  • to blowUp(array of point points, double
    scaleFactor)
  • // With the para do construct can alter
  • // all elements in a collection in parallel.
  • para (p in points) do
  • p.x scaleFactor
  • p.y scaleFactor

7
The case statement
  • // The case is different from Cs switch
  • case (name)
  • Mark,Angie occupation programmer
  • Heidi occupation writer
  • Rover
  • occupation dog
  • print(Woof)
  • else occupation unknown
  • // Motivation for difference is to avoid problems
  • // with missing breaks, and allow use of
    non-integer
  • // expressions.

8
Object Oriented Features
  • Classes with single inheritance.
  • Interfaces similar to Java. Automatic
    serialization of objects
  • No overloading (but default parameters allowed).
  • Methods must be declared polymorphic to be
    overridden.

9
A Simple Class and Serialization
  • class family
  • string name
  • array of string members
  • family kents (Kent, (Mira, Tisa, Jim,
    Heidi))
  • print(kents)
  • gt (Kent, (Mira, Tisa, Jim, Heidi))
  • print(kents.members.size)
  • gt 4

10
Other Advanced Features
  • Flexible quotes makes embedding HTML and other
    intricate text in program easy.
  • Does variable substitution in strings.
  • Bounds checking on array accesses, and checking
    for use of uninitialized objects. Errors generate
    stack trace and position of error in source.
  • For statement operates over collections (and
    makes bounds checks unneeded). Traditional for
    () also supported.
  • No need to predeclare functions or for separate
    header files.
  • Built in dir (aka hash,directory) collection. No
    need to cast objects out of collections.

11
Printing HTML fragment
  • string title My ParaFlow CGI Program
    programName
  • string background images/gears.jpg
  • print(quote to ENDOFHTML
  • ltHTMLgt
  • ltHEADgtltTITLEgttitlelt/TITLEgtlt/HEADgt
  • ltBODYgt BACKGROUNDbackgroundgt
  • ltPgtHello HTML CGI World from ParaFlowlt/Pgt
  • lt/BODYgt
  • lt/HTMLgt
  • ENDOFHTML)

12
Example Dir and For
  • dir of int numNames
  • (one _at_ 1, two _at_ 2, three _at_ 3)
  • print(numNamesone)
  • 1
  • for (i in numNames)
  • print( i ii)
  • 1 1
  • 2 4
  • 3 9
  • for (key_at_val in numNames)
  • print(key -gt val)
  • one -gt 1
  • two -gt 2
  • three-gt 3

13
Run Time Errors
  • to goTooFar(array of int a, int value)
  • // Set all elements of a to a value with a bug
  • for (int i0 ilt a.size i)
  • ai value
  • to initArrays(array of int a, int aVal, string
    why)
  • // Initialize two arrays to values
  • print(Initializing a and b because why)
  • goTooFar(a,aVal)
  • array10 of int a
  • initArrays(a,123,just because)
  • Initializing a because just because
  • -------- start stack dump --------
  • goTooFar(altarray of 10gt, value123)
  • initArrays(altarray of 10gt, aVal123, whyjust
    because)
  • Run time error line 5 col 4 of pastEnd.pf array
    access out of bounds

14
More complex classes
  • class animal
  • string name
  • to printName() print(self.name)
  • polymorphic to speak() print(???)
  • class dog extends animal
  • polymorphic to speak() print(bark)
  • class toyPoodle extends dog
  • polymorphic to speak() print(yip)
  • dog fido (Fido), toyPoodle fifi (Fifi)
  • array of animals (fido, fifi)
  • foreach (a in animals)
  • a.speak()
  • gtbark

15
Whats Implemented
  • Classes with inheritance polymorphism
  • Print and file I/O that handles objects of
    different types without being told how.
  • For, while, if, case, functions with multiple
    returns
  • Modules, exceptions, interfaces
  • String, file, html fetch libraries.
  • Reference counting/auto freeing of objects
  • Serial implementations of para constructs.

16
Still to come
  • Making parallel constructs actually work in
    parallel.
  • Generating Pentium rather than C code.
  • Current code is about 1/4 speed of equivalent C
  • Generating Open Source buzz on language
  • Open Source Conf Portland in July is launch

17
Implementation
  • Whole module done in memory in many passes
  • Tokenizer
  • Scan tokens for class names
  • Parser
  • Resolving variable names
  • Type checker
  • C code generator
  • Calls gcc on C code.
Write a Comment
User Comments (0)
About PowerShow.com