remove $reify_switch

This commit is contained in:
Mark Thom
2019-04-05 09:04:05 -06:00
parent 6dade1b917
commit 03f2190d6b
5 changed files with 6 additions and 57 deletions

View File

@@ -1,6 +1,6 @@
[package]
name = "scryer-prolog"
version = "0.8.40"
version = "0.8.41"
authors = ["Mark Thom <markjordanthom@gmail.com>"]
repository = "https://github.com/mthom/scryer-prolog"
description = "A modern Prolog implementation written mostly in Rust."

View File

@@ -129,7 +129,6 @@ ref_thread_local! {
m.insert(("\\==", 2), ClauseType::BuiltIn(BuiltInClauseType::NotEq));
m.insert(("partial_string", 2), ClauseType::BuiltIn(BuiltInClauseType::PartialString));
m.insert(("read", 1), ClauseType::BuiltIn(BuiltInClauseType::Read));
m.insert(("$reify_switch", 3), ClauseType::BuiltIn(BuiltInClauseType::ReifySwitch));
m.insert(("sort", 2), ClauseType::BuiltIn(BuiltInClauseType::Sort));
m
@@ -391,7 +390,6 @@ pub enum BuiltInClauseType {
NotEq,
PartialString,
Read,
ReifySwitch,
Sort,
}
@@ -424,7 +422,6 @@ impl BuiltInClauseType {
&BuiltInClauseType::NotEq => clause_name!("\\=="),
&BuiltInClauseType::PartialString => clause_name!("partial_string"),
&BuiltInClauseType::Read => clause_name!("read"),
&BuiltInClauseType::ReifySwitch => clause_name!("$reify_switch"),
&BuiltInClauseType::Sort => clause_name!("sort"),
}
}
@@ -446,7 +443,6 @@ impl BuiltInClauseType {
&BuiltInClauseType::Nl => 0,
&BuiltInClauseType::PartialString => 1,
&BuiltInClauseType::Read => 1,
&BuiltInClauseType::ReifySwitch => 3,
&BuiltInClauseType::Sort => 2,
}
}

View File

@@ -4,18 +4,13 @@
:- use_module(library(dif)).
/* in essence, '$reify_switch'(T, Then_0, Else_0) is semantically this,
( T == true -> call(Then_0)
if_(If_1, Then_0, Else_0) :-
call(If_1, T),
( T == true -> call(Then_0)
; T == false -> call(Else_0)
; nonvar(T) -> throw(error(type_error(boolean, T), _))
; throw(error(instantiation_error, _))
).
but it does not create choice points.
*/
if_(If_1, Then_0, Else_0) :-
call(If_1, T),
'$call_with_default_policy'('$reify_switch'(T, Then_0, Else_0)).
=(X, Y, T) :-
( X == Y -> T = true

View File

@@ -169,7 +169,7 @@ impl PermissionError {
pub enum ValidType {
Atom,
Atomic,
Boolean,
// Boolean,
// Byte,
Callable,
// Character,
@@ -190,7 +190,7 @@ impl ValidType {
match self {
ValidType::Atom => "atom",
ValidType::Atomic => "atomic",
ValidType::Boolean => "boolean",
// ValidType::Boolean => "boolean",
// ValidType::Byte => "byte",
ValidType::Callable => "callable",
// ValidType::Character => "character",

View File

@@ -589,48 +589,6 @@ pub(crate) trait CallPolicy: Any {
return_from_clause!(machine_st.last_call, machine_st)
},
&BuiltInClauseType::ReifySwitch => {
let truth_value = machine_st[temp_v!(1)].clone();
let truth_value = machine_st.store(machine_st.deref(truth_value));
match truth_value {
Addr::Con(Constant::Atom(atom, spec)) =>
match atom.as_str() {
"true" => {
let t_branch = machine_st[temp_v!(2)].clone();
machine_st[temp_v!(1)] = t_branch;
self.call_n(machine_st, 1, indices)
},
"false" => {
let f_branch = machine_st[temp_v!(3)].clone();
machine_st[temp_v!(1)] = f_branch;
self.call_n(machine_st, 1, indices)
}
_ => {
let truth_value = Addr::Con(Constant::Atom(atom, spec));
let stub = MachineError::functor_stub(clause_name!("if_"), 3);
let err = MachineError::type_error(ValidType::Boolean, truth_value);
Err(machine_st.error_form(err, stub))
}
},
ref addr if addr.is_ref() => {
let stub = MachineError::functor_stub(clause_name!("if_"), 3);
let err = MachineError::instantiation_error();
Err(machine_st.error_form(err, stub))
},
addr => {
let stub = MachineError::functor_stub(clause_name!("if_"), 3);
let err = MachineError::type_error(ValidType::Boolean, addr);
Err(machine_st.error_form(err, stub))
}
}
},
&BuiltInClauseType::CopyTerm => {
machine_st.copy_term();
return_from_clause!(machine_st.last_call, machine_st)