Permalink
Browse files

preparations for enabling "for (int i....".

  • Loading branch information...
1 parent 07abbd1 commit 426723663d12f25f53b0baa134c3d3696b3a4276 @kjs kjs committed Jun 26, 2012
Showing with 18 additions and 9 deletions.
  1. +3 −3 failures/struct.m1
  2. +1 −1 run_m1.sh
  3. +3 −3 src/ast.c
  4. +4 −0 src/ast.h
  5. +7 −2 src/m1.y
View
6 failures/struct.m1
@@ -20,9 +20,9 @@ void main() {
print(a.b.c.x, "\n");
/* Select one of 3: any other combination fails. */
- foo(a.b.c.x);
-// baz(a);
-// bar(a.b.c);
+ foo(a.b.c.x);
+ baz(a);
+ bar(a.b.c);
}
View
2 run_m1.sh
@@ -11,5 +11,5 @@ file_suffixe=${1##*.}
./m1 $1 2>/dev/null > $filename.m0
[ -s $filename.m0 ] || { echo "error: outputs a empty file $filename.m0 when compiling $1"; exit 1; }
./m0_assembler.pl $filename.m0 >/dev/null
-./m0 $filename.m0b || { exit 1; }
+perl m0_interp.pl $filename.m0b || { exit 1; }
exit 0
View
6 src/ast.c
@@ -244,8 +244,8 @@ constdecl(M1_compiler *comp, char *type, char *name, m1_expression *e) {
return expr;
}
-static void
-expr_set_for(m1_expression *node, m1_expression *init, m1_expression *cond, m1_expression *step,
+void
+expr_set_for(M1_compiler *comp, m1_expression *node, m1_expression *init, m1_expression *cond, m1_expression *step,
m1_expression *stat)
{
node->expr.o = (m1_forexpr *)m1_malloc(sizeof(m1_forexpr));
@@ -259,7 +259,7 @@ expr_set_for(m1_expression *node, m1_expression *init, m1_expression *cond, m1_e
m1_expression *
forexpr(M1_compiler *comp, m1_expression *init, m1_expression *cond, m1_expression *step, m1_expression *stat) {
m1_expression *expr = expression(comp, EXPR_FOR);
- expr_set_for(expr, init, cond, step, stat);
+ //expr_set_for(comp, expr, init, cond, step, stat);
return expr;
}
View
4 src/ast.h
@@ -362,6 +362,10 @@ extern m1_expression *whileexpr(M1_compiler *comp, m1_expression *cond, m1_expre
extern m1_expression *dowhileexpr(M1_compiler *comp, m1_expression *cond, m1_expression *block);
extern m1_expression *forexpr(M1_compiler *comp, m1_expression *init, m1_expression *cond, m1_expression *step, m1_expression *stat);
+extern void expr_set_for(M1_compiler *comp, m1_expression *node, m1_expression *init,
+ m1_expression *cond, m1_expression *step, m1_expression *stat);
+
+
extern m1_expression *inc_or_dec(M1_compiler *comp, m1_expression *obj, m1_unop optype);
extern m1_expression *returnexpr(M1_compiler *comp, m1_expression *retexp);
extern m1_expression *assignexpr(M1_compiler *comp, m1_expression *lhs, int assignop, m1_expression *rhs);
View
9 src/m1.y
@@ -198,6 +198,7 @@ yyerror(yyscan_t yyscanner, M1_compiler *comp, const char *str) {
while_stat
do_stat
for_stat
+ for_head
arguments
for_init
for_inits
@@ -822,10 +823,14 @@ expr_list : expression
}
;
-for_stat : "for" '(' for_init ';' for_cond ';' for_step ')' statement
- { $$ = forexpr(comp, $3, $5, $7, $9); }
+for_stat : for_head '(' for_init ';' for_cond ';' for_step ')' statement
+ { expr_set_for(comp, $1, $3, $5, $7, $9); }
;
+for_head : "for" /* ensure for expr node is in place to enable loop iterator declarations. */
+ { $$ = forexpr(comp, NULL, NULL, NULL, NULL); }
+ ;
+
for_init : /* empty */
{ $$ = NULL; }
| for_inits

0 comments on commit 4267236

Please sign in to comment.