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

Implements the OP_CONTAINS opcode for checking array membership 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)
 free_value (arr)
 free_value (needle)
 push_value (vm, make_int(ok ? 1 :0))

Variables

case OP_CONTAINS
Value arr = pop_value(vm)
int ok = array_contains(&arr, &needle)
 break

Detailed Description

Implements the OP_CONTAINS opcode for checking array membership in the VM.

This file handles the OP_CONTAINS instruction, which checks if a value is present in an array. The value and array are popped from the stack, and a boolean result (1/0) is pushed back.

Behavior:

  • Pops the value and array from the stack.
  • Checks if the value is present in the array.
  • Pushes 1 (true) or 0 (false) onto the stack.

Error Handling:

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

Example: // Bytecode: OP_CONTAINS // Stack before: [20, [10, 20, 30]] // Stack after: [1]

Definition in file contains.c.

Function Documentation

◆ free_value() [1/2]

free_value(arr)

◆ free_value() [2/2]

free_value(needle)

◆ if()

if(arr.type ! = VAL_ARRAY)

Definition at line 34 of file contains.c.

◆ push_value()

push_value(vm,
make_int(ok ? 1 :0) )

Variable Documentation

◆ arr

Value arr = pop_value(vm)

Definition at line 33 of file contains.c.

◆ break

break

Definition at line 42 of file contains.c.

◆ ok

int ok = array_contains(&arr, &needle)

Definition at line 38 of file contains.c.

◆ OP_CONTAINS

case OP_CONTAINS

Definition at line 31 of file contains.c.