Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit 426723663d12f25f53b0baa134c3d3696b3a4276 1 parent 07abbd1
Klaas-Jan Stol kjs authored
6 failures/struct.m1
@@ -20,9 +20,9 @@ void main() {
20 20 print(a.b.c.x, "\n");
21 21
22 22 /* Select one of 3: any other combination fails. */
23   - foo(a.b.c.x);
24   -// baz(a);
25   -// bar(a.b.c);
  23 + foo(a.b.c.x);
  24 + baz(a);
  25 + bar(a.b.c);
26 26
27 27 }
28 28
2  run_m1.sh
@@ -11,5 +11,5 @@ file_suffixe=${1##*.}
11 11 ./m1 $1 2>/dev/null > $filename.m0
12 12 [ -s $filename.m0 ] || { echo "error: outputs a empty file $filename.m0 when compiling $1"; exit 1; }
13 13 ./m0_assembler.pl $filename.m0 >/dev/null
14   -./m0 $filename.m0b || { exit 1; }
  14 +perl m0_interp.pl $filename.m0b || { exit 1; }
15 15 exit 0
6 src/ast.c
@@ -244,8 +244,8 @@ constdecl(M1_compiler *comp, char *type, char *name, m1_expression *e) {
244 244 return expr;
245 245 }
246 246
247   -static void
248   -expr_set_for(m1_expression *node, m1_expression *init, m1_expression *cond, m1_expression *step,
  247 +void
  248 +expr_set_for(M1_compiler *comp, m1_expression *node, m1_expression *init, m1_expression *cond, m1_expression *step,
249 249 m1_expression *stat)
250 250 {
251 251 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
259 259 m1_expression *
260 260 forexpr(M1_compiler *comp, m1_expression *init, m1_expression *cond, m1_expression *step, m1_expression *stat) {
261 261 m1_expression *expr = expression(comp, EXPR_FOR);
262   - expr_set_for(expr, init, cond, step, stat);
  262 + //expr_set_for(comp, expr, init, cond, step, stat);
263 263 return expr;
264 264 }
265 265
4 src/ast.h
@@ -362,6 +362,10 @@ extern m1_expression *whileexpr(M1_compiler *comp, m1_expression *cond, m1_expre
362 362 extern m1_expression *dowhileexpr(M1_compiler *comp, m1_expression *cond, m1_expression *block);
363 363 extern m1_expression *forexpr(M1_compiler *comp, m1_expression *init, m1_expression *cond, m1_expression *step, m1_expression *stat);
364 364
  365 +extern void expr_set_for(M1_compiler *comp, m1_expression *node, m1_expression *init,
  366 + m1_expression *cond, m1_expression *step, m1_expression *stat);
  367 +
  368 +
365 369 extern m1_expression *inc_or_dec(M1_compiler *comp, m1_expression *obj, m1_unop optype);
366 370 extern m1_expression *returnexpr(M1_compiler *comp, m1_expression *retexp);
367 371 extern m1_expression *assignexpr(M1_compiler *comp, m1_expression *lhs, int assignop, m1_expression *rhs);
9 src/m1.y
@@ -198,6 +198,7 @@ yyerror(yyscan_t yyscanner, M1_compiler *comp, const char *str) {
198 198 while_stat
199 199 do_stat
200 200 for_stat
  201 + for_head
201 202 arguments
202 203 for_init
203 204 for_inits
@@ -822,10 +823,14 @@ expr_list : expression
822 823 }
823 824 ;
824 825
825   -for_stat : "for" '(' for_init ';' for_cond ';' for_step ')' statement
826   - { $$ = forexpr(comp, $3, $5, $7, $9); }
  826 +for_stat : for_head '(' for_init ';' for_cond ';' for_step ')' statement
  827 + { expr_set_for(comp, $1, $3, $5, $7, $9); }
827 828 ;
828 829
  830 +for_head : "for" /* ensure for expr node is in place to enable loop iterator declarations. */
  831 + { $$ = forexpr(comp, NULL, NULL, NULL, NULL); }
  832 + ;
  833 +
829 834 for_init : /* empty */
830 835 { $$ = NULL; }
831 836 | for_inits

0 comments on commit 4267236

Please sign in to comment.
Something went wrong with that request. Please try again.