}
pub enum BuiltInInstruction {
- CleanUpBlock,
- CompareNumber(CompareNumberQT, ArithmeticTerm, ArithmeticTerm),
+ CleanUpBlock,
EraseBall,
Fail,
GetArgCall,
GetArgExecute,
GetBall,
GetCurrentBlock,
- GetCutPoint(RegType),
- DynamicCompareNumber(CompareNumberQT),
- DynamicIs,
+ GetCutPoint(RegType),
InstallCleaner,
InstallNewBlock,
- InternalCallN,
- IsAtomic(RegType),
- IsCompound(RegType),
- IsFloat(RegType),
- IsInteger(RegType),
- IsNonVar(RegType),
- IsRational(RegType),
- IsString(RegType),
- IsVar(RegType),
+ InternalCallN,
ResetBlock,
RestoreCutPolicy,
SetBall,
CatchCall,
CatchExecute,
CheckCpExecute,
+ CompareNumber(CompareNumberQT, ArithmeticTerm, ArithmeticTerm),
DisplayCall,
DisplayExecute,
Deallocate,
DuplicateTermCall,
DuplicateTermExecute,
+ DynamicCompareNumber(CompareNumberQT),
+ DynamicIs,
EqCall,
EqExecute,
Execute(TabledRc<Atom>, usize),
GotoCall(usize, usize), // p, arity.
GotoExecute(usize, usize), // p, arity.
GroundCall,
- GroundExecute,
+ GroundExecute,
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,
&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,
&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,
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) =>
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),
}
}
}
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
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),
+ write!(f, "clean_up_block"),
&BuiltInInstruction::EraseBall =>
write!(f, "erase_ball"),
&BuiltInInstruction::Fail =>
&BuiltInInstruction::InstallNewBlock =>
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),
+ write!(f, "internal_call_N"),
&BuiltInInstruction::ResetBlock =>
write!(f, "reset_block"),
&BuiltInInstruction::RestoreCutPolicy =>
cut_policy: &mut Box<CutPolicy>,
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;
- },
+ match instr {
&BuiltInInstruction::GetArgCall =>
try_or_fail!(self, {
let val = self.try_get_arg();
self.or_stack.truncate(self.b);
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 => {
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;
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))
)
}
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))
)
}
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))
)
}