diff options
Diffstat (limited to 'bytecode/bytecode.c')
| -rw-r--r-- | bytecode/bytecode.c | 59 |
1 files changed, 0 insertions, 59 deletions
diff --git a/bytecode/bytecode.c b/bytecode/bytecode.c deleted file mode 100644 index 9ac4a1e..0000000 --- a/bytecode/bytecode.c +++ /dev/null @@ -1,59 +0,0 @@ -#include <stdbool.h> -#include <stdio.h> -#include <stdlib.h> - -#include "oper.h" -#include "panic.h" -#include "byte_slice.h" - -static uint8_t_slice xrealloc(void *ptr, size_t size) -{ - void *p = realloc(ptr, size); - if (!p) { - panicf("Out of memory!\n"); - } - return (uint8_t_slice) { - .buf = p, - .size = size, - }; -} - -static uint8_t_slice read_file(char *filename) -{ - FILE *f = fopen(filename, "r"); - if (!f) { - panicf("File %s does not exit!\n", filename); - } - uint8_t_slice out = { .size = 0, .buf = NULL }; - size_t offset = 0; - while (true) { - if (offset >= out.size) { - size_t new_size = 2 * out.size + 1; - out = xrealloc(out.buf, new_size); - } - size_t read_size = out.size - offset; - size_t n = fread(out.buf + offset, 1, read_size, f); - if (n < read_size) { - if (ferror(f)) { - panicf("Read error!\n"); - } - return uint8_t_slice2(out, 0, offset + n); - } - offset += n; - } -} - -int main(int argc, char **argv) -{ - if (argc < 2) { - printf("Usage error: need a filename.\n"); - return 1; - } - - uint8_t_slice program = read_file(argv[1]); - - run(program); - - // run never returns. I'm just putting this here to taunt you: - free(program.buf); -} |
