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

Implements the OP_APOP 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)
 if (!array_pop(&arr, &out))
 free_value (arr)
 push_value (vm, out)

Variables

case OP_APOP
Value out
 break

Detailed Description

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

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:

  • Pops the array from the stack.
  • Removes the last element from the array.
  • Pushes the removed element onto the stack.

Error Handling:

  • Exits with an error if the array is of the wrong type.
  • Exits with an error if the array is empty.

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

Definition in file apop.c.

Function Documentation

◆ free_value()

free_value(arr)

◆ if() [1/2]

if(!array_pop &, &out)

Definition at line 39 of file apop.c.

◆ if() [2/2]

if(arr.type ! = VAL_ARRAY)

Definition at line 34 of file apop.c.

◆ push_value()

push_value(vm,
out )

Variable Documentation

◆ break

break

Definition at line 45 of file apop.c.

◆ OP_APOP

case OP_APOP

Definition at line 32 of file apop.c.

◆ out

Value out

Definition at line 38 of file apop.c.