Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[refact] use array representaion per discussion #287

Merged
merged 1 commit into from
Apr 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions jscomp/js_config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,11 @@ let weak = "Caml_weak"
let backtrace = "Caml_backtrace"
let gc = "Caml_gc"
let int32 = "Caml_int32"
let block = "Block"

let runtime_set =
[
block;
int32;
gc ;
backtrace;
Expand Down
1 change: 1 addition & 0 deletions jscomp/js_config.mli
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ val default_gen_tds : bool ref
val runtime_set : String_set.t
val stdlib_set : String_set.t

val block : string
val int32 : string
val gc : string
val backtrace : string
Expand Down
21 changes: 7 additions & 14 deletions jscomp/js_dump.ml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ module L = struct
let ge = ">="
let plus_plus = "++" (* FIXME: use (i = i + 1 | 0) instead *)
let minus_minus = "--"
let caml_block = "Block"
let caml_block_create = "__"
end
let return_indent = (String.length L.return / Ext_pp.indent_length)

Expand Down Expand Up @@ -892,28 +894,19 @@ and

| Number (Int { i = 0l ; _}) ,
(Blk_tuple | Blk_array | Blk_variant _ | Blk_record _ | Blk_na | Blk_module _
| Blk_constructor (_, 1)
| Blk_constructor (_, 1) (* Sync up with {!Js_dump}*)
)
(* Hack to optimize option which is really pervasive in ocaml,
we need concrete benchmark to support this
*)
-> expression_desc cxt l f (Array (el, mutable_flag))
(* TODO: for numbers like 248, 255 we can reverse engineer to make it
[Obj.xx_flag], but we can not do this in runtime libraries
*)

| _, _
->
expression_desc cxt l f
(J.Object (
let length, rev_list =
List.fold_left (fun (i,acc) v ->
(i+1, (Js_op.Int_key i, v) :: acc)
) (0, []) el in
List.rev_append rev_list
[(Js_op.Length, E.small_int length) ; (Js_op.Tag, tag)]
)
)
P.string f L.caml_block;
P.string f L.dot ;
P.string f L.caml_block_create;
P.paren_group f 1 (fun _ -> arguments cxt f [tag; E.arr mutable_flag el])
end
| Caml_block_tag e ->
P.group f 1 (fun _ ->
Expand Down
21 changes: 17 additions & 4 deletions jscomp/js_fold_basic.ml
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,24 @@ class count_hard_dependencies =
match x with
| {expression_desc = Call (_,_, {arity = NA}); _}
(* see [Js_exp_make.runtime_var_dot] *)
-> begin
->
Hash_set.add hard_dependencies
(Lam_module_ident.of_runtime (Ext_ident.create_js Js_config.curry));
super#expression x
| {expression_desc = Caml_block(_,_, tag, tag_info); _}
->
begin match tag.expression_desc, tag_info with
| Number (Int { i = 0l ; _}) ,
(Blk_tuple | Blk_array | Blk_variant _ | Blk_record _ | Blk_na | Blk_module _
| Blk_constructor (_, 1)
) (*Sync up with {!Js_dump}*)
-> ()
| _, _
->
Hash_set.add hard_dependencies
(Lam_module_ident.of_runtime (Ext_ident.create_js Js_config.curry));
super#expression x
end
(Lam_module_ident.of_runtime (Ext_ident.create_js Js_config.block));
end;
super#expression x
| _ -> super#expression x
method get_hard_dependencies = hard_dependencies
end
Expand Down
10 changes: 5 additions & 5 deletions jscomp/runtime/.depend
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
block.cmi :
caml_array.cmi :
caml_backtrace.cmi :
caml_bigarray.cmi :
caml_block.cmi :
caml_builtin_exceptions.cmi :
caml_exceptions.cmi : caml_builtin_exceptions.cmi
caml_float.cmi :
Expand All @@ -21,14 +21,14 @@ caml_string.cmi :
caml_sys.cmi :
caml_utils.cmi :
caml_weak.cmi :
block.cmo : block.cmi
block.cmx : block.cmi
caml_array.cmo : js.cmo caml_array.cmi
caml_array.cmx : js.cmx caml_array.cmi
caml_backtrace.cmo : caml_backtrace.cmi
caml_backtrace.cmx : caml_backtrace.cmi
caml_bigarray.cmo : caml_bigarray.cmi
caml_bigarray.cmx : caml_bigarray.cmi
caml_block.cmo : caml_block.cmi
caml_block.cmx : caml_block.cmi
caml_builtin_exceptions.cmo : caml_builtin_exceptions.cmi
caml_builtin_exceptions.cmx : caml_builtin_exceptions.cmi
caml_exceptions.cmo : caml_builtin_exceptions.cmi caml_exceptions.cmi
Expand Down Expand Up @@ -79,14 +79,14 @@ js_error.cmo :
js_error.cmx :
typed_array.cmo :
typed_array.cmx :
block.cmo : block.cmi
block.cmj : block.cmi
caml_array.cmo : js.cmo caml_array.cmi
caml_array.cmj : js.cmj caml_array.cmi
caml_backtrace.cmo : caml_backtrace.cmi
caml_backtrace.cmj : caml_backtrace.cmi
caml_bigarray.cmo : caml_bigarray.cmi
caml_bigarray.cmj : caml_bigarray.cmi
caml_block.cmo : caml_block.cmi
caml_block.cmj : caml_block.cmi
caml_builtin_exceptions.cmo : caml_builtin_exceptions.cmi
caml_builtin_exceptions.cmj : caml_builtin_exceptions.cmi
caml_exceptions.cmo : caml_builtin_exceptions.cmi caml_exceptions.cmi
Expand Down
11 changes: 11 additions & 0 deletions jscomp/runtime/block.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Generated CODE, PLEASE EDIT WITH CARE
'use strict';


function __(tag, block) {
block.tag = tag;
return block;
}

exports.__ = __;
/* No side effect */
2 changes: 1 addition & 1 deletion jscomp/runtime/caml_block.ml → jscomp/runtime/block.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@

(* Note that when we introduce it in {!Js_dump}
we need introduce dependency properly *)
let create tag block =
let __ tag block =
Obj.set_tag block tag; block
3 changes: 2 additions & 1 deletion jscomp/runtime/caml_block.mli → jscomp/runtime/block.mli
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@

(* Author: Hongbo Zhang *)

val create : int -> Obj.t -> Obj.t

val __ : int -> Obj.t -> Obj.t
7 changes: 2 additions & 5 deletions jscomp/runtime/caml_obj.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
'use strict';

var Caml_builtin_exceptions = require("./caml_builtin_exceptions");
var Block = require("./block");

function caml_obj_dup(x) {
var len = x.length;
Expand Down Expand Up @@ -36,11 +37,7 @@ function caml_obj_truncate(x, new_size) {
}

function caml_lazy_make_forward(x) {
return {
0: x,
length: 1,
tag: 250
};
return Block.__(250, [x]);
}

function caml_update_dummy(x, y) {
Expand Down
3 changes: 2 additions & 1 deletion jscomp/runtime/runtime.mllib
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ caml_utils
caml_sys
caml_io
caml_float
caml_block

caml_lexer
caml_parser
caml_primitive
Expand All @@ -29,3 +29,4 @@ fn
js_error
caml_curry
curry
block
Loading