@@ -38,6 +38,7 @@ heavy::ContextLocal parse_source_file;
3838
3939heavy::ExternBuiltinSyntax cond_expand;
4040heavy::ExternBuiltinSyntax define;
41+ heavy::ExternBuiltinSyntax define_binding;
4142heavy::ExternBuiltinSyntax define_syntax;
4243heavy::ExternBuiltinSyntax syntax_rules;
4344heavy::ExternBuiltinSyntax syntax_fn;
@@ -133,8 +134,8 @@ mlir::Value quasiquote(OpGen& OG, Pair* P);
133134void op_eval (Context& C, ValueRefs Args);
134135
135136mlir::Value define (OpGen& OG, Pair* P) {
136- Pair* P2 = dyn_cast<Pair>(P->Cdr );
137- Value Id = nullptr ;
137+ Pair* P2 = dyn_cast<Pair>(P->Cdr );
138+ Value Id;
138139
139140 if (!P2)
140141 return OG.SetError (" invalid syntax for define" , P);
@@ -148,6 +149,21 @@ mlir::Value define(OpGen& OG, Pair* P) {
148149 return OG.createDefine (Id, P2, P);
149150}
150151
152+ // Binds a dynamically loaded heavy::ContextLocal.
153+ mlir::Value define_binding (OpGen& OG, Pair* P) {
154+ Pair* P2 = dyn_cast<Pair>(P->Cdr );
155+ Value Name;
156+ Value ExtName;
157+
158+ if (P2) {
159+ Name = P2->Car ;
160+ ExtName = P2->Cdr .car ();
161+ }
162+ if (!P2 || !ExtName || !isa<Symbol>(Name) || !isa<Symbol, String>(ExtName))
163+ return OG.SetError (" invalid syntax for define-binding" , P);
164+ return OG.createExternalBinding (Name, ExtName);
165+ }
166+
151167mlir::Value define_syntax (OpGen& OG, Pair* P) {
152168 Pair* P2 = dyn_cast<Pair>(P->Cdr );
153169 if (!P2) return OG.SetError (" invalid define-syntax syntax" , P);
@@ -1299,6 +1315,7 @@ void HEAVY_BASE_INIT(heavy::Context& Context) {
12991315 Context.DialectRegistry ->insert <heavy::Dialect>();
13001316 // syntax
13011317 HEAVY_BASE_VAR (define) = heavy::builtins::define;
1318+ HEAVY_BASE_VAR (define_binding) = heavy::builtins::define_binding;
13021319 HEAVY_BASE_VAR (define_syntax) = heavy::builtins::define_syntax;
13031320 HEAVY_BASE_VAR (syntax_rules) = heavy::builtins::syntax_rules;
13041321 HEAVY_BASE_VAR (syntax_fn) = heavy::builtins::syntax_fn;
@@ -1322,7 +1339,6 @@ void HEAVY_BASE_INIT(heavy::Context& Context) {
13221339 HEAVY_BASE_VAR (source_loc) = heavy::builtins::source_loc;
13231340 HEAVY_BASE_VAR (source_loc_valid) = heavy::builtins::source_loc_valid;
13241341 HEAVY_BASE_VAR (dump_source_loc) = heavy::builtins::dump_source_loc;
1325- HEAVY_BASE_VAR (parse_source_file).init (Context);
13261342
13271343 // functions
13281344 HEAVY_BASE_VAR (add) = heavy::builtins::add;
@@ -1369,7 +1385,6 @@ void HEAVY_BASE_INIT(heavy::Context& Context) {
13691385 HEAVY_BASE_VAR (eval) = heavy::builtins::eval;
13701386 HEAVY_BASE_VAR (op_eval) = heavy::builtins::op_eval;
13711387 HEAVY_BASE_VAR (compile) = heavy::builtins::compile;
1372- HEAVY_BASE_VAR (module_path).init (Context);
13731388
13741389 HEAVY_BASE_VAR (is_boolean) = heavy::builtins::is_boolean;
13751390 HEAVY_BASE_VAR (is_bytevector) = heavy::builtins::is_bytevector;
@@ -1399,6 +1414,8 @@ void HEAVY_BASE_LOAD_MODULE(heavy::Context& Context) {
13991414 heavy::initModuleNames (Context, HEAVY_BASE_LIB_STR, {
14001415 // syntax
14011416 {" define" , HEAVY_BASE_VAR (define)},
1417+ {" define-binding" ,
1418+ HEAVY_BASE_VAR (define_binding)},
14021419 {" define-syntax" , HEAVY_BASE_VAR (define_syntax)},
14031420 {" if" , HEAVY_BASE_VAR (if_)},
14041421 {" lambda" , HEAVY_BASE_VAR (lambda)},
0 commit comments