Fun 0.41.5
The programming language that makes You have fun
Loading...
Searching...
No Matches
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
25case 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 : "");
35 push_value(vm, make_int(ok ? 1 : 0));
36 break;
37}
@ OP_HAS_KEY
Definition bytecode.h:133
int ok
Definition contains.c:38
push_value(vm, make_int(ok ? 1 :0))
Value m
Definition has_key.c:27
free_value(m)
int map_has(const Value *vm, const char *key)
Check whether the map contains the specified key.
Definition map.c:130
Tagged union representing a Fun value.
Definition value.h:68
ValueType type
Definition value.h:69
char * s
Definition value.h:73
Value make_int(int64_t v)
Construct a Value representing a 64-bit integer.
Definition value.c:51
@ VAL_MAP
Definition value.h:56
@ VAL_STRING
Definition value.h:53
#define fprintf
Definition vm.c:200
#define exit(code)
Definition vm.c:230