Absent any deep overhauls to syntax or constant-handling, hack in the ability to project a cexp var binding to a token in the parser. Use it in comp/rustc.rc and comp/lib/llvm.rs.

This commit is contained in:
Graydon Hoare 2010-08-16 13:02:46 -07:00
parent 176899a970
commit 7e62aa6801
5 changed files with 61 additions and 21 deletions

View file

@ -310,7 +310,7 @@ type cdir =
| CDIR_mod of (Ast.ident * Ast.mod_item) | CDIR_mod of (Ast.ident * Ast.mod_item)
| CDIR_auth of auth | CDIR_auth of auth
type env = { env_bindings: (Ast.ident * pval) list; type env = { env_bindings: ((Ast.ident * pval) list) ref;
env_prefix: filename list; env_prefix: filename list;
env_items: (filename, Ast.mod_items) Hashtbl.t; env_items: (filename, Ast.mod_items) Hashtbl.t;
env_files: (node_id,filename) Hashtbl.t; env_files: (node_id,filename) Hashtbl.t;
@ -357,10 +357,11 @@ and eval_cexp (env:env) (exp:cexp) : cdir array =
| CEXP_let {node=cl} -> | CEXP_let {node=cl} ->
let ident = cl.let_ident in let ident = cl.let_ident in
let v = eval_pexp env cl.let_value in let v = eval_pexp env cl.let_value in
let env = { env with let old_bindings = !(env.env_bindings) in
env_bindings = ((ident,v)::env.env_bindings ) } env.env_bindings := (ident,v)::old_bindings;
in let res = eval_cexps env cl.let_body in
eval_cexps env cl.let_body env.env_bindings := old_bindings;
res
| CEXP_src_mod {node=s; id=id} -> | CEXP_src_mod {node=s; id=id} ->
let name = s.src_ident in let name = s.src_ident in
@ -381,6 +382,7 @@ and eval_cexp (env:env) (exp:cexp) : cdir array =
ps.pstate_opaque_id ps.pstate_opaque_id
ps.pstate_sess ps.pstate_sess
ps.pstate_get_mod ps.pstate_get_mod
ps.pstate_get_cenv_tok
ps.pstate_infer_lib_name ps.pstate_infer_lib_name
env.env_required env.env_required
env.env_required_syms env.env_required_syms
@ -518,7 +520,7 @@ and eval_pexp (env:env) (exp:Pexp.pexp) : pval =
| Pexp.PEXP_lval (Pexp.PLVAL_ident ident) -> | Pexp.PEXP_lval (Pexp.PLVAL_ident ident) ->
begin begin
match ltab_search env.env_bindings ident with match ltab_search !(env.env_bindings) ident with
None -> raise (err (Printf.sprintf "no binding for '%s' found" None -> raise (err (Printf.sprintf "no binding for '%s' found"
ident) env.env_ps) ident) env.env_ps)
| Some v -> v | Some v -> v
@ -622,11 +624,6 @@ let parse_crate_file
let oref = ref (Opaque 0) in let oref = ref (Opaque 0) in
let required = Hashtbl.create 4 in let required = Hashtbl.create 4 in
let required_syms = Hashtbl.create 4 in let required_syms = Hashtbl.create 4 in
let ps =
make_parser tref nref oref sess get_mod
infer_lib_name required required_syms fname
in
let files = Hashtbl.create 0 in let files = Hashtbl.create 0 in
let items = Hashtbl.create 4 in let items = Hashtbl.create 4 in
let target_bindings = let target_bindings =
@ -648,11 +645,23 @@ let parse_crate_file
("build_input", PVAL_str fname); ("build_input", PVAL_str fname);
] ]
in in
let initial_bindings = let bindings =
target_bindings ref (target_bindings
@ build_bindings @ build_bindings)
in in
let env = { env_bindings = initial_bindings; let get_cenv_tok ps ident =
match ltab_search (!bindings) ident with
None -> raise (err (Printf.sprintf "no binding for '%s' found"
ident) ps)
| Some (PVAL_bool b) -> LIT_BOOL b
| Some (PVAL_str s) -> LIT_STR s
| Some (PVAL_num n) -> LIT_INT n
in
let ps =
make_parser tref nref oref sess get_mod get_cenv_tok
infer_lib_name required required_syms fname
in
let env = { env_bindings = bindings;
env_prefix = [Filename.dirname fname]; env_prefix = [Filename.dirname fname];
env_items = Hashtbl.create 0; env_items = Hashtbl.create 0;
env_files = files; env_files = files;
@ -720,8 +729,12 @@ let parse_src_file
let oref = ref (Opaque 0) in let oref = ref (Opaque 0) in
let required = Hashtbl.create 0 in let required = Hashtbl.create 0 in
let required_syms = Hashtbl.create 0 in let required_syms = Hashtbl.create 0 in
let get_cenv_tok ps ident =
raise (err (Printf.sprintf "no binding for '%s' found"
ident) ps)
in
let ps = let ps =
make_parser tref nref oref sess get_mod make_parser tref nref oref sess get_mod get_cenv_tok
infer_lib_name required required_syms fname infer_lib_name required required_syms fname
in in
with_err_handling sess with_err_handling sess

View file

@ -786,9 +786,17 @@ and parse_mod_item (ps:pstate) : (Ast.ident * Ast.mod_item) =
EQ -> EQ ->
begin begin
bump ps; bump ps;
match peek ps with let do_tok t =
LIT_STR s -> (bump ps; s) bump ps;
| _ -> raise (unexpected ps) match t with
LIT_STR s -> s
| _ -> raise (unexpected ps)
in
match peek ps with
IDENT i ->
do_tok (ps.pstate_get_cenv_tok ps i)
| t ->
do_tok t
end end
| _ -> ps.pstate_infer_lib_name ident | _ -> ps.pstate_infer_lib_name ident
in in

View file

@ -23,6 +23,7 @@ type pstate =
pstate_node_id : node_id ref; pstate_node_id : node_id ref;
pstate_opaque_id : opaque_id ref; pstate_opaque_id : opaque_id ref;
pstate_get_mod : get_mod_fn; pstate_get_mod : get_mod_fn;
pstate_get_cenv_tok : pstate -> Ast.ident -> token;
pstate_infer_lib_name : (Ast.ident -> filename); pstate_infer_lib_name : (Ast.ident -> filename);
pstate_required : (node_id, (required_lib * nabi_conv)) Hashtbl.t; pstate_required : (node_id, (required_lib * nabi_conv)) Hashtbl.t;
pstate_required_syms : (node_id, string) Hashtbl.t; } pstate_required_syms : (node_id, string) Hashtbl.t; }
@ -45,6 +46,7 @@ let make_parser
(oref:opaque_id ref) (oref:opaque_id ref)
(sess:Session.sess) (sess:Session.sess)
(get_mod:get_mod_fn) (get_mod:get_mod_fn)
(get_cenv_tok:pstate -> Ast.ident -> token)
(infer_lib_name:Ast.ident -> filename) (infer_lib_name:Ast.ident -> filename)
(required:(node_id, (required_lib * nabi_conv)) Hashtbl.t) (required:(node_id, (required_lib * nabi_conv)) Hashtbl.t)
(required_syms:(node_id, string) Hashtbl.t) (required_syms:(node_id, string) Hashtbl.t)
@ -68,6 +70,7 @@ let make_parser
pstate_node_id = nref; pstate_node_id = nref;
pstate_opaque_id = oref; pstate_opaque_id = oref;
pstate_get_mod = get_mod; pstate_get_mod = get_mod;
pstate_get_cenv_tok = get_cenv_tok;
pstate_infer_lib_name = infer_lib_name; pstate_infer_lib_name = infer_lib_name;
pstate_required = required; pstate_required = required;
pstate_required_syms = required_syms; } pstate_required_syms = required_syms; }

View file

@ -6,7 +6,7 @@ type LongLong = i64;
type Long = i32; type Long = i32;
type Bool = int; type Bool = int;
native mod llvm = "libLLVM-2.7.so" { native mod llvm = llvm_lib {
type ModuleRef; type ModuleRef;
type ContextRef; type ContextRef;

View file

@ -14,7 +14,23 @@ mod driver {
} }
mod lib { mod lib {
mod llvm; alt (target_os) {
case ("win32") {
let (llvm_lib = "llvm-2.8svn.dll") {
mod llvm;
}
}
case ("macos") {
let (llvm_lib = "libllvm-2.8svn.dylib") {
mod llvm;
}
}
else {
let (llvm_lib = "libllvm-2.8svn.so") {
mod llvm;
}
}
}
} }
// Local Variables: // Local Variables: