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

Implements the OP_ENUMERATE opcode for enumerating 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, out)

Variables

case OP_ENUMERATE
Value out = bi_enumerate(&arr)
 break

Detailed Description

Implements the OP_ENUMERATE opcode for enumerating arrays in the VM.

This file handles the OP_ENUMERATE instruction, which creates an array of [index, value] pairs from an array. The array is popped from the stack, and the new array is pushed back.

Behavior:

  • Pops the array from the stack.
  • Creates a new array of [index, value] pairs.
  • Pushes the new array onto the stack.

Error Handling:

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

Example: // Bytecode: OP_ENUMERATE // Stack before: [[10, 20, 30]] // Stack after: [[[0, 10], [1, 20], [2, 30]]]

Definition in file enumerate.c.

Function Documentation

◆ free_value()

free_value(arr)

◆ if()

if(arr.type ! = VAL_ARRAY)

Definition at line 33 of file enumerate.c.

◆ push_value()

push_value(vm,
out )

Variable Documentation

◆ break

break

Definition at line 40 of file enumerate.c.

◆ OP_ENUMERATE

case OP_ENUMERATE

Definition at line 31 of file enumerate.c.

◆ out

Definition at line 37 of file enumerate.c.