1
0
Fork 0
forked from fun/fun

Some more opcode refactoring. (0.3.1)

This commit is contained in:
Johannes Findeisen 2025-09-16 04:51:49 +02:00
commit 228615db18
12 changed files with 42 additions and 59 deletions

View file

@ -8,10 +8,10 @@
*/
/**
* @file arr_pop.c
* @brief Implements the OP_ARR_POP opcode for removing elements from arrays in the VM.
* @file apop.c
* @brief Implements the OP_APOP opcode for removing elements from arrays in the VM.
*
* This file handles the OP_ARR_POP instruction, which removes the last element from an array
* This file handles the OP_APOP instruction, which removes the last element from an array
* and pushes the removed element onto the stack. The array is popped from the stack.
*
* Behavior:
@ -24,7 +24,7 @@
* - Exits with an error if the array is empty.
*
* Example:
* // Bytecode: OP_ARR_POP
* // Bytecode: OP_APOP
* // Stack before: [[10, 20, 30]]
* // Stack after: [30]
*
@ -32,10 +32,10 @@
* @date 2025-10-16
*/
case OP_ARR_POP: {
case OP_APOP: {
Value arr = pop_value(vm);
if (arr.type != VAL_ARRAY) {
fprintf(stderr, "Runtime type error: ARR_POP expects array\n");
fprintf(stderr, "Runtime type error: ARR_APOP expects array\n");
exit(1);
}
Value out;

View file

@ -8,10 +8,10 @@
*/
/**
* @file arr_insert.c
* @brief Implements the OP_ARR_INSERT opcode for inserting elements into arrays in the VM.
* @file insert.c
* @brief Implements the OP_INSERT opcode for inserting elements into arrays in the VM.
*
* This file handles the OP_ARR_INSERT instruction, which inserts a value into an array
* This file handles the OP_INSERT instruction, which inserts a value into an array
* at a specified index. The array, index, and value are popped from the stack, and the
* new length of the array is pushed back onto the stack.
*
@ -25,7 +25,7 @@
* - Exits with an error if memory allocation fails during the insertion.
*
* Example:
* // Bytecode: OP_ARR_INSERT
* // Bytecode: OP_INSERT
* // Stack before: [42, 1, [10, 20, 30]]
* // Stack after: [4]
*
@ -33,7 +33,7 @@
* @date 2025-10-16
*/
case OP_ARR_INSERT: {
case OP_INSERT: {
Value v = pop_value(vm);
Value idx = pop_value(vm);
Value arr = pop_value(vm);

View file

@ -32,7 +32,7 @@
* @date 2025-10-16
*/
case OP_ARR_PUSH: {
case OP_PUSH: {
Value v = pop_value(vm);
Value arr = pop_value(vm);
if (arr.type != VAL_ARRAY) {

View file

@ -33,7 +33,7 @@
* @date 2025-10-16
*/
case OP_ARR_REMOVE: {
case OP_REMOVE: {
Value idx = pop_value(vm);
Value arr = pop_value(vm);
if (arr.type != VAL_ARRAY || idx.type != VAL_INT) {

View file

@ -32,7 +32,7 @@
* @date 2025-10-16
*/
case OP_ARR_SET: {
case OP_SET: {
Value v = pop_value(vm);
Value idx = pop_value(vm);
Value arr = pop_value(vm);