Fun 0.41.5
The programming language that makes you have fun!
Loading...
Searching...
No Matches
jump_if_false.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 jump_if_false.c
12 * @brief Implements the OP_JUMP_IF_FALSE opcode for conditional jumps in the VM.
13 *
14 * This file handles the OP_JUMP_IF_FALSE instruction, which jumps if the top
15 * stack value is falsey (0, false, nil, etc).
16 *
17 * Behavior:
18 * - Pops condition value from stack
19 * - Jumps to operand IP if falsey
20 * - Continues normally if truthy
21 *
22 * Used for:
23 * - If statements
24 * - While loops
25 * - Logical expressions
26 */
27
29 Value cond = pop_value(vm);
30 int truthy = value_is_truthy(&cond);
32 if (!truthy) {
33 f->ip = inst.operand;
34 }
35 break;
36}
@ OP_JUMP_IF_FALSE
Definition bytecode.h:58
int truthy
free_value(cond)
FILE * f
Definition read_file.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
static Value pop_value(VM *vm)
Pop a Value from the VM operand stack.
Definition vm.c:580