It works for if and while statments. Number of params not going well
This commit is contained in:
@ -542,37 +542,48 @@ compound_statement statement_list {
|
|||||||
|
|
||||||
|
|
||||||
compound_statement:
|
compound_statement:
|
||||||
WHILE L_PAREN
|
WHILE L_PAREN {
|
||||||
{
|
|
||||||
S_Push(TrueList, S_Init(), 0);
|
S_Push(TrueList, S_Init(), 0);
|
||||||
S_Push(FalseList, S_Init(), 0);
|
S_Push(FalseList, S_Init(), 0);
|
||||||
|
int *l = calloc(1, sizeof(int));
|
||||||
|
*l = label_gen();
|
||||||
|
emit_label(*l);
|
||||||
|
S_Push(stack, l, 2);
|
||||||
} expression R_PAREN {
|
} expression R_PAREN {
|
||||||
emit_label(label_gen());
|
emit_label(label_gen());
|
||||||
emit_backpatch(S_Pop(TrueList), getLabel(current));
|
emit_backpatch(S_Pop(TrueList), getLabel(current));
|
||||||
} sblock {
|
} sblock {
|
||||||
$$ = $7;
|
$$ = $7;
|
||||||
emit_label(label_gen());
|
int l = label_gen();
|
||||||
emit_backpatch(S_Pop(FalseList), getLabel(current));
|
emit_backpatch(S_Pop(FalseList), l);
|
||||||
|
emit_goto(*(int*)(S_Pop(stack)));
|
||||||
|
emit_label(l);
|
||||||
}
|
}
|
||||||
| IF L_PAREN expression R_PAREN THEN {emit_label(label_gen());}
|
| IF L_PAREN {
|
||||||
sblock ELSE {emit_label(label_gen());}
|
S_Push(TrueList, S_Init(), 0);
|
||||||
sblock {
|
S_Push(FalseList, S_Init(), 0);
|
||||||
/*
|
}expression R_PAREN THEN {
|
||||||
*/
|
emit_label(label_gen());
|
||||||
if ($7 == undefined && $10 != undefined) {
|
emit_backpatch(S_Pop(TrueList), getLabel(current));
|
||||||
$$ = $10;
|
} sblock ELSE {
|
||||||
} else if ($7 != undefined && $10 == undefined) {
|
int l = label_gen();
|
||||||
$$ = $7;
|
emit_backpatch(S_Pop(FalseList), l);
|
||||||
} else if ($7 == $10) {
|
emit_label(l);
|
||||||
$$ = $7;
|
} sblock {
|
||||||
}else if((getAdInfoType((TableNode*)$7) == TYPE_ARRAY_TYPE) && ((TableNode*)$10)==addr){
|
if ($8 == undefined && $11 != undefined) {
|
||||||
$$ = $7;
|
$$ = $11;
|
||||||
}else if((getAdInfoType((TableNode*)$7) == TYPE_RECORD_TYPE) && ((TableNode*)$10)==addr){
|
} else if ($8 != undefined && $11 == undefined) {
|
||||||
$$ = $7;
|
$$ = $8;
|
||||||
}else if(((TableNode*)$7)==addr && (getAdInfoType((TableNode*)$10) == TYPE_ARRAY_TYPE)){
|
} else if ($8 == $11) {
|
||||||
$$ = $10;
|
$$ = $8;
|
||||||
}else if(((TableNode*)$7)==addr && (getAdInfoType((TableNode*)$10) == TYPE_RECORD_TYPE)){
|
}else if((getAdInfoType((TableNode*)$8) == TYPE_ARRAY_TYPE) && ((TableNode*)$11)==addr){
|
||||||
$$ = $10;
|
$$ = $8;
|
||||||
|
}else if((getAdInfoType((TableNode*)$8) == TYPE_RECORD_TYPE) && ((TableNode*)$11)==addr){
|
||||||
|
$$ = $8;
|
||||||
|
}else if(((TableNode*)$8)==addr && (getAdInfoType((TableNode*)$11) == TYPE_ARRAY_TYPE)){
|
||||||
|
$$ = $11;
|
||||||
|
}else if(((TableNode*)$8)==addr && (getAdInfoType((TableNode*)$11) == TYPE_RECORD_TYPE)){
|
||||||
|
$$ = $11;
|
||||||
} else {
|
} else {
|
||||||
printdebug("3 differing return types within same function at line %d, column %d", @1.first_line, @1.first_column);
|
printdebug("3 differing return types within same function at line %d, column %d", @1.first_line, @1.first_column);
|
||||||
//printf("%s\n", getName((TableNode*)$6));
|
//printf("%s\n", getName((TableNode*)$6));
|
||||||
@ -847,7 +858,6 @@ expression:
|
|||||||
S_Push(TrueList, t, 1);
|
S_Push(TrueList, t, 1);
|
||||||
}
|
}
|
||||||
S_Push(t, current, 1);
|
S_Push(t, current, 1);
|
||||||
S_Push(S_Peek(TrueList), current, 1);
|
|
||||||
emit_goto(0);
|
emit_goto(0);
|
||||||
t = S_Peek(FalseList);
|
t = S_Peek(FalseList);
|
||||||
if(t==NULL){
|
if(t==NULL){
|
||||||
@ -873,7 +883,19 @@ expression:
|
|||||||
char* temp = temp_var_gen();
|
char* temp = temp_var_gen();
|
||||||
TableNode* node = CreateEntry(cur,TYPE_PRIMITIVE, boo, temp, NULL);
|
TableNode* node = CreateEntry(cur,TYPE_PRIMITIVE, boo, temp, NULL);
|
||||||
emit_conditional_jump(E_EQUAL_TO, 0, tn_or_const(NODE,$1), tn_or_const(NODE,$3));
|
emit_conditional_jump(E_EQUAL_TO, 0, tn_or_const(NODE,$1), tn_or_const(NODE,$3));
|
||||||
|
Stack * t = S_Peek(TrueList);
|
||||||
|
if(t==NULL){
|
||||||
|
t = S_Init();
|
||||||
|
S_Push(TrueList, t, 1);
|
||||||
|
}
|
||||||
|
S_Push(t, current, 1);
|
||||||
emit_goto(0);
|
emit_goto(0);
|
||||||
|
t = S_Peek(FalseList);
|
||||||
|
if(t==NULL){
|
||||||
|
t = S_Init();
|
||||||
|
S_Push(FalseList, t, 1);
|
||||||
|
}
|
||||||
|
S_Push(t, current, 1);
|
||||||
$$ = node;
|
$$ = node;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -1022,15 +1044,8 @@ assignable:
|
|||||||
t= TYPE_UNDEFINED;
|
t= TYPE_UNDEFINED;
|
||||||
throw_error(ERROR_TYPE, "Undefined type returned by function.");
|
throw_error(ERROR_TYPE, "Undefined type returned by function.");
|
||||||
}
|
}
|
||||||
// TODO: add from stack
|
|
||||||
// TODO: emit_function_call
|
|
||||||
TableNode* node = CreateEntry(cur,t, typeNode2, temp, NULL);
|
TableNode* node = CreateEntry(cur,t, typeNode2, temp, NULL);
|
||||||
int a = 0;
|
|
||||||
/*
|
|
||||||
if(S_IsEmpty(stack)){
|
|
||||||
int a = S_Size(S_Peek(stack));
|
int a = S_Size(S_Peek(stack));
|
||||||
}
|
|
||||||
*/
|
|
||||||
emit_push_all(S_Peek(stack));
|
emit_push_all(S_Peek(stack));
|
||||||
S_Pop(stack);
|
S_Pop(stack);
|
||||||
emit_function_call(node, a, tn_or_const(NODE, $1));
|
emit_function_call(node, a, tn_or_const(NODE, $1));
|
||||||
|
@ -496,7 +496,7 @@ void emit_as_file(FILE * out_file, Instruction * i){
|
|||||||
break;
|
break;
|
||||||
case E_IF_X_TRUE:
|
case E_IF_X_TRUE:
|
||||||
fprintf(out_file,
|
fprintf(out_file,
|
||||||
"%4.d: if %s goto %d\n",
|
"%4.d: if %s GOTO %d\n",
|
||||||
i->index,
|
i->index,
|
||||||
get_string(i->operand1),
|
get_string(i->operand1),
|
||||||
i->label
|
i->label
|
||||||
@ -504,7 +504,7 @@ void emit_as_file(FILE * out_file, Instruction * i){
|
|||||||
break;
|
break;
|
||||||
case E_IF_X_FALSE:
|
case E_IF_X_FALSE:
|
||||||
fprintf(out_file,
|
fprintf(out_file,
|
||||||
"%4.d: if %s false goto %d\n",
|
"%4.d: if %s false GOTO %d\n",
|
||||||
i->index,
|
i->index,
|
||||||
get_string(i->operand1),
|
get_string(i->operand1),
|
||||||
i->label
|
i->label
|
||||||
|
@ -15,7 +15,6 @@ function make_list : list
|
|||||||
|
|
||||||
make_list (a) := {
|
make_list (a) := {
|
||||||
[integer:orig_a; llnode: ret; llnode: curr; llnode: temp]
|
[integer:orig_a; llnode: ret; llnode: curr; llnode: temp]
|
||||||
|
|
||||||
if (a < 0 | a = 0) then {
|
if (a < 0 | a = 0) then {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
|
@ -12,7 +12,12 @@ bar (r,s) := {
|
|||||||
|
|
||||||
entry (arg) := {
|
entry (arg) := {
|
||||||
[ integer: result ; rec: w]
|
[ integer: result ; rec: w]
|
||||||
result := bar(1,2);
|
while ( result = result ) {
|
||||||
|
while ( result < w.y ) {
|
||||||
|
result := 8;
|
||||||
|
}
|
||||||
|
result := 9;
|
||||||
|
}
|
||||||
result := bar('c', 7);
|
result := bar('c', 7);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Reference in New Issue
Block a user