]> Repositorios git - scryer-prolog.git/commitdiff
add halt/0
authorMark Thom <[email protected]>
Sun, 17 Mar 2019 20:38:55 +0000 (14:38 -0600)
committerMark Thom <[email protected]>
Sun, 17 Mar 2019 20:38:55 +0000 (14:38 -0600)
README.md
src/prolog/clause_types.rs
src/prolog/lib/builtins.pl
src/prolog/machine/system_calls.rs

index 007b7edf8513d15ce3ba9f7c4ce067e75017e609..4b1a69e62841e1b79685d62eba58926fcbf61d3e 100644 (file)
--- a/README.md
+++ b/README.md
@@ -174,6 +174,7 @@ The following predicates are built-in to Scryer.
 * `gen_nat/1`
 * `goal_expansion/2`
 * `ground/1`
+* `halt/0`
 * `integer/1`
 * `is_list/1`
 * `is_partial_string/1`
index 8e4ee2a6450bedf49e89aca56ff69ffed3b07655..dc5f78b57e82e5bf91faca9352bc943530364221 100644 (file)
@@ -160,6 +160,7 @@ pub enum SystemClauseType {
     GetClause,
     GetCurrentPredicateList,
     GetModuleClause,
+    Halt,
     ModuleHeadIsDynamic,
     GetLiftedHeapFromOffset,
     GetLiftedHeapFromOffsetDiff,
@@ -234,6 +235,7 @@ impl SystemClauseType {
             &SystemClauseType::GetDoubleQuotes => clause_name!("$get_double_quotes"),
             &SystemClauseType::GetModuleClause => clause_name!("$get_module_clause"),
             &SystemClauseType::GetSCCCleaner => clause_name!("$get_scc_cleaner"),
+            &SystemClauseType::Halt => clause_name!("$halt"),
             &SystemClauseType::HeadIsDynamic => clause_name!("$head_is_dynamic"),
             &SystemClauseType::InstallSCCCleaner => clause_name!("$install_scc_cleaner"),
             &SystemClauseType::InstallInferenceCounter => clause_name!("$install_inference_counter"),
@@ -302,6 +304,7 @@ impl SystemClauseType {
             ("$get_lh_from_offset_diff", 3) => Some(SystemClauseType::GetLiftedHeapFromOffsetDiff),
             ("$get_double_quotes", 1) => Some(SystemClauseType::GetDoubleQuotes),
             ("$get_scc_cleaner", 1) => Some(SystemClauseType::GetSCCCleaner),
+            ("$halt", 0) => Some(SystemClauseType::Halt),
             ("$head_is_dynamic", 1) => Some(SystemClauseType::HeadIsDynamic),
             ("$install_scc_cleaner", 2) => Some(SystemClauseType::InstallSCCCleaner),
             ("$install_inference_counter", 3) => Some(SystemClauseType::InstallInferenceCounter),
index 91b693da4e4aceacde9ff63832646caa12c1a97c..52fd1a7ab94cd4e397d430c8c9d031d63bed3098 100644 (file)
@@ -9,8 +9,8 @@
        assertz/1, bagof/3, bb_b_put/2, bb_get/2, bb_put/2,
        call_cleanup/2, call_with_inference_limit/3, catch/3,
        clause/2, current_predicate/1, current_prolog_flag/2,
-       expand_goal/2, expand_term/2, findall/3, findall/4, once/1,
-       repeat/0, retract/1, set_prolog_flag/2, setof/3,
+       expand_goal/2, expand_term/2, findall/3, findall/4, halt/0,
+       once/1, repeat/0, retract/1, set_prolog_flag/2, setof/3,
        setup_call_cleanup/3, term_variables/2, throw/1, true/0,
        false/0, write/1, write_canonical/1, writeq/1, write_term/2]).
 
@@ -753,3 +753,5 @@ reset_global_var_at_key(Key) :- '$reset_global_var_at_key'(Key).
 
 bb_get(Key, Value) :- atom(Key), !, '$fetch_global_var'(Key, Value).
 bb_get(Key, _) :- throw(error(type_error(atom, Key), bb_get/2)).
+
+halt :- '$halt'.
index ebce8f23f1a08aedf530774507b4665d3de13349..25ab0fa21bc152fcb4bbe0b2ba6e1332de24eabb 100644 (file)
@@ -628,6 +628,8 @@ impl MachineState {
 
                 self.fail = true;
             },
+            &SystemClauseType::Halt =>
+                std::process::exit(0),
             &SystemClauseType::InstallSCCCleaner => {
                 let addr = self[temp_v!(1)].clone();
                 let b = self.b;