Class RuleClauseCode


  • public class RuleClauseCode
    extends java.lang.Object
    Object used to hold the compiled bytecode stream for a single rule clause. This uses a slightly WAM-like code stream but gluing of the clauses together into disjunctions is done in the interpreter loop so a complete predicate is represented as a list of RuleClauseCode objects.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static byte ALLOCATE
      Allocate a new environment frame
      static byte CALL_BUILTIN
      call a built-in operation defined by a rule clause (clauseIndex(
      static byte CALL_PREDICATE
      call a predicate code object (predicateCodeList)
      static byte CALL_PREDICATE_INDEX
      call a predicate code object with run time indexing (predicateCodeList)
      static byte CALL_TABLED
      call a table code object ()
      static byte CALL_TRIPLE_MATCH
      call a pure triple match (predicate)
      static byte CALL_WILD_TABLED
      call a table code object from a wildcard ()
      static byte CLEAR_ARG
      reset an argument to an unbound variable (Ai)
      static byte CLEAR_TEMP
      reset a temp variable to an unbound variable (Ti)
      static byte CLEAR_VARIABLE
      reset a permanent variable to an unbound variable (Yi)
      static byte GET_CONSTANT
      fetch constant argument (const, Ai)
      static byte GET_FUNCTOR
      deconstruct a functor argument (functor)
      static byte GET_TEMP
      fetch temporary variable argument (Ti, Ai)
      static byte GET_VARIABLE
      fetch permanent variable argument, first occurance (Yi, Ai)
      static byte LAST_CALL_PREDICATE
      variant on CALL_PREDICATE using the last call optimization, only current used in chain rules
      static byte MAKE_FUNCTOR
      create a functor object from a rule template (templateFunctor)
      static int MAX_ARGUMENT_VARS
      The maximum number of argument variables allowed in a single goal Future refactorings will remove this restriction.
      static int MAX_PERMANENT_VARS
      The maximum number of permanent variables allowed in a single rule clause.
      static int MAX_TEMPORARY_VARS
      The maximum number of temporary variables allowed in a single rule clause.
      static byte PROCEED
      return from a call, proceeed along AND tree
      static byte PUT_CONSTANT
      put constant value into call parameter (const, Ai)
      static byte PUT_DEREF_VARIABLE
      put a dereferenced permanent variable into call parameter ready for BUILTIN call (Yi, Ai)
      static byte PUT_NEW_VARIABLE
      put permanaent variable into call parameter, first occurance (Yi, Ai)
      static byte PUT_TEMP
      put temp variable into call parameter (Ti, Ai)
      static byte PUT_VARIABLE
      put permanaent variable into call parameter (Yi, Ai)
      static RuleClauseCode returnCodeBlock
      Dummy code block which just returns
      static byte TEST_BOUND
      Test if an argument is bound (Ai)
      static byte TEST_UNBOUND
      Test if an argument is unbound (Ai)
      static byte UNIFY_TEMP
      fetch temporary variable argument, later occurance (Ti, Ai)
      static byte UNIFY_VARIABLE
      fetch permanent variable argument, later occurance (Yi, Ai)
    • Constructor Summary

      Constructors 
      Constructor Description
      RuleClauseCode​(Rule rule)
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void compile​(LPRuleStore ruleStore)
      Compile the rule into byte code.
      java.lang.Object[] getArgs()
      Return the argument vector associated with this clauses' byte codes.
      byte[] getCode()
      Return the byte code vector for this clause.
      Rule getRule()
      Return the rule from which this code block was compiled.
      static void main​(java.lang.String[] args)
      Debug support - not unit testing.
      void print​(java.io.PrintStream out)
      Debug helper - list the code to a stream
      int termIndex​(int pc)
      Translate a program counter offset to the index of the corresponding body term (or -1 if a head term or a dummy rule).
      java.lang.String toString()
      Print clause as rule for tracing.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • GET_CONSTANT

        public static final byte GET_CONSTANT
        fetch constant argument (const, Ai)
        See Also:
        Constant Field Values
      • GET_VARIABLE

        public static final byte GET_VARIABLE
        fetch permanent variable argument, first occurance (Yi, Ai)
        See Also:
        Constant Field Values
      • UNIFY_VARIABLE

        public static final byte UNIFY_VARIABLE
        fetch permanent variable argument, later occurance (Yi, Ai)
        See Also:
        Constant Field Values
      • GET_TEMP

        public static final byte GET_TEMP
        fetch temporary variable argument (Ti, Ai)
        See Also:
        Constant Field Values
      • UNIFY_TEMP

        public static final byte UNIFY_TEMP
        fetch temporary variable argument, later occurance (Ti, Ai)
        See Also:
        Constant Field Values
      • PUT_CONSTANT

        public static final byte PUT_CONSTANT
        put constant value into call parameter (const, Ai)
        See Also:
        Constant Field Values
      • PUT_NEW_VARIABLE

        public static final byte PUT_NEW_VARIABLE
        put permanaent variable into call parameter, first occurance (Yi, Ai)
        See Also:
        Constant Field Values
      • PUT_VARIABLE

        public static final byte PUT_VARIABLE
        put permanaent variable into call parameter (Yi, Ai)
        See Also:
        Constant Field Values
      • PUT_DEREF_VARIABLE

        public static final byte PUT_DEREF_VARIABLE
        put a dereferenced permanent variable into call parameter ready for BUILTIN call (Yi, Ai)
        See Also:
        Constant Field Values
      • PUT_TEMP

        public static final byte PUT_TEMP
        put temp variable into call parameter (Ti, Ai)
        See Also:
        Constant Field Values
      • CALL_PREDICATE

        public static final byte CALL_PREDICATE
        call a predicate code object (predicateCodeList)
        See Also:
        Constant Field Values
      • GET_FUNCTOR

        public static final byte GET_FUNCTOR
        deconstruct a functor argument (functor)
        See Also:
        Constant Field Values
      • CALL_PREDICATE_INDEX

        public static final byte CALL_PREDICATE_INDEX
        call a predicate code object with run time indexing (predicateCodeList)
        See Also:
        Constant Field Values
      • CALL_TRIPLE_MATCH

        public static final byte CALL_TRIPLE_MATCH
        call a pure triple match (predicate)
        See Also:
        Constant Field Values
      • LAST_CALL_PREDICATE

        public static final byte LAST_CALL_PREDICATE
        variant on CALL_PREDICATE using the last call optimization, only current used in chain rules
        See Also:
        Constant Field Values
      • CALL_TABLED

        public static final byte CALL_TABLED
        call a table code object ()
        See Also:
        Constant Field Values
      • CALL_WILD_TABLED

        public static final byte CALL_WILD_TABLED
        call a table code object from a wildcard ()
        See Also:
        Constant Field Values
      • PROCEED

        public static final byte PROCEED
        return from a call, proceeed along AND tree
        See Also:
        Constant Field Values
      • MAKE_FUNCTOR

        public static final byte MAKE_FUNCTOR
        create a functor object from a rule template (templateFunctor)
        See Also:
        Constant Field Values
      • CALL_BUILTIN

        public static final byte CALL_BUILTIN
        call a built-in operation defined by a rule clause (clauseIndex(
        See Also:
        Constant Field Values
      • CLEAR_VARIABLE

        public static final byte CLEAR_VARIABLE
        reset a permanent variable to an unbound variable (Yi)
        See Also:
        Constant Field Values
      • CLEAR_TEMP

        public static final byte CLEAR_TEMP
        reset a temp variable to an unbound variable (Ti)
        See Also:
        Constant Field Values
      • CLEAR_ARG

        public static final byte CLEAR_ARG
        reset an argument to an unbound variable (Ai)
        See Also:
        Constant Field Values
      • ALLOCATE

        public static final byte ALLOCATE
        Allocate a new environment frame
        See Also:
        Constant Field Values
      • TEST_BOUND

        public static final byte TEST_BOUND
        Test if an argument is bound (Ai)
        See Also:
        Constant Field Values
      • TEST_UNBOUND

        public static final byte TEST_UNBOUND
        Test if an argument is unbound (Ai)
        See Also:
        Constant Field Values
      • MAX_PERMANENT_VARS

        public static final int MAX_PERMANENT_VARS
        The maximum number of permanent variables allowed in a single rule clause. Now only relevent for initial holding clause.
        See Also:
        Constant Field Values
      • MAX_ARGUMENT_VARS

        public static final int MAX_ARGUMENT_VARS
        The maximum number of argument variables allowed in a single goal Future refactorings will remove this restriction.
        See Also:
        Constant Field Values
      • MAX_TEMPORARY_VARS

        public static final int MAX_TEMPORARY_VARS
        The maximum number of temporary variables allowed in a single rule clause.
        See Also:
        Constant Field Values
      • returnCodeBlock

        public static RuleClauseCode returnCodeBlock
        Dummy code block which just returns
    • Constructor Detail

      • RuleClauseCode

        public RuleClauseCode​(Rule rule)
        Constructor.
        Parameters:
        rule - the rule to be compiled
    • Method Detail

      • getCode

        public byte[] getCode()
        Return the byte code vector for this clause.
      • getArgs

        public java.lang.Object[] getArgs()
        Return the argument vector associated with this clauses' byte codes.
      • getRule

        public Rule getRule()
        Return the rule from which this code block was compiled.
      • compile

        public void compile​(LPRuleStore ruleStore)
        Compile the rule into byte code.
        Parameters:
        ruleStore - the store of LP rules through which calls to other predicates can be resolved.
      • termIndex

        public int termIndex​(int pc)
        Translate a program counter offset to the index of the corresponding body term (or -1 if a head term or a dummy rule).
      • print

        public void print​(java.io.PrintStream out)
        Debug helper - list the code to a stream
      • toString

        public java.lang.String toString()
        Print clause as rule for tracing.
        Overrides:
        toString in class java.lang.Object
      • main

        public static void main​(java.lang.String[] args)
        Debug support - not unit testing.