Skip to content

fix && || tail call, it generates some large expressions (Fix #50) #73

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

Merged
merged 1 commit into from
Feb 4, 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
11 changes: 8 additions & 3 deletions jscomp/js_output.ml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ let of_block ?value ?(finished = False) block =

let dummy = {value = None; block = []; finished = Dummy }

let handle_name_tail (name : st) (should_return : Lam_compile_defs.return_type)
let handle_name_tail
(name : st)
(should_return : Lam_compile_defs.return_type)
lam (exp : J.expression) : t =
begin match name, should_return with
| EffectCall, False ->
Expand All @@ -66,10 +68,13 @@ let handle_name_tail (name : st) (should_return : Lam_compile_defs.return_type)
| NeedValue, _ -> {block = []; value = Some exp; finished = False }
end

let handle_block_return (st : st) (should_return : Lam_compile_defs.return_type) (lam : Lambda.lambda) (block : J.block) exp : t =
let handle_block_return
(st : st)
(should_return : Lam_compile_defs.return_type)
(lam : Lambda.lambda) (block : J.block) exp : t =
match st, should_return with
| Declare (kind,n), False ->
make (block @ [ S.define ~kind n exp])
make (block @ [ S.define ~kind n exp])
| Assign n, False -> make (block @ [S.assign n exp])
| (Declare _ | Assign _), True _ -> make [S.unknown_lambda lam] ~finished:True
| EffectCall, False -> make block ~value:exp
Expand Down
1 change: 1 addition & 0 deletions jscomp/lam_analysis.ml
Original file line number Diff line number Diff line change
Expand Up @@ -454,3 +454,4 @@ let is_closed_by set lam =

let is_closed lam =
Ident_map.is_empty (free_variables Ident_set.empty Ident_map.empty lam)

2 changes: 2 additions & 0 deletions jscomp/lam_analysis.mli
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ val free_variables : Ident_set.t -> stats Ident_map.t -> Lambda.lambda -> stats

val small_inline_size : int
val exit_inline_size : int


47 changes: 47 additions & 0 deletions jscomp/lam_compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,53 @@ and
*)
| {value = None; _} -> assert false
end
| Lprim(Psequand , [l;r] )
->
begin match cxt with
| {should_return = True _ }
(* Invariant: if [should_return], then [st] will not be [NeedValue] *)
->
compile_lambda cxt (Lifthenelse (l, r, Lam_util.lam_false))
| _ ->
let l_block,l_expr =
match compile_lambda {cxt with st = NeedValue; should_return = False} l with
| {block = a; value = Some b} -> a, b
| _ -> assert false
in
let r_block, r_expr =
match compile_lambda {cxt with st = NeedValue; should_return = False} r with
| {block = a; value = Some b} -> a, b
| _ -> assert false
in
let args_code = l_block @ r_block in
let exp = E.and_ l_expr r_expr in
Js_output.handle_block_return st should_return lam args_code exp
end

| Lprim(Psequor, [l;r])
->
begin match cxt with
| {should_return = True _ }
(* Invariant: if [should_return], then [st] will not be [NeedValue] *)
->
compile_lambda cxt (Lifthenelse (l, Lam_util.lam_true, r))
| _ ->
let l_block,l_expr =
match compile_lambda {cxt with st = NeedValue; should_return = False} l with
| {block = a; value = Some b} -> a, b
| _ -> assert false
in
let r_block, r_expr =
match compile_lambda {cxt with st = NeedValue; should_return = False} r with
| {block = a; value = Some b} -> a, b
| _ -> assert false
in
let args_code = l_block @ r_block in
let exp = E.or_ l_expr r_expr in
Js_output.handle_block_return st should_return lam args_code exp
end


| Lprim (prim, args_lambda) ->
begin
let args_block, args_expr =
Expand Down
5 changes: 5 additions & 0 deletions jscomp/lam_util.ml
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,8 @@ let print_ident_set fmt s =

let mk_apply_info ?(loc = Location.none) apply_status : Lambda.apply_info =
{ apply_loc = loc; apply_status }


let lam_true : Lambda.lambda = Lconst (Const_pointer ( 1, NullConstructor "true"))

let lam_false : Lambda.lambda = Lconst (Const_pointer( 0, NullConstructor "false"))
3 changes: 3 additions & 0 deletions jscomp/lam_util.mli
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@ val ident_set_of_list : Ident.t list -> Ident_set.t
val print_ident_set : Format.formatter -> Ident_set.t -> unit

