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

Implements the OP_INDEX_SET opcode for array and map assignment 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 (container.type==VAL_ARRAY)
 exit (1)

Variables

case OP_INDEX_SET
Value idx = pop_value(vm)
Value container = pop_value(vm)
 else
 break

Detailed Description

Implements the OP_INDEX_SET opcode for array and map assignment in the VM.

This file handles the OP_INDEX_SET instruction, which assigns a value to an element in an array or a key in a map.

Behavior:

  • Pops the value, index/key, and container from the stack.
  • For arrays, assigns the value to the specified index.
  • For maps, assigns the value to the specified key.

Error Handling:

  • Exits with an error if the container is not an array or map, if the index/key is of the wrong type, or if the index is out of bounds.

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

Definition in file index_set.c.

Function Documentation

◆ exit()

exit(1)

◆ if()

if(container.type = VAL_ARRAY)

Definition at line 40 of file index_set.c.

Here is the call graph for this function:

Variable Documentation

◆ break

break

Definition at line 66 of file index_set.c.

◆ container

Value container = pop_value(vm)

Definition at line 35 of file index_set.c.

◆ else

else
Initial value:
{
fprintf(stderr, "Runtime type error: INDEX_SET expects array or map\n")
#define fprintf
Definition vm.c:200

Definition at line 62 of file index_set.c.

◆ idx

Value idx = pop_value(vm)

Definition at line 34 of file index_set.c.

◆ OP_INDEX_SET

case OP_INDEX_SET

Definition at line 32 of file index_set.c.