This article has multiple issues. Please helpimprove it or discuss these issues on thetalk page.(Learn how and when to remove these messages) (Learn how and when to remove this message)
|
| ParaSail | |
|---|---|
![]() Logo for ParaSail Programming Language | |
| Paradigm | compiled,concurrent,imperative,structured,object-oriented |
| Designed by | S. Tucker Taft |
| Developer | AdaCore |
| First appeared | 2009; 16 years ago (2009) |
| Stable release | 9.3 / 6 June 2021; 4 years ago (2021-06-06) |
| Typing discipline | strong,static |
| Platform | x86 |
| OS | Linux,macOS,Windows |
| License | GPL v3 |
| Filename extensions | .psi, .psl |
| Website | parasail-lang |
| Majorimplementations | |
| psli, pslc | |
| Influenced by | |
| Modula,Ada,Pascal,ML | |
| Influenced | |
| Nim[1] | |
Parallel Specification and Implementation Language (ParaSail) is anobject-orientedparallel programming language. Its design and ongoing implementation is described in a blog[2] and on its official website.[3]
ParaSail uses apointer-free programming model, whereobjects can grow and shrink, and value semantics are used for assignment. It has no globalgarbage collected heap. Instead,region-based memory management is used throughout. Types can be recursive, so long as the recursive components are declaredoptional. There are no global variables, no parameter aliasing, and all subexpressions of an expression can be evaluated in parallel.Assertions,preconditions,postconditions,class invariants, etc., are part of the standardsyntax, using aHoare-like notation. Any possiblerace conditions are detected atcompile time.
Initial design of ParaSail began in September 2009, by S. Tucker Taft.
Both aninterpreter using the ParaSailvirtual machine, and anLLVM-based ParaSailcompiler are available.Work stealing is used for scheduling ParaSail's light-weightthreads. The latest version can be downloaded from the ParaSail website.[3]
This sectionneeds expansion. You can help byadding to it.(February 2018) |
Thesyntax of ParaSail is similar toModula, but with a class-and-interface-based object-oriented programming model more similar toJava orC#.
More recently, the parallel constructs of ParaSail have been adapted to other syntaxes, to produceJava-like,Python-like, andAda-likeparallel languages, dubbed, respectively, Javallel, Parython, and Sparkel (named after the Ada subsetSPARK on which it is based). Compilers and interpreters for these languages are included with the ParaSail implementation.[3]
The following is aHello world program in ParaSail:
funcHello_World(varIO)isIO.Println("Hello, World");endfuncHello_World;
The following is an interface to a basic map module:
interfaceBMap<Key_TypeisOrdered<>;Element_TypeisAssignable<>>isop"[]"()->BMap;// Create an empty mapfuncInsert(varBMap;Key:Key_Type;Value:Element_Type);funcFind(BMap;Key:Key_Type)->optionalElement_Type;funcDelete(varBMap;Key:Key_Type);funcCount(BMap)->Univ_Integer;endinterfaceBMap;
Here is a possible implementation of this map module,using a binary tree:
classBMapisinterfaceBinary_Node<>is// A simple "concrete" binary node modulevarLeft:optionalBinary_Node;varRight:optionalBinary_Node;constKey:Key_Type;varValue:optionalElement_Type;// null means deletedendinterfaceBinary_Node;varTree:optionalBinary_Node;varCount:=0;exportsop"[]"()->BMapis// Create an empty mapreturn(Tree=>null,Count=>0);endop"[]";funcInsert(varBMap;Key:Key_Type;Value:Element_Type)is// Search for Key, overwrite if found, insert new node if notforM=>BMap.TreeloopifMis nullthen// Not already in the map; add itM:=(Key=>Key,Value=>Value,Left=>null,Right=>null);BMap.Count+=1;elsecaseKey=?M.Keyof[#less]=>continueloopwithM.Left;[#greater]=>continueloopwithM.Right;[#equal]=>// Key is already in the map;// bump count if Value was null;ifM.Valueis nullthenBMap.Count+=1;endif;// in any case overwrite the Value fieldM.Value:=Value;return;endcase;endif;endloop;endfuncInsert;funcFind(BMap;Key:Key_Type)->optionalElement_Typeis// Search for Key, return associated Value if present, or null otherwiseforM=>BMap.TreewhileMnot nullloopcaseKey=?M.Keyof[#less]=>continueloopwithM.Left;[#greater]=>continueloopwithM.Right;[#equal]=>// Found it; return the valuereturnM.Value;endcase;endloop;// Not found in BMapreturnnull;endfuncFind;funcDelete(varBMap;Key:Key_Type)is// Search for Key; delete associated node if foundforM=>BMap.TreewhileMnot nullloopcaseKey=?M.Keyof[#less]=>continueloopwithM.Left;[#greater]=>continueloopwithM.Right;[#equal]=>// Found it; if at most one subtree is non-null, overwrite// it; otherwise, set its value field to null// (to avoid a more complex re-balancing).ifM.Leftis nullthen// Move right subtree into MM<==M.Right;elsifM.Rightis nullthen// Move left subtree into MM<==M.Left;else// Cannot immediately reclaim node;// set value field to null instead.M.Value:=null;endif;// Decrement countBMap.Count-=1;endcase;endloop;// Not found in the mapendfuncDelete;funcCount(BMap)->Univ_Integeris// Return count of number of items in mapreturnBMap.Count;endfuncCount;endclassBMap;
Here is a simple test program for the BMap module:
importPSL::Core::Random;importBMap;funcTest_BMap(Num:Univ_Integer;Seed:Univ_Integer)is// Test the Binary-Tree-based MapvarRan:Random:=Start(Seed);// Start a random-number sequence// Declare a map from integers to stringsvarM:BMap<Key_Type=>Univ_Integer,Element_Type=>Univ_String>;M:=[];// Initialize the map to the empty mapforIin1..Num*2forwardloop// Add elements to the mapconstKey:=Next(Ran)modNum+1;constVal:="Val"|To_String(I);Println("About to insert "|Key|" => "|Val);Insert(M,Key,Val);endloop;Println("Count = "|Count(M));forIin1..Numloop// Search for elements in the mapconstKey:=Next(Ran)modNum+1;Println("Looking for "|Key|", found "|Find(M,Key));endloop;forIin1..Num/3loop// Delete some elements from the mapconstKey:=Next(Ran)modNum+1;Println("About to delete "|Key);Delete(M,Key);endloop;Println("Count = "|Count(M));forIin1..Numforwardloop// Search again for elements in the mapPrintln("Looking for "|I|", found "|Find(M,I));endloop;endfuncTest_BMap;