I added some more backpatching and some more files for testing
This commit is contained in:
@ -662,7 +662,14 @@ compound_statement:
|
||||
|
||||
simple_statement:
|
||||
assignable ASSIGN expression
|
||||
{ printdebug("simple statement");
|
||||
{
|
||||
// ----------------------------------------------------------------------------
|
||||
emit_label(label_gen());
|
||||
emit_backpatch(S_Pop(TrueList), getLabel(current));
|
||||
emit_backpatch(S_Pop(FalseList), getLabel(current));
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
printdebug("simple statement");
|
||||
TableNode* node;
|
||||
if((getAdInfoType((getTypeEntry((TableNode*)$1))) == TYPE_FUNCTION_TYPE)||
|
||||
(getAdInfoType((getTypeEntry((TableNode*)$1))) == TYPE_ARRAY_TYPE)||
|
||||
@ -744,7 +751,7 @@ ablock:
|
||||
|
||||
argument_list:
|
||||
expression{
|
||||
TableNode* arg = CreateEntry(cur, getAdInfoType((TableNode*)$1), getTypeEntry((TableNode*)$1), arg_var_gen(), NULL);
|
||||
TableNode * arg = CreateEntry(cur, getAdInfoType((TableNode*)$1), getTypeEntry((TableNode*)$1), arg_var_gen(), NULL);
|
||||
// ----------------------------------------------------------------------------
|
||||
// this is emitting the param withthe wrong TableNode
|
||||
// We need to fiture out how to get the right one.
|
||||
@ -891,7 +898,11 @@ expression:
|
||||
|
||||
| expression AND expression
|
||||
{
|
||||
char* temp = temp_var_gen();
|
||||
TableNode* node = CreateEntry(cur,TYPE_PRIMITIVE, boo, temp, NULL);
|
||||
// ----------------------------------------------------------------------------
|
||||
uint_least8_t b = 0;
|
||||
emit_assignment(node, tn_or_const(BOOLEAN,&b));
|
||||
emit_label(label_gen());
|
||||
emit_backpatch(S_Pop(TrueList), getLabel(current));
|
||||
emit_conditional_jump(E_IF_X_FALSE, 0, tn_or_const(NODE, $1));
|
||||
@ -917,7 +928,8 @@ expression:
|
||||
S_Push(FalseList, t, 1);
|
||||
}
|
||||
S_Push(t, current, 1);
|
||||
|
||||
b = 1;
|
||||
emit_assignment(node, tn_or_const(BOOLEAN,&b));
|
||||
emit_goto(0);
|
||||
t = S_Peek(TrueList);
|
||||
if(t==NULL){
|
||||
@ -928,8 +940,6 @@ expression:
|
||||
S_Merge(FalseList);
|
||||
// ----------------------------------------------------------------------------
|
||||
printdebug("AND");
|
||||
char* temp = temp_var_gen();
|
||||
TableNode* node = CreateEntry(cur,TYPE_PRIMITIVE, boo, temp, NULL);
|
||||
if((getTypeEntry((TableNode*)$1)==getTypeEntry((TableNode*)$3)) && getTypeEntry((TableNode*)$1) == boo) {
|
||||
//emit_binary_op(E_AND,node,tn_or_const(NODE,$1),tn_or_const(NODE,$3));
|
||||
$$ = node;
|
||||
@ -941,7 +951,11 @@ expression:
|
||||
|
||||
| expression OR expression
|
||||
{
|
||||
char* temp = temp_var_gen();
|
||||
TableNode* node = CreateEntry(cur,TYPE_PRIMITIVE, boo, temp, NULL);
|
||||
// ----------------------------------------------------------------------------
|
||||
uint_least8_t b = 1;
|
||||
emit_assignment(node, tn_or_const(BOOLEAN,&b));
|
||||
emit_label(label_gen());
|
||||
emit_backpatch(S_Pop(TrueList), getLabel(current));
|
||||
emit_conditional_jump(E_IF_X_TRUE, 0, tn_or_const(NODE, $1));
|
||||
@ -967,6 +981,8 @@ expression:
|
||||
S_Push(TrueList, t, 1);
|
||||
}
|
||||
S_Push(t, current, 1);
|
||||
b = 0;
|
||||
emit_assignment(node, tn_or_const(BOOLEAN,&b));
|
||||
emit_goto(0);
|
||||
t = S_Peek(FalseList);
|
||||
if(t==NULL){
|
||||
@ -978,8 +994,6 @@ expression:
|
||||
// ----------------------------------------------------------------------------
|
||||
printdebug("OR");
|
||||
if((getTypeEntry((TableNode*)$1)==getTypeEntry((TableNode*)$3)) && getTypeEntry((TableNode*)$1) == boo) {
|
||||
char* temp = temp_var_gen();
|
||||
TableNode* node = CreateEntry(cur,TYPE_PRIMITIVE, boo, temp, NULL);
|
||||
$$ = node;
|
||||
} else {
|
||||
$$=undefined;
|
||||
@ -1067,9 +1081,59 @@ expression:
|
||||
}
|
||||
|
||||
// TODO: We need to type check this.
|
||||
| RESERVE ID {$$ = undefined; }
|
||||
| RESERVE ID {
|
||||
char* temp = temp_var_gen();
|
||||
TableNode* node = CreateEntry(cur,TYPE_PRIMITIVE, addr, temp, NULL);
|
||||
TableNode * n = look_up(cur, $2);
|
||||
if(getAdInfoType(n) != TYPE_RECORD){
|
||||
throw_error(ERROR_TYPE, "Invalid Reserve expression with object %s of type %s.",
|
||||
getName((TableNode*)n), getType((TableNode*)n));
|
||||
$$=undefined;
|
||||
}
|
||||
int v = getRecTotal(getTypeEntry(n));
|
||||
emit_reserve(node, tn_or_const(INTEGER, &v));
|
||||
$$ = node;
|
||||
}
|
||||
| RELEASE ID {$$ = undefined; }
|
||||
| RESERVE ID L_PAREN argument_list R_PAREN {$$ = undefined; }
|
||||
| RESERVE ID {
|
||||
cur = CreateScope(cur, -1,-1);
|
||||
} L_PAREN argument_list R_PAREN {
|
||||
char* temp = temp_var_gen();
|
||||
TableNode* node = CreateEntry(cur,TYPE_PRIMITIVE, addr, temp, NULL);
|
||||
int a = S_Size(S_Peek(stack)) + 1;
|
||||
emit_push_all(S_Peek(stack));
|
||||
S_Pop(stack);
|
||||
emit_function_call(node, a, tn_or_const(NODE, $2));
|
||||
$$ = node;
|
||||
/*
|
||||
TableNode * t = getFirstEntry(cur);
|
||||
TableNode * n = look_up(cur, $2);
|
||||
if(getAdInfoType(n) == TYPE_ARRAY){
|
||||
int array_dims = getNumArrDim(getTypeEntry(n));
|
||||
if ($5 != array_dims) {
|
||||
throw_error(ERROR_SYNTAX, "expected %d dimensions for this array but got %d", array_dims, $5);
|
||||
}else{
|
||||
while(t != NULL && t != undefined && getName(t)[0] != '&'){
|
||||
t = getNextEntry(t);
|
||||
}
|
||||
if(getTypeEntry(t) != integ){
|
||||
throw_error(ERROR_TYPE, "Arg for an array is not of type integer");
|
||||
}
|
||||
t = getNextEntry(t);
|
||||
while(t != NULL && t != undefined && getName(t)[0] != '&'){
|
||||
while(getTypeEntry(t) != integ)(arg_given != NULL && getName(arg_given)[0]!='&'){
|
||||
arg_given = getNextEntry(arg_given);
|
||||
}
|
||||
if(getTypeEntry(arg_given) != getTypeEntry(param_arg_type)){
|
||||
throw_error(ERROR_TYPE, "expected type %s expression as argument of a record in function call but got type %s", getType(param_arg_type), getType(arg_given));
|
||||
}
|
||||
arg_given = getNextEntry(arg_given);
|
||||
param_arg_type = getNextEntry(param_arg_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
| RELEASE ID L_PAREN argument_list R_PAREN
|
||||
{
|
||||
int d = getAdInfoType((TableNode*)$2);
|
||||
|
@ -309,6 +309,8 @@ void emit_return(TNodeOrConst * value){
|
||||
}
|
||||
|
||||
void emit_reserve(TableNode * result, TNodeOrConst * size){
|
||||
// this needs to change
|
||||
// we need to take a int
|
||||
emit_parameter(size);
|
||||
emit_function_call(result, 1, tn_or_const(NODE, look_up(cur, "reserve")));
|
||||
}
|
||||
|
@ -45,13 +45,13 @@ b(x) := {
|
||||
i := x;
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
c(x) := {
|
||||
[string: s]
|
||||
s := "Hi!";
|
||||
return x(s);
|
||||
}
|
||||
|
||||
|
||||
|
||||
(* Function definition
|
||||
entry is the first function called
|
||||
@ -66,7 +66,7 @@ entry(arg) := {
|
||||
result := 0;
|
||||
}
|
||||
else {
|
||||
[ Boolean : b]
|
||||
[ Boolean : b]
|
||||
result := entry("hello");
|
||||
}
|
||||
result := c(f);
|
||||
|
11
tests/sprint3/test/sp3_arr_reserve.alpha
Normal file
11
tests/sprint3/test/sp3_arr_reserve.alpha
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
type main: string -> integer
|
||||
function entry: main
|
||||
type t: 3 -> integer
|
||||
|
||||
|
||||
entry (arg) := {
|
||||
[ t:a]
|
||||
a := reserve a(1, 3, 4);
|
||||
return 0;
|
||||
}
|
@ -14,7 +14,7 @@ bar (r,s) := {
|
||||
*)
|
||||
entry (arg) := {
|
||||
[ Boolean:x ; Boolean:y ; Boolean:z ; Boolean:t]
|
||||
if ( ( x < y ) (* < ( z & t )*)) then {
|
||||
if ( ( x & y ) ) then {
|
||||
|
||||
(*
|
||||
if ( x<y & !(x=y) ) then {
|
||||
@ -23,7 +23,7 @@ entry (arg) := {
|
||||
}
|
||||
*)
|
||||
|
||||
z := 9;
|
||||
z := x < y;
|
||||
} else {
|
||||
y := true; (* bar('c', 7); *)
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ bar (r,s) := {
|
||||
|
||||
entry (arg) := {
|
||||
[ Boolean:x ; Boolean:y ; Boolean:z ; Boolean:t]
|
||||
while ( !( x & y ) (* | ( z | t ) *) ) {
|
||||
while ( ( x | y ) (* | ( z | t ) *) ) {
|
||||
(*
|
||||
if ( ( x < y ) & ( z = t ) ) then {
|
||||
y := z < t;
|
||||
@ -20,7 +20,7 @@ entry (arg) := {
|
||||
t := z = t;
|
||||
}
|
||||
*)
|
||||
y := true; (* bar('c', 7); *)
|
||||
y := t < z; (* bar('c', 7); *)
|
||||
}
|
||||
(* x := x & y; *)
|
||||
return 0;
|
||||
|
18
tests/sprint4/test/sp4_cg_fib.alpha
Normal file
18
tests/sprint4/test/sp4_cg_fib.alpha
Normal file
@ -0,0 +1,18 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -4,8 +4,8 @@ function test: main
|
||||
|
||||
test (a) := {
|
||||
[Boolean: b; integer: x; integer: y]
|
||||
x := 1;
|
||||
character x := 1;
|
||||
y := 2;
|
||||
b := x < y;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user