diff options
author | kartofen <mladenovnasko0@gmail.com> | 2023-08-14 21:20:39 +0300 |
---|---|---|
committer | kartofen <mladenovnasko0@gmail.com> | 2023-08-14 21:20:39 +0300 |
commit | a7bb8ace49f5725e0f92336ab5af28b4c8900aff (patch) | |
tree | 5d00d7a5d159e9702b46c23542fffc09e591c271 /src/value.h | |
parent | f83187a830deff27ce0cdd4c175ffe2785461685 (diff) |
parser done
Diffstat (limited to 'src/value.h')
-rw-r--r-- | src/value.h | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/value.h b/src/value.h new file mode 100644 index 0000000..60d2c43 --- /dev/null +++ b/src/value.h @@ -0,0 +1,62 @@ +#ifndef LITERAL_H +#define LITERAL_H + +typedef struct value *value_t; + +struct literal { + enum literal_type { + LITERAL_STRING, + LITERAL_NUM_INT, + LITERAL_NUM_FLOAT + } type; + + union { + char *string; + long num_int; + float num_float; + }; +}; + +// struct pair { +// }; +// struct proc { +// }; + +struct value { + enum value_type { + VALUE_SYMBOL, + VALUE_LITERAL, + VALUE_PAIR, + VALUE_LIST, + VALUE_PROC, + VALUE_TYPES + } type; + + int references; + + union { + char *symbol; + struct literal literal; + // struct pair pair; + // struct pari list; + // struct proc_t proc; + }; +}; + +// try to save data as a literal +// returns a value_t on success and NULL on fail +// ret is set to: 0 on sucess, > 0 on fail (data isnt this type), +// and < 0 on error +value_t value_create(enum value_type type, void *data, int *ret); + +// returns a value_t on success +value_t value_copy(value_t value); + +// destroys a value +void value_destroy(value_t value); + +// copy a string version of the value the buf[buf_sz] +// returns buf on success +char *value_string(value_t value, char *buf, size_t buf_sz); + +#endif |