Exemple #1
0
func (self *Remainder) Call(args ...value.Value) value.Value {
	if len(args) != 2 {
		panic(fmt.Errorf("remainder: arity mismatch, expected 2, given %s\n", len(args)))
	}

	var n1, n2 int64
	if arg1, ok := args[0].(*value.Int); !ok {
		panic(fmt.Errorf("remainder: contract violation, expected: integer?"))
	} else {
		n1 = arg1.Value
	}

	if arg2, ok := args[1].(*value.Int); !ok {
		panic(fmt.Errorf("remainder: contract violation, expected: integer?"))
	} else {
		n2 = arg2.Value
	}

	return value.NewInt(n1 % n2)
}
Exemple #2
0
func (self *Mul) Call(args ...value.Value) value.Value {
	var result float64 = 1
	isfloat := false

	for _, item := range args {
		switch operand := item.(type) {
		case *value.Int:
			result *= float64(operand.Value)
		case *value.Float:
			isfloat = true
			result *= operand.Value
		default:
			panic(fmt.Errorf("%v: unexpected number", self.String()))
		}
	}
	if isfloat {
		return value.NewFloat(result)
	}
	return value.NewInt(int64(result))
}
Exemple #3
0
func (self *Int) Eval(env *scope.Scope) value.Value {
	return value.NewInt(self.value)
}