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
make_map.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
32
33
case
OP_MAKE_MAP
: {
34
int
pairs = inst.operand;
35
if
(pairs < 0) {
36
fprintf
(stderr,
"MAKE_MAP invalid pair count\n"
);
37
exit
(1);
38
}
39
Value
m
=
make_map_empty
();
40
for
(
int
i = 0; i < pairs; ++i) {
41
Value
val
= pop_value(vm);
42
Value
key = pop_value(vm);
43
if
(key.
type
!=
VAL_STRING
) {
44
fprintf
(stderr,
"Map literal keys must be strings\n"
);
45
exit
(1);
46
}
47
if
(!
map_set
(&
m
, key.
s
? key.
s
:
""
,
val
)) {
48
fprintf
(stderr,
"Map literal set failed\n"
);
49
exit
(1);
50
}
51
free_value
(key);
52
}
53
push_value
(vm,
m
);
54
break
;
55
}
OP_MAKE_MAP
@ OP_MAKE_MAP
Definition
bytecode.h:130
m
Value m
Definition
has_key.c:27
val
Value val
Definition
load_local.c:36
push_value
push_value(vm, m)
map_set
int map_set(Value *vm, const char *key, Value v)
Insert or replace a key in the map.
Definition
map.c:79
make_map_empty
Value make_map_empty(void)
Construct a new empty map Value.
Definition
map.c:35
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
free_value
void free_value(Value v)
Free dynamic storage owned by a Value.
Definition
value.c:517
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