Compiling Interaction Nets · Outlines Compiling Interaction Nets Abubakar.Hassan at kcl.ac.uk...
Transcript of Compiling Interaction Nets · Outlines Compiling Interaction Nets Abubakar.Hassan at kcl.ac.uk...
Outlines
Compiling Interaction Nets
Abubakar.Hassan at kcl.ac.uk
Department of Computer ScienceKings College London
April 4, 2006
Abubakar.Hassan at kcl.ac.uk Compiling Interaction Nets
Outlines Interaction Nets Programming Language
Outline
1 Interaction Nets Programming LanguageBackgroundLanguage SyntaxForeign Language InterfaceModule System
2 Compilation of Interaction netsAbstract MachineCompilation schemes
3 Conclusions and Future work
Abubakar.Hassan at kcl.ac.uk Compiling Interaction Nets
Programming Language
Part I
Interaction Nets Programming Language
Abubakar.Hassan at kcl.ac.uk Compiling Interaction Nets
Programming Language
BackgroundLanguage SyntaxForeign Language InterfaceModule System
Interaction nets system
Define a set Σ of Agents
����α
?
@ �· · ·x1 xn
y = α(x1, . . . , xn)
and a set R of Rules
����α ����
β-�@
�
�
@
......
x1
xn
ym
y1
=⇒ N...
...x1
xn
ym
y1
Abubakar.Hassan at kcl.ac.uk Compiling Interaction Nets
Programming Language
BackgroundLanguage SyntaxForeign Language InterfaceModule System
Example
Σ = {Z, S , +}:
����Z6
����S6
����+
@@��
x = Z() y = S(a) w = +(d , e)
R =
����Z
����+
����S
����+
����+
����S6
�� @
� @
��
�
� @@
=⇒ =⇒
Abubakar.Hassan at kcl.ac.uk Compiling Interaction Nets
Programming Language
BackgroundLanguage SyntaxForeign Language InterfaceModule System
a = Add(x , y), a = Z =⇒ x = ya = Add(x , y), a = S(z) =⇒ x = S(b), z = Add(b, y)
Replace equals for equals:
Z = Add(x , x) =⇒S(Add(b, y)) = Add(S(b), y) =⇒
we replace the ‘=’ by ‘><’ and remove =⇒ if empty.
Z >< Add(x , x)S(Add(b, y)) >< Add(S(b), y)
Abubakar.Hassan at kcl.ac.uk Compiling Interaction Nets
Programming Language
BackgroundLanguage SyntaxForeign Language InterfaceModule System
Net with active pair and Reduction
����S
����Z6
����Z6
����+
@@��
� ����S
I −→ ����Z
����Z6
����+
����S6
@@��
� ����S
I −→
����Z6
����S6
����S6
After replacing equals for equals:
S(Z) = Add(z ,S(Z)) −→ Z = Add(S ,S(Z))−→ S(S(Z))
Abubakar.Hassan at kcl.ac.uk Compiling Interaction Nets
Programming Language
BackgroundLanguage SyntaxForeign Language InterfaceModule System
Language Syntax
We can see interaction nets as a configurationc = (Σ, 〈~t | u1 = v1, . . . un = vn〉,R)
P ::= (agent | rule)∗ netagent ::= agentName : arityrule ::= [ruleName: ] term >< term ( => net | )net ::= [netName: ] equation (, equation)∗ |equation ::= term = termterm ::= agentName(term, ..., term) | var
Abubakar.Hassan at kcl.ac.uk Compiling Interaction Nets
Programming Language
BackgroundLanguage SyntaxForeign Language InterfaceModule System
Example
Z:0 S:1Add:2AddZ: Z >< Add(x,x)AddS: S(Add(b,y)) >< Add(S(b),y)S(Z) = Add(b,S(Z))
Abubakar.Hassan at kcl.ac.uk Compiling Interaction Nets
Programming Language
BackgroundLanguage SyntaxForeign Language InterfaceModule System
Foreign Language Interface
P ::= (agent | rule)∗ netagent ::= agentName : arityrule ::= [ruleName: ] term >< term ( => net | )net ::= [netName: ] equation (, equation)∗ |equation ::= term = termterm ::= agentName{`}(term, ..., term)
Abubakar.Hassan at kcl.ac.uk Compiling Interaction Nets
Programming Language
BackgroundLanguage SyntaxForeign Language InterfaceModule System
Example
fact:1 num:0 ans:0num{int n} >< fact(ans{Factorial.fact(n)})fact(x) = num{8}
Abubakar.Hassan at kcl.ac.uk Compiling Interaction Nets
Programming Language
BackgroundLanguage SyntaxForeign Language InterfaceModule System
Module System
P ::= module { [import modName[. compName]](agent | rule)∗ net }
agent ::= [*]agentName : arityrule ::= [[*]ruleName: ] term >< term ( => net | )net ::= [[*]netName: ] equation (, equation)∗ |equation ::= term = termterm ::= [*]agentName{`}(term, ..., term)
Abubakar.Hassan at kcl.ac.uk Compiling Interaction Nets
Programming Language
BackgroundLanguage SyntaxForeign Language InterfaceModule System
Example
module add {import arith.Zimport arith.S*Add:2*AddZ: Z >< Add(x,x)*AddS: S(Add(b,y)) >< Add(S(b),y)S(Z) = Add(b,S(Z)) }
Abubakar.Hassan at kcl.ac.uk Compiling Interaction Nets
Compiler
Part II
Compilation of Interaction nets
Abubakar.Hassan at kcl.ac.uk Compiling Interaction Nets
CompilerAbstract Machineschemes
Compilation
Compiling a program p.net gives a linkable p.l and a p.sym. Welink p.l to get a loadable p.o which is ready for execution by theabstract machine.Stack based machine that executes the bcodes.
bcodes ::= S | A | MS ::= loadc | store | load | popA ::= mkAgent | mkVar | mkNet | mkRuleM ::= getVar | connectPorts | eval
A state of the machine is a configuration:
〈PC , ρ, S ,A,R〉
Abubakar.Hassan at kcl.ac.uk Compiling Interaction Nets
CompilerAbstract Machineschemes
Compilation schemes
A program may consist of a list of modules M1, ...Mn. Thecompilation scheme Cp compiles each module using the schemeCm. This in turn compiles each of the component
c = (Σ, 〈~t | u1 = v1, . . . un = vn〉,R)
in the module by using the appropriate scheme:
Cp = CmJM1K, ..., CmJMnK
Abubakar.Hassan at kcl.ac.uk Compiling Interaction Nets
CompilerAbstract Machineschemes
The compilation of a module generates the following code:
CmJ(Σ, 〈~t | u1 = v1, . . . un = vn〉,R)K =
ruleName :CRJr1K...ruleName :CRJrnKnetName :CNJu1 = v1K...netName :CNJun = vnKinterface :CT JtK
Abubakar.Hassan at kcl.ac.uk Compiling Interaction Nets
CompilerAbstract Machineschemes
Example
The code generated by compiling:module Erase{Eps:0EpsEpsRule: Eps >< EpsEpsNet: Eps = Eps}is:EpsEpsRule:loadc epsloadc 1mkAgentstore 0load 0store 1loadc epsloadc 1mkAgentstore 0load 0store 0
loadc 2load 0load 1mkRulepopEpsNet:loadc epsloadc 1mkAgentstore 0load 0store 1loadc eps
loadc 1mkAgentstore 0load 0store 0load 0load 1mkNetevalpop
Abubakar.Hassan at kcl.ac.uk Compiling Interaction Nets
CompilerAbstract Machineschemes
Execution starts from the initial configuration:
P ` 〈0, [], [], [], []〉
The machine starts executing the instructions under the labelEpsEpsRule. After interpreting all the code in this label, weobtain the configuration:
p ` 〈16, [], [], [], [Eps,Eps]〉
The configuration obtained after executing the code in the labelEpsNet, before the instruction eval:
p ` 〈32, [], [], [Eps,Eps], [Eps,Eps]〉
The final configuration obtained after the eval instruction:
p ` 〈33, [], [0 7→ ε], [], [Eps,Eps]〉
Abubakar.Hassan at kcl.ac.uk Compiling Interaction Nets
Conclusions and Future work
Future work
We have seen for the first time a compilation scheme forInteraction nets.
extend the core language
study alternative compilation schemes
compilation for parallel hardware
optimisations
type system
Abubakar.Hassan at kcl.ac.uk Compiling Interaction Nets
Conclusions and Future work
Abubakar.Hassan at kcl.ac.uk Compiling Interaction Nets
Conclusions and Future work
Abubakar.Hassan at kcl.ac.uk Compiling Interaction Nets
Conclusions and Future work
Abubakar.Hassan at kcl.ac.uk Compiling Interaction Nets
Conclusions and Future work
Compilation Schemes
Cv JvK =
loadc vmkVarstore−i
CtJα(t1 · · · tn)K
CaJαKstore−iCaJt1Kstore−i + 1load iloadc 1load i + 1
Abubakar.Hassan at kcl.ac.uk Compiling Interaction Nets
Conclusions and Future work
CnJα(u1, ..., un) = β(v1, ..., vn)K =
CtJα(u1 · · · un)KCtJβ(v1 · · · vn)KmkNetevalpop
Cr Jα(t1, ..., tn) >< β(u1, ..., un)K =
CtJα(t1 · · · tn)KCtJβ(u1 · · · un)KmkRulepop
Abubakar.Hassan at kcl.ac.uk Compiling Interaction Nets
Conclusions and Future work
CaJαK =
loadc αloadc armkAgentstore−iloadc 0connectPortsstore−i...CaJtnK
store−i + 1load iloadc nload i + 1loadc 0connectPortsstore−i
Abubakar.Hassan at kcl.ac.uk Compiling Interaction Nets