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

Implements the OP_EQ opcode for equality comparison 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==b.type)
 free_value (a)
 free_value (b)

Variables

case OP_EQ
Value a = pop_value(vm)
int eq = 0
 else
 break

Detailed Description

Implements the OP_EQ opcode for equality comparison in the VM.

This file handles the OP_EQ instruction, which checks if two values are equal. The values are popped from the stack, and the result (1 or 0) is pushed back.

Behavior:

  • Pops two values from the stack.
  • Checks if the values are equal.
  • Pushes 1 (true) or 0 (false) onto the stack.

Error Handling:

  • Exits with an error if the operands are of incompatible types.

Example: // Bytecode: OP_EQ // Stack before: [42, 42] // Stack after: [1]

Definition in file eq.c.

Function Documentation

◆ free_value() [1/2]

free_value(a)

◆ free_value() [2/2]

free_value(b)

◆ if()

if(a.type = = b.type)

Definition at line 35 of file eq.c.

Variable Documentation

◆ a

Value a = pop_value(vm)

Definition at line 33 of file eq.c.

◆ break

break

Definition at line 69 of file eq.c.

◆ else

else
Initial value:
{
if ((a.type == VAL_BOOL && b.type == VAL_INT) || (a.type == VAL_INT && b.type == VAL_BOOL)) {
int ai = (a.type == VAL_BOOL) ? (a.i != 0) : (a.i != 0);
int bi = (b.type == VAL_BOOL) ? (b.i != 0) : (b.i != 0);
eq = (ai == bi);
} else {
eq = 0;
}
}
Value a
Definition add.c:37
push_value(vm, out)
uint32_t b
Definition band.c:32
int eq
Definition eq.c:34
Value make_bool(int v)
Construct a boolean Value.
Definition value.c:79
@ VAL_BOOL
Definition value.h:52
@ VAL_INT
Definition value.h:51

Definition at line 56 of file eq.c.

◆ eq

int eq = 0

Definition at line 34 of file eq.c.

◆ OP_EQ

case OP_EQ

Definition at line 31 of file eq.c.