ParaSail (Programmiersprache) - ParaSail (programming language)
Logo von Abouzar Abbasi entworfen
| |
Paradigma | kompiliert , gleichzeitig , imperativ , strukturiert , objektorientiert |
---|---|
Entworfen von | S. Tucker Taft |
Entwickler | AdaCore |
Erstmals erschienen | 2009 |
Stabile Version | 8.4 / 2. November 2019
|
Schreibdisziplin | stark , statisch |
Plattform | x86 |
Betriebssystem | Linux , MacOS , Windows |
Lizenz | GPL v3 |
Dateinamenerweiterungen | .psi, .psl |
Webseite | parasail-lang |
Wichtige Implementierungen | |
psli, pslc | |
Beeinflusst von | |
Modula , Ada , Pascal , ML | |
Beeinflusst | |
Nim |
Die parallele Spezifikations- und Implementierungssprache ( ParaSail ) ist eine objektorientierte parallele Programmiersprache . Das Design und die laufende Implementierung werden in einem Blog und auf der offiziellen Website beschrieben.
Parasail verwendet einen Zeiger Programmiermodell -freien, wo Objekte wachsen und schrumpfen, und Wert - Semantik für die Zuordnung verwendet. Es wurde kein globaler Müllhaufen gesammelt . Stattdessen wird durchgehend eine regionbasierte Speicherverwaltung verwendet. Typen können rekursiv sein, solange die rekursiven Komponenten als optional deklariert sind . Es gibt keine globalen Variablen, kein Parameter-Aliasing und alle Unterausdrücke eines Ausdrucks können parallel ausgewertet werden. Behauptungen , Vorbedingungen , Nachbedingungen , Klasseninvarianten usw. sind Teil der Standardsyntax unter Verwendung einer Hoare- ähnlichen Notation. Mögliche Rennbedingungen werden zur Kompilierungszeit erkannt .
Das erste Design von ParaSail begann im September 2009 von S. Tucker Taft.
Es stehen sowohl ein Interpreter mit der virtuellen ParaSail- Maschine als auch ein LLVM- basierter ParaSail- Compiler zur Verfügung. Das Stehlen von Arbeit wird zum Planen der leichten Fäden von ParaSail verwendet . Die neueste Version kann von der ParaSail-Website heruntergeladen werden.
Beschreibung
Die Syntax von ParaSail ähnelt Modula , jedoch mit einem klassen- und schnittstellenbasierten objektorientierten Programmiermodell, das Java oder C # ähnlicher ist .
In jüngerer Zeit wurden die parallelen Konstrukte von ParaSail an andere Syntaxen angepasst, um Java- ähnliche, Python- ähnliche und Ada- ähnliche parallele Sprachen zu erzeugen , die als Javallel, Parython und Sparkel (benannt nach der Ada-Teilmenge SPARK on) bezeichnet werden worauf es basiert). Compiler und Interpreter für diese Sprachen sind in der ParaSail-Implementierung enthalten.
Beispiele
Das Folgende ist ein Hello World-Programm in ParaSail:
func Hello_World(var IO) is
IO.Println("Hello, World");
end func Hello_World;
Das Folgende ist eine Schnittstelle zu einem grundlegenden Kartenmodul:
interface BMap<Key_Type is Ordered<>; Element_Type is Assignable<>> is
op "[]"() -> BMap; // Create an empty map
func Insert(var BMap; Key : Key_Type; Value : Element_Type);
func Find(BMap; Key : Key_Type) -> optional Element_Type;
func Delete(var BMap; Key : Key_Type);
func Count(BMap) -> Univ_Integer;
end interface BMap;
Hier ist eine mögliche Implementierung dieses Kartenmoduls unter Verwendung eines Binärbaums:
class BMap is
interface Binary_Node<> is
// A simple "concrete" binary node module
var Left : optional Binary_Node;
var Right : optional Binary_Node;
const Key : Key_Type;
var Value : optional Element_Type; // null means deleted
end interface Binary_Node;
var Tree : optional Binary_Node;
var Count := 0;
exports
op "[]"() -> BMap is // Create an empty map
return (Tree => null, Count => 0);
end op "[]";
func Insert(var BMap; Key : Key_Type; Value : Element_Type) is
// Search for Key, overwrite if found, insert new node if not
for M => BMap.Tree loop
if M is null then
// Not already in the map; add it
M := (Key => Key, Value => Value, Left => null, Right => null);
BMap.Count += 1;
else
case Key =? M.Key of
[#less] =>
continue loop with M.Left;
[#greater] =>
continue loop with M.Right;
[#equal] =>
// Key is already in the map;
// bump count if Value was null;
if M.Value is null then
BMap.Count += 1;
end if;
// in any case overwrite the Value field
M.Value := Value;
return;
end case;
end if;
end loop;
end func Insert;
func Find(BMap; Key : Key_Type) -> optional Element_Type is
// Search for Key, return associated Value if present, or null otherwise
for M => BMap.Tree while M not null loop
case Key =? M.Key of
[#less] =>
continue loop with M.Left;
[#greater] =>
continue loop with M.Right;
[#equal] =>
// Found it; return the value
return M.Value;
end case;
end loop;
// Not found in BMap
return null;
end func Find;
func Delete(var BMap; Key : Key_Type) is
// Search for Key; delete associated node if found
for M => BMap.Tree while M not null loop
case Key =? M.Key of
[#less] =>
continue loop with M.Left;
[#greater] =>
continue loop with M.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).
if M.Left is null then
// Move right subtree into M
M <== M.Right;
elsif M.Right is null then
// Move left subtree into M
M <== M.Left;
else
// Cannot immediately reclaim node;
// set value field to null instead.
M.Value := null;
end if;
// Decrement count
BMap.Count -= 1;
end case;
end loop;
// Not found in the map
end func Delete;
func Count(BMap) -> Univ_Integer is
// Return count of number of items in map
return BMap.Count;
end func Count;
end class BMap;
Hier ist ein einfaches Testprogramm für das BMap-Modul:
import PSL::Core::Random;
import BMap;
func Test_BMap(Num : Univ_Integer; Seed : Univ_Integer) is
// Test the Binary-Tree-based Map
var Ran : Random := Start(Seed); // Start a random-number sequence
// Declare a map from integers to strings
var M : BMap<Key_Type => Univ_Integer, Element_Type => Univ_String>;
M := []; // Initialize the map to the empty map
for I in 1..Num*2 forward loop // Add elements to the map
const Key := Next(Ran) mod Num + 1;
const Val := "Val" | To_String(I);
Println("About to insert " | Key | " => " | Val);
Insert(M, Key, Val);
end loop;
Println("Count = " | Count(M));
for I in 1..Num loop // Search for elements in the map
const Key := Next(Ran) mod Num + 1;
Println("Looking for " | Key | ", found " | Find(M, Key));
end loop;
for I in 1..Num/3 loop // Delete some elements from the map
const Key := Next(Ran) mod Num + 1;
Println("About to delete " | Key);
Delete(M, Key);
end loop;
Println("Count = " | Count(M));
for I in 1..Num forward loop // Search again for elements in the map
Println("Looking for " | I | ", found " | Find(M, I));
end loop;
end func Test_BMap;
Verweise
Allgemeine Hinweise
- Graham-Rowe, Duncan (28. Juli 2011). "Neue Sprache für die parallele Programmierung" . Technologieüberprüfung . MIT.
- Clarke, Peter (28. Juli 2011). "SofCheck bereitet ParaSail-Parallelsprache vor" . EETimes . UBM Electronics.
- Taft, S. Tucker (9. Juni 2012). "ParaSail: Weniger ist mehr mit Multicore" . EETimes . UBM Electronics.
- Selwood, Dick (18. Juli 2012). "Braucht die Welt eine neue Programmiersprache?" . EEJournal . techfocus media, inc.
Externe Links