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...

This graph shows which files directly or indirectly include this file:

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]

Definition in file len.c.

Function Documentation

◆ free_value()

free_value ( a )

◆ if()

if ( a. type = VAL_STRING)

Definition at line 34 of file len.c.

◆ push_value()

push_value ( vm ,
make_int(len)  )

Variable Documentation

◆ break

break

Definition at line 45 of file len.c.

◆ else

else
Initial value:
{
Value make_int(int64_t v)
Construct a Value representing a 64-bit integer.
Definition value.c:51
static void push_value(VM *vm, Value v)
Push a Value onto the VM operand stack.
Definition vm.c:564

Definition at line 39 of file len.c.

◆ len

int len = 0

Definition at line 33 of file len.c.

◆ OP_LEN

case OP_LEN

Definition at line 31 of file len.c.