summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2022-01-13 16:06:17 +0100
committerJo-Philipp Wich <jo@mein.io>2022-01-18 10:58:11 +0100
commit6c2caf9fbb9d346cfb20cd5c83875fdff77e584c (patch)
tree4d0fe816584e8f351ed0f1da8be0b9ccf1c5635f /include
parent725bb75b7b66dd1e0a381908e831cede0402cb6e (diff)
source: refactor source file handling
- Move source object pointer into program entity which is referenced by each function - Move lineinfo related routines into source.c and use them from lexer.c since lineinfo encoding does not belong into the lexical analyzer. - Implement initial infrastructure for detecting source file type, this is required later to differentiate between plaintext and precompiled bytecode files Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'include')
-rw-r--r--include/ucode/program.h4
-rw-r--r--include/ucode/source.h9
-rw-r--r--include/ucode/types.h4
3 files changed, 13 insertions, 4 deletions
diff --git a/include/ucode/program.h b/include/ucode/program.h
index 9bbc67e..0f56f99 100644
--- a/include/ucode/program.h
+++ b/include/ucode/program.h
@@ -20,11 +20,11 @@
#include "types.h"
-uc_program_t *uc_program_new(void);
+uc_program_t *uc_program_new(uc_source_t *);
void uc_program_free(uc_program_t *);
-uc_value_t *uc_program_function_new(uc_program_t *, const char *, size_t, uc_source_t *);
+uc_value_t *uc_program_function_new(uc_program_t *, const char *, size_t);
size_t uc_program_function_id(uc_program_t *, uc_value_t *);
uc_value_t *uc_program_function_load(uc_program_t *, size_t);
diff --git a/include/ucode/source.h b/include/ucode/source.h
index 3de7c93..e7a5667 100644
--- a/include/ucode/source.h
+++ b/include/ucode/source.h
@@ -25,6 +25,10 @@
#include "types.h"
+typedef enum {
+ UC_SOURCE_TYPE_PLAIN = 0,
+} uc_source_type_t;
+
uc_source_t *uc_source_new_file(const char *path);
uc_source_t *uc_source_new_buffer(const char *name, char *buf, size_t len);
@@ -33,4 +37,9 @@ size_t uc_source_get_line(uc_source_t *source, size_t *offset);
uc_source_t *uc_source_get(uc_source_t *source);
void uc_source_put(uc_source_t *source);
+uc_source_type_t uc_source_type_test(uc_source_t *source);
+
+void uc_source_line_next(uc_source_t *source);
+void uc_source_line_update(uc_source_t *source, size_t off);
+
#endif /* __SOURCE_H_ */
diff --git a/include/ucode/types.h b/include/ucode/types.h
index be10ac5..66db5ea 100644
--- a/include/ucode/types.h
+++ b/include/ucode/types.h
@@ -154,7 +154,6 @@ typedef struct uc_function {
size_t nupvals;
size_t srcpos;
uc_chunk_t chunk;
- uc_source_t *source;
struct uc_program *program;
uc_weakref_t progref;
char name[];
@@ -205,6 +204,7 @@ uc_declare_vector(uc_resource_types_t, uc_resource_type_t *);
typedef struct uc_program {
uc_value_list_t constants;
uc_weakref_t functions;
+ uc_source_t *source;
} uc_program_t;
@@ -350,7 +350,7 @@ size_t ucv_object_length(uc_value_t *);
: 0); \
entry##key = entry_next##key)
-uc_value_t *ucv_function_new(const char *, size_t, uc_source_t *, uc_program_t *);
+uc_value_t *ucv_function_new(const char *, size_t, uc_program_t *);
size_t ucv_function_srcpos(uc_value_t *, size_t);
uc_value_t *ucv_cfunction_new(const char *, uc_cfn_ptr_t);