mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-06 14:58:50 +00:00
failure fix, format, etc.
This commit is contained in:
parent
e9c4d48cf9
commit
ce013b682c
2 changed files with 62 additions and 49 deletions
|
|
@ -96,22 +96,23 @@ void run(bytefile *bf) {
|
|||
case 2: { // SEXP %s %d // create sexpr with tag=%s and %d elements 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);
|
||||
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) {
|
||||
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) {
|
||||
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
|
||||
void* sexp = Bsexp((aint *)buffer, BOX(args_count + 1));
|
||||
void *sexp = Bsexp((aint *)buffer, BOX(args_count + 1));
|
||||
|
||||
push_extra_root(sexp);
|
||||
s_push(&s, sexp);
|
||||
|
|
@ -121,20 +122,25 @@ void run(bytefile *bf) {
|
|||
break;
|
||||
}
|
||||
|
||||
case 3: // STI - write by ref (?)
|
||||
// TODO
|
||||
case 3: { // STI - write by ref (?)
|
||||
// TODO: check, add checks
|
||||
void *elem = s_pop(&s);
|
||||
void **addr = (void **)s_pop(&s);
|
||||
*addr = elem;
|
||||
s_push(&s, elem);
|
||||
break;
|
||||
}
|
||||
|
||||
case 4: { // STA - write to array elem
|
||||
void* elem = s_pop(&s);
|
||||
void *elem = s_pop(&s);
|
||||
aint index = s_pop_i(&s);
|
||||
void* data = s_pop(&s);
|
||||
void *data = s_pop(&s);
|
||||
s_push(&s, Bsta(data, index, elem));
|
||||
break;
|
||||
}
|
||||
|
||||
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) {
|
||||
failure("negative file offset jumps are not allowed");
|
||||
|
|
@ -246,7 +252,8 @@ void run(bytefile *bf) {
|
|||
if (s.fp != NULL && s.call_ip == NULL) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -256,11 +263,12 @@ void run(bytefile *bf) {
|
|||
if (s.fp != NULL && s.call_ip == NULL) {
|
||||
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;
|
||||
}
|
||||
|
||||
case 4: // CLOSURE 0x%.8x // TODO: check
|
||||
case 4: // CLOSURE 0x%.8x
|
||||
{
|
||||
aint call_offset = 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 ??
|
||||
|
||||
void* closure = Bclosure((aint*)s.sp, args_count);
|
||||
void *closure = Bclosure((aint *)s.sp, args_count);
|
||||
|
||||
push_extra_root(closure);
|
||||
s_popn(&s, args_count + 1);
|
||||
|
|
@ -310,19 +318,24 @@ void run(bytefile *bf) {
|
|||
}
|
||||
|
||||
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);
|
||||
|
||||
printf("tag hash is %i, n is %i, peek is %i\n", UNBOX(LtagHash((char*)name)), args_count, s_peek(&s));
|
||||
if (UNBOXED(s_peek(&s))) printf("aaaaaaaaaaaaaaaaaaa");
|
||||
printf("tag hash is %i, n is %i, peek is %i\n",
|
||||
UNBOX(LtagHash((char *)name)), args_count, s_peek(&s));
|
||||
if (UNBOXED(s_peek(&s)))
|
||||
printf("aaaaaaaaaaaaaaaaaaa");
|
||||
else {
|
||||
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 (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));
|
||||
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 (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;
|
||||
}
|
||||
|
||||
|
|
@ -330,8 +343,10 @@ void run(bytefile *bf) {
|
|||
Barray((aint *)s.sp, ip_read_int(&s.ip));
|
||||
break;
|
||||
|
||||
case 9: // FAIL %d %d // TODO
|
||||
failure("[FAIL]: %d-%d\n", ip_read_int(&s.ip), ip_read_int(&s.ip));
|
||||
case 9: // FAIL %d %d
|
||||
// TODO: check (?)
|
||||
// TODO: real filename
|
||||
Bmatch_failure(s_pop(&s), "interpreter", ip_read_int(&s.ip), ip_read_int(&s.ip));
|
||||
break;
|
||||
|
||||
case 10: // LINE %d
|
||||
|
|
@ -361,7 +376,6 @@ void run(bytefile *bf) {
|
|||
break;
|
||||
case 4: // #ref
|
||||
s_push_i(&s, Bunboxed_patt(s_pop(&s))); // TODO: check
|
||||
// TODO
|
||||
break;
|
||||
case 5: // #val
|
||||
s_push_i(&s, Bboxed_patt(s_pop(&s))); // TODO: check
|
||||
|
|
@ -390,8 +404,7 @@ void run(bytefile *bf) {
|
|||
|
||||
case 3: { // CALL Lstring
|
||||
void *val = s_pop(&s);
|
||||
void *str =
|
||||
Lstring((aint *)&val); // FIXME: not working, GC extra root error
|
||||
void *str = Lstring((aint *)&val);
|
||||
s_push(&s, str);
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -242,8 +242,8 @@ void **var_by_category(struct State *s, enum VarCategory category,
|
|||
if (count <= id) {
|
||||
failure("can't read arguments: too big id, %i >= %ul", id, count);
|
||||
}
|
||||
// TODO: check if not reversed order
|
||||
return (void **)d->contents + id;
|
||||
// TODO: check
|
||||
return (void **)d->contents + id; // order is not important ??
|
||||
// &Belem(s->fp->closure, BOX(id + 1));
|
||||
break;
|
||||
break;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue