@@ -5,30 +5,32 @@ const path = require("path");
55
66const template = fs . readFileSync ( path . join ( __dirname , "template.txt" ) , "utf8" ) ;
77
8- let mkwire , mktwins , getfv ;
8+ let mkwire , mktwins , getfv , subst ;
99
10- function psi ( shared , list )
10+ function box ( fv , list , lvl )
11+ {
12+ for ( const atom in fv ) {
13+ const ref = fv [ atom ] . ref ;
14+ const agent = `\\bra_{${ lvl } }(${ ref } )` ;
15+
16+ list . push ( `${ atom } = ${ agent } ` ) ;
17+ }
18+ }
19+
20+ function psi ( shared , list , lvl )
1121{
1222 for ( const atom in shared ) {
1323 const twins = shared [ atom ] ;
1424 const wleft = twins . left ;
1525 const wright = twins . right ;
16- const agent = `\\fan_{0 }` ;
26+ const agent = `\\fan_{${ lvl } }` ;
1727 const tree = `${ agent } (${ wright } , ${ wleft } )` ;
1828
1929 list . push ( `${ atom } = ${ tree } ` ) ;
2030 }
2131}
2232
23- function mkscope ( n , s )
24- {
25- for ( let i = 0 ; i < n ; i ++ )
26- s = `\\scope_{0}(${ s } )` ;
27-
28- return s ;
29- }
30-
31- function gamma ( obj , root , list )
33+ function gamma ( obj , root , list , lvl )
3234{
3335 const node = obj . node ;
3436
@@ -39,7 +41,7 @@ function gamma(obj, root, list)
3941
4042 list . push ( `${ root } = ${ agent } ` ) ;
4143 } else {
42- const agent = mkscope ( obj . index , root ) ;
44+ const agent = `\\cro_{ ${ lvl } }( ${ root } )` ;
4345
4446 list . push ( `${ obj . name } = ${ agent } ` ) ;
4547 }
@@ -49,25 +51,38 @@ function gamma(obj, root, list)
4951 const fv = getfv ( body ) ;
5052 const wire = mkwire ( ) ;
5153 const agent = ( id in fv ) ? id : "\\erase" ;
52- const tree = `\\lambda (${ agent } , ${ wire } )` ;
54+ const tree = `\\lam_{ ${ lvl } } (${ agent } , ${ wire } )` ;
5355
5456 list . push ( `${ root } = ${ tree } ` ) ;
5557
56- gamma ( body , wire , list ) ;
58+ gamma ( body , wire , list , lvl ) ;
5759 } else if ( "appl" == node ) {
5860 const wleft = mkwire ( ) ;
5961 const wright = mkwire ( ) ;
6062 const left = obj . left ;
6163 const right = obj . right ;
6264 const shared = mktwins ( left , right ) ;
63- const agent = `\\apply(${ wright } , ${ root } )` ;
65+ const agent = `\\app_{${ lvl } }` ;
66+ const tree = `${ agent } (${ wright } , ${ root } )` ;
67+ const fv = getfv ( right ) ;
68+
69+ for ( const atom in fv ) {
70+ const wref = mkwire ( ) ;
71+
72+ fv [ atom ] = {
73+ ref : wref
74+ } ;
75+ }
76+
77+ subst ( right , fv , "ref" ) ;
6478
65- list . push ( `${ wleft } = ${ agent } ` ) ;
79+ list . push ( `${ wleft } = ${ tree } ` ) ;
6680
67- gamma ( left , wleft , list ) ;
68- gamma ( right , wright , list ) ;
81+ gamma ( left , wleft , list , lvl ) ;
82+ gamma ( right , wright , list , lvl + 1 ) ;
6983
70- psi ( shared , list ) ;
84+ box ( fv , list , lvl ) ;
85+ psi ( shared , list , lvl ) ;
7186 }
7287}
7388
@@ -80,8 +95,9 @@ function encode(generic, term)
8095 mkwire = generic . mkwire ;
8196 mktwins = generic . mktwins ;
8297 getfv = generic . getfv ;
98+ subst = generic . subst ;
8399
84- gamma ( term , "root" , inconfig ) ;
100+ gamma ( term , "root" , inconfig , 0 ) ;
85101
86102 inconfig . inet = template ;
87103 return inconfig ;
0 commit comments