diff --git a/usr/gri/gosrc/compilation.go b/usr/gri/gosrc/compilation.go index c520d00fe1c..9a76ae1f171 100644 --- a/usr/gri/gosrc/compilation.go +++ b/usr/gri/gosrc/compilation.go @@ -7,6 +7,7 @@ package Compilation import Globals "globals" import Object "object" import Type "type" +import Universe "universe" import Package "package" import Scanner "scanner" import Parser "parser" @@ -16,7 +17,8 @@ export Compilation type Compilation struct { src_name string; pkg *Globals.Object; - imports *Globals.List; // a list of *Globals.Package + imports [256] *Package.Package; // TODO need open arrays + nimports int; } @@ -48,5 +50,26 @@ func (C *Compilation) Export() { export Compile -func Compile() { +func Compile(src_name string, verbose int) { + comp := new(Compilation); + comp.src_name = src_name; + comp.pkg = nil; + comp.nimports = 0; + + src, ok := sys.readfile(src_name); + if !ok { + print "cannot open ", src_name, "\n" + return; + } + + Universe.Init(); + + S := new(Scanner.Scanner); + S.Open(src_name, src); + + P := new(Parser.Parser); + P.Open(S, verbose); + + print "parsing ", src_name, "\n"; + P.ParseProgram(); } diff --git a/usr/gri/gosrc/globals.go b/usr/gri/gosrc/globals.go index 1518fc1ad97..3fd0981ebf6 100644 --- a/usr/gri/gosrc/globals.go +++ b/usr/gri/gosrc/globals.go @@ -60,7 +60,7 @@ export Scope type Scope struct { parent *Scope; entries *List; - // entries *map[string] *Object; // doesn't work yet + // entries *map[string] *Object; // doesn't work properly } diff --git a/usr/gri/gosrc/go.go b/usr/gri/gosrc/go.go index 70fb1765f36..b9704e0ab24 100644 --- a/usr/gri/gosrc/go.go +++ b/usr/gri/gosrc/go.go @@ -5,12 +5,7 @@ package main import Build "build" -import Globals "globals" -import Object "object" -import Type "type" -import Universe "universe" -import Scanner "scanner" -import Parser "parser" +import Compilation "compilation" func PrintHelp() { @@ -26,19 +21,6 @@ func PrintHelp() { } -func Compile(filename, src string, verbose int) { - Universe.Init(); - - S := new(Scanner.Scanner); - S.Open(filename, src); - - P := new(Parser.Parser); - P.Open(S, verbose); - - P.ParseProgram(); -} - - func main() { if sys.argc() <= 1 { PrintHelp(); @@ -56,12 +38,6 @@ func main() { continue; } - src, ok := sys.readfile(sys.argv(i)); - if ok { - print "parsing " + sys.argv(i) + "\n"; - Compile(sys.argv(i), src, verbose); - } else { - print "error: cannot read " + sys.argv(i) + "\n"; - } + Compilation.Compile(sys.argv(i), verbose); } }