on master help sign in
7 files changed+66−21
since splitsnapshots
unifiedsplit
TODO.md+1−3 desk/lib/lua/interpreter.hoon+51−5 desk/lib/lua/parser.hoon+2−2 desk/lib/lua/printer.hoon+5−5 desk/res/lua/baz.lua+3−2 desk/res/lua/foo.lua+2−2 desk/sur/lua.hoon+2−2
TODO.md+1−3
@@ -8,6 +8,4 @@
88- [x] ^ should be higher priority than unary ops
99- [x] Unifiy parened exprs
1010- [ ] pow
11−
12−
13− {f()} -- creates a list with all results from f().
11+- [ ] attributes
desk/lib/lua/interpreter.hoon+51−5
@@ -33,7 +33,7 @@
3333 $:
3434 tables=$~([(malt ~[[0 *table]]) 1] (objects table))
3535 global-env=table
36− local-envs=$~(~[(malt ~[['_ENV' table+[0 ~]]])] (list (map name value)))
36+ local-envs=$~(~[(malt ~[['_ENV' table+[0 ~]]])] (lest (map name value)))
3737 ==
3838++ eval-m
3939 |$ [val]
@@ -59,8 +59,10 @@
5959 |= state
6060 [st ~]
6161++ eval-blok
62+ =<
6263 |= =blok
6364 ^- (eval-m value)
65+ %- with-local
6466 =/ body body.blok
6567 |-
6668 ^- (eval-m value)
@@ -68,9 +70,36 @@
6870 ?~ ret.blok (pure nil+~)
6971 ?~ u.ret.blok (pure nil+~)
7072 ;< rets=(lest value) bind (eval-exprlist u.u.ret.blok)
71− (pure multires+rets)
73+ (pure (multires rets))
7274 ;< ~ bind (eval-stat i.body)
73− $(body t.body)
75+ ;< ret=value bind $(body t.body)
76+ (pure ret)
77+ |%
78+ ++ with-local
79+ |* act=(eval-m)
80+ ^- _act
81+ ;< ~ bind push-local
82+ ;< res=_val:$:act bind act
83+ ;< ~ bind pop-local
84+ (pure res)
85+ ++ push-local
86+ ^- (eval-m ~)
87+ |= st=state
88+ =. local-envs.st [*(map name value) local-envs.st]
89+ [st ~]
90+ ++ pop-local
91+ ^- (eval-m ~)
92+ |= st=state
93+ =. local-envs.st
94+ ?~ t.local-envs.st !!
95+ t.local-envs.st
96+ [st ~]
97+ --
98+++ multires
99+ |= vals=(lest value)
100+ ^- value
101+ ?~ t.vals i.vals
102+ multires+vals
74103++ eval-exprlist
75104 |= vals=exprlist
76105 ^- (eval-m (lest value))
@@ -96,15 +125,31 @@
96125 (set-table ->-.i.asmnts (~(put by tabl) ->+.i.asmnts +.i.asmnts))
97126 ==
98127 $(asmnts t.asmnts)
128+ %local-asmnt
129+ =/ lhs=(list name)
130+ %+ turn attrnamelist.stat
131+ |= [=name attr=(unit attrib)]
132+ ?> ?=(~ attr)
133+ name
134+ ;< actual-values=(list [name value]) bind
135+ ?~ rhs.stat (pure ~)
136+ ;< rhs=(list value) bind (eval-exprlist u.rhs.stat)
137+ (pure (zip lhs rhs))
138+ ;< st=state bind get-state
139+ =. i.local-envs.st
140+ %- ~(uni by i.local-envs.st)
141+ %- malt
142+ (weld (turn lhs |=(=name [name `value`nil+~])) actual-values)
143+ (set-state st)
99144 ==
100145++ set-var
101146 |= var=name
102147 |= val=value
103148 ^- (eval-m ~)
104149 ;< envs=(list (map name value)) bind get-local-envs
105− =/ new-envs=(unit (list (map name value)))
150+ =/ new-envs=(unit (lest (map name value)))
106151 |-
107− ^- (unit (list (map name value)))
152+ ^- (unit (lest (map name value)))
108153 ?~ envs ~
109154 ?. (~(has by i.envs) var)
110155 =/ rest $(envs t.envs)
@@ -141,6 +186,7 @@
141186 =/ tail=value (normalize-multires i.vals)
142187 ?: ?=(%multires -.tail) +.tail [tail ~]
143188 [i.vals $(vals t.vals)]
189+ ?~ t.res i.res
144190 multires+res
145191 ==
146192++ process-varlist
desk/lib/lua/parser.hoon+2−2
@@ -568,7 +568,7 @@ apex
568568++ parse-local-asmnt
569569 %^ tnee %parse-local-asmnt local-asmnt
570570 %+ cook
571− |= [* * =attnamelist rhs=(unit explist)] [attnamelist rhs]
571+ |= [* * =attrnamelist rhs=(unit explist)] [attrnamelist rhs]
572572 ;~ plug
573573 (jest 'local')
574574 wss
@@ -582,7 +582,7 @@ apex
582582 ==
583583 ==
584584++ parse-attnamelist
585− %^ tnee %parse-attnamelist attnamelist
585+ %^ tnee %parse-attnamelist attrnamelist
586586 %+ most (ifix [ws ws] com)
587587 ;~ plug
588588 parse-name
desk/lib/lua/printer.hoon+5−5
@@ -264,7 +264,7 @@ print
264264 %- zing
265265 :~
266266 "local "
267− (print-attnamelist attnamelist.local-asmnt)
267+ (print-attrnamelist attrnamelist.local-asmnt)
268268 ?~ rhs.local-asmnt ""
269269 %- zing
270270 :~
@@ -272,13 +272,13 @@ print
272272 (print-explist u.rhs.local-asmnt)
273273 ==
274274 ==
275−:: attnamelist
275+:: attrnamelist
276276::
277−++ print-attnamelist
278− |= =attnamelist
277+++ print-attrnamelist
278+ |= =attrnamelist
279279 ^- tape
280280 %- commaed
281− %+ turn attnamelist
281+ %+ turn attrnamelist
282282 |= [=name attr=(unit attrib)]
283283 %- zing
284284 :~
desk/res/lua/baz.lua+3−2
@@ -1,5 +1,6 @@
11x = 8
22
3−y = x
3+local y = x + 3
44
5−return y
5+
6+return y / 2
desk/res/lua/foo.lua+2−2
@@ -47,9 +47,9 @@ do
4747 return 8, foo;
4848end
4949
50−print('the way of the future')
50+-- print('the way of the future')
5151
52−print 'hello'
52+-- print 'hello'
5353
5454h{key1 = 'Sonmi~451'}
5555
desk/sur/lua.hoon+2−2
@@ -104,8 +104,8 @@
104104+$ funcbody [pars=parlist body=blok]
105105+$ parlist [pars=(list name) wildcard=?]
106106+$ local-function [=name body=funcbody]
107−+$ local-asmnt [=attnamelist rhs=(unit exprlist)]
108−+$ attnamelist (lest [=name attr=(unit attrib)])
107++$ local-asmnt [=attrnamelist rhs=(unit exprlist)]
108++$ attrnamelist (lest [=name attr=(unit attrib)])
109109+$ attrib
110110 $?
111111 %const