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
neq.c
Go to the documentation of this file.
1
9
30
31
case
OP_NEQ
: {
32
Value
b
= pop_value(vm);
33
Value
a
= pop_value(vm);
34
int
neq
= 1;
35
if
(
a
.type ==
b
.type) {
36
switch
(
a
.type) {
37
case
VAL_INT
:
38
neq
= (
a
.i !=
b
.i);
39
break
;
40
case
VAL_BOOL
:
41
neq
= ((
a
.i != 0) != (
b
.i != 0));
42
break
;
43
case
VAL_STRING
:
44
neq
= (
a
.s &&
b
.s) ? (strcmp(
a
.s,
b
.s) != 0) : (
a
.s !=
b
.s);
45
break
;
46
case
VAL_FUNCTION
:
47
neq
= (
a
.fn !=
b
.fn);
48
break
;
49
case
VAL_NIL
:
50
neq
= 0;
51
break
;
52
default
:
53
neq
= 1;
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
neq
= (ai != bi);
62
}
else
{
63
neq
= 1;
64
}
65
}
66
push_value(vm,
make_bool
(
neq
));
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_NEQ
@ OP_NEQ
Definition
bytecode.h:54
free_value
free_value(a)
neq
int neq
Definition
neq.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