compiler now compiles some things
This commit is contained in:
parent
9616fb616e
commit
ce345f2440
13 changed files with 425 additions and 74 deletions
36
src/chunk.c
36
src/chunk.c
|
|
@ -1,6 +1,37 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "chunk.h"
|
||||
|
||||
#include "vendor/yar.h"
|
||||
|
||||
Bc *chunk_new(V) {
|
||||
Bc *chunk = calloc(1, sizeof(Bc));
|
||||
chunk->ref = 1;
|
||||
return chunk;
|
||||
}
|
||||
|
||||
V chunk_acquire(Bc *chunk) {
|
||||
#if CHUNK_DEBUG
|
||||
fprintf(stderr, "DEBUG: acquiring chunk at %p\n", (V *)chunk);
|
||||
#endif
|
||||
chunk->ref++;
|
||||
}
|
||||
V chunk_release(Bc *chunk) {
|
||||
#if CHUNK_DEBUG
|
||||
fprintf(stderr, "DEBUG: releasing chunk at %p\n", (V *)chunk);
|
||||
#endif
|
||||
|
||||
if (--chunk->ref == 0) {
|
||||
#if CHUNK_DEBUG
|
||||
fprintf(stderr, "DEBUG: freeing chunk at %p\n", (V *)chunk);
|
||||
#endif
|
||||
yar_free(&chunk->constants);
|
||||
yar_free(chunk);
|
||||
free(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
V chunk_emit_byte(Bc *chunk, U8 byte) { *yar_append(chunk) = byte; }
|
||||
|
||||
V chunk_emit_sleb128(Bc *chunk, I num) {
|
||||
|
|
@ -22,8 +53,3 @@ I chunk_add_constant(Bc *chunk, O value) {
|
|||
*yar_append(&chunk->constants) = value;
|
||||
return mark;
|
||||
}
|
||||
|
||||
V chunk_free(Bc *chunk) {
|
||||
yar_free(&chunk->constants);
|
||||
yar_free(chunk);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue