Ejemplo n.º 1
0
func (doc *docReader) init(pkgName string) {
	doc.pkgName = pkgName
	doc.values = vector.New(0)
	doc.types = make(map[string]*typeDoc)
	doc.funcs = make(map[string]*ast.FuncDecl)
	doc.bugs = vector.New(0)
}
Ejemplo n.º 2
0
func (p *parser) init(filename string, input []byte) {
	p.ErrorList.Init()
	p.trace = true
	p.scanner.Init(filename, input, p)
	p.Instlist = vector.New(0)
	p.Datalist = vector.New(0)
	p.Labels = make(map[string]*inst.LabelT)
	p.next()
}
Ejemplo n.º 3
0
// Data returns a slice containing the elements of iter.
func Data(iter Iterable) []interface{} {
	vec := vector.New(0)
	for e := range iter.Iter() {
		vec.Push(e)
	}
	return vec.Data()
}
Ejemplo n.º 4
0
// Compile parses a regular expression and returns, if successful, a Regexp
// object that can be used to match against text.
func Compile(str string) (regexp *Regexp, error os.Error) {
	regexp = new(Regexp)
	regexp.expr = str
	regexp.inst = vector.New(0)
	error = regexp.doParse()
	return
}
Ejemplo n.º 5
0
func Primes_up_to(number int64) (results []int64) {
	space := make([]bool, number)
	p := int64(2)
	for {
		fmt.Printf("%d\n", p)
		// mark all multiples of p non-prime
		for i := p + p; i < number; i += p {
			space[i] = true
		}
		if int64(math.Pow(float64(p), 2)) > number {
			break
		}
		// find the next p
		for i := p + 1; i < number; i += 1 {
			if space[i] == false {
				p = i
				break
			}
		}
	}
	tresults := vector.New(0)
	for i := int64(2); i < number; i++ {
		if space[i] == false {
			tresults.Push(i)
		}
	}
	results = make([]int64, tresults.Len())
	i := 0
	for v := range tresults.Iter() {
		results[i] = v.(int64)
		i++
	}

	return
}
Ejemplo n.º 6
0
func (doc *docReader) lookupTypeDoc(name string) *typeDoc {
	if name == "" {
		return nil // no type docs for anonymous types
	}
	if tdoc, found := doc.types[name]; found {
		return tdoc
	}
	// type wasn't found - add one without declaration
	tdoc := &typeDoc{nil, vector.New(0), make(map[string]*ast.FuncDecl), make(map[string]*ast.FuncDecl)}
	doc.types[name] = tdoc
	return tdoc
}
Ejemplo n.º 7
0
func TestAll(t *testing.T) {
	s := new(S);
	// initialized by hand for clarity.
	s.header = "Header";
	s.integer = 77;
	s.raw = "&<>!@ #$%^";
	s.innerT = t1;
	s.data = []T{t1, t2};
	s.pdata = []*T{&t1, &t2};
	s.empty = []*T{};
	s.null = nil;
	s.vec = vector.New(0);
	s.vec.Push("elt1");
	s.vec.Push("elt2");
	s.true = true;
	s.false = false;

	var buf bytes.Buffer;
	for _, test := range tests {
		buf.Reset();
		tmpl, err := Parse(test.in, formatters);
		if err != nil {
			t.Error("unexpected parse error:", err);
			continue;
		}
		err = tmpl.Execute(s, &buf);
		if test.err == "" {
			if err != nil {
				t.Error("unexpected execute error:", err);
			}
		} else {
			if err == nil || err.String() != test.err {
				t.Errorf("expected execute error %q, got %q", test.err, err.String());
			}
		}
		if buf.String() != test.out {
			t.Errorf("for %q: expected %q got %q", test.in, test.out, buf.String());
		}
	}
}
Ejemplo n.º 8
0
func NewAsyncGofunge93(code [][]byte) *AsyncGofunge93 {
	b := new(AsyncGofunge93);
	b.code = code;
	b.stack = &ChanStack{vector.New(0)};
	return b;
}
Ejemplo n.º 9
0
func NewGofunge93(code [][]byte) *Gofunge93 {
	b := new(Gofunge93);
	b.code = code;
	b.stack = &Stack{vector.New(0)};
	return b;
}
Ejemplo n.º 10
0
func (b *Writer) addLine() {
	b.lines.Push(vector.New(0))
}
Ejemplo n.º 11
0
Archivo: main.go Proyecto: ox/GoStones
func main() {
	flag.Parse()
	errors := vector.New(0)

	//fill repositories StringVector
	repositories := vector.New(0) //make a new vec
	file, err := os.Open("./list.txt", os.O_RDONLY, 0755)
	if file == nil {
		errors.Push(err)
	}

	in = bufio.NewReader(file)
	ik := 0

	for {
		dat2, err := in.ReadSlice('\n')
		if err == os.EOF || (string(dat2[0:len(dat2)-1]) == "" && err == os.EOF) {
			errors.Push(err)
			break
		}

		if string(dat2[0]) != "#" && string(dat2[0]) != "" && string(dat2[0]) != "\n" { //# is a comment
			str := strings.Split(string(dat2), " ", -1)
			gem := NewGemSource(str[1:len(str)], str[0])
			repositories.Push(gem)

			ik++
		}
	}

	//get the version number
	if *get_go_gems_version {
		go_gems_version, err := io.ReadFile("./go_stones_version")

		if go_gems_version == nil {
			errors.Push(err)
		}
		fmt.Println("GoStones version ", string(go_gems_version))

		br()
	}

	//list repositories
	if *list {
		fmt.Println("listing", ik, "repos:")
		for i := 0; i < ik; i++ {
			fmt.Printf("%v\n", repositories.At(i).(*GemSource).url)
		}
		br()
	}

	if *list_full {
		for i := 0; i < ik; i++ {
			fmt.Printf("%v\n----------------------\n    ", repositories.At(i).(*GemSource))
			for _, v := range repositories.At(i).(*GemSource).short_names {
				fmt.Printf("%v\n    ", v)
			}
			br()
		}
	}

	if *remove_repository != "" {

		fmt.Println("looking for", *remove_repository)

		l := 0

		for ; l < ik; l++ {
			gem := repositories.At(l).(*GemSource)

			if gem.url == *remove_repository {
				fmt.Print("found! removing ", gem.url, " at ", l, "\n")
				repositories.Delete(l)
				break
			}

			for _, v := range gem.short_names {
				if v == *remove_repository || v == *remove_repository+"\n" {
					fmt.Print("found! removing ", v, " at ", l, "\n")
					repositories.Delete(l)
					l = ik
					break
				}
			}
		}

		if repositories.Len() == ik { //nothing was removed
			//our fall through
			fmt.Println("No such alias or url found in the list, check spelling or url,", repositories.Len())
			os.Exit(1)
		}

		file, err := os.Open("./list.txt", os.O_RDWR, 0755)
		if file == nil {
			errors.Push(err)
		}

		out = bufio.NewWriter(file)

		errlol := io.WriteFile(file.Name(), []byte{}, 0755)
		if errlol != nil {
			fmt.Print(errlol)
			errors.Push(errlol)
			os.Exit(1)
		}

		for i := 0; i < repositories.Len(); i++ {
			gem := repositories.At(i).(*GemSource)
			io.WriteString(out, gem.url)
			fmt.Print(gem)

			for k := 0; k < len(gem.short_names); k++ {
				io.WriteString(out, " "+gem.short_names[k])
				fmt.Print(" " + gem.short_names[k])
			}
			//io.WriteString(out, "\n" );
		}

		out.Flush()
		file.Close()
	}

	if *add_repo != "" {
		str := strings.Split(*add_repo, " ", -1)

		var gem *GemSource

		if len(str) == 1 {
			_, short_name := path.Split(str[0])
			short_name = strings.Split(short_name, ".", -1)[0]
			gem = NewGemSource([]string{short_name + "\n"}, str[0])
			fmt.Println("no alias provided, making it", short_name)
		} else {
			gem = NewGemSource(str[1:len(str)], str[0])
		}

		fmt.Println("adding:", gem)

		repositories.Push(gem)

		file, err := os.Open("./list.txt", os.O_RDWR, 0755)
		if file == nil {
			errors.Push(err)
		}

		out = bufio.NewWriter(file)

		for i := 0; i < repositories.Len(); i++ {
			gem := repositories.At(i).(*GemSource)
			io.WriteString(out, gem.url)
			for k := 0; k < len(gem.short_names); k++ {
				io.WriteString(out, " "+gem.short_names[k])
			}
		}
		io.WriteString(out, "\n")

		out.Flush()
		file.Close()
	}

	if *install != "" {
		file_name := *install

		//search the repos for the right file
		for i := 0; i < ik; i++ {
			gem := repositories.At(i).(*GemSource)
			_, pre_tested_name := path.Split(gem.short_names[0])
			tested_name := strings.Split(pre_tested_name, ".", -1)[0]

			for _, val := range gem.short_names {

				if tested_name == file_name || val == file_name || val == file_name+"\n" {
					str := strings.Split(gem.url, ":", -1)

					fmt.Println(str[0])

					switch str[0] {
					case "http":
						fmt.Println("Pulling from the net...")

						response, _, err := http.Get(gem.url)
						if err != nil {
							fmt.Println(err)
							os.Exit(1)
						}

						var nr int
						const buf_size = 0x10
						buf := make([]byte, buf_size)
						nr, _ = response.Body.Read(buf)

						if nr >= buf_size {
							panic("Buffer overrun")
						}

						errorr := io.WriteFile("./"+pre_tested_name, buf, 0755)
						if errorr != nil {
							fmt.Println(errorr)
							os.Exit(1)
						}

						buf = nil
						response.Body.Close()
						break

					case "git":
						fmt.Println("git'n it from the net...")

						dir := git_from_net(string(gem.url))
						log.Stdout(dir)
						build_pkg(string(dir))

						break
					}

					fmt.Println("passed retrieving file...")

					break
				}
			}
		}
	}

	if *show_errors {
		fmt.Println(errors)
	}

	file.Close()

}
Ejemplo n.º 12
0
func (b *_JsonBuilder) Array() { b.Put(&_Array{vector.New(0), _Null{}}) }