move to meson for build system
This commit is contained in:
parent
fdd1ee61b5
commit
9616fb616e
28 changed files with 123 additions and 24 deletions
|
|
@ -1,7 +1,13 @@
|
|||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
|
||||
[*.{c,h,grr}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[meson.build]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
|
|
|||
5
.gitignore
vendored
5
.gitignore
vendored
|
|
@ -1,5 +1,4 @@
|
|||
*.o
|
||||
.cache
|
||||
/growl
|
||||
/.cache
|
||||
/build
|
||||
/.envrc
|
||||
/compile_commands.json
|
||||
|
|
|
|||
11
makefile
11
makefile
|
|
@ -1,11 +0,0 @@
|
|||
CC := cc
|
||||
CFLAGS := -Og -g -std=c99 -Wpedantic -Wall
|
||||
OBJS = chunk.o gc.o main.o object.o parser.o print.o vm.o vendor/mpc.o \
|
||||
vendor/yar.o
|
||||
|
||||
growl: $(OBJS)
|
||||
$(CC) -o growl $(OBJS)
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f growl $(OBJS)
|
||||
25
meson.build
Normal file
25
meson.build
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
project(
|
||||
'growl',
|
||||
'c',
|
||||
meson_version : '>= 1.3.0',
|
||||
version : '0.1',
|
||||
default_options : ['buildtype=debugoptimized', 'c_std=c99', 'warning_level=3'],
|
||||
)
|
||||
|
||||
sources = [
|
||||
'src/chunk.c',
|
||||
'src/compile.c',
|
||||
'src/gc.c',
|
||||
'src/object.c',
|
||||
'src/parser.c',
|
||||
'src/print.c',
|
||||
'src/vm.c',
|
||||
'src/vendor/mpc.c',
|
||||
'src/vendor/yar.c',
|
||||
]
|
||||
|
||||
exe = executable(
|
||||
'growl',
|
||||
'src/main.c', sources,
|
||||
install : true,
|
||||
)
|
||||
0
object.c
0
object.c
0
print.c
0
print.c
0
print.h
0
print.h
|
|
@ -3,5 +3,6 @@
|
|||
pkgs.mkShell {
|
||||
buildInputs = with pkgs; [
|
||||
clang-tools bear gdb tinycc
|
||||
meson ninja
|
||||
];
|
||||
}
|
||||
|
|
|
|||
6
src/compile.c
Normal file
6
src/compile.c
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#include "compile.h"
|
||||
|
||||
|
||||
I compile_program(mpc_ast_t *ast) {
|
||||
|
||||
}
|
||||
4
src/compile.h
Normal file
4
src/compile.h
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#include "common.h"
|
||||
#include "vendor/mpc.h"
|
||||
|
||||
I compile_program(mpc_ast_t *);
|
||||
|
|
@ -3,7 +3,9 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "chunk.h"
|
||||
#include "gc.h"
|
||||
#include "object.h"
|
||||
#include "vendor/yar.h"
|
||||
|
||||
#define ALIGN(n) (((n) + 7) & ~7)
|
||||
|
|
@ -18,14 +20,14 @@ V gc_reset(Gc *gc, I mark) { gc->roots.count = mark; }
|
|||
|
||||
static O copy(Gc *gc, Hd *hdr) {
|
||||
assert(infrom(gc, hdr));
|
||||
assert(hdr->type != TYPE_FWD);
|
||||
assert(hdr->type != OBJ_FWD);
|
||||
|
||||
Z sz = ALIGN(hdr->size);
|
||||
Hd *new = (Hd *)gc->to.free;
|
||||
gc->to.free += sz;
|
||||
memcpy(new, hdr, sz);
|
||||
|
||||
hdr->type = TYPE_FWD;
|
||||
hdr->type = OBJ_FWD;
|
||||
O *obj = (O *)(hdr + 1);
|
||||
*obj = BOX(new);
|
||||
return *obj;
|
||||
|
|
@ -40,7 +42,7 @@ static O forward(Gc *gc, O obj) {
|
|||
return obj;
|
||||
|
||||
Hd *hdr = UNBOX(obj);
|
||||
if (hdr->type == TYPE_FWD) {
|
||||
if (hdr->type == OBJ_FWD) {
|
||||
O *o = (O *)(hdr + 1);
|
||||
return *o;
|
||||
} else {
|
||||
|
|
@ -76,7 +78,13 @@ V gc_collect(Gc *gc) {
|
|||
Hd *hdr = (Hd *)scan;
|
||||
switch (hdr->type) {
|
||||
// TODO: the rest of the owl
|
||||
case TYPE_FWD:
|
||||
case OBJ_QUOT: {
|
||||
Bc *chunk = (Bc *)(hdr + 1);
|
||||
for (Z i = 0; i < chunk->constants.count; i++)
|
||||
chunk->constants.items[i] = forward(gc, chunk->constants.items[i]);
|
||||
break;
|
||||
}
|
||||
case OBJ_FWD:
|
||||
fprintf(stderr, "fatal GC error: forwarding pointer in to-space\n");
|
||||
abort();
|
||||
default:
|
||||
10
src/object.c
Normal file
10
src/object.c
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#include "object.h"
|
||||
|
||||
I type(O o) {
|
||||
if (o == NIL)
|
||||
return TYPE_NIL;
|
||||
if (IMM(o))
|
||||
return TYPE_NUM;
|
||||
Hd *h = UNBOX(o);
|
||||
return h->type;
|
||||
}
|
||||
|
|
@ -11,7 +11,14 @@
|
|||
#define ORD(x) ((O)(x) >> 1)
|
||||
|
||||
enum {
|
||||
TYPE_FWD,
|
||||
OBJ_FWD = 2,
|
||||
OBJ_QUOT,
|
||||
};
|
||||
|
||||
enum {
|
||||
TYPE_NIL = 0,
|
||||
TYPE_NUM = 1,
|
||||
TYPE_FWD = OBJ_FWD,
|
||||
};
|
||||
|
||||
typedef uintptr_t O;
|
||||
|
|
@ -21,4 +28,6 @@ typedef struct Hd {
|
|||
U32 size, type;
|
||||
} Hd;
|
||||
|
||||
I type(O);
|
||||
|
||||
#endif
|
||||
|
|
@ -4,7 +4,6 @@
|
|||
#include "common.h"
|
||||
#include "vendor/mpc.h"
|
||||
|
||||
|
||||
V parser_init(V);
|
||||
V parser_deinit(V);
|
||||
|
||||
20
src/print.c
Normal file
20
src/print.c
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "object.h"
|
||||
#include "print.h"
|
||||
|
||||
V print(O o) {
|
||||
if (o == NIL) {
|
||||
printf("nil");
|
||||
} else if (IMM(o)) {
|
||||
printf("%" PRIdPTR, ORD(o));
|
||||
} else {
|
||||
printf("<obj type=%ld ptr=%p>", type(o), (void *)o);
|
||||
}
|
||||
}
|
||||
|
||||
V println(O o) {
|
||||
print(o);
|
||||
putchar('\n');
|
||||
}
|
||||
10
src/print.h
Normal file
10
src/print.h
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#ifndef PRINT_H
|
||||
#define PRINT_H
|
||||
|
||||
#include "common.h"
|
||||
#include "object.h"
|
||||
|
||||
V print(O);
|
||||
V println(O);
|
||||
|
||||
#endif
|
||||
0
vendor/mpc.c → src/vendor/mpc.c
vendored
0
vendor/mpc.c → src/vendor/mpc.c
vendored
0
vendor/mpc.h → src/vendor/mpc.h
vendored
0
vendor/mpc.h → src/vendor/mpc.h
vendored
0
vendor/yar.c → src/vendor/yar.c
vendored
0
vendor/yar.c → src/vendor/yar.c
vendored
0
vendor/yar.h → src/vendor/yar.h
vendored
0
vendor/yar.h → src/vendor/yar.h
vendored
|
|
@ -1,5 +1,7 @@
|
|||
#include "vm.h"
|
||||
#include "gc.h"
|
||||
#include "print.h"
|
||||
#include <stdio.h>
|
||||
|
||||
static I decode_sleb128(U8 **ptr) {
|
||||
I result = 0;
|
||||
|
|
@ -45,16 +47,23 @@ V vm_run(Vm *vm, Bc *chunk, I offset) {
|
|||
U8 opcode;
|
||||
switch (opcode = *vm->ip++) {
|
||||
case OP_NOP:
|
||||
break;
|
||||
case OP_RETURN:
|
||||
return;
|
||||
continue;
|
||||
case OP_CONST: {
|
||||
I idx = decode_sleb128(&vm->ip);
|
||||
vm_push(vm, chunk->constants.items[idx]);
|
||||
break;
|
||||
}
|
||||
case OP_RETURN:
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
gc_reset(&vm->gc, mark);
|
||||
// print stack :3
|
||||
for (O *i = vm->stack; i < vm->sp; i++) {
|
||||
print(*i);
|
||||
putchar(' ');
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
|
|
@ -9,8 +9,12 @@
|
|||
|
||||
enum {
|
||||
OP_NOP = 0,
|
||||
OP_CONST, // Push constant to stack
|
||||
OP_JUMP, // Relative jump
|
||||
OP_JUMP_IF_NIL, // Relative jump if top-of-stack is nil
|
||||
OP_DOWORD,
|
||||
OP_CALL,
|
||||
OP_RETURN,
|
||||
OP_CONST,
|
||||
};
|
||||
|
||||
#define STACK_SIZE 256
|
||||
Loading…
Add table
Add a link
Reference in a new issue