compiler/vm/vmobjects

    Dark Mode
Search:
  Source   Edit

This module contains procedures for interacting with locations.

Types

VariantFieldIterCtx = object
  i, L: int
  last, nextDiscField: FieldIndex
  bI: uint32                 ## index of the current walk-list entry
  
The state for the variant field iterator. Before calling get or next for the first time, the iterator has to be set up with setup   Source   Edit

Procs

func `$`(s: VmString): string {....raises: [], tags: [].}
  Source   Edit
func `<=`(a, b: VmString): bool {....raises: [], tags: [].}
  Source   Edit
func `<`(a, b: VmString): bool {....raises: [], tags: [].}
  Source   Edit
func `==`(a, b: VmString): bool {....raises: [], tags: [].}
  Source   Edit
func `==`(a: VmString; b: openArray[char]): bool {....raises: [], tags: [].}
  Source   Edit
func `>=`(a, b: VmString): bool {....raises: [], tags: [].}
  Source   Edit
func `>`(a, b: VmString): bool {....raises: [], tags: [].}
  Source   Edit
func `[]=`(s: var VmString; i: Natural; c: char) {....raises: [], tags: [].}
Set the char at index i. Doesn't do any validation or index checking. The caller is expected to take care of that   Source   Edit
func `[]`(s: VmSlice; i: Natural): LocHandle {....raises: [], tags: [].}
Creates a LocHandle to the i-th element of the slice s   Source   Edit
func `[]`(s: VmString; i: Natural): char {....raises: [], tags: [].}
Return the char at index i. Doesn't perform any validation or index checking -- the caller is expected to take care of that.   Source   Edit
func add(s: var string; str: VmString) {....raises: [], tags: [].}
  Source   Edit
func add(s: var VmString; c: char; mm: var VmAllocator) {....raises: [], tags: [].}
  Source   Edit
func add(s: var VmString; chars: openArray[char]; mm: var VmAllocator) {.
    ...raises: [], tags: [].}
  Source   Edit
func add(s: var VmString; str: VmString; mm: var VmAllocator) {....raises: [],
    tags: [].}
  Source   Edit
proc arrayCopy(mm: var VmMemoryManager; dest: var VmMemoryRegion;
               src: VmMemoryRegion; count: Natural; elemTyp: PVmType;
               reset: static[bool])
Copies (via assignment) all items from src[0..count-1] to dest[0..count-1]   Source   Edit
func arrayLen(loc: LocHandle): int {....raises: [], tags: [].}
Returns the number of items of the array-like at loc   Source   Edit
func asCString(s: VmString): cstring {....raises: [], tags: [].}
Returns a cstring that is a direct view into the vm string's backing memory   Source   Edit
func asgnRef(dst: var HeapSlotHandle; src: HeapSlotHandle;
             mm: var VmMemoryManager; reset: static[bool])
  Source   Edit
func asgnVmString(dest: var VmString; src: VmString; a: var VmAllocator) {.
    ...raises: [], tags: [].}
  Source   Edit
func cmp(a, b: VmString): int {....raises: [], tags: [].}
  Source   Edit
proc copyToLocation(mm: var VmMemoryManager; dest: var VmMemoryRegion;
                    src: VmMemoryRegion; typ: PVmType;
                    reset: static[bool] = true)
Copies the data at src to dest. This is equivalent to an assignment in user-code. reset indicates whether dest is in an initial zero state (false) or already contains valid data (true).Deep-copy the value with type typ at location src to dest. The source and destination location must not overlap in memory   Source   Edit
proc copyVmSeq(dest: var VmSeq; src: VmSeq; typ: PVmType;
               mm: var VmMemoryManager) {....raises: [Exception],
    tags: [RootEffect].}
  Source   Edit
func get(ctx: VariantFieldIterCtx): tuple[valid: bool, idx: FieldIndex] {.
    ...raises: [], tags: [].}
Returns the current field index (or 0) and whether iteration is finished   Source   Edit
func getItemHandle(loc: LocHandle; index: Natural; a: VmAllocator): LocHandle {.
    ...raises: [], tags: [].}
Creates a handle to the item at index for the array-like at loc   Source   Edit
func getItemHandle(s: VmSeq; typ: PVmType; index: Natural; a: VmAllocator): LocHandle {.
    inline, ...raises: [], tags: [].}
Creates a handle to the seq item at index   Source   Edit
func growBy(s: var VmSeq; typ: PVmType; num: Natural; mm: var VmMemoryManager) {.
    inline, ...raises: [], tags: [].}
  Source   Edit
func newVmSeq(s: var VmSeq; typ: PVmType; numItems: Natural;
              mm: var VmMemoryManager) {....raises: [Exception], tags: [RootEffect].}
  Source   Edit
func newVmString(s: var VmString; numElements: Natural; a: var VmAllocator) {.
    ...raises: [], tags: [].}
  Source   Edit
func newVmString(s: var VmString; src: openArray[char]; a: var VmAllocator) {.
    ...raises: [], tags: [].}
  Source   Edit
func next(ctx: var VariantFieldIterCtx; src: VmMemoryRegion; typ: PVmType) {.
    ...raises: [], tags: [].}
Moves the iterator to the next active field, or does nothing if no more active fields are left. The fields are iterated in ascending index order but excludes fields of base types (if there exists a base type). typ must be the same match the type passed to setup   Source   Edit
func packDiscr(value, index, numBits: Natural): int {....raises: [], tags: [].}
Packs the discriminator value and branch index into a combined value   Source   Edit
func readDiscrBranch(loc: LocHandle; owner: PVmType; idx: FieldIndex): int {.
    ...raises: [], tags: [].}
