]> Cypherpunks repositories - gostls13.git/commitdiff
foundation for import unsafe
authorKen Thompson <ken@golang.org>
Tue, 9 Dec 2008 03:46:39 +0000 (19:46 -0800)
committerKen Thompson <ken@golang.org>
Tue, 9 Dec 2008 03:46:39 +0000 (19:46 -0800)
R=r
OCL=20794
CL=20794

src/cmd/6g/align.c
src/cmd/gc/Makefile
src/cmd/gc/go.h
src/cmd/gc/go.y
src/cmd/gc/lex.c
src/cmd/gc/mksys.c
src/cmd/gc/sys.go
src/cmd/gc/sysimport.c
src/cmd/gc/unsafe.go [new file with mode: 0644]

index 209c0765b1f85236bf23b3d5f9d0a313afe900c6..aaf2fabfa062fa2026a8140a06725dea3b278474 100644 (file)
@@ -203,7 +203,7 @@ typedefs[] =
 {
        "int",          TINT,           TINT32,
        "uint",         TUINT,          TUINT32,
-       "uptrint",      TUINTPTR,       TUINT64,
+       "uintptr",      TUINTPTR,       TUINT64,
        "float",        TFLOAT,         TFLOAT32,
 };
 
index 502f37146d00d22ee4c72c5740f8ca1fbb7d1334..744460bd8a33dd7ec751c1f8f2b470e8d1febd84 100644 (file)
@@ -39,10 +39,13 @@ y.tab.h: $(YFILES)
 y.tab.c: y.tab.h
        test -f y.tab.c && touch y.tab.c
 
-sysimport.c:   sys.go mksys.c
+sysimport.c:   sys.go unsafe.go mksys.c
        gcc -o mksys mksys.c
        6g sys.go
-       ./mksys sys.6 >_sysimport.c && mv _sysimport.c sysimport.c
+       6g unsafe.go
+       ./mksys sys >_sysimport.c &&\
+               ./mksys unsafe >>_sysimport.c &&\
+               mv _sysimport.c sysimport.c
 
 clean:
        rm -f $(OFILES) *.6 enam.c 6.out a.out y.tab.h y.tab.c $(LIB) _sysimport.c
index 68898c998845cc2290737c1b4eaa600ca6bf8d8c..dc6de63c6c6579a74067655c7766795e5c0dc594 100644 (file)
@@ -467,6 +467,7 @@ EXTERN      Sym*    pkgmyname;      // my name for package
 EXTERN Sym*    pkgimportname;  // package name from imported package
 EXTERN int     tptr;           // either TPTR32 or TPTR64
 extern char*   sysimport;
+extern char*   unsafeimport;
 EXTERN char*   filename;       // name to uniqify names
 EXTERN void    (*dcladj)(Sym*);        // declaration is being exported/packaged
 
@@ -535,7 +536,7 @@ int yyparse(void);
 int    mainlex(int, char*[]);
 void   setfilename(char*);
 void   importfile(Val*);
-void   cannedimports(void);
+void   cannedimports(char*, char*);
 void   unimportfile();
 int32  yylex(void);
 void   lexinit(void);
index bcee5ec5b3859e4448a8eb545fce604127ff71a2..f504595cb75b771de8d5106f5f31afbf181d06f7 100644 (file)
@@ -104,12 +104,12 @@ package:
        {
                yyerror("package statement must be first");
                mkpackage("main");
-               cannedimports();
+               cannedimports("sys.6", sysimport);
        }
 |      LPACKAGE sym
        {
                mkpackage($2->name);
-               cannedimports();
+               cannedimports("sys.6", sysimport);
        }
 
 imports:
@@ -1086,6 +1086,8 @@ Bnon_fn_type:
 nametype:
        LATYPE
        {
+               if($1->otype != T && $1->otype->etype == TANY)
+                       yyerror("the any type is restricted");
                $$ = oldtype($1);
        }
 
index 126a201d6f16b110cbf895bae18792db3c35df98..dc2ec6166a17b1ba5003271a7c48af3d640c545f 100644 (file)
@@ -218,6 +218,11 @@ importfile(Val *f)
                return;
        }
 
+       if(strcmp(f->u.sval->s, "unsafe") == 0) {
+               cannedimports("unsafe.6", unsafeimport);
+               return;
+       }
+
        if(!findpkg(f->u.sval))
                fatal("can't find import: %Z", f->u.sval);
        imp = Bopen(namebuf, OREAD);
