#ifndef L2_BYTECODE_H #define L2_BYTECODE_H #include typedef uint32_t l2_word; #define l2_bytecode_version 2 enum l2_opcode { /* * Do nothing. */ L2_OP_NOP, /* * Discard the top element from the stack. * Pop */ L2_OP_DISCARD, /* * Swap the top and second-top elements, then pop the new top element. * Pop * Pop * Push */ L2_OP_SWAP_DISCARD, /* * Duplicate the top element on the stack. * Push - 1> */ L2_OP_DUP, /* * Add two words. * Pop * Pop * Push + */ L2_OP_ADD, /* * Call a function; func_call * Pop times * Pop * Push array with args * Call * (Before returning, the function will push a return value onto the stack) */ L2_OP_FUNC_CALL_U4, /* * Call an infix function * Pop * Pop * Pop * Call * (Before returning, the function will push a return value onto the stack) */ L2_OP_FUNC_CALL_INFIX, /* * Jump relative; rjmp * Jump words forwards */ L2_OP_RJMP_U4, /* * Look up a value from the current stack frame; stack_frame_lookup * Find in stack frame using * Push */ L2_OP_STACK_FRAME_LOOKUP_U4, /* * Set a value in the current stack frame; stack_frame_set * Read * Assign to stack frame at */ L2_OP_STACK_FRAME_SET_U4, /* * Replace a value on the stack; stack_frame_replace * Read * Assign to stack frame at */ L2_OP_STACK_FRAME_REPLACE_U4, /* * Return from a function. * Pop * FSPop * Reset stack pointer to * Push * Jump to */ L2_OP_RET, /* * Put a reference to none at the top of the stack. * Push 0 */ L2_OP_ALLOC_NONE, /* * Allocate an atom from one word; alloc_atom * Alloc atom from * Push */ L2_OP_ALLOC_ATOM_U4, /* * Allocate a real from two words; alloc_real * Alloc real from * Push */ L2_OP_ALLOC_REAL_D8, /* * Allocate a buffer from static data; alloc_buffer_static * Alloc buffer with and * Push */ L2_OP_ALLOC_BUFFER_STATIC_U4, /* * Allocate an array; * Pop times * Alloc array * Push */ L2_OP_ALLOC_ARRAY_U4, /* * Allocate an integer->value map. * Alloc namespace * Push */ L2_OP_ALLOC_NAMESPACE, /* * Allocate a function; alloc_function * Alloc function pointing to location * Push */ L2_OP_ALLOC_FUNCTION_U4, /* * Set a namespace's name to a value; namespace_set * Read * Read * Assign to ]> */ L2_OP_NAMESPACE_SET_U4, /* * Lookup a value from a namespace; namespace_lookup * Pop * Push ]> */ L2_OP_NAMESPACE_LOOKUP_U4, /* * Look up a value from an array; array_lookup * Pop * Push ]> */ L2_OP_ARRAY_LOOKUP_U4, /* * Set a value in an array; array_set * Read * Read * Assign to ]> */ L2_OP_ARRAY_SET, /* * Look up a runtime value in an array or object. * Pop * Pop * Push ]> */ L2_OP_DYNAMIC_LOOKUP, /* * Set a value in an array or object. * Pop * Pop * Pop * Assign to ]> */ L2_OP_DYNAMIC_SET, /* * Halt execution. */ L2_OP_HALT, }; #endif