Class SymRegistryImpl

java.lang.Object
org.kink_lang.kink.internal.sym.SymRegistryImpl
All Implemented Interfaces:
SymRegistry

public class SymRegistryImpl extends Object implements SymRegistry
The bidirectional registry of syms and sym-handles.

A sym-handle is an int value between 1 and 0x3fff_ffff corresponding to a sym. A handle is generated when handleFor(String) is called for the sym for the first time.

The registry can be accessed from multiple threads concurrently.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The maximum sym handle of preloaded control syms.
    static final int
    Sym handle of "repr".
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a sym handle.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Registers or gets the handle of the sym.
    static boolean
    isPreloaded(int handle)
    Whether the handle is a preloaded fun.
    boolean
    isValidHandle(int handle)
    Returns true if the handle is registered.
    symFor(int handle)
    Returns the corresponding sym for the handle.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MAX_PRELOADED_CONTROL

      public static final int MAX_PRELOADED_CONTROL
      The maximum sym handle of preloaded control syms.
    • REPR

      public static final int REPR
      Sym handle of "repr".
  • Constructor Details

    • SymRegistryImpl

      public SymRegistryImpl()
      Constructs a sym handle.
  • Method Details

    • handleFor

      public int handleFor(String sym)
      Registers or gets the handle of the sym.
      Specified by:
      handleFor in interface SymRegistry
      Parameters:
      sym - the sym.
      Returns:
      the handle.
      Throws:
      IllegalStateException - if the sym is not registered yet, and the registry does not have capacity for the new sym.
    • symFor

      public String symFor(int handle)
      Returns the corresponding sym for the handle.
      Specified by:
      symFor in interface SymRegistry
      Parameters:
      handle - the handle.
      Returns:
      the corresponding sym for the handle.
      Throws:
      IllegalArgumentException - if the specified handle is not registered.
    • isValidHandle

      public boolean isValidHandle(int handle)
      Returns true if the handle is registered.
      Specified by:
      isValidHandle in interface SymRegistry
      Parameters:
      handle - the handle.
      Returns:
      true if the handle is registered.
    • isPreloaded

      public static boolean isPreloaded(int handle)
      Whether the handle is a preloaded fun.
      Parameters:
      handle - the handle to test.
      Returns:
      whether the handle is a preloaded fun.