mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-07 15:28:49 +00:00
fixes, some cleanup
This commit is contained in:
parent
e456304eb3
commit
1548c16eeb
4 changed files with 9 additions and 28 deletions
BIN
byterun/Sort.bc
BIN
byterun/Sort.bc
Binary file not shown.
|
|
@ -66,8 +66,12 @@ static inline void s_push_i(aint val) { s_push((void *)val); }
|
||||||
static inline void s_push_nil() { s_push(NULL); }
|
static inline void s_push_nil() { s_push(NULL); }
|
||||||
|
|
||||||
static inline void s_pushn_nil(size_t n) {
|
static inline void s_pushn_nil(size_t n) {
|
||||||
|
if ((void **)__gc_stack_top + (aint)n - 1 <= s.stack) {
|
||||||
|
s_failure(&s, "stack overflow");
|
||||||
|
}
|
||||||
for (size_t i = 0; i < n; ++i) {
|
for (size_t i = 0; i < n; ++i) {
|
||||||
s_push(NULL);
|
__gc_stack_top -= sizeof(void *);
|
||||||
|
*(void **)__gc_stack_top = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -82,7 +86,6 @@ static inline void *s_pop() {
|
||||||
printf("--> pop\n");
|
printf("--> pop\n");
|
||||||
#endif
|
#endif
|
||||||
void *value = *(void **)__gc_stack_top;
|
void *value = *(void **)__gc_stack_top;
|
||||||
// *(void **)__gc_stack_top = NULL;
|
|
||||||
__gc_stack_top += sizeof(void *);
|
__gc_stack_top += sizeof(void *);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
@ -90,9 +93,10 @@ static inline void *s_pop() {
|
||||||
static inline aint s_pop_i() { return (aint)s_pop(); }
|
static inline aint s_pop_i() { return (aint)s_pop(); }
|
||||||
|
|
||||||
static inline void s_popn(size_t n) {
|
static inline void s_popn(size_t n) {
|
||||||
for (size_t i = 0; i < n; ++i) {
|
if ((void **)__gc_stack_top + (aint)n - 1 >= s_top()) {
|
||||||
s_pop();
|
s_failure(&s, "empty stack");
|
||||||
}
|
}
|
||||||
|
__gc_stack_top += n * sizeof(void *);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------ functions ------
|
// ------ functions ------
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ int main(int argc, char** argv) {
|
||||||
failure("no file name provided");
|
failure("no file name provided");
|
||||||
}
|
}
|
||||||
|
|
||||||
// printf("size of aint is %i\n", sizeof(aint));
|
|
||||||
bytefile *f = read_file(argv[1]);
|
bytefile *f = read_file(argv[1]);
|
||||||
// #ifdef DEBUG_VERSION
|
// #ifdef DEBUG_VERSION
|
||||||
// dump_file (stdout, f);
|
// dump_file (stdout, f);
|
||||||
|
|
|
||||||
|
|
@ -40,27 +40,6 @@ void run(bytefile *bf, int argc, char **argv) {
|
||||||
printf("--- interpreter run ---\n");
|
printf("--- interpreter run ---\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// const char *ops[] = {
|
|
||||||
// "+", "-", "*", "/", "%", "<", "<=", ">", ">=", "==", "!=", "&&", "!!"};
|
|
||||||
// aint (*ops_func[])(void *, void *) = {
|
|
||||||
// &Ls__Infix_43, // +
|
|
||||||
// &Ls__Infix_45, // -
|
|
||||||
// &Ls__Infix_42, // *
|
|
||||||
// &Ls__Infix_47, // /
|
|
||||||
// &Ls__Infix_37, // %
|
|
||||||
// &Ls__Infix_60, // <
|
|
||||||
// &Ls__Infix_6061, // <=
|
|
||||||
// &Ls__Infix_62, // >
|
|
||||||
// &Ls__Infix_6261, // >=
|
|
||||||
// &Ls__Infix_6161, // ==
|
|
||||||
// &Ls__Infix_3361, // !=
|
|
||||||
// &Ls__Infix_3838, // &&
|
|
||||||
// &Ls__Infix_3333, // !!
|
|
||||||
// };
|
|
||||||
|
|
||||||
// const char *pats[] = {"=str", "#string", "#array", "#sexp",
|
|
||||||
// "#ref", "#val", "#fun"};
|
|
||||||
|
|
||||||
// argc, argv
|
// argc, argv
|
||||||
{
|
{
|
||||||
s_push_i(BOX(argc));
|
s_push_i(BOX(argc));
|
||||||
|
|
@ -78,7 +57,6 @@ void run(bytefile *bf, int argc, char **argv) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
do {
|
do {
|
||||||
// char *before_op_ip = s.ip; // save to set s.prev_ip
|
|
||||||
bool call_happened = false;
|
bool call_happened = false;
|
||||||
|
|
||||||
if (s.ip >= bf->code_ptr + bf->code_size) {
|
if (s.ip >= bf->code_ptr + bf->code_size) {
|
||||||
|
|
@ -104,7 +82,7 @@ void run(bytefile *bf, int argc, char **argv) {
|
||||||
case CMD_BINOP: { // BINOP ops[l-1]
|
case CMD_BINOP: { // BINOP ops[l-1]
|
||||||
void *left = s_pop();
|
void *left = s_pop();
|
||||||
void *right = s_pop();
|
void *right = s_pop();
|
||||||
switch ((int)l) {
|
switch (l) {
|
||||||
case CMD_BINOP_ADD: // +
|
case CMD_BINOP_ADD: // +
|
||||||
s_push_i(Ls__Infix_43(right, left));
|
s_push_i(Ls__Infix_43(right, left));
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue