mirror of
https://github.com/janet-lang/janet
synced 2025-02-17 17:20:01 +00:00
Remove dsiasm from binary.
This commit is contained in:
parent
1e8c1bb74c
commit
68f834f03b
4
Makefile
4
Makefile
@ -6,8 +6,8 @@ TARGET=interp
|
|||||||
PREFIX=/usr/local
|
PREFIX=/usr/local
|
||||||
|
|
||||||
# C sources
|
# C sources
|
||||||
HEADERS=vm.h ds.h compile.h parse.h value.h disasm.h datatypes.h gc.h util.h
|
HEADERS=vm.h ds.h compile.h parse.h value.h datatypes.h gc.h util.h
|
||||||
SOURCES=main.c parse.c value.c vm.c ds.c compile.c disasm.c gc.c
|
SOURCES=main.c parse.c value.c vm.c ds.c compile.c gc.c
|
||||||
OBJECTS=$(patsubst %.c,%.o,$(SOURCES))
|
OBJECTS=$(patsubst %.c,%.o,$(SOURCES))
|
||||||
|
|
||||||
all: $(TARGET)
|
all: $(TARGET)
|
||||||
|
12
main.c
12
main.c
@ -5,8 +5,8 @@
|
|||||||
#include "parse.h"
|
#include "parse.h"
|
||||||
#include "compile.h"
|
#include "compile.h"
|
||||||
#include "value.h"
|
#include "value.h"
|
||||||
#include "disasm.h"
|
|
||||||
|
|
||||||
|
/* Simple printer for gst strings */
|
||||||
void string_put(FILE *out, uint8_t * string) {
|
void string_put(FILE *out, uint8_t * string) {
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
uint32_t len = gst_string_length(string);
|
uint32_t len = gst_string_length(string);
|
||||||
@ -91,16 +91,8 @@ void debug_repl(FILE *in, FILE *out) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Print asm */
|
|
||||||
if (out) {
|
|
||||||
fprintf(out, "\n");
|
|
||||||
gst_dasm_function(out, func.data.function);
|
|
||||||
fprintf(out, "\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Execute function */
|
/* Execute function */
|
||||||
gst_load(&vm, func);
|
if (gst_start(&vm, func)) {
|
||||||
if (gst_start(&vm)) {
|
|
||||||
if (out) {
|
if (out) {
|
||||||
if (vm.crash) {
|
if (vm.crash) {
|
||||||
fprintf(out, "VM crash: %s\n", vm.crash);
|
fprintf(out, "VM crash: %s\n", vm.crash);
|
||||||
|
@ -9,4 +9,10 @@
|
|||||||
# Unlike most lisps, it is not a pure functional language. Also unlike lisp, gst does
|
# Unlike most lisps, it is not a pure functional language. Also unlike lisp, gst does
|
||||||
# not make much use of a list data structure, instead using arrays and objects for
|
# not make much use of a list data structure, instead using arrays and objects for
|
||||||
# better performance at runtime.
|
# better performance at runtime.
|
||||||
|
(do
|
||||||
|
(:= a 1)
|
||||||
|
(while (< a 1025)
|
||||||
|
(print a)
|
||||||
|
(:= a (* a 2))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
81
vm.c
81
vm.c
@ -18,19 +18,52 @@ static GstValue gst_vm_literal(Gst *vm, GstFunction *fn, uint16_t index) {
|
|||||||
return fn->def->literals[index];
|
return fn->def->literals[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Load a function into the VM. The function will be called with
|
||||||
|
* no arguments when run */
|
||||||
|
static void gst_load(Gst *vm, GstValue callee) {
|
||||||
|
uint32_t startCapacity;
|
||||||
|
uint32_t locals, i;
|
||||||
|
uint16_t *pc;
|
||||||
|
GstStackFrame *frame;
|
||||||
|
GstThread *thread = gst_alloc(vm, sizeof(GstThread));
|
||||||
|
if (callee.type == GST_FUNCTION) {
|
||||||
|
locals = callee.data.function->def->locals;
|
||||||
|
pc = callee.data.function->def->byteCode;
|
||||||
|
} else if (callee.type == GST_CFUNCTION) {
|
||||||
|
locals = 0;
|
||||||
|
pc = NULL;
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
startCapacity = locals + GST_FRAME_SIZE + 10;
|
||||||
|
thread->data = gst_alloc(vm, sizeof(GstValue) * startCapacity);
|
||||||
|
thread->capacity = startCapacity;
|
||||||
|
thread->count = GST_FRAME_SIZE;
|
||||||
|
vm->thread = thread;
|
||||||
|
frame = (GstStackFrame *)thread->data;
|
||||||
|
frame->prevSize = 0;
|
||||||
|
frame->size = locals;
|
||||||
|
frame->callee = callee;
|
||||||
|
frame->errorJump = NULL;
|
||||||
|
frame->env = NULL;
|
||||||
|
frame->pc = pc;
|
||||||
|
/* Nil arguments */
|
||||||
|
for (i = 0; i < locals; ++i)
|
||||||
|
thread->data[GST_FRAME_SIZE + i].type = GST_NIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Start running the VM */
|
/* Start running the VM */
|
||||||
int gst_start(Gst *vm) {
|
int gst_start(Gst *vm, GstValue func) {
|
||||||
/* VM state */
|
/* VM state */
|
||||||
GstThread thread = *vm->thread;
|
GstThread thread;
|
||||||
GstValue *stack;
|
GstValue *stack;
|
||||||
GstStackFrame frame;
|
GstStackFrame frame;
|
||||||
GstValue temp, v1, v2;
|
GstValue temp, v1, v2;
|
||||||
uint16_t *pc;
|
uint16_t *pc;
|
||||||
|
/* Load the callee */
|
||||||
/* Check for proper initialization */
|
gst_load(vm, func);
|
||||||
if (thread.count == 0) {
|
thread = *vm->thread;
|
||||||
gst_error(vm, "need thread in vm state");
|
|
||||||
}
|
|
||||||
stack = thread.data + thread.count;
|
stack = thread.data + thread.count;
|
||||||
frame = *((GstStackFrame *)(stack - GST_FRAME_SIZE));
|
frame = *((GstStackFrame *)(stack - GST_FRAME_SIZE));
|
||||||
pc = frame.pc;
|
pc = frame.pc;
|
||||||
@ -572,40 +605,6 @@ void gst_init(Gst *vm) {
|
|||||||
vm->thread = NULL;
|
vm->thread = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Load a function into the VM. The function will be called with
|
|
||||||
* no arguments when run */
|
|
||||||
void gst_load(Gst *vm, GstValue callee) {
|
|
||||||
uint32_t startCapacity;
|
|
||||||
uint32_t locals, i;
|
|
||||||
uint16_t *pc;
|
|
||||||
GstStackFrame *frame;
|
|
||||||
GstThread *thread = gst_alloc(vm, sizeof(GstThread));
|
|
||||||
if (callee.type == GST_FUNCTION) {
|
|
||||||
locals = callee.data.function->def->locals;
|
|
||||||
pc = callee.data.function->def->byteCode;
|
|
||||||
} else if (callee.type == GST_CFUNCTION) {
|
|
||||||
locals = 0;
|
|
||||||
pc = NULL;
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
startCapacity = locals + GST_FRAME_SIZE + 10;
|
|
||||||
thread->data = gst_alloc(vm, sizeof(GstValue) * startCapacity);
|
|
||||||
thread->capacity = startCapacity;
|
|
||||||
thread->count = GST_FRAME_SIZE;
|
|
||||||
vm->thread = thread;
|
|
||||||
frame = (GstStackFrame *)thread->data;
|
|
||||||
frame->prevSize = 0;
|
|
||||||
frame->size = locals;
|
|
||||||
frame->callee = callee;
|
|
||||||
frame->errorJump = NULL;
|
|
||||||
frame->env = NULL;
|
|
||||||
frame->pc = pc;
|
|
||||||
/* Nil arguments */
|
|
||||||
for (i = 0; i < locals; ++i)
|
|
||||||
thread->data[GST_FRAME_SIZE + i].type = GST_NIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Clear all memory associated with the VM */
|
/* Clear all memory associated with the VM */
|
||||||
void gst_deinit(Gst *vm) {
|
void gst_deinit(Gst *vm) {
|
||||||
gst_clear_memory(vm);
|
gst_clear_memory(vm);
|
||||||
|
7
vm.h
7
vm.h
@ -27,11 +27,8 @@ void gst_init(Gst * vm);
|
|||||||
/* Deinitialize the VM */
|
/* Deinitialize the VM */
|
||||||
void gst_deinit(Gst * vm);
|
void gst_deinit(Gst * vm);
|
||||||
|
|
||||||
/* Load a function to be run on the VM */
|
/* Start running the VM with a given entry point */
|
||||||
void gst_load(Gst * vm, GstValue func);
|
int gst_start(Gst * vm, GstValue func);
|
||||||
|
|
||||||
/* Start running the VM */
|
|
||||||
int gst_start(Gst * vm);
|
|
||||||
|
|
||||||
/* Run garbage collection */
|
/* Run garbage collection */
|
||||||
void gst_collect(Gst * vm);
|
void gst_collect(Gst * vm);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user