]> Repositorios git - scryer-prolog.git/commitdiff
include builtins implicitly in every module.
authorMark Thom <[email protected]>
Thu, 5 Jul 2018 05:25:55 +0000 (23:25 -0600)
committerMark Thom <[email protected]>
Thu, 5 Jul 2018 05:25:55 +0000 (23:25 -0600)
src/main.rs
src/prolog/compile.rs
src/prolog/lib/control.pl
src/prolog/lib/lists.pl
src/prolog/lib/queues.pl
src/prolog/machine/mod.rs

index c4c749fef052c3a727cc44788ba54ad674c7fcda..ddc82b101b978a543ff842d2c92f35bb9aa06946 100644 (file)
@@ -32,7 +32,7 @@ fn prolog_repl() {
         match read() {
             Input::Line(line) => parse_and_compile_line(&mut wam, line.as_str()),
             Input::Batch(batch) =>
-                match compile_listing(&mut wam, batch.as_str()) {
+                match compile_user_module(&mut wam, batch.as_str()) {
                     EvalSession::Error(e) => println!("{}", e),
                     _ => {}
                 },
index 50716f5cac929b3292767ccf80c7fef540d36468..35b0c6971763ab615f6acc230205ef4745964fd6 100644 (file)
@@ -180,7 +180,7 @@ impl<'a> ListingCompiler<'a> {
 
             compile_appendix(&mut decl_code, Vec::from(queue))?;
 
-            let idx = code_dir.entry((name, arity)).or_insert(CodeIndex::default());            
+            let idx = code_dir.entry((name, arity)).or_insert(CodeIndex::default());
             set_code_index!(idx, IndexPtr::Index(p), self.get_module_name());
 
             code.extend(decl_code.into_iter());
@@ -193,7 +193,7 @@ impl<'a> ListingCompiler<'a> {
         let code_dir = mem::replace(indices.code_dir, HashMap::new());
         let op_dir   = mem::replace(indices.op_dir, HashMap::new());
 
-        if let Some(mut module) = self.module {
+        if let Some(mut module) = self.module {            
             module.code_dir.extend(as_module_code_dir(code_dir));
             module.op_dir.extend(op_dir.into_iter());
 
@@ -213,8 +213,6 @@ fn use_module(module: &mut Option<Module>, submodule: &Module, indices: &mut Mac
     if let &mut Some(ref mut module) = module {
         module.use_module(submodule);
     }
-
-    // self.wam.use_module_in_toplevel(name);
 }
 
 fn use_qualified_module(module: &mut Option<Module>, submodule: &Module, exports: &Vec<PredicateKey>,
@@ -225,13 +223,11 @@ fn use_qualified_module(module: &mut Option<Module>, submodule: &Module, exports
     if let &mut Some(ref mut module) = module {
         module.use_qualified_module(submodule, exports);
     }
-
-    // self.wam.use_qualified_module_in_toplevel(name, exports);
 }
 
-pub fn compile_listing(wam: &mut Machine, src_str: &str) -> EvalSession {
-    let mut indices = machine_code_index!(&mut CodeDir::new(), &mut default_op_dir());
-
+pub
+fn compile_listing(wam: &mut Machine, src_str: &str, mut indices: MachineCodeIndex) -> EvalSession
+{
     let mut worker   = TopLevelBatchWorker::new(src_str.as_bytes(), wam.atom_tbl());
     let mut compiler = ListingCompiler::new(wam);
 
@@ -266,3 +262,15 @@ pub fn compile_listing(wam: &mut Machine, src_str: &str) -> EvalSession {
 
     EvalSession::EntrySuccess
 }
+
+pub fn compile_user_module(wam: &mut Machine, src_str: &str) -> EvalSession {
+    let mut indices  = machine_code_index!(&mut CodeDir::new(), &mut default_op_dir());
+
+    if let Some(ref builtins) = wam.modules.get(&clause_name!("builtins")) {
+        indices.use_module(builtins);        
+    } else {
+        return EvalSession::from(SessionError::ModuleNotFound);        
+    }
+
+    compile_listing(wam, src_str, indices)
+}
index 4f641e59bcade1b87d1b523d906cda7a350850c5..94090a056c967432a1176eedfa07f26ffdd7eb9a 100644 (file)
@@ -1,5 +1,3 @@
-:- use_module(library(builtins)).
-
 :- module(control, [(\=)/2, (\+)/1, between/3, once/1, repeat/0]).
 
 :- op(900, fy, \+).
index 05725838e53fbdc7564fcc05244eae11322ee5f7..1c5317da4c976a2b22d0d7e0287da3f81869a684 100644 (file)
@@ -1,5 +1,3 @@
-:- use_module(library(builtins)).
-
 :- module(lists, [member/2, select/3, append/3, memberchk/2,
                  reverse/2, length/2, maplist/2, maplist/3,
                  maplist/4, maplist/5, maplist/6, maplist/7,
index f1faf80bb3a847ca576ae7a055f60efa448590b0..1cc1e6c86e16cc74cf101f8b969fc2ae09cf88a7 100644 (file)
@@ -1,5 +1,3 @@
-:- use_module(library(builtins)).
-
 :- module(queues, [queue/1, queue/2, queue_head/3, queue_head_list/3,
                   queue_last/3, queue_last_list/3, list_queue/2,
                   queue_length/2]).
index cac185c9b81aa8ae3fc8014f628e1df1dfb4e389..e42981f037e1cb1dc8faacf1d56e92f0b2d11ce4 100644 (file)
@@ -111,11 +111,12 @@ impl Machine {
             cached_query: None
         };
 
-        compile_listing(&mut wam, BUILTINS);        
+        let indices = machine_code_index!(&mut CodeDir::new(), &mut default_op_dir());
+        compile_listing(&mut wam, BUILTINS, indices);
 
-        compile_listing(&mut wam, LISTS);
-        compile_listing(&mut wam, CONTROL);
-        compile_listing(&mut wam, QUEUES);
+        compile_user_module(&mut wam, LISTS);
+        compile_user_module(&mut wam, CONTROL);
+        compile_user_module(&mut wam, QUEUES);
 
         wam.use_module_in_toplevel(clause_name!("builtins"));