Bug fixes
This commit is contained in:
@@ -689,12 +689,6 @@ Token next_token(Parser *p)
|
|||||||
if (streq(kword, S("false"))) return (Token) { .type=TOKEN_KWORD_FALSE };
|
if (streq(kword, S("false"))) return (Token) { .type=TOKEN_KWORD_FALSE };
|
||||||
if (streq(kword, S("include"))) return (Token) { .type=TOKEN_KWORD_INCLUDE };
|
if (streq(kword, S("include"))) return (Token) { .type=TOKEN_KWORD_INCLUDE };
|
||||||
|
|
||||||
kword = copystr(kword, p->a);
|
|
||||||
if (kword.len == 0) {
|
|
||||||
parser_report(p, "Out of memory");
|
|
||||||
return (Token) { .type=TOKEN_ERROR };
|
|
||||||
}
|
|
||||||
|
|
||||||
return (Token) { .type=TOKEN_IDENT, .sval=kword };
|
return (Token) { .type=TOKEN_IDENT, .sval=kword };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4040,6 +4034,28 @@ char *print_instruction(char *p, char *data)
|
|||||||
case OPCODE_PUSHFL:
|
case OPCODE_PUSHFL:
|
||||||
printf("PUSHFL");
|
printf("PUSHFL");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case OPCODE_FOR:
|
||||||
|
{
|
||||||
|
uint8_t a;
|
||||||
|
memcpy(&a, p, sizeof(uint8_t));
|
||||||
|
p += sizeof(uint8_t);
|
||||||
|
|
||||||
|
uint8_t b;
|
||||||
|
memcpy(&b, p, sizeof(uint8_t));
|
||||||
|
p += sizeof(uint8_t);
|
||||||
|
|
||||||
|
uint8_t c;
|
||||||
|
memcpy(&c, p, sizeof(uint8_t));
|
||||||
|
p += sizeof(uint8_t);
|
||||||
|
|
||||||
|
uint32_t d;
|
||||||
|
memcpy(&d, p, sizeof(uint32_t));
|
||||||
|
p += sizeof(uint32_t);
|
||||||
|
|
||||||
|
printf("FOR %u %u %u %u", a, b, c, d);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
@@ -4572,7 +4588,7 @@ static void value_to_string_inner(Value v, ToStringContext *tostr)
|
|||||||
int cursor = 0;
|
int cursor = 0;
|
||||||
while (batch) {
|
while (batch) {
|
||||||
|
|
||||||
int num = ITEMS_PER_MAP_BATCH;
|
int num = ITEMS_PER_ARRAY_BATCH;
|
||||||
if (batch->next == NULL)
|
if (batch->next == NULL)
|
||||||
num = a->tail_count;
|
num = a->tail_count;
|
||||||
|
|
||||||
@@ -4644,6 +4660,8 @@ struct WL_State {
|
|||||||
String data;
|
String data;
|
||||||
int off;
|
int off;
|
||||||
|
|
||||||
|
bool trace;
|
||||||
|
|
||||||
WL_Arena *a;
|
WL_Arena *a;
|
||||||
|
|
||||||
char *errbuf;
|
char *errbuf;
|
||||||
@@ -4693,6 +4711,8 @@ void eval_report(WL_State *state, char *fmt, ...)
|
|||||||
|
|
||||||
static uint8_t read_u8(WL_State *state)
|
static uint8_t read_u8(WL_State *state)
|
||||||
{
|
{
|
||||||
|
assert(state->off >= 0);
|
||||||
|
assert(state->off < state->code.len);
|
||||||
return state->code.ptr[state->off++];
|
return state->code.ptr[state->off++];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4726,11 +4746,12 @@ static double read_f64(WL_State *state)
|
|||||||
int step(WL_State *state)
|
int step(WL_State *state)
|
||||||
{
|
{
|
||||||
uint8_t opcode = read_u8(state);
|
uint8_t opcode = read_u8(state);
|
||||||
/*
|
|
||||||
printf("%-3d: ", e->off);
|
if (state->trace) {
|
||||||
print_instruction(state->code.ptr + e->off, e->data.ptr);
|
printf("%-3d: ", state->off-1);
|
||||||
|
print_instruction(state->code.ptr + state->off - 1, state->data.ptr);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
*/
|
}
|
||||||
|
|
||||||
switch (opcode) {
|
switch (opcode) {
|
||||||
|
|
||||||
@@ -5505,6 +5526,8 @@ int step(WL_State *state)
|
|||||||
uint8_t var_2 = read_u8(state);
|
uint8_t var_2 = read_u8(state);
|
||||||
uint32_t end = read_u32(state);
|
uint32_t end = read_u32(state);
|
||||||
|
|
||||||
|
printf("for end %u\n", end); // TODO
|
||||||
|
|
||||||
int base;
|
int base;
|
||||||
{
|
{
|
||||||
int group = state->frames[state->num_frames-1].group;
|
int group = state->frames[state->num_frames-1].group;
|
||||||
@@ -5578,6 +5601,7 @@ WL_State *WL_State_init(WL_Arena *a, WL_Program p, char *err, int errmax)
|
|||||||
.code=code,
|
.code=code,
|
||||||
.data=data,
|
.data=data,
|
||||||
.off=0,
|
.off=0,
|
||||||
|
.trace=false,
|
||||||
.a=a,
|
.a=a,
|
||||||
.errbuf=err,
|
.errbuf=err,
|
||||||
.errmax=errmax,
|
.errmax=errmax,
|
||||||
@@ -5601,6 +5625,11 @@ void WL_State_free(WL_State *state)
|
|||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WL_State_trace(WL_State *state, int trace)
|
||||||
|
{
|
||||||
|
state->trace = (trace != 0);
|
||||||
|
}
|
||||||
|
|
||||||
WL_Result WL_eval(WL_State *state)
|
WL_Result WL_eval(WL_State *state)
|
||||||
{
|
{
|
||||||
if (state->sysvar.len > 0) {
|
if (state->sysvar.len > 0) {
|
||||||
@@ -6105,3 +6134,8 @@ WL_CompileResult WL_compile(WL_Compiler *compiler, WL_String file, WL_String con
|
|||||||
|
|
||||||
return (WL_CompileResult) { .type=WL_COMPILE_RESULT_DONE, .program=ares.program };
|
return (WL_CompileResult) { .type=WL_COMPILE_RESULT_DONE, .program=ares.program };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WL_dump_program(WL_Program program)
|
||||||
|
{
|
||||||
|
print_program(program);
|
||||||
|
}
|
||||||
|
|||||||
@@ -64,8 +64,11 @@ void WL_Compiler_free (WL_Compiler *compiler);
|
|||||||
WL_CompileResult WL_compile (WL_Compiler *compiler, WL_String file, WL_String content);
|
WL_CompileResult WL_compile (WL_Compiler *compiler, WL_String file, WL_String content);
|
||||||
WL_State* WL_State_init (WL_Arena *a, WL_Program p, char *err, int errmax);
|
WL_State* WL_State_init (WL_Arena *a, WL_Program p, char *err, int errmax);
|
||||||
void WL_State_free (WL_State *state);
|
void WL_State_free (WL_State *state);
|
||||||
|
void WL_State_trace (WL_State *state, int trace);
|
||||||
WL_Result WL_eval (WL_State *state);
|
WL_Result WL_eval (WL_State *state);
|
||||||
|
|
||||||
|
void WL_dump_program(WL_Program program);
|
||||||
|
|
||||||
int WL_streq (WL_String a, char *b, int blen);
|
int WL_streq (WL_String a, char *b, int blen);
|
||||||
int WL_peeknone (WL_State *state, int off);
|
int WL_peeknone (WL_State *state, int off);
|
||||||
int WL_peekint (WL_State *state, int off, long long *x);
|
int WL_peekint (WL_State *state, int off, long long *x);
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ int main(int argc, char **argv)
|
|||||||
assert(0); // TODO
|
assert(0); // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int num_loaded_files = 0;
|
||||||
|
char *loaded_files[128];
|
||||||
|
|
||||||
WL_CompileResult result;
|
WL_CompileResult result;
|
||||||
WL_String path = { file, strlen(file) };
|
WL_String path = { file, strlen(file) };
|
||||||
for (int i = 0;; i++) {
|
for (int i = 0;; i++) {
|
||||||
@@ -51,7 +54,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
result = WL_compile(compiler, path, (WL_String) { file_data, file_size });
|
result = WL_compile(compiler, path, (WL_String) { file_data, file_size });
|
||||||
|
|
||||||
free(file_data);
|
loaded_files[num_loaded_files++] = file_data;
|
||||||
|
|
||||||
if (result.type == WL_COMPILE_RESULT_ERROR) {
|
if (result.type == WL_COMPILE_RESULT_ERROR) {
|
||||||
printf("Compilation of '%.*s' failed\n", path.len, path.ptr);
|
printf("Compilation of '%.*s' failed\n", path.len, path.ptr);
|
||||||
@@ -65,6 +68,9 @@ int main(int argc, char **argv)
|
|||||||
path = result.path;
|
path = result.path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < num_loaded_files; i++)
|
||||||
|
free(loaded_files[i]);
|
||||||
|
|
||||||
WL_Compiler_free(compiler);
|
WL_Compiler_free(compiler);
|
||||||
|
|
||||||
if (result.type == WL_COMPILE_RESULT_ERROR) {
|
if (result.type == WL_COMPILE_RESULT_ERROR) {
|
||||||
@@ -75,6 +81,8 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
WL_State *state = WL_State_init(&a, program, err, (int) sizeof(err));
|
WL_State *state = WL_State_init(&a, program, err, (int) sizeof(err));
|
||||||
|
|
||||||
|
WL_State_trace(state, 0);
|
||||||
|
|
||||||
for (bool done = false; !done; ) {
|
for (bool done = false; !done; ) {
|
||||||
|
|
||||||
WL_Result result = WL_eval(state);
|
WL_Result result = WL_eval(state);
|
||||||
|
|||||||
@@ -1594,6 +1594,28 @@ char *print_instruction(char *p, char *data)
|
|||||||
case OPCODE_PUSHFL:
|
case OPCODE_PUSHFL:
|
||||||
printf("PUSHFL");
|
printf("PUSHFL");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case OPCODE_FOR:
|
||||||
|
{
|
||||||
|
uint8_t a;
|
||||||
|
memcpy(&a, p, sizeof(uint8_t));
|
||||||
|
p += sizeof(uint8_t);
|
||||||
|
|
||||||
|
uint8_t b;
|
||||||
|
memcpy(&b, p, sizeof(uint8_t));
|
||||||
|
p += sizeof(uint8_t);
|
||||||
|
|
||||||
|
uint8_t c;
|
||||||
|
memcpy(&c, p, sizeof(uint8_t));
|
||||||
|
p += sizeof(uint8_t);
|
||||||
|
|
||||||
|
uint32_t d;
|
||||||
|
memcpy(&d, p, sizeof(uint32_t));
|
||||||
|
p += sizeof(uint32_t);
|
||||||
|
|
||||||
|
printf("FOR %u %u %u %u", a, b, c, d);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
|
|||||||
@@ -116,3 +116,8 @@ WL_CompileResult WL_compile(WL_Compiler *compiler, WL_String file, WL_String con
|
|||||||
|
|
||||||
return (WL_CompileResult) { .type=WL_COMPILE_RESULT_DONE, .program=ares.program };
|
return (WL_CompileResult) { .type=WL_COMPILE_RESULT_DONE, .program=ares.program };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WL_dump_program(WL_Program program)
|
||||||
|
{
|
||||||
|
print_program(program);
|
||||||
|
}
|
||||||
@@ -55,8 +55,11 @@ void WL_Compiler_free (WL_Compiler *compiler);
|
|||||||
WL_CompileResult WL_compile (WL_Compiler *compiler, WL_String file, WL_String content);
|
WL_CompileResult WL_compile (WL_Compiler *compiler, WL_String file, WL_String content);
|
||||||
WL_State* WL_State_init (WL_Arena *a, WL_Program p, char *err, int errmax);
|
WL_State* WL_State_init (WL_Arena *a, WL_Program p, char *err, int errmax);
|
||||||
void WL_State_free (WL_State *state);
|
void WL_State_free (WL_State *state);
|
||||||
|
void WL_State_trace (WL_State *state, int trace);
|
||||||
WL_Result WL_eval (WL_State *state);
|
WL_Result WL_eval (WL_State *state);
|
||||||
|
|
||||||
|
void WL_dump_program(WL_Program program);
|
||||||
|
|
||||||
int WL_streq (WL_String a, char *b, int blen);
|
int WL_streq (WL_String a, char *b, int blen);
|
||||||
int WL_peeknone (WL_State *state, int off);
|
int WL_peeknone (WL_State *state, int off);
|
||||||
int WL_peekint (WL_State *state, int off, long long *x);
|
int WL_peekint (WL_State *state, int off, long long *x);
|
||||||
|
|||||||
+17
-4
@@ -20,6 +20,8 @@ struct WL_State {
|
|||||||
String data;
|
String data;
|
||||||
int off;
|
int off;
|
||||||
|
|
||||||
|
bool trace;
|
||||||
|
|
||||||
WL_Arena *a;
|
WL_Arena *a;
|
||||||
|
|
||||||
char *errbuf;
|
char *errbuf;
|
||||||
@@ -69,6 +71,8 @@ void eval_report(WL_State *state, char *fmt, ...)
|
|||||||
|
|
||||||
static uint8_t read_u8(WL_State *state)
|
static uint8_t read_u8(WL_State *state)
|
||||||
{
|
{
|
||||||
|
assert(state->off >= 0);
|
||||||
|
assert(state->off < state->code.len);
|
||||||
return state->code.ptr[state->off++];
|
return state->code.ptr[state->off++];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,11 +106,12 @@ static double read_f64(WL_State *state)
|
|||||||
int step(WL_State *state)
|
int step(WL_State *state)
|
||||||
{
|
{
|
||||||
uint8_t opcode = read_u8(state);
|
uint8_t opcode = read_u8(state);
|
||||||
/*
|
|
||||||
printf("%-3d: ", e->off);
|
if (state->trace) {
|
||||||
print_instruction(state->code.ptr + e->off, e->data.ptr);
|
printf("%-3d: ", state->off-1);
|
||||||
|
print_instruction(state->code.ptr + state->off - 1, state->data.ptr);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
*/
|
}
|
||||||
|
|
||||||
switch (opcode) {
|
switch (opcode) {
|
||||||
|
|
||||||
@@ -881,6 +886,8 @@ int step(WL_State *state)
|
|||||||
uint8_t var_2 = read_u8(state);
|
uint8_t var_2 = read_u8(state);
|
||||||
uint32_t end = read_u32(state);
|
uint32_t end = read_u32(state);
|
||||||
|
|
||||||
|
printf("for end %u\n", end); // TODO
|
||||||
|
|
||||||
int base;
|
int base;
|
||||||
{
|
{
|
||||||
int group = state->frames[state->num_frames-1].group;
|
int group = state->frames[state->num_frames-1].group;
|
||||||
@@ -954,6 +961,7 @@ WL_State *WL_State_init(WL_Arena *a, WL_Program p, char *err, int errmax)
|
|||||||
.code=code,
|
.code=code,
|
||||||
.data=data,
|
.data=data,
|
||||||
.off=0,
|
.off=0,
|
||||||
|
.trace=false,
|
||||||
.a=a,
|
.a=a,
|
||||||
.errbuf=err,
|
.errbuf=err,
|
||||||
.errmax=errmax,
|
.errmax=errmax,
|
||||||
@@ -977,6 +985,11 @@ void WL_State_free(WL_State *state)
|
|||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WL_State_trace(WL_State *state, int trace)
|
||||||
|
{
|
||||||
|
state->trace = (trace != 0);
|
||||||
|
}
|
||||||
|
|
||||||
WL_Result WL_eval(WL_State *state)
|
WL_Result WL_eval(WL_State *state)
|
||||||
{
|
{
|
||||||
if (state->sysvar.len > 0) {
|
if (state->sysvar.len > 0) {
|
||||||
|
|||||||
@@ -255,12 +255,6 @@ Token next_token(Parser *p)
|
|||||||
if (streq(kword, S("false"))) return (Token) { .type=TOKEN_KWORD_FALSE };
|
if (streq(kword, S("false"))) return (Token) { .type=TOKEN_KWORD_FALSE };
|
||||||
if (streq(kword, S("include"))) return (Token) { .type=TOKEN_KWORD_INCLUDE };
|
if (streq(kword, S("include"))) return (Token) { .type=TOKEN_KWORD_INCLUDE };
|
||||||
|
|
||||||
kword = copystr(kword, p->a);
|
|
||||||
if (kword.len == 0) {
|
|
||||||
parser_report(p, "Out of memory");
|
|
||||||
return (Token) { .type=TOKEN_ERROR };
|
|
||||||
}
|
|
||||||
|
|
||||||
return (Token) { .type=TOKEN_IDENT, .sval=kword };
|
return (Token) { .type=TOKEN_IDENT, .sval=kword };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -470,7 +470,7 @@ static void value_to_string_inner(Value v, ToStringContext *tostr)
|
|||||||
int cursor = 0;
|
int cursor = 0;
|
||||||
while (batch) {
|
while (batch) {
|
||||||
|
|
||||||
int num = ITEMS_PER_MAP_BATCH;
|
int num = ITEMS_PER_ARRAY_BATCH;
|
||||||
if (batch->next == NULL)
|
if (batch->next == NULL)
|
||||||
num = a->tail_count;
|
num = a->tail_count;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user