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

Implements the OP_LEN opcode for getting the length of arrays or strings in the VM. More...

Go to the source code of this file.

Functions

 if (a.type==VAL_STRING)
 free_value (a)
 push_value (vm, make_int(len))

Variables

case OP_LEN
int len = 0
 else
 break

Detailed Description

Implements the OP_LEN opcode for getting the length of arrays or strings in the VM.

This file handles the OP_LEN instruction, which retrieves the length of an array or string. The array or string is popped from the stack, and the length is pushed back.

Behavior:

  • Pops the array or string from the stack.
  • Retrieves the length of the array or string.
  • Pushes the length onto the stack.

Error Handling:

  • Exits with an error if the operand is not an array or string.

Example: // Bytecode: OP_LEN // Stack before: ["hello"] // Stack after: [5]

Author
Johannes Findeisen
Date
2025-09-16

Definition in file len.c.

Function Documentation

◆ free_value()

free_value(a)

◆ if()

if(a.type = VAL_STRING)

Definition at line 37 of file len.c.

◆ push_value()

push_value(vm,
make_int(len) )

Variable Documentation

◆ break

break

Definition at line 48 of file len.c.

◆ else

else
Initial value:
{
push_value(vm, make_int(0))
Value make_int(int64_t v)
Construct a Value representing a 64-bit integer.
Definition value.c:51

Definition at line 42 of file len.c.

◆ len

int len = 0

Definition at line 36 of file len.c.

◆ OP_LEN

case OP_LEN

Definition at line 34 of file len.c.