Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
hhugo committed Apr 7, 2020
1 parent 56d6a69 commit 32e7aa9
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 38 deletions.
14 changes: 8 additions & 6 deletions runtime/dynlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ var current_libs = [0, joo_global_object]

//Provides: caml_dynlink_open_lib
//Requires: current_libs, caml_failwith
//Requires: caml_jsstring_of_string
function caml_dynlink_open_lib (_mode,file) {
var name = file.toString();
joo_global_object.console.log("Dynlink: try to open ", name);
//caml_failwith("file not found: "+name)
current_libs.push({});
return current_libs.length;
var name = caml_jsstring_of_string(file);
joo_global_object.console.log("Dynlink: try to open ", name);
//caml_failwith("file not found: "+name)
current_libs.push({});
return current_libs.length;
}

//Provides: caml_dynlink_close_lib
Expand All @@ -38,8 +39,9 @@ function caml_dynlink_close_lib (idx) {

//Provides: caml_dynlink_lookup_symbol
//Requires: current_libs
//Requires: caml_jsstring_of_string
function caml_dynlink_lookup_symbol (idx, fun_name) {
var name = fun_name.toString();
var name = caml_jsstring_of_string(fun_name);
joo_global_object.console.log("Dynlink: look for symbol ", name);
if(current_libs[idx] && current_libs[idx][name])
return current_libs[idx][name];
Expand Down
15 changes: 9 additions & 6 deletions runtime/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ var caml_root = caml_current_dir.match(/[^\/]*\//)[0];
function MlFile(){ }

//Provides: caml_make_path
//Requires: caml_current_dir,MlBytes
//Requires: caml_current_dir
//Requires: caml_jsstring_of_string
function caml_make_path (name) {
name=(name instanceof MlBytes)?name.toString():name;
name=caml_jsstring_of_string(name);
if(name.charCodeAt(0) != 47)
name = caml_current_dir + name;
var comp = name.split("/");
Expand Down Expand Up @@ -133,16 +134,18 @@ function caml_sys_chdir(dir) {
}

//Provides: caml_raise_no_such_file
//Requires: MlBytes, caml_raise_sys_error
//Requires: caml_raise_sys_error
//Requires: caml_jsbytes_of_string
function caml_raise_no_such_file(name){
name = (name instanceof MlBytes)?name.toString():name;
name = caml_jsbytes_of_string(name);
caml_raise_sys_error (name + ": No such file or directory");
}

//Provides: caml_raise_not_a_dir
//Requires: MlBytes, caml_raise_sys_error
//Requires: caml_raise_sys_error
//Requires: caml_jsbytes_of_string
function caml_raise_not_a_dir(name){
name = (name instanceof MlBytes)?name.toString():name;
name = caml_jsbytes_of_string(name);
caml_raise_sys_error (name + ": Not a directory");
}

Expand Down
25 changes: 16 additions & 9 deletions runtime/graphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ function caml_gr_state_set(ctx) {
//Requires: caml_gr_state_create
//Requires: caml_gr_state_set
//Requires: caml_failwith
//Requires: caml_jsstring_of_string
function caml_gr_open_graph(info){
var g = joo_global_object;
var info = info.toString();
var info = caml_jsstring_of_string(info);
function get(name){
var res = info.match("(^|,) *"+name+" *= *([a-zA-Z0-9_]+) *(,|$)");
if(res) return res[2];
Expand Down Expand Up @@ -97,6 +98,7 @@ function caml_gr_state_init(){
}

//Provides: caml_gr_state_create
//Requires: caml_string_of_jsbytes
function caml_gr_state_create(canvas,w,h){
var context = canvas.getContext("2d");
return {
Expand All @@ -107,10 +109,10 @@ function caml_gr_state_create(canvas,w,h){
width : w,
height : h,
line_width : 1,
font : "fixed",
font : caml_string_of_jsbytes("fixed"),
text_size : 26,
color : 0x000000,
title : ""
title : caml_string_of_jsbytes("")
};
}

Expand All @@ -131,11 +133,12 @@ function caml_gr_close_graph(){

//Provides: caml_gr_set_window_title
//Requires: caml_gr_state_get
//Requires: caml_jsstring_of_string
function caml_gr_set_window_title(name){
var s = caml_gr_state_get();
name = name.toString?name.toString():name;
s.title = name;
if(s.set_title) s.set_title(name);
var jsname = caml_jsstring_of_string(name);
if(s.set_title) s.set_title(jsname);
return 0;
}

Expand Down Expand Up @@ -356,34 +359,38 @@ function caml_gr_draw_char(c){

//Provides: caml_gr_draw_string
//Requires: caml_gr_draw_str
//Requires: caml_jsstring_of_string
function caml_gr_draw_string(str){
caml_gr_draw_str(str.toString());
caml_gr_draw_str(caml_jsstring_of_string(str));
return 0;
}

//Provides: caml_gr_set_font
//Requires: caml_gr_state_get
//Requires: caml_jsstring_of_string
function caml_gr_set_font(f){
var s = caml_gr_state_get();
s.font = f;
s.context.font = s.text_size + "px " + s.font.toString();
s.context.font = s.text_size + "px " + caml_jsstring_of_string(s.font);
return 0;
}

//Provides: caml_gr_set_text_size
//Requires: caml_gr_state_get
//Requires: caml_jsstring_of_string
function caml_gr_set_text_size(size){
var s = caml_gr_state_get();
s.text_size = size;
s.context.font = s.text_size + "px " + s.font.toString();
s.context.font = s.text_size + "px " + caml_jsstring_of_string(s.font);
return 0;
}

//Provides: caml_gr_text_size
//Requires: caml_gr_state_get
//Requires: caml_jsstring_of_string
function caml_gr_text_size(txt){
var s = caml_gr_state_get();
var w = s.context.measureText(txt.toString()).width;
var w = s.context.measureText(caml_jsstring_of_string(txt)).width;
return [0,w,s.text_size];
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/int64.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ function caml_int64_format (fmt, x) {
}

//Provides: caml_int64_of_string
//Requires: caml_parse_sign_and_base, caml_failwith, caml_parse_digit, MlBytes
//Requires: caml_parse_sign_and_base, caml_failwith, caml_parse_digit
//Requires: caml_int64_of_int32, caml_int64_ult
//Requires: caml_int64_add, caml_int64_mul, caml_int64_neg
//Requires: caml_ml_string_length,caml_string_unsafe_get, MlInt64
Expand Down
5 changes: 3 additions & 2 deletions runtime/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function caml_std_output(chanid,s){
//Requires: js_print_stderr, js_print_stdout
//Requires: caml_std_output
//Requires: resolve_fs_device
//Requires: caml_jsbytes_of_string
function caml_sys_open_internal(idx,output,file,flags) {
if(caml_global_data.fds === undefined) caml_global_data.fds = new Array();
flags=flags?flags:{};
Expand Down Expand Up @@ -73,9 +74,9 @@ function caml_sys_open (name, flags, _perms) {
flags=flags[2];
}
if(f.rdonly && f.wronly)
caml_raise_sys_error(name.toString() + " : flags Open_rdonly and Open_wronly are not compatible");
caml_raise_sys_error(caml_jsbytes_of_string(name) + " : flags Open_rdonly and Open_wronly are not compatible");
if(f.text && f.binary)
caml_raise_sys_error(name.toString() + " : flags Open_text and Open_binary are not compatible");
caml_raise_sys_error(caml_jsbytes_of_string(name) + " : flags Open_text and Open_binary are not compatible");
var root = resolve_fs_device(name);
var file = root.device.open(root.rest,f);
var idx = caml_global_data.fd_last_idx?caml_global_data.fd_last_idx:0;
Expand Down
24 changes: 12 additions & 12 deletions runtime/jslib_js_of_ocaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ function caml_js_to_array(a) { return raw_array_cons(a,0); }

//Provides: caml_js_var mutable (const)
//Requires: js_print_stderr
//Requires: MlBytes
//Requires: caml_jsstring_of_string
function caml_js_var(x) {
var x = x.toString();
var x = caml_jsstring_of_string(x);
//Checks that x has the form ident[.ident]*
if(!x.match(/^[a-zA-Z_$][a-zA-Z_$0-9]*(\.[a-zA-Z_$][a-zA-Z_$0-9]*)*$/)){
js_print_stderr("caml_js_var: \"" + x + "\" is not a valid JavaScript variable. continuing ..");
Expand All @@ -67,10 +67,10 @@ function caml_js_fun_call(f, a) {
return f.apply(null, caml_js_from_array(a));
}
//Provides: caml_js_meth_call (mutable, const, shallow)
//Requires: MlBytes
//Requires: caml_jsstring_of_string
//Requires: caml_js_from_array
function caml_js_meth_call(o, f, args) {
return o[f.toString()].apply(o, caml_js_from_array(args));
return o[caml_jsstring_of_string(f)].apply(o, caml_js_from_array(args));
}
//Provides: caml_js_new (const, shallow)
//Requires: caml_js_from_array
Expand Down Expand Up @@ -171,30 +171,30 @@ function caml_js_wrap_meth_callback_unsafe(f) {
function caml_js_equals (x, y) { return +(x == y); }

//Provides: caml_js_eval_string (const)
//Requires: MlBytes
function caml_js_eval_string (s) {return eval(s.toString());}
//Requires: caml_jsstring_of_string
function caml_js_eval_string (s) {return eval(caml_jsstring_of_string(s));}

//Provides: caml_js_expr (const)
//Requires: js_print_stderr
//Requires: MlBytes
//Requires: caml_jsstring_of_string
function caml_js_expr(s) {
js_print_stderr("caml_js_expr: fallback to runtime evaluation");
return eval(s.toString());}
return eval(caml_jsstring_of_string(s));}

//Provides: caml_pure_js_expr const (const)
//Requires: js_print_stderr
//Requires: MlBytes
//Requires: caml_jsstring_of_string
function caml_pure_js_expr (s){
js_print_stderr("caml_pure_js_expr: fallback to runtime evaluation");
return eval(s.toString());}
return eval(caml_jsstring_of_string(s));}

//Provides: caml_js_object (object_literal)
//Requires: MlBytes
//Requires: caml_jsstring_of_string
function caml_js_object (a) {
var o = {};
for (var i = 1; i < a.length; i++) {
var p = a[i];
o[p[1].toString()] = p[2];
o[caml_jsstring_of_string(p[1])] = p[2];
}
return o;
}
Expand Down
6 changes: 4 additions & 2 deletions runtime/stdlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -1149,8 +1149,9 @@ function caml_sys_const_ostype_unix () { return 1; }
function caml_sys_const_ostype_win32 () { return 0; }

//Provides: caml_sys_system_command
//Requires: caml_jsstring_of_string
function caml_sys_system_command(cmd){
var cmd = cmd.toString();
var cmd = caml_jsstring_of_string(cmd);
joo_global_object.console.log(cmd);
if (typeof require != "undefined"
&& require('child_process')
Expand Down Expand Up @@ -1269,9 +1270,10 @@ function caml_set_static_env(k,v){
//Provides: caml_sys_getenv (const)
//Requires: caml_raise_not_found
//Requires: caml_string_of_jsstring
//Requires: caml_jsstring_of_string
function caml_sys_getenv (name) {
var g = joo_global_object;
var n = name.toString();
var n = caml_jsstring_of_string(name);
//nodejs env
if(g.process
&& g.process.env
Expand Down

0 comments on commit 32e7aa9

Please sign in to comment.