Make Obj_Is_A inert
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/5bcc19e0 Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/5bcc19e0 Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/5bcc19e0 Branch: refs/heads/master Commit: 5bcc19e06c618535371f4cb363dee676cdbd3855 Parents: b8aa6de Author: Nick Wellnhofer <[email protected]> Authored: Wed May 27 18:34:31 2015 +0200 Committer: Nick Wellnhofer <[email protected]> Committed: Thu May 28 17:43:25 2015 +0200 ---------------------------------------------------------------------- compiler/src/CFCBindClass.c | 9 ++++++++- runtime/core/Clownfish/Blob.c | 2 +- runtime/core/Clownfish/ByteBuf.c | 2 +- runtime/core/Clownfish/CharBuf.c | 6 +++--- runtime/core/Clownfish/Hash.c | 2 +- runtime/core/Clownfish/Num.c | 8 ++++---- runtime/core/Clownfish/Obj.c | 2 +- runtime/core/Clownfish/Obj.cfh | 4 ++-- runtime/core/Clownfish/String.c | 4 ++-- runtime/core/Clownfish/Test/TestObj.c | 10 +++++----- runtime/core/Clownfish/Vector.c | 2 +- runtime/go/clownfish/clownfish.go | 2 +- runtime/perl/buildlib/Clownfish/Build/Binding.pm | 6 +----- runtime/perl/xs/XSBind.c | 18 +++++++++--------- runtime/ruby/ext/Bind.c | 4 ++-- 15 files changed, 42 insertions(+), 39 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/5bcc19e0/compiler/src/CFCBindClass.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCBindClass.c b/compiler/src/CFCBindClass.c index 661ff60..58b7024 100644 --- a/compiler/src/CFCBindClass.c +++ b/compiler/src/CFCBindClass.c @@ -669,10 +669,16 @@ S_wrapper_defs(CFCBindClass *self) { "static CFISH_INLINE cfish_String*\n" "%s%s_get_class_name(%s *self) {\n" " return cfish_Obj_get_class_name((cfish_Obj*)self);\n" + "}\n" + "\n" + "static CFISH_INLINE bool\n" + "%s%s_is_a(%s *self, cfish_Class *ancestor) {\n" + " return cfish_Obj_is_a((cfish_Obj*)self, ancestor);\n" "}\n"; return CFCUtil_sprintf(pattern, prefix, nickname, struct_sym, + prefix, nickname, struct_sym, prefix, nickname, struct_sym); } @@ -777,7 +783,8 @@ S_short_names(CFCBindClass *self) { if (strcmp(CFCClass_get_name(client), "Clownfish::Obj") != 0) { static const char *wrapped_funcs[] = { "get_class", - "get_class_name" + "get_class_name", + "is_a" }; static int num_wrapped_funcs = sizeof(wrapped_funcs) / sizeof(wrapped_funcs[0]); http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/5bcc19e0/runtime/core/Clownfish/Blob.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Blob.c b/runtime/core/Clownfish/Blob.c index d013399..0766396 100644 --- a/runtime/core/Clownfish/Blob.c +++ b/runtime/core/Clownfish/Blob.c @@ -103,7 +103,7 @@ bool Blob_Equals_IMP(Blob *self, Obj *other) { Blob *const twin = (Blob*)other; if (twin == self) { return true; } - if (!Obj_Is_A(other, BLOB)) { return false; } + if (!Obj_is_a(other, BLOB)) { return false; } return SI_equals_bytes(self, twin->buf, twin->size); } http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/5bcc19e0/runtime/core/Clownfish/ByteBuf.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/ByteBuf.c b/runtime/core/Clownfish/ByteBuf.c index d7439f5..f32fa2c 100644 --- a/runtime/core/Clownfish/ByteBuf.c +++ b/runtime/core/Clownfish/ByteBuf.c @@ -116,7 +116,7 @@ bool BB_Equals_IMP(ByteBuf *self, Obj *other) { ByteBuf *const twin = (ByteBuf*)other; if (twin == self) { return true; } - if (!Obj_Is_A(other, BYTEBUF)) { return false; } + if (!Obj_is_a(other, BYTEBUF)) { return false; } return SI_equals_bytes(self, twin->buf, twin->size); } http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/5bcc19e0/runtime/core/Clownfish/CharBuf.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/CharBuf.c b/runtime/core/Clownfish/CharBuf.c index 089390f..e5e3aa2 100644 --- a/runtime/core/Clownfish/CharBuf.c +++ b/runtime/core/Clownfish/CharBuf.c @@ -182,7 +182,7 @@ CB_VCatF_IMP(CharBuf *self, const char *pattern, va_list args) { if (!obj) { CB_Cat_Trusted_Utf8(self, "[NULL]", 6); } - else if (Obj_Is_A(obj, STRING)) { + else if (Obj_is_a(obj, STRING)) { CB_Cat(self, (String*)obj); } else { @@ -341,12 +341,12 @@ void CB_Mimic_IMP(CharBuf *self, Obj *other) { const char *ptr; size_t size; - if (Obj_Is_A(other, CHARBUF)) { + if (Obj_is_a(other, CHARBUF)) { CharBuf *twin = (CharBuf*)other; ptr = twin->ptr; size = twin->size; } - else if (Obj_Is_A(other, STRING)) { + else if (Obj_is_a(other, STRING)) { String *twin = (String*)other; ptr = twin->ptr; size = twin->size; http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/5bcc19e0/runtime/core/Clownfish/Hash.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Hash.c b/runtime/core/Clownfish/Hash.c index 90e8959..54a4c26 100644 --- a/runtime/core/Clownfish/Hash.c +++ b/runtime/core/Clownfish/Hash.c @@ -262,7 +262,7 @@ Hash_Equals_IMP(Hash *self, Obj *other) { Hash *twin = (Hash*)other; if (twin == self) { return true; } - if (!Obj_Is_A(other, HASH)) { return false; } + if (!Obj_is_a(other, HASH)) { return false; } if (self->size != twin->size) { return false; } HashEntry *entry = (HashEntry*)self->entries; http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/5bcc19e0/runtime/core/Clownfish/Num.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Num.c b/runtime/core/Clownfish/Num.c index aeb9429..d13c242 100644 --- a/runtime/core/Clownfish/Num.c +++ b/runtime/core/Clownfish/Num.c @@ -41,7 +41,7 @@ bool Num_Equals_IMP(Num *self, Obj *other) { Num *twin = (Num*)other; if (twin == self) { return true; } - if (!Obj_Is_A(other, NUM)) { return false; } + if (!Obj_is_a(other, NUM)) { return false; } if (Num_To_F64(self) != Num_To_F64(twin)) { return false; } if (Num_To_I64(self) != Num_To_I64(twin)) { return false; } return true; @@ -84,7 +84,7 @@ IntNum_init(IntNum *self) { int32_t IntNum_Compare_To_IMP(IntNum *self, Obj *other) { - if (!Obj_Is_A(other, INTNUM)) { + if (!Obj_is_a(other, INTNUM)) { return -Obj_Compare_To(other, (Obj*)self); } int64_t self_value = IntNum_To_I64(self); @@ -283,8 +283,8 @@ bool Int64_Equals_IMP(Integer64 *self, Obj *other) { Num *twin = (Num*)other; if (twin == (Num*)self) { return true; } - if (!Obj_Is_A(other, NUM)) { return false; } - if (Num_Is_A(twin, FLOATNUM)) { + if (!Obj_is_a(other, NUM)) { return false; } + if (Obj_is_a(other, FLOATNUM)) { double floating_val = Num_To_F64(twin); int64_t int_val = (int64_t)floating_val; if ((double)int_val != floating_val) { return false; } http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/5bcc19e0/runtime/core/Clownfish/Obj.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Obj.c b/runtime/core/Clownfish/Obj.c index a1196f8..888ebf4 100644 --- a/runtime/core/Clownfish/Obj.c +++ b/runtime/core/Clownfish/Obj.c @@ -43,7 +43,7 @@ Obj_Destroy_IMP(Obj *self) { } bool -Obj_Is_A_IMP(Obj *self, Class *ancestor) { +Obj_is_a(Obj *self, Class *ancestor) { Class *klass = self ? self->klass : NULL; while (klass != NULL) { http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/5bcc19e0/runtime/core/Clownfish/Obj.cfh ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Obj.cfh b/runtime/core/Clownfish/Obj.cfh index 7f4074b..e212ad5 100644 --- a/runtime/core/Clownfish/Obj.cfh +++ b/runtime/core/Clownfish/Obj.cfh @@ -75,8 +75,8 @@ public abstract class Clownfish::Obj { /** Indicate whether the object is a descendent of `ancestor`. */ - public bool - Is_A(Obj *self, Class *ancestor); + public inert bool + is_a(Obj *self, Class *ancestor); /** Generic stringification: "ClassName@hex_mem_address". */ http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/5bcc19e0/runtime/core/Clownfish/String.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/String.c b/runtime/core/Clownfish/String.c index 382ef6c..a1ac875 100644 --- a/runtime/core/Clownfish/String.c +++ b/runtime/core/Clownfish/String.c @@ -353,7 +353,7 @@ bool Str_Equals_IMP(String *self, Obj *other) { String *const twin = (String*)other; if (twin == self) { return true; } - if (!Obj_Is_A(other, STRING)) { return false; } + if (!Obj_is_a(other, STRING)) { return false; } return Str_Equals_Utf8_IMP(self, twin->ptr, twin->size); } @@ -602,7 +602,7 @@ bool StrIter_Equals_IMP(StringIterator *self, Obj *other) { StringIterator *const twin = (StringIterator*)other; if (twin == self) { return true; } - if (!Obj_Is_A(other, STRINGITERATOR)) { return false; } + if (!Obj_is_a(other, STRINGITERATOR)) { return false; } return self->string == twin->string && self->byte_offset == twin->byte_offset; } http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/5bcc19e0/runtime/core/Clownfish/Test/TestObj.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Test/TestObj.c b/runtime/core/Clownfish/Test/TestObj.c index 42c82fa..c0d25ea 100644 --- a/runtime/core/Clownfish/Test/TestObj.c +++ b/runtime/core/Clownfish/Test/TestObj.c @@ -86,13 +86,13 @@ test_Equals(TestBatchRunner *runner) { } static void -test_Is_A(TestBatchRunner *runner) { +test_is_a(TestBatchRunner *runner) { String *string = Str_new_from_trusted_utf8("", 0); Class *str_class = Str_get_class(string); String *class_name = Str_get_class_name(string); - TEST_TRUE(runner, Str_Is_A(string, STRING), "String Is_A String."); - TEST_TRUE(runner, Str_Is_A(string, OBJ), "String Is_A Obj."); + TEST_TRUE(runner, Str_is_a(string, STRING), "String is_a String."); + TEST_TRUE(runner, Str_is_a(string, OBJ), "String is_a Obj."); TEST_TRUE(runner, str_class == STRING, "get_class"); TEST_TRUE(runner, Str_Equals(Class_Get_Name(STRING), (Obj*)class_name), "get_class_name"); @@ -122,7 +122,7 @@ S_verify_abstract_error(TestBatchRunner *runner, Err_Attempt_t routine, sprintf(message, "%s() is abstract", name); Err *error = Err_trap(routine, context); TEST_TRUE(runner, error != NULL - && Err_Is_A(error, ERR) + && Err_is_a(error, ERR) && Str_Find_Utf8(Err_Get_Mess(error), "bstract", 7) != -1, message); DECREF(error); @@ -145,7 +145,7 @@ TestObj_Run_IMP(TestObj *self, TestBatchRunner *runner) { test_refcounts(runner); test_To_String(runner); test_Equals(runner); - test_Is_A(runner); + test_is_a(runner); test_abstract_routines(runner); } http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/5bcc19e0/runtime/core/Clownfish/Vector.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Vector.c b/runtime/core/Clownfish/Vector.c index 1fa775c..3f72eea 100644 --- a/runtime/core/Clownfish/Vector.c +++ b/runtime/core/Clownfish/Vector.c @@ -256,7 +256,7 @@ bool Vec_Equals_IMP(Vector *self, Obj *other) { Vector *twin = (Vector*)other; if (twin == self) { return true; } - if (!Obj_Is_A(other, VECTOR)) { return false; } + if (!Obj_is_a(other, VECTOR)) { return false; } if (twin->size != self->size) { return false; } http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/5bcc19e0/runtime/go/clownfish/clownfish.go ---------------------------------------------------------------------- diff --git a/runtime/go/clownfish/clownfish.go b/runtime/go/clownfish/clownfish.go index 143c7c6..fa239f0 100644 --- a/runtime/go/clownfish/clownfish.go +++ b/runtime/go/clownfish/clownfish.go @@ -97,7 +97,7 @@ func CFStringToGo(ptr unsafe.Pointer) string { if cfString == nil { return "" } - if !C.CFISH_Str_Is_A(cfString, C.CFISH_STRING) { + if !C.cfish_Str_is_a(cfString, C.CFISH_STRING) { cfString := C.CFISH_Str_To_String(cfString) defer C.cfish_dec_refcount(unsafe.Pointer(cfString)) } http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/5bcc19e0/runtime/perl/buildlib/Clownfish/Build/Binding.pm ---------------------------------------------------------------------- diff --git a/runtime/perl/buildlib/Clownfish/Build/Binding.pm b/runtime/perl/buildlib/Clownfish/Build/Binding.pm index aa9ca76..8097d6b 100644 --- a/runtime/perl/buildlib/Clownfish/Build/Binding.pm +++ b/runtime/perl/buildlib/Clownfish/Build/Binding.pm @@ -392,9 +392,6 @@ sub bind_obj { To_String Equals ); - my @hand_rolled = qw( - Is_A - ); my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new; my $synopsis = <<'END_SYNOPSIS'; @@ -509,7 +506,7 @@ is_a(self, class_name) CODE: { cfish_Class *target = cfish_Class_fetch_class(class_name); - RETVAL = CFISH_Obj_Is_A(self, target); + RETVAL = cfish_Obj_is_a(self, target); } OUTPUT: RETVAL END_XS_CODE @@ -522,7 +519,6 @@ END_XS_CODE alias => 'DESTROY', method => 'Destroy', ); - $binding->exclude_method($_) for @hand_rolled; $binding->append_xs($xs_code); $binding->set_pod_spec($pod_spec); http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/5bcc19e0/runtime/perl/xs/XSBind.c ---------------------------------------------------------------------- diff --git a/runtime/perl/xs/XSBind.c b/runtime/perl/xs/XSBind.c index eca8145..ab2d8ae 100644 --- a/runtime/perl/xs/XSBind.c +++ b/runtime/perl/xs/XSBind.c @@ -145,22 +145,22 @@ XSBind_cfish_to_perl(pTHX_ cfish_Obj *obj) { if (obj == NULL) { return newSV(0); } - else if (CFISH_Obj_Is_A(obj, CFISH_STRING)) { + else if (cfish_Obj_is_a(obj, CFISH_STRING)) { return XSBind_str_to_sv(aTHX_ (cfish_String*)obj); } - else if (CFISH_Obj_Is_A(obj, CFISH_BLOB)) { + else if (cfish_Obj_is_a(obj, CFISH_BLOB)) { return XSBind_blob_to_sv(aTHX_ (cfish_Blob*)obj); } - else if (CFISH_Obj_Is_A(obj, CFISH_BYTEBUF)) { + else if (cfish_Obj_is_a(obj, CFISH_BYTEBUF)) { return XSBind_bb_to_sv(aTHX_ (cfish_ByteBuf*)obj); } - else if (CFISH_Obj_Is_A(obj, CFISH_VECTOR)) { + else if (cfish_Obj_is_a(obj, CFISH_VECTOR)) { return S_cfish_array_to_perl_array(aTHX_ (cfish_Vector*)obj); } - else if (CFISH_Obj_Is_A(obj, CFISH_HASH)) { + else if (cfish_Obj_is_a(obj, CFISH_HASH)) { return S_cfish_hash_to_perl_hash(aTHX_ (cfish_Hash*)obj); } - else if (CFISH_Obj_Is_A(obj, CFISH_FLOATNUM)) { + else if (cfish_Obj_is_a(obj, CFISH_FLOATNUM)) { return newSVnv(CFISH_FloatNum_To_F64((cfish_FloatNum*)obj)); } else if (obj == (cfish_Obj*)CFISH_TRUE) { @@ -169,15 +169,15 @@ XSBind_cfish_to_perl(pTHX_ cfish_Obj *obj) { else if (obj == (cfish_Obj*)CFISH_FALSE) { return newSViv(0); } - else if (sizeof(IV) == 8 && CFISH_Obj_Is_A(obj, CFISH_INTNUM)) { + else if (sizeof(IV) == 8 && cfish_Obj_is_a(obj, CFISH_INTNUM)) { int64_t num = CFISH_IntNum_To_I64((cfish_IntNum*)obj); return newSViv((IV)num); } - else if (sizeof(IV) == 4 && CFISH_Obj_Is_A(obj, CFISH_INTEGER32)) { + else if (sizeof(IV) == 4 && cfish_Obj_is_a(obj, CFISH_INTEGER32)) { int32_t num = (int32_t)CFISH_Int32_To_I64((cfish_Integer32*)obj); return newSViv((IV)num); } - else if (sizeof(IV) == 4 && CFISH_Obj_Is_A(obj, CFISH_INTEGER64)) { + else if (sizeof(IV) == 4 && cfish_Obj_is_a(obj, CFISH_INTEGER64)) { int64_t num = CFISH_Int64_To_I64((cfish_Integer64*)obj); return newSVnv((double)num); // lossy } http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/5bcc19e0/runtime/ruby/ext/Bind.c ---------------------------------------------------------------------- diff --git a/runtime/ruby/ext/Bind.c b/runtime/ruby/ext/Bind.c index fa8a130..a12b1e1 100644 --- a/runtime/ruby/ext/Bind.c +++ b/runtime/ruby/ext/Bind.c @@ -20,10 +20,10 @@ VALUE Bind_cfish_to_ruby(cfish_Obj *obj) { - if (CFISH_Obj_Is_A(obj, CFISH_STRING)) { + if (cfish_Obj_is_a(obj, CFISH_STRING)) { return Bind_str_to_ruby((cfish_String*)obj); } - else if (CFISH_Obj_Is_A(obj, CFISH_VECTOR)) { + else if (cfish_Obj_is_a(obj, CFISH_VECTOR)) { return S_cfish_array_to_ruby_array((cfish_Vector*)obj); } }
