#ifndef L2_BYTECODE_H #define L2_BYTECODE_H #include typedef uint32_t l2_word; enum l2_opcode { /* * Do nothing. */ L2_OP_NOP, /* * Push a value to the stack. * Push */ L2_OP_PUSH, /* * Push a value to the stack. * Push * Push */ L2_OP_PUSH_2, /* * Discard the top element from the stack. * Pop */ L2_OP_POP, /* * Duplicate the top element on the stack. * Push - 1> */ L2_OP_DUP, /* * Add two words. * Pop * Pop * Push + */ L2_OP_ADD, /* * Call a function. * Pop * Pop argc times * Pop * Push + 1 * Push array with args * Call */ L2_OP_FUNC_CALL, /* * Jump relative. * Pop * Jump words forwards */ L2_OP_RJMP, /* * Look up a value from the current stack frame. * Pop * Find in stack frame using * Push */ L2_OP_STACK_FRAME_LOOKUP, /* * Set a value in the current stack frame. * Pop * Read * Assign to stack frame */ L2_OP_STACK_FRAME_SET, /* * Return from a function. * NSPop * Pop (discard args array) * Pop * Jump to */ L2_OP_RET, /* * Allocate an atom from one word. * Pop * Alloc integer from * Push */ L2_OP_ALLOC_ATOM, /* * Allocate a real from two words. * Pop * Pop * Alloc real from << 32 | * Push */ L2_OP_ALLOC_REAL, /* * Allocate a buffer from static data. * Pop * Pop * Alloc buffer with length=, offset= * Push */ L2_OP_ALLOC_BUFFER_STATIC, /* * Allocate a zeroed buffer. * Pop * Alloc buffer with length= * Push */ L2_OP_ALLOC_BUFFER_ZERO, /* * Allocate an array. * Alloc array * Push */ L2_OP_ALLOC_ARRAY, /* * Allocate an integer->value map. * Alloc namespace * Push */ L2_OP_ALLOC_NAMESPACE, /* * Allocate a function. * Pop * Alloc function pointing to location * Push */ L2_OP_ALLOC_FUNCTION, /* * Set a namespace's name to a value. * Pop * Read * Read * Assign to ]> */ L2_OP_NAMESPACE_SET, /* * Set a namespace's name to a value. * Pop * Pop * Push ]> */ L2_OP_NAMESPACE_LOOKUP, /* * Halt execution. */ L2_OP_HALT, }; #endif