You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2014/04/12 08:49:41 UTC
[lucy-commits] [06/27] Remove bundled Clownfish.
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/runtime/core/Clownfish/Method.cfh
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/Method.cfh b/clownfish/runtime/core/Clownfish/Method.cfh
deleted file mode 100644
index 4f73384..0000000
--- a/clownfish/runtime/core/Clownfish/Method.cfh
+++ /dev/null
@@ -1,59 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-parcel Clownfish;
-
-/** Method metadata.
- */
-
-class Clownfish::Method inherits Clownfish::Obj {
-
- String *name;
- String *host_alias;
- cfish_method_t callback_func;
- size_t offset;
- bool is_excluded;
-
- inert Method*
- new(String *name, cfish_method_t callback_func, size_t offset);
-
- inert Method*
- init(Method *self, String *name, cfish_method_t callback_func,
- size_t offset);
-
- String*
- Get_Name(Method *self);
-
- nullable String*
- Get_Host_Alias(Method *self);
-
- bool
- Is_Excluded_From_Host(Method *self);
-
- incremented Obj*
- Inc_RefCount(Method *self);
-
- uint32_t
- Dec_RefCount(Method *self);
-
- uint32_t
- Get_RefCount(Method *self);
-
- public void
- Destroy(Method *self);
-}
-
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/runtime/core/Clownfish/Num.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/Num.c b/clownfish/runtime/core/Clownfish/Num.c
deleted file mode 100644
index cf38a86..0000000
--- a/clownfish/runtime/core/Clownfish/Num.c
+++ /dev/null
@@ -1,396 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define C_CFISH_NUM
-#define C_CFISH_INTNUM
-#define C_CFISH_FLOATNUM
-#define C_CFISH_INTEGER32
-#define C_CFISH_INTEGER64
-#define C_CFISH_FLOAT32
-#define C_CFISH_FLOAT64
-#define C_CFISH_BOOLNUM
-#define CFISH_USE_SHORT_NAMES
-#define CHY_USE_SHORT_NAMES
-
-#include "charmony.h"
-
-#include "Clownfish/Num.h"
-#include "Clownfish/String.h"
-#include "Clownfish/Err.h"
-#include "Clownfish/VTable.h"
-
-Num*
-Num_init(Num *self) {
- ABSTRACT_CLASS_CHECK(self, NUM);
- return self;
-}
-
-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 (Num_To_F64(self) != Num_To_F64(twin)) { return false; }
- if (Num_To_I64(self) != Num_To_I64(twin)) { return false; }
- return true;
-}
-
-/***************************************************************************/
-
-FloatNum*
-FloatNum_init(FloatNum *self) {
- ABSTRACT_CLASS_CHECK(self, FLOATNUM);
- return (FloatNum*)Num_init((Num*)self);
-}
-
-int32_t
-FloatNum_Compare_To_IMP(FloatNum *self, Obj *other) {
- Num *twin = (Num*)CERTIFY(other, NUM);
- double f64_diff = FloatNum_To_F64(self) - Num_To_F64(twin);
- if (f64_diff < 0) { return -1; }
- else if (f64_diff > 0) { return 1; }
- return 0;
-}
-
-String*
-FloatNum_To_String_IMP(FloatNum *self) {
- return Str_newf("%f64", FloatNum_To_F64(self));
-}
-
-/***************************************************************************/
-
-IntNum*
-IntNum_init(IntNum *self) {
- ABSTRACT_CLASS_CHECK(self, INTNUM);
- return (IntNum*)Num_init((Num*)self);
-}
-
-int32_t
-IntNum_Compare_To_IMP(IntNum *self, Obj *other) {
- if (!Obj_Is_A(other, INTNUM)) {
- return -Obj_Compare_To(other, (Obj*)self);
- }
- int64_t self_value = IntNum_To_I64(self);
- int64_t other_value = Obj_To_I64(other);
- if (self_value < other_value) { return -1; }
- else if (self_value > other_value) { return 1; }
- return 0;
-}
-
-String*
-IntNum_To_String_IMP(IntNum *self) {
- return Str_newf("%i64", IntNum_To_I64(self));
-}
-
-/***************************************************************************/
-
-Float32*
-Float32_new(float value) {
- Float32 *self = (Float32*)VTable_Make_Obj(FLOAT32);
- return Float32_init(self, value);
-}
-
-Float32*
-Float32_init(Float32 *self, float value) {
- self->value = value;
- return (Float32*)FloatNum_init((FloatNum*)self);
-}
-
-float
-Float32_Get_Value_IMP(Float32 *self) {
- return self->value;
-}
-
-void
-Float32_Set_Value_IMP(Float32 *self, float value) {
- self->value = value;
-}
-
-double
-Float32_To_F64_IMP(Float32 *self) {
- return self->value;
-}
-
-int64_t
-Float32_To_I64_IMP(Float32 *self) {
- return (int64_t)self->value;
-}
-
-int32_t
-Float32_Hash_Sum_IMP(Float32 *self) {
- return *(int32_t*)&self->value;
-}
-
-Float32*
-Float32_Clone_IMP(Float32 *self) {
- return Float32_new(self->value);
-}
-
-void
-Float32_Mimic_IMP(Float32 *self, Obj *other) {
- Float32 *twin = (Float32*)CERTIFY(other, FLOAT32);
- self->value = twin->value;
-}
-
-/***************************************************************************/
-
-Float64*
-Float64_new(double value) {
- Float64 *self = (Float64*)VTable_Make_Obj(FLOAT64);
- return Float64_init(self, value);
-}
-
-Float64*
-Float64_init(Float64 *self, double value) {
- self->value = value;
- return (Float64*)FloatNum_init((FloatNum*)self);
-}
-
-double
-Float64_Get_Value_IMP(Float64 *self) {
- return self->value;
-}
-
-void
-Float64_Set_Value_IMP(Float64 *self, double value) {
- self->value = value;
-}
-
-double
-Float64_To_F64_IMP(Float64 *self) {
- return self->value;
-}
-
-int64_t
-Float64_To_I64_IMP(Float64 *self) {
- return (int64_t)self->value;
-}
-
-Float64*
-Float64_Clone_IMP(Float64 *self) {
- return Float64_new(self->value);
-}
-
-void
-Float64_Mimic_IMP(Float64 *self, Obj *other) {
- Float64 *twin = (Float64*)CERTIFY(other, FLOAT64);
- self->value = twin->value;
-}
-
-int32_t
-Float64_Hash_Sum_IMP(Float64 *self) {
- int32_t *ints = (int32_t*)&self->value;
- return ints[0] ^ ints[1];
-}
-
-/***************************************************************************/
-
-Integer32*
-Int32_new(int32_t value) {
- Integer32 *self = (Integer32*)VTable_Make_Obj(INTEGER32);
- return Int32_init(self, value);
-}
-
-Integer32*
-Int32_init(Integer32 *self, int32_t value) {
- self->value = value;
- return (Integer32*)IntNum_init((IntNum*)self);
-}
-
-int32_t
-Int32_Get_Value_IMP(Integer32 *self) {
- return self->value;
-}
-
-void
-Int32_Set_Value_IMP(Integer32 *self, int32_t value) {
- self->value = value;
-}
-
-double
-Int32_To_F64_IMP(Integer32 *self) {
- return self->value;
-}
-
-int64_t
-Int32_To_I64_IMP(Integer32 *self) {
- return self->value;
-}
-
-Integer32*
-Int32_Clone_IMP(Integer32 *self) {
- return Int32_new(self->value);
-}
-
-void
-Int32_Mimic_IMP(Integer32 *self, Obj *other) {
- Integer32 *twin = (Integer32*)CERTIFY(other, INTEGER32);
- self->value = twin->value;
-}
-
-int32_t
-Int32_Hash_Sum_IMP(Integer32 *self) {
- return self->value;
-}
-
-/***************************************************************************/
-
-Integer64*
-Int64_new(int64_t value) {
- Integer64 *self = (Integer64*)VTable_Make_Obj(INTEGER64);
- return Int64_init(self, value);
-}
-
-Integer64*
-Int64_init(Integer64 *self, int64_t value) {
- self->value = value;
- return (Integer64*)IntNum_init((IntNum*)self);
-}
-
-int64_t
-Int64_Get_Value_IMP(Integer64 *self) {
- return self->value;
-}
-
-void
-Int64_Set_Value_IMP(Integer64 *self, int64_t value) {
- self->value = value;
-}
-
-double
-Int64_To_F64_IMP(Integer64 *self) {
- return (double)self->value;
-}
-
-int64_t
-Int64_To_I64_IMP(Integer64 *self) {
- return self->value;
-}
-
-Integer64*
-Int64_Clone_IMP(Integer64 *self) {
- return Int64_new(self->value);
-}
-
-void
-Int64_Mimic_IMP(Integer64 *self, Obj *other) {
- Integer64 *twin = (Integer64*)CERTIFY(other, INTEGER64);
- self->value = twin->value;
-}
-
-int32_t
-Int64_Hash_Sum_IMP(Integer64 *self) {
- int32_t *ints = (int32_t*)&self->value;
- return ints[0] ^ ints[1];
-}
-
-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)) {
- double floating_val = Num_To_F64(twin);
- int64_t int_val = (int64_t)floating_val;
- if ((double)int_val != floating_val) { return false; }
- if (int_val != self->value) { return false; }
- }
- else {
- if (self->value != Num_To_I64(twin)) { return false; }
- }
- return true;
-}
-
-/***************************************************************************/
-
-
-BoolNum *Bool_true_singleton;
-BoolNum *Bool_false_singleton;
-
-void
-Bool_init_class() {
- Bool_true_singleton = (BoolNum*)VTable_Make_Obj(BOOLNUM);
- Bool_true_singleton->value = true;
- Bool_true_singleton->string = Str_newf("true");
- Bool_false_singleton = (BoolNum*)VTable_Make_Obj(BOOLNUM);
- Bool_false_singleton->value = false;
- Bool_false_singleton->string = Str_newf("false");
-}
-
-BoolNum*
-Bool_singleton(bool value) {
- return value ? CFISH_TRUE : CFISH_FALSE;
-}
-
-void
-Bool_Destroy_IMP(BoolNum *self) {
- if (self && self != CFISH_TRUE && self != CFISH_FALSE) {
- SUPER_DESTROY(self, BOOLNUM);
- }
-}
-
-bool
-Bool_Get_Value_IMP(BoolNum *self) {
- return self->value;
-}
-
-double
-Bool_To_F64_IMP(BoolNum *self) {
- return (double)self->value;
-}
-
-int64_t
-Bool_To_I64_IMP(BoolNum *self) {
- return self->value;
-}
-
-bool
-Bool_To_Bool_IMP(BoolNum *self) {
- return self->value;
-}
-
-BoolNum*
-Bool_Clone_IMP(BoolNum *self) {
- return self;
-}
-
-int32_t
-Bool_Hash_Sum_IMP(BoolNum *self) {
- int64_t hash_sum = PTR_TO_I64(self) + self->value;
- return (int32_t)hash_sum;
-}
-
-String*
-Bool_To_String_IMP(BoolNum *self) {
- return (String*)INCREF(self->string);
-}
-
-bool
-Bool_Equals_IMP(BoolNum *self, Obj *other) {
- return self == (BoolNum*)other;
-}
-
-BoolNum*
-Bool_Inc_RefCount_IMP(BoolNum *self) {
- return self;
-}
-
-uint32_t
-Bool_Dec_RefCount_IMP(BoolNum *self) {
- UNUSED_VAR(self);
- return 1;
-}
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/runtime/core/Clownfish/Num.cfh
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/Num.cfh b/clownfish/runtime/core/Clownfish/Num.cfh
deleted file mode 100644
index 56983ce..0000000
--- a/clownfish/runtime/core/Clownfish/Num.cfh
+++ /dev/null
@@ -1,277 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-parcel Clownfish;
-
-/** Abstract base class for numbers.
- */
-abstract class Clownfish::Num inherits Clownfish::Obj {
-
- inert Num*
- init(Num *self);
-
- public bool
- Equals(Num *self, Obj *other);
-}
-
-/** Abstract base class for floating point numbers.
- */
-abstract class Clownfish::FloatNum inherits Clownfish::Num {
-
- inert FloatNum*
- init(FloatNum *self);
-
- public int32_t
- Compare_To(FloatNum *self, Obj *other);
-
- public incremented String*
- To_String(FloatNum *self);
-}
-
-
-/** Abstract base class for Integers.
- */
-abstract class Clownfish::IntNum inherits Clownfish::Num {
-
- inert IntNum*
- init(IntNum *self);
-
- public int32_t
- Compare_To(IntNum *self, Obj *other);
-
- public incremented String*
- To_String(IntNum *self);
-}
-
-/** Single precision floating point number.
- */
-class Clownfish::Float32 inherits Clownfish::FloatNum {
-
- float value;
-
- /**
- * @param value Initial value.
- */
- inert Float32*
- init(Float32* self, float value);
-
- inert Float32*
- new(float value);
-
- void
- Set_Value(Float32 *self, float value);
-
- float
- Get_Value(Float32 *self);
-
- public int64_t
- To_I64(Float32 *self);
-
- public double
- To_F64(Float32 *self);
-
- public int32_t
- Hash_Sum(Float32 *self);
-
- public incremented Float32*
- Clone(Float32 *self);
-
- public void
- Mimic(Float32 *self, Obj *other);
-}
-
-/** Double precision floating point number.
- */
-class Clownfish::Float64 inherits Clownfish::FloatNum {
-
- double value;
-
- /**
- * @param value Initial value.
- */
- inert Float64*
- init(Float64* self, double value);
-
- inert Float64*
- new(double value);
-
- void
- Set_Value(Float64 *self, double value);
-
- double
- Get_Value(Float64 *self);
-
- public int64_t
- To_I64(Float64 *self);
-
- public double
- To_F64(Float64 *self);
-
- public int32_t
- Hash_Sum(Float64 *self);
-
- public incremented Float64*
- Clone(Float64 *self);
-
- public void
- Mimic(Float64 *self, Obj *other);
-}
-
-/** 32-bit signed integer.
- */
-class Clownfish::Integer32 cnick Int32
- inherits Clownfish::IntNum {
-
- int32_t value;
-
- /**
- * @param value Initial value.
- */
- inert Integer32*
- init(Integer32* self, int32_t value);
-
- inert Integer32*
- new(int32_t value);
-
- void
- Set_Value(Integer32 *self, int32_t value);
-
- int32_t
- Get_Value(Integer32 *self);
-
- public int64_t
- To_I64(Integer32 *self);
-
- public double
- To_F64(Integer32 *self);
-
- public int32_t
- Hash_Sum(Integer32 *self);
-
- public incremented Integer32*
- Clone(Integer32 *self);
-
- public void
- Mimic(Integer32 *self, Obj *other);
-}
-
-/**
- * 64-bit signed integer.
- */
-class Clownfish::Integer64 cnick Int64
- inherits Clownfish::IntNum {
-
- int64_t value;
-
- /**
- * @param value Initial value.
- */
- inert Integer64*
- init(Integer64* self, int64_t value);
-
- inert Integer64*
- new(int64_t value);
-
- void
- Set_Value(Integer64 *self, int64_t value);
-
- int64_t
- Get_Value(Integer64 *self);
-
- public int64_t
- To_I64(Integer64 *self);
-
- public double
- To_F64(Integer64 *self);
-
- public int32_t
- Hash_Sum(Integer64 *self);
-
- public bool
- Equals(Integer64 *self, Obj *other);
-
- public incremented Integer64*
- Clone(Integer64 *self);
-
- public void
- Mimic(Integer64 *self, Obj *other);
-}
-
-
-/**
- * Boolean type.
- *
- * There are only two singleton instances of this class: CFISH_TRUE and
- * CFISH_FALSE.
- */
-class Clownfish::BoolNum cnick Bool inherits Clownfish::IntNum {
- bool value;
- String *string;
-
- inert BoolNum *true_singleton;
- inert BoolNum *false_singleton;
-
- inert void
- init_class();
-
- /** Return either CFISH_TRUE or CFISH_FALSE depending on the supplied
- * value.
- */
- inert BoolNum*
- singleton(bool value);
-
- public void
- Destroy(BoolNum *self);
-
- bool
- Get_Value(BoolNum *self);
-
- public int64_t
- To_I64(BoolNum *self);
-
- public double
- To_F64(BoolNum *self);
-
- public bool
- To_Bool(BoolNum *self);
-
- public int32_t
- Hash_Sum(BoolNum *self);
-
- /* Returns self. */
- public incremented BoolNum*
- Clone(BoolNum *self);
-
- public bool
- Equals(BoolNum *self, Obj *other);
-
- public incremented String*
- To_String(BoolNum *self);
-
- incremented BoolNum*
- Inc_RefCount(BoolNum *self);
-
- uint32_t
- Dec_RefCount(BoolNum *self);
-}
-
-__C__
-
-#define CFISH_TRUE cfish_Bool_true_singleton
-#define CFISH_FALSE cfish_Bool_false_singleton
-
-__END_C__
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/runtime/core/Clownfish/Obj.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/Obj.c b/clownfish/runtime/core/Clownfish/Obj.c
deleted file mode 100644
index d76ea19..0000000
--- a/clownfish/runtime/core/Clownfish/Obj.c
+++ /dev/null
@@ -1,102 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define C_CFISH_OBJ
-#define C_CFISH_VTABLE
-#define CFISH_USE_SHORT_NAMES
-#define CHY_USE_SHORT_NAMES
-
-#include "charmony.h"
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "Clownfish/Obj.h"
-#include "Clownfish/String.h"
-#include "Clownfish/Err.h"
-#include "Clownfish/Hash.h"
-#include "Clownfish/VTable.h"
-#include "Clownfish/Util/Memory.h"
-
-Obj*
-Obj_init(Obj *self) {
- ABSTRACT_CLASS_CHECK(self, OBJ);
- return self;
-}
-
-void
-Obj_Destroy_IMP(Obj *self) {
- FREEMEM(self);
-}
-
-int32_t
-Obj_Hash_Sum_IMP(Obj *self) {
- int64_t hash_sum = PTR_TO_I64(self);
- return (int32_t)hash_sum;
-}
-
-bool
-Obj_Is_A_IMP(Obj *self, VTable *ancestor) {
- VTable *vtable = self ? self->vtable : NULL;
-
- while (vtable != NULL) {
- if (vtable == ancestor) {
- return true;
- }
- vtable = vtable->parent;
- }
-
- return false;
-}
-
-bool
-Obj_Equals_IMP(Obj *self, Obj *other) {
- return (self == other);
-}
-
-String*
-Obj_To_String_IMP(Obj *self) {
-#if (SIZEOF_PTR == 4)
- return Str_newf("%o@0x%x32", Obj_Get_Class_Name(self), self);
-#elif (SIZEOF_PTR == 8)
- int64_t iaddress = PTR_TO_I64(self);
- uint64_t address = (uint64_t)iaddress;
- uint32_t address_hi = address >> 32;
- uint32_t address_lo = address & 0xFFFFFFFF;
- return Str_newf("%o@0x%x32%x32", Obj_Get_Class_Name(self), address_hi,
- address_lo);
-#else
- #error "Unexpected pointer size."
-#endif
-}
-
-bool
-Obj_To_Bool_IMP(Obj *self) {
- return !!Obj_To_I64(self);
-}
-
-VTable*
-Obj_Get_VTable_IMP(Obj *self) {
- return self->vtable;
-}
-
-String*
-Obj_Get_Class_Name_IMP(Obj *self) {
- return VTable_Get_Name(self->vtable);
-}
-
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/runtime/core/Clownfish/Obj.cfh
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/Obj.cfh b/clownfish/runtime/core/Clownfish/Obj.cfh
deleted file mode 100644
index fafccfc..0000000
--- a/clownfish/runtime/core/Clownfish/Obj.cfh
+++ /dev/null
@@ -1,192 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-parcel Clownfish;
-
-/** Base class for all objects.
- */
-
-public class Clownfish::Obj {
-
- VTable *vtable;
-
- /** Abstract initializer.
- */
- public inert Obj*
- init(Obj* self);
-
- /** Return an object's refcount.
- */
- uint32_t
- Get_RefCount(Obj *self);
-
- /** Increment an object's refcount.
- *
- * @return The object, allowing an assignment idiom.
- */
- incremented Obj*
- Inc_RefCount(Obj *self);
-
- /** NULL-safe invocation of Inc_RefCount().
- *
- * @return NULL if <code>self</code> is NULL, otherwise the return value
- * of Inc_RefCount().
- */
- inert inline incremented Obj*
- incref(Obj *self);
-
- /** Decrement an object's refcount, calling Destroy() if it hits 0.
- *
- * @return the modified refcount.
- */
- uint32_t
- Dec_RefCount(Obj *self);
-
- /** NULL-safe invocation of Dec_RefCount().
- *
- * @return NULL if <code>self</code> is NULL, otherwise the return value
- * of Dec_RefCount().
- */
- inert inline uint32_t
- decref(Obj *self);
-
- /** Return a host-language object wrapper for this object.
- */
- void*
- To_Host(Obj *self);
-
- /** Return a clone of the object.
- */
- public abstract incremented Obj*
- Clone(Obj *self);
-
- /** Generic destructor. Frees the struct itself but not any complex
- * member elements.
- */
- public void
- Destroy(Obj *self);
-
- /** Invoke the Destroy() method found in <code>vtable</code> on
- * <code>self</code>.
- *
- * TODO: Eliminate this function if we can arrive at a proper SUPER syntax.
- */
- inert inline void
- super_destroy(Obj *self, VTable *vtable);
-
- /** Indicate whether two objects are the same. By default, compares the
- * memory address.
- *
- * @param other Another Obj.
- */
- public bool
- Equals(Obj *self, Obj *other);
-
- /** Indicate whether one object is less than, equal to, or greater than
- * another.
- *
- * @param other Another Obj.
- * @return 0 if the objects are equal, a negative number if
- * <code>self</code> is less than <code>other</code>, and a positive
- * number if <code>self</code> is greater than <code>other</code>.
- */
- public abstract int32_t
- Compare_To(Obj *self, Obj *other);
-
- /** Return a hash code for the object -- by default, the memory address.
- */
- public int32_t
- Hash_Sum(Obj *self);
-
- /** Return the object's VTable.
- */
- public VTable*
- Get_VTable(Obj *self);
-
- /** Return the name of the class that the object belongs to.
- */
- public String*
- Get_Class_Name(Obj *self);
-
- /** Indicate whether the object is a descendent of <code>ancestor</code>.
- */
- public bool
- Is_A(Obj *self, VTable *ancestor);
-
- /** Generic stringification: "ClassName@hex_mem_address".
- */
- public incremented String*
- To_String(Obj *self);
-
- /** Convert the object to a 64-bit integer.
- */
- public abstract int64_t
- To_I64(Obj *self);
-
- /** Convert the object to a double precision floating point number.
- */
- public abstract double
- To_F64(Obj *self);
-
- /** Evaluate the object in a boolean context. By default, invokes
- * To_I64() and returns true if it is non-zero.
- */
- public bool
- To_Bool(Obj *self);
-
- /** Update the internal state of the object to mimic that of
- * <code>other</code>.
- */
- public abstract void
- Mimic(Obj *self, Obj *other);
-}
-
-__C__
-static CFISH_INLINE void
-cfish_Obj_super_destroy(cfish_Obj *self, cfish_VTable *vtable) {
- CFISH_Obj_Destroy_t super_destroy
- = CFISH_SUPER_METHOD_PTR(vtable, CFISH_Obj_Destroy);
- super_destroy(self);
-}
-
-#define CFISH_SUPER_DESTROY(_self, _vtable) \
- cfish_Obj_super_destroy((cfish_Obj*)_self, _vtable)
-
-static CFISH_INLINE cfish_Obj*
-cfish_Obj_incref(cfish_Obj *self) {
- if (self != NULL) { return CFISH_Obj_Inc_RefCount(self); }
- else { return NULL; }
-}
-
-#define CFISH_INCREF(_self) cfish_Obj_incref((cfish_Obj*)_self)
-
-static CFISH_INLINE uint32_t
-cfish_Obj_decref(cfish_Obj *self) {
- if (self != NULL) { return CFISH_Obj_Dec_RefCount(self); }
- else { return 0; }
-}
-
-#define CFISH_DECREF(_self) cfish_Obj_decref((cfish_Obj*)_self)
-
-#ifdef CFISH_USE_SHORT_NAMES
- #define SUPER_DESTROY(_self, _vtable) CFISH_SUPER_DESTROY(_self, _vtable)
- #define INCREF(_self) CFISH_INCREF(_self)
- #define DECREF(_self) CFISH_DECREF(_self)
-#endif
-
-__END_C__
-
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/runtime/core/Clownfish/String.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/String.c b/clownfish/runtime/core/Clownfish/String.c
deleted file mode 100644
index 9f691ad..0000000
--- a/clownfish/runtime/core/Clownfish/String.c
+++ /dev/null
@@ -1,921 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define C_CFISH_STRING
-#define C_CFISH_STACKSTRING
-#define C_CFISH_STRINGITERATOR
-#define C_CFISH_STACKSTRINGITERATOR
-#define CFISH_USE_SHORT_NAMES
-#define CHY_USE_SHORT_NAMES
-
-#include "charmony.h"
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <ctype.h>
-
-#include "Clownfish/VTable.h"
-#include "Clownfish/String.h"
-
-#include "Clownfish/CharBuf.h"
-#include "Clownfish/Err.h"
-#include "Clownfish/Util/Memory.h"
-#include "Clownfish/Util/StringHelper.h"
-
-#define STR_STACKTOP(string) \
- Str_StackTop(string, alloca(sizeof(StackStringIterator)))
-#define STR_STACKTAIL(string) \
- Str_StackTail(string, alloca(sizeof(StackStringIterator)))
-
-// Helper function for throwing invalid UTF-8 error. Since THROW uses
-// a String internally, calling THROW with invalid UTF-8 would create an
-// infinite loop -- so we fwrite some of the bogus text to stderr and
-// invoke THROW with a generic message.
-#define DIE_INVALID_UTF8(text, size) \
- S_die_invalid_utf8(text, size, __FILE__, __LINE__, CFISH_ERR_FUNC_MACRO)
-static void
-S_die_invalid_utf8(const char *text, size_t size, const char *file, int line,
- const char *func);
-
-String*
-Str_new_from_utf8(const char *utf8, size_t size) {
- if (!StrHelp_utf8_valid(utf8, size)) {
- DIE_INVALID_UTF8(utf8, size);
- }
- String *self = (String*)VTable_Make_Obj(STRING);
- return Str_init_from_trusted_utf8(self, utf8, size);
-}
-
-String*
-Str_new_from_trusted_utf8(const char *utf8, size_t size) {
- String *self = (String*)VTable_Make_Obj(STRING);
- return Str_init_from_trusted_utf8(self, utf8, size);
-}
-
-String*
-Str_init_from_trusted_utf8(String *self, const char *utf8, size_t size) {
- // Allocate.
- char *ptr = (char*)MALLOCATE(size + 1);
-
- // Copy.
- memcpy(ptr, utf8, size);
- ptr[size] = '\0'; // Null terminate.
-
- // Assign.
- self->ptr = ptr;
- self->size = size;
- self->origin = self;
-
- return self;
-}
-
-String*
-Str_new_steal_utf8(char *utf8, size_t size) {
- if (!StrHelp_utf8_valid(utf8, size)) {
- DIE_INVALID_UTF8(utf8, size);
- }
- String *self = (String*)VTable_Make_Obj(STRING);
- return Str_init_steal_trusted_utf8(self, utf8, size);
-}
-
-String*
-Str_new_steal_trusted_utf8(char *utf8, size_t size) {
- String *self = (String*)VTable_Make_Obj(STRING);
- return Str_init_steal_trusted_utf8(self, utf8, size);
-}
-
-String*
-Str_init_steal_trusted_utf8(String *self, char *utf8, size_t size) {
- self->ptr = utf8;
- self->size = size;
- self->origin = self;
- return self;
-}
-
-String*
-Str_new_wrap_utf8(const char *utf8, size_t size) {
- if (!StrHelp_utf8_valid(utf8, size)) {
- DIE_INVALID_UTF8(utf8, size);
- }
- String *self = (String*)VTable_Make_Obj(STRING);
- return Str_init_wrap_trusted_utf8(self, utf8, size);
-}
-
-String*
-Str_new_wrap_trusted_utf8(const char *utf8, size_t size) {
- String *self = (String*)VTable_Make_Obj(STRING);
- return Str_init_wrap_trusted_utf8(self, utf8, size);
-}
-
-String*
-Str_init_wrap_trusted_utf8(String *self, const char *ptr, size_t size) {
- self->ptr = ptr;
- self->size = size;
- self->origin = NULL;
- return self;
-}
-
-String*
-Str_new_from_char(int32_t code_point) {
- const size_t MAX_UTF8_BYTES = 4;
- char *ptr = (char*)MALLOCATE(MAX_UTF8_BYTES + 1);
- size_t size = StrHelp_encode_utf8_char(code_point, (uint8_t*)ptr);
- ptr[size] = '\0';
-
- String *self = (String*)VTable_Make_Obj(STRING);
- self->ptr = ptr;
- self->size = size;
- self->origin = self;
- return self;
-}
-
-String*
-Str_newf(const char *pattern, ...) {
- CharBuf *buf = CB_new(strlen(pattern));
- va_list args;
- va_start(args, pattern);
- CB_VCatF(buf, pattern, args);
- va_end(args);
- String *self = CB_Yield_String(buf);
- DECREF(buf);
- return self;
-}
-
-static String*
-S_new_substring(String *string, size_t byte_offset, size_t size) {
- String *self = (String*)VTable_Make_Obj(STRING);
-
- if (string->origin == NULL) {
- // Copy substring of wrapped strings.
- Str_init_from_trusted_utf8(self, string->ptr + byte_offset, size);
- }
- else {
- self->ptr = string->ptr + byte_offset;
- self->size = size;
- self->origin = (String*)INCREF(string->origin);
- }
-
- return self;
-}
-
-Obj*
-Str_Inc_RefCount_IMP(String *self) {
- if (self->origin == NULL) {
- // Copy wrapped strings when the refcount is increased.
- String *copy = (String*)VTable_Make_Obj(STRING);
- return (Obj*)Str_init_from_trusted_utf8(copy, self->ptr, self->size);
- }
- else {
- Str_Inc_RefCount_t super_incref
- = SUPER_METHOD_PTR(STRING, CFISH_Str_Inc_RefCount);
- return super_incref(self);
- }
-}
-
-void
-Str_Destroy_IMP(String *self) {
- if (self->origin == self) {
- FREEMEM((char*)self->ptr);
- }
- else {
- DECREF(self->origin);
- }
- SUPER_DESTROY(self, STRING);
-}
-
-int32_t
-Str_Hash_Sum_IMP(String *self) {
- uint32_t hashvalue = 5381;
- StackStringIterator *iter = STR_STACKTOP(self);
-
- const SStrIter_Next_t next
- = METHOD_PTR(STACKSTRINGITERATOR, CFISH_SStrIter_Next);
- int32_t code_point;
- while (STRITER_DONE != (code_point = next(iter))) {
- hashvalue = ((hashvalue << 5) + hashvalue) ^ code_point;
- }
-
- return (int32_t) hashvalue;
-}
-
-static void
-S_die_invalid_utf8(const char *text, size_t size, const char *file, int line,
- const char *func) {
- fprintf(stderr, "Invalid UTF-8, aborting: '");
- fwrite(text, sizeof(char), size < 200 ? size : 200, stderr);
- if (size > 200) { fwrite("[...]", sizeof(char), 5, stderr); }
- fprintf(stderr, "' (length %lu)\n", (unsigned long)size);
- Err_throw_at(ERR, file, line, func, "Invalid UTF-8");
-}
-
-String*
-Str_To_String_IMP(String *self) {
- return (String*)INCREF(self);
-}
-
-String*
-Str_Swap_Chars_IMP(String *self, int32_t match, int32_t replacement) {
- CharBuf *charbuf = CB_new(self->size);
- StackStringIterator *iter = STR_STACKTOP(self);
- int32_t code_point;
-
- while (STRITER_DONE != (code_point = SStrIter_Next(iter))) {
- if (code_point == match) { code_point = replacement; }
- CB_Cat_Char(charbuf, code_point);
- }
-
- String *retval = CB_Yield_String(charbuf);
- DECREF(charbuf);
- return retval;
-}
-
-int64_t
-Str_To_I64_IMP(String *self) {
- return Str_BaseX_To_I64(self, 10);
-}
-
-int64_t
-Str_BaseX_To_I64_IMP(String *self, uint32_t base) {
- StackStringIterator *iter = STR_STACKTOP(self);
- int64_t retval = 0;
- bool is_negative = false;
- int32_t code_point = SStrIter_Next(iter);
-
- // Advance past minus sign.
- if (code_point == '-') {
- code_point = SStrIter_Next(iter);
- is_negative = true;
- }
-
- // Accumulate.
- while (code_point != STRITER_DONE) {
- if (isalnum(code_point)) {
- int32_t addend = isdigit(code_point)
- ? code_point - '0'
- : tolower(code_point) - 'a' + 10;
- if (addend > (int32_t)base) { break; }
- retval *= base;
- retval += addend;
- }
- else {
- break;
- }
- code_point = SStrIter_Next(iter);
- }
-
- // Apply minus sign.
- if (is_negative) { retval = 0 - retval; }
-
- return retval;
-}
-
-static double
-S_safe_to_f64(String *self) {
- size_t amount = self->size < 511 ? self->size : 511;
- char buf[512];
- memcpy(buf, self->ptr, amount);
- buf[amount] = 0; // NULL-terminate.
- return strtod(buf, NULL);
-}
-
-double
-Str_To_F64_IMP(String *self) {
- char *end;
- double value = strtod(self->ptr, &end);
- size_t consumed = end - self->ptr;
- if (consumed > self->size) { // strtod overran
- value = S_safe_to_f64(self);
- }
- return value;
-}
-
-char*
-Str_To_Utf8_IMP(String *self) {
- char *buf = (char*)malloc(self->size + 1);
- memcpy(buf, self->ptr, self->size);
- buf[self->size] = '\0'; // NULL-terminate.
- return buf;
-}
-
-String*
-Str_Clone_IMP(String *self) {
- return (String*)INCREF(self);
-}
-
-String*
-Str_Cat_IMP(String *self, String *other) {
- return Str_Cat_Trusted_Utf8(self, other->ptr, other->size);
-}
-
-String*
-Str_Cat_Utf8_IMP(String *self, const char* ptr, size_t size) {
- if (!StrHelp_utf8_valid(ptr, size)) {
- DIE_INVALID_UTF8(ptr, size);
- }
- return Str_Cat_Trusted_Utf8(self, ptr, size);
-}
-
-String*
-Str_Cat_Trusted_Utf8_IMP(String *self, const char* ptr, size_t size) {
- size_t result_size = self->size + size;
- char *result_ptr = (char*)MALLOCATE(result_size + 1);
- memcpy(result_ptr, self->ptr, self->size);
- memcpy(result_ptr + self->size, ptr, size);
- result_ptr[result_size] = '\0';
- String *result = (String*)VTable_Make_Obj(STRING);
- return Str_init_steal_trusted_utf8(result, result_ptr, result_size);
-}
-
-bool
-Str_Starts_With_IMP(String *self, String *prefix) {
- return Str_Starts_With_Utf8_IMP(self, prefix->ptr, prefix->size);
-}
-
-bool
-Str_Starts_With_Utf8_IMP(String *self, const char *prefix, size_t size) {
- if (size <= self->size
- && (memcmp(self->ptr, prefix, size) == 0)
- ) {
- return true;
- }
- else {
- return false;
- }
-}
-
-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; }
- return Str_Equals_Utf8_IMP(self, twin->ptr, twin->size);
-}
-
-int32_t
-Str_Compare_To_IMP(String *self, Obj *other) {
- CERTIFY(other, STRING);
- return Str_compare(&self, &other);
-}
-
-bool
-Str_Equals_Utf8_IMP(String *self, const char *ptr, size_t size) {
- if (self->size != size) {
- return false;
- }
- return (memcmp(self->ptr, ptr, self->size) == 0);
-}
-
-bool
-Str_Ends_With_IMP(String *self, String *postfix) {
- return Str_Ends_With_Utf8_IMP(self, postfix->ptr, postfix->size);
-}
-
-bool
-Str_Ends_With_Utf8_IMP(String *self, const char *postfix, size_t postfix_len) {
- if (postfix_len <= self->size) {
- const char *start = self->ptr + self->size - postfix_len;
- if (memcmp(start, postfix, postfix_len) == 0) {
- return true;
- }
- }
-
- return false;
-}
-
-int64_t
-Str_Find_IMP(String *self, String *substring) {
- return Str_Find_Utf8(self, substring->ptr, substring->size);
-}
-
-int64_t
-Str_Find_Utf8_IMP(String *self, const char *ptr, size_t size) {
- StackStringIterator *iter = STR_STACKTOP(self);
- int64_t location = 0;
-
- while (iter->byte_offset + size <= self->size) {
- if (memcmp(self->ptr + iter->byte_offset, ptr, size) == 0) {
- return location;
- }
- SStrIter_Advance(iter, 1);
- location++;
- }
-
- return -1;
-}
-
-String*
-Str_Trim_IMP(String *self) {
- StackStringIterator *top = STR_STACKTOP(self);
- SStrIter_Skip_Next_Whitespace(top);
-
- StackStringIterator *tail = NULL;
- if (top->byte_offset < self->size) {
- tail = STR_STACKTAIL(self);
- SStrIter_Skip_Prev_Whitespace(tail);
- }
-
- return StrIter_substring((StringIterator*)top, (StringIterator*)tail);
-}
-
-String*
-Str_Trim_Top_IMP(String *self) {
- StackStringIterator *top = STR_STACKTOP(self);
- SStrIter_Skip_Next_Whitespace(top);
- return StrIter_substring((StringIterator*)top, NULL);
-}
-
-String*
-Str_Trim_Tail_IMP(String *self) {
- StackStringIterator *tail = STR_STACKTAIL(self);
- SStrIter_Skip_Prev_Whitespace(tail);
- return StrIter_substring(NULL, (StringIterator*)tail);
-}
-
-size_t
-Str_Length_IMP(String *self) {
- StackStringIterator *iter = STR_STACKTOP(self);
- return SStrIter_Advance(iter, SIZE_MAX);
-}
-
-int32_t
-Str_Code_Point_At_IMP(String *self, size_t tick) {
- StackStringIterator *iter = STR_STACKTOP(self);
- SStrIter_Advance(iter, tick);
- int32_t code_point = SStrIter_Next(iter);
- return code_point == STRITER_DONE ? 0 : code_point;
-}
-
-int32_t
-Str_Code_Point_From_IMP(String *self, size_t tick) {
- if (tick == 0) { return 0; }
- StackStringIterator *iter = STR_STACKTAIL(self);
- SStrIter_Recede(iter, tick - 1);
- int32_t code_point = SStrIter_Prev(iter);
- return code_point == STRITER_DONE ? 0 : code_point;
-}
-
-String*
-Str_SubString_IMP(String *self, size_t offset, size_t len) {
- StackStringIterator *iter = STR_STACKTOP(self);
-
- SStrIter_Advance(iter, offset);
- size_t start_offset = iter->byte_offset;
-
- SStrIter_Advance(iter, len);
- size_t size = iter->byte_offset - start_offset;
-
- return S_new_substring(self, start_offset, size);
-}
-
-int
-Str_compare(const void *va, const void *vb) {
- String *a = *(String**)va;
- String *b = *(String**)vb;
- size_t min_size;
- int tie;
-
- if (a->size <= b->size) {
- min_size = a->size;
- tie = a->size < b->size ? -1 : 0;
- }
- else {
- min_size = b->size;
- tie = 1;
- }
-
- int comparison = memcmp(a->ptr, b->ptr, min_size);
- if (comparison < 0) { return -1; }
- if (comparison > 0) { return 1; }
-
- return tie;
-}
-
-bool
-Str_less_than(const void *va, const void *vb) {
- return Str_compare(va, vb) < 0 ? true : false;
-}
-
-size_t
-Str_Get_Size_IMP(String *self) {
- return self->size;
-}
-
-const char*
-Str_Get_Ptr8_IMP(String *self) {
- return self->ptr;
-}
-
-StringIterator*
-Str_Top_IMP(String *self) {
- return StrIter_new(self, 0);
-}
-
-StringIterator*
-Str_Tail_IMP(String *self) {
- return StrIter_new(self, self->size);
-}
-
-StackStringIterator*
-Str_StackTop_IMP(String *self, void *allocation) {
- return SStrIter_new(allocation, self, 0);
-}
-
-StackStringIterator*
-Str_StackTail_IMP(String *self, void *allocation) {
- return SStrIter_new(allocation, self, self->size);
-}
-
-/*****************************************************************/
-
-StackString*
-SStr_new_from_str(void *allocation, size_t alloc_size, String *string) {
- size_t size = string->size;
- char *ptr = ((char*)allocation) + sizeof(StackString);
-
- if (alloc_size < sizeof(StackString) + size + 1) {
- THROW(ERR, "alloc_size of StackString too small");
- }
-
- memcpy(ptr, string->ptr, size);
- ptr[size] = '\0';
-
- StackString *self = (StackString*)VTable_Init_Obj(STACKSTRING, allocation);
- self->ptr = ptr;
- self->size = size;
- self->origin = NULL;
- return self;
-}
-
-StackString*
-SStr_wrap_str(void *allocation, const char *ptr, size_t size) {
- StackString *self
- = (StackString*)VTable_Init_Obj(STACKSTRING, allocation);
- self->size = size;
- self->ptr = ptr;
- self->origin = NULL;
- return self;
-}
-
-StackString*
-SStr_wrap(void *allocation, String *source) {
- return SStr_wrap_str(allocation, source->ptr, source->size);
-}
-
-size_t
-SStr_size() {
- return sizeof(StackString);
-}
-
-void
-SStr_Destroy_IMP(StackString *self) {
- THROW(ERR, "Can't destroy a StackString ('%o')", self);
-}
-
-/*****************************************************************/
-
-StringIterator*
-StrIter_new(String *string, size_t byte_offset) {
- StringIterator *self = (StringIterator*)VTable_Make_Obj(STRINGITERATOR);
- self->string = (String*)INCREF(string);
- self->byte_offset = byte_offset;
- return self;
-}
-
-String*
-StrIter_substring(StringIterator *top, StringIterator *tail) {
- String *string;
- size_t top_offset;
- size_t tail_offset;
-
- if (tail == NULL) {
- if (top == NULL) {
- THROW(ERR, "StrIter_substring: Both top and tail are NULL");
- }
- string = top->string;
- tail_offset = string->size;
- }
- else {
- string = tail->string;
- if (top != NULL && string != top->string) {
- THROW(ERR, "StrIter_substring: strings don't match");
- }
-
- tail_offset = tail->byte_offset;
- if (tail_offset > string->size) {
- THROW(ERR, "Invalid StringIterator offset");
- }
- }
-
- if (top == NULL) {
- top_offset = 0;
- }
- else {
- top_offset = top->byte_offset;
- if (top_offset > tail_offset) {
- THROW(ERR, "StrIter_substring: top is behind tail");
- }
- }
-
- return S_new_substring(string, top_offset, tail_offset - top_offset);
-}
-
-StringIterator*
-StrIter_Clone_IMP(StringIterator *self) {
- return StrIter_new(self->string, self->byte_offset);
-}
-
-void
-StrIter_Assign_IMP(StringIterator *self, StringIterator *other) {
- if (self->string != other->string) {
- DECREF(self->string);
- self->string = (String*)INCREF(other->string);
- }
- self->byte_offset = other->byte_offset;
-}
-
-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; }
- return self->string == twin->string
- && self->byte_offset == twin->byte_offset;
-}
-
-int32_t
-StrIter_Compare_To_IMP(StringIterator *self, Obj *other) {
- StringIterator *twin = (StringIterator*)CERTIFY(other, STRINGITERATOR);
- if (self->string != twin->string) {
- THROW(ERR, "Can't compare iterators of different strings");
- }
- if (self->byte_offset < twin->byte_offset) { return -1; }
- if (self->byte_offset > twin->byte_offset) { return 1; }
- return 0;
-}
-
-bool
-StrIter_Has_Next_IMP(StringIterator *self) {
- return self->byte_offset < self->string->size;
-}
-
-bool
-StrIter_Has_Prev_IMP(StringIterator *self) {
- return self->byte_offset != 0;
-}
-
-int32_t
-StrIter_Next_IMP(StringIterator *self) {
- String *string = self->string;
- size_t byte_offset = self->byte_offset;
- size_t size = string->size;
-
- if (byte_offset >= size) { return STRITER_DONE; }
-
- const uint8_t *const ptr = (const uint8_t*)string->ptr;
- int32_t retval = ptr[byte_offset++];
-
- if (retval >= 0x80) {
- /*
- * The 'mask' bit is tricky. In each iteration, 'retval' is
- * left-shifted by 6 and 'mask' by 5 bits. So relative to the first
- * byte of the sequence, 'mask' moves one bit to the right.
- *
- * The possible outcomes after the loop are:
- *
- * Two byte sequence
- * retval: 110aaaaa bbbbbb
- * mask: 00100000 000000
- *
- * Three byte sequence
- * retval: 1110aaaa bbbbbb cccccc
- * mask: 00010000 000000 000000
- *
- * Four byte sequence
- * retval: 11110aaa bbbbbb cccccc dddddd
- * mask: 00001000 000000 000000 000000
- *
- * This also illustrates why the exit condition (retval & mask)
- * works. After the first iteration, the third most significant bit
- * is tested. After the second iteration, the fourth, and so on.
- */
-
- int32_t mask = 1 << 6;
-
- do {
- if (byte_offset >= size) {
- THROW(ERR, "StrIter_Next: Invalid UTF-8");
- }
-
- retval = (retval << 6) | (ptr[byte_offset++] & 0x3F);
- mask <<= 5;
- } while (retval & mask);
-
- retval &= mask - 1;
- }
-
- self->byte_offset = byte_offset;
- return retval;
-}
-
-int32_t
-StrIter_Prev_IMP(StringIterator *self) {
- size_t byte_offset = self->byte_offset;
-
- if (byte_offset == 0) { return STRITER_DONE; }
-
- const uint8_t *const ptr = (const uint8_t*)self->string->ptr;
- int32_t retval = ptr[--byte_offset];
-
- if (retval >= 0x80) {
- // Construct the result from right to left.
-
- if (byte_offset == 0) {
- THROW(ERR, "StrIter_Prev: Invalid UTF-8");
- }
-
- retval &= 0x3F;
- int shift = 6;
- int32_t first_byte_mask = 0x1F;
- int32_t byte = ptr[--byte_offset];
-
- while ((byte & 0xC0) == 0x80) {
- if (byte_offset == 0) {
- THROW(ERR, "StrIter_Prev: Invalid UTF-8");
- }
-
- retval |= (byte & 0x3F) << shift;
- shift += 6;
- first_byte_mask >>= 1;
- byte = ptr[--byte_offset];
- }
-
- retval |= (byte & first_byte_mask) << shift;
- }
-
- self->byte_offset = byte_offset;
- return retval;
-}
-
-size_t
-StrIter_Advance_IMP(StringIterator *self, size_t num) {
- size_t num_skipped = 0;
- size_t byte_offset = self->byte_offset;
- size_t size = self->string->size;
- const uint8_t *const ptr = (const uint8_t*)self->string->ptr;
-
- while (num_skipped < num) {
- if (byte_offset >= size) {
- break;
- }
- uint8_t first_byte = ptr[byte_offset];
- byte_offset += StrHelp_UTF8_COUNT[first_byte];
- ++num_skipped;
- }
-
- if (byte_offset > size) {
- THROW(ERR, "StrIter_Advance: Invalid UTF-8");
- }
-
- self->byte_offset = byte_offset;
- return num_skipped;
-}
-
-size_t
-StrIter_Recede_IMP(StringIterator *self, size_t num) {
- size_t num_skipped = 0;
- size_t byte_offset = self->byte_offset;
- const uint8_t *const ptr = (const uint8_t*)self->string->ptr;
-
- while (num_skipped < num) {
- if (byte_offset == 0) {
- break;
- }
-
- uint8_t byte;
- do {
- if (byte_offset == 0) {
- THROW(ERR, "StrIter_Recede: Invalid UTF-8");
- }
-
- byte = ptr[--byte_offset];
- } while ((byte & 0xC0) == 0x80);
- ++num_skipped;
- }
-
- self->byte_offset = byte_offset;
- return num_skipped;
-}
-
-size_t
-StrIter_Skip_Next_Whitespace_IMP(StringIterator *self) {
- size_t num_skipped = 0;
- size_t byte_offset = self->byte_offset;
- int32_t code_point;
-
- while (STRITER_DONE != (code_point = StrIter_Next(self))) {
- if (!StrHelp_is_whitespace(code_point)) { break; }
- byte_offset = self->byte_offset;
- ++num_skipped;
- }
-
- self->byte_offset = byte_offset;
- return num_skipped;
-}
-
-size_t
-StrIter_Skip_Prev_Whitespace_IMP(StringIterator *self) {
- size_t num_skipped = 0;
- size_t byte_offset = self->byte_offset;
- int32_t code_point;
-
- while (STRITER_DONE != (code_point = StrIter_Prev(self))) {
- if (!StrHelp_is_whitespace(code_point)) { break; }
- byte_offset = self->byte_offset;
- ++num_skipped;
- }
-
- self->byte_offset = byte_offset;
- return num_skipped;
-}
-
-bool
-StrIter_Starts_With_IMP(StringIterator *self, String *prefix) {
- return StrIter_Starts_With_Utf8_IMP(self, prefix->ptr, prefix->size);
-}
-
-bool
-StrIter_Starts_With_Utf8_IMP(StringIterator *self, const char *prefix,
- size_t size) {
- String *string = self->string;
- size_t byte_offset = self->byte_offset;
-
- if (byte_offset > string->size) {
- THROW(ERR, "Invalid StringIterator offset");
- }
-
- if (string->size - byte_offset < size) { return false; }
-
- return memcmp(string->ptr + byte_offset, prefix, size) == 0;
-}
-
-bool
-StrIter_Ends_With_IMP(StringIterator *self, String *postfix) {
- return StrIter_Ends_With_Utf8_IMP(self, postfix->ptr, postfix->size);
-}
-
-bool
-StrIter_Ends_With_Utf8_IMP(StringIterator *self, const char *postfix,
- size_t size) {
- String *string = self->string;
- size_t byte_offset = self->byte_offset;
-
- if (byte_offset > string->size) {
- THROW(ERR, "Invalid StringIterator offset");
- }
-
- if (byte_offset < size) { return false; }
-
- return memcmp(string->ptr + byte_offset - size, postfix, size) == 0;
-}
-
-void
-StrIter_Destroy_IMP(StringIterator *self) {
- DECREF(self->string);
- SUPER_DESTROY(self, STRINGITERATOR);
-}
-
-/*****************************************************************/
-
-StackStringIterator*
-SStrIter_new(void *allocation, String *string, size_t byte_offset) {
- StackStringIterator *self
- = (StackStringIterator*)VTable_Init_Obj(STACKSTRINGITERATOR,
- allocation);
- // Assume that the string will be available for the lifetime of the
- // iterator and don't increase its refcount.
- self->string = string;
- self->byte_offset = byte_offset;
- return self;
-}
-
-void
-SStrIter_Destroy_IMP(StackStringIterator *self) {
- UNUSED_VAR(self);
- THROW(ERR, "Can't destroy a StackStringIterator");
-}
-
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/runtime/core/Clownfish/String.cfh
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/String.cfh b/clownfish/runtime/core/Clownfish/String.cfh
deleted file mode 100644
index 8a065cb..0000000
--- a/clownfish/runtime/core/Clownfish/String.cfh
+++ /dev/null
@@ -1,449 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-parcel Clownfish;
-
-/**
- * Immutable string holding Unicode characters.
- */
-
-class Clownfish::String cnick Str
- inherits Clownfish::Obj {
-
- const char *ptr;
- size_t size;
- String *origin;
-
- /** Return a new String which holds a copy of the passed-in string.
- * Check for UTF-8 validity.
- */
- inert incremented String*
- new_from_utf8(const char *utf8, size_t size);
-
- /** Return a new String which holds a copy of the passed-in string. No
- * validity checking is performed.
- */
- inert incremented String*
- new_from_trusted_utf8(const char *utf8, size_t size);
-
- /** Initialize the String using the passed-in string. Do not check
- * validity of supplied UTF-8.
- */
- inert String*
- init_from_trusted_utf8(String *self, const char *utf8, size_t size);
-
- /** Return a pointer to a new String which assumes ownership of the
- * passed-in string. Check validity of supplied UTF-8.
- */
- inert incremented String*
- new_steal_utf8(char *utf8, size_t size);
-
- /** Return a pointer to a new String which assumes ownership of the
- * passed-in string. Do not check validity of supplied UTF-8.
- */
- inert incremented String*
- new_steal_trusted_utf8(char *utf8, size_t size);
-
- /** Initialize the String using the passed-in string. Do not check
- * validity of supplied UTF-8.
- */
- public inert String*
- init_steal_trusted_utf8(String *self, char *utf8, size_t size);
-
- /** Return a pointer to a new String which wraps an external buffer
- * containing UTF-8. The buffer must stay unchanged for the lifetime
- * of the String. Check validity of supplied UTF-8.
- */
- inert incremented String*
- new_wrap_utf8(const char *utf8, size_t size);
-
- /** Return a pointer to a new String which wraps an external buffer
- * containing UTF-8. The buffer must stay unchanged for the lifetime
- * of the String. Do not check validity of supplied UTF-8.
- */
- inert incremented String*
- new_wrap_trusted_utf8(const char *utf8, size_t size);
-
- /** Initialize the String which wraps an external buffer containing
- * UTF-8. Do not check validity of supplied UTF-8.
- */
- public inert String*
- init_wrap_trusted_utf8(String *self, const char *utf8, size_t size);
-
- /** Return a String which holds a single character.
- */
- inert incremented String*
- new_from_char(int32_t code_point);
-
- /** Return a pointer to a new String which contains formatted data
- * expanded according to CB_VCatF.
- *
- * Note: a user-supplied <code>pattern</code> string is a security hole
- * and must not be allowed.
- */
- inert incremented String*
- newf(const char *pattern, ...);
-
- /** Perform lexical comparison of two Strings, with level of indirection
- * set to please qsort and friends.
- */
- inert int
- compare(const void *va, const void *vb);
-
- /** Perform lexical comparison of two Strings, with level of indirection
- * set to please qsort and friends, and return true if <code>a</code> is
- * less than <code>b</code>.
- */
- inert bool
- less_than(const void *va, const void *vb);
-
- /** Return the concatenation of the String and <code>other</code>.
- */
- incremented String*
- Cat(String *self, String *other);
-
- /** Return the concatenation of the String and the passed-in raw UTF-8.
- */
- incremented String*
- Cat_Utf8(String *self, const char *ptr, size_t size);
-
- /** Return the concatenation of the String and the passed-in raw UTF-8.
- * Don't check for UTF-8 validity.
- */
- incremented String*
- Cat_Trusted_Utf8(String *self, const char *ptr, size_t size);
-
- /** Replace all instances of one character for the other.
- *
- * @return a new String with the characters replaced.
- */
- incremented String*
- Swap_Chars(String *self, int32_t match, int32_t replacement);
-
- public int64_t
- To_I64(String *self);
-
- /** Extract a 64-bit integer from a variable-base stringified version.
- */
- int64_t
- BaseX_To_I64(String *self, uint32_t base);
-
- public double
- To_F64(String *self);
-
- /** Test whether the String starts with the content of another.
- */
- bool
- Starts_With(String *self, String *prefix);
-
- /** Test whether the String starts with the passed-in string.
- */
- bool
- Starts_With_Utf8(String *self, const char *prefix, size_t size);
-
- /** Test whether the String ends with the content of another.
- */
- bool
- Ends_With(String *self, String *postfix);
-
- /** Test whether the String ends with the passed-in string.
- */
- bool
- Ends_With_Utf8(String *self, const char *postfix, size_t size);
-
- /** Return the location of the substring within the String (measured in
- * code points), or -1 if the substring does not match.
- */
- int64_t
- Find(String *self, String *substring);
-
- int64_t
- Find_Utf8(String *self, const char *ptr, size_t size);
-
- /** Test whether the String matches the passed-in string.
- */
- bool
- Equals_Utf8(String *self, const char *ptr, size_t size);
-
- /** Return the number of Unicode code points in the object's string.
- */
- size_t
- Length(String *self);
-
- /** Get the String's <code>size</code> attribute.
- */
- size_t
- Get_Size(String *self);
-
- /** Return the internal backing array for the String if its internal
- * encoding is UTF-8. If it is not encoded as UTF-8 throw an exception.
- */
- const char*
- Get_Ptr8(String *self);
-
- /** Return a NULL-terminated copy of the string data in UTF-8 encoding.
- * The buffer must be freed by the caller.
- */
- char*
- To_Utf8(String *self);
-
- public incremented String*
- Clone(String *self);
-
- incremented Obj*
- Inc_RefCount(String *self);
-
- public void
- Destroy(String *self);
-
- public bool
- Equals(String *self, Obj *other);
-
- public int32_t
- Compare_To(String *self, Obj *other);
-
- public int32_t
- Hash_Sum(String *self);
-
- public incremented String*
- To_String(String *self);
-
- /** Remove Unicode whitespace characters from both top and tail.
- */
- String*
- Trim(String *self);
-
- /** Remove leading Unicode whitespace.
- */
- String*
- Trim_Top(String *self);
-
- /** Remove trailing Unicode whitespace.
- */
- String*
- Trim_Tail(String *self);
-
- /** Return the Unicode code point at the specified number of code points
- * in. Return 0 if the string length is exceeded. (XXX It would be
- * better to throw an exception, but that's not practical with UTF-8 and
- * no cached length.)
- */
- int32_t
- Code_Point_At(String *self, size_t tick);
-
- /** Return the Unicode code point at the specified number of code points
- * counted backwards from the end of the string. Return 0 if outside the
- * string.
- */
- int32_t
- Code_Point_From(String *self, size_t tick);
-
- /** Return a newly allocated String containing a copy of the indicated
- * substring.
- * @param offset Offset from the top, in code points.
- * @param len The desired length of the substring, in code points.
- */
- incremented String*
- SubString(String *self, size_t offset, size_t len);
-
- /** Return an iterator to the start of the string.
- */
- incremented StringIterator*
- Top(String *self);
-
- /** Return an iterator to the end of the string.
- */
- incremented StringIterator*
- Tail(String *self);
-
- /** Return a stack iterator to the start of the string.
- */
- incremented StackStringIterator*
- StackTop(String *self, void *allocation);
-
- /** Return a stack iterator to the end of the string.
- */
- incremented StackStringIterator*
- StackTail(String *self, void *allocation);
-}
-
-class Clownfish::StackString cnick SStr
- inherits Clownfish::String {
-
- /**
- * @param allocation A single block of memory which will be used for both
- * the StackString object and its buffer.
- * @param alloc_size The size of the allocation.
- * @param string String to be copied.
- */
- inert incremented StackString*
- new_from_str(void *allocation, size_t alloc_size, String *string);
-
- inert incremented StackString*
- wrap(void *allocation, String *source);
-
- inert incremented StackString*
- wrap_str(void *allocation, const char *ptr, size_t size);
-
- /** Return the size for a StackString struct.
- */
- inert size_t
- size();
-
- /** Throws an error.
- */
- public void
- Destroy(StackString *self);
-}
-
-class Clownfish::StringIterator cnick StrIter
- inherits Clownfish::Obj {
-
- String *string;
- size_t byte_offset;
-
- inert incremented StringIterator*
- new(String *string, size_t byte_offset);
-
- /** Return the substring between the top and tail iterators.
- * @param offset Top iterator. Use start of string if NULL.
- * @param len Tail iterator. Use end of string if NULL.
- */
- inert incremented String*
- substring(StringIterator *top, StringIterator *tail);
-
- public incremented StringIterator*
- Clone(StringIterator *self);
-
- public void
- Assign(StringIterator *self, StringIterator *other);
-
- public bool
- Equals(StringIterator *self, Obj *other);
-
- public int32_t
- Compare_To(StringIterator *self, Obj *other);
-
- /** Return true if the iterator is not at the end of the string.
- */
- public bool
- Has_Next(StringIterator *self);
-
- /** Return true if the iterator is not at the start of the string.
- */
- public bool
- Has_Prev(StringIterator *self);
-
- /** Return the code point after the current position and advance the
- * iterator. Return CFISH_STRITER_DONE at the end of the string.
- */
- public int32_t
- Next(StringIterator *self);
-
- /** Return the code point before the current position and go one step back.
- * Return CFISH_STRITER_DONE at the start of the string.
- */
- public int32_t
- Prev(StringIterator *self);
-
- /** Skip code points.
- * @param num The number of code points to skip.
- * @return the number of code points actually skipped. This can be less
- * than the requested number if the end of the string is reached.
- */
- public size_t
- Advance(StringIterator *self, size_t num);
-
- /** Skip code points backward.
- * @param num The number of code points to skip.
- * @return the number of code points actually skipped. This can be less
- * than the requested number if the start of the string is reached.
- */
- public size_t
- Recede(StringIterator *self, size_t num);
-
- /** Skip whitespace.
- * @return the number of code points skipped.
- */
- public size_t
- Skip_Next_Whitespace(StringIterator *self);
-
- /** Skip whitespace backward.
- * @return the number of code points skipped.
- */
- public size_t
- Skip_Prev_Whitespace(StringIterator *self);
-
- /** Test whether the content after the iterator starts with
- * <code>prefix</code>.
- */
- bool
- Starts_With(StringIterator *self, String *prefix);
-
- /** Test whether the content after the iterator starts with the passed-in
- * string.
- */
- bool
- Starts_With_Utf8(StringIterator *self, const char *prefix, size_t size);
-
- /** Test whether the content before the iterator ends with
- * <code>postfix</code>.
- */
- bool
- Ends_With(StringIterator *self, String *postfix);
-
- /** Test whether the content before the iterator ends with the passed-in
- * string.
- */
- bool
- Ends_With_Utf8(StringIterator *self, const char *postfix, size_t size);
-
- public void
- Destroy(StringIterator *self);
-}
-
-class Clownfish::StackStringIterator cnick SStrIter
- inherits Clownfish::StringIterator {
-
- inert incremented StackStringIterator*
- new(void *allocation, String *string, size_t byte_offset);
-
- public void
- Destroy(StackStringIterator *self);
-}
-
-__C__
-
-#define CFISH_SSTR_BLANK() \
- cfish_SStr_wrap_str(cfish_alloca(cfish_SStr_size()), "", 0)
-
-#define CFISH_SSTR_WRAP(source) \
- cfish_SStr_wrap(cfish_alloca(cfish_SStr_size()), source)
-
-#define CFISH_SSTR_WRAP_UTF8(ptr, size) \
- cfish_SStr_wrap_str(cfish_alloca(cfish_SStr_size()), ptr, size)
-
-#define CFISH_STRITER_DONE -1
-
-#ifdef CFISH_USE_SHORT_NAMES
- #define SSTR_BLANK CFISH_SSTR_BLANK
- #define SSTR_WRAP CFISH_SSTR_WRAP
- #define SSTR_WRAP_UTF8 CFISH_SSTR_WRAP_UTF8
- #define STRITER_DONE CFISH_STRITER_DONE
-#endif
-__END_C__
-
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/runtime/core/Clownfish/Test.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/Test.c b/clownfish/runtime/core/Clownfish/Test.c
deleted file mode 100644
index b891331..0000000
--- a/clownfish/runtime/core/Clownfish/Test.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define CFISH_USE_SHORT_NAMES
-#define TESTCFISH_USE_SHORT_NAMES
-
-#include "Clownfish/Test.h"
-
-#include "Clownfish/TestHarness/TestBatch.h"
-#include "Clownfish/TestHarness/TestSuite.h"
-
-#include "Clownfish/Test/TestByteBuf.h"
-#include "Clownfish/Test/TestString.h"
-#include "Clownfish/Test/TestCharBuf.h"
-#include "Clownfish/Test/TestErr.h"
-#include "Clownfish/Test/TestHash.h"
-#include "Clownfish/Test/TestLockFreeRegistry.h"
-#include "Clownfish/Test/TestNum.h"
-#include "Clownfish/Test/TestObj.h"
-#include "Clownfish/Test/TestVArray.h"
-#include "Clownfish/Test/Util/TestAtomic.h"
-#include "Clownfish/Test/Util/TestMemory.h"
-#include "Clownfish/Test/Util/TestNumberUtils.h"
-#include "Clownfish/Test/Util/TestStringHelper.h"
-
-TestSuite*
-Test_create_test_suite() {
- TestSuite *suite = TestSuite_new();
-
- TestSuite_Add_Batch(suite, (TestBatch*)TestVArray_new());
- TestSuite_Add_Batch(suite, (TestBatch*)TestHash_new());
- TestSuite_Add_Batch(suite, (TestBatch*)TestObj_new());
- TestSuite_Add_Batch(suite, (TestBatch*)TestErr_new());
- TestSuite_Add_Batch(suite, (TestBatch*)TestBB_new());
- TestSuite_Add_Batch(suite, (TestBatch*)TestStr_new());
- TestSuite_Add_Batch(suite, (TestBatch*)TestCB_new());
- TestSuite_Add_Batch(suite, (TestBatch*)TestNumUtil_new());
- TestSuite_Add_Batch(suite, (TestBatch*)TestNum_new());
- TestSuite_Add_Batch(suite, (TestBatch*)TestStrHelp_new());
- TestSuite_Add_Batch(suite, (TestBatch*)TestAtomic_new());
- TestSuite_Add_Batch(suite, (TestBatch*)TestLFReg_new());
- TestSuite_Add_Batch(suite, (TestBatch*)TestMemory_new());
-
- return suite;
-}
-
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/runtime/core/Clownfish/Test.cfh
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/Test.cfh b/clownfish/runtime/core/Clownfish/Test.cfh
deleted file mode 100644
index 68dc8bc..0000000
--- a/clownfish/runtime/core/Clownfish/Test.cfh
+++ /dev/null
@@ -1,26 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-parcel TestClownfish;
-
-/** Clownfish test suite.
- */
-inert class Clownfish::Test {
- inert incremented TestSuite*
- create_test_suite();
-}
-
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/runtime/core/Clownfish/Test/TestByteBuf.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/Test/TestByteBuf.c b/clownfish/runtime/core/Clownfish/Test/TestByteBuf.c
deleted file mode 100644
index dcea3b5..0000000
--- a/clownfish/runtime/core/Clownfish/Test/TestByteBuf.c
+++ /dev/null
@@ -1,156 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <string.h>
-
-#define CFISH_USE_SHORT_NAMES
-#define TESTCFISH_USE_SHORT_NAMES
-
-#include "Clownfish/Test/TestByteBuf.h"
-
-#include "Clownfish/ByteBuf.h"
-#include "Clownfish/Test.h"
-#include "Clownfish/TestHarness/TestBatchRunner.h"
-#include "Clownfish/TestHarness/TestUtils.h"
-#include "Clownfish/VTable.h"
-
-TestByteBuf*
-TestBB_new() {
- return (TestByteBuf*)VTable_Make_Obj(TESTBYTEBUF);
-}
-
-static void
-test_Equals(TestBatchRunner *runner) {
- ByteBuf *wanted = BB_new_bytes("foo", 4); // Include terminating NULL.
- ByteBuf *got = BB_new_bytes("foo", 4);
-
- TEST_TRUE(runner, BB_Equals(wanted, (Obj*)got), "Equals");
- TEST_INT_EQ(runner, BB_Hash_Sum(got), BB_Hash_Sum(wanted), "Hash_Sum");
-
- TEST_TRUE(runner, BB_Equals_Bytes(got, "foo", 4), "Equals_Bytes");
- TEST_FALSE(runner, BB_Equals_Bytes(got, "foo", 3),
- "Equals_Bytes spoiled by different size");
- TEST_FALSE(runner, BB_Equals_Bytes(got, "bar", 4),
- "Equals_Bytes spoiled by different content");
-
- BB_Set_Size(got, 3);
- TEST_FALSE(runner, BB_Equals(wanted, (Obj*)got),
- "Different size spoils Equals");
- TEST_FALSE(runner, BB_Hash_Sum(got) == BB_Hash_Sum(wanted),
- "Different size spoils Hash_Sum (probably -- at least this one)");
-
- BB_Mimic_Bytes(got, "bar", 4);
- TEST_INT_EQ(runner, BB_Get_Size(wanted), BB_Get_Size(got),
- "same length");
- TEST_FALSE(runner, BB_Equals(wanted, (Obj*)got),
- "Different content spoils Equals");
-
- DECREF(got);
- DECREF(wanted);
-}
-
-static void
-test_Grow(TestBatchRunner *runner) {
- ByteBuf *bb = BB_new(1);
- TEST_INT_EQ(runner, BB_Get_Capacity(bb), 8,
- "Allocate in 8-byte increments");
- BB_Grow(bb, 9);
- TEST_INT_EQ(runner, BB_Get_Capacity(bb), 16,
- "Grow in 8-byte increments");
- DECREF(bb);
-}
-
-static void
-test_Clone(TestBatchRunner *runner) {
- ByteBuf *bb = BB_new_bytes("foo", 3);
- ByteBuf *twin = BB_Clone(bb);
- TEST_TRUE(runner, BB_Equals(bb, (Obj*)twin), "Clone");
- DECREF(bb);
- DECREF(twin);
-}
-
-static void
-test_compare(TestBatchRunner *runner) {
- ByteBuf *a = BB_new_bytes("foo\0a", 5);
- ByteBuf *b = BB_new_bytes("foo\0b", 5);
-
- BB_Set_Size(a, 4);
- BB_Set_Size(b, 4);
- TEST_INT_EQ(runner, BB_compare(&a, &b), 0,
- "BB_compare returns 0 for equal ByteBufs");
-
- BB_Set_Size(a, 3);
- TEST_TRUE(runner, BB_compare(&a, &b) < 0, "shorter ByteBuf sorts first");
-
- BB_Set_Size(a, 5);
- BB_Set_Size(b, 5);
- TEST_TRUE(runner, BB_compare(&a, &b) < 0,
- "NULL doesn't interfere with BB_compare");
-
- DECREF(a);
- DECREF(b);
-}
-
-static void
-test_Mimic(TestBatchRunner *runner) {
- ByteBuf *a = BB_new_bytes("foo", 3);
- ByteBuf *b = BB_new(0);
-
- BB_Mimic(b, (Obj*)a);
- TEST_TRUE(runner, BB_Equals(a, (Obj*)b), "Mimic");
-
- BB_Mimic_Bytes(a, "bar", 4);
- TEST_TRUE(runner, strcmp(BB_Get_Buf(a), "bar") == 0,
- "Mimic_Bytes content");
- TEST_INT_EQ(runner, BB_Get_Size(a), 4, "Mimic_Bytes size");
-
- BB_Mimic(b, (Obj*)a);
- TEST_TRUE(runner, BB_Equals(a, (Obj*)b), "Mimic");
-
- DECREF(a);
- DECREF(b);
-}
-
-static void
-test_Cat(TestBatchRunner *runner) {
- ByteBuf *wanted = BB_new_bytes("foobar", 6);
- ByteBuf *got = BB_new_bytes("foo", 3);
- ByteBuf *scratch = BB_new_bytes("bar", 3);
-
- BB_Cat(got, scratch);
- TEST_TRUE(runner, BB_Equals(wanted, (Obj*)got), "Cat");
-
- BB_Mimic_Bytes(wanted, "foobarbaz", 9);
- BB_Cat_Bytes(got, "baz", 3);
- TEST_TRUE(runner, BB_Equals(wanted, (Obj*)got), "Cat_Bytes");
-
- DECREF(scratch);
- DECREF(got);
- DECREF(wanted);
-}
-
-void
-TestBB_Run_IMP(TestByteBuf *self, TestBatchRunner *runner) {
- TestBatchRunner_Plan(runner, (TestBatch*)self, 21);
- test_Equals(runner);
- test_Grow(runner);
- test_Clone(runner);
- test_compare(runner);
- test_Mimic(runner);
- test_Cat(runner);
-}
-
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/runtime/core/Clownfish/Test/TestByteBuf.cfh
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/Test/TestByteBuf.cfh b/clownfish/runtime/core/Clownfish/Test/TestByteBuf.cfh
deleted file mode 100644
index 3335c95..0000000
--- a/clownfish/runtime/core/Clownfish/Test/TestByteBuf.cfh
+++ /dev/null
@@ -1,29 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-parcel TestClownfish;
-
-class Clownfish::Test::TestByteBuf cnick TestBB
- inherits Clownfish::TestHarness::TestBatch {
-
- inert incremented TestByteBuf*
- new();
-
- void
- Run(TestByteBuf *self, TestBatchRunner *runner);
-}
-
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/runtime/core/Clownfish/Test/TestCharBuf.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/Test/TestCharBuf.c b/clownfish/runtime/core/Clownfish/Test/TestCharBuf.c
deleted file mode 100644
index 48c36a1..0000000
--- a/clownfish/runtime/core/Clownfish/Test/TestCharBuf.c
+++ /dev/null
@@ -1,300 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <string.h>
-#include <stdio.h>
-
-#define CHY_USE_SHORT_NAMES
-#define CFISH_USE_SHORT_NAMES
-#define TESTCFISH_USE_SHORT_NAMES
-
-#include "charmony.h"
-
-#include "Clownfish/Test/TestCharBuf.h"
-
-#include "Clownfish/CharBuf.h"
-#include "Clownfish/Num.h"
-#include "Clownfish/String.h"
-#include "Clownfish/Test.h"
-#include "Clownfish/TestHarness/TestBatchRunner.h"
-#include "Clownfish/TestHarness/TestUtils.h"
-#include "Clownfish/VTable.h"
-
-static char smiley[] = { (char)0xE2, (char)0x98, (char)0xBA, 0 };
-static uint32_t smiley_len = 3;
-
-TestCharBuf*
-TestCB_new() {
- return (TestCharBuf*)VTable_Make_Obj(TESTCHARBUF);
-}
-
-static CharBuf*
-S_get_cb(const char *string) {
- return CB_new_from_utf8(string, strlen(string));
-}
-
-static String*
-S_get_str(const char *string) {
- return Str_new_from_utf8(string, strlen(string));
-}
-
-static bool
-S_cb_equals(CharBuf *cb, String *other) {
- String *string = CB_To_String(cb);
- bool retval = Str_Equals(string, (Obj*)other);
- DECREF(string);
- return retval;
-}
-
-static void
-test_Cat(TestBatchRunner *runner) {
- String *wanted = Str_newf("a%s", smiley);
- CharBuf *got = S_get_cb("");
-
- CB_Cat(got, wanted);
- TEST_TRUE(runner, S_cb_equals(got, wanted), "Cat");
- DECREF(got);
-
- got = S_get_cb("a");
- CB_Cat_Char(got, 0x263A);
- TEST_TRUE(runner, S_cb_equals(got, wanted), "Cat_Char");
- DECREF(got);
-
- got = S_get_cb("a");
- CB_Cat_Utf8(got, smiley, smiley_len);
- TEST_TRUE(runner, S_cb_equals(got, wanted), "Cat_Utf8");
- DECREF(got);
-
- got = S_get_cb("a");
- CB_Cat_Trusted_Utf8(got, smiley, smiley_len);
- TEST_TRUE(runner, S_cb_equals(got, wanted), "Cat_Trusted_Utf8");
- DECREF(got);
-
- DECREF(wanted);
-}
-
-static void
-test_Mimic_and_Clone(TestBatchRunner *runner) {
- String *wanted = S_get_str("foo");
- CharBuf *wanted_cb = S_get_cb("foo");
- CharBuf *got = S_get_cb("bar");
-
- CB_Mimic(got, (Obj*)wanted);
- TEST_TRUE(runner, S_cb_equals(got, wanted), "Mimic String");
- DECREF(got);
-
- got = S_get_cb("bar");
- CB_Mimic(got, (Obj*)wanted_cb);
- TEST_TRUE(runner, S_cb_equals(got, wanted), "Mimic CharBuf");
- DECREF(got);
-
- got = S_get_cb("bar");
- CB_Mimic_Utf8(got, "foo", 3);
- TEST_TRUE(runner, S_cb_equals(got, wanted), "Mimic_Utf8");
- DECREF(got);
-
- got = CB_Clone(wanted_cb);
- TEST_TRUE(runner, S_cb_equals(got, wanted), "Clone");
- DECREF(got);
-
- DECREF(wanted);
-}
-
-/*
-static void
-test_Truncate(TestBatchRunner *runner) {
- String *wanted = Str_newf("a%s", smiley);
- CharBuf *got = CB_newf("a%s%sb%sc", smiley, smiley, smiley);
- CB_Truncate(got, 2);
- TEST_TRUE(runner, S_cb_equals(got, wanted), "Truncate");
- DECREF(wanted);
- DECREF(got);
-}
-*/
-
-static void
-test_vcatf_s(TestBatchRunner *runner) {
- String *wanted = S_get_str("foo bar bizzle baz");
- CharBuf *got = S_get_cb("foo ");
- CB_catf(got, "bar %s baz", "bizzle");
- TEST_TRUE(runner, S_cb_equals(got, wanted), "%%s");
- DECREF(wanted);
- DECREF(got);
-}
-
-static void
-test_vcatf_null_string(TestBatchRunner *runner) {
- String *wanted = S_get_str("foo bar [NULL] baz");
- CharBuf *got = S_get_cb("foo ");
- CB_catf(got, "bar %s baz", NULL);
- TEST_TRUE(runner, S_cb_equals(got, wanted), "%%s NULL");
- DECREF(wanted);
- DECREF(got);
-}
-
-static void
-test_vcatf_str(TestBatchRunner *runner) {
- String *wanted = S_get_str("foo bar ZEKE baz");
- String *catworthy = S_get_str("ZEKE");
- CharBuf *got = S_get_cb("foo ");
- CB_catf(got, "bar %o baz", catworthy);
- TEST_TRUE(runner, S_cb_equals(got, wanted), "%%o CharBuf");
- DECREF(catworthy);
- DECREF(wanted);
- DECREF(got);
-}
-
-static void
-test_vcatf_obj(TestBatchRunner *runner) {
- String *wanted = S_get_str("ooga 20 booga");
- Integer32 *i32 = Int32_new(20);
- CharBuf *got = S_get_cb("ooga");
- CB_catf(got, " %o booga", i32);
- TEST_TRUE(runner, S_cb_equals(got, wanted), "%%o Obj");
- DECREF(i32);
- DECREF(wanted);
- DECREF(got);
-}
-
-static void
-test_vcatf_null_obj(TestBatchRunner *runner) {
- String *wanted = S_get_str("foo bar [NULL] baz");
- CharBuf *got = S_get_cb("foo ");
- CB_catf(got, "bar %o baz", NULL);
- TEST_TRUE(runner, S_cb_equals(got, wanted), "%%o NULL");
- DECREF(wanted);
- DECREF(got);
-}
-
-static void
-test_vcatf_i8(TestBatchRunner *runner) {
- String *wanted = S_get_str("foo bar -3 baz");
- int8_t num = -3;
- CharBuf *got = S_get_cb("foo ");
- CB_catf(got, "bar %i8 baz", num);
- TEST_TRUE(runner, S_cb_equals(got, wanted), "%%i8");
- DECREF(wanted);
- DECREF(got);
-}
-
-static void
-test_vcatf_i32(TestBatchRunner *runner) {
- String *wanted = S_get_str("foo bar -100000 baz");
- int32_t num = -100000;
- CharBuf *got = S_get_cb("foo ");
- CB_catf(got, "bar %i32 baz", num);
- TEST_TRUE(runner, S_cb_equals(got, wanted), "%%i32");
- DECREF(wanted);
- DECREF(got);
-}
-
-static void
-test_vcatf_i64(TestBatchRunner *runner) {
- String *wanted = S_get_str("foo bar -5000000000 baz");
- int64_t num = INT64_C(-5000000000);
- CharBuf *got = S_get_cb("foo ");
- CB_catf(got, "bar %i64 baz", num);
- TEST_TRUE(runner, S_cb_equals(got, wanted), "%%i64");
- DECREF(wanted);
- DECREF(got);
-}
-
-static void
-test_vcatf_u8(TestBatchRunner *runner) {
- String *wanted = S_get_str("foo bar 3 baz");
- uint8_t num = 3;
- CharBuf *got = S_get_cb("foo ");
- CB_catf(got, "bar %u8 baz", num);
- TEST_TRUE(runner, S_cb_equals(got, wanted), "%%u8");
- DECREF(wanted);
- DECREF(got);
-}
-
-static void
-test_vcatf_u32(TestBatchRunner *runner) {
- String *wanted = S_get_str("foo bar 100000 baz");
- uint32_t num = 100000;
- CharBuf *got = S_get_cb("foo ");
- CB_catf(got, "bar %u32 baz", num);
- TEST_TRUE(runner, S_cb_equals(got, wanted), "%%u32");
- DECREF(wanted);
- DECREF(got);
-}
-
-static void
-test_vcatf_u64(TestBatchRunner *runner) {
- String *wanted = S_get_str("foo bar 5000000000 baz");
- uint64_t num = UINT64_C(5000000000);
- CharBuf *got = S_get_cb("foo ");
- CB_catf(got, "bar %u64 baz", num);
- TEST_TRUE(runner, S_cb_equals(got, wanted), "%%u64");
- DECREF(wanted);
- DECREF(got);
-}
-
-static void
-test_vcatf_f64(TestBatchRunner *runner) {
- String *wanted;
- char buf[64];
- float num = 1.3f;
- CharBuf *got = S_get_cb("foo ");
- sprintf(buf, "foo bar %g baz", num);
- wanted = Str_new_from_trusted_utf8(buf, strlen(buf));
- CB_catf(got, "bar %f64 baz", num);
- TEST_TRUE(runner, S_cb_equals(got, wanted), "%%f64");
- DECREF(wanted);
- DECREF(got);
-}
-
-static void
-test_vcatf_x32(TestBatchRunner *runner) {
- String *wanted;
- char buf[64];
- unsigned long num = INT32_MAX;
- CharBuf *got = S_get_cb("foo ");
-#if (SIZEOF_LONG == 4)
- sprintf(buf, "foo bar %.8lx baz", num);
-#elif (SIZEOF_INT == 4)
- sprintf(buf, "foo bar %.8x baz", (unsigned)num);
-#endif
- wanted = Str_new_from_trusted_utf8(buf, strlen(buf));
- CB_catf(got, "bar %x32 baz", (uint32_t)num);
- TEST_TRUE(runner, S_cb_equals(got, wanted), "%%x32");
- DECREF(wanted);
- DECREF(got);
-}
-
-void
-TestCB_Run_IMP(TestCharBuf *self, TestBatchRunner *runner) {
- TestBatchRunner_Plan(runner, (TestBatch*)self, 21);
- test_vcatf_s(runner);
- test_vcatf_null_string(runner);
- test_vcatf_str(runner);
- test_vcatf_obj(runner);
- test_vcatf_null_obj(runner);
- test_vcatf_i8(runner);
- test_vcatf_i32(runner);
- test_vcatf_i64(runner);
- test_vcatf_u8(runner);
- test_vcatf_u32(runner);
- test_vcatf_u64(runner);
- test_vcatf_f64(runner);
- test_vcatf_x32(runner);
- test_Cat(runner);
- test_Mimic_and_Clone(runner);
-}
-
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/runtime/core/Clownfish/Test/TestCharBuf.cfh
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/Test/TestCharBuf.cfh b/clownfish/runtime/core/Clownfish/Test/TestCharBuf.cfh
deleted file mode 100644
index 3cc5d43..0000000
--- a/clownfish/runtime/core/Clownfish/Test/TestCharBuf.cfh
+++ /dev/null
@@ -1,29 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-parcel TestClownfish;
-
-class Clownfish::Test::TestCharBuf cnick TestCB
- inherits Clownfish::TestHarness::TestBatch {
-
- inert incremented TestCharBuf*
- new();
-
- void
- Run(TestCharBuf *self, TestBatchRunner *runner);
-}
-
-