/** {@inheritDoc} */ public FunctorName getFunctorFunctorName(Functor functor) { return interner.getFunctorFunctorName(functor); }
/** {@inheritDoc} */ public FunctorName getFunctorFunctorName(Functor functor) { return interner.getFunctorFunctorName(functor); }
/** * Applies a built-in replacement transformation to functors. If the functor matches built-in, a * {@link BuiltInFunctor} is created with a mapping to the functors built-in implementation, and the functors * arguments are copied into this new functor. If the functor does not match a built-in, it is returned unmodified. * * @param functor The functor to attempt to map onto a built-in. * * @return The functor umodified, or a {@link BuiltInFunctor} replacement for it. */ public BuiltInFunctor apply(Functor functor) { FunctorName functorName = interner.getFunctorFunctorName(functor); Class<? extends BuiltInFunctor> builtInClass; if (builtIns.containsKey(functorName)) { builtInClass = builtIns.get(functorName); } else { builtInClass = DefaultBuiltIn.class; } return ReflectionUtils.newInstance(ReflectionUtils.getConstructor(builtInClass, new Class[] { Functor.class }), new Object[] { functor }); } }
/** * Applies a built-in replacement transformation to functors. If the functor matches built-in, a * {@link BuiltInFunctor} is created with a mapping to the functors built-in implementation, and the functors * arguments are copied into this new functor. If the functor does not match a built-in, it is returned unmodified. * * @param functor The functor to attempt to map onto a built-in. * * @return The functor unmodified, or a {@link BuiltInFunctor} replacement for it. */ public Functor apply(Functor functor) { FunctorName functorName = defaultBuiltIn.getInterner().getFunctorFunctorName(functor); Class<? extends BuiltInFunctor> builtInClass; builtInClass = builtIns.get(functorName); if (builtInClass != null) { return ReflectionUtils.newInstance(ReflectionUtils.getConstructor(builtInClass, new Class[] { Functor.class, DefaultBuiltIn.class }), new Object[] { functor, defaultBuiltIn }); } else { return functor; } } }
/** * Applies a built-in replacement transformation to functors. If the functor matches built-in, a * {@link BuiltInFunctor} is created with a mapping to the functors built-in implementation, and the functors * arguments are copied into this new functor. If the functor does not match a built-in, it is returned unmodified. * * @param functor The functor to attempt to map onto a built-in. * * @return The functor umodified, or a {@link BuiltInFunctor} replacement for it. */ public Functor transform(Functor functor) { FunctorName functorName = interner.getFunctorFunctorName(functor); if (builtInExpressions.containsKey(functorName)) { Class<? extends Functor> builtInExpressionClass = builtInExpressions.get(functorName); return ReflectionUtils.newInstance(ReflectionUtils.getConstructor(builtInExpressionClass, new Class[] { Integer.TYPE, Term[].class }), new Object[] { functor.getName(), functor.getArguments() }); } else { return functor; } } }
/** {@inheritDoc} */ public SizeableLinkedList<WAMInstruction> compileBodyCall(Functor expression, boolean isFirstBody, boolean isLastBody, boolean chainRule, int permVarsRemaining) { // Used to build up the results in. SizeableLinkedList<WAMInstruction> instructions = new SizeableLinkedList<WAMInstruction>(); // Generate the call or tail-call instructions, followed by the call address, which is f_n of the // called program. if (isLastBody) { // Deallocate the stack frame at the end of the clause, but prior to calling the last // body predicate. // This is not required for chain rules, as they do not need a stack frame. if (!chainRule) { instructions.add(new WAMInstruction(WAMInstruction.WAMInstructionSet.Deallocate)); } instructions.add(new WAMInstruction(WAMInstruction.WAMInstructionSet.Execute, interner.getFunctorFunctorName(expression))); } else { instructions.add(new WAMInstruction(WAMInstruction.WAMInstructionSet.Call, (byte) (permVarsRemaining & 0xff), interner.getFunctorFunctorName(expression))); } return instructions; }
interner.getFunctorFunctorName(nextFunctor), nextFunctor); instructions.add(instruction);
FunctorName fn = interner.getFunctorFunctorName(clause.getHead()); WAMLabel entryLabel = new WAMLabel(fn, clauseNumber);