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
fb3af53f
Commit
fb3af53f
authored
Jul 19, 2008
by
Ken Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
initialization
SVN=128115
parent
5a90ede8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
112 additions
and
2 deletions
+112
-2
src/cmd/gc/dcl.c
src/cmd/gc/dcl.c
+102
-0
src/cmd/gc/go.h
src/cmd/gc/go.h
+1
-0
src/cmd/gc/go.y
src/cmd/gc/go.y
+8
-2
src/runtime/rt0_amd64.s
src/runtime/rt0_amd64.s
+1
-0
No files found.
src/cmd/gc/dcl.c
View file @
fb3af53f
...
...
@@ -877,3 +877,105 @@ forwdcl(Sym *s)
s
->
forwtype
=
t
;
return
t
;
}
// hand-craft the following initialization code
// var init_%%%_done bool; (1)
// func init_%%%_function() (2)
// if init_%%%_done { return } (3)
// init_%%%_done = true; (4)
// for Y {
// init_%%%_function() (5)
// }
// if true { <init stmts> } (6)
// init() // if any (7)
// return (8)
// }
// export init_%%%_function (9)
void
fninit
(
Node
*
n
)
{
Node
*
done
,
*
any
,
*
init
;
Node
*
a
,
*
b
,
*
r
;
Iter
iter
;
ulong
h
;
Sym
*
s
;
r
=
N
;
// (1)
vargen
++
;
snprint
(
namebuf
,
sizeof
(
namebuf
),
"init_%.3ld_done"
,
vargen
);
done
=
newname
(
lookup
(
namebuf
));
addvar
(
done
,
types
[
TBOOL
],
PEXTERN
);
// (2)
maxarg
=
0
;
stksize
=
0
;
vargen
++
;
h
=
vargen
;
if
(
strcmp
(
package
,
"main"
)
==
0
)
h
=
999
;
snprint
(
namebuf
,
sizeof
(
namebuf
),
"init_%.3ld_function"
,
h
);
b
=
nod
(
ODCLFUNC
,
N
,
N
);
b
->
nname
=
newname
(
lookup
(
namebuf
));
b
->
type
=
functype
(
N
,
N
,
N
);
funchdr
(
b
);
// (3)
a
=
nod
(
OIF
,
N
,
N
);
a
->
ntest
=
done
;
a
->
nbody
=
nod
(
ORETURN
,
N
,
N
);
r
=
list
(
r
,
a
);
// (4)
a
=
nod
(
OAS
,
done
,
booltrue
);
r
=
list
(
r
,
a
);
// (5)
init
=
N
;
for
(
h
=
0
;
h
<
NHASH
;
h
++
)
for
(
s
=
hash
[
h
];
s
!=
S
;
s
=
s
->
link
)
{
if
(
s
->
name
[
0
]
!=
'i'
)
continue
;
if
(
strstr
(
s
->
name
,
"init"
)
==
nil
)
continue
;
if
(
strstr
(
s
->
name
,
"_function"
)
==
nil
)
{
if
(
strcmp
(
s
->
name
,
"init"
)
==
0
)
init
=
s
->
oname
;
continue
;
}
if
(
s
->
oname
==
N
)
continue
;
a
=
nod
(
OCALL
,
s
->
oname
,
N
);
r
=
list
(
r
,
a
);
}
// (6)
r
=
list
(
r
,
n
);
// (7)
if
(
init
!=
N
)
{
a
=
nod
(
OCALL
,
init
,
N
);
r
=
list
(
r
,
a
);
}
// (8)
a
=
nod
(
ORETURN
,
N
,
N
);
r
=
list
(
r
,
a
);
// (9)
a
=
nod
(
OEXPORT
,
N
,
N
);
a
->
sym
=
b
->
nname
->
sym
;
markexport
(
a
);
b
->
nbody
=
rev
(
r
);
//dump("b", b);
//dump("r", b->nbody);
popdcl
();
compile
(
b
);
}
src/cmd/gc/go.h
View file @
fb3af53f
...
...
@@ -542,6 +542,7 @@ Node* oldname(Sym*);
Type
*
newtype
(
Sym
*
);
Type
*
oldtype
(
Sym
*
);
Type
*
forwdcl
(
Sym
*
);
void
fninit
(
Node
*
);
/*
* export.c
...
...
src/cmd/gc/go.y
View file @
fb3af53f
...
...
@@ -66,6 +66,7 @@ file:
{
if
(
debug
[
'f'
])
frame
(
1
);
fninit
($
4
);
testdclstack
();
}
...
...
@@ -138,12 +139,17 @@ xdcl:
|
LEXPORT
export_list_r
{
markexport
(
rev
($
2
));
$$
=
N
;
}
|
LEXPORT
'('
export_list_r
')'
{
markexport
(
rev
($
3
));
$$
=
N
;
}
|
xfndcl
{
$$
=
N
;
}
|
';'
{
$$
=
N
;
...
...
@@ -168,9 +174,9 @@ Acommon_dcl:
}
|
LCONST
'('
constdcl_list_r
osemi
')'
{
$$
=
N
;
iota
=
0
;
lastconst
=
N
;
$$
=
N
;
}
|
LTYPE
Atypedcl
{
...
...
@@ -1089,7 +1095,7 @@ xdcl_list_r:
xdcl
|
xdcl_list_r
xdcl
{
$$
=
nod
(
OLIST
,
$
1
,
$
2
);
$$
=
list
(
$
1
,
$
2
);
}
vardcl_list_r
:
...
...
src/runtime/rt0_amd64.s
View file @
fb3af53f
...
...
@@ -33,6 +33,7 @@ TEXT _rt0_amd64(SB),7,$-8
MOVQ
24
(
SP
),
AX
//
copy
argv
MOVQ
AX
,
8
(
SP
)
CALL
args
(
SB
)
CALL
main
·
init_999_function
(
SB
)
//
initialization
//
create
a
new
goroutine
to
start
program
...
...
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