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

Implements the OP_CLEAR opcode for clearing 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)
 free_value (arr)
 push_value (vm, make_int(0))

Variables

case OP_CLEAR
array_cleararr
 break

Detailed Description

Implements the OP_CLEAR opcode for clearing arrays in the VM.

Handles the OP_CLEAR instruction, which removes all elements from an array. The array is popped from the stack; the opcode pushes an integer result (currently 0) as an acknowledgement.

Behavior:

  • Pops the array from the stack.
  • Clears all elements from the array (array becomes empty in place).
  • Pushes 0 (integer) to acknowledge success.

Error Handling:

  • Exits with a runtime error if the operand is not an array.

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

Definition in file clear.c.

Function Documentation

◆ free_value()

free_value(arr)

◆ if()

if(arr.type ! = VAL_ARRAY)

Definition at line 34 of file clear.c.

◆ push_value()

push_value(vm,
make_int(0) )

Variable Documentation

◆ arr

Definition at line 38 of file clear.c.

◆ break

break

Definition at line 41 of file clear.c.

◆ OP_CLEAR

case OP_CLEAR

Definition at line 32 of file clear.c.