TinyTotVM provides 55+ core instructions plus comprehensive standard library covering all aspects of modern programming language execution.
ADD, SUB, MUL, DIV ; Basic integer arithmetic
MOD ; Modulo operation
ADD_F, SUB_F, MUL_F, DIV_F ; Float arithmetic with IEEE 754 compliance
EQ, NE, GT, LT, GE, LE ; Integer comparisons
EQ_F, NE_F, GT_F, LT_F, GE_F, LE_F ; Float comparisons
AND, OR, NOT ; Boolean logic operations
PUSH_INT 42 ; Push integer literal
PUSH_FLOAT 3.14 ; Push float literal
PUSH_STR "hello" ; Push string literal
TRUE, FALSE, NULL ; Push boolean/null constants
DUP ; Duplicate top stack value
STORE varname ; Store value in current scope
LOAD varname ; Load variable value
DELETE varname ; Remove variable from scope
DUMP_SCOPE ; Debug: print current scope
MAKE_OBJECT ; Create empty object
SET_FIELD name ; Set object field
GET_FIELD name ; Get object field
HAS_FIELD name ; Check if field exists
DELETE_FIELD name ; Remove object field
KEYS ; Get all field names as list
MAKE_LIST 3 ; Create list from top 3 stack items
LEN ; Get length of list/object
INDEX ; Access list element by index
CALL label param1 param2 ; Call function with parameters
RET ; Return from function
MAKE_FUNCTION label x y ; Create function pointer
CALL_FUNCTION ; Call function from stack
MAKE_LAMBDA label x y ; Create anonymous function (closure)
CAPTURE varname ; Capture variable for closure
JMP label ; Unconditional jump
JZ label ; Jump if zero/false/null
LABEL name ; Define a label
TRY ; Start exception handling block
CATCH varname ; Catch exceptions in variable
THROW ; Throw exception from stack
END_TRY ; End exception handling block
IMPORT path ; Import module by file path
EXPORT name ; Export variable/function by name
PRINT ; Print top stack value
READ_LINE ; Read line from stdin
READ_CHAR ; Read single character from stdin
READ_INPUT ; Read all input until EOF from stdin
READ_FILE ; Read file contents to string
WRITE_FILE ; Write string to file
APPEND_FILE ; Append content to file
FILE_EXISTS ; Check if file exists
FILE_SIZE ; Get file size in bytes
DELETE_FILE ; Delete a file
LIST_DIR ; List directory contents
READ_BYTES ; Read file as byte array
WRITE_BYTES ; Write byte array to file
GET_ENV ; Get environment variable
SET_ENV ; Set environment variable
GET_ARGS ; Get command line arguments
EXEC ; Execute external command
EXEC_CAPTURE ; Execute command and capture output
EXIT ; Exit with status code
GET_TIME ; Get current Unix timestamp
SLEEP ; Sleep for specified milliseconds
FORMAT_TIME ; Format timestamp to string
HTTP_GET ; HTTP GET request
HTTP_POST ; HTTP POST request
TCP_CONNECT ; Connect to TCP server
TCP_LISTEN ; Listen on TCP port
TCP_SEND ; Send data over TCP connection
TCP_RECV ; Receive data from TCP connection
UDP_BIND ; Bind UDP socket to port
UDP_SEND ; Send UDP packet
UDP_RECV ; Receive UDP packet
DNS_RESOLVE ; Resolve hostname to IP address
ASYNC_READ ; Asynchronous file read
ASYNC_WRITE ; Asynchronous file write
AWAIT ; Wait for async operation completion
STREAM_CREATE ; Create data stream
STREAM_READ ; Read from data stream
STREAM_WRITE ; Write to data stream
STREAM_CLOSE ; Close data stream
JSON_PARSE ; Parse JSON string to object
JSON_STRINGIFY ; Convert value to JSON string
CSV_PARSE ; Parse CSV data to list
CSV_WRITE ; Convert list to CSV format
COMPRESS ; Compress data
DECOMPRESS ; Decompress data
ENCRYPT ; Encrypt data with key
DECRYPT ; Decrypt data with key
HASH ; Generate hash of data
DB_CONNECT ; Connect to database
DB_QUERY ; Execute database query
DB_EXEC ; Execute database command
HALT ; Stop execution
TinyTotVM supports 14 built-in value types:
- Int(i64) - 64-bit signed integers
- Float(f64) - IEEE 754 double-precision floats
- Str(String) - UTF-8 strings
- Bool(bool) - Boolean values
- Null - Null/undefined value
- List(Vec) - Dynamic arrays
- Object(HashMap<String, Value>) - Dynamic objects
- Bytes(Vec) - Byte arrays
- Connection(String) - Network connections
- Stream(String) - Data streams
- Future(String) - Async operations
- Function - Function pointers
- Closure - Closures with captured environment
- Exception - Exception objects with stack traces
All operations use comprehensive error handling instead of crashes:
StackUnderflow- Not enough values on stackTypeMismatch- Incompatible types for operationUndefinedVariable- Variable not found in scopeIndexOutOfBounds- List/string index out of rangeFileError- File operation failureParseError- Syntax or parsing errorCallStackUnderflow- Return without callNoVariableScope- No variable scope available
Instructions support both numeric and symbolic addressing:
; Numeric addressing
JMP 42
CALL 100 param1 param2
; Symbolic addressing
JMP end_loop
CALL my_function x y
LABEL end_loop
LABEL my_functionWhen using the experimental --use-ir flag, TinyTotVM translates stack-based bytecode to register-based intermediate representation with the following instruction set:
MOV r1, #5 ; Move immediate value to register
MOV r2, r1 ; Move register to register
ADD r3, r1, r2 ; r3 = r1 + r2
SUB r3, r1, r2 ; r3 = r1 - r2
MUL r3, r1, r2 ; r3 = r1 * r2
DIV r3, r1, r2 ; r3 = r1 / r2
JMP 100 ; Unconditional jump to instruction 100
JZ r1, 200 ; Jump to instruction 200 if r1 is zero
PRINT r1 ; Print value in register r1
HALT ; Terminate execution
Note: The IR mode provides comprehensive instruction translation with automatic fallback to the SMP scheduler for concurrency operations, ensuring full compatibility with all TinyTotVM features.