>> "hello world"
""hello world""
Amazing how many small bugs one can code.
>> if System.true then 1 else 2
if System.true then 1 else 2
Segmentation fault (core dumped)
>> "hello world"
""hello world""
Amazing how many small bugs one can code.
>> if System.true then 1 else 2
if System.true then 1 else 2
Segmentation fault (core dumped)
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;
}
}
};
class IntegerMinus: public VMObjectCombinator {
public:
IntegerMinus(VM* m):
VMObjectCombinator(VM_OBJECT_FLAG_INTERNAL, m,
"System", "intminus") {
}
IntegerMinus(const IntegerMinus& d)
: IntegerMinus(d.machine()) {
}
VMObjectPtr clone() const {
return VMObjectPtr(new IntegerMinus(*this));
}
VMObjectPtr reduce(const VMObjectPtr& thunk) const override {
auto tt = VM_OBJECT_ARRAY_VALUE(thunk);
auto rt = tt[0];
auto rti = tt[1];
auto k = tt[2];
VMObjectPtr r;
if (tt.size() > 6) {
auto arg0 = tt[5];
auto arg1 = tt[6];
auto i0 = VM_OBJECT_INTEGER_VALUE(arg0);
auto i1 = VM_OBJECT_INTEGER_VALUE(arg1);
auto ir = i0 + i1;
r = VMObjectInteger(ir).clone();
} else {
VMObjectPtrs rr;
for (uint i = 4; i<tt.size(); i++) {
rr.push_back(tt[i]);
}
r = VMObjectArray(rr).clone();
}
auto index = VM_OBJECT_INTEGER_VALUE(rti);
auto rta = VM_OBJECT_ARRAY_CAST(rt);
rta->set(index, r);
return k;
}
};
At the moment I don't feel like copying this code for every operator, can't solve it reasonably with a macro or template (or I don't know how), and don't want to solve it with a general class and a function pointer. I'll wait a day, something will come up.
namespace Test (
def f = [ X, Y -> X ]
def g = [ f X -> f X X ]
)
using Test
def main = g (f 1)
[marco@stallion src]$ ./egel ../tests/match.eg
1