ref: 0cf3816c9419954317fd54da5a063615402bf1d1
parent: b1f62daf95818858863af0cfe7138a0acac751b2
author: Peter Mikkelsen <peter@pmikkelsen.com>
date: Thu Jul 22 12:58:42 EDT 2021
Actually load repl.pl with the prolog loader, and handle module directives
--- a/builtins.c
+++ b/builtins.c
@@ -68,6 +68,7 @@
BuiltinProto(builtinsetstreamposition);
BuiltinProto(builtinop);
BuiltinProto(builtincurrentops);
+BuiltinProto(builtinnewemptymodule);
int compareterms(Term *, Term *);
@@ -193,6 +194,8 @@
return builtinop;
if(Match(L"current_ops", 1))
return builtincurrentops;
+ if(Match(L"$new_empty_module", 1))
+ return builtinnewemptymodule;
return nil;
}
@@ -1164,7 +1167,7 @@
p->builtin = 0;
p->dynamic = 1;
p->next = nil;
- module->predicates = appendpredicate(module->predicates, p);
+ module->predicates = appendpredicate(p, module->predicates);
return 1;
}
@@ -1631,4 +1634,14 @@
Term *realops = mklist(oplist);
return unify(ops, realops, bindings);
+}
+
+int
+builtinnewemptymodule(Term *goal, Binding **bindings, Module *module)
+{
+ USED(bindings);
+ USED(module);
+ Rune *name = goal->children->text;
+ addemptymodule(name);
+ return 1;
}
\ No newline at end of file
--- a/loader.pl
+++ b/loader.pl
@@ -65,6 +65,10 @@
close(S).
handle_directive(ensure_loaded(F), Module, Module) :-
ensure_load(F).
+handle_directive(module(NewModule, Exports), Module, NewModule) :-
+ is_atom(NewModule),
+ '$new_empty_module'(NewModule).
+ % Do something about the exports as well.
handle_directive(D, Module, Module) :-
write('Cannot handle directive: '),
write(D),
@@ -75,5 +79,5 @@
ensure_load(F) :-
( ensure_loads(F)
-> true
- ; asserta(ensure_loads(F)), load_module_from_file(F)
+ ; loader:asserta(ensure_loads(F)), load_module_from_file(F)
).
--- a/module.c
+++ b/module.c
@@ -21,7 +21,6 @@
}
usermodule = addemptymodule(L"user");
- parsemodule("/sys/lib/prolog/repl.pl");
parsemodule("/sys/lib/prolog/loader.pl");
}