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

Implements the OP_MAKE_MAP opcode for creating maps in the VM. More...

Go to the source code of this file.

Functions

 if (pairs< 0)
 for (int i=0;i< pairs;++i)
 push_value (vm, m)

Variables

case OP_MAKE_MAP
Value m = make_map_empty()
 break

Detailed Description

Implements the OP_MAKE_MAP opcode for creating maps in the VM.

This file handles the OP_MAKE_MAP instruction, which pops pairs key-value pairs from the stack, creates a map from them, and pushes the resulting map back onto the stack.

Behavior:

  • Validates the number of pairs to ensure it is non-negative.
  • Ensures that map keys are strings.
  • Constructs the map using make_map_empty and map_set.
  • Pushes the map onto the stack.

Error Handling:

  • Exits with an error if the number of pairs is invalid, if keys are not strings, or if map construction fails.

Example: // Bytecode: OP_MAKE_MAP 2 // Stack before: ["key1", 1, "key2", 2] // Stack after: [{"key1": 1, "key2": 2}]

Definition in file make_map.c.

Function Documentation

◆ for()

for()

Definition at line 40 of file make_map.c.

Here is the call graph for this function:

◆ if()

if()

Definition at line 35 of file make_map.c.

◆ push_value()

push_value(vm,
m )

Variable Documentation

◆ break

break

Definition at line 54 of file make_map.c.

◆ m

Definition at line 39 of file make_map.c.

◆ OP_MAKE_MAP

case OP_MAKE_MAP

Definition at line 33 of file make_map.c.