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

Implements the OP_SPLIT opcode for splitting strings in the VM. More...

Go to the source code of this file.

Functions

 if (str.type !=VAL_STRING||sep.type !=VAL_STRING)
 free_value (str)
 free_value (sep)
 push_value (vm, out)

Variables

case OP_SPLIT
Value str = pop_value(vm)
Value out = bi_split(&str, &sep)
 break

Detailed Description

Implements the OP_SPLIT opcode for splitting strings in the VM.

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

Behavior:

  • Pops the separator and string from the stack.
  • Splits the string into an array of substrings using the separator.
  • Pushes the resulting array onto the stack.

Error Handling:

  • Exits with an error if the operands are not strings.

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

Author
Johannes Findeisen
Date
2025-10-16

Definition in file split.c.

Function Documentation

◆ free_value() [1/2]

free_value(sep)

◆ free_value() [2/2]

free_value(str)

◆ if()

if(str.type ! = VAL_STRING || sep.type != VAL_STRING)

Definition at line 38 of file split.c.

◆ push_value()

push_value(vm,
out )

Variable Documentation

◆ break

break

Definition at line 46 of file split.c.

◆ OP_SPLIT

case OP_SPLIT

Definition at line 35 of file split.c.

◆ out

Value out = bi_split(&str, &sep)

Definition at line 42 of file split.c.

◆ str

Value str = pop_value(vm)

Definition at line 37 of file split.c.