aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/forward_decl.h8
-rw-r--r--include/program.h5
-rw-r--r--include/std_gc/hash_map.h3
-rw-r--r--include/std_gc/list.h21
-rw-r--r--include/value.h27
5 files changed, 49 insertions, 15 deletions
diff --git a/include/forward_decl.h b/include/forward_decl.h
new file mode 100644
index 0000000..cc7ec12
--- /dev/null
+++ b/include/forward_decl.h
@@ -0,0 +1,8 @@
+#ifndef TSL_FORWARD_DECL_H
+#define TSL_FORWARD_DECL_H
+
+typedef struct TslValue TslValue;
+
+struct ____tsl_dummy { int dd; };
+
+#endif /* TSL_FORWARD_DECL_H */
diff --git a/include/program.h b/include/program.h
index 5c4737b..bbd3f37 100644
--- a/include/program.h
+++ b/include/program.h
@@ -10,9 +10,12 @@ typedef enum {
TSL_STACK_VALUE_TYPE_NUMBER,
TSL_STACK_VALUE_TYPE_BOOL,
TSL_STACK_VALUE_TYPE_STRING,
+ TSL_STACK_VALUE_TYPE_NULL,
TSL_STACK_VALUE_TYPE_FUNCTION,
TSL_STACK_VALUE_TYPE_VARIABLE,
- TSL_STACK_VALUE_TYPE_NULL,
+ TSL_STACK_VALUE_TYPE_LIST,
+ TSL_STACK_VALUE_TYPE_MAP,
+ TSL_STACK_VALUE_TYPE_INDEX,
TSL_STACK_VALUE_TYPE_COMMAND_ARG
} TslStackValueType;
diff --git a/include/std_gc/hash_map.h b/include/std_gc/hash_map.h
index e67dd75..e1a016d 100644
--- a/include/std_gc/hash_map.h
+++ b/include/std_gc/hash_map.h
@@ -1,8 +1,9 @@
#ifndef TSL_HASH_MAP_H
#define TSL_HASH_MAP_H
-#include "../value.h"
+#include "../forward_decl.h"
#include <stdint.h>
+#include <stddef.h>
/* TODO: Optimize small hash map by using the members of the struct instead of allocating on heap */
typedef struct {
diff --git a/include/std_gc/list.h b/include/std_gc/list.h
new file mode 100644
index 0000000..469f585
--- /dev/null
+++ b/include/std_gc/list.h
@@ -0,0 +1,21 @@
+#ifndef TSL_LIST_H
+#define TSL_LIST_H
+
+#include "../forward_decl.h"
+#include <stddef.h>
+
+typedef struct {
+ void *data;
+ size_t size;
+ size_t capacity;
+} TslList;
+
+void tsl_list_init(TslList *self);
+int tsl_list_append(TslList *self, const TslValue *data);
+int tsl_list_set_capacity_hint(TslList *self, size_t capacity);
+TslValue* tsl_list_begin(TslList *self);
+TslValue* tsl_list_end(TslList *self);
+/* Returns NULL if index is out of bounds of the list */
+TslValue* tsl_list_get(TslList *self, double index);
+
+#endif /* TSL_LIST_H */
diff --git a/include/value.h b/include/value.h
index e26cc4a..d9c6354 100644
--- a/include/value.h
+++ b/include/value.h
@@ -1,9 +1,12 @@
#ifndef TSL_VALUE_H
#define TSL_VALUE_H
+#include "forward_decl.h"
#include <stddef.h>
#include <stdint.h>
#include "string_view.h"
+#include "std_gc/list.h"
+#include "std_gc/hash_map.h"
typedef enum {
TSL_TYPE_NULL,
@@ -13,6 +16,7 @@ typedef enum {
TSL_TYPE_BOOL,
TSL_TYPE_LIST,
TSL_TYPE_MAP,
+ TSL_TYPE_FUNCTION,
TSL_TYPE_USERDATA
} TslType;
@@ -29,32 +33,29 @@ typedef struct {
size_t size;
} TslString;
-/* TODO: Implement this */
-typedef struct {
- void *data;
- size_t size;
-} TslList;
-
-/* TODO: Implement this */
-typedef struct {
- void *data;
-} TslMap;
+/* This is an index to the function */
+typedef int TslFunction;
-typedef struct {
+struct TslValue {
union {
TslNumber number;
TslString *string;
TslStringView string_view;
TslBool boolean;
+ TslBool null;
TslList *list;
- TslMap *map;
+ TslHashMap *map;
+ TslFunction function;
void *userdata;
} data;
uint8_t type;
-} TslValue;
+};
uint64_t tsl_value_hash(const TslValue *value);
/* Returns 1 if equal, otherwise returns 0 */
int tsl_value_equals(const TslValue *lhs, const TslValue *rhs);
+/* This should be called before setting/modifying the data of the value */
+void tsl_value_clear(TslValue *self);
+
#endif /* TSL_VALUE_H */