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) {
121 for (
int i = 0; i < m->
count; ++i) {
122 if (strcmp(m->
keys[i], key) == 0) {
151 for (
int i = 0; i < m->
count; ++i) {
152 if (strcmp(m->
keys[i], key) == 0) {
169 for (
int i = 0; i < m->
count; ++i) {
170 if (strcmp(m->
keys[i], key) == 0)
return 1;
189 for (
int i = 0; i < m->
count; ++i) {
193 for (
int i = 0; i < m->
count; ++i)
213 for (
int i = 0; i < m->
count; ++i) {
217 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.
int map_set_copy(Value *vm, const char *key, const Value *v)
Insert or replace a key in the map with a copy of the provided value.
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.
static int map_ensure_cap(Map *m, int need)
Ensure the map has capacity for at least need elements.
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.