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
187e9939
Commit
187e9939
authored
9 years ago
by
Alan Schmitt
Browse files
Options
Downloads
Patches
Plain Diff
first try at logging
parent
1775e4aa
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
+14
-22
14 additions, 22 deletions
generator/js_of_ast.ml
generator/main.ml
+4
-5
4 additions, 5 deletions
generator/main.ml
with
18 additions
and
27 deletions
generator/js_of_ast.ml
+
14
−
22
View file @
187e9939
...
...
@@ -239,32 +239,19 @@ let ctx_initial =
"ctx_empty"
(****************************************************************)
(* MODES *)
type
generate_mode
=
|
Mode_unlogged
|
Mode_line_token
|
Mode_logged
let
current_mode
=
if
!
logging
then
Mode_logged
else
Mode_unlogged
(****************************************************************)
(* LOGGED CONSTRUCTORS *)
let
generate_logged_case
spat
binders
ctx
newctx
sbody
need_break
=
(* Note: binders is a list of pairs of id *)
(* Note: if binders = [], then newctx = ctx *)
match
current_mode
with
match
!
current_mode
with
|
Mode_line_token
|
Mode_logged
|
Mode_unlogged
->
let
sbinders
=
ppf_match_binders
binders
in
(
Printf
.
sprintf
"@[<v 2>%s:@;@[<v 2>%s%s@]@]"
spat
sbinders
sbody
)
^
(
if
need_break
then
Printf
.
sprintf
"@,break;"
else
""
)
(
Printf
.
sprintf
"@[<v 0>%s:@;<1 2>@[<v 0>%s%s%s@]@]"
spat
sbinders
sbody
(
if
need_break
then
"@,break;"
else
""
))
(* generate_logged_case implement using
...
...
@@ -285,9 +272,13 @@ with help of
let
generate_logged_return
ctx
sbody
=
match
current_mode
with
match
!
current_mode
with
|
Mode_line_token
|
Mode_logged
|
Mode_logged
->
let
id
=
id_fresh
"_return_"
in
let
token
=
"12"
in
Printf
.
sprintf
"var %s = %s;@,log_event(lineof(%s), ctx_push(%s, {
\"
return_value
\"
, %s}),
\"
return
\"
);@,return %s@,"
id
sbody
token
ctx
id
id
|
Mode_unlogged
->
Printf
.
sprintf
"return %s;"
sbody
(* Printf.sprintf "@[<v 0>return %s;@]" sbody *)
...
...
@@ -304,7 +295,7 @@ var t=e; logEvent(LINEOF(432423), ctx_push(ctx, {"return",t}), "return"); return
let
generate_logged_let
ids
ctx
newctx
sdecl
sbody
=
match
current_mode
with
match
!
current_mode
with
|
Mode_line_token
|
Mode_logged
|
Mode_unlogged
->
...
...
@@ -322,7 +313,7 @@ var x=e; var newctx=ctx_push(ctx,x,e); logEvent(LINEOF(432423), "let", ctx);sbod
*)
let
generate_logged_enter
arg_ids
ctx
newctx
sbody
=
match
current_mode
with
match
!
current_mode
with
|
Mode_line_token
|
Mode_logged
|
Mode_unlogged
->
...
...
@@ -624,8 +615,9 @@ and js_of_pattern pat obj =
let
to_javascript
module_name
typedtree
=
let
content
=
js_of_structure
typedtree
in
let
pre_res
=
ppf_module_wrap
module_name
content
in
(
L
.
logged_output
pre_res
,
L
.
unlogged_output
pre_res
,
pre_res
)
let
str_ppf
=
Format
.
str_formatter
in
Format
.
fprintf
str_ppf
(
Scanf
.
format_from_string
pre_res
""
);
Format
.
flush_str_formatter
()
(****************************************************************)
(* COMMENTS *)
...
...
This diff is collapsed.
Click to expand it.
generator/main.ml
+
4
−
5
View file @
187e9939
...
...
@@ -27,7 +27,7 @@ let _ =
]
(
fun
f
->
files
:=
f
::
!
files
)
(
"usage: [-I dir] [..other options..] file.ml"
);
current_mode
:=
if
!
logging
then
Mode_logged
else
Mode_unlogged
;
if
List
.
length
!
files
<>
1
then
failwith
"Expects one argument: the filename of the ML source file"
;
let
sourcefile
=
List
.
hd
!
files
in
...
...
@@ -52,7 +52,6 @@ let _ =
|
Some
(
parsetree1
,
(
typedtree1
,_
))
->
parsetree1
,
typedtree1
in
let
(
logged
,
unlogged
,
pre
)
=
Js_of_ast
.
to_javascript
modulename
typedtree1
in
file_put_contents
log_output
logged
;
file_put_contents
unlog_output
unlogged
;
file_put_contents
pre_output
pre
;
let
out
=
Js_of_ast
.
to_javascript
modulename
typedtree1
in
let
output_filename
=
if
!
logging
then
log_output
else
unlog_output
in
file_put_contents
output_filename
out
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