Skip to content

Commit

Permalink
for working
Browse files Browse the repository at this point in the history
  • Loading branch information
SchawnnDev committed Jan 18, 2023
1 parent f6d41e0 commit 1dd3bf7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
4 changes: 2 additions & 2 deletions gen/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ instructions : id ASSIGN final_concatenation {log_debug("instructions: (%s, %s,
| DECLARE id LBRACKET table_int RBRACKET { doDeclareStaticArray($2, $4); if(HAS_ERROR()) YYABORT ; }
| IF marker_if test_block marker_test THEN list_instructions marker_end_instruction else_part FI { doMarkerFi(); if(HAS_ERROR()) YYABORT ; deleteBlock(); if(HAS_ERROR()) YYABORT ; }
| marker_for_header marker_for_arg marker_do DO list_instructions marker_done DONE { doForIdAssignArg($1); if(HAS_ERROR()) YYABORT ; doMarkerEndLoop(); if(HAS_ERROR()) YYABORT ; deleteBlock(); if(HAS_ERROR()) YYABORT ;}
| marker_for_header IN marker_for_list marker_do DO list_instructions marker_done DONE {doForIdAssign($1); if(HAS_ERROR()) YYABORT ; doMarkerEndLoop(); if(HAS_ERROR()) YYABORT ; doDeleteLocalOffset($3); if(HAS_ERROR()) YYABORT ; deleteBlock(); if(HAS_ERROR()) YYABORT ;}
| marker_for_header IN marker_for_list marker_do DO list_instructions marker_done DONE {doForIdAssign($1, $3); if(HAS_ERROR()) YYABORT ; doMarkerEndLoop(); if(HAS_ERROR()) YYABORT ; doDeleteLocalOffset($3); if(HAS_ERROR()) YYABORT ; deleteBlock(); if(HAS_ERROR()) YYABORT ;}
| WHILE marker_loop test_block marker_test DO list_instructions marker_done DONE { doMarkerEndLoop(); if(HAS_ERROR()) YYABORT ; deleteBlock(); if(HAS_ERROR()) YYABORT ; }
| UNTIL marker_loop test_block marker_until marker_test DO list_instructions marker_done DONE { doMarkerEndLoop(); if(HAS_ERROR()) YYABORT ; deleteBlock(); if(HAS_ERROR()) YYABORT ; }
| CASE operand IN list_case ESAC
Expand Down Expand Up @@ -215,7 +215,7 @@ marker_if : { $$ = ""; addBlock(BLOCK_IF); if(HAS_ERROR()) YYABORT ; }

marker_until : { $$ = ""; doNegBoolExpression(); if(HAS_ERROR()) YYABORT ; }

marker_for_list : list_operand { $$ = doMarkerForList($1); if(HAS_ERROR()) YYABORT ; if(HAS_ERROR()) YYABORT ; doMarkerLoop(BLOCK_FOR,$$); if(HAS_ERROR()) YYABORT ; doMarkerTestFor(); if(HAS_ERROR()) YYABORT ;}
marker_for_list : list_operand { $$ = doMarkerForList($1); if(HAS_ERROR()) YYABORT ; doMarkerTestFor(); if(HAS_ERROR()) YYABORT ;}

marker_for_header : FOR marker_for id { $$ = getOrCreateForIdMarker($3); if(HAS_ERROR()) YYABORT ; }

Expand Down
2 changes: 1 addition & 1 deletion include/compilation.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Marker doMarkerArg();

int doMarkerTestFor();

int doForIdAssign(Marker mark);
int doForIdAssign(Marker mark, Marker tempValues);

int doMarkerEndLoop();

Expand Down
13 changes: 9 additions & 4 deletions src/compilation.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ int doMarkerTestFor()
return RETURN_SUCCESS;
}

int doForIdAssign(Marker mark)
int doForIdAssign(Marker mark, Marker tempValues)
{
asm_code_printf("\t %s:\n",getForLabel())

Expand All @@ -543,15 +543,17 @@ int doForIdAssign(Marker mark)
asm_loadLabelAddressIntoRegister(slot->label, "$t2");
}

asm_code_printf("\tmul $t3, $s0, %d\n", ASM_INTEGER_SIZE)
asm_loadLabelIntoRegister(tempValues->lbl, "$s0");
asm_code_printf("\tsubi $s0, $s0, 1\n")
asm_code_printf("\tmul $t3, $s0, %d\n", -ASM_INTEGER_SIZE)
asm_code_printf("\tadd $t3, $t3, $s7\n") // Add local offset
asm_code_printf("\tadd $t3, $t3, $sp\n") // dont forget to add sp
asm_code_printf("\taddi $t3, $t3, %d\n", ASM_VAR_REGISTERS_CACHE_SIZE)
asm_code_printf("\tadd $t3, $t3, $sp\n") // don't forget to add sp
asm_code_printf("\tlw $t4, 0($t3)\n")
asm_code_printf("\tsw $t4, 0($t2)\n")

asm_code_printf("\n\tj %s_\n",getForLabel())


destroyMarker(mark);
CHECK_ERROR_RETURN(RETURN_FAILURE)
return RETURN_SUCCESS;
Expand Down Expand Up @@ -725,6 +727,9 @@ Marker doMarkerForList(MemorySlotList list)
asm_code_printf("\n\t# End do marker for list section\n\n")

CHECK_ERROR_RETURN(NULL)

doMarkerLoop(BLOCK_FOR,mark);

return mark;
}

Expand Down
26 changes: 11 additions & 15 deletions tests/runtime/basic.sos
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
ite=0;
ite_bis=0;

test_function()
{
while test ${ite_bis} -le 1 do
ite_bis = $( expr ${ite_bis} + 1 )
done;
echo ite_bis
} ;

while test ${ite} -lt 5 do
echo "ite: " ${ite};
res=$(test_function);
echo "ite_bis: " ${res}
for te in "hello" "how" "do" "you" "do" do
echo ${te} "\n"
done;

fact () { # n
for te in "hello" "how" "do" "you" "do" do
echo ${te} "\n";
for te in "BARA" "BARA" "BERE" "BARA" "BARA" "BERE" do
echo ${te}
done
done
} ;
fact;
exit

0 comments on commit 1dd3bf7

Please sign in to comment.