Reverse stack order so list builders work properly

trunk
alexis 2022-05-22 18:16:34 -06:00
parent 3c010285c2
commit c75f7deeb1
4 changed files with 23 additions and 22 deletions

View File

@ -160,11 +160,11 @@ void arl_run_until(char const * word)
.v_list = sc->stack
};
arl_list_hold(sc->stack);
arl_list_insert(sc->parent->stack, &list_val, 0);
arl_list_insert(sc->parent->stack, &list_val, -1);
}
else
{
arl_list_insert(sc->stack, &val, 0);
arl_list_insert(sc->stack, &val, -1);
}
}
}

View File

@ -61,13 +61,13 @@ arl_builtin_t const * arl_find_builtin(char const * name)
void arl_h_pop2(arl_value_t * x, arl_value_t * y)
{
if (!arl_list_pull(ARL_SCOPE->stack, 0, x))
if (!arl_list_pull(ARL_SCOPE->stack, -1, x))
arl_throw(ARL_E_POPEMPTY);
if (y && !arl_list_pull(ARL_SCOPE->stack, 0, y))
if (y && !arl_list_pull(ARL_SCOPE->stack, -1, y))
{
// Put x back first
arl_list_insert(ARL_SCOPE->stack, x, 0);
arl_list_insert(ARL_SCOPE->stack, x, -1);
arl_throw(ARL_E_POPEMPTY);
}
}

View File

@ -19,7 +19,7 @@ void arlb_binary(void * arg)
arl_h_coerce(&x, &y);
arl_h_ensure_num(&x, &y);
op(&y, &x);
arl_list_insert(ARL_SCOPE->stack, &y, 0);
arl_list_insert(ARL_SCOPE->stack, &y, -1);
}
void arlb_op_plus(arl_value_t * y, arl_value_t const * x)

View File

@ -24,17 +24,18 @@ void arlb_dupn(void * arg)
else
n = (unsigned) (uintptr_t) arg;
arl_list_iter_t it;
arl_value_t * v = arl_list_first(ARL_SCOPE->stack, &it);
unsigned pos = 0;
int take_pos = -1, push_pos = -1;
while (n--)
{
if (!v)
arl_value_t v;
if (!arl_list_pick(ARL_SCOPE->stack, take_pos, &v))
arl_throw(ARL_E_POPEMPTY);
arl_list_insert(ARL_SCOPE->stack, v, pos++);
v = arl_list_next(ARL_SCOPE->stack, &it);
arl_list_insert(ARL_SCOPE->stack, &v, push_pos);
arl_value_release(&v);
take_pos -= 2;
push_pos -= 1;
}
}
@ -54,7 +55,7 @@ void arlb_dropn(void * arg)
while (n--)
{
if (!arl_list_remove(ARL_SCOPE->stack, 0))
if (!arl_list_remove(ARL_SCOPE->stack, -1))
arl_throw(ARL_E_POPEMPTY);
}
}
@ -74,10 +75,10 @@ void arlb_pick(void * arg)
n = (int) (intptr_t) arg - 1;
arl_value_t v;
if (!arl_list_pick(ARL_SCOPE->stack, n, &v))
if (!arl_list_pick(ARL_SCOPE->stack, -1 - n, &v))
arl_throw(ARL_E_POPEMPTY);
arl_list_insert(ARL_SCOPE->stack, &v, 0);
arl_list_insert(ARL_SCOPE->stack, &v, -1);
arl_value_release(&v);
}
@ -96,10 +97,10 @@ void arlb_roll(void * arg)
n = (int) (intptr_t) arg - 1;
arl_value_t v;
if (!arl_list_pull(ARL_SCOPE->stack, n, &v))
if (!arl_list_pull(ARL_SCOPE->stack, -1 - n, &v))
arl_throw(ARL_E_POPEMPTY);
arl_list_insert(ARL_SCOPE->stack, &v, 0);
arl_list_insert(ARL_SCOPE->stack, &v, -1);
arl_value_release(&v);
}
@ -118,10 +119,10 @@ void arlb_rolld(void * arg)
n = -1;
arl_value_t v;
if (!arl_list_pull(ARL_SCOPE->stack, 0, &v))
if (!arl_list_pull(ARL_SCOPE->stack, -1, &v))
arl_throw(ARL_E_POPEMPTY);
arl_list_insert(ARL_SCOPE->stack, &v, n);
arl_list_insert(ARL_SCOPE->stack, &v, -1 - n);
arl_value_release(&v);
}
@ -132,6 +133,6 @@ void arlb_depth(void * arg)
arl_value_t x;
x.v_int = n;
x.type = ARL_T_INT; // TODO real, not int
arl_list_insert(ARL_SCOPE->stack, &x, 0);
x.type = ARL_T_INT;
arl_list_insert(ARL_SCOPE->stack, &x, -1);
}