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

@ -98,7 +98,8 @@ void run(bytefile *bf) {
// 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");
@ -121,9 +122,14 @@ 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);
@ -134,7 +140,7 @@ void run(bytefile *bf) {
} }
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);
@ -313,13 +321,18 @@ void run(bytefile *bf) {
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));
@ -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;