diff options
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | mem.c | 18 | ||||
-rw-r--r-- | mem.h | 8 | ||||
-rw-r--r-- | val.c | 3 | ||||
-rw-r--r-- | vm.c | 15 | ||||
-rw-r--r-- | vm.h | 2 |
6 files changed, 31 insertions, 19 deletions
@@ -1,5 +1,5 @@ -CS=ast.c com.c dis.c prs.c read.c val.c vm.c -HS=ast.h dis.h prs.h read.h val.h vm.h +CS=ast.c com.c dis.c mem.c prs.c read.c val.c vm.c +HS=ast.h dis.h mem.h prs.h read.h val.h vm.h CFLAGS=-O3 -Wall -Wpedantic -Werror=implicit-function-declaration bþ: $(CS) $(HS) @@ -0,0 +1,18 @@ +#include "mem.h" + +#include <stdio.h> +#include <stdlib.h> + +void *M(void *p, size_t sz) { + if (sz == 0) { + free(p); + return NULL; + } else { + void *x = realloc(p, sz); + if (x == NULL) { + printf("out of memory! aaaaaaa!!!!!\n"); + exit(42); + } + return x; + } +} @@ -0,0 +1,8 @@ +#ifndef _mem_h +#define _mem_h + +#include <stddef.h> + +void *M(void *p, size_t sz); + +#endif @@ -1,7 +1,8 @@ #include <stdio.h> #include <string.h> #include "val.h" -#include "vm.h" +#include "mem.h" + ObjString *objstring_new(char *src, size_t len) { char *d = M(NULL, (1 + len) * sizeof (char)); @@ -6,22 +6,9 @@ #include "val.h" #include "vm.h" +#include "mem.h" #include "dis.h" -void *M(void *p, size_t sz) { - if (sz == 0) { - free(p); - return NULL; - } else { - void *x = realloc(p, sz); - if (x == NULL) { - printf("out of memory! aaaaaaa!!!!!\n"); - exit(42); - } - return x; - } -} - Chunk chunk_new() { return (Chunk){ @@ -7,8 +7,6 @@ #include "val.h" -void *M(void *p, size_t sz); - typedef struct { // bytecode size_t blen; |