summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2022-07-20 14:49:18 +0200
committerJo-Philipp Wich <jo@mein.io>2022-07-30 00:41:56 +0200
commit41114a02a38a65956010bab95c4bff19af7ac1ed (patch)
treed993746857c6a57ff61dfefc315537825c1ee63f
parent70ae3040fb384e7a77ef43ca6b426269f9acdcab (diff)
source: add tracking of exported symbols
Extend abstract source objects to maintain a list of exported symbols and add functions to append and lookup exported names. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r--include/ucode/source.h3
-rw-r--r--include/ucode/types.h2
-rw-r--r--source.c25
-rw-r--r--types.c4
4 files changed, 34 insertions, 0 deletions
diff --git a/include/ucode/source.h b/include/ucode/source.h
index 6f9a8d7..b3eaa34 100644
--- a/include/ucode/source.h
+++ b/include/ucode/source.h
@@ -54,4 +54,7 @@ void uc_source_line_update(uc_source_t *source, size_t off);
void uc_source_runpath_set(uc_source_t *source, const char *runpath);
+bool uc_source_export_add(uc_source_t *source, uc_value_t *name);
+ssize_t uc_source_export_lookup(uc_source_t *source, uc_value_t *name);
+
#endif /* UCODE_SOURCE_H */
diff --git a/include/ucode/types.h b/include/ucode/types.h
index 314dbc8..cde84f6 100644
--- a/include/ucode/types.h
+++ b/include/ucode/types.h
@@ -65,6 +65,7 @@ typedef struct {
/* Source buffer defintions */
uc_declare_vector(uc_lineinfo_t, uint8_t);
+uc_declare_vector(uc_exports_t, uc_value_t *);
typedef struct {
uc_value_t header;
@@ -72,6 +73,7 @@ typedef struct {
FILE *fp;
size_t off;
uc_lineinfo_t lineinfo;
+ uc_exports_t exports;
} uc_source_t;
diff --git a/source.c b/source.c
index b8f2e91..902ad4c 100644
--- a/source.c
+++ b/source.c
@@ -196,3 +196,28 @@ uc_source_runpath_set(uc_source_t *source, const char *runpath)
source->runpath = xstrdup(runpath);
}
+
+bool
+uc_source_export_add(uc_source_t *source, uc_value_t *name)
+{
+ ssize_t idx = uc_source_export_lookup(source, name);
+
+ if (idx > -1)
+ return false;
+
+ uc_vector_push(&source->exports, ucv_get(name));
+
+ return true;
+}
+
+ssize_t
+uc_source_export_lookup(uc_source_t *source, uc_value_t *name)
+{
+ size_t i;
+
+ for (i = 0; i < source->exports.count; i++)
+ if (ucv_is_equal(source->exports.entries[i], name))
+ return i;
+
+ return -1;
+}
diff --git a/types.c b/types.c
index e7c9afa..2fba207 100644
--- a/types.c
+++ b/types.c
@@ -292,7 +292,11 @@ ucv_free(uc_value_t *uv, bool retain)
if (source->runpath != source->filename)
free(source->runpath);
+ for (i = 0; i < source->exports.count; i++)
+ ucv_put(source->exports.entries[i]);
+
uc_vector_clear(&source->lineinfo);
+ uc_vector_clear(&source->exports);
fclose(source->fp);
free(source->buffer);
break;