Package convex.core.lang
Class AOp<T extends ACell>
java.lang.Object
convex.core.data.AObject
convex.core.data.ACell
convex.core.lang.AOp<T>
- Type Parameters:
T
- the type of the operation return value
- All Implemented Interfaces:
IValidated
,IWriteable
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
-
Field Summary
Fields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal int
encode
(byte[] bs, int pos) Writes this Cell's encoding to a byte array, including a tag byte which will be written first.abstract int
encodeRaw
(byte[] bs, int pos) Writes the raw data for this Op to the specified bytebuffer.int
Estimate the encoded data size for this Cell.abstract Context
Executes this op with the given context.byte
getTag()
Gets the tag byte for this cell.final AType
getType()
Gets the most specific known runtime Type for this Cell.boolean
Returns true if this Cell is in a canonical representation for message writing.final boolean
Returns true if this Cell represents a first class CVM Value.abstract byte
opCode()
Returns the opcode for this opConverts this Cell to its canonical version.updateRefs
(IRefFunction func) Updates all Refs in this object using the given function.Methods inherited from class convex.core.data.ACell
announce, announce, attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createAnnounced, createEncoding, createPersisted, createPersisted, createRef, equals, equals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getRef, getRef, getRefCount, hashCode, isCompletelyEncoded, isEmbedded, mark, mark, toCVMString, toString, validate, validateCell
Methods inherited from class convex.core.data.AObject
attachEncoding, print, print, print
-
Constructor Details
-
AOp
public AOp()
-
-
Method Details
-
execute
Executes this op with the given context. Must preserve depth unless an exceptional is returned.- Parameters:
context
- Initial Context- Returns:
- The updated Context after executing this operation
-
getType
Description copied from class:ACell
Gets the most specific known runtime Type for this Cell. -
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 highly likely to contain the entire object when encoded, including the tag byte. Should not traverse soft Refs, i.e. must be usable on arbitrary partial data structures- 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 representation for message writing. Non-canonical objects may be used on a temporary internal basis, they must always be converted to canonical representations for external use (e.g. Encoding).- Specified by:
isCanonical
in classACell
- Returns:
- true if the object is in canonical format, false otherwise
-
toCanonical
Description copied from class:ACell
Converts this Cell to its canonical version. Must return this Cell if already canonical, may be O(n) in size of value otherwise.- Specified by:
toCanonical
in classACell
- Returns:
- Canonical version of Cell
-
isCVMValue
public final boolean isCVMValue()Description copied from class:ACell
Returns true if this Cell represents a first class CVM Value. Sub-structural cells that are not themselves first class values should return false, pretty much everything else should return true. Note: CVM values might not be in a canonical format, e.g. temporary data structures- Specified by:
isCVMValue
in classACell
- 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. Cell must be canonical, or else an error may occur.- Specified by:
encode
in interfaceIWriteable
- Specified by:
encode
in classACell
- Parameters:
bs
- A byte array to which to write the encodingpos
- 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. -
updateRefs
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. The implementation *should* re-attach any original encoding in order to prevent re-encoding or surplus hashing 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 classACell
- 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 equal to the first byte of the Cell's canonical Encoding, and is sufficient to distinguish how to read the rest of the encoding.
-