Exemple #1
0
func ReOrElse(vm *gelo.VM, w gelo.Word) *Regexp {
	r, ok := w.(*Regexp)
	if !ok {
		gelo.TypeMismatch(vm, "regexp", w.Type())
	}
	return r
}
Exemple #2
0
func TypeMismatchError(vm *gelo.VM, args *gelo.List, ac uint) gelo.Word {
	if ac != 2 {
		gelo.ArgumentError(vm, "TypeMismatchError",
			"expected-type recieved-type", args)
	}
	gelo.TypeMismatch(vm, args.Value.Ser(), args.Next.Value.Ser())
	panic("Issue 65")
}
Exemple #3
0
//Not the best name. Rewrites quote (ie rewrites $@[]) then returns
//a list of lists of symbols
func Partial_eval(vm *gelo.VM, args *gelo.List, ac uint) gelo.Word {
	if ac != 1 {
		gelo.ArgumentError(vm, "partial-eval", "quote", args)
	}
	lists, ok := vm.API.PartialEval(vm.API.QuoteOrElse(args.Value))
	if !ok {
		gelo.TypeMismatch(vm, "code quote", "literal quote")
	}
	return lists
}
Exemple #4
0
func ToIdx(vm *gelo.VM, w gelo.Word, length int) int {
	n := vm.API.NumberOrElse(w)
	j, ok := n.Int()
	if !ok || math.MaxInt32 < j {
		gelo.TypeMismatch(vm, "32-bit integer", "float")
	}
	i := int(j)
	if (i < 0 && i < -length) || (i >= 0 && i >= length) {
		IndexError(vm, i, n)
	}
	return (length + i) % length
}
Exemple #5
0
func _export_parser(vm *gelo.VM, args *gelo.List) (int, *gelo.List) {
	Args := _up_parser(vm, args)
	levels, ok := Args["levels"]
	lvl := 1
	var lvl64 int64
	if ok {
		lvl64, ok = vm.API.NumberOrElse(levels).Int()
		if !ok || lvl < 0 {
			gelo.TypeMismatch(vm, "positive integer", "number")
		}
		lvl = int(lvl64)
	}
	return lvl, Args["args"].(*gelo.List)
}