Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
997a9429
Commit
997a9429
authored
Aug 04, 2008
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- import/export cleanup: added comments, removed dead code, re-org structure
R=r OCL=13816 CL=13816
parent
695f83a9
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
154 additions
and
163 deletions
+154
-163
export.go
usr/gri/gosrc/export.go
+74
-73
globals.go
usr/gri/gosrc/globals.go
+2
-12
import.go
usr/gri/gosrc/import.go
+72
-72
parser.go
usr/gri/gosrc/parser.go
+6
-6
No files found.
usr/gri/gosrc/export.go
View file @
997a9429
...
@@ -21,9 +21,7 @@ type Exporter struct {
...
@@ -21,9 +21,7 @@ type Exporter struct {
};
};
func
(
E
*
Exporter
)
WriteType
(
typ
*
Globals
.
Type
);
func
(
E
*
Exporter
)
WriteObject
(
obj
*
Globals
.
Object
);
func
(
E
*
Exporter
)
WriteObject
(
obj
*
Globals
.
Object
);
func
(
E
*
Exporter
)
WritePackage
(
pno
int
);
func
(
E
*
Exporter
)
WriteByte
(
x
byte
)
{
func
(
E
*
Exporter
)
WriteByte
(
x
byte
)
{
...
@@ -65,13 +63,14 @@ func (E *Exporter) WriteString(s string) {
...
@@ -65,13 +63,14 @@ func (E *Exporter) WriteString(s string) {
}
}
func
(
E
*
Exporter
)
WriteObjectTag
(
tag
int
)
{
func
(
E
*
Exporter
)
WritePackageTag
(
tag
int
)
{
if
tag
<
0
{
panic
"tag < 0"
;
}
E
.
WriteInt
(
tag
);
E
.
WriteInt
(
tag
);
if
E
.
debug
{
if
E
.
debug
{
print
"
\n
"
,
Object
.
KindStr
(
tag
);
if
tag
>=
0
{
print
" [P"
,
tag
,
"]"
;
// package ref
}
else
{
print
"
\n
P"
,
E
.
pkg_ref
,
":"
;
}
}
}
}
}
...
@@ -88,28 +87,45 @@ func (E *Exporter) WriteTypeTag(tag int) {
...
@@ -88,28 +87,45 @@ func (E *Exporter) WriteTypeTag(tag int) {
}
}
func
(
E
*
Exporter
)
WritePackageTag
(
tag
int
)
{
func
(
E
*
Exporter
)
WriteObjectTag
(
tag
int
)
{
if
tag
<
0
{
panic
"tag < 0"
;
}
E
.
WriteInt
(
tag
);
E
.
WriteInt
(
tag
);
if
E
.
debug
{
if
E
.
debug
{
if
tag
>=
0
{
print
"
\n
"
,
Object
.
KindStr
(
tag
);
print
" [P"
,
tag
,
"]"
;
// package ref
}
else
{
print
"
\n
P"
,
E
.
pkg_ref
,
":"
;
}
}
}
func
(
E
*
Exporter
)
WritePackage
(
pkg
*
Globals
.
Package
)
{
if
E
.
comp
.
pkg_list
[
pkg
.
obj
.
pnolev
]
!=
pkg
{
panic
"inconsistent package object"
}
if
pkg
.
ref
>=
0
{
E
.
WritePackageTag
(
pkg
.
ref
);
// package already exported
return
;
}
}
E
.
WritePackageTag
(
-
1
);
pkg
.
ref
=
E
.
pkg_ref
;
E
.
pkg_ref
++
;
E
.
WriteString
(
pkg
.
obj
.
ident
);
E
.
WriteString
(
pkg
.
file_name
);
E
.
WriteString
(
pkg
.
key
);
}
}
func
(
E
*
Exporter
)
WriteScope
(
scope
*
Globals
.
Scope
,
export_all
bool
)
{
func
(
E
*
Exporter
)
WriteScope
(
scope
*
Globals
.
Scope
)
{
if
E
.
debug
{
if
E
.
debug
{
print
" {"
;
print
" {"
;
}
}
for
p
:=
scope
.
entries
.
first
;
p
!=
nil
;
p
=
p
.
next
{
for
p
:=
scope
.
entries
.
first
;
p
!=
nil
;
p
=
p
.
next
{
if
export_all
||
p
.
obj
.
exported
{
E
.
WriteObject
(
p
.
obj
);
E
.
WriteObject
(
p
.
obj
);
}
}
}
E
.
WriteObject
(
nil
);
E
.
WriteObject
(
nil
);
if
E
.
debug
{
if
E
.
debug
{
...
@@ -118,42 +134,6 @@ func (E *Exporter) WriteScope(scope *Globals.Scope, export_all bool) {
...
@@ -118,42 +134,6 @@ func (E *Exporter) WriteScope(scope *Globals.Scope, export_all bool) {
}
}
func
(
E
*
Exporter
)
WriteObject
(
obj
*
Globals
.
Object
)
{
if
obj
==
nil
{
E
.
WriteObjectTag
(
Object
.
END
);
return
;
}
E
.
WriteObjectTag
(
obj
.
kind
);
if
obj
.
kind
==
Object
.
TYPE
{
// named types are always primary types
// and handled entirely by WriteType()
if
obj
.
typ
.
obj
!=
obj
{
panic
"inconsistent primary type"
}
E
.
WriteType
(
obj
.
typ
);
return
;
}
E
.
WriteString
(
obj
.
ident
);
E
.
WriteType
(
obj
.
typ
);
switch
obj
.
kind
{
case
Object
.
CONST
:
E
.
WriteInt
(
0
);
// should be the correct value
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
:
panic
"UNREACHABLE"
;
}
}
func
(
E
*
Exporter
)
WriteType
(
typ
*
Globals
.
Type
)
{
func
(
E
*
Exporter
)
WriteType
(
typ
*
Globals
.
Type
)
{
if
typ
.
ref
>=
0
{
if
typ
.
ref
>=
0
{
E
.
WriteTypeTag
(
typ
.
ref
);
// type already exported
E
.
WriteTypeTag
(
typ
.
ref
);
// type already exported
...
@@ -161,18 +141,18 @@ func (E *Exporter) WriteType(typ *Globals.Type) {
...
@@ -161,18 +141,18 @@ func (E *Exporter) WriteType(typ *Globals.Type) {
}
}
if
-
typ
.
form
>=
0
{
if
-
typ
.
form
>=
0
{
panic
"
-typ.form >= 0"
;
// conflict with ref numbers
panic
"
conflict with ref numbers"
;
}
}
E
.
WriteTypeTag
(
-
typ
.
form
);
E
.
WriteTypeTag
(
-
typ
.
form
);
typ
.
ref
=
E
.
type_ref
;
typ
.
ref
=
E
.
type_ref
;
E
.
type_ref
++
;
E
.
type_ref
++
;
// if we have a
primary
type, export the type identifier and package
// if we have a
named
type, export the type identifier and package
ident
:=
""
;
ident
:=
""
;
if
typ
.
obj
!=
nil
{
if
typ
.
obj
!=
nil
{
//
primary
type
//
named
type
if
typ
.
obj
.
typ
!=
typ
{
if
typ
.
obj
.
typ
!=
typ
{
panic
"inconsistent
primary
type"
;
panic
"inconsistent
named
type"
;
}
}
ident
=
typ
.
obj
.
ident
;
ident
=
typ
.
obj
.
ident
;
if
!
typ
.
obj
.
exported
{
if
!
typ
.
obj
.
exported
{
...
@@ -185,8 +165,8 @@ func (E *Exporter) WriteType(typ *Globals.Type) {
...
@@ -185,8 +165,8 @@ func (E *Exporter) WriteType(typ *Globals.Type) {
E
.
WriteString
(
ident
);
E
.
WriteString
(
ident
);
if
len
(
ident
)
>
0
{
if
len
(
ident
)
>
0
{
//
primary
type
//
named
type
E
.
WritePackage
(
typ
.
obj
.
pnolev
);
E
.
WritePackage
(
E
.
comp
.
pkg_list
[
typ
.
obj
.
pnolev
]
);
}
}
switch
typ
.
form
{
switch
typ
.
form
{
...
@@ -207,10 +187,10 @@ func (E *Exporter) WriteType(typ *Globals.Type) {
...
@@ -207,10 +187,10 @@ func (E *Exporter) WriteType(typ *Globals.Type) {
case
Type
.
FUNCTION
:
case
Type
.
FUNCTION
:
E
.
WriteInt
(
typ
.
flags
);
E
.
WriteInt
(
typ
.
flags
);
E
.
WriteScope
(
typ
.
scope
,
true
);
E
.
WriteScope
(
typ
.
scope
);
case
Type
.
STRUCT
,
Type
.
INTERFACE
:
case
Type
.
STRUCT
,
Type
.
INTERFACE
:
E
.
WriteScope
(
typ
.
scope
,
true
);
// for now
E
.
WriteScope
(
typ
.
scope
);
case
Type
.
POINTER
,
Type
.
REFERENCE
:
case
Type
.
POINTER
,
Type
.
REFERENCE
:
E
.
WriteType
(
typ
.
elt
);
E
.
WriteType
(
typ
.
elt
);
...
@@ -221,23 +201,38 @@ func (E *Exporter) WriteType(typ *Globals.Type) {
...
@@ -221,23 +201,38 @@ func (E *Exporter) WriteType(typ *Globals.Type) {
}
}
func
(
E
*
Exporter
)
WritePackage
(
pno
int
)
{
func
(
E
*
Exporter
)
WriteObject
(
obj
*
Globals
.
Object
)
{
if
pno
<
0
{
if
obj
==
nil
{
pno
=
0
;
E
.
WriteObjectTag
(
Object
.
END
);
return
;
}
}
pkg
:=
E
.
comp
.
pkg_list
[
pno
];
E
.
WriteObjectTag
(
obj
.
kind
);
if
pkg
.
ref
>=
0
{
E
.
WritePackageTag
(
pkg
.
ref
);
// package already exported
if
obj
.
kind
==
Object
.
TYPE
{
// named types are handled entirely by WriteType()
if
obj
.
typ
.
obj
!=
obj
{
panic
"inconsistent named type"
}
E
.
WriteType
(
obj
.
typ
);
return
;
return
;
}
}
E
.
WritePackageTag
(
-
1
);
E
.
WriteString
(
obj
.
ident
);
pkg
.
ref
=
E
.
pkg_ref
;
E
.
WriteType
(
obj
.
typ
);
E
.
pkg_ref
++
;
E
.
WriteString
(
pkg
.
obj
.
ident
);
switch
obj
.
kind
{
E
.
WriteString
(
pkg
.
file_name
);
case
Object
.
CONST
:
E
.
WriteString
(
pkg
.
key
);
E
.
WriteInt
(
0
);
// should be the correct value
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
:
panic
"UNREACHABLE"
;
}
}
}
...
@@ -264,9 +259,15 @@ func (E *Exporter) Export(comp* Globals.Compilation, file_name string) {
...
@@ -264,9 +259,15 @@ func (E *Exporter) Export(comp* Globals.Compilation, file_name string) {
}
}
E
.
type_ref
=
Universe
.
types
.
len_
;
E
.
type_ref
=
Universe
.
types
.
len_
;
// export package 0
pkg
:=
comp
.
pkg_list
[
0
];
pkg
:=
comp
.
pkg_list
[
0
];
E
.
WritePackage
(
0
);
E
.
WritePackage
(
pkg
);
E
.
WriteScope
(
pkg
.
scope
,
false
);
for
p
:=
pkg
.
scope
.
entries
.
first
;
p
!=
nil
;
p
=
p
.
next
{
if
p
.
obj
.
exported
{
E
.
WriteObject
(
p
.
obj
);
}
}
E
.
WriteObject
(
nil
);
if
E
.
debug
{
if
E
.
debug
{
print
"
\n
("
,
E
.
buf_pos
,
" bytes)
\n
"
;
print
"
\n
("
,
E
.
buf_pos
,
" bytes)
\n
"
;
...
...
usr/gri/gosrc/globals.go
View file @
997a9429
...
@@ -126,12 +126,13 @@ func NewType(form int) *Type {
...
@@ -126,12 +126,13 @@ func NewType(form int) *Type {
export
NewPackage
;
export
NewPackage
;
func
NewPackage
(
file_name
string
,
obj
*
Object
)
*
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
;
pkg
.
key
=
"<the package key>"
;
// TODO fix this
pkg
.
key
=
"<the package key>"
;
// TODO fix this
pkg
.
obj
=
obj
;
pkg
.
obj
=
obj
;
pkg
.
scope
=
scope
;
return
pkg
;
return
pkg
;
}
}
...
@@ -316,14 +317,3 @@ func (C *Compilation) Insert(pkg *Package) {
...
@@ -316,14 +317,3 @@ func (C *Compilation) Insert(pkg *Package) {
C
.
pkg_list
[
C
.
pkg_ref
]
=
pkg
;
C
.
pkg_list
[
C
.
pkg_ref
]
=
pkg
;
C
.
pkg_ref
++
;
C
.
pkg_ref
++
;
}
}
func
(
C
*
Compilation
)
InsertImport
(
pkg
*
Package
)
*
Package
{
p
:=
C
.
Lookup
(
pkg
.
file_name
);
if
(
p
==
nil
)
{
// no primary package found
C
.
Insert
(
pkg
);
p
=
pkg
;
}
return
p
;
}
usr/gri/gosrc/import.go
View file @
997a9429
...
@@ -23,9 +23,7 @@ type Importer struct {
...
@@ -23,9 +23,7 @@ type Importer struct {
};
};
func
(
I
*
Importer
)
ReadType
()
*
Globals
.
Type
;
func
(
I
*
Importer
)
ReadObject
()
*
Globals
.
Object
;
func
(
I
*
Importer
)
ReadObject
()
*
Globals
.
Object
;
func
(
I
*
Importer
)
ReadPackage
()
*
Globals
.
Package
;
func
(
I
*
Importer
)
ReadByte
()
byte
{
func
(
I
*
Importer
)
ReadByte
()
byte
{
...
@@ -74,13 +72,14 @@ func (I *Importer) ReadString() string {
...
@@ -74,13 +72,14 @@ func (I *Importer) ReadString() string {
}
}
func
(
I
*
Importer
)
Read
Object
Tag
()
int
{
func
(
I
*
Importer
)
Read
Package
Tag
()
int
{
tag
:=
I
.
ReadInt
();
tag
:=
I
.
ReadInt
();
if
tag
<
0
{
panic
"tag < 0"
;
}
if
I
.
debug
{
if
I
.
debug
{
print
"
\n
"
,
Object
.
KindStr
(
tag
);
if
tag
>=
0
{
print
" [P"
,
tag
,
"]"
;
// package ref
}
else
{
print
"
\n
P"
,
I
.
pkg_ref
,
":"
;
}
}
}
return
tag
;
return
tag
;
}
}
...
@@ -99,16 +98,45 @@ func (I *Importer) ReadTypeTag() int {
...
@@ -99,16 +98,45 @@ func (I *Importer) ReadTypeTag() int {
}
}
func
(
I
*
Importer
)
Read
Package
Tag
()
int
{
func
(
I
*
Importer
)
Read
Object
Tag
()
int
{
tag
:=
I
.
ReadInt
();
tag
:=
I
.
ReadInt
();
if
tag
<
0
{
panic
"tag < 0"
;
}
if
I
.
debug
{
if
I
.
debug
{
print
"
\n
"
,
Object
.
KindStr
(
tag
);
}
return
tag
;
}
func
(
I
*
Importer
)
ReadPackage
()
*
Globals
.
Package
{
tag
:=
I
.
ReadPackageTag
();
if
tag
>=
0
{
if
tag
>=
0
{
print
" [P"
,
tag
,
"]"
;
// package ref
return
I
.
pkg_list
[
tag
];
// package already imported
}
else
{
print
"
\n
P"
,
I
.
pkg_ref
,
":"
;
}
}
ident
:=
I
.
ReadString
();
file_name
:=
I
.
ReadString
();
key
:=
I
.
ReadString
();
// Canonicalize package - if it was imported before,
// use the primary import.
pkg
:=
I
.
comp
.
Lookup
(
file_name
);
if
pkg
==
nil
{
// new package
obj
:=
Globals
.
NewObject
(
-
1
,
Object
.
PACKAGE
,
ident
);
pkg
=
Globals
.
NewPackage
(
file_name
,
obj
,
Globals
.
NewScope
(
nil
));
I
.
comp
.
Insert
(
pkg
);
}
else
if
key
!=
pkg
.
key
{
// the package was imported before but the package
// key has changed
panic
"package key inconsistency"
;
}
}
return
tag
;
I
.
pkg_list
[
I
.
pkg_ref
]
=
pkg
;
I
.
pkg_ref
++
;
return
pkg
;
}
}
...
@@ -120,7 +148,7 @@ func (I *Importer) ReadScope() *Globals.Scope {
...
@@ -120,7 +148,7 @@ func (I *Importer) ReadScope() *Globals.Scope {
scope
:=
Globals
.
NewScope
(
nil
);
scope
:=
Globals
.
NewScope
(
nil
);
obj
:=
I
.
ReadObject
();
obj
:=
I
.
ReadObject
();
for
obj
!=
nil
{
for
obj
!=
nil
{
scope
.
Insert
Import
(
obj
);
scope
.
Insert
(
obj
);
obj
=
I
.
ReadObject
();
obj
=
I
.
ReadObject
();
}
}
...
@@ -132,44 +160,6 @@ func (I *Importer) ReadScope() *Globals.Scope {
...
@@ -132,44 +160,6 @@ func (I *Importer) ReadScope() *Globals.Scope {
}
}
func
(
I
*
Importer
)
ReadObject
()
*
Globals
.
Object
{
tag
:=
I
.
ReadObjectTag
();
if
tag
==
Object
.
END
{
return
nil
;
}
if
tag
==
Object
.
TYPE
{
// named types are always primary types
// and handled entirely by ReadType()
typ
:=
I
.
ReadType
();
if
typ
.
obj
.
typ
!=
typ
{
panic
"inconsistent primary type"
;
}
return
typ
.
obj
;
}
ident
:=
I
.
ReadString
();
obj
:=
Globals
.
NewObject
(
0
,
tag
,
ident
);
obj
.
typ
=
I
.
ReadType
();
switch
(
tag
)
{
case
Object
.
CONST
:
I
.
ReadInt
();
// should set the value field
case
Object
.
VAR
:
I
.
ReadInt
();
// should set the address/offset field
case
Object
.
FUNC
:
I
.
ReadInt
();
// should set the address/offset field
default
:
panic
"UNREACHABLE"
;
}
return
obj
;
}
func
(
I
*
Importer
)
ReadType
()
*
Globals
.
Type
{
func
(
I
*
Importer
)
ReadType
()
*
Globals
.
Type
{
tag
:=
I
.
ReadTypeTag
();
tag
:=
I
.
ReadTypeTag
();
if
tag
>=
0
{
if
tag
>=
0
{
...
@@ -181,7 +171,7 @@ func (I *Importer) ReadType() *Globals.Type {
...
@@ -181,7 +171,7 @@ func (I *Importer) ReadType() *Globals.Type {
ident
:=
I
.
ReadString
();
ident
:=
I
.
ReadString
();
if
len
(
ident
)
>
0
{
if
len
(
ident
)
>
0
{
//
primary
type
//
named
type
pkg
:=
I
.
ReadPackage
();
pkg
:=
I
.
ReadPackage
();
// create corresponding type object
// create corresponding type object
...
@@ -234,32 +224,40 @@ func (I *Importer) ReadType() *Globals.Type {
...
@@ -234,32 +224,40 @@ func (I *Importer) ReadType() *Globals.Type {
}
}
func
(
I
*
Importer
)
ReadPackage
()
*
Globals
.
Package
{
func
(
I
*
Importer
)
ReadObject
()
*
Globals
.
Object
{
tag
:=
I
.
ReadPackageTag
();
tag
:=
I
.
ReadObjectTag
();
if
tag
>=
0
{
if
tag
==
Object
.
END
{
return
I
.
pkg_list
[
tag
];
// package already imported
return
nil
;
}
if
tag
==
Object
.
TYPE
{
// named types are handled entirely by ReadType()
typ
:=
I
.
ReadType
();
if
typ
.
obj
.
typ
!=
typ
{
panic
"inconsistent named type"
;
}
return
typ
.
obj
;
}
}
ident
:=
I
.
ReadString
();
ident
:=
I
.
ReadString
();
file_name
:=
I
.
ReadString
();
obj
:=
Globals
.
NewObject
(
0
,
tag
,
ident
);
key
:=
I
.
ReadString
();
obj
.
typ
=
I
.
ReadType
();
pkg
:=
I
.
comp
.
Lookup
(
file_name
);
if
pkg
==
nil
{
switch
(
tag
)
{
// new package
case
Object
.
CONST
:
obj
:=
Globals
.
NewObject
(
-
1
,
Object
.
PACKAGE
,
ident
);
I
.
ReadInt
();
// should set the value field
pkg
=
Globals
.
NewPackage
(
file_name
,
obj
);
pkg
.
scope
=
Globals
.
NewScope
(
nil
);
pkg
=
I
.
comp
.
InsertImport
(
pkg
);
}
else
if
key
!=
pkg
.
key
{
case
Object
.
VAR
:
// package inconsistency
I
.
ReadInt
();
// should set the address/offset field
panic
"package key inconsistency"
;
case
Object
.
FUNC
:
I
.
ReadInt
();
// should set the address/offset field
default
:
panic
"UNREACHABLE"
;
}
}
I
.
pkg_list
[
I
.
pkg_ref
]
=
pkg
;
I
.
pkg_ref
++
;
return
pkg
;
return
obj
;
}
}
...
@@ -290,13 +288,15 @@ func (I *Importer) Import(comp* Globals.Compilation, file_name string) *Globals.
...
@@ -290,13 +288,15 @@ func (I *Importer) Import(comp* Globals.Compilation, file_name string) *Globals.
I
.
type_ref
++
;
I
.
type_ref
++
;
}
}
// import package
pkg
:=
I
.
ReadPackage
();
pkg
:=
I
.
ReadPackage
();
obj
:=
I
.
ReadObject
();
{
obj
:=
I
.
ReadObject
();
for
obj
!=
nil
{
for
obj
!=
nil
{
obj
.
pnolev
=
pkg
.
obj
.
pnolev
;
obj
.
pnolev
=
pkg
.
obj
.
pnolev
;
pkg
.
scope
.
InsertImport
(
obj
);
pkg
.
scope
.
InsertImport
(
obj
);
obj
=
I
.
ReadObject
();
obj
=
I
.
ReadObject
();
}
}
}
if
I
.
debug
{
if
I
.
debug
{
print
"
\n
("
,
I
.
buf_pos
,
" bytes)
\n
"
;
print
"
\n
("
,
I
.
buf_pos
,
" bytes)
\n
"
;
...
...
usr/gri/gosrc/parser.go
View file @
997a9429
...
@@ -1917,18 +1917,18 @@ func (P *Parser) ParseProgram() {
...
@@ -1917,18 +1917,18 @@ func (P *Parser) ParseProgram() {
P
.
OpenScope
();
P
.
OpenScope
();
P
.
Expect
(
Scanner
.
PACKAGE
);
P
.
Expect
(
Scanner
.
PACKAGE
);
obj
:=
P
.
ParseIdentDecl
(
Object
.
PACKAGE
);
obj
:=
P
.
ParseIdentDecl
(
Object
.
PACKAGE
);
pkg
:=
Globals
.
NewPackage
(
P
.
S
.
filename
,
obj
);
P
.
comp
.
Insert
(
pkg
);
if
P
.
comp
.
pkg_ref
!=
1
{
panic
"should have exactly one package now"
;
}
P
.
Optional
(
Scanner
.
SEMICOLON
);
P
.
Optional
(
Scanner
.
SEMICOLON
);
{
if
P
.
level
!=
0
{
{
if
P
.
level
!=
0
{
panic
"incorrect scope level"
;
panic
"incorrect scope level"
;
}
}
P
.
OpenScope
();
P
.
OpenScope
();
pkg
.
scope
=
P
.
top_scope
;
P
.
comp
.
Insert
(
Globals
.
NewPackage
(
P
.
S
.
filename
,
obj
,
P
.
top_scope
));
if
P
.
comp
.
pkg_ref
!=
1
{
panic
"should have exactly one package now"
;
}
for
P
.
tok
==
Scanner
.
IMPORT
{
for
P
.
tok
==
Scanner
.
IMPORT
{
P
.
ParseDecl
(
false
,
Scanner
.
IMPORT
);
P
.
ParseDecl
(
false
,
Scanner
.
IMPORT
);
P
.
Optional
(
Scanner
.
SEMICOLON
);
P
.
Optional
(
Scanner
.
SEMICOLON
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment