mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-05 22:38:44 +00:00
Fixed ugly bug in nested function support
This commit is contained in:
parent
3f0e1c4b15
commit
de2955cbc9
8 changed files with 38 additions and 3 deletions
1
regression/orig/test069.log
Normal file
1
regression/orig/test069.log
Normal file
|
|
@ -0,0 +1 @@
|
|||
> 0
|
||||
1
regression/orig/test070.log
Normal file
1
regression/orig/test070.log
Normal file
|
|
@ -0,0 +1 @@
|
|||
> 0
|
||||
11
regression/test069.expr
Normal file
11
regression/test069.expr
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fun f (x) {
|
||||
fun inner (y) {
|
||||
return if y == 0 then 0 else inner (y-1) fi
|
||||
}
|
||||
|
||||
return inner (x)
|
||||
}
|
||||
|
||||
local n = read ();
|
||||
|
||||
write (f (5))
|
||||
1
regression/test069.input
Normal file
1
regression/test069.input
Normal file
|
|
@ -0,0 +1 @@
|
|||
5
|
||||
15
regression/test070.expr
Normal file
15
regression/test070.expr
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
fun f (x) {
|
||||
fun inner1 (y) {
|
||||
return if y == 0 then 0 else inner2 (y-1) fi
|
||||
}
|
||||
|
||||
fun inner2 (y) {
|
||||
return if y == 0 then 0 else inner1 (y-1) fi
|
||||
}
|
||||
|
||||
return inner1 (x)
|
||||
}
|
||||
|
||||
local n = read ();
|
||||
|
||||
write (f (5))
|
||||
1
regression/test070.input
Normal file
1
regression/test070.input
Normal file
|
|
@ -0,0 +1 @@
|
|||
5
|
||||
|
|
@ -132,7 +132,7 @@ module State =
|
|||
| I
|
||||
| G of (string * bool) list * (string, 'a) arrow
|
||||
| L of (string * bool) list * (string, 'a) arrow * 'a t
|
||||
with show,html
|
||||
with show, html
|
||||
|
||||
(* Get the depth level of a state *)
|
||||
let rec level = function
|
||||
|
|
|
|||
|
|
@ -425,8 +425,8 @@ object (self : 'self)
|
|||
};
|
||||
scope = init_scope (
|
||||
let rec readdress_to_closure = function
|
||||
| State.L (xs, _, tl) ->
|
||||
State.L (xs, (fun _ -> Value.Access (~-1)), readdress_to_closure tl)
|
||||
| State.L (xs, st, tl) ->
|
||||
State.L (xs, (fun name -> match st name with Value.Fun _ as x -> x | _ -> Value.Access (~-1)), readdress_to_closure tl)
|
||||
| st -> st
|
||||
in
|
||||
readdress_to_closure st'
|
||||
|
|
@ -739,7 +739,12 @@ let compile cmd ((imports, infixes), p) =
|
|||
env, true, se @ (if fe then [LABEL lexp] else []) @ [DUP] @ (List.flatten @@ List.rev code) @ [JMP l]
|
||||
in
|
||||
let rec compile_fundef env ((name, args, stmt, st) as fd) =
|
||||
(* Printf.eprintf "Compile fundef: %s, state=%s\n" name (show(State.t) (show(Value.designation)) st); *)
|
||||
(* Printf.eprintf "st (inner) = %s\n" (try show(Value.designation) @@ State.eval st "inner" with _ -> " not found"); *)
|
||||
let env = env#open_fun_scope fd in
|
||||
|
||||
(*Printf.eprintf "Lookup: %s\n%!" (try show(Value.designation) @@ snd (env#lookup "inner") with _ -> "no inner..."); *)
|
||||
|
||||
let env = List.fold_left (fun env arg -> env#add_arg arg) env args in
|
||||
let lend, env = env#get_label in
|
||||
let env, flag, code = compile_expr lend env stmt in
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue