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

Implements the OP_JOIN opcode for joining array elements into a string 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||sep.type !=VAL_STRING)
 free_value (arr)
 free_value (sep)
 push_value (vm, out)

Variables

case OP_JOIN
Value arr = pop_value(vm)
Value out = bi_join(&arr, &sep)
 break

Detailed Description

Implements the OP_JOIN opcode for joining array elements into a string in the VM.

This file handles the OP_JOIN instruction, which joins the elements of an array into a string using a separator. The separator and array are popped from the stack, and the resulting string is pushed back.

Behavior:

  • Pops the separator and array from the stack.
  • Joins the array elements into a string using the separator.
  • Pushes the resulting string onto the stack.

Error Handling:

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

Example: // Bytecode: OP_JOIN // Stack before: [", ", ["a", "b", "c"]] // Stack after: ["a, b, c"]

Definition in file join.c.

Function Documentation

◆ free_value() [1/2]

free_value(arr)

◆ free_value() [2/2]

free_value(sep)

◆ if()

if(arr.type ! = VAL_ARRAY || sep.type != VAL_STRING)

Definition at line 35 of file join.c.

◆ push_value()

push_value(vm,
out )

Variable Documentation

◆ arr

Value arr = pop_value(vm)

Definition at line 34 of file join.c.

◆ break

break

Definition at line 43 of file join.c.

◆ OP_JOIN

case OP_JOIN

Definition at line 32 of file join.c.

◆ out

Value out = bi_join(&arr, &sep)

Definition at line 39 of file join.c.