Tagged union representing a Fun value.
int value_is_truthy(const Value *v)
Evaluate a Value's truthiness according to Fun language rules.
Value make_bool(int v)
Construct a boolean Value.
char * string_substr(const char *s, int start, int len)
Create a newly allocated substring of s.
void print_value(const Value *v)
Print a human-readable representation of a Value to stdout.
char * array_join_with_sep(const Value *arr, const char *sep)
Join the elements of a Value array into a single newly allocated C string.
Value make_nil(void)
Construct a nil Value.
int array_insert(Value *v, int index, Value newElem)
Insert a new element at a specific position in an array.
int array_pop(Value *v, Value *out)
Remove the last element from an array.
Value make_string(const char *s)
Construct a string Value by duplicating the given C string.
int array_length(const Value *v)
Get the element count of an array Value.
int map_set(Value *m, const char *key, Value v)
Insert or replace a key in the map.
Value make_function(struct Bytecode *fn)
Construct a function Value referencing bytecode.
Value deep_copy_value(const Value *v)
Deep copy a Value, recursively copying arrays and maps.
int array_contains(const Value *arr, const Value *needle)
Check if an array Value contains a given element.
void free_value(Value v)
Free dynamic storage owned by a Value.
Value array_concat(const Value *a, const Value *b)
Concatenate two array Values.
int map_get_copy(const Value *m, const char *key, Value *out)
Look up a key and copy the stored value into out.
char * value_to_string_alloc(const Value *v)
Allocate a printable C string for a Value.
int array_get_copy(const Value *v, int index, Value *out)
Copy an array element into out.
Value make_float(double v)
Construct a Value representing a double-precision float.
Value make_map_empty(void)
Construct a new empty map Value.
Value map_values_array(const Value *m)
Return all map values as an array (deep-copied).
int map_has(const Value *m, const char *key)
Check whether the map contains the specified key.
int array_push(Value *v, Value newElem)
Append a Value to an array.
int value_equals(const Value *a, const Value *b)
Compare two Values for equality.
int string_find(const char *hay, const char *needle)
Find first occurrence of needle in hay.
void array_clear(Value *arr)
Remove all elements from an array Value, freeing their contents.
Value string_split_to_array(const char *s, const char *sep)
Split a C string by separator into a Value array of strings.
Value make_int(int64_t v)
Construct a Value representing a 64-bit integer.
int array_index_of(const Value *arr, const Value *needle)
Find the index of the first occurrence of an element in an array.
Value array_slice(const Value *v, int start, int end)
Create a shallow-copied slice of an array Value.
Value make_array_from_values(const Value *vals, int count)
Create an array Value by copying items from an input span.
ValueType
Enumeration of all runtime value types supported by Fun.
int array_set(Value *v, int index, Value newElem)
Replace an element of an array with a new Value.
Value map_keys_array(const Value *m)
Return all map keys as an array of strings.
Value copy_value(const Value *v)
Shallow copy a Value.
int array_remove(Value *v, int index, Value *out)
Remove an element at index from an array.