Skip to content

Commit

Permalink
assign statement's lhs is of type m1_object. this is preparation for …
Browse files Browse the repository at this point in the history
…adding another parameter to gencode_obj
  • Loading branch information
kjs committed Jun 1, 2012
1 parent faffddd commit 609fbac
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion m1_ast.c
Expand Up @@ -286,7 +286,7 @@ expr_set_assign(M1_compiler *comp, m1_expression *node, m1_expression *lhs, int
a += b => a = a + b
*/
node->expr.a = (m1_assignment *)m1_malloc(sizeof(m1_assignment));
node->expr.a->lhs = lhs;
node->expr.a->lhs = lhs->expr.t;

switch (assignop) {
case OP_ASSIGN: /* normal case */
Expand Down
2 changes: 1 addition & 1 deletion m1_ast.h
Expand Up @@ -41,7 +41,7 @@ typedef struct m1_struct {


typedef struct m1_assignment {
struct m1_expression *lhs;
struct m1_object *lhs;
struct m1_expression *rhs;

} m1_assignment;
Expand Down
4 changes: 3 additions & 1 deletion m1_eval.c
Expand Up @@ -12,6 +12,8 @@ Sample AST walking code to print out the equivalent M1 code.

#define OUT stderr

static void eval_assign(m1_assignment *a);
static void eval_obj(m1_object *o);
static void eval_expr(m1_expression *e);

static void
Expand All @@ -27,7 +29,7 @@ eval_int(int value) {

static void
eval_assign(m1_assignment *a) {
eval_expr(a->lhs);
eval_obj(a->lhs);
fprintf(OUT, " = ");
eval_expr(a->rhs);
fprintf(OUT, ";");
Expand Down
15 changes: 10 additions & 5 deletions m1_gencode.c
Expand Up @@ -38,7 +38,7 @@ in gencode_number().

static m1_reg gencode_expr(M1_compiler *comp, m1_expression *e);
static void gencode_block(M1_compiler *comp, m1_expression *block);

static m1_reg gencode_obj(M1_compiler *comp, m1_object *obj, m1_object **parent);

static const char type_chars[4] = {'i', 'n', 's', 'p'};
static const char reg_chars[4] = {'I', 'N', 'S', 'P'};
Expand Down Expand Up @@ -110,7 +110,7 @@ gencode_int(M1_compiler *comp, m1_literal *lit) {
set_imm Ix, y, z
*/
m1_reg reg;
m1_reg reg;

assert(comp != NULL);
assert(lit != NULL);
Expand Down Expand Up @@ -156,13 +156,14 @@ gencode_string(M1_compiler *comp, m1_literal *lit) {
static m1_reg
gencode_assign(M1_compiler *comp, NOTNULL(m1_assignment *a)) {
m1_reg lhs, rhs;
m1_object *parent;

debug("gencode_assign start...\n");

assert(a != NULL);

rhs = gencode_expr(comp, a->rhs);
lhs = gencode_expr(comp, a->lhs);
lhs = gencode_obj(comp, a->lhs, &parent);

/* copy the value held in register for rhs to the register of lhs */
assert((lhs.type >= 0) && (lhs.type < 4));
Expand Down Expand Up @@ -303,8 +304,12 @@ gencode_obj(M1_compiler *comp, m1_object *obj, m1_object **parent) {
{
int offset = 0;
m1_reg offsetreg = gencode_expr(comp, obj->obj.index);

// fprintf(OUT, "\tderef\t%d, <array>, I%d\n", reg.no);
if (obj->is_target == 1) {
// fprintf(OUT, "\tderef\t%d, <array>, I%d\n", reg.no);
}
else {

}
break;
}
default:
Expand Down
5 changes: 4 additions & 1 deletion m1_semcheck.c
Expand Up @@ -9,6 +9,9 @@

static m1_type check_expr(M1_compiler *comp, m1_expression *e);
static void check_block(M1_compiler *comp, m1_expression *expr);
static m1_type check_obj(M1_compiler *comp, m1_object *obj);



static void
type_error(M1_compiler *comp, unsigned line, char *msg) {
Expand All @@ -24,7 +27,7 @@ warning(M1_compiler *comp, unsigned line, char *msg) {

static void
check_assign(M1_compiler *comp, m1_assignment *a) {
m1_type ltype = check_expr(comp, a->lhs);
m1_type ltype = check_obj(comp, a->lhs);
m1_type rtype = check_expr(comp, a->rhs);

if (ltype != rtype) {
Expand Down

0 comments on commit 609fbac

Please sign in to comment.