diff options
author | Teddy <[email protected]> | 2013-08-08 12:03:04 +0800 |
---|---|---|
committer | Teddy <[email protected]> | 2013-08-08 12:03:04 +0800 |
commit | f0cf9e4d5cd358c7ac3759b9a1f47f07daf74104 (patch) | |
tree | 1804e66b4dc6473ac8421f2429fff45e7af7885f /builtin.cpp | |
parent | e50e8bff705beed1ecb41ab7b5336b39fc041056 (diff) |
eqv? is implemented
Diffstat (limited to 'builtin.cpp')
-rw-r--r-- | builtin.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/builtin.cpp b/builtin.cpp index 573159a..491d1ae 100644 --- a/builtin.cpp +++ b/builtin.cpp @@ -1211,6 +1211,39 @@ BUILTIN_PROC_DEF(list_tail) { return ptr; } +BUILTIN_PROC_DEF(is_eqv) { + ARGS_EXACTLY_TWO; + EvalObj *obj1 = args->car; + EvalObj *obj2 = TO_CONS(args->cdr)->car; + ClassType otype = obj1->get_otype(); + + if (otype != obj2->get_otype()) return new BoolObj(false); + if (otype & CLS_BOOL_OBJ) + return new BoolObj( + static_cast<BoolObj*>(obj1)->val == + static_cast<BoolObj*>(obj2)->val); + if (otype & CLS_SYM_OBJ) + return new BoolObj( + static_cast<SymObj*>(obj1)->val == + static_cast<SymObj*>(obj2)->val); + if (otype & CLS_NUM_OBJ) + { + NumObj *num1 = static_cast<NumObj*>(obj1); + NumObj *num2 = static_cast<NumObj*>(obj2); + if (num1->is_exact() != num2->is_exact()) + return new BoolObj(false); + if (num1->level < num2->level) + return new BoolObj(num1->eq(num1->convert(num2))); + else + return new BoolObj(num2->eq(num2->convert(num1))); + } + if (otype & CLS_CHAR_OBJ) + return new BoolObj( + static_cast<CharObj*>(obj1)->ch == + static_cast<CharObj*>(obj2)->ch); // (char=?) + return new BoolObj(obj1 == obj2); +} + BUILTIN_PROC_DEF(display) { ARGS_EXACTLY_ONE; printf("%s\n", args->car->ext_repr().c_str()); |