Commit 7a799be4 authored by Robert Griesemer's avatar Robert Griesemer

- switch to new export syntax

- deprecate old syntax in this front-end (use -6g for compatibility)

R=r
OCL=13831
CL=13833
parent 4f6ba4c8
...@@ -11,8 +11,7 @@ import Universe "universe" ...@@ -11,8 +11,7 @@ import Universe "universe"
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Expressions // Expressions
export BinaryExpr export type BinaryExpr struct {
type BinaryExpr struct {
typ_ *Globals.Type; typ_ *Globals.Type;
op int; op int;
x, y Globals.Expr; x, y Globals.Expr;
...@@ -28,14 +27,12 @@ func (x *BinaryExpr) typ() *Globals.Type { ...@@ -28,14 +27,12 @@ func (x *BinaryExpr) typ() *Globals.Type {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Statements // Statements
export Block export type Block struct {
type Block struct {
// TODO fill in // TODO fill in
} }
export IfStat export type IfStat struct {
type IfStat struct {
cond Globals.Expr; cond Globals.Expr;
then_ Globals.Stat; then_ Globals.Stat;
else_ Globals.Stat; else_ Globals.Stat;
......
...@@ -6,14 +6,12 @@ ...@@ -6,14 +6,12 @@
package base package base
type Foo int export type Foo int
type Bar *float; export type Bar *float;
type Node struct { export type Node struct {
left, right *Node; left, right *Node;
val bool; val bool;
f Foo f Foo
} }
export Foo, Bar, Node
...@@ -17,8 +17,7 @@ import Printer "printer" ...@@ -17,8 +17,7 @@ import Printer "printer"
import Verifier "verifier" import Verifier "verifier"
export Compile export func Compile(comp *Globals.Compilation, file_name string) {
func Compile(comp *Globals.Compilation, file_name string) {
src, ok := sys.readfile(file_name); src, ok := sys.readfile(file_name);
if !ok { if !ok {
print "cannot open ", file_name, "\n" print "cannot open ", file_name, "\n"
......
...@@ -9,28 +9,32 @@ package decls ...@@ -9,28 +9,32 @@ package decls
import "base" import "base"
import base2 "base" import base2 "base"
const c0 int = 0 export const c0 int = 0
const c1 float = 1. export const c1 float = 1.
const ( const (
c2 byte = 2; c2 byte = 2;
c3 int = 3; c3 int = 3;
c4 float = 4.; c4 float = 4.;
) )
type Node0 base.Node export type (
type Node1 *base2.Node Node0 base.Node
Node1 *base2.Node
)
type T0 byte export type T0 byte
type T1 T0 export type T1 T0
type (
T2 [10]T0;
T3 map [string] int;
)
export type T4 struct {
f1, f2, f3 int;
f4 [] float;
};
type ( type (
T2 [10]T0; T5 *T4;
T3 map [string] int;
T4 struct {
f1, f2, f3 int;
f4 [] float;
};
T5 *T4;
) )
type F0 func () type F0 func ()
...@@ -42,67 +46,67 @@ type F5 func (a, b int, c float) (z T5, ok bool) ...@@ -42,67 +46,67 @@ type F5 func (a, b int, c float) (z T5, ok bool)
type F6 func (a int, b float) bool type F6 func (a int, b float) bool
type F7 func (a int, b float, c, d *bool) bool type F7 func (a int, b float, c, d *bool) bool
export type M0 func (p T5) . ();
type ( type (
M0 func (p T5) . (); M1 func (p T5) . (a int);
M1 func (p T5) . (a int); M2 func (p T5) . (a, b int, c float);
M2 func (p T5) . (a, b int, c float); M3 func (p T5) . () bool;
M3 func (p T5) . () bool; M4 func (p T5) . (a int) (z T5, ok bool);
M4 func (p T5) . (a int) (z T5, ok bool);
M5 func (p T5) . (a, b int, c float) (z T5, ok bool);
) )
export type M5 func (p T5) . (a, b int, c float) (z T5, ok bool);
type T6 chan int type T6 chan int
type T7 chan<- *T6 type T7 chan<- *T6
type T8 chan-< *T6 type T8 chan-< *T6
type T9 struct { type T9 struct {
p *T9; p *T9;
q [] *map [int] *T9; q [] *map [int] *T9;
f *func(x, y *T9) *T9; f *func(x, y *T9) *T9;
} }
type T10; type T10;
type T11 struct { type T11 struct {
p *T10; p *T10;
} }
type T10 struct { type T10 struct {
p *T11; p *T11;
} }
type T12 struct { type T12 struct {
p *T12 p *T12
} }
type I0 interface {} type I0 interface {}
type I1 interface { type I1 interface {
Do0(q *I0); Do0(q *I0);
Do1(p *I1) bool; Do1(p *I1) bool;
} }
type I2 interface { export type I2 interface {
M0(); M0();
M1(a int); M1(a int);
M2(a, b int, c float); M2(a, b int, c float);
M3() bool; M3() bool;
M4(a int) (z T5, ok bool); M4(a int) (z T5, ok bool);
M5(a, b int, c float) (z T5, ok bool); M5(a, b int, c float) (z T5, ok bool);
} }
var v0 int var v0 int
var v1 float = c1 var v1 float = c1
var ( export var (
v2 T2; v2 T2;
v3 struct { v3 struct {
f1, f2, f3 *M0; f1, f2, f3 *M0;
} }
) )
func f0() {} export func f0() {}
func f1(a int) {} export func f1(a int) {}
func f2(a, b int, c float) {} func f2(a, b int, c float) {}
func f3() bool { return false; } func f3() bool { return false; }
func f4(a int) (z T5, ok bool) {} func f4(a int) (z T5, ok bool) {}
...@@ -118,9 +122,5 @@ func (p *T4) m2(a, b int, c float) {} ...@@ -118,9 +122,5 @@ func (p *T4) m2(a, b int, c float) {}
func (p *T4) m3() bool { return false; } func (p *T4) m3() bool { return false; }
func (p *T4) m4(a int) (z T5, ok bool) { return; } func (p *T4) m4(a int) (z T5, ok bool) { return; }
func (p *T4) m5(a, b int, c float) (z T5, ok bool) { func (p *T4) m5(a, b int, c float) (z T5, ok bool) {
L: var x = a; L: var x = a;
} }
export c0, c1, v2, v3
export T0, T1, T4, T4, T4, M0, M5, I2, f0, f1
export Node0, Node1
...@@ -282,8 +282,7 @@ func (E *Exporter) Export(comp* Globals.Compilation, file_name string) { ...@@ -282,8 +282,7 @@ func (E *Exporter) Export(comp* Globals.Compilation, file_name string) {
} }
export Export export func Export(comp* Globals.Compilation, pkg_name string) {
func Export(comp* Globals.Compilation, pkg_name string) {
var E Exporter; var E Exporter;
(&E).Export(comp, Utils.FixExt(Utils.BaseName(pkg_name))); (&E).Export(comp, Utils.FixExt(Utils.BaseName(pkg_name)));
} }
...@@ -103,8 +103,7 @@ export type Stat interface { ...@@ -103,8 +103,7 @@ export type Stat interface {
export var Universe_undef_t *Type // initialized by Universe to Universe.undef_t export var Universe_undef_t *Type // initialized by Universe to Universe.undef_t
export NewObject export func NewObject(pos, kind int, ident string) *Object {
func NewObject(pos, kind int, ident string) *Object {
obj := new(Object); obj := new(Object);
obj.exported = false; obj.exported = false;
obj.pos = pos; obj.pos = pos;
...@@ -116,8 +115,7 @@ func NewObject(pos, kind int, ident string) *Object { ...@@ -116,8 +115,7 @@ func NewObject(pos, kind int, ident string) *Object {
} }
export NewType export func NewType(form int) *Type {
func NewType(form int) *Type {
typ := new(Type); typ := new(Type);
typ.ref = -1; // not yet exported typ.ref = -1; // not yet exported
typ.form = form; typ.form = form;
...@@ -125,8 +123,7 @@ func NewType(form int) *Type { ...@@ -125,8 +123,7 @@ func NewType(form int) *Type {
} }
export NewPackage; export func NewPackage(file_name string, obj *Object, scope *Scope) *Package {
func NewPackage(file_name string, obj *Object, scope *Scope) *Package {
pkg := new(Package); pkg := new(Package);
pkg.ref = -1; // not yet exported pkg.ref = -1; // not yet exported
pkg.file_name = file_name; pkg.file_name = file_name;
...@@ -137,14 +134,12 @@ func NewPackage(file_name string, obj *Object, scope *Scope) *Package { ...@@ -137,14 +134,12 @@ func NewPackage(file_name string, obj *Object, scope *Scope) *Package {
} }
export NewList export func NewList() *List {
func NewList() *List {
return new(List); return new(List);
} }
export NewScope export func NewScope(parent *Scope) *Scope {
func NewScope(parent *Scope) *Scope {
scope := new(Scope); scope := new(Scope);
scope.parent = parent; scope.parent = parent;
scope.entries = NewList(); scope.entries = NewList();
...@@ -152,8 +147,7 @@ func NewScope(parent *Scope) *Scope { ...@@ -152,8 +147,7 @@ func NewScope(parent *Scope) *Scope {
} }
export NewCompilation; export func NewCompilation(flags *Flags) *Compilation {
func NewCompilation(flags *Flags) *Compilation {
comp := new(Compilation); comp := new(Compilation);
comp.flags = flags; comp.flags = flags;
return comp; return comp;
......
...@@ -306,8 +306,7 @@ func (I *Importer) Import(comp* Globals.Compilation, file_name string) *Globals. ...@@ -306,8 +306,7 @@ func (I *Importer) Import(comp* Globals.Compilation, file_name string) *Globals.
} }
export Import export func Import(comp* Globals.Compilation, pkg_name string) *Globals.Package {
func Import(comp* Globals.Compilation, pkg_name string) *Globals.Package {
var I Importer; var I Importer;
return (&I).Import(comp, Utils.FixExt(pkg_name)); return (&I).Import(comp, Utils.FixExt(pkg_name));
} }
...@@ -19,8 +19,7 @@ export const /* kind */ ( ...@@ -19,8 +19,7 @@ export const /* kind */ (
// globals.go. // globals.go.
export KindStr export func KindStr(kind int) string {
func KindStr(kind int) string {
switch kind { switch kind {
case BAD: return "BAD"; case BAD: return "BAD";
case CONST: return "CONST"; case CONST: return "CONST";
......
...@@ -14,8 +14,7 @@ import Import "import" ...@@ -14,8 +14,7 @@ import Import "import"
import AST "ast" import AST "ast"
export Parser export type Parser struct {
type Parser struct {
comp *Globals.Compilation; comp *Globals.Compilation;
semantic_checks bool; semantic_checks bool;
verbose, indent int; verbose, indent int;
...@@ -1796,9 +1795,14 @@ func (P *Parser) ParseFuncDecl(exported bool) { ...@@ -1796,9 +1795,14 @@ func (P *Parser) ParseFuncDecl(exported bool) {
func (P *Parser) ParseExportDecl() { func (P *Parser) ParseExportDecl() {
P.Trace("ExportDecl"); P.Trace("ExportDecl");
// TODO this needs to be clarified - the current syntax is // TODO This is deprecated syntax and should go away eventually.
// "everything goes" - sigh... // (Also at the moment the syntax is everything goes...)
//P.Expect(Scanner.EXPORT); //P.Expect(Scanner.EXPORT);
if !P.comp.flags.sixg {
P.Error(P.pos, "deprecated export syntax (use -6g to enable)");
}
has_paren := false; has_paren := false;
if P.tok == Scanner.LPAREN { if P.tok == Scanner.LPAREN {
P.Next(); P.Next();
......
...@@ -259,8 +259,7 @@ func (P *Printer) PrintType(typ *Globals.Type) { ...@@ -259,8 +259,7 @@ func (P *Printer) PrintType(typ *Globals.Type) {
} }
export PrintObject export func PrintObject(comp *Globals.Compilation, obj *Globals.Object, print_all bool) {
func PrintObject(comp *Globals.Compilation, obj *Globals.Object, print_all bool) {
var P Printer; var P Printer;
(&P).Init(comp, print_all); (&P).Init(comp, print_all);
(&P).PrintObjectStruct(obj); (&P).PrintObjectStruct(obj);
......
...@@ -111,8 +111,7 @@ var Keywords *map [string] int; ...@@ -111,8 +111,7 @@ var Keywords *map [string] int;
var VerboseMsgs bool; // error message customization var VerboseMsgs bool; // error message customization
export TokenName export func TokenName(tok int) string {
func TokenName(tok int) string {
switch (tok) { switch (tok) {
case ILLEGAL: return "illegal"; case ILLEGAL: return "illegal";
case EOF: return "eof"; case EOF: return "eof";
......
...@@ -27,8 +27,7 @@ export const /* flag */ ( ...@@ -27,8 +27,7 @@ export const /* flag */ (
// globals.go. // globals.go.
export FormStr export func FormStr(form int) string {
func FormStr(form int) string {
switch form { switch form {
case UNDEF: return "UNDEF"; case UNDEF: return "UNDEF";
case BAD: return "BAD"; case BAD: return "BAD";
......
...@@ -9,24 +9,7 @@ import Object "object" ...@@ -9,24 +9,7 @@ import Object "object"
import Type "type" import Type "type"
export export var (
scope,
types,
undef_t, bad_t, nil_t,
bool_t,
uint8_t, uint16_t, uint32_t, uint64_t,
int8_t, int16_t, int32_t, int64_t,
float32_t, float64_t, float80_t,
string_t, any_t,
byte_t,
ushort_t, uint_t, ulong_t,
short_t, int_t, long_t,
float_t, double_t,
ptrint_t,
true_, false_
var (
scope *Globals.Scope; scope *Globals.Scope;
types *Globals.List; types *Globals.List;
......
...@@ -5,8 +5,7 @@ ...@@ -5,8 +5,7 @@
package Utils package Utils
export BaseName export 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) - 1; i := len(s) - 1;
for i >= 0 && s[i] != '/' { for i >= 0 && s[i] != '/' {
...@@ -19,8 +18,7 @@ func BaseName(s string) string { ...@@ -19,8 +18,7 @@ func BaseName(s string) string {
} }
export FixExt export func FixExt(s string) string {
func FixExt(s string) string {
i := len(s) - 3; // 3 == len(".go"); i := len(s) - 3; // 3 == len(".go");
if i >= 0 && s[i : len(s)] == ".go" { if i >= 0 && s[i : len(s)] == ".go" {
s = s[0 : i]; s = s[0 : i];
...@@ -29,8 +27,7 @@ func FixExt(s string) string { ...@@ -29,8 +27,7 @@ func FixExt(s string) string {
} }
export GetEnv export func GetEnv(key string) string {
func GetEnv(key string) string {
n := len(key); n := len(key);
for i := 0; i < sys.envc(); i++ { for i := 0; i < sys.envc(); i++ {
v := sys.envv(i); v := sys.envv(i);
......
...@@ -104,8 +104,7 @@ func VerifyPackage(pkg *Globals.Package, pno int) { ...@@ -104,8 +104,7 @@ func VerifyPackage(pkg *Globals.Package, pno int) {
} }
export Verify export func Verify(comp *Globals.Compilation) {
func Verify(comp *Globals.Compilation) {
for i := 0; i < comp.pkg_ref; i++ { for i := 0; i < comp.pkg_ref; i++ {
VerifyPackage(comp.pkg_list[i], i); VerifyPackage(comp.pkg_list[i], i);
} }
......
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