You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2013/06/07 18:10:30 UTC
[lucy-commits] [15/16] Build Lucy with external Clownfish library
http://git-wip-us.apache.org/repos/asf/lucy/blob/ddff7ce9/core/Clownfish/Err.c
----------------------------------------------------------------------
diff --git a/core/Clownfish/Err.c b/core/Clownfish/Err.c
deleted file mode 100644
index 0dd0363..0000000
--- a/core/Clownfish/Err.c
+++ /dev/null
@@ -1,261 +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_ERR
-#define C_CFISH_OBJ
-#define C_CFISH_VTABLE
-#define CFISH_USE_SHORT_NAMES
-#define CHY_USE_SHORT_NAMES
-
-#include <string.h>
-#include <stdio.h>
-#include <ctype.h>
-
-#include "Clownfish/Err.h"
-#include "Clownfish/CharBuf.h"
-#include "Clownfish/VTable.h"
-#include "Clownfish/Util/Memory.h"
-
-Err*
-Err_new(CharBuf *mess) {
- Err *self = (Err*)VTable_Make_Obj(ERR);
- return Err_init(self, mess);
-}
-
-Err*
-Err_init(Err *self, CharBuf *mess) {
- self->mess = mess;
- return self;
-}
-
-void
-Err_destroy(Err *self) {
- DECREF(self->mess);
- SUPER_DESTROY(self, ERR);
-}
-
-Err*
-Err_make(Err *self) {
- UNUSED_VAR(self);
- return Err_new(CB_new(0));
-}
-
-CharBuf*
-Err_to_string(Err *self) {
- return (CharBuf*)INCREF(self->mess);
-}
-
-void
-Err_cat_mess(Err *self, const CharBuf *mess) {
- CB_Cat(self->mess, mess);
-}
-
-// Fallbacks in case variadic macros aren't available.
-#ifndef CHY_HAS_VARIADIC_MACROS
-void
-THROW(VTable *vtable, char *pattern, ...) {
- va_list args;
- Err_Make_t make = METHOD_PTR(CERTIFY(vtable, VTABLE), Cfish_Err_Make);
- Err *err = (Err*)CERTIFY(make(NULL), ERR);
- CharBuf *mess = Err_Get_Mess(err);
-
- va_start(args, pattern);
- CB_VCatF(mess, pattern, args);
- va_end(args);
-
- Err_do_throw(err);
-}
-void
-CFISH_WARN(char *pattern, ...) {
- va_list args;
- CharBuf *const message = CB_new(strlen(pattern) + 10);
-
- va_start(args, pattern);
- CB_VCatF(message, pattern, args);
- va_end(args);
-
- Err_warn_mess(message);
-}
-CharBuf*
-CFISH_MAKE_MESS(char *pattern, ...) {
- va_list args;
- CharBuf *const message = CB_new(strlen(pattern) + 10);
-
- va_start(args, pattern);
- CB_VCatF(message, pattern, args);
- va_end(args);
-
- return message;
-}
-#endif
-
-
-static void
-S_vcat_mess(CharBuf *message, const char *file, int line, const char *func,
- const char *pattern, va_list args) {
- size_t guess_len = strlen(file)
- + func ? strlen(func) : 0
- + strlen(pattern)
- + 30;
- CB_Grow(message, guess_len);
- CB_VCatF(message, pattern, args);
- if (func != NULL) {
- CB_catf(message, "\n\t%s at %s line %i32\n", func, file, (int32_t)line);
- }
- else {
- CB_catf(message, "\n\t%s line %i32\n", file, (int32_t)line);
- }
-}
-
-CharBuf*
-Err_make_mess(const char *file, int line, const char *func,
- const char *pattern, ...) {
- va_list args;
- size_t guess_len = strlen(pattern) + strlen(file) + 20;
- CharBuf *message = CB_new(guess_len);
- va_start(args, pattern);
- S_vcat_mess(message, file, line, func, pattern, args);
- va_end(args);
- return message;
-}
-
-void
-Err_warn_at(const char *file, int line, const char *func,
- const char *pattern, ...) {
- va_list args;
- CharBuf *message = CB_new(0);
- va_start(args, pattern);
- S_vcat_mess(message, file, line, func, pattern, args);
- va_end(args);
- Err_warn_mess(message);
-}
-
-CharBuf*
-Err_get_mess(Err *self) {
- return self->mess;
-}
-
-void
-Err_add_frame(Err *self, const char *file, int line, const char *func) {
- if (CB_Ends_With_Str(self->mess, "\n", 1)) { CB_Chop(self->mess, 1); }
-
- if (func != NULL) {
- CB_catf(self->mess, "\n\t%s at %s line %i32\n", func, file,
- (int32_t)line);
- }
- else {
- CB_catf(self->mess, "\n\tat %s line %i32\n", file, (int32_t)line);
- }
-}
-
-void
-Err_rethrow(Err *self, const char *file, int line, const char *func) {
- Err_add_frame(self, file, line, func);
- Err_do_throw(self);
-}
-
-void
-Err_throw_at(VTable *vtable, const char *file, int line,
- const char *func, const char *pattern, ...) {
- va_list args;
- Err_Make_t make = METHOD_PTR(CERTIFY(vtable, VTABLE), Cfish_Err_Make);
- Err *err = (Err*)CERTIFY(make(NULL), ERR);
- CharBuf *mess = Err_Get_Mess(err);
-
- va_start(args, pattern);
- S_vcat_mess(mess, file, line, func, pattern, args);
- va_end(args);
-
- Err_do_throw(err);
-}
-
-// Inlined, slightly optimized version of Obj_is_a.
-static INLINE bool
-SI_obj_is_a(Obj *obj, VTable *target_vtable) {
- VTable *vtable = obj->vtable;
-
- while (vtable != NULL) {
- if (vtable == target_vtable) {
- return true;
- }
- vtable = vtable->parent;
- }
-
- return false;
-}
-
-Obj*
-Err_downcast(Obj *obj, VTable *vtable, const char *file, int line,
- const char *func) {
- if (obj && !SI_obj_is_a(obj, vtable)) {
- Err_throw_at(ERR, file, line, func, "Can't downcast from %o to %o",
- Obj_Get_Class_Name(obj), VTable_Get_Name(vtable));
- }
- return obj;
-}
-
-Obj*
-Err_certify(Obj *obj, VTable *vtable, const char *file, int line,
- const char *func) {
- if (!obj) {
- Err_throw_at(ERR, file, line, func, "Object isn't a %o, it's NULL",
- VTable_Get_Name(vtable));
- }
- else if (!SI_obj_is_a(obj, vtable)) {
- Err_throw_at(ERR, file, line, func, "Can't downcast from %o to %o",
- Obj_Get_Class_Name(obj), VTable_Get_Name(vtable));
- }
- return obj;
-}
-
-#ifdef CHY_HAS_WINDOWS_H
-
-#include <windows.h>
-
-char*
-Err_win_error() {
- size_t buf_size = 256;
- char *buf = (char*)MALLOCATE(buf_size);
- size_t message_len = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
- NULL, // message source table
- GetLastError(),
- 0, // language id
- buf,
- buf_size,
- NULL // empty va_list
- );
- if (message_len == 0) {
- char unknown[] = "Unknown error";
- size_t len = sizeof(unknown);
- strncpy(buf, unknown, len);
- }
- else if (message_len > 1) {
- // Kill stupid newline.
- buf[message_len - 2] = '\0';
- }
- return buf;
-}
-
-#else
-
-char*
-Err_win_error() {
- return NULL; // Never called.
-}
-
-#endif // CHY_HAS_WINDOWS_H
-
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/ddff7ce9/core/Clownfish/Err.cfh
----------------------------------------------------------------------
diff --git a/core/Clownfish/Err.cfh b/core/Clownfish/Err.cfh
deleted file mode 100644
index 7bc4f86..0000000
--- a/core/Clownfish/Err.cfh
+++ /dev/null
@@ -1,257 +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;
-
-__C__
-typedef void
-(*Cfish_Err_Attempt_t)(void *context);
-
-#ifdef CFISH_USE_SHORT_NAMES
- #define Err_Attempt_t Cfish_Err_Attempt_t
-#endif
-__END_C__
-
-/**
- * Exception.
- *
- * Clownfish::Err is the base class for exceptions in the Clownfish object
- * hierarchy.
- *
- * The Err module also provides access to a per-thread Err shared variable via
- * set_error() and get_error(). It may be used to store an Err object
- * temporarily, so that calling code may choose how to handle a particular
- * error condition.
- */
-public class Clownfish::Err inherits Clownfish::Obj {
-
- CharBuf *mess;
-
- inert void
- init_class();
-
- inert incremented Err*
- new(decremented CharBuf *mess);
-
- inert Err*
- init(Err *self, decremented CharBuf *mess);
-
- public void
- Destroy(Err *self);
-
- public incremented CharBuf*
- To_String(Err *self);
-
- void*
- To_Host(Err *self);
-
- /** Concatenate the supplied argument onto the internal "mess".
- */
- public void
- Cat_Mess(Err *self, const CharBuf *mess);
-
- public CharBuf*
- Get_Mess(Err *self);
-
- /** Add information about the current stack frame onto <code>mess</code>.
- */
- void
- Add_Frame(Err *self, const char *file, int line, const char *func);
-
- public incremented Err*
- Make(Err *self);
-
- /** Set the value of "error", a per-thread Err shared variable.
- */
- public inert void
- set_error(decremented Err *error);
-
- /** Retrieve per-thread Err shared variable "error".
- */
- public inert nullable Err*
- get_error();
-
- /** Run <code>routine</code> within the host's exception handling
- * environment, catching and returning any errors that occur.
- *
- * If an unrecognized host exception is trapped, it will be wrapped in an
- * Err so that it can be handled by Clownfish code.
- *
- * @return an Err, or NULL if no exception occurs.
- */
- public inert incremented nullable Err*
- trap(Cfish_Err_Attempt_t routine, void *context);
-
- /** Print an error message to stderr with some C contextual information.
- * Usually invoked via the WARN(pattern, ...) macro.
- */
- inert void
- warn_at(const char *file, int line, const char *func,
- const char *pattern, ...);
-
- /** Raise an exception. Usually invoked via the THROW macro.
- */
- inert void
- throw_at(VTable *vtable, const char *file, int line, const char *func,
- const char *pattern, ...);
-
- /** Throw an existing exception after tacking on additional context data.
- */
- inert void
- rethrow(Err *error, const char *file, int line, const char *func);
-
- /** Raise an exception. Clean up the supplied message by decrementing its
- * refcount.
- *
- * @param vtable The vtable for the Err class to throw.
- * @param message Error message, to be output verbatim.
- */
- inert void
- throw_mess(VTable *vtable, decremented CharBuf *message);
-
- /** Invoke host exception handling.
- */
- inert void
- do_throw(decremented Err *self);
-
- /** Invoke host warning mechanism. Clean up the supplied message by
- * decrementing its refcount.
- *
- * @param message Error message, to be output verbatim.
- */
- inert void
- warn_mess(decremented CharBuf *message);
-
- /** Create a formatted error message. Ususally invoked via the MAKE_MESS
- * macro.
- */
- inert CharBuf*
- make_mess(const char *file, int line, const char *func,
- const char *pattern, ...);
-
- /** Verify that <code>obj</code> is either NULL or inherits from
- * the class represented by <code>vtable</code>.
- *
- * @return the object.
- */
- inert nullable Obj*
- downcast(Obj *obj, VTable *vtable, const char *file, int line,
- const char *func);
-
- /** Verify that <code>obj</code> is not NULL and inherits from the class
- * represented by <code>vtable</code>.
- *
- * @return the object.
- */
- inert Obj*
- certify(Obj *obj, VTable *vtable, const char *file, int line,
- const char *func);
-
- /** Verify that an object belongs to a subclass and not an abstract class.
- */
- inert inline void
- abstract_class_check(Obj *obj, VTable *vtable);
-
- /** On Windows, return a newly allocated buffer containing the string
- * description for the the last error in the thread.
- */
- inert char*
- win_error();
-}
-
-__C__
-#ifdef CHY_HAS_FUNC_MACRO
- #define CFISH_ERR_FUNC_MACRO CHY_FUNC_MACRO
-#else
- #define CFISH_ERR_FUNC_MACRO NULL
-#endif
-
-#define CFISH_ERR_ADD_FRAME(_error) \
- Cfish_Err_Add_Frame(_error, __FILE__, __LINE__, \
- CFISH_ERR_FUNC_MACRO)
-
-#define CFISH_RETHROW(_error) \
- cfish_Err_rethrow((cfish_Err*)_error, __FILE__, __LINE__, \
- CFISH_ERR_FUNC_MACRO)
-
-/** Macro version of cfish_Err_throw_at which inserts contextual information
- * automatically, provided that the compiler supports the necessary features.
- */
-#ifdef CHY_HAS_VARIADIC_MACROS
- #ifdef CHY_HAS_ISO_VARIADIC_MACROS
- #define CFISH_THROW(_vtable, ...) \
- cfish_Err_throw_at(_vtable, __FILE__, __LINE__, CFISH_ERR_FUNC_MACRO, \
- __VA_ARGS__)
- #define CFISH_WARN(...) \
- cfish_Err_warn_at(__FILE__, __LINE__, CFISH_ERR_FUNC_MACRO, __VA_ARGS__)
- #define CFISH_MAKE_MESS(...) \
- cfish_Err_make_mess(__FILE__, __LINE__, CFISH_ERR_FUNC_MACRO, \
- __VA_ARGS__)
- #elif defined(CHY_HAS_GNUC_VARIADIC_MACROS)
- #define CFISH_THROW(_vtable, args...) \
- cfish_Err_throw_at(_vtable, __FILE__, __LINE__, \
- CFISH_ERR_FUNC_MACRO, ##args)
- #define CFISH_WARN(args...) \
- cfish_Err_warn_at(__FILE__, __LINE__, CFISH_ERR_FUNC_MACRO, ##args)
- #define CFISH_MAKE_MESS(args...) \
- cfish_Err_make_mess(__FILE__, __LINE__, CFISH_ERR_FUNC_MACRO, ##args)
- #endif
-#else
- void
- CFISH_THROW(cfish_VTable *vtable, char* format, ...);
- void
- CFISH_WARN(char* format, ...);
- cfish_CharBuf*
- CFISH_MAKE_MESS(char* format, ...);
-#endif
-
-#define CFISH_DOWNCAST(_obj, _vtable) \
- cfish_Err_downcast((cfish_Obj*)(_obj), (_vtable), \
- __FILE__, __LINE__, CFISH_ERR_FUNC_MACRO)
-
-
-#define CFISH_CERTIFY(_obj, _vtable) \
- cfish_Err_certify((cfish_Obj*)(_obj), (_vtable), \
- __FILE__, __LINE__, CFISH_ERR_FUNC_MACRO)
-
-static CFISH_INLINE void
-cfish_Err_abstract_class_check(cfish_Obj *obj, cfish_VTable *vtable) {
- cfish_VTable *const my_vtable = (cfish_VTable*)((cfish_Dummy*)obj)->vtable;
- if (my_vtable == vtable) {
- cfish_CharBuf *mess = CFISH_MAKE_MESS("%o is an abstract class",
- Cfish_Obj_Get_Class_Name(obj));
- Cfish_Obj_Dec_RefCount(obj);
- cfish_Err_throw_mess(CFISH_ERR, mess);
- }
-}
-
-#define CFISH_ABSTRACT_CLASS_CHECK(_obj, _vtable) \
- cfish_Err_abstract_class_check(((cfish_Obj*)_obj), _vtable)
-
-#ifdef CFISH_USE_SHORT_NAMES
- #define THROW CFISH_THROW
- #define RETHROW CFISH_RETHROW
- #define WARN CFISH_WARN
- #define MAKE_MESS CFISH_MAKE_MESS
- #define ERR_ADD_FRAME CFISH_ERR_ADD_FRAME
- #define ERR_FUNC_MACRO CFISH_ERR_FUNC_MACRO
- #define DOWNCAST CFISH_DOWNCAST
- #define CERTIFY CFISH_CERTIFY
- #define ABSTRACT_CLASS_CHECK CFISH_ABSTRACT_CLASS_CHECK
-#endif
-__END_C__
-
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/ddff7ce9/core/Clownfish/Hash.c
----------------------------------------------------------------------
diff --git a/core/Clownfish/Hash.c b/core/Clownfish/Hash.c
deleted file mode 100644
index e18f512..0000000
--- a/core/Clownfish/Hash.c
+++ /dev/null
@@ -1,434 +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_HASH
-#define C_CFISH_HASHTOMBSTONE
-#define CFISH_USE_SHORT_NAMES
-#define CHY_USE_SHORT_NAMES
-
-#include <string.h>
-#include <stdlib.h>
-
-#include "Clownfish/VTable.h"
-
-#include "Clownfish/Hash.h"
-#include "Clownfish/CharBuf.h"
-#include "Clownfish/Err.h"
-#include "Clownfish/VArray.h"
-#include "Clownfish/Util/Memory.h"
-
-static HashTombStone *TOMBSTONE;
-
-#define HashEntry cfish_HashEntry
-
-typedef struct HashEntry {
- Obj *key;
- Obj *value;
- int32_t hash_sum;
-} HashEntry;
-
-// Reset the iterator. Hash_Iterate must be called to restart iteration.
-static INLINE void
-SI_kill_iter(Hash *self);
-
-// Return the entry associated with the key, if any.
-static INLINE HashEntry*
-SI_fetch_entry(Hash *self, const Obj *key, int32_t hash_sum);
-
-// Double the number of buckets and redistribute all entries.
-static INLINE HashEntry*
-SI_rebuild_hash(Hash *self);
-
-void
-Hash_init_class() {
- TOMBSTONE = (HashTombStone*)VTable_Make_Obj(HASHTOMBSTONE);
-}
-
-Hash*
-Hash_new(uint32_t capacity) {
- Hash *self = (Hash*)VTable_Make_Obj(HASH);
- return Hash_init(self, capacity);
-}
-
-Hash*
-Hash_init(Hash *self, uint32_t capacity) {
- // Allocate enough space to hold the requested number of elements without
- // triggering a rebuild.
- uint32_t requested_capacity = capacity < INT32_MAX ? capacity : INT32_MAX;
- uint32_t threshold;
- capacity = 16;
- while (1) {
- threshold = (capacity / 3) * 2;
- if (threshold > requested_capacity) { break; }
- capacity *= 2;
- }
-
- // Init.
- self->size = 0;
- self->iter_tick = -1;
-
- // Derive.
- self->capacity = capacity;
- self->entries = (HashEntry*)CALLOCATE(capacity, sizeof(HashEntry));
- self->threshold = threshold;
-
- return self;
-}
-
-void
-Hash_destroy(Hash *self) {
- if (self->entries) {
- Hash_Clear(self);
- FREEMEM(self->entries);
- }
- SUPER_DESTROY(self, HASH);
-}
-
-Hash*
-Hash_dump(Hash *self) {
- Hash *dump = Hash_new(self->size);
- Obj *key;
- Obj *value;
-
- Hash_Iterate(self);
- while (Hash_Next(self, &key, &value)) {
- // Since JSON only supports text hash keys, Dump() can only support
- // text hash keys.
- CERTIFY(key, CHARBUF);
- Hash_Store(dump, key, Obj_Dump(value));
- }
-
- return dump;
-}
-
-Obj*
-Hash_load(Hash *self, Obj *dump) {
- Hash *source = (Hash*)CERTIFY(dump, HASH);
- CharBuf *class_name = (CharBuf*)Hash_Fetch_Str(source, "_class", 6);
- UNUSED_VAR(self);
-
- // Assume that the presence of the "_class" key paired with a valid class
- // name indicates the output of a Dump rather than an ordinary Hash. */
- if (class_name && CB_Is_A(class_name, CHARBUF)) {
- VTable *vtable = VTable_fetch_vtable(class_name);
-
- if (!vtable) {
- CharBuf *parent_class = VTable_find_parent_class(class_name);
- if (parent_class) {
- VTable *parent = VTable_singleton(parent_class, NULL);
- vtable = VTable_singleton(class_name, parent);
- DECREF(parent_class);
- }
- else {
- // TODO: Fix Hash_Load() so that it works with ordinary hash
- // keys named "_class".
- THROW(ERR, "Can't find class '%o'", class_name);
- }
- }
-
- // Dispatch to an alternate Load() method.
- if (vtable) {
- Obj_Load_t load = METHOD_PTR(vtable, Cfish_Obj_Load);
- if (load == Obj_load) {
- THROW(ERR, "Abstract method Load() not defined for %o",
- VTable_Get_Name(vtable));
- }
- else if (load != (Obj_Load_t)Hash_load) { // stop inf loop
- return VTable_Load_Obj(vtable, dump);
- }
- }
- }
-
- // It's an ordinary Hash.
- Hash *loaded = Hash_new(source->size);
- Obj *key;
- Obj *value;
- Hash_Iterate(source);
- while (Hash_Next(source, &key, &value)) {
- Hash_Store(loaded, key, Obj_Load(value, value));
- }
-
- return (Obj*)loaded;
-
-}
-
-void
-Hash_clear(Hash *self) {
- HashEntry *entry = (HashEntry*)self->entries;
- HashEntry *const limit = entry + self->capacity;
-
- // Iterate through all entries.
- for (; entry < limit; entry++) {
- if (!entry->key) { continue; }
- DECREF(entry->key);
- DECREF(entry->value);
- entry->key = NULL;
- entry->value = NULL;
- entry->hash_sum = 0;
- }
-
- self->size = 0;
-}
-
-void
-Hash_do_store(Hash *self, Obj *key, Obj *value,
- int32_t hash_sum, bool use_this_key) {
- HashEntry *entries = self->size >= self->threshold
- ? SI_rebuild_hash(self)
- : (HashEntry*)self->entries;
- uint32_t tick = hash_sum;
- const uint32_t mask = self->capacity - 1;
-
- while (1) {
- tick &= mask;
- HashEntry *entry = entries + tick;
- if (entry->key == (Obj*)TOMBSTONE || !entry->key) {
- if (entry->key == (Obj*)TOMBSTONE) {
- // Take note of diminished tombstone clutter.
- self->threshold++;
- }
- entry->key = use_this_key
- ? key
- : Hash_Make_Key(self, key, hash_sum);
- entry->value = value;
- entry->hash_sum = hash_sum;
- self->size++;
- break;
- }
- else if (entry->hash_sum == hash_sum
- && Obj_Equals(key, entry->key)
- ) {
- DECREF(entry->value);
- entry->value = value;
- break;
- }
- tick++; // linear scan
- }
-}
-
-void
-Hash_store(Hash *self, Obj *key, Obj *value) {
- Hash_do_store(self, key, value, Obj_Hash_Sum(key), false);
-}
-
-void
-Hash_store_str(Hash *self, const char *key, size_t key_len, Obj *value) {
- ZombieCharBuf *key_buf = ZCB_WRAP_STR((char*)key, key_len);
- Hash_do_store(self, (Obj*)key_buf, value,
- ZCB_Hash_Sum(key_buf), false);
-}
-
-Obj*
-Hash_make_key(Hash *self, Obj *key, int32_t hash_sum) {
- UNUSED_VAR(self);
- UNUSED_VAR(hash_sum);
- return Obj_Clone(key);
-}
-
-Obj*
-Hash_fetch_str(Hash *self, const char *key, size_t key_len) {
- ZombieCharBuf *key_buf = ZCB_WRAP_STR(key, key_len);
- return Hash_fetch(self, (Obj*)key_buf);
-}
-
-static INLINE HashEntry*
-SI_fetch_entry(Hash *self, const Obj *key, int32_t hash_sum) {
- uint32_t tick = hash_sum;
- HashEntry *const entries = (HashEntry*)self->entries;
- HashEntry *entry;
-
- while (1) {
- tick &= self->capacity - 1;
- entry = entries + tick;
- if (!entry->key) {
- // Failed to find the key, so return NULL.
- return NULL;
- }
- else if (entry->hash_sum == hash_sum
- && Obj_Equals(key, entry->key)
- ) {
- return entry;
- }
- tick++;
- }
-}
-
-Obj*
-Hash_fetch(Hash *self, const Obj *key) {
- HashEntry *entry = SI_fetch_entry(self, key, Obj_Hash_Sum(key));
- return entry ? entry->value : NULL;
-}
-
-Obj*
-Hash_delete(Hash *self, const Obj *key) {
- HashEntry *entry = SI_fetch_entry(self, key, Obj_Hash_Sum(key));
- if (entry) {
- Obj *value = entry->value;
- DECREF(entry->key);
- entry->key = (Obj*)TOMBSTONE;
- entry->value = NULL;
- entry->hash_sum = 0;
- self->size--;
- self->threshold--; // limit number of tombstones
- return value;
- }
- else {
- return NULL;
- }
-}
-
-Obj*
-Hash_delete_str(Hash *self, const char *key, size_t key_len) {
- ZombieCharBuf *key_buf = ZCB_WRAP_STR(key, key_len);
- return Hash_delete(self, (Obj*)key_buf);
-}
-
-uint32_t
-Hash_iterate(Hash *self) {
- SI_kill_iter(self);
- return self->size;
-}
-
-static INLINE void
-SI_kill_iter(Hash *self) {
- self->iter_tick = -1;
-}
-
-bool
-Hash_next(Hash *self, Obj **key, Obj **value) {
- while (1) {
- if (++self->iter_tick >= (int32_t)self->capacity) {
- // Bail since we've completed the iteration.
- --self->iter_tick;
- *key = NULL;
- *value = NULL;
- return false;
- }
- else {
- HashEntry *const entry
- = (HashEntry*)self->entries + self->iter_tick;
- if (entry->key && entry->key != (Obj*)TOMBSTONE) {
- // Success!
- *key = entry->key;
- *value = entry->value;
- return true;
- }
- }
- }
-}
-
-Obj*
-Hash_find_key(Hash *self, const Obj *key, int32_t hash_sum) {
- HashEntry *entry = SI_fetch_entry(self, key, hash_sum);
- return entry ? entry->key : NULL;
-}
-
-VArray*
-Hash_keys(Hash *self) {
- Obj *key;
- Obj *val;
- VArray *keys = VA_new(self->size);
- Hash_Iterate(self);
- while (Hash_Next(self, &key, &val)) {
- VA_push(keys, INCREF(key));
- }
- return keys;
-}
-
-VArray*
-Hash_values(Hash *self) {
- Obj *key;
- Obj *val;
- VArray *values = VA_new(self->size);
- Hash_Iterate(self);
- while (Hash_Next(self, &key, &val)) { VA_push(values, INCREF(val)); }
- return values;
-}
-
-bool
-Hash_equals(Hash *self, Obj *other) {
- Hash *twin = (Hash*)other;
- Obj *key;
- Obj *val;
-
- if (twin == self) { return true; }
- if (!Obj_Is_A(other, HASH)) { return false; }
- if (self->size != twin->size) { return false; }
-
- Hash_Iterate(self);
- while (Hash_Next(self, &key, &val)) {
- Obj *other_val = Hash_Fetch(twin, key);
- if (!other_val || !Obj_Equals(other_val, val)) { return false; }
- }
-
- return true;
-}
-
-uint32_t
-Hash_get_capacity(Hash *self) {
- return self->capacity;
-}
-
-uint32_t
-Hash_get_size(Hash *self) {
- return self->size;
-}
-
-static INLINE HashEntry*
-SI_rebuild_hash(Hash *self) {
- HashEntry *old_entries = (HashEntry*)self->entries;
- HashEntry *entry = old_entries;
- HashEntry *limit = old_entries + self->capacity;
-
- SI_kill_iter(self);
- self->capacity *= 2;
- self->threshold = (self->capacity / 3) * 2;
- self->entries = (HashEntry*)CALLOCATE(self->capacity, sizeof(HashEntry));
- self->size = 0;
-
- for (; entry < limit; entry++) {
- if (!entry->key || entry->key == (Obj*)TOMBSTONE) {
- continue;
- }
- Hash_do_store(self, entry->key, entry->value,
- entry->hash_sum, true);
- }
-
- FREEMEM(old_entries);
-
- return (HashEntry*)self->entries;
-}
-
-/***************************************************************************/
-
-uint32_t
-HashTombStone_get_refcount(HashTombStone* self) {
- CHY_UNUSED_VAR(self);
- return 1;
-}
-
-HashTombStone*
-HashTombStone_inc_refcount(HashTombStone* self) {
- return self;
-}
-
-uint32_t
-HashTombStone_dec_refcount(HashTombStone* self) {
- UNUSED_VAR(self);
- return 1;
-}
-
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/ddff7ce9/core/Clownfish/Hash.cfh
----------------------------------------------------------------------
diff --git a/core/Clownfish/Hash.cfh b/core/Clownfish/Hash.cfh
deleted file mode 100644
index 6397368..0000000
--- a/core/Clownfish/Hash.cfh
+++ /dev/null
@@ -1,159 +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;
-
-/**
- * Hashtable.
- *
- * Values are stored by reference and may be any kind of Obj. By default, keys
- * are cloned and so must belong to a class that implements Clone(); however,
- * this behavior can be changed by overridding Make_Key(), e.g. to implement
- * efficient hash sets.
- */
-class Clownfish::Hash inherits Clownfish::Obj {
-
- void *entries;
- uint32_t capacity;
- uint32_t size;
- uint32_t threshold; /* rehashing trigger point */
- int32_t iter_tick; /* used when iterating */
-
- inert void
- init_class();
-
- inert incremented Hash*
- new(uint32_t capacity = 0);
-
- /**
- * @param capacity The number of elements that the hash will be asked to
- * hold initially.
- */
- inert Hash*
- init(Hash *self, uint32_t capacity = 0);
-
- /** Empty the hash of all key-value pairs.
- */
- void
- Clear(Hash *self);
-
- /** Store a key-value pair. If <code>key</code> is not already present,
- * Make_Key() will be called to manufacture the internally used key.
- */
- void
- Store(Hash *self, Obj *key, decremented Obj *value);
-
- void
- Store_Str(Hash *self, const char *str, size_t len,
- decremented Obj *value);
-
- /** Fetch the value associated with <code>key</code>.
- *
- * @return the value, or NULL if <code>key</code> is not present.
- */
- nullable Obj*
- Fetch(Hash *self, const Obj *key);
-
- nullable Obj*
- Fetch_Str(Hash *self, const char *key, size_t key_len);
-
- /** Attempt to delete a key-value pair from the hash.
- *
- * @return the value if <code>key</code> exists and thus deletion
- * succeeds; otherwise NULL.
- */
- incremented nullable Obj*
- Delete(Hash *self, const Obj *key);
-
- incremented nullable Obj*
- Delete_Str(Hash *self, const char *key, size_t key_ley);
-
- /** Prepare to iterate over all the key-value pairs in the hash.
- *
- * @return the number of pairs which will be iterated over.
- */
- uint32_t
- Iterate(Hash *self);
-
- /** Retrieve the next key-value pair from the hash, setting the supplied
- * pointers to point at them.
- *
- * @return true while iterating, false when the iterator has been
- * exhausted.
- */
- bool
- Next(Hash *self, Obj **key, Obj **value);
-
- /** Search for a key which Equals the key supplied, and return the key
- * rather than its value.
- */
- nullable Obj*
- Find_Key(Hash *self, const Obj *key, int32_t hash_sum);
-
- /** Return an VArray of pointers to the hash's keys.
- */
- incremented VArray*
- Keys(Hash *self);
-
- /** Return an VArray of pointers to the hash's values.
- */
- incremented VArray*
- Values(Hash *self);
-
- /** Create a key to be stored within the hash entry. Implementations must
- * supply an object which produces the same Hash_Sum() value and tests
- * true for Equals(). By default, calls Clone().
- */
- public incremented Obj*
- Make_Key(Hash *self, Obj *key, int32_t hash_sum);
-
- uint32_t
- Get_Capacity(Hash *self);
-
- /** Accessor for Hash's "size" member.
- *
- * @return the number of key-value pairs.
- */
- public uint32_t
- Get_Size(Hash *self);
-
- public bool
- Equals(Hash *self, Obj *other);
-
- public incremented Hash*
- Dump(Hash *self);
-
- public incremented Obj*
- Load(Hash *self, Obj *dump);
-
- public void
- Destroy(Hash *self);
-}
-
-class Clownfish::Hash::HashTombStone
- inherits Clownfish::Obj {
-
- uint32_t
- Get_RefCount(HashTombStone* self);
-
- incremented HashTombStone*
- Inc_RefCount(HashTombStone* self);
-
- uint32_t
- Dec_RefCount(HashTombStone* self);
-}
-
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/ddff7ce9/core/Clownfish/LockFreeRegistry.c
----------------------------------------------------------------------
diff --git a/core/Clownfish/LockFreeRegistry.c b/core/Clownfish/LockFreeRegistry.c
deleted file mode 100644
index 8745071..0000000
--- a/core/Clownfish/LockFreeRegistry.c
+++ /dev/null
@@ -1,129 +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_LOCKFREEREGISTRY
-#define CFISH_USE_SHORT_NAMES
-#define CHY_USE_SHORT_NAMES
-
-#include "Clownfish/LockFreeRegistry.h"
-#include "Clownfish/Err.h"
-#include "Clownfish/VTable.h"
-#include "Clownfish/Util/Atomic.h"
-#include "Clownfish/Util/Memory.h"
-
-typedef struct cfish_LFRegEntry {
- Obj *key;
- Obj *value;
- int32_t hash_sum;
- struct cfish_LFRegEntry *volatile next;
-} cfish_LFRegEntry;
-#define LFRegEntry cfish_LFRegEntry
-
-LockFreeRegistry*
-LFReg_new(size_t capacity) {
- LockFreeRegistry *self
- = (LockFreeRegistry*)VTable_Make_Obj(LOCKFREEREGISTRY);
- return LFReg_init(self, capacity);
-}
-
-LockFreeRegistry*
-LFReg_init(LockFreeRegistry *self, size_t capacity) {
- self->capacity = capacity;
- self->entries = CALLOCATE(capacity, sizeof(void*));
- return self;
-}
-
-bool
-LFReg_register(LockFreeRegistry *self, Obj *key, Obj *value) {
- LFRegEntry *new_entry = NULL;
- int32_t hash_sum = Obj_Hash_Sum(key);
- size_t bucket = (uint32_t)hash_sum % self->capacity;
- LFRegEntry *volatile *entries = (LFRegEntry*volatile*)self->entries;
- LFRegEntry *volatile *slot = &(entries[bucket]);
-
- // Proceed through the linked list. Bail out if the key has already been
- // registered.
-FIND_END_OF_LINKED_LIST:
- while (*slot) {
- LFRegEntry *entry = *slot;
- if (entry->hash_sum == hash_sum) {
- if (Obj_Equals(key, entry->key)) {
- return false;
- }
- }
- slot = &(entry->next);
- }
-
- // We've found an empty slot. Create the new entry.
- if (!new_entry) {
- new_entry = (LFRegEntry*)MALLOCATE(sizeof(LFRegEntry));
- new_entry->hash_sum = hash_sum;
- new_entry->key = INCREF(key);
- new_entry->value = INCREF(value);
- new_entry->next = NULL;
- }
-
- /* Attempt to append the new node onto the end of the linked list.
- * However, if another thread filled the slot since we found it (perhaps
- * while we were allocating that new node), the compare-and-swap will
- * fail. If that happens, we have to go back and find the new end of the
- * linked list, then try again. */
- if (!Atomic_cas_ptr((void*volatile*)slot, NULL, new_entry)) {
- goto FIND_END_OF_LINKED_LIST;
- }
-
- return true;
-}
-
-Obj*
-LFReg_fetch(LockFreeRegistry *self, Obj *key) {
- int32_t hash_sum = Obj_Hash_Sum(key);
- size_t bucket = (uint32_t)hash_sum % self->capacity;
- LFRegEntry **entries = (LFRegEntry**)self->entries;
- LFRegEntry *entry = entries[bucket];
-
- while (entry) {
- if (entry->hash_sum == hash_sum) {
- if (Obj_Equals(key, entry->key)) {
- return entry->value;
- }
- }
- entry = entry->next;
- }
-
- return NULL;
-}
-
-void
-LFReg_destroy(LockFreeRegistry *self) {
- LFRegEntry **entries = (LFRegEntry**)self->entries;
-
- for (size_t i = 0; i < self->capacity; i++) {
- LFRegEntry *entry = entries[i];
- while (entry) {
- LFRegEntry *next_entry = entry->next;
- DECREF(entry->key);
- DECREF(entry->value);
- FREEMEM(entry);
- entry = next_entry;
- }
- }
- FREEMEM(self->entries);
-
- SUPER_DESTROY(self, LOCKFREEREGISTRY);
-}
-
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/ddff7ce9/core/Clownfish/LockFreeRegistry.cfh
----------------------------------------------------------------------
diff --git a/core/Clownfish/LockFreeRegistry.cfh b/core/Clownfish/LockFreeRegistry.cfh
deleted file mode 100644
index 2a3d62a..0000000
--- a/core/Clownfish/LockFreeRegistry.cfh
+++ /dev/null
@@ -1,45 +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;
-
-/** Specialized lock free hash table for storing VTables.
- */
-class Clownfish::LockFreeRegistry cnick LFReg inherits Clownfish::Obj {
-
- size_t capacity;
- void *entries;
-
- inert incremented LockFreeRegistry*
- new(size_t capacity);
-
- inert LockFreeRegistry*
- init(LockFreeRegistry *self, size_t capacity);
-
- public void
- Destroy(LockFreeRegistry *self);
-
- bool
- Register(LockFreeRegistry *self, Obj *key, Obj *value);
-
- nullable Obj*
- Fetch(LockFreeRegistry *self, Obj *key);
-
- void*
- To_Host(LockFreeRegistry *self);
-}
-
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/ddff7ce9/core/Clownfish/Method.c
----------------------------------------------------------------------
diff --git a/core/Clownfish/Method.c b/core/Clownfish/Method.c
deleted file mode 100644
index 235226a..0000000
--- a/core/Clownfish/Method.c
+++ /dev/null
@@ -1,64 +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_METHOD
-#define CFISH_USE_SHORT_NAMES
-#define CHY_USE_SHORT_NAMES
-
-#include "Clownfish/Method.h"
-#include "Clownfish/CharBuf.h"
-#include "Clownfish/Err.h"
-#include "Clownfish/VTable.h"
-
-Method*
-Method_new(const CharBuf *name, cfish_method_t callback_func, size_t offset) {
- Method *self = (Method*)VTable_Make_Obj(METHOD);
- return Method_init(self, name, callback_func, offset);
-}
-
-Method*
-Method_init(Method *self, const CharBuf *name, cfish_method_t callback_func,
- size_t offset) {
- self->name = CB_Clone(name);
- self->callback_func = callback_func;
- self->offset = offset;
- return self;
-}
-
-void
-Method_destroy(Method *self) {
- THROW(ERR, "Insane attempt to destroy Method '%o'", self->name);
-}
-
-Obj*
-Method_inc_refcount(Method *self) {
- return (Obj*)self;
-}
-
-uint32_t
-Method_dec_refcount(Method *self) {
- UNUSED_VAR(self);
- return 1;
-}
-
-uint32_t
-Method_get_refcount(Method *self) {
- UNUSED_VAR(self);
- // See comments in VTable.c
- return 1;
-}
-
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/ddff7ce9/core/Clownfish/Method.cfh
----------------------------------------------------------------------
diff --git a/core/Clownfish/Method.cfh b/core/Clownfish/Method.cfh
deleted file mode 100644
index 5cac0b2..0000000
--- a/core/Clownfish/Method.cfh
+++ /dev/null
@@ -1,48 +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 {
-
- CharBuf *name;
- cfish_method_t callback_func;
- size_t offset;
-
- inert Method*
- new(const CharBuf *name, cfish_method_t callback_func, size_t offset);
-
- inert Method*
- init(Method *self, const CharBuf *name, cfish_method_t callback_func,
- size_t offset);
-
- 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/ddff7ce9/core/Clownfish/Num.c
----------------------------------------------------------------------
diff --git a/core/Clownfish/Num.c b/core/Clownfish/Num.c
deleted file mode 100644
index 63641dc..0000000
--- a/core/Clownfish/Num.c
+++ /dev/null
@@ -1,395 +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 C_CFISH_VIEWCHARBUF
-#define CFISH_USE_SHORT_NAMES
-#define CHY_USE_SHORT_NAMES
-
-#include "Clownfish/Num.h"
-#include "Clownfish/CharBuf.h"
-#include "Clownfish/Err.h"
-#include "Clownfish/VTable.h"
-
-Num*
-Num_init(Num *self) {
- ABSTRACT_CLASS_CHECK(self, NUM);
- return self;
-}
-
-bool
-Num_equals(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(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;
-}
-
-CharBuf*
-FloatNum_to_string(FloatNum *self) {
- return CB_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(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;
-}
-
-CharBuf*
-IntNum_to_string(IntNum *self) {
- return CB_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(Float32 *self) {
- return self->value;
-}
-
-void
-Float32_set_value(Float32 *self, float value) {
- self->value = value;
-}
-
-double
-Float32_to_f64(Float32 *self) {
- return self->value;
-}
-
-int64_t
-Float32_to_i64(Float32 *self) {
- return (int64_t)self->value;
-}
-
-int32_t
-Float32_hash_sum(Float32 *self) {
- return *(int32_t*)&self->value;
-}
-
-Float32*
-Float32_clone(Float32 *self) {
- return Float32_new(self->value);
-}
-
-void
-Float32_mimic(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(Float64 *self) {
- return self->value;
-}
-
-void
-Float64_set_value(Float64 *self, double value) {
- self->value = value;
-}
-
-double
-Float64_to_f64(Float64 *self) {
- return self->value;
-}
-
-int64_t
-Float64_to_i64(Float64 *self) {
- return (int64_t)self->value;
-}
-
-Float64*
-Float64_clone(Float64 *self) {
- return Float64_new(self->value);
-}
-
-void
-Float64_mimic(Float64 *self, Obj *other) {
- Float64 *twin = (Float64*)CERTIFY(other, FLOAT64);
- self->value = twin->value;
-}
-
-int32_t
-Float64_hash_sum(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(Integer32 *self) {
- return self->value;
-}
-
-void
-Int32_set_value(Integer32 *self, int32_t value) {
- self->value = value;
-}
-
-double
-Int32_to_f64(Integer32 *self) {
- return self->value;
-}
-
-int64_t
-Int32_to_i64(Integer32 *self) {
- return self->value;
-}
-
-Integer32*
-Int32_clone(Integer32 *self) {
- return Int32_new(self->value);
-}
-
-void
-Int32_mimic(Integer32 *self, Obj *other) {
- Integer32 *twin = (Integer32*)CERTIFY(other, INTEGER32);
- self->value = twin->value;
-}
-
-int32_t
-Int32_hash_sum(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(Integer64 *self) {
- return self->value;
-}
-
-void
-Int64_set_value(Integer64 *self, int64_t value) {
- self->value = value;
-}
-
-double
-Int64_to_f64(Integer64 *self) {
- return (double)self->value;
-}
-
-int64_t
-Int64_to_i64(Integer64 *self) {
- return self->value;
-}
-
-Integer64*
-Int64_clone(Integer64 *self) {
- return Int64_new(self->value);
-}
-
-void
-Int64_mimic(Integer64 *self, Obj *other) {
- Integer64 *twin = (Integer64*)CERTIFY(other, INTEGER64);
- self->value = twin->value;
-}
-
-int32_t
-Int64_hash_sum(Integer64 *self) {
- int32_t *ints = (int32_t*)&self->value;
- return ints[0] ^ ints[1];
-}
-
-bool
-Int64_equals(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 = CB_newf("true");
- Bool_false_singleton = (BoolNum*)VTable_Make_Obj(BOOLNUM);
- Bool_false_singleton->value = false;
- Bool_false_singleton->string = CB_newf("false");
-}
-
-BoolNum*
-Bool_singleton(bool value) {
- return value ? CFISH_TRUE : CFISH_FALSE;
-}
-
-void
-Bool_destroy(BoolNum *self) {
- if (self && self != CFISH_TRUE && self != CFISH_FALSE) {
- SUPER_DESTROY(self, BOOLNUM);
- }
-}
-
-bool
-Bool_get_value(BoolNum *self) {
- return self->value;
-}
-
-double
-Bool_to_f64(BoolNum *self) {
- return (double)self->value;
-}
-
-int64_t
-Bool_to_i64(BoolNum *self) {
- return self->value;
-}
-
-bool
-Bool_to_bool(BoolNum *self) {
- return self->value;
-}
-
-BoolNum*
-Bool_clone(BoolNum *self) {
- return self;
-}
-
-int32_t
-Bool_hash_sum(BoolNum *self) {
- int64_t hash_sum = PTR_TO_I64(self) + self->value;
- return (int32_t)hash_sum;
-}
-
-CharBuf*
-Bool_to_string(BoolNum *self) {
- return (CharBuf*)CB_Inc_RefCount(self->string);
-}
-
-bool
-Bool_equals(BoolNum *self, Obj *other) {
- return self == (BoolNum*)other;
-}
-
-BoolNum*
-Bool_inc_refcount(BoolNum *self) {
- return self;
-}
-
-uint32_t
-Bool_dec_refcount(BoolNum *self) {
- UNUSED_VAR(self);
- return 1;
-}
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/ddff7ce9/core/Clownfish/Num.cfh
----------------------------------------------------------------------
diff --git a/core/Clownfish/Num.cfh b/core/Clownfish/Num.cfh
deleted file mode 100644
index 3f6a8d6..0000000
--- a/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 CharBuf*
- 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 CharBuf*
- 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;
- CharBuf *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 CharBuf*
- 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/ddff7ce9/core/Clownfish/Obj.c
----------------------------------------------------------------------
diff --git a/core/Clownfish/Obj.c b/core/Clownfish/Obj.c
deleted file mode 100644
index f8f6e2d..0000000
--- a/core/Clownfish/Obj.c
+++ /dev/null
@@ -1,105 +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 <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "Clownfish/Obj.h"
-#include "Clownfish/CharBuf.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(Obj *self) {
- FREEMEM(self);
-}
-
-int32_t
-Obj_hash_sum(Obj *self) {
- int64_t hash_sum = PTR_TO_I64(self);
- return (int32_t)hash_sum;
-}
-
-bool
-Obj_is_a(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(Obj *self, Obj *other) {
- return (self == other);
-}
-
-CharBuf*
-Obj_to_string(Obj *self) {
-#if (SIZEOF_PTR == 4)
- return CB_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 CB_newf("%o@0x%x32%x32", Obj_Get_Class_Name(self), address_hi,
- address_lo);
-#else
- #error "Unexpected pointer size."
-#endif
-}
-
-bool
-Obj_to_bool(Obj *self) {
- return !!Obj_To_I64(self);
-}
-
-Obj*
-Obj_dump(Obj *self) {
- return (Obj*)Obj_To_String(self);
-}
-
-VTable*
-Obj_get_vtable(Obj *self) {
- return self->vtable;
-}
-
-CharBuf*
-Obj_get_class_name(Obj *self) {
- return VTable_Get_Name(self->vtable);
-}
-
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/ddff7ce9/core/Clownfish/Obj.cfh
----------------------------------------------------------------------
diff --git a/core/Clownfish/Obj.cfh b/core/Clownfish/Obj.cfh
deleted file mode 100644
index 17c39c5..0000000
--- a/core/Clownfish/Obj.cfh
+++ /dev/null
@@ -1,212 +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);
-
- /** Zero argument factory constructor.
- */
- public abstract incremented Obj*
- Make(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 CharBuf*
- 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 CharBuf*
- 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);
-
- /** Return a representation of the object using only scalars, hashes, and
- * arrays. Some implementations support JSON serialization via Dump() and
- * its companion method, Load(); for others, Dump() is only a debugging
- * aid. The default simply calls To_String().
- */
- public incremented Obj*
- Dump(Obj *self);
-
- /** Create an object from the output of a call to Dump().
- *
- * @param dump The output of Dump().
- */
- public abstract incremented Obj*
- Load(Obj *self, Obj *dump);
-
- /** 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/ddff7ce9/core/Clownfish/Test.c
----------------------------------------------------------------------
diff --git a/core/Clownfish/Test.c b/core/Clownfish/Test.c
deleted file mode 100644
index 546af45..0000000
--- a/core/Clownfish/Test.c
+++ /dev/null
@@ -1,58 +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/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*)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/ddff7ce9/core/Clownfish/Test.cfh
----------------------------------------------------------------------
diff --git a/core/Clownfish/Test.cfh b/core/Clownfish/Test.cfh
deleted file mode 100644
index 68dc8bc..0000000
--- a/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/ddff7ce9/core/Clownfish/Test/TestByteBuf.c
----------------------------------------------------------------------
diff --git a/core/Clownfish/Test/TestByteBuf.c b/core/Clownfish/Test/TestByteBuf.c
deleted file mode 100644
index 159a8db..0000000
--- a/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(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/ddff7ce9/core/Clownfish/Test/TestByteBuf.cfh
----------------------------------------------------------------------
diff --git a/core/Clownfish/Test/TestByteBuf.cfh b/core/Clownfish/Test/TestByteBuf.cfh
deleted file mode 100644
index 3335c95..0000000
--- a/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);
-}
-
-