Bit of code cleanup/documentation
This commit is contained in:
parent
c55b15cdfa
commit
492f20f74a
|
|
@ -19,8 +19,8 @@ bool init_vm() {
|
|||
return true;
|
||||
}
|
||||
|
||||
u32 syscall(u32 id, u32 args, u32 mem_ptr) {
|
||||
USED(args);
|
||||
u32 syscall(u32 id, u32 size, u32 mem_ptr) {
|
||||
USED(size);
|
||||
switch(id) {
|
||||
case SYSCALL_DBG_PRINT: {
|
||||
printf("%d\n", mem[mem_ptr]);
|
||||
|
|
@ -70,8 +70,6 @@ void test_fibonacci() {
|
|||
code[cp++] = ENCODE_B(OP_PUSH, 4, 0);
|
||||
code[cp++] = ENCODE_A(OP_CALL, 2, 3, 2);
|
||||
|
||||
|
||||
|
||||
code[cp++] = ENCODE_B(OP_RETURN, 0, 0);
|
||||
}
|
||||
|
||||
|
|
|
|||
20
vm/vm.c
20
vm/vm.c
|
|
@ -25,9 +25,9 @@ bool step_vm() {
|
|||
DECODE_A(instruction)
|
||||
u32 fn_ptr;
|
||||
|
||||
u32 rd = fp + (dest * 4);
|
||||
u32 r1 = src1;
|
||||
u32 r2 = fp + src2;
|
||||
u32 rd = fp + (dest * 4);/* function to jump to */
|
||||
u32 r1 = src1; /* locals count */
|
||||
u32 r2 = fp + (src2 * 4);/* local child return value to*/
|
||||
|
||||
fn_ptr = READ_U32(rd);
|
||||
|
||||
|
|
@ -42,7 +42,7 @@ bool step_vm() {
|
|||
mp += 4;
|
||||
/* now set the frame pointer, where the locals start */
|
||||
fp = mp;
|
||||
/* move mp by count many locals */
|
||||
/* move mp forward by count many locals */
|
||||
mp += (4 * r1);
|
||||
/* jump to dest_ptr */
|
||||
pc = fn_ptr;
|
||||
|
|
@ -60,7 +60,7 @@ bool step_vm() {
|
|||
u32 frame_start = fp - FRAME_HEADER_SIZE;
|
||||
u32 parent_fp = READ_U32(frame_start);
|
||||
u32 return_address = READ_U32(frame_start + 4);
|
||||
u32 parent_local_return_address = 4 * READ_U32(frame_start + 8);
|
||||
u32 parent_local_return_address = READ_U32(frame_start + 8);
|
||||
|
||||
USED(replaces_value);
|
||||
/* reset memory to parents end of memory */
|
||||
|
|
@ -68,8 +68,8 @@ bool step_vm() {
|
|||
/* reset the frame pointer */
|
||||
fp = parent_fp;
|
||||
|
||||
/* copy value to end of mp if it is a pointer */
|
||||
if (is_ptr) {
|
||||
/* copy value to end of mp if it is a pointer */
|
||||
WRITE_U32(parent_local_return_address, mp);
|
||||
size = READ_U32(return_value);
|
||||
WRITE_U32(mp, size);
|
||||
|
|
@ -90,10 +90,10 @@ bool step_vm() {
|
|||
}
|
||||
case OP_SYSCALL: {
|
||||
DECODE_A(instruction)
|
||||
u32 id = dest;
|
||||
u32 args = src1;
|
||||
u32 rd = fp + (src2 * 4);
|
||||
flag = syscall(id, args, rd);
|
||||
u32 id = dest; /* syscall id */
|
||||
u32 size = src1; /* size of heap at that pointer */
|
||||
u32 rd = fp + (src2 * 4); /* the pointer */
|
||||
flag = syscall(id, size, rd);
|
||||
return true;
|
||||
}
|
||||
case OP_LOAD_IMM: {
|
||||
|
|
|
|||
Loading…
Reference in New Issue