UNPKG

microvium

Version:

A compact, embeddable scripting engine for microcontrollers for executing small scripts written in a subset of JavaScript.

423 lines 24.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.mvm_TeBytecodeSection = exports.isUInt32 = exports.isSInt32 = exports.isSInt16 = exports.isUInt16 = exports.isUInt14 = exports.isSInt14 = exports.isUInt12 = exports.isUInt8 = exports.isSInt8 = exports.isUInt7 = exports.isUInt4 = exports.vm_TeWellKnownValues = exports.mvm_TeBuiltins = exports.mvm_TeType = exports.TeTypeCode = exports.mvm_TeError = exports.SInt32 = exports.SInt16 = exports.SInt14 = exports.SInt8 = exports.UInt32 = exports.UInt16 = exports.UInt14 = exports.UInt12 = exports.UInt8 = exports.UInt7 = exports.UInt4 = void 0; // Note: `runtime-types.ts` should not have any imports, because it's used by the wasm library as well const assert = (x) => { if (!x) throw new Error('Assertion failed'); }; const UInt4 = (n) => (assert(isUInt4(n)), n); exports.UInt4 = UInt4; const UInt7 = (n) => (assert(isUInt7(n)), n); exports.UInt7 = UInt7; const UInt8 = (n) => (assert(isUInt8(n)), n); exports.UInt8 = UInt8; const UInt12 = (n) => (assert(isUInt12(n)), n); exports.UInt12 = UInt12; const UInt14 = (n) => (assert(isUInt14(n)), n); exports.UInt14 = UInt14; const UInt16 = (n) => (assert(isUInt16(n)), n); exports.UInt16 = UInt16; const UInt32 = (n) => (assert(isUInt32(n)), n); exports.UInt32 = UInt32; const SInt8 = (n) => (assert(isSInt8(n)), n); exports.SInt8 = SInt8; const SInt14 = (n) => (assert(isSInt14(n)), n); exports.SInt14 = SInt14; const SInt16 = (n) => (assert(isSInt16(n)), n); exports.SInt16 = SInt16; const SInt32 = (n) => (assert(isSInt32(n)), n); exports.SInt32 = SInt32; var mvm_TeError; (function (mvm_TeError) { /* 0 */ mvm_TeError[mvm_TeError["MVM_E_SUCCESS"] = 0] = "MVM_E_SUCCESS"; /* 1 */ mvm_TeError[mvm_TeError["MVM_E_UNEXPECTED"] = 1] = "MVM_E_UNEXPECTED"; /* 2 */ mvm_TeError[mvm_TeError["MVM_E_MALLOC_FAIL"] = 2] = "MVM_E_MALLOC_FAIL"; /* 3 */ mvm_TeError[mvm_TeError["MVM_E_ALLOCATION_TOO_LARGE"] = 3] = "MVM_E_ALLOCATION_TOO_LARGE"; /* 4 */ mvm_TeError[mvm_TeError["MVM_E_INVALID_ADDRESS"] = 4] = "MVM_E_INVALID_ADDRESS"; /* 5 */ mvm_TeError[mvm_TeError["MVM_E_COPY_ACROSS_BUCKET_BOUNDARY"] = 5] = "MVM_E_COPY_ACROSS_BUCKET_BOUNDARY"; /* 6 */ mvm_TeError[mvm_TeError["MVM_E_FUNCTION_NOT_FOUND"] = 6] = "MVM_E_FUNCTION_NOT_FOUND"; /* 7 */ mvm_TeError[mvm_TeError["MVM_E_INVALID_HANDLE"] = 7] = "MVM_E_INVALID_HANDLE"; /* 8 */ mvm_TeError[mvm_TeError["MVM_E_STACK_OVERFLOW"] = 8] = "MVM_E_STACK_OVERFLOW"; /* 9 */ mvm_TeError[mvm_TeError["MVM_E_UNRESOLVED_IMPORT"] = 9] = "MVM_E_UNRESOLVED_IMPORT"; /* 10 */ mvm_TeError[mvm_TeError["MVM_E_ATTEMPT_TO_WRITE_TO_ROM"] = 10] = "MVM_E_ATTEMPT_TO_WRITE_TO_ROM"; /* 11 */ mvm_TeError[mvm_TeError["MVM_E_INVALID_ARGUMENTS"] = 11] = "MVM_E_INVALID_ARGUMENTS"; /* 12 */ mvm_TeError[mvm_TeError["MVM_E_TYPE_ERROR"] = 12] = "MVM_E_TYPE_ERROR"; /* 13 */ mvm_TeError[mvm_TeError["MVM_E_TARGET_NOT_CALLABLE"] = 13] = "MVM_E_TARGET_NOT_CALLABLE"; /* 14 */ mvm_TeError[mvm_TeError["MVM_E_HOST_ERROR"] = 14] = "MVM_E_HOST_ERROR"; /* 15 */ mvm_TeError[mvm_TeError["MVM_E_NOT_IMPLEMENTED"] = 15] = "MVM_E_NOT_IMPLEMENTED"; /* 16 */ mvm_TeError[mvm_TeError["MVM_E_HOST_RETURNED_INVALID_VALUE"] = 16] = "MVM_E_HOST_RETURNED_INVALID_VALUE"; /* 17 */ mvm_TeError[mvm_TeError["MVM_E_ASSERTION_FAILED"] = 17] = "MVM_E_ASSERTION_FAILED"; /* 18 */ mvm_TeError[mvm_TeError["MVM_E_INVALID_BYTECODE"] = 18] = "MVM_E_INVALID_BYTECODE"; /* 19 */ mvm_TeError[mvm_TeError["MVM_E_UNRESOLVED_EXPORT"] = 19] = "MVM_E_UNRESOLVED_EXPORT"; /* 20 */ mvm_TeError[mvm_TeError["MVM_E_RANGE_ERROR"] = 20] = "MVM_E_RANGE_ERROR"; /* 21 */ mvm_TeError[mvm_TeError["MVM_E_DETACHED_EPHEMERAL"] = 21] = "MVM_E_DETACHED_EPHEMERAL"; /* 22 */ mvm_TeError[mvm_TeError["MVM_E_TARGET_IS_NOT_A_VM_FUNCTION"] = 22] = "MVM_E_TARGET_IS_NOT_A_VM_FUNCTION"; /* 23 */ mvm_TeError[mvm_TeError["MVM_E_FLOAT64"] = 23] = "MVM_E_FLOAT64"; /* 24 */ mvm_TeError[mvm_TeError["MVM_E_NAN"] = 24] = "MVM_E_NAN"; /* 25 */ mvm_TeError[mvm_TeError["MVM_E_NEG_ZERO"] = 25] = "MVM_E_NEG_ZERO"; /* 26 */ mvm_TeError[mvm_TeError["MVM_E_OPERATION_REQUIRES_FLOAT_SUPPORT"] = 26] = "MVM_E_OPERATION_REQUIRES_FLOAT_SUPPORT"; /* 27 */ mvm_TeError[mvm_TeError["MVM_E_BYTECODE_CRC_FAIL"] = 27] = "MVM_E_BYTECODE_CRC_FAIL"; /* 28 */ mvm_TeError[mvm_TeError["MVM_E_BYTECODE_REQUIRES_FLOAT_SUPPORT"] = 28] = "MVM_E_BYTECODE_REQUIRES_FLOAT_SUPPORT"; /* 29 */ mvm_TeError[mvm_TeError["MVM_E_PROTO_IS_READONLY"] = 29] = "MVM_E_PROTO_IS_READONLY"; /* 30 */ mvm_TeError[mvm_TeError["MVM_E_SNAPSHOT_TOO_LARGE"] = 30] = "MVM_E_SNAPSHOT_TOO_LARGE"; /* 31 */ mvm_TeError[mvm_TeError["MVM_E_MALLOC_MUST_RETURN_POINTER_TO_EVEN_BOUNDARY"] = 31] = "MVM_E_MALLOC_MUST_RETURN_POINTER_TO_EVEN_BOUNDARY"; /* 32 */ mvm_TeError[mvm_TeError["MVM_E_ARRAY_TOO_LONG"] = 32] = "MVM_E_ARRAY_TOO_LONG"; /* 33 */ mvm_TeError[mvm_TeError["MVM_E_OUT_OF_MEMORY"] = 33] = "MVM_E_OUT_OF_MEMORY"; /* 34 */ mvm_TeError[mvm_TeError["MVM_E_TOO_MANY_ARGUMENTS"] = 34] = "MVM_E_TOO_MANY_ARGUMENTS"; /* 35 */ mvm_TeError[mvm_TeError["MVM_E_REQUIRES_LATER_ENGINE"] = 35] = "MVM_E_REQUIRES_LATER_ENGINE"; /* 36 */ mvm_TeError[mvm_TeError["MVM_E_PORT_FILE_VERSION_MISMATCH"] = 36] = "MVM_E_PORT_FILE_VERSION_MISMATCH"; /* 37 */ mvm_TeError[mvm_TeError["MVM_E_PORT_FILE_MACRO_TEST_FAILURE"] = 37] = "MVM_E_PORT_FILE_MACRO_TEST_FAILURE"; /* 38 */ mvm_TeError[mvm_TeError["MVM_E_EXPECTED_POINTER_SIZE_TO_BE_16_BIT"] = 38] = "MVM_E_EXPECTED_POINTER_SIZE_TO_BE_16_BIT"; /* 39 */ mvm_TeError[mvm_TeError["MVM_E_EXPECTED_POINTER_SIZE_NOT_TO_BE_16_BIT"] = 39] = "MVM_E_EXPECTED_POINTER_SIZE_NOT_TO_BE_16_BIT"; /* 40 */ mvm_TeError[mvm_TeError["MVM_E_TYPE_ERROR_TARGET_IS_NOT_CALLABLE"] = 40] = "MVM_E_TYPE_ERROR_TARGET_IS_NOT_CALLABLE"; /* 41 */ mvm_TeError[mvm_TeError["MVM_E_TDZ_ERROR"] = 41] = "MVM_E_TDZ_ERROR"; /* 42 */ mvm_TeError[mvm_TeError["MVM_E_MALLOC_NOT_WITHIN_RAM_PAGE"] = 42] = "MVM_E_MALLOC_NOT_WITHIN_RAM_PAGE"; /* 43 */ mvm_TeError[mvm_TeError["MVM_E_INVALID_ARRAY_INDEX"] = 43] = "MVM_E_INVALID_ARRAY_INDEX"; /* 44 */ mvm_TeError[mvm_TeError["MVM_E_UNCAUGHT_EXCEPTION"] = 44] = "MVM_E_UNCAUGHT_EXCEPTION"; /* 45 */ mvm_TeError[mvm_TeError["MVM_E_FATAL_ERROR_MUST_KILL_VM"] = 45] = "MVM_E_FATAL_ERROR_MUST_KILL_VM"; /* 46 */ mvm_TeError[mvm_TeError["MVM_E_OBJECT_KEYS_ON_NON_OBJECT"] = 46] = "MVM_E_OBJECT_KEYS_ON_NON_OBJECT"; /* 47 */ mvm_TeError[mvm_TeError["MVM_E_INVALID_UINT8_ARRAY_LENGTH"] = 47] = "MVM_E_INVALID_UINT8_ARRAY_LENGTH"; /* 48 */ mvm_TeError[mvm_TeError["MVM_E_CAN_ONLY_ASSIGN_BYTES_TO_UINT8_ARRAY"] = 48] = "MVM_E_CAN_ONLY_ASSIGN_BYTES_TO_UINT8_ARRAY"; /* 49 */ mvm_TeError[mvm_TeError["MVM_E_WRONG_BYTECODE_VERSION"] = 49] = "MVM_E_WRONG_BYTECODE_VERSION"; /* 50 */ mvm_TeError[mvm_TeError["MVM_E_USING_NEW_ON_NON_CLASS"] = 50] = "MVM_E_USING_NEW_ON_NON_CLASS"; /* 51 */ mvm_TeError[mvm_TeError["MVM_E_INSTRUCTION_COUNT_REACHED"] = 51] = "MVM_E_INSTRUCTION_COUNT_REACHED"; /* 52 */ mvm_TeError[mvm_TeError["MVM_E_REQUIRES_ACTIVE_VM"] = 52] = "MVM_E_REQUIRES_ACTIVE_VM"; /* 53 */ mvm_TeError[mvm_TeError["MVM_E_ASYNC_START_ERROR"] = 53] = "MVM_E_ASYNC_START_ERROR"; /* 54 */ mvm_TeError[mvm_TeError["MVM_E_ASYNC_WITHOUT_AWAIT"] = 54] = "MVM_E_ASYNC_WITHOUT_AWAIT"; /* 55 */ mvm_TeError[mvm_TeError["MVM_E_TYPE_ERROR_AWAIT_NON_PROMISE"] = 55] = "MVM_E_TYPE_ERROR_AWAIT_NON_PROMISE"; /* 56 */ mvm_TeError[mvm_TeError["MVM_E_HEAP_CORRUPT"] = 56] = "MVM_E_HEAP_CORRUPT"; /* 57 */ mvm_TeError[mvm_TeError["MVM_E_CLASS_PROTOTYPE_MUST_BE_NULL_OR_OBJECT"] = 57] = "MVM_E_CLASS_PROTOTYPE_MUST_BE_NULL_OR_OBJECT"; })(mvm_TeError = exports.mvm_TeError || (exports.mvm_TeError = {})); ; /** * Type code indicating the type of data. * * This enumeration is divided into reference types (TC_REF_) and value types * (TC_VAL_). Reference type codes are used on allocations, whereas value type * codes are never used on allocations. The space for the type code in the * allocation header is 4 bits, so there are up to 16 reference types and these * must be the first 16 types in the enumeration. * * The reference type range is subdivided into containers or non-containers. The * GC uses this distinction to decide whether the body of the allocation should * be interpreted as `Value`s (i.e. may contain pointers). To minimize the code, * either ALL words in a container are `Value`s, or none. * * Value types are for the values that can be represented within the 16-bit * mvm_Value without interpreting it as a pointer. */ var TeTypeCode; (function (TeTypeCode) { // Note: only type code values in the range 0-15 can be used as the types for // allocations, since the allocation header allows 4 bits for the type. Types // 0-8 are non-container types, 0xC-F are container types (9-B reserved). // Every word in a container must be a `Value`. No words in a non-container // can be a `Value` (the GC uses this to distinguish whether an allocation may // contain pointers, and the signature of each word). Note that buffer-like // types would not count as containers by this definition. /* --------------------------- Reference types --------------------------- */ // A type used during garbage collection. Allocations of this type have a // single 16-bit forwarding pointer in the allocation. TeTypeCode[TeTypeCode["TC_REF_TOMBSTONE"] = 0] = "TC_REF_TOMBSTONE"; TeTypeCode[TeTypeCode["TC_REF_INT32"] = 1] = "TC_REF_INT32"; TeTypeCode[TeTypeCode["TC_REF_FLOAT64"] = 2] = "TC_REF_FLOAT64"; /** * UTF8-encoded string that may or may not be unique. * * Note: If a TC_REF_STRING is in bytecode, it is because it encodes a value * that is illegal as a property index in Microvium (i.e. it encodes an * integer). */ TeTypeCode[TeTypeCode["TC_REF_STRING"] = 3] = "TC_REF_STRING"; /** * TC_REF_INTERNED_STRING * * A string whose address uniquely identifies its contents, and does not * encode an integer in the range 0 to 0x1FFF. * * To keep property lookup efficient, Microvium requires that strings used as * property keys can be compared using pointer equality. This requires that * there is only one instance of each of those strings (see * https://en.wikipedia.org/wiki/String_interning). * * A string with the type code TC_REF_INTERNED_STRING means that it exists in * one of the interning tables (either the one in ROM or the one in RAM). Not * all strings are interned, because it would be expensive if every string * concatenation resulted in a search of the intern table and possibly a new * entry (imagine if every JSON string landed up in the table!). * * In practice we do this: * * - All valid non-index property keys in ROM are interned. If a string is in * ROM but it is not interned, the engine can conclude that it is not a * valid property key or it is an index. * - Strings constructed in RAM are only interned when they're used to access * properties. */ TeTypeCode[TeTypeCode["TC_REF_INTERNED_STRING"] = 4] = "TC_REF_INTERNED_STRING"; TeTypeCode[TeTypeCode["TC_REF_FUNCTION"] = 5] = "TC_REF_FUNCTION"; TeTypeCode[TeTypeCode["TC_REF_HOST_FUNC"] = 6] = "TC_REF_HOST_FUNC"; TeTypeCode[TeTypeCode["TC_REF_UINT8_ARRAY"] = 7] = "TC_REF_UINT8_ARRAY"; TeTypeCode[TeTypeCode["TC_REF_SYMBOL"] = 8] = "TC_REF_SYMBOL"; /* --------------------------- Container types --------------------------- */ TeTypeCode[TeTypeCode["TC_REF_DIVIDER_CONTAINER_TYPES"] = 9] = "TC_REF_DIVIDER_CONTAINER_TYPES"; TeTypeCode[TeTypeCode["TC_REF_CLASS"] = 9] = "TC_REF_CLASS"; TeTypeCode[TeTypeCode["TC_REF_VIRTUAL"] = 10] = "TC_REF_VIRTUAL"; TeTypeCode[TeTypeCode["TC_REF_RESERVED_1"] = 11] = "TC_REF_RESERVED_1"; TeTypeCode[TeTypeCode["TC_REF_PROPERTY_LIST"] = 12] = "TC_REF_PROPERTY_LIST"; TeTypeCode[TeTypeCode["TC_REF_ARRAY"] = 13] = "TC_REF_ARRAY"; TeTypeCode[TeTypeCode["TC_REF_FIXED_LENGTH_ARRAY"] = 14] = "TC_REF_FIXED_LENGTH_ARRAY"; TeTypeCode[TeTypeCode["TC_REF_CLOSURE"] = 15] = "TC_REF_CLOSURE"; /* ----------------------------- Value types ----------------------------- */ TeTypeCode[TeTypeCode["TC_VAL_INT14"] = 16] = "TC_VAL_INT14"; TeTypeCode[TeTypeCode["TC_VAL_UNDEFINED"] = 17] = "TC_VAL_UNDEFINED"; TeTypeCode[TeTypeCode["TC_VAL_NULL"] = 18] = "TC_VAL_NULL"; TeTypeCode[TeTypeCode["TC_VAL_TRUE"] = 19] = "TC_VAL_TRUE"; TeTypeCode[TeTypeCode["TC_VAL_FALSE"] = 20] = "TC_VAL_FALSE"; TeTypeCode[TeTypeCode["TC_VAL_NAN"] = 21] = "TC_VAL_NAN"; TeTypeCode[TeTypeCode["TC_VAL_NEG_ZERO"] = 22] = "TC_VAL_NEG_ZERO"; TeTypeCode[TeTypeCode["TC_VAL_DELETED"] = 23] = "TC_VAL_DELETED"; TeTypeCode[TeTypeCode["TC_VAL_STR_LENGTH"] = 24] = "TC_VAL_STR_LENGTH"; TeTypeCode[TeTypeCode["TC_VAL_STR_PROTO"] = 25] = "TC_VAL_STR_PROTO"; /** * TC_VAL_NO_OP_FUNC * * Represents a function that does nothing and returns undefined. * * This is required by async-await for the case where you void-call an async * function and it needs to synthesize a dummy callback that does nothing, * particularly for a host async function to call back. */ TeTypeCode[TeTypeCode["TC_VAL_NO_OP_FUNC"] = 26] = "TC_VAL_NO_OP_FUNC"; TeTypeCode[TeTypeCode["TC_END"] = 27] = "TC_END"; })(TeTypeCode = exports.TeTypeCode || (exports.TeTypeCode = {})); ; var mvm_TeType; (function (mvm_TeType) { mvm_TeType[mvm_TeType["VM_T_UNDEFINED"] = 0] = "VM_T_UNDEFINED"; mvm_TeType[mvm_TeType["VM_T_NULL"] = 1] = "VM_T_NULL"; mvm_TeType[mvm_TeType["VM_T_BOOLEAN"] = 2] = "VM_T_BOOLEAN"; mvm_TeType[mvm_TeType["VM_T_NUMBER"] = 3] = "VM_T_NUMBER"; mvm_TeType[mvm_TeType["VM_T_STRING"] = 4] = "VM_T_STRING"; mvm_TeType[mvm_TeType["VM_T_FUNCTION"] = 5] = "VM_T_FUNCTION"; mvm_TeType[mvm_TeType["VM_T_OBJECT"] = 6] = "VM_T_OBJECT"; mvm_TeType[mvm_TeType["VM_T_ARRAY"] = 7] = "VM_T_ARRAY"; mvm_TeType[mvm_TeType["VM_T_UINT8_ARRAY"] = 8] = "VM_T_UINT8_ARRAY"; mvm_TeType[mvm_TeType["VM_T_CLASS"] = 9] = "VM_T_CLASS"; mvm_TeType[mvm_TeType["VM_T_SYMBOL"] = 10] = "VM_T_SYMBOL"; mvm_TeType[mvm_TeType["VM_T_BIG_INT"] = 11] = "VM_T_BIG_INT"; mvm_TeType[mvm_TeType["VM_T_END"] = 12] = "VM_T_END"; })(mvm_TeType = exports.mvm_TeType || (exports.mvm_TeType = {})); ; var mvm_TeBuiltins; (function (mvm_TeBuiltins) { mvm_TeBuiltins[mvm_TeBuiltins["BIN_INTERNED_STRINGS"] = 0] = "BIN_INTERNED_STRINGS"; mvm_TeBuiltins[mvm_TeBuiltins["BIN_ARRAY_PROTO"] = 1] = "BIN_ARRAY_PROTO"; mvm_TeBuiltins[mvm_TeBuiltins["BIN_STR_PROTOTYPE"] = 2] = "BIN_STR_PROTOTYPE"; mvm_TeBuiltins[mvm_TeBuiltins["BIN_ASYNC_CONTINUE"] = 3] = "BIN_ASYNC_CONTINUE"; mvm_TeBuiltins[mvm_TeBuiltins["BIN_ASYNC_CATCH_BLOCK"] = 4] = "BIN_ASYNC_CATCH_BLOCK"; mvm_TeBuiltins[mvm_TeBuiltins["BIN_ASYNC_HOST_CALLBACK"] = 5] = "BIN_ASYNC_HOST_CALLBACK"; mvm_TeBuiltins[mvm_TeBuiltins["BIN_PROMISE_PROTOTYPE"] = 6] = "BIN_PROMISE_PROTOTYPE"; mvm_TeBuiltins[mvm_TeBuiltins["BIN_BUILTIN_COUNT"] = 7] = "BIN_BUILTIN_COUNT"; })(mvm_TeBuiltins = exports.mvm_TeBuiltins || (exports.mvm_TeBuiltins = {})); ; var vm_TeWellKnownValues; (function (vm_TeWellKnownValues) { vm_TeWellKnownValues[vm_TeWellKnownValues["VM_VALUE_UNDEFINED"] = 1] = "VM_VALUE_UNDEFINED"; vm_TeWellKnownValues[vm_TeWellKnownValues["VM_VALUE_NULL"] = 5] = "VM_VALUE_NULL"; vm_TeWellKnownValues[vm_TeWellKnownValues["VM_VALUE_TRUE"] = 9] = "VM_VALUE_TRUE"; vm_TeWellKnownValues[vm_TeWellKnownValues["VM_VALUE_FALSE"] = 13] = "VM_VALUE_FALSE"; vm_TeWellKnownValues[vm_TeWellKnownValues["VM_VALUE_NAN"] = 17] = "VM_VALUE_NAN"; vm_TeWellKnownValues[vm_TeWellKnownValues["VM_VALUE_NEG_ZERO"] = 21] = "VM_VALUE_NEG_ZERO"; vm_TeWellKnownValues[vm_TeWellKnownValues["VM_VALUE_DELETED"] = 25] = "VM_VALUE_DELETED"; vm_TeWellKnownValues[vm_TeWellKnownValues["VM_VALUE_STR_LENGTH"] = 29] = "VM_VALUE_STR_LENGTH"; vm_TeWellKnownValues[vm_TeWellKnownValues["VM_VALUE_STR_PROTO"] = 33] = "VM_VALUE_STR_PROTO"; vm_TeWellKnownValues[vm_TeWellKnownValues["VM_VALUE_NO_OP_FUNC"] = 37] = "VM_VALUE_NO_OP_FUNC"; vm_TeWellKnownValues[vm_TeWellKnownValues["VM_VALUE_WELLKNOWN_END"] = 38] = "VM_VALUE_WELLKNOWN_END"; })(vm_TeWellKnownValues = exports.vm_TeWellKnownValues || (exports.vm_TeWellKnownValues = {})); ; function isUInt4(value) { return (value | 0) === value && value >= 0 && value <= 0xF; } exports.isUInt4 = isUInt4; function isUInt7(value) { return (value | 0) === value && value >= 0 && value <= 0x7F; } exports.isUInt7 = isUInt7; function isSInt8(value) { return (value | 0) === value && value >= -0x80 && value <= 0x7F; } exports.isSInt8 = isSInt8; function isUInt8(value) { return (value | 0) === value && value >= 0 && value <= 0xFF; } exports.isUInt8 = isUInt8; function isUInt12(value) { return (value | 0) === value && value >= 0 && value <= 0xFFF; } exports.isUInt12 = isUInt12; function isSInt14(value) { return (value | 0) === value && value >= -0x2000 && value <= 0x1FFF; } exports.isSInt14 = isSInt14; function isUInt14(value) { return (value | 0) === value && value >= 0x0000 && value <= 0x3FFF; } exports.isUInt14 = isUInt14; function isUInt16(value) { return (value | 0) === value && value >= 0 && value <= 0xFFFF; } exports.isUInt16 = isUInt16; function isSInt16(value) { return (value | 0) === value && value >= -0x8000 && value <= 0x7FFF; } exports.isSInt16 = isSInt16; function isSInt32(value) { return (value | 0) === value; } exports.isSInt32 = isSInt32; function isUInt32(value) { return typeof value === 'number' && Math.round(value) === value && value >= 0 && value <= 4294967295; } exports.isUInt32 = isUInt32; // These sections appear in the bytecode in the order they appear in this // enumeration. var mvm_TeBytecodeSection; (function (mvm_TeBytecodeSection) { /** * Import Table * * List of host function IDs (vm_TsImportTableEntry) which are called by the * VM. References from the VM to host functions are represented as indexes * into this table. These IDs are resolved to their corresponding host * function pointers when a VM is restored. */ mvm_TeBytecodeSection[mvm_TeBytecodeSection["BCS_IMPORT_TABLE"] = 0] = "BCS_IMPORT_TABLE"; /** * A list of immutable `vm_TsExportTableEntry` that the VM exports, mapping * export IDs to their corresponding VM Value. Mostly these values will just * be function pointers. */ // TODO: We need to test what happens if we export numbers and objects mvm_TeBytecodeSection[mvm_TeBytecodeSection["BCS_EXPORT_TABLE"] = 1] = "BCS_EXPORT_TABLE"; /** * Short Call Table. Table of vm_TsShortCallTableEntry. * * To make the representation of function calls in IL more compact, up to 256 * of the most frequent function calls are listed in this table, including the * function target and the argument count. * * See `LBL_CALL_SHORT` */ mvm_TeBytecodeSection[mvm_TeBytecodeSection["BCS_SHORT_CALL_TABLE"] = 2] = "BCS_SHORT_CALL_TABLE"; /** * Builtins * * See `mvm_TeBuiltins` * * Table of `Value`s that need to be directly identifiable by the engine, such * as the Array prototype. * * These are not copied into RAM, they are just constant values like the * exports, but like other values in ROM they are permitted to hold mutable * values by pointing (as BytecodeMappedPtr) to the corresponding global * variable slot. * * Note: at one point, I had these as single-byte offsets into the global * variable space, but this made the assumption that all accessible builtins * are also mutable, which is probably not true. The new design makes the * opposite assumption: most builtins will be immutable at runtime (e.g. * nobody changes the array prototype), so they can be stored in ROM and * referenced by immutable Value pointers, making them usable but not * consuming RAM at all. It's the exception rather than the rule that some of * these may be mutable and require indirection through the global slot table. */ mvm_TeBytecodeSection[mvm_TeBytecodeSection["BCS_BUILTINS"] = 3] = "BCS_BUILTINS"; /** * Interned Strings Table * * To keep property lookup efficient, Microvium requires that strings used as * property keys can be compared using pointer equality. This requires that * there is only one instance of each string (see * https://en.wikipedia.org/wiki/String_interning). This table is the * alphabetical listing of all the strings in ROM (or at least, all those * which are valid property keys). See also TC_REF_INTERNED_STRING. * * There may be two string tables: one in ROM and one in RAM. The latter is * required in general if the program might use arbitrarily-computed strings * as property keys. For efficiency, the ROM string table is contiguous and * sorted, to allow for binary searching, while the RAM string table is a * linked list for efficiency in appending (expected to be used only * occasionally). */ mvm_TeBytecodeSection[mvm_TeBytecodeSection["BCS_STRING_TABLE"] = 4] = "BCS_STRING_TABLE"; /** * Functions and other immutable data structures. * * While the whole bytecode is essentially "ROM", only this ROM section * contains addressable allocations. */ mvm_TeBytecodeSection[mvm_TeBytecodeSection["BCS_ROM"] = 5] = "BCS_ROM"; /** * Globals * * One `Value` entry for the initial value of each global variable. The number * of global variables is determined by the size of this section. * * This section will be copied into RAM at startup (restore). * * Note: the global slots are used both for global variables and for "handles" * (these are different to the user-defined handles for referencing VM objects * from user space). Handles allow ROM allocations to reference RAM * allocations, even though the ROM can't be updated when the RAM allocation * moves during a GC collection. A handle is a slot in the "globals" space, * where the slot itself is pointed to by a ROM value and it points to the * corresponding RAM value. During a GC cycle, the RAM value may move and the * handle slot is updated, but the handle slot itself doesn't move. See * `offsetToDynamicPtr` in `encode-snapshot.ts`. * * The handles appear as the *last* global slots, and will generally not be * referenced by `LOAD_GLOBAL` instructions. * * WARNING: the globals section is the last section before the heap, so no ROM * pointer should point after the globals section. Some functions (e.g. * vm_getHandleTargetOrNull) assume this to be true. */ mvm_TeBytecodeSection[mvm_TeBytecodeSection["BCS_GLOBALS"] = 6] = "BCS_GLOBALS"; /** * Heap Section: heap allocations. * * This section is copied into RAM when the VM is restored. It becomes the * initial value of the GC heap. It contains allocations that are mutable * (like the DATA section) but also subject to garbage collection. * * Note: the heap must be at the end, because it is the only part that changes * size from one snapshot to the next. There is code that depends on this * being the last section because the size of this section is computed as * running to the end of the bytecode image. */ mvm_TeBytecodeSection[mvm_TeBytecodeSection["BCS_HEAP"] = 7] = "BCS_HEAP"; mvm_TeBytecodeSection[mvm_TeBytecodeSection["BCS_SECTION_COUNT"] = 8] = "BCS_SECTION_COUNT"; })(mvm_TeBytecodeSection = exports.mvm_TeBytecodeSection || (exports.mvm_TeBytecodeSection = {})); ; //# sourceMappingURL=runtime-types.js.map