Skip to content
This repository was archived by the owner on Jul 31, 2018. It is now read-only.

Commit 05e3309

Browse files
tilkIgnoredAmbience
authored andcommitted
Nicer handling of eval, closer to ES6.
1 parent c8b4be6 commit 05e3309

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

coq/JsCorrectness.v

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3165,9 +3165,11 @@ Proof.
31653165
M vthis = o ->
31663166
red_expr S0 C (expr_call_5 l is_eval_direct vs (out_ter S3 vthis)) o).
31673167
clear HR S o. introv HR. subst M.
3168-
case_if.
3169-
subst. applys red_expr_call_5_eval. applys* run_eval_correct.
3170-
applys* red_expr_call_5_not_eval. apply* IH.
3168+
case_if as a.
3169+
destruct a as (a1&a2). apply bool_eq_true in a2. rewrite a2. subst_hyp a1.
3170+
applys red_expr_call_5_eval. applys* run_eval_correct.
3171+
applys* red_expr_call_5_not_eval. rew_logic in *. rew_reflect. eassumption.
3172+
apply* IH.
31713173
clear EQM.
31723174
subst. destruct rv; tryfalse.
31733175
applys* red_expr_call_4_not_ref.
@@ -4991,7 +4993,8 @@ Proof.
49914993
(* prealloc_global *)
49924994
discriminate.
49934995
(* prealloc_global_eval *)
4994-
discriminate.
4996+
apply red_spec_call_prealloc_global_eval.
4997+
applys* run_eval_correct.
49954998
(* prealloc_global_parse_int *)
49964999
discriminate.
49975000
(* prealloc_global_parse_float *)

coq/JsInterpreter.v

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,8 +2083,8 @@ Definition run_expr_call runs S C e1 e2s : result :=
20832083
*)
20842084
ifb (is_callable S3 l) then
20852085
'let follow := fun vthis =>
2086-
ifb l = prealloc_global_eval then
2087-
run_eval runs S3 C is_eval_direct vs
2086+
ifb l = prealloc_global_eval /\ is_eval_direct then
2087+
run_eval runs S3 C true vs
20882088
else runs_type_call runs S3 C l vthis vs in
20892089
match rv with
20902090
| resvalue_value v => follow undef
@@ -2638,6 +2638,9 @@ Definition run_array_join_elements runs S C l (k length : int) (sep : string) sR
26382638
Definition run_call_prealloc runs S C B vthis (args : list value) : result :=
26392639
match B with
26402640

2641+
| prealloc_global_eval =>
2642+
run_eval runs S C false args
2643+
26412644
| prealloc_global_is_nan =>
26422645
'let v := get_arg 0 args in
26432646
if_number (to_number runs S C v) (fun S0 n =>

coq/JsPrettyRules.v

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,12 +1050,12 @@ with red_expr : state -> execution_ctx -> ext_expr -> out -> Prop :=
10501050
red_expr S C (expr_call_5 l is_eval_direct vs (out_ter S undef)) o ->
10511051
red_expr S C (expr_call_4 (resvalue_value v) l is_eval_direct vs) o
10521052

1053-
| red_expr_call_5_eval : forall S0 S C is_eval_direct vs v o, (* Step 8, special for eval *)
1054-
red_expr S C (spec_call_global_eval is_eval_direct vs) o ->
1055-
red_expr S0 C (expr_call_5 prealloc_global_eval is_eval_direct vs (out_ter S v)) o
1053+
| red_expr_call_5_eval : forall S0 S C vs v o, (* Step 8, special for eval *)
1054+
red_expr S C (spec_call_global_eval true vs) o ->
1055+
red_expr S0 C (expr_call_5 prealloc_global_eval true vs (out_ter S v)) o
10561056

10571057
| red_expr_call_5_not_eval : forall S0 S C l is_eval_direct vs v o, (* Step 8 *)
1058-
l <> prealloc_global_eval ->
1058+
l <> prealloc_global_eval \/ !is_eval_direct ->
10591059
red_expr S C (spec_call l v vs) o ->
10601060
red_expr S0 C (expr_call_5 l is_eval_direct vs (out_ter S v)) o
10611061

@@ -3278,6 +3278,12 @@ with red_expr : state -> execution_ctx -> ext_expr -> out -> Prop :=
32783278
(*------------------------------------------------------------*)
32793279
(** ** Global object builtin functions (15.1) *)
32803280

3281+
(** Calling eval as a function *)
3282+
3283+
| red_spec_call_prealloc_global_eval : forall S C o vthis args,
3284+
red_expr S C (spec_call_global_eval false args) o ->
3285+
red_expr S C (spec_call_prealloc prealloc_global_eval vthis args) o
3286+
32813287
(** Eval (returns value) (15.1.2) *)
32823288

32833289
| red_spec_call_global_eval : forall S C bdirect args v o,

0 commit comments

Comments
 (0)