From 155645307a16155e2b0d6399c19c1ba459048e5d Mon Sep 17 00:00:00 2001 From: Stephan Renatus Date: Mon, 6 Apr 2020 17:35:21 +0200 Subject: [PATCH] use partial strings for passing argv to toplevel.pl In run_top_level: rename variables, make them partial strings The rename is mostly cosmetic: all of argv is passed, and if argv contains flags, goals, etc, it's more than filenames. Using partial strings instead of atom came from discussions about how to pass goals in the CLI, and can thus be considered preliminary work for that. In toplevel.pl: convert partial string to atom before passing it to `use_module`. Signed-off-by: Stephan Renatus --- src/prolog/machine/mod.rs | 21 +++++++-------------- src/prolog/toplevel.pl | 9 +++++---- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/prolog/machine/mod.rs b/src/prolog/machine/mod.rs index 06d80ba1..8b1da483 100644 --- a/src/prolog/machine/mod.rs +++ b/src/prolog/machine/mod.rs @@ -336,23 +336,16 @@ impl Machine { } pub fn run_top_level(&mut self) { - use std::env; + use std::env; - let mut filename_atoms = vec![]; - - // the first of these is the path to the scryer-prolog executable, so skip - // it. - for filename in env::args().skip(1) { - let atom = clause_name!(filename, self.indices.atom_tbl); - filename_atoms.push(HeapCellValue::Atom(atom, None)); - } - - let list_addr = - Addr::HeapCell(self.machine_st.heap.to_list(filename_atoms.into_iter())); + let mut arg_pstrs = vec![]; + for arg in env::args() { + arg_pstrs.push(self.machine_st.heap.put_complete_string(&arg)); + } + let list_addr = Addr::HeapCell(self.machine_st.heap.to_list(arg_pstrs.into_iter())); - self.machine_st[temp_v!(1)] = list_addr; + self.machine_st[temp_v!(1)] = list_addr; self.machine_st.p = CodePtr::Local(LocalCodePtr::DirEntry(self.toplevel_idx)); - self.run_query(); } diff --git a/src/prolog/toplevel.pl b/src/prolog/toplevel.pl index 4f037c9a..c2aa20f3 100644 --- a/src/prolog/toplevel.pl +++ b/src/prolog/toplevel.pl @@ -3,13 +3,14 @@ :- module('$toplevel', ['$repl'/1, consult/1, use_module/1, use_module/2]). -'$repl'(ListOfModules) :- - maplist('$use_list_of_modules', ListOfModules), +'$repl'([_|Args]) :- + maplist('$use_list_of_modules', Args), false. '$repl'(_) :- '$repl'. -'$use_list_of_modules'(Module) :- - catch(use_module(Module), E, '$print_exception'(E)). +'$use_list_of_modules'(Mod0) :- + atom_chars(Mod, Mod0), + catch(use_module(Mod), E, '$print_exception'(E)). '$repl' :- catch('$read_and_match', E, '$print_exception'(E)), -- 2.54.0