45 v.map = (
struct Map *)
m;
55static int map_ensure_cap(
Map *
m,
int need) {
56 if (
m->cap >= need)
return 1;
57 int ncap =
m->cap == 0 ? 4 :
m->cap * 2;
60 char **nkeys = (
char **)realloc(
m->keys,
sizeof(
char *) * ncap);
62 if (!nkeys || !nvals)
return 0;
85 for (
int i = 0; i <
m->count; ++i) {
86 if (strcmp(
m->keys[i], key) == 0) {
92 if (!map_ensure_cap(
m,
m->count + 1)) {
96 m->keys[
m->count] = strdup(key);
97 m->vals[
m->count] =
v;
115 for (
int i = 0; i <
m->count; ++i) {
116 if (strcmp(
m->keys[i], key) == 0) {
133 for (
int i = 0; i <
m->count; ++i) {
134 if (strcmp(
m->keys[i], key) == 0)
return 1;
153 for (
int i = 0; i <
m->count; ++i) {
157 for (
int i = 0; i <
m->count; ++i)
177 for (
int i = 0; i <
m->count; ++i) {
181 for (
int i = 0; i <
m->count; ++i)
int map_set(Value *vm, const char *key, Value v)
Insert or replace a key in the map.
Value map_values_array(const Value *vm)
Return all map values as an array (deep-copied).
Value make_map_empty(void)
Construct a new empty map Value.
int map_get_copy(const Value *vm, const char *key, Value *out)
Look up a key and copy the stored value into out.
Value map_keys_array(const Value *vm)
Return all map keys as an array of strings.
int map_has(const Value *vm, const char *key)
Check whether the map contains the specified key.
Tagged union representing a Fun value.
Value make_nil(void)
Construct a nil Value.
Value make_string(const char *s)
Construct a string Value by duplicating the given C string.
void free_value(Value v)
Free dynamic storage owned by a Value.
Value make_array_from_values(const Value *vals, int count)
Create an array Value by copying items from an input span.
Value copy_value(const Value *v)
Shallow copy a Value.
Defines the Value type and associated functions for the Fun VM.