package base
+type Foo int
+
+type Bar *float;
+
type Node struct {
left, right *Node;
- val bool
+ val bool;
+ f Foo
}
-export Node
+export Foo, Bar, Node
package decls
-import "base"
+//import "base"
import base "base"
import base2 "base"
func (E *Exporter) WriteType(typ *Globals.Type);
func (E *Exporter) WriteObject(obj *Globals.Object);
-func (E *Exporter) WritePackage(pkg *Globals.Package);
+func (E *Exporter) WritePackage(pno int);
func (E *Exporter) WriteByte(x byte) {
E.WriteObjectTag(obj.kind);
E.WriteString(obj.ident);
E.WriteType(obj.typ);
- E.WritePackage(E.comp.pkgs[obj.pnolev]);
+ E.WritePackage(obj.pnolev);
switch obj.kind {
case Object.CONST:
panic "typ.obj.type() != typ"; // primary type
}
E.WriteString(typ.obj.ident);
- E.WritePackage(E.comp.pkgs[typ.obj.pnolev]);
+ E.WritePackage(typ.obj.pnolev);
} else {
E.WriteString("");
}
switch typ.form {
+ case Type.ALIAS:
+ E.WriteType(typ.elt);
+
case Type.ARRAY:
E.WriteInt(typ.len_);
E.WriteType(typ.elt);
}
-func (E *Exporter) WritePackage(pkg *Globals.Package) {
+func (E *Exporter) WritePackage(pno int) {
+ if pno < 0 {
+ pno = 0;
+ }
+ pkg := E.comp.pkgs[pno];
if pkg.ref >= 0 {
E.WritePackageTag(pkg.ref); // package already exported
return;
E.type_ref = Universe.types.len_;
pkg := comp.pkgs[0];
- E.WritePackage(pkg);
+ E.WritePackage(0);
E.WriteScope(pkg.scope);
if E.debug {
I.type_ref++;
switch (typ.form) {
- default: fallthrough;
+ case Type.ALIAS:
+ typ.elt = I.ReadType();
+
case Type.ARRAY:
typ.len_ = I.ReadInt();
typ.elt = I.ReadType();
P.Declare(obj);
}
- typ := P.TryType(); // nil if we have an explicit forward declaration
+ // If the next token is an identifier and we have a legal program,
+ // it must be a typename. In that case this declaration introduces
+ // an alias type.
+ make_alias := P.tok == Scanner.IDENT;
+
+ // If we have an explicit forward declaration, TryType will not
+ // find a type and return nil.
+ typ := P.TryType();
if typ != nil {
+ if make_alias {
+ alias := Globals.NewType(Type.ALIAS);
+ alias.elt = typ;
+ typ = alias;
+ }
obj.typ = typ;
if typ.obj == nil {
typ.obj = obj; // primary type object
}
P.PrintType(typ);
+ case Type.ALIAS:
+ P.PrintType(typ.elt);
+
case Type.ARRAY:
print "[]";
P.PrintType(typ.elt);
UNDEF, BAD, NIL,
BOOL, UINT, INT, FLOAT, STRING,
ANY,
- ARRAY, STRUCT, INTERFACE, MAP, CHANNEL, FUNCTION, POINTER, REFERENCE
+ ALIAS, ARRAY, STRUCT, INTERFACE, MAP, CHANNEL, FUNCTION, POINTER, REFERENCE
const /* form */ (
// internal types
// 'any' type
ANY;
// composite types
- ARRAY; STRUCT; INTERFACE; MAP; CHANNEL; FUNCTION; POINTER; REFERENCE;
+ ALIAS; ARRAY; STRUCT; INTERFACE; MAP; CHANNEL; FUNCTION; POINTER; REFERENCE;
)
case FLOAT: return "FLOAT";
case STRING: return "STRING";
case ANY: return "ANY";
+ case ALIAS: return "ALIAS";
case ARRAY: return "ARRAY";
case STRUCT: return "STRUCT";
case INTERFACE: return "INTERFACE";
}
-func DeclAlias(ident string, typ *Globals.Type) *Globals.Type {
- return DeclObj(Object.TYPE, ident, typ).typ;
-}
-
-
func DeclType(form int, ident string, size int) *Globals.Type {
typ := Globals.NewType(form);
typ.size = size;
- return DeclAlias(ident, typ);
+ return DeclObj(Object.TYPE, ident, typ).typ;
+}
+
+
+func DeclAlias(ident string, typ *Globals.Type) *Globals.Type {
+ alias := Globals.NewType(Type.ALIAS);
+ alias.elt = typ;
+ return DeclObj(Object.TYPE, ident, alias).typ;
}
break;
case Type.ANY:
break;
+ case Type.ALIAS:
+ break;
case Type.ARRAY:
break;
case Type.STRUCT: