@@ -7,23 +7,24 @@ const template = fs.readFileSync(path.join(__dirname, "template.txt"), "utf8");
77
88let mkwire , bv ;
99
10- function rho ( id , list )
10+ function rho ( id , list , lvl )
1111{
1212 bv [ id ] . forEach ( entry => {
1313 const wire = entry . wire ;
14- const lvl = entry . index ;
14+ const delta = entry . lvl - lvl - 1 ;
1515 const next = mkwire ( ) ;
16- const agent = `\\fan_{${ lvl } }(${ next } , ${ wire } )` ;
16+ const agent = `\\fan_{[${ lvl } , ${ delta } ]}` ;
17+ const tree = `${ agent } (${ next } , ${ wire } )` ;
1718
18- list . push ( `${ id } = ${ agent } ` ) ;
19+ list . push ( `${ id } = ${ tree } ` ) ;
1920
2021 id = next ;
2122 } ) ;
2223
2324 list . push ( `${ id } = \\nil` ) ;
2425}
2526
26- function gamma ( obj , root , list )
27+ function gamma ( obj , root , list , lvl )
2728{
2829 const node = obj . node ;
2930
@@ -38,40 +39,42 @@ function gamma(obj, root, list)
3839 const id = obj . name ;
3940
4041 bv [ id ] . push ( {
41- index : obj . index ,
42+ lvl : lvl ,
4243 wire : root
4344 } ) ;
4445 }
4546 } else if ( "abst" == node ) {
4647 const id = obj . var ;
4748 const body = obj . body ;
4849 const wire = mkwire ( ) ;
49- let tree = "\\lam (%s, %s)" ;
50+ let tree = "\\lam_{%s} (%s, %s)" ;
5051
52+ tree = tree . replace ( "%s" , lvl ) ;
5153 tree = tree . replace ( "%s" , id ) ;
5254 tree = tree . replace ( "%s" , wire ) ;
5355
5456 list . push ( root + " = " + tree ) ;
5557
5658 bv [ id ] = [ ] ;
5759
58- gamma ( body , wire , list ) ;
60+ gamma ( body , wire , list , lvl ) ;
5961
60- rho ( id , list ) ;
62+ rho ( id , list , lvl ) ;
6163 } else if ( "appl" == node ) {
6264 const wleft = mkwire ( ) ;
6365 const wright = mkwire ( ) ;
6466 const left = obj . left ;
6567 const right = obj . right ;
66- let agent = "\\app (%s, %s)" ;
68+ let agent = "\\app_{%s} (%s, %s)" ;
6769
70+ agent = agent . replace ( "%s" , lvl ) ;
6871 agent = agent . replace ( "%s" , wright ) ;
6972 agent = agent . replace ( "%s" , root ) ;
7073
7174 list . push ( wleft + " = " + agent ) ;
7275
73- gamma ( left , wleft , list ) ;
74- gamma ( right , wright , list ) ;
76+ gamma ( left , wleft , list , lvl ) ;
77+ gamma ( right , wright , list , lvl + 1 ) ;
7578 }
7679}
7780
@@ -84,7 +87,7 @@ function encode(generic, term)
8487 mkwire = generic . mkwire ;
8588
8689 bv = { } ;
87- gamma ( term , "root" , inconfig ) ;
90+ gamma ( term , "root" , inconfig , 0 ) ;
8891
8992 inconfig . inet = template ;
9093 return inconfig ;
0 commit comments