Skip to content
Snippets Groups Projects
Commit d3f3adc6 authored by charguer's avatar charguer Committed by Alan Schmitt
Browse files

new ctx branch

parent 6835c1ae
No related branches found
No related tags found
No related merge requests found
...@@ -381,3 +381,83 @@ let to_javascript module_name typedtree = ...@@ -381,3 +381,83 @@ let to_javascript module_name typedtree =
let pre_res = ppf_module_wrap module_name content in let pre_res = ppf_module_wrap module_name content in
(L.logged_output pre_res, L.unlogged_output pre_res, pre_res) (L.logged_output pre_res, L.unlogged_output pre_res, pre_res)
(*
ctx_empty
ctx_push(ctx, bindings) where bindings = [ { key:"ls", val:ls}, { key:"xs", val:xs } ]
example:
ctx321 = ctx_push(ctx320, bindings); log(|line|, ctx321, "ctx_push")
enter (or call) => current ctx plus arguments of the call
return (was exit) => current ctx plus return value
let (on the "in") => current ctx plus new binding
case => current ctx plus bound variables
type token_info = ctx_operation * ctx
if ==> viewed as match with case true/false.
ctx_empty is passed on each structure_item
on each ctx extension, we need a fresh name (enter, let, match_branch)
(for return values, do the extension on the fly)
return f(x);
translates as
var v213 = f(x);
log(|line|, ctx_push(ctx320, {key: "return", val: v213}), "return")
match v with | None -> x | Some y -> y
translates as
function() {
----------------------
let f ... =
match ...
=>
switch
case:
return;
----------------------
let f ... =
match .. ->
match ...
=>
return
----------------------
let x = match ... in ...
=>
switch ...
case:
x = ..; break;
case:
x = ..; break;
----------------------
let x =
match .. ->
match .. ->
=>
would not work without wrapping
----------------------
f (match ...)
=>
requires A-normalization
*)
\ No newline at end of file
let testa x =
x
let testb x =
let x = x in x
let testc x =
let y = x in
let x = y+1 in
x+y
let testd x =
let f x =
let y = x in y in
f x
let teste x =
let y =
let z = x in z in
y
let testf x =
let f a =
let y = a in x+y in
f x
let testg x =
if x then 1 else 0
let test0 =
match Some 3 with
| None -> 2
| Some y -> y
let test1 on =
let x =
match on with
| None -> 0
| Some n -> n
in
2*x
let test2 v =
let x =
let x = 3 in x+1
in
x
let test3 x =
let x =
match x with
| None -> 1
| Some x -> x+2
in
x
let test4 x =
let y = x+1 in
let x x = x in
x (let x = y in x)
let test5 x =
match x with
| None -> 0
| Some x -> let x = x+x in x+1
(*
let test6 =
function z -> match z with (x,y) -> x
*)
(*
let test6 (x,y) =
x
*)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment