This module contains the type definitions for the new evaluation engine. An instruction is 1-3 int32s in memory, it is a register based VM.
Types
PProc = ref object blocks*: seq[TBlock] sym*: PSym regInfo*: seq[tuple[inUse: bool, kind: TSlotKind]]
- Source Edit
Profiler = object tEnter*: float tos*: PStackFrame
- Source Edit
PStackFrame = ref TStackFrame
- Source Edit
TCtx = object of TPassContext code*: seq[TInstr] debug*: seq[TLineInfo] globals*: PNode constants*: PNode types*: seq[PType] currentExceptionA*, currentExceptionB*: PNode exceptionInstr*: int prc*: PProc module*: PSym callsite*: PNode mode*: TEvalMode features*: TSandboxFlags traceActive*: bool loopIterations*: int comesFromHeuristic*: TLineInfo callbacks*: seq[VmCallback] callbackIndex*: Table[string, int] errorFlag*: string cache*: IdentCache config*: ConfigRef graph*: ModuleGraph oldErrorCount*: int profiler*: Profiler templInstCounter*: ref int vmstateDiff*: seq[(PSym, PNode)] procToCodePos*: Table[int, int] cannotEval*: bool
- Source Edit
TEvalMode = enum emRepl, ## evaluate because in REPL mode emConst, ## evaluate for 'const' according to spec emOptimize, ## evaluate for optimization purposes (same as ## emConst?) emStaticExpr, ## evaluate for enforced compile time eval ## ('static' context) emStaticStmt ## 'static' as an expression
- reason for evaluation Source Edit
TFullReg = object case kind*: TRegisterKind of rkNone: nil of rkInt: intVal*: BiggestInt of rkFloat: floatVal*: BiggestFloat of rkNode: node*: PNode of rkRegisterAddr: regAddr*: ptr TFullReg of rkNodeAddr: nodeAddr*: ptr PNode
- Source Edit
TInstr = distinct TInstrType
- Source Edit
TInstrType = uint64
- Source Edit
TOpcode = enum opcEof, opcRet, opcYldYoid, opcYldVal, opcAsgnInt, opcAsgnFloat, opcAsgnRef, opcAsgnComplex, opcCastIntToFloat32, opcCastIntToFloat64, opcCastFloatToInt32, opcCastFloatToInt64, opcCastPtrToInt, opcCastIntToPtr, opcFastAsgnComplex, opcNodeToReg, opcLdArr, opcLdArrAddr, opcWrArr, opcLdObj, opcLdObjAddr, opcWrObj, opcAddrReg, opcAddrNode, opcLdDeref, opcWrDeref, opcWrStrIdx, opcLdStrIdx, opcLdStrIdxAddr, opcSlice, opcAddInt, opcAddImmInt, opcSubInt, opcSubImmInt, opcLenSeq, opcLenStr, opcLenCstring, opcIncl, opcInclRange, opcExcl, opcCard, opcMulInt, opcDivInt, opcModInt, opcAddFloat, opcSubFloat, opcMulFloat, opcDivFloat, opcShrInt, opcShlInt, opcAshrInt, opcBitandInt, opcBitorInt, opcBitxorInt, opcAddu, opcSubu, opcMulu, opcDivu, opcModu, opcEqInt, opcLeInt, opcLtInt, opcEqFloat, opcLeFloat, opcLtFloat, opcLeu, opcLtu, opcEqRef, opcEqNimNode, opcSameNodeType, opcXor, opcNot, opcUnaryMinusInt, opcUnaryMinusFloat, opcBitnotInt, opcEqStr, opcEqCString, opcLeStr, opcLtStr, opcEqSet, opcLeSet, opcLtSet, opcMulSet, opcPlusSet, opcMinusSet, opcXorSet, opcConcatStr, opcContainsSet, opcRepr, opcSetLenStr, opcSetLenSeq, opcIsNil, opcOf, opcIs, opcParseFloat, opcConv, opcCast, opcQuit, opcInvalidField, opcNarrowS, opcNarrowU, opcSignExtend, opcAddStrCh, opcAddStrStr, opcAddSeqElem, opcRangeChck, opcNAdd, opcNAddMultiple, opcNKind, opcNSymKind, opcNIntVal, opcNFloatVal, opcNSymbol, opcNIdent, opcNGetType, opcNStrVal, opcNSigHash, opcNGetSize, opcNSetIntVal, opcNSetFloatVal, opcNSetSymbol, opcNSetIdent, opcNSetStrVal, opcNNewNimNode, opcNCopyNimNode, opcNCopyNimTree, opcNDel, opcGenSym, opcNccValue, opcNccInc, opcNcsAdd, opcNcsIncl, opcNcsLen, opcNcsAt, opcNctPut, opcNctLen, opcNctGet, opcNctHasNext, opcNctNext, opcNodeId, opcSlurp, opcGorge, opcParseExprToAst, opcParseStmtToAst, opcQueryErrorFlag, opcNError, opcNWarning, opcNHint, opcNGetLineInfo, opcNCopyLineInfo, opcNSetLineInfoLine, opcNSetLineInfoColumn, opcNSetLineInfoFile, opcEqIdent, opcStrToIdent, opcGetImpl, opcGetImplTransf, opcEcho, opcIndCall, opcIndCallAsgn, opcRaise, opcNChild, opcNSetChild, opcCallSite, opcNewStr, opcTJmp, opcFJmp, opcJmp, opcJmpBack, opcBranch, opcTry, opcExcept, opcFinally, opcFinallyEnd, opcNew, opcNewSeq, opcLdNull, opcLdNullReg, opcLdConst, opcAsgnConst, opcLdGlobal, opcLdGlobalAddr, opcLdGlobalDerefFFI, opcLdGlobalAddrDerefFFI, opcLdImmInt, opcNBindSym, opcNDynBindSym, opcSetType, opcTypeTrait, opcSymOwner, opcSymIsInstantiationOf
- Source Edit
TRegisterKind = enum rkNone, rkNode, rkInt, rkFloat, rkRegisterAddr, rkNodeAddr
- Source Edit
TSandboxFlag = enum allowCast, ## allow unsafe language feature: 'cast' allowInfiniteLoops ## allow endless loops
- what the evaluation engine should allow Source Edit
TSandboxFlags = set[TSandboxFlag]
- Source Edit
TSlotKind = enum slotEmpty, slotFixedVar, slotFixedLet, slotTempUnknown, slotTempInt, slotTempFloat, slotTempStr, slotTempComplex, slotTempPerm
- Source Edit
TStackFrame {.acyclic.} = object prc*: PSym slots*: seq[TFullReg] next*: PStackFrame comesFrom*: int safePoints*: seq[int]
- Source Edit
VmArgs = object ra*, rb*, rc*: Natural = 0 slots*: ptr UncheckedArray[TFullReg] currentException*: PNode currentLineInfo*: TLineInfo
- Source Edit
VmCallback = proc (args: VmArgs) {.closure.}
- Source Edit
Consts
byteExcess = 128
- Source Edit
firstABxInstr = opcTJmp
- Source Edit
largeInstrs = {opcConv, opcCast, opcNewSeq, opcOf}
- Source Edit
nimNodeFlag = 16
- Source Edit
regBxShift = 24'u64
- Source Edit
relativeJumps = {opcTJmp, opcFJmp, opcJmp, opcJmpBack}
- Source Edit
slotSomeTemp = slotTempUnknown
- Source Edit
wordExcess = 8388608
- Source Edit
Procs
proc newCtx(module: PSym; cache: IdentCache; g: ModuleGraph; idgen: IdGenerator): PCtx {. ...raises: [], tags: [], forbids: [].}
- Source Edit
proc registerCallback(c: PCtx; name: string; callback: VmCallback): int {. discardable, ...raises: [], tags: [], forbids: [].}
- Source Edit