compiler/vm/vmmemory

    Dark Mode
Search:
  Source   Edit

This module implements the allocator and also contains routines for working with handles.

Types

DerefFailureCode = enum
  dfcNil,                   ## nil-access
  dfcInvalid,               ## not a valid ref
  dfcFreed,                 ## ref's target was already freed
  dfcTypeMismatch            ## ref's type is not compatible with the target's type
  Source   Edit

Consts

FailureCodeToEvent = [vmEvtNilAccess, vmEvtAccessOutOfBounds,
                      vmEvtAccessOutOfBounds, vmEvtAccessTypeMismatch]
  Source   Edit

Procs

func allocConstantLocation(a: var VmAllocator; typ: PVmType): LocHandle {.
    ...raises: [], tags: [].}
  Source   Edit
func allocLocationMemory(a: var VmAllocator; len: Natural): CellId {.used,
    ...raises: [], tags: [].}
  Source   Edit
func allocSingleLocation(a: var VmAllocator; typ: PVmType): LocHandle {.
    ...raises: [], tags: [].}
  Source   Edit
func allocTypedLocations(a: var VmAllocator; typ: PVmType;
                         count, lenInBytes: Natural): CellPtr {....raises: [],
    tags: [].}
  Source   Edit
func dealloc(a: var VmAllocator; c: CellId) {....raises: [], tags: [].}
Frees the cell's memory and marks the cell slot as empty. c is required to name a valid non-empty cell   Source   Edit
func dealloc(a: var VmAllocator; handle: LocHandle) {.inline, ...raises: [],
    tags: [].}
Deallocates the valid cell handle references.   Source   Edit
func dealloc(a: var VmAllocator; p: CellPtr) {....raises: [], tags: [].}
Deallocates the cell indicated by the valid cell pointer p. A nil pointer is ignored.   Source   Edit
func deref(handle: LocHandle): ptr Atom {.inline, ...raises: [], tags: [].}
  Source   Edit
func getFieldHandle(h: LocHandle; idx: FieldIndex): LocHandle {.inline,
    ...raises: [], tags: [].}
  Source   Edit
func getFieldHandle(loc: LocHandle; pos: FieldPosition): LocHandle {....raises: [],
    tags: [].}
Creates a handle to the field with position pos of the object at location h   Source   Edit
func getUsedMem(a: VmAllocator): uint {....raises: [], tags: [].}
Calculates and returns the combined size-in-bytes of all current allocations   Source   Edit
func heapDecRef(heap: var VmHeap; a: var VmAllocator; slot: HeapSlotHandle) {.
    ...raises: [], tags: [].}
Decrements the ref-counter for the given slot (expected to be valid). If the counter reaches zero, the slot is added to the list of slots pending clean-up   Source   Edit
func heapIncRef(heap: var VmHeap; slot: HeapSlotHandle) {....raises: [], tags: [].}
Increments the ref-counter for the given slot (expected to be valid)   Source   Edit
func heapNew(heap: var VmHeap; a: var VmAllocator; typ: PVmType): HeapSlotHandle {.
    ...raises: [], tags: [].}
Creates a new managed slot of type typ and sets the ref-count to 1   Source   Edit
func isValid(heap: VmHeap; slot: HeapSlotHandle): bool {....raises: [], tags: [].}
Tests if slot is valid. A HeapSlotHandle is valid if it references an existing slot that is not empty or awaiting clean-up   Source   Edit
func loadFullSlice(a: VmAllocator; cp: CellPtr; typ: PVmType): VmSlice {.
    ...raises: [], tags: [].}
Attempts to create and returns a slice with item type typ covering all locations of the sequence cell corresponding to cp. Returns a slice signaling invalid if that's not possible.   Source   Edit
func makeLocHandle(a: VmAllocator; cp: CellPtr; offset: Natural; typ: PVmType): LocHandle {.
    ...raises: [], tags: [].}
Attempts to create a handle to an interior location of the cell coressponding to cp. If cp is not a valid cell pointer, a handle that signals "invalid" is returned.   Source   Edit
func makeLocHandle(a: VmAllocator; p: pointer; typ: PVmType): LocHandle {.
    ...raises: [], tags: [].}
Attempts to create a handle to the guest memory location that to host address p maps to. A handle signaling "invalid" is returned if no mapping exists.   Source   Edit
func mapPointerToCell(a: VmAllocator; p: CellPtr): CellId {....raises: [], tags: [].}
Maps a cell pointer to the corresponding cell id, or -1 if the pointer is not a valid cell pointer.   Source   Edit
func mapToCell(a: VmAllocator; p: CellPtr): lent VmCell {....raises: [], tags: [].}
  Source   Edit
func subLocation(h: LocHandle; offset: Natural; typ: PVmType): LocHandle {.
    inline, ...raises: [], tags: [].}
Creates a handle to the interior location located at the relative offset, using typ for the handle's type.   Source   Edit
func tryDeref(heap: VmHeap; slot: HeapSlotHandle): Option[LocHandle] {.
    ...raises: [], tags: [].}
Tries to retrieve the managed location's handle. Returns the handle on success, or none if slot doesn't reference a valid slot   Source   Edit
func tryDeref(heap: VmHeap; slot: HeapSlotHandle; typ: PVmType): Result[
    LocHandle, DerefFailureCode] {....raises: [], tags: [].}
Tries to load the managed location's handle. If typ is not nil, the location's type must be either the same or a sub-type of typ. If the type check fails or if slot doesn't reference a valid slot, the failure code is returned. Otherwise, a handle to the location is returned   Source   Edit
func unsafeDeref(heap: VmHeap; slot: HeapSlotHandle): LocHandle {....raises: [],
    tags: [].}
Retrieves the managed location's handle without safety checks. Only use this if you're sure that slot is valid   Source   Edit

Templates

template `[]`[T](p: VmMemPointer | CellPtr; s: Slice[T]): untyped
  Source   Edit
template byteView(c: VmCell): untyped
  Source   Edit
template byteView(handle: LocHandle): untyped
  Source   Edit
template byteView(slice: VmSlice): untyped
  Source   Edit
template slice(p: VmMemPointer | CellPtr; len: Natural): untyped
  Source   Edit
template slice(p: VmMemPointer | CellPtr; offset, len: Natural): untyped
  Source   Edit