Value* IntegerValue::multiply(Value* operand) { if (operand->getType() == "INTEGER") { IntegerValue* operandValue = dynamic_cast<IntegerValue*> (operand); return new IntegerValue(this->value * operandValue->value); } else if (operand->getType() == "BOOLEAN") { BooleanValue* operandValue = dynamic_cast<BooleanValue*> (operand); return new IntegerValue(this->value * operandValue->value); } else if (operand->getType() == "STRING") { return operand->multiply(this); } else if (operand->getType() == "DOUBLE") { DoubleValue* operandValue = dynamic_cast<DoubleValue*> (operand); return new DoubleValue(this->value * operandValue->value); } throw wrong_type("Right operand of multiply operator has incorrect type " + operand->getType()); }
Value* StringValue::greaterEqual(Value* operand) { if (operand->getType() == "STRING") { StringValue* operandValue = dynamic_cast<StringValue*> (operand); return new BooleanValue(this->value >= operandValue->value); } throw wrong_type("Right operand of greater equal operator has incorrect type " + operand->getType()); }
Value* StringValue::plus(Value* operand) { if (operand->getType() == "STRING") { StringValue* operandValue = dynamic_cast<StringValue*> (operand); return new StringValue(this->value + operandValue->value); } throw wrong_type("Right operand of plus operator has incorrect type " + operand->getType()); }
Value* IntegerValue::mod(Value* operand) { if (operand->getType() == "INTEGER") { IntegerValue* operandValue = dynamic_cast<IntegerValue*> (operand); if (operandValue->value == 0) { throw std::out_of_range("Division by zero in mod operator"); } return new IntegerValue(this->value % operandValue->value); } throw wrong_type("Right operand of mod operator has incorrect type " + operand->getType()); }
Value* BooleanValue::greaterEqual(Value* operand) { if (operand->getType() == "INTEGER") { IntegerValue* operandValue = dynamic_cast<IntegerValue*> (operand); return new BooleanValue(this->value >= operandValue->value); } else if (operand->getType() == "BOOLEAN") { BooleanValue* operandValue = dynamic_cast<BooleanValue*> (operand); return new BooleanValue(this->value >= operandValue->value); } throw wrong_type("Right operand of greater equal operator has incorrect type " + operand->getType()); }
Value* DoubleValue::greaterEqual(Value* operand) { if (operand->getType() == "INTEGER") { IntegerValue* operandValue = dynamic_cast<IntegerValue*> (operand); return operandValue->lessEqual(this); } else if (operand->getType() == "DOUBLE") { DoubleValue* operandValue = dynamic_cast<DoubleValue*> (operand); return new DoubleValue(this->value >= operandValue->value); } throw wrong_type("Right operand of greater equal operator has incorrect type " + operand->getType()); }
Value* DoubleValue::minus(Value* operand) { if (operand->getType() == "INTEGER") { IntegerValue* operandValue = dynamic_cast<IntegerValue*> (operand); return new DoubleValue(this->value - operandValue->value); } else if (operand->getType() == "DOUBLE") { DoubleValue* operandValue = dynamic_cast<DoubleValue*> (operand); return new DoubleValue(this->value - operandValue->value); } throw wrong_type("Right operand of minus operator has incorrect type " + operand->getType()); }
Value* IntegerValue::andOperator(Value* operand) { if (operand->getType() == "INTEGER") { IntegerValue* operandValue = dynamic_cast<IntegerValue*> (operand); return new IntegerValue(this->value & operandValue->value); } else if (operand->getType() == "BOOLEAN") { BooleanValue* operandValue = dynamic_cast<BooleanValue*> (operand); return new IntegerValue(this->value & operandValue->value); } throw wrong_type("Right operand of and operator has incorrect type " + operand->getType()); }
Value* StringValue::multiply(Value* operand) { if (operand->getType() == "INTEGER") { IntegerValue* operandValue = dynamic_cast<IntegerValue*> (operand); std::string resultString; for (int i = 0; i < operandValue->value; ++i) { resultString += this->value; } return new StringValue(resultString); } throw wrong_type("Right operand of multiply operator has incorrect type " + operand->getType()); }
static void __attribute__((noreturn)) apply_implementation(closure *self, int argc, oop k, oop f, ...) { pair *prev = NULL; pair *arglist = mknull(); pair *p; int i; va_list vl; oop a; if (argc < 3) { wrong_variable_argc(argc, 3); } va_start(vl, f); for (i = (argc - 3) - 1; i >= 0; i--) { p = alloca(sizeof(pair)); a = va_arg(vl, oop); *p = (pair) mkpair(a, mknull()); if (prev == NULL) { arglist = p; } else { prev->cdr = p; } prev = p; } a = va_arg(vl, oop); if (!(ispair(a) || isnil(a))) { wrong_type(argc); } if (prev == NULL) { arglist = a; } else { prev->cdr = a; } va_end(vl); p = alloca(sizeof(pair)); *p = (pair) mkpair(k, arglist); arglist = p; checkedcallfun(f, -1, arglist); }
Value* IntegerValue::lessEqual(Value* operand) { if (operand->getType() == "INTEGER") { IntegerValue* operandValue = dynamic_cast<IntegerValue*> (operand); return new BooleanValue(this->value <= operandValue->value); } else if (operand->getType() == "BOOLEAN") { BooleanValue* operandValue = dynamic_cast<BooleanValue*> (operand); return new BooleanValue(this->value <= operandValue->value); } else if (operand->getType() == "DOUBLE") { DoubleValue* operandValue = dynamic_cast<DoubleValue*> (operand); return new BooleanValue(this->value <= operandValue->value); } throw wrong_type("Right operand of less equal operator has incorrect type " + operand->getType()); }
Value* IntegerValue::divide(Value* operand) { if (operand->getType() == "INTEGER") { IntegerValue* operandValue = dynamic_cast<IntegerValue*> (operand); if (operandValue->value == 0) { throw std::out_of_range("Division by zero in div operator"); } return new DoubleValue(double(this->value) / operandValue->value); } else if (operand->getType() == "DOUBLE") { DoubleValue* operandValue = dynamic_cast<DoubleValue*> (operand); if (operandValue->value == 0) { throw std::out_of_range("Division by zero in div operator"); } return new DoubleValue(this->value / operandValue->value); } throw wrong_type("Right operand of div operator has incorrect type " + operand->getType()); }