From 1e2cfa596a9a5f1ab91f2093469c05833dc6472c Mon Sep 17 00:00:00 2001 From: Cesar Roux Dit Buisson <cr1013@imperial.ac.uk> Date: Fri, 9 Oct 2015 10:44:07 +0100 Subject: [PATCH] Correct ctx creation and push --- generator/log.ml | 6 ++++-- generator/tests/log_source.js | 24 ++++++++++++------------ navig.html | 3 ++- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/generator/log.ml b/generator/log.ml index 60993ec..a6a2099 100644 --- a/generator/log.ml +++ b/generator/log.ml @@ -164,7 +164,7 @@ struct let ctx_processing id = let rec aux = function | [] -> "" - | x :: xs -> "\n" ^ pad ^ "ctx_push(ctx, \"" ^ x ^ "\", " ^ x ^ ", \"value\");" ^ aux xs + | x :: xs -> "\n" ^ pad ^ "ctx = ctx_push(ctx, \"" ^ x ^ "\", " ^ x ^ ", \"value\");" ^ aux xs in id |> to_format |> Format.sprintf |> global_replace (regexp "var ") "" |> split (regexp ", ") |> List.map (fun x -> List.hd (split (regexp " = ") x)) |> aux @@ -176,7 +176,9 @@ struct Buffer.add_string buf str; Buffer.add_string buf ("\n" ^ pad ^ "var ctx = ctx_empty();"); (* Logging needs changing so we can use args actual name instead of t *) - List.map (fun x -> Buffer.add_string buf ("\n" ^ pad ^ "ctx_push(ctx, \"t\", " ^ x ^ ", \"expr\");") ) argslist; + List.map (fun x -> Buffer.add_string buf ("\n" ^ pad ^ "ctx = ctx_push(ctx, \"" ^ x ^ "\", " ^ x ^ ", \"term\");") ) argslist; + (* Find way to trickle actual function name in log call? *) + Buffer.add_string buf ("\n" ^ pad ^ "log(" ^ string_of_int (i + 1) ^ ", ctx, \"function\");"); aux i ((tks, str) :: xs) | ReturnStrip -> let strsplit = split (regexp "return") str in diff --git a/generator/tests/log_source.js b/generator/tests/log_source.js index ced5c44..e6b188c 100644 --- a/generator/tests/log_source.js +++ b/generator/tests/log_source.js @@ -30,19 +30,19 @@ var eval_ = function (expr) { return (function () { switch (expr.type) { case "Const": var n = expr.value; - ctx_push(ctx, "n", n, "value"); + ctx = ctx_push(ctx, "n", n, "value"); log(26 , ctx, "Const"); return n; case "Add": var ls = expr.left, rs = expr.right; - ctx_push(ctx, "ls", ls, "value"); - ctx_push(ctx, "rs", rs, "value"); + ctx = ctx_push(ctx, "ls", ls, "value"); + ctx = ctx_push(ctx, "rs", rs, "value"); log(28 , ctx, "Add"); return call_wrap(29, ls, eval_) + call_wrap(29, rs, eval_); case "Sub": var ls = expr.left, rs = expr.right; - ctx_push(ctx, "ls", ls, "value"); - ctx_push(ctx, "rs", rs, "value"); + ctx = ctx_push(ctx, "ls", ls, "value"); + ctx = ctx_push(ctx, "rs", rs, "value"); log(30 , ctx, "Sub"); return (function() { log_custom({line: 31, type: "enter"}); @@ -52,19 +52,19 @@ var eval_ = function (expr) { }()); case "Mul": var ls = expr.left, rs = expr.right; - ctx_push(ctx, "ls", ls, "value"); - ctx_push(ctx, "rs", rs, "value"); + ctx = ctx_push(ctx, "ls", ls, "value"); + ctx = ctx_push(ctx, "rs", rs, "value"); log(32 , ctx, "Mul"); return call_wrap(33, line, eval_) * call_wrap(33, rs, eval_); case "Div": var ls = expr.left, rs = expr.right; - ctx_push(ctx, "ls", ls, "value"); - ctx_push(ctx, "rs", rs, "value"); + ctx = ctx_push(ctx, "ls", ls, "value"); + ctx = ctx_push(ctx, "rs", rs, "value"); log(34 , ctx, "Div"); return call_wrap(35, ls, eval_) / call_wrap(35, rs, eval_); case "Pop": var s = expr.stack; - ctx_push(ctx, "s", s, "value"); + ctx = ctx_push(ctx, "s", s, "value"); log(36 , ctx, "Pop"); return Stack.pop(call_wrap(37, s, evals)); } @@ -82,8 +82,8 @@ var evals = function (sexpr) { case "Emp": return {type: "Stack.N"}; case "Push": var v = sexpr.value, s = sexpr.stack; - ctx_push(ctx, "v", v, "value"); - ctx_push(ctx, "s", s, "value"); + ctx = ctx_push(ctx, "v", v, "value"); + ctx = ctx_push(ctx, "s", s, "value"); log(48 , ctx, "Push"); return Stack.push(call_wrap(49, v, eval_), call_wrap(49, s, evals)); diff --git a/navig.html b/navig.html index e41a3de..1763eab 100644 --- a/navig.html +++ b/navig.html @@ -35,7 +35,8 @@ <script src="sparray.js"></script> <script type = "text/javascript" src="source.js"></script> <script src="interp.js"></script> -<script src="generator/tests/log_source.js"></script> +<script src="generator/tests/calc.log.js"></script> +<!--<script src="generator/tests/log_source.js"></script>--> <style> .source_div { -- GitLab