Implement A_REVERSE instruction

This commit is contained in:
Nunuhara Cabbage
2019-12-21 07:19:38 -08:00
parent a8d1abb483
commit 6b16bd1b8e
4 changed files with 21 additions and 2 deletions
+2 -2
View File
@@ -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
+12
View File
@@ -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;
}
}
+1
View File
@@ -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 */
+6
View File
@@ -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: