diff options
author | ubq323 <ubq323@ubq323.website> | 2023-08-04 22:38:48 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2023-08-04 22:38:48 +0100 |
commit | f67a3fd05c1b2fe8c749fc2f58287b1b14b011d8 (patch) | |
tree | 5566db459c3414ad1c9c18bcc61a21e0ab034f37 | |
parent | 7c9790d7726e0bb3f44bec15eff7631080d45b03 (diff) |
move M to its own file
-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; |