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
maps
has_key.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
24
25
case
OP_HAS_KEY
: {
26
Value
key = pop_value(vm);
27
Value
m
= pop_value(vm);
28
if
(
m
.type !=
VAL_MAP
|| key.
type
!=
VAL_STRING
) {
29
fprintf
(stderr,
"HAS_KEY expects (map, string)\n"
);
30
exit
(1);
31
}
32
int
ok
=
map_has
(&
m
, key.
s
? key.
s
:
""
);
33
free_value
(
m
);
34
free_value
(key);
35
push_value
(vm,
make_int
(
ok
? 1 : 0));
36
break
;
37
}
OP_HAS_KEY
@ OP_HAS_KEY
Definition
bytecode.h:133
ok
int ok
Definition
contains.c:38
push_value
push_value(vm, make_int(ok ? 1 :0))
m
Value m
Definition
has_key.c:27
free_value
free_value(m)
map_has
int map_has(const Value *vm, const char *key)
Check whether the map contains the specified key.
Definition
map.c:130
Value
Tagged union representing a Fun value.
Definition
value.h:68
Value::type
ValueType type
Definition
value.h:69
Value::s
char * s
Definition
value.h:73
make_int
Value make_int(int64_t v)
Construct a Value representing a 64-bit integer.
Definition
value.c:51
VAL_MAP
@ VAL_MAP
Definition
value.h:56
VAL_STRING
@ VAL_STRING
Definition
value.h:53
fprintf
#define fprintf
Definition
vm.c:200
exit
#define exit(code)
Definition
vm.c:230
Generated on
for Fun by
1.16.1