Commit b0ada5dd authored by Robert Griesemer's avatar Robert Griesemer

- more work on semantic checks - not yet enabled by default

R=r
OCL=13391
CL=13391
parent 84c8d85f
......@@ -8,15 +8,39 @@ import Globals "globals"
import Universe "universe"
// ----------------------------------------------------------------------------
// Expressions
export Expr
type Expr struct {
type Expr interface {
}
export BinaryExpr
type BinaryExpr struct {
typ *Globals.Type;
op int;
x, y *Expr;
x, y Expr;
}
// ----------------------------------------------------------------------------
// Statements
export Stat
type Stat struct {
// To be completed
type Stat interface {
}
export Block
type Block struct {
// TODO fill in
}
export IfStat
type IfStat struct {
cond Expr;
then_ Stat;
else_ Stat;
}
......@@ -149,23 +149,23 @@ func (E *Exporter) WriteObject(obj *Globals.Object) {
E.WriteObjTag(obj.kind);
E.WriteString(obj.ident);
E.WriteType(obj.typ);
E.WritePackage(E.comp.pkgs[obj.pnolev]);
//E.WritePackage(E.comp.pkgs[obj.pnolev]);
switch obj.kind {
case Object.BAD: fallthrough;
case Object.PACKAGE: fallthrough;
case Object.PTYPE:
panic "UNREACHABLE";
case Object.CONST:
E.WriteInt(0); // should be the correct value
break;
case Object.TYPE:
// nothing to do
case Object.VAR:
E.WriteInt(0); // should be the correct address/offset
case Object.FUNC:
E.WriteInt(0); // should be the correct address/offset
default:
print "obj.kind = ", obj.kind, "\n";
panic "UNREACHABLE";
}
}
......@@ -200,41 +200,30 @@ func (E *Exporter) WriteType(typ *Globals.Type) {
}
switch typ.form {
case Type.UNDEF: fallthrough;
case Type.BAD: fallthrough;
case Type.NIL: fallthrough;
case Type.BOOL: fallthrough;
case Type.UINT: fallthrough;
case Type.INT: fallthrough;
case Type.FLOAT: fallthrough;
case Type.STRING: fallthrough;
case Type.ANY:
panic "UNREACHABLE";
case Type.ARRAY:
E.WriteInt(typ.len_);
E.WriteTypeField(typ.elt);
E.WriteType(typ.elt);
case Type.MAP:
E.WriteTypeField(typ.key);
E.WriteTypeField(typ.elt);
E.WriteType(typ.key);
E.WriteType(typ.elt);
case Type.CHANNEL:
E.WriteInt(typ.flags);
E.WriteTypeField(typ.elt);
E.WriteType(typ.elt);
case Type.FUNCTION:
E.WriteInt(typ.flags);
fallthrough;
case Type.STRUCT: fallthrough;
case Type.INTERFACE:
E.WriteScope(typ.scope);
case Type.STRUCT, Type.INTERFACE:
E.WriteScope(typ.scope);
case Type.POINTER: fallthrough;
case Type.REFERENCE:
E.WriteTypeField(typ.elt);
case Type.POINTER, Type.REFERENCE:
E.WriteType(typ.elt);
default:
print "typ.form = ", typ.form, "\n";
panic "UNREACHABLE";
}
}
......
......@@ -32,8 +32,8 @@ type Type struct {
size int; // in bytes
len_ int; // array length, no. of parameters (w/o recv)
obj *Object; // primary type object or NULL
key *Object; // maps
elt *Object; // arrays, maps, channels, pointers, references
key *Type; // maps
elt *Type; // arrays, maps, channels, pointers
scope *Scope; // structs, interfaces, functions
}
......
......@@ -216,15 +216,15 @@ func (I *Importer) ReadType() *Globals.Type {
case Type.ARRAY:
typ.len_ = I.ReadInt();
typ.elt = I.ReadTypeField();
typ.elt = I.ReadType();
case Type.MAP:
typ.key = I.ReadTypeField();
typ.elt = I.ReadTypeField();
typ.key = I.ReadType();
typ.elt = I.ReadType();
case Type.CHANNEL:
typ.flags = I.ReadInt();
typ.elt = I.ReadTypeField();
typ.elt = I.ReadType();
case Type.FUNCTION:
typ.flags = I.ReadInt();
......@@ -235,7 +235,7 @@ func (I *Importer) ReadType() *Globals.Type {
case Type.POINTER: fallthrough;
case Type.REFERENCE:
typ.elt = I.ReadTypeField();
typ.elt = I.ReadType();
}
return ptyp; // only use primary type
......
This diff is collapsed.
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package Scope
import Globals "Globals"
type Scope Globals.Scope
func New(parent *Scope) *Scope {
panic "UNIMPLEMENTED";
return nil;
}
......@@ -10,7 +10,6 @@ export
ANY,
ARRAY, STRUCT, INTERFACE, MAP, CHANNEL, FUNCTION, POINTER, REFERENCE
const /* form */ (
// internal types
UNDEF = iota; BAD; NIL;
......@@ -23,6 +22,9 @@ const /* form */ (
)
export
SEND, RECV
const /* flag */ (
SEND = 1 << iota; // chan>
RECV; // chan< or method
......
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