帕拉索(编程语言)

伞兵
旁尾编程语言徽标
范例 编译并发命令结构化面向对象
设计 S. Tucker Taft
开发人员 Adacore
首先出现 2009
稳定版本
9.3 / 6 2021年6月
打字学科 静态
平台 x86
作业系统 LinuxMacOSWindows
执照 GPL V3
文件名扩展 .psi,.psl
网站 Parasail-lang .org
主要实施
PSLI,PSLC
被影响
模块ADAPASCALML
受影响
尼姆

并行规范和实现语言Parasail )是面向对象的并行编程语言。它的设计和正在进行的实施在博客和官方网站上进行了描述。

Parasail使用无指针的编程模型,对象可以在其中生长和缩小,并将价值语义用于分配。它没有全球垃圾收集的堆。相反,始终使用基于区域的内存管理。只要递归组件被宣布为可选,类型就可以是递归的。没有全局变量,没有参数混溶,并且可以并行评估表达式的所有子表达。主张前提条件后条件班级不变等是标准语法的一部分,使用hoare -like符号。在编译时检测到任何可能的比赛条件

Parasail的最初设计始于2009年9月,S。TuckerTaft。

使用Parasail Virtual Machine的解释器和基于LLVM的帕拉索编译器都可以使用。窃取工作用于安排Parasail的轻重量线程。最新版本可以从Parasail网站下载。

描述

帕拉赛语的语法类似于模量,但基于基于班级的对象的编程模型与JavaC#更相似。

最近,Parasail的平行结构已适用于其他语法,以产生Java ,类似于Java,类似PythonAda类似于ADA的平行语言,分别称为,称为Javallel,Parython和Sparkel(以Ada subset Spark上的ADA子集命名它是基于的)。这些语言的编译器和口译商包含在Parasail实施中。

例子

以下是Parasail的Hello World计划

func Hello_World(var IO) is
    IO.Println("Hello, World");
end func Hello_World;

以下是基本地图模块的接口:

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;

这是使用二进制树的该地图模块的可能实现:

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;

这是BMAP模块的简单测试程序:

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;