failure fix, format, etc.

This commit is contained in:
ProgramSnail 2024-11-07 01:14:57 +03:00
parent e9c4d48cf9
commit ce013b682c
2 changed files with 62 additions and 49 deletions

View file

@ -96,22 +96,23 @@ void run(bytefile *bf) {
case 2: { // SEXP %s %d // create sexpr with tag=%s and %d elements from case 2: { // SEXP %s %d // create sexpr with tag=%s and %d elements from
// stack // stack
// params read from stack // params read from stack
const char* name = ip_read_string(&s.ip, bf); const char *name = ip_read_string(&s.ip, bf);
aint args_count = ip_read_int(&s.ip); aint args_count = ip_read_int(&s.ip);
printf("tag hash is %i, n os %i\n", UNBOX(LtagHash((char*)name)), args_count); printf("tag hash is %i, n os %i\n", UNBOX(LtagHash((char *)name)),
args_count);
if (args_count < 0) { if (args_count < 0) {
failure("SEXP: args count should be >= 0"); failure("SEXP: args count should be >= 0");
} }
void ** buffer = calloc(args_count + 1, sizeof(void*)); void **buffer = calloc(args_count + 1, sizeof(void *));
for (size_t i = 0; i < args_count; ++i) { for (size_t i = 0; i < args_count; ++i) {
buffer[i] = s_pop(&s); buffer[i] = s_pop(&s);
} }
buffer[args_count] = (void*)LtagHash((char*)name); buffer[args_count] = (void *)LtagHash((char *)name);
// TODO: FIXME: not working with elems // TODO: FIXME: not working with elems
void* sexp = Bsexp((aint *)buffer, BOX(args_count + 1)); void *sexp = Bsexp((aint *)buffer, BOX(args_count + 1));
push_extra_root(sexp); push_extra_root(sexp);
s_push(&s, sexp); s_push(&s, sexp);
@ -121,20 +122,25 @@ void run(bytefile *bf) {
break; break;
} }
case 3: // STI - write by ref (?) case 3: { // STI - write by ref (?)
// TODO // TODO: check, add checks
void *elem = s_pop(&s);
void **addr = (void **)s_pop(&s);
*addr = elem;
s_push(&s, elem);
break; break;
}
case 4: { // STA - write to array elem case 4: { // STA - write to array elem
void* elem = s_pop(&s); void *elem = s_pop(&s);
aint index = s_pop_i(&s); aint index = s_pop_i(&s);
void* data = s_pop(&s); void *data = s_pop(&s);
s_push(&s, Bsta(data, index, elem)); s_push(&s, Bsta(data, index, elem));
break; break;
} }
case 5: { // JMP 0x%.8x case 5: { // JMP 0x%.8x
int jmp_p = ip_read_int(&s.ip); // TODO: check int jmp_p = ip_read_int(&s.ip);
if (jmp_p < 0) { if (jmp_p < 0) {
failure("negative file offset jumps are not allowed"); failure("negative file offset jumps are not allowed");
@ -246,7 +252,8 @@ void run(bytefile *bf) {
if (s.fp != NULL && s.call_ip == NULL) { if (s.fp != NULL && s.call_ip == NULL) {
failure("BEGIN: not after call"); failure("BEGIN: not after call");
} }
s_enter_f(&s, s.call_ip /*ip from call*/, s.is_closure_call, args_sz, locals_sz); s_enter_f(&s, s.call_ip /*ip from call*/, s.is_closure_call, args_sz,
locals_sz);
break; break;
} }
@ -256,11 +263,12 @@ void run(bytefile *bf) {
if (s.fp != NULL && s.call_ip == NULL) { if (s.fp != NULL && s.call_ip == NULL) {
failure("BEGIN: not after call"); failure("BEGIN: not after call");
} }
s_enter_f(&s, s.call_ip /*ip from call*/, s.is_closure_call, args_sz, locals_sz); s_enter_f(&s, s.call_ip /*ip from call*/, s.is_closure_call, args_sz,
locals_sz);
break; break;
} }
case 4: // CLOSURE 0x%.8x // TODO: check case 4: // CLOSURE 0x%.8x
{ {
aint call_offset = ip_read_int(&s.ip); aint call_offset = ip_read_int(&s.ip);
aint args_count = ip_read_int(&s.ip); aint args_count = ip_read_int(&s.ip);
@ -274,7 +282,7 @@ void run(bytefile *bf) {
} }
s_push(&s, bf->code_ptr + call_offset); // TODO: check way of storage ?? s_push(&s, bf->code_ptr + call_offset); // TODO: check way of storage ??
void* closure = Bclosure((aint*)s.sp, args_count); void *closure = Bclosure((aint *)s.sp, args_count);
push_extra_root(closure); push_extra_root(closure);
s_popn(&s, args_count + 1); s_popn(&s, args_count + 1);
@ -310,19 +318,24 @@ void run(bytefile *bf) {
} }
case 7: { // TAG %s %d case 7: { // TAG %s %d
const char* name = ip_read_string(&s.ip, bf); const char *name = ip_read_string(&s.ip, bf);
aint args_count = ip_read_int(&s.ip); aint args_count = ip_read_int(&s.ip);
printf("tag hash is %i, n is %i, peek is %i\n", UNBOX(LtagHash((char*)name)), args_count, s_peek(&s)); printf("tag hash is %i, n is %i, peek is %i\n",
if (UNBOXED(s_peek(&s))) printf("aaaaaaaaaaaaaaaaaaa"); UNBOX(LtagHash((char *)name)), args_count, s_peek(&s));
if (UNBOXED(s_peek(&s)))
printf("aaaaaaaaaaaaaaaaaaa");
else { else {
data* r = TO_DATA(s_peek(&s)); data *r = TO_DATA(s_peek(&s));
if ((aint)BOX(TAG(r->data_header) != SEXP_TAG)) printf("bbbbbbbb %i %i", TAG(r->data_header), SEXP_TAG); if ((aint)BOX(TAG(r->data_header) != SEXP_TAG))
if (TO_SEXP(s_peek(&s))->tag != UNBOX(LtagHash((char*)name))) printf("cccccccccc"); printf("bbbbbbbb %i %i", TAG(r->data_header), SEXP_TAG);
if (LEN(r->data_header) != UNBOX(args_count)) printf("dddddd %i %i", LEN(r->data_header), UNBOX(args_count)); if (TO_SEXP(s_peek(&s))->tag != UNBOX(LtagHash((char *)name)))
printf("cccccccccc");
if (LEN(r->data_header) != UNBOX(args_count))
printf("dddddd %i %i", LEN(r->data_header), UNBOX(args_count));
} }
s_push_i(&s, Btag(s_pop(&s), LtagHash((char*)name), args_count)); s_push_i(&s, Btag(s_pop(&s), LtagHash((char *)name), args_count));
break; break;
} }
@ -330,8 +343,10 @@ void run(bytefile *bf) {
Barray((aint *)s.sp, ip_read_int(&s.ip)); Barray((aint *)s.sp, ip_read_int(&s.ip));
break; break;
case 9: // FAIL %d %d // TODO case 9: // FAIL %d %d
failure("[FAIL]: %d-%d\n", ip_read_int(&s.ip), ip_read_int(&s.ip)); // TODO: check (?)
// TODO: real filename
Bmatch_failure(s_pop(&s), "interpreter", ip_read_int(&s.ip), ip_read_int(&s.ip));
break; break;
case 10: // LINE %d case 10: // LINE %d
@ -361,7 +376,6 @@ void run(bytefile *bf) {
break; break;
case 4: // #ref case 4: // #ref
s_push_i(&s, Bunboxed_patt(s_pop(&s))); // TODO: check s_push_i(&s, Bunboxed_patt(s_pop(&s))); // TODO: check
// TODO
break; break;
case 5: // #val case 5: // #val
s_push_i(&s, Bboxed_patt(s_pop(&s))); // TODO: check s_push_i(&s, Bboxed_patt(s_pop(&s))); // TODO: check
@ -390,8 +404,7 @@ void run(bytefile *bf) {
case 3: { // CALL Lstring case 3: { // CALL Lstring
void *val = s_pop(&s); void *val = s_pop(&s);
void *str = void *str = Lstring((aint *)&val);
Lstring((aint *)&val); // FIXME: not working, GC extra root error
s_push(&s, str); s_push(&s, str);
break; break;
} }

View file

@ -242,8 +242,8 @@ void **var_by_category(struct State *s, enum VarCategory category,
if (count <= id) { if (count <= id) {
failure("can't read arguments: too big id, %i >= %ul", id, count); failure("can't read arguments: too big id, %i >= %ul", id, count);
} }
// TODO: check if not reversed order // TODO: check
return (void **)d->contents + id; return (void **)d->contents + id; // order is not important ??
// &Belem(s->fp->closure, BOX(id + 1)); // &Belem(s->fp->closure, BOX(id + 1));
break; break;
break; break;