diff options
| author | Rose Hogenson <rhogenson@posteo.net> | 2023-02-11 21:31:04 -0800 |
|---|---|---|
| committer | Rose Hogenson <rhogenson@posteo.net> | 2023-02-11 21:31:04 -0800 |
| commit | 5989629a7951e544ad4656672025a99ecd08c7c9 (patch) | |
| tree | 89e2ca80f73d8dcf16a9fadcea41b2e141bdf4eb /bytecode/bytecode.c | |
| parent | aafc502de6f9ecbeb4638b1862f4fa5ac82199d7 (diff) | |
| download | sml-5989629a7951e544ad4656672025a99ecd08c7c9.tar.zst | |
Change how slices work.
I'm switching to a more macro-heavy solution. Hopefully it
proves robust.
Diffstat (limited to 'bytecode/bytecode.c')
| -rw-r--r-- | bytecode/bytecode.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/bytecode/bytecode.c b/bytecode/bytecode.c index 1d0f957..9ac4a1e 100644 --- a/bytecode/bytecode.c +++ b/bytecode/bytecode.c @@ -4,27 +4,27 @@ #include "oper.h" #include "panic.h" -#include "slice.h" +#include "byte_slice.h" -static struct slice xrealloc(void *ptr, size_t size) +static uint8_t_slice xrealloc(void *ptr, size_t size) { void *p = realloc(ptr, size); if (!p) { panicf("Out of memory!\n"); } - return (struct slice) { + return (uint8_t_slice) { .buf = p, .size = size, }; } -struct slice read_file(char *filename) +static uint8_t_slice read_file(char *filename) { FILE *f = fopen(filename, "r"); if (!f) { panicf("File %s does not exit!\n", filename); } - struct slice out = { .size = 0, .buf = NULL }; + uint8_t_slice out = { .size = 0, .buf = NULL }; size_t offset = 0; while (true) { if (offset >= out.size) { @@ -37,7 +37,7 @@ struct slice read_file(char *filename) if (ferror(f)) { panicf("Read error!\n"); } - return slice(out, 0, offset + n); + return uint8_t_slice2(out, 0, offset + n); } offset += n; } @@ -50,7 +50,7 @@ int main(int argc, char **argv) return 1; } - struct slice program = read_file(argv[1]); + uint8_t_slice program = read_file(argv[1]); run(program); |
