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

Implements the OP_MAKE_ARRAY opcode for creating 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 (n< 0||vm->sp+1< n)
 if (!vals)
 for (int i=n - 1;i >=0;--i)
 for (int i=0;i< n;++i)
 free (vals)
 push_value (vm, arr)

Variables

case OP_MAKE_ARRAY
Valuevals = (Value *)malloc(sizeof(Value) * n)
Value arr = make_array_from_values(vals, n)
 break

Detailed Description

Implements the OP_MAKE_ARRAY opcode for creating arrays in the VM.

This file handles the OP_MAKE_ARRAY instruction, which pops n values from the stack, creates an array from them, and pushes the resulting array back onto the stack.

Behavior:

  • Validates the number of elements (n) to ensure it is non-negative and within stack bounds.
  • Allocates temporary storage for the array elements.
  • Constructs the array using make_array_from_values.
  • Frees temporary storage and pushes the array onto the stack.

Error Handling:

  • Exits with an error if n is invalid or if memory allocation fails.

Example: // Bytecode: OP_MAKE_ARRAY 3 // Stack before: [1, 2, 3] // Stack after: [[1, 2, 3]]

Definition in file make_array.c.

Function Documentation

◆ for() [1/2]

for()

Definition at line 49 of file make_array.c.

Here is the call graph for this function:

◆ for() [2/2]

for(inti = n - 1; i >= 0; --i)

Definition at line 44 of file make_array.c.

◆ free()

free(vals)
Here is the caller graph for this function:

◆ if() [1/2]

if(!vals)

Definition at line 40 of file make_array.c.

◆ if() [2/2]

if()

Definition at line 34 of file make_array.c.

◆ push_value()

push_value(vm,
arr )

Variable Documentation

◆ arr

Definition at line 48 of file make_array.c.

◆ break

break

Definition at line 54 of file make_array.c.

◆ OP_MAKE_ARRAY

case OP_MAKE_ARRAY

Definition at line 32 of file make_array.c.

◆ vals

Value* vals = (Value *)malloc(sizeof(Value) * n)

Definition at line 39 of file make_array.c.