@@ -277,11 +282,8 @@ unimportfile(void)
 }
 
 void
-cannedimports(void)
+cannedimports(char *file, char *cp)
 {
-       char *file;
-
-       file = "sys.6";
        lineno++;               // if sys.6 is included on line 1,
        linehist(file, 0);      // the debugger gets confused
 
@@ -290,7 +292,7 @@ cannedimports(void)
        curio.peekc = 0;
        curio.peekc1 = 0;
        curio.infile = file;
-       curio.cp = sysimport;
+       curio.cp = cp;
 
        pkgmyname = S;
        inimportsys = 1;
index cf0537c31890ab9d8aa149f43b568cb1c92adfe5..a3838203fd52c8708915c968261c3731d5183d33 100644 (file)
 int
 main(int argc, char **argv)
 {
+       char *name;
        FILE *fin;
-       char buf[1024], *p, *q;
+       char buf[1024], initfunc[1024], *p, *q;
 
        if(argc != 2) {
-               fprintf(stderr, "usage: mksys sys.6\n");
+               fprintf(stderr, "usage: sys sys\n");
+               fprintf(stderr, "in file $1.6 s/PACKAGE/$1/\n");
                exit(1);
        }
-       if((fin = fopen(argv[1], "r")) == NULL) {
-               fprintf(stderr, "open %s: %s\n", argv[1], strerror(errno));
+
+       name = argv[1];
+       snprintf(initfunc, sizeof(initfunc), "init_%s_function", name);
+
+       snprintf(buf, sizeof(buf), "%s.6", name);
+       if((fin = fopen(buf, "r")) == NULL) {
+               fprintf(stderr, "open %s: %s\n", buf, strerror(errno));
                exit(1);
        }
 
@@ -33,7 +40,7 @@ main(int argc, char **argv)
        exit(1);
 
 begin:
-       printf("char *sysimport = \n");
+       printf("char *%simport = \n", name);
 
        // process imports, stopping at $$ that closes them
        while(fgets(buf, sizeof buf, fin) != NULL) {
@@ -45,17 +52,21 @@ begin:
                for(p=buf; *p==' ' || *p == '\t'; p++)
                        ;
 
-               // cut out decl of init_sys_function - it doesn't exist
-               if(strstr(buf, "init_sys_function"))
+               // cut out decl of init_$1_function - it doesn't exist
+               if(strstr(buf, initfunc))
                        continue;
 
-               // sys.go claims to be in package SYS to avoid
-               // conflicts during "6g sys.go".  rename SYS to sys.
-               for(q=p; *q; q++)
-                       if(memcmp(q, "SYS", 3) == 0)
-                               memmove(q, "sys", 3);
+               // sys.go claims to be in package PACKAGE to avoid
+               // conflicts during "6g sys.go".  rename PACKAGE to $2.
+               printf("\t\"");
+               while(q = strstr(p, "PACKAGE")) {
+                       *q = 0;
+                       printf("%s", p);        // up to the substitution
+                       printf("%s", name);     // the sub name
+                       p = q+7;                // continue with rest
+               }
 
-               printf("\t\"%s\\n\"\n", p);
+               printf("%s\\n\"\n", p);
        }
        fprintf(stderr, "did not find end of imports\n");
        exit(1);
index bc91beb043ca4d176e87f00497244b0814ccd9b6..41a702c74dc77626c356774e107e011df7a2b979 100644 (file)
@@ -3,7 +3,7 @@
 // license that can be found in the LICENSE file.
 
 
-package SYS    // rename to avoid redeclaration errors
+package PACKAGE
 
 export func    mal(int32) *any;
 export func    breakpoint();
index 56b6b8aca6378a50a45d2ad98ebf469b8dbf9e14..aa40e773f0e8f34ac4cf447dd0012dbc0339a326 100644 (file)
@@ -79,3 +79,8 @@ char *sysimport =
        "export func sys.semrelease (sema *int32)\n"
        "\n"
        "$$\n";
+char *unsafeimport = 
+       "package unsafe\n"
+       "export type unsafe.pointer *any\n"
+       "\n"
+       "$$\n";
diff --git a/src/cmd/gc/unsafe.go b/src/cmd/gc/unsafe.go
new file mode 100644 (file)
index 0000000..ba6aa7c
--- /dev/null
@@ -0,0 +1,8 @@
+// Copyright 2009 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+
+package PACKAGE
+
+export type    pointer *any;