val mk_apply_info : ?loc:Location.t -> Lambda.apply_status -> Lambda.apply_info

val lam_true : Lambda.lambda
val lam_false : Lambda.lambda
7 changes: 6 additions & 1 deletion jscomp/runtime/caml_string.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,12 @@ function caml_string_of_char_array(chars) {

function caml_is_printable(c) {
var code = c;
return +(code > 31 && code < 127);
if (code > 31) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should improve it later

return +(code < 127);
}
else {
return /* false */0;
}
}

exports.add = add;
Expand Down
7 changes: 6 additions & 1 deletion jscomp/stdlib/camlinternalFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,12 @@ function bprint_char_set(buf, char_set) {
var is_alone = function (c) {
var match_001 = Char.chr(c - 1);
var match_002 = Char.chr(c + 1);
return +(is_in_char_set(set, c) && !(is_in_char_set(set, match_001) && is_in_char_set(set, match_002)));
if (is_in_char_set(set, c)) {
return !(is_in_char_set(set, match_001) && is_in_char_set(set, match_002));
}
else {
return /* false */0;
}
};
if (is_alone(/* "]" */93)) {
buffer_add_char(buf, /* "]" */93);
Expand Down
26 changes: 23 additions & 3 deletions jscomp/stdlib/filename.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,35 @@ function is_dir_sep(s, i) {
}

function is_relative(n) {
return +(n.length < 1 || n.charCodeAt(0) !== /* "/" */47);
if (n.length < 1) {
return /* true */1;
}
else {
return +(n.charCodeAt(0) !== /* "/" */47);
}
}

function is_implicit(n) {
return +(is_relative(n) && (n.length < 2 || $$String.sub(n, 0, 2) !== "./") && (n.length < 3 || $$String.sub(n, 0, 3) !== "../"));
if (is_relative(n) && (n.length < 2 || $$String.sub(n, 0, 2) !== "./")) {
if (n.length < 3) {
return /* true */1;
}
else {
return +($$String.sub(n, 0, 3) !== "../");
}
}
else {
return /* false */0;
}
}

function check_suffix(name, suff) {
return +(name.length >= suff.length && $$String.sub(name, name.length - suff.length, suff.length) === suff);
if (name.length >= suff.length) {
return +($$String.sub(name, name.length - suff.length, suff.length) === suff);
}
else {
return /* false */0;
}
}

var temp_dir_name;
Expand Down
36 changes: 27 additions & 9 deletions jscomp/stdlib/hashtbl.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,15 +361,21 @@ function replace(h, key, info) {
}

function mem(h, key) {
var mem_in_bucket = function (param) {
var _param = h[2][key_index(h, key)];
while(true) {
var param = _param;
if (param) {
return +(Caml_primitive.caml_compare(param[1], key) === 0 || mem_in_bucket(param[3]));
if (Caml_primitive.caml_compare(param[1], key)) {
_param = param[3];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

benefit

}
else {
return /* true */1;
}
}
else {
return /* false */0;
}
};
return mem_in_bucket(h[2][key_index(h, key)]);
}

function iter(f, h) {
Expand Down Expand Up @@ -620,15 +626,21 @@ function MakeSeeded(H) {
}
};
var mem = function (h, key) {
var mem_in_bucket = function (param) {
var _param = h[2][key_index(h, key)];
while(true) {
var param = _param;
if (param) {
return +(H[1](param[1], key) || mem_in_bucket(param[3]));
if (H[1](param[1], key)) {
return /* true */1;
}
else {
_param = param[3];
}
}
else {
return /* false */0;
}
};
return mem_in_bucket(h[2][key_index(h, key)]);
};
return [
0,
Expand Down Expand Up @@ -823,15 +835,21 @@ function Make(H) {
}
};
var mem = function (h, key) {
var mem_in_bucket = function (param) {
var _param = h[2][key_index(h, key)];
while(true) {
var param = _param;
if (param) {
return +(equal(param[1], key) || mem_in_bucket(param[3]));
if (equal(param[1], key)) {
return /* true */1;
}
else {
_param = param[3];
}
}
else {
return /* false */0;
}
};
return mem_in_bucket(h[2][key_index(h, key)]);
};
var create$1 = function (sz) {
return create([
Expand Down
Loading