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
920c6106
Commit
920c6106
authored
Sep 03, 2009
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
top-level func
R=austin DELTA=21 (5 added, 10 deleted, 6 changed) OCL=34355 CL=34355
parent
851497bc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
15 deletions
+10
-15
usr/austin/eval/stmt.go
usr/austin/eval/stmt.go
+5
-13
usr/austin/eval/stmt_test.go
usr/austin/eval/stmt_test.go
+3
-0
usr/austin/eval/world.go
usr/austin/eval/world.go
+2
-2
No files found.
usr/austin/eval/stmt.go
View file @
920c6106
...
...
@@ -335,26 +335,21 @@ func (a *stmtCompiler) compileDeclStmt(s *ast.DeclStmt) {
a
.
silentErrors
++
;
case
*
ast
.
FuncDecl
:
log
.
Crash
(
"FuncDecl at statement level"
);
if
!
a
.
block
.
global
{
log
.
Crash
(
"FuncDecl at statement level"
);
}
case
*
ast
.
GenDecl
:
switch
decl
.
Tok
{
case
token
.
IMPORT
:
if
decl
.
Tok
==
token
.
IMPORT
&&
!
a
.
block
.
global
{
log
.
Crash
(
"import at statement level"
);
case
token
.
CONST
:
log
.
Crashf
(
"%v not implemented"
,
decl
.
Tok
);
case
token
.
TYPE
:
a
.
compileTypeDecl
(
a
.
block
,
decl
);
case
token
.
VAR
:
a
.
compileVarDecl
(
decl
);
}
default
:
log
.
Crashf
(
"Unexpected Decl type %T"
,
s
.
Decl
);
}
a
.
compileDecl
(
s
.
Decl
);
}
// decl might or might not be at top level;
func
(
a
*
stmtCompiler
)
compileVarDecl
(
decl
*
ast
.
GenDecl
)
{
for
_
,
spec
:=
range
decl
.
Specs
{
spec
:=
spec
.
(
*
ast
.
ValueSpec
);
...
...
@@ -380,7 +375,6 @@ func (a *stmtCompiler) compileVarDecl(decl *ast.GenDecl) {
}
}
// decl is top level
func
(
a
*
stmtCompiler
)
compileDecl
(
decl
ast
.
Decl
)
{
switch
d
:=
decl
.
(
type
)
{
case
*
ast
.
BadDecl
:
...
...
@@ -395,8 +389,6 @@ func (a *stmtCompiler) compileDecl(decl ast.Decl) {
// Declare and initialize v before compiling func
// so that body can refer to itself.
c
:=
a
.
block
.
DefineConst
(
d
.
Name
.
Value
,
a
.
pos
,
decl
.
Type
,
decl
.
Type
.
Zero
());
// TODO(rsc): How to mark v as constant
// so the type checker rejects assignments to it?
fn
:=
a
.
compileFunc
(
a
.
block
,
decl
,
d
.
Body
);
if
fn
==
nil
{
return
;
...
...
usr/austin/eval/stmt_test.go
View file @
920c6106
...
...
@@ -331,6 +331,9 @@ var stmtTests = []test {
CErr
(
"x := make(map[int] int); (func(a,b int){})(x[0])"
,
"not enough"
),
CErr
(
"x := make(map[int] int); x[1] = oneTwo()"
,
"too many"
),
RErr
(
"x := make(map[int] int); i = x[1]"
,
"key '1' not found"
),
// Functions
Val2
(
"func fib(n int) int { if n <= 2 { return n } return fib(n-1) + fib(n-2) }"
,
"fib(4)"
,
5
,
"fib(10)"
,
89
),
}
func
TestStmt
(
t
*
testing
.
T
)
{
...
...
usr/austin/eval/world.go
View file @
920c6106
...
...
@@ -73,7 +73,7 @@ func (w *World) compileStmts(stmts []ast.Stmt) (Code, os.Error) {
return
&
stmtCode
{
w
,
fc
.
get
()},
nil
;
}
func
(
w
*
World
)
compileDecls
(
decls
[]
ast
.
Decl
)
(
Code
,
os
.
Error
)
{
func
(
w
*
World
)
compileDecls
(
decls
[]
ast
.
Decl
)
(
Code
,
os
.
Error
)
{
stmts
:=
make
([]
ast
.
Stmt
,
len
(
decls
));
for
i
,
d
:=
range
decls
{
stmts
[
i
]
=
&
ast
.
DeclStmt
{
d
};
...
...
@@ -144,7 +144,7 @@ func (w *World) Compile(text string) (Code, os.Error) {
// Otherwise try as DeclList.
decls
,
err1
:=
parser
.
ParseDeclList
(
"input"
,
text
);
if
err
==
nil
{
if
err
1
==
nil
{
return
w
.
compileDecls
(
decls
);
}
...
...
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