fx: implement a proper value-type mechanism
This commit is contained in:
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
set(source_dirs hash)
|
set(source_dirs hash int float)
|
||||||
export_fx_namespace_details(fx)
|
export_fx_namespace_details(fx)
|
||||||
|
|||||||
@@ -1,84 +1,19 @@
|
|||||||
#include <fx/bool.h>
|
#include <fx/bool.h>
|
||||||
#include <fx/stream.h>
|
#include <fx/macros.h>
|
||||||
|
#include <fx/value-type.h>
|
||||||
/*** PRIVATE DATA *************************************************************/
|
|
||||||
|
|
||||||
struct fx_bool_p {
|
|
||||||
bool b_value;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*** PRIVATE FUNCTIONS ********************************************************/
|
|
||||||
|
|
||||||
static void bool_set_value(struct fx_bool_p *i, bool v)
|
|
||||||
{
|
|
||||||
i->b_value = v;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool bool_get_value(struct fx_bool_p *i)
|
|
||||||
{
|
|
||||||
return i->b_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*** PUBLIC FUNCTIONS *********************************************************/
|
|
||||||
|
|
||||||
fx_bool *fx_bool_create(bool value)
|
|
||||||
{
|
|
||||||
fx_bool *i = fx_object_create(FX_TYPE_BOOL);
|
|
||||||
if (!i) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct fx_bool_p *p = fx_object_get_private(i, FX_TYPE_BOOL);
|
|
||||||
p->b_value = value;
|
|
||||||
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
void fx_bool_set_value(fx_bool *i, bool v)
|
|
||||||
{
|
|
||||||
FX_CLASS_DISPATCH_STATIC_V(FX_TYPE_BOOL, bool_set_value, i, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool fx_bool_get_value(const fx_bool *i)
|
|
||||||
{
|
|
||||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_BOOL, bool_get_value, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*** VIRTUAL FUNCTIONS ********************************************************/
|
|
||||||
|
|
||||||
static void bool_init(fx_object *obj, void *priv)
|
|
||||||
{
|
|
||||||
struct fx_bool_p *i = priv;
|
|
||||||
|
|
||||||
i->b_value = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void bool_fini(fx_object *obj, void *priv)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static void bool_to_string(const fx_object *obj, fx_stream *out)
|
|
||||||
{
|
|
||||||
struct fx_bool_p *i = fx_object_get_private(obj, FX_TYPE_BOOL);
|
|
||||||
if (i->b_value == false) {
|
|
||||||
fx_stream_write_cstr(out, "false", NULL);
|
|
||||||
} else {
|
|
||||||
fx_stream_write_cstr(out, "true", NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*** CLASS DEFINITION *********************************************************/
|
/*** CLASS DEFINITION *********************************************************/
|
||||||
|
|
||||||
FX_TYPE_CLASS_BEGIN(fx_bool)
|
FX_TYPE_CLASS_BEGIN(fx_bool)
|
||||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||||
FX_INTERFACE_ENTRY(to_string) = bool_to_string;
|
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||||
FX_TYPE_CLASS_END(fx_bool)
|
FX_TYPE_CLASS_END(fx_bool)
|
||||||
|
|
||||||
FX_TYPE_DEFINITION_BEGIN(fx_bool)
|
FX_TYPE_DEFINITION_BEGIN(fx_bool)
|
||||||
FX_TYPE_ID(0x9c8453bf, 0xfc92, 0x4b0a, 0xbcaf, 0xd0c6cdba9310);
|
__FX_VALUE_TYPE_ID(BOOL);
|
||||||
|
FX_TYPE_EXTENDS(FX_TYPE_VALUE_TYPE);
|
||||||
|
FX_TYPE_NAME("fx.bool");
|
||||||
FX_TYPE_CLASS(fx_bool_class);
|
FX_TYPE_CLASS(fx_bool_class);
|
||||||
FX_TYPE_INSTANCE_PRIVATE(struct fx_bool_p);
|
FX_TYPE_INSTANCE_PRIVATE(bool);
|
||||||
FX_TYPE_INSTANCE_INIT(bool_init);
|
|
||||||
FX_TYPE_INSTANCE_FINI(bool_fini);
|
|
||||||
FX_TYPE_DEFINITION_END(fx_bool)
|
FX_TYPE_DEFINITION_END(fx_bool)
|
||||||
|
|||||||
@@ -244,6 +244,15 @@ enum fx_status fx_bstr_write_cstr(
|
|||||||
return bstr_puts(str, s, nr_written);
|
return bstr_puts(str, s, nr_written);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum fx_status fx_bstr_write_wstr(
|
||||||
|
struct fx_bstr *str,
|
||||||
|
const fx_wchar *s,
|
||||||
|
size_t *nr_written)
|
||||||
|
{
|
||||||
|
/* TODO */
|
||||||
|
return FX_ERR_NOT_SUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
enum fx_status fx_bstr_write_cstr_list(
|
enum fx_status fx_bstr_write_cstr_list(
|
||||||
struct fx_bstr *str,
|
struct fx_bstr *str,
|
||||||
const char **strs,
|
const char **strs,
|
||||||
@@ -348,8 +357,11 @@ enum fx_status fx_bstr_write_fmt(
|
|||||||
{
|
{
|
||||||
va_list arg;
|
va_list arg;
|
||||||
va_start(arg, format);
|
va_start(arg, format);
|
||||||
enum fx_status result
|
enum fx_status result = fx_bstr_write_vfmt(
|
||||||
= fx_bstr_write_vfmt(str, nr_written, format, arg);
|
str,
|
||||||
|
nr_written,
|
||||||
|
format,
|
||||||
|
arg);
|
||||||
va_end(arg);
|
va_end(arg);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -0,0 +1,133 @@
|
|||||||
|
#include <ctype.h>
|
||||||
|
#include <fx/cstr.h>
|
||||||
|
#include <fx/value-type.h>
|
||||||
|
|
||||||
|
/*** CLASS DEFINITION *********************************************************/
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_BEGIN(fx_cstr)
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_TYPE_CLASS_END(fx_cstr)
|
||||||
|
|
||||||
|
FX_TYPE_DEFINITION_BEGIN(fx_cstr)
|
||||||
|
__FX_VALUE_TYPE_ID(CSTR);
|
||||||
|
FX_TYPE_EXTENDS(FX_TYPE_VALUE_TYPE);
|
||||||
|
FX_TYPE_NAME("fx.cstr");
|
||||||
|
FX_TYPE_CLASS(fx_cstr_class);
|
||||||
|
FX_TYPE_INSTANCE_PRIVATE(char *);
|
||||||
|
FX_TYPE_DEFINITION_END(fx_cstr)
|
||||||
|
|
||||||
|
/*** MISC FUNCTIONS ***********************************************************/
|
||||||
|
|
||||||
|
char *fx_strdup(const char *s)
|
||||||
|
{
|
||||||
|
size_t len = strlen(s);
|
||||||
|
char *p = malloc(len + 1);
|
||||||
|
if (!p) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(p, s, len);
|
||||||
|
p[len] = '\0';
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t fx_strlen(const char *s, fx_strlen_flags flags)
|
||||||
|
{
|
||||||
|
if (!(flags & (FX_STRLEN_IGNORE_ESC | FX_STRLEN_IGNORE_MOD))) {
|
||||||
|
return strlen(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t out = 0;
|
||||||
|
for (size_t i = 0; s[i]; i++) {
|
||||||
|
if (s[i] == '\033' && (flags & FX_STRLEN_IGNORE_ESC)) {
|
||||||
|
while (!isalpha(s[i]) && s[i]) {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s[i] == '[' && (flags & FX_STRLEN_IGNORE_MOD)) {
|
||||||
|
i++;
|
||||||
|
if (s[i] == '[') {
|
||||||
|
out++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (s[i] != ']' && s[i]) {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
out++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
int fx_wstrcmp(const fx_wchar *a, const fx_wchar *b)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i = 0; a[i] == b[i]; i++)
|
||||||
|
if (a[i] == '\0')
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return a[i] - b[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
int fx_wastrcmp(const char *a, const fx_wchar *b)
|
||||||
|
{
|
||||||
|
while (1) {
|
||||||
|
fx_wchar ch_a = fx_wchar_utf8_codepoint_decode(a);
|
||||||
|
fx_wchar ch_b = *b;
|
||||||
|
|
||||||
|
if (ch_a != ch_b) {
|
||||||
|
return ch_a - ch_b;
|
||||||
|
}
|
||||||
|
|
||||||
|
a += fx_wchar_utf8_codepoint_stride(a);
|
||||||
|
b++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
fx_wchar *fx_wstrdup(const fx_wchar *s)
|
||||||
|
{
|
||||||
|
size_t len = fx_wstrlen(s);
|
||||||
|
fx_wchar *buf = calloc(len + 1, sizeof(fx_wchar));
|
||||||
|
if (!buf) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(buf, s, len * sizeof(fx_wchar));
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t fx_wstrlen(const fx_wchar *s)
|
||||||
|
{
|
||||||
|
size_t len;
|
||||||
|
for (len = 0; s[len] != 0; len++)
|
||||||
|
;
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t fx_wstrcspn(const fx_wchar *dest, const fx_wchar *src)
|
||||||
|
{
|
||||||
|
size_t i = 0;
|
||||||
|
for (i = 0; dest[i]; i++) {
|
||||||
|
for (size_t ii = 0; src[ii]; ii++) {
|
||||||
|
if (dest[i] == src[ii]) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
-280
@@ -1,280 +0,0 @@
|
|||||||
#include <fx/double.h>
|
|
||||||
#include <fx/stream.h>
|
|
||||||
#include <inttypes.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
/*** PRIVATE DATA *************************************************************/
|
|
||||||
|
|
||||||
enum double_type {
|
|
||||||
DOUBLE_REGULAR = 0,
|
|
||||||
DOUBLE_INF_POSITIVE,
|
|
||||||
DOUBLE_INF_NEGATIVE,
|
|
||||||
DOUBLE_NAN_POSITIVE,
|
|
||||||
DOUBLE_NAN_NEGATIVE,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct fx_double_p {
|
|
||||||
enum double_type i_type;
|
|
||||||
double i_value;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*** PRIVATE FUNCTIONS ********************************************************/
|
|
||||||
|
|
||||||
static bool double_get_value(const struct fx_double_p *i)
|
|
||||||
{
|
|
||||||
return i->i_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void double_set_value(struct fx_double_p *i, double v)
|
|
||||||
{
|
|
||||||
i->i_type = DOUBLE_REGULAR;
|
|
||||||
i->i_value = v;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void double_set_value_nan(struct fx_double_p *i)
|
|
||||||
{
|
|
||||||
i->i_type = DOUBLE_NAN_POSITIVE;
|
|
||||||
i->i_value = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void double_set_value_nan_negative(struct fx_double_p *i)
|
|
||||||
{
|
|
||||||
i->i_type = DOUBLE_NAN_NEGATIVE;
|
|
||||||
i->i_value = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void double_set_value_inf(struct fx_double_p *i)
|
|
||||||
{
|
|
||||||
i->i_type = DOUBLE_INF_POSITIVE;
|
|
||||||
i->i_value = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void double_set_value_inf_negative(struct fx_double_p *i)
|
|
||||||
{
|
|
||||||
i->i_type = DOUBLE_INF_NEGATIVE;
|
|
||||||
i->i_value = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool double_is_nan(struct fx_double_p *i)
|
|
||||||
{
|
|
||||||
return i->i_type == DOUBLE_NAN_POSITIVE
|
|
||||||
|| i->i_type == DOUBLE_NAN_NEGATIVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool double_is_nan_positive(struct fx_double_p *i)
|
|
||||||
{
|
|
||||||
return i->i_type == DOUBLE_NAN_POSITIVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool double_is_nan_negative(struct fx_double_p *i)
|
|
||||||
{
|
|
||||||
return i->i_type == DOUBLE_NAN_NEGATIVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool double_is_inf(struct fx_double_p *i)
|
|
||||||
{
|
|
||||||
return i->i_type == DOUBLE_INF_POSITIVE
|
|
||||||
|| i->i_type == DOUBLE_INF_NEGATIVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool double_is_inf_positive(struct fx_double_p *i)
|
|
||||||
{
|
|
||||||
return i->i_type == DOUBLE_INF_POSITIVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool double_is_inf_negative(struct fx_double_p *i)
|
|
||||||
{
|
|
||||||
return i->i_type == DOUBLE_INF_NEGATIVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*** PUBLIC FUNCTIONS *********************************************************/
|
|
||||||
|
|
||||||
fx_double *fx_double_create(double value)
|
|
||||||
{
|
|
||||||
fx_double *i = fx_object_create(FX_TYPE_DOUBLE);
|
|
||||||
if (!i) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct fx_double_p *p = fx_object_get_private(i, FX_TYPE_DOUBLE);
|
|
||||||
p->i_type = DOUBLE_REGULAR;
|
|
||||||
p->i_value = value;
|
|
||||||
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
fx_double *fx_double_create_nan(void)
|
|
||||||
{
|
|
||||||
fx_double *i = fx_object_create(FX_TYPE_DOUBLE);
|
|
||||||
if (!i) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct fx_double_p *p = fx_object_get_private(i, FX_TYPE_DOUBLE);
|
|
||||||
p->i_type = DOUBLE_NAN_POSITIVE;
|
|
||||||
p->i_value = 0;
|
|
||||||
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
fx_double *fx_double_create_nan_negative(void)
|
|
||||||
{
|
|
||||||
fx_double *i = fx_object_create(FX_TYPE_DOUBLE);
|
|
||||||
if (!i) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct fx_double_p *p = fx_object_get_private(i, FX_TYPE_DOUBLE);
|
|
||||||
p->i_type = DOUBLE_NAN_NEGATIVE;
|
|
||||||
p->i_value = 0;
|
|
||||||
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
fx_double *fx_double_create_inf(void)
|
|
||||||
{
|
|
||||||
fx_double *i = fx_object_create(FX_TYPE_DOUBLE);
|
|
||||||
if (!i) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct fx_double_p *p = fx_object_get_private(i, FX_TYPE_DOUBLE);
|
|
||||||
p->i_type = DOUBLE_INF_POSITIVE;
|
|
||||||
p->i_value = 0;
|
|
||||||
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
fx_double *fx_double_create_inf_negative(void)
|
|
||||||
{
|
|
||||||
fx_double *i = fx_object_create(FX_TYPE_DOUBLE);
|
|
||||||
if (!i) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct fx_double_p *p = fx_object_get_private(i, FX_TYPE_DOUBLE);
|
|
||||||
p->i_type = DOUBLE_INF_NEGATIVE;
|
|
||||||
p->i_value = 0;
|
|
||||||
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
double fx_double_get_value(const fx_double *i)
|
|
||||||
{
|
|
||||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_DOUBLE, double_get_value, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
void fx_double_set_value(fx_double *i, double v)
|
|
||||||
{
|
|
||||||
FX_CLASS_DISPATCH_STATIC_V(FX_TYPE_DOUBLE, double_set_value, i, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
void fx_double_set_value_nan(fx_double *i)
|
|
||||||
{
|
|
||||||
FX_CLASS_DISPATCH_STATIC_V0(FX_TYPE_DOUBLE, double_set_value_nan, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
void fx_double_set_value_nan_negative(fx_double *i)
|
|
||||||
{
|
|
||||||
FX_CLASS_DISPATCH_STATIC_V0(
|
|
||||||
FX_TYPE_DOUBLE,
|
|
||||||
double_set_value_nan_negative,
|
|
||||||
i);
|
|
||||||
}
|
|
||||||
|
|
||||||
void fx_double_set_value_inf(fx_double *i)
|
|
||||||
{
|
|
||||||
FX_CLASS_DISPATCH_STATIC_V0(FX_TYPE_DOUBLE, double_set_value_inf, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
void fx_double_set_value_inf_negative(fx_double *i)
|
|
||||||
{
|
|
||||||
FX_CLASS_DISPATCH_STATIC_V0(
|
|
||||||
FX_TYPE_DOUBLE,
|
|
||||||
double_set_value_inf_negative,
|
|
||||||
i);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool fx_double_is_nan(const fx_double *i)
|
|
||||||
{
|
|
||||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_DOUBLE, double_is_nan, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool fx_double_is_nan_positive(const fx_double *i)
|
|
||||||
{
|
|
||||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_DOUBLE, double_is_nan_positive, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool fx_double_is_nan_negative(const fx_double *i)
|
|
||||||
{
|
|
||||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_DOUBLE, double_is_nan_negative, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool fx_double_is_inf(const fx_double *i)
|
|
||||||
{
|
|
||||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_DOUBLE, double_is_inf, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool fx_double_is_inf_positive(const fx_double *i)
|
|
||||||
{
|
|
||||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_DOUBLE, double_is_inf_positive, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool fx_double_is_inf_negative(const fx_double *i)
|
|
||||||
{
|
|
||||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_DOUBLE, double_is_inf_negative, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*** VIRTUAL FUNCTIONS ********************************************************/
|
|
||||||
|
|
||||||
static void double_init(fx_object *obj, void *priv)
|
|
||||||
{
|
|
||||||
struct fx_double_p *i = priv;
|
|
||||||
|
|
||||||
i->i_type = DOUBLE_REGULAR;
|
|
||||||
i->i_value = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void double_fini(fx_object *obj, void *priv)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static void double_to_string(const fx_object *obj, fx_stream *out)
|
|
||||||
{
|
|
||||||
struct fx_double_p *i = fx_object_get_private(obj, FX_TYPE_DOUBLE);
|
|
||||||
switch (i->i_type) {
|
|
||||||
case DOUBLE_REGULAR:
|
|
||||||
fx_stream_write_fmt(out, NULL, "%" PRIdPTR, i->i_value);
|
|
||||||
break;
|
|
||||||
case DOUBLE_INF_POSITIVE:
|
|
||||||
fx_stream_write_cstr(out, "inf", NULL);
|
|
||||||
break;
|
|
||||||
case DOUBLE_INF_NEGATIVE:
|
|
||||||
fx_stream_write_cstr(out, "-inf", NULL);
|
|
||||||
break;
|
|
||||||
case DOUBLE_NAN_POSITIVE:
|
|
||||||
fx_stream_write_cstr(out, "NaN", NULL);
|
|
||||||
break;
|
|
||||||
case DOUBLE_NAN_NEGATIVE:
|
|
||||||
fx_stream_write_cstr(out, "-NaN", NULL);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*** CLASS DEFINITION *********************************************************/
|
|
||||||
|
|
||||||
FX_TYPE_CLASS_BEGIN(fx_double)
|
|
||||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
|
||||||
FX_INTERFACE_ENTRY(to_string) = double_to_string;
|
|
||||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
|
||||||
FX_TYPE_CLASS_END(fx_double)
|
|
||||||
|
|
||||||
FX_TYPE_DEFINITION_BEGIN(fx_double)
|
|
||||||
FX_TYPE_ID(0x3b20f57a, 0x2ddf, 0x4682, 0x81c4, 0x4fe404a6524e);
|
|
||||||
FX_TYPE_CLASS(fx_double_class);
|
|
||||||
FX_TYPE_INSTANCE_PRIVATE(struct fx_double_p);
|
|
||||||
FX_TYPE_INSTANCE_INIT(double_init);
|
|
||||||
FX_TYPE_INSTANCE_FINI(double_fini);
|
|
||||||
FX_TYPE_DEFINITION_END(fx_double)
|
|
||||||
@@ -1177,6 +1177,66 @@ bool fx_wchar_is_alpha(fx_wchar c)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool wchar_is_control(fx_wchar c)
|
||||||
|
{
|
||||||
|
if (c >= 0x0000 && c <= 0x001F) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c == 0x007F) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c >= 0x0080 && c <= 0x009F) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (c) {
|
||||||
|
case 0x00AD:
|
||||||
|
case 0x034F:
|
||||||
|
case 0x070F:
|
||||||
|
case 0x180E:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c >= 0x200B && c <= 0x200F) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c >= 0x202A && c <= 0x202E) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c >= 0x2060 && c <= 0x2064) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c >= 0x2066 && c <= 0x206F) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c == 0xFEFF) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c >= 0xFFF9 && c <= 0xFFFB) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c >= 0x13430 && c <= 0x13438) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fx_wchar_is_graph(fx_wchar c)
|
||||||
|
{
|
||||||
|
return !wchar_is_control(c);
|
||||||
|
}
|
||||||
|
|
||||||
bool fx_wchar_is_hex_digit(fx_wchar c)
|
bool fx_wchar_is_hex_digit(fx_wchar c)
|
||||||
{
|
{
|
||||||
return iswxdigit(c);
|
return iswxdigit(c);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include <fx/endian.h>
|
#include <fx/endian.h>
|
||||||
|
#if 0
|
||||||
|
|
||||||
fx_i16 fx_i16_htob(uint16_t v)
|
fx_i16 fx_i16_htob(uint16_t v)
|
||||||
{
|
{
|
||||||
@@ -211,3 +212,4 @@ uint64_t fx_i64_stoh(fx_i64 v)
|
|||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#include <fx/float.h>
|
||||||
|
#include <fx/value-type.h>
|
||||||
|
|
||||||
|
/*** CLASS DEFINITION *********************************************************/
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_BEGIN(fx_double)
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_TYPE_CLASS_END(fx_double)
|
||||||
|
|
||||||
|
FX_TYPE_DEFINITION_BEGIN(fx_double)
|
||||||
|
__FX_VALUE_TYPE_ID(DOUBLE);
|
||||||
|
FX_TYPE_EXTENDS(FX_TYPE_VALUE_TYPE);
|
||||||
|
FX_TYPE_NAME("fx.double");
|
||||||
|
FX_TYPE_CLASS(fx_double_class);
|
||||||
|
FX_TYPE_INSTANCE_PRIVATE(double);
|
||||||
|
FX_TYPE_DEFINITION_END(fx_double)
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#include <fx/float.h>
|
||||||
|
#include <fx/value-type.h>
|
||||||
|
|
||||||
|
/*** CLASS DEFINITION *********************************************************/
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_BEGIN(fx_float)
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_TYPE_CLASS_END(fx_float)
|
||||||
|
|
||||||
|
FX_TYPE_DEFINITION_BEGIN(fx_float)
|
||||||
|
__FX_VALUE_TYPE_ID(FLOAT);
|
||||||
|
FX_TYPE_EXTENDS(FX_TYPE_VALUE_TYPE);
|
||||||
|
FX_TYPE_NAME("fx.float");
|
||||||
|
FX_TYPE_CLASS(fx_float_class);
|
||||||
|
FX_TYPE_INSTANCE_PRIVATE(float);
|
||||||
|
FX_TYPE_DEFINITION_END(fx_float)
|
||||||
+14
-15
@@ -30,20 +30,20 @@ A million repetitions of "a"
|
|||||||
|
|
||||||
/* blk0() and blk() perform the initial expand. */
|
/* blk0() and blk() perform the initial expand. */
|
||||||
/* I got the idea of expanding during the round function from SSLeay */
|
/* I got the idea of expanding during the round function from SSLeay */
|
||||||
#if defined(LITTLE_ENDIAN)
|
#if FX_ENDIAN == 0
|
||||||
#define blk0(i) \
|
#define blk0(i) \
|
||||||
(block->l[i] = (rol(block->l[i], 24) & 0xFF00FF00) \
|
(block->l[i] = (rol(block->l[i], 24) & 0xFF00FF00) \
|
||||||
| (rol(block->l[i], 8) & 0x00FF00FF))
|
| (rol(block->l[i], 8) & 0x00FF00FF))
|
||||||
#elif defined(BIG_ENDIAN)
|
#elif FX_ENDIAN == 1
|
||||||
#define blk0(i) block->l[i]
|
#define blk0(i) block->l[i]
|
||||||
#else
|
#else
|
||||||
#error "Endianness not defined!"
|
#error "Endianness not defined!"
|
||||||
#endif
|
#endif
|
||||||
#define blk(i) \
|
#define blk(i) \
|
||||||
(block->l[i & 15] \
|
(block->l[i & 15] = rol( \
|
||||||
= rol(block->l[(i + 13) & 15] ^ block->l[(i + 8) & 15] \
|
block->l[(i + 13) & 15] ^ block->l[(i + 8) & 15] \
|
||||||
^ block->l[(i + 2) & 15] ^ block->l[i & 15], \
|
^ block->l[(i + 2) & 15] ^ block->l[i & 15], \
|
||||||
1))
|
1))
|
||||||
|
|
||||||
/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */
|
/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */
|
||||||
#define R0(v, w, x, y, z, i) \
|
#define R0(v, w, x, y, z, i) \
|
||||||
@@ -235,11 +235,10 @@ static void sha_finish(struct fx_hash_ctx *context, void *out, size_t max)
|
|||||||
unsigned char c;
|
unsigned char c;
|
||||||
|
|
||||||
for (i = 0; i < 8; i++) {
|
for (i = 0; i < 8; i++) {
|
||||||
finalcount[i]
|
finalcount[i] = (unsigned char)((context->ctx_state.sha1.count[(
|
||||||
= (unsigned char)((context->ctx_state.sha1
|
i >= 4 ? 0 : 1)]
|
||||||
.count[(i >= 4 ? 0 : 1)]
|
>> ((3 - (i & 3)) * 8))
|
||||||
>> ((3 - (i & 3)) * 8))
|
& 255); /* Endian independent */
|
||||||
& 255); /* Endian independent */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char digest[FX_DIGEST_LENGTH_SHA1];
|
char digest[FX_DIGEST_LENGTH_SHA1];
|
||||||
@@ -251,10 +250,10 @@ static void sha_finish(struct fx_hash_ctx *context, void *out, size_t max)
|
|||||||
}
|
}
|
||||||
sha_update(context, finalcount, 8); /* Should cause a SHA1Transform() */
|
sha_update(context, finalcount, 8); /* Should cause a SHA1Transform() */
|
||||||
for (i = 0; i < 20; i++) {
|
for (i = 0; i < 20; i++) {
|
||||||
digest[i]
|
digest[i] = (unsigned char)((context->ctx_state.sha1
|
||||||
= (unsigned char)((context->ctx_state.sha1.state[i >> 2]
|
.state[i >> 2]
|
||||||
>> ((3 - (i & 3)) * 8))
|
>> ((3 - (i & 3)) * 8))
|
||||||
& 255);
|
& 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(out, digest, fx_min(size_t, sizeof digest, max));
|
memcpy(out, digest, fx_min(size_t, sizeof digest, max));
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#ifndef FX_CORE_BSTR_H_
|
#ifndef FX_CORE_BSTR_H_
|
||||||
#define FX_CORE_BSTR_H_
|
#define FX_CORE_BSTR_H_
|
||||||
|
|
||||||
|
#include <fx/encoding.h>
|
||||||
#include <fx/misc.h>
|
#include <fx/misc.h>
|
||||||
#include <fx/status.h>
|
#include <fx/status.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
@@ -77,6 +78,9 @@ FX_API fx_status fx_bstr_write_vfmt(
|
|||||||
const char *format,
|
const char *format,
|
||||||
va_list arg);
|
va_list arg);
|
||||||
|
|
||||||
|
FX_API fx_status
|
||||||
|
fx_bstr_write_wstr(fx_bstr *strv, const fx_wchar *str, size_t *nr_written);
|
||||||
|
|
||||||
FX_API char *fx_bstr_rope(const struct fx_rope *rope, size_t *nr_written);
|
FX_API char *fx_bstr_rope(const struct fx_rope *rope, size_t *nr_written);
|
||||||
FX_API char *fx_bstr_fmt(size_t *nr_written, const char *format, ...);
|
FX_API char *fx_bstr_fmt(size_t *nr_written, const char *format, ...);
|
||||||
FX_API char *fx_bstr_vfmt(size_t *nr_written, const char *format, va_list arg);
|
FX_API char *fx_bstr_vfmt(size_t *nr_written, const char *format, va_list arg);
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
#ifndef FX_CSTR_H_
|
||||||
|
#define FX_CSTR_H_
|
||||||
|
|
||||||
|
#include <fx/encoding.h>
|
||||||
|
#include <fx/macros.h>
|
||||||
|
|
||||||
|
FX_DECLS_BEGIN;
|
||||||
|
|
||||||
|
typedef enum fx_strlen_flags {
|
||||||
|
FX_STRLEN_NORMAL = 0,
|
||||||
|
FX_STRLEN_IGNORE_ESC = 0x01u,
|
||||||
|
FX_STRLEN_IGNORE_MOD = 0x02u,
|
||||||
|
FX_STRLEN_CODEPOINTS = 0x04u,
|
||||||
|
} fx_strlen_flags;
|
||||||
|
|
||||||
|
#define FX_TYPE_CSTR (fx_cstr_get_type())
|
||||||
|
|
||||||
|
FX_DECLARE_TYPE(fx_cstr);
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_cstr)
|
||||||
|
FX_TYPE_CLASS_DECLARATION_END(fx_cstr)
|
||||||
|
|
||||||
|
FX_API fx_type_id fx_cstr_get_type(void);
|
||||||
|
|
||||||
|
FX_API char *fx_strdup(const char *s);
|
||||||
|
FX_API size_t fx_strlen(const char *s, fx_strlen_flags flags);
|
||||||
|
FX_API int fx_wstrcmp(const fx_wchar *a, const fx_wchar *b);
|
||||||
|
FX_API int fx_wastrcmp(const char *a, const fx_wchar *b);
|
||||||
|
FX_API fx_wchar *fx_wstrdup(const fx_wchar *s);
|
||||||
|
FX_API size_t fx_wstrlen(const fx_wchar *s);
|
||||||
|
FX_API size_t fx_wstrcspn(const fx_wchar *dest, const fx_wchar *src);
|
||||||
|
|
||||||
|
FX_DECLS_END;
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
#ifndef FX_DOUBLE_H_
|
|
||||||
#define FX_DOUBLE_H_
|
|
||||||
|
|
||||||
#include <fx/macros.h>
|
|
||||||
|
|
||||||
FX_DECLS_BEGIN;
|
|
||||||
|
|
||||||
#define FX_TYPE_DOUBLE (fx_double_get_type())
|
|
||||||
|
|
||||||
FX_DECLARE_TYPE(fx_double);
|
|
||||||
|
|
||||||
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_double)
|
|
||||||
FX_TYPE_CLASS_DECLARATION_END(fx_double)
|
|
||||||
|
|
||||||
FX_API fx_type_id fx_double_get_type(void);
|
|
||||||
|
|
||||||
FX_API fx_double *fx_double_create(double value);
|
|
||||||
FX_API fx_double *fx_double_create_nan(void);
|
|
||||||
FX_API fx_double *fx_double_create_nan_negative(void);
|
|
||||||
FX_API fx_double *fx_double_create_inf(void);
|
|
||||||
FX_API fx_double *fx_double_create_inf_negative(void);
|
|
||||||
|
|
||||||
FX_API void fx_double_set_value(fx_double *i, double v);
|
|
||||||
FX_API void fx_double_set_value_nan(fx_double *i);
|
|
||||||
FX_API void fx_double_set_value_nan_negative(fx_double *i);
|
|
||||||
FX_API void fx_double_set_value_inf(fx_double *i);
|
|
||||||
FX_API void fx_double_set_value_inf_negative(fx_double *i);
|
|
||||||
|
|
||||||
FX_API bool fx_double_is_nan(const fx_double *i);
|
|
||||||
FX_API bool fx_double_is_nan_positive(const fx_double *i);
|
|
||||||
FX_API bool fx_double_is_nan_negative(const fx_double *i);
|
|
||||||
FX_API bool fx_double_is_inf(const fx_double *i);
|
|
||||||
FX_API bool fx_double_is_inf_positive(const fx_double *i);
|
|
||||||
FX_API bool fx_double_is_inf_negative(const fx_double *i);
|
|
||||||
|
|
||||||
FX_API double fx_double_get_value(const fx_double *i);
|
|
||||||
|
|
||||||
FX_DECLS_END;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -11,6 +11,7 @@ typedef int32_t fx_wchar;
|
|||||||
|
|
||||||
FX_API bool fx_wchar_is_alpha(fx_wchar c);
|
FX_API bool fx_wchar_is_alpha(fx_wchar c);
|
||||||
FX_API bool fx_wchar_is_number(fx_wchar c);
|
FX_API bool fx_wchar_is_number(fx_wchar c);
|
||||||
|
FX_API bool fx_wchar_is_graph(fx_wchar c);
|
||||||
static inline bool fx_wchar_is_bin_digit(fx_wchar c)
|
static inline bool fx_wchar_is_bin_digit(fx_wchar c)
|
||||||
{
|
{
|
||||||
return c >= '0' && c <= '1';
|
return c >= '0' && c <= '1';
|
||||||
@@ -35,8 +36,7 @@ FX_API fx_wchar fx_wchar_utf8_codepoint_decode(const char *s);
|
|||||||
FX_API unsigned int fx_wchar_utf8_codepoint_encode(fx_wchar c, char s[4]);
|
FX_API unsigned int fx_wchar_utf8_codepoint_encode(fx_wchar c, char s[4]);
|
||||||
FX_API unsigned int fx_wchar_utf8_codepoint_stride(const char *s);
|
FX_API unsigned int fx_wchar_utf8_codepoint_stride(const char *s);
|
||||||
FX_API size_t fx_wchar_utf8_codepoint_count(const char *s, size_t nr_bytes);
|
FX_API size_t fx_wchar_utf8_codepoint_count(const char *s, size_t nr_bytes);
|
||||||
FX_API size_t fx_wchar_utf8_string_encoded_size(
|
FX_API size_t
|
||||||
const fx_wchar *s,
|
fx_wchar_utf8_string_encoded_size(const fx_wchar *s, size_t nr_codepoints);
|
||||||
size_t nr_codepoints);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+2
-18
@@ -4,6 +4,7 @@
|
|||||||
#include <fx/misc.h>
|
#include <fx/misc.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#if 0
|
||||||
typedef struct {
|
typedef struct {
|
||||||
union {
|
union {
|
||||||
unsigned char i_bytes[sizeof(uint16_t)];
|
unsigned char i_bytes[sizeof(uint16_t)];
|
||||||
@@ -27,23 +28,6 @@ typedef struct {
|
|||||||
uint64_t i_uval;
|
uint64_t i_uval;
|
||||||
};
|
};
|
||||||
} fx_i64;
|
} fx_i64;
|
||||||
|
#endif
|
||||||
FX_API fx_i16 fx_i16_htob(uint16_t v);
|
|
||||||
FX_API fx_i16 fx_i16_htos(uint16_t v);
|
|
||||||
|
|
||||||
FX_API uint16_t fx_i16_btoh(fx_i16 v);
|
|
||||||
FX_API uint16_t fx_i16_stoh(fx_i16 v);
|
|
||||||
|
|
||||||
FX_API fx_i32 fx_i32_htob(uint32_t v);
|
|
||||||
FX_API fx_i32 fx_i32_htos(uint32_t v);
|
|
||||||
|
|
||||||
FX_API uint32_t fx_i32_btoh(fx_i32 v);
|
|
||||||
FX_API uint32_t fx_i32_stoh(fx_i32 v);
|
|
||||||
|
|
||||||
FX_API fx_i64 fx_i64_htob(uint64_t v);
|
|
||||||
FX_API fx_i64 fx_i64_htos(uint64_t v);
|
|
||||||
|
|
||||||
FX_API uint64_t fx_i64_btoh(fx_i64 v);
|
|
||||||
FX_API uint64_t fx_i64_stoh(fx_i64 v);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
#ifndef FX_DOUBLE_H_
|
||||||
|
#define FX_DOUBLE_H_
|
||||||
|
|
||||||
|
#include <fx/macros.h>
|
||||||
|
|
||||||
|
FX_DECLS_BEGIN;
|
||||||
|
|
||||||
|
#define FX_TYPE_FLOAT (fx_float_get_type())
|
||||||
|
#define FX_TYPE_DOUBLE (fx_double_get_type())
|
||||||
|
|
||||||
|
FX_DECLARE_TYPE(fx_float);
|
||||||
|
FX_DECLARE_TYPE(fx_double);
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_float)
|
||||||
|
FX_TYPE_CLASS_DECLARATION_END(fx_float)
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_double)
|
||||||
|
FX_TYPE_CLASS_DECLARATION_END(fx_double)
|
||||||
|
|
||||||
|
FX_API fx_type_id fx_float_get_type(void);
|
||||||
|
FX_API fx_type_id fx_double_get_type(void);
|
||||||
|
|
||||||
|
FX_DECLS_END;
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
#ifndef FX_INT_PRIMITIVES_H_
|
||||||
|
#define FX_INT_PRIMITIVES_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
typedef int8_t sbyte;
|
||||||
|
typedef uint8_t byte;
|
||||||
|
typedef int16_t i16;
|
||||||
|
typedef uint16_t u16;
|
||||||
|
typedef int32_t i32;
|
||||||
|
typedef uint32_t u32;
|
||||||
|
typedef int64_t i64;
|
||||||
|
typedef uint64_t u64;
|
||||||
|
typedef intptr_t iptr;
|
||||||
|
typedef uintptr_t uptr;
|
||||||
|
|
||||||
|
#endif
|
||||||
+141
-18
@@ -1,39 +1,162 @@
|
|||||||
#ifndef FX_INT_H_
|
#ifndef FX_INT_H_
|
||||||
#define FX_INT_H_
|
#define FX_INT_H_
|
||||||
|
|
||||||
|
#include <fx/int-primitives.h>
|
||||||
#include <fx/macros.h>
|
#include <fx/macros.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
FX_DECLS_BEGIN;
|
FX_DECLS_BEGIN;
|
||||||
|
|
||||||
#define FX_TYPE_INT (fx_int_get_type())
|
#define FX_TYPE_I16 (fx_i16_get_type())
|
||||||
|
#define FX_TYPE_U16 (fx_u16_get_type())
|
||||||
|
#define FX_TYPE_I32 (fx_i32_get_type())
|
||||||
|
#define FX_TYPE_U32 (fx_u32_get_type())
|
||||||
|
#define FX_TYPE_I64 (fx_i64_get_type())
|
||||||
|
#define FX_TYPE_U64 (fx_u64_get_type())
|
||||||
|
#define FX_TYPE_IPTR (fx_iptr_get_type())
|
||||||
|
#define FX_TYPE_UPTR (fx_uptr_get_type())
|
||||||
|
|
||||||
|
#define FX_TYPE_SBYTE (fx_sbyte_get_type())
|
||||||
|
#define FX_TYPE_BYTE (fx_byte_get_type())
|
||||||
|
#define FX_TYPE_SHORT (fx_short_get_type())
|
||||||
|
#define FX_TYPE_USHORT (fx_ushort_get_type())
|
||||||
|
#define FX_TYPE_INT (fx_int_get_type())
|
||||||
|
#define FX_TYPE_UINT (fx_uint_get_type())
|
||||||
|
#define FX_TYPE_LONG (fx_long_get_type())
|
||||||
|
#define FX_TYPE_ULONG (fx_ulong_get_type())
|
||||||
|
#define FX_TYPE_LONGLONG (fx_longlong_get_type())
|
||||||
|
#define FX_TYPE_ULONGLONG (fx_ulonglong_get_type())
|
||||||
|
#define FX_TYPE_SIZE (fx_size_get_type())
|
||||||
|
|
||||||
|
FX_DECLARE_TYPE(fx_i16);
|
||||||
|
FX_DECLARE_TYPE(fx_u16);
|
||||||
|
FX_DECLARE_TYPE(fx_i32);
|
||||||
|
FX_DECLARE_TYPE(fx_u32);
|
||||||
|
FX_DECLARE_TYPE(fx_i64);
|
||||||
|
FX_DECLARE_TYPE(fx_u64);
|
||||||
|
FX_DECLARE_TYPE(fx_iptr);
|
||||||
|
FX_DECLARE_TYPE(fx_uptr);
|
||||||
|
|
||||||
|
FX_DECLARE_TYPE(fx_sbyte);
|
||||||
|
FX_DECLARE_TYPE(fx_byte);
|
||||||
|
FX_DECLARE_TYPE(fx_short);
|
||||||
|
FX_DECLARE_TYPE(fx_ushort);
|
||||||
FX_DECLARE_TYPE(fx_int);
|
FX_DECLARE_TYPE(fx_int);
|
||||||
|
FX_DECLARE_TYPE(fx_uint);
|
||||||
|
FX_DECLARE_TYPE(fx_long);
|
||||||
|
FX_DECLARE_TYPE(fx_ulong);
|
||||||
|
FX_DECLARE_TYPE(fx_longlong);
|
||||||
|
FX_DECLARE_TYPE(fx_ulonglong);
|
||||||
|
FX_DECLARE_TYPE(fx_size);
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_i16)
|
||||||
|
FX_TYPE_CLASS_DECLARATION_END(fx_i16)
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_u16)
|
||||||
|
FX_TYPE_CLASS_DECLARATION_END(fx_u16)
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_i32)
|
||||||
|
FX_TYPE_CLASS_DECLARATION_END(fx_i32)
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_u32)
|
||||||
|
FX_TYPE_CLASS_DECLARATION_END(fx_u32)
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_i64)
|
||||||
|
FX_TYPE_CLASS_DECLARATION_END(fx_i64)
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_u64)
|
||||||
|
FX_TYPE_CLASS_DECLARATION_END(fx_u64)
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_iptr)
|
||||||
|
FX_TYPE_CLASS_DECLARATION_END(fx_iptr)
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_uptr)
|
||||||
|
FX_TYPE_CLASS_DECLARATION_END(fx_uptr)
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_sbyte)
|
||||||
|
FX_TYPE_CLASS_DECLARATION_END(fx_sbyte)
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_byte)
|
||||||
|
FX_TYPE_CLASS_DECLARATION_END(fx_byte)
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_short)
|
||||||
|
FX_TYPE_CLASS_DECLARATION_END(fx_short)
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_ushort)
|
||||||
|
FX_TYPE_CLASS_DECLARATION_END(fx_ushort)
|
||||||
|
|
||||||
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_int)
|
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_int)
|
||||||
FX_TYPE_CLASS_DECLARATION_END(fx_int)
|
FX_TYPE_CLASS_DECLARATION_END(fx_int)
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_uint)
|
||||||
|
FX_TYPE_CLASS_DECLARATION_END(fx_uint)
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_long)
|
||||||
|
FX_TYPE_CLASS_DECLARATION_END(fx_long)
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_ulong)
|
||||||
|
FX_TYPE_CLASS_DECLARATION_END(fx_ulong)
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_longlong)
|
||||||
|
FX_TYPE_CLASS_DECLARATION_END(fx_longlong)
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_ulonglong)
|
||||||
|
FX_TYPE_CLASS_DECLARATION_END(fx_ulonglong)
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_size)
|
||||||
|
FX_TYPE_CLASS_DECLARATION_END(fx_size)
|
||||||
|
|
||||||
|
FX_API fx_type_id fx_i16_get_type(void);
|
||||||
|
FX_API fx_type_id fx_u16_get_type(void);
|
||||||
|
FX_API fx_type_id fx_i32_get_type(void);
|
||||||
|
FX_API fx_type_id fx_u32_get_type(void);
|
||||||
|
FX_API fx_type_id fx_i64_get_type(void);
|
||||||
|
FX_API fx_type_id fx_u64_get_type(void);
|
||||||
|
FX_API fx_type_id fx_iptr_get_type(void);
|
||||||
|
FX_API fx_type_id fx_uptr_get_type(void);
|
||||||
|
|
||||||
|
FX_API fx_type_id fx_sbyte_get_type(void);
|
||||||
|
FX_API fx_type_id fx_byte_get_type(void);
|
||||||
|
FX_API fx_type_id fx_short_get_type(void);
|
||||||
|
FX_API fx_type_id fx_ushort_get_type(void);
|
||||||
FX_API fx_type_id fx_int_get_type(void);
|
FX_API fx_type_id fx_int_get_type(void);
|
||||||
|
FX_API fx_type_id fx_uint_get_type(void);
|
||||||
|
FX_API fx_type_id fx_long_get_type(void);
|
||||||
|
FX_API fx_type_id fx_ulong_get_type(void);
|
||||||
|
FX_API fx_type_id fx_longlong_get_type(void);
|
||||||
|
FX_API fx_type_id fx_ulonglong_get_type(void);
|
||||||
|
FX_API fx_type_id fx_size_get_type(void);
|
||||||
|
|
||||||
FX_API fx_int *fx_int_create(intptr_t value);
|
FX_API i16 fx_i16_htob(i16 v);
|
||||||
FX_API fx_int *fx_int_create_nan(void);
|
FX_API i16 fx_i16_htos(i16 v);
|
||||||
FX_API fx_int *fx_int_create_nan_negative(void);
|
FX_API i16 fx_i16_btoh(i16 v);
|
||||||
FX_API fx_int *fx_int_create_inf(void);
|
FX_API i16 fx_i16_stoh(i16 v);
|
||||||
FX_API fx_int *fx_int_create_inf_negative(void);
|
|
||||||
|
|
||||||
FX_API void fx_int_set_value(fx_int *i, intptr_t v);
|
FX_API u16 fx_u16_htob(u16 v);
|
||||||
FX_API void fx_int_set_value_nan(fx_int *i);
|
FX_API u16 fx_u16_htos(u16 v);
|
||||||
FX_API void fx_int_set_value_nan_negative(fx_int *i);
|
FX_API u16 fx_u16_btoh(u16 v);
|
||||||
FX_API void fx_int_set_value_inf(fx_int *i);
|
FX_API u16 fx_u16_stoh(u16 v);
|
||||||
FX_API void fx_int_set_value_inf_negative(fx_int *i);
|
|
||||||
|
|
||||||
FX_API bool fx_int_is_nan(const fx_int *i);
|
FX_API i32 fx_i32_htob(i32 v);
|
||||||
FX_API bool fx_int_is_nan_positive(const fx_int *i);
|
FX_API i32 fx_i32_htos(i32 v);
|
||||||
FX_API bool fx_int_is_nan_negative(const fx_int *i);
|
FX_API i32 fx_i32_btoh(i32 v);
|
||||||
FX_API bool fx_int_is_inf(const fx_int *i);
|
FX_API i32 fx_i32_stoh(i32 v);
|
||||||
FX_API bool fx_int_is_inf_positive(const fx_int *i);
|
|
||||||
FX_API bool fx_int_is_inf_negative(const fx_int *i);
|
|
||||||
|
|
||||||
FX_API intptr_t fx_int_get_value(const fx_int *i);
|
FX_API u32 fx_u32_htob(u32 v);
|
||||||
|
FX_API u32 fx_u32_htos(u32 v);
|
||||||
|
FX_API u32 fx_u32_btoh(u32 v);
|
||||||
|
FX_API u32 fx_u32_stoh(u32 v);
|
||||||
|
|
||||||
|
FX_API i64 fx_i64_htob(i64 v);
|
||||||
|
FX_API i64 fx_i64_htos(i64 v);
|
||||||
|
FX_API i64 fx_i64_btoh(i64 v);
|
||||||
|
FX_API i64 fx_i64_stoh(i64 v);
|
||||||
|
|
||||||
|
FX_API u64 fx_u64_htob(u64 v);
|
||||||
|
FX_API u64 fx_u64_htos(u64 v);
|
||||||
|
FX_API u64 fx_u64_btoh(u64 v);
|
||||||
|
FX_API u64 fx_u64_stoh(u64 v);
|
||||||
|
|
||||||
FX_DECLS_END;
|
FX_DECLS_END;
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
#include <fx/object.h>
|
#include <fx/object.h>
|
||||||
#include <fx/thread.h>
|
#include <fx/thread.h>
|
||||||
#include <fx/type.h>
|
#include <fx/type.h>
|
||||||
#include <fx/value.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define __FX_IFACE_I0(p, x) p##x
|
#define __FX_IFACE_I0(p, x) p##x
|
||||||
@@ -28,7 +27,7 @@
|
|||||||
#define FX_TYPE_CONSTRUCTOR(name, impl, flags, ...) \
|
#define FX_TYPE_CONSTRUCTOR(name, impl, flags, ...) \
|
||||||
do { \
|
do { \
|
||||||
if (ty) { \
|
if (ty) { \
|
||||||
fx_value_type args[] = {__VA_ARGS__}; \
|
fx_type_id args[] = {__VA_ARGS__}; \
|
||||||
fx_function *func = fx_function_create( \
|
fx_function *func = fx_function_create( \
|
||||||
name, \
|
name, \
|
||||||
FX_FUNCTION_F_CONSTRUCTOR \
|
FX_FUNCTION_F_CONSTRUCTOR \
|
||||||
@@ -36,14 +35,14 @@
|
|||||||
(fx_function_impl)impl, \
|
(fx_function_impl)impl, \
|
||||||
args, \
|
args, \
|
||||||
sizeof args / sizeof args[0], \
|
sizeof args / sizeof args[0], \
|
||||||
FX_VALUE_TYPE_POINTER); \
|
FX_TYPE_OBJECT); \
|
||||||
fx_type_add_function(ty, func); \
|
fx_type_add_function(ty, func); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
#define FX_TYPE_METHOD(return_type, name, impl, flags, ...) \
|
#define FX_TYPE_METHOD(return_type, name, impl, flags, ...) \
|
||||||
do { \
|
do { \
|
||||||
if (ty) { \
|
if (ty) { \
|
||||||
fx_value_type args[] = {__VA_ARGS__}; \
|
fx_type_id args[] = {__VA_ARGS__}; \
|
||||||
fx_function *func = fx_function_create( \
|
fx_function *func = fx_function_create( \
|
||||||
name, \
|
name, \
|
||||||
(flags), \
|
(flags), \
|
||||||
@@ -117,6 +116,9 @@
|
|||||||
|
|
||||||
#define FX_TYPE_ID(a, b, c, d, e) \
|
#define FX_TYPE_ID(a, b, c, d, e) \
|
||||||
fx_type_id_init(&type_info->ty_id, a, b, c, d, e)
|
fx_type_id_init(&type_info->ty_id, a, b, c, d, e)
|
||||||
|
#define __FX_VALUE_TYPE_ID(ty_name) \
|
||||||
|
type_info->ty_id.a.p00 = __FX_VALUE_TYPE_BASEID; \
|
||||||
|
type_info->ty_id.a.p01 = __FX_VALUE_TYPE_##ty_name
|
||||||
#define FX_TYPE_NAME(n) type_info->ty_name = (n)
|
#define FX_TYPE_NAME(n) type_info->ty_name = (n)
|
||||||
#define FX_TYPE_EXTENDS(parent_id) \
|
#define FX_TYPE_EXTENDS(parent_id) \
|
||||||
fx_type_id_copy(parent_id, &type_info->ty_parent_id)
|
fx_type_id_copy(parent_id, &type_info->ty_parent_id)
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ typedef struct _fx_object_class {
|
|||||||
} fx_object_class;
|
} fx_object_class;
|
||||||
|
|
||||||
FX_API fx_type_id fx_object_get_type(void);
|
FX_API fx_type_id fx_object_get_type(void);
|
||||||
|
FX_API fx_type_id fx_object_query_type(const fx_object *obj);
|
||||||
|
|
||||||
FX_API void *fx_object_get_private(const fx_object *object, fx_type_id type);
|
FX_API void *fx_object_get_private(const fx_object *object, fx_type_id type);
|
||||||
FX_API void *fx_object_get_protected(const fx_object *object, fx_type_id type);
|
FX_API void *fx_object_get_protected(const fx_object *object, fx_type_id type);
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
#ifndef FX_POINTER_H_
|
||||||
|
#define FX_POINTER_H_
|
||||||
|
|
||||||
|
#include <fx/macros.h>
|
||||||
|
|
||||||
|
FX_DECLS_BEGIN;
|
||||||
|
|
||||||
|
#define FX_TYPE_POINTER (fx_pointer_get_type())
|
||||||
|
|
||||||
|
FX_DECLARE_TYPE(fx_pointer);
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_pointer)
|
||||||
|
FX_TYPE_CLASS_DECLARATION_END(fx_pointer)
|
||||||
|
|
||||||
|
FX_API fx_type_id fx_pointer_get_type(void);
|
||||||
|
|
||||||
|
FX_DECLS_END;
|
||||||
|
|
||||||
|
#endif
|
||||||
+1
-15
@@ -2,6 +2,7 @@
|
|||||||
#define FX_STRING_H_
|
#define FX_STRING_H_
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <fx/cstr.h>
|
||||||
#include <fx/encoding.h>
|
#include <fx/encoding.h>
|
||||||
#include <fx/iterator.h>
|
#include <fx/iterator.h>
|
||||||
#include <fx/macros.h>
|
#include <fx/macros.h>
|
||||||
@@ -25,16 +26,6 @@ FX_TYPE_CLASS_DECLARATION_END(fx_string)
|
|||||||
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_string_iterator)
|
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_string_iterator)
|
||||||
FX_TYPE_CLASS_DECLARATION_END(fx_string_iterator)
|
FX_TYPE_CLASS_DECLARATION_END(fx_string_iterator)
|
||||||
|
|
||||||
#define FX_CSTR(s) (fx_string_create_from_cstr(s))
|
|
||||||
#define FX_RV_CSTR(s) (FX_RV(fx_string_create_from_cstr(s)))
|
|
||||||
|
|
||||||
typedef enum fx_strlen_flags {
|
|
||||||
FX_STRLEN_NORMAL = 0,
|
|
||||||
FX_STRLEN_IGNORE_ESC = 0x01u,
|
|
||||||
FX_STRLEN_IGNORE_MOD = 0x02u,
|
|
||||||
FX_STRLEN_CODEPOINTS = 0x04u,
|
|
||||||
} fx_strlen_flags;
|
|
||||||
|
|
||||||
typedef enum fx_string_tokenise_flags {
|
typedef enum fx_string_tokenise_flags {
|
||||||
FX_STRING_TOK_F_NORMAL = 0x00u,
|
FX_STRING_TOK_F_NORMAL = 0x00u,
|
||||||
FX_STRING_TOK_F_INCLUDE_EMPTY_TOKENS = 0x01u,
|
FX_STRING_TOK_F_INCLUDE_EMPTY_TOKENS = 0x01u,
|
||||||
@@ -132,11 +123,6 @@ FX_API bool fx_string_iterator_next(fx_string_iterator *it);
|
|||||||
// FX_API fx_status fx_string_iterator_erase(fx_string_iterator *it);
|
// FX_API fx_status fx_string_iterator_erase(fx_string_iterator *it);
|
||||||
FX_API bool fx_string_iterator_is_valid(const fx_string_iterator *it);
|
FX_API bool fx_string_iterator_is_valid(const fx_string_iterator *it);
|
||||||
|
|
||||||
FX_API char *fx_strdup(const char *s);
|
|
||||||
FX_API size_t fx_strlen(const char *s, fx_strlen_flags flags);
|
|
||||||
FX_API fx_wchar *fx_wstrdup(const fx_wchar *s);
|
|
||||||
FX_API size_t fx_wstrlen(const fx_wchar *s);
|
|
||||||
|
|
||||||
FX_API uint64_t fx_string_hash(const fx_string *s);
|
FX_API uint64_t fx_string_hash(const fx_string *s);
|
||||||
|
|
||||||
FX_DECLS_END;
|
FX_DECLS_END;
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ FX_API const char *fx_stringstream_ptr(const fx_stringstream *strv);
|
|||||||
FX_API char *fx_stringstream_steal(fx_stringstream *strv);
|
FX_API char *fx_stringstream_steal(fx_stringstream *strv);
|
||||||
|
|
||||||
FX_API size_t fx_stringstream_get_length(const fx_stringstream *strv);
|
FX_API size_t fx_stringstream_get_length(const fx_stringstream *strv);
|
||||||
|
FX_API size_t fx_stringstream_get_available(const fx_stringstream *strv);
|
||||||
|
|
||||||
FX_DECLS_END;
|
FX_DECLS_END;
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#define FX_TYPE_VOID ((fx_type_id)NULL)
|
||||||
#define FX_TYPE_MAX_INTERFACES 64
|
#define FX_TYPE_MAX_INTERFACES 64
|
||||||
|
|
||||||
struct _fx_class;
|
struct _fx_class;
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
#ifndef FX_UINT_H_
|
|
||||||
#define FX_UINT_H_
|
|
||||||
|
|
||||||
#include <fx/macros.h>
|
|
||||||
|
|
||||||
FX_DECLS_BEGIN;
|
|
||||||
|
|
||||||
#define FX_TYPE_UINT (fx_uint_get_type())
|
|
||||||
|
|
||||||
FX_DECLARE_TYPE(fx_uint);
|
|
||||||
|
|
||||||
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_uint)
|
|
||||||
FX_TYPE_CLASS_DECLARATION_END(fx_uint)
|
|
||||||
|
|
||||||
FX_API fx_type_id fx_uint_get_type(void);
|
|
||||||
|
|
||||||
FX_API fx_uint *fx_uint_create(uintptr_t value);
|
|
||||||
FX_API fx_uint *fx_uint_create_nan(void);
|
|
||||||
FX_API fx_uint *fx_uint_create_inf(void);
|
|
||||||
|
|
||||||
FX_API void fx_uint_set_value(fx_uint *i, uintptr_t v);
|
|
||||||
FX_API void fx_uint_set_value_nan(fx_uint *i);
|
|
||||||
FX_API void fx_uint_set_value_inf(fx_uint *i);
|
|
||||||
|
|
||||||
FX_API bool fx_uint_is_nan(const fx_uint *i);
|
|
||||||
FX_API bool fx_uint_is_inf(const fx_uint *i);
|
|
||||||
|
|
||||||
FX_API uintptr_t fx_uint_get_value(const fx_uint *i);
|
|
||||||
|
|
||||||
FX_DECLS_END;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
#ifndef FX_VALUE_TYPE_H_
|
||||||
|
#define FX_VALUE_TYPE_H_
|
||||||
|
|
||||||
|
#include <fx/macros.h>
|
||||||
|
|
||||||
|
FX_DECLS_BEGIN;
|
||||||
|
|
||||||
|
#define __FX_VALUE_TYPE_BASEID 0xe58f43c1c468899c
|
||||||
|
|
||||||
|
enum {
|
||||||
|
__FX_VALUE_TYPE_BOOL = 1,
|
||||||
|
__FX_VALUE_TYPE_I16,
|
||||||
|
__FX_VALUE_TYPE_U16,
|
||||||
|
__FX_VALUE_TYPE_I32,
|
||||||
|
__FX_VALUE_TYPE_U32,
|
||||||
|
__FX_VALUE_TYPE_I64,
|
||||||
|
__FX_VALUE_TYPE_U64,
|
||||||
|
__FX_VALUE_TYPE_IPTR,
|
||||||
|
__FX_VALUE_TYPE_UPTR,
|
||||||
|
|
||||||
|
__FX_VALUE_TYPE_SBYTE,
|
||||||
|
__FX_VALUE_TYPE_BYTE,
|
||||||
|
__FX_VALUE_TYPE_SHORT,
|
||||||
|
__FX_VALUE_TYPE_USHORT,
|
||||||
|
__FX_VALUE_TYPE_INT,
|
||||||
|
__FX_VALUE_TYPE_UINT,
|
||||||
|
__FX_VALUE_TYPE_LONG,
|
||||||
|
__FX_VALUE_TYPE_ULONG,
|
||||||
|
__FX_VALUE_TYPE_LONGLONG,
|
||||||
|
__FX_VALUE_TYPE_ULONGLONG,
|
||||||
|
__FX_VALUE_TYPE_SIZE,
|
||||||
|
|
||||||
|
__FX_VALUE_TYPE_FLOAT,
|
||||||
|
__FX_VALUE_TYPE_DOUBLE,
|
||||||
|
|
||||||
|
__FX_VALUE_TYPE_CSTR,
|
||||||
|
__FX_VALUE_TYPE_POINTER,
|
||||||
|
};
|
||||||
|
|
||||||
|
#define FX_TYPE_VALUE_TYPE (fx_value_type_get_type())
|
||||||
|
|
||||||
|
FX_DECLARE_TYPE(fx_value_type);
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_value_type)
|
||||||
|
FX_TYPE_CLASS_DECLARATION_END(fx_value_type)
|
||||||
|
|
||||||
|
FX_DECLS_END;
|
||||||
|
|
||||||
|
FX_API fx_type_id fx_value_type_get_type(void);
|
||||||
|
FX_API bool fx_type_is_value_type(fx_type_id ty);
|
||||||
|
FX_API unsigned int __fx_type_get_value_type(fx_type_id ty);
|
||||||
|
|
||||||
|
#endif
|
||||||
+68
-46
@@ -1,66 +1,84 @@
|
|||||||
#ifndef FX_VALUE_H_
|
#ifndef FX_VALUE_H_
|
||||||
#define FX_VALUE_H_
|
#define FX_VALUE_H_
|
||||||
|
|
||||||
|
#include <fx/bool.h>
|
||||||
|
#include <fx/cstr.h>
|
||||||
|
#include <fx/float.h>
|
||||||
|
#include <fx/int.h>
|
||||||
#include <fx/object.h>
|
#include <fx/object.h>
|
||||||
|
#include <fx/pointer.h>
|
||||||
#include <fx/type.h>
|
#include <fx/type.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#define FX_VALUE_EMPTY ((fx_value) {})
|
#define FX_VALUE_EMPTY ((fx_value) {})
|
||||||
#define FX_VALUE_BOOL(v) \
|
#define __FX_VALUE_CREATE(type, member, value) \
|
||||||
((fx_value) { \
|
((fx_value) { \
|
||||||
.v_type.t_primitive = FX_VALUE_TYPE_BOOL, \
|
.v_type = FX_TYPE_##type, \
|
||||||
.v_bool = (v), \
|
.member = (value), \
|
||||||
})
|
|
||||||
#define FX_VALUE_INT(v) \
|
|
||||||
((fx_value) { \
|
|
||||||
.v_type.t_primitive = FX_VALUE_TYPE_INT, \
|
|
||||||
.v_int = (v), \
|
|
||||||
})
|
|
||||||
#define FX_VALUE_UINT(v) \
|
|
||||||
((fx_value) { \
|
|
||||||
.v_type.t_primitive = FX_VALUE_TYPE_UINT, \
|
|
||||||
.v_uint = (v), \
|
|
||||||
})
|
|
||||||
#define FX_VALUE_DOUBLE(v) \
|
|
||||||
((fx_value) { \
|
|
||||||
.v_type.t_primitive = FX_VALUE_TYPE_DOUBLE, \
|
|
||||||
.v_double = (v), \
|
|
||||||
})
|
|
||||||
#define FX_VALUE_CSTR(v) \
|
|
||||||
((fx_value) { \
|
|
||||||
.v_type.t_primitive = FX_VALUE_TYPE_CSTR, \
|
|
||||||
.v_cstr = (v), \
|
|
||||||
})
|
|
||||||
#define FX_VALUE_POINTER(v) \
|
|
||||||
((fx_value) { \
|
|
||||||
.v_type.t_primitive = FX_VALUE_TYPE_POINTER, \
|
|
||||||
.v_pointer = (v), \
|
|
||||||
})
|
})
|
||||||
|
#define FX_BOOL(v) __FX_VALUE_CREATE(BOOL, v_bool, v)
|
||||||
|
#define FX_I16(v) __FX_VALUE_CREATE(I16, v_i16, v)
|
||||||
|
#define FX_U16(v) __FX_VALUE_CREATE(U16, v_u16, v)
|
||||||
|
#define FX_I32(v) __FX_VALUE_CREATE(I32, v_i32, v)
|
||||||
|
#define FX_U32(v) __FX_VALUE_CREATE(U32, v_u32, v)
|
||||||
|
#define FX_I64(v) __FX_VALUE_CREATE(I64, v_i64, v)
|
||||||
|
#define FX_U64(v) __FX_VALUE_CREATE(U64, v_u64, v)
|
||||||
|
#define FX_IPTR(v) __FX_VALUE_CREATE(IPTR, v_iptr, v)
|
||||||
|
#define FX_UPTR(v) __FX_VALUE_CREATE(UPTR, v_uptr, v)
|
||||||
|
|
||||||
typedef enum fx_value_type {
|
#define FX_SBYTE(v) __FX_VALUE_CREATE(SBYTE, v_sbyte, v)
|
||||||
FX_VALUE_TYPE_NONE = 0,
|
#define FX_BYTE(v) __FX_VALUE_CREATE(BYTE, v_byte, v)
|
||||||
FX_VALUE_TYPE_BOOL,
|
#define FX_SHORT(v) __FX_VALUE_CREATE(SHORT, v_short, v)
|
||||||
FX_VALUE_TYPE_INT,
|
#define FX_USHORT(v) __FX_VALUE_CREATE(USHORT, v_ushort, v)
|
||||||
FX_VALUE_TYPE_UINT,
|
#define FX_INT(v) __FX_VALUE_CREATE(INT, v_int, v)
|
||||||
FX_VALUE_TYPE_DOUBLE,
|
#define FX_UINT(v) __FX_VALUE_CREATE(UINT, v_uint, v)
|
||||||
FX_VALUE_TYPE_CSTR,
|
#define FX_LONG(v) __FX_VALUE_CREATE(LONG, v_long, v)
|
||||||
FX_VALUE_TYPE_POINTER,
|
#define FX_ULONG(v) __FX_VALUE_CREATE(ULONG, v_ulong, v)
|
||||||
|
#define FX_LONGLONG(v) __FX_VALUE_CREATE(LONGLONG, v_int, v)
|
||||||
|
#define FX_ULONGLONG(v) __FX_VALUE_CREATE(ULONGLONG, v_uint, v)
|
||||||
|
#define FX_SIZE(v) __FX_VALUE_CREATE(SIZE, v_size, v)
|
||||||
|
|
||||||
/* any value greater than this represents an object fx_type_id */
|
#define FX_FLOAT(v) __FX_VALUE_CREATE(FLOAT, v_float, v)
|
||||||
__FX_VALUE_TYPE_OBJECT_BOUNDARY = 1024,
|
#define FX_DOUBLE(v) __FX_VALUE_CREATE(DOUBLE, v_double, v)
|
||||||
} fx_value_type;
|
|
||||||
|
#define FX_CSTR(v) __FX_VALUE_CREATE(CSTR, v_cstr, v)
|
||||||
|
#define FX_POINTER(v) __FX_VALUE_CREATE(POINTER, v_pointer, v)
|
||||||
|
#define FX_VALUE_OBJECT(v) \
|
||||||
|
((fx_value) { \
|
||||||
|
.v_type = fx_object_query_type((fx_object *)v), \
|
||||||
|
.v_object = (fx_object *)(v), \
|
||||||
|
})
|
||||||
|
|
||||||
typedef struct fx_value {
|
typedef struct fx_value {
|
||||||
union {
|
fx_type_id v_type;
|
||||||
fx_value_type t_primitive;
|
|
||||||
fx_type_id t_object;
|
|
||||||
} v_type;
|
|
||||||
|
|
||||||
union {
|
union {
|
||||||
bool v_bool;
|
bool v_bool;
|
||||||
intptr_t v_int;
|
|
||||||
uintptr_t v_uint;
|
i16 v_i16;
|
||||||
|
u16 v_u16;
|
||||||
|
i32 v_i32;
|
||||||
|
u32 v_u32;
|
||||||
|
i64 v_i64;
|
||||||
|
u64 v_u64;
|
||||||
|
iptr v_iptr;
|
||||||
|
uptr v_uptr;
|
||||||
|
|
||||||
|
sbyte v_sbyte;
|
||||||
|
byte v_byte;
|
||||||
|
short v_short;
|
||||||
|
unsigned short v_ushort;
|
||||||
|
int v_int;
|
||||||
|
unsigned int v_uint;
|
||||||
|
long v_long;
|
||||||
|
unsigned long v_ulong;
|
||||||
|
long long v_longlong;
|
||||||
|
unsigned long long v_ulonglong;
|
||||||
|
size_t v_size;
|
||||||
|
|
||||||
|
float v_float;
|
||||||
double v_double;
|
double v_double;
|
||||||
|
|
||||||
const char *v_cstr;
|
const char *v_cstr;
|
||||||
void *v_pointer;
|
void *v_pointer;
|
||||||
fx_object *v_object;
|
fx_object *v_object;
|
||||||
@@ -68,11 +86,15 @@ typedef struct fx_value {
|
|||||||
} fx_value;
|
} fx_value;
|
||||||
|
|
||||||
FX_API void fx_value_init(fx_value *v, fx_type_id type);
|
FX_API void fx_value_init(fx_value *v, fx_type_id type);
|
||||||
FX_API void fx_value_init_primitive(fx_value *v, fx_value_type type);
|
|
||||||
|
|
||||||
FX_API void fx_value_copy(fx_value *dst, fx_value *src);
|
FX_API void fx_value_copy(fx_value *dst, fx_value *src);
|
||||||
FX_API void fx_value_copy_array(fx_value *dst, fx_value *src, size_t count);
|
FX_API void fx_value_copy_array(fx_value *dst, fx_value *src, size_t count);
|
||||||
|
|
||||||
|
static inline bool fx_value_is_type(const fx_value *value, fx_type_id ty)
|
||||||
|
{
|
||||||
|
return fx_type_id_compare(value->v_type, ty) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
FX_API void fx_value_unset(fx_value *v);
|
FX_API void fx_value_unset(fx_value *v);
|
||||||
FX_API void fx_value_unset_array(fx_value *v, size_t length);
|
FX_API void fx_value_unset_array(fx_value *v, size_t length);
|
||||||
|
|
||||||
|
|||||||
@@ -1,272 +0,0 @@
|
|||||||
#include <fx/int.h>
|
|
||||||
#include <fx/stream.h>
|
|
||||||
#include <inttypes.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
/*** PRIVATE DATA *************************************************************/
|
|
||||||
|
|
||||||
enum int_type {
|
|
||||||
INT_REGULAR = 0,
|
|
||||||
INT_INF_POSITIVE,
|
|
||||||
INT_INF_NEGATIVE,
|
|
||||||
INT_NAN_POSITIVE,
|
|
||||||
INT_NAN_NEGATIVE,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct fx_int_p {
|
|
||||||
enum int_type i_type;
|
|
||||||
intptr_t i_value;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*** PRIVATE FUNCTIONS ********************************************************/
|
|
||||||
|
|
||||||
static bool int_get_value(const struct fx_int_p *i)
|
|
||||||
{
|
|
||||||
return i->i_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void int_set_value(struct fx_int_p *i, intptr_t v)
|
|
||||||
{
|
|
||||||
i->i_type = INT_REGULAR;
|
|
||||||
i->i_value = v;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void int_set_value_nan(struct fx_int_p *i)
|
|
||||||
{
|
|
||||||
i->i_type = INT_NAN_POSITIVE;
|
|
||||||
i->i_value = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void int_set_value_nan_negative(struct fx_int_p *i)
|
|
||||||
{
|
|
||||||
i->i_type = INT_NAN_NEGATIVE;
|
|
||||||
i->i_value = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void int_set_value_inf(struct fx_int_p *i)
|
|
||||||
{
|
|
||||||
i->i_type = INT_INF_POSITIVE;
|
|
||||||
i->i_value = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void int_set_value_inf_negative(struct fx_int_p *i)
|
|
||||||
{
|
|
||||||
i->i_type = INT_INF_NEGATIVE;
|
|
||||||
i->i_value = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool int_is_nan(struct fx_int_p *i)
|
|
||||||
{
|
|
||||||
return i->i_type == INT_NAN_POSITIVE || i->i_type == INT_NAN_NEGATIVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool int_is_nan_positive(struct fx_int_p *i)
|
|
||||||
{
|
|
||||||
return i->i_type == INT_NAN_POSITIVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool int_is_nan_negative(struct fx_int_p *i)
|
|
||||||
{
|
|
||||||
return i->i_type == INT_NAN_NEGATIVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool int_is_inf(struct fx_int_p *i)
|
|
||||||
{
|
|
||||||
return i->i_type == INT_INF_POSITIVE || i->i_type == INT_INF_NEGATIVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool int_is_inf_positive(struct fx_int_p *i)
|
|
||||||
{
|
|
||||||
return i->i_type == INT_INF_POSITIVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool int_is_inf_negative(struct fx_int_p *i)
|
|
||||||
{
|
|
||||||
return i->i_type == INT_INF_NEGATIVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*** PUBLIC FUNCTIONS *********************************************************/
|
|
||||||
|
|
||||||
fx_int *fx_int_create(intptr_t value)
|
|
||||||
{
|
|
||||||
fx_int *i = fx_object_create(FX_TYPE_INT);
|
|
||||||
if (!i) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct fx_int_p *p = fx_object_get_private(i, FX_TYPE_INT);
|
|
||||||
p->i_type = INT_REGULAR;
|
|
||||||
p->i_value = value;
|
|
||||||
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
fx_int *fx_int_create_nan(void)
|
|
||||||
{
|
|
||||||
fx_int *i = fx_object_create(FX_TYPE_INT);
|
|
||||||
if (!i) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct fx_int_p *p = fx_object_get_private(i, FX_TYPE_INT);
|
|
||||||
p->i_type = INT_NAN_POSITIVE;
|
|
||||||
p->i_value = 0;
|
|
||||||
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
fx_int *fx_int_create_nan_negative(void)
|
|
||||||
{
|
|
||||||
fx_int *i = fx_object_create(FX_TYPE_INT);
|
|
||||||
if (!i) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct fx_int_p *p = fx_object_get_private(i, FX_TYPE_INT);
|
|
||||||
p->i_type = INT_NAN_NEGATIVE;
|
|
||||||
p->i_value = 0;
|
|
||||||
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
fx_int *fx_int_create_inf(void)
|
|
||||||
{
|
|
||||||
fx_int *i = fx_object_create(FX_TYPE_INT);
|
|
||||||
if (!i) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct fx_int_p *p = fx_object_get_private(i, FX_TYPE_INT);
|
|
||||||
p->i_type = INT_INF_POSITIVE;
|
|
||||||
p->i_value = 0;
|
|
||||||
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
fx_int *fx_int_create_inf_negative(void)
|
|
||||||
{
|
|
||||||
fx_int *i = fx_object_create(FX_TYPE_INT);
|
|
||||||
if (!i) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct fx_int_p *p = fx_object_get_private(i, FX_TYPE_INT);
|
|
||||||
p->i_type = INT_INF_NEGATIVE;
|
|
||||||
p->i_value = 0;
|
|
||||||
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
intptr_t fx_int_get_value(const fx_int *i)
|
|
||||||
{
|
|
||||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_INT, int_get_value, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
void fx_int_set_value(fx_int *i, intptr_t v)
|
|
||||||
{
|
|
||||||
FX_CLASS_DISPATCH_STATIC_V(FX_TYPE_INT, int_set_value, i, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
void fx_int_set_value_nan(fx_int *i)
|
|
||||||
{
|
|
||||||
FX_CLASS_DISPATCH_STATIC_V0(FX_TYPE_INT, int_set_value_nan, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
void fx_int_set_value_nan_negative(fx_int *i)
|
|
||||||
{
|
|
||||||
FX_CLASS_DISPATCH_STATIC_V0(FX_TYPE_INT, int_set_value_nan_negative, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
void fx_int_set_value_inf(fx_int *i)
|
|
||||||
{
|
|
||||||
FX_CLASS_DISPATCH_STATIC_V0(FX_TYPE_INT, int_set_value_inf, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
void fx_int_set_value_inf_negative(fx_int *i)
|
|
||||||
{
|
|
||||||
FX_CLASS_DISPATCH_STATIC_V0(FX_TYPE_INT, int_set_value_inf_negative, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool fx_int_is_nan(const fx_int *i)
|
|
||||||
{
|
|
||||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_INT, int_is_nan, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool fx_int_is_nan_positive(const fx_int *i)
|
|
||||||
{
|
|
||||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_INT, int_is_nan_positive, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool fx_int_is_nan_negative(const fx_int *i)
|
|
||||||
{
|
|
||||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_INT, int_is_nan_negative, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool fx_int_is_inf(const fx_int *i)
|
|
||||||
{
|
|
||||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_INT, int_is_inf, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool fx_int_is_inf_positive(const fx_int *i)
|
|
||||||
{
|
|
||||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_INT, int_is_inf_positive, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool fx_int_is_inf_negative(const fx_int *i)
|
|
||||||
{
|
|
||||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_INT, int_is_inf_negative, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*** VIRTUAL FUNCTIONS ********************************************************/
|
|
||||||
|
|
||||||
static void int_init(fx_object *obj, void *priv)
|
|
||||||
{
|
|
||||||
struct fx_int_p *i = priv;
|
|
||||||
|
|
||||||
i->i_type = INT_REGULAR;
|
|
||||||
i->i_value = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void int_fini(fx_object *obj, void *priv)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static void int_to_string(const fx_object *obj, fx_stream *out)
|
|
||||||
{
|
|
||||||
struct fx_int_p *i = fx_object_get_private(obj, FX_TYPE_INT);
|
|
||||||
switch (i->i_type) {
|
|
||||||
case INT_REGULAR:
|
|
||||||
fx_stream_write_fmt(out, NULL, "%" PRIdPTR, i->i_value);
|
|
||||||
break;
|
|
||||||
case INT_INF_POSITIVE:
|
|
||||||
fx_stream_write_cstr(out, "inf", NULL);
|
|
||||||
break;
|
|
||||||
case INT_INF_NEGATIVE:
|
|
||||||
fx_stream_write_cstr(out, "-inf", NULL);
|
|
||||||
break;
|
|
||||||
case INT_NAN_POSITIVE:
|
|
||||||
fx_stream_write_cstr(out, "NaN", NULL);
|
|
||||||
break;
|
|
||||||
case INT_NAN_NEGATIVE:
|
|
||||||
fx_stream_write_cstr(out, "-NaN", NULL);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*** CLASS DEFINITION *********************************************************/
|
|
||||||
|
|
||||||
FX_TYPE_CLASS_BEGIN(fx_int)
|
|
||||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
|
||||||
FX_INTERFACE_ENTRY(to_string) = int_to_string;
|
|
||||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
|
||||||
FX_TYPE_CLASS_END(fx_int)
|
|
||||||
|
|
||||||
FX_TYPE_DEFINITION_BEGIN(fx_int)
|
|
||||||
FX_TYPE_ID(0x3b20f57a, 0x2ddf, 0x4682, 0x81c4, 0x4fe404a6524e);
|
|
||||||
FX_TYPE_CLASS(fx_int_class);
|
|
||||||
FX_TYPE_INSTANCE_PRIVATE(struct fx_int_p);
|
|
||||||
FX_TYPE_INSTANCE_INIT(int_init);
|
|
||||||
FX_TYPE_INSTANCE_FINI(int_fini);
|
|
||||||
FX_TYPE_DEFINITION_END(fx_int)
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#include <fx/int.h>
|
||||||
|
#include <fx/value-type.h>
|
||||||
|
|
||||||
|
/*** CLASS DEFINITION *********************************************************/
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_BEGIN(fx_byte)
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_TYPE_CLASS_END(fx_byte)
|
||||||
|
|
||||||
|
FX_TYPE_DEFINITION_BEGIN(fx_byte)
|
||||||
|
__FX_VALUE_TYPE_ID(BYTE);
|
||||||
|
FX_TYPE_EXTENDS(FX_TYPE_VALUE_TYPE);
|
||||||
|
FX_TYPE_NAME("fx.byte");
|
||||||
|
FX_TYPE_CLASS(fx_byte_class);
|
||||||
|
FX_TYPE_INSTANCE_PRIVATE(byte);
|
||||||
|
FX_TYPE_DEFINITION_END(fx_byte)
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
#include <fx/int.h>
|
||||||
|
#include <fx/value-type.h>
|
||||||
|
|
||||||
|
#define SWAP16(v) (((v << 8) & 0xFF00) | ((v >> 8) & 0x00FF))
|
||||||
|
|
||||||
|
i16 fx_i16_htob(i16 v)
|
||||||
|
{
|
||||||
|
#if FX_ENDIAN == 1
|
||||||
|
return v;
|
||||||
|
#else
|
||||||
|
return SWAP16(v);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
i16 fx_i16_htos(i16 v)
|
||||||
|
{
|
||||||
|
#if FX_ENDIAN == 0
|
||||||
|
return v;
|
||||||
|
#else
|
||||||
|
return SWAP16(v);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
i16 fx_i16_btoh(i16 v)
|
||||||
|
{
|
||||||
|
#if FX_ENDIAN == 1
|
||||||
|
return v;
|
||||||
|
#else
|
||||||
|
return SWAP16(v);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
i16 fx_i16_stoh(i16 v)
|
||||||
|
{
|
||||||
|
#if FX_ENDIAN == 0
|
||||||
|
return v;
|
||||||
|
#else
|
||||||
|
return SWAP16(v);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
/*** CLASS DEFINITION *********************************************************/
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_BEGIN(fx_i16)
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_TYPE_CLASS_END(fx_i16)
|
||||||
|
|
||||||
|
FX_TYPE_DEFINITION_BEGIN(fx_i16)
|
||||||
|
__FX_VALUE_TYPE_ID(I16);
|
||||||
|
FX_TYPE_EXTENDS(FX_TYPE_VALUE_TYPE);
|
||||||
|
FX_TYPE_NAME("fx.i16");
|
||||||
|
FX_TYPE_CLASS(fx_i16_class);
|
||||||
|
FX_TYPE_INSTANCE_PRIVATE(i16);
|
||||||
|
FX_TYPE_DEFINITION_END(fx_i16)
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
#include <fx/int.h>
|
||||||
|
#include <fx/value-type.h>
|
||||||
|
|
||||||
|
#define SWAP32(v) \
|
||||||
|
(((v << 24) & 0xFF000000) | ((v << 8) & 0x00FF0000) \
|
||||||
|
| ((v >> 8) & 0x0000FF00) | ((v >> 24) & 0x000000FF))
|
||||||
|
|
||||||
|
i32 fx_i32_htob(i32 v)
|
||||||
|
{
|
||||||
|
#if FX_ENDIAN == 1
|
||||||
|
return v;
|
||||||
|
#else
|
||||||
|
return SWAP32(v);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
i32 fx_i32_htos(i32 v)
|
||||||
|
{
|
||||||
|
#if FX_ENDIAN == 0
|
||||||
|
return v;
|
||||||
|
#else
|
||||||
|
return SWAP32(v);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
i32 fx_i32_btoh(i32 v)
|
||||||
|
{
|
||||||
|
#if FX_ENDIAN == 1
|
||||||
|
return v;
|
||||||
|
#else
|
||||||
|
return SWAP32(v);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
i32 fx_i32_stoh(i32 v)
|
||||||
|
{
|
||||||
|
#if FX_ENDIAN == 0
|
||||||
|
return v;
|
||||||
|
#else
|
||||||
|
return SWAP32(v);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/*** CLASS DEFINITION *********************************************************/
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_BEGIN(fx_i32)
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_TYPE_CLASS_END(fx_i32)
|
||||||
|
|
||||||
|
FX_TYPE_DEFINITION_BEGIN(fx_i32)
|
||||||
|
__FX_VALUE_TYPE_ID(I32);
|
||||||
|
FX_TYPE_EXTENDS(FX_TYPE_VALUE_TYPE);
|
||||||
|
FX_TYPE_NAME("fx.i32");
|
||||||
|
FX_TYPE_CLASS(fx_i32_class);
|
||||||
|
FX_TYPE_INSTANCE_PRIVATE(i32);
|
||||||
|
FX_TYPE_DEFINITION_END(fx_i32)
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
#include <fx/int.h>
|
||||||
|
#include <fx/value-type.h>
|
||||||
|
|
||||||
|
/* clang-format off */
|
||||||
|
#define SWAP64(v) \
|
||||||
|
(((v << 56) & 0xFF00000000000000) | ((v >> 56) & 0x00000000000000FF) \
|
||||||
|
|((v << 40) & 0x00FF000000000000) | ((v >> 40) & 0x000000000000FF00) \
|
||||||
|
|((v << 24) & 0x0000FF0000000000) | ((v >> 24) & 0x0000000000FF0000) \
|
||||||
|
|((v << 8) & 0x000000FF00000000) | ((v >> 8) & 0x00000000FF000000))
|
||||||
|
/* clang-format on */
|
||||||
|
|
||||||
|
i64 fx_i64_htob(i64 v)
|
||||||
|
{
|
||||||
|
#if FX_ENDIAN == 1
|
||||||
|
return v;
|
||||||
|
#else
|
||||||
|
return SWAP64(v);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
i64 fx_i64_htos(i64 v)
|
||||||
|
{
|
||||||
|
#if FX_ENDIAN == 0
|
||||||
|
return v;
|
||||||
|
#else
|
||||||
|
return SWAP64(v);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
i64 fx_i64_btoh(i64 v)
|
||||||
|
{
|
||||||
|
#if FX_ENDIAN == 1
|
||||||
|
return v;
|
||||||
|
#else
|
||||||
|
return SWAP64(v);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
i64 fx_i64_stoh(i64 v)
|
||||||
|
{
|
||||||
|
#if FX_ENDIAN == 0
|
||||||
|
return v;
|
||||||
|
#else
|
||||||
|
return SWAP64(v);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/*** CLASS DEFINITION *********************************************************/
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_BEGIN(fx_i64)
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_TYPE_CLASS_END(fx_i64)
|
||||||
|
|
||||||
|
FX_TYPE_DEFINITION_BEGIN(fx_i64)
|
||||||
|
__FX_VALUE_TYPE_ID(I64);
|
||||||
|
FX_TYPE_EXTENDS(FX_TYPE_VALUE_TYPE);
|
||||||
|
FX_TYPE_NAME("fx.i64");
|
||||||
|
FX_TYPE_CLASS(fx_i64_class);
|
||||||
|
FX_TYPE_INSTANCE_PRIVATE(i64);
|
||||||
|
FX_TYPE_DEFINITION_END(fx_i64)
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#include <fx/int.h>
|
||||||
|
#include <fx/value-type.h>
|
||||||
|
|
||||||
|
/*** CLASS DEFINITION *********************************************************/
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_BEGIN(fx_int)
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_TYPE_CLASS_END(fx_int)
|
||||||
|
|
||||||
|
FX_TYPE_DEFINITION_BEGIN(fx_int)
|
||||||
|
__FX_VALUE_TYPE_ID(INT);
|
||||||
|
FX_TYPE_EXTENDS(FX_TYPE_VALUE_TYPE);
|
||||||
|
FX_TYPE_NAME("fx.int");
|
||||||
|
FX_TYPE_CLASS(fx_int_class);
|
||||||
|
FX_TYPE_INSTANCE_PRIVATE(int);
|
||||||
|
FX_TYPE_DEFINITION_END(fx_int)
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#include <fx/int.h>
|
||||||
|
#include <fx/value-type.h>
|
||||||
|
|
||||||
|
/*** CLASS DEFINITION *********************************************************/
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_BEGIN(fx_iptr)
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_TYPE_CLASS_END(fx_iptr)
|
||||||
|
|
||||||
|
FX_TYPE_DEFINITION_BEGIN(fx_iptr)
|
||||||
|
__FX_VALUE_TYPE_ID(IPTR);
|
||||||
|
FX_TYPE_EXTENDS(FX_TYPE_VALUE_TYPE);
|
||||||
|
FX_TYPE_NAME("fx.iptr");
|
||||||
|
FX_TYPE_CLASS(fx_iptr_class);
|
||||||
|
FX_TYPE_INSTANCE_PRIVATE(iptr);
|
||||||
|
FX_TYPE_DEFINITION_END(fx_iptr)
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#include <fx/int.h>
|
||||||
|
#include <fx/value-type.h>
|
||||||
|
|
||||||
|
/*** CLASS DEFINITION *********************************************************/
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_BEGIN(fx_long)
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_TYPE_CLASS_END(fx_long)
|
||||||
|
|
||||||
|
FX_TYPE_DEFINITION_BEGIN(fx_long)
|
||||||
|
__FX_VALUE_TYPE_ID(LONG);
|
||||||
|
FX_TYPE_EXTENDS(FX_TYPE_VALUE_TYPE);
|
||||||
|
FX_TYPE_NAME("fx.long");
|
||||||
|
FX_TYPE_CLASS(fx_long_class);
|
||||||
|
FX_TYPE_INSTANCE_PRIVATE(long);
|
||||||
|
FX_TYPE_DEFINITION_END(fx_long)
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#include <fx/int.h>
|
||||||
|
#include <fx/value-type.h>
|
||||||
|
|
||||||
|
/*** CLASS DEFINITION *********************************************************/
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_BEGIN(fx_longlong)
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_TYPE_CLASS_END(fx_longlong)
|
||||||
|
|
||||||
|
FX_TYPE_DEFINITION_BEGIN(fx_longlong)
|
||||||
|
__FX_VALUE_TYPE_ID(LONGLONG);
|
||||||
|
FX_TYPE_EXTENDS(FX_TYPE_VALUE_TYPE);
|
||||||
|
FX_TYPE_NAME("fx.longlong");
|
||||||
|
FX_TYPE_CLASS(fx_longlong_class);
|
||||||
|
FX_TYPE_INSTANCE_PRIVATE(long long);
|
||||||
|
FX_TYPE_DEFINITION_END(fx_longlong)
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#include <fx/int.h>
|
||||||
|
#include <fx/value-type.h>
|
||||||
|
|
||||||
|
/*** CLASS DEFINITION *********************************************************/
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_BEGIN(fx_sbyte)
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_TYPE_CLASS_END(fx_sbyte)
|
||||||
|
|
||||||
|
FX_TYPE_DEFINITION_BEGIN(fx_sbyte)
|
||||||
|
__FX_VALUE_TYPE_ID(SBYTE);
|
||||||
|
FX_TYPE_EXTENDS(FX_TYPE_VALUE_TYPE);
|
||||||
|
FX_TYPE_NAME("fx.sbyte");
|
||||||
|
FX_TYPE_CLASS(fx_sbyte_class);
|
||||||
|
FX_TYPE_INSTANCE_PRIVATE(sbyte);
|
||||||
|
FX_TYPE_DEFINITION_END(fx_sbyte)
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
|
||||||
|
#include <fx/int.h>
|
||||||
|
#include <fx/value-type.h>
|
||||||
|
|
||||||
|
/*** CLASS DEFINITION *********************************************************/
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_BEGIN(fx_short)
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_TYPE_CLASS_END(fx_short)
|
||||||
|
|
||||||
|
FX_TYPE_DEFINITION_BEGIN(fx_short)
|
||||||
|
__FX_VALUE_TYPE_ID(SHORT);
|
||||||
|
FX_TYPE_EXTENDS(FX_TYPE_VALUE_TYPE);
|
||||||
|
FX_TYPE_NAME("fx.short");
|
||||||
|
FX_TYPE_CLASS(fx_short_class);
|
||||||
|
FX_TYPE_INSTANCE_PRIVATE(short);
|
||||||
|
FX_TYPE_DEFINITION_END(fx_short)
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#include <fx/int.h>
|
||||||
|
#include <fx/value-type.h>
|
||||||
|
|
||||||
|
/*** CLASS DEFINITION *********************************************************/
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_BEGIN(fx_size)
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_TYPE_CLASS_END(fx_size)
|
||||||
|
|
||||||
|
FX_TYPE_DEFINITION_BEGIN(fx_size)
|
||||||
|
__FX_VALUE_TYPE_ID(SIZE);
|
||||||
|
FX_TYPE_EXTENDS(FX_TYPE_VALUE_TYPE);
|
||||||
|
FX_TYPE_NAME("fx.size");
|
||||||
|
FX_TYPE_CLASS(fx_size_class);
|
||||||
|
FX_TYPE_INSTANCE_PRIVATE(size_t);
|
||||||
|
FX_TYPE_DEFINITION_END(fx_size)
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
#include <fx/int.h>
|
||||||
|
#include <fx/value-type.h>
|
||||||
|
|
||||||
|
#define SWAP16(v) (((v << 8) & 0xFF00) | ((v >> 8) & 0x00FF))
|
||||||
|
|
||||||
|
u16 fx_u16_htob(u16 v)
|
||||||
|
{
|
||||||
|
#if FX_ENDIAN == 1
|
||||||
|
return v;
|
||||||
|
#else
|
||||||
|
return SWAP16(v);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
u16 fx_u16_htos(u16 v)
|
||||||
|
{
|
||||||
|
#if FX_ENDIAN == 0
|
||||||
|
return v;
|
||||||
|
#else
|
||||||
|
return SWAP16(v);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
u16 fx_u16_btoh(u16 v)
|
||||||
|
{
|
||||||
|
#if FX_ENDIAN == 1
|
||||||
|
return v;
|
||||||
|
#else
|
||||||
|
return SWAP16(v);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
u16 fx_u16_stoh(u16 v)
|
||||||
|
{
|
||||||
|
#if FX_ENDIAN == 0
|
||||||
|
return v;
|
||||||
|
#else
|
||||||
|
return SWAP16(v);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/*** CLASS DEFINITION *********************************************************/
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_BEGIN(fx_u16)
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_TYPE_CLASS_END(fx_u16)
|
||||||
|
|
||||||
|
FX_TYPE_DEFINITION_BEGIN(fx_u16)
|
||||||
|
__FX_VALUE_TYPE_ID(U16);
|
||||||
|
FX_TYPE_EXTENDS(FX_TYPE_VALUE_TYPE);
|
||||||
|
FX_TYPE_NAME("fx.u16");
|
||||||
|
FX_TYPE_CLASS(fx_u16_class);
|
||||||
|
FX_TYPE_INSTANCE_PRIVATE(u16);
|
||||||
|
FX_TYPE_DEFINITION_END(fx_u16)
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
#include <fx/int.h>
|
||||||
|
#include <fx/value-type.h>
|
||||||
|
|
||||||
|
#define SWAP32(v) \
|
||||||
|
(((v << 24) & 0xFF000000) | ((v << 8) & 0x00FF0000) \
|
||||||
|
| ((v >> 8) & 0x0000FF00) | ((v >> 24) & 0x000000FF))
|
||||||
|
|
||||||
|
u32 fx_u32_htob(u32 v)
|
||||||
|
{
|
||||||
|
#if FX_ENDIAN == 1
|
||||||
|
return v;
|
||||||
|
#else
|
||||||
|
return SWAP32(v);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 fx_u32_htos(u32 v)
|
||||||
|
{
|
||||||
|
#if FX_ENDIAN == 0
|
||||||
|
return v;
|
||||||
|
#else
|
||||||
|
return SWAP32(v);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 fx_u32_btoh(u32 v)
|
||||||
|
{
|
||||||
|
#if FX_ENDIAN == 1
|
||||||
|
return v;
|
||||||
|
#else
|
||||||
|
return SWAP32(v);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 fx_u32_stoh(u32 v)
|
||||||
|
{
|
||||||
|
#if FX_ENDIAN == 0
|
||||||
|
return v;
|
||||||
|
#else
|
||||||
|
return SWAP32(v);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/*** CLASS DEFINITION *********************************************************/
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_BEGIN(fx_u32)
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_TYPE_CLASS_END(fx_u32)
|
||||||
|
|
||||||
|
FX_TYPE_DEFINITION_BEGIN(fx_u32)
|
||||||
|
__FX_VALUE_TYPE_ID(U32);
|
||||||
|
FX_TYPE_EXTENDS(FX_TYPE_VALUE_TYPE);
|
||||||
|
FX_TYPE_NAME("fx.u32");
|
||||||
|
FX_TYPE_CLASS(fx_u32_class);
|
||||||
|
FX_TYPE_INSTANCE_PRIVATE(u32);
|
||||||
|
FX_TYPE_DEFINITION_END(fx_u32)
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
#include <fx/int.h>
|
||||||
|
#include <fx/value-type.h>
|
||||||
|
|
||||||
|
/* clang-format off */
|
||||||
|
#define SWAP64(v) \
|
||||||
|
(((v << 56) & 0xFF00000000000000) | ((v >> 56) & 0x00000000000000FF) \
|
||||||
|
|((v << 40) & 0x00FF000000000000) | ((v >> 40) & 0x000000000000FF00) \
|
||||||
|
|((v << 24) & 0x0000FF0000000000) | ((v >> 24) & 0x0000000000FF0000) \
|
||||||
|
|((v << 8) & 0x000000FF00000000) | ((v >> 8) & 0x00000000FF000000))
|
||||||
|
/* clang-format on */
|
||||||
|
|
||||||
|
u64 fx_u64_htob(u64 v)
|
||||||
|
{
|
||||||
|
#if FX_ENDIAN == 1
|
||||||
|
return v;
|
||||||
|
#else
|
||||||
|
return SWAP64(v);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
u64 fx_u64_htos(u64 v)
|
||||||
|
{
|
||||||
|
#if FX_ENDIAN == 0
|
||||||
|
return v;
|
||||||
|
#else
|
||||||
|
return SWAP64(v);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
u64 fx_u64_btoh(u64 v)
|
||||||
|
{
|
||||||
|
#if FX_ENDIAN == 1
|
||||||
|
return v;
|
||||||
|
#else
|
||||||
|
return SWAP64(v);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
u64 fx_u64_stoh(u64 v)
|
||||||
|
{
|
||||||
|
#if FX_ENDIAN == 0
|
||||||
|
return v;
|
||||||
|
#else
|
||||||
|
return SWAP64(v);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/*** CLASS DEFINITION *********************************************************/
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_BEGIN(fx_u64)
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_TYPE_CLASS_END(fx_u64)
|
||||||
|
|
||||||
|
FX_TYPE_DEFINITION_BEGIN(fx_u64)
|
||||||
|
__FX_VALUE_TYPE_ID(U64);
|
||||||
|
FX_TYPE_EXTENDS(FX_TYPE_VALUE_TYPE);
|
||||||
|
FX_TYPE_NAME("fx.u64");
|
||||||
|
FX_TYPE_CLASS(fx_u64_class);
|
||||||
|
FX_TYPE_INSTANCE_PRIVATE(u64);
|
||||||
|
FX_TYPE_DEFINITION_END(fx_u64)
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#include <fx/int.h>
|
||||||
|
#include <fx/value-type.h>
|
||||||
|
|
||||||
|
/*** CLASS DEFINITION *********************************************************/
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_BEGIN(fx_uint)
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_TYPE_CLASS_END(fx_uint)
|
||||||
|
|
||||||
|
FX_TYPE_DEFINITION_BEGIN(fx_uint)
|
||||||
|
__FX_VALUE_TYPE_ID(UINT);
|
||||||
|
FX_TYPE_EXTENDS(FX_TYPE_VALUE_TYPE);
|
||||||
|
FX_TYPE_NAME("fx.uint");
|
||||||
|
FX_TYPE_CLASS(fx_uint_class);
|
||||||
|
FX_TYPE_INSTANCE_PRIVATE(unsigned int);
|
||||||
|
FX_TYPE_DEFINITION_END(fx_uint)
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#include <fx/int.h>
|
||||||
|
#include <fx/value-type.h>
|
||||||
|
|
||||||
|
/*** CLASS DEFINITION *********************************************************/
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_BEGIN(fx_ulong)
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_TYPE_CLASS_END(fx_ulong)
|
||||||
|
|
||||||
|
FX_TYPE_DEFINITION_BEGIN(fx_ulong)
|
||||||
|
__FX_VALUE_TYPE_ID(ULONG);
|
||||||
|
FX_TYPE_EXTENDS(FX_TYPE_VALUE_TYPE);
|
||||||
|
FX_TYPE_NAME("fx.ulong");
|
||||||
|
FX_TYPE_CLASS(fx_ulong_class);
|
||||||
|
FX_TYPE_INSTANCE_PRIVATE(unsigned long);
|
||||||
|
FX_TYPE_DEFINITION_END(fx_ulong)
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#include <fx/int.h>
|
||||||
|
#include <fx/value-type.h>
|
||||||
|
|
||||||
|
/*** CLASS DEFINITION *********************************************************/
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_BEGIN(fx_ulonglong)
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_TYPE_CLASS_END(fx_ulonglong)
|
||||||
|
|
||||||
|
FX_TYPE_DEFINITION_BEGIN(fx_ulonglong)
|
||||||
|
__FX_VALUE_TYPE_ID(ULONGLONG);
|
||||||
|
FX_TYPE_EXTENDS(FX_TYPE_VALUE_TYPE);
|
||||||
|
FX_TYPE_NAME("fx.ulonglong");
|
||||||
|
FX_TYPE_CLASS(fx_ulonglong_class);
|
||||||
|
FX_TYPE_INSTANCE_PRIVATE(unsigned long long);
|
||||||
|
FX_TYPE_DEFINITION_END(fx_ulonglong)
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#include <fx/int.h>
|
||||||
|
#include <fx/value-type.h>
|
||||||
|
|
||||||
|
/*** CLASS DEFINITION *********************************************************/
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_BEGIN(fx_uptr)
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_TYPE_CLASS_END(fx_uptr)
|
||||||
|
|
||||||
|
FX_TYPE_DEFINITION_BEGIN(fx_uptr)
|
||||||
|
__FX_VALUE_TYPE_ID(UPTR);
|
||||||
|
FX_TYPE_EXTENDS(FX_TYPE_VALUE_TYPE);
|
||||||
|
FX_TYPE_NAME("fx.uptr");
|
||||||
|
FX_TYPE_CLASS(fx_uptr_class);
|
||||||
|
FX_TYPE_INSTANCE_PRIVATE(uptr);
|
||||||
|
FX_TYPE_DEFINITION_END(fx_uptr)
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#include <fx/int.h>
|
||||||
|
#include <fx/value-type.h>
|
||||||
|
|
||||||
|
/*** CLASS DEFINITION *********************************************************/
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_BEGIN(fx_ushort)
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_TYPE_CLASS_END(fx_ushort)
|
||||||
|
|
||||||
|
FX_TYPE_DEFINITION_BEGIN(fx_ushort)
|
||||||
|
__FX_VALUE_TYPE_ID(USHORT);
|
||||||
|
FX_TYPE_EXTENDS(FX_TYPE_VALUE_TYPE);
|
||||||
|
FX_TYPE_NAME("fx.ushort");
|
||||||
|
FX_TYPE_CLASS(fx_ushort_class);
|
||||||
|
FX_TYPE_INSTANCE_PRIVATE(unsigned short);
|
||||||
|
FX_TYPE_DEFINITION_END(fx_ushort)
|
||||||
@@ -21,6 +21,11 @@ FX_TYPE_DEFINITION_BEGIN(fx_object)
|
|||||||
FX_TYPE_CLASS(fx_object_class);
|
FX_TYPE_CLASS(fx_object_class);
|
||||||
FX_TYPE_DEFINITION_END(fx_object)
|
FX_TYPE_DEFINITION_END(fx_object)
|
||||||
|
|
||||||
|
fx_type_id fx_object_query_type(const struct _fx_object *obj)
|
||||||
|
{
|
||||||
|
return &obj->obj_type->ty_id;
|
||||||
|
}
|
||||||
|
|
||||||
fx_result fx_object_instantiate(
|
fx_result fx_object_instantiate(
|
||||||
struct fx_type_info *type,
|
struct fx_type_info *type,
|
||||||
struct _fx_object **out_object)
|
struct _fx_object **out_object)
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#include <fx/pointer.h>
|
||||||
|
#include <fx/value-type.h>
|
||||||
|
|
||||||
|
/*** CLASS DEFINITION *********************************************************/
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_BEGIN(fx_pointer)
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_TYPE_CLASS_END(fx_pointer)
|
||||||
|
|
||||||
|
FX_TYPE_DEFINITION_BEGIN(fx_pointer)
|
||||||
|
__FX_VALUE_TYPE_ID(POINTER);
|
||||||
|
FX_TYPE_EXTENDS(FX_TYPE_VALUE_TYPE);
|
||||||
|
FX_TYPE_NAME("fx.pointer");
|
||||||
|
FX_TYPE_CLASS(fx_pointer_class);
|
||||||
|
FX_TYPE_INSTANCE_PRIVATE(void *);
|
||||||
|
FX_TYPE_DEFINITION_END(fx_pointer)
|
||||||
+5
-77
@@ -1,4 +1,5 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <fx/cstr.h>
|
||||||
#include <fx/reflection/function.h>
|
#include <fx/reflection/function.h>
|
||||||
#include <fx/stream.h>
|
#include <fx/stream.h>
|
||||||
#include <fx/string.h>
|
#include <fx/string.h>
|
||||||
@@ -1718,18 +1719,18 @@ FX_TYPE_CLASS_BEGIN(fx_string)
|
|||||||
FX_INTERFACE_ENTRY(it_cbegin) = iterator_cbegin;
|
FX_INTERFACE_ENTRY(it_cbegin) = iterator_cbegin;
|
||||||
FX_TYPE_VTABLE_INTERFACE_END(fx_iterable, FX_TYPE_ITERABLE)
|
FX_TYPE_VTABLE_INTERFACE_END(fx_iterable, FX_TYPE_ITERABLE)
|
||||||
|
|
||||||
FX_TYPE_CONSTRUCTOR("create", fx_string_create, 0, FX_VALUE_TYPE_NONE);
|
FX_TYPE_CONSTRUCTOR("create", fx_string_create, 0, FX_TYPE_VOID);
|
||||||
FX_TYPE_CONSTRUCTOR(
|
FX_TYPE_CONSTRUCTOR(
|
||||||
"create_from_cstr",
|
"create_from_cstr",
|
||||||
fx_string_create_from_cstr,
|
fx_string_create_from_cstr,
|
||||||
1,
|
1,
|
||||||
FX_VALUE_TYPE_CSTR);
|
FX_TYPE_CSTR);
|
||||||
FX_TYPE_METHOD(
|
FX_TYPE_METHOD(
|
||||||
FX_VALUE_TYPE_CSTR,
|
FX_TYPE_CSTR,
|
||||||
"get_cstr",
|
"get_cstr",
|
||||||
fx_string_get_cstr,
|
fx_string_get_cstr,
|
||||||
0,
|
0,
|
||||||
FX_VALUE_TYPE_POINTER);
|
FX_TYPE_STRING);
|
||||||
FX_TYPE_CLASS_END(fx_string)
|
FX_TYPE_CLASS_END(fx_string)
|
||||||
|
|
||||||
FX_TYPE_DEFINITION_BEGIN(fx_string)
|
FX_TYPE_DEFINITION_BEGIN(fx_string)
|
||||||
@@ -1763,76 +1764,3 @@ FX_TYPE_DEFINITION_BEGIN(fx_string_iterator)
|
|||||||
FX_TYPE_CLASS(fx_string_iterator_class);
|
FX_TYPE_CLASS(fx_string_iterator_class);
|
||||||
FX_TYPE_INSTANCE_PRIVATE(struct fx_string_iterator_p);
|
FX_TYPE_INSTANCE_PRIVATE(struct fx_string_iterator_p);
|
||||||
FX_TYPE_DEFINITION_END(fx_string_iterator)
|
FX_TYPE_DEFINITION_END(fx_string_iterator)
|
||||||
|
|
||||||
/*** MISC FUNCTIONS ***********************************************************/
|
|
||||||
|
|
||||||
char *fx_strdup(const char *s)
|
|
||||||
{
|
|
||||||
size_t len = strlen(s);
|
|
||||||
char *p = malloc(len + 1);
|
|
||||||
if (!p) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(p, s, len);
|
|
||||||
p[len] = '\0';
|
|
||||||
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t fx_strlen(const char *s, fx_strlen_flags flags)
|
|
||||||
{
|
|
||||||
if (!(flags & (FX_STRLEN_IGNORE_ESC | FX_STRLEN_IGNORE_MOD))) {
|
|
||||||
return strlen(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t out = 0;
|
|
||||||
for (size_t i = 0; s[i]; i++) {
|
|
||||||
if (s[i] == '\033' && (flags & FX_STRLEN_IGNORE_ESC)) {
|
|
||||||
while (!isalpha(s[i]) && s[i]) {
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s[i] == '[' && (flags & FX_STRLEN_IGNORE_MOD)) {
|
|
||||||
i++;
|
|
||||||
if (s[i] == '[') {
|
|
||||||
out++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (s[i] != ']' && s[i]) {
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
out++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
fx_wchar *fx_wstrdup(const fx_wchar *s)
|
|
||||||
{
|
|
||||||
size_t len = fx_wstrlen(s);
|
|
||||||
fx_wchar *buf = calloc(len + 1, sizeof(fx_wchar));
|
|
||||||
if (!buf) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(buf, s, len * sizeof(fx_wchar));
|
|
||||||
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t fx_wstrlen(const fx_wchar *s)
|
|
||||||
{
|
|
||||||
size_t len;
|
|
||||||
for (len = 0; s[len] != 0; len++)
|
|
||||||
;
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
|
|||||||
+19
-10
@@ -58,6 +58,10 @@ static enum fx_status __gets(
|
|||||||
|
|
||||||
ss->ss_ptr += to_copy;
|
ss->ss_ptr += to_copy;
|
||||||
|
|
||||||
|
if (ss->ss_ptr == ss->ss_len) {
|
||||||
|
ss->ss_ptr = ss->ss_len = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (nr_read) {
|
if (nr_read) {
|
||||||
*nr_read = to_copy;
|
*nr_read = to_copy;
|
||||||
}
|
}
|
||||||
@@ -163,8 +167,9 @@ fx_stringstream *fx_stringstream_create_with_buffer(char *buf, size_t max)
|
|||||||
}
|
}
|
||||||
|
|
||||||
fx_stream_cfg *cfg = fx_object_get_protected(s, FX_TYPE_STREAM);
|
fx_stream_cfg *cfg = fx_object_get_protected(s, FX_TYPE_STREAM);
|
||||||
struct fx_stringstream_p *p
|
struct fx_stringstream_p *p = fx_object_get_private(
|
||||||
= fx_object_get_private(s, FX_TYPE_STRINGSTREAM);
|
s,
|
||||||
|
FX_TYPE_STRINGSTREAM);
|
||||||
|
|
||||||
cfg->s_mode = FX_STREAM_READ | FX_STREAM_WRITE | Z__FX_STREAM_STATIC;
|
cfg->s_mode = FX_STREAM_READ | FX_STREAM_WRITE | Z__FX_STREAM_STATIC;
|
||||||
|
|
||||||
@@ -184,8 +189,9 @@ fx_stringstream *fx_stringstream_create(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
fx_stream_cfg *cfg = fx_object_get_protected(s, FX_TYPE_STREAM);
|
fx_stream_cfg *cfg = fx_object_get_protected(s, FX_TYPE_STREAM);
|
||||||
struct fx_stringstream_p *p
|
struct fx_stringstream_p *p = fx_object_get_private(
|
||||||
= fx_object_get_private(s, FX_TYPE_STRINGSTREAM);
|
s,
|
||||||
|
FX_TYPE_STRINGSTREAM);
|
||||||
|
|
||||||
cfg->s_mode = FX_STREAM_READ | FX_STREAM_WRITE | Z__FX_STREAM_STATIC;
|
cfg->s_mode = FX_STREAM_READ | FX_STREAM_WRITE | Z__FX_STREAM_STATIC;
|
||||||
|
|
||||||
@@ -264,8 +270,9 @@ static void stringstream_fini(fx_object *obj, void *priv)
|
|||||||
|
|
||||||
enum fx_status stream_getc(fx_stream *stream, fx_wchar *c)
|
enum fx_status stream_getc(fx_stream *stream, fx_wchar *c)
|
||||||
{
|
{
|
||||||
struct fx_stringstream_p *s
|
struct fx_stringstream_p *s = fx_object_get_private(
|
||||||
= fx_object_get_private(stream, FX_TYPE_STRINGSTREAM);
|
stream,
|
||||||
|
FX_TYPE_STRINGSTREAM);
|
||||||
|
|
||||||
enum fx_status status = __getc(s, c);
|
enum fx_status status = __getc(s, c);
|
||||||
|
|
||||||
@@ -278,8 +285,9 @@ enum fx_status stream_read(
|
|||||||
size_t count,
|
size_t count,
|
||||||
size_t *nr_read)
|
size_t *nr_read)
|
||||||
{
|
{
|
||||||
struct fx_stringstream_p *s
|
struct fx_stringstream_p *s = fx_object_get_private(
|
||||||
= fx_object_get_private(stream, FX_TYPE_STRINGSTREAM);
|
stream,
|
||||||
|
FX_TYPE_STRINGSTREAM);
|
||||||
|
|
||||||
enum fx_status status = __gets(s, buf, count, nr_read);
|
enum fx_status status = __gets(s, buf, count, nr_read);
|
||||||
|
|
||||||
@@ -292,8 +300,9 @@ enum fx_status stream_write(
|
|||||||
size_t count,
|
size_t count,
|
||||||
size_t *nr_written)
|
size_t *nr_written)
|
||||||
{
|
{
|
||||||
struct fx_stringstream_p *s
|
struct fx_stringstream_p *s = fx_object_get_private(
|
||||||
= fx_object_get_private(stream, FX_TYPE_STRINGSTREAM);
|
stream,
|
||||||
|
FX_TYPE_STRINGSTREAM);
|
||||||
|
|
||||||
enum fx_status status = __puts(s, (const char *)buf, count, nr_written);
|
enum fx_status status = __puts(s, (const char *)buf, count, nr_written);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
#include <fx/value-type.h>
|
||||||
|
#include <fx/value.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
fx_value v = FX_I32(1024);
|
||||||
|
printf("%u\n", __fx_type_get_value_type(FX_TYPE_I64));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include <fx/bst.h>
|
#include <fx/bst.h>
|
||||||
#include <fx/endian.h>
|
#include <fx/endian.h>
|
||||||
|
#include <fx/int.h>
|
||||||
#include <fx/object.h>
|
#include <fx/object.h>
|
||||||
#include <fx/reflection/function.h>
|
#include <fx/reflection/function.h>
|
||||||
#include <fx/type.h>
|
#include <fx/type.h>
|
||||||
@@ -111,25 +112,19 @@ static struct fx_type_component *create_type_component(
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fx_type_id_init(
|
void fx_type_id_init(union fx_type_id *out, u32 a, u16 b, u16 c, u16 d, u64 e)
|
||||||
union fx_type_id *out,
|
|
||||||
uint32_t a,
|
|
||||||
uint16_t b,
|
|
||||||
uint16_t c,
|
|
||||||
uint16_t d,
|
|
||||||
uint64_t e)
|
|
||||||
{
|
{
|
||||||
fx_i32 x_a = fx_i32_htob(a);
|
a = fx_u32_htob(a);
|
||||||
fx_i16 x_b = fx_i16_htob(b);
|
b = fx_u16_htob(b);
|
||||||
fx_i16 x_c = fx_i16_htob(c);
|
c = fx_u16_htob(c);
|
||||||
fx_i16 x_d = fx_i16_htob(d);
|
d = fx_u16_htob(d);
|
||||||
fx_i64 x_e = fx_i64_htob(e);
|
e = fx_u64_htob(e);
|
||||||
|
|
||||||
memcpy(&out->b[0], x_a.i_bytes, sizeof x_a.i_bytes);
|
memcpy(&out->b[0], &a, sizeof a);
|
||||||
memcpy(&out->b[4], x_b.i_bytes, sizeof x_b.i_bytes);
|
memcpy(&out->b[4], &b, sizeof b);
|
||||||
memcpy(&out->b[6], x_c.i_bytes, sizeof x_c.i_bytes);
|
memcpy(&out->b[6], &c, sizeof c);
|
||||||
memcpy(&out->b[8], x_d.i_bytes, sizeof x_d.i_bytes);
|
memcpy(&out->b[8], &d, sizeof d);
|
||||||
memcpy(&out->b[10], &x_e.i_bytes[2], sizeof x_e.i_bytes - 2);
|
memcpy(&out->b[10], (byte *)&e + 2, sizeof e - 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void initialise_type_component(
|
static void initialise_type_component(
|
||||||
|
|||||||
@@ -1,174 +0,0 @@
|
|||||||
#include <fx/stream.h>
|
|
||||||
#include <fx/uint.h>
|
|
||||||
#include <inttypes.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
/*** PRIVATE DATA *************************************************************/
|
|
||||||
|
|
||||||
enum uint_type {
|
|
||||||
UINT_REGULAR = 0,
|
|
||||||
UINT_INF,
|
|
||||||
UINT_NAN,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct fx_uint_p {
|
|
||||||
enum uint_type i_type;
|
|
||||||
uintptr_t i_value;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*** PRIVATE FUNCTIONS ********************************************************/
|
|
||||||
|
|
||||||
static uintptr_t uint_get_value(const struct fx_uint_p *i)
|
|
||||||
{
|
|
||||||
return i->i_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void uint_set_value(struct fx_uint_p *i, uintptr_t v)
|
|
||||||
{
|
|
||||||
i->i_type = UINT_REGULAR;
|
|
||||||
i->i_value = v;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void uint_set_value_nan(struct fx_uint_p *i)
|
|
||||||
{
|
|
||||||
i->i_type = UINT_NAN;
|
|
||||||
i->i_value = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void uint_set_value_inf(struct fx_uint_p *i)
|
|
||||||
{
|
|
||||||
i->i_type = UINT_INF;
|
|
||||||
i->i_value = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool uint_is_nan(struct fx_uint_p *i)
|
|
||||||
{
|
|
||||||
return i->i_type == UINT_NAN;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool uint_is_inf(struct fx_uint_p *i)
|
|
||||||
{
|
|
||||||
return i->i_type == UINT_INF;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*** PUBLIC FUNCTIONS *********************************************************/
|
|
||||||
|
|
||||||
fx_uint *fx_uint_create(uintptr_t value)
|
|
||||||
{
|
|
||||||
fx_uint *i = fx_object_create(FX_TYPE_UINT);
|
|
||||||
if (!i) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct fx_uint_p *p = fx_object_get_private(i, FX_TYPE_UINT);
|
|
||||||
p->i_type = UINT_REGULAR;
|
|
||||||
p->i_value = value;
|
|
||||||
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
fx_uint *fx_uint_create_nan(void)
|
|
||||||
{
|
|
||||||
fx_uint *i = fx_object_create(FX_TYPE_UINT);
|
|
||||||
if (!i) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct fx_uint_p *p = fx_object_get_private(i, FX_TYPE_UINT);
|
|
||||||
p->i_type = UINT_NAN;
|
|
||||||
p->i_value = 0;
|
|
||||||
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
fx_uint *fx_uint_create_inf(void)
|
|
||||||
{
|
|
||||||
fx_uint *i = fx_object_create(FX_TYPE_UINT);
|
|
||||||
if (!i) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct fx_uint_p *p = fx_object_get_private(i, FX_TYPE_UINT);
|
|
||||||
p->i_type = UINT_INF;
|
|
||||||
p->i_value = 0;
|
|
||||||
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
uintptr_t fx_uint_get_value(const fx_uint *i)
|
|
||||||
{
|
|
||||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_UINT, uint_get_value, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
void fx_uint_set_value(fx_uint *i, uintptr_t v)
|
|
||||||
{
|
|
||||||
FX_CLASS_DISPATCH_STATIC_V(FX_TYPE_UINT, uint_set_value, i, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
void fx_uint_set_value_nan(fx_uint *i)
|
|
||||||
{
|
|
||||||
FX_CLASS_DISPATCH_STATIC_V0(FX_TYPE_UINT, uint_set_value_nan, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
void fx_uint_set_value_inf(fx_uint *i)
|
|
||||||
{
|
|
||||||
FX_CLASS_DISPATCH_STATIC_V0(FX_TYPE_UINT, uint_set_value_inf, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool fx_uint_is_nan(const fx_uint *i)
|
|
||||||
{
|
|
||||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_UINT, uint_is_nan, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool fx_uint_is_inf(const fx_uint *i)
|
|
||||||
{
|
|
||||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_UINT, uint_is_inf, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*** VIRTUAL FUNCTIONS ********************************************************/
|
|
||||||
|
|
||||||
static void uint_init(fx_object *obj, void *priv)
|
|
||||||
{
|
|
||||||
struct fx_uint_p *i = priv;
|
|
||||||
|
|
||||||
i->i_type = UINT_REGULAR;
|
|
||||||
i->i_value = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void uint_fini(fx_object *obj, void *priv)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static void uint_to_string(const fx_object *obj, fx_stream *out)
|
|
||||||
{
|
|
||||||
struct fx_uint_p *i = fx_object_get_private(obj, FX_TYPE_UINT);
|
|
||||||
switch (i->i_type) {
|
|
||||||
case UINT_REGULAR:
|
|
||||||
fx_stream_write_fmt(out, NULL, "%" PRIdPTR, i->i_value);
|
|
||||||
break;
|
|
||||||
case UINT_INF:
|
|
||||||
fx_stream_write_cstr(out, "inf", NULL);
|
|
||||||
break;
|
|
||||||
case UINT_NAN:
|
|
||||||
fx_stream_write_cstr(out, "NaN", NULL);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*** CLASS DEFINITION *********************************************************/
|
|
||||||
|
|
||||||
FX_TYPE_CLASS_BEGIN(fx_uint)
|
|
||||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
|
||||||
FX_INTERFACE_ENTRY(to_string) = uint_to_string;
|
|
||||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
|
||||||
FX_TYPE_CLASS_END(fx_uint)
|
|
||||||
|
|
||||||
FX_TYPE_DEFINITION_BEGIN(fx_uint)
|
|
||||||
FX_TYPE_ID(0x79aee484, 0x5dd5, 0x463a, 0xb0c8, 0x60873abdf088);
|
|
||||||
FX_TYPE_CLASS(fx_uint_class);
|
|
||||||
FX_TYPE_INSTANCE_PRIVATE(struct fx_uint_p);
|
|
||||||
FX_TYPE_INSTANCE_INIT(uint_init);
|
|
||||||
FX_TYPE_INSTANCE_FINI(uint_fini);
|
|
||||||
FX_TYPE_DEFINITION_END(fx_uint)
|
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
#include <fx/value-type.h>
|
||||||
|
|
||||||
|
bool fx_type_is_value_type(fx_type_id ty)
|
||||||
|
{
|
||||||
|
return ty->a.p00 == __FX_VALUE_TYPE_BASEID;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int __fx_type_get_value_type(fx_type_id ty)
|
||||||
|
{
|
||||||
|
if (ty->a.p00 != __FX_VALUE_TYPE_BASEID) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ty->a.p01;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*** CLASS DEFINITION *********************************************************/
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_BEGIN(fx_value_type)
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||||
|
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_TYPE_CLASS_END(fx_value_type)
|
||||||
|
|
||||||
|
FX_TYPE_DEFINITION_BEGIN(fx_value_type)
|
||||||
|
type_info->ty_id.a.p00 = __FX_VALUE_TYPE_BASEID;
|
||||||
|
type_info->ty_id.a.p01 = 0;
|
||||||
|
FX_TYPE_NAME("fx.value-type");
|
||||||
|
FX_TYPE_CLASS(fx_value_type_class);
|
||||||
|
FX_TYPE_DEFINITION_END(fx_value_type)
|
||||||
+14
-16
@@ -1,23 +1,19 @@
|
|||||||
#include <fx/bool.h>
|
#include <fx/bool.h>
|
||||||
#include <fx/double.h>
|
#include <fx/float.h>
|
||||||
#include <fx/int.h>
|
#include <fx/int.h>
|
||||||
#include <fx/string.h>
|
#include <fx/string.h>
|
||||||
#include <fx/uint.h>
|
#include <fx/value-type.h>
|
||||||
#include <fx/value.h>
|
#include <fx/value.h>
|
||||||
|
|
||||||
void fx_value_init(fx_value *v, fx_type_id type)
|
void fx_value_init(fx_value *v, fx_type_id type)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void fx_value_init_primitive(fx_value *v, fx_value_type type)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void fx_value_copy(fx_value *dst, fx_value *src)
|
void fx_value_copy(fx_value *dst, fx_value *src)
|
||||||
{
|
{
|
||||||
memcpy(dst, src, sizeof *dst);
|
memcpy(dst, src, sizeof *dst);
|
||||||
|
|
||||||
if (dst->v_type.t_primitive > __FX_VALUE_TYPE_OBJECT_BOUNDARY) {
|
if (!fx_type_is_value_type(dst->v_type)) {
|
||||||
fx_object_ref(dst->v_object);
|
fx_object_ref(dst->v_object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -31,9 +27,11 @@ void fx_value_copy_array(fx_value *dst, fx_value *src, size_t count)
|
|||||||
|
|
||||||
void fx_value_unset(fx_value *v)
|
void fx_value_unset(fx_value *v)
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
if (v->v_type.t_primitive > __FX_VALUE_TYPE_OBJECT_BOUNDARY) {
|
if (v->v_type.t_primitive > __FX_VALUE_TYPE_OBJECT_BOUNDARY) {
|
||||||
fx_object_unref(v->v_object);
|
fx_object_unref(v->v_object);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
memset(v, 0x0, sizeof *v);
|
memset(v, 0x0, sizeof *v);
|
||||||
}
|
}
|
||||||
@@ -73,6 +71,7 @@ void fx_value_set_object(fx_value *v, fx_object *obj)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
bool fx_value_is_bool(const fx_value *v)
|
bool fx_value_is_bool(const fx_value *v)
|
||||||
{
|
{
|
||||||
if (v->v_type.t_primitive == FX_VALUE_TYPE_BOOL) {
|
if (v->v_type.t_primitive == FX_VALUE_TYPE_BOOL) {
|
||||||
@@ -223,17 +222,16 @@ double fx_value_get_double(const fx_value *v)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
const char *fx_value_get_cstr(const fx_value *v)
|
const char *fx_value_get_cstr(const fx_value *v)
|
||||||
{
|
{
|
||||||
if (v->v_type.t_primitive == FX_VALUE_TYPE_CSTR) {
|
if (v->v_type == FX_TYPE_CSTR) {
|
||||||
return v->v_cstr;
|
return v->v_cstr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (v->v_type.t_primitive > __FX_VALUE_TYPE_OBJECT_BOUNDARY) {
|
if (v->v_type == FX_TYPE_STRING) {
|
||||||
if (fx_type_id_compare(v->v_type.t_object, FX_TYPE_STRING)) {
|
return fx_string_get_cstr(v->v_object);
|
||||||
return fx_string_get_cstr(v->v_object);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -241,7 +239,7 @@ const char *fx_value_get_cstr(const fx_value *v)
|
|||||||
|
|
||||||
void *fx_value_get_pointer(fx_value *v)
|
void *fx_value_get_pointer(fx_value *v)
|
||||||
{
|
{
|
||||||
if (v->v_type.t_primitive == FX_VALUE_TYPE_POINTER) {
|
if (__fx_type_get_value_type(v->v_type) == __FX_VALUE_TYPE_POINTER) {
|
||||||
return v->v_pointer;
|
return v->v_pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,7 +248,7 @@ void *fx_value_get_pointer(fx_value *v)
|
|||||||
|
|
||||||
const void *fx_value_get_pointer_c(const fx_value *v)
|
const void *fx_value_get_pointer_c(const fx_value *v)
|
||||||
{
|
{
|
||||||
if (v->v_type.t_primitive == FX_VALUE_TYPE_POINTER) {
|
if (__fx_type_get_value_type(v->v_type) == __FX_VALUE_TYPE_POINTER) {
|
||||||
return v->v_pointer;
|
return v->v_pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,7 +257,7 @@ const void *fx_value_get_pointer_c(const fx_value *v)
|
|||||||
|
|
||||||
fx_object *fx_value_get_object(fx_value *v)
|
fx_object *fx_value_get_object(fx_value *v)
|
||||||
{
|
{
|
||||||
if (v->v_type.t_primitive > __FX_VALUE_TYPE_OBJECT_BOUNDARY) {
|
if (!fx_type_is_value_type(v->v_type)) {
|
||||||
return v->v_object;
|
return v->v_object;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,7 +266,7 @@ fx_object *fx_value_get_object(fx_value *v)
|
|||||||
|
|
||||||
const fx_object *fx_value_get_object_c(const fx_value *v)
|
const fx_object *fx_value_get_object_c(const fx_value *v)
|
||||||
{
|
{
|
||||||
if (v->v_type.t_primitive > __FX_VALUE_TYPE_OBJECT_BOUNDARY) {
|
if (!fx_type_is_value_type(v->v_type)) {
|
||||||
return v->v_object;
|
return v->v_object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user