#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 * Push + 1 * Jump to */ L2_OP_CALL, /* * Generate a stack frame. * Alloc namespace * NSPush */ L2_OP_GEN_STACK_FRAME, /* * 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 * Jump to */ L2_OP_RET, /* * Allocate an integer from one word. * Pop * Alloc integer from * Push */ L2_OP_ALLOC_INTEGER_32, /* * Allocate an integer from two words. * Pop * Pop * Alloc integer from << 32 | * Push */ L2_OP_ALLOC_INTEGER_64, /* * Allocate a real from one word. * Pop * Alloc real from * Push */ L2_OP_ALLOC_REAL_32, /* * Allocate a real from two words. * Pop * Pop * Alloc real from << 32 | * Push */ L2_OP_ALLOC_REAL_64, /* * 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, /* * Set a namespace's name to a value. * Pop * Read * Read * Assign to ]> */ L2_OP_NAMESPACE_SET, /* * Halt execution. */ L2_OP_HALT, }; #endif