move several builtins to control.

This commit is contained in:
Mark Thom
2018-02-12 18:30:44 -07:00
parent 47055d189d
commit a1fb4f529b
4 changed files with 146 additions and 135 deletions

View File

@@ -821,7 +821,6 @@ pub enum ArithmeticInstruction {
pub enum BuiltInInstruction {
CleanUpBlock,
CompareNumber(CompareNumberQT, ArithmeticTerm, ArithmeticTerm),
EraseBall,
Fail,
GetArgCall,
@@ -829,19 +828,9 @@ pub enum BuiltInInstruction {
GetBall,
GetCurrentBlock,
GetCutPoint(RegType),
DynamicCompareNumber(CompareNumberQT),
DynamicIs,
InstallCleaner,
InstallNewBlock,
InternalCallN,
IsAtomic(RegType),
IsCompound(RegType),
IsFloat(RegType),
IsInteger(RegType),
IsNonVar(RegType),
IsRational(RegType),
IsString(RegType),
IsVar(RegType),
ResetBlock,
RestoreCutPolicy,
SetBall,
@@ -861,11 +850,14 @@ pub enum ControlInstruction {
CatchCall,
CatchExecute,
CheckCpExecute,
CompareNumber(CompareNumberQT, ArithmeticTerm, ArithmeticTerm),
DisplayCall,
DisplayExecute,
Deallocate,
DuplicateTermCall,
DuplicateTermExecute,
DynamicCompareNumber(CompareNumberQT),
DynamicIs,
EqCall,
EqExecute,
Execute(TabledRc<Atom>, usize),
@@ -880,6 +872,14 @@ pub enum ControlInstruction {
JmpByCall(usize, usize), // arity, global_offset.
JmpByExecute(usize, usize),
IsCall(RegType, ArithmeticTerm),
IsAtomic(RegType),
IsCompound(RegType),
IsFloat(RegType),
IsInteger(RegType),
IsNonVar(RegType),
IsRational(RegType),
IsString(RegType),
IsVar(RegType),
IsExecute(RegType, ArithmeticTerm),
NotEqCall,
NotEqExecute,
@@ -896,10 +896,13 @@ impl ControlInstruction {
&ControlInstruction::Call(_, _, _) => true,
&ControlInstruction::CatchCall => true,
&ControlInstruction::CatchExecute => true,
&ControlInstruction::CompareNumber(..) => true,
&ControlInstruction::DisplayCall => true,
&ControlInstruction::DisplayExecute => true,
&ControlInstruction::DuplicateTermCall => true,
&ControlInstruction::DuplicateTermExecute => true,
&ControlInstruction::DynamicCompareNumber(_) => true,
&ControlInstruction::DynamicIs => true,
&ControlInstruction::EqCall => true,
&ControlInstruction::EqExecute => true,
&ControlInstruction::Execute(_, _) => true,
@@ -916,6 +919,14 @@ impl ControlInstruction {
&ControlInstruction::GotoExecute(..) => true,
&ControlInstruction::GroundCall => true,
&ControlInstruction::GroundExecute => true,
&ControlInstruction::IsAtomic(_) => true,
&ControlInstruction::IsCompound(_) => true,
&ControlInstruction::IsFloat(_) => true,
&ControlInstruction::IsInteger(_) => true,
&ControlInstruction::IsNonVar(_) => true,
&ControlInstruction::IsRational(_) => true,
&ControlInstruction::IsString(_) => true,
&ControlInstruction::IsVar(_) => true,
&ControlInstruction::IsCall(..) => true,
&ControlInstruction::IsExecute(..) => true,
&ControlInstruction::JmpByCall(..) => true,

View File

@@ -151,6 +151,24 @@ impl fmt::Display for ControlInstruction {
write!(f, "is_call {}, {}", r, at),
&ControlInstruction::IsExecute(r, ref at) =>
write!(f, "is_execute {}, {}", r, at),
&ControlInstruction::IsAtomic(r) =>
write!(f, "is_atomic {}", r),
&ControlInstruction::IsCompound(r) =>
write!(f, "is_compound {}", r),
&ControlInstruction::IsFloat(r) =>
write!(f, "is_float {}", r),
&ControlInstruction::IsRational(r) =>
write!(f, "is_rational {}", r),
&ControlInstruction::IsNonVar(r) =>
write!(f, "is_non_var {}", r),
&ControlInstruction::IsString(r) =>
write!(f, "is_string {}", r),
&ControlInstruction::IsInteger(r) =>
write!(f, "is_integer {}", r),
&ControlInstruction::DynamicIs =>
write!(f, "call_is"),
&ControlInstruction::IsVar(r) =>
write!(f, "is_var {}", r),
&ControlInstruction::JmpByCall(arity, offset) =>
write!(f, "jmp_by_call {}/{}", offset, arity),
&ControlInstruction::JmpByExecute(arity, offset) =>
@@ -165,6 +183,10 @@ impl fmt::Display for ControlInstruction {
write!(f, "call_throw"),
&ControlInstruction::ThrowExecute =>
write!(f, "execute_throw"),
&ControlInstruction::CompareNumber(cmp, ref at_1, ref at_2) =>
write!(f, "number_test {}, {}, {} ", cmp, at_1, at_2),
&ControlInstruction::DynamicCompareNumber(cmp) =>
write!(f, "dynamic_number_test {}", cmp),
}
}
}
@@ -187,10 +209,6 @@ impl fmt::Display for BuiltInInstruction {
match self {
&BuiltInInstruction::CleanUpBlock =>
write!(f, "clean_up_block"),
&BuiltInInstruction::CompareNumber(cmp, ref at_1, ref at_2) =>
write!(f, "number_test {}, {}, {} ", cmp, at_1, at_2),
&BuiltInInstruction::DynamicCompareNumber(cmp) =>
write!(f, "dynamic_number_test {}", cmp),
&BuiltInInstruction::EraseBall =>
write!(f, "erase_ball"),
&BuiltInInstruction::Fail =>
@@ -211,24 +229,6 @@ impl fmt::Display for BuiltInInstruction {
write!(f, "install_new_block"),
&BuiltInInstruction::InternalCallN =>
write!(f, "internal_call_N"),
&BuiltInInstruction::IsAtomic(r) =>
write!(f, "is_atomic {}", r),
&BuiltInInstruction::IsCompound(r) =>
write!(f, "is_compound {}", r),
&BuiltInInstruction::IsFloat(r) =>
write!(f, "is_float {}", r),
&BuiltInInstruction::IsRational(r) =>
write!(f, "is_rational {}", r),
&BuiltInInstruction::IsNonVar(r) =>
write!(f, "is_non_var {}", r),
&BuiltInInstruction::IsString(r) =>
write!(f, "is_string {}", r),
&BuiltInInstruction::IsInteger(r) =>
write!(f, "is_integer {}", r),
&BuiltInInstruction::DynamicIs =>
write!(f, "call_is"),
&BuiltInInstruction::IsVar(r) =>
write!(f, "is_var {}", r),
&BuiltInInstruction::ResetBlock =>
write!(f, "reset_block"),
&BuiltInInstruction::RestoreCutPolicy =>

View File

@@ -1129,25 +1129,6 @@ impl MachineState {
instr: &BuiltInInstruction)
{
match instr {
&BuiltInInstruction::CompareNumber(cmp, ref at_1, ref at_2) => {
let n1 = try_or_fail!(self, self.get_number(at_1));
let n2 = try_or_fail!(self, self.get_number(at_2));
self.compare_numbers(cmp, n1, n2);
},
&BuiltInInstruction::DynamicCompareNumber(cmp) => {
let n1 = try_or_fail!(self, self.arith_eval_by_metacall(temp_v!(1)));
let n2 = try_or_fail!(self, self.arith_eval_by_metacall(temp_v!(2)));
self.compare_numbers(cmp, n1, n2);
},
&BuiltInInstruction::DynamicIs => {
let a = self[temp_v!(1)].clone();
let result = try_or_fail!(self, self.arith_eval_by_metacall(temp_v!(2)));
self.unify(a, Addr::Con(Constant::Number(result)));
self.p += 1;
},
&BuiltInInstruction::GetArgCall =>
try_or_fail!(self, {
let val = self.try_get_arg();
@@ -1293,70 +1274,6 @@ SetupCallCleanupCutPolicy.")
self.fail = true;
},
&BuiltInInstruction::IsAtomic(r) => {
let d = self.store(self.deref(self[r].clone()));
match d {
Addr::Con(_) => self.p += 1,
_ => self.fail = true
};
},
&BuiltInInstruction::IsInteger(r) => {
let d = self.store(self.deref(self[r].clone()));
match d {
Addr::Con(Constant::Number(Number::Integer(_))) => self.p += 1,
_ => self.fail = true
};
},
&BuiltInInstruction::IsCompound(r) => {
let d = self.store(self.deref(self[r].clone()));
match d {
Addr::Str(_) => self.p += 1,
_ => self.fail = true
};
},
&BuiltInInstruction::IsFloat(r) => {
let d = self.store(self.deref(self[r].clone()));
match d {
Addr::Con(Constant::Number(Number::Float(_))) => self.p += 1,
_ => self.fail = true
};
},
&BuiltInInstruction::IsRational(r) => {
let d = self.store(self.deref(self[r].clone()));
match d {
Addr::Con(Constant::Number(Number::Rational(_))) => self.p += 1,
_ => self.fail = true
};
},
&BuiltInInstruction::IsString(r) => {
let d = self.store(self.deref(self[r].clone()));
match d {
Addr::Con(Constant::String(_)) => self.p += 1,
_ => self.fail = true
};
},
&BuiltInInstruction::IsNonVar(r) => {
let d = self.store(self.deref(self[r].clone()));
match d {
Addr::HeapCell(_) | Addr::StackCell(..) => self.fail = true,
_ => self.p += 1
};
},
&BuiltInInstruction::IsVar(r) => {
let d = self.store(self.deref(self[r].clone()));
match d {
Addr::HeapCell(_) | Addr::StackCell(_,_) => self.p += 1,
_ => self.fail = true
};
},
&BuiltInInstruction::InternalCallN =>
self.handle_internal_call_n(code_dir),
&BuiltInInstruction::Fail => {
@@ -1615,6 +1532,89 @@ SetupCallCleanupCutPolicy.")
self.duplicate_term();
self.p = self.cp;
},
&ControlInstruction::CompareNumber(cmp, ref at_1, ref at_2) => {
let n1 = try_or_fail!(self, self.get_number(at_1));
let n2 = try_or_fail!(self, self.get_number(at_2));
self.compare_numbers(cmp, n1, n2);
},
&ControlInstruction::DynamicCompareNumber(cmp) => {
let n1 = try_or_fail!(self, self.arith_eval_by_metacall(temp_v!(1)));
let n2 = try_or_fail!(self, self.arith_eval_by_metacall(temp_v!(2)));
self.compare_numbers(cmp, n1, n2);
},
&ControlInstruction::DynamicIs => {
let a = self[temp_v!(1)].clone();
let result = try_or_fail!(self, self.arith_eval_by_metacall(temp_v!(2)));
self.unify(a, Addr::Con(Constant::Number(result)));
self.p += 1;
},
&ControlInstruction::IsAtomic(r) => {
let d = self.store(self.deref(self[r].clone()));
match d {
Addr::Con(_) => self.p += 1,
_ => self.fail = true
};
},
&ControlInstruction::IsInteger(r) => {
let d = self.store(self.deref(self[r].clone()));
match d {
Addr::Con(Constant::Number(Number::Integer(_))) => self.p += 1,
_ => self.fail = true
};
},
&ControlInstruction::IsCompound(r) => {
let d = self.store(self.deref(self[r].clone()));
match d {
Addr::Str(_) => self.p += 1,
_ => self.fail = true
};
},
&ControlInstruction::IsFloat(r) => {
let d = self.store(self.deref(self[r].clone()));
match d {
Addr::Con(Constant::Number(Number::Float(_))) => self.p += 1,
_ => self.fail = true
};
},
&ControlInstruction::IsRational(r) => {
let d = self.store(self.deref(self[r].clone()));
match d {
Addr::Con(Constant::Number(Number::Rational(_))) => self.p += 1,
_ => self.fail = true
};
},
&ControlInstruction::IsString(r) => {
let d = self.store(self.deref(self[r].clone()));
match d {
Addr::Con(Constant::String(_)) => self.p += 1,
_ => self.fail = true
};
},
&ControlInstruction::IsNonVar(r) => {
let d = self.store(self.deref(self[r].clone()));
match d {
Addr::HeapCell(_) | Addr::StackCell(..) => self.fail = true,
_ => self.p += 1
};
},
&ControlInstruction::IsVar(r) => {
let d = self.store(self.deref(self[r].clone()));
match d {
Addr::HeapCell(_) | Addr::StackCell(_,_) => self.p += 1,
_ => self.fail = true
};
},
&ControlInstruction::EqCall => {
self.fail = self.eq_test();
self.p += 1;

View File

@@ -30,7 +30,7 @@ macro_rules! deallocate {
macro_rules! compare_number_instr {
($cmp: expr, $at_1: expr, $at_2: expr) => (
Line::BuiltIn(BuiltInInstruction::CompareNumber($cmp, $at_1, $at_2))
Line::Control(ControlInstruction::CompareNumber($cmp, $at_1, $at_2))
)
}
@@ -158,50 +158,50 @@ macro_rules! retry_me_else {
macro_rules! is_atomic {
($reg:expr) => (
Line::BuiltIn(BuiltInInstruction::IsAtomic($reg))
Line::Control(ControlInstruction::IsAtomic($reg))
)
}
macro_rules! is_integer {
($reg:expr) => (
Line::BuiltIn(BuiltInInstruction::IsInteger($reg))
Line::Control(ControlInstruction::IsInteger($reg))
)
}
macro_rules! is_compound {
($r:expr) => (
Line::BuiltIn(BuiltInInstruction::IsCompound($r))
Line::Control(ControlInstruction::IsCompound($r))
)
}
macro_rules! is_float {
($r:expr) => (
Line::BuiltIn(BuiltInInstruction::IsFloat($r))
Line::Control(ControlInstruction::IsFloat($r))
)
}
macro_rules! is_rational {
($r:expr) => (
Line::BuiltIn(BuiltInInstruction::IsRational($r))
Line::Control(ControlInstruction::IsRational($r))
)
}
macro_rules! is_nonvar {
($r:expr) => (
Line::BuiltIn(BuiltInInstruction::IsNonVar($r))
Line::Control(ControlInstruction::IsNonVar($r))
)
}
macro_rules! is_string {
($r:expr) => (
Line::BuiltIn(BuiltInInstruction::IsString($r))
Line::Control(ControlInstruction::IsString($r))
)
}
macro_rules! is_var {
($reg:expr) => (
Line::BuiltIn(BuiltInInstruction::IsVar($reg))
Line::Control(ControlInstruction::IsVar($reg))
)
}
@@ -469,13 +469,13 @@ macro_rules! display {
macro_rules! dynamic_is {
() => (
Line::BuiltIn(BuiltInInstruction::DynamicIs)
Line::Control(ControlInstruction::DynamicIs)
)
}
macro_rules! dynamic_num_test {
($cmp:expr) => (
Line::BuiltIn(BuiltInInstruction::DynamicCompareNumber($cmp))
Line::Control(ControlInstruction::DynamicCompareNumber($cmp))
)
}