Fun
0.41.5
The programming language that makes You have fun
Main Page
Data Structures
Files
File List
Globals
Loading...
Searching...
No Matches
src
vm
logic
eq.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
30
31
case
OP_EQ
: {
32
Value
b
= pop_value(vm);
33
Value
a
= pop_value(vm);
34
int
eq
= 0;
35
if
(
a
.type ==
b
.type) {
36
switch
(
a
.type) {
37
case
VAL_INT
:
38
eq
= (
a
.i ==
b
.i);
39
break
;
40
case
VAL_BOOL
:
41
eq
= ((
a
.i != 0) == (
b
.i != 0));
42
break
;
43
case
VAL_STRING
:
44
eq
= (
a
.s &&
b
.s) ? (strcmp(
a
.s,
b
.s) == 0) : (
a
.s ==
b
.s);
45
break
;
46
case
VAL_FUNCTION
:
47
eq
= (
a
.fn ==
b
.fn);
48
break
;
49
case
VAL_NIL
:
50
eq
= 1;
51
break
;
52
default
:
53
eq
= 0;
54
break
;
55
}
56
}
else
{
57
/* interop: bool vs int (0/1) */
58
if
((
a
.type ==
VAL_BOOL
&&
b
.type ==
VAL_INT
) || (
a
.type ==
VAL_INT
&&
b
.type ==
VAL_BOOL
)) {
59
int
ai = (
a
.type ==
VAL_BOOL
) ? (
a
.i != 0) : (
a
.i != 0);
60
int
bi = (
b
.type ==
VAL_BOOL
) ? (
b
.i != 0) : (
b
.i != 0);
61
eq
= (ai == bi);
62
}
else
{
63
eq
= 0;
64
}
65
}
66
push_value(vm,
make_bool
(
eq
));
67
free_value
(
a
);
68
free_value
(
b
);
69
break
;
70
}
a
Value a
Definition
add.c:37
b
uint32_t b
Definition
band.c:32
OP_EQ
@ OP_EQ
Definition
bytecode.h:53
free_value
free_value(a)
eq
int eq
Definition
eq.c:34
Value
Tagged union representing a Fun value.
Definition
value.h:68
make_bool
Value make_bool(int v)
Construct a boolean Value.
Definition
value.c:79
VAL_BOOL
@ VAL_BOOL
Definition
value.h:52
VAL_STRING
@ VAL_STRING
Definition
value.h:53
VAL_FUNCTION
@ VAL_FUNCTION
Definition
value.h:54
VAL_NIL
@ VAL_NIL
Definition
value.h:57
VAL_INT
@ VAL_INT
Definition
value.h:51
Generated on
for Fun by
1.16.1