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

Implements the OP_INDEX_GET opcode for array and map indexing 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_GET
Value container = pop_value(vm)
 else
 break

Detailed Description

Implements the OP_INDEX_GET opcode for array and map indexing in the VM.

This file handles the OP_INDEX_GET instruction, which retrieves an element from an array or a value from a map using an index or key.

Behavior:

  • Pops the index/key and container from the stack.
  • For arrays, retrieves the element at the specified index.
  • For maps, retrieves the value associated with the specified key.
  • Pushes the retrieved value onto the stack.

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_GET // Stack before: [1, [10, 20, 30]] // Stack after: [20]

Definition in file index_get.c.

Function Documentation

◆ exit()

exit(1)

◆ if()

else if(container.type = VAL_ARRAY)

Definition at line 40 of file index_get.c.

Here is the call graph for this function:

Variable Documentation

◆ break

break

Definition at line 70 of file index_get.c.

◆ container

Value container = pop_value(vm)

Definition at line 35 of file index_get.c.

◆ else

else
Initial value:
{
fprintf(stderr, "Runtime type error: INDEX_GET expects array or map (got container=%s, index=%s)\n",
value_type_name(container.type), value_type_name(idx.type))
Value container
Definition index_get.c:35
int idx
Definition index_of.c:38
#define fprintf
Definition vm.c:200

Definition at line 65 of file index_get.c.

◆ OP_INDEX_GET

case OP_INDEX_GET

Definition at line 33 of file index_get.c.