- Change lambda to represent only anoymous-function.
open Asm
type ast =
- Method of string * string list * ast
+ Lambda of string list * ast
| Call of string * ast list
| String of string
| Int of int
| Lt (l,r) -> binary_op LessThan l r
| Leq (l,r) -> binary_op LessEquals l r
(* syntax *)
- | Method (name,args,body) ->
+ | Lambda (args,body) ->
let env' =
add_register args env in
let args' =
List.map (const 0) args in
let m =
- make_meth ~args:args' name @@ generate_expr body env' in
+ make_meth ~args:args' "" @@ generate_expr body env' in
[NewFunction m]
| Block xs ->
List.concat @@ interperse [Pop] @@ (List.map expr xs)
type ast =
- Method of string * string list * ast
+ Lambda of string list * ast
| Call of string * ast list
| String of string
| Int of int
| Symbol "lambda"::List args::body ->
let body' =
List.map make_ast body in
- Ast.Method ("",List.map (fun (Symbol x)->x) args,Ast.Block body')
+ Ast.Lambda (List.map (fun (Symbol x)->x) args,Ast.Block body')
| ((Symbol name)::args) ->
Ast.Call (name,List.map make_ast args)
| _ ->
test call =
assert_equal
(result [NewFunction (result [PushInt 42]) ])
- (compile (Method ("",[],Block [Int 42])))
+ (compile (Lambda ([],Block [Int 42])))
test call_with_args =
assert_equal
(result [NewFunction (result ~args:[0;0] [GetLocal 2])])
- (compile (Method ("",["x";"y"],Block [Var "y"])))
+ (compile (Lambda (["x";"y"],Block [Var "y"])))
compile_string "(begin 1 2)"
test lammda =
- assert_equal [Method ("",[],Block [Int 42])] @@
+ assert_equal [Lambda ([],Block [Int 42])] @@
compile_string "(lambda () 42)"
test lammda_with_args =
- assert_equal [Method ("",["a";"b";"c"],Block [Int 42])] @@
+ assert_equal [Lambda (["a";"b";"c"],Block [Int 42])] @@
compile_string "(lambda (a b c) 42)"