Skip to content
Snippets Groups Projects
Commit e38c8be7 authored by Thomas Wood's avatar Thomas Wood
Browse files

Remove old files

parent 5062c73f
No related branches found
No related tags found
No related merge requests found
# Log and Generation Recap
### What stage is this at?
Right now, the generator is capable of creating nearly ready javascript on the calc example. The `run_trm` wrap has been removed from this branch but a single `make tests` in `js_of_ocaml-advlog` generates navig.html ready code that just needs to be included.
### What's missing?
In the immediate, the if then else pattern in generated javascript doesn't have according `return` call logging. This can be tested in the `tests/mylist.ml` example.
The generation and updating of ctx inside of a function is also incorrect (in some instances): It would be best to have differently named contexts, ie:
```ocaml
> [A] - representation of the variables in context
let A':=
match A return attributes with
| attributes_data_of Ad =>
> [A, Ad]
attributes_accessor_of_attributes_data Ad
| attributes_accessor_of Aa =>
> [A, Aa]
attributes_data_of_attributes_accessor Aa
end
in
>[A, A']
...
```
In this example, we would be accidentally adding Ad and Aa to the context outside of the `let` because of our use of a single ctx name. Multi names can be implemented at any level, the easiest being `js_of_ast` where we still have information as to what context we are stepping into and out of, then sending a generated ctx name to the logger to use.
### Adding new logging information
`js_of_ast` notifies the logger where it wants a "log context" via a call to `L.log_line` which takes a string and a list of `ctx_operation`.
These operations are defined twice inside log.ml. Both need to be identical. First occurence is line 34.
These contexts will then get recorded and signalled in a generated line via a token (form: `|<number>|`).
`log_line` searches for a new line or break, which may not exist yet in a string in the OCaml Print Format.
The context must then be matched inside the `add_line` `aux` recursive function, which steps through each token list/line pair and completes the action the token is defined to do inside the following match. The catchall skips any non matched tokens.
The final string is reconstructed via a Buffer, so add your logging lines in the same manner, ie:
```
| Exit ->
(* Log exit of a function *)
Buffer.add_string buf ("\n" ^ pad ^ "log_custom({line:" ^ string_of_int (i + 1) ^ ", type: \"exit\"});");
aux i ((tks, str) :: xs)
```
It doesn't matter if the context doesn't also add the original string back in the buffer, as long as you call `aux` recursively with the same i and the remaining tokens. You can also modify the original string by sending the modified version instead of the `str` seen in the example above.
\ No newline at end of file
function run_trm (code) {
var Stack = {
is_empty: function (s) {
return s === {type: "N"};
},
push: function (x, stack) {
return {type: "C", value: x, stack: stack};
},
pop: function (stack) {
return (function () {
switch (stack.type) {
case "C": var x = stack.value, xs = stack.stack;
return x;
case "N":
return stuck("Empty list");
}
}())
;
},
}
var eval_ = function (expr) {
var ctx = ctx_empty();
ctx = ctx_push(ctx, "t", expr, "term");
log(23, ctx, "eval_");
return (function () {
switch (expr.type) {
case "Const": var n = expr.value;
ctx = ctx_push(ctx, "n", n, "value");
log(26 , ctx, "Const");
return n;
case "Add": var ls = expr.left, rs = expr.right;
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 = 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"});
var res = eval_(ls) - eval_(rs);
log_custom({line: 31, type: "exit"});
return res;
}());
case "Mul": var ls = expr.left, rs = expr.right;
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 = 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 = ctx_push(ctx, "s", s, "value");
log(36 , ctx, "Pop");
return Stack.pop(call_wrap(37, s, evals));
}
}())
;
};
var evals = function (sexpr) {
var ctx = ctx_empty();
ctx = ctx_push(ctx, "t", sexpr, "term");
log(43, ctx, "evals");
return (function () {
switch (sexpr.type) {
case "Emp":
return {type: "Stack.N"};
case "Push": var v = sexpr.value, s = sexpr.stack;
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));
}
}())
;
};
return eval_(code);
};
\ 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