Fun 0.41.5
The programming language that makes You have fun
Loading...
Searching...
No Matches
neq.c
Go to the documentation of this file.
1
9
30
31case 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));
69 break;
70}
Value a
Definition add.c:37
uint32_t b
Definition band.c:32
@ OP_NEQ
Definition bytecode.h:54
free_value(a)
int neq
Definition neq.c:34
Tagged union representing a Fun value.
Definition value.h:68
Value make_bool(int v)
Construct a boolean Value.
Definition value.c:79
@ VAL_BOOL
Definition value.h:52
@ VAL_STRING
Definition value.h:53
@ VAL_FUNCTION
Definition value.h:54
@ VAL_NIL
Definition value.h:57
@ VAL_INT
Definition value.h:51