Example #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
}
Example #2
0
File: error.go Project: catb0t/gelo
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")
}
Example #3
0
File: eval.go Project: catb0t/gelo
//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
}
Example #4
0
File: util.go Project: catb0t/gelo
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
}
Example #5
0
File: names.go Project: catb0t/gelo
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)
}