From: Mark Thom Date: Sat, 27 Jan 2018 22:54:05 +0000 (-0700) Subject: tighten =.. code X-Git-Tag: v0.8.110~599 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=60440ea86ba45111851180fc2cfdc99ef5807d1c;p=scryer-prolog.git tighten =.. code --- diff --git a/src/prolog/ast.rs b/src/prolog/ast.rs index bc1d4804..0bed72e0 100644 --- a/src/prolog/ast.rs +++ b/src/prolog/ast.rs @@ -782,7 +782,8 @@ pub enum BuiltInInstruction { CompareNumber(CompareNumberQT, ArithmeticTerm, ArithmeticTerm), EraseBall, Fail, - GetArg, + GetArgCall, + GetArgExecute, GetBall, GetCurrentBlock, GetCutPoint(RegType), diff --git a/src/prolog/builtins.rs b/src/prolog/builtins.rs index 33309da2..672e43ff 100644 --- a/src/prolog/builtins.rs +++ b/src/prolog/builtins.rs @@ -195,7 +195,7 @@ fn get_builtins(atom_tbl: TabledData) -> Code { functor_execute!(), // functor/3, 146. is_integer!(temp_v!(1)), // integer/1, 147. proceed!(), - get_arg!(), // get_arg/3, 149. + get_arg_execute!(), // get_arg/3, 149. try_me_else!(10), // arg/3, 150. allocate!(4), fact![get_var_in_fact!(perm_v!(1), 1), @@ -358,7 +358,7 @@ fn get_builtins(atom_tbl: TabledData) -> Code { neck_cut!(), query![put_value!(temp_v!(6), 2), put_value!(temp_v!(5), 3)], - arg_execute!(), + get_arg_execute!(), trust_me!(), allocate!(5), fact![get_list!(Level::Shallow, temp_v!(1)), @@ -370,7 +370,7 @@ fn get_builtins(atom_tbl: TabledData) -> Code { query![put_value!(perm_v!(5), 1), put_value!(perm_v!(3), 2), put_value!(temp_v!(5), 3)], - arg_call!(), + get_arg_call!(), add!(ArithmeticTerm::Reg(perm_v!(5)), ArithmeticTerm::Number(rc_integer!(1)), 1), diff --git a/src/prolog/io.rs b/src/prolog/io.rs index 4c84bfbe..185eb3f7 100644 --- a/src/prolog/io.rs +++ b/src/prolog/io.rs @@ -124,9 +124,9 @@ impl fmt::Display for ControlInstruction { &ControlInstruction::ExecuteN(arity) => write!(f, "execute_N {}", arity), &ControlInstruction::FunctorCall => - write!(f, "call_functor"), + write!(f, "functor_call"), &ControlInstruction::FunctorExecute => - write!(f, "execute_functor"), + write!(f, "functor_execute"), &ControlInstruction::Deallocate => write!(f, "deallocate"), &ControlInstruction::Execute(ref name, arity) => @@ -179,8 +179,10 @@ impl fmt::Display for BuiltInInstruction { write!(f, "erase_ball"), &BuiltInInstruction::Fail => write!(f, "false"), - &BuiltInInstruction::GetArg => - write!(f, "get_arg X1, X2, X3"), + &BuiltInInstruction::GetArgCall => + write!(f, "get_arg_call X1, X2, X3"), + &BuiltInInstruction::GetArgExecute => + write!(f, "get_arg_execute X1, X2, X3"), &BuiltInInstruction::GetBall => write!(f, "get_ball X1"), &BuiltInInstruction::GetCurrentBlock => @@ -471,8 +473,6 @@ pub fn compile<'a, 'b: 'a>(wam: &'a mut Machine, tl: &'b TopLevelPacket) -> Eval return EvalSession::from(e); }; - print_code(&code); - if !code.is_empty() { if let Some(name) = tl.name() { wam.add_user_code(name, tl.arity(), code) diff --git a/src/prolog/machine/machine_state.rs b/src/prolog/machine/machine_state.rs index 8fadde4a..bc0b6a89 100644 --- a/src/prolog/machine/machine_state.rs +++ b/src/prolog/machine/machine_state.rs @@ -1325,7 +1325,13 @@ impl MachineState { self.unify(a, Addr::Con(Constant::Number(result))); 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, { let val = self.try_get_arg(); self.p = self.cp; diff --git a/src/prolog/macros.rs b/src/prolog/macros.rs index 564996d8..8219e59f 100644 --- a/src/prolog/macros.rs +++ b/src/prolog/macros.rs @@ -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 { ($r:expr) => ( FactInstruction::UnifyValue($r) @@ -412,9 +400,15 @@ macro_rules! add { ) } -macro_rules! get_arg { +macro_rules! get_arg_call { + () => ( + Line::BuiltIn(BuiltInInstruction::GetArgCall) + ) +} + +macro_rules! get_arg_execute { () => ( - Line::BuiltIn(BuiltInInstruction::GetArg) + Line::BuiltIn(BuiltInInstruction::GetArgExecute) ) }