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
430ff591
There was a problem fetching the pipeline summary.
Commit
430ff591
authored
8 years ago
by
Thomas Wood
Browse files
Options
Downloads
Patches
Plain Diff
General tidying up
parent
083f0174
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
generator/main.ml
+25
-53
25 additions, 53 deletions
generator/main.ml
generator/mytools.ml
+3
-1
3 additions, 1 deletion
generator/mytools.ml
generator/params.ml
+10
-0
10 additions, 0 deletions
generator/params.ml
tools.js
+1
-1
1 addition, 1 deletion
tools.js
with
39 additions
and
55 deletions
generator/main.ml
+
25
−
53
View file @
430ff591
...
...
@@ -12,16 +12,12 @@ open Mytools
(*#########################################################################*)
let
ppf
=
Format
.
std_formatter
let
outputfile
=
ref
None
(* err_formatter *)
(*#########################################################################*)
let
add_to_list
li
s
=
li
:=
s
::
!
li
let
tool_name
=
"ml2js"
...
...
@@ -31,7 +27,6 @@ let init_path () =
Env
.
reset_cache
()
(** Return the initial environment in which compilation proceeds. *)
let
initial_env
()
=
try
let
env
=
Env
.
initial_unsafe_string
in
...
...
@@ -39,11 +34,13 @@ let initial_env () =
with
Not_found
->
Misc
.
fatal_error
"cannot open stdlib"
(** Analysis of an implementation file. Returns (Some typedtree) if
no error occured, else None and an error message is printed.*)
let
process_implementation_file
ppf
sourcefile
=
(** Analysis of an implementation file.
* ppf: error printer
* sourcefile: path/filename of source file
* oprefix: output file name prefix (possibly manually set with -o)
**)
let
process_implementation_file
ppf
sourcefile
oprefix
=
init_path
()
;
let
oprefix
=
Compenv
.
output_prefix
sourcefile
in
let
modulename
=
Compenv
.
module_of_filename
ppf
sourcefile
oprefix
in
Env
.
set_unit_name
modulename
;
let
env
=
initial_env
()
in
...
...
@@ -56,18 +53,14 @@ let process_implementation_file ppf sourcefile =
Location
.
report_exception
ppf
e
;
exit
2
let
_
=
(*---------------------------------------------------*)
(* parsing of command line *)
let
files
=
ref
[]
in
Arg
.
parse
[
(
"-I"
,
Arg
.
String
(
fun
i
->
Clflags
.
include_dirs
:=
i
::
!
Clflags
.
include_dirs
)
,
"includes a directory where to look for interface files"
);
(
"-o"
,
Arg
.
String
(
fun
s
->
outputfile
:=
Some
s
)
,
"set the output file name"
);
[
(
"-I"
,
Arg
.
String
(
add_to_list
Clflags
.
include_dirs
)
,
"includes a directory where to look for interface files"
);
(
"-o"
,
Arg
.
String
(
fun
s
->
Clflags
.
output_name
:=
Some
s
)
,
"set the output file"
);
(
"-debug"
,
Arg
.
Set
debug
,
"trace the various steps"
);
(
"-dsource"
,
Arg
.
Set
Clflags
.
dump_source
,
"dump source after ppx"
);
(
"-ppx"
,
Arg
.
String
(
add_to_list
Clflags
.
all_ppx
(* TODO Compenv.first_ppx *)
)
,
"load ppx"
);
...
...
@@ -81,22 +74,14 @@ let _ =
if
List
.
length
!
files
<>
1
then
failwith
"Expects one argument: the filename of the ML source file"
;
let
sourcefile
=
List
.
hd
!
files
in
if
not
(
Filename
.
check_suffix
sourcefile
".ml"
)
then
failwith
"The file name must be of the form *.ml"
;
let
basename
=
Filename
.
chop_suffix
(
Filename
.
basename
sourcefile
)
".ml"
in
let
dirname
=
Filename
.
dirname
sourcefile
in
let
pathname
=
if
dirname
=
""
then
basename
else
(
dirname
^
"/"
^
basename
)
in
(* Could use Clflags.output_name and Compenv.output_prefix? *)
let
log_output
,
unlog_output
,
token_output
,
pseudo_output
,
ptoken_output
,
mlloc_output
=
match
!
outputfile
with
|
None
->
Filename
.
concat
dirname
(
basename
^
".log.js"
)
,
Filename
.
concat
dirname
(
basename
^
".unlog.js"
)
,
Filename
.
concat
dirname
(
basename
^
".token.js"
)
,
Filename
.
concat
dirname
(
basename
^
".pseudo.js"
)
,
Filename
.
concat
dirname
(
basename
^
".ptoken.js"
)
,
Filename
.
concat
dirname
(
basename
^
".mlloc.js"
)
|
Some
f
->
f
^
".log.js"
,
f
^
".unlog.js"
,
f
^
".token.js"
,
f
^
".pseudo.js"
,
f
^
".ptoken.js"
,
f
^
".mlloc.js"
in
let
sourcebase
=
Filename
.
basename
sourcefile
in
(* Input file basename, for logging *)
let
oprefix
=
Compenv
.
output_prefix
sourcefile
in
(* Output filename prefix, inc. path *)
let
output_filename
=
oprefix
^
(
get_mode_extension
!
current_mode
)
in
let
mlloc_output
=
oprefix
^
".mlloc.js"
in
(*---------------------------------------------------*)
(* set flags *)
...
...
@@ -115,40 +100,27 @@ let _ =
let
generate_mlloc_file
()
=
let
outchannel
=
open_out
mlloc_output
in
let
put
str
=
output_string
outchannel
str
;
output_string
outchannel
"
\n
"
in
let
put
=
output_endline
outchannel
in
put
" lineof_temp = [];"
;
let
filename
=
basename
^
".ml"
in
Js_of_ast
.(
~~
Hashtbl
.
iter
token_locs
(
fun
key
(
pos_start
,
pos_stop
)
->
put
(
Printf
.
sprintf
" lineof_temp[%d] = [%d,%d,%d,%d];"
key
pos_start
.
pos_line
pos_start
.
pos_col
pos_stop
.
pos_line
pos_stop
.
pos_col
);
));
put
(
Printf
.
sprintf
"lineof_data[
\"
%s
\"
] = lineof_temp;"
filenam
e
);
put
(
Printf
.
sprintf
"lineof_data[
\"
%s
\"
] = lineof_temp;"
sourcebas
e
);
close_out
outchannel
;
Printf
.
printf
"Wrote %s
\n
"
mlloc_output
;
in
(*---------------------------------------------------*)
(* "reading and typing source file" *)
let
(
parsetree
,
(
typedtree
,_
)
,
module_name
)
=
process_implementation_file
ppf
sourcefile
in
match
!
current_mode
with
|
Mode_cmi
->
Printf
.
printf
"Wrote %s.cmi
\n
"
pathname
|
_
->
let
out
=
Js_of_ast
.
to_javascript
basename
module_name
typedtree
in
let
output_filename
=
match
!
current_mode
with
|
Mode_unlogged
TokenTrue
->
token_output
|
Mode_unlogged
TokenFalse
->
unlog_output
|
Mode_pseudo
TokenTrue
->
ptoken_output
|
Mode_pseudo
TokenFalse
->
pseudo_output
|
Mode_logged
->
log_output
|
_
->
assert
false
in
file_put_contents
output_filename
out
;
Printf
.
printf
"Wrote %s
\n
"
output_filename
;
if
!
current_mode
=
(
Mode_unlogged
TokenTrue
)
then
generate_mlloc_file
()
let
(
parsetree
,
(
typedtree
,_
)
,
module_name
)
=
process_implementation_file
ppf
sourcefile
oprefix
in
if
!
current_mode
<>
Mode_cmi
then
begin
let
out
=
Js_of_ast
.
to_javascript
sourcebase
module_name
typedtree
in
file_put_contents
output_filename
out
;
if
!
current_mode
=
(
Mode_unlogged
TokenTrue
)
then
generate_mlloc_file
()
end
;
Printf
.
printf
"Wrote %s
\n
"
output_filename
This diff is collapsed.
Click to expand it.
generator/mytools.ml
+
3
−
1
View file @
430ff591
...
...
@@ -180,6 +180,9 @@ let file_put_contents filename text =
with
Sys_error
s
->
failwith
(
"Could not write in file: "
^
filename
^
"
\n
"
^
s
)
let
output_endline
outchannel
str
=
output_string
outchannel
str
;
output_char
outchannel
'\n'
(**************************************************************)
(** Try-with manipulation functions *)
...
...
@@ -246,4 +249,3 @@ let error ?loc s =
let
warning
?
loc
s
=
option_iter
(
Location
.
print_loc
err_formatter
)
loc
;
Printf
.
printf
"%s
\n
"
(
"Warning: "
^
s
^
"."
)
This diff is collapsed.
Click to expand it.
generator/params.ml
+
10
−
0
View file @
430ff591
...
...
@@ -2,6 +2,8 @@ let debug = ref false
let
(
~~
)
f
x
y
=
f
y
x
let
add_to_list
li
s
=
li
:=
s
::
!
li
(****************************************************************)
(* MODES *)
...
...
@@ -28,6 +30,14 @@ let set_current_mode s =
|
"ptoken"
->
Mode_pseudo
TokenTrue
|
_
->
failwith
"Invalid mode, chose log, unlog, or token"
let
get_mode_extension
m
=
match
m
with
|
Mode_unlogged
TokenTrue
->
".token.js"
|
Mode_unlogged
TokenFalse
->
".unlog.js"
|
Mode_pseudo
TokenTrue
->
".ptoken.js"
|
Mode_pseudo
TokenFalse
->
".pseudo.js"
|
Mode_logged
->
".log.js"
|
Mode_cmi
->
".cmi"
let
is_mode_pseudo
()
=
(
match
!
current_mode
with
Mode_pseudo
_
->
true
|
_
->
false
)
...
...
This diff is collapsed.
Click to expand it.
tools.js
+
1
−
1
View file @
430ff591
...
...
@@ -37,7 +37,7 @@ function reset_datalog() {
function
log_event
(
filename
,
token
,
ctx
,
type
)
{
// TODO populate state with object_heap, env_record_heap, fresh_locations, and populate env
// compute "foo.ml" and "foo.ps
u
edo" from "foo.js"
// compute "foo.ml" and "foo.pse
u
do" from "foo.js"
var
len
=
filename
.
length
;
var
base
=
filename
.
substr
(
0
,
len
-
2
);
var
mlfilename
=
base
+
"
ml
"
;
...
...
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