format code

This commit is contained in:
lixianjing 2021-01-03 18:42:56 +08:00
parent d97cbd07a4
commit 0c48fca4a2
14 changed files with 99 additions and 106 deletions

View File

@ -22,18 +22,17 @@
#if defined(LINUX) || defined(WINDOWS) || defined(MACOS) || defined(ANDROID) || defined(IOS)
#define FSCRIPT_WITH_MATH 1
#define FSCRIPT_WITH_TYPED_ARRAY 1
#endif/*PC*/
#endif /*PC*/
ret_t fscript_ext_init(void) {
fscript_object_register();
#ifdef FSCRIPT_WITH_MATH
fscript_math_register();
#endif/*FSCRIPT_WITH_MATH*/
#endif /*FSCRIPT_WITH_MATH*/
#ifdef FSCRIPT_WITH_TYPED_ARRAY
fscript_typed_array_register();
#endif/*FSCRIPT_WITH_TYPED_ARRAY*/
#endif /*FSCRIPT_WITH_TYPED_ARRAY*/
return RET_OK;
}

View File

@ -14,7 +14,6 @@
*
*/
#include "tkc/fscript.h"
static ret_t func_pow(fscript_t* fscript, fscript_args_t* args, value_t* result) {
@ -85,5 +84,3 @@ ret_t fscript_math_register(void) {
return RET_OK;
}

View File

@ -47,7 +47,7 @@ static ret_t func_object_get_prop(fscript_t* fscript, fscript_args_t* args, valu
obj = value_object(args->args);
return_value_if_fail(obj != NULL, RET_BAD_PARAMS);
object_get_prop(obj, value_str(args->args+1), result);
object_get_prop(obj, value_str(args->args + 1), result);
return RET_OK;
}
@ -58,7 +58,7 @@ static ret_t func_object_set_prop(fscript_t* fscript, fscript_args_t* args, valu
obj = value_object(args->args);
return_value_if_fail(obj != NULL, RET_BAD_PARAMS);
value_set_bool(result, object_set_prop(obj, value_str(args->args+1), args->args+2) == RET_OK);
value_set_bool(result, object_set_prop(obj, value_str(args->args + 1), args->args + 2) == RET_OK);
return RET_OK;
}

View File

@ -14,7 +14,6 @@
*
*/
#include "tkc/fscript.h"
#include "tkc/object_typed_array.h"
@ -25,27 +24,27 @@ static ret_t func_array_create(fscript_t* fscript, fscript_args_t* args, value_t
value_type_t type = VALUE_TYPE_INT8;
FSCRIPT_FUNC_CHECK(args->size == 2, RET_BAD_PARAMS);
stype = value_str(args->args);
capacity = value_uint32(args->args+1);
capacity = value_uint32(args->args + 1);
if(tk_str_eq(stype, "i8")) {
if (tk_str_eq(stype, "i8")) {
type = VALUE_TYPE_INT8;
} else if(tk_str_eq(stype, "i16")) {
} else if (tk_str_eq(stype, "i16")) {
type = VALUE_TYPE_INT16;
} else if(tk_str_eq(stype, "i32")) {
} else if (tk_str_eq(stype, "i32")) {
type = VALUE_TYPE_INT32;
} else if(tk_str_eq(stype, "i64")) {
} else if (tk_str_eq(stype, "i64")) {
type = VALUE_TYPE_INT64;
} else if(tk_str_eq(stype, "u8")) {
} else if (tk_str_eq(stype, "u8")) {
type = VALUE_TYPE_UINT8;
} else if(tk_str_eq(stype, "u16")) {
} else if (tk_str_eq(stype, "u16")) {
type = VALUE_TYPE_UINT16;
} else if(tk_str_eq(stype, "u32")) {
} else if (tk_str_eq(stype, "u32")) {
type = VALUE_TYPE_UINT32;
} else if(tk_str_eq(stype, "u64")) {
} else if (tk_str_eq(stype, "u64")) {
type = VALUE_TYPE_UINT64;
} else if(tk_str_eq(stype, "f32")) {
} else if (tk_str_eq(stype, "f32")) {
type = VALUE_TYPE_FLOAT32;
} else if(tk_str_eq(stype, "float")) {
} else if (tk_str_eq(stype, "float")) {
type = VALUE_TYPE_DOUBLE;
} else {
type = VALUE_TYPE_INT32;
@ -70,7 +69,7 @@ static ret_t func_array_push(fscript_t* fscript, fscript_args_t* args, value_t*
arr = get_typed_array(fscript, args);
return_value_if_fail(arr != NULL, RET_BAD_PARAMS);
value_set_bool(result, typed_array_push(arr, args->args+1) == RET_OK);
value_set_bool(result, typed_array_push(arr, args->args + 1) == RET_OK);
return RET_OK;
}
@ -90,7 +89,8 @@ static ret_t func_array_set(fscript_t* fscript, fscript_args_t* args, value_t* r
arr = get_typed_array(fscript, args);
return_value_if_fail(arr != NULL, RET_BAD_PARAMS);
value_set_bool(result, typed_array_set(arr, value_uint32(args->args+1), args->args+2) == RET_OK);
value_set_bool(result,
typed_array_set(arr, value_uint32(args->args + 1), args->args + 2) == RET_OK);
return RET_OK;
}
@ -101,7 +101,7 @@ static ret_t func_array_get(fscript_t* fscript, fscript_args_t* args, value_t* r
arr = get_typed_array(fscript, args);
return_value_if_fail(arr != NULL, RET_BAD_PARAMS);
typed_array_get(arr, value_uint32(args->args+1), result);
typed_array_get(arr, value_uint32(args->args + 1), result);
return RET_OK;
}
@ -134,7 +134,8 @@ static ret_t func_array_insert(fscript_t* fscript, fscript_args_t* args, value_t
arr = get_typed_array(fscript, args);
return_value_if_fail(arr != NULL, RET_BAD_PARAMS);
value_set_bool(result, typed_array_insert(arr, value_uint32(args->args+1), args->args+2) == RET_OK);
value_set_bool(result,
typed_array_insert(arr, value_uint32(args->args + 1), args->args + 2) == RET_OK);
return RET_OK;
}
@ -145,7 +146,7 @@ static ret_t func_array_remove(fscript_t* fscript, fscript_args_t* args, value_t
arr = get_typed_array(fscript, args);
return_value_if_fail(arr != NULL, RET_BAD_PARAMS);
value_set_bool(result, typed_array_remove(arr, value_uint32(args->args+1)) == RET_OK);
value_set_bool(result, typed_array_remove(arr, value_uint32(args->args + 1)) == RET_OK);
return RET_OK;
}
@ -163,5 +164,3 @@ ret_t fscript_typed_array_register(void) {
return RET_OK;
}

View File

@ -17,18 +17,18 @@ void do_echo(tk_iostream_t* iostream) {
while (ret == 0) {
ret = tk_istream_read(istream, (uint8_t*)&size, sizeof(size));
log_debug("size=%u ret=%d\n",size, ret);
log_debug("size=%u ret=%d\n", size, ret);
sleep_ms(1000);
}
return_if_fail(ret == sizeof(size));
buff = TKMEM_ALLOC(size+1);
memset(buff, 0x00, size+1);
log_debug("size=%u\n",size);
ret = tk_istream_read_len(istream, (uint8_t*)buff, size, 600*1000);
log_debug("(%u==%d):%s",size, ret, buff);
buff = TKMEM_ALLOC(size + 1);
memset(buff, 0x00, size + 1);
log_debug("size=%u\n", size);
ret = tk_istream_read_len(istream, (uint8_t*)buff, size, 600 * 1000);
log_debug("(%u==%d):%s", size, ret, buff);
if(ret > 0) {
if (ret > 0) {
tk_ostream_write_len(ostream, &ret, sizeof(ret), 10000);
tk_ostream_write_len(ostream, buff, ret, 600 * 1000);
}

View File

@ -20,14 +20,14 @@ void do_send(tk_iostream_t* iostream, const char* filename) {
return_if_fail(data != NULL);
ret = tk_ostream_write_len(ostream, (uint8_t*)&size, sizeof(size), 1000);
ret = tk_ostream_write_len(ostream, (uint8_t*)data, size, 600*1000);
ret = tk_ostream_write_len(ostream, (uint8_t*)data, size, 600 * 1000);
log_debug("send size=%u ret=%d \n", size, ret);
memset(data, 0x00, size);
ret = tk_istream_read_len(istream, (uint8_t*)&size, sizeof(size), 1000);
return_if_fail(ret == sizeof(size));
log_debug("size=%u\n", size);
ret = tk_istream_read_len(istream, (uint8_t*)data, size, 600*1000);
ret = tk_istream_read_len(istream, (uint8_t*)data, size, 600 * 1000);
if (ret >= 0) {
data[ret] = '\0';

View File

@ -37,13 +37,13 @@ static ret_t object_rbuffer_get_prop(object_t* obj, const char* name, value_t* v
object_rbuffer_t* o = OBJECT_RBUFFER(obj);
return_value_if_fail(o != NULL && o->rbuffer != NULL, RET_BAD_PARAMS);
if(tk_str_eq(name, "cursor")) {
if (tk_str_eq(name, "cursor")) {
value_set_uint32(v, o->rbuffer->cursor);
ret = RET_OK;
} else if(tk_str_eq(name, "capacity")) {
} else if (tk_str_eq(name, "capacity")) {
value_set_uint32(v, o->rbuffer->capacity);
ret = RET_OK;
} else if(tk_str_eq(name, "data")) {
} else if (tk_str_eq(name, "data")) {
value_set_pointer(v, (void*)(o->rbuffer->data));
ret = RET_OK;
}
@ -52,13 +52,12 @@ static ret_t object_rbuffer_get_prop(object_t* obj, const char* name, value_t* v
}
static const object_vtable_t s_object_rbuffer_vtable = {.type = "object_rbuffer",
.desc = "object_rbuffer",
.size = sizeof(object_rbuffer_t),
.is_collection = FALSE,
.on_destroy = object_rbuffer_on_destroy,
.get_prop = object_rbuffer_get_prop,
.set_prop = object_rbuffer_set_prop
};
.desc = "object_rbuffer",
.size = sizeof(object_rbuffer_t),
.is_collection = FALSE,
.on_destroy = object_rbuffer_on_destroy,
.get_prop = object_rbuffer_get_prop,
.set_prop = object_rbuffer_set_prop};
object_t* object_rbuffer_create(const uint8_t* data, uint32_t capacity) {
object_t* o = NULL;

View File

@ -43,13 +43,13 @@ static ret_t object_typed_array_get_prop(object_t* obj, const char* name, value_
object_typed_array_t* o = OBJECT_TYPED_ARRAY(obj);
return_value_if_fail(o != NULL && o->arr != NULL, RET_BAD_PARAMS);
if(tk_str_eq(name, "size")) {
if (tk_str_eq(name, "size")) {
value_set_uint32(v, o->arr->size);
ret = RET_OK;
} else if(tk_str_eq(name, "byte_size")) {
} else if (tk_str_eq(name, "byte_size")) {
value_set_uint32(v, o->arr->size * o->arr->element_size);
ret = RET_OK;
} else if(tk_str_eq(name, "data")) {
} else if (tk_str_eq(name, "data")) {
value_set_pointer(v, o->arr->data);
ret = RET_OK;
}
@ -57,14 +57,14 @@ static ret_t object_typed_array_get_prop(object_t* obj, const char* name, value_
return ret;
}
static const object_vtable_t s_object_typed_array_vtable = {.type = "object_typed_array",
.desc = "object_typed_array",
.size = sizeof(object_typed_array_t),
.is_collection = FALSE,
.on_destroy = object_typed_array_on_destroy,
.get_prop = object_typed_array_get_prop,
.set_prop = object_typed_array_set_prop
};
static const object_vtable_t s_object_typed_array_vtable = {
.type = "object_typed_array",
.desc = "object_typed_array",
.size = sizeof(object_typed_array_t),
.is_collection = FALSE,
.on_destroy = object_typed_array_on_destroy,
.get_prop = object_typed_array_get_prop,
.set_prop = object_typed_array_set_prop};
object_t* object_typed_array_create(value_type_t type, uint32_t capacity) {
object_t* o = NULL;

View File

@ -43,13 +43,13 @@ static ret_t object_wbuffer_get_prop(object_t* obj, const char* name, value_t* v
object_wbuffer_t* o = OBJECT_WBUFFER(obj);
return_value_if_fail(o != NULL && o->wbuffer != NULL, RET_BAD_PARAMS);
if(tk_str_eq(name, "cursor")) {
if (tk_str_eq(name, "cursor")) {
value_set_uint32(v, o->wbuffer->cursor);
ret = RET_OK;
} else if(tk_str_eq(name, "capacity")) {
} else if (tk_str_eq(name, "capacity")) {
value_set_uint32(v, o->wbuffer->capacity);
ret = RET_OK;
} else if(tk_str_eq(name, "data")) {
} else if (tk_str_eq(name, "data")) {
value_set_pointer(v, o->wbuffer->data);
ret = RET_OK;
}
@ -58,13 +58,12 @@ static ret_t object_wbuffer_get_prop(object_t* obj, const char* name, value_t* v
}
static const object_vtable_t s_object_wbuffer_vtable = {.type = "object_wbuffer",
.desc = "object_wbuffer",
.size = sizeof(object_wbuffer_t),
.is_collection = FALSE,
.on_destroy = object_wbuffer_on_destroy,
.get_prop = object_wbuffer_get_prop,
.set_prop = object_wbuffer_set_prop
};
.desc = "object_wbuffer",
.size = sizeof(object_wbuffer_t),
.is_collection = FALSE,
.on_destroy = object_wbuffer_on_destroy,
.get_prop = object_wbuffer_get_prop,
.set_prop = object_wbuffer_set_prop};
object_t* object_wbuffer_create_ex(bool_t extendable, uint8_t* data, uint32_t capacity) {
object_t* o = NULL;
@ -75,7 +74,7 @@ object_t* object_wbuffer_create_ex(bool_t extendable, uint8_t* data, uint32_t ca
wrapper = OBJECT_WBUFFER(o);
return_value_if_fail(wrapper != NULL, NULL);
if(extendable) {
if (extendable) {
wrapper->wbuffer = wbuffer_init_extendable(&(wrapper->awbuffer));
} else {
wrapper->wbuffer = wbuffer_init(&(wrapper->awbuffer), data, capacity);

View File

@ -53,32 +53,32 @@ TEST(TypedArray, basic) {
TEST(TypedArray, push) {
value_t v;
uint8_t i = 0;
uint8_t i = 0;
typed_array_t* a = typed_array_create(VALUE_TYPE_UINT8, 0);
ASSERT_EQ(a != NULL, true);
for(i = 0; i < 255; i++) {
for (i = 0; i < 255; i++) {
ASSERT_EQ(a->size, i);
ASSERT_EQ(typed_array_push(a, value_set_uint8(&v, i)), RET_OK);
ASSERT_EQ(typed_array_tail(a, &v), RET_OK);
ASSERT_EQ(value_uint8(&v), i);
}
for(; i > 0; i--) {
for (; i > 0; i--) {
ASSERT_EQ(a->size, i);
ASSERT_EQ(typed_array_tail(a, &v), RET_OK);
ASSERT_EQ(value_uint8(&v), i-1);
ASSERT_EQ(value_uint8(&v), i - 1);
ASSERT_EQ(typed_array_pop(a, &v), RET_OK);
ASSERT_EQ(value_uint8(&v), i-1);
ASSERT_EQ(value_uint8(&v), i - 1);
}
typed_array_destroy(a);
}
TEST(TypedArray, insert) {
value_t v;
uint8_t i = 0;
uint8_t i = 0;
typed_array_t* a = typed_array_create(VALUE_TYPE_UINT8, 0);
ASSERT_EQ(a != NULL, true);
for(i = 0; i < 255; i++) {
for (i = 0; i < 255; i++) {
ASSERT_EQ(a->size, i);
ASSERT_EQ(typed_array_insert(a, 0, value_set_uint8(&v, i)), RET_OK);
ASSERT_EQ(typed_array_get(a, 0, &v), RET_OK);
@ -98,11 +98,11 @@ TEST(TypedArray, pointer) {
TEST(TypedArray, insert_uint64) {
value_t v;
uint8_t i = 0;
uint8_t i = 0;
typed_array_t* a = typed_array_create(VALUE_TYPE_UINT64, 0);
ASSERT_EQ(a != NULL, true);
ASSERT_EQ(a->element_size, sizeof(uint64_t));
for(i = 0; i < 255; i++) {
for (i = 0; i < 255; i++) {
ASSERT_EQ(a->size, i);
ASSERT_EQ(typed_array_insert(a, 0, value_set_uint64(&v, i)), RET_OK);
ASSERT_EQ(typed_array_get(a, 0, &v), RET_OK);
@ -120,11 +120,11 @@ TEST(TypedArray, insert_uint64) {
TEST(TypedArray, insert_double) {
value_t v;
uint8_t i = 0;
uint8_t i = 0;
typed_array_t* a = typed_array_create(VALUE_TYPE_DOUBLE, 10);
ASSERT_EQ(a != NULL, true);
ASSERT_EQ(a->element_size, sizeof(double_t));
for(i = 0; i < 255; i++) {
for (i = 0; i < 255; i++) {
ASSERT_EQ(a->size, i);
ASSERT_EQ(typed_array_insert(a, 0, value_set_double(&v, i)), RET_OK);
ASSERT_EQ(typed_array_get(a, 0, &v), RET_OK);
@ -142,11 +142,11 @@ TEST(TypedArray, insert_double) {
TEST(TypedArray, insert_uint32) {
value_t v;
uint8_t i = 0;
uint8_t i = 0;
typed_array_t* a = typed_array_create(VALUE_TYPE_UINT32, 0);
ASSERT_EQ(a != NULL, true);
ASSERT_EQ(a->element_size, sizeof(uint32_t));
for(i = 0; i < 255; i++) {
for (i = 0; i < 255; i++) {
ASSERT_EQ(a->size, i);
ASSERT_EQ(typed_array_insert(a, 0, value_set_uint32(&v, i)), RET_OK);
ASSERT_EQ(typed_array_get(a, 0, &v), RET_OK);
@ -164,13 +164,13 @@ TEST(TypedArray, insert_uint32) {
TEST(TypedArray, object1) {
value_t v;
uint8_t i = 0;
uint8_t i = 0;
object_t* obj = object_typed_array_create(VALUE_TYPE_UINT32, 0);
typed_array_t* a = OBJECT_TYPED_ARRAY(obj)->arr;
ASSERT_EQ(a != NULL, true);
ASSERT_EQ(a->element_size, sizeof(uint32_t));
for(i = 0; i < 255; i++) {
for (i = 0; i < 255; i++) {
ASSERT_EQ(a->size, i);
ASSERT_EQ(typed_array_insert(a, 0, value_set_uint32(&v, i)), RET_OK);
ASSERT_EQ(typed_array_get(a, 0, &v), RET_OK);
@ -178,7 +178,7 @@ TEST(TypedArray, object1) {
}
ASSERT_EQ(object_get_prop_int(obj, "size", 0), i);
ASSERT_EQ(object_get_prop_int(obj, "byte_size", 0), i*sizeof(uint32_t));
ASSERT_EQ(object_get_prop_int(obj, "byte_size", 0), i * sizeof(uint32_t));
ASSERT_EQ(object_get_prop_pointer(obj, "data"), (void*)a->data);
typed_array_destroy(a);