/** * Execute the given built in as a body clause, only if it is side-effect-free. * @param context an execution context giving access to other relevant data * @return true if the functor has an implementation and that implementation returns true when evaluated */ public boolean safeEvalAsBodyClause(RuleContext context) { if (getImplementor() == null) { logger.warn("Invoking undefined functor " + getName() + " in " + context.getRule().toShortString()); return false; } if (implementor.isSafe()) { return implementor.bodyCall(getBoundArgs(context.getEnv()), args.length, context); } else { return false; } }
public boolean call(Builtin builtin, Node n1, Node n2) { return builtin.bodyCall(new Node[] {n1, n2}, 2, new DummyRuleContext()); }
imp.headAction( f.getArgs(), f.getArgLength(), context );
/** * Constructor. * @param builtin the invoking builtin * @param context the invoking rule context * @param message a text explanation of the error */ public BuiltinException(Builtin builtin, RuleContext context, String message) { super("Error in clause of rule (" + context.getRule().toShortString() + ") " + builtin.getName() + ": " + message); } }
@Override public void register(String functor, Builtin impl) { builtins.put(functor, impl); builtinsByURI.put(impl.getURI(), impl); }
/** * Check if a rule from the conflict set is still OK to fire. * Just checks the non-monotonic guards such as noValue. */ public boolean shouldStillFire() { // Check any non-pattern clauses for (int i = 0; i < rule.bodyLength(); i++) { Object clause = rule.getBodyElement(i); if (clause instanceof Functor) { Builtin builtin = ((Functor)clause).getImplementor(); if (builtin != null && !builtin.isMonotonic()) { if (!((Functor)clause).evalAsBodyClause(this)) { return false; } } } } return true; }
/** * Emit code for a call to a built-in predicate (functor). * @param functor the built-in to be invoked. */ void emitBody(Functor functor) { Node[] fargs = functor.getArgs(); Builtin builtin = functor.getImplementor(); if (builtin == null) { throw new LPRuleSyntaxException("Unknown builtin operation " + functor.getName(), rule); } if (builtin.getArgLength() != 0 && builtin.getArgLength() != fargs.length) { throw new LPRuleSyntaxException("Wrong number of arguments to functor " + functor.getName() + " : got " + functor.getArgLength() + " : expected " + builtin.getArgLength(), rule); } for (int i = 0; i < fargs.length; i++) { Node node = fargs[i]; // We optionally force an eager dereference of variables here. // We used to force this but the current builtin implementations // now robust against it (the do a deref themselves anyway). emitBodyPut(node, i, true); } code[p++] = CALL_BUILTIN; code[p++] = (byte)fargs.length; args.add(builtin); }
/** * Execute the given built in as a body clause, only if it is side-effect-free. * @param context an execution context giving access to other relevant data * @return true if the functor has an implementation and that implementation returns true when evaluated */ public boolean safeEvalAsBodyClause(RuleContext context) { if (getImplementor() == null) { logger.warn("Invoking undefined functor " + getName() + " in " + context.getRule().toShortString()); return false; } if (implementor.isSafe()) { return implementor.bodyCall(getBoundArgs(context.getEnv()), args.length, context); } else { return false; } }
public boolean call(Builtin builtin, Node n1, Node n2) { return builtin.bodyCall(new Node[] {n1, n2}, 2, new DummyRuleContext()); }
imp.headAction( f.getArgs(), f.getArgLength(), context );
/** * Constructor. * @param builtin the invoking builtin * @param context the invoking rule context * @param message a text explanation of the error */ public BuiltinException(Builtin builtin, RuleContext context, String message) { super("Error in clause of rule (" + context.getRule().toShortString() + ") " + builtin.getName() + ": " + message); } }
@Override public void register(String functor, Builtin impl) { builtins.put(functor, impl); builtinsByURI.put(impl.getURI(), impl); }
/** * Check if a rule from the conflict set is still OK to fire. * Just checks the non-monotonic guards such as noValue. */ public boolean shouldStillFire() { // Check any non-pattern clauses for (int i = 0; i < rule.bodyLength(); i++) { Object clause = rule.getBodyElement(i); if (clause instanceof Functor) { Builtin builtin = ((Functor)clause).getImplementor(); if (builtin != null && !builtin.isMonotonic()) { if (!((Functor)clause).evalAsBodyClause(this)) { return false; } } } } return true; }
/** * Emit code for a call to a built-in predicate (functor). * @param functor the built-in to be invoked. */ void emitBody(Functor functor) { Node[] fargs = functor.getArgs(); Builtin builtin = functor.getImplementor(); if (builtin == null) { throw new LPRuleSyntaxException("Unknown builtin operation " + functor.getName(), rule); } if (builtin.getArgLength() != 0 && builtin.getArgLength() != fargs.length) { throw new LPRuleSyntaxException("Wrong number of arguments to functor " + functor.getName() + " : got " + functor.getArgLength() + " : expected " + builtin.getArgLength(), rule); } for (int i = 0; i < fargs.length; i++) { Node node = fargs[i]; // We optionally force an eager dereference of variables here. // We used to force this but the current builtin implementations // now robust against it (the do a deref themselves anyway). emitBodyPut(node, i, true); } code[p++] = CALL_BUILTIN; code[p++] = (byte)fargs.length; args.add(builtin); }
/** * Execute the given built in as a body clause. * @param context an execution context giving access to other relevant data * @return true if the functor has an implementation and that implementation returns true when evaluated */ public boolean evalAsBodyClause(RuleContext context) { if (getImplementor() == null) { logger.warn("Invoking undefined functor " + getName() + " in " + context.getRule().toShortString()); return false; } return implementor.bodyCall(getBoundArgs(context.getEnv()), args.length, context); }
imp.headAction( f.getArgs(), f.getArgLength(), tempContext );