-(let ((f (lambda () (print 42))))
- (f))
\ No newline at end of file
+(let ((f (lambda () 42)))
+ (print (f)))
\ No newline at end of file
let inst =
[GetLocal_0;PushScope] @
body @
- [ReturnVoid] in
+ [ReturnValue] in
{ name = name;
params=[];
return=0;
make_meth name @@ expr body in
[NewFunction m]
| Block xs ->
- (concatMap expr xs)
+ List.concat @@ interperse [Pop] @@ (List.map expr xs)
| Var name ->
let scope,index =
List.assoc name table in
load;
[GetLocal_0];
concatMap expr args;
- [Asm.Call (List.length args);Pop]]
+ [Asm.Call (List.length args)]]
| Call (name,args) ->
let mname =
Cpool.QName ((Cpool.Namespace ""),name) in
- [FindPropStrict mname]
- @ (concatMap expr args)
- @ [CallPropLex (mname,List.length args);
- Pop;]
+ List.concat [
+ [FindPropStrict mname];
+ concatMap expr args;
+ [CallPropLex (mname,List.length args)]]
| If (cond,cons,alt) ->
let l_alt =
Label.make () in
else
a::range (a+1) b
+let rec interperse delim =
+ function
+ [] -> []
+ | [x] -> [x]
+ | x::xs -> x::delim::interperse delim xs
+
type ('a,'b) either = Left of 'a | Right of 'b
let left =
function
params=[];
return=0;
flags=0;
- instructions=[GetLocal_0;PushScope;]@inst@[ReturnVoid];
+ instructions=[GetLocal_0;PushScope;]@inst@[ReturnValue];
traits=[];
exceptions=[]}
assert_equal
(result [FindPropStrict (QName ((Namespace ""),"print"));
PushString "Hello";
- CallPropLex (QName ((Namespace ""),"print"),1);
- Pop])
+ CallPropLex (QName ((Namespace ""),"print"),1)])
(compile (Call ("print",[String "Hello"])))
test int =
test block =
assert_equal
- (result [PushInt 1;PushInt 2])
+ (result [PushInt 1;Pop;PushInt 2])
(compile (Block [Int 1;Int 2]))
test if_ =
PushScope;
GetScopeObject 1;
GetProperty (QName ((Namespace ""),"0"));
+ Pop;
GetScopeObject 1;
GetProperty (QName ((Namespace ""),"1"));
PopScope])