Commit c242b53d authored by Ken Thompson's avatar Ken Thompson

more maps

more semi-colons
type assignment of constants

SVN=123278
parent c5bb50c9
...@@ -20,7 +20,17 @@ convlit(Node *n, Type *t) ...@@ -20,7 +20,17 @@ convlit(Node *n, Type *t)
goto bad1; goto bad1;
case Wlitnil: case Wlitnil:
if(isptr[et] || et = TINTER) if(isptr[et] || et == TINTER)
break;
goto bad1;
case Wlitstr:
if(isptrto(t, TSTRING))
break;
goto bad1;
case Wlitbool:
if(et == TBOOL)
break; break;
goto bad1; goto bad1;
......
...@@ -446,6 +446,7 @@ void warn(char*, ...); ...@@ -446,6 +446,7 @@ void warn(char*, ...);
void fatal(char*, ...); void fatal(char*, ...);
void linehist(char*, long); void linehist(char*, long);
Node* nod(int, Node*, Node*); Node* nod(int, Node*, Node*);
Node* list(Node*, Node*);
Type* typ(int); Type* typ(int);
Dcl* dcl(void); Dcl* dcl(void);
Node* rev(Node*); Node* rev(Node*);
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
%type <lint> chandir %type <lint> chandir
%type <node> xdcl xdcl_list_r oxdcl_list common_dcl %type <node> xdcl xdcl_list_r oxdcl_list common_dcl
%type <node> oarg_type_list arg_type_list_r arg_type %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> complex_stmt compound_stmt ostmt_list
%type <node> stmt_list_r Astmt_list_r Bstmt_list_r %type <node> stmt_list_r Astmt_list_r Bstmt_list_r
%type <node> Astmt Bstmt Cstmt Dstmt %type <node> Astmt Bstmt Cstmt Dstmt
...@@ -232,20 +232,14 @@ else_stmt2: ...@@ -232,20 +232,14 @@ else_stmt2:
} }
simple_stmt: simple_stmt:
inc_stmt
| noninc_stmt
noninc_stmt:
expr expr
{ {
$$ = $1; $$ = $1;
} }
| expr LINC
{
$$ = nod(OASOP, $1, literal(1));
$$->etype = OADD;
}
| expr LDEC
{
$$ = nod(OASOP, $1, literal(1));
$$->etype = OSUB;
}
| expr LASOP expr | expr LASOP expr
{ {
$$ = nod(OASOP, $1, $3); $$ = nod(OASOP, $1, $3);
...@@ -264,6 +258,18 @@ simple_stmt: ...@@ -264,6 +258,18 @@ simple_stmt:
$$ = nod(OAS, $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: complex_stmt:
LFOR for_stmt LFOR for_stmt
{ {
...@@ -1094,14 +1100,15 @@ Bstmt: ...@@ -1094,14 +1100,15 @@ Bstmt:
* need semi in back YES * need semi in back YES
*/ */
Cstmt: Cstmt:
simple_stmt noninc_stmt
/* /*
* need semi in front YES * need semi in front YES
* need semi in back NO * need semi in back NO
*/ */
Dstmt: Dstmt:
new_name ':' inc_stmt
| new_name ':'
{ {
$$ = nod(OLABEL, $1, N); $$ = nod(OLABEL, $1, N);
} }
...@@ -1114,15 +1121,15 @@ Astmt_list_r: ...@@ -1114,15 +1121,15 @@ Astmt_list_r:
| Dstmt | Dstmt
| Astmt_list_r Astmt | Astmt_list_r Astmt
{ {
$$ = nod(OLIST, $1, $2); $$ = list($1, $2);
} }
| Astmt_list_r Dstmt | Astmt_list_r Dstmt
{ {
$$ = nod(OLIST, $1, $2); $$ = list($1, $2);
} }
| Bstmt_list_r Astmt | Bstmt_list_r Astmt
{ {
$$ = nod(OLIST, $1, $2); $$ = list($1, $2);
} }
/* /*
...@@ -1133,15 +1140,15 @@ Bstmt_list_r: ...@@ -1133,15 +1140,15 @@ Bstmt_list_r:
| Cstmt | Cstmt
| Astmt_list_r Bstmt | Astmt_list_r Bstmt
{ {
$$ = nod(OLIST, $1, $2); $$ = list($1, $2);
} }
| Astmt_list_r Cstmt | Astmt_list_r Cstmt
{ {
$$ = nod(OLIST, $1, $2); $$ = list($1, $2);
} }
| Bstmt_list_r Bstmt | Bstmt_list_r Bstmt
{ {
$$ = nod(OLIST, $1, $2); $$ = list($1, $2);
} }
stmt_list_r: stmt_list_r:
......
...@@ -254,6 +254,16 @@ nod(int op, Node *nleft, Node *nright) ...@@ -254,6 +254,16 @@ nod(int op, Node *nleft, Node *nright)
return n; return n;
} }
Node*
list(Node *a, Node *b)
{
if(a == N)
return b;
if(b == N)
return a;
return nod(OLIST, a, b);
}
Type* Type*
typ(int et) typ(int et)
{ {
......
...@@ -12,8 +12,12 @@ static Node* curfn; ...@@ -12,8 +12,12 @@ static Node* curfn;
void void
walk(Node *fn) walk(Node *fn)
{ {
if(debug['W'])
dump("fn-before", fn->nbody);
curfn = fn; curfn = fn;
walktype(fn->nbody, Etop); walktype(fn->nbody, Etop);
if(debug['W'])
dump("fn", fn->nbody);
} }
void void
...@@ -458,6 +462,9 @@ loop: ...@@ -458,6 +462,9 @@ loop:
goto badt; goto badt;
case TMAP: case TMAP:
print("top=%d type %lT", top, t);
dump("index", n);
// right side must map type // right side must map type
if(n->right->type == T) { if(n->right->type == T) {
convlit(n->right, t->down); convlit(n->right, t->down);
...@@ -470,6 +477,8 @@ loop: ...@@ -470,6 +477,8 @@ loop:
goto badt; goto badt;
n->op = OINDEX; n->op = OINDEX;
n->type = t->type; n->type = t->type;
if(top == Erv)
*n = *mapop(n, top);
break; break;
case TSTRING: case TSTRING:
...@@ -710,7 +719,6 @@ walkswitch(Node *sw, Type*(*call)(Node*, Type*)) ...@@ -710,7 +719,6 @@ walkswitch(Node *sw, Type*(*call)(Node*, Type*))
{ {
Node *n, *c; Node *n, *c;
Type *place; Type *place;
place = call(sw->ntest, T); place = call(sw->ntest, T);
n = sw->nbody; n = sw->nbody;
...@@ -1372,10 +1380,10 @@ mapop(Node *n, int top) ...@@ -1372,10 +1380,10 @@ mapop(Node *n, int top)
r->type = n->type; r->type = n->type;
break; break;
case OINDEXPTR: case OINDEX:
if(top != Erv) if(top != Erv)
goto nottop; goto nottop;
dump("access start", n);
// mapaccess1(hmap *map[any]any, key any) (val any); // mapaccess1(hmap *map[any]any, key any) (val any);
t = fixmap(n->left->type); t = fixmap(n->left->type);
...@@ -1408,6 +1416,7 @@ mapop(Node *n, int top) ...@@ -1408,6 +1416,7 @@ mapop(Node *n, int top)
r = nod(OCALL, on, r); r = nod(OCALL, on, r);
walktype(r, Erv); walktype(r, Erv);
r->type = t->type; r->type = t->type;
dump("access finish", r);
break; break;
// mapaccess2(hmap *map[any]any, key any) (val any, pres bool); // mapaccess2(hmap *map[any]any, key any) (val any, pres bool);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment