mirror of
https://github.com/nunuhara/xsystem4.git
synced 2026-10-08 14:58:14 +03:00
Implement A_REVERSE instruction
This commit is contained in:
+2
-2
@@ -221,8 +221,8 @@ const struct instruction instructions[NR_OPCODES] = {
|
||||
OP(LI_RSHIFTA, 0),
|
||||
OP(LI_INC, 0),
|
||||
OP(LI_DEC, 0),
|
||||
OP(A_FIND, 0), // TODO
|
||||
OP(A_REVERSE, 0), // TODO
|
||||
OP(A_FIND, 0),
|
||||
OP(A_REVERSE, 0),
|
||||
OP(SH_SR_ASSIGN, 0), // TODO
|
||||
OP(SH_MEM_ASSIGN_LOCAL, 0), // TODO
|
||||
OP(A_NUMOF_GLOB_1, 0), // TODO
|
||||
|
||||
@@ -488,3 +488,15 @@ int array_find(struct page *page, int start, int end, union vm_value v, int comp
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void array_reverse(struct page *page)
|
||||
{
|
||||
if (!page)
|
||||
return;
|
||||
|
||||
for (int start = 0, end = page->nr_vars-1; start < end; start++, end--) {
|
||||
union vm_value tmp = page->values[start];
|
||||
page->values[start] = page->values[end];
|
||||
page->values[end] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,5 +100,6 @@ bool array_erase(struct page **page, int i);
|
||||
void array_insert(struct page **_page, int i, union vm_value v, int data_type, int struct_type);
|
||||
void array_sort(struct page *page, int compare_fno);
|
||||
int array_find(struct page *page, int start, int end, union vm_value v, int compare_fno);
|
||||
void array_reverse(struct page *page);
|
||||
|
||||
#endif /* SYSTEM4_PAGE_H */
|
||||
|
||||
@@ -1556,6 +1556,12 @@ static void execute_instruction(enum opcode opcode)
|
||||
int start = stack_pop().i;
|
||||
int array = stack_pop_var()->i;
|
||||
stack_push(array_find(heap[array].page, start, end, v, fno));
|
||||
break;
|
||||
}
|
||||
case A_REVERSE: {
|
||||
int array = stack_pop_var()->i;
|
||||
array_reverse(heap[array].page);
|
||||
break;
|
||||
}
|
||||
// -- NOOPs ---
|
||||
case FUNC:
|
||||
|
||||
Reference in New Issue
Block a user