Built-ins: Maps and more... ;)
This commit is contained in:
parent
a4f4fcba99
commit
d1bbd2e501
9 changed files with 663 additions and 36 deletions
15
src/value.h
15
src/value.h
|
|
@ -5,12 +5,14 @@
|
|||
|
||||
struct Bytecode; /* forward */
|
||||
struct Array; /* forward */
|
||||
struct Map; /* forward */
|
||||
|
||||
typedef enum {
|
||||
VAL_INT,
|
||||
VAL_STRING,
|
||||
VAL_FUNCTION,
|
||||
VAL_ARRAY,
|
||||
VAL_MAP,
|
||||
VAL_NIL
|
||||
} ValueType;
|
||||
|
||||
|
|
@ -21,6 +23,7 @@ typedef struct {
|
|||
char *s;
|
||||
struct Bytecode *fn;
|
||||
struct Array *arr;
|
||||
struct Map *map;
|
||||
};
|
||||
} Value;
|
||||
|
||||
|
|
@ -42,9 +45,17 @@ int array_remove(Value *v, int index, Value *out); /* returns 1 on suc
|
|||
Value array_slice(const Value *v, int start, int end); /* negative end means till end */
|
||||
Value array_concat(const Value *a, const Value *b); /* returns new array */
|
||||
|
||||
/* maps (string keys) */
|
||||
Value make_map_empty(void); /* new empty map */
|
||||
int map_set(Value *m, const char *key, Value v); /* 1 on ok (takes ownership of v) */
|
||||
int map_get_copy(const Value *m, const char *key, Value *out);/* 1 on found, out=copy */
|
||||
int map_has(const Value *m, const char *key); /* 1/0 */
|
||||
Value map_keys_array(const Value *m); /* array of strings */
|
||||
Value map_values_array(const Value *m); /* array of values (copies) */
|
||||
|
||||
/* copy/free */
|
||||
Value copy_value(const Value *v); /* deep for strings, RC for arrays, shallow fn */
|
||||
Value deep_copy_value(const Value *v); /* deep copy including arrays */
|
||||
Value copy_value(const Value *v); /* deep for strings, RC for arrays/maps, shallow fn */
|
||||
Value deep_copy_value(const Value *v); /* deep copy including arrays/maps */
|
||||
void free_value(Value v); /* frees owned resources */
|
||||
|
||||
/* utilities */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue