1
0
mirror of https://github.com/golang/go synced 2024-11-25 15:17:58 -07:00

- switched most of existing Go code to new export syntax

- adjusted lang doc

R=r
DELTA=192  (26 added, 65 deleted, 101 changed)
OCL=13844
CL=13848
This commit is contained in:
Robert Griesemer 2008-08-04 17:17:59 -07:00
parent d28acc42ec
commit 2f4352a26d
25 changed files with 118 additions and 157 deletions

View File

@ -4,7 +4,7 @@ The Go Programming Language (DRAFT)
Robert Griesemer, Rob Pike, Ken Thompson Robert Griesemer, Rob Pike, Ken Thompson
---- ----
(July 22, 2008) (August 4, 2008)
This document is a semi-formal specification/proposal for a new This document is a semi-formal specification/proposal for a new
systems programming language. The document is under active systems programming language. The document is under active
@ -993,13 +993,34 @@ Literals
Declarations Declarations
---- ----
A declaration associates a name with a language entity such as a type, A declaration associates a name with a language entity such as a constant, type,
constant, variable, or function. variable, or function.
Declaration = ConstDecl | TypeDecl | VarDecl | FunctionDecl | ExportDecl . Declaration = [ "export" ] ( ConstDecl | TypeDecl | VarDecl | FunctionDecl ) .
Global declarations optionally may be marked for export with the reserved word
"export". Local declarations can never be exported.
All identifiers (and only those identifiers) declared in exported declarations
are made visible to clients of this package, that is other packages that import
this package.
If the declaration defines a type, the type structure is exported as well. In
particular, if the declaration defines a new "struct" or "interface" type,
all structure fields and all structure and interface methods are exported also.
export const pi float = 3.14159265
export func Parse(source string);
Note that at the moment the old-style export via ExportDecl is still supported.
TODO: Eventually we need to be able to restrict visibility of fields and methods.
(gri) The default should be no struct fields and methods are automatically exported.
TODO: specify range of visibility, scope rules. TODO: specify range of visibility, scope rules.
[OLD
Declaration = ConstDecl | TypeDecl | VarDecl | FunctionDecl | ExportDecl .
END]
Const declarations Const declarations
---- ----
@ -1018,7 +1039,7 @@ A constant declaration gives a name to the value of a constant expression.
) )
The constant expression may be omitted, in which case the expression is The constant expression may be omitted, in which case the expression is
the last expression used after the "const" keyword. If no such expression the last expression used after the reserved word "const". If no such expression
exists, the constant expression cannot be omitted. exists, the constant expression cannot be omitted.
Together with the 'iota' constant generator this permits light-weight Together with the 'iota' constant generator this permits light-weight
@ -1185,6 +1206,7 @@ the following holds:
t.next == nil t.next == nil
[OLD
Export declarations Export declarations
---- ----
@ -1213,6 +1235,7 @@ export directive.
TODO: complete this section TODO: complete this section
TODO: export as a mechanism for public and private struct fields? TODO: export as a mechanism for public and private struct fields?
END]
Expressions Expressions
@ -1293,7 +1316,7 @@ to call the function.
Other operators behave as in C. Other operators behave as in C.
The "iota" keyword is discussed in a later section. The reserved word "iota" is discussed in a later section.
Examples of primary expressions Examples of primary expressions
@ -1322,7 +1345,7 @@ Examples of general expressions
The nil value The nil value
---- ----
The keyword The reserved word
nil nil
represents the ``zero'' value for a pointer type or interface type. represents the ``zero'' value for a pointer type or interface type.
@ -1538,9 +1561,9 @@ elements.
The constant generator 'iota' The constant generator 'iota'
---- ----
Within a declaration, the keyword 'iota' represents successive Within a declaration, the reserved word 'iota' represents successive
elements of an integer sequence. elements of an integer sequence.
It is reset to zero whenever the keyword 'const' It is reset to zero whenever the reserved word 'const'
introduces a new declaration and increments as each identifier introduces a new declaration and increments as each identifier
is declared. For instance, 'iota' can be used to construct is declared. For instance, 'iota' can be used to construct
a set of related constants: a set of related constants:
@ -1854,7 +1877,7 @@ Switches provide multi-way execution.
There can be at most one default case in a switch statement. There can be at most one default case in a switch statement.
The "fallthrough" keyword indicates that the control should flow from The reserved word "fallthrough" indicates that the control should flow from
the end of this case clause to the first statement of the next clause. the end of this case clause to the first statement of the next clause.
The expressions do not need to be constants. They will The expressions do not need to be constants. They will

View File

@ -4,7 +4,7 @@
package vector package vector
export Vector, New; //export Vector, New;
/* /*
import vector "vector" import vector "vector"
@ -18,7 +18,7 @@ export Vector, New;
type Element interface { type Element interface {
} }
type Vector struct { export type Vector struct {
nalloc int; nalloc int;
nelem int; nelem int;
elem *[]Element; elem *[]Element;
@ -49,7 +49,7 @@ func is_pow10(i int) bool {
return false; return false;
} }
func New() *Vector { export func New() *Vector {
v := new(Vector); v := new(Vector);
v.nelem = 0; v.nelem = 0;
v.nalloc = 1; v.nalloc = 1;

View File

@ -39,12 +39,12 @@ package flag
import fmt "fmt" import fmt "fmt"
export Bool, Int, String //export Bool, Int, String
export Arg, NArg //export Arg, NArg
export Parse //export Parse
//export Flag.BVal BUG: variable exported but not defined: Flag.BVal //export Flag.BVal BUG: variable exported but not defined: Flag.BVal
//export Flag.SVal BUG: variable exported but not defined: Flag.SVal //export Flag.SVal BUG: variable exported but not defined: Flag.SVal
export Flag //export Flag
// BUG: ctoi, atoi, atob belong elsewhere // BUG: ctoi, atoi, atob belong elsewhere
func ctoi(c int64) int64 { func ctoi(c int64) int64 {
@ -275,7 +275,7 @@ type Value interface {
} }
// -- Flag structure (internal) // -- Flag structure (internal)
type Flag struct { export type Flag struct {
name string; name string;
usage string; usage string;
value Value; value Value;
@ -330,7 +330,7 @@ func New() *Flags {
var flags *Flags = New(); var flags *Flags = New();
func Arg(i int) string { export func Arg(i int) string {
i += flags.first_arg; i += flags.first_arg;
if i < 0 || i >= sys.argc() { if i < 0 || i >= sys.argc() {
return ""; return "";
@ -338,7 +338,7 @@ func Arg(i int) string {
return sys.argv(i) return sys.argv(i)
} }
func NArg() int32 { export func NArg() int32 {
return sys.argc() - flags.first_arg return sys.argc() - flags.first_arg
} }
@ -358,15 +358,15 @@ func Add(name string, value Value, usage string) *Flag {
return f; return f;
} }
func Bool(name string, value bool, p *bool, usage string) *Flag { export func Bool(name string, value bool, p *bool, usage string) *Flag {
return Add(name, NewBoolValue(value, p), usage); return Add(name, NewBoolValue(value, p), usage);
} }
func Int(name string, value int64, p *int64, usage string) *Flag { export func Int(name string, value int64, p *int64, usage string) *Flag {
return Add(name, NewIntValue(value, p), usage); return Add(name, NewIntValue(value, p), usage);
} }
func String(name, value string, p *string, usage string) *Flag { export func String(name, value string, p *string, usage string) *Flag {
return Add(name, NewStringValue(value, p), usage); return Add(name, NewStringValue(value, p), usage);
} }
@ -458,7 +458,7 @@ func (f *Flags) ParseOne(index int) (ok bool, next int)
return true, index + 1 return true, index + 1
} }
func Parse() { export func Parse() {
for i := 1; i < sys.argc(); { for i := 1; i < sys.argc(); {
ok, next := flags.ParseOne(i); ok, next := flags.ParseOne(i);
if next > 0 { if next > 0 {

View File

@ -13,7 +13,7 @@ package fmt
// import sys "sys" // import sys "sys"
export Fmt, New; //export Fmt, New;
const NByte = 64; const NByte = 64;
const NPows10 = 160; const NPows10 = 160;
@ -31,7 +31,7 @@ func init() {
} }
} }
type Fmt struct { export type Fmt struct {
buf string; buf string;
wid int; wid int;
wid_present bool; wid_present bool;
@ -53,7 +53,7 @@ func (f *Fmt) init() {
f.clearflags(); f.clearflags();
} }
func New() *Fmt { export func New() *Fmt {
f := new(Fmt); f := new(Fmt);
f.init(); f.init();
return f; return f;

View File

@ -6,8 +6,6 @@ package math
import math "math" import math "math"
export asin, acos
/* /*
* asin(arg) and acos(arg) return the arcsin, arccos, * asin(arg) and acos(arg) return the arcsin, arccos,
* respectively of their arguments. * respectively of their arguments.
@ -20,7 +18,7 @@ const
pio2 = .15707963267948966192313216e1 pio2 = .15707963267948966192313216e1
) )
func export func
asin(arg float64)float64 asin(arg float64)float64
{ {
var temp, x float64; var temp, x float64;
@ -49,7 +47,7 @@ asin(arg float64)float64
return temp; return temp;
} }
func export func
acos(arg float64)float64 acos(arg float64)float64
{ {
if(arg > 1 || arg < -1) { if(arg > 1 || arg < -1) {

View File

@ -4,8 +4,6 @@
package math package math
export atan
/* /*
* floating-point arctangent * floating-point arctangent
* *
@ -70,7 +68,7 @@ satan(arg float64) float64
* atan makes its argument positive and * atan makes its argument positive and
* calls the inner routine satan. * calls the inner routine satan.
*/ */
func export func
atan(arg float64) float64 atan(arg float64) float64
{ {

View File

@ -5,7 +5,6 @@
package math package math
import math "math" import math "math"
export atan2
/* /*
* atan2 discovers what quadrant the angle * atan2 discovers what quadrant the angle
@ -18,7 +17,7 @@ const
pi = .3141592653589793238462643383276e1; pi = .3141592653589793238462643383276e1;
) )
func export func
atan2(arg1, arg2 float64) float64 atan2(arg1, arg2 float64) float64
{ {
var x float64; var x float64;

View File

@ -5,7 +5,6 @@
package math package math
import math "math" import math "math"
export exp
/* /*
* exp returns the exponential func of its * exp returns the exponential func of its
@ -27,7 +26,7 @@ const
maxf = 10000; maxf = 10000;
) )
func export func
exp(arg float64) float64 exp(arg float64) float64
{ {
var x, fract, temp1, temp2, xsq float64; var x, fract, temp1, temp2, xsq float64;

View File

@ -4,9 +4,7 @@
package math package math
export fabs export func
func
fabs(arg float64) float64 fabs(arg float64) float64
{ {

View File

@ -4,14 +4,12 @@
package math package math
export floor, ceil
/* /*
* floor and ceil-- greatest integer <= arg * floor and ceil-- greatest integer <= arg
* (resp least >=) * (resp least >=)
*/ */
func export func
floor(arg float64) float64 floor(arg float64) float64
{ {
var fract, d float64; var fract, d float64;
@ -28,7 +26,7 @@ floor(arg float64) float64
return d; return d;
} }
func export func
ceil(arg float64) float64 ceil(arg float64) float64
{ {
return -floor(-arg); return -floor(-arg);

View File

@ -4,13 +4,11 @@
package math package math
export fmod
/* /*
* floating-point mod func without infinity or NaN checking * floating-point mod func without infinity or NaN checking
*/ */
func export func
fmod(x, y float64) float64 fmod(x, y float64) float64
{ {
var yexp, rexp int; var yexp, rexp int;

View File

@ -4,8 +4,6 @@
package math package math
export hypot
/* /*
* hypot -- sqrt(p*p + q*q), but overflows only if the result does. * hypot -- sqrt(p*p + q*q), but overflows only if the result does.
* See Cleve Moler and Donald Morrison, * See Cleve Moler and Donald Morrison,
@ -14,7 +12,7 @@ export hypot
* Vol. 27, Number 6, pp. 577-581, Nov. 1983 * Vol. 27, Number 6, pp. 577-581, Nov. 1983
*/ */
func export func
hypot(p, q float64) float64 hypot(p, q float64) float64
{ {
var r, s, pfac float64; var r, s, pfac float64;

View File

@ -4,8 +4,6 @@
package math package math
export log, log10
/* /*
* log returns the natural logarithm of its floating * log returns the natural logarithm of its floating
* point argument. * point argument.
@ -29,7 +27,7 @@ const
q2 = -.891110902798312337e1; q2 = -.891110902798312337e1;
) )
func export func
log(arg float64) float64 log(arg float64) float64
{ {
var x, z, zsq, temp float64; var x, z, zsq, temp float64;
@ -58,7 +56,7 @@ log(arg float64) float64
return temp; return temp;
} }
func export func
log10(arg float64) float64 log10(arg float64) float64
{ {

View File

@ -5,13 +5,12 @@
package math package math
import math "math" import math "math"
export pow
/* /*
arg1 ^ arg2 (exponentiation) arg1 ^ arg2 (exponentiation)
*/ */
func export func
pow(arg1,arg2 float64) float64 pow(arg1,arg2 float64) float64
{ {
var temp float64; var temp float64;

View File

@ -4,8 +4,6 @@
package math package math
export pow10
/* /*
* this table might overflow 127-bit exponent representations. * this table might overflow 127-bit exponent representations.
* in that case, truncate it after 1.0e38. * in that case, truncate it after 1.0e38.
@ -18,7 +16,7 @@ export pow10
const tabsize = 70; const tabsize = 70;
var tab[tabsize] float64; var tab[tabsize] float64;
func export func
pow10(e int) float64 pow10(e int) float64
{ {
if e < 0 { if e < 0 {

View File

@ -4,8 +4,6 @@
package math package math
export sin, cos
const const
( (
p0 = .1357884097877375669092680e8; p0 = .1357884097877375669092680e8;
@ -56,7 +54,7 @@ sinus(arg float64, quad int) float64
return temp1/temp2; return temp1/temp2;
} }
func export func
cos(arg float64) float64 cos(arg float64) float64
{ {
if arg < 0 { if arg < 0 {
@ -65,7 +63,7 @@ cos(arg float64) float64
return sinus(arg, 1); return sinus(arg, 1);
} }
func export func
sin(arg float64) float64 sin(arg float64) float64
{ {
return sinus(arg, 0); return sinus(arg, 0);

View File

@ -5,7 +5,6 @@
package math package math
import math "math" import math "math"
export sinh, cosh
/* /*
* sinh(arg) returns the hyperbolic sine of its floating- * sinh(arg) returns the hyperbolic sine of its floating-
@ -32,7 +31,7 @@ const
q2 = -0.173678953558233699533450911e+3; q2 = -0.173678953558233699533450911e+3;
) )
func export func
sinh(arg float64) float64 sinh(arg float64) float64
{ {
var temp, argsq float64; var temp, argsq float64;
@ -63,7 +62,7 @@ sinh(arg float64) float64
return temp; return temp;
} }
func export func
cosh(arg float64) float64 cosh(arg float64) float64
{ {
if arg < 0 { if arg < 0 {

View File

@ -4,8 +4,6 @@
package math package math
export sqrt
/* /*
* sqrt returns the square root of its floating * sqrt returns the square root of its floating
* point argument. Newton's method. * point argument. Newton's method.
@ -13,7 +11,7 @@ export sqrt
* calls frexp * calls frexp
*/ */
func export func
sqrt(arg float64) float64 sqrt(arg float64) float64
{ {
var x, temp float64; var x, temp float64;

View File

@ -4,8 +4,6 @@
package math package math
export tan
/* /*
* floating point tangent * floating point tangent
* Coefficients are #4285 from Hart & Cheney. (19.74D) * Coefficients are #4285 from Hart & Cheney. (19.74D)
@ -24,7 +22,7 @@ const
piu4 = .1273239544735162686151070107e+1; // 4/pi piu4 = .1273239544735162686151070107e+1; // 4/pi
) )
func export func
tan(arg float64) float64 tan(arg float64) float64
{ {
var temp, e, x, xsq float64; var temp, e, x, xsq float64;

View File

@ -5,7 +5,6 @@
package math package math
import math "math" import math "math"
export tanh
/* /*
* tanh(arg) computes the hyperbolic tangent of its floating * tanh(arg) computes the hyperbolic tangent of its floating
@ -15,7 +14,7 @@ export tanh
* would cause overflow improperly. * would cause overflow improperly.
*/ */
func export func
tanh(arg float64) float64 tanh(arg float64) float64
{ {
if arg < 0 { if arg < 0 {

View File

@ -9,6 +9,7 @@
*/ */
package rand package rand
/*
export export
srand // set rand state (int32) srand // set rand state (int32)
vrand // int64 63-bits vrand // int64 63-bits
@ -18,6 +19,7 @@ export
lnrand // int32 % (int32) lnrand // int32 % (int32)
nrand // int % (int) nrand // int % (int)
frand; // float64 >=0.0 <1.0 frand; // float64 >=0.0 <1.0
*/
const const
( (
@ -51,7 +53,7 @@ seedrand(x int32) int32
return x; return x;
} }
func export func
srand(seed int32) srand(seed int32)
{ {
rng_tap = 0; rng_tap = 0;
@ -81,7 +83,7 @@ srand(seed int32)
} }
} }
func export func
vrand() int64 vrand() int64
{ {
rng_tap--; rng_tap--;
@ -99,21 +101,21 @@ vrand() int64
return x; return x;
} }
func export func
lrand() int32 lrand() int32
{ {
x := vrand() & 0x7fffffff; x := vrand() & 0x7fffffff;
return int32(x); return int32(x);
} }
func export func
rand() int rand() int
{ {
x := vrand() & 0x7fff; x := vrand() & 0x7fff;
return int(x); return int(x);
} }
func export func
vnrand(n int64) int64 vnrand(n int64) int64
{ {
var v,slop int64; var v,slop int64;
@ -124,21 +126,21 @@ vnrand(n int64) int64
return v % n; return v % n;
} }
func export func
lnrand(n int32) int32 lnrand(n int32) int32
{ {
v := vnrand(int64(n)); v := vnrand(int64(n));
return int32(v); return int32(v);
} }
func export func
nrand(n int) int nrand(n int) int
{ {
v := vnrand(int64(n)); v := vnrand(int64(n));
return int(v); return int(v);
} }
func export func
frand() float64 frand() float64
{ {
var x float64; var x float64;

View File

@ -7,12 +7,10 @@ package Integer
const ValueLen = 1000; const ValueLen = 1000;
type Word uint32 type Word uint32
type Value *[ValueLen]Word type Value *[ValueLen]Word
type IntegerImpl struct { export type IntegerImpl struct {
val Value val Value
} }
type Integer *IntegerImpl export type Integer *IntegerImpl
export IntegerImpl, Integer
const N = 4; const N = 4;
const H = 1 const H = 1
@ -458,14 +456,12 @@ func tostring(x Value) string {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Creation // Creation
export FromInt export func FromInt(v int) Integer {
func FromInt(v int) Integer {
return new(IntegerImpl).Init(make(v)); return new(IntegerImpl).Init(make(v));
} }
export FromString export func FromString(s string) Integer {
func FromString(s string) Integer {
return new(IntegerImpl).Init(make_from_string(s)); return new(IntegerImpl).Init(make_from_string(s));
} }
@ -613,8 +609,7 @@ func (x Integer) geq (y Integer) bool {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Specials // Specials
export Fact export func Fact(n int) Integer {
func Fact(n int) Integer {
return new(IntegerImpl).Init(fact(n)); return new(IntegerImpl).Init(fact(n));
} }

View File

@ -8,10 +8,10 @@ package syscall
import syscall "syscall" import syscall "syscall"
export Stat //export Stat
export stat, fstat, lstat //export stat, fstat, lstat
export open, creat, close, read, write, pipe //export open, creat, close, read, write, pipe
export unlink //export unlink
func StatToInt(s *Stat) int64; func StatToInt(s *Stat) int64;
@ -31,7 +31,7 @@ type Timespec struct {
tv_nsec int64; tv_nsec int64;
} }
type Stat struct { export type Stat struct {
st_dev dev_t; /* ID of device containing file */ st_dev dev_t; /* ID of device containing file */
st_mode mode_t; /* protection */ st_mode mode_t; /* protection */
st_nlink nlink_t; /* number of hard links */ st_nlink nlink_t; /* number of hard links */
@ -65,51 +65,37 @@ const (
O_TRUNC = 0x400; O_TRUNC = 0x400;
) )
export ( export func open(name *byte, mode int64, flags int64) (ret int64, errno int64) {
O_RDONLY,
O_WRONLY,
O_RDWR,
O_APPEND,
O_ASYNC,
O_CREAT,
O_NOCTTY,
O_NONBLOCK,
O_NDELAY,
O_SYNC,
O_TRUNC
)
func open(name *byte, mode int64, flags int64) (ret int64, errno int64) {
const SYSOPEN = 5; const SYSOPEN = 5;
r1, r2, err := syscall.Syscall(SYSOPEN, AddrToInt(name), mode, flags); r1, r2, err := syscall.Syscall(SYSOPEN, AddrToInt(name), mode, flags);
return r1, err; return r1, err;
} }
func creat(name *byte, mode int64) (ret int64, errno int64) { export func creat(name *byte, mode int64) (ret int64, errno int64) {
const SYSOPEN = 5; const SYSOPEN = 5;
r1, r2, err := syscall.Syscall(SYSOPEN, AddrToInt(name), mode, O_CREAT|O_WRONLY|O_TRUNC); r1, r2, err := syscall.Syscall(SYSOPEN, AddrToInt(name), mode, O_CREAT|O_WRONLY|O_TRUNC);
return r1, err; return r1, err;
} }
func close(fd int64) (ret int64, errno int64) { export func close(fd int64) (ret int64, errno int64) {
const SYSCLOSE = 6; const SYSCLOSE = 6;
r1, r2, err := syscall.Syscall(SYSCLOSE, fd, 0, 0); r1, r2, err := syscall.Syscall(SYSCLOSE, fd, 0, 0);
return r1, err; return r1, err;
} }
func read(fd int64, buf *byte, nbytes int64) (ret int64, errno int64) { export func read(fd int64, buf *byte, nbytes int64) (ret int64, errno int64) {
const SYSREAD = 3; const SYSREAD = 3;
r1, r2, err := syscall.Syscall(SYSREAD, fd, AddrToInt(buf), nbytes); r1, r2, err := syscall.Syscall(SYSREAD, fd, AddrToInt(buf), nbytes);
return r1, err; return r1, err;
} }
func write(fd int64, buf *byte, nbytes int64) (ret int64, errno int64) { export func write(fd int64, buf *byte, nbytes int64) (ret int64, errno int64) {
const SYSWRITE = 4; const SYSWRITE = 4;
r1, r2, err := syscall.Syscall(SYSWRITE, fd, AddrToInt(buf), nbytes); r1, r2, err := syscall.Syscall(SYSWRITE, fd, AddrToInt(buf), nbytes);
return r1, err; return r1, err;
} }
func pipe(fds *[2]int64) (ret int64, errno int64) { export func pipe(fds *[2]int64) (ret int64, errno int64) {
const SYSPIPE = 42; const SYSPIPE = 42;
r1, r2, err := syscall.Syscall(SYSPIPE, 0, 0, 0); r1, r2, err := syscall.Syscall(SYSPIPE, 0, 0, 0);
if r1 < 0 { if r1 < 0 {
@ -120,25 +106,25 @@ func pipe(fds *[2]int64) (ret int64, errno int64) {
return 0, 0; return 0, 0;
} }
func stat(name *byte, buf *Stat) (ret int64, errno int64) { export func stat(name *byte, buf *Stat) (ret int64, errno int64) {
const SYSSTAT = 338; const SYSSTAT = 338;
r1, r2, err := syscall.Syscall(SYSSTAT, AddrToInt(name), StatToInt(buf), 0); r1, r2, err := syscall.Syscall(SYSSTAT, AddrToInt(name), StatToInt(buf), 0);
return r1, err; return r1, err;
} }
func lstat(name *byte, buf *Stat) (ret int64, errno int64) { export func lstat(name *byte, buf *Stat) (ret int64, errno int64) {
const SYSLSTAT = 340; const SYSLSTAT = 340;
r1, r2, err := syscall.Syscall(SYSLSTAT, AddrToInt(name), StatToInt(buf), 0); r1, r2, err := syscall.Syscall(SYSLSTAT, AddrToInt(name), StatToInt(buf), 0);
return r1, err; return r1, err;
} }
func fstat(fd int64, buf *Stat) (ret int64, errno int64) { export func fstat(fd int64, buf *Stat) (ret int64, errno int64) {
const SYSFSTAT = 339; const SYSFSTAT = 339;
r1, r2, err := syscall.Syscall(SYSFSTAT, fd, StatToInt(buf), 0); r1, r2, err := syscall.Syscall(SYSFSTAT, fd, StatToInt(buf), 0);
return r1, err; return r1, err;
} }
func unlink(name *byte) (ret int64, errno int64) { export func unlink(name *byte) (ret int64, errno int64) {
const SYSUNLINK = 10; const SYSUNLINK = 10;
r1, r2, err := syscall.Syscall(SYSUNLINK, AddrToInt(name), 0, 0); r1, r2, err := syscall.Syscall(SYSUNLINK, AddrToInt(name), 0, 0);
return r1, err; return r1, err;

View File

@ -8,10 +8,10 @@ package syscall
import syscall "syscall" import syscall "syscall"
export Stat //export Stat
export stat, fstat, lstat //export stat, fstat, lstat
export open, creat, close, read, write, pipe //export open, creat, close, read, write, pipe
export unlink //export unlink
func StatToInt(s *Stat) int64; func StatToInt(s *Stat) int64;
func Addr32ToInt(s *int32) int64; func Addr32ToInt(s *int32) int64;
@ -32,7 +32,7 @@ type Timespec struct {
tv_nsec int64; tv_nsec int64;
} }
type Stat struct { export type Stat struct {
st_dev dev_t; /* ID of device containing file */ st_dev dev_t; /* ID of device containing file */
st_ino ino_t; /* inode number */ st_ino ino_t; /* inode number */
st_nlink nlink_t; /* number of hard links */ st_nlink nlink_t; /* number of hard links */
@ -66,51 +66,37 @@ const (
O_TRUNC = 0x200; O_TRUNC = 0x200;
) )
export ( export func open(name *byte, mode int64, flags int64) (ret int64, errno int64) {
O_RDONLY,
O_WRONLY,
O_RDWR,
O_APPEND,
O_ASYNC,
O_CREAT,
O_NOCTTY,
O_NONBLOCK,
O_NDELAY,
O_SYNC,
O_TRUNC
)
func open(name *byte, mode int64, flags int64) (ret int64, errno int64) {
const SYSOPEN = 2; const SYSOPEN = 2;
r1, r2, err := syscall.Syscall(SYSOPEN, AddrToInt(name), mode, flags); r1, r2, err := syscall.Syscall(SYSOPEN, AddrToInt(name), mode, flags);
return r1, err; return r1, err;
} }
func creat(name *byte, mode int64) (ret int64, errno int64) { export func creat(name *byte, mode int64) (ret int64, errno int64) {
const SYSOPEN = 2; const SYSOPEN = 2;
r1, r2, err := syscall.Syscall(SYSOPEN, AddrToInt(name), mode, O_CREAT|O_WRONLY|O_TRUNC); r1, r2, err := syscall.Syscall(SYSOPEN, AddrToInt(name), mode, O_CREAT|O_WRONLY|O_TRUNC);
return r1, err; return r1, err;
} }
func close(fd int64) (ret int64, errno int64) { export func close(fd int64) (ret int64, errno int64) {
const SYSCLOSE = 3; const SYSCLOSE = 3;
r1, r2, err := syscall.Syscall(SYSCLOSE, fd, 0, 0); r1, r2, err := syscall.Syscall(SYSCLOSE, fd, 0, 0);
return r1, err; return r1, err;
} }
func read(fd int64, buf *byte, nbytes int64) (ret int64, errno int64) { export func read(fd int64, buf *byte, nbytes int64) (ret int64, errno int64) {
const SYSREAD = 0; const SYSREAD = 0;
r1, r2, err := syscall.Syscall(SYSREAD, fd, AddrToInt(buf), nbytes); r1, r2, err := syscall.Syscall(SYSREAD, fd, AddrToInt(buf), nbytes);
return r1, err; return r1, err;
} }
func write(fd int64, buf *byte, nbytes int64) (ret int64, errno int64) { export func write(fd int64, buf *byte, nbytes int64) (ret int64, errno int64) {
const SYSWRITE = 1; const SYSWRITE = 1;
r1, r2, err := syscall.Syscall(SYSWRITE, fd, AddrToInt(buf), nbytes); r1, r2, err := syscall.Syscall(SYSWRITE, fd, AddrToInt(buf), nbytes);
return r1, err; return r1, err;
} }
func pipe(fds *[2]int64) (ret int64, errno int64) { export func pipe(fds *[2]int64) (ret int64, errno int64) {
const SYSPIPE = 22; const SYSPIPE = 22;
var t [2] int32; var t [2] int32;
r1, r2, err := syscall.Syscall(SYSPIPE, Addr32ToInt(&t[0]), 0, 0); r1, r2, err := syscall.Syscall(SYSPIPE, Addr32ToInt(&t[0]), 0, 0);
@ -122,25 +108,25 @@ func pipe(fds *[2]int64) (ret int64, errno int64) {
return 0, 0; return 0, 0;
} }
func stat(name *byte, buf *Stat) (ret int64, errno int64) { export func stat(name *byte, buf *Stat) (ret int64, errno int64) {
const SYSSTAT = 4; const SYSSTAT = 4;
r1, r2, err := syscall.Syscall(SYSSTAT, AddrToInt(name), StatToInt(buf), 0); r1, r2, err := syscall.Syscall(SYSSTAT, AddrToInt(name), StatToInt(buf), 0);
return r1, err; return r1, err;
} }
func lstat(name *byte, buf *Stat) (ret int64, errno int64) { export func lstat(name *byte, buf *Stat) (ret int64, errno int64) {
const SYSLSTAT = 6; const SYSLSTAT = 6;
r1, r2, err := syscall.Syscall(SYSLSTAT, AddrToInt(name), StatToInt(buf), 0); r1, r2, err := syscall.Syscall(SYSLSTAT, AddrToInt(name), StatToInt(buf), 0);
return r1, err; return r1, err;
} }
func fstat(fd int64, buf *Stat) (ret int64, errno int64) { export func fstat(fd int64, buf *Stat) (ret int64, errno int64) {
const SYSFSTAT = 5; const SYSFSTAT = 5;
r1, r2, err := syscall.Syscall(SYSFSTAT, fd, StatToInt(buf), 0); r1, r2, err := syscall.Syscall(SYSFSTAT, fd, StatToInt(buf), 0);
return r1, err; return r1, err;
} }
func unlink(name *byte) (ret int64, errno int64) { export func unlink(name *byte) (ret int64, errno int64) {
const SYSUNLINK = 87; const SYSUNLINK = 87;
r1, r2, err := syscall.Syscall(SYSUNLINK, AddrToInt(name), 0, 0); r1, r2, err := syscall.Syscall(SYSUNLINK, AddrToInt(name), 0, 0);
return r1, err; return r1, err;

View File

@ -8,10 +8,6 @@ package syscall
* Foundation of system call interface. * Foundation of system call interface.
*/ */
func Syscall(trap int64, a1, a2, a3 int64) (r1, r2, err int64); export func Syscall(trap int64, a1, a2, a3 int64) (r1, r2, err int64);
func AddrToInt(b *byte) int64; export func AddrToInt(b *byte) int64;
export Syscall
export AddrToInt