Implement To_Host for Nums
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/7bceed1d Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/7bceed1d Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/7bceed1d Branch: refs/heads/master Commit: 7bceed1d72ab4d0a97426a4003066fe42403344b Parents: 7a4aeb9 Author: Nick Wellnhofer <wellnho...@aevum.de> Authored: Fri May 29 12:56:43 2015 +0200 Committer: Nick Wellnhofer <wellnho...@aevum.de> Committed: Fri May 29 17:44:47 2015 +0200 ---------------------------------------------------------------------- runtime/core/Clownfish/Num.cfh | 15 +++++++++ runtime/perl/xs/XSBind.c | 67 +++++++++++++++++++++++++------------ 2 files changed, 61 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/7bceed1d/runtime/core/Clownfish/Num.cfh ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Num.cfh b/runtime/core/Clownfish/Num.cfh index b43d958..781048a 100644 --- a/runtime/core/Clownfish/Num.cfh +++ b/runtime/core/Clownfish/Num.cfh @@ -87,6 +87,9 @@ final class Clownfish::Float32 inherits Clownfish::FloatNum { inert Float32* new(float value); + void* + To_Host(Float32 *self); + void Set_Value(Float32 *self, float value); @@ -121,6 +124,9 @@ final class Clownfish::Float64 inherits Clownfish::FloatNum { inert Float64* new(double value); + void* + To_Host(Float64 *self); + void Set_Value(Float64 *self, double value); @@ -156,6 +162,9 @@ final class Clownfish::Integer32 nickname Int32 inert Integer32* new(int32_t value); + void* + To_Host(Integer32 *self); + void Set_Value(Integer32 *self, int32_t value); @@ -192,6 +201,9 @@ final class Clownfish::Integer64 nickname Int64 inert Integer64* new(int64_t value); + void* + To_Host(Integer64 *self); + void Set_Value(Integer64 *self, int64_t value); @@ -240,6 +252,9 @@ class Clownfish::BoolNum nickname Bool inherits Clownfish::IntNum { public void Destroy(BoolNum *self); + void* + To_Host(BoolNum *self); + bool Get_Value(BoolNum *self); http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/7bceed1d/runtime/perl/xs/XSBind.c ---------------------------------------------------------------------- diff --git a/runtime/perl/xs/XSBind.c b/runtime/perl/xs/XSBind.c index fa571f9..72c4337 100644 --- a/runtime/perl/xs/XSBind.c +++ b/runtime/perl/xs/XSBind.c @@ -19,6 +19,11 @@ #define C_CFISH_OBJ #define C_CFISH_CLASS +#define C_CFISH_FLOAT32 +#define C_CFISH_FLOAT64 +#define C_CFISH_INTEGER32 +#define C_CFISH_INTEGER64 +#define C_CFISH_BOOLNUM #define NEED_newRV_noinc #include "charmony.h" #include "XSBind.h" @@ -160,27 +165,6 @@ XSBind_cfish_to_perl(pTHX_ cfish_Obj *obj) { 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)) { - return newSVnv(CFISH_FloatNum_To_F64((cfish_FloatNum*)obj)); - } - else if (obj == (cfish_Obj*)CFISH_TRUE) { - return newSViv(1); - } - else if (obj == (cfish_Obj*)CFISH_FALSE) { - return newSViv(0); - } - 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)) { - 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)) { - int64_t num = CFISH_Int64_To_I64((cfish_Integer64*)obj); - return newSVnv((double)num); // lossy - } else { return (SV*)CFISH_Obj_To_Host(obj); } @@ -1048,6 +1032,47 @@ cfish_Err_trap(CFISH_Err_Attempt_t routine, void *context) { return error; } +/****************************** Clownfish::Num ******************************/ + +void* +CFISH_Float32_To_Host_IMP(cfish_Float32 *self) { + dTHX; + return newSVnv(self->value); +} + +void* +CFISH_Float64_To_Host_IMP(cfish_Float64 *self) { + dTHX; + return newSVnv(self->value); +} + +void* +CFISH_Int32_To_Host_IMP(cfish_Integer32 *self) { + dTHX; + return newSViv((IV)self->value); +} + +void* +CFISH_Int64_To_Host_IMP(cfish_Integer64 *self) { + dTHX; + SV *sv = NULL; + + if (sizeof(IV) >= 8) { + sv = newSViv((IV)self->value); + } + else { + sv = newSVnv((double)self->value); // lossy + } + + return sv; +} + +void* +CFISH_Bool_To_Host_IMP(cfish_BoolNum *self) { + dTHX; + return newSViv((IV)self->value); +} + /********************* Clownfish::TestHarness::TestUtils ********************/