Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 99380c7810 | |||
| 2d396ee071 | |||
| 34a8ccff95 | |||
| d9835cea0b |
@@ -37,6 +37,7 @@ struct fx_directory_iterator_p {
|
||||
fx_directory *root;
|
||||
|
||||
fx_directory_entry entry;
|
||||
fx_value entry_value;
|
||||
};
|
||||
|
||||
/*** PRIVATE FUNCTIONS ********************************************************/
|
||||
@@ -510,6 +511,8 @@ static void update_iterator_data(struct fx_directory_iterator_p *it)
|
||||
fx_path *path = fx_path_create_from_cstr(
|
||||
ent->fts_path + fx_path_length(it->_p->d_path_abs) + 1);
|
||||
|
||||
fx_value_unset(&it->entry_value);
|
||||
it->entry_value = FX_POINTER(&it->entry);
|
||||
it->entry.filename = ent->fts_name;
|
||||
it->entry.filepath = path;
|
||||
|
||||
@@ -616,12 +619,7 @@ fx_iterator *fx_directory_begin(
|
||||
return it_obj;
|
||||
}
|
||||
|
||||
static fx_iterator *iterator_begin(fx_object *obj)
|
||||
{
|
||||
return fx_directory_begin(obj, FX_DIRECTORY_ITERATE_PARENT_FIRST);
|
||||
}
|
||||
|
||||
static const fx_iterator *iterator_cbegin(const fx_object *obj)
|
||||
static const fx_iterator *iterator_begin(const fx_object *obj)
|
||||
{
|
||||
return fx_directory_begin(
|
||||
(fx_object *)obj,
|
||||
@@ -692,20 +690,12 @@ static enum fx_status iterator_erase(fx_iterator *obj)
|
||||
return iterator_move_next(obj);
|
||||
}
|
||||
|
||||
static fx_iterator_value iterator_get_value(fx_iterator *obj)
|
||||
static const fx_value *iterator_get_value(const fx_iterator *obj)
|
||||
{
|
||||
struct fx_directory_iterator_p *it
|
||||
= fx_object_get_private(obj, FX_TYPE_DIRECTORY_ITERATOR);
|
||||
|
||||
return FX_ITERATOR_VALUE_PTR(&it->entry);
|
||||
}
|
||||
|
||||
static const fx_iterator_value iterator_get_cvalue(const fx_iterator *obj)
|
||||
{
|
||||
struct fx_directory_iterator_p *it
|
||||
= fx_object_get_private(obj, FX_TYPE_DIRECTORY_ITERATOR);
|
||||
|
||||
return FX_ITERATOR_VALUE_CPTR(&it->entry);
|
||||
return &it->entry_value;
|
||||
}
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
@@ -718,7 +708,6 @@ FX_TYPE_CLASS_BEGIN(fx_directory)
|
||||
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_INTERFACE_ENTRY(it_begin) = iterator_begin;
|
||||
FX_INTERFACE_ENTRY(it_cbegin) = iterator_cbegin;
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_TYPE_CLASS_END(fx_directory)
|
||||
|
||||
@@ -741,7 +730,6 @@ FX_TYPE_CLASS_BEGIN(fx_directory_iterator)
|
||||
FX_INTERFACE_ENTRY(it_move_next) = iterator_move_next;
|
||||
FX_INTERFACE_ENTRY(it_erase) = iterator_erase;
|
||||
FX_INTERFACE_ENTRY(it_get_value) = iterator_get_value;
|
||||
FX_INTERFACE_ENTRY(it_get_cvalue) = iterator_get_cvalue;
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_TYPE_CLASS_END(fx_directory_iterator)
|
||||
|
||||
|
||||
+10
-3
@@ -392,11 +392,18 @@ void path_fini(fx_object *obj, void *priv)
|
||||
fx_string_unref(path->p_pathstr);
|
||||
}
|
||||
|
||||
void path_to_string(const fx_object *obj, fx_stream *out)
|
||||
static fx_status path_to_string(
|
||||
const fx_value *obj,
|
||||
fx_stream *out,
|
||||
const char *format)
|
||||
{
|
||||
struct fx_path_p *path = fx_object_get_private(obj, FX_TYPE_PATH);
|
||||
struct fx_path_p *path
|
||||
= fx_object_get_private(obj->v_object, FX_TYPE_PATH);
|
||||
|
||||
fx_stream_write_cstr(out, fx_string_get_cstr(path->p_pathstr), NULL);
|
||||
return fx_stream_write_cstr(
|
||||
out,
|
||||
fx_string_get_cstr(path->p_pathstr),
|
||||
NULL);
|
||||
}
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#include <fx/type.h>
|
||||
#include <fx/value-type.h>
|
||||
#include <platform/callvm.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -11,7 +13,7 @@
|
||||
}
|
||||
#endif
|
||||
|
||||
void callvm_reset(struct callvm* vm, unsigned int max_fixed_args)
|
||||
void callvm_reset(struct callvm *vm, unsigned int max_fixed_args)
|
||||
{
|
||||
vm->vm_arg_int_count = 0;
|
||||
vm->vm_arg_double_count = 0;
|
||||
@@ -20,14 +22,14 @@ void callvm_reset(struct callvm* vm, unsigned int max_fixed_args)
|
||||
vm->vm_double_excess_count = 0;
|
||||
}
|
||||
|
||||
static void expand_excess(struct callvm* vm)
|
||||
static void expand_excess(struct callvm *vm)
|
||||
{
|
||||
size_t new_capacity = vm->vm_arg_excess_max * 2;
|
||||
if (!new_capacity) {
|
||||
new_capacity = 4;
|
||||
}
|
||||
|
||||
void* buf = realloc(
|
||||
void *buf = realloc(
|
||||
vm->vm_arg_excess,
|
||||
new_capacity * sizeof *vm->vm_arg_excess);
|
||||
|
||||
@@ -39,7 +41,7 @@ static void expand_excess(struct callvm* vm)
|
||||
vm->vm_arg_excess_max = new_capacity;
|
||||
}
|
||||
|
||||
static void push_excess(struct callvm* vm, uintptr_t value)
|
||||
static void push_excess(struct callvm *vm, uintptr_t value)
|
||||
{
|
||||
if (vm->vm_arg_excess_count + 1 > vm->vm_arg_excess_max) {
|
||||
expand_excess(vm);
|
||||
@@ -49,7 +51,7 @@ static void push_excess(struct callvm* vm, uintptr_t value)
|
||||
vm->vm_arg_count++;
|
||||
}
|
||||
|
||||
static void push_int(struct callvm* vm, uintptr_t value)
|
||||
static void push_int(struct callvm *vm, uintptr_t value)
|
||||
{
|
||||
if (vm->vm_arg_int_count >= MAX_INT_ARGS) {
|
||||
push_excess(vm, value);
|
||||
@@ -60,10 +62,10 @@ static void push_int(struct callvm* vm, uintptr_t value)
|
||||
vm->vm_arg_count++;
|
||||
}
|
||||
|
||||
static void push_double(struct callvm* vm, double value)
|
||||
static void push_double(struct callvm *vm, double value)
|
||||
{
|
||||
if (vm->vm_arg_double_count >= MAX_DOUBLE_ARGS) {
|
||||
push_excess(vm, *(uintptr_t*)&value);
|
||||
push_excess(vm, *(uintptr_t *)&value);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -75,35 +77,164 @@ static void push_double(struct callvm* vm, double value)
|
||||
}
|
||||
}
|
||||
|
||||
void callvm_push(struct callvm* vm, const fx_value* value)
|
||||
void callvm_push(struct callvm *vm, const fx_value *value)
|
||||
{
|
||||
switch (value->v_type.t_primitive) {
|
||||
case FX_VALUE_TYPE_DOUBLE:
|
||||
if (!fx_type_is_value_type(value->v_type)) {
|
||||
push_int(vm, (uintptr_t)value->v_object);
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned int value_type = __fx_type_get_value_type(value->v_type);
|
||||
|
||||
switch (value_type) {
|
||||
case __FX_VALUE_TYPE_BOOL:
|
||||
push_int(vm, value->v_bool);
|
||||
break;
|
||||
case __FX_VALUE_TYPE_I16:
|
||||
push_int(vm, value->v_i16);
|
||||
break;
|
||||
case __FX_VALUE_TYPE_U16:
|
||||
push_int(vm, value->v_u16);
|
||||
break;
|
||||
case __FX_VALUE_TYPE_I32:
|
||||
push_int(vm, value->v_i32);
|
||||
break;
|
||||
case __FX_VALUE_TYPE_U32:
|
||||
push_int(vm, value->v_u32);
|
||||
break;
|
||||
case __FX_VALUE_TYPE_I64:
|
||||
push_int(vm, value->v_i64);
|
||||
break;
|
||||
case __FX_VALUE_TYPE_U64:
|
||||
push_int(vm, value->v_u64);
|
||||
break;
|
||||
case __FX_VALUE_TYPE_IPTR:
|
||||
push_int(vm, value->v_iptr);
|
||||
break;
|
||||
case __FX_VALUE_TYPE_UPTR:
|
||||
push_int(vm, value->v_uptr);
|
||||
break;
|
||||
case __FX_VALUE_TYPE_SBYTE:
|
||||
push_int(vm, value->v_sbyte);
|
||||
break;
|
||||
case __FX_VALUE_TYPE_BYTE:
|
||||
push_int(vm, value->v_byte);
|
||||
break;
|
||||
case __FX_VALUE_TYPE_SHORT:
|
||||
push_int(vm, value->v_short);
|
||||
break;
|
||||
case __FX_VALUE_TYPE_USHORT:
|
||||
push_int(vm, value->v_ushort);
|
||||
break;
|
||||
case __FX_VALUE_TYPE_INT:
|
||||
push_int(vm, value->v_int);
|
||||
break;
|
||||
case __FX_VALUE_TYPE_UINT:
|
||||
push_int(vm, value->v_uint);
|
||||
break;
|
||||
case __FX_VALUE_TYPE_LONG:
|
||||
push_int(vm, value->v_long);
|
||||
break;
|
||||
case __FX_VALUE_TYPE_ULONG:
|
||||
push_int(vm, value->v_ulong);
|
||||
break;
|
||||
case __FX_VALUE_TYPE_LONGLONG:
|
||||
push_int(vm, value->v_longlong);
|
||||
break;
|
||||
case __FX_VALUE_TYPE_ULONGLONG:
|
||||
push_int(vm, value->v_ulonglong);
|
||||
break;
|
||||
case __FX_VALUE_TYPE_SIZE:
|
||||
push_int(vm, value->v_size);
|
||||
break;
|
||||
case __FX_VALUE_TYPE_FLOAT:
|
||||
push_double(vm, value->v_float);
|
||||
break;
|
||||
case __FX_VALUE_TYPE_DOUBLE:
|
||||
push_double(vm, value->v_double);
|
||||
break;
|
||||
default:
|
||||
case __FX_VALUE_TYPE_CSTR:
|
||||
push_int(vm, (uintptr_t)value->v_cstr);
|
||||
break;
|
||||
case __FX_VALUE_TYPE_POINTER:
|
||||
push_int(vm, (uintptr_t)value->v_pointer);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
extern uintptr_t callvm_invoke_i(fx_function_impl impl, struct callvm* vm);
|
||||
extern double callvm_invoke_d(fx_function_impl impl, struct callvm* vm);
|
||||
extern void callvm_invoke_v(fx_function_impl impl, struct callvm* vm);
|
||||
extern uintptr_t callvm_invoke_i(fx_function_impl impl, struct callvm *vm);
|
||||
extern double callvm_invoke_d(fx_function_impl impl, struct callvm *vm);
|
||||
extern void callvm_invoke_v(fx_function_impl impl, struct callvm *vm);
|
||||
|
||||
fx_value callvm_invoke(
|
||||
struct callvm* vm,
|
||||
struct callvm *vm,
|
||||
fx_function_impl impl,
|
||||
fx_value_type return_type)
|
||||
fx_type_id return_type)
|
||||
{
|
||||
switch (return_type) {
|
||||
case FX_VALUE_TYPE_NONE:
|
||||
callvm_invoke_v(impl, vm);
|
||||
break;
|
||||
case FX_VALUE_TYPE_DOUBLE:
|
||||
return FX_VALUE_DOUBLE(callvm_invoke_d(impl, vm));
|
||||
if (!fx_type_is_value_type(return_type)) {
|
||||
uintptr_t v = callvm_invoke_i(impl, vm);
|
||||
fx_value result = {
|
||||
.v_type = return_type,
|
||||
.v_object = (fx_object *)v,
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
unsigned int value_type = __fx_type_get_value_type(return_type);
|
||||
|
||||
switch (value_type) {
|
||||
case __FX_VALUE_TYPE_BOOL:
|
||||
return FX_BOOL(callvm_invoke_i(impl, vm));
|
||||
case __FX_VALUE_TYPE_I16:
|
||||
return FX_I16(callvm_invoke_i(impl, vm));
|
||||
case __FX_VALUE_TYPE_U16:
|
||||
return FX_U16(callvm_invoke_i(impl, vm));
|
||||
case __FX_VALUE_TYPE_I32:
|
||||
return FX_I32(callvm_invoke_i(impl, vm));
|
||||
case __FX_VALUE_TYPE_U32:
|
||||
return FX_U32(callvm_invoke_i(impl, vm));
|
||||
case __FX_VALUE_TYPE_I64:
|
||||
return FX_I64(callvm_invoke_i(impl, vm));
|
||||
case __FX_VALUE_TYPE_U64:
|
||||
return FX_U64(callvm_invoke_i(impl, vm));
|
||||
case __FX_VALUE_TYPE_IPTR:
|
||||
return FX_IPTR(callvm_invoke_i(impl, vm));
|
||||
case __FX_VALUE_TYPE_UPTR:
|
||||
return FX_UPTR(callvm_invoke_i(impl, vm));
|
||||
case __FX_VALUE_TYPE_SBYTE:
|
||||
return FX_SBYTE(callvm_invoke_i(impl, vm));
|
||||
case __FX_VALUE_TYPE_BYTE:
|
||||
return FX_BYTE(callvm_invoke_i(impl, vm));
|
||||
case __FX_VALUE_TYPE_SHORT:
|
||||
return FX_SHORT(callvm_invoke_i(impl, vm));
|
||||
case __FX_VALUE_TYPE_USHORT:
|
||||
return FX_USHORT(callvm_invoke_i(impl, vm));
|
||||
case __FX_VALUE_TYPE_INT:
|
||||
return FX_INT(callvm_invoke_i(impl, vm));
|
||||
case __FX_VALUE_TYPE_UINT:
|
||||
return FX_UINT(callvm_invoke_i(impl, vm));
|
||||
case __FX_VALUE_TYPE_LONG:
|
||||
return FX_LONG(callvm_invoke_i(impl, vm));
|
||||
case __FX_VALUE_TYPE_ULONG:
|
||||
return FX_ULONG(callvm_invoke_i(impl, vm));
|
||||
case __FX_VALUE_TYPE_LONGLONG:
|
||||
return FX_LONGLONG(callvm_invoke_i(impl, vm));
|
||||
case __FX_VALUE_TYPE_ULONGLONG:
|
||||
return FX_ULONGLONG(callvm_invoke_i(impl, vm));
|
||||
case __FX_VALUE_TYPE_SIZE:
|
||||
return FX_SIZE(callvm_invoke_i(impl, vm));
|
||||
case __FX_VALUE_TYPE_FLOAT:
|
||||
return FX_FLOAT(callvm_invoke_d(impl, vm));
|
||||
case __FX_VALUE_TYPE_DOUBLE:
|
||||
return FX_DOUBLE(callvm_invoke_d(impl, vm));
|
||||
case __FX_VALUE_TYPE_CSTR:
|
||||
return FX_CSTR((const char *)callvm_invoke_i(impl, vm));
|
||||
case __FX_VALUE_TYPE_POINTER:
|
||||
return FX_POINTER((void *)callvm_invoke_i(impl, vm));
|
||||
default:
|
||||
return FX_VALUE_INT(callvm_invoke_i(impl, vm));
|
||||
return FX_VALUE_EMPTY;
|
||||
}
|
||||
|
||||
return FX_VALUE_EMPTY;
|
||||
|
||||
@@ -32,6 +32,6 @@ extern void callvm_push(struct callvm *vm, const fx_value *value);
|
||||
extern fx_value callvm_invoke(
|
||||
struct callvm *vm,
|
||||
fx_function_impl impl,
|
||||
fx_value_type return_type);
|
||||
fx_type_id return_type);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -359,7 +359,7 @@ fx_status cstr_to_size(const char *in, size_t *out)
|
||||
return FX_ERR_BAD_STATE;
|
||||
}
|
||||
|
||||
if (v > SIZE_T_MAX) {
|
||||
if (v > SIZE_MAX) {
|
||||
return FX_ERR_BAD_STATE;
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -22,17 +22,17 @@ int main(int argc, const char **argv)
|
||||
/* TODO re-implement json support */
|
||||
fx_serial_ctx *ctx = NULL;
|
||||
|
||||
fx_object *data;
|
||||
fx_value data = FX_VALUE_EMPTY;
|
||||
result = fx_serial_ctx_deserialise(ctx, src, &data, 0);
|
||||
if (fx_result_is_error(result)) {
|
||||
fx_throw(result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
fx_object_to_string(data, fx_stdout, NULL);
|
||||
fx_value_to_string(&data, fx_stdout, NULL);
|
||||
fx_stream_write_char(fx_stdout, '\n');
|
||||
|
||||
fx_object_unref(data);
|
||||
fx_value_unset(&data);
|
||||
fx_object_unref(src);
|
||||
fx_serial_ctx_unref(ctx);
|
||||
|
||||
|
||||
+4
-4
@@ -22,21 +22,21 @@ int main(int argc, const char **argv)
|
||||
|
||||
fx_serial_ctx *ctx = fx_toml_serial_ctx_create();
|
||||
|
||||
fx_object *data = NULL;
|
||||
fx_value data = FX_VALUE_EMPTY;
|
||||
result = fx_serial_ctx_deserialise(ctx, src, &data, 0);
|
||||
if (fx_result_is_error(result)) {
|
||||
fx_throw(result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
if (!fx_value_is_set(&data)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
fx_object_to_string(data, fx_stdout, NULL);
|
||||
fx_value_to_string(&data, fx_stdout, NULL);
|
||||
fx_stream_write_char(fx_stdout, '\n');
|
||||
|
||||
fx_object_unref(data);
|
||||
fx_value_unset(&data);
|
||||
fx_object_unref(src);
|
||||
fx_serial_ctx_unref(ctx);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user