Ejemplo n.º 1
0
func Ptrptr(pt *Ptr, p uintptr) {
	if unsafe.Sizeof(pt) > p64sz {
		panic("pointers are too big")
	}
	ps := sliceptr(p, p64sz)
	err := pbytes.MarshalBinary(ps, uintptr(unsafe.Pointer(pt)))
	if err != nil {
		panic("xnew marshal")
	}
}
Ejemplo n.º 2
0
func push32(c uint32) {
	if int(mst.sp)+4 > mst.stackend {
		panic("stack overflow")
	}
	err := pbytes.MarshalBinary(mst.stack[mst.sp:], c)
	if err != nil {
		panic("push32")
	}
	mst.sp += 4
}
Ejemplo n.º 3
0
func pushn(xd []byte) {
	if int(mst.sp)+len(xd) > mst.stackend {
		panic("stack overflow")
	}
	err := pbytes.MarshalBinary(mst.stack[mst.sp:], xd)
	if err != nil {
		panic("pushn")
	}
	mst.sp += len(xd)
}
Ejemplo n.º 4
0
func push64(c uint64) {
	if int(mst.sp)+8 > mst.stackend {
		panic("stack overflow")
	}
	err := pbytes.MarshalBinary(mst.stack[mst.sp:], c)
	if err != nil {
		panic("push64")
	}
	mst.sp += 8
}
Ejemplo n.º 5
0
func xgreadmouse() {
	var x, y, nbut int
	g := xgrx(int(pop32()), "greadmouse")
	xp := popslice(u32sz)
	yp := popslice(u32sz)
	nbutp := popslice(u32sz)
	g.ReadMouse(&x, &y, &nbut)
	err := pbytes.MarshalBinary(xp, x)
	if err != nil {
		panic("xgreadmouse marshal")
	}
	err = pbytes.MarshalBinary(yp, y)
	if err != nil {
		panic("xgreadmouse marshal")
	}
	err = pbytes.MarshalBinary(nbutp, nbut)
	if err != nil {
		panic("xgreadmouse marshal")
	}
}
Ejemplo n.º 6
0
func xrand() {
	n := int(pop32())
	if n<=0 || n>paminstr.Maxint {
		panic("rand: n should be in (0, Maxint] ")
	}
	i := randsrc.Intn(n)
	ip := popslice(u32sz)
	err := pbytes.MarshalBinary(ip, i)
	if err != nil {
		panic("rand marshal")
	}
}
Ejemplo n.º 7
0
func pushr(c float64) {
	if math.IsNaN(c) {
		panic("invalid operation on float")
	}
	n := float32(c)
	if int(mst.sp)+4 > mst.stackend {
		panic("stack overflow")
	}
	err := pbytes.MarshalBinary(mst.stack[mst.sp:], n)
	if err != nil {
		panic("pushr")
	}
	mst.sp += 4
}
Ejemplo n.º 8
0
func xopen() {
	t1 := tfetch(int(pop32()))
	t2 := tfetch(int(pop32()))
	fp := popslice(u32sz)
	name := popn(int(t1.sz))
	mode := popn(int(t2.sz))
	if name == "stdgraph" {
		panic("use gopen for stdgraph")
	}
	n := uint32(xbopen(name, mode, nil))
	err := pbytes.MarshalBinary(fp, n)
	if err != nil {
		panic("xopen marshal")
	}
}
Ejemplo n.º 9
0
func xgopen() {
	t1 := tfetch(int(pop32()))
	ip := popslice(u32sz)
	name := popn(int(t1.sz))
	g := gx.OpenGraphics(name)
	if g == nil {
		panic("unable to open graphx")
	}
	i := xbgopen(g)
	err := pbytes.MarshalBinary(ip, i)
	if err != nil {
		panic("gopen marshal")
	}
	urlopen("http://localhost:4242/" + name)
}
Ejemplo n.º 10
0
func xfpeek() {
	var (
		c   rune
		err error
	)
	fid := pop32()
	f, sc := xbfile(int(fid))
	if !f.isgraphic() {
		flushall()
	}
	cp := popslice(u32sz)
	if f.eof {
		panic("peek: eof met")
	}
	if f.eol {
		c = rune(paminstr.EOL[0])
	} else {
		c, _, err = sc.ReadRune()
		if iseof(c, err) {
			c = 0xFF
			f.eof = true
		} else if err != nil {
			panic("fpeek: bad file")
		} else {
			if c == rune(paminstr.EOL[0]) {
				f.eol = true
			} else {
				sc.UnreadRune()
			}
		}
	}
	err = pbytes.MarshalBinary(cp, c)
	if err != nil {
		panic("xfpeek marshal")
	}
	if debug['I'] != 0 {
		fmt.Fprintf(os.Stderr, "fpeek: c '%c'[%x] file %d: eol %veof %v\n",
			c, c, fid, f.eol, f.eof)
	}
}
Ejemplo n.º 11
0
func xgkeypress() {
	t1 := tfetch(int(pop32()))
	fid := int(pop32())
	f, _ := xbfile(fid)
	g := xgrx(fid, "greadkeys")
	switch t1.fmt {
	case 'c':
		cp := popslice(int(t1.sz))
		for i := 0; i < len(cp); i++ {
			cp[i] = 0
		}
		c := g.ReadKeyPress()
		if c == 0xff {
			f.eof = true
		}
		err := pbytes.MarshalBinary(cp, c)
		if err != nil {
			panic("xgreadkeys: marshal")
		}
	case 'a':
		nc := t1.nitems
		cp := popslice(4*nc)
		cpp := make([]byte, nc)
		g.ReadKeyPresses(cpp)
		if cpp[0] == 0xff {
			f.eof = true
		}
		for i := 0; i < len(cp); i++ {
			if i%4 == 0 {
				cp[i] = cpp[i/4]
			} else {
				cp[i] = 0
			}
		}
	default:
		panic("xgreadkeys: can't read variables of this type")
	}
}
Ejemplo n.º 12
0
func _xfread(tid int, f *Xfile) {
	var sc io.RuneScanner
	if f.isgraphic() {
		sc = f.graph
	} else {
		sc = f.b
		flushall()
	}
	if f.eof {
		panic("read: eof met")
	}
	if (f.mode&rMode) == 0 {
		panic("read: file not open for reading")
	}
	switch mabs.tents[tid].fmt {
	case 'i', 'u', 'h':
		d := popslice(int(mabs.tents[tid].sz))
		s := readword(f, true)
		n, err := strconv.ParseInt(s, 0, 64)
		if err != nil {
			panic("read: no int value found")
		}

		if int(n)<mabs.tents[tid].first || int(n)>mabs.tents[tid].last {
			panic("read: value is out of range")
		}
		err = pbytes.MarshalBinary(d, int(n))
		if err != nil {
			panic("_xfread marshal")
		}
	case 'e':
		d := popslice(mabs.tents[tid].nitems*p32sz)
		s := readword(f, false)
		for i := 0; i < mabs.tents[tid].nitems; i++ {
			if strings.EqualFold(s, mabs.tents[tid].lits[i]) {
				err := pbytes.MarshalBinary(d, mabs.tents[tid].first+i)
				if err != nil {
					panic("_xfread marshal")
				}
				return
			}
		}
		panic("read: no enumerated value found")
	case 'c':
		d := popslice(int(mabs.tents[tid].sz))
		if f.eol {
			panic("read: at end of line")
		}
		n, _, err := sc.ReadRune()
		if err != nil {
			if iseof(n, err) {
				n = 0xFF
				f.eof = true
				f.eol = false
			} else {
				panic("read error")
			}
		} else {
			f.eol = n == rune(paminstr.EOL[0])
			if int(n)<mabs.tents[tid].first || int(n)>mabs.tents[tid].last {
				panic("read: value is out of range")
			}
		}
		err = pbytes.MarshalBinary(d, n)
		if err != nil {
			panic("_xfread marshal")
		}
	case 'b':
		d := popslice(int(mabs.tents[tid].sz))
		s := readword(f, false)
		n := 0
		if strings.EqualFold(s, "True") {
			n = 1
		} else if !strings.EqualFold(s, "False") {
			panic("read: no bool value found")
		}
		err := pbytes.MarshalBinary(d, n)
		if err != nil {
			panic("_xfread marshal")
		}
	case 'l':
		/* opacity is like a float with range */
		d := popslice(int(mabs.tents[tid].sz))
		s := readword(f, true)
		df, err := strconv.ParseFloat(s, 64)
		if err != nil {
			panic("read: no float value found")
		}
		if df<float64(mabs.tents[tid].first) || df>float64(mabs.tents[tid].last) {
			panic("read: value is out of range")
		}
		err = pbytes.MarshalBinary(d, float32(df))
		if err != nil {
			panic("_xfread marshal")
		}
	case 'r':
		d := popslice(int(mabs.tents[tid].sz))
		s := readword(f, true)
		df, err := strconv.ParseFloat(s, 64)
		if err != nil {
			panic("read: no float value found")
		}
		err = pbytes.MarshalBinary(d, float32(df))
		if err != nil {
			panic("_xfread marshal")
		}
	case 'a':
		d := popslice(4*mabs.tents[tid].nitems)
		str := make([]rune, 0)
		spad := make([]rune, 3)
		for i := 0; i < mabs.tents[tid].nitems; i += 1 {
			n, w, err := sc.ReadRune()
			str = append(str, n)
			str = append(str, spad[0:4-w]...)
			if byte(n) == paminstr.EOL[0] {
				panic("read: eol")
			}
			if err != nil {
				if iseof(n, err) {
					panic("read: eof met")
				} else {
					panic("error reading")
				}
			}
		}
		err := pbytes.MarshalBinary(d, string(str))
		if err != nil {
			panic("_xfread marshal")
		}
	default:
		panic("read: can't read variables of this type")
	}
}