org.deri.iris.compiler
Class BuiltinRegister

java.lang.Object
  extended by org.deri.iris.compiler.BuiltinRegister

public final class BuiltinRegister
extends Object

Holds the registry of built-in atoms that the parser can use to translate predicates to built-ins as the logic program is parsed.

Before a built-in can be recognized by the parser it must first be registered with the associated BuiltinRegister. The BuiltinRegister uses instances of the built-ins to get their predicate names and their class instances. The BuiltinRegister basically holds a map between predicate symbol and class instance. This class initialises itself with all the standard IRIS built-ins.

To add more, simply call registerBuiltin() with an instance of the new built-in type.

To unregister a built-in call unregisterBuiltin(). However, beware that unregistering any of the standard built-ins can lead to undefined behaviour.


Constructor Summary
BuiltinRegister()
          Constructs a new built-in register and register all the standard IRIS built-ins.
 
Method Summary
 boolean equals(Object o)
           
 int getBuiltinArity(String s)
          Returns the arity of a registered built-in.
 Class<?> getBuiltinClass(String s)
          Returns the class of a registered built-in.
 int hashCode()
           
 void registerBuiltin(IBuiltinAtom builtin)
          Registers a single built-in.
 String toString()
           Returns a short description of this object.
 void unregisterBuiltin(IBuiltinAtom builtin)
          De-registers a single built-in.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BuiltinRegister

public BuiltinRegister()
Constructs a new built-in register and register all the standard IRIS built-ins.

Method Detail

registerBuiltin

public void registerBuiltin(IBuiltinAtom builtin)
Registers a single built-in. Already registered built-ins will be overwritten.

Parameters:
builtin - an instance of the built-in to register
Throws:
IllegalArgumentException - if the class is null

unregisterBuiltin

public void unregisterBuiltin(IBuiltinAtom builtin)
De-registers a single built-in.

Parameters:
builtin - an instance of the built-in to de-register
Throws:
IllegalArgumentException - if the class is null

getBuiltinArity

public int getBuiltinArity(String s)
Returns the arity of a registered built-in.

Parameters:
s - the name (predicate symbol) of the built-in
Returns:
the arity, or -1 if such a built-in hasn't been registered yet

getBuiltinClass

public Class<?> getBuiltinClass(String s)
Returns the class of a registered built-in.

Parameters:
s - the name (predicate symbol) of the built-in
Returns:
the class, or null if such a built-in hasn't been registered yet

toString

public String toString()

Returns a short description of this object. The format of the returned string is undocumented and subject to change.

An example return string could be: [ADD[3, org.deri.iris.builtins.AddBuiltin],SUBTRACT[3, org.deri.builtins.SubtractBuiltin]]

Overrides:
toString in class Object
Returns:
the description

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object