tighten =.. code

This commit is contained in:
Mark Thom
2018-01-27 15:54:05 -07:00
parent 4f645b4664
commit 60440ea86b
5 changed files with 26 additions and 25 deletions

View File

@@ -782,7 +782,8 @@ pub enum BuiltInInstruction {
CompareNumber(CompareNumberQT, ArithmeticTerm, ArithmeticTerm), CompareNumber(CompareNumberQT, ArithmeticTerm, ArithmeticTerm),
EraseBall, EraseBall,
Fail, Fail,
GetArg, GetArgCall,
GetArgExecute,
GetBall, GetBall,
GetCurrentBlock, GetCurrentBlock,
GetCutPoint(RegType), GetCutPoint(RegType),

View File

@@ -195,7 +195,7 @@ fn get_builtins(atom_tbl: TabledData<Atom>) -> Code {
functor_execute!(), // functor/3, 146. functor_execute!(), // functor/3, 146.
is_integer!(temp_v!(1)), // integer/1, 147. is_integer!(temp_v!(1)), // integer/1, 147.
proceed!(), proceed!(),
get_arg!(), // get_arg/3, 149. get_arg_execute!(), // get_arg/3, 149.
try_me_else!(10), // arg/3, 150. try_me_else!(10), // arg/3, 150.
allocate!(4), allocate!(4),
fact![get_var_in_fact!(perm_v!(1), 1), fact![get_var_in_fact!(perm_v!(1), 1),
@@ -358,7 +358,7 @@ fn get_builtins(atom_tbl: TabledData<Atom>) -> Code {
neck_cut!(), neck_cut!(),
query![put_value!(temp_v!(6), 2), query![put_value!(temp_v!(6), 2),
put_value!(temp_v!(5), 3)], put_value!(temp_v!(5), 3)],
arg_execute!(), get_arg_execute!(),
trust_me!(), trust_me!(),
allocate!(5), allocate!(5),
fact![get_list!(Level::Shallow, temp_v!(1)), fact![get_list!(Level::Shallow, temp_v!(1)),
@@ -370,7 +370,7 @@ fn get_builtins(atom_tbl: TabledData<Atom>) -> Code {
query![put_value!(perm_v!(5), 1), query![put_value!(perm_v!(5), 1),
put_value!(perm_v!(3), 2), put_value!(perm_v!(3), 2),
put_value!(temp_v!(5), 3)], put_value!(temp_v!(5), 3)],
arg_call!(), get_arg_call!(),
add!(ArithmeticTerm::Reg(perm_v!(5)), add!(ArithmeticTerm::Reg(perm_v!(5)),
ArithmeticTerm::Number(rc_integer!(1)), ArithmeticTerm::Number(rc_integer!(1)),
1), 1),

View File

@@ -124,9 +124,9 @@ impl fmt::Display for ControlInstruction {
&ControlInstruction::ExecuteN(arity) => &ControlInstruction::ExecuteN(arity) =>
write!(f, "execute_N {}", arity), write!(f, "execute_N {}", arity),
&ControlInstruction::FunctorCall => &ControlInstruction::FunctorCall =>
write!(f, "call_functor"), write!(f, "functor_call"),
&ControlInstruction::FunctorExecute => &ControlInstruction::FunctorExecute =>
write!(f, "execute_functor"), write!(f, "functor_execute"),
&ControlInstruction::Deallocate => &ControlInstruction::Deallocate =>
write!(f, "deallocate"), write!(f, "deallocate"),
&ControlInstruction::Execute(ref name, arity) => &ControlInstruction::Execute(ref name, arity) =>
@@ -179,8 +179,10 @@ impl fmt::Display for BuiltInInstruction {
write!(f, "erase_ball"), write!(f, "erase_ball"),
&BuiltInInstruction::Fail => &BuiltInInstruction::Fail =>
write!(f, "false"), write!(f, "false"),
&BuiltInInstruction::GetArg => &BuiltInInstruction::GetArgCall =>
write!(f, "get_arg X1, X2, X3"), write!(f, "get_arg_call X1, X2, X3"),
&BuiltInInstruction::GetArgExecute =>
write!(f, "get_arg_execute X1, X2, X3"),
&BuiltInInstruction::GetBall => &BuiltInInstruction::GetBall =>
write!(f, "get_ball X1"), write!(f, "get_ball X1"),
&BuiltInInstruction::GetCurrentBlock => &BuiltInInstruction::GetCurrentBlock =>
@@ -471,8 +473,6 @@ pub fn compile<'a, 'b: 'a>(wam: &'a mut Machine, tl: &'b TopLevelPacket) -> Eval
return EvalSession::from(e); return EvalSession::from(e);
}; };
print_code(&code);
if !code.is_empty() { if !code.is_empty() {
if let Some(name) = tl.name() { if let Some(name) = tl.name() {
wam.add_user_code(name, tl.arity(), code) wam.add_user_code(name, tl.arity(), code)

View File

@@ -1325,7 +1325,13 @@ impl MachineState {
self.unify(a, Addr::Con(Constant::Number(result))); self.unify(a, Addr::Con(Constant::Number(result)));
self.p += 1; self.p += 1;
}, },
&BuiltInInstruction::GetArg => &BuiltInInstruction::GetArgCall =>
try_or_fail!(self, {
let val = self.try_get_arg();
self.p += 1;
val
}),
&BuiltInInstruction::GetArgExecute =>
try_or_fail!(self, { try_or_fail!(self, {
let val = self.try_get_arg(); let val = self.try_get_arg();
self.p = self.cp; self.p = self.cp;

View File

@@ -358,18 +358,6 @@ macro_rules! functor_execute {
) )
} }
macro_rules! arg_execute {
() => (
Line::Control(ControlInstruction::ArgExecute)
)
}
macro_rules! arg_call {
() => (
Line::Control(ControlInstruction::ArgCall)
)
}
macro_rules! unify_value { macro_rules! unify_value {
($r:expr) => ( ($r:expr) => (
FactInstruction::UnifyValue($r) FactInstruction::UnifyValue($r)
@@ -412,9 +400,15 @@ macro_rules! add {
) )
} }
macro_rules! get_arg { macro_rules! get_arg_call {
() => ( () => (
Line::BuiltIn(BuiltInInstruction::GetArg) Line::BuiltIn(BuiltInInstruction::GetArgCall)
)
}
macro_rules! get_arg_execute {
() => (
Line::BuiltIn(BuiltInInstruction::GetArgExecute)
) )
} }