Class AOp<T extends ACell>

Type Parameters:
T - the type of the operation return value
All Implemented Interfaces:
IValidated, IWriteable
Direct Known Subclasses:
AMultiOp, Constant, Def, Lambda, Local, Lookup, Set, Special

public abstract class AOp<T extends ACell> extends ACell
Abstract base class for CVM operations "...that was the big revelation to me when I was in graduate school—when I finally understood that the half page of code on the bottom of page 13 of the Lisp 1.5 manual was Lisp in itself. These were “Maxwell’s Equations of Software!” This is the whole world of programming in a few lines that I can put my hand over." - Alan Kay
  • Constructor Details

    • AOp

      public AOp()
  • Method Details

    • execute

      public abstract <I extends ACell> Context<T> execute(Context<I> context)
      Executes this op with the given context. Must preserve depth unless an exceptional is returned.
      Type Parameters:
      I - Type of Context
      Parameters:
      context - Initial Context
      Returns:
      The updated Context after executing this operation
    • getType

      public final AType getType()
      Description copied from class: ACell
      Gets the most specific known runtime Type for this Cell.
      Overrides:
      getType in class ACell
      Returns:
      The Type of this Call
    • estimatedEncodingSize

      public int estimatedEncodingSize()
      Description copied from interface: IWriteable
      Estimate the encoded data size for this Cell. Used for quickly sizing buffers. Implementations should try to return a size that is likely to contain the entire object when represented in binary format, including the tag byte.
      Returns:
      The estimated size for the binary representation of this object.
    • isCanonical

      public boolean isCanonical()
      Description copied from class: ACell
      Returns true if this Cell is in a canonical format for message writing. Reading or writing a non-canonical value should be considered illegal, but non-canonical objects may be used on a temporary internal basis.
      Specified by:
      isCanonical in class ACell
      Returns:
      true if the object is in canonical format, false otherwise
    • toCanonical

      public ACell toCanonical()
      Description copied from class: ACell
      Converts this Cell to its canonical version. Returns this if already canonical
      Specified by:
      toCanonical in class ACell
      Returns:
      Canonical version of Cell
    • isCVMValue

      public final boolean isCVMValue()
      Description copied from class: ACell
      Returns true if this object represents a first class CVM Value. Sub-structural cells that are not themselves first class values should return false. CVM values might not be in a canonical format, e.g. temporary data structures
      Specified by:
      isCVMValue in class ACell
      Returns:
      true if the object is a CVM Value, false otherwise
    • opCode

      public abstract byte opCode()
      Returns the opcode for this op
      Returns:
      Opcode as a byte
    • encode

      public final int encode(byte[] bs, int pos)
      Description copied from class: ACell
      Writes this Cell's encoding to a byte array, including a tag byte which will be written first
      Specified by:
      encode in interface IWriteable
      Specified by:
      encode in class ACell
      Parameters:
      bs - A byte array to which to write the encoding
      pos - The offset into the byte array
      Returns:
      New position after writing
    • encodeRaw

      public abstract int encodeRaw(byte[] bs, int pos)
      Writes the raw data for this Op to the specified bytebuffer. Assumes Op tag and opcode already written.
      Specified by:
      encodeRaw in class ACell
      Parameters:
      bs - Byte array to write to
      pos - Position to write in byte array
      Returns:
      The updated position
    • updateRefs

      public abstract AOp<T> updateRefs(IRefFunction func)
      Description copied from class: ACell
      Updates all Refs in this object using the given function. The function *must not* change the hash value of Refs, in order to ensure structural integrity of modified data structures. This is a building block for a very sneaky trick that enables use to do a lot of efficient operations on large trees of smart references. Must return the same object if no Refs are altered.
      Overrides:
      updateRefs in class ACell
      Parameters:
      func - Ref update function
      Returns:
      Cell with updated Refs
    • getTag

      public byte getTag()
      Description copied from class: ACell
      Gets the tag byte for this cell. The tag byte is always written as the first byte of the Cell's Encoding
      Specified by:
      getTag in class ACell
      Returns:
      Tag byte for this Cell