Reads the discriminator value from loc and extracts/translates the branch index   Source   Edit
func readDiscriminant(h: LocHandle): BiggestInt {.inline, ...raises: [], tags: [].}
  Source   Edit
func readDiscriminant(h: VmMemoryRegion; numBits: Natural): BiggestInt {.inline,
    ...raises: [], tags: [].}
  Source   Edit
func readFloat(m: VmMemoryRegion): BiggestFloat {.inline, ...raises: [], tags: [].}
  Source   Edit
func readFloat32(m: VmMemoryRegion): BiggestFloat {.inline, ...raises: [], tags: [].}
  Source   Edit
func readFloat64(m: VmMemoryRegion): BiggestFloat {.inline, ...raises: [], tags: [].}
  Source   Edit
func readIntBits(r: VmMemoryRegion): BiggestInt {.inline, ...raises: [], tags: [].}
  Source   Edit
func readUInt(r: VmMemoryRegion): BiggestInt {.inline, ...raises: [], tags: [].}
Since uints are mostly stored as BiggestInt inside the compiler/VM, they're returned as BiggestInt here too.   Source   Edit
proc resetBranch(mm: var VmMemoryManager; h: LocHandle; idx: FieldIndex;
                 branch: int) {....raises: [Exception], tags: [RootEffect].}
Cleanup the given branch of the discriminator at fieldIndex. branch must be equal to the currently active branch (not enforced, so watch out)   Source   Edit
func resetLocation(mm: var VmMemoryManager; loc: var VmMemoryRegion;
                   typ: PVmType) {....raises: [Exception], tags: [RootEffect].}
If the given location is a managed atomic location, cleans up and frees any auxiliary memory. If the location is a compound location, recursively cleans up all managed sub-locations   Source   Edit
func setLen(s: var VmString; newLen: Natural; a: var VmAllocator) {....raises: [],
    tags: [].}
Truncates or extends the length of s to newLen   Source   Edit
func setLenSeq(s: var VmSeq; typ: PVmType; len: int; mm: var VmMemoryManager) {.
    ...raises: [Exception], tags: [RootEffect].}
  Source   Edit
func setup(ctx: var VariantFieldIterCtx; typ: PVmType; branch: uint32) {.
    ...raises: [], tags: [].}
Initializes the iterator state. branch is the walk-list entry index of the branch that is to be iterated   Source   Edit
func toSlice(loc: LocHandle): VmSlice {....raises: [], tags: [].}
Creates a VmSlice view for the array location loc   Source   Edit
func toSlice(s: VmSeq; elemTyp: PVmType; a: VmAllocator): VmSlice {....raises: [],
    tags: [].}
Creates a VmSlice view for all elements in the seq s   Source   Edit
func unpackDiscr(v: BiggestInt; numBits: Natural): tuple[value: int, index: int] {.
    inline, ...raises: [], tags: [].}
Extracts the discriminator value and branch index from the combined value   Source   Edit
proc writeDiscrField(loc: LocHandle; owner: PVmType; idx: FieldIndex;
                     value, index: Natural) {....raises: [], tags: [].}

Writes the discriminator to loc.

owner refers to the type of the object the field is part of. idx is the field's index.

  Source   Edit
func writeFloat(h: LocHandle; f: BiggestFloat) {.inline, ...raises: [], tags: [].}
Write the float to the location. Converts the float to the locations size prior to writing   Source   Edit
func writeFloat32(h: LocHandle; f: float32) {.inline, ...raises: [], tags: [].}
  Source   Edit
func writeFloat32(h: VmMemPointer; f: float32) {.inline, ...raises: [], tags: [].}
  Source   Edit
func writeFloat64(h: LocHandle; f: float64) {.inline, ...raises: [], tags: [].}
  Source   Edit
func writeFloat64(h: VmMemPointer; f: float64) {.inline, ...raises: [], tags: [].}
  Source   Edit
func writeInt(r: var VmMemoryRegion; val: BiggestInt) {.inline, ...raises: [],
    tags: [].}
  Source   Edit
func writeUInt(h: LocHandle; val: BiggestInt) {.inline, ...raises: [], tags: [].}
  Source   Edit
func writeUInt(r: var VmMemoryRegion; val: BiggestInt) {.inline, ...raises: [],
    tags: [].}
  Source   Edit

Iterators

iterator variantFieldIndices(src: VmMemoryRegion; typ: PVmType;
                             branch: uint32 = 0'u32): FieldIndex {....raises: [],
    tags: [].}
Iterates over the active fields (excluding base type fields) of the object at location src. The iterator supports changing active branches via discriminator updates on-the-fly, but only the one at the currently yielded field index.   Source   Edit
iterator variantFields(src: VmMemoryRegion; typ: PVmType; branch: uint32 = 0'u32): (
    int, PVmType) {....raises: [], tags: [].}
Similar to variantFieldIndices, but yields the (offset, type) pair instead of the index   Source   Edit

Templates

template `==`(a, b: VmFunctionPtr): bool
  Source   Edit
template bitSet(handle: LocHandle): untyped
Get a view to the set value stored in the location at handle   Source   Edit
template mbitSet(handle: LocHandle): untyped
Get a mutable view to the set value stored in the location at handle   Source   Edit
template signExtended(val, size: BiggestInt): untyped
Calculates sign-extended x without branching. size is the number of bytes val occupies.   Source   Edit