void fatal(char*, ...);
void linehist(char*, long);
Node* nod(int, Node*, Node*);
+Node* list(Node*, Node*);
Type* typ(int);
Dcl* dcl(void);
Node* rev(Node*);
%type <lint> chandir
%type <node> xdcl xdcl_list_r oxdcl_list common_dcl
%type <node> oarg_type_list arg_type_list_r arg_type
-%type <node> else_stmt1 else_stmt2
+%type <node> else_stmt1 else_stmt2 inc_stmt noninc_stmt
%type <node> complex_stmt compound_stmt ostmt_list
%type <node> stmt_list_r Astmt_list_r Bstmt_list_r
%type <node> Astmt Bstmt Cstmt Dstmt
}
simple_stmt:
+ inc_stmt
+| noninc_stmt
+
+noninc_stmt:
expr
{
$$ = $1;
}
-| expr LINC
- {
- $$ = nod(OASOP, $1, literal(1));
- $$->etype = OADD;
- }
-| expr LDEC
- {
- $$ = nod(OASOP, $1, literal(1));
- $$->etype = OSUB;
- }
| expr LASOP expr
{
$$ = nod(OASOP, $1, $3);
$$ = nod(OAS, $1, $3);
}
+inc_stmt:
+ expr LINC
+ {
+ $$ = nod(OASOP, $1, literal(1));
+ $$->etype = OADD;
+ }
+| expr LDEC
+ {
+ $$ = nod(OASOP, $1, literal(1));
+ $$->etype = OSUB;
+ }
+
complex_stmt:
LFOR for_stmt
{
* need semi in back YES
*/
Cstmt:
- simple_stmt
+ noninc_stmt
/*
* need semi in front YES
* need semi in back NO
*/
Dstmt:
- new_name ':'
+ inc_stmt
+| new_name ':'
{
$$ = nod(OLABEL, $1, N);
}
| Dstmt
| Astmt_list_r Astmt
{
- $$ = nod(OLIST, $1, $2);
+ $$ = list($1, $2);
}
| Astmt_list_r Dstmt
{
- $$ = nod(OLIST, $1, $2);
+ $$ = list($1, $2);
}
| Bstmt_list_r Astmt
{
- $$ = nod(OLIST, $1, $2);
+ $$ = list($1, $2);
}
/*
| Cstmt
| Astmt_list_r Bstmt
{
- $$ = nod(OLIST, $1, $2);
+ $$ = list($1, $2);
}
| Astmt_list_r Cstmt
{
- $$ = nod(OLIST, $1, $2);
+ $$ = list($1, $2);
}
| Bstmt_list_r Bstmt
{
- $$ = nod(OLIST, $1, $2);
+ $$ = list($1, $2);
}
stmt_list_r:
void
walk(Node *fn)
{
+ if(debug['W'])
+ dump("fn-before", fn->nbody);
curfn = fn;
walktype(fn->nbody, Etop);
+ if(debug['W'])
+ dump("fn", fn->nbody);
}
void
goto badt;
case TMAP:
+
+print("top=%d type %lT", top, t);
+dump("index", n);
// right side must map type
if(n->right->type == T) {
convlit(n->right, t->down);
goto badt;
n->op = OINDEX;
n->type = t->type;
+ if(top == Erv)
+*n = *mapop(n, top);
break;
case TSTRING:
{
Node *n, *c;
Type *place;
-
place = call(sw->ntest, T);
n = sw->nbody;
r->type = n->type;
break;
- case OINDEXPTR:
+ case OINDEX:
if(top != Erv)
goto nottop;
-
+dump("access start", n);
// mapaccess1(hmap *map[any]any, key any) (val any);
t = fixmap(n->left->type);
r = nod(OCALL, on, r);
walktype(r, Erv);
r->type = t->type;
+dump("access finish", r);
break;
// mapaccess2(hmap *map[any]any, key any) (val any, pres bool);