Commit 85303f27 authored by Robert Griesemer's avatar Robert Griesemer

- moved struct Compilation into globals.go, adjusted deps

- bail out after > 10 errors
- fixed send/recv statements

SVN=127890
parent 9e2d1850
...@@ -13,47 +13,6 @@ import Parser "parser" ...@@ -13,47 +13,6 @@ import Parser "parser"
import Export "export" 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 { func BaseName(s string) string {
// TODO this is not correct for non-ASCII strings! // TODO this is not correct for non-ASCII strings!
i := len(s); i := len(s);
...@@ -76,12 +35,12 @@ func FixExt(s string) string { ...@@ -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"; panic "UNIMPLEMENTED";
} }
func (C *Compilation) Export() { func Export(C *Globals.Compilation) {
file_name := FixExt(BaseName(C.src_name)); // strip src dir file_name := FixExt(BaseName(C.src_name)); // strip src dir
Export.Export(file_name/*, C */); Export.Export(file_name/*, C */);
} }
...@@ -89,7 +48,7 @@ func (C *Compilation) Export() { ...@@ -89,7 +48,7 @@ func (C *Compilation) Export() {
export Compile export Compile
func Compile(src_name string, verbose int) { func Compile(src_name string, verbose int) {
comp := new(Compilation); comp := new(Globals.Compilation);
comp.src_name = src_name; comp.src_name = src_name;
comp.pkg = nil; comp.pkg = nil;
comp.nimports = 0; comp.nimports = 0;
......
...@@ -6,9 +6,9 @@ package Globals ...@@ -6,9 +6,9 @@ package Globals
// The following types should really be in their respective files // The following types should really be in their respective files
// (object.go, type.go, scope.go, package.go) but they refer to each // (object.go, type.go, scope.go, package.go, compilation.go) but
// other and we don't know how to handle forward-declared pointers // they refer to each other and we don't know how to handle forward
// across packages yet. // declared pointers across packages yet.
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
...@@ -75,6 +75,15 @@ type Package struct { ...@@ -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 // Creation
...@@ -226,3 +235,38 @@ func (scope *Scope) Print() { ...@@ -226,3 +235,38 @@ func (scope *Scope) Print() {
} }
print "\n}\n"; 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;
}
...@@ -1004,8 +1004,8 @@ func (P *Parser) TryStatement() bool { ...@@ -1004,8 +1004,8 @@ func (P *Parser) TryStatement() bool {
case Scanner.FUNC: case Scanner.FUNC:
// for now we do not allow local function declarations // for now we do not allow local function declarations
fallthrough; fallthrough;
case Scanner.LSS: fallthrough; case Scanner.SEND: fallthrough;
case Scanner.GTR: case Scanner.RECV:
P.ParseSimpleStat(); // send or receive P.ParseSimpleStat(); // send or receive
case Scanner.IDENT: case Scanner.IDENT:
switch P.ident { switch P.ident {
......
...@@ -425,6 +425,10 @@ func (S *Scanner) Error(pos int, msg string) { ...@@ -425,6 +425,10 @@ func (S *Scanner) Error(pos int, msg string) {
S.nerrors++; S.nerrors++;
S.errpos = pos; S.errpos = pos;
} }
if S.nerrors >= 10 {
sys.exit(1);
}
} }
......
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