Skip to content

Commit

Permalink
improvements to type checker. Add a test for type casting. Fix up typ…
Browse files Browse the repository at this point in the history
…ecasting code gen.
  • Loading branch information
kjs committed Jun 10, 2012
1 parent 0681fe8 commit 77b100b
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 102 deletions.
5 changes: 5 additions & 0 deletions src/decl.c
Expand Up @@ -6,6 +6,11 @@
#include "ast.h"


void
print_type(m1_decl *type) {
fprintf(stderr, "TYPE: [%s]\n", type->name);
}

/*
Find the declaration for type <typename>.
Expand Down
1 change: 1 addition & 0 deletions src/decl.h
Expand Up @@ -47,6 +47,7 @@ typedef struct m1_decl {

} m1_decl;

extern void print_type(m1_decl *type);

extern m1_decl *type_find_def(M1_compiler *, char *type);
extern m1_decl *type_enter_struct(M1_compiler *comp, char *structname, struct m1_struct *structdef);
Expand Down
4 changes: 2 additions & 2 deletions src/gencode.c
Expand Up @@ -1436,10 +1436,10 @@ gencode_cast(M1_compiler *comp, m1_castexpr *expr) {

switch (expr->targettype) {
case VAL_INT:
fprintf(OUT, "\tntoi\tI%d, %c%d, x\n", result.no, reg_chars[(int)reg.type], reg.no);
fprintf(OUT, "\tconvert_i_n\tI%d, %c%d, x\n", result.no, reg_chars[(int)reg.type], reg.no);
break;
case VAL_FLOAT:
fprintf(OUT, "\titon\tN%d, %c%d, x\n", result.no, reg_chars[(int)reg.type], reg.no);
fprintf(OUT, "\tconvert_n_i\tN%d, %c%d, x\n", result.no, reg_chars[(int)reg.type], reg.no);
break;
default:
assert(0);
Expand Down
4 changes: 2 additions & 2 deletions src/m1.l
Expand Up @@ -182,7 +182,7 @@ FLOATNUM {SIGN}?(({DIGITS}{DOT}{DIGIT}*|{DOT}{DIGITS})([eE]{SIGN}?{DIGITS
m1_decl *decl = type_find_def(comp, yytext);

if (decl == NULL) { /* not found, so must be an identifier */
fprintf(stderr, "%s is a TK_IDENT\n", yytext);
// fprintf(stderr, "%s is a TK_IDENT\n", yytext);
return TK_IDENT;
}
else {
Expand All @@ -192,7 +192,7 @@ FLOATNUM {SIGN}?(({DIGITS}{DOT}{DIGIT}*|{DOT}{DIGITS})([eE]{SIGN}?{DIGITS
}
}
else {
fprintf(stderr, "%s is a TK_IDENT\n", yytext);
// fprintf(stderr, "%s is a TK_IDENT\n", yytext);
return TK_IDENT;
}

Expand Down

0 comments on commit 77b100b

Please sign in to comment.