"syscall";
)
-export type FD struct {
+type FD struct {
fildes int64; // file descriptor number
name string; // file name at Open time
}
return &FD{fd, name}
}
-export var (
+var (
Stdin = newFD(0, "/dev/stdin");
Stdout = newFD(1, "/dev/stdout");
Stderr = newFD(2, "/dev/stderr");
)
-export func Open(name string, mode int64, perm int64) (fd *FD, err *os.Error) {
+func Open(name string, mode int64, perm int64) (fd *FD, err *os.Error) {
r, e := syscall.Open(name, mode, perm);
return newFD(r, name), os.ErrnoToError(e)
}
package sort
-export type SortInterface interface {
+type SortInterface interface {
Len() int;
Less(i, j int) bool;
Swap(i, j int);
}
-export func Sort(data SortInterface) {
+func Sort(data SortInterface) {
for i := 1; i < data.Len(); i++ {
for j := i; j > 0 && data.Less(j, j-1); j-- {
data.Swap(j, j-1);
}
}
-export func IsSorted(data SortInterface) bool {
+func IsSorted(data SortInterface) bool {
n := data.Len();
for i := n - 1; i > 0; i-- {
if data.Less(i, i - 1) {
// Convenience types for common cases
-export type IntArray []int
+type IntArray []int
func (p IntArray) Len() int { return len(p); }
func (p IntArray) Less(i, j int) bool { return p[i] < p[j]; }
func (p IntArray) Swap(i, j int) { p[i], p[j] = p[j], p[i]; }
-export type FloatArray []float
+type FloatArray []float
func (p FloatArray) Len() int { return len(p); }
func (p FloatArray) Less(i, j int) bool { return p[i] < p[j]; }
func (p FloatArray) Swap(i, j int) { p[i], p[j] = p[j], p[i]; }
-export type StringArray []string
+type StringArray []string
func (p StringArray) Len() int { return len(p); }
func (p StringArray) Less(i, j int) bool { return p[i] < p[j]; }
// Convenience wrappers for common cases
-export func SortInts(a []int) { Sort(IntArray(a)); }
-export func SortFloats(a []float) { Sort(FloatArray(a)); }
-export func SortStrings(a []string) { Sort(StringArray(a)); }
+func SortInts(a []int) { Sort(IntArray(a)); }
+func SortFloats(a []float) { Sort(FloatArray(a)); }
+func SortStrings(a []string) { Sort(StringArray(a)); }
-export func IntsAreSorted(a []int) bool { return IsSorted(IntArray(a)); }
-export func FloatsAreSorted(a []float) bool { return IsSorted(FloatArray(a)); }
-export func StringsAreSorted(a []string) bool { return IsSorted(StringArray(a)); }
+func IntsAreSorted(a []int) bool { return IsSorted(IntArray(a)); }
+func FloatsAreSorted(a []float) bool { return IsSorted(FloatArray(a)); }
+func StringsAreSorted(a []string) bool { return IsSorted(StringArray(a)); }
// used by go programs
-export func Breakpoint();
+func Breakpoint();
-export func Reflect(i interface { }) (uint64, string, bool);
-export func Unreflect(uint64, string, bool) (ret interface { });
+func Reflect(i interface { }) (uint64, string, bool);
+func Unreflect(uint64, string, bool) (ret interface { });
-export var Args []string;
-export var Envs []string;
+var Args []string;
+var Envs []string;
-export func Frexp(float64) (float64, int); // break fp into exp,fract
-export func Ldexp(float64, int) float64; // make fp from exp,fract
-export func Modf(float64) (float64, float64); // break fp into double.double
-export func IsInf(float64, int) bool; // test for infinity
-export func IsNaN(float64) bool; // test for not-a-number
-export func Inf(int) float64; // return signed Inf
-export func NaN() float64; // return a NaN
-export func Float32bits(float32) uint32; // raw bits
-export func Float64bits(float64) uint64; // raw bits
-export func Float32frombits(uint32) float32; // raw bits
-export func Float64frombits(uint64) float64; // raw bits
+func Frexp(float64) (float64, int); // break fp into exp,fract
+func Ldexp(float64, int) float64; // make fp from exp,fract
+func Modf(float64) (float64, float64); // break fp into double.double
+func IsInf(float64, int) bool; // test for infinity
+func IsNaN(float64) bool; // test for not-a-number
+func Inf(int) float64; // return signed Inf
+func NaN() float64; // return a NaN
+func Float32bits(float32) uint32; // raw bits
+func Float64bits(float64) uint64; // raw bits
+func Float32frombits(uint32) float32; // raw bits
+func Float64frombits(uint64) float64; // raw bits
-export func Gosched();
-export func Goexit();
+func Gosched();
+func Goexit();
-export func BytesToRune(*byte, int, int) (int, int); // convert bytes to runes
-export func StringToRune(string, int) (int, int); // convert bytes to runes
+func BytesToRune(*byte, int, int) (int, int); // convert bytes to runes
+func StringToRune(string, int) (int, int); // convert bytes to runes
-export func Exit(int);
+func Exit(int);
-export func Caller(n int) (pc uint64, file string, line int, ok bool);
+func Caller(n int) (pc uint64, file string, line int, ok bool);
-export func SemAcquire(sema *int32);
-export func SemRelease(sema *int32);
+func SemAcquire(sema *int32);
+func SemRelease(sema *int32);
// results are packed again. For faster unpacking/packing, the base size
// in bits must be even.
-export type (
+type (
Digit uint64;
Digit2 uint32; // half-digits for division
)
}
-export func Dump(x []Digit) {
+func Dump(x []Digit) {
print("[", len(x), "]");
for i := len(x) - 1; i >= 0; i-- {
print(" ", x[i]);
// n, m len(x), len(y)
-export type Natural []Digit;
+type Natural []Digit;
var (
natZero Natural = Natural{};
// Creation
-export func Nat(x uint) Natural {
+func Nat(x uint) Natural {
switch x {
case 0: return natZero;
case 1: return natOne;
// Determines base (octal, decimal, hexadecimal) if base == 0.
// Returns the number and base.
-export func NatFromString(s string, base uint, slen *int) (Natural, uint) {
+func NatFromString(s string, base uint, slen *int) (Natural, uint) {
// determine base if necessary
i, n := 0, len(s);
if base == 0 {
}
-export func MulRange(a, b uint) Natural {
+func MulRange(a, b uint) Natural {
switch {
case a > b: return Nat(1);
case a == b: return Nat(a);
}
-export func Fact(n uint) Natural {
+func Fact(n uint) Natural {
// Using MulRange() instead of the basic for-loop
// lead to faster factorial computation.
return MulRange(2, n);
}
-export func Binomial(n, k uint) Natural {
+func Binomial(n, k uint) Natural {
return MulRange(n-k+1, n).Div(MulRange(1, k));
}
// Integers are normalized if the mantissa is normalized and the sign is
// false for mant == 0. Use MakeInt to create normalized Integers.
-export type Integer struct {
+type Integer struct {
sign bool;
mant Natural;
}
// Creation
-export func MakeInt(sign bool, mant Natural) *Integer {
+func MakeInt(sign bool, mant Natural) *Integer {
if mant.IsZero() {
sign = false; // normalize
}
}
-export func Int(x int) *Integer {
+func Int(x int) *Integer {
sign := false;
var ux uint;
if x < 0 {
// Determines base (octal, decimal, hexadecimal) if base == 0.
// Returns the number and base.
-export func IntFromString(s string, base uint, slen *int) (*Integer, uint) {
+func IntFromString(s string, base uint, slen *int) (*Integer, uint) {
// get sign, if any
sign := false;
if len(s) > 0 && (s[0] == '-' || s[0] == '+') {
// ----------------------------------------------------------------------------
// Rational numbers
-export type Rational struct {
+type Rational struct {
a *Integer; // numerator
b Natural; // denominator
}
// Creation
-export func MakeRat(a *Integer, b Natural) *Rational {
+func MakeRat(a *Integer, b Natural) *Rational {
f := a.mant.Gcd(b); // f > 0
if f.Cmp(Nat(1)) != 0 {
a = MakeInt(a.sign, a.mant.Div(f));
}
-export func Rat(a0 int, b0 int) *Rational {
+func Rat(a0 int, b0 int) *Rational {
a, b := Int(a0), Int(b0);
if b.sign {
a = a.Neg();
// Determines base (octal, decimal, hexadecimal) if base == 0.
// Returns the number and base of the nominator.
-export func RatFromString(s string, base uint, slen *int) (*Rational, uint) {
+func RatFromString(s string, base uint, slen *int) (*Rational, uint) {
// read nominator
var alen, blen int;
a, abase := IntFromString(s, base, &alen);
}
}
-export func TestNatConv(t *testing.T) {
+func TestNatConv(t *testing.T) {
tester = t;
test_msg = "NatConvA";
nat_eq(0, a, bignum.Nat(991));
}
-export func TestIntConv(t *testing.T) {
+func TestIntConv(t *testing.T) {
tester = t;
test_msg = "IntConv";
var slen int;
}
-export func TestRatConv(t *testing.T) {
+func TestRatConv(t *testing.T) {
tester = t;
test_msg = "RatConv";
var slen int;
}
-export func TestNatAdd(t *testing.T) {
+func TestNatAdd(t *testing.T) {
tester = t;
test_msg = "NatAddA";
nat_eq(0, add(nat_zero, nat_zero), nat_zero);
}
-export func TestNatSub(t *testing.T) {
+func TestNatSub(t *testing.T) {
tester = t;
test_msg = "NatSubA";
nat_eq(0, nat_zero.Sub(nat_zero), nat_zero);
}
-export func TestNatMul(t *testing.T) {
+func TestNatMul(t *testing.T) {
tester = t;
test_msg = "NatMulA";
nat_eq(0, mul(c, nat_zero), nat_zero);
}
-export func TestNatDiv(t *testing.T) {
+func TestNatDiv(t *testing.T) {
tester = t;
test_msg = "NatDivA";
nat_eq(0, c.Div(nat_one), c);
}
-export func TestIntQuoRem(t *testing.T) {
+func TestIntQuoRem(t *testing.T) {
tester = t;
test_msg = "IntQuoRem";
type T struct { x, y, q, r int };
}
-export func TestIntDivMod(t *testing.T) {
+func TestIntDivMod(t *testing.T) {
tester = t;
test_msg = "IntDivMod";
type T struct { x, y, q, r int };
}
-export func TestNatMod(t *testing.T) {
+func TestNatMod(t *testing.T) {
tester = t;
test_msg = "NatModA";
for i := uint(0); ; i++ {
}
-export func TestNatShift(t *testing.T) {
+func TestNatShift(t *testing.T) {
tester = t;
test_msg = "NatShift1L";
test(0, b.Shl(0).Cmp(b) == 0);
}
-export func TestIntShift(t *testing.T) {
+func TestIntShift(t *testing.T) {
tester = t;
test_msg = "IntShift1L";
test(0, ip.Shl(0).Cmp(ip) == 0);
}
-export func TestNatCmp(t *testing.T) {
+func TestNatCmp(t *testing.T) {
tester = t;
test_msg = "NatCmp";
test(0, a.Cmp(a) == 0);
}
-export func TestNatLog2(t *testing.T) {
+func TestNatLog2(t *testing.T) {
tester = t;
test_msg = "NatLog2A";
test(0, nat_one.Log2() == 0);
test(1, nat_two.Log2() == 1);
test(2, bignum.Nat(3).Log2() == 1);
test(3, bignum.Nat(4).Log2() == 2);
-
+
test_msg = "NatLog2B";
for i := uint(0); i < 100; i++ {
test(i, nat_one.Shl(i).Log2() == i);
}
-export func TestNatGcd(t *testing.T) {
+func TestNatGcd(t *testing.T) {
tester = t;
test_msg = "NatGcdA";
f := bignum.Nat(99991);
}
-export func TestNatPow(t *testing.T) {
+func TestNatPow(t *testing.T) {
tester = t;
test_msg = "NatPowA";
nat_eq(0, nat_two.Pow(0), nat_one);
}
-export func TestNatPop(t *testing.T) {
+func TestNatPop(t *testing.T) {
tester = t;
test_msg = "NatPopA";
test(0, nat_zero.Pop() == 0);
defaultBufSize = 4096
)
-export var (
+var (
EndOfFile = os.NewError("end of file");
PhaseError = os.NewError("phase error");
BufferFull = os.NewError("buffer full");
// Buffered input.
-export type BufRead struct {
+type BufRead struct {
buf []byte;
rd io.Read;
r, w int;
err *os.Error;
}
-export func NewBufReadSize(rd io.Read, size int) (b *BufRead, err *os.Error) {
+func NewBufReadSize(rd io.Read, size int) (b *BufRead, err *os.Error) {
if size <= 0 {
return nil, BadBufSize
}
return b, nil
}
-export func NewBufRead(rd io.Read) (b *BufRead, err *os.Error) {
+func NewBufRead(rd io.Read) (b *BufRead, err *os.Error) {
return NewBufReadSize(rd, defaultBufSize);
}
// buffered output
-export type BufWrite struct {
+type BufWrite struct {
err *os.Error;
buf []byte;
n int;
wr io.Write;
}
-export func NewBufWriteSize(wr io.Write, size int) (b *BufWrite, err *os.Error) {
+func NewBufWriteSize(wr io.Write, size int) (b *BufWrite, err *os.Error) {
if size <= 0 {
return nil, BadBufSize
}
return b, nil
}
-export func NewBufWrite(wr io.Write) (b *BufWrite, err *os.Error) {
+func NewBufWrite(wr io.Write) (b *BufWrite, err *os.Error) {
return NewBufWriteSize(wr, defaultBufSize);
}
23, 32, 46, 64, 93, 128, 1024, 4096
}
-export func TestBufReadSimple(t *testing.T) {
+func TestBufReadSimple(t *testing.T) {
b, e := NewBufRead(newByteReader(io.StringBytes("hello world")));
if s := readBytes(b); s != "hello world" {
t.Errorf("simple hello world test failed: got %q", s);
}
}
-export func TestBufRead(t *testing.T) {
+func TestBufRead(t *testing.T) {
var texts [31]string;
str := "";
all := "";
name string;
fn *()writeBuffer;
}
-export func TestBufWrite(t *testing.T) {
+func TestBufWrite(t *testing.T) {
var data [8192]byte;
var writers = []writeMaker {
package array
-export type Element interface {
+type Element interface {
}
-export type Array struct {
+type Array struct {
// TODO do not export field
a []Element
}
}
-export func New(len int) *Array {
+func New(len int) *Array {
return new(Array).Init(len)
}
// Partial SortInterface support
-export type LessInterface interface {
+type LessInterface interface {
Less(y Element) bool
}
import "sort"
-export func TestInit(t *testing.T) {
+func TestInit(t *testing.T) {
var a array.Array;
if a.Init(0).Len() != 0 { t.Error("A") }
if a.Init(1).Len() != 1 { t.Error("B") }
}
-export func TestNew(t *testing.T) {
+func TestNew(t *testing.T) {
if array.New(0).Len() != 0 { t.Error("A") }
if array.New(1).Len() != 1 { t.Error("B") }
if array.New(10).Len() != 10 { t.Error("C") }
}
-export func Val(i int) int {
+func Val(i int) int {
return i*991 - 1234
}
-export func TestAccess(t *testing.T) {
+func TestAccess(t *testing.T) {
const n = 100;
var a array.Array;
a.Init(n);
}
-export func TestInsertRemoveClear(t *testing.T) {
+func TestInsertRemoveClear(t *testing.T) {
const n = 100;
a := array.New(0);
/* currently doesn't compile due to linker bug
-export func TestSorting(t *testing.T) {
+func TestSorting(t *testing.T) {
const n = 100;
a := array.NewIntArray(n);
for i := n-1; i >= 0; i-- {
import "array"
-export type IntArray struct {
+type IntArray struct {
// TODO do not export field
array.Array;
}
}
-export func NewIntArray(len int) *IntArray {
+func NewIntArray(len int) *IntArray {
return new(IntArray).Init(len)
}
}
// -- Flag structure (internal)
-export type Flag struct {
+type Flag struct {
name string;
usage string;
value _Value;
var flags *allFlags = &allFlags{make(map[string] *Flag), make(map[string] *Flag), 1}
-export func PrintDefaults() {
+func PrintDefaults() {
for k, f := range flags.formal {
print(" -", f.name, "=", f.value.str(), ": ", f.usage, "\n");
}
}
-export func Usage() {
+func Usage() {
if len(sys.Args) > 0 {
print("Usage of ", sys.Args[0], ": \n");
} else {
sys.Exit(1);
}
-export func NFlag() int {
+func NFlag() int {
return len(flags.actual)
}
-export func Arg(i int) string {
+func Arg(i int) string {
i += flags.first_arg;
if i < 0 || i >= len(sys.Args) {
return "";
return sys.Args[i]
}
-export func NArg() int {
+func NArg() int {
return len(sys.Args) - flags.first_arg
}
flags.formal[name] = f;
}
-export func Bool(name string, value bool, usage string) *bool {
+func Bool(name string, value bool, usage string) *bool {
p := new(bool);
add(name, newBoolValue(value, p), usage);
return p;
}
-export func BoolVar(p *bool, name string, value bool, usage string) {
+func BoolVar(p *bool, name string, value bool, usage string) {
add(name, newBoolValue(value, p), usage);
}
-export func Int(name string, value int, usage string) *int {
+func Int(name string, value int, usage string) *int {
p := new(int);
add(name, newIntValue(value, p), usage);
return p;
}
-export func IntVar(p *int, name string, value int, usage string) {
+func IntVar(p *int, name string, value int, usage string) {
add(name, newIntValue(value, p), usage);
}
-export func Int64(name string, value int64, usage string) *int64 {
+func Int64(name string, value int64, usage string) *int64 {
p := new(int64);
add(name, newInt64Value(value, p), usage);
return p;
}
-export func Int64Var(p *int64, name string, value int64, usage string) {
+func Int64Var(p *int64, name string, value int64, usage string) {
add(name, newInt64Value(value, p), usage);
}
-export func Uint(name string, value uint, usage string) *uint {
+func Uint(name string, value uint, usage string) *uint {
p := new(uint);
add(name, newUintValue(value, p), usage);
return p;
}
-export func UintVar(p *uint, name string, value uint, usage string) {
+func UintVar(p *uint, name string, value uint, usage string) {
add(name, newUintValue(value, p), usage);
}
-export func Uint64(name string, value uint64, usage string) *uint64 {
+func Uint64(name string, value uint64, usage string) *uint64 {
p := new(uint64);
add(name, newUint64Value(value, p), usage);
return p;
}
-export func Uint64Var(p *uint64, name string, value uint64, usage string) {
+func Uint64Var(p *uint64, name string, value uint64, usage string) {
add(name, newUint64Value(value, p), usage);
}
-export func String(name, value string, usage string) *string {
+func String(name, value string, usage string) *string {
p := new(string);
add(name, newStringValue(value, p), usage);
return p;
}
-export func StringVar(p *string, name, value string, usage string) {
+func StringVar(p *string, name, value string, usage string) {
add(name, newStringValue(value, p), usage);
}
return true, index + 1
}
-export func Parse() {
+func Parse() {
for i := 1; i < len(sys.Args); {
ok, next := flags.ParseOne(i);
if next > 0 {
"testing";
)
-export func TestFmtInterface(t *testing.T) {
+func TestFmtInterface(t *testing.T) {
var i1 interface{};
i1 = "abc";
s := fmt.Sprintf("%s", i1);
fmtTest{ "%20g", sys.NaN(), " NaN" },
}
-export func TestSprintf(t *testing.T) {
+func TestSprintf(t *testing.T) {
for i := 0; i < len(fmttests); i++ {
tt := fmttests[i];
s := fmt.Sprintf(tt.fmt, tt.val);
flagTest{ "%-1.2abc", "[%-1.2a]bc" },
}
-export func TestFlagParser(t *testing.T) {
+func TestFlagParser(t *testing.T) {
var flagprinter flagPrinter;
for i := 0; i < len(flagtests); i++ {
tt := flagtests[i];
}
}
-export func TestStructPrinter(t *testing.T) {
+func TestStructPrinter(t *testing.T) {
var s struct {
a string;
b string;
}
}
-export func TestArrayPrinter(t *testing.T) {
+func TestArrayPrinter(t *testing.T) {
a := []int{1, 2, 3, 4, 5};
want := "[1 2 3 4 5]";
out := fmt.Sprintf("%v", a);
}
}
-export type Fmt struct {
+type Fmt struct {
buf string;
wid int;
wid_present bool;
f.clearflags();
}
-export func New() *Fmt {
+func New() *Fmt {
f := new(Fmt);
f.init();
return f;
// Representation of printer state passed to custom formatters.
// Provides access to the io.Write interface plus information about
// the active formatting verb.
-export type Formatter interface {
+type Formatter interface {
Write(b []byte) (ret int, err *os.Error);
Width() (wid int, ok bool);
Precision() (prec int, ok bool);
Flag(int) bool;
}
-export type Format interface {
+type Format interface {
Format(f Formatter, c int);
}
-export type String interface {
+type String interface {
String() string
}
// These routines end in 'f' and take a format string.
-export func Fprintf(w io.Write, format string, a ...) (n int, error *os.Error) {
+func Fprintf(w io.Write, format string, a ...) (n int, error *os.Error) {
v := reflect.NewValue(a).(reflect.PtrValue).Sub().(reflect.StructValue);
p := newPrinter();
p.doprintf(format, v);
return n, error;
}
-export func Printf(format string, v ...) (n int, errno *os.Error) {
+func Printf(format string, v ...) (n int, errno *os.Error) {
n, errno = Fprintf(os.Stdout, format, v);
return n, errno;
}
-export func Sprintf(format string, a ...) string {
+func Sprintf(format string, a ...) string {
v := reflect.NewValue(a).(reflect.PtrValue).Sub().(reflect.StructValue);
p := newPrinter();
p.doprintf(format, v);
// These routines do not take a format string and add spaces only
// when the operand on neither side is a string.
-export func Fprint(w io.Write, a ...) (n int, error *os.Error) {
+func Fprint(w io.Write, a ...) (n int, error *os.Error) {
v := reflect.NewValue(a).(reflect.PtrValue).Sub().(reflect.StructValue);
p := newPrinter();
p.doprint(v, false, false);
return n, error;
}
-export func Print(v ...) (n int, errno *os.Error) {
+func Print(v ...) (n int, errno *os.Error) {
n, errno = Fprint(os.Stdout, v);
return n, errno;
}
-export func Sprint(a ...) string {
+func Sprint(a ...) string {
v := reflect.NewValue(a).(reflect.PtrValue).Sub().(reflect.StructValue);
p := newPrinter();
p.doprint(v, false, false);
// always add spaces between operands, and add a newline
// after the last operand.
-export func Fprintln(w io.Write, a ...) (n int, error *os.Error) {
+func Fprintln(w io.Write, a ...) (n int, error *os.Error) {
v := reflect.NewValue(a).(reflect.PtrValue).Sub().(reflect.StructValue);
p := newPrinter();
p.doprint(v, true, true);
return n, error;
}
-export func Println(v ...) (n int, errno *os.Error) {
+func Println(v ...) (n int, errno *os.Error) {
n, errno = Fprintln(os.Stdout, v);
return n, errno;
}
-export func Sprintln(a ...) string {
+func Sprintln(a ...) string {
v := reflect.NewValue(a).(reflect.PtrValue).Sub().(reflect.StructValue);
p := newPrinter();
p.doprint(v, true, true);
import "os"
-export type Digest struct {
+type Digest struct {
a, b uint32;
n int;
}
_MaxIter = 5552; // max mod-free iterations before would overflow uint32
)
-export func NewDigest() *Digest {
+func NewDigest() *Digest {
return &Digest{1, 0, 0};
}
_Adler32Test{ 0x2e5d1316, "How can you write a big system without C++? -Paul Glick" },
}
-export func TestGolden(t *testing.T) {
+func TestGolden(t *testing.T) {
for i := 0; i < len(golden); i++ {
g := golden[i];
c := NewDigest();
import "os"
-export const (
+const (
// Far and away the most common CRC-32 polynomial.
// Used by ethernet (IEEE 802.3), v.42, fddi, gzip, zip, png, mpeg-2, ...
IEEE = 0xedb88320;
)
// TODO(rsc): Change to [256]uint32 once 6g can handle it.
-export type Table []uint32
+type Table []uint32
-export func MakeTable(poly uint32) Table {
+func MakeTable(poly uint32) Table {
t := make(Table, 256);
for i := 0; i < 256; i++ {
crc := uint32(i);
return t;
}
-export var IEEETable = MakeTable(IEEE);
+var IEEETable = MakeTable(IEEE);
-export type Digest struct {
+type Digest struct {
crc uint32;
tab Table;
}
-export func NewDigest(tab Table) *Digest {
+func NewDigest(tab Table) *Digest {
return &Digest{0, tab};
}
-export func NewIEEEDigest() *Digest {
+func NewIEEEDigest() *Digest {
return NewDigest(IEEETable);
}
_Crc32Test{ 0x8e0bb443, "How can you write a big system without C++? -Paul Glick" },
}
-export func TestGolden(t *testing.T) {
+func TestGolden(t *testing.T) {
for i := 0; i < len(golden); i++ {
g := golden[i];
c := NewIEEEDigest();
_Init3 = 0x10325476;
)
-export type Digest struct {
+type Digest struct {
s [4]uint32;
x [_Chunk]byte;
nx int;
len uint64;
}
-export func NewDigest() *Digest {
+func NewDigest() *Digest {
d := new(Digest);
d.s[0] = _Init0;
d.s[1] = _Init1;
md5Test{ "132f7619d33b523b1d9e5bd8e0928355", "How can you write a big system without C++? -Paul Glick" },
}
-export func TestGolden(t *testing.T) {
+func TestGolden(t *testing.T) {
for i := 0; i < len(golden); i++ {
g := golden[i];
c := NewDigest();
_Init4 = 0xC3D2E1F0;
)
-export type Digest struct {
+type Digest struct {
h [5]uint32;
x [_Chunk]byte;
nx int;
len uint64;
}
-export func NewDigest() *Digest {
+func NewDigest() *Digest {
d := new(Digest);
d.h[0] = _Init0;
d.h[1] = _Init1;
sha1Test{ "6627d6904d71420b0bf3886ab629623538689f45", "How can you write a big system without C++? -Paul Glick" },
}
-export func TestGolden(t *testing.T) {
+func TestGolden(t *testing.T) {
for i := 0; i < len(golden); i++ {
g := golden[i];
c := NewDigest();
)
// Active HTTP connection (server side).
-export type Conn struct {
+type Conn struct {
rwc io.ReadWriteClose;
br *bufio.BufRead;
bw *bufio.BufWrite;
}
// Create new connection from rwc.
-export func NewConn(rwc io.ReadWriteClose) (c *Conn, err *os.Error) {
+func NewConn(rwc io.ReadWriteClose) (c *Conn, err *os.Error) {
c = new(Conn);
c.rwc = rwc;
if c.br, err = bufio.NewBufRead(rwc); err != nil {
_MaxHeaderLines = 1024;
)
-export var (
+var (
LineTooLong = os.NewError("http header line too long");
ValueTooLong = os.NewError("http header value too long");
HeaderTooLong = os.NewError("http header too long");
)
// HTTP Request
-export type Request struct {
+type Request struct {
method string; // GET, PUT,etc.
rawurl string;
url *URL; // URI after GET, PUT etc.
}
// Read and parse a request from b.
-export func ReadRequest(b *bufio.BufRead) (req *Request, err *os.Error) {
+func ReadRequest(b *bufio.BufRead) (req *Request, err *os.Error) {
req = new(Request);
// First line: GET /index.html HTTP/1.0
}
// Web server: already listening on l, call f for each request.
-export func Serve(l net.Listener, f *(*Conn, *Request)) *os.Error {
+func Serve(l net.Listener, f *(*Conn, *Request)) *os.Error {
// TODO: Make this unnecessary
s, e := os.Getenv("GOMAXPROCS");
if n, ok := strconv.Atoi(s); n < 3 {
}
// Web server: listen on address, call f for each request.
-export func ListenAndServe(addr string, f *(*Conn, *Request)) *os.Error {
+func ListenAndServe(addr string, f *(*Conn, *Request)) *os.Error {
l, e := net.Listen("tcp", addr);
if e != nil {
return e
"strings"
)
-export var (
+var (
BadURL = os.NewError("bad url syntax")
)
}
// Unescape %xx into hex.
-export func URLUnescape(s string) (string, *os.Error) {
+func URLUnescape(s string) (string, *os.Error) {
// Count %, check that they're well-formed.
n := 0;
for i := 0; i < len(s); {
return string(t), nil;
}
-export type URL struct {
+type URL struct {
raw string;
scheme string;
rawpath string;
}
// Parse rawurl into a URL structure.
-export func ParseURL(rawurl string) (url *URL, err *os.Error) {
+func ParseURL(rawurl string) (url *URL, err *os.Error) {
if rawurl == "" {
return nil, BadURL
}
}
// A URL reference is a URL with #frag potentially added. Parse it.
-export func ParseURLReference(rawurlref string) (url *URL, err *os.Error) {
+func ParseURLReference(rawurlref string) (url *URL, err *os.Error) {
// Cut off #frag.
rawurl, frag := split(rawurlref, '#', true);
if url, err = ParseURL(rawurl); err != nil {
}
}
-export type ByteBuffer struct {
+type ByteBuffer struct {
buf []byte;
off int; // Read from here
len int; // Write to here
return b.buf[0:b.len]
}
-
-export func NewByteBufferFromArray(buf []byte) *ByteBuffer {
+func NewByteBufferFromArray(buf []byte) *ByteBuffer {
b := new(ByteBuffer);
b.buf = buf;
b.off = 0;
"syscall";
)
-export var ErrEOF = os.NewError("EOF")
+var ErrEOF = os.NewError("EOF")
-export type Read interface {
+type Read interface {
Read(p []byte) (n int, err *os.Error);
}
-export type Write interface {
+type Write interface {
Write(p []byte) (n int, err *os.Error);
}
-export type ReadWrite interface {
+type ReadWrite interface {
Read(p []byte) (n int, err *os.Error);
Write(p []byte) (n int, err *os.Error);
}
-export type ReadWriteClose interface {
+type ReadWriteClose interface {
Read(p []byte) (n int, err *os.Error);
Write(p []byte) (n int, err *os.Error);
Close() *os.Error;
}
-export func WriteString(w Write, s string) (n int, err *os.Error) {
+func WriteString(w Write, s string) (n int, err *os.Error) {
b := make([]byte, len(s)+1);
if !syscall.StringToBytes(b, s) {
return -1, os.EINVAL
}
// Read until buffer is full, EOF, or error
-export func Readn(fd Read, buf []byte) (n int, err *os.Error) {
+func Readn(fd Read, buf []byte) (n int, err *os.Error) {
n = 0;
for n < len(buf) {
nn, e := fd.Read(buf[n:len(buf)]);
return n, err
}
-export func Make_FullReader(fd Read) Read {
+func Make_FullReader(fd Read) Read {
if fr, ok := fd.(*_FullRead); ok {
// already a _FullRead
return fd
// Copies n bytes (or until EOF is reached) from src to dst.
// Returns the number of bytes copied and the error, if any.
-export func Copyn(src Read, dst Write, n int64) (written int64, err *os.Error) {
+func Copyn(src Read, dst Write, n int64) (written int64, err *os.Error) {
buf := make([]byte, 32*1024);
for written < n {
l := len(buf);
// Copies from src to dst until EOF is reached.
// Returns the number of bytes copied and the error, if any.
-export func Copy(src Read, dst Write) (written int64, err *os.Error) {
+func Copy(src Read, dst Write) (written int64, err *os.Error) {
buf := make([]byte, 32*1024);
for {
nr, er := src.Read(buf);
// Convert a string to an array of bytes for easy marshaling.
// Could fill with syscall.StringToBytes but it adds an unnecessary \000
// so the length would be wrong.
-export func StringBytes(s string) []byte {
+func StringBytes(s string) []byte {
b := make([]byte, len(s));
for i := 0; i < len(s); i++ {
b[i] = s[i];
"strings";
)
-export const (
+const (
StringKind = iota;
NumberKind;
MapKind; // JSON term is "Object", but in Go, it's a map
NullKind;
)
-export type Json interface {
+type Json interface {
Kind() int;
String() string;
Number() float64;
Len() int;
}
-export func JsonToString(j Json) string {
+func JsonToString(j Json) string {
if j == nil {
return "null"
}
}
type _Null struct { }
-export var Null Json = &_Null{}
+var Null Json = &_Null{}
func (*_Null) Kind() int { return NullKind }
func (*_Null) String() string { return "null" }
func (*_Null) Number() float64 { return 0 }
return s;
}
-export func Walk(j Json, path string) Json {
+func Walk(j Json, path string) Json {
for len(path) > 0 {
var elem string;
if i := strings.Index(path, "/"); i >= 0 {
return j
}
-export func Equal(a, b Json) bool {
+func Equal(a, b Json) bool {
switch {
case a == nil && b == nil:
return true;
return bb
}
-export func StringToJson(s string) (json Json, ok bool, errtok string) {
+func StringToJson(s string) (json Json, ok bool, errtok string) {
var errindx int;
var j Json;
b := new(_JsonBuilder);
`{"a":1}`,
}
-export func TestJson(t *testing.T) {
+func TestJson(t *testing.T) {
for i := 0; i < len(jsontests); i++ {
val, ok, errtok := StringToJson(jsontests[i]);
if !ok {
}
}
-export func TestJsonMap(t *testing.T) {
+func TestJsonMap(t *testing.T) {
values := make(map[string]Json);
mapstr := "{";
for i := 0; i < len(jsontests); i++ {
return v, true;
}
-export func Unquote(s string) (t string, ok bool) {
+func Unquote(s string) (t string, ok bool) {
if len(s) < 2 || s[0] != '"' || s[len(s)-1] != '"' {
return
}
return string(b[0:w]), true
}
-export func Quote(s string) string {
+func Quote(s string) string {
chr := make([]byte, utf8.UTFMax);
chr0 := chr[0:1];
b := new(io.ByteBuffer);
type _Value interface {}
-export type Builder interface {
+type Builder interface {
// Set value
Int64(i int64);
Uint64(i uint64);
return ok;
}
-export func Parse(s string, build Builder) (ok bool, errindx int, errtok string) {
+func Parse(s string, build Builder) (ok bool, errindx int, errtok string) {
lex := new(_Lexer);
lex.s = s;
lex.Next();
return nobuilder
}
-export func Unmarshal(s string, val interface{}) (ok bool, errtok string) {
+func Unmarshal(s string, val interface{}) (ok bool, errtok string) {
var errindx int;
var val1 interface{};
b := &_StructBuilder{ reflect.NewValue(val) };
}
}
-export func TestUnmarshal(t *testing.T) {
+func TestUnmarshal(t *testing.T) {
var m _MyStruct;
m.f = true;
ok, errtok := Unmarshal(_Encoded, &m);
package malloc
-export type Stats struct {
+type Stats struct {
Alloc uint64;
Sys uint64;
};
-export func Alloc(uint64) *byte;
-export func Free(*byte);
-export func GetStats() *Stats;
-export func Lookup(*byte) (*byte, uintptr);
+func Alloc(uint64) *byte;
+func Free(*byte);
+func GetStats() *Stats;
+func Lookup(*byte) (*byte, uintptr);
return tolerance(a, b, 4e-16);
}
-export func TestAsin(t *testing.T) {
+func TestAsin(t *testing.T) {
for i := 0; i < len(vf); i++ {
if f := math.Asin(vf[i]/10); !veryclose(asin[i], f) {
t.Errorf("math.Asin(%g) = %g, want %g\n", vf[i]/10, f, asin[i]);
}
}
-export func TestAtan(t *testing.T) {
+func TestAtan(t *testing.T) {
for i := 0; i < len(vf); i++ {
if f := math.Atan(vf[i]); !veryclose(atan[i], f) {
t.Errorf("math.Atan(%g) = %g, want %g\n", vf[i], f, atan[i]);
}
}
-export func TestExp(t *testing.T) {
+func TestExp(t *testing.T) {
for i := 0; i < len(vf); i++ {
if f := math.Exp(vf[i]); !veryclose(exp[i], f) {
t.Errorf("math.Exp(%g) = %g, want %g\n", vf[i], f, exp[i]);
}
}
-export func TestFloor(t *testing.T) {
+func TestFloor(t *testing.T) {
for i := 0; i < len(vf); i++ {
if f := math.Floor(vf[i]); floor[i] != f {
t.Errorf("math.Floor(%g) = %g, want %g\n", vf[i], f, floor[i]);
}
}
-export func TestLog(t *testing.T) {
+func TestLog(t *testing.T) {
for i := 0; i < len(vf); i++ {
a := math.Fabs(vf[i]);
if f := math.Log(a); log[i] != f {
}
}
-export func TestPow(t *testing.T) {
+func TestPow(t *testing.T) {
for i := 0; i < len(vf); i++ {
if f := math.Pow(10, vf[i]); !close(pow[i], f) {
t.Errorf("math.Pow(10, %.17g) = %.17g, want %.17g\n", vf[i], f, pow[i]);
}
}
-export func TestSin(t *testing.T) {
+func TestSin(t *testing.T) {
for i := 0; i < len(vf); i++ {
if f := math.Sin(vf[i]); !close(sin[i], f) {
t.Errorf("math.Sin(%g) = %g, want %g\n", vf[i], f, sin[i]);
}
}
-export func TestSinh(t *testing.T) {
+func TestSinh(t *testing.T) {
for i := 0; i < len(vf); i++ {
if f := math.Sinh(vf[i]); !veryclose(sinh[i], f) {
t.Errorf("math.Sinh(%g) = %g, want %g\n", vf[i], f, sinh[i]);
}
}
-export func TestSqrt(t *testing.T) {
+func TestSqrt(t *testing.T) {
for i := 0; i < len(vf); i++ {
a := math.Fabs(vf[i]);
if f := math.Sqrt(a); !veryclose(sqrt[i], f) {
}
}
-export func TestTan(t *testing.T) {
+func TestTan(t *testing.T) {
for i := 0; i < len(vf); i++ {
if f := math.Tan(vf[i]); !close(tan[i], f) {
t.Errorf("math.Tan(%g) = %g, want %g\n", vf[i], f, tan[i]);
}
}
-export func TestTanh(t *testing.T) {
+func TestTanh(t *testing.T) {
for i := 0; i < len(vf); i++ {
if f := math.Tanh(vf[i]); !veryclose(tanh[i], f) {
t.Errorf("math.Tanh(%g) = %g, want %g\n", vf[i], f, tanh[i]);
}
}
-export func TestHypot(t *testing.T) {
+func TestHypot(t *testing.T) {
for i := 0; i < len(vf); i++ {
a := math.Fabs(tanh[i]*math.Sqrt(2));
if f := math.Hypot(tanh[i], tanh[i]); !veryclose(a, f) {
* Arctan is called after appropriate range reduction.
*/
-export func Asin(arg float64) float64 {
+func Asin(arg float64) float64 {
var temp, x float64;
var sign bool;
return temp;
}
-export func Acos(arg float64) float64 {
+func Acos(arg float64) float64 {
if arg > 1 || arg < -1 {
return sys.NaN();
}
* atan makes its argument positive and
* calls the inner routine satan.
*/
-export func Atan(arg float64) float64 {
+func Atan(arg float64) float64 {
if arg > 0 {
return satan(arg);
}
* atan2 discovers what quadrant the angle
* is in and calls atan.
*/
-export func Atan2(arg1, arg2 float64) float64 {
+func Atan2(arg1, arg2 float64) float64 {
if arg1+arg2 == arg1 {
if arg1 >= 0 {
return Pi/2;
package math
-export const (
+const (
// Mathematical constants.
// Reference: http://www.research.att.com/~njas/sequences/Axxxxxx
// compiler will convert from decimal to binary accurately enough
// to produce the hexadecimal values shown.
-export func Exp(x float64) float64 {
+func Exp(x float64) float64 {
const (
Ln2Hi = 6.93147180369123816490e-01;
Ln2Lo = 1.90821492927058770002e-10;
package math
-export func Fabs(arg float64) float64 {
+func Fabs(arg float64) float64 {
if arg < 0 {
return -arg;
}
* (resp least >=)
*/
-export func Floor(arg float64) float64 {
+func Floor(arg float64) float64 {
if arg < 0 {
d, fract := sys.Modf(-arg);
if fract != 0.0 {
return d;
}
-export func Ceil(arg float64) float64 {
+func Ceil(arg float64) float64 {
return -Floor(-arg);
}
* floating-point mod func without infinity or NaN checking
*/
-export func Fmod(x, y float64) float64 {
+func Fmod(x, y float64) float64 {
if y == 0 {
return x;
}
* Vol. 27, Number 6, pp. 577-581, Nov. 1983
*/
-export func Hypot(p, q float64) float64 {
+func Hypot(p, q float64) float64 {
if p < 0 {
p = -p;
}
// compiler will convert from decimal to binary accurately enough
// to produce the hexadecimal values shown.
-export func Log(x float64) float64 {
+func Log(x float64) float64 {
const (
Ln2Hi = 6.93147180369123816490e-01; /* 3fe62e42 fee00000 */
Ln2Lo = 1.90821492927058770002e-10; /* 3dea39ef 35793c76 */
return k*Ln2Hi - ((hfsq-(s*(hfsq+R)+k*Ln2Lo)) - f);
}
-export func Log10(arg float64) float64 {
+func Log10(arg float64) float64 {
if arg <= 0 {
return sys.NaN();
}
import "math"
// x^y: exponentiation
-export func Pow(x, y float64) float64 {
+func Pow(x, y float64) float64 {
// TODO: x or y NaN, ±Inf, maybe ±0.
switch {
case y == 0:
var pow10tab [70]float64;
-export func Pow10(e int) float64 {
+func Pow10(e int) float64 {
if e < 0 {
return 1/Pow10(-e);
}
return temp1/temp2;
}
-export func Cos(arg float64) float64 {
+func Cos(arg float64) float64 {
if arg < 0 {
arg = -arg;
}
return sinus(arg, 1);
}
-export func Sin(arg float64) float64 {
+func Sin(arg float64) float64 {
return sinus(arg, 0);
}
* all arguments.
*/
-export func Sinh(arg float64) float64 {
+func Sinh(arg float64) float64 {
// The coefficients are #2029 from Hart & Cheney. (20.36D)
const
(
return temp;
}
-export func Cosh(arg float64) float64 {
+func Cosh(arg float64) float64 {
if arg < 0 {
arg = - arg;
}
* calls frexp
*/
-export func Sqrt(arg float64) float64 {
+func Sqrt(arg float64) float64 {
if sys.IsInf(arg, 1) {
return arg;
}
* floating point tangent
*/
-export func Tan(arg float64) float64 {
+func Tan(arg float64) float64 {
// Coefficients are #4285 from Hart & Cheney. (19.74D)
const
(
* would cause overflow improperly.
*/
-export func Tanh(arg float64) float64 {
+func Tanh(arg float64) float64 {
if arg < 0 {
arg = -arg;
if arg > 21 {
"[2001:4860:0:2001::68]:80" // ipv6.google.com; removed if ipv6 flag not set
}
-export func TestDialGoogle(t *testing.T) {
+func TestDialGoogle(t *testing.T) {
// If no ipv6 tunnel, don't try the last address.
if !*ipv6 {
googleaddrs[len(googleaddrs)-1] = ""
"strings";
)
-export var (
+var (
DNS_InternalError = os.NewError("internal dns error");
DNS_MissingConfig = os.NewError("no dns configuration");
DNS_No_Answer = os.NewError("dns got no answer");
cfg = DNS_ReadConfig();
}
-export func LookupHost(name string) (name1 string, addrs []string, err *os.Error) {
+func LookupHost(name string) (name1 string, addrs []string, err *os.Error) {
// TODO(rsc): Pick out obvious non-DNS names to avoid
// sending stupid requests to the server?
"strconv";
)
-export type DNS_Config struct {
+type DNS_Config struct {
servers []string; // servers to use
search []string; // suffixes to append to local name
ndots int; // number of dots in name to trigger absolute lookup
// TODO(rsc): Supposed to call uname() and chop the beginning
// of the host name to get the default search domain.
// We assume it's in resolv.conf anyway.
-export func DNS_ReadConfig() *DNS_Config {
+func DNS_ReadConfig() *DNS_Config {
file := _Open("/etc/resolv.conf");
if file == nil {
return nil
// _Packet formats
// Wire constants.
-export const (
+const (
// valid DNS_RR_Header.rrtype and DNS_Question.qtype
DNS_TypeA = 1;
DNS_TypeNS = 2;
)
// DNS queries.
-export type DNS_Question struct {
+type DNS_Question struct {
name string "domain-name"; // "domain-name" specifies encoding; see packers below
qtype uint16;
qclass uint16;
// DNS responses (resource records).
// There are many types of messages,
// but they all share the same header.
-export type DNS_RR_Header struct {
+type DNS_RR_Header struct {
name string "domain-name";
rrtype uint16;
class uint16;
return h
}
-export type DNS_RR interface {
+type DNS_RR interface {
Header() *DNS_RR_Header
}
// Specific DNS RR formats for each query type.
-export type DNS_RR_CNAME struct {
+type DNS_RR_CNAME struct {
DNS_RR_Header;
cname string "domain-name";
}
-export type DNS_RR_HINFO struct {
+type DNS_RR_HINFO struct {
DNS_RR_Header;
cpu string;
os string;
}
-export type DNS_RR_MB struct {
+type DNS_RR_MB struct {
DNS_RR_Header;
mb string "domain-name";
}
-export type DNS_RR_MG struct {
+type DNS_RR_MG struct {
DNS_RR_Header;
mg string "domain-name";
}
-export type DNS_RR_MINFO struct {
+type DNS_RR_MINFO struct {
DNS_RR_Header;
rmail string "domain-name";
email string "domain-name";
}
-export type DNS_RR_MR struct {
+type DNS_RR_MR struct {
DNS_RR_Header;
mr string "domain-name";
}
-export type DNS_RR_MX struct {
+type DNS_RR_MX struct {
DNS_RR_Header;
pref uint16;
mx string "domain-name";
}
-export type DNS_RR_NS struct {
+type DNS_RR_NS struct {
DNS_RR_Header;
ns string "domain-name";
}
-export type DNS_RR_PTR struct {
+type DNS_RR_PTR struct {
DNS_RR_Header;
ptr string "domain-name";
}
-export type DNS_RR_SOA struct {
+type DNS_RR_SOA struct {
DNS_RR_Header;
ns string "domain-name";
mbox string "domain-name";
minttl uint32;
}
-export type DNS_RR_TXT struct {
+type DNS_RR_TXT struct {
DNS_RR_Header;
txt string; // not domain name
}
-export type DNS_RR_A struct {
+type DNS_RR_A struct {
DNS_RR_Header;
a uint32 "ipv4";
}
rcode int;
}
-export type DNS_Msg struct {
+type DNS_Msg struct {
_DNS_Msg_Top;
question []DNS_Question;
answer []DNS_RR;
// Network file descriptor. Only intended to be used internally,
// but have to export to make it available in other files implementing package net.
-export type FD struct {
+type FD struct {
// immutable until Close
fd int64;
osfd *os.FD;
pollserver = p
}
-export func NewFD(fd int64) (f *FD, err *os.Error) {
+func NewFD(fd int64) (f *FD, err *os.Error) {
if pollserver == nil {
once.Do(&_StartServer);
}
"syscall";
)
-export type Pollster struct {
+type Pollster struct {
kq int64;
eventbuf [10]syscall.Kevent_t;
events []syscall.Kevent_t;
}
-export func NewPollster() (p *Pollster, err *os.Error) {
+func NewPollster() (p *Pollster, err *os.Error) {
p = new(Pollster);
var e int64;
if p.kq, e = syscall.Kqueue(); e != 0 {
writeFlags = syscall.EPOLLOUT
)
-export type Pollster struct {
+type Pollster struct {
epfd int64;
// Events we're already waiting for
events map[int64] uint32;
}
-export func NewPollster() (p *Pollster, err *os.Error) {
+func NewPollster() (p *Pollster, err *os.Error) {
p = new(Pollster);
var e int64;
"net"
)
-export const (
+const (
IPv4len = 4;
IPv6len = 16
)
}
// Well-known IP addresses
-export var IPv4bcast, IPv4allsys, IPv4allrouter, IPv4prefix, IPallbits, IPnoaddr []byte
+var IPv4bcast, IPv4allsys, IPv4allrouter, IPv4prefix, IPallbits, IPnoaddr []byte
func init() {
IPv4bcast = _MakeIPv4(0xff, 0xff, 0xff, 0xff);
// Is p an IPv4 address (perhaps in IPv6 form)?
// If so, return the 4-byte V4 array.
-export func ToIPv4(p []byte) []byte {
+func ToIPv4(p []byte) []byte {
if len(p) == IPv4len {
return p
}
}
// Convert p to IPv6 form.
-export func ToIPv6(p []byte) []byte {
+func ToIPv6(p []byte) []byte {
if len(p) == IPv4len {
return _MakeIPv4(p[0], p[1], p[2], p[3])
}
}
// Default route masks for IPv4.
-export var (
+var (
ClassAMask = _MakeIPv4(0xff, 0, 0, 0);
ClassBMask = _MakeIPv4(0xff, 0xff, 0, 0);
ClassCMask = _MakeIPv4(0xff, 0xff, 0xff, 0);
)
-export func DefaultMask(p []byte) []byte {
+func DefaultMask(p []byte) []byte {
if p = ToIPv4(p); p == nil {
return nil
}
}
// Apply mask to ip, returning new address.
-export func Mask(ip []byte, mask []byte) []byte {
+func Mask(ip []byte, mask []byte) []byte {
n := len(ip);
if n != len(mask) {
return nil
}
// Convert IP address to string.
-export func IPToString(p []byte) string {
+func IPToString(p []byte) string {
// If IPv4, use dotted notation.
if p4 := ToIPv4(p); len(p4) == 4 {
return itod(uint(p4[0]))+"."
return n
}
-export func MaskToString(mask []byte) string {
+func MaskToString(mask []byte) string {
switch len(mask) {
case 4:
n := _SimpleMaskLength(mask);
return p
}
-export func ParseIP(s string) []byte {
+func ParseIP(s string) []byte {
p := _ParseIPv4(s);
if p != nil {
return p
parseIPTest{"::ffff:4a7d:1363", _IPv4(74, 125, 19, 99)},
}
-export func TestParseIP(t *testing.T) {
+func TestParseIP(t *testing.T) {
for i := 0; i < len(parseiptests); i++ {
tt := parseiptests[i];
if out := ParseIP(tt.in); !isEqual(out, tt.out) {
"syscall";
)
-export var (
+var (
BadAddress = os.NewError("malformed address");
MissingAddress = os.NewError("missing address");
UnknownNetwork = os.NewError("unknown network");
Unknown_SocketFamily = os.NewError("unknown socket family");
)
-export func LookupHost(name string) (name1 string, addrs []string, err *os.Error)
+func LookupHost(name string) (name1 string, addrs []string, err *os.Error)
// Split "host:port" into "host" and "port".
// Host cannot contain colons unless it is bracketed.
// TCP connections.
-export type ConnTCP struct {
+type ConnTCP struct {
_ConnBase
}
return c
}
-export func DialTCP(net, laddr, raddr string) (c *ConnTCP, err *os.Error) {
+func DialTCP(net, laddr, raddr string) (c *ConnTCP, err *os.Error) {
if raddr == "" {
return nil, MissingAddress
}
// TODO(rsc): UDP headers mode
-export type ConnUDP struct {
+type ConnUDP struct {
_ConnBase
}
return c
}
-export func DialUDP(net, laddr, raddr string) (c *ConnUDP, err *os.Error) {
+func DialUDP(net, laddr, raddr string) (c *ConnUDP, err *os.Error) {
if raddr == "" {
return nil, MissingAddress
}
// TODO: raw ethernet connections
-export type Conn interface {
+type Conn interface {
Read(b []byte) (n int, err *os.Error);
Write(b []byte) (n int, err *os.Error);
ReadFrom(b []byte) (n int, addr string, err *os.Error);
// Eventually, we plan to allow names in addition to IP addresses,
// but that requires writing a DNS library.
-export func Dial(net, laddr, raddr string) (c Conn, err *os.Error) {
+func Dial(net, laddr, raddr string) (c Conn, err *os.Error) {
switch net {
case "tcp", "tcp4", "tcp6":
c, err := DialTCP(net, laddr, raddr);
}
-export type Listener interface {
+type Listener interface {
Accept() (c Conn, raddr string, err *os.Error);
Close() *os.Error;
}
-export type ListenerTCP struct {
+type ListenerTCP struct {
fd *FD;
laddr string
}
-export func ListenTCP(net, laddr string) (l *ListenerTCP, err *os.Error) {
+func ListenTCP(net, laddr string) (l *ListenerTCP, err *os.Error) {
fd, e := _InternetSocket(net, laddr, "", syscall.SOCK_STREAM, "listen");
if e != nil {
return nil, e
return l.fd.Close()
}
-export func Listen(net, laddr string) (l Listener, err *os.Error) {
+func Listen(net, laddr string) (l Listener, err *os.Error) {
switch net {
case "tcp", "tcp4", "tcp6":
l, err := ListenTCP(net, laddr);
"unsafe";
)
-export func IPv4ToSockaddr(p []byte, port int) (sa1 *syscall.Sockaddr, err *os.Error) {
+func IPv4ToSockaddr(p []byte, port int) (sa1 *syscall.Sockaddr, err *os.Error) {
p = ToIPv4(p);
if p == nil || port < 0 || port > 0xFFFF {
return nil, os.EINVAL
for i := 0; i < IPv4len; i++ {
sa.Addr[i] = p[i]
}
- return unsafe.pointer(sa).(*syscall.Sockaddr), nil
+ return unsafe.Pointer(sa).(*syscall.Sockaddr), nil
}
-export func IPv6ToSockaddr(p []byte, port int) (sa1 *syscall.Sockaddr, err *os.Error) {
+func IPv6ToSockaddr(p []byte, port int) (sa1 *syscall.Sockaddr, err *os.Error) {
p = ToIPv6(p);
if p == nil || port < 0 || port > 0xFFFF {
return nil, os.EINVAL
for i := 0; i < IPv6len; i++ {
sa.Addr[i] = p[i]
}
- return unsafe.pointer(sa).(*syscall.Sockaddr), nil
+ return unsafe.Pointer(sa).(*syscall.Sockaddr), nil
}
-export func SockaddrToIP(sa1 *syscall.Sockaddr) (p []byte, port int, err *os.Error) {
+func SockaddrToIP(sa1 *syscall.Sockaddr) (p []byte, port int, err *os.Error) {
switch sa1.Family {
case syscall.AF_INET:
- sa := unsafe.pointer(sa1).(*syscall.SockaddrInet4);
+ sa := unsafe.Pointer(sa1).(*syscall.SockaddrInet4);
a := ToIPv6(sa.Addr);
if a == nil {
return nil, 0, os.EINVAL
}
return a, int(sa.Port[0])<<8 + int(sa.Port[1]), nil;
case syscall.AF_INET6:
- sa := unsafe.pointer(sa1).(*syscall.SockaddrInet6);
+ sa := unsafe.Pointer(sa1).(*syscall.SockaddrInet6);
a := ToIPv6(sa.Addr);
if a == nil {
return nil, 0, os.EINVAL
return nil, 0, nil // not reached
}
-export func ListenBacklog() int64 {
+func ListenBacklog() int64 {
return syscall.SOMAXCONN
}
"unsafe";
)
-export func IPv4ToSockaddr(p []byte, port int) (sa1 *syscall.Sockaddr, err *os.Error) {
+func IPv4ToSockaddr(p []byte, port int) (sa1 *syscall.Sockaddr, err *os.Error) {
p = ToIPv4(p);
if p == nil || port < 0 || port > 0xFFFF {
return nil, os.EINVAL
for i := 0; i < IPv4len; i++ {
sa.Addr[i] = p[i]
}
- return unsafe.pointer(sa).(*syscall.Sockaddr), nil
+ return unsafe.Pointer(sa).(*syscall.Sockaddr), nil
}
var _IPv6zero [16]byte;
-export func IPv6ToSockaddr(p []byte, port int) (sa1 *syscall.Sockaddr, err *os.Error) {
+func IPv6ToSockaddr(p []byte, port int) (sa1 *syscall.Sockaddr, err *os.Error) {
p = ToIPv6(p);
if p == nil || port < 0 || port > 0xFFFF {
return nil, os.EINVAL
for i := 0; i < IPv6len; i++ {
sa.Addr[i] = p[i]
}
- return unsafe.pointer(sa).(*syscall.Sockaddr), nil
+ return unsafe.Pointer(sa).(*syscall.Sockaddr), nil
}
-export func SockaddrToIP(sa1 *syscall.Sockaddr) (p []byte, port int, err *os.Error) {
+func SockaddrToIP(sa1 *syscall.Sockaddr) (p []byte, port int, err *os.Error) {
switch sa1.Family {
case syscall.AF_INET:
- sa := unsafe.pointer(sa1).(*syscall.SockaddrInet4);
+ sa := unsafe.Pointer(sa1).(*syscall.SockaddrInet4);
a := ToIPv6(sa.Addr);
if a == nil {
return nil, 0, os.EINVAL
}
return a, int(sa.Port[0])<<8 + int(sa.Port[1]), nil;
case syscall.AF_INET6:
- sa := unsafe.pointer(sa1).(*syscall.SockaddrInet6);
+ sa := unsafe.Pointer(sa1).(*syscall.SockaddrInet6);
a := ToIPv6(sa.Addr);
if a == nil {
return nil, 0, os.EINVAL
return nil, 0, nil // not reached
}
-export func ListenBacklog() int64 {
+func ListenBacklog() int64 {
// TODO: Read the limit from /proc/sys/net/core/somaxconn,
// to take advantage of kernels that have raised the limit.
return syscall.SOMAXCONN
"testing";
)
-export func TestReadLine(t *testing.T) {
+func TestReadLine(t *testing.T) {
filename := "/etc/services"; // a nice big file
fd, err := os.Open(filename, os.O_RDONLY, 0);
file.Close();
}
-export func LookupPort(netw, name string) (port int, ok bool) {
+func LookupPort(netw, name string) (port int, ok bool) {
once.Do(&_ReadServices);
switch netw {
portTest{ "tcp", "--badport--", 0, false },
}
-export func TestLookupPort(t *testing.T) {
+func TestLookupPort(t *testing.T) {
for i := 0; i < len(porttests); i++ {
tt := porttests[i];
if port, ok := LookupPort(tt.netw, tt.name); port != tt.port || ok != tt.ok {
<-done; // make sure server stopped
}
-export func TestTcpServer(t *testing.T) {
+func TestTcpServer(t *testing.T) {
doTest(t, "tcp", "0.0.0.0:9997", "127.0.0.1:9997");
doTest(t, "tcp", "[::]:9997", "[::ffff:127.0.0.1]:9997");
doTest(t, "tcp", "[::]:9997", "127.0.0.1:9997");
}
}
-export func Do(f *()) {
+func Do(f *()) {
// Look for job in map (avoids channel communication).
// If not there, ask map server to make one.
// TODO: Uncomment use of jobmap[f] once
ncall++
}
-export func TestOnce(t *testing.T) {
+func TestOnce(t *testing.T) {
ncall = 0;
once.Do(&call);
if ncall != 1 {
import os "os"
-export var (
+var (
ENOENV = NewError("no such environment variable");
)
-export func Getenv(s string) (v string, err *Error) {
+func Getenv(s string) (v string, err *Error) {
n := len(s);
if n == 0 {
return "", EINVAL
// Errors are singleton structures. Use the String() method to get their contents --
// it handles the nil (no error) case.
-export type Error struct {
+type Error struct {
s string
}
// errors simultaneously but the consequences are unimportant.
// Allocate an Error object, but if it's been seen before, share that one.
-export func NewError(s string) *Error {
+func NewError(s string) *Error {
if s == "" {
return nil
}
}
// Allocate an Error objecct, but if it's been seen before, share that one.
-export func ErrnoToError(errno int64) *Error {
+func ErrnoToError(errno int64) *Error {
if errno == 0 {
return nil
}
return err;
}
-export var (
+var (
ENONE = ErrnoToError(syscall.ENONE);
EPERM = ErrnoToError(syscall.EPERM);
ENOENT = ErrnoToError(syscall.ENOENT);
import os "os"
// FDs are wrappers for file descriptors
-export type FD struct {
+type FD struct {
fd int64
}
-export func NewFD(fd int64) *FD {
+func NewFD(fd int64) *FD {
if fd < 0 {
return nil
}
return &FD{fd}
}
-export var (
+var (
Stdin = NewFD(0);
Stdout = NewFD(1);
Stderr = NewFD(2);
)
-export const (
+const (
O_RDONLY = syscall.O_RDONLY;
O_WRONLY = syscall.O_WRONLY;
O_RDWR = syscall.O_RDWR;
O_TRUNC = syscall.O_TRUNC;
)
-export func Open(name string, mode int, flags int) (fd *FD, err *Error) {
+func Open(name string, mode int, flags int) (fd *FD, err *Error) {
r, e := syscall.Open(name, int64(mode), int64(flags));
return NewFD(r), ErrnoToError(e)
}
return int(r), ErrnoToError(e)
}
-export func Pipe() (fd1 *FD, fd2 *FD, err *Error) {
+func Pipe() (fd1 *FD, fd2 *FD, err *Error) {
var p [2]int64;
r, e := syscall.Pipe(&p);
if e != 0 {
return NewFD(p[0]), NewFD(p[1]), nil
}
-export func Mkdir(name string, perm int) *Error {
+func Mkdir(name string, perm int) *Error {
r, e := syscall.Mkdir(name, int64(perm));
return ErrnoToError(e)
}
"syscall"
)
-export func Time() (sec int64, nsec int64, err *Error) {
+func Time() (sec int64, nsec int64, err *Error) {
var errno int64;
sec, nsec, errno = syscall.Gettimeofday();
if errno != 0 {
return x;
}
-export func Seed(seed int32) {
+func Seed(seed int32) {
rng_tap = 0;
rng_feed = _LEN-_TAP;
}
}
-export func Int63() int64 {
+func Int63() int64 {
rng_tap--;
if rng_tap < 0 {
rng_tap += _LEN;
return x;
}
-export func Uint32() uint32 {
+func Uint32() uint32 {
return uint32(Int63() >> 31);
}
-export func Int31() int32 {
+func Int31() int32 {
return int32(Int63() >> 32);
}
-export func Int() int {
+func Int() int {
u := uint(Int63());
return int(u << 1 >> 1); // clear sign bit if int == int32
}
-export func Int63n(n int64) int64 {
+func Int63n(n int64) int64 {
if n <= 0 {
return 0
}
return v % n
}
-export func Int31n(n int32) int32 {
+func Int31n(n int32) int32 {
return int32(Int63n(int64(n)))
}
-export func Intn(n int) int {
+func Intn(n int) int {
return int(Int63n(int64(n)))
}
-export func Float64() float64 {
+func Float64() float64 {
x := float64(Int63()) / float64(_MASK);
for x >= 1 {
x = float64(Int63()) / float64(_MASK);
return x;
}
-export func Float32() float32 {
+func Float32() float32 {
return float32(Float64())
}
-export func Float() float
+func Float() float
{
return float(Float64())
}
-export func Perm(n int) []int {
+func Perm(n int) []int {
m := make([]int, n);
for i:=0; i<n; i++ {
m[i] = i;
assert(reflect.ValueToString(v), t);
}
-export type T struct { a int; b float64; c string; d *int }
+type T struct { a int; b float64; c string; d *int }
-export func TestAll(tt *testing.T) { // TODO(r): wrap up better
+func TestAll(tt *testing.T) { // TODO(r): wrap up better
var s string;
var t reflect.Type;
}
}
-export func TestInterfaceGet(t *testing.T) {
+func TestInterfaceGet(t *testing.T) {
var inter struct { e interface{ } };
inter.e = 123.456;
v1 := reflect.NewValue(&inter);
assert(v3.Type().String(), "float");
}
-export func TestCopyArray(t *testing.T) {
+func TestCopyArray(t *testing.T) {
a := []int{ 1, 2, 3, 4, 10, 9, 8, 7 };
b := []int{ 11, 22, 33, 44, 1010, 99, 88, 77, 66, 55, 44 };
c := []int{ 11, 22, 33, 44, 1010, 99, 88, 77, 66, 55, 44 };
}
}
-export func TestBigUnnamedStruct(t *testing.T) {
+func TestBigUnnamedStruct(t *testing.T) {
b := struct{a,b,c,d int64}{1, 2, 3, 4};
v := NewValue(b);
b1 := v.Interface().(struct{a,b,c,d int64});
type big struct {
a, b, c, d, e int64
}
-export func TestBigStruct(t *testing.T) {
+func TestBigStruct(t *testing.T) {
b := big{1, 2, 3, 4, 5};
v := NewValue(b);
b1 := v.Interface().(big);
"strconv";
)
-export func TypeToString(typ Type, expand bool) string
-export func ValueToString(val Value) string
+func TypeToString(typ Type, expand bool) string
+func ValueToString(val Value) string
func doubleQuote(s string) string {
out := "\"";
return str;
}
-export func TypeToString(typ Type, expand bool) string {
+func TypeToString(typ Type, expand bool) string {
var str string;
if name := typ.Name(); !expand && name != "" {
return name
return strconv.Itoa64(v);
}
-export func ValueToString(val Value) string {
+func ValueToString(val Value) string {
var str string;
typ := val.Type();
switch(val.Kind()) {
"sync";
)
-export type Type interface
+type Type interface
-export func ExpandType(name string) Type
+func ExpandType(name string) Type
func typestrings() string // implemented in C; declared here
-export const (
+const (
MissingKind = iota;
ArrayKind;
BoolKind;
var missingString = "$missing$" // syntactic name for undefined type names
var dotDotDotString = "..."
-export type Type interface {
+type Type interface {
Kind() int;
Name() string;
String() string;
}
// Prebuilt basic types
-export var (
+var (
Missing = newBasicType(missingString, MissingKind, 1);
DotDotDot = newBasicType(dotDotDotString, DotDotDotKind, 16); // TODO(r): size of interface?
Bool = newBasicType("bool", BoolKind, 1); // TODO: need to know how big a bool is
// -- Pointer
-export type PtrType interface {
+type PtrType interface {
Sub() Type
}
// -- Array
-export type ArrayType interface {
+type ArrayType interface {
Open() bool;
Len() int;
Elem() Type;
// -- Map
-export type MapType interface {
+type MapType interface {
Key() Type;
Elem() Type;
}
// -- Chan
-export type ChanType interface {
+type ChanType interface {
Dir() int;
Elem() Type;
}
-export const ( // channel direction
+const ( // channel direction
SendDir = 1 << iota;
RecvDir;
BothDir = SendDir | RecvDir;
// -- Struct
-export type StructType interface {
+type StructType interface {
Field(int) (name string, typ Type, tag string, offset int);
Len() int;
}
// -- Interface
-export type InterfaceType interface {
+type InterfaceType interface {
Field(int) (name string, typ Type, tag string, offset int);
Len() int;
}
// -- Func
-export type FuncType interface {
+type FuncType interface {
In() StructType;
Out() StructType;
}
return s;
}
-export func ParseTypeString(name, typestring string) Type {
+func ParseTypeString(name, typestring string) Type {
if typestring == "" {
// If the typestring is empty, it represents (the type of) a nil interface value
return nilInterface
}
// Type is known by name. Find (and create if necessary) its real type.
-export func ExpandType(name string) Type {
+func ExpandType(name string) Type {
lock();
t, ok := types[name];
if ok {
"unsafe";
)
-export type Addr unsafe.pointer
+type Addr unsafe.Pointer
func equalType(a, b Type) bool {
return a.String() == b.String()
}
-export type Value interface {
+type Value interface {
Kind() int;
Type() Type;
Addr() Addr;
// -- Missing
-export type MissingValue interface {
+type MissingValue interface {
Kind() int;
Type() Type;
Addr() Addr;
// -- Int
-export type IntValue interface {
+type IntValue interface {
Kind() int;
Get() int;
Set(int);
// -- Int8
-export type Int8Value interface {
+type Int8Value interface {
Kind() int;
Get() int8;
Set(int8);
// -- Int16
-export type Int16Value interface {
+type Int16Value interface {
Kind() int;
Get() int16;
Set(int16);
// -- Int32
-export type Int32Value interface {
+type Int32Value interface {
Kind() int;
Get() int32;
Set(int32);
// -- Int64
-export type Int64Value interface {
+type Int64Value interface {
Kind() int;
Get() int64;
Set(int64);
// -- Uint
-export type UintValue interface {
+type UintValue interface {
Kind() int;
Get() uint;
Set(uint);
// -- Uint8
-export type Uint8Value interface {
+type Uint8Value interface {
Kind() int;
Get() uint8;
Set(uint8);
// -- Uint16
-export type Uint16Value interface {
+type Uint16Value interface {
Kind() int;
Get() uint16;
Set(uint16);
// -- Uint32
-export type Uint32Value interface {
+type Uint32Value interface {
Kind() int;
Get() uint32;
Set(uint32);
// -- Uint64
-export type Uint64Value interface {
+type Uint64Value interface {
Kind() int;
Get() uint64;
Set(uint64);
// -- Uintptr
-export type UintptrValue interface {
+type UintptrValue interface {
Kind() int;
Get() uintptr;
Set(uintptr);
// -- Float
-export type FloatValue interface {
+type FloatValue interface {
Kind() int;
Get() float;
Set(float);
// -- Float32
-export type Float32Value interface {
+type Float32Value interface {
Kind() int;
Get() float32;
Set(float32);
// -- Float64
-export type Float64Value interface {
+type Float64Value interface {
Kind() int;
Get() float64;
Set(float64);
// -- Float80
-export type Float80Value interface {
+type Float80Value interface {
Kind() int;
Get() float80;
Set(float80);
// -- String
-export type StringValue interface {
+type StringValue interface {
Kind() int;
Get() string;
Set(string);
// -- Bool
-export type BoolValue interface {
+type BoolValue interface {
Kind() int;
Get() bool;
Set(bool);
// -- Pointer
-export type PtrValue interface {
+type PtrValue interface {
Kind() int;
Type() Type;
Sub() Value;
// -- Array
-export type ArrayValue interface {
+type ArrayValue interface {
Kind() int;
Type() Type;
Open() bool;
// -- Map TODO: finish and test
-export type MapValue interface {
+type MapValue interface {
Kind() int;
Type() Type;
Len() int;
// -- Chan
-export type ChanValue interface {
+type ChanValue interface {
Kind() int;
Type() Type;
}
// -- Struct
-export type StructValue interface {
+type StructValue interface {
Kind() int;
Type() Type;
Len() int;
// -- Interface
-export type InterfaceValue interface {
+type InterfaceValue interface {
Kind() int;
Type() Type;
Get() interface {};
// -- Func
-export type FuncValue interface {
+type FuncValue interface {
Kind() int;
Type() Type;
}
return c(typ, addr);
}
-export func NewInitValue(typ Type) Value {
+func NewInitValue(typ Type) Value {
// Some values cannot be made this way.
switch typ.Kind() {
case FuncKind: // must be pointers, at least for now (TODO?)
uint32 cap; // allocated number of elements
};
*/
-export func NewOpenArrayValue(typ ArrayType, len, cap int) ArrayValue {
+func NewOpenArrayValue(typ ArrayType, len, cap int) ArrayValue {
if !typ.Open() {
return nil
}
return newValueAddr(typ, Addr(array));
}
-export func CopyArray(dst ArrayValue, src ArrayValue, n int) {
+func CopyArray(dst ArrayValue, src ArrayValue, n int) {
if n == 0 {
return
}
}
-export func NewValue(e interface {}) Value {
+func NewValue(e interface {}) Value {
value, typestring, indir := sys.Reflect(e);
typ, ok := typecache[typestring];
if !ok {
}
var bad_re = []stringError{
stringError{ `*`, regexp.ErrBareClosure },
- stringError{ `(abc`, regexp.ErrUnmatchedLpar },
- stringError{ `abc)`, regexp.ErrUnmatchedRpar },
- stringError{ `x[a-z`, regexp.ErrUnmatchedLbkt },
- stringError{ `abc]`, regexp.ErrUnmatchedRbkt },
- stringError{ `[z-a]`, regexp.ErrBadRange },
- stringError{ `abc\`, regexp.ErrExtraneousBackslash },
- stringError{ `a**`, regexp.ErrBadClosure },
- stringError{ `a*+`, regexp.ErrBadClosure },
- stringError{ `a??`, regexp.ErrBadClosure },
- stringError{ `*`, regexp.ErrBareClosure },
+ stringError{ `(abc`, regexp.ErrUnmatchedLpar },
+ stringError{ `abc)`, regexp.ErrUnmatchedRpar },
+ stringError{ `x[a-z`, regexp.ErrUnmatchedLbkt },
+ stringError{ `abc]`, regexp.ErrUnmatchedRbkt },
+ stringError{ `[z-a]`, regexp.ErrBadRange },
+ stringError{ `abc\`, regexp.ErrExtraneousBackslash },
+ stringError{ `a**`, regexp.ErrBadClosure },
+ stringError{ `a*+`, regexp.ErrBadClosure },
+ stringError{ `a??`, regexp.ErrBadClosure },
+ stringError{ `*`, regexp.ErrBareClosure },
stringError{ `\x`, regexp.ErrBadBackslash },
}
}
}
-export func TestGoodCompile(t *testing.T) {
+func TestGoodCompile(t *testing.T) {
for i := 0; i < len(good_re); i++ {
compileTest(t, good_re[i], nil);
}
}
-export func TestBadCompile(t *testing.T) {
+func TestBadCompile(t *testing.T) {
for i := 0; i < len(bad_re); i++ {
compileTest(t, bad_re[i].re, bad_re[i].err)
}
}
-export func TestExecute(t *testing.T) {
+func TestExecute(t *testing.T) {
for i := 0; i < len(matches); i++ {
test := &matches[i];
executeTest(t, test.re, test.text, test.match)
}
}
-export func TestMatch(t *testing.T) {
+func TestMatch(t *testing.T) {
for i := 0; i < len(matches); i++ {
test := &matches[i];
matchTest(t, test.re, test.text, test.match)
}
}
-export func TestMatchStrings(t *testing.T) {
+func TestMatchStrings(t *testing.T) {
for i := 0; i < len(matches); i++ {
test := &matches[i];
matchTest(t, test.re, test.text, test.match)
}
}
-export func TestMatchFunction(t *testing.T) {
+func TestMatchFunction(t *testing.T) {
for i := 0; i < len(matches); i++ {
test := &matches[i];
matchFunctionTest(t, test.re, test.text, test.match)
var debug = false;
-export var ErrInternal = os.NewError("internal error");
-export var ErrUnmatchedLpar = os.NewError("unmatched '('");
-export var ErrUnmatchedRpar = os.NewError("unmatched ')'");
-export var ErrUnmatchedLbkt = os.NewError("unmatched '['");
-export var ErrUnmatchedRbkt = os.NewError("unmatched ']'");
-export var ErrBadRange = os.NewError("bad range in character class");
-export var ErrExtraneousBackslash = os.NewError("extraneous backslash");
-export var ErrBadClosure = os.NewError("repeated closure (**, ++, etc.)");
-export var ErrBareClosure = os.NewError("closure applies to nothing");
-export var ErrBadBackslash = os.NewError("illegal backslash escape");
+var ErrInternal = os.NewError("internal error");
+var ErrUnmatchedLpar = os.NewError("unmatched '('");
+var ErrUnmatchedRpar = os.NewError("unmatched ')'");
+var ErrUnmatchedLbkt = os.NewError("unmatched '['");
+var ErrUnmatchedRbkt = os.NewError("unmatched ']'");
+var ErrBadRange = os.NewError("bad range in character class");
+var ErrExtraneousBackslash = os.NewError("extraneous backslash");
+var ErrBadClosure = os.NewError("repeated closure (**, ++, etc.)");
+var ErrBareClosure = os.NewError("closure applies to nothing");
+var ErrBadBackslash = os.NewError("illegal backslash escape");
// An instruction executed by the NFA
type instr interface {
}
// Public interface has only execute functionality
-export type Regexp interface {
+type Regexp interface {
Execute(s string) []int;
Match(s string) bool;
MatchStrings(s string) []string;
}
// Compile in separate goroutine; wait for result
-export func Compile(str string) (regexp Regexp, error *os.Error) {
+func Compile(str string) (regexp Regexp, error *os.Error) {
ch := make(chan *_RE);
go compiler(str, ch);
re := <-ch;
// Exported function for simple boolean check. Anything more fancy
// needs a call to Compile.
-export func Match(pattern string, s string) (matched bool, error *os.Error) {
+func Match(pattern string, s string) (matched bool, error *os.Error) {
re, err := Compile(pattern);
if err != nil {
return false, err
package sort
-export type SortInterface interface {
+type SortInterface interface {
Len() int;
Less(i, j int) bool;
Swap(i, j int);
}
}
-export func Sort(data SortInterface) {
+func Sort(data SortInterface) {
quickSort(data, 0, data.Len());
}
-export func IsSorted(data SortInterface) bool {
+func IsSorted(data SortInterface) bool {
n := data.Len();
for i := n - 1; i > 0; i-- {
if data.Less(i, i - 1) {
// Convenience types for common cases
-export type IntArray []int
+type IntArray []int
func (p IntArray) Len() int { return len(p); }
func (p IntArray) Less(i, j int) bool { return p[i] < p[j]; }
func (p IntArray) Swap(i, j int) { p[i], p[j] = p[j], p[i]; }
-export type FloatArray []float
+type FloatArray []float
func (p FloatArray) Len() int { return len(p); }
func (p FloatArray) Less(i, j int) bool { return p[i] < p[j]; }
func (p FloatArray) Swap(i, j int) { p[i], p[j] = p[j], p[i]; }
-export type StringArray []string
+type StringArray []string
func (p StringArray) Len() int { return len(p); }
func (p StringArray) Less(i, j int) bool { return p[i] < p[j]; }
// Convenience wrappers for common cases
-export func SortInts(a []int) { Sort(IntArray(a)); }
-export func SortFloats(a []float) { Sort(FloatArray(a)); }
-export func SortStrings(a []string) { Sort(StringArray(a)); }
+func SortInts(a []int) { Sort(IntArray(a)); }
+func SortFloats(a []float) { Sort(FloatArray(a)); }
+func SortStrings(a []string) { Sort(StringArray(a)); }
-export func IntsAreSorted(a []int) bool { return IsSorted(IntArray(a)); }
-export func FloatsAreSorted(a []float) bool { return IsSorted(FloatArray(a)); }
-export func StringsAreSorted(a []string) bool { return IsSorted(StringArray(a)); }
+func IntsAreSorted(a []int) bool { return IsSorted(IntArray(a)); }
+func FloatsAreSorted(a []float) bool { return IsSorted(FloatArray(a)); }
+func StringsAreSorted(a []string) bool { return IsSorted(StringArray(a)); }
var floats = [...]float{74.3, 59.0, 238.2, -784.0, 2.3, 9845.768, -959.7485, 905, 7.8, 7.8}
var strings = [...]string{"", "Hello", "foo", "bar", "foo", "f00", "%*&^*&^&", "***"}
-export func TestSortIntArray(t *testing.T) {
+func TestSortIntArray(t *testing.T) {
data := ints;
a := IntArray(data);
sort.Sort(a);
}
}
-export func TestSortFloatArray(t *testing.T) {
+func TestSortFloatArray(t *testing.T) {
data := floats;
a := FloatArray(data);
sort.Sort(a);
}
}
-export func TestSortStringArray(t *testing.T) {
+func TestSortStringArray(t *testing.T) {
data := strings;
a := StringArray(data);
sort.Sort(a);
}
}
-export func TestSortInts(t *testing.T) {
+func TestSortInts(t *testing.T) {
data := ints;
sort.SortInts(data);
if !sort.IntsAreSorted(data) {
}
}
-export func TestSortFloats(t *testing.T) {
+func TestSortFloats(t *testing.T) {
data := floats;
sort.SortFloats(data);
if !sort.FloatsAreSorted(data) {
}
}
-export func TestSortStrings(t *testing.T) {
+func TestSortStrings(t *testing.T) {
data := strings;
sort.SortStrings(data);
if !sort.StringsAreSorted(data) {
}
}
-export func TestSortLarge_Random(t *testing.T) {
+func TestSortLarge_Random(t *testing.T) {
data := make([]int, 1000000);
for i := 0; i < len(data); i++ {
data[i] = rand.Intn(100);
return i;
}
-export func TestBentleyMcIlroy(t *testing.T) {
+func TestBentleyMcIlroy(t *testing.T) {
sizes := []int{100, 1023, 1024, 1025};
dists := []string{"sawtooth", "rand", "stagger", "plateau", "shuffle"};
modes := []string{"copy", "reverse", "reverse1", "reverse2", "sort", "dither"};
// If s is syntactically well-formed but is more than 1/2 ULP
// away from the largest floating point number of the given size,
// returns f = ±Inf, err = os.ERANGE.
-export func Atof64(s string) (f float64, err *os.Error) {
+func Atof64(s string) (f float64, err *os.Error) {
neg, d, trunc, ok := stringToDecimal(s);
if !ok {
return 0, os.EINVAL;
return f, err
}
-export func Atof32(s string) (f float32, err *os.Error) {
+func Atof32(s string) (f float32, err *os.Error) {
neg, d, trunc, ok := stringToDecimal(s);
if !ok {
return 0, os.EINVAL;
return f, err
}
-export func Atof(s string) (f float, err *os.Error) {
+func Atof(s string) (f float, err *os.Error) {
if FloatSize == 32 {
f1, err1 := Atof32(s);
return float(f1), err1;
strconv.optimize = oldopt;
}
-export func TestAtof(t *testing.T) {
+func TestAtof(t *testing.T) {
testAtof(t, true);
}
-export func TestAtofSlow(t *testing.T) {
+func TestAtofSlow(t *testing.T) {
testAtof(t, false);
}
var intsize = computeIntsize();
// Convert decimal string to unsigned integer.
-export func Atoui64(s string) (i uint64, err *os.Error) {
+func Atoui64(s string) (i uint64, err *os.Error) {
// empty string bad
if len(s) == 0 {
return 0, os.EINVAL
}
// Convert decimal string to integer.
-export func Atoi64(s string) (i int64, err *os.Error) {
+func Atoi64(s string) (i int64, err *os.Error) {
// empty string bad
if len(s) == 0 {
return 0, os.EINVAL
return n, nil
}
-export func Atoui(s string) (i uint, err *os.Error) {
+func Atoui(s string) (i uint, err *os.Error) {
i1, e1 := Atoui64(s);
if e1 != nil && e1 != os.ERANGE {
return 0, e1
return i, nil
}
-export func Atoi(s string) (i int, err *os.Error) {
+func Atoi(s string) (i int, err *os.Error) {
i1, e1 := Atoi64(s);
if e1 != nil && e1 != os.ERANGE {
return 0, e1
atoi32Test{ "-2147483649", -1<<31, os.ERANGE },
}
-export func TestAtoui64(t *testing.T) {
+func TestAtoui64(t *testing.T) {
for i := 0; i < len(atoui64tests); i++ {
test := &atoui64tests[i];
out, err := strconv.Atoui64(test.in);
}
}
-export func TestAtoi64(t *testing.T) {
+func TestAtoi64(t *testing.T) {
for i := 0; i < len(atoi64test); i++ {
test := &atoi64test[i];
out, err := strconv.Atoi64(test.in);
}
}
-export func TestAtoui(t *testing.T) {
+func TestAtoui(t *testing.T) {
switch intsize {
case 32:
for i := 0; i < len(atoui32tests); i++ {
}
}
-export func TestAtoi(t *testing.T) {
+func TestAtoi(t *testing.T) {
switch intsize {
case 32:
for i := 0; i < len(atoi32tests); i++ {
shiftTest{ 1953125, 9, "1000000000" },
}
-export func TestDecimalShift(t *testing.T) {
+func TestDecimalShift(t *testing.T) {
ok := true;
for i := 0; i < len(shifttests); i++ {
test := &shifttests[i];
roundTest{ 12999999, 4, "12990000", "13000000", "13000000", 13000000 },
}
-export func TestDecimalRound(t *testing.T) {
+func TestDecimalRound(t *testing.T) {
for i := 0; i < len(roundtests); i++ {
test := &roundtests[i];
s := strconv.newDecimal(test.i).RoundDown(test.nd).String();
roundIntTest{ 1000, 0, 1000 },
}
-export func TestDecimalRoundedInteger(t *testing.T) {
+func TestDecimalRoundedInteger(t *testing.T) {
for i := 0; i < len(roundinttests); i++ {
test := roundinttests[i];
// TODO: should be able to use int := here.
return f1, true;
}
-export func TestFp(t *testing.T) {
+func TestFp(t *testing.T) {
fd, err := os.Open("testfp.txt", os.O_RDONLY, 0);
if err != nil {
panicln("testfp: open testfp.txt:", err.String());
}
return 64;
}
-export var FloatSize = floatsize()
+var FloatSize = floatsize()
-export func Ftoa32(f float32, fmt byte, prec int) string {
+func Ftoa32(f float32, fmt byte, prec int) string {
return genericFtoa(uint64(sys.Float32bits(f)), fmt, prec, &float32info);
}
-export func Ftoa64(f float64, fmt byte, prec int) string {
+func Ftoa64(f float64, fmt byte, prec int) string {
return genericFtoa(sys.Float64bits(f), fmt, prec, &float64info);
}
-export func Ftoa(f float, fmt byte, prec int) string {
+func Ftoa(f float, fmt byte, prec int) string {
if FloatSize == 32 {
return Ftoa32(float32(f), fmt, prec);
}
ftoaTest{ -1, 'b', -1, "-4503599627370496p-52" },
}
-export func TestFtoa(t *testing.T) {
+func TestFtoa(t *testing.T) {
if strconv.FloatSize != 32 {
panic("floatsize: ", strconv.FloatSize);
}
package strconv
-export func Itoa64(i int64) string {
+func Itoa64(i int64) string {
if i == 0 {
return "0"
}
return string(b[bp:len(b)])
}
-export func Itoa(i int) string {
+func Itoa(i int) string {
return Itoa64(int64(i));
}
itoa64Test{ -1<<63, "-9223372036854775808" },
}
-export func TestItoa(t *testing.T) {
+func TestItoa(t *testing.T) {
for i := 0; i < len(itoa64tests); i++ {
test := itoa64tests[i];
s := strconv.Itoa64(test.in);
const lowerhex = "0123456789abcdef"
-export func Quote(s string) string {
+func Quote(s string) string {
t := `"`;
for i := 0; i < len(s); i++ {
switch {
return t;
}
-export func CanBackquote(s string) bool {
+func CanBackquote(s string) bool {
for i := 0; i < len(s); i++ {
if s[i] < ' ' || s[i] == '`' {
return false;
quoteTest{ "\x04", `"\x04"` },
}
-export func TestQuote(t *testing.T) {
+func TestQuote(t *testing.T) {
for i := 0; i < len(quotetests); i++ {
tt := quotetests[i];
if out := Quote(tt.in); out != tt.out {
canBackquoteTest{ `☺`, true },
}
-export func TestCanBackquote(t *testing.T) {
+func TestCanBackquote(t *testing.T) {
for i := 0; i < len(canbackquotetests); i++ {
tt := canbackquotetests[i];
if out := CanBackquote(tt.in); out != tt.out {
import "utf8"
// Split string into array of UTF-8 sequences (still strings)
-export func Explode(s string) []string {
+func Explode(s string) []string {
a := make([]string, utf8.RuneCountInString(s, 0, len(s)));
j := 0;
var size, rune int;
}
// Count non-overlapping instances of sep in s.
-export func Count(s, sep string) int {
+func Count(s, sep string) int {
if sep == "" {
return utf8.RuneCountInString(s, 0, len(s))+1
}
}
// Return index of first instance of sep in s.
-export func Index(s, sep string) int {
+func Index(s, sep string) int {
if sep == "" {
return 0
}
}
// Split string into list of strings at separators
-export func Split(s, sep string) []string {
+func Split(s, sep string) []string {
if sep == "" {
return Explode(s)
}
}
// Join list of strings with separators between them.
-export func Join(a []string, sep string) string {
+func Join(a []string, sep string) string {
if len(a) == 0 {
return ""
}
var commas = "1,2,3,4";
var dots = "1....2....3....4";
-export type ExplodeTest struct {
+type ExplodeTest struct {
s string;
a []string;
}
ExplodeTest{ abcd, []string{"a", "b", "c", "d"} },
ExplodeTest{ faces, []string{"☺", "☻", "☹" } },
}
-export func TestExplode(t *testing.T) {
+func TestExplode(t *testing.T) {
for i := 0; i < len(explodetests); i++ {
tt := explodetests[i];
a := Explode(tt.s);
}
}
-export type SplitTest struct {
+type SplitTest struct {
s string;
sep string;
a []string;
SplitTest{ faces, "~", []string{faces} },
SplitTest{ faces, "", []string{"☺", "☻", "☹"} },
}
-export func TestSplit(t *testing.T) {
+func TestSplit(t *testing.T) {
for i := 0; i < len(splittests); i++ {
tt := splittests[i];
a := Split(tt.s, tt.sep);
func semacquire(*int32)
func semrelease(*int32)
-export type Mutex struct {
+type Mutex struct {
key int32;
sema int32;
}
"testing"
)
-export func HammerSemaphore(s *int32, cdone chan bool) {
+func HammerSemaphore(s *int32, cdone chan bool) {
for i := 0; i < 1000; i++ {
semacquire(s);
semrelease(s);
cdone <- true;
}
-export func TestSemaphore(t *testing.T) {
+func TestSemaphore(t *testing.T) {
s := new(int32);
*s = 1;
c := make(chan bool);
}
-export func HammerMutex(m *Mutex, cdone chan bool) {
+func HammerMutex(m *Mutex, cdone chan bool) {
for i := 0; i < 1000; i++ {
m.Lock();
m.Unlock();
cdone <- true;
}
-export func TestMutex(t *testing.T) {
+func TestMutex(t *testing.T) {
m := new(Mutex);
c := make(chan bool);
for i := 0; i < 10; i++ {
package syscall
-export const (
+const (
ENONE=0;
EPERM=1;
ENOENT=2;
return string(buf)[i:len(buf)];
}
-export func Errstr(errno int64) string {
+func Errstr(errno int64) string {
if errno < 0 || errno >= len(error) {
return "Error " + str(errno)
}
package syscall
-export const (
+const (
ENONE=0;
EPERM=1;
ENOENT=2;
return string(buf)[i:len(buf)];
}
-export func Errstr(errno int64) string {
+func Errstr(errno int64) string {
if errno < 0 || errno >= len(error) {
return "Error " + str(errno)
}
const nameBufsize = 512
-export func Open(name string, mode int64, perm int64) (ret int64, errno int64) {
+func Open(name string, mode int64, perm int64) (ret int64, errno int64) {
var namebuf [nameBufsize]byte;
if !StringToBytes(namebuf, name) {
return -1, ENAMETOOLONG
}
- r1, r2, err := Syscall(SYS_OPEN, int64(uintptr(unsafe.pointer(&namebuf[0]))), mode, perm);
+ r1, r2, err := Syscall(SYS_OPEN, int64(uintptr(unsafe.Pointer(&namebuf[0]))), mode, perm);
return r1, err;
}
-export func Creat(name string, perm int64) (ret int64, errno int64) {
+func Creat(name string, perm int64) (ret int64, errno int64) {
var namebuf [nameBufsize]byte;
if !StringToBytes(namebuf, name) {
return -1, ENAMETOOLONG
}
- r1, r2, err := Syscall(SYS_OPEN, int64(uintptr(unsafe.pointer(&namebuf[0]))), O_CREAT|O_WRONLY|O_TRUNC, perm);
+ r1, r2, err := Syscall(SYS_OPEN, int64(uintptr(unsafe.Pointer(&namebuf[0]))), O_CREAT|O_WRONLY|O_TRUNC, perm);
return r1, err;
}
-export func Close(fd int64) (ret int64, errno int64) {
+func Close(fd int64) (ret int64, errno int64) {
r1, r2, err := Syscall(SYS_CLOSE, fd, 0, 0);
return r1, err;
}
-export func Read(fd int64, buf *byte, nbytes int64) (ret int64, errno int64) {
- r1, r2, err := Syscall(SYS_READ, fd, int64(uintptr(unsafe.pointer(buf))), nbytes);
+func Read(fd int64, buf *byte, nbytes int64) (ret int64, errno int64) {
+ r1, r2, err := Syscall(SYS_READ, fd, int64(uintptr(unsafe.Pointer(buf))), nbytes);
return r1, err;
}
-export func Write(fd int64, buf *byte, nbytes int64) (ret int64, errno int64) {
- r1, r2, err := Syscall(SYS_WRITE, fd, int64(uintptr(unsafe.pointer(buf))), nbytes);
+func Write(fd int64, buf *byte, nbytes int64) (ret int64, errno int64) {
+ r1, r2, err := Syscall(SYS_WRITE, fd, int64(uintptr(unsafe.Pointer(buf))), nbytes);
return r1, err;
}
-export func Pipe(fds *[2]int64) (ret int64, errno int64) {
+func Pipe(fds *[2]int64) (ret int64, errno int64) {
r1, r2, err := Syscall(SYS_PIPE, 0, 0, 0);
if r1 < 0 {
return r1, err;
return 0, 0;
}
-export func Stat(name string, buf *Stat_t) (ret int64, errno int64) {
+func Stat(name string, buf *Stat_t) (ret int64, errno int64) {
var namebuf [nameBufsize]byte;
if !StringToBytes(namebuf, name) {
return -1, ENAMETOOLONG
}
- r1, r2, err := Syscall(SYS_STAT64, int64(uintptr(unsafe.pointer(&namebuf[0]))), int64(uintptr(unsafe.pointer(buf))), 0);
+ r1, r2, err := Syscall(SYS_STAT64, int64(uintptr(unsafe.Pointer(&namebuf[0]))), int64(uintptr(unsafe.Pointer(buf))), 0);
return r1, err;
}
-export func Lstat(name *byte, buf *Stat_t) (ret int64, errno int64) {
- r1, r2, err := Syscall(SYS_LSTAT, int64(uintptr(unsafe.pointer(name))), int64(uintptr(unsafe.pointer(buf))), 0);
+func Lstat(name *byte, buf *Stat_t) (ret int64, errno int64) {
+ r1, r2, err := Syscall(SYS_LSTAT, int64(uintptr(unsafe.Pointer(name))), int64(uintptr(unsafe.Pointer(buf))), 0);
return r1, err;
}
-export func Fstat(fd int64, buf *Stat_t) (ret int64, errno int64) {
- r1, r2, err := Syscall(SYS_FSTAT, fd, int64(uintptr(unsafe.pointer(buf))), 0);
+func Fstat(fd int64, buf *Stat_t) (ret int64, errno int64) {
+ r1, r2, err := Syscall(SYS_FSTAT, fd, int64(uintptr(unsafe.Pointer(buf))), 0);
return r1, err;
}
-export func Unlink(name string) (ret int64, errno int64) {
+func Unlink(name string) (ret int64, errno int64) {
var namebuf [nameBufsize]byte;
if !StringToBytes(namebuf, name) {
return -1, ENAMETOOLONG
}
- r1, r2, err := Syscall(SYS_UNLINK, int64(uintptr(unsafe.pointer(&namebuf[0]))), 0, 0);
+ r1, r2, err := Syscall(SYS_UNLINK, int64(uintptr(unsafe.Pointer(&namebuf[0]))), 0, 0);
return r1, err;
}
-export func Fcntl(fd, cmd, arg int64) (ret int64, errno int64) {
+func Fcntl(fd, cmd, arg int64) (ret int64, errno int64) {
r1, r2, err := Syscall(SYS_FCNTL, fd, cmd, arg);
return r1, err
}
-export func Mkdir(name string, perm int64) (ret int64, errno int64) {
+func Mkdir(name string, perm int64) (ret int64, errno int64) {
var namebuf [nameBufsize]byte;
if !StringToBytes(namebuf, name) {
return -1, ENAMETOOLONG
}
- r1, r2, err := Syscall(SYS_MKDIR, int64(uintptr(unsafe.pointer(&namebuf[0]))), perm, 0);
+ r1, r2, err := Syscall(SYS_MKDIR, int64(uintptr(unsafe.Pointer(&namebuf[0]))), perm, 0);
return r1, err;
}
-export func Dup2(fd1, fd2 int64) (ret int64, errno int64) {
+func Dup2(fd1, fd2 int64) (ret int64, errno int64) {
r1, r2, err := Syscall(SYS_DUP2, fd1, fd2, 0);
return r1, err;
}
const nameBufsize = 512
-export func Open(name string, mode int64, perm int64) (ret int64, errno int64) {
+func Open(name string, mode int64, perm int64) (ret int64, errno int64) {
var namebuf [nameBufsize]byte;
if !StringToBytes(namebuf, name) {
return -1, ENAMETOOLONG
}
- r1, r2, err := Syscall(SYS_OPEN, int64(uintptr(unsafe.pointer(&namebuf[0]))), mode, perm);
+ r1, r2, err := Syscall(SYS_OPEN, int64(uintptr(unsafe.Pointer(&namebuf[0]))), mode, perm);
return r1, err;
}
-export func Creat(name string, perm int64) (ret int64, errno int64) {
+func Creat(name string, perm int64) (ret int64, errno int64) {
var namebuf [nameBufsize]byte;
if !StringToBytes(namebuf, name) {
return -1, ENAMETOOLONG
}
- r1, r2, err := Syscall(SYS_OPEN, int64(uintptr(unsafe.pointer(&namebuf[0]))), O_CREAT|O_WRONLY|O_TRUNC, perm);
+ r1, r2, err := Syscall(SYS_OPEN, int64(uintptr(unsafe.Pointer(&namebuf[0]))), O_CREAT|O_WRONLY|O_TRUNC, perm);
return r1, err;
}
-export func Close(fd int64) (ret int64, errno int64) {
+func Close(fd int64) (ret int64, errno int64) {
r1, r2, err := Syscall(SYS_CLOSE, fd, 0, 0);
return r1, err;
}
-export func Read(fd int64, buf *byte, nbytes int64) (ret int64, errno int64) {
- r1, r2, err := Syscall(SYS_READ, fd, int64(uintptr(unsafe.pointer(buf))), nbytes);
+func Read(fd int64, buf *byte, nbytes int64) (ret int64, errno int64) {
+ r1, r2, err := Syscall(SYS_READ, fd, int64(uintptr(unsafe.Pointer(buf))), nbytes);
return r1, err;
}
-export func Write(fd int64, buf *byte, nbytes int64) (ret int64, errno int64) {
- r1, r2, err := Syscall(SYS_WRITE, fd, int64(uintptr(unsafe.pointer(buf))), nbytes);
+func Write(fd int64, buf *byte, nbytes int64) (ret int64, errno int64) {
+ r1, r2, err := Syscall(SYS_WRITE, fd, int64(uintptr(unsafe.Pointer(buf))), nbytes);
return r1, err;
}
-export func Pipe(fds *[2]int64) (ret int64, errno int64) {
+func Pipe(fds *[2]int64) (ret int64, errno int64) {
var t [2] int32;
- r1, r2, err := Syscall(SYS_PIPE, int64(uintptr(unsafe.pointer(&t[0]))), 0, 0);
+ r1, r2, err := Syscall(SYS_PIPE, int64(uintptr(unsafe.Pointer(&t[0]))), 0, 0);
if r1 < 0 {
return r1, err;
}
return 0, 0;
}
-export func Stat(name string, buf *Stat_t) (ret int64, errno int64) {
+func Stat(name string, buf *Stat_t) (ret int64, errno int64) {
var namebuf [nameBufsize]byte;
if !StringToBytes(namebuf, name) {
return -1, ENAMETOOLONG
}
- r1, r2, err := Syscall(SYS_STAT, int64(uintptr(unsafe.pointer(&namebuf[0]))), int64(uintptr(unsafe.pointer(buf))), 0);
+ r1, r2, err := Syscall(SYS_STAT, int64(uintptr(unsafe.Pointer(&namebuf[0]))), int64(uintptr(unsafe.Pointer(buf))), 0);
return r1, err;
}
-export func Lstat(name *byte, buf *Stat_t) (ret int64, errno int64) {
- r1, r2, err := Syscall(SYS_LSTAT, int64(uintptr(unsafe.pointer(name))), int64(uintptr(unsafe.pointer(buf))), 0);
+func Lstat(name *byte, buf *Stat_t) (ret int64, errno int64) {
+ r1, r2, err := Syscall(SYS_LSTAT, int64(uintptr(unsafe.Pointer(name))), int64(uintptr(unsafe.Pointer(buf))), 0);
return r1, err;
}
-export func Fstat(fd int64, buf *Stat_t) (ret int64, errno int64) {
- r1, r2, err := Syscall(SYS_FSTAT, fd, int64(uintptr(unsafe.pointer(buf))), 0);
+func Fstat(fd int64, buf *Stat_t) (ret int64, errno int64) {
+ r1, r2, err := Syscall(SYS_FSTAT, fd, int64(uintptr(unsafe.Pointer(buf))), 0);
return r1, err;
}
-export func Unlink(name string) (ret int64, errno int64) {
+func Unlink(name string) (ret int64, errno int64) {
var namebuf [nameBufsize]byte;
if !StringToBytes(namebuf, name) {
return -1, ENAMETOOLONG
}
- r1, r2, err := Syscall(SYS_UNLINK, int64(uintptr(unsafe.pointer(&namebuf[0]))), 0, 0);
+ r1, r2, err := Syscall(SYS_UNLINK, int64(uintptr(unsafe.Pointer(&namebuf[0]))), 0, 0);
return r1, err;
}
-export func Fcntl(fd, cmd, arg int64) (ret int64, errno int64) {
+func Fcntl(fd, cmd, arg int64) (ret int64, errno int64) {
r1, r2, err := Syscall(SYS_FCNTL, fd, cmd, arg);
return r1, err
}
-export func Mkdir(name string, perm int64) (ret int64, errno int64) {
+func Mkdir(name string, perm int64) (ret int64, errno int64) {
var namebuf [nameBufsize]byte;
if !StringToBytes(namebuf, name) {
return -1, ENAMETOOLONG
}
- r1, r2, err := Syscall(SYS_MKDIR, int64(uintptr(unsafe.pointer(&namebuf[0]))), perm, 0);
+ r1, r2, err := Syscall(SYS_MKDIR, int64(uintptr(unsafe.Pointer(&namebuf[0]))), perm, 0);
return r1, err;
}
-export func Dup2(fd1, fd2 int64) (ret int64, errno int64) {
+func Dup2(fd1, fd2 int64) (ret int64, errno int64) {
r1, r2, err := Syscall(SYS_DUP2, fd1, fd2, 0);
return r1, err;
}
package syscall
-export const(
+const(
SIGHUP = 1;
SIGINT = 2;
SIGQUIT = 3;
package syscall
-export const(
+const(
SIGHUP = 1;
SIGINT = 2;
SIGQUIT = 3;
"unsafe";
)
-export func SockaddrToSockaddrInet4(s *Sockaddr) *SockaddrInet4;
-export func SockaddrToSockaddrInet6(s *Sockaddr) *SockaddrInet6;
-export func SockaddrInet4ToSockaddr(s *SockaddrInet4) *Sockaddr;
-export func SockaddrInet6ToSockaddr(s *SockaddrInet6) *Sockaddr;
+func SockaddrToSockaddrInet4(s *Sockaddr) *SockaddrInet4;
+func SockaddrToSockaddrInet6(s *Sockaddr) *SockaddrInet6;
+func SockaddrInet4ToSockaddr(s *SockaddrInet4) *Sockaddr;
+func SockaddrInet6ToSockaddr(s *SockaddrInet6) *Sockaddr;
-export func Socket(domain, proto, typ int64) (ret int64, err int64) {
+func Socket(domain, proto, typ int64) (ret int64, err int64) {
r1, r2, e := Syscall(SYS_SOCKET, domain, proto, typ);
return r1, e
}
-export func Connect(fd int64, sa *Sockaddr) (ret int64, err int64) {
- r1, r2, e := Syscall(SYS_CONNECT, fd, int64(uintptr(unsafe.pointer(sa))), int64(sa.Len));
+func Connect(fd int64, sa *Sockaddr) (ret int64, err int64) {
+ r1, r2, e := Syscall(SYS_CONNECT, fd, int64(uintptr(unsafe.Pointer(sa))), int64(sa.Len));
return r1, e
}
-export func Bind(fd int64, sa *Sockaddr) (ret int64, err int64) {
- r1, r2, e := Syscall(SYS_BIND, fd, int64(uintptr(unsafe.pointer(sa))), int64(sa.Len));
+func Bind(fd int64, sa *Sockaddr) (ret int64, err int64) {
+ r1, r2, e := Syscall(SYS_BIND, fd, int64(uintptr(unsafe.Pointer(sa))), int64(sa.Len));
return r1, e
}
-export func Listen(fd, n int64) (ret int64, err int64) {
+func Listen(fd, n int64) (ret int64, err int64) {
r1, r2, e := Syscall(SYS_LISTEN, fd, n, 0);
return r1, e
}
-export func Accept(fd int64, sa *Sockaddr) (ret int64, err int64) {
+func Accept(fd int64, sa *Sockaddr) (ret int64, err int64) {
var n int32 = SizeofSockaddr;
- r1, r2, e := Syscall(SYS_ACCEPT, fd, int64(uintptr(unsafe.pointer(sa))), int64(uintptr(unsafe.pointer(&n))));
+ r1, r2, e := Syscall(SYS_ACCEPT, fd, int64(uintptr(unsafe.Pointer(sa))), int64(uintptr(unsafe.Pointer(&n))));
return r1, e
}
-export func Setsockopt(fd, level, opt, valueptr, length int64) (ret int64, err int64) {
+func Setsockopt(fd, level, opt, valueptr, length int64) (ret int64, err int64) {
if fd < 0 {
return -1, EINVAL
}
return r1, e
}
-export func Setsockopt_int(fd, level, opt int64, value int) int64 {
+func Setsockopt_int(fd, level, opt int64, value int) int64 {
var n int32 = int32(opt);
- r1, e := Setsockopt(fd, level, opt, int64(uintptr(unsafe.pointer(&n))), 4);
+ r1, e := Setsockopt(fd, level, opt, int64(uintptr(unsafe.Pointer(&n))), 4);
return e
}
-export func Setsockopt_tv(fd, level, opt, nsec int64) int64 {
+func Setsockopt_tv(fd, level, opt, nsec int64) int64 {
var tv Timeval;
nsec += 999;
tv.Sec = int64(nsec/1000000000);
tv.Usec = uint32(nsec%1000000000);
- r1, e := Setsockopt(fd, level, opt, int64(uintptr(unsafe.pointer(&tv))), 4);
+ r1, e := Setsockopt(fd, level, opt, int64(uintptr(unsafe.Pointer(&tv))), 4);
return e
}
-export func Setsockopt_linger(fd, level, opt int64, sec int) int64 {
+func Setsockopt_linger(fd, level, opt int64, sec int) int64 {
var l Linger;
if sec != 0 {
l.Yes = 1;
l.Yes = 0;
l.Sec = 0;
}
- r1, err := Setsockopt(fd, level, opt, int64(uintptr(unsafe.pointer(&l))), 8);
+ r1, err := Setsockopt(fd, level, opt, int64(uintptr(unsafe.Pointer(&l))), 8);
return err
}
/*
-export func Getsockopt(fd, level, opt, valueptr, lenptr int64) (ret int64, errno int64) {
+func Getsockopt(fd, level, opt, valueptr, lenptr int64) (ret int64, errno int64) {
r1, r2, err := Syscall6(SYS_GETSOCKOPT, fd, level, opt, valueptr, lenptr, 0);
return r1, err;
}
*/
-export func Kqueue() (ret int64, errno int64) {
+func Kqueue() (ret int64, errno int64) {
r1, r2, err := Syscall(SYS_KQUEUE, 0, 0, 0);
return r1, err
}
-export func Kevent(kq int64, changes, events []Kevent_t, timeout *Timespec) (ret int64, errno int64) {
+func Kevent(kq int64, changes, events []Kevent_t, timeout *Timespec) (ret int64, errno int64) {
var nchange, changeptr, nevent, eventptr int64;
nchange = 0;
changeptr = 0;
nevent = 0;
eventptr = 0;
if len(changes) > 0 {
- changeptr = int64(uintptr(unsafe.pointer(&changes[0])));
+ changeptr = int64(uintptr(unsafe.Pointer(&changes[0])));
nchange = int64(len(changes))
}
if len(events) > 0 {
- eventptr = int64(uintptr(unsafe.pointer(&events[0])));
+ eventptr = int64(uintptr(unsafe.Pointer(&events[0])));
nevent = int64(len(events))
}
r1, r2, err := Syscall6(SYS_KEVENT, kq, changeptr, nchange,
- eventptr, nevent, int64(uintptr(unsafe.pointer(timeout))));
+ eventptr, nevent, int64(uintptr(unsafe.Pointer(timeout))));
return r1, err
}
"unsafe";
)
-export func SockaddrToSockaddrInet4(s *Sockaddr) *SockaddrInet4;
-export func SockaddrToSockaddrInet6(s *Sockaddr) *SockaddrInet6;
-export func SockaddrInet4ToSockaddr(s *SockaddrInet4) *Sockaddr;
-export func SockaddrInet6ToSockaddr(s *SockaddrInet6) *Sockaddr;
+func SockaddrToSockaddrInet4(s *Sockaddr) *SockaddrInet4;
+func SockaddrToSockaddrInet6(s *Sockaddr) *SockaddrInet6;
+func SockaddrInet4ToSockaddr(s *SockaddrInet4) *Sockaddr;
+func SockaddrInet6ToSockaddr(s *SockaddrInet6) *Sockaddr;
func saLen(s *Sockaddr) int64 {
switch s.Family {
return 0
}
-export func Socket(domain, proto, typ int64) (ret int64, err int64) {
+func Socket(domain, proto, typ int64) (ret int64, err int64) {
r1, r2, e := Syscall(SYS_SOCKET, domain, proto, typ);
return r1, e
}
-export func Connect(fd int64, sa *Sockaddr) (ret int64, err int64) {
- r1, r2, e := Syscall(SYS_CONNECT, fd, int64(uintptr(unsafe.pointer(sa))), saLen(sa));
+func Connect(fd int64, sa *Sockaddr) (ret int64, err int64) {
+ r1, r2, e := Syscall(SYS_CONNECT, fd, int64(uintptr(unsafe.Pointer(sa))), saLen(sa));
return r1, e
}
-export func Bind(fd int64, sa *Sockaddr) (ret int64, err int64) {
- r1, r2, e := Syscall(SYS_BIND, fd, int64(uintptr(unsafe.pointer(sa))), saLen(sa));
+func Bind(fd int64, sa *Sockaddr) (ret int64, err int64) {
+ r1, r2, e := Syscall(SYS_BIND, fd, int64(uintptr(unsafe.Pointer(sa))), saLen(sa));
return r1, e
}
-export func Listen(fd, n int64) (ret int64, err int64) {
+func Listen(fd, n int64) (ret int64, err int64) {
r1, r2, e := Syscall(SYS_LISTEN, fd, n, 0);
return r1, e
}
-export func Accept(fd int64, sa *Sockaddr) (ret int64, err int64) {
+func Accept(fd int64, sa *Sockaddr) (ret int64, err int64) {
var n int32 = SizeofSockaddr;
- r1, r2, e := Syscall(SYS_ACCEPT, fd, int64(uintptr(unsafe.pointer(sa))), int64(uintptr(unsafe.pointer(&n))));
+ r1, r2, e := Syscall(SYS_ACCEPT, fd, int64(uintptr(unsafe.Pointer(sa))), int64(uintptr(unsafe.Pointer(&n))));
return r1, e
}
-export func Setsockopt(fd, level, opt, valueptr, length int64) (ret int64, err int64) {
+func Setsockopt(fd, level, opt, valueptr, length int64) (ret int64, err int64) {
if fd < 0 {
return -1, EINVAL
}
return r1, e
}
-export func Setsockopt_int(fd, level, opt int64, value int) int64 {
+func Setsockopt_int(fd, level, opt int64, value int) int64 {
n := int32(opt);
- r1, e := Setsockopt(fd, level, opt, int64(uintptr(unsafe.pointer(&n))), 4);
+ r1, e := Setsockopt(fd, level, opt, int64(uintptr(unsafe.Pointer(&n))), 4);
return e
}
-export func Setsockopt_tv(fd, level, opt, nsec int64) int64 {
+func Setsockopt_tv(fd, level, opt, nsec int64) int64 {
var tv Timeval;
nsec += 999;
tv.Sec = int64(nsec/1000000000);
tv.Usec = uint64(nsec%1000000000);
- r1, e := Setsockopt(fd, level, opt, int64(uintptr(unsafe.pointer(&tv))), 4);
+ r1, e := Setsockopt(fd, level, opt, int64(uintptr(unsafe.Pointer(&tv))), 4);
return e
}
-export func Setsockopt_linger(fd, level, opt int64, sec int) int64 {
+func Setsockopt_linger(fd, level, opt int64, sec int) int64 {
var l Linger;
if sec != 0 {
l.Yes = 1;
l.Yes = 0;
l.Sec = 0
}
- r1, err := Setsockopt(fd, level, opt, int64(uintptr(unsafe.pointer(&l))), 8);
+ r1, err := Setsockopt(fd, level, opt, int64(uintptr(unsafe.Pointer(&l))), 8);
return err
}
/*
-export func getsockopt(fd, level, opt, valueptr, lenptr int64) (ret int64, errno int64) {
+func getsockopt(fd, level, opt, valueptr, lenptr int64) (ret int64, errno int64) {
r1, r2, err := Syscall6(GETSOCKOPT, fd, level, opt, valueptr, lenptr, 0);
return r1, err;
}
*/
-export func Epoll_create(size int64) (ret int64, errno int64) {
+func Epoll_create(size int64) (ret int64, errno int64) {
r1, r2, err := syscall.Syscall(SYS_EPOLL_CREATE, size, 0, 0);
return r1, err
}
-export func Epoll_ctl(epfd, op, fd int64, ev *EpollEvent) int64 {
- r1, r2, err := syscall.Syscall6(SYS_EPOLL_CTL, epfd, op, fd, int64(uintptr(unsafe.pointer(ev))), 0, 0);
+func Epoll_ctl(epfd, op, fd int64, ev *EpollEvent) int64 {
+ r1, r2, err := syscall.Syscall6(SYS_EPOLL_CTL, epfd, op, fd, int64(uintptr(unsafe.Pointer(ev))), 0, 0);
return err
}
-export func Epoll_wait(epfd int64, ev []EpollEvent, msec int64) (ret int64, err int64) {
+func Epoll_wait(epfd int64, ev []EpollEvent, msec int64) (ret int64, err int64) {
var evptr, nev int64;
if ev != nil && len(ev) > 0 {
nev = int64(len(ev));
- evptr = int64(uintptr(unsafe.pointer(&ev[0])))
+ evptr = int64(uintptr(unsafe.Pointer(&ev[0])))
}
r1, r2, err1 := syscall.Syscall6(SYS_EPOLL_WAIT, epfd, evptr, nev, msec, 0, 0);
return r1, err1
* Foundation of system call interface.
*/
-export func Syscall(trap int64, a1, a2, a3 int64) (r1, r2, err int64);
-export func Syscall6(trap int64, a1, a2, a3, a4, a5, a6 int64) (r1, r2, err int64);
-export func RawSyscall(trap int64, a1, a2, a3 int64) (r1, r2, err int64);
+func Syscall(trap int64, a1, a2, a3 int64) (r1, r2, err int64);
+func Syscall6(trap int64, a1, a2, a3, a4, a5, a6 int64) (r1, r2, err int64);
+func RawSyscall(trap int64, a1, a2, a3 int64) (r1, r2, err int64);
/*
* Used to convert file names to byte arrays for passing to kernel,
* but useful elsewhere too.
*/
-export func StringToBytes(b []byte, s string) bool {
+func StringToBytes(b []byte, s string) bool {
if len(s) >= len(b) {
return false
}
package syscall
-export const (
+const (
// SYS_NOSYS = 0; // { int nosys(void); } { indirect syscall }
SYS_EXIT = 1; // { void exit(int rval); }
SYS_FORK = 2; // { int fork(void); }
package syscall
-export const(
+const(
SYS_READ = 0;
SYS_WRITE = 1;
SYS_OPEN = 2;
import syscall "syscall"
-export func Gettimeofday() (sec, nsec, errno int64) {
+func Gettimeofday() (sec, nsec, errno int64) {
// The "1" in the call is the timeval pointer, which must be
// non-zero but is otherwise unused. The results
// are returned in r1, r2.
return r1, r2*1000, 0
}
-export func Nstotimeval(ns int64, tv *Timeval) {
+func Nstotimeval(ns int64, tv *Timeval) {
ns += 999; // round up
tv.Sec = int64(ns/1000000000);
tv.Usec = uint32(ns%1000000000 / 1000);
"unsafe";
)
-export func Gettimeofday() (sec, nsec, errno int64) {
+func Gettimeofday() (sec, nsec, errno int64) {
var tv Timeval;
- r1, r2, e := Syscall(SYS_GETTIMEOFDAY, int64(uintptr(unsafe.pointer(&tv))), 0, 0);
+ r1, r2, e := Syscall(SYS_GETTIMEOFDAY, int64(uintptr(unsafe.Pointer(&tv))), 0, 0);
if e != 0 {
return 0, 0, e
}
return int64(tv.Sec), int64(tv.Usec*1000), 0
}
-export func Nstotimeval(ns int64, tv *Timeval) {
+func Nstotimeval(ns int64, tv *Timeval) {
ns += 999; // round up
tv.Sec = int64(ns/1000000000);
tv.Usec = uint64(ns%1000000000 / 1000);
// Time
-export type Timespec struct {
+type Timespec struct {
Sec int64;
Nsec uint64;
}
-export type Timeval struct {
+type Timeval struct {
Sec int64;
Usec uint32;
}
// Processes
-export type Rusage struct {
+type Rusage struct {
Utime Timeval;
Stime Timeval;
Maxrss int64;
// Files
-export const (
+const (
O_RDONLY = 0x0;
O_WRONLY = 0x1;
O_RDWR = 0x2;
FD_CLOEXEC = 1;
)
-export type Stat_t struct {
+type Stat_t struct {
Dev uint32;
Mode uint16;
Nlink uint16;
// Sockets
-export const (
+const (
AF_UNIX = 1;
AF_INET = 2;
AF_DATAKIT = 9;
SOMAXCONN = 128;
)
-export type SockaddrUnix struct {
+type SockaddrUnix struct {
Len byte;
Family byte;
Path [104]byte
}
-export const SizeofSockaddrUnix = 106
+const SizeofSockaddrUnix = 106
-export type SockaddrInet4 struct {
+type SockaddrInet4 struct {
Len byte;
Family byte;
Port [2]byte;
Addr [4]byte;
Zero [8]byte
}
-export const SizeofSockaddrInet4 = 16
+const SizeofSockaddrInet4 = 16
-export type SockaddrInet6 struct {
+type SockaddrInet6 struct {
Len byte;
Family byte;
Port [2]byte;
Addr [16]byte;
Scopeid [4]byte;
}
-export const SizeofSockaddrInet6 = 28
+const SizeofSockaddrInet6 = 28
-export type Sockaddr struct {
+type Sockaddr struct {
Len byte;
Family byte;
Opaque [126]byte
}
-export const SizeofSockaddr = 128
+const SizeofSockaddr = 128
-export type Linger struct {
+type Linger struct {
Yes int32;
Sec int32;
}
// Events (kqueue, kevent)
-export const (
+const (
// filters
EVFILT_READ = -1;
EVFILT_WRITE = -2;
EV_ERROR = 0x4000
)
-export type Kevent_t struct {
+type Kevent_t struct {
Ident int64;
Filter int16;
Flags uint16;
// Time
-export type Timespec struct {
+type Timespec struct {
Sec int64;
Nsec uint64;
}
-export type Timeval struct {
+type Timeval struct {
Sec int64;
Usec uint64;
}
// Processes
-export type Rusage struct {
+type Rusage struct {
Utime Timeval;
Stime Timeval;
Maxrss int64;
// Files
-export const (
+const (
O_RDONLY = 0x0;
O_WRONLY = 0x1;
O_RDWR = 0x2;
FD_CLOEXEC = 1;
)
-export type Stat_t struct {
+type Stat_t struct {
Dev uint64;
Ino uint64;
Nlink uint64;
// Sockets
-export const (
+const (
AF_UNIX = 1;
AF_INET = 2;
AF_INET6 = 10;
SOMAXCONN = 128;
)
-export type SockaddrUnix struct {
+type SockaddrUnix struct {
Family uint16;
Path [108]byte
}
-export const SizeofSockaddrUnix = 110
+const SizeofSockaddrUnix = 110
-export type SockaddrInet4 struct {
+type SockaddrInet4 struct {
Family uint16;
Port [2]byte;
Addr [4]byte;
Zero [8]byte
}
-export const SizeofSockaddrInet4 = 16
+const SizeofSockaddrInet4 = 16
-export type SockaddrInet6 struct {
+type SockaddrInet6 struct {
Family uint16;
Port [2]byte;
Flowinfo [4]byte;
Addr [16]byte;
Scopeid [4]byte;
}
-export const SizeofSockaddrInet6 = 28
+const SizeofSockaddrInet6 = 28
-export type Sockaddr struct {
+type Sockaddr struct {
Family uint16;
Opaque [126]byte
}
-export const SizeofSockaddr = 128
+const SizeofSockaddr = 128
-export type Linger struct {
+type Linger struct {
Yes int32;
Sec int32;
}
// Events (epoll)
-export const (
+const (
// EpollEvent.events
EPOLLIN = 0x1;
EPOLLOUT = 0x4;
EPOLL_CTL_DEL = 0x2;
)
-export type EpollEvent struct {
+type EpollEvent struct {
Events uint32;
Fd int32;
Pad int32;
// filter_html ignores html tags and handles entities (starting with '&'
// and ending in ';') as single characters (width = 1)
-export type Writer struct {
+type Writer struct {
// TODO should not export any of the fields
// configuration
writer io.Write;
}
-export func New(writer io.Write, cellwidth, padding int, padchar byte, align_left, filter_html bool) *Writer {
+func New(writer io.Write, cellwidth, padding int, padchar byte, align_left, filter_html bool) *Writer {
return new(Writer).Init(writer, cellwidth, padding, padchar, align_left, filter_html)
}
}
-export func Test(t *testing.T) {
+func Test(t *testing.T) {
check(
t, 8, 1, '.', true, false,
"",
return s
}
-export type T struct {
+type T struct {
errors string;
failed bool;
ch chan *T;
t.FailNow();
}
-export type Test struct {
+type Test struct {
Name string;
F *(*T);
}
t.ch <- t;
}
-export func Main(tests []Test) {
+func Main(tests []Test) {
flag.Parse();
ok := true;
if len(tests) == 0 {
}
syscall.Nstotimeval(when - now, &tv);
- syscall.Syscall6(syscall.SYS_SELECT, 0, 0, 0, 0, int64(uintptr(unsafe.pointer(&tv))), 0);
+ syscall.Syscall6(syscall.SYS_SELECT, 0, 0, 0, 0, int64(uintptr(unsafe.Pointer(&tv))), 0);
now = time.Nanoseconds();
c <- now;
}
}
-export func Tick(ns int64) chan int64 {
+func Tick(ns int64) chan int64 {
if ns <= 0 {
return nil
}
"time";
)
-export func TestTick(t *testing.T) {
+func TestTick(t *testing.T) {
const (
Delta = 100*1e6;
Count = 10;
)
// Seconds since January 1, 1970 00:00:00 GMT
-export func Seconds() int64 {
+func Seconds() int64 {
sec, nsec, err := os.Time();
if err != nil {
panic("time: os.Time: ", err.String());
}
// Nanoseconds since January 1, 1970 00:00:00 GMT
-export func Nanoseconds() int64 {
+func Nanoseconds() int64 {
sec, nsec, err := os.Time();
if err != nil {
panic("time: os.Time: ", err.String());
return sec*1e9 + nsec
}
-export const (
+const (
Sunday = iota;
Monday;
Tuesday;
Saturday;
)
-export type Time struct {
+type Time struct {
year int64; // 2008 is 2008
month, day int; // Sep-17 is 9, 17
hour, minute, second int; // 10:43:12 is 10, 43, 12
_Days1970To2001 = 31*365+8;
)
-export func SecondsToUTC(sec int64) *Time {
+func SecondsToUTC(sec int64) *Time {
t := new(Time);
// Split into time and day.
return t;
}
-export func UTC() *Time {
+func UTC() *Time {
return SecondsToUTC(Seconds())
}
// TODO: Should this return an error?
-export func SecondsToLocalTime(sec int64) *Time {
+func SecondsToLocalTime(sec int64) *Time {
zone, offset, err := time.LookupTimezone(sec);
if err != nil {
return SecondsToUTC(sec)
return t
}
-export func LocalTime() *Time {
+func LocalTime() *Time {
return SecondsToLocalTime(Seconds())
}
&& t.zone == u.zone
}
-export func TestSecondsToUTC(t *testing.T) {
+func TestSecondsToUTC(t *testing.T) {
for i := 0; i < len(utctests); i++ {
sec := utctests[i].seconds;
golden := &utctests[i].golden;
}
}
-export func TestSecondsToLocalTime(t *testing.T) {
+func TestSecondsToLocalTime(t *testing.T) {
for i := 0; i < len(localtests); i++ {
sec := localtests[i].seconds;
golden := &localtests[i].golden;
_HeaderSize = 4+16+4*7
)
-export var (
+var (
BadZoneinfo = os.NewError("time: malformed zoneinfo");
NoZoneinfo = os.NewError("time: unknown time zone")
)
zones, zoneerr = readinfofile("/etc/localtime");
}
-export func LookupTimezone(sec int64) (zone string, offset int, err *os.Error) {
+func LookupTimezone(sec int64) (zone string, offset int, err *os.Error) {
once.Do(&_SetupZone);
if zoneerr != nil || len(zones) == 0 {
return "GMT", 0, zoneerr
package unicode
-export type Range struct {
+type Range struct {
lo int;
hi int;
stride int;
}
-export var Upper = []Range{
+var Upper = []Range{
Range{0x0041, 0x005a, 1},
Range{0x00c0, 0x00d6, 1},
Range{0x00d8, 0x00de, 1},
Range{0x1d7ca, 0x1d7ca, 1},
}
-export var Letter = []Range {
+var Letter = []Range {
Range{0x0041, 0x005a, 1},
Range{0x0061, 0x007a, 1},
Range{0x00aa, 0x00b5, 11},
Range{0x2f800, 0x2fa1d, 1},
}
-export func Is(ranges []Range, rune int) bool {
+func Is(ranges []Range, rune int) bool {
// common case: rune is ASCII or Latin-1
if rune < 0x100 {
for i := 0; i < len(ranges); i++ {
return false;
}
-export func IsUpper(rune int) bool {
+func IsUpper(rune int) bool {
return Is(Upper, rune);
}
-export func IsLetter(rune int) bool {
+func IsLetter(rune int) bool {
return Is(Letter, rune);
}
0x10ffff,
}
-export func TestIsLetter(t *testing.T) {
+func TestIsLetter(t *testing.T) {
for i, r := range(upper) {
if !IsLetter(r) {
t.Errorf("IsLetter(%#x) = false, want true\n", r);
}
}
-export func TestIsUpper(t *testing.T) {
+func TestIsUpper(t *testing.T) {
for i, r := range(upper) {
if !IsUpper(r) {
t.Errorf("IsUpper(%#x) = false, want true\n", r);
package utf8
-export const (
+const (
RuneError = 0xFFFD;
RuneSelf = 0x80;
RuneMax = 0x10FFFF;
return RuneError, 1, false
}
-export func FullRune(p []byte) bool {
+func FullRune(p []byte) bool {
rune, size, short := decodeRuneInternal(p);
return !short
}
-export func FullRuneInString(s string, i int) bool {
+func FullRuneInString(s string, i int) bool {
rune, size, short := decodeRuneInStringInternal(s, i, len(s) - i);
return !short
}
-export func DecodeRune(p []byte) (rune, size int) {
+func DecodeRune(p []byte) (rune, size int) {
var short bool;
rune, size, short = decodeRuneInternal(p);
return;
}
-export func DecodeRuneInString(s string, i int) (rune, size int) {
+func DecodeRuneInString(s string, i int) (rune, size int) {
var short bool;
rune, size, short = decodeRuneInStringInternal(s, i, len(s) - i);
return;
}
-export func RuneLen(rune int) int {
+func RuneLen(rune int) int {
switch {
case rune <= _Rune1Max:
return 1;
return -1;
}
-export func EncodeRune(rune int, p []byte) int {
+func EncodeRune(rune int, p []byte) int {
if rune <= _Rune1Max {
p[0] = byte(rune);
return 1;
return 4;
}
-export func RuneCount(p []byte) int {
+func RuneCount(p []byte) int {
i := 0;
var n int;
for n = 0; i < len(p); n++ {
return n;
}
-export func RuneCountInString(s string, i int, l int) int {
+func RuneCountInString(s string, i int, l int) int {
ei := i + l;
n := 0;
for n = 0; i < ei; n++ {
"utf8";
)
-export type Utf8Map struct {
+type Utf8Map struct {
rune int;
str string;
}
return b[0:len(s)];
}
-export func TestFullRune(t *testing.T) {
+func TestFullRune(t *testing.T) {
for i := 0; i < len(utf8map); i++ {
m := utf8map[i];
b := bytes(m.str);
return true;
}
-export func TestEncodeRune(t *testing.T) {
+func TestEncodeRune(t *testing.T) {
for i := 0; i < len(utf8map); i++ {
m := utf8map[i];
b := bytes(m.str);
}
}
-export func TestDecodeRune(t *testing.T) {
+func TestDecodeRune(t *testing.T) {
for i := 0; i < len(utf8map); i++ {
m := utf8map[i];
b := bytes(m.str);
}
}
-export type RuneCountTest struct {
+type RuneCountTest struct {
in string;
out int;
}
RuneCountTest{ "1,2,3,4", 7 },
RuneCountTest{ "\xe2\x00", 2 },
}
-export func TestRuneCount(t *testing.T) {
+func TestRuneCount(t *testing.T) {
for i := 0; i < len(runecounttests); i++ {
tt := runecounttests[i];
if out := utf8.RuneCountInString(tt.in, 0, len(tt.in)); out != tt.out {
package main
-export type T chan uint64;
+type T chan uint64;
-export func M(f uint64) (in, out T) {
+func M(f uint64) (in, out T) {
in = make(T, 100);
out = make(T, 100);
go func(in, out T, f uint64) {
"fmt";
)
-export type T struct {
+type T struct {
a float64;
b int64;
c string;
}
var a = []int{ 1, 2, 3 }
-export var NIL []int;
+var NIL []int;
func arraycmptest() {
a1 := a;
}
}
-export func SameArray(a, b []int) bool {
+func SameArray(a, b []int) bool {
if len(a) != len(b) || cap(a) != cap(b) {
return false;
}
}
}
-export type E struct { }
+type E struct { }
var e E
func interfacetest() {
// license that can be found in the LICENSE file.
package main
-export type S struct { a int }
-export type PS *S
+type S struct { a int }
+type PS *S
func (p *S) get() int {
return p.a
}
package main
-export type T ()
+type T ()
-export type I interface {
+type I interface {
f, g ();
h T; // should only allow FunctionType here
}
-export type S struct {
+type S struct {
}
func (s *S) f() {}
// license that can be found in the LICENSE file.
package main
-export const ( F = 1 )
+const ( F = 1 )
func fn(i int) int {
if i == F() { // ERROR "function"
return 0
package main
-export type I interface { send(chan <- int) }
+type I interface { send(chan <- int) }
-export type S struct { v int }
+type S struct { v int }
func (p *S) send(c chan <- int) { c <- p.v }
func main() {
package main
-export const N = 10
+const N = 10
-export func AsynchFifo() {
+func AsynchFifo() {
ch := make(chan int, N);
for i := 0; i < N; i++ {
ch <- i
}
}
-export func Chain(ch <-chan int, val int, in <-chan int, out chan<- int) {
+func Chain(ch <-chan int, val int, in <-chan int, out chan<- int) {
<-in;
if <-ch != val {
panic(val)
}
// thread together a daisy chain to read the elements in sequence
-export func SynchFifo() {
+func SynchFifo() {
ch := make(chan int);
in := make(chan int);
start := in;
var chnameserial int
var seqno int
-export func Init();
+func Init();
func mkdch() *dch {
c := chnameserial % len(chnames);
}
}
-export type PS *dch; // power series
-export type PS2 *[2] PS; // pair of power series
+type PS *dch; // power series
+type PS2 *[2] PS; // pair of power series
-export var Ones PS
-export var Twos PS
+var Ones PS
+var Twos PS
func mkPS() *dch {
return mkdch()
}
// print eval in floating point of PS at x=c to n terms
-export func Evaln(c *rat, U PS, n int)
+func Evaln(c *rat, U PS, n int)
{
xn := float64(1);
x := float64(c.num)/float64(c.den);
}
// Print n terms of a power series
-export func Printn(U PS, n int){
+func Printn(U PS, n int){
done := false;
for ; !done && n>0; n-- {
u := get(U);
print(("\n"));
}
-export func Print(U PS){
+func Print(U PS){
Printn(U,1000000000);
}
// Make a pair of power series identical to a given power series
-export func Split(U PS) *dch2{
+func Split(U PS) *dch2{
UU := mkdch2();
go split(U,UU);
return UU;
}
// Add two power series
-export func Add(U, V PS) PS{
+func Add(U, V PS) PS{
Z := mkPS();
go func(U, V, Z PS){
var uv [] *rat;
}
// Multiply a power series by a constant
-export func Cmul(c *rat,U PS) PS{
+func Cmul(c *rat,U PS) PS{
Z := mkPS();
go func(c *rat, U, Z PS){
done := false;
// Subtract
-export func Sub(U, V PS) PS{
+func Sub(U, V PS) PS{
return Add(U, Cmul(neg(one), V));
}
// Multiply a power series by the monomial x^n
-export func Monmul(U PS, n int) PS{
+func Monmul(U PS, n int) PS{
Z := mkPS();
go func(n int, U PS, Z PS){
for ; n>0; n-- { put(zero,Z) }
// Multiply by x
-export func Xmul(U PS) PS{
+func Xmul(U PS) PS{
return Monmul(U,1);
}
-export func Rep(c *rat) PS{
+func Rep(c *rat) PS{
Z := mkPS();
go repeat(c,Z);
return Z;
// Monomial c*x^n
-export func Mon(c *rat, n int) PS{
+func Mon(c *rat, n int) PS{
Z:=mkPS();
go func(c *rat, n int, Z PS){
if(c.num!=0) {
return Z;
}
-export func Shift(c *rat, U PS) PS{
+func Shift(c *rat, U PS) PS{
Z := mkPS();
go func(c *rat, U, Z PS){
put(c,Z);
// to a (finite) power series
/* BUG: NEED LEN OF ARRAY
-export func Poly(a [] *rat) PS{
+func Poly(a [] *rat) PS{
Z:=mkPS();
begin func(a [] *rat, Z PS){
j:=0;
// let V = v + x*VV
// then UV = u*v + x*(u*VV+v*UU) + x*x*UU*VV
-export func Mul(U, V PS) PS{
+func Mul(U, V PS) PS{
Z:=mkPS();
go func(U, V, Z PS){
<-Z.req;
// Differentiate
-export func Diff(U PS) PS{
+func Diff(U PS) PS{
Z:=mkPS();
go func(U, Z PS){
<-Z.req;
}
// Integrate, with const of integration
-export func Integ(c *rat,U PS) PS{
+func Integ(c *rat,U PS) PS{
Z:=mkPS();
go func(c *rat, U, Z PS){
put(c,Z);
// Binomial theorem (1+x)^c
-export func Binom(c *rat) PS{
+func Binom(c *rat) PS{
Z:=mkPS();
go func(c *rat, Z PS){
n := 1;
// u*ZZ + z*UU +x*UU*ZZ = 0
// ZZ = -UU*(z+x*ZZ)/u;
-export func Recip(U PS) PS{
+func Recip(U PS) PS{
Z:=mkPS();
go func(U, Z PS){
ZZ:=mkPS2();
// DZ = Z*DU
// integrate to get Z
-export func Exp(U PS) PS{
+func Exp(U PS) PS{
ZZ := mkPS2();
split(Integ(one,Mul(ZZ[0],Diff(U))),ZZ);
return ZZ[1];
// then S(U,V) = u + VV*S(V,UU)
// bug: a nonzero constant term is ignored
-export func Subst(U, V PS) PS {
+func Subst(U, V PS) PS {
Z:= mkPS();
go func(U, V, Z PS) {
VV := Split(V);
// Monomial Substition: U(c x^n)
// Each Ui is multiplied by c^i and followed by n-1 zeros
-export func MonSubst(U PS, c0 *rat, n int) PS {
+func MonSubst(U PS, c0 *rat, n int) PS {
Z:= mkPS();
go func(U, Z PS, c0 *rat, n int) {
c := one;
}
-export func Init() {
+func Init() {
chnameserial = -1;
seqno = 0;
chnames = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
}
}
-export const N=10
+const N=10
func checka(U PS, a []*rat, str string) {
for i := 0; i < N; i++ {
check(U, a[i], 1, str);
var chnameserial int
var seqno int
-export func Init();
+func Init();
func mkdch() *dch {
c := chnameserial % len(chnames);
}
}
-export type PS *dch; // power series
-export type PS2 *[2] PS; // pair of power series
+type PS *dch; // power series
+type PS2 *[2] PS; // pair of power series
-export var Ones PS
-export var Twos PS
+var Ones PS
+var Twos PS
func mkPS() *dch {
return mkdch()
}
// print eval in floating point of PS at x=c to n terms
-export func Evaln(c *rat, U PS, n int)
+func Evaln(c *rat, U PS, n int)
{
xn := float64(1);
x := float64(c.num)/float64(c.den);
}
// Print n terms of a power series
-export func Printn(U PS, n int){
+func Printn(U PS, n int){
done := false;
for ; !done && n>0; n-- {
u := get(U);
print(("\n"));
}
-export func Print(U PS){
+func Print(U PS){
Printn(U,1000000000);
}
// Make a pair of power series identical to a given power series
-export func Split(U PS) *dch2{
+func Split(U PS) *dch2{
UU := mkdch2();
go split(U,UU);
return UU;
}
// Add two power series
-export func Add(U, V PS) PS{
+func Add(U, V PS) PS{
Z := mkPS();
go func(U, V, Z PS){
var uv [] item;
}
// Multiply a power series by a constant
-export func Cmul(c *rat,U PS) PS{
+func Cmul(c *rat,U PS) PS{
Z := mkPS();
go func(c *rat, U, Z PS){
done := false;
// Subtract
-export func Sub(U, V PS) PS{
+func Sub(U, V PS) PS{
return Add(U, Cmul(neg(one), V));
}
// Multiply a power series by the monomial x^n
-export func Monmul(U PS, n int) PS{
+func Monmul(U PS, n int) PS{
Z := mkPS();
go func(n int, U PS, Z PS){
for ; n>0; n-- { put(zero,Z) }
// Multiply by x
-export func Xmul(U PS) PS{
+func Xmul(U PS) PS{
return Monmul(U,1);
}
-export func Rep(c *rat) PS{
+func Rep(c *rat) PS{
Z := mkPS();
go repeat(c,Z);
return Z;
// Monomial c*x^n
-export func Mon(c *rat, n int) PS{
+func Mon(c *rat, n int) PS{
Z:=mkPS();
go func(c *rat, n int, Z PS){
if(c.num!=0) {
return Z;
}
-export func Shift(c *rat, U PS) PS{
+func Shift(c *rat, U PS) PS{
Z := mkPS();
go func(c *rat, U, Z PS){
put(c,Z);
// to a (finite) power series
/* BUG: NEED LEN OF ARRAY
-export func Poly(a [] *rat) PS{
+func Poly(a [] *rat) PS{
Z:=mkPS();
begin func(a [] *rat, Z PS){
j:=0;
// let V = v + x*VV
// then UV = u*v + x*(u*VV+v*UU) + x*x*UU*VV
-export func Mul(U, V PS) PS{
+func Mul(U, V PS) PS{
Z:=mkPS();
go func(U, V, Z PS){
<-Z.req;
// Differentiate
-export func Diff(U PS) PS{
+func Diff(U PS) PS{
Z:=mkPS();
go func(U, Z PS){
<-Z.req;
}
// Integrate, with const of integration
-export func Integ(c *rat,U PS) PS{
+func Integ(c *rat,U PS) PS{
Z:=mkPS();
go func(c *rat, U, Z PS){
put(c,Z);
// Binomial theorem (1+x)^c
-export func Binom(c *rat) PS{
+func Binom(c *rat) PS{
Z:=mkPS();
go func(c *rat, Z PS){
n := 1;
// u*ZZ + z*UU +x*UU*ZZ = 0
// ZZ = -UU*(z+x*ZZ)/u;
-export func Recip(U PS) PS{
+func Recip(U PS) PS{
Z:=mkPS();
go func(U, Z PS){
ZZ:=mkPS2();
// DZ = Z*DU
// integrate to get Z
-export func Exp(U PS) PS{
+func Exp(U PS) PS{
ZZ := mkPS2();
split(Integ(one,Mul(ZZ[0],Diff(U))),ZZ);
return ZZ[1];
// then S(U,V) = u + VV*S(V,UU)
// bug: a nonzero constant term is ignored
-export func Subst(U, V PS) PS {
+func Subst(U, V PS) PS {
Z:= mkPS();
go func(U, V, Z PS) {
VV := Split(V);
// Monomial Substition: U(c x^n)
// Each Ui is multiplied by c^i and followed by n-1 zeros
-export func MonSubst(U PS, c0 *rat, n int) PS {
+func MonSubst(U PS, c0 *rat, n int) PS {
Z:= mkPS();
go func(U, Z PS, c0 *rat, n int) {
c := one;
}
-export func Init() {
+func Init() {
chnameserial = -1;
seqno = 0;
chnames = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
}
}
-export const N=10
+const N=10
func checka(U PS, a []*rat, str string) {
for i := 0; i < N; i++ {
check(U, a[i], 1, str);
var counter uint
var shift uint
-export func GetValue() uint {
+func GetValue() uint {
counter++;
return 1 << shift
}
-export func Send(a, b chan uint) int {
+func Send(a, b chan uint) int {
var i int;
LOOP:
for {
package main
// Send the sequence 2, 3, 4, ... to channel 'ch'.
-export func Generate(ch chan<- int) {
+func Generate(ch chan<- int) {
for i := 2; ; i++ {
ch <- i // Send 'i' to channel 'ch'.
}
// Copy the values from channel 'in' to channel 'out',
// removing those divisible by 'prime'.
-export func Filter(in <-chan int, out chan<- int, prime int) {
+func Filter(in <-chan int, out chan<- int, prime int) {
for {
i := <-in; // Receive value of new variable 'i' from 'in'.
if i % prime != 0 {
}
// The prime sieve: Daisy-chain Filter processes together.
-export func Sieve(primes chan<- int) {
+func Sieve(primes chan<- int) {
ch := make(chan int); // Create a new channel.
go Generate(ch); // Start Generate() as a subprocess.
for {
package main
-export type T struct { i int; f float; s string; next *T }
+type T struct { i int; f float; s string; next *T }
-export type R struct { num int }
+type R struct { num int }
func itor(a int) *R {
r := new(R);
}
}
-export type P struct { a, b int };
-export func NewP(a, b int) *P {
+type P struct { a, b int };
+func NewP(a, b int) *P {
return &P{a, b}
}
package main
-export type A struct // ERROR "incomplete"
-export type B interface // ERROR "incomplete"
+type A struct // ERROR "incomplete"
+type B interface // ERROR "incomplete"
-export type C struct
-export type D interface
+type C struct
+type D interface
-export type C struct { }
-export type D interface { }
+type C struct { }
+type D interface { }
package main
-export type (
+type (
Point struct { x, y float };
Polar Point
)
package main
-export type T struct {
+type T struct {
x, y int;
}
package main
-export type Type interface {
+type Type interface {
TypeName() string;
}
-export type TInt struct {
+type TInt struct {
}
// TInt
package main
-export foo
+foo
func main() {}
package main
-export type Element interface {
+type Element interface {
}
-export type Vector struct {
+type Vector struct {
}
func (v *Vector) Insert(i int, e Element) {
package main
-export type Element interface {
+type Element interface {
}
-export type Vector struct {
+type Vector struct {
nelem int;
elem []Element;
}
-export func New() *Vector {
+func New() *Vector {
v := new(Vector);
v.nelem = 0;
v.elem = make([]Element, 10);
package main
-export func Alloc(i int) int {
+func Alloc(i int) int {
switch i {
default:
return 5;
package main
-export type S struct {
+type S struct {
};
func (p *S) M1a() ;
package main
-export type T struct {
+type T struct {
i int
}
package main
-export type T *struct {}
+type T *struct {}
func (x T) M () {} // ERROR "pointer|receiver"
package main
-export type Element interface {
+type Element interface {
}
-export type Vector struct {
+type Vector struct {
elem []Element;
}
return v.elem[i];
}
-export type TStruct struct {
+type TStruct struct {
name string;
fields *Vector;
}
package main
-export type T struct {
+type T struct {
s string;
}
}
/*
-uetli:/home/gri/go/test/bugs gri$ 6g bug057.go
+uetli:/home/gri/go/test/bugs gri$ 6g bug057.go
bug057.go:14: syntax error
*/
package main
-export type Box struct {};
+type Box struct {};
var m map[string] *Box;
func main() {
package main
-export func P(a []string) string {
+func P(a []string) string {
s := "{";
for i := 0; i < 2; i++ {
if i > 0 {
package main
-export type (
+type (
Type struct;
Object struct;
)
-export type Scope struct {
+type Scope struct {
entries map[string] *Object;
}
-export type Type struct {
+type Type struct {
scope *Scope;
}
-export type Object struct {
+type Object struct {
typ *Type;
}
-export func Lookup(scope *Scope) *Object {
+func Lookup(scope *Scope) *Object {
return scope.entries["foo"];
}
package main
-export type T struct { m map[int]int }
+type T struct { m map[int]int }
func main() {
t := new(T);
t.m = make(map[int]int);
package bug0
-export type T0 struct {
+type T0 struct {
}
-export var V0 T0
+var V0 T0
package main
-export type Service struct {
+type Service struct {
rpc [2]int;
}
package bug0
-export var V0 *() int;
-export var V1 *() (a int);
-export var V2 *() (a, b int);
+var V0 *() int;
+var V1 *() (a int);
+var V2 *() (a, b int);
package main
-export type I1 interface {}
-export type I2 interface { pr() }
+type I1 interface {}
+type I2 interface { pr() }
func e() I1;
package main
-export type S struct {
+type S struct {
}
func (p *S) M() {
print("M\n");
}
-export type I interface {
+type I interface {
M();
}
package main
-export type A []int;
+type A []int;
func main() {
a := &A{0};
/*
uetli:~/Source/go1/test/bugs gri$ 6g bug096.go && 6l bug096.6 && 6.out
Trace/BPT trap
-uetli:~/Source/go1/test/bugs gri$
+uetli:~/Source/go1/test/bugs gri$
*/
/*
package main
-export type A []int;
+type A []int;
func main() {
var a [3]A;
package main
-export type A []int;
-export type M map[int] int;
+type A []int;
+type M map[int] int;
func main() {
var a *A = &A{0};
package main
// Interface
-export type I interface { F() int }
+type I interface { F() int }
// Implements interface
-export type S struct { }
+type S struct { }
func (s *S) F() int { return 1 }
// Allocates S but returns I
// Arg is unused but important:
// if you take it out (and the 0s below)
// then the bug goes away.
-export func NewI(i int) I {
+func NewI(i int) I {
return new(S)
}
// Uses interface method.
-export func Use(x I) {
+func Use(x I) {
x.F()
}
// license that can be found in the LICENSE file.
package bug0
-export const A = -1
+const A = -1
var ncall int;
-export type Iffy interface {
+type Iffy interface {
Me() Iffy
}
-export type Stucky struct {
+type Stucky struct {
n int
}
package main
-export type T struct { s string }
+type T struct { s string }
var t = T{"hi"}
func main() {}
// license that can be found in the LICENSE file.
package main
-export type I interface { };
+type I interface { };
func foo1(i int) int { return i }
func foo2(i int32) int32 { return i }
func main() {
package main
-export const B32 = 1<<32 - 1
-export const C32 = (-1) & ((1<<32) - 1)
-export const D32 = ^0
+const B32 = 1<<32 - 1
+const C32 = (-1) & ((1<<32) - 1)
+const D32 = ^0
func main() {
if B32 != 0xFFFFFFFF {
package main
-export func Send(c chan int) int {
+func Send(c chan int) int {
select {
default:
return 1;
import "strconv";
-export type Test struct {
+type Test struct {
f float64;
in string;
out string;
return 8, 8.0;
}
-export type T struct {
+type T struct {
x, y int;
}
// ----------------------------------------------------------------------------
// Helper functions
-export func ASSERT(p bool) {
+func ASSERT(p bool) {
if !p {
// panic 0;
}
// ----------------------------------------------------------------------------
// Implementation of the HashMap
-export type KeyType interface {
+type KeyType interface {
Hash() uint32;
Match(other *KeyType) bool
}
-export type ValueType interface {
+type ValueType interface {
// empty interface
}
-export type Entry struct {
+type Entry struct {
key *KeyType;
value *ValueType;
}
// Using the Array type below doesn't seem to work
//type Array array [1024] Entry;
-export type HashMap struct {
+type HashMap struct {
map_ *[1024] Entry;
log2_capacity_ uint32;
occupancy_ uint32;
// ----------------------------------------------------------------------------
// Test code
-export type Number struct {
+type Number struct {
x uint32;
}
}
-export func MakeNumber (x uint32) *Number {
+func MakeNumber (x uint32) *Number {
var n *Number = new(Number);
n.x = x;
return n;
}
-export var (
+var (
Zero = Big.Rat(0, 1);
One = Big.Rat(1, 1);
)
-export type Matrix struct {
+type Matrix struct {
n, m int;
a []*Big.Rational;
}
}
-export func NewMatrix(n, m int) *Matrix {
+func NewMatrix(n, m int) *Matrix {
assert(0 <= n && 0 <= m);
a := new(Matrix);
a.n = n;
}
-export func NewUnit(n int) *Matrix {
+func NewUnit(n int) *Matrix {
a := NewMatrix(n, n);
for i := 0; i < n; i++ {
for j := 0; j < n; j++ {
}
-export func NewHilbert(n int) *Matrix {
+func NewHilbert(n int) *Matrix {
a := NewMatrix(n, n);
for i := 0; i < n; i++ {
for j := 0; j < n; j++ {
}
-export func MakeRat(x Big.Natural) *Big.Rational {
+func MakeRat(x Big.Natural) *Big.Rational {
return Big.MakeRat(Big.MakeInt(false, x), Big.Nat(1));
}
-export func NewInverseHilbert(n int) *Matrix {
+func NewInverseHilbert(n int) *Matrix {
a := NewMatrix(n, n);
for i := 0; i < n; i++ {
for j := 0; j < n; j++ {
package main
-export type I2 interface
+type I2 interface
-export type I1 interface {
+type I1 interface {
foo() I2
}
-export type I2 interface {
+type I2 interface {
bar() I1
}
-export type T int
+type T int
func (t T) bar() I1;
func (t T) foo() I2 { return t }
func (t T) bar() I1 { return t }
package main
-export type Inst interface {
+type Inst interface {
Next() *Inst;
}
-export type Regexp struct {
+type Regexp struct {
code []Inst;
start Inst;
}
-export type Start struct {
+type Start struct {
foo *Inst;
}
func (start *Start) Next() *Inst { return nil }
-export func AddInst(Inst) *Inst {
+func AddInst(Inst) *Inst {
print("ok in addinst\n");
return nil
}
package main
-export type S struct
+type S struct
-export type I interface {
+type I interface {
Foo()
}
}
// hide S down here to avoid static warning
-export type S struct {
+type S struct {
}
package main
-export type S struct { a int }
-export type T struct { b string }
+type S struct { a int }
+type T struct { b string }
func (s *S) Name() int8 { return 1 }
func (t *T) Name() int64 { return 64 }
-export type I1 interface { Name() int8 }
-export type I2 interface { Name() int64 }
+type I1 interface { Name() int8 }
+type I2 interface { Name() int64 }
func main() {
var i1 I1;
package main
-export type I interface { M() int64 }
+type I interface { M() int64 }
-export type BigPtr struct { a, b, c, d int64 }
+type BigPtr struct { a, b, c, d int64 }
func (z *BigPtr) M() int64 { return z.a+z.b+z.c+z.d }
-export type SmallPtr struct { a int32 }
+type SmallPtr struct { a int32 }
func (z *SmallPtr) M() int64 { return int64(z.a) }
-export type IntPtr int32
+type IntPtr int32
func (z *IntPtr) M() int64 { return int64(*z) }
var bad bool
test("&intptr", &intptr);
}
-export type Big struct { a, b, c, d int64 }
+type Big struct { a, b, c, d int64 }
func (z Big) M() int64 { return z.a+z.b+z.c+z.d }
-export type Small struct { a int32 }
+type Small struct { a int32 }
func (z Small) M() int64 { return int64(z.a) }
-export type Int int32
+type Int int32
func (z Int) M() int64 { return int64(z) }
func nonptrs() {
package main
-export type T struct { a int }
+type T struct { a int }
var t *T
-export type I interface { M() }
+type I interface { M() }
var i I
func main() {
}
}
-export type I1 interface { Get() int; Put(int); }
+type I1 interface { Get() int; Put(int); }
-export type S1 struct { i int }
+type S1 struct { i int }
func (p S1) Get() int { return p.i }
func (p S1) Put(i int) { p.i = i }
check(s.i == 1, "f3 s");
}
-export type S2 struct { i int }
+type S2 struct { i int }
func (p *S2) Get() int { return p.i }
func (p *S2) Put(i int) { p.i = i }
check(s.i == 2, "f6 s");
}
-export type I2 interface { Get() int64; Put(int64); }
+type I2 interface { Get() int64; Put(int64); }
-export type S3 struct { i, j, k, l int64 }
+type S3 struct { i, j, k, l int64 }
func (p S3) Get() int64 { return p.l }
func (p S3) Put(i int64) { p.l = i }
check(s.l == 4, "f9 s");
}
-export type S4 struct { i, j, k, l int64 }
+type S4 struct { i, j, k, l int64 }
func (p *S4) Get() int64 { return p.l }
func (p *S4) Put(i int64) { p.l = i }
g float = 4.5 * float(iota);
)
-export const (
+const (
X = 0;
Y;
Z;
)
-export const (
+const (
A = 1 << iota;
B;
C;
return randx%n;
}
-export type Chan
+type Chan
struct
{
sc,rc chan int; // send and recv chan
package main
-export type
+type
I interface
{
test1,
******
******/
-export type
+type
SubpSubp struct
{
a7 int;
******
******/
-export type
+type
SubpSub struct
{
a6 int;
******
******/
-export type
+type
SubSubp struct
{
a5 int;
******
******/
-export type
+type
SubSub struct
{
a4 int;
******
******/
-export type
+type
Subp struct
{
a3 int;
******
******/
-export type
+type
Sub struct
{
a2 int;
******
******/
-export type
+type
S struct
{
a1 int;
type myint int;
type mystring string;
-export type I0 interface {};
+type I0 interface {};
func
f()
package main
-export type S struct
+type S struct
{
a,b int;
}
-export type I1 interface
+type I1 interface
{
f ()int;
}
-export type I2 interface
+type I2 interface
{
g,f ()int;
}
package main
-export type Iputs interface
+type Iputs interface
{
puts (s string);
}
// ---------
-export type Print struct
+type Print struct
{
whoami int;
put Iputs;
// ---------
-export type Bio struct
+type Bio struct
{
whoami int;
put Iputs;
// ---------
-export type File struct
+type File struct
{
whoami int;
put Iputs;
package main
-export type C struct
+type C struct
{
a int;
x *(p *C)int;
package main
-export type Item interface
+type Item interface
{
Print();
}
-export type ListItem struct
+type ListItem struct
{
item Item;
next *ListItem;
}
-export type List struct
+type List struct
{
head *ListItem;
}
}
// Something to put in a list
-export type Integer struct
+type Integer struct
{
val int;
}
const nilchar = 0;
-export type (
+type (
Atom struct;
List struct;
Slist struct;
)
-export type Atom struct {
+type Atom struct {
str string;
integer int;
next *Slist; /* in hash bucket */
}
-export type List struct {
+type List struct {
car *Slist;
cdr*Slist;
}
-export type Slist struct {
+type Slist struct {
isatom bool;
isstring bool;
//union {
// free(slist);
}
-export func OpenFile();
-export func Parse() *Slist;
+func OpenFile();
+func Parse() *Slist;
//Slist* atom(byte *s, int i);
var tokenbuf [100]byte;
var tokenlen int = 0;
-export const EOF int = -1;
+const EOF int = -1;
func main()
{
print("\n");
}
-export func Get() int
+func Get() int
{
var c int;
return c;
}
-export func WhiteSpace(c int) bool
+func WhiteSpace(c int) bool
{
return c == ' ' || c == '\t' || c == '\r' || c == '\n';
}
-export func NextToken()
+func NextToken()
{
var i, c int;
var backslash bool;
}
}
-export func Expect(c int)
+func Expect(c int)
{
if token != c {
print("parse error: expected ", c, "\n");
}
// Parse a non-parenthesized list up to a closing paren or EOF
-export func ParseList() *Slist
+func ParseList() *Slist
{
var slist, retval *Slist;
return v;
}
-export func Parse() *Slist
+func Parse() *Slist
{
var slist *Slist;
return nil;
}
-export func OpenFile()
+func OpenFile()
{
input = "(defn foo (add 12 34))\n\x00";
inputindex = 0;
return 8, 8.0;
}
-export type T struct {
+type T struct {
x, y int;
}
func memset(b *byte, c byte, n uint64) {
np := uintptr(n);
for i := uintptr(0); i < np; i++ {
- *(b.(unsafe.pointer).(uintptr)+i).(unsafe.pointer).(*byte) = c;
+ *(b.(unsafe.Pointer).(uintptr)+i).(unsafe.Pointer).(*byte) = c;
}
}
var b []*byte;
var stats = malloc.GetStats();
-export func OkAmount(size, n uintptr) bool {
+func OkAmount(size, n uintptr) bool {
if n < size {
return false
}
return true
}
-export func AllocAndFree(size, count int) {
+func AllocAndFree(size, count int) {
if *chatty {
fmt.Printf("size=%d count=%d ...\n", size, count);
}
const arraylen = 2; // BUG: shouldn't need this
-export func P(a []string) string {
+func P(a []string) string {
s := "{";
for i := 0; i < len(a); i++ {
if i > 0 {
package main
-export type S string
-export type S1 string
-export type I int
-export type I1 int
-export type T struct { x int }
-export type T1 T
+type S string
+type S1 string
+type I int
+type I1 int
+type T struct { x int }
+type T1 T
func (s S) val() int { return 1 }
func (s *S1) val() int { return 2 }
//func (t T) val() int { return 7 }
func (t *T1) val() int { return 8 }
-export type Val interface {
+type Val interface {
val() int
}
package main
-export type T struct { }
+type T struct { }
func (t *T) M(int, string); // GCCGO_ERROR "previous"
func (t *T) M(int, float) { } // ERROR "redeclared|redefinition"
package main
-export type T struct {a int}
-export type P *T
-export type P1 *T
+type T struct {a int}
+type P *T
+type P1 *T
func (p P) val() int { return 1 } // ERROR "receiver"
func (p *P1) val() int { return 1 } // ERROR "receiver"
package main
-export type T [] int
+type T [] int
func (t T) Len() int { return len(t) }
-export type I interface {
+type I interface {
Len() int
}
package main
-export type T struct {
+type T struct {
i int
}
-export type IN interface {
+type IN interface {
}
func main() {
package main
-export type Number struct {
+type Number struct {
next *Number
}
package main
// Send the sequence 2, 3, 4, ... to channel 'ch'.
-export func Generate(ch chan<- int) {
+func Generate(ch chan<- int) {
for i := 2; ; i++ {
ch <- i // Send 'i' to channel 'ch'.
}
// Copy the values from channel 'in' to channel 'out',
// removing those divisible by 'prime'.
-export func Filter(in <-chan int, out chan<- int, prime int) {
+func Filter(in <-chan int, out chan<- int, prime int) {
for {
i := <-in; // Receive value of new variable 'i' from 'in'.
if i % prime != 0 {
}
// The prime sieve: Daisy-chain Filter processes together.
-export func Sieve() {
+func Sieve() {
ch := make(chan int); // Create a new channel.
go Generate(ch); // Start Generate() as a subprocess.
for {
mask4 = 1 << iota;
)
-export type (
+type (
Empty interface {};
Point struct {
x, y int;
import "array"
-export type S struct {
+type S struct {
val int
}
// ----------------------------------------------------------------------------
// Expressions
-export const /* op */ (
+const /* op */ (
LITERAL = iota;
OBJECT;
DEREF;
// ----------------------------------------------------------------------------
// Literals
-export type Literal struct {
+type Literal struct {
pos_ int;
typ_ *Globals.Type;
b bool;
func (x *Literal) typ() *Globals.Type { return x.typ_; }
-export func NewLiteral(pos int, typ *Globals.Type) *Literal {
+func NewLiteral(pos int, typ *Globals.Type) *Literal {
x := new(Literal);
x.pos_ = pos;
x.typ_ = typ;
}
-export var Bad, True, False, Nil *Literal;
+var Bad, True, False, Nil *Literal;
// ----------------------------------------------------------------------------
// NOTE We could use Globals.Object directly if we'd added a typ()
// method to its interface. However, this would require renaming the
// typ field everywhere... - Need to think about accessors again.
-export type Object struct {
+type Object struct {
pos_ int;
obj *Globals.Object;
}
func (x *Object) typ() *Globals.Type { return x.obj.typ; }
-export func NewObject(pos int, obj* Globals.Object) *Object {
+func NewObject(pos int, obj* Globals.Object) *Object {
x := new(Object);
x.pos_ = pos;
x.obj = obj;
// Derefs
// TODO model Deref as unary operation?
-export type Deref struct {
+type Deref struct {
ptr_ Globals.Expr;
}
func (x *Deref) typ() *Globals.Type { return x.ptr_.typ().elt; }
-export func NewDeref(ptr Globals.Expr) *Deref {
+func NewDeref(ptr Globals.Expr) *Deref {
x := new(Deref);
x.ptr_ = ptr;
return x;
// Selectors
// TODO model Selector as binary operation?
-export type Selector struct {
+type Selector struct {
pos_ int;
typ_ *Globals.Type;
}
func (x *Selector) typ() *Globals.Type { return x.typ_; }
-export func NewSelector(pos int, typ *Globals.Type) *Selector {
+func NewSelector(pos int, typ *Globals.Type) *Selector {
x := new(Selector);
x.pos_ = pos;
x.typ_ = typ;
// ----------------------------------------------------------------------------
// Calls
-export type Call struct {
+type Call struct {
recv, callee Globals.Expr;
args *Globals.List;
}
func (x *Call) typ() *Globals.Type { return nil; }
-export func NewCall(args *Globals.List) *Call {
+func NewCall(args *Globals.List) *Call {
x := new(Call);
x.args = args;
return x;
// ----------------------------------------------------------------------------
// Binary expressions
-export type BinaryExpr struct {
+type BinaryExpr struct {
op_ int;
pos_ int;
typ_ *Globals.Type;
// ----------------------------------------------------------------------------
// Tuples
-export type Tuple struct {
+type Tuple struct {
typ_ *Globals.Type;
list *Globals.List;
}
func (x *Tuple) typ() *Globals.Type { return x.typ_; }
-export func NewTuple(list *Globals.List) *Tuple {
+func NewTuple(list *Globals.List) *Tuple {
// make corresponding tuple type
scope := Globals.NewScope(nil);
for p := list.first; p != nil; p = p.next {
}
typ := Globals.NewType(Type.TUPLE);
typ.scope = scope;
-
+
// create the tuple
x := new(Tuple);
x.typ_ = typ;
// ----------------------------------------------------------------------------
// Statements
-export type Block struct {
+type Block struct {
// TODO fill in
}
-export type IfStat struct {
+type IfStat struct {
cond Globals.Expr;
then_ Globals.Stat;
else_ Globals.Stat;
package base
-export type Foo int
+type Foo int
-export type Bar *float;
+type Bar *float;
-export type Node struct {
+type Node struct {
left, right *Node;
val bool;
f Foo;
}
-export func (p *Node) F(x int) {};
+func (p *Node) F(x int) {};
-export type I interface {
+type I interface {
f();
}
}
-export func Error(comp *Globals.Compilation, pos int, msg string) {
+func Error(comp *Globals.Compilation, pos int, msg string) {
const errdist = 10;
delta := pos - comp.errpos; // may be negative!
if delta < 0 {
}
-export func Import(comp *Globals.Compilation, pkg_file string) *Globals.Package {
+func Import(comp *Globals.Compilation, pkg_file string) *Globals.Package {
data, ok := ReadImport(comp, pkg_file, comp.flags.update_packages);
var pkg *Globals.Package;
if ok {
}
-export func Export(comp *Globals.Compilation, pkg_file string) {
+func Export(comp *Globals.Compilation, pkg_file string) {
data := Exporter.Export(comp);
ok := Platform.WriteObjectFile(pkg_file, data);
if !ok {
}
-export func Compile(comp *Globals.Compilation, src_file string) {
+func Compile(comp *Globals.Compilation, src_file string) {
// TODO This is incorrect: When compiling with the -r flag, we are
// calling this function recursively w/o setting up a new comp - this
// is broken and leads to an assertion error (more then one package
import "base"
import base2 "base"
-export const c0 int = 0
-export const c1 float = 1.
+const c0 int = 0
+const c1 float = 1.
const (
c2 byte = 2;
c3 int = 3;
)
-export type (
+type (
Node0 base.Node
Node1 *base2.Node
)
-export type T0 byte
-export type T1 T0
+type T0 byte
+type T1 T0
type (
T2 [10]T0;
T3 map [string] int;
)
-export type T4 struct {
+type T4 struct {
f1, f2, f3 int;
f4 [] float;
};
f *(x, y *T9) *T9;
}
-export type T11 struct {
+type T11 struct {
p *T10;
}
Do0(q *I0);
Do1(p *I1) bool;
}
-export type I2 interface {
+type I2 interface {
M0();
M1(a int);
M2(a, b int, c float);
var v0 int
var v1 float = c1
-export var (
+var (
v2 T2;
v3 struct {
f1, f2, f3 *M0;
)
-export func f0() {}
-export func f1(a int) {}
+func f0() {}
+func f1(a int) {}
func f2(a, b int, c float) {}
func f3() bool { return false; }
func f4(a int) (z T5, ok bool) {}
}
}
E.WriteObject(nil);
-
+
if E.debug {
print(" }");
}
ident = "." + ident;
}
}
-
+
E.WriteString(ident);
if len(ident) > 0 {
// named type
E.WritePackage(E.comp.pkg_list[typ.obj.pnolev]);
}
-
+
switch typ.form {
case Type.VOID:
// for now until we have enough of the front-end working.
-
+
case Type.FORWARD:
// corresponding package must be forward-declared too
if typ.obj == nil || E.comp.pkg_list[typ.obj.pnolev].key != "" {
panic("inconsistency in package.type forward declaration");
}
-
+
case Type.ALIAS, Type.MAP:
E.WriteType(typ.key);
E.WriteType(typ.elt);
E.WriteInt(typ.len);
E.WriteType(typ.elt);
E.WriteScope(typ.scope);
-
+
case Type.STRUCT, Type.INTERFACE:
E.WriteScope(typ.scope);
case Object.VAR, Object.FIELD:
E.WriteInt(0); // should be the correct address/offset
-
+
case Object.FUNC:
E.WriteInt(0); // should be the correct address/offset
-
+
default:
panic("UNREACHABLE");
}
E.buf_pos = 0;
E.pkg_ref = 0;
E.type_ref = 0;
-
+
// write magic bits
magic := Platform.MAGIC_obj_file; // TODO remove once len(constant) works
for i := 0; i < len(magic); i++ {
E.WriteByte(magic[i]);
}
-
+
// Predeclared types are "pre-exported".
// TODO run the loop below only in debug mode
{ i := 0;
}
}
E.type_ref = Universe.types.len;
-
+
// export package 0
pkg := comp.pkg_list[0];
E.WritePackage(pkg);
E.WriteScope(pkg.scope);
-
+
if E.debug {
print("\n(", E.buf_pos, " bytes)\n");
}
-
+
return string(E.buf)[0 : E.buf_pos];
}
-export func Export(comp* Globals.Compilation) string {
+func Export(comp* Globals.Compilation) string {
var E Exporter;
return (&E).Export(comp);
}
}
-export func Deref(comp *Globals.Compilation, x Globals.Expr) Globals.Expr {
+func Deref(comp *Globals.Compilation, x Globals.Expr) Globals.Expr {
switch typ := x.typ(); typ.form {
case Type.BAD:
// ignore
-
+
case Type.POINTER:
x = AST.NewDeref(x);
-
+
default:
Error(comp, x.pos(), `"*" not applicable (typ.form = ` + Type.FormStr(typ.form) + `)`);
x = AST.Bad;
}
-
+
return x;
}
-export func Select(comp *Globals.Compilation, x Globals.Expr, pos int, selector string) Globals.Expr {
+func Select(comp *Globals.Compilation, x Globals.Expr, pos int, selector string) Globals.Expr {
if x.typ().form == Type.POINTER {
x = Deref(comp, x);
}
obj := typ.scope.Lookup(selector);
if obj != nil {
x = AST.NewSelector(x.pos(), obj.typ);
-
+
} else {
Error(comp, pos, `no field/method "` + selector + `"`);
x = AST.Bad;
Error(comp, pos, `"." not applicable (typ.form = ` + Type.FormStr(typ.form) + `)`);
x = AST.Bad;
}
-
+
return x;
}
-export func AssertType(comp *Globals.Compilation, x Globals.Expr, pos int, typ *Globals.Type) Globals.Expr {
+func AssertType(comp *Globals.Compilation, x Globals.Expr, pos int, typ *Globals.Type) Globals.Expr {
return AST.Bad;
}
-export func Index(comp *Globals.Compilation, x, i Globals.Expr) Globals.Expr {
+func Index(comp *Globals.Compilation, x, i Globals.Expr) Globals.Expr {
if x.typ().form == Type.POINTER {
x = Deref(comp, x);
}
switch typ := x.typ(); typ.form {
case Type.BAD:
// ignore
-
+
case Type.STRING, Type.ARRAY:
x = AST.Bad;
-
+
case Type.MAP:
if Type.Equal(typ.key, i.typ()) {
// x = AST.NewSubscript(x, i1);
x = AST.Bad;
-
+
} else {
Error(comp, x.pos(), "map key type mismatch");
x = AST.Bad;
}
-
+
default:
Error(comp, x.pos(), `"[]" not applicable (typ.form = ` + Type.FormStr(typ.form) + `)`);
x = AST.Bad;
}
-export func Slice(comp *Globals.Compilation, x, i, j Globals.Expr) Globals.Expr {
+func Slice(comp *Globals.Compilation, x, i, j Globals.Expr) Globals.Expr {
if x.typ().form == Type.POINTER {
x = Deref(comp, x);
}
break;
case Type.STRING, Type.ARRAY:
x = AST.Bad;
-
+
case Type.MAP:
if Type.Equal(typ.key, i.typ()) {
// x = AST.NewSubscript(x, i1);
x = AST.Bad;
-
+
} else {
Error(comp, x.pos(), "map key type mismatch");
x = AST.Bad;
}
-
+
default:
Error(comp, x.pos(), `"[:]" not applicable (typ.form = ` + Type.FormStr(typ.form) + `)`);
x = AST.Bad;
}
-export func Call(comp *Globals.Compilation, x Globals.Expr, args *Globals.List) Globals.Expr {
+func Call(comp *Globals.Compilation, x Globals.Expr, args *Globals.List) Globals.Expr {
if x.typ().form == Type.POINTER {
x = Deref(comp, x);
}
-
+
if x.op() == AST.OBJECT && x.(*AST.Object).obj.kind == Object.BUILTIN {
panic("builtin call - UNIMPLEMENTED");
}
-
+
typ := x.typ();
if typ.form == Type.FUNCTION || typ.form == Type.METHOD {
// TODO check args against parameters
}
-
+
return AST.Bad;
}
-export func UnaryExpr(comp *Globals.Compilation, x Globals.Expr) Globals.Expr {
+func UnaryExpr(comp *Globals.Compilation, x Globals.Expr) Globals.Expr {
return AST.Bad;
}
-export func BinaryExpr(comp *Globals.Compilation, x, y Globals.Expr) Globals.Expr {
+func BinaryExpr(comp *Globals.Compilation, x, y Globals.Expr) Globals.Expr {
e := new(AST.BinaryExpr);
e.typ_ = x.typ(); // TODO fix this
//e.op = P.tok; // TODO should we use tokens or separate operator constants?
// source code (pos), has a name (ident), a type (typ), and a package number
// or nesting level (pnolev).
-export type Object struct {
+type Object struct {
exported bool;
pos int; // source position (< 0 if unknown position)
kind int;
}
-export type Type struct {
+type Type struct {
ref int; // for exporting only: >= 0 means already exported
form int;
size int; // in bytes
}
-export type Package struct {
+type Package struct {
ref int; // for exporting only: >= 0 means already exported
file_name string;
key string;
}
-export type List struct {
+type List struct {
len int;
first, last *Elem;
};
-export type Scope struct {
+type Scope struct {
parent *Scope;
entries *List;
// entries map[string] *Object; // doesn't work properly
}
-export type Flags struct {
+type Flags struct {
debug bool;
object_file string;
update_packages bool;
}
-export type Environment struct {
+type Environment struct {
Error *(comp *Compilation, pos int, msg string);
Import *(comp *Compilation, pkg_file string) *Package;
Export *(comp *Compilation, pkg_file string);
}
-export type Compilation struct {
+type Compilation struct {
// environment
flags *Flags;
env *Environment;
-
+
// TODO rethink the need for this here
src_file string;
src string;
-
+
// Error handling
nerrors int; // number of errors reported
errpos int; // last error position
-
+
// TODO use open arrays eventually
pkg_list [256] *Package; // pkg_list[0] is the current package
pkg_ref int;
}
-export type Expr interface {
+type Expr interface {
op() int; // node operation
pos() int; // source position
typ() *Type;
}
-export type Stat interface {
+type Stat interface {
// ... more to come here
}
// TODO This is hideous! We need to have a decent way to do lists.
// Ideally open arrays that allow '+'.
-export type Elem struct {
+type Elem struct {
next *Elem;
val int;
str string;
// ----------------------------------------------------------------------------
// Creation
-export var Universe_void_t *Type // initialized by Universe to Universe.void_t
+var Universe_void_t *Type // initialized by Universe to Universe.void_t
-export func NewObject(pos, kind int, ident string) *Object {
+func NewObject(pos, kind int, ident string) *Object {
obj := new(Object);
obj.exported = false;
obj.pos = pos;
}
-export func NewType(form int) *Type {
+func NewType(form int) *Type {
typ := new(Type);
typ.ref = -1; // not yet exported
typ.form = form;
}
-export func NewPackage(file_name string, obj *Object, scope *Scope) *Package {
+func NewPackage(file_name string, obj *Object, scope *Scope) *Package {
pkg := new(Package);
pkg.ref = -1; // not yet exported
pkg.file_name = file_name;
}
-export func NewList() *List {
+func NewList() *List {
return new(List);
}
-export func NewScope(parent *Scope) *Scope {
+func NewScope(parent *Scope) *Scope {
scope := new(Scope);
scope.parent = parent;
scope.entries = NewList();
ident := I.ReadString();
file_name := I.ReadString();
key := I.ReadString();
-
+
// Canonicalize package - if it was imported before,
// use the primary import.
pkg := I.comp.Lookup(file_name);
}
obj = I.ReadObject();
}
-
+
if I.debug {
print(" }");
}
if len(ident) > 0 {
// named type
pkg := I.ReadPackage();
-
+
// create corresponding type object
obj := Globals.NewObject(0, Object.TYPE, ident);
obj.exported = true;
// for now until we have enough of the front-end working
// change the form to BAD to avoid error messages
typ.form = Type.BAD;
-
+
case Type.FORWARD:
typ.scope = Globals.NewScope(nil);
-
+
case Type.TUPLE:
typ.elt = I.ReadType();
-
+
case Type.ALIAS, Type.MAP:
typ.key = I.ReadType();
typ.elt = I.ReadType();
if tag == Object.END {
return nil;
}
-
+
if tag == Object.TYPE {
// named types are handled entirely by ReadType()
typ := I.ReadType();
}
return typ.obj;
}
-
+
ident := I.ReadString();
obj := Globals.NewObject(0, tag, ident);
obj.exported = true;
case Object.FUNC:
I.ReadInt(); // should set the address/offset field
-
+
default:
panic("UNREACHABLE");
}
I.buf_pos = 0;
I.pkg_ref = 0;
I.type_ref = 0;
-
+
// check magic bits
if !Utils.Contains(data, Platform.MAGIC_obj_file, 0) {
return nil;
}
-
+
// Predeclared types are "pre-imported".
for p := Universe.types.first; p != nil; p = p.next {
if p.typ.ref != I.type_ref {
// import package
pkg := I.ReadPackage();
I.ReadScope(pkg.scope, true);
-
+
if I.debug {
print("\n(", I.buf_pos, " bytes)\n");
}
-
+
return pkg;
}
-export func Import(comp *Globals.Compilation, data string) *Globals.Package {
+func Import(comp *Globals.Compilation, data string) *Globals.Package {
var I Importer;
pkg := (&I).Import(comp, data);
return pkg;
import Globals "globals"
-export const /* kind */ (
+const /* kind */ (
BAD = iota; // error handling
CONST; TYPE; VAR; FIELD; FUNC; BUILTIN; PACKAGE; LABEL;
END; // end of scope (import/export only)
// globals.go.
-export func KindStr(kind int) string {
+func KindStr(kind int) string {
switch kind {
case BAD: return "BAD";
case CONST: return "CONST";
import Expr "expr"
-export type Parser struct {
+type Parser struct {
comp *Globals.Compilation;
verbose bool;
indent uint;
scanner *Scanner.Scanner;
tokchan chan *Scanner.Token;
-
+
// Token
tok int; // one token look-ahead
pos int; // token source position
}
// open arrays must be pointers
fallthrough;
-
+
case Type.MAP, Type.CHANNEL, Type.FUNCTION:
P.Error(pos, "must be pointer to this type");
typ = Universe.bad_t;
// TODO introduce dummy package so we can continue safely
}
}
-
+
P.Next(); // consume package name
P.Expect(Scanner.PERIOD);
pos, ident := P.ParseIdent(false);
}
elt = obj.typ;
}
-
+
} else if P.tok == Scanner.IDENT {
if P.Lookup(P.val) == nil {
// implicit type forward declaration
- // create a named forward type
+ // create a named forward type
pos, ident := P.ParseIdent(false);
obj := Globals.NewObject(pos, Object.TYPE, ident);
elt = Globals.NewType(Type.FORWARD);
P.Expect(Scanner.PERIOD);
pos := P.pos;
-
+
if P.tok >= Scanner.IDENT {
pos, selector := P.ParseIdent(true);
x = Expr.Select(P.comp, x, pos, selector);
P.Ecart();
return x; // TODO fix this
}
-
+
x := P.ParsePrimaryExpr(-1, "");
P.Ecart();
pos_list, ident_list = Globals.NewList(), Globals.NewList(); // "pairs" of (pos, ident)
expr_list = Globals.NewList();
-
+
P.ParseIdentOrExpr(pos_list, ident_list, expr_list);
for P.tok == Scanner.COMMA {
P.Next();
P.Next();
pos := P.pos;
val_list := P.ParseNewExpressionList();
-
+
// assign variables
if val_list.len == 1 && val_list.first.expr.typ().form == Type.TUPLE {
panic("UNIMPLEMENTED");
} else {
var p, q *Globals.Elem;
for p, q = expr_list.first, val_list.first; p != nil && q != nil; p, q = p.next, q.next {
-
+
}
if p != nil || q != nil {
P.Error(pos, "number of expressions does not match number of variables");
P.Error(P.pos, `pre-import of package "sys" failed`);
}
}
-
+
for P.tok == Scanner.IMPORT {
P.ParseDecl(false, Scanner.IMPORT);
P.Optional(Scanner.SEMICOLON);
// ----------------------------------------------------------------------------
// Environment
-export var
+var
GOARCH,
GOOS,
GOROOT,
// ----------------------------------------------------------------------------
// I/O
-export const (
+const (
MAGIC_obj_file = "@gri-go.7@v0"; // make it clear thar it cannot be a source file
src_file_ext = ".go";
obj_file_ext = ".7";
)
-export func ReadObjectFile(filename string) (data string, ok bool) {
+func ReadObjectFile(filename string) (data string, ok bool) {
data, ok = sys.readfile(filename + obj_file_ext);
magic := MAGIC_obj_file; // TODO remove once len(constant) works
if ok && len(data) >= len(magic) && data[0 : len(magic)] == magic {
}
-export func ReadSourceFile(name string) (data string, ok bool) {
+func ReadSourceFile(name string) (data string, ok bool) {
name = Utils.TrimExt(name, src_file_ext) + src_file_ext;
data, ok = sys.readfile(name);
return data, ok;
}
-export func WriteObjectFile(name string, data string) bool {
+func WriteObjectFile(name string, data string) bool {
name = Utils.TrimExt(Utils.BaseName(name), src_file_ext) + obj_file_ext;
return sys.writefile(name, data);
}
}
r0 := p0 + typ.len;
l0 := typ.scope.entries.len;
-
+
if P.level == 0 {
print("func ");
print(" ");
}
}
-
+
if fun != nil {
P.PrintObject(fun);
//print(" ");
} else if p0 > 0 {
print(". ");
}
-
+
P.PrintSigRange(typ, p0, r0);
if r0 < l0 {
}
}
}
-
+
// print the scope
const scale = 2;
if n > 0 {
case Object.BUILTIN:
P.PrintObject(obj);
print(" /* builtin */");
-
+
case Object.PACKAGE:
print("package ");
P.PrintObject(obj);
default:
panic("UNREACHABLE");
}
-
+
if P.level > 0 {
print(";");
}
switch typ.form {
case Type.VOID:
print("void");
-
+
case Type.BAD:
print("<bad type>");
P.PrintType(typ.key);
print(" */");
}
-
+
case Type.ARRAY:
print("[]");
P.PrintType(typ.elt);
default:
panic("UNREACHABLE");
-
+
}
}
}
-export func PrintObject(comp *Globals.Compilation, obj *Globals.Object, print_all bool) {
+func PrintObject(comp *Globals.Compilation, obj *Globals.Object, print_all bool) {
var P Printer;
(&P).Init(comp, print_all);
(&P).PrintObjectStruct(obj);
import Utils "utils"
-export const (
+const (
ILLEGAL = iota;
EOF;
INT;
var VerboseMsgs bool; // error message customization
-export func TokenName(tok int) string {
+func TokenName(tok int) string {
switch (tok) {
case ILLEGAL: return "illegal";
case EOF: return "eof";
}
-export type Scanner struct {
+type Scanner struct {
filename string; // error reporting only
nerrors int; // number of errors
errpos int; // last error position
}
-export type Token struct {
+type Token struct {
pos int;
tok int;
val string;
import C "c"
import D "d"
-export type T1 C.T1;
-export type T2 D.T2;
+type T1 C.T1;
+type T2 D.T2;
-export var (
+var (
v0 D.T1;
v1 C.T1;
v2 *C.F1;
import "d"
-export type T1 D.T1;
-export type T2 D.T2;
-export type F1 (a D.T1, b *D.T2);
+type T1 D.T1;
+type T2 D.T2;
+type F1 (a D.T1, b *D.T2);
type T0 int
-export type T1 struct {
+type T1 struct {
n int;
a, b T0;
}
-export type T2 struct {
+type T2 struct {
u, v float;
}
-export func (obj *T2) M1(u, v float) {
+func (obj *T2) M1(u, v float) {
}
-export func F0(a int, b T0) int {
+func F0(a int, b T0) int {
return a + b;
}
\ No newline at end of file
import Object "object"
-export const /* form */ (
+const /* form */ (
// internal types
// We should never see one of these.
UNDEF = iota;
-
+
// VOID types are used when we don't have a type. Never exported.
// (exported type forms must be > 0)
VOID;
-
+
// BAD types are compatible with any type and don't cause further errors.
// They are introduced only as a result of an error in the source code. A
// correct program cannot have BAD types.
BAD;
-
+
// FORWARD types are forward-declared (incomplete) types. They can only
// be used as element types of pointer types and must be resolved before
// their internals are accessible.
// TUPLE types represent multi-valued result types of functions and
// methods.
TUPLE;
-
+
// The type of nil.
NIL;
// basic types
BOOL; UINT; INT; FLOAT; STRING; INTEGER;
-
+
// 'any' type // TODO this should go away eventually
ANY;
-
+
// composite types
ALIAS; ARRAY; STRUCT; INTERFACE; MAP; CHANNEL; FUNCTION; METHOD; POINTER;
)
-export const /* Type.aux */ (
+const /* Type.aux */ (
SEND = 1; // chan>
RECV = 2; // chan<
)
// globals.go.
-export func FormStr(form int) string {
+func FormStr(form int) string {
switch form {
case VOID: return "VOID";
case BAD: return "BAD";
}
-export func Equal(x, y *Globals.Type) bool;
+func Equal(x, y *Globals.Type) bool;
func Equal0(x, y *Globals.Type) bool {
if x == y {
return true; // bad types are always equal (avoid excess error messages)
}
- // TODO where to check for *T == nil ?
+ // TODO where to check for *T == nil ?
if x.form != y.form {
return false; // types of different forms are not equal
}
case POINTER:
return Equal(x.elt, y.elt);
-
+
case TUPLE:
panic("UNIMPLEMENTED");
return false;
}
-export func Equal(x, y *Globals.Type) bool {
+func Equal(x, y *Globals.Type) bool {
res := Equal0(x, y);
// TODO should do the check below only in debug mode
if Equal0(y, x) != res {
}
-export func Assigneable(from, to *Globals.Type) bool {
+func Assigneable(from, to *Globals.Type) bool {
if Equal(from, to) {
return true;
}
-
+
panic("UNIMPLEMENTED");
return false;
}
import Type "type"
-export var (
+var (
scope *Globals.Scope;
types *Globals.List;
-
+
// internal types
void_t,
bad_t,
nil_t,
-
+
// basic types
bool_t,
uint8_t,
string_t,
integer_t,
any_t,
-
+
// alias types
byte_t,
ushort_t,
float_t,
double_t,
ptrint_t *Globals.Type;
-
+
true_,
false_,
iota_,
func init() {
scope = Globals.NewScope(nil); // universe has no parent
types = Globals.NewList();
-
+
// Interal types
void_t = Globals.NewType(Type.VOID);
Globals.Universe_void_t = void_t;
bad_t = Globals.NewType(Type.BAD);
nil_t = Globals.NewType(Type.NIL);
-
+
// Basic types
bool_t = Register(DeclType(Type.BOOL, "bool", 1));
uint8_t = Register(DeclType(Type.UINT, "uint8", 1));
DeclObj(Object.BUILTIN, "new", void_t);
DeclObj(Object.BUILTIN, "panic", void_t);
DeclObj(Object.BUILTIN, "print", void_t);
-
+
// scope.Print();
}
package Utils
-export func BaseName(s string) string {
+func BaseName(s string) string {
// TODO this is not correct for non-ASCII strings!
i := len(s) - 1;
for i >= 0 && s[i] != '/' {
}
-export func Contains(s, sub string, pos int) bool {
+func Contains(s, sub string, pos int) bool {
end := pos + len(sub);
return pos >= 0 && end <= len(s) && s[pos : end] == sub;
}
-export func TrimExt(s, ext string) string {
+func TrimExt(s, ext string) string {
i := len(s) - len(ext);
if i >= 0 && s[i : len(s)] == ext {
s = s[0 : i];
}
-export func IntToString(x, base int) string {
+func IntToString(x, base int) string {
x0 := x;
if x < 0 {
x = -x;
buf[i] = hex[x % base];
x /= base;
}
-
+
if x0 < 0 {
i--;
buf[i] = '-';
}
-
+
return string(buf)[i : len(buf)];
}
case Type.VOID:
case Type.BAD:
break; // TODO for now - remove eventually
-
+
case Type.FORWARD:
if typ.scope == nil {
Error("forward types must have a scope");
}
-export func Verify(comp *Globals.Compilation) {
+func Verify(comp *Globals.Compilation) {
V := new(Verifier);
V.Verify(comp);
}
)
-export type (
+type (
Object struct;
Type struct;
// Object represents a language object, such as a constant, variable, type, etc.
-export const /* kind */ (
+const /* kind */ (
BADOBJ = iota; // error handling
NONE; // kind unknown
CONST; TYPE; VAR; FIELD; FUNC; BUILTIN; PACKAGE; LABEL;
)
-export func KindStr(kind int) string {
+func KindStr(kind int) string {
switch kind {
case BADOBJ: return "BADOBJ";
case NONE: return "NONE";
}
-export type Object struct {
+type Object struct {
Id int; // unique id
Pos int; // source position (< 0 if unknown position)
Ident string;
Typ *Type; // nil for packages
Pnolev int; // >= 0: package no., <= 0: function nesting level, 0: global level
-
+
// attached values
Block *array.Array; End int; // stats for function literals; end of block pos
}
}
-export var Universe_void_typ *Type // initialized by Universe to Universe.void_typ
+var Universe_void_typ *Type // initialized by Universe to Universe.void_typ
var objectId int;
-export func NewObject(pos, kind int, ident string) *Object {
+func NewObject(pos, kind int, ident string) *Object {
obj := new(Object);
obj.Id = objectId;
objectId++;
-
+
obj.Pos = pos;
obj.Kind = kind;
obj.Ident = ident;
// ----------------------------------------------------------------------------
// Scopes
-export type Scope struct {
+type Scope struct {
Parent *Scope;
entries map[string] *Object;
}
-export func NewScope(parent *Scope) *Scope {
+func NewScope(parent *Scope) *Scope {
scope := new(Scope);
scope.Parent = parent;
scope.entries = make(map[string]*Object, 8);
// ----------------------------------------------------------------------------
// All nodes have a source position and and token.
-export type Node struct {
+type Node struct {
Pos int; // source position (< 0 => unknown position)
Tok int; // identifying token
}
// ----------------------------------------------------------------------------
// Expressions
-export type Expr struct {
+type Expr struct {
Node;
X, Y *Expr; // binary (X, Y) and unary (Y) expressions
Obj *Object;
}
-export func NewExpr(pos, tok int, x, y *Expr) *Expr {
+func NewExpr(pos, tok int, x, y *Expr) *Expr {
if x != nil && x.Tok == Scanner.TYPE || y != nil && y.Tok == Scanner.TYPE {
panic("no type expression allowed");
}
// TODO probably don't need the tok parameter eventually
-export func NewLit(tok int, obj *Object) *Expr {
+func NewLit(tok int, obj *Object) *Expr {
e := new(Expr);
e.Pos, e.Tok, e.Obj = obj.Pos, tok, obj;
return e;
}
-export var BadExpr = NewExpr(0, Scanner.ILLEGAL, nil, nil);
+var BadExpr = NewExpr(0, Scanner.ILLEGAL, nil, nil);
// ----------------------------------------------------------------------------
// Types
-export const /* form */ (
+const /* form */ (
// internal types
// We should never see one of these.
UNDEF = iota;
-
+
// VOID types are used when we don't have a type. Never exported.
// (exported type forms must be > 0)
VOID;
-
+
// BADTYPE types are compatible with any type and don't cause further errors.
// They are introduced only as a result of an error in the source code. A
// correct program cannot have BAD types.
BADTYPE;
-
+
// FORWARD types are forward-declared (incomplete) types. They can only
// be used as element types of pointer types and must be resolved before
// their internals are accessible.
// TUPLE types represent multi-valued result types of functions and
// methods.
TUPLE;
-
+
// The type of nil.
NIL;
// basic types
BOOL; UINT; INT; FLOAT; STRING; INTEGER;
-
+
// composite types
ALIAS; ARRAY; STRUCT; INTERFACE; MAP; CHANNEL; FUNCTION; METHOD; POINTER;
-
+
// open-ended parameter type
ELLIPSIS
)
-export func FormStr(form int) string {
+func FormStr(form int) string {
switch form {
case VOID: return "VOID";
case BADTYPE: return "BADTYPE";
}
-export const /* channel mode */ (
+const /* channel mode */ (
FULL = iota;
SEND;
RECV;
)
-export type Type struct {
+type Type struct {
Id int; // unique id
Ref int; // for exporting only: >= 0 means already exported
var typeId int;
-export func NewType(pos, form int) *Type {
+func NewType(pos, form int) *Type {
typ := new(Type);
typ.Id = typeId;
typeId++;
// requires complete Type.Pos access
-export func NewTypeExpr(typ *Type) *Expr {
+func NewTypeExpr(typ *Type) *Expr {
obj := NewObject(typ.Pos, TYPE, "");
obj.Typ = typ;
return NewLit(Scanner.TYPE, obj);
}
-export var BadType = NewType(0, Scanner.ILLEGAL);
+var BadType = NewType(0, Scanner.ILLEGAL);
// ----------------------------------------------------------------------------
// Statements
-export type Stat struct {
+type Stat struct {
Node;
Init, Post *Stat;
Expr *Expr;
}
-export func NewStat(pos, tok int) *Stat {
+func NewStat(pos, tok int) *Stat {
s := new(Stat);
s.Pos, s.Tok = pos, tok;
return s;
}
-export var BadStat = NewStat(0, Scanner.ILLEGAL);
+var BadStat = NewStat(0, Scanner.ILLEGAL);
// ----------------------------------------------------------------------------
// Declarations
-export type Decl struct {
+type Decl struct {
Node;
Exported bool;
Ident *Expr; // nil for ()-style declarations
}
-export func NewDecl(pos, tok int, exported bool) *Decl {
+func NewDecl(pos, tok int, exported bool) *Decl {
d := new(Decl);
d.Pos, d.Tok, d.Exported = pos, tok, exported;
return d;
}
-export var BadDecl = NewDecl(0, Scanner.ILLEGAL, false);
+var BadDecl = NewDecl(0, Scanner.ILLEGAL, false);
// ----------------------------------------------------------------------------
// Program
-export type Comment struct {
+type Comment struct {
Pos int;
Text string;
}
-export func NewComment(pos int, text string) *Comment {
+func NewComment(pos int, text string) *Comment {
c := new(Comment);
c.Pos, c.Text = pos, text;
return c;
}
-export type Program struct {
+type Program struct {
Pos int; // tok is Scanner.PACKAGE
Ident *Expr;
Decls *array.Array;
}
-export func NewProgram(pos int) *Program {
+func NewProgram(pos int) *Program {
p := new(Program);
p.Pos = pos;
return p;
}
-export type Flags struct {
+type Flags struct {
Verbose bool;
Sixg bool;
Deps bool;
}
-export func Compile(src_file string, flags *Flags) (*AST.Program, int) {
+func Compile(src_file string, flags *Flags) (*AST.Program, int) {
src, ok := Platform.ReadSourceFile(src_file);
if !ok {
print("cannot open ", src_file, "\n");
}
-export func ComputeDeps(src_file string, flags *Flags) {
+func ComputeDeps(src_file string, flags *Flags) {
globalset := make(map [string] bool);
wset := array.New(0);
wset.Push(src_file);
)
-export type Parser struct {
+type Parser struct {
// Tracing/debugging
verbose, sixg, deps, naming bool;
indent uint;
// Nesting levels
expr_lev int; // 0 = control clause level, 1 = expr inside ()'s
scope_lev int; // 0 = global scope, 1 = function scope of global functions, etc.
-
+
// Scopes
top_scope *AST.Scope;
};
// If scope != nil, lookup identifier in scope. Otherwise create one.
func (P *Parser) ParseIdent(scope *AST.Scope) *AST.Expr {
P.Trace("Ident");
-
+
x := AST.BadExpr;
if P.tok == Scanner.IDENT {
var obj *AST.Object;
P.Next();
d.Val = P.ParseExpressionList();
}
-
+
P.Declare(d.Ident, AST.CONST);
P.VerifyExport(d.Ident, exported);
// ----------------------------------------------------------------------------
// Environment
-export var
+var
GOARCH,
GOOS,
GOROOT,
// ----------------------------------------------------------------------------
// I/O
-export const (
+const (
MAGIC_obj_file = "@gri-go.7@v0"; // make it clear that it cannot be a source file
Src_file_ext = ".go";
Obj_file_ext = ".7";
return err1;
}
-export func ReadObjectFile(filename string) (string, bool) {
+func ReadObjectFile(filename string) (string, bool) {
data, err := readfile(filename + Obj_file_ext);
magic := MAGIC_obj_file; // TODO remove once len(constant) works
if err == nil && len(data) >= len(magic) && data[0 : len(magic)] == magic {
}
-export func ReadSourceFile(name string) (string, bool) {
+func ReadSourceFile(name string) (string, bool) {
name = Utils.TrimExt(name, Src_file_ext) + Src_file_ext;
data, err := readfile(name);
return data, err == nil;
}
-export func WriteObjectFile(name string, data string) bool {
+func WriteObjectFile(name string, data string) bool {
name = Utils.TrimExt(Utils.BaseName(name), Src_file_ext) + Obj_file_ext;
return writefile(name, data) != nil;
}
var (
debug = flag.Bool("debug", false, "print debugging information");
-
+
// layout control
tabwidth = flag.Int("tabwidth", 8, "tab width");
usetabs = flag.Bool("usetabs", true, "align with tabs instead of blanks");
)
-export type Printer struct {
+type Printer struct {
// output
text io.Write;
-
+
// comments
comments *array.Array; // the list of all comments
cindex int; // the current comments index
lastpos int; // pos after last string
level int; // scope level
indentation int; // indentation level (may be different from scope level)
-
+
// formatting parameters
separator int; // pending separator
newlines int; // pending newlines
-
+
// semantic state
state int; // current semantic state
laststate int; // state for last string
func (P *Printer) Init(text io.Write, comments *array.Array) {
// writers
P.text = text;
-
+
// comments
P.comments = comments;
P.cindex = -1;
P.NextComment();
-
+
// formatting parameters & semantic state initialized correctly by default
}
// we have a comment/newline that comes before the string
comment := P.comments.At(P.cindex).(*AST.Comment);
ctext := comment.Text;
-
+
if ctext == "\n" {
// found a newline in src - count it
nlcount++;
ctext += " ";
}
}
-
+
// print comment
if *debug {
P.Printf("[%d]", P.cpos);
// At this point we may have nlcount > 0: In this case we found newlines
// that were not followed by a comment. They are recognized (or not) when
// printing newlines below.
-
+
// --------------------------------
// interpret state
// (any pending separator or comment must be printed in previous state)
func (P *Printer) HtmlEpilogue() {
if *html {
- P.TaggedString(0,
+ P.TaggedString(0,
"</pre>\n"
"</body>\n"
"<html>\n",
case Scanner.IDENT:
P.HtmlIdentifier(x);
-
+
case Scanner.INT, Scanner.STRING, Scanner.FLOAT:
// literal
P.String(x.Pos, x.Obj.Ident);
} else {
P.Expr1(x.Y, Scanner.HighestPrec);
}
-
+
case Scanner.LBRACK:
// index
P.Expr1(x.X, Scanner.HighestPrec);
P.String(x.Pos, "{");
P.Expr(x.Y);
P.String(0, "}");
-
+
default:
// unary and binary expressions including ":" for pairs
prec := Scanner.UnaryPrec;
P.Token(s.Pos, s.Tok);
P.indentation++;
P.separator = none;
-
+
case Scanner.CONST, Scanner.TYPE, Scanner.VAR:
// declaration
P.Declaration(s.Decl, false);
P.Error(d.Pos, d.Tok, "decl");
}
}
-
+
P.newlines = 2;
}
// ----------------------------------------------------------------------------
// External interface
-export func Print(prog *AST.Program) {
+func Print(prog *AST.Program) {
// setup
var P Printer;
padchar := byte(' ');
P.HtmlPrologue("package " + prog.Ident.Obj.Ident);
P.Program(prog);
P.HtmlEpilogue();
-
+
P.String(0, ""); // flush pending separator/newlines
err := text.Flush();
if err != nil {
"utils";
)
-export const (
+const (
ILLEGAL = iota;
IDENT;
)
-export func TokenString(tok int) string {
+func TokenString(tok int) string {
switch tok {
case ILLEGAL: return "ILLEGAL";
}
-export const (
+const (
LowestPrec = -1;
UnaryPrec = 7;
HighestPrec = 8;
)
-export func Precedence(tok int) int {
+func Precedence(tok int) int {
switch tok {
case COLON:
return 0;
}
-export type ErrorHandler interface {
+type ErrorHandler interface {
Error(pos int, msg string);
Warning(pos int, msg string);
}
-export type Scanner struct {
+type Scanner struct {
// setup
err ErrorHandler;
src string; // source
}
-export type Token struct {
+type Token struct {
Pos int;
Tok int;
Val string;
package main
-export type Proto struct {
+type Proto struct {
a int "a tag";
b, c, d *Proto "bcd" "tag";
*Proto "proto tag"
)
-export const /* enum1 */ (
+const /* enum1 */ (
EnumTag0 = iota;
EnumTag1;
EnumTag2;
)
-export type S struct {}
+type S struct {}
-export type T struct {
+type T struct {
x, y int;
s string;
next_t *T
for i := 0; i < d.List.Len(); i++ {
s.CheckDeclaration(d.List.At(i).(*AST.Decl))
}
-
+
} else {
// single declaration
switch d.Tok {
// ----------------------------------------------------------------------------
-export func CheckProgram(err Scanner.ErrorHandler, p *AST.Program) {
+func CheckProgram(err Scanner.ErrorHandler, p *AST.Program) {
var s state;
s.Init(err);
s.CheckProgram(p);
)
-export var (
+var (
Scope *AST.Scope;
Types array.Array;
-
+
// internal types
Void_typ,
Bad_typ,
Nil_typ,
-
+
// basic types
Bool_typ,
Uint8_typ,
Float80_typ,
String_typ,
Integer_typ,
-
+
// convenience types
Byte_typ,
Uint_typ,
Int_typ,
Float_typ,
Uintptr_typ *AST.Type;
-
+
True_obj,
False_obj,
Iota_obj,
func init() {
Scope = AST.NewScope(nil); // universe has no parent
Types.Init(32);
-
+
// Interal types
Void_typ = AST.NewType(-1 /* no source pos */, AST.VOID);
AST.Universe_void_typ = Void_typ;
Bad_typ = AST.NewType(-1 /* no source pos */, AST.BADTYPE);
Nil_typ = AST.NewType(-1 /* no source pos */, AST.NIL);
-
+
// Basic types
Bool_typ = register(declType(AST.BOOL, "bool", 1));
Uint8_typ = register(declType(AST.UINT, "uint8", 1));
declObj(AST.BUILTIN, "new", Void_typ);
declObj(AST.BUILTIN, "panic", Void_typ);
declObj(AST.BUILTIN, "print", Void_typ);
-
+
// scope.Print();
}
package Utils
-export func BaseName(s string) string {
+func BaseName(s string) string {
// TODO this is not correct for non-ASCII strings!
i := len(s) - 1;
for i >= 0 && s[i] != '/' {
}
-export func Contains(s, sub string, pos int) bool {
+func Contains(s, sub string, pos int) bool {
end := pos + len(sub);
return pos >= 0 && end <= len(s) && s[pos : end] == sub;
}
-export func TrimExt(s, ext string) string {
+func TrimExt(s, ext string) string {
i := len(s) - len(ext);
if i >= 0 && s[i : len(s)] == ext {
s = s[0 : i];
}
-export func IntToString(x, base int) string {
+func IntToString(x, base int) string {
x0 := x;
if x < 0 {
x = -x;
buf[i] = hex[x % base];
x /= base;
}
-
+
if x0 < 0 {
i--;
buf[i] = '-';
}
-
+
return string(buf)[i : len(buf)];
}