]> Cypherpunks repositories - gostls13.git/commitdiff
i2s and i2i
authorKen Thompson <ken@golang.org>
Tue, 12 Aug 2008 23:36:18 +0000 (16:36 -0700)
committerKen Thompson <ken@golang.org>
Tue, 12 Aug 2008 23:36:18 +0000 (16:36 -0700)
R=r
OCL=14140
CL=14140

src/cmd/6g/gen.c
src/cmd/gc/go.h
src/cmd/gc/go.y
src/cmd/gc/lex.c

index babaebbba8cc351a4c1a80f35d2d2b0b9b0c0075..876f78988f084c21fc781c6ebc72c4d2a90d2b15 100644 (file)
@@ -303,6 +303,7 @@ void
 agen_inter(Node *n, Node *res)
 {
        Node nodo, nodr, nodt;
+       Node *var;
        Sym *s;
        char *e;
        int32 o,lno;
@@ -355,9 +356,10 @@ agen_inter(Node *n, Node *res)
 
                nodo.xoffset = 1*widthptr;
                if(!n->left->addable) {
-                       agen(n->left, &nodr);
-                       gmove(&nodr, &nodo);
-                       fatal("agen_inter i2i");
+                       var = nod(OXXX, N, N);
+                       tempname(var, n->left->type);
+                       cgen(n->left, var);
+                       cgen(var, &nodo);
                } else {
                        cgen(n->left, &nodo);
                }
@@ -380,9 +382,10 @@ agen_inter(Node *n, Node *res)
 
                nodo.xoffset = 1*widthptr;
                if(!n->left->addable) {
-                       agen(n->left, &nodr);
-                       gmove(&nodr, &nodo);
-                       fatal("agen_inter i2s");
+                       var = nod(OXXX, N, N);
+                       tempname(var, n->left->type);
+                       cgen(n->left, var);
+                       cgen(var, &nodo);
                } else {
                        cgen(n->left, &nodo);
                }
index 47f1f54f4143e82ca4cb04667320c6859d4194b0..a1377fba4b6b5955780bd2b391bc81f138988ee0 100644 (file)
@@ -250,14 +250,14 @@ enum
        OPTR, OARRAY,
        ORETURN, OFOR, OIF, OSWITCH, OI2S, OS2I, OI2I,
        OAS, OASOP, OCASE, OXCASE, OSCASE, OFALL, OXFALL,
-       OGOTO, OPROC, ONEW, OPANIC, OPRINT, OEMPTY, OSELECT,
+       OGOTO, OPROC, ONEW, OEMPTY, OSELECT,
+       OLEN, OPANIC, OPRINT, OTYPEOF,
 
        OOROR,
        OANDAND,
        OEQ, ONE, OLT, OLE, OGE, OGT,
        OADD, OSUB, OOR, OXOR,
        OMUL, ODIV, OMOD, OLSH, ORSH, OAND,
-       OLEN,
        OFUNC,
        OLABEL,
        OBREAK,
index f660c887a76c32d2b1547e27da6222e28e1b73ac..523642dd3da38c93379b9fada4997b5d5c2b8614 100644 (file)
 %token <sym>           LPACKAGE LIMPORT LEXPORT
 %token <sym>           LMAP LCHAN LINTERFACE LFUNC LSTRUCT
 %token <sym>           LCOLAS LFALL LRETURN
-%token <sym>           LNEW LLEN
+%token <sym>           LNEW LLEN LTYPEOF LPANIC LPRINT
 %token <sym>           LVAR LTYPE LCONST LCONVERT LSELECT
 %token <sym>           LFOR LIF LELSE LSWITCH LCASE LDEFAULT
 %token <sym>           LBREAK LCONTINUE LGO LGOTO LRANGE
 %token <sym>           LNIL LTRUE LFALSE LIOTA
-%token <sym>           LPANIC LPRINT LIGNORE
 
 %token                 LOROR LANDAND LEQ LNE LLE LLT LGE LGT
 %token                 LLSH LRSH LINC LDEC LSEND LRECV
+%token                 LIGNORE
 
 %type  <sym>           sym sym1 sym2 key1 key2 laconst lname latype
 %type  <lint>          chandir
@@ -733,6 +733,11 @@ pexpr:
        {
                $$ = nod(OLEN, $3, N);
        }
+|      LTYPEOF '(' type ')'
+       {
+               $$ = nod(OTYPEOF, N, N);
+               $$->type = $3;
+       }
 |      LNEW '(' type ')'
        {
                $$ = nod(ONEW, N, N);
@@ -852,6 +857,7 @@ key1:
 |      LPRINT
 |      LNEW
 |      LBASETYPE
+|      LTYPEOF
 
 /*
  * keywords that we can
@@ -884,7 +890,6 @@ key2:
 |      LGO
 |      LGOTO
 |      LRANGE
-|      LIGNORE
 
 name:
        lname
index 2087ed5eabd7693aebe145736d81929b91055cad..ceec9242928ea8497aae24b3036aeb5b40061b0f 100644 (file)
@@ -981,12 +981,12 @@ static    struct
        "chan",         LCHAN,          Txxx,
        "const",        LCONST,         Txxx,
        "continue",     LCONTINUE,      Txxx,
-       "convert",      LCONVERT,       Txxx,           // should be a var
+       "convert",      LCONVERT,       Txxx,
        "default",      LDEFAULT,       Txxx,
        "else",         LELSE,          Txxx,
        "export",       LEXPORT,        Txxx,
        "fallthrough",  LFALL,          Txxx,
-       "false",        LFALSE,         Txxx,           // should be a var
+       "false",        LFALSE,         Txxx,
        "for",          LFOR,           Txxx,
        "func",         LFUNC,          Txxx,
        "go",           LGO,            Txxx,
@@ -996,19 +996,20 @@ static    struct
        "interface",    LINTERFACE,     Txxx,
        "iota",         LIOTA,          Txxx,
        "map",          LMAP,           Txxx,
-       "new",          LNEW,           Txxx,           // should be a var
-       "len",          LLEN,           Txxx,           // should be a var
-       "nil",          LNIL,           Txxx,           // should be a var
+       "new",          LNEW,           Txxx,
+       "len",          LLEN,           Txxx,
+       "nil",          LNIL,           Txxx,
        "package",      LPACKAGE,       Txxx,
-       "panic",        LPANIC,         Txxx,           // temp
-       "print",        LPRINT,         Txxx,           // temp
+       "panic",        LPANIC,         Txxx,
+       "print",        LPRINT,         Txxx,
        "range",        LRANGE,         Txxx,
        "return",       LRETURN,        Txxx,
        "select",       LSELECT,        Txxx,
        "struct",       LSTRUCT,        Txxx,
        "switch",       LSWITCH,        Txxx,
-       "true",         LTRUE,          Txxx,           // should be a var
+       "true",         LTRUE,          Txxx,
        "type",         LTYPE,          Txxx,
+       "typeof",       LTYPEOF,        Txxx,
        "var",          LVAR,           Txxx,
 
        "notwithstanding",              LIGNORE,        Txxx,