Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
jsexplain
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Verified Software
jsexplain
Commits
d3f3adc6
Commit
d3f3adc6
authored
9 years ago
by
charguer
Committed by
Alan Schmitt
9 years ago
Browse files
Options
Downloads
Patches
Plain Diff
new ctx branch
parent
6835c1ae
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
generator/js_of_ast.ml
+80
-0
80 additions, 0 deletions
generator/js_of_ast.ml
generator/tests/testctx.ml
+83
-0
83 additions, 0 deletions
generator/tests/testctx.ml
with
163 additions
and
0 deletions
generator/js_of_ast.ml
+
80
−
0
View file @
d3f3adc6
...
@@ -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
This diff is collapsed.
Click to expand it.
generator/tests/testctx.ml
0 → 100644
+
83
−
0
View file @
d3f3adc6
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment