Below, a definition of a dyadic combinator.
class Min: public Dyadic {
public:
DYADIC_PREAMBLE(Min, "System", "min");
VMObjectPtr apply(const VMObjectPtr& arg0,
const VMObjectPtr& arg1) const override {
if ( (arg0->tag() == VM_OBJECT_INTEGER) &&
(arg1->tag() == VM_OBJECT_INTEGER) ) {
auto i0 = VM_OBJECT_INTEGER_VALUE(arg0);
auto i1 = VM_OBJECT_INTEGER_VALUE(arg1);
return VMObjectInteger(i0-i1).clone();
} else if ( (arg0->tag() == VM_OBJECT_FLOAT) &&
(arg1->tag() == VM_OBJECT_FLOAT) ) {
auto f0 = VM_OBJECT_FLOAT_VALUE(arg0);
auto f1 = VM_OBJECT_FLOAT_VALUE(arg1);
return VMObjectFloat(f0-f1).clone();
} else {
return nullptr;
}
}
};
I can't say I am happy about the size of the binary it produces though. I guess it's necessary, but well, it won't run on a PIC.
No comments:
Post a Comment