Fun 0.41.5
The programming language that makes You have fun
Loading...
Searching...
No Matches
remove.c File Reference

Implements the OP_REMOVE opcode for removing elements from arrays in the VM. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

 if (arr.type !=VAL_ARRAY||idx.type !=VAL_INT)
 if (!array_remove(&arr,(int) idx.i, &out))
 free_value (arr)
 free_value (idx)
 push_value (vm, out)

Variables

case OP_REMOVE
Value arr = pop_value(vm)
Value out
 break

Detailed Description

Implements the OP_REMOVE opcode for removing elements from arrays in the VM.

Handles the OP_REMOVE instruction, which removes an element from an array at the specified index. The array and index are popped from the stack; the removed element is pushed back onto the stack.

Behavior:

  • Pops the index and array from the stack.
  • Removes the element at the specified index from the array.
  • Pushes the removed element onto the stack.

Error Handling:

  • Exits with a runtime error if the container is not an array or index is not an int.
  • Exits with a runtime error if the index is out of bounds.

Example: // Bytecode: OP_REMOVE // Stack before: [1, [10, 20, 30]] // Stack after: [20]

Definition in file remove.c.

Function Documentation

◆ free_value() [1/2]

free_value(arr)

◆ free_value() [2/2]

free_value(idx)

◆ if() [1/2]

if(!array_remove(&, intidx.i,
&out )

Definition at line 41 of file remove.c.

◆ if() [2/2]

if(arr.type ! = VAL_ARRAY || idx.type != VAL_INT)

Definition at line 36 of file remove.c.

◆ push_value()

push_value(vm,
out )

Variable Documentation

◆ arr

Value arr = pop_value(vm)

Definition at line 35 of file remove.c.

◆ break

break

Definition at line 48 of file remove.c.

◆ OP_REMOVE

case OP_REMOVE

Definition at line 33 of file remove.c.

◆ out

Value out

Definition at line 40 of file remove.c.