Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
2527bba9
Commit
2527bba9
authored
Jan 15, 2009
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
casify pretty
R=r OCL=22899 CL=22899
parent
605d0746
Changes
12
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
620 additions
and
618 deletions
+620
-618
usr/gri/pretty/ast.go
usr/gri/pretty/ast.go
+76
-76
usr/gri/pretty/compilation.go
usr/gri/pretty/compilation.go
+17
-17
usr/gri/pretty/parser.go
usr/gri/pretty/parser.go
+163
-163
usr/gri/pretty/platform.go
usr/gri/pretty/platform.go
+10
-10
usr/gri/pretty/pretty.go
usr/gri/pretty/pretty.go
+2
-2
usr/gri/pretty/printer.go
usr/gri/pretty/printer.go
+148
-148
usr/gri/pretty/scanner.go
usr/gri/pretty/scanner.go
+106
-105
usr/gri/pretty/selftest0.go
usr/gri/pretty/selftest0.go
+1
-1
usr/gri/pretty/selftest2.go
usr/gri/pretty/selftest2.go
+9
-9
usr/gri/pretty/test.sh
usr/gri/pretty/test.sh
+3
-2
usr/gri/pretty/typechecker.go
usr/gri/pretty/typechecker.go
+13
-13
usr/gri/pretty/universe.go
usr/gri/pretty/universe.go
+72
-72
No files found.
usr/gri/pretty/ast.go
View file @
2527bba9
...
@@ -54,23 +54,23 @@ export func KindStr(kind int) string {
...
@@ -54,23 +54,23 @@ export func KindStr(kind int) string {
export
type
Object
struct
{
export
type
Object
struct
{
i
d
int
;
// unique id
I
d
int
;
// unique id
p
os
int
;
// source position (< 0 if unknown position)
P
os
int
;
// source position (< 0 if unknown position)
k
ind
int
;
// object kind
K
ind
int
;
// object kind
i
dent
string
;
I
dent
string
;
t
yp
*
Type
;
// nil for packages
T
yp
*
Type
;
// nil for packages
p
nolev
int
;
// >= 0: package no., <= 0: function nesting level, 0: global level
P
nolev
int
;
// >= 0: package no., <= 0: function nesting level, 0: global level
// attached values
// attached values
block
*
array
.
Array
;
e
nd
int
;
// stats for function literals; end of block pos
Block
*
array
.
Array
;
E
nd
int
;
// stats for function literals; end of block pos
}
}
func
(
obj
*
Object
)
IsExported
()
bool
{
func
(
obj
*
Object
)
IsExported
()
bool
{
switch
obj
.
k
ind
{
switch
obj
.
K
ind
{
case
NONE
/* FUNC for now */
,
CONST
,
TYPE
,
VAR
,
FUNC
:
case
NONE
/* FUNC for now */
,
CONST
,
TYPE
,
VAR
,
FUNC
:
ch
,
size
:=
utf8
.
DecodeRuneInString
(
obj
.
i
dent
,
0
);
ch
,
size
:=
utf8
.
DecodeRuneInString
(
obj
.
I
dent
,
0
);
return
unicode
.
IsUpper
(
ch
);
return
unicode
.
IsUpper
(
ch
);
}
}
return
false
;
return
false
;
...
@@ -78,18 +78,18 @@ func (obj *Object) IsExported() bool {
...
@@ -78,18 +78,18 @@ func (obj *Object) IsExported() bool {
export
var
Universe_void_typ
*
Type
// initialized by Universe to Universe.void_typ
export
var
Universe_void_typ
*
Type
// initialized by Universe to Universe.void_typ
var
O
bjectId
int
;
var
o
bjectId
int
;
export
func
NewObject
(
pos
,
kind
int
,
ident
string
)
*
Object
{
export
func
NewObject
(
pos
,
kind
int
,
ident
string
)
*
Object
{
obj
:=
new
(
Object
);
obj
:=
new
(
Object
);
obj
.
id
=
O
bjectId
;
obj
.
Id
=
o
bjectId
;
O
bjectId
++
;
o
bjectId
++
;
obj
.
p
os
=
pos
;
obj
.
P
os
=
pos
;
obj
.
k
ind
=
kind
;
obj
.
K
ind
=
kind
;
obj
.
i
dent
=
ident
;
obj
.
I
dent
=
ident
;
obj
.
t
yp
=
Universe_void_typ
;
obj
.
T
yp
=
Universe_void_typ
;
obj
.
p
nolev
=
0
;
obj
.
P
nolev
=
0
;
return
obj
;
return
obj
;
}
}
...
@@ -133,23 +133,23 @@ func (scope *Scope) Lookup(ident string) *Object {
...
@@ -133,23 +133,23 @@ func (scope *Scope) Lookup(ident string) *Object {
}
}
func
(
scope
*
Scope
)
A
dd
(
obj
*
Object
)
{
func
(
scope
*
Scope
)
a
dd
(
obj
*
Object
)
{
scope
.
entries
[
obj
.
i
dent
]
=
obj
;
scope
.
entries
[
obj
.
I
dent
]
=
obj
;
}
}
func
(
scope
*
Scope
)
Insert
(
obj
*
Object
)
{
func
(
scope
*
Scope
)
Insert
(
obj
*
Object
)
{
if
scope
.
LookupLocal
(
obj
.
i
dent
)
!=
nil
{
if
scope
.
LookupLocal
(
obj
.
I
dent
)
!=
nil
{
panic
(
"obj already inserted"
);
panic
(
"obj already inserted"
);
}
}
scope
.
A
dd
(
obj
);
scope
.
a
dd
(
obj
);
}
}
func
(
scope
*
Scope
)
InsertImport
(
obj
*
Object
)
*
Object
{
func
(
scope
*
Scope
)
InsertImport
(
obj
*
Object
)
*
Object
{
p
:=
scope
.
LookupLocal
(
obj
.
i
dent
);
p
:=
scope
.
LookupLocal
(
obj
.
I
dent
);
if
p
==
nil
{
if
p
==
nil
{
scope
.
A
dd
(
obj
);
scope
.
a
dd
(
obj
);
p
=
obj
;
p
=
obj
;
}
}
return
p
;
return
p
;
...
@@ -169,8 +169,8 @@ func (scope *Scope) Print() {
...
@@ -169,8 +169,8 @@ func (scope *Scope) Print() {
// All nodes have a source position and and token.
// All nodes have a source position and and token.
export
type
Node
struct
{
export
type
Node
struct
{
p
os
int
;
// source position (< 0 => unknown position)
P
os
int
;
// source position (< 0 => unknown position)
t
ok
int
;
// identifying token
T
ok
int
;
// identifying token
}
}
...
@@ -179,8 +179,8 @@ export type Node struct {
...
@@ -179,8 +179,8 @@ export type Node struct {
export
type
Expr
struct
{
export
type
Expr
struct
{
Node
;
Node
;
x
,
y
*
Expr
;
// binary (x, y) and unary (y
) expressions
X
,
Y
*
Expr
;
// binary (X, Y) and unary (Y
) expressions
o
bj
*
Object
;
O
bj
*
Object
;
}
}
...
@@ -189,7 +189,7 @@ func (x *Expr) Len() int {
...
@@ -189,7 +189,7 @@ func (x *Expr) Len() int {
return
0
;
return
0
;
}
}
n
:=
1
;
n
:=
1
;
for
;
x
.
tok
==
Scanner
.
COMMA
;
x
=
x
.
y
{
for
;
x
.
Tok
==
Scanner
.
COMMA
;
x
=
x
.
Y
{
n
++
;
n
++
;
}
}
return
n
;
return
n
;
...
@@ -197,11 +197,11 @@ func (x *Expr) Len() int {
...
@@ -197,11 +197,11 @@ func (x *Expr) Len() int {
export
func
NewExpr
(
pos
,
tok
int
,
x
,
y
*
Expr
)
*
Expr
{
export
func
NewExpr
(
pos
,
tok
int
,
x
,
y
*
Expr
)
*
Expr
{
if
x
!=
nil
&&
x
.
tok
==
Scanner
.
TYPE
||
y
!=
nil
&&
y
.
t
ok
==
Scanner
.
TYPE
{
if
x
!=
nil
&&
x
.
Tok
==
Scanner
.
TYPE
||
y
!=
nil
&&
y
.
T
ok
==
Scanner
.
TYPE
{
panic
(
"no type expression allowed"
);
panic
(
"no type expression allowed"
);
}
}
e
:=
new
(
Expr
);
e
:=
new
(
Expr
);
e
.
pos
,
e
.
tok
,
e
.
x
,
e
.
y
=
pos
,
tok
,
x
,
y
;
e
.
Pos
,
e
.
Tok
,
e
.
X
,
e
.
Y
=
pos
,
tok
,
x
,
y
;
return
e
;
return
e
;
}
}
...
@@ -209,7 +209,7 @@ export func NewExpr(pos, tok int, x, y *Expr) *Expr {
...
@@ -209,7 +209,7 @@ export func NewExpr(pos, tok int, x, y *Expr) *Expr {
// TODO probably don't need the tok parameter eventually
// TODO probably don't need the tok parameter eventually
export
func
NewLit
(
tok
int
,
obj
*
Object
)
*
Expr
{
export
func
NewLit
(
tok
int
,
obj
*
Object
)
*
Expr
{
e
:=
new
(
Expr
);
e
:=
new
(
Expr
);
e
.
pos
,
e
.
tok
,
e
.
obj
=
obj
.
p
os
,
tok
,
obj
;
e
.
Pos
,
e
.
Tok
,
e
.
Obj
=
obj
.
P
os
,
tok
,
obj
;
return
e
;
return
e
;
}
}
...
@@ -296,47 +296,47 @@ export const /* channel mode */ (
...
@@ -296,47 +296,47 @@ export const /* channel mode */ (
export
type
Type
struct
{
export
type
Type
struct
{
i
d
int
;
// unique id
I
d
int
;
// unique id
r
ef
int
;
// for exporting only: >= 0 means already exported
R
ef
int
;
// for exporting only: >= 0 means already exported
f
orm
int
;
// type form
F
orm
int
;
// type form
s
ize
int
;
// size in bytes
S
ize
int
;
// size in bytes
o
bj
*
Object
;
// primary type object or NULL
O
bj
*
Object
;
// primary type object or NULL
s
cope
*
Scope
;
// forwards, structs, interfaces, functions
S
cope
*
Scope
;
// forwards, structs, interfaces, functions
// syntactic components
// syntactic components
p
os
int
;
// source position (< 0 if unknown position)
P
os
int
;
// source position (< 0 if unknown position)
e
xpr
*
Expr
;
// type name, array length
E
xpr
*
Expr
;
// type name, array length
m
ode
int
;
// channel mode
M
ode
int
;
// channel mode
k
ey
*
Type
;
// receiver type or map key
K
ey
*
Type
;
// receiver type or map key
e
lt
*
Type
;
// array, map, channel or pointer element type, function result type
E
lt
*
Type
;
// array, map, channel or pointer element type, function result type
list
*
array
.
Array
;
e
nd
int
;
// struct fields, interface methods, function parameters
List
*
array
.
Array
;
E
nd
int
;
// struct fields, interface methods, function parameters
s
cope
*
Scope
;
// struct fields, methods
S
cope
*
Scope
;
// struct fields, methods
}
}
var
T
ypeId
int
;
var
t
ypeId
int
;
export
func
NewType
(
pos
,
form
int
)
*
Type
{
export
func
NewType
(
pos
,
form
int
)
*
Type
{
typ
:=
new
(
Type
);
typ
:=
new
(
Type
);
typ
.
id
=
T
ypeId
;
typ
.
Id
=
t
ypeId
;
T
ypeId
++
;
t
ypeId
++
;
typ
.
r
ef
=
-
1
;
// not yet exported
typ
.
R
ef
=
-
1
;
// not yet exported
typ
.
p
os
=
pos
;
typ
.
P
os
=
pos
;
typ
.
f
orm
=
form
;
typ
.
F
orm
=
form
;
return
typ
;
return
typ
;
}
}
func
(
t
*
Type
)
n
fields
()
int
{
func
(
t
*
Type
)
N
fields
()
int
{
if
t
.
l
ist
==
nil
{
if
t
.
L
ist
==
nil
{
return
0
;
return
0
;
}
}
nx
,
nt
:=
0
,
0
;
nx
,
nt
:=
0
,
0
;
for
i
,
n
:=
0
,
t
.
l
ist
.
Len
();
i
<
n
;
i
++
{
for
i
,
n
:=
0
,
t
.
L
ist
.
Len
();
i
<
n
;
i
++
{
if
t
.
list
.
At
(
i
)
.
(
*
Expr
)
.
t
ok
==
Scanner
.
TYPE
{
if
t
.
List
.
At
(
i
)
.
(
*
Expr
)
.
T
ok
==
Scanner
.
TYPE
{
nt
++
;
nt
++
;
}
else
{
}
else
{
nx
++
;
nx
++
;
...
@@ -349,10 +349,10 @@ func (t *Type) nfields() int {
...
@@ -349,10 +349,10 @@ func (t *Type) nfields() int {
}
}
// requires complete Type.
p
os access
// requires complete Type.
P
os access
export
func
NewTypeExpr
(
typ
*
Type
)
*
Expr
{
export
func
NewTypeExpr
(
typ
*
Type
)
*
Expr
{
obj
:=
NewObject
(
typ
.
p
os
,
TYPE
,
""
);
obj
:=
NewObject
(
typ
.
P
os
,
TYPE
,
""
);
obj
.
t
yp
=
typ
;
obj
.
T
yp
=
typ
;
return
NewLit
(
Scanner
.
TYPE
,
obj
);
return
NewLit
(
Scanner
.
TYPE
,
obj
);
}
}
...
@@ -365,16 +365,16 @@ export var BadType = NewType(0, Scanner.ILLEGAL);
...
@@ -365,16 +365,16 @@ export var BadType = NewType(0, Scanner.ILLEGAL);
export
type
Stat
struct
{
export
type
Stat
struct
{
Node
;
Node
;
init
,
p
ost
*
Stat
;
Init
,
P
ost
*
Stat
;
e
xpr
*
Expr
;
E
xpr
*
Expr
;
block
*
array
.
Array
;
e
nd
int
;
// block end position
Block
*
array
.
Array
;
E
nd
int
;
// block end position
d
ecl
*
Decl
;
D
ecl
*
Decl
;
}
}
export
func
NewStat
(
pos
,
tok
int
)
*
Stat
{
export
func
NewStat
(
pos
,
tok
int
)
*
Stat
{
s
:=
new
(
Stat
);
s
:=
new
(
Stat
);
s
.
pos
,
s
.
t
ok
=
pos
,
tok
;
s
.
Pos
,
s
.
T
ok
=
pos
,
tok
;
return
s
;
return
s
;
}
}
...
@@ -387,19 +387,19 @@ export var BadStat = NewStat(0, Scanner.ILLEGAL);
...
@@ -387,19 +387,19 @@ export var BadStat = NewStat(0, Scanner.ILLEGAL);
export
type
Decl
struct
{
export
type
Decl
struct
{
Node
;
Node
;
e
xported
bool
;
E
xported
bool
;
i
dent
*
Expr
;
// nil for ()-style declarations
I
dent
*
Expr
;
// nil for ()-style declarations
t
yp
*
Type
;
T
yp
*
Type
;
v
al
*
Expr
;
V
al
*
Expr
;
// list of *Decl for ()-style declarations
// list of *Decl for ()-style declarations
// list of *Stat for func declarations (or nil for forward decl)
// list of *Stat for func declarations (or nil for forward decl)
list
*
array
.
Array
;
e
nd
int
;
List
*
array
.
Array
;
E
nd
int
;
}
}
export
func
NewDecl
(
pos
,
tok
int
,
exported
bool
)
*
Decl
{
export
func
NewDecl
(
pos
,
tok
int
,
exported
bool
)
*
Decl
{
d
:=
new
(
Decl
);
d
:=
new
(
Decl
);
d
.
pos
,
d
.
tok
,
d
.
e
xported
=
pos
,
tok
,
exported
;
d
.
Pos
,
d
.
Tok
,
d
.
E
xported
=
pos
,
tok
,
exported
;
return
d
;
return
d
;
}
}
...
@@ -411,28 +411,28 @@ export var BadDecl = NewDecl(0, Scanner.ILLEGAL, false);
...
@@ -411,28 +411,28 @@ export var BadDecl = NewDecl(0, Scanner.ILLEGAL, false);
// Program
// Program
export
type
Comment
struct
{
export
type
Comment
struct
{
p
os
int
;
P
os
int
;
t
ext
string
;
T
ext
string
;
}
}
export
func
NewComment
(
pos
int
,
text
string
)
*
Comment
{
export
func
NewComment
(
pos
int
,
text
string
)
*
Comment
{
c
:=
new
(
Comment
);
c
:=
new
(
Comment
);
c
.
pos
,
c
.
t
ext
=
pos
,
text
;
c
.
Pos
,
c
.
T
ext
=
pos
,
text
;
return
c
;
return
c
;
}
}
export
type
Program
struct
{
export
type
Program
struct
{
p
os
int
;
// tok is Scanner.PACKAGE
P
os
int
;
// tok is Scanner.PACKAGE
i
dent
*
Expr
;
I
dent
*
Expr
;
d
ecls
*
array
.
Array
;
D
ecls
*
array
.
Array
;
c
omments
*
array
.
Array
;
C
omments
*
array
.
Array
;
}
}
export
func
NewProgram
(
pos
int
)
*
Program
{
export
func
NewProgram
(
pos
int
)
*
Program
{
p
:=
new
(
Program
);
p
:=
new
(
Program
);
p
.
p
os
=
pos
;
p
.
P
os
=
pos
;
return
p
;
return
p
;
}
}
usr/gri/pretty/compilation.go
View file @
2527bba9
...
@@ -34,7 +34,7 @@ export type Flags struct {
...
@@ -34,7 +34,7 @@ export type Flags struct {
}
}
type
E
rrorHandler
struct
{
type
e
rrorHandler
struct
{
filename
string
;
filename
string
;
src
string
;
src
string
;
nerrors
int
;
nerrors
int
;
...
@@ -44,7 +44,7 @@ type ErrorHandler struct {
...
@@ -44,7 +44,7 @@ type ErrorHandler struct {
}
}
func
(
h
*
E
rrorHandler
)
Init
(
filename
,
src
string
,
columns
bool
)
{
func
(
h
*
e
rrorHandler
)
Init
(
filename
,
src
string
,
columns
bool
)
{
h
.
filename
=
filename
;
h
.
filename
=
filename
;
h
.
src
=
src
;
h
.
src
=
src
;
h
.
nerrors
=
0
;
h
.
nerrors
=
0
;
...
@@ -55,7 +55,7 @@ func (h *ErrorHandler) Init(filename, src string, columns bool) {
...
@@ -55,7 +55,7 @@ func (h *ErrorHandler) Init(filename, src string, columns bool) {
// Compute (line, column) information for a given source position.
// Compute (line, column) information for a given source position.
func
(
h
*
E
rrorHandler
)
LineCol
(
pos
int
)
(
line
,
col
int
)
{
func
(
h
*
e
rrorHandler
)
LineCol
(
pos
int
)
(
line
,
col
int
)
{
line
=
1
;
line
=
1
;
lpos
:=
0
;
lpos
:=
0
;
...
@@ -75,7 +75,7 @@ func (h *ErrorHandler) LineCol(pos int) (line, col int) {
...
@@ -75,7 +75,7 @@ func (h *ErrorHandler) LineCol(pos int) (line, col int) {
}
}
func
(
h
*
E
rrorHandler
)
ErrorMsg
(
pos
int
,
msg
string
)
{
func
(
h
*
e
rrorHandler
)
ErrorMsg
(
pos
int
,
msg
string
)
{
print
(
h
.
filename
,
":"
);
print
(
h
.
filename
,
":"
);
if
pos
>=
0
{
if
pos
>=
0
{
// print position
// print position
...
@@ -97,7 +97,7 @@ func (h *ErrorHandler) ErrorMsg(pos int, msg string) {
...
@@ -97,7 +97,7 @@ func (h *ErrorHandler) ErrorMsg(pos int, msg string) {
}
}
func
(
h
*
E
rrorHandler
)
Error
(
pos
int
,
msg
string
)
{
func
(
h
*
e
rrorHandler
)
Error
(
pos
int
,
msg
string
)
{
// only report errors that are sufficiently far away from the previous error
// only report errors that are sufficiently far away from the previous error
// in the hope to avoid most follow-up errors
// in the hope to avoid most follow-up errors
const
errdist
=
20
;
const
errdist
=
20
;
...
@@ -112,7 +112,7 @@ func (h *ErrorHandler) Error(pos int, msg string) {
...
@@ -112,7 +112,7 @@ func (h *ErrorHandler) Error(pos int, msg string) {
}
}
func
(
h
*
E
rrorHandler
)
Warning
(
pos
int
,
msg
string
)
{
func
(
h
*
e
rrorHandler
)
Warning
(
pos
int
,
msg
string
)
{
panic
(
"UNIMPLEMENTED"
);
panic
(
"UNIMPLEMENTED"
);
}
}
...
@@ -124,7 +124,7 @@ export func Compile(src_file string, flags *Flags) (*AST.Program, int) {
...
@@ -124,7 +124,7 @@ export func Compile(src_file string, flags *Flags) (*AST.Program, int) {
return
nil
,
1
;
return
nil
,
1
;
}
}
var
err
E
rrorHandler
;
var
err
e
rrorHandler
;
err
.
Init
(
src_file
,
src
,
flags
.
columns
);
err
.
Init
(
src_file
,
src
,
flags
.
columns
);
var
scanner
Scanner
.
Scanner
;
var
scanner
Scanner
.
Scanner
;
...
@@ -148,7 +148,7 @@ export func Compile(src_file string, flags *Flags) (*AST.Program, int) {
...
@@ -148,7 +148,7 @@ export func Compile(src_file string, flags *Flags) (*AST.Program, int) {
}
}
func
F
ileExists
(
name
string
)
bool
{
func
f
ileExists
(
name
string
)
bool
{
fd
,
err
:=
OS
.
Open
(
name
,
OS
.
O_RDONLY
,
0
);
fd
,
err
:=
OS
.
Open
(
name
,
OS
.
O_RDONLY
,
0
);
if
err
==
nil
{
if
err
==
nil
{
fd
.
Close
();
fd
.
Close
();
...
@@ -158,7 +158,7 @@ func FileExists(name string) bool {
...
@@ -158,7 +158,7 @@ func FileExists(name string) bool {
}
}
func
A
ddDeps
(
globalset
map
[
string
]
bool
,
wset
*
array
.
Array
,
src_file
string
,
flags
*
Flags
)
{
func
a
ddDeps
(
globalset
map
[
string
]
bool
,
wset
*
array
.
Array
,
src_file
string
,
flags
*
Flags
)
{
dummy
,
found
:=
globalset
[
src_file
];
dummy
,
found
:=
globalset
[
src_file
];
if
!
found
{
if
!
found
{
globalset
[
src_file
]
=
true
;
globalset
[
src_file
]
=
true
;
...
@@ -168,27 +168,27 @@ func AddDeps(globalset map [string] bool, wset *array.Array, src_file string, fl
...
@@ -168,27 +168,27 @@ func AddDeps(globalset map [string] bool, wset *array.Array, src_file string, fl
return
;
return
;
}
}
nimports
:=
prog
.
d
ecls
.
Len
();
nimports
:=
prog
.
D
ecls
.
Len
();
if
nimports
>
0
{
if
nimports
>
0
{
print
(
src_file
,
".6:
\t
"
);
print
(
src_file
,
".6:
\t
"
);
localset
:=
make
(
map
[
string
]
bool
);
localset
:=
make
(
map
[
string
]
bool
);
for
i
:=
0
;
i
<
nimports
;
i
++
{
for
i
:=
0
;
i
<
nimports
;
i
++
{
decl
:=
prog
.
d
ecls
.
At
(
i
)
.
(
*
AST
.
Decl
);
decl
:=
prog
.
D
ecls
.
At
(
i
)
.
(
*
AST
.
Decl
);
assert
(
decl
.
tok
==
Scanner
.
IMPORT
&&
decl
.
val
.
t
ok
==
Scanner
.
STRING
);
assert
(
decl
.
Tok
==
Scanner
.
IMPORT
&&
decl
.
Val
.
T
ok
==
Scanner
.
STRING
);
src
:=
decl
.
val
.
obj
.
i
dent
;
src
:=
decl
.
Val
.
Obj
.
I
dent
;
src
=
src
[
1
:
len
(
src
)
-
1
];
// strip "'s
src
=
src
[
1
:
len
(
src
)
-
1
];
// strip "'s
// ignore files when they are seen a 2nd time
// ignore files when they are seen a 2nd time
dummy
,
found
:=
localset
[
src
];
dummy
,
found
:=
localset
[
src
];
if
!
found
{
if
!
found
{
localset
[
src
]
=
true
;
localset
[
src
]
=
true
;
if
F
ileExists
(
src
+
".go"
)
{
if
f
ileExists
(
src
+
".go"
)
{
wset
.
Push
(
src
);
wset
.
Push
(
src
);
print
(
" "
,
src
,
".6"
);
print
(
" "
,
src
,
".6"
);
}
else
if
}
else
if
F
ileExists
(
Platform
.
GOROOT
+
"/pkg/"
+
src
+
".6"
)
||
f
ileExists
(
Platform
.
GOROOT
+
"/pkg/"
+
src
+
".6"
)
||
F
ileExists
(
Platform
.
GOROOT
+
"/pkg/"
+
src
+
".a"
)
{
f
ileExists
(
Platform
.
GOROOT
+
"/pkg/"
+
src
+
".a"
)
{
}
else
{
}
else
{
// TODO should collect these and print later
// TODO should collect these and print later
...
@@ -207,6 +207,6 @@ export func ComputeDeps(src_file string, flags *Flags) {
...
@@ -207,6 +207,6 @@ export func ComputeDeps(src_file string, flags *Flags) {
wset
:=
array
.
New
(
0
);
wset
:=
array
.
New
(
0
);
wset
.
Push
(
src_file
);
wset
.
Push
(
src_file
);
for
wset
.
Len
()
>
0
{
for
wset
.
Len
()
>
0
{
A
ddDeps
(
globalset
,
wset
,
wset
.
Pop
()
.
(
string
),
flags
);
a
ddDeps
(
globalset
,
wset
,
wset
.
Pop
()
.
(
string
),
flags
);
}
}
}
}
usr/gri/pretty/parser.go
View file @
2527bba9
This diff is collapsed.
Click to expand it.
usr/gri/pretty/platform.go
View file @
2527bba9
...
@@ -17,7 +17,7 @@ export var
...
@@ -17,7 +17,7 @@ export var
USER
string
;
USER
string
;
func
G
etEnv
(
key
string
)
string
{
func
g
etEnv
(
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
);
...
@@ -30,10 +30,10 @@ func GetEnv(key string) string {
...
@@ -30,10 +30,10 @@ func GetEnv(key string) string {
func
init
()
{
func
init
()
{
GOARCH
=
G
etEnv
(
"GOARCH"
);
GOARCH
=
g
etEnv
(
"GOARCH"
);
GOOS
=
G
etEnv
(
"GOOS"
);
GOOS
=
g
etEnv
(
"GOOS"
);
GOROOT
=
G
etEnv
(
"GOROOT"
);
GOROOT
=
g
etEnv
(
"GOROOT"
);
USER
=
G
etEnv
(
"USER"
);
USER
=
g
etEnv
(
"USER"
);
}
}
...
@@ -42,13 +42,13 @@ func init() {
...
@@ -42,13 +42,13 @@ func init() {
export
const
(
export
const
(
MAGIC_obj_file
=
"@gri-go.7@v0"
;
// make it clear that it cannot be a source file
MAGIC_obj_file
=
"@gri-go.7@v0"
;
// make it clear that it cannot be a source file
s
rc_file_ext
=
".go"
;
S
rc_file_ext
=
".go"
;
o
bj_file_ext
=
".7"
;
O
bj_file_ext
=
".7"
;
)
)
export
func
ReadObjectFile
(
filename
string
)
(
data
string
,
ok
bool
)
{
export
func
ReadObjectFile
(
filename
string
)
(
data
string
,
ok
bool
)
{
data
,
ok
=
sys
.
readfile
(
filename
+
o
bj_file_ext
);
data
,
ok
=
sys
.
readfile
(
filename
+
O
bj_file_ext
);
magic
:=
MAGIC_obj_file
;
// TODO remove once len(constant) works
magic
:=
MAGIC_obj_file
;
// TODO remove once len(constant) works
if
ok
&&
len
(
data
)
>=
len
(
magic
)
&&
data
[
0
:
len
(
magic
)]
==
magic
{
if
ok
&&
len
(
data
)
>=
len
(
magic
)
&&
data
[
0
:
len
(
magic
)]
==
magic
{
return
data
,
ok
;
return
data
,
ok
;
...
@@ -58,13 +58,13 @@ export func ReadObjectFile(filename string) (data string, ok bool) {
...
@@ -58,13 +58,13 @@ export func ReadObjectFile(filename string) (data string, ok bool) {
export
func
ReadSourceFile
(
name
string
)
(
data
string
,
ok
bool
)
{
export
func
ReadSourceFile
(
name
string
)
(
data
string
,
ok
bool
)
{
name
=
Utils
.
TrimExt
(
name
,
src_file_ext
)
+
s
rc_file_ext
;
name
=
Utils
.
TrimExt
(
name
,
Src_file_ext
)
+
S
rc_file_ext
;
data
,
ok
=
sys
.
readfile
(
name
);
data
,
ok
=
sys
.
readfile
(
name
);
return
data
,
ok
;
return
data
,
ok
;
}
}
export
func
WriteObjectFile
(
name
string
,
data
string
)
bool
{
export
func
WriteObjectFile
(
name
string
,
data
string
)
bool
{
name
=
Utils
.
TrimExt
(
Utils
.
BaseName
(
name
),
src_file_ext
)
+
o
bj_file_ext
;
name
=
Utils
.
TrimExt
(
Utils
.
BaseName
(
name
),
Src_file_ext
)
+
O
bj_file_ext
;
return
sys
.
writefile
(
name
,
data
);
return
sys
.
writefile
(
name
,
data
);
}
}
usr/gri/pretty/pretty.go
View file @
2527bba9
...
@@ -29,7 +29,7 @@ func init() {
...
@@ -29,7 +29,7 @@ func init() {
}
}
func
U
sage
()
{
func
u
sage
()
{
print
(
"usage: pretty { flags } { files }
\n
"
);
print
(
"usage: pretty { flags } { files }
\n
"
);
Flag
.
PrintDefaults
();
Flag
.
PrintDefaults
();
sys
.
exit
(
0
);
sys
.
exit
(
0
);
...
@@ -40,7 +40,7 @@ func main() {
...
@@ -40,7 +40,7 @@ func main() {
Flag
.
Parse
();
Flag
.
Parse
();
if
Flag
.
NFlag
()
==
0
&&
Flag
.
NArg
()
==
0
{
if
Flag
.
NFlag
()
==
0
&&
Flag
.
NArg
()
==
0
{
U
sage
();
u
sage
();
}
}
// process files
// process files
...
...
usr/gri/pretty/printer.go
View file @
2527bba9
This diff is collapsed.
Click to expand it.
usr/gri/pretty/scanner.go
View file @
2527bba9
This diff is collapsed.
Click to expand it.
usr/gri/pretty/selftest0.go
View file @
2527bba9
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
package
main
package
main
type
Proto
struct
{
export
type
Proto
struct
{
a
int
"a tag"
;
a
int
"a tag"
;
b
,
c
,
d
*
Proto
"bcd"
"tag"
;
b
,
c
,
d
*
Proto
"bcd"
"tag"
;
*
Proto
"proto tag"
*
Proto
"proto tag"
...
...
usr/gri/pretty/selftest2.go
View file @
2527bba9
...
@@ -11,7 +11,7 @@ import (
...
@@ -11,7 +11,7 @@ import (
)
)
const
/* enum1 */
(
export
const
/* enum1 */
(
EnumTag0
=
iota
;
EnumTag0
=
iota
;
EnumTag1
;
EnumTag1
;
EnumTag2
;
EnumTag2
;
...
@@ -32,10 +32,10 @@ const /* enum2 */ (
...
@@ -32,10 +32,10 @@ const /* enum2 */ (
)
)
type
S
struct
{}
export
type
S
struct
{}
type
T
struct
{
export
type
T
struct
{
x
,
y
int
;
x
,
y
int
;
s
string
;
s
string
;
next_t
*
T
next_t
*
T
...
@@ -43,7 +43,7 @@ type T struct {
...
@@ -43,7 +43,7 @@ type T struct {
var
(
var
(
A
=
5
;
aa
=
5
;
u
,
v
,
w
int
=
0
,
0
,
0
;
u
,
v
,
w
int
=
0
,
0
,
0
;
foo
=
"foo"
;
foo
=
"foo"
;
fixed_array0
=
[
10
]
int
{};
fixed_array0
=
[
10
]
int
{};
...
@@ -54,7 +54,7 @@ var (
...
@@ -54,7 +54,7 @@ var (
var
(
var
(
// Unicode identifiers
// Unicode identifiers
ä
,
ö
,
ü
,
Á
,
Ø
,
Å
,
ƒ
,
ß
int
;
ä
,
ö
,
ü
,
ƒ
,
ß
int
;
)
)
...
@@ -105,24 +105,24 @@ func f3(a *[]int, m map[string] int) {
...
@@ -105,24 +105,24 @@ func f3(a *[]int, m map[string] int) {
}
}
println
(
"A3"
);
println
(
"A3"
);
for
i
:
x
:=
range
a
{
for
i
,
x
:=
range
a
{
println
(
i
,
x
);
println
(
i
,
x
);
}
}
println
(
"M1"
);
println
(
"M1"
);
for
i
range
m
{
for
i
:=
range
m
{
println
(
i
);
println
(
i
);
}
}
println
(
"M2"
);
println
(
"M2"
);
for
i
,
x
range
m
{
for
i
,
x
:=
range
m
{
println
(
i
,
x
);
println
(
i
,
x
);
}
}
println
(
"M3"
);
println
(
"M3"
);
var
i
string
;
var
i
string
;
var
x
int
;
var
x
int
;
for
i
:
x
=
range
m
{
for
i
,
x
=
range
m
{
println
(
i
,
x
);
println
(
i
,
x
);
}
}
}
}
...
...
usr/gri/pretty/test.sh
View file @
2527bba9
...
@@ -10,6 +10,7 @@ TMP3=test_tmp3.go
...
@@ -10,6 +10,7 @@ TMP3=test_tmp3.go
COUNT
=
0
COUNT
=
0
count
()
{
count
()
{
#echo $1
let
COUNT
=
$COUNT
+1
let
COUNT
=
$COUNT
+1
let
M
=
$COUNT
%10
let
M
=
$COUNT
%10
if
[
$M
==
0
]
;
then
if
[
$M
==
0
]
;
then
...
@@ -25,7 +26,7 @@ apply1() {
...
@@ -25,7 +26,7 @@ apply1() {
# files with errors (skip them)
# files with errors (skip them)
method1.go
|
selftest1.go
|
func3.go
|
bug014.go
|
bug029.go
|
bug032.go
|
bug050.go
|
\
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
)
;;
bug068.go
|
bug088.go
|
bug083.go
|
bug106.go
|
bug125.go
|
bug126.go
)
;;
*
)
$1
$2
;
count
;;
*
)
$1
$2
;
count
$F
;;
esac
esac
}
}
...
@@ -130,7 +131,7 @@ if [ $? != 0 ]; then
...
@@ -130,7 +131,7 @@ if [ $? != 0 ]; then
echo
"Error (selftest1): pretty -t selftest1.go"
echo
"Error (selftest1): pretty -t selftest1.go"
exit
1
exit
1
fi
fi
count
count
selftest1.go
# run over all .go files
# run over all .go files
...
...
usr/gri/pretty/typechecker.go
View file @
2527bba9
...
@@ -11,13 +11,13 @@ import (
...
@@ -11,13 +11,13 @@ import (
)
)
type
S
tate
struct
{
type
s
tate
struct
{
// setup
// setup
err
Scanner
.
ErrorHandler
;
err
Scanner
.
ErrorHandler
;
}
}
func
(
s
*
S
tate
)
Init
(
err
Scanner
.
ErrorHandler
)
{
func
(
s
*
s
tate
)
Init
(
err
Scanner
.
ErrorHandler
)
{
s
.
err
=
err
;
s
.
err
=
err
;
}
}
...
@@ -42,27 +42,27 @@ func assert(pred bool) {
...
@@ -42,27 +42,27 @@ func assert(pred bool) {
}
}
func
(
s
*
S
tate
)
Error
(
pos
int
,
msg
string
)
{
func
(
s
*
s
tate
)
Error
(
pos
int
,
msg
string
)
{
s
.
err
.
Error
(
pos
,
msg
);
s
.
err
.
Error
(
pos
,
msg
);
}
}
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
func
(
s
*
S
tate
)
CheckType
()
{
func
(
s
*
s
tate
)
CheckType
()
{
}
}
func
(
s
*
S
tate
)
CheckDeclaration
(
d
*
AST
.
Decl
)
{
func
(
s
*
s
tate
)
CheckDeclaration
(
d
*
AST
.
Decl
)
{
if
d
.
tok
!=
Scanner
.
FUNC
&&
d
.
l
ist
!=
nil
{
if
d
.
Tok
!=
Scanner
.
FUNC
&&
d
.
L
ist
!=
nil
{
// group of parenthesized declarations
// group of parenthesized declarations
for
i
:=
0
;
i
<
d
.
l
ist
.
Len
();
i
++
{
for
i
:=
0
;
i
<
d
.
L
ist
.
Len
();
i
++
{
s
.
CheckDeclaration
(
d
.
l
ist
.
At
(
i
)
.
(
*
AST
.
Decl
))
s
.
CheckDeclaration
(
d
.
L
ist
.
At
(
i
)
.
(
*
AST
.
Decl
))
}
}
}
else
{
}
else
{
// single declaration
// single declaration
switch
d
.
t
ok
{
switch
d
.
T
ok
{
case
Scanner
.
IMPORT
:
case
Scanner
.
IMPORT
:
case
Scanner
.
EXPORT
:
case
Scanner
.
EXPORT
:
case
Scanner
.
CONST
:
case
Scanner
.
CONST
:
...
@@ -76,9 +76,9 @@ func (s *State) CheckDeclaration(d *AST.Decl) {
...
@@ -76,9 +76,9 @@ func (s *State) CheckDeclaration(d *AST.Decl) {
}
}
func
(
s
*
S
tate
)
CheckProgram
(
p
*
AST
.
Program
)
{
func
(
s
*
s
tate
)
CheckProgram
(
p
*
AST
.
Program
)
{
for
i
:=
0
;
i
<
p
.
d
ecls
.
Len
();
i
++
{
for
i
:=
0
;
i
<
p
.
D
ecls
.
Len
();
i
++
{
s
.
CheckDeclaration
(
p
.
d
ecls
.
At
(
i
)
.
(
*
AST
.
Decl
));
s
.
CheckDeclaration
(
p
.
D
ecls
.
At
(
i
)
.
(
*
AST
.
Decl
));
}
}
}
}
...
@@ -86,7 +86,7 @@ func (s *State) CheckProgram(p *AST.Program) {
...
@@ -86,7 +86,7 @@ func (s *State) CheckProgram(p *AST.Program) {
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
export
func
CheckProgram
(
err
Scanner
.
ErrorHandler
,
p
*
AST
.
Program
)
{
export
func
CheckProgram
(
err
Scanner
.
ErrorHandler
,
p
*
AST
.
Program
)
{
var
s
S
tate
;
var
s
s
tate
;
s
.
Init
(
err
);
s
.
Init
(
err
);
s
.
CheckProgram
(
p
);
s
.
CheckProgram
(
p
);
}
}
usr/gri/pretty/universe.go
View file @
2527bba9
...
@@ -11,113 +11,113 @@ import (
...
@@ -11,113 +11,113 @@ import (
export
var
(
export
var
(
s
cope
*
AST
.
Scope
;
S
cope
*
AST
.
Scope
;
t
ypes
array
.
Array
;
T
ypes
array
.
Array
;
// internal types
// internal types
v
oid_typ
,
V
oid_typ
,
b
ad_typ
,
B
ad_typ
,
n
il_typ
,
N
il_typ
,
// basic types
// basic types
b
ool_typ
,
B
ool_typ
,
u
int8_typ
,
U
int8_typ
,
u
int16_typ
,
U
int16_typ
,
u
int32_typ
,
U
int32_typ
,
u
int64_typ
,
U
int64_typ
,
i
nt8_typ
,
I
nt8_typ
,
i
nt16_typ
,
I
nt16_typ
,
i
nt32_typ
,
I
nt32_typ
,
i
nt64_typ
,
I
nt64_typ
,
f
loat32_typ
,
F
loat32_typ
,
f
loat64_typ
,
F
loat64_typ
,
f
loat80_typ
,
F
loat80_typ
,
s
tring_typ
,
S
tring_typ
,
i
nteger_typ
,
I
nteger_typ
,
// convenience types
// convenience types
b
yte_typ
,
B
yte_typ
,
u
int_typ
,
U
int_typ
,
i
nt_typ
,
I
nt_typ
,
f
loat_typ
,
F
loat_typ
,
u
intptr_typ
*
AST
.
Type
;
U
intptr_typ
*
AST
.
Type
;
t
rue_obj
,
T
rue_obj
,
f
alse_obj
,
F
alse_obj
,
i
ota_obj
,
I
ota_obj
,
n
il_obj
*
AST
.
Object
;
N
il_obj
*
AST
.
Object
;
)
)
func
D
eclObj
(
kind
int
,
ident
string
,
typ
*
AST
.
Type
)
*
AST
.
Object
{
func
d
eclObj
(
kind
int
,
ident
string
,
typ
*
AST
.
Type
)
*
AST
.
Object
{
obj
:=
AST
.
NewObject
(
-
1
/* no source pos */
,
kind
,
ident
);
obj
:=
AST
.
NewObject
(
-
1
/* no source pos */
,
kind
,
ident
);
obj
.
t
yp
=
typ
;
obj
.
T
yp
=
typ
;
if
kind
==
AST
.
TYPE
&&
typ
.
o
bj
==
nil
{
if
kind
==
AST
.
TYPE
&&
typ
.
O
bj
==
nil
{
typ
.
o
bj
=
obj
;
// set primary type object
typ
.
O
bj
=
obj
;
// set primary type object
}
}
s
cope
.
Insert
(
obj
);
S
cope
.
Insert
(
obj
);
return
obj
return
obj
}
}
func
D
eclType
(
form
int
,
ident
string
,
size
int
)
*
AST
.
Type
{
func
d
eclType
(
form
int
,
ident
string
,
size
int
)
*
AST
.
Type
{
typ
:=
AST
.
NewType
(
-
1
/* no source pos */
,
form
);
typ
:=
AST
.
NewType
(
-
1
/* no source pos */
,
form
);
typ
.
s
ize
=
size
;
typ
.
S
ize
=
size
;
return
DeclObj
(
AST
.
TYPE
,
ident
,
typ
)
.
t
yp
;
return
declObj
(
AST
.
TYPE
,
ident
,
typ
)
.
T
yp
;
}
}
func
R
egister
(
typ
*
AST
.
Type
)
*
AST
.
Type
{
func
r
egister
(
typ
*
AST
.
Type
)
*
AST
.
Type
{
typ
.
ref
=
t
ypes
.
Len
();
typ
.
Ref
=
T
ypes
.
Len
();
t
ypes
.
Push
(
typ
);
T
ypes
.
Push
(
typ
);
return
typ
;
return
typ
;
}
}
func
init
()
{
func
init
()
{
s
cope
=
AST
.
NewScope
(
nil
);
// universe has no parent
S
cope
=
AST
.
NewScope
(
nil
);
// universe has no parent
t
ypes
.
Init
(
32
);
T
ypes
.
Init
(
32
);
// Interal types
// Interal types
v
oid_typ
=
AST
.
NewType
(
-
1
/* no source pos */
,
AST
.
VOID
);
V
oid_typ
=
AST
.
NewType
(
-
1
/* no source pos */
,
AST
.
VOID
);
AST
.
Universe_void_typ
=
v
oid_typ
;
AST
.
Universe_void_typ
=
V
oid_typ
;
b
ad_typ
=
AST
.
NewType
(
-
1
/* no source pos */
,
AST
.
BADTYPE
);
B
ad_typ
=
AST
.
NewType
(
-
1
/* no source pos */
,
AST
.
BADTYPE
);
n
il_typ
=
AST
.
NewType
(
-
1
/* no source pos */
,
AST
.
NIL
);
N
il_typ
=
AST
.
NewType
(
-
1
/* no source pos */
,
AST
.
NIL
);
// Basic types
// Basic types
bool_typ
=
Register
(
D
eclType
(
AST
.
BOOL
,
"bool"
,
1
));
Bool_typ
=
register
(
d
eclType
(
AST
.
BOOL
,
"bool"
,
1
));
uint8_typ
=
Register
(
D
eclType
(
AST
.
UINT
,
"uint8"
,
1
));
Uint8_typ
=
register
(
d
eclType
(
AST
.
UINT
,
"uint8"
,
1
));
uint16_typ
=
Register
(
D
eclType
(
AST
.
UINT
,
"uint16"
,
2
));
Uint16_typ
=
register
(
d
eclType
(
AST
.
UINT
,
"uint16"
,
2
));
uint32_typ
=
Register
(
D
eclType
(
AST
.
UINT
,
"uint32"
,
4
));
Uint32_typ
=
register
(
d
eclType
(
AST
.
UINT
,
"uint32"
,
4
));
uint64_typ
=
Register
(
D
eclType
(
AST
.
UINT
,
"uint64"
,
8
));
Uint64_typ
=
register
(
d
eclType
(
AST
.
UINT
,
"uint64"
,
8
));
int8_typ
=
Register
(
D
eclType
(
AST
.
INT
,
"int8"
,
1
));
Int8_typ
=
register
(
d
eclType
(
AST
.
INT
,
"int8"
,
1
));
int16_typ
=
Register
(
D
eclType
(
AST
.
INT
,
"int16"
,
2
));
Int16_typ
=
register
(
d
eclType
(
AST
.
INT
,
"int16"
,
2
));
int32_typ
=
Register
(
D
eclType
(
AST
.
INT
,
"int32"
,
4
));
Int32_typ
=
register
(
d
eclType
(
AST
.
INT
,
"int32"
,
4
));
int64_typ
=
Register
(
D
eclType
(
AST
.
INT
,
"int64"
,
8
));
Int64_typ
=
register
(
d
eclType
(
AST
.
INT
,
"int64"
,
8
));
float32_typ
=
Register
(
D
eclType
(
AST
.
FLOAT
,
"float32"
,
4
));
Float32_typ
=
register
(
d
eclType
(
AST
.
FLOAT
,
"float32"
,
4
));
float64_typ
=
Register
(
D
eclType
(
AST
.
FLOAT
,
"float64"
,
8
));
Float64_typ
=
register
(
d
eclType
(
AST
.
FLOAT
,
"float64"
,
8
));
float80_typ
=
Register
(
D
eclType
(
AST
.
FLOAT
,
"float80"
,
10
));
Float80_typ
=
register
(
d
eclType
(
AST
.
FLOAT
,
"float80"
,
10
));
string_typ
=
Register
(
D
eclType
(
AST
.
STRING
,
"string"
,
8
));
String_typ
=
register
(
d
eclType
(
AST
.
STRING
,
"string"
,
8
));
integer_typ
=
Register
(
D
eclType
(
AST
.
INTEGER
,
"integer"
,
8
));
Integer_typ
=
register
(
d
eclType
(
AST
.
INTEGER
,
"integer"
,
8
));
// All but 'byte' should be platform-dependent, eventually.
// All but 'byte' should be platform-dependent, eventually.
byte_typ
=
Register
(
D
eclType
(
AST
.
UINT
,
"byte"
,
1
));
Byte_typ
=
register
(
d
eclType
(
AST
.
UINT
,
"byte"
,
1
));
uint_typ
=
Register
(
D
eclType
(
AST
.
UINT
,
"uint"
,
4
));
Uint_typ
=
register
(
d
eclType
(
AST
.
UINT
,
"uint"
,
4
));
int_typ
=
Register
(
D
eclType
(
AST
.
INT
,
"int"
,
4
));
Int_typ
=
register
(
d
eclType
(
AST
.
INT
,
"int"
,
4
));
float_typ
=
Register
(
D
eclType
(
AST
.
FLOAT
,
"float"
,
4
));
Float_typ
=
register
(
d
eclType
(
AST
.
FLOAT
,
"float"
,
4
));
uintptr_typ
=
Register
(
D
eclType
(
AST
.
UINT
,
"uintptr"
,
8
));
Uintptr_typ
=
register
(
d
eclType
(
AST
.
UINT
,
"uintptr"
,
8
));
// Predeclared constants
// Predeclared constants
true_obj
=
DeclObj
(
AST
.
CONST
,
"true"
,
b
ool_typ
);
True_obj
=
declObj
(
AST
.
CONST
,
"true"
,
B
ool_typ
);
false_obj
=
DeclObj
(
AST
.
CONST
,
"false"
,
b
ool_typ
);
False_obj
=
declObj
(
AST
.
CONST
,
"false"
,
B
ool_typ
);
iota_obj
=
DeclObj
(
AST
.
CONST
,
"iota"
,
i
nt_typ
);
Iota_obj
=
declObj
(
AST
.
CONST
,
"iota"
,
I
nt_typ
);
nil_obj
=
DeclObj
(
AST
.
CONST
,
"nil"
,
n
il_typ
);
Nil_obj
=
declObj
(
AST
.
CONST
,
"nil"
,
N
il_typ
);
// Builtin functions
// Builtin functions
DeclObj
(
AST
.
BUILTIN
,
"len"
,
v
oid_typ
);
declObj
(
AST
.
BUILTIN
,
"len"
,
V
oid_typ
);
DeclObj
(
AST
.
BUILTIN
,
"new"
,
v
oid_typ
);
declObj
(
AST
.
BUILTIN
,
"new"
,
V
oid_typ
);
DeclObj
(
AST
.
BUILTIN
,
"panic"
,
v
oid_typ
);
declObj
(
AST
.
BUILTIN
,
"panic"
,
V
oid_typ
);
DeclObj
(
AST
.
BUILTIN
,
"print"
,
v
oid_typ
);
declObj
(
AST
.
BUILTIN
,
"print"
,
V
oid_typ
);
// scope.Print();
// scope.Print();
}
}
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