Skip to content
Snippets Groups Projects
Commit 1e2cfa59 authored by Cesar Roux Dit Buisson's avatar Cesar Roux Dit Buisson
Browse files

Correct ctx creation and push

parent 71c7a334
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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));
......
......@@ -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 {
......
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