Skip to content

Instantly share code, notes, and snippets.

@prepor
Created February 6, 2018 14:13
Show Gist options
  • Save prepor/318870531e3b54af50aecdac1a64666f to your computer and use it in GitHub Desktop.
Save prepor/318870531e3b54af50aecdac1a64666f to your computer and use it in GitHub Desktop.
module OAM-SYNTAX
syntax Ints ::= List{Int,","}
syntax Op ::= "#parallel" Int Int
| "#otherwise" Int Int
| "#pruning" Int Int Int
| "#sequential" Int Int Int
| "#callFun" Int "[" Ints "]"
| "#callDynamic" Int "[" Ints "]"
| "#ffi" Int
| "#coeffect" Int
| "#stop"
| "#constInt" Int
| "#closure" Int Int
| "#label" Int
syntax Val ::= Int
syntax SourceOp ::= Int ":" Op
syntax SourceOps ::= List{SourceOp, " "}
syntax SourceFun ::= Int Int "{" SourceOps "}"
syntax SourceFuns ::= List{SourceFun, " "}
endmodule
module OAM
imports OAM-SYNTAX
syntax Env ::= env(Map)
syntax Stack ::= stack(List)
syntax PendValue ::= pendVal(Val)
| "pendStopped"
| "pend"
syntax Pending ::= pending(PendValue, List)
syntax Frame ::= fPruning(Int, Pending)
| fOtherwise(Bool, Int, Int, Int)
| fSequential(Int, Int, Int)
syntax Val ::= closure(Int, Int, Env)
syntax OrcToken ::= OrcToken(Int, Int, Env, Stack)
syntax KResult ::= Val
configuration <T>
<threads>
<thread multiplicity="*">
<currentFun>0</currentFun>
<pc>-1</pc>
<k>.:Op</k>
<result>.:Val</result>
<stack>.List</stack>
</thread>
</threads>
<queue>.List</queue>
<values>.List</values>
<instance>
<currentCoeffect>0</currentCoeffect>
<blocks>.List</blocks>
</instance>
<ops>
<op multiplicity="*">
<opFunId>0</opFunId>
<opId>0</opId>
<body>#stop</body>
</op>
</ops>
<initOps>.Map</initOps>
<source>$PGM:SourceFuns</source>
</T>
rule <source>Id _ { (OpId : Body) XS => XS } _</source>
<ops>
... (.Bag =>
<op>
<opFunId>Id</opFunId>
<opId>OpId</opId>
<body>Body</body>
</op>)
...</ops>
rule <source> (Id (InitId => -1) { _ }) _</source>
<initOps>... .Map => Id |-> InitId ...</initOps>
requires InitId =/=Int -1
rule <source>_ -1 { .SourceOps } XS => XS</source>
// Main thread
rule <threads>
.Bag => <thread>
<currentFun>0</currentFun>
<pc>-1</pc>
<k>.:Op</k>
<result>.:Val</result>
<stack>.List</stack>
</thread>
</threads>
// Init op
rule <thread>...
<currentFun>FunId:Int</currentFun>
<pc>-1 => OpId</pc>
...</thread>
<initOps>... FunId |-> OpId ...</initOps>
// Place actual op
rule <thread>...
<pc>OpId</pc>
<currentFun>FunId</currentFun>
<k>. => Body</k>
...</thread>
<op>...
<opFunId>FunId</opFunId>
<opId>OpId</opId>
<body>Body</body>
...</op>
endmodule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment