feat: add depth, pick, roll, qdup, 2dup, 2drop, 2swap words
Co-authored-by: aider (openrouter/deepseek/deepseek-v4-pro) <aider@aider.chat>
This commit is contained in:
@@ -722,3 +722,70 @@ void do_repeat(Word* w) {
|
||||
|
||||
compile_buf[while_offset_idx].num = compile_idx - while_offset_idx;
|
||||
}
|
||||
|
||||
void do_depth(Word* w) {
|
||||
(void)w;
|
||||
data_push(data_sp + 1);
|
||||
}
|
||||
|
||||
void do_pick(Word* w) {
|
||||
(void)w;
|
||||
if (data_sp < 0) return;
|
||||
int64_t idx = data_pop();
|
||||
if (idx < 0 || idx > data_sp) return;
|
||||
int64_t value = data_stack[data_sp - (int32_t)idx];
|
||||
data_push(value);
|
||||
}
|
||||
|
||||
void do_roll(Word* w) {
|
||||
(void)w;
|
||||
if (data_sp < 0) return;
|
||||
int64_t n = data_pop();
|
||||
if (n == 0) return;
|
||||
if (n < 0 || n > data_sp) return;
|
||||
int64_t i = data_stack[data_sp - (int32_t)n];
|
||||
int32_t pos = (int32_t)(data_sp - (int32_t)n);
|
||||
while (pos < data_sp) {
|
||||
data_stack[pos] = data_stack[pos + 1];
|
||||
pos++;
|
||||
}
|
||||
data_stack[data_sp] = i;
|
||||
}
|
||||
|
||||
void do_qdup(Word* w) {
|
||||
(void)w;
|
||||
if (data_sp < 0) return;
|
||||
int64_t v = data_pop();
|
||||
if (v != 0) {
|
||||
data_push(v);
|
||||
data_push(v);
|
||||
}
|
||||
}
|
||||
|
||||
void do_2dup(Word* w) {
|
||||
(void)w;
|
||||
if (data_sp < 1) return;
|
||||
int64_t b = data_stack[data_sp];
|
||||
int64_t a = data_stack[data_sp - 1];
|
||||
data_push(a);
|
||||
data_push(b);
|
||||
}
|
||||
|
||||
void do_2drop(Word* w) {
|
||||
(void)w;
|
||||
data_pop();
|
||||
data_pop();
|
||||
}
|
||||
|
||||
void do_2swap(Word* w) {
|
||||
(void)w;
|
||||
if (data_sp < 3) return;
|
||||
int64_t d = data_pop(); // x4
|
||||
int64_t c = data_pop(); // x3
|
||||
int64_t b = data_pop(); // x2
|
||||
int64_t a = data_pop(); // x1
|
||||
data_push(b);
|
||||
data_push(a);
|
||||
data_push(d);
|
||||
data_push(c);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user