I added some code to help with constants but it's not working.
This commit is contained in:
@ -23,20 +23,20 @@ void emit_helper(void){
|
||||
}
|
||||
}
|
||||
|
||||
void emit_binary_op(char* result, Op op, char* arg1, char* arg2){
|
||||
void emit_binary_op(TableNode * result, Op op, TableNode * arg1, TableNode * arg2){
|
||||
emit_helper();
|
||||
current->opcode = op;
|
||||
current->result = look_up(cur, result);
|
||||
current->operand1 = look_up(cur, arg1);
|
||||
current->operand2 = look_up(cur, arg2);
|
||||
current->result = result;
|
||||
current->operand1 = arg1;
|
||||
current->operand2 = arg2;
|
||||
return;
|
||||
}
|
||||
|
||||
void emit_unary_op(char* result, Op op, char* arg){
|
||||
void emit_unary_op(TableNode * result, Op op, TableNode * arg){
|
||||
emit_helper();
|
||||
current->opcode = op;
|
||||
current->result = look_up(cur, result);
|
||||
current->operand1 = look_up(cur, arg);
|
||||
current->result = result;
|
||||
current->operand1 = arg;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,30 @@ typedef enum {
|
||||
|
||||
|
||||
} Op;
|
||||
|
||||
typedef enum {
|
||||
NODE,
|
||||
INTEGER,
|
||||
STRING,
|
||||
CHARACTER,
|
||||
ADDRESS,
|
||||
BOOLEAN
|
||||
} Discriminant;
|
||||
|
||||
typedef union {
|
||||
TableNode * node;
|
||||
int integer;
|
||||
char * string;
|
||||
char character;
|
||||
void * address;
|
||||
bool Boolean;
|
||||
} Register_union;
|
||||
|
||||
typedef struct {
|
||||
Discriminant d;
|
||||
Register_union r_union;
|
||||
} TNodeOrConst;
|
||||
|
||||
typedef struct Instruction {
|
||||
Op opcode;
|
||||
TableNode * result;
|
||||
|
29
test.alpha
Normal file
29
test.alpha
Normal file
@ -0,0 +1,29 @@
|
||||
|
||||
|
||||
|
||||
type a : 1 -> integers
|
||||
type t : integer -> a
|
||||
type r : integer -> integer
|
||||
|
||||
|
||||
|
||||
function foo : t
|
||||
function bar : r
|
||||
function entry :
|
||||
|
||||
bar(a) := {
|
||||
5 + bar(a - 1);
|
||||
return a * bar(a-1);
|
||||
}
|
||||
|
||||
foo(c) := {
|
||||
[a: arg]
|
||||
arg := reserve arg(c);
|
||||
return arg;
|
||||
}
|
||||
|
||||
entry(args) := {
|
||||
[a: b]
|
||||
b := foo(8);
|
||||
}
|
||||
|
Reference in New Issue
Block a user