Fun 0.41.5
The programming language that makes you have fun!
Loading...
Searching...
No Matches
and.c
Go to the documentation of this file.
1/*
2 * This file is part of the Fun programming language.
3 * https://fun-lang.xyz/
4 *
5 * Copyright 2025 Johannes Findeisen <you@hanez.org>
6 * Licensed under the terms of the Apache-2.0 license.
7 * https://opensource.org/license/apache-2-0
8 */
9
10/**
11 * @file and.c
12 * @brief Implements the OP_AND opcode for logical AND in the VM.
13 *
14 * This file handles the OP_AND instruction, which performs a logical AND operation
15 * on two boolean values. The values are popped from the stack, and the result is pushed back.
16 *
17 * Behavior:
18 * - Pops two boolean values from the stack.
19 * - Performs a logical AND operation.
20 * - Pushes the result (1 or 0) onto the stack.
21 *
22 * Error Handling:
23 * - Exits with an error if the operands are not boolean values.
24 *
25 * Example:
26 * - Bytecode: OP_AND
27 * - Stack before: [1, 0]
28 * - Stack after: [0]
29 */
30
31case OP_AND: {
32 Value b = pop_value(vm);
38 break;
39}
Value a
Definition add.c:37
free_value(a)
push_value(vm, make_bool(res))
uint32_t b
Definition band.c:32
@ OP_AND
Definition bytecode.h:71
const char * res
Definition get_string.c:38
Tagged union representing a Fun value.
Definition value.h:68
int value_is_truthy(const Value *v)
Evaluate a Value's truthiness according to Fun language rules.
Definition value.c:610
Value make_bool(int v)
Construct a boolean Value.
Definition value.c:79
static Value pop_value(VM *vm)
Pop a Value from the VM operand stack.
Definition vm.c:580