Package convex.core.lang.ops
Class Let<T extends ACell>
java.lang.Object
convex.core.data.AObject
convex.core.data.ACell
convex.core.lang.AOp<T>
convex.core.lang.ops.AMultiOp<T>
convex.core.lang.ops.Let<T>
- Type Parameters:
T
- Result type of Op
- All Implemented Interfaces:
IValidated
,IWriteable
Op for executing a body after lexically binding one or more symbols.
Can represent (let [..] ..) and (loop [..] ..).
Loop version can act as a target for (recur ...) expressions.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final int
protected final boolean
Vector of binding forms.Fields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
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.Executes this op with the given context.executeBody
(Context ctx) getRef
(int i) Gets a numbered child Ref from within this Cell.int
Gets the number of Refs contained within this Cell.byte
opCode()
Returns the opcode for this opboolean
print
(BlobBuilder bb, long limit) Prints this Object to a readable String Representation.Read a Let Op from a Blob encodingRecreates this object with an updated list of child Ops.updateRefs
(IRefFunction func) Updates all Refs in this object using the given function.Methods inherited from class convex.core.lang.ops.AMultiOp
validateCell
Methods inherited from class convex.core.lang.AOp
encode, getTag, getType, isCanonical, isCVMValue, toCanonical
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, hashCode, isCompletelyEncoded, isEmbedded, mark, mark, toCVMString, toString, validate
Methods inherited from class convex.core.data.AObject
attachEncoding, print, print
-
Field Details
-
symbols
Vector of binding forms. Can be destructuring forms -
bindingCount
protected final int bindingCount -
isLoop
protected final boolean isLoop
-
-
Constructor Details
-
Let
-
-
Method Details
-
create
-
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 classAMultiOp<T extends ACell>
- Parameters:
func
- Ref update function- Returns:
- Cell with updated Refs
-
getRefCount
public int getRefCount()Description copied from class:ACell
Gets the number of Refs contained within this Cell. This number is final / immutable for any given instance and is defined by the Cell encoding rules. WARNING: may not be valid id Cell is not canonical Contained Refs may be either external or embedded.- Overrides:
getRefCount
in classAMultiOp<T extends ACell>
- Returns:
- The number of Refs in this Cell
-
getRef
Description copied from class:ACell
Gets a numbered child Ref from within this Cell. WARNING: May be unreliable is cell is not canonical -
recreate
Description copied from class:AMultiOp
Recreates this object with an updated list of child Ops. -
recreate
-
execute
Description copied from class:AOp
Executes this op with the given context. Must preserve depth unless an exceptional is returned. -
executeBody
-
print
Description copied from class:AObject
Prints this Object to a readable String Representation. SECURITY: Must halt and return false in O(1) time when limit of printing is exceeded otherwise DoS attacks may be possible. -
opCode
public byte opCode()Description copied from class:AOp
Returns the opcode for this op -
encodeRaw
public int encodeRaw(byte[] bs, int pos) Description copied from class:AOp
Writes the raw data for this Op to the specified bytebuffer. Assumes Op tag and opcode already written. -
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- Specified by:
estimatedEncodingSize
in interfaceIWriteable
- Overrides:
estimatedEncodingSize
in classAMultiOp<T extends ACell>
- Returns:
- The estimated size for the binary representation of this object.
-
read
public static <T extends ACell> Let<T> read(Blob b, int pos, boolean isLoop) throws BadFormatException Read a Let Op from a Blob encoding- Parameters:
b
- Blob to read frompos
- Start position in Blob (location of tag byte)isLoop
- Indicates if the Op should be considered a loop target- Returns:
- New decoded instance
- Throws:
BadFormatException
- In the event of any encoding error
-