diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-01-28 20:15:13 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-01-29 23:33:07 +0100 |
commit | 2cb627f3ba79bfce98e4cf6ab4b2e8029e8cb09e (patch) | |
tree | d4080e561b42f0ae706efe07b7158e9555eab708 /include | |
parent | 1094ffa276990fd53abe633e5b14869d7c538a16 (diff) |
program: rename bytecode load/write functions, track path of executed file
Extend source objects with a `runpath` field which contains the original
path of the source being executed by the VM.
When instantiating source objects from file paths, the `runpath` will be
set to the `filename`. When instantiating source buffers using
`uc_source_new_buffer()`, the runpath is initially unset.
A new function `uc_source_runpath_set()` can be used to adjust the runtime
path being associated with a source object.
Extend bytecode loading logic to set the source buffer runtime path to the
precompiled bytecode file path being loaded and executed. This is required
for `sourcepath()` and relative paths in `include()` to function correctly
when executing precompiled programs.
Finally rename `uc_program_from_file()` and `uc_program_to_file()` to
`uc_program_load()` and `uc_program_write()` respectively since the load
part now operates on an `uc_source_t` input buffer instead of a plain
`FILE *` handle.
Adjust users of these API functions accordingly.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'include')
-rw-r--r-- | include/ucode/program.h | 4 | ||||
-rw-r--r-- | include/ucode/source.h | 2 | ||||
-rw-r--r-- | include/ucode/types.h | 2 |
3 files changed, 5 insertions, 3 deletions
diff --git a/include/ucode/program.h b/include/ucode/program.h index 9a5c553..39131eb 100644 --- a/include/ucode/program.h +++ b/include/ucode/program.h @@ -31,8 +31,8 @@ uc_value_t *uc_program_function_load(uc_program_t *, size_t); uc_value_t *uc_program_get_constant(uc_program_t *, size_t); ssize_t uc_program_add_constant(uc_program_t *, uc_value_t *); -void uc_program_to_file(uc_program_t *, FILE *, bool); -uc_program_t *uc_program_from_file(FILE *file, char **); +void uc_program_write(uc_program_t *, FILE *, bool); +uc_program_t *uc_program_load(uc_source_t *, char **); uc_function_t *uc_program_entry(uc_program_t *); diff --git a/include/ucode/source.h b/include/ucode/source.h index ac0b487..b05e84b 100644 --- a/include/ucode/source.h +++ b/include/ucode/source.h @@ -45,4 +45,6 @@ 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); +void uc_source_runpath_set(uc_source_t *source, const char *runpath); + #endif /* __SOURCE_H_ */ diff --git a/include/ucode/types.h b/include/ucode/types.h index 66db5ea..cc55150 100644 --- a/include/ucode/types.h +++ b/include/ucode/types.h @@ -66,7 +66,7 @@ typedef struct { uc_declare_vector(uc_lineinfo_t, uint8_t); typedef struct { - char *filename, *buffer; + char *filename, *runpath, *buffer; FILE *fp; size_t usecount, off; uc_lineinfo_t lineinfo; |