type (
- Any interface {};
+ Object struct;
Type struct;
Expr struct;
Stat struct;
// All nodes have a source position and and token.
export type Node struct {
- pos, tok int;
+ pos int; // source position (< 0 => unknown position)
+ tok int; // identifying token
+}
+
+
+// ----------------------------------------------------------------------------
+// Objects represent declared language objects, such as a const, type, var;
+// but also anonymous objects such as type and other literals.
+
+export type Object struct {
+ Node;
+ lit string; // identifiers and literals
+ typ *Type;
+ val *Expr;
+}
+
+
+export func NewObject(pos, tok int, lit string) *Object {
+ obj := new(Object);
+ obj.pos, obj.tok = pos, tok;
+ obj.lit = lit;
+ obj.typ = nil; // Universe::void_typ
+ return obj;
}
export type Expr struct {
Node;
x, y *Expr; // binary (x, y) and unary (y) expressions
+ obj *Object;
+
// TODO find a more space efficient way to hold these
s string; // identifiers and literals
t *Type; // type expressions, function literal types
type Type struct
type Scope struct
-type Elem struct
type OldCompilation struct
// Object represents a language object, such as a constant, variable, type,
}
-// TODO This is hideous! We need to have a decent way to do lists.
-// Ideally open arrays that allow '+'.
-
-export type Elem struct {
- next *Elem;
- val int;
- str string;
- obj *Object;
- typ *Type;
- expr Expr
-}
-
-
// ----------------------------------------------------------------------------
// Creation
x = P.ParseIdent();
case Scanner.LPAREN:
- // TODO we could have a function type here as in: new(**())
+ // TODO we could have a function type here as in: new(())
// (currently not working)
P.Next();
P.expr_lev++;
case Scanner.FUNC:
x = P.ParseFunctionLit();
- /*
- case Scanner.NEW:
- x = P.ParseNewCall();
- */
-
default:
t := P.TryType();
if t != nil {
# these files don't pass the idempotency test yet
log.go | type.go | types_amd64_darwin.go | \
\
- selftest1.go | func3.go | bug014.go | bug029.go | bug032.go | bug050.go | \
- bug068.go | bug088.go | bug083.go | bug106.go | bug125.go ) ;; # skip - files contain syntax errors
+ method1.go | selftest1.go | func3.go | bug014.go | bug029.go | bug032.go | bug050.go | \
+ bug068.go | bug088.go | bug083.go | bug106.go | bug125.go | bug126.go ) ;; # skip - files contain errors
* ) $1 $2; count ;;
esac
}
// method
// TODO
} else {
- s.DeclareIdent(d.ident, d.tok, d.typ);
+ // functions may be forward-declared
+ obj := s.Lookup(d.ident.s);
+ if obj != nil {
+ // TODO check if proper forward-declaration
+
+ } else {
+ s.DeclareIdent(d.ident, d.tok, d.typ);
+ }
}
default:
// ----------------------------------------------------------------------------
export func CheckProgram(err Scanner.ErrorHandler, p *AST.Program) {
- return; // DISABLED FOR NOW
-
var s State;
s.Init(err);
s.CheckProgram(p);