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
1d4daa2d
Commit
1d4daa2d
authored
Dec 08, 2008
by
Ken Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
foundation for import unsafe
R=r OCL=20794 CL=20794
parent
6478df1c
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
57 additions
and
25 deletions
+57
-25
src/cmd/6g/align.c
src/cmd/6g/align.c
+1
-1
src/cmd/gc/Makefile
src/cmd/gc/Makefile
+5
-2
src/cmd/gc/go.h
src/cmd/gc/go.h
+2
-1
src/cmd/gc/go.y
src/cmd/gc/go.y
+4
-2
src/cmd/gc/lex.c
src/cmd/gc/lex.c
+7
-5
src/cmd/gc/mksys.c
src/cmd/gc/mksys.c
+24
-13
src/cmd/gc/sys.go
src/cmd/gc/sys.go
+1
-1
src/cmd/gc/sysimport.c
src/cmd/gc/sysimport.c
+5
-0
src/cmd/gc/unsafe.go
src/cmd/gc/unsafe.go
+8
-0
No files found.
src/cmd/6g/align.c
View file @
1d4daa2d
...
@@ -203,7 +203,7 @@ typedefs[] =
...
@@ -203,7 +203,7 @@ typedefs[] =
{
{
"int"
,
TINT
,
TINT32
,
"int"
,
TINT
,
TINT32
,
"uint"
,
TUINT
,
TUINT32
,
"uint"
,
TUINT
,
TUINT32
,
"u
ptrint
"
,
TUINTPTR
,
TUINT64
,
"u
intptr
"
,
TUINTPTR
,
TUINT64
,
"float"
,
TFLOAT
,
TFLOAT32
,
"float"
,
TFLOAT
,
TFLOAT32
,
};
};
...
...
src/cmd/gc/Makefile
View file @
1d4daa2d
...
@@ -39,10 +39,13 @@ y.tab.h: $(YFILES)
...
@@ -39,10 +39,13 @@ y.tab.h: $(YFILES)
y.tab.c
:
y.tab.h
y.tab.c
:
y.tab.h
test
-f
y.tab.c
&&
touch
y.tab.c
test
-f
y.tab.c
&&
touch
y.tab.c
sysimport.c
:
sys.go mksys.c
sysimport.c
:
sys.go
unsafe.go
mksys.c
gcc
-o
mksys mksys.c
gcc
-o
mksys mksys.c
6g sys.go
6g sys.go
./mksys sys.6
>
_sysimport.c
&&
mv
_sysimport.c sysimport.c
6g unsafe.go
./mksys sys
>
_sysimport.c
&&
\
./mksys unsafe
>>
_sysimport.c
&&
\
mv
_sysimport.c sysimport.c
clean
:
clean
:
rm
-f
$(OFILES)
*
.6 enam.c 6.out a.out y.tab.h y.tab.c
$(LIB)
_sysimport.c
rm
-f
$(OFILES)
*
.6 enam.c 6.out a.out y.tab.h y.tab.c
$(LIB)
_sysimport.c
...
...
src/cmd/gc/go.h
View file @
1d4daa2d
...
@@ -467,6 +467,7 @@ EXTERN Sym* pkgmyname; // my name for package
...
@@ -467,6 +467,7 @@ EXTERN Sym* pkgmyname; // my name for package
EXTERN
Sym
*
pkgimportname
;
// package name from imported package
EXTERN
Sym
*
pkgimportname
;
// package name from imported package
EXTERN
int
tptr
;
// either TPTR32 or TPTR64
EXTERN
int
tptr
;
// either TPTR32 or TPTR64
extern
char
*
sysimport
;
extern
char
*
sysimport
;
extern
char
*
unsafeimport
;
EXTERN
char
*
filename
;
// name to uniqify names
EXTERN
char
*
filename
;
// name to uniqify names
EXTERN
void
(
*
dcladj
)(
Sym
*
);
// declaration is being exported/packaged
EXTERN
void
(
*
dcladj
)(
Sym
*
);
// declaration is being exported/packaged
...
@@ -535,7 +536,7 @@ int yyparse(void);
...
@@ -535,7 +536,7 @@ int yyparse(void);
int
mainlex
(
int
,
char
*
[]);
int
mainlex
(
int
,
char
*
[]);
void
setfilename
(
char
*
);
void
setfilename
(
char
*
);
void
importfile
(
Val
*
);
void
importfile
(
Val
*
);
void
cannedimports
(
void
);
void
cannedimports
(
char
*
,
char
*
);
void
unimportfile
();
void
unimportfile
();
int32
yylex
(
void
);
int32
yylex
(
void
);
void
lexinit
(
void
);
void
lexinit
(
void
);
...
...
src/cmd/gc/go.y
View file @
1d4daa2d
...
@@ -104,12 +104,12 @@ package:
...
@@ -104,12 +104,12 @@ package:
{
{
yyerror
(
"package statement must be first"
);
yyerror
(
"package statement must be first"
);
mkpackage
(
"main"
);
mkpackage
(
"main"
);
cannedimports
();
cannedimports
(
"sys.6"
,
sysimport
);
}
}
|
LPACKAGE
sym
|
LPACKAGE
sym
{
{
mkpackage
($
2
->
name
);
mkpackage
($
2
->
name
);
cannedimports
();
cannedimports
(
"sys.6"
,
sysimport
);
}
}
imports
:
imports
:
...
@@ -1086,6 +1086,8 @@ Bnon_fn_type:
...
@@ -1086,6 +1086,8 @@ Bnon_fn_type:
nametype
:
nametype
:
LATYPE
LATYPE
{
{
if
($
1
->
otype
!= T && $1->otype->etype == TANY)
yyerror
(
"the any type is restricted"
);
$$
=
oldtype
($
1
);
$$
=
oldtype
($
1
);
}
}
...
...
src/cmd/gc/lex.c
View file @
1d4daa2d
...
@@ -218,6 +218,11 @@ importfile(Val *f)
...
@@ -218,6 +218,11 @@ importfile(Val *f)
return
;
return
;
}
}
if
(
strcmp
(
f
->
u
.
sval
->
s
,
"unsafe"
)
==
0
)
{
cannedimports
(
"unsafe.6"
,
unsafeimport
);
return
;
}
if
(
!
findpkg
(
f
->
u
.
sval
))
if
(
!
findpkg
(
f
->
u
.
sval
))
fatal
(
"can't find import: %Z"
,
f
->
u
.
sval
);
fatal
(
"can't find import: %Z"
,
f
->
u
.
sval
);
imp
=
Bopen
(
namebuf
,
OREAD
);
imp
=
Bopen
(
namebuf
,
OREAD
);
...
@@ -277,11 +282,8 @@ unimportfile(void)
...
@@ -277,11 +282,8 @@ unimportfile(void)
}
}
void
void
cannedimports
(
void
)
cannedimports
(
char
*
file
,
char
*
cp
)
{
{
char
*
file
;
file
=
"sys.6"
;
lineno
++
;
// if sys.6 is included on line 1,
lineno
++
;
// if sys.6 is included on line 1,
linehist
(
file
,
0
);
// the debugger gets confused
linehist
(
file
,
0
);
// the debugger gets confused
...
@@ -290,7 +292,7 @@ cannedimports(void)
...
@@ -290,7 +292,7 @@ cannedimports(void)
curio
.
peekc
=
0
;
curio
.
peekc
=
0
;
curio
.
peekc1
=
0
;
curio
.
peekc1
=
0
;
curio
.
infile
=
file
;
curio
.
infile
=
file
;
curio
.
cp
=
sysimport
;
curio
.
cp
=
cp
;
pkgmyname
=
S
;
pkgmyname
=
S
;
inimportsys
=
1
;
inimportsys
=
1
;
...
...
src/cmd/gc/mksys.c
View file @
1d4daa2d
...
@@ -13,15 +13,22 @@
...
@@ -13,15 +13,22 @@
int
int
main
(
int
argc
,
char
**
argv
)
main
(
int
argc
,
char
**
argv
)
{
{
char
*
name
;
FILE
*
fin
;
FILE
*
fin
;
char
buf
[
1024
],
*
p
,
*
q
;
char
buf
[
1024
],
initfunc
[
1024
],
*
p
,
*
q
;
if
(
argc
!=
2
)
{
if
(
argc
!=
2
)
{
fprintf
(
stderr
,
"usage: mksys sys.6
\n
"
);
fprintf
(
stderr
,
"usage: sys sys
\n
"
);
fprintf
(
stderr
,
"in file $1.6 s/PACKAGE/$1/
\n
"
);
exit
(
1
);
exit
(
1
);
}
}
if
((
fin
=
fopen
(
argv
[
1
],
"r"
))
==
NULL
)
{
fprintf
(
stderr
,
"open %s: %s
\n
"
,
argv
[
1
],
strerror
(
errno
));
name
=
argv
[
1
];
snprintf
(
initfunc
,
sizeof
(
initfunc
),
"init_%s_function"
,
name
);
snprintf
(
buf
,
sizeof
(
buf
),
"%s.6"
,
name
);
if
((
fin
=
fopen
(
buf
,
"r"
))
==
NULL
)
{
fprintf
(
stderr
,
"open %s: %s
\n
"
,
buf
,
strerror
(
errno
));
exit
(
1
);
exit
(
1
);
}
}
...
@@ -33,7 +40,7 @@ main(int argc, char **argv)
...
@@ -33,7 +40,7 @@ main(int argc, char **argv)
exit
(
1
);
exit
(
1
);
begin:
begin:
printf
(
"char *
sysimport =
\n
"
);
printf
(
"char *
%simport =
\n
"
,
name
);
// process imports, stopping at $$ that closes them
// process imports, stopping at $$ that closes them
while
(
fgets
(
buf
,
sizeof
buf
,
fin
)
!=
NULL
)
{
while
(
fgets
(
buf
,
sizeof
buf
,
fin
)
!=
NULL
)
{
...
@@ -45,17 +52,21 @@ begin:
...
@@ -45,17 +52,21 @@ begin:
for
(
p
=
buf
;
*
p
==
' '
||
*
p
==
'\t'
;
p
++
)
for
(
p
=
buf
;
*
p
==
' '
||
*
p
==
'\t'
;
p
++
)
;
;
// cut out decl of init_
sys
_function - it doesn't exist
// cut out decl of init_
$1
_function - it doesn't exist
if
(
strstr
(
buf
,
"init_sys_function"
))
if
(
strstr
(
buf
,
initfunc
))
continue
;
continue
;
// sys.go claims to be in package SYS to avoid
// sys.go claims to be in package PACKAGE to avoid
// conflicts during "6g sys.go". rename SYS to sys.
// conflicts during "6g sys.go". rename PACKAGE to $2.
for
(
q
=
p
;
*
q
;
q
++
)
printf
(
"
\t\"
"
);
if
(
memcmp
(
q
,
"SYS"
,
3
)
==
0
)
while
(
q
=
strstr
(
p
,
"PACKAGE"
))
{
memmove
(
q
,
"sys"
,
3
);
*
q
=
0
;
printf
(
"%s"
,
p
);
// up to the substitution
printf
(
"%s"
,
name
);
// the sub name
p
=
q
+
7
;
// continue with rest
}
printf
(
"
\t\"
%s
\\
n
\"\n
"
,
p
);
printf
(
"%s
\\
n
\"\n
"
,
p
);
}
}
fprintf
(
stderr
,
"did not find end of imports
\n
"
);
fprintf
(
stderr
,
"did not find end of imports
\n
"
);
exit
(
1
);
exit
(
1
);
...
...
src/cmd/gc/sys.go
View file @
1d4daa2d
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
// license that can be found in the LICENSE file.
// license that can be found in the LICENSE file.
package
SYS
// rename to avoid redeclaration errors
package
PACKAGE
export
func
mal
(
int32
)
*
any
;
export
func
mal
(
int32
)
*
any
;
export
func
breakpoint
();
export
func
breakpoint
();
...
...
src/cmd/gc/sysimport.c
View file @
1d4daa2d
...
@@ -79,3 +79,8 @@ char *sysimport =
...
@@ -79,3 +79,8 @@ char *sysimport =
"export func sys.semrelease (sema *int32)
\n
"
"export func sys.semrelease (sema *int32)
\n
"
"
\n
"
"
\n
"
"$$
\n
"
;
"$$
\n
"
;
char
*
unsafeimport
=
"package unsafe
\n
"
"export type unsafe.pointer *any
\n
"
"
\n
"
"$$
\n
"
;
src/cmd/gc/unsafe.go
0 → 100644
View file @
1d4daa2d
// 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
PACKAGE
export
type
pointer
*
any
;
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