]> Cypherpunks repositories - gostls13.git/commitdiff
more complex - constants
authorKen Thompson <ken@golang.org>
Thu, 18 Feb 2010 22:46:28 +0000 (14:46 -0800)
committerKen Thompson <ken@golang.org>
Thu, 18 Feb 2010 22:46:28 +0000 (14:46 -0800)
import and export

R=rsc
CC=golang-dev
https://golang.org/cl/214050

src/cmd/gc/const.c
src/cmd/gc/export.c
src/cmd/gc/go.h
src/cmd/gc/go.y
src/cmd/gc/walk.c
src/pkg/runtime/type.go

index fed3b14762ab75e5f33884b5d7759a7856b83bbb..1727e775a2b5ee4fac0d719241ca68dfc05e77c1 100644 (file)
@@ -851,6 +851,26 @@ nodlit(Val v)
        return n;
 }
 
+Node*
+nodcplxlit(Val r, Val i)
+{
+       Node *n;
+       Mpcplx *c;
+
+       c = mal(sizeof(*c));
+       n = nod(OLITERAL, N, N);
+       n->type = types[TIDEAL];
+       n->val.u.cval = c;
+       n->val.ctype = CTCPLX;
+
+       if(r.ctype != CTFLT || i.ctype != CTFLT)
+               fatal("nodcplxlit ctype %d/%d", r.ctype, i.ctype);
+
+       mpmovefltflt(&c->real, r.u.fval);
+       mpmovefltflt(&c->imag, i.u.fval);
+       return n;
+}
+
 // TODO(rsc): combine with convlit
 void
 defaultlit(Node **np, Type *t)
index ec1c135d82ef90ecf3ce0c7ee1d86189927e82df..d11ddf2ea86bcc9fefe66a47dc9d2c1d5e1c2f4d 100644 (file)
@@ -133,6 +133,9 @@ dumpexportconst(Sym *s)
        case CTFLT:
                Bprint(bout, "%F\n", n->val.u.fval);
                break;
+       case CTCPLX:
+               Bprint(bout, "(%F+%F)\n", &n->val.u.cval->real, &n->val.u.cval->imag);
+               break;
        case CTSTR:
                Bprint(bout, "\"%Z\"\n", n->val.u.sval);
                break;
index 642b706111042a674f61b27320a5ffb9bcc93a65..753de0399a2fa4391b5ffc0d581dc2d9376b796b 100644 (file)
@@ -851,6 +851,7 @@ void        linehist(char*, int32, int);
 int32  setlineno(Node*);
 Node*  nod(int, Node*, Node*);
 Node*  nodlit(Val);
+Node*  nodcplxlit(Val, Val);
 Type*  typ(int);
 int    algtype(Type*);
 void   dodump(Node*, int);
index f2a037710bcd53f41114110a4b259ac25ccb36c0..06696d52fcd63d3049351bdade77a60700a961c5 100644 (file)
@@ -76,7 +76,8 @@
 
 %type  <sym>   hidden_importsym hidden_pkg_importsym
 
-%type  <node>  hidden_constant hidden_dcl hidden_interfacedcl hidden_structdcl hidden_opt_sym
+%type  <node>  hidden_constant hidden_literal hidden_dcl
+%type  <node>  hidden_interfacedcl hidden_structdcl hidden_opt_sym
 
 %type  <list>  hidden_funres
 %type  <list>  ohidden_funres
@@ -1743,7 +1744,7 @@ hidden_funres:
                $$ = list1(nod(ODCLFIELD, N, typenod($1)));
        }
 
-hidden_constant:
+hidden_literal:
        LLITERAL
        {
                $$ = nodlit($1);
@@ -1769,6 +1770,13 @@ hidden_constant:
                        yyerror("bad constant %S", $$->sym);
        }
 
+hidden_constant:
+       hidden_literal
+|      '(' hidden_literal '+' hidden_literal ')'
+       {
+               $$ = nodcplxlit($2->val, $4->val);
+       }
+
 hidden_importsym:
        LLITERAL '.' sym
        {
index a6b420eb66cad1d9a816bf1381a96aa346f98a59..e528e3f6c000319b26591f0a0f7961868261fcbc 100644 (file)
@@ -1724,6 +1724,12 @@ walkprint(Node *nn, NodeList **init, int defer)
                                t = types[TFLOAT64];
                        } else
                                on = syslook("printfloat", 0);
+               } else if(iscomplex[et]) {
+                       if(defer) {
+                               fmtprint(&fmt, "%%f");
+                               t = types[TFLOAT64];
+                       } else
+                               on = syslook("printcomplex", 0);
                } else if(et == TBOOL) {
                        if(defer)
                                fmtprint(&fmt, "%%t");
index 7227904acd729924961e011f42d8d494572af560..c37447718fffbb991a6051d44bad0081a428caac 100644 (file)
@@ -102,7 +102,7 @@ type FloatType commonType
 // Complex64Type represents a complex64 type.
 type Complex64Type commonType
 
-// Complex128Type represents a complex32 type.
+// Complex128Type represents a complex128 type.
 type Complex128Type commonType
 
 // ComplexType represents a complex type.