bool var::ahead::operator()(const var& x, const var& y) const { long r = x.primary() - y.primary(); if (r) return r < 0; switch (x.primary()) { case Primary::Object: { r = reinterpret_cast<long>(x.object().type) - reinterpret_cast<long>(y.object().type); if (r) return r < 0; return x.object().compare(y.object()) < 0; } case Primary::Key: { r = x.key().kind() - y.key().kind(); if (r) return r < 0; return x.key().key < y.key().key; } case Primary::Symbol: return x.ptr < y.ptr; case Primary::Tuple: { r = x.tuple().size - y.tuple().size; if (r) return r < 0; for (uint i = 0; i < x.tuple().size; ++i) if ((*this)(x.tuple()[i], y.tuple()[i])) return true; } return false; } return 0; }
bool var::equal(const var& x) const { if (primary() != x.primary()) return false; switch (primary()) { case Primary::Symbol: return symbol() == x.symbol(); case Primary::Key: return key().key == x.key().key; case Primary::Object: if (object().type != x.object().type) return false; return object().equal(x.object()); case Primary::Tuple: return tuple().equal(x.tuple()); } // Primary::Null return true; }
void to_lua(lua_State* L, const var& x) { switch (x.primary()) { case Primary::Null: lua_pushnil(L); return; case Primary::Symbol: to_lua(L, x.symbol()); return; case Primary::Key: to_lua(L, x.key()); return; case Primary::Object: to_lua(L, x.object()); return; case Primary::Tuple: to_lua(L, x.tuple()); return; } }
long var::compare(const var& x) const { long r = primary() - x.primary(); if (r) return r; switch (primary()) { case Primary::Symbol: return symbol()->compare(x.symbol()); case Primary::Key: return key().compare(x.key()); case Primary::Object: { long r = object().type->compare(x.object().type); if (r) return r; } return object().compare(x.object()); case Primary::Tuple: return tuple().compare(x.tuple()); } return 0; }