Fun 0.41.5
The programming language that makes You have fun
Loading...
Searching...
No Matches
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
34 int pairs = inst.operand;
35 if (pairs < 0) {
36 fprintf(stderr, "MAKE_MAP invalid pair count\n");
37 exit(1);
38 }
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 }
54 break;
55}
@ OP_MAKE_MAP
Definition bytecode.h:130
Value m
Definition has_key.c:27
Value val
Definition load_local.c:36
push_value(vm, m)
int map_set(Value *vm, const char *key, Value v)
Insert or replace a key in the map.
Definition map.c:79
Value make_map_empty(void)
Construct a new empty map Value.
Definition map.c:35
Tagged union representing a Fun value.
Definition value.h:68
ValueType type
Definition value.h:69
char * s
Definition value.h:73
void free_value(Value v)
Free dynamic storage owned by a Value.
Definition value.c:517
@ VAL_STRING
Definition value.h:53
#define fprintf
Definition vm.c:200
#define exit(code)
Definition vm.c:230