@@ -310,7 +310,7 @@ type cdir =
310
310
| CDIR_mod of (Ast .ident * Ast .mod_item )
311
311
| CDIR_auth of auth
312
312
313
- type env = { env_bindings : (Ast .ident * pval ) list ;
313
+ type env = { env_bindings : (( Ast .ident * pval ) list ) ref ;
314
314
env_prefix : filename list ;
315
315
env_items : (filename , Ast .mod_items ) Hashtbl .t ;
316
316
env_files : (node_id ,filename) Hashtbl .t ;
@@ -357,10 +357,11 @@ and eval_cexp (env:env) (exp:cexp) : cdir array =
357
357
| CEXP_let {node =cl } ->
358
358
let ident = cl.let_ident in
359
359
let v = eval_pexp env cl.let_value in
360
- let env = { env with
361
- env_bindings = ((ident,v)::env.env_bindings ) }
362
- in
363
- eval_cexps env cl.let_body
360
+ let old_bindings = ! (env.env_bindings) in
361
+ env.env_bindings := (ident,v)::old_bindings;
362
+ let res = eval_cexps env cl.let_body in
363
+ env.env_bindings := old_bindings;
364
+ res
364
365
365
366
| CEXP_src_mod {node =s ; id =id } ->
366
367
let name = s.src_ident in
@@ -381,6 +382,7 @@ and eval_cexp (env:env) (exp:cexp) : cdir array =
381
382
ps.pstate_opaque_id
382
383
ps.pstate_sess
383
384
ps.pstate_get_mod
385
+ ps.pstate_get_cenv_tok
384
386
ps.pstate_infer_lib_name
385
387
env.env_required
386
388
env.env_required_syms
@@ -518,7 +520,7 @@ and eval_pexp (env:env) (exp:Pexp.pexp) : pval =
518
520
519
521
| Pexp. PEXP_lval (Pexp. PLVAL_ident ident ) ->
520
522
begin
521
- match ltab_search env.env_bindings ident with
523
+ match ltab_search ! ( env.env_bindings) ident with
522
524
None -> raise (err (Printf. sprintf " no binding for '%s' found"
523
525
ident) env.env_ps)
524
526
| Some v -> v
@@ -622,11 +624,6 @@ let parse_crate_file
622
624
let oref = ref (Opaque 0 ) in
623
625
let required = Hashtbl. create 4 in
624
626
let required_syms = Hashtbl. create 4 in
625
- let ps =
626
- make_parser tref nref oref sess get_mod
627
- infer_lib_name required required_syms fname
628
- in
629
-
630
627
let files = Hashtbl. create 0 in
631
628
let items = Hashtbl. create 4 in
632
629
let target_bindings =
@@ -648,11 +645,23 @@ let parse_crate_file
648
645
(" build_input" , PVAL_str fname);
649
646
]
650
647
in
651
- let initial_bindings =
652
- target_bindings
653
- @ build_bindings
648
+ let bindings =
649
+ ref ( target_bindings
650
+ @ build_bindings)
654
651
in
655
- let env = { env_bindings = initial_bindings;
652
+ let get_cenv_tok ps ident =
653
+ match ltab_search (! bindings) ident with
654
+ None -> raise (err (Printf. sprintf " no binding for '%s' found"
655
+ ident) ps)
656
+ | Some (PVAL_bool b ) -> LIT_BOOL b
657
+ | Some (PVAL_str s ) -> LIT_STR s
658
+ | Some (PVAL_num n ) -> LIT_INT n
659
+ in
660
+ let ps =
661
+ make_parser tref nref oref sess get_mod get_cenv_tok
662
+ infer_lib_name required required_syms fname
663
+ in
664
+ let env = { env_bindings = bindings;
656
665
env_prefix = [Filename. dirname fname];
657
666
env_items = Hashtbl. create 0 ;
658
667
env_files = files;
@@ -720,8 +729,12 @@ let parse_src_file
720
729
let oref = ref (Opaque 0 ) in
721
730
let required = Hashtbl. create 0 in
722
731
let required_syms = Hashtbl. create 0 in
732
+ let get_cenv_tok ps ident =
733
+ raise (err (Printf. sprintf " no binding for '%s' found"
734
+ ident) ps)
735
+ in
723
736
let ps =
724
- make_parser tref nref oref sess get_mod
737
+ make_parser tref nref oref sess get_mod get_cenv_tok
725
738
infer_lib_name required required_syms fname
726
739
in
727
740
with_err_handling sess
0 commit comments