]> Cypherpunks repositories - gostls13.git/commitdiff
- moved struct Compilation into globals.go, adjusted deps
authorRobert Griesemer <gri@golang.org>
Thu, 17 Jul 2008 22:11:46 +0000 (15:11 -0700)
committerRobert Griesemer <gri@golang.org>
Thu, 17 Jul 2008 22:11:46 +0000 (15:11 -0700)
- bail out after > 10 errors
- fixed send/recv statements

SVN=127890

usr/gri/gosrc/compilation.go
usr/gri/gosrc/globals.go
usr/gri/gosrc/parser.go
usr/gri/gosrc/scanner.go

index 3e602b9e40c454cd3843a570f90faa633e76b882..062c963e06dddc3c4bb7f3b06692cd00bb738851 100644 (file)
@@ -13,47 +13,6 @@ import Parser "parser"
 import Export "export"
 
 
-export Compilation
-type Compilation struct {
-  src_name string;
-  pkg *Globals.Object;
-  imports [256] *Globals.Package;  // TODO need open arrays
-  nimports int;
-}
-
-
-func (C *Compilation) Lookup(file_name string) *Globals.Package {
-       for i := 0; i < C.nimports; i++ {
-               pkg := C.imports[i];
-               if pkg.file_name == file_name {
-                       return pkg;
-               }
-       }
-       return nil;
-}
-
-
-func (C *Compilation) Insert(pkg *Globals.Package) {
-       if C.Lookup(pkg.file_name) != nil {
-               panic "package already inserted";
-       }
-       pkg.pno = C.nimports;
-       C.imports[C.nimports] = pkg;
-       C.nimports++;
-}
-
-
-func (C *Compilation) InsertImport(pkg *Globals.Package) *Globals.Package {
-       p := C.Lookup(pkg.file_name);
-       if (p == nil) {
-               // no primary package found
-               C.Insert(pkg);
-               p = pkg;
-       }
-       return p;
-}
-
-
 func BaseName(s string) string {
        // TODO this is not correct for non-ASCII strings!
        i := len(s);
@@ -76,12 +35,12 @@ func FixExt(s string) string {
 }
 
 
-func (C *Compilation) Import(pkg_name string) (pno int) {
+func Import(C *Globals.Compilation, pkg_name string) (pno int) {
        panic "UNIMPLEMENTED";
 }
 
 
-func (C *Compilation) Export() {
+func Export(C *Globals.Compilation) {
        file_name := FixExt(BaseName(C.src_name));  // strip src dir
        Export.Export(file_name/*, C */);
 }
@@ -89,7 +48,7 @@ func (C *Compilation) Export() {
 
 export Compile
 func Compile(src_name string, verbose int) {
-       comp := new(Compilation);
+       comp := new(Globals.Compilation);
        comp.src_name = src_name;
        comp.pkg = nil;
        comp.nimports = 0;
index 83d3a8fb3f969c42101af31d84764e9d2cab631f..c86289b7adacfa4c848055af9861648380e3a60e 100644 (file)
@@ -6,9 +6,9 @@ package Globals
 
 
 // The following types should really be in their respective files
-// (object.go, type.go, scope.go, package.go) but they refer to each
-// other and we don't know how to handle forward-declared pointers
-// across packages yet.
+// (object.go, type.go, scope.go, package.go, compilation.go) but
+// they refer to each other and we don't know how to handle forward
+// declared pointers across packages yet.
 
 
 // ----------------------------------------------------------------------------
@@ -75,6 +75,15 @@ type Package struct {
 }
 
 
+export Compilation
+type Compilation struct {
+  src_name string;
+  pkg *Object;
+  imports [256] *Package;  // TODO need open arrays
+  nimports int;
+}
+
+
 // ----------------------------------------------------------------------------
 // Creation
 
@@ -226,3 +235,38 @@ func (scope *Scope) Print() {
        }
        print "\n}\n";
 }
+
+
+// ----------------------------------------------------------------------------
+// Compilation methods
+
+func (C *Compilation) Lookup(file_name string) *Package {
+       for i := 0; i < C.nimports; i++ {
+               pkg := C.imports[i];
+               if pkg.file_name == file_name {
+                       return pkg;
+               }
+       }
+       return nil;
+}
+
+
+func (C *Compilation) Insert(pkg *Package) {
+       if C.Lookup(pkg.file_name) != nil {
+               panic "package already inserted";
+       }
+       pkg.pno = C.nimports;
+       C.imports[C.nimports] = pkg;
+       C.nimports++;
+}
+
+
+func (C *Compilation) InsertImport(pkg *Package) *Package {
+       p := C.Lookup(pkg.file_name);
+       if (p == nil) {
+               // no primary package found
+               C.Insert(pkg);
+               p = pkg;
+       }
+       return p;
+}
index f93567a2c63cca34f7bdf668fec1a7d6848cfdde..e99279ba4af29d742105d3b72cbca08afd367db1 100644 (file)
@@ -1004,8 +1004,8 @@ func (P *Parser) TryStatement() bool {
        case Scanner.FUNC:
                // for now we do not allow local function declarations
                fallthrough;
-       case Scanner.LSS: fallthrough;
-       case Scanner.GTR:
+       case Scanner.SEND: fallthrough;
+       case Scanner.RECV:
                P.ParseSimpleStat();  // send or receive
        case Scanner.IDENT:
                switch P.ident {
index a5c63e20f949997451d6c9daabde77c3c75c8a74..5ef8081da6199f0e035693d4add9a47fabcb0cb1 100644 (file)
@@ -425,6 +425,10 @@ func (S *Scanner) Error(pos int, msg string) {
                S.nerrors++;
                S.errpos = pos;
        }
+       
+       if S.nerrors >= 10 {
+               sys.exit(1);
+       }
 }