Esempio n. 1
0
func New(o Object) *Imp {
	//
	x := new(Imp)
	switch o.(type) {
	case *enum.Imp:
		x.Object, x.typ = enum.New(enum.Enum(o.(*enum.Imp).Typ())), Enumerator
	case *tval.Imp:
		x.Object, x.typ = tval.New(), TruthValue
	case *char.Imp:
		x.Object, x.typ = char.New(), Character
	case *text.Imp:
		x.Object, x.typ = text.New(o.(*text.Imp).Len()), Text
	case *bnat.Imp:
		x.Object, x.typ = bnat.New(o.(*bnat.Imp).Startval()), Natural
	case *breal.Imp:
		x.Object, x.typ = breal.New(4), Real
	case *clk.Imp:
		x.Object, x.typ = clk.New(), Clocktime
	case *day.Imp:
		x.Object, x.typ = day.New(), Calendarday
	case *euro.Imp:
		x.Object, x.typ = euro.New(), Euro
	case *cntry.Imp:
		x.Object, x.typ = cntry.New(), Country
	case *pers.Imp:
		x.Object, x.typ = pers.New(), Person
	case *phone.Imp:
		x.Object, x.typ = phone.New(), PhoneNumber
	case *addr.Imp:
		x.Object, x.typ = addr.New(), Address
	default:
		ker.Panic("atom.New: parameter does not characterize an atom.Atomtype")
	}
	return x
}
Esempio n. 2
0
func (x *Imp) Get() Any {
	//
	if x.anchor == nil {
		return nil
	}
	if x.actual == nil {
		ker.Panic("set.Get error: x.actual == nil")
	}
	return Clone(x.actual.root)
}
Esempio n. 3
0
func Want(y, m, d uint) {
	//
	wanted := day.New()
	wanted.SetFormat(day.Yymmdd)
	if wanted.Set(d, m, 2000+y) {
		if v.Less(wanted) {
			errh.Error("Your murus "+v.String()+" is outdated. You need "+wanted.String()+".", 0)
			ker.Halt(-1)
		}
	} else {
		ker.Panic("parameters for v.Want are nonsense")
	}
}
Esempio n. 4
0
// x.path is the list of nodes from actual up to root.
// min/max == true, iff the actual node w.r.t. Less
// is the smallest/largest object in x.
func (x *Imp) defPath() (bool, bool) {
	//
	t := x.anchor
	x.path = &node{t, nil}
	min, max := true, true
	for {
		if t == x.actual {
			break
		}
		if x == nil {
			ker.Panic("murus/set/path.go defPath: x == nil")
		}
		if t.root == nil {
			ker.Panic("murus/set/path.go defPath: t.root == nil")
		}
		if Less(x.actual.root, t.root) { // TODO avoid crash
			t, max = t.left, false
		} else {
			t, min = t.right, false
		}
		x.path = &node{t, x.path}
	}
	return min && t.left == nil, max && t.right == nil
}
Esempio n. 5
0
func Decode(a Any, b []byte) Any {
	//
	switch a.(type) {
	case Object:
		a.(Object).Decode(b)
		return a
	case byte:
		a = b[0]
		/*/
		  /*/
	case float64: // workaround (bug in Go ?)
		u := uint64(0)
		for i := 0; i < 8; i++ {
			u <<= 8
			u += uint64(b[i])
		}
		//    return math.Float64frombits (u)
		return *(*float64)(unsafe.Pointer(&u))
		/*/
		  /*/
	case string:
		return string(b)
	case []byte:
		copy(a.([]byte), b)
		return a
	default:
		n := uintptr(unsafe.Sizeof(a)) // 8 (386) resp. 16 (amd64)
		/*/
		    t:= reflect.TypeOf (a)
		    s:= t.Size ()
		/*/
		s := reflect.TypeOf(a).Size()
		if s != uintptr(len(b)) {
			ker.Panic("obj.Decode error: s == " + strconv.Itoa(int(s)) +
				", len(b) == " + strconv.Itoa(int(uintptr(len(b)))))
		}
		if s < n {
			n = uintptr(n / 2)
		} else {
			n = uintptr(0)
		}
		addr := uintptr(unsafe.Pointer(&a))
		for i := uintptr(0); i < s; i++ {
			*(*byte)(unsafe.Pointer(addr + n + i)) = b[i]
		}
	}
	return a
}
Esempio n. 6
0
func New(nc, nr uint) *Imp {
	//
	x := new(Imp)
	x.nC, x.nR = nc, nr
	x.stat = make([]status, x.nC)
	for r := uint(0); r < x.nR; r++ {
		x.stat[r].max = make([]uint, x.nC)
		for c := uint(0); c < x.nC; c++ {
			x.stat[r].max[c] = ker.MaxNat
		}
	}
	c := func(k uint) bool {
		var b bool
		for r := uint(0); r < x.nR; r++ {
			b = b ||
				x.stat[r].number == 0 ||
				x.stat[r].class == k && x.stat[r].number < x.stat[r].max[k]
		}
		return b
	}
	e := func(a Any, k uint) {
		for r := uint(0); r < x.nR; r++ {
			if x.stat[r].number == 0 || x.stat[r].class == k {
				x.stat[r].class = k
				x.stat[r].number++
				n := a.(*uint)
				*n = r
				return
			}
		}
		ker.Panic(pack + ".New() error")
	}
	l := func(a Any, k uint) {
		for r := uint(0); r < x.nR; r++ {
			if x.stat[r].class == k && x.stat[r].number > 0 {
				x.stat[r].number--
			}
		}
	}
	x.Imp = cs.New(x.nC, c, e, l)
	return x
}
Esempio n. 7
0
func NewR(h []*host.Imp, p []uint) *ImpR {
	//
	n := uint(len(h))
	if n == 0 {
		ker.Panic("dlock.NewR for n == 0")
	}
	me := uint(0)
	for i := uint(0); i < n; i++ {
		if host.Local(h[i].String()) {
			me = i
		}
	}
	k := (me + n - 1) / n
	in := nchan.New(false, h[k].String(), uint16(p[k]), true)
	k = (me + 1) / n
	out := nchan.New(false, h[k].String(), uint16(p[k]), true)
	x := new(ImpR)
	x.entry.Lock()
	x.exit.Lock()
	go func() {
		for {
			if halt {
				break
			}
			in.Recv()
			if x.crit {
				x.entry.Unlock()
				x.exit.Lock()
			}
			out.Send(true)
		}
		in.Terminate()
		out.Terminate()
	}()
	if me == 0 {
		out.Send(true)
	}
	return x
}
Esempio n. 8
0
func WrongUintParameterPanic(s string, a Any, n uint) {
	//
	ker.Panic("method " + s +
		" for object of type " + reflect.TypeOf(a).String() +
		" got wrong value for " + strconv.FormatUint(uint64(n), 10))
}
Esempio n. 9
0
func PanicIfNotOk(a Any) {
	//
	if !Atomic(a) && !IsObject(a) {
		ker.Panic("parameter is neither Atomic nor implements Object")
	}
}
Esempio n. 10
0
func NotCompatiblePanic() {
	//
	ker.Panic("the two involved types are not compatible")
}
Esempio n. 11
0
func TypeNotEqPanic(a, b Any) {
	//
	ker.Panic("the types " + reflect.TypeOf(a).String() +
		" and " + reflect.TypeOf(b).String() + " are not equal")
}
Esempio n. 12
0
func TypePanic() {
	//
	ker.Panic("the type does not fit to the implementation")
}
Esempio n. 13
0
func DivBy0Panic() {
	//
	ker.Panic("division by 0")
}
Esempio n. 14
0
func (x *Imp) Split(Y Iterator) {
	//
	//  y:= x.imp (Y)
	ker.Panic("piset.Split not yet implemented")
}
Esempio n. 15
0
func (x *Imp) ClrPred(p Pred) {
	//
	ker.Panic("piset.ClrPred not yet implemented")
}