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

Implements the OP_NEQ opcode for inequality comparison in the VM. More...

Go to the source code of this file.

Functions

 if (a.type==b.type)
 free_value (a)
 free_value (b)

Variables

case OP_NEQ
Value a = pop_value(vm)
int neq = 1
 else
 break

Detailed Description

Implements the OP_NEQ opcode for inequality comparison in the VM.

This file is part of the Fun programming language. https://fun-lang.xyz/

Copyright 2025 Johannes Findeisen you@h.nosp@m.anez.nosp@m..org Licensed under the terms of the Apache-2.0 license. https://opensource.org/license/apache-2-0

This file handles the OP_NEQ instruction, which checks if two values are not 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 not 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_NEQ // Stack before: [42, 10] // Stack after: [1]

Definition in file neq.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 neq.c.

Variable Documentation

◆ a

Value a = pop_value(vm)

Definition at line 33 of file neq.c.

◆ break

break

Definition at line 69 of file neq.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);
neq = (ai != bi);
} else {
neq = 1;
}
}
Value a
Definition add.c:37
push_value(vm, out)
uint32_t b
Definition band.c:32
int neq
Definition neq.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 neq.c.

◆ neq

int neq = 1

Definition at line 34 of file neq.c.

◆ OP_NEQ

case OP_NEQ

Definition at line 31 of file neq.c.