diff --git a/chitu/Ubuntu/makefile b/chitu/Ubuntu/makefile deleted file mode 100755 index 7bfacbf1af2242aff38e65128f99fe57c14ae088..0000000000000000000000000000000000000000 --- a/chitu/Ubuntu/makefile +++ /dev/null @@ -1,16 +0,0 @@ -MATH = chitu_math.o -BASE = chitu_base.o -MAIN = chitu.o -OBJS = $(BASE) $(MAIN) $(MATH) -CFLAGS= -O3 -std=c99 -Wall -DLOSU_LINUX -I ../buildenv -fPIC -CC=x86_64-linux-gnu-gcc -T=ElsLib_chitu.lsd - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) $(BASE) $(MATH) -shared -lm -s -lc - -clean: - rm -rf $T $(OBJS) $(BASE) $(MATH) core core.* \ No newline at end of file diff --git a/chitu/Windows/makefile b/chitu/Windows/makefile deleted file mode 100755 index 2514abe7bb80859f79668c7c03b7983a9276f662..0000000000000000000000000000000000000000 --- a/chitu/Windows/makefile +++ /dev/null @@ -1,18 +0,0 @@ -MATH = chitu_math.o -BASE = chitu_base.o -MAIN = chitu.o -OBJS = $(BASE) $(MAIN) $(MATH) -CFLAGS= -O3 -std=c99 -Wall -DLOSU_WINDOWS -I ../buildenv -fPIC -CC=x86_64-w64-mingw32-gcc -T=ElsLib_chitu.lsd - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -L ../buildenv -l:libeasylosu.dll -lm -static -shared -s - -clean: - rm -rf $T - rm -rf $(BASE) - rm -rf $(MAIN) - rm -rf $(MATH) diff --git a/chitu/chitu.c b/chitu/chitu.c deleted file mode 100755 index 1944de7378d08f4a6484debde268d92f824a99bd..0000000000000000000000000000000000000000 --- a/chitu/chitu.c +++ /dev/null @@ -1,728 +0,0 @@ -#include "chitu.h" -#include "chitu_base.h" -#include "chitu_math.h" - -static char *ptr_name = "__ptr__"; - -#define getptr_fromunit(vm, unit_p) ((void *)obj_toptr(vm, obj_indexunit(vm, *unit_p, obj_newstr(vm, ptr_name)))) - -// #数组的创建和操作 -int ELSAPI_chitu_chitu_array_create(els_VmObj* vm) // chitu_array_create(u:unit, len:int, init:num): ptr -{ - LosuObj *unit = arg_get(vm, 1); - chitu_array *a = chitu_array_create(arg_getnum(vm, 2), arg_getnum(vm, 3)); - - if (a == NULL) - { - arg_returnnull(vm); - return 1; - } - - obj_setunit(vm, *unit, obj_newstr(vm, ptr_name), obj_newptr(vm, (void *)a)); - return 1; -} - -int ELSAPI_chitu_chitu_array_free(els_VmObj* vm) // chitu_array_free(u:unit): 1 -{ - LosuObj *unit = arg_get(vm, 1); - chitu_array *a = getptr_fromunit(vm, unit); - - if (a == NULL) - { - arg_returnnull(vm); - return 1; - } - - chitu_array_free(a); - obj_setunit(vm, *unit, obj_newstr(vm, ptr_name), obj_newnull(vm)); - return 1; -} - -int ELSAPI_chitu_chitu_array_dataptr(els_VmObj* vm) // chitu_array_dataptr(u:unit): ptr -{ - LosuObj *unit = arg_get(vm, 1); - chitu_array *a = getptr_fromunit(vm, unit); - - if (a == NULL) - { - arg_returnnull(vm); - return 1; - } - - arg_returnptr(vm, (void *)chitu_array_dataptr(a)); - return 1; -} - -int ELSAPI_chitu_chitu_array_clear(els_VmObj* vm) // chitu_array_clear(u:unit): null -{ - LosuObj *unit = arg_get(vm, 1); - chitu_array *a = getptr_fromunit(vm, unit); - - if (a == NULL) - { - arg_returnnull(vm); - return 1; - } - - chitu_array_clear(a); - return 1; -} - -int ELSAPI_chitu_chitu_array_set(els_VmObj* vm) // chitu_array_set(u:unit, n:num): num -{ - LosuObj *unit = arg_get(vm, 1); - double n = arg_getnum(vm, 2); - chitu_array *a = getptr_fromunit(vm, unit); - - if (a == NULL) - { - arg_returnnull(vm); - return 1; - } - - chitu_array_set(a, n); - arg_returnnum(vm, n); - return 1; -} - -int ELSAPI_chitu_chitu_array_cat(els_VmObj* vm) // chitu_array_cat(a:unit, b:unit): int -{ - LosuObj *unit1 = arg_get(vm, 1); - LosuObj *unit2 = arg_get(vm, 2); - chitu_array *a = getptr_fromunit(vm, unit1); - chitu_array *b = getptr_fromunit(vm, unit2); - chitu_array *newa; - - if (a == NULL || b == NULL) - { - arg_returnnull(vm); - return 1; - } - - newa = chitu_array_cat(a, b); - chitu_array_free(a); - obj_setunit(vm, *unit1, obj_newstr(vm, ptr_name), obj_newptr(vm, (void *)newa)); - arg_return(vm, *unit1); - return 1; -} - -int ELSAPI_chitu_chitu_array_slice(els_VmObj* vm) // chitu_array_slice(u:unit, start:int, end:int): unit -{ - chitu_array *a, *newa; - LosuObj *unit = arg_get(vm, 1); - double start = arg_getnum(vm, 2); - double end = arg_getnum(vm, 3); - - a = getptr_fromunit(vm, unit); - - if (a == NULL) - { - arg_returnnull(vm); - return 1; - } - - newa = chitu_array_slice(a, start, end); - if (newa != NULL) - arg_returnptr(vm, (void *)newa); - else - arg_returnnull(vm); - - return 1; -} - -int ELSAPI_chitu_chitu_array_length(els_VmObj* vm) // chitu_array_length(u:unit): int -{ - LosuObj *unit = arg_get(vm, 1); - chitu_array *a = getptr_fromunit(vm, unit); - - if (a == NULL) - { - arg_returnnull(vm); - return 1; - } - - arg_returnnum(vm, chitu_array_length(a)); - return 1; -} - -int ELSAPI_chitu_chitu_array_copy(els_VmObj* vm) // chitu_array_copy(u:unit): unit -{ - LosuObj *unit1 = arg_get(vm, 1); - chitu_array *a = getptr_fromunit(vm, unit1); - - if (a == NULL) - { - arg_returnnull(vm); - return 1; - } - - chitu_array *newa = chitu_array_copy(a); - arg_returnptr(vm, (void *)newa); - return 1; -} - -int ELSAPI_chitu_chitu_array_get(els_VmObj* vm) -{ - LosuObj *unit = arg_get(vm, 1); - chitu_array *a = getptr_fromunit(vm, unit); - - if (a == NULL) - { - arg_returnnull(vm); - return 1; - } - - uint64_t index = arg_getnum(vm, 2); - double data; - - if (chitu_array_get(a, index, &data)) - arg_returnnum(vm, data); - else - arg_returnnull(vm); - - return 1; -} - -int ELSAPI_chitu_chitu_array_insert(els_VmObj* vm) -{ - LosuObj *unit = arg_get(vm, 1); - chitu_array *a = getptr_fromunit(vm, unit); - - if (a == NULL) - { - arg_returnnull(vm); - return 1; - } - - uint64_t index = arg_getnum(vm, 2); - double data = arg_getnum(vm, 3); - - if (chitu_array_insert(a, index, data)) - arg_returnnum(vm, data); - else - arg_returnnull(vm); - - return 1; -} - -int ELSAPI_chitu_chitu_array_print(els_VmObj* vm) -{ - LosuObj *unit = arg_get(vm, 1); - chitu_array *a = getptr_fromunit(vm, unit); - - if (a == NULL) - { - arg_returnnull(vm); - return 1; - } - - chitu_array_print(a); - return 1; -} - -// #自定义运算 -int ELSAPI_chitu_chitu_array_cfunct(els_VmObj* vm) // chitu_array_cfunct(u:unit, f:ptr): unit -{ - LosuObj *unit = arg_get(vm, 1); - double (*cfunct)(double) = (void *)arg_getptr(vm, 2); - cfunct = (void *)arg_getptr(vm, 2); - chitu_array *a = getptr_fromunit(vm, unit); - - if (a == NULL) - { - arg_returnnull(vm); - return 1; - } - - chitu_array_cfunct(a, cfunct); - arg_return(vm, *unit); - return 1; -} - -int ELSAPI_chitu_chitu_array_lsfunct(els_VmObj* vm) // chitu_array_lsfunct(u:unit, f:ptr): unit -{ - return 1; -} - -// #四则运算 -int ELSAPI_chitu_chitu_array_plus(els_VmObj* vm) // chitu_array_plus(u:unit, n:num): unit -{ - LosuObj *unit = arg_get(vm, 1); - chitu_array *a = getptr_fromunit(vm, unit); - - if (a == NULL) - { - arg_returnnull(vm); - return 1; - } - - if (arg_gettype(vm, 2) == ELS_API_TYPE_NUMBER) - { - double n = arg_getnum(vm, 2); - chitu_array_plus(a, n); - } - else if (arg_gettype(vm, 2) == ELS_API_TYPE_UNIT) - { - LosuObj *unit2 = arg_get(vm, 2); - LosuObj *ptr_obj = obj_indexunit(vm, *unit2, obj_newstr(vm, ptr_name)); - chitu_array *b; - - if (obj_type(vm, ptr_obj) == ELS_API_TYPE_PTR) - { - b = (void *)obj_toptr(vm, ptr_obj); - chitu_array_plusa(a, b); - } - } - - arg_return(vm, *unit); - return 1; -} - -int ELSAPI_chitu_chitu_array_minus(els_VmObj* vm) // chitu_array_minus(u:unit, n:num): unit -{ - LosuObj *unit = arg_get(vm, 1); - chitu_array *a = getptr_fromunit(vm, unit); - - if (a == NULL) - { - arg_returnnull(vm); - return 1; - } - - if (arg_gettype(vm, 2) == ELS_API_TYPE_NUMBER) - { - double n = arg_getnum(vm, 2); - chitu_array_minus(a, n); - } - else if (arg_gettype(vm, 2) == ELS_API_TYPE_UNIT) - { - LosuObj *unit2 = arg_get(vm, 2); - LosuObj *ptr_obj = obj_indexunit(vm, *unit2, obj_newstr(vm, ptr_name)); - chitu_array *b; - - if (obj_type(vm, ptr_obj) == ELS_API_TYPE_PTR) - { - b = (void *)obj_toptr(vm, ptr_obj); - chitu_array_minusa(a, b); - } - } - - arg_return(vm, *unit); - return 1; -} - -int ELSAPI_chitu_chitu_array_mutiplys(els_VmObj* vm) // chitu_array_mutiplys(u:unit, n:num): unit -{ - LosuObj *unit = arg_get(vm, 1); - chitu_array *a = getptr_fromunit(vm, unit); - - if (a == NULL) - { - arg_returnnull(vm); - return 1; - } - - if (arg_gettype(vm, 2) == ELS_API_TYPE_NUMBER) - { - double n = arg_getnum(vm, 2); - chitu_array_mutiplys(a, n); - } - else if (arg_gettype(vm, 2) == ELS_API_TYPE_UNIT) - { - LosuObj *unit2 = arg_get(vm, 2); - LosuObj *ptr_obj = obj_indexunit(vm, *unit2, obj_newstr(vm, ptr_name)); - chitu_array *b; - - if (obj_type(vm, ptr_obj) == ELS_API_TYPE_PTR) - { - b = (void *)obj_toptr(vm, ptr_obj); - chitu_array_mutiplysa(a, b); - } - } - - arg_return(vm, *unit); - return 1; -} - -int ELSAPI_chitu_chitu_array_divide(els_VmObj* vm) // chitu_array_divide(u:unit. n:num): unit -{ - LosuObj *unit = arg_get(vm, 1); - chitu_array *a = getptr_fromunit(vm, unit); - - if (a == NULL) - { - arg_returnnull(vm); - return 1; - } - - if (arg_gettype(vm, 2) == ELS_API_TYPE_NUMBER) - { - double n = arg_getnum(vm, 2); - chitu_array_divide(a, n); - } - else if (arg_gettype(vm, 2) == ELS_API_TYPE_UNIT) - { - LosuObj *unit2 = arg_get(vm, 2); - LosuObj *ptr_obj = obj_indexunit(vm, *unit2, obj_newstr(vm, ptr_name)); - chitu_array *b; - - if (obj_type(vm, ptr_obj) == ELS_API_TYPE_PTR) - { - b = (void *)obj_toptr(vm, ptr_obj); - chitu_array_dividea(a, b); - } - } - - arg_return(vm, *unit); - return 1; -} - -// #取模 -int ELSAPI_chitu_chitu_array_mod(els_VmObj* vm) // chitu_array_mod(u:unit, n:num): unit -{ - LosuObj *unit = arg_get(vm, 1); - chitu_array *a = getptr_fromunit(vm, unit); - - if (a == NULL) - { - arg_returnnull(vm); - return 1; - } - - if (arg_gettype(vm, 2) == ELS_API_TYPE_NUMBER) - { - double n = arg_getnum(vm, 2); - chitu_array_mod(a, n); - } - else if (arg_gettype(vm, 2) == ELS_API_TYPE_UNIT) - { - LosuObj *unit2 = arg_get(vm, 2); - LosuObj *ptr_obj = obj_indexunit(vm, *unit2, obj_newstr(vm, ptr_name)); - chitu_array *b; - - if (obj_type(vm, ptr_obj) == ELS_API_TYPE_PTR) - { - b = (void *)obj_toptr(vm, ptr_obj); - chitu_array_moda(a, b); - } - } - - arg_return(vm, *unit); - return 1; -} - -// #指数运算 -int ELSAPI_chitu_chitu_array_squre(els_VmObj* vm) // chitu_array_squre(u:unit): unit -{ - LosuObj *unit = arg_get(vm, 1); - chitu_array *a = getptr_fromunit(vm, unit); - - if (a == NULL) - { - arg_returnnull(vm); - return 1; - } - - chitu_array_squre(a); - arg_return(vm, *unit); - return 1; -} - -int ELSAPI_chitu_chitu_array_sqrt(els_VmObj* vm) // chitu_array_sqrt(u:unit): unit -{ - LosuObj *unit = arg_get(vm, 1); - chitu_array *a = getptr_fromunit(vm, unit); - - if (a == NULL) - { - arg_returnnull(vm); - return 1; - } - - chitu_array_sqrt(a); - arg_return(vm, *unit); - return 1; -} - -int ELSAPI_chitu_chitu_array_cube(els_VmObj* vm) // chitu_array_cube(u:unit): unit -{ - LosuObj *unit = arg_get(vm, 1); - chitu_array *a = getptr_fromunit(vm, unit); - - if (a == NULL) - { - arg_returnnull(vm); - return 1; - } - - chitu_array_cube(a); - arg_return(vm, *unit); - return 1; -} - -int ELSAPI_chitu_chitu_array_cbrt(els_VmObj* vm) // chitu_array_cbrt(u:unit): unit -{ - LosuObj *unit = arg_get(vm, 1); - chitu_array *a = getptr_fromunit(vm, unit); - - if (a == NULL) - { - arg_returnnull(vm); - return 1; - } - - chitu_array_cbrt(a); - arg_return(vm, *unit); - return 1; -} - -int ELSAPI_chitu_chitu_array_pow(els_VmObj* vm) // chitu_array_pow(u:unit, n:num): unit -{ - LosuObj *unit = arg_get(vm, 1); - double n = arg_getnum(vm, 2); - chitu_array *a = getptr_fromunit(vm, unit); - - if (a == NULL) - { - arg_returnnull(vm); - return 1; - } - - chitu_array_pow(a, n); - arg_return(vm, *unit); - return 1; -} - -// #杂项 -int ELSAPI_chitu_chitu_array_sum(els_VmObj* vm) // chitu_array_sum(u:unit) -{ - LosuObj *unit = arg_get(vm, 1); - chitu_array *a = getptr_fromunit(vm, unit); - - if (a == NULL) - { - arg_returnnull(vm); - return 1; - } - - arg_returnnum(vm, chitu_array_sum(a)); - return 1; -} - -int ELSAPI_chitu_chitu_array_even(els_VmObj* vm) // chitu_array_even(u:unit) -{ - LosuObj *unit = arg_get(vm, 1); - chitu_array *a = getptr_fromunit(vm, unit); - - if (a == NULL) - { - arg_returnnull(vm); - return 1; - } - - arg_returnnum(vm, chitu_array_even(a)); - return 1; -} - -int ELSAPI_chitu_chitu_array_variance(els_VmObj* vm) // chitu_array_variance(u:unit) -{ - LosuObj *unit = arg_get(vm, 1); - chitu_array *a = getptr_fromunit(vm, unit); - - if (a == NULL) - { - arg_returnnull(vm); - return 1; - } - - arg_returnnum(vm, chitu_array_variance(a)); - return 1; -} - -int ELSAPI_chitu_chitu_array_standard_deviation(els_VmObj* vm) // chitu_array_standard_deviation(u:unit) -{ - LosuObj *unit = arg_get(vm, 1); - chitu_array *a = getptr_fromunit(vm, unit); - - if (a == NULL) - { - arg_returnnull(vm); - return 1; - } - - arg_returnnum(vm, chitu_array_standard_deviation(a)); - return 1; -} - -int ELSAPI_chitu_chitu_array_max(els_VmObj* vm) // chitu_array_max(u:unit): number -{ - LosuObj *unit = arg_get(vm, 1); - chitu_array *a = getptr_fromunit(vm, unit); - double result; - - if (a == NULL) - { - arg_returnnull(vm); - return 1; - } - - chitu_array_max(a, &result); - arg_returnnum(vm, result); - return 1; -} - -int ELSAPI_chitu_chitu_array_min(els_VmObj* vm) // chitu_array_min(u:unit): number -{ - LosuObj *unit = arg_get(vm, 1); - chitu_array *a = getptr_fromunit(vm, unit); - double result; - - if (a == NULL) - { - arg_returnnull(vm); - return 1; - } - - chitu_array_min(a, &result); - arg_returnnum(vm, result); - return 1; -} - -// #排序 -int ELSAPI_chitu_chitu_array_sort(els_VmObj* vm) // chitu_array_sort(u:unit): unit -{ - LosuObj *unit = arg_get(vm, 1); - chitu_array *a = getptr_fromunit(vm, unit); - - if (a == NULL) - { - arg_returnnull(vm); - return 1; - } - - chitu_array_sort(a); - - arg_return(vm, *unit); - return 1; -} - -int ELSAPI_chitu_chitu_array_reverse(els_VmObj* vm) // chitu_array_reverse(u:unit): unit -{ - LosuObj *unit = arg_get(vm, 1); - chitu_array *a = getptr_fromunit(vm, unit); - - if (a == NULL) - { - arg_returnnull(vm); - return 1; - } - - chitu_array_reverse(a); - - arg_return(vm, *unit); - return 1; -} - -// #随机函数 -int ELSAPI_chitu_chitu_array_srand(els_VmObj* vm) // chitu_array_srand(u:unit, seed:number): unit -{ - uint64_t seed = arg_getnum(vm, 2); - chitu_srand(seed); - return 1; -} - -int ELSAPI_chitu_chitu_array_random(els_VmObj* vm) // chitu_array_random(u:unit): unit -{ - LosuObj *unit = arg_get(vm, 1); - chitu_array *a = getptr_fromunit(vm, unit); - - if (a == NULL) - { - arg_returnnull(vm); - return 1; - } - - chitu_array_random(a); - arg_return(vm, *unit); - return 1; -} - -int ELSAPI_chitu_chitu_array_randint(els_VmObj* vm) // chitu_array_randint(u:unit, start:int, end:int): unit -{ - LosuObj *unit = arg_get(vm, 1); - uint64_t start = arg_getnum(vm, 2); - uint64_t end = arg_getnum(vm, 3); - chitu_array *a = getptr_fromunit(vm, unit); - - if (a == NULL) - { - arg_returnnull(vm); - return 1; - } - - chitu_array_randint(a, start, end); - arg_return(vm, *unit); - return 1; -} - -int ELSAPI_chitu_chitu_array_randfloat(els_VmObj* vm) // chitu_array_randfloat(u:unit, start:num, end:num): unit -{ - LosuObj *unit = arg_get(vm, 1); - double start = arg_getnum(vm, 2); - double end = arg_getnum(vm, 3); - chitu_array *a = getptr_fromunit(vm, unit); - - if (a == NULL) - { - arg_returnnull(vm); - return 1; - } - - chitu_array_randfloat(a, start, end); - arg_return(vm, *unit); - return 1; -} - -int ELSAPI_chitu_chitu_array_choice(els_VmObj* vm) // chitu_array_choice(u:unit): unit -{ - LosuObj *unit = arg_get(vm, 1); - chitu_array *a = getptr_fromunit(vm, unit); - - if (a == NULL) - { - arg_returnnull(vm); - return 1; - } - - arg_returnnum(vm, chitu_array_choice(a)); - return 1; -} - -int ELSAPI_chitu_chitu_array_tounit(els_VmObj* vm) -{ - LosuObj *unit = arg_get(vm, 1); - chitu_array *a = getptr_fromunit(vm, unit); - - if (a == NULL) - { - arg_returnnull(vm); - return 1; - } - - LosuObj output = obj_newunit(vm); - double val; - - for (uint64_t i = 0; i < chitu_array_length(a); i++) - { - chitu_array_get(a, i, &val); - obj_setunit(vm, output, obj_newnum(vm, i + 1), obj_newnum(vm, val)); - } - - arg_return(vm, output); - return 1; -} - -int ELSAPI_chitu_chitu_array_fromunit(els_VmObj* vm) -{ - return 1; -} diff --git a/chitu/chitu.els b/chitu/chitu.els deleted file mode 100755 index bd244d24c5ccf1e2edbb7e94b32c9efc2e1c1e54..0000000000000000000000000000000000000000 --- a/chitu/chitu.els +++ /dev/null @@ -1,147 +0,0 @@ -#!declare - -#数组的创建和操作 -chitu_array_create(u:unit, len:int, init:num): ptr -chitu_array_free(u:unit): 1 -chitu_array_dataptr(u:unit): ptr -chitu_array_clear(u:unit): null -chitu_array_set(u:unit, n:num): num -chitu_array_cat(a:unit, b:unit): int -chitu_array_slice(u:unit, start:int, end:int): unit -chitu_array_length(u:unit): int -chitu_array_copy(u:unit): unit -chitu_array_get(u:unit, i:int) -chitu_array_insert(u:unit, i:int, d:double) -chitu_array_print(u:unit) - -#自定义运算 -chitu_array_cfunct(u:unit, f:ptr): unit -chitu_array_lsfunct(u:unit, f:ptr): unit - -#四则运算 -chitu_array_plus(u:unit, n:num): unit -chitu_array_minus(u:unit, n:num): unit -chitu_array_mutiplys(u:unit, n:num): unit -chitu_array_divide(u:unit. n:num): unit - -#取模 -chitu_array_mod(u:unit, n:num): unit - -#指数运算 -chitu_array_squre(u:unit): unit -chitu_array_sqrt(u:unit): unit -chitu_array_cube(u:unit): unit -chitu_array_cbrt(u:unit): unit -chitu_array_pow(u:unit, n:num): unit - -#杂项 -chitu_array_sum(u:unit) -chitu_array_even(u:unit) -chitu_array_variance(u:unit) -chitu_array_standard_deviation(u:unit) -chitu_array_max(u:unit): number -chitu_array_min(u:unit): number - -#排序 -chitu_array_sort(u:unit): unit -chitu_array_reverse(u:unit): unit - -#随机函数 -chitu_array_srand(u:unit, seed:number): unit -chitu_array_random(u:unit): unit -chitu_array_randint(u:unit, start:int, end:int): unit -chitu_array_randfloat(u:unit, start:num, end:num): unit -chitu_array_choice(u:unit): unit - -#类型转化 -chitu_array_tounit(u:unit): unit -chitu_array_fromunit(u:unit, unit): unit - -#!end - -#!script -引('stdlib') - -赤兔 = {} - -赤兔.更改随机数种子 = chitu_array_srand - -方法 赤兔.创建数组(长度, 初始值): - 令 新对象 = {} - 长度 = 长度 或 0 - 初始值 = 初始值 或 0 - - chitu_array_create(新对象, 长度, 初始值) - - 新对象.删除 = chitu_array_free - 新对象.长度 = chitu_array_length - 新对象.索引 = chitu_array_get - 新对象.插入 = chitu_array_insert - 新对象.数据指针 = chitu_array_dataptr - 新对象.清空 = chitu_array_clear - 新对象.设置 = chitu_array_set - 新对象.拼接 = chitu_array_cat - 新对象.打印 = chitu_array_print - - 方法 新对象.复制(): - 令 复制后对象 = 赤兔.创建数组() - 复制后对象.__ptr__ = chitu_array_copy(此) - 回 复制后对象 - ; - - 方法 新对象.切片(开始, 结束): - 令 切片后对象 = 赤兔.创建数组() - 令 新指针 = chitu_array_slice(此, 开始, 结束) - 切片后对象.删除() - - 如果 新指针: - 切片后对象.__ptr__ = 新指针 - 否则 - 切片后对象 = 空 - ; - - 回 切片后对象 - ; - - 新对象.调用C函数 = chitu_array_cfunct - - 新对象.加 = chitu_array_plus - 新对象.减 = chitu_array_minus - 新对象.乘 = chitu_array_mutiplys - 新对象.除 = chitu_array_divide - 新对象.取模 = chitu_array_mod - 新对象.平方 = chitu_array_squre - 新对象.开平方 = chitu_array_sqrt - 新对象.立方 = chitu_array_cube - 新对象.开立方 = chitu_array_cbrt - - 新对象.求和 = chitu_array_sum - 新对象.求平均数 = chitu_array_even - 新对象.求方差 = chitu_array_variance - 新对象.求标准差 = chitu_array_standard_deviation - 新对象.求最大值 = chitu_array_max - 新对象.求最小值 = chitu_array_min - - 新对象.排序 = chitu_array_sort - 新对象.倒置 = chitu_array_reverse - - 新对象.填充随机数 = chitu_array_random - 新对象.填充随机整数 = chitu_array_randint - 新对象.填充随机实数 = chitu_array_randfloat - 新对象.随机选择 = chitu_array_choice - - 新对象["::+"] = 新对象.加 - 新对象["::-"] = 新对象.减 - 新对象["::*"] = 新对象.乘 - 新对象["::/"] = 新对象.除 - 新对象["::^"] = 新对象.乘法 - 新对象["::&"] = 新对象.拼接 - - 新对象.转化为单元 = chitu_array_tounit - - 回 新对象 -; - -赤兔.更改随机数种子((时间.秒() + 时间.计时()) ^ 3) - -#!end diff --git a/chitu/chitu.h b/chitu/chitu.h deleted file mode 100755 index 17c583a4a70058bfb5876f9c8e5cff09a3a0ba27..0000000000000000000000000000000000000000 --- a/chitu/chitu.h +++ /dev/null @@ -1,181 +0,0 @@ -#include "els.h" -// #数组的创建和操作 -int ELSAPI_chitu_chitu_array_create(els_VmObj* vm); // chitu_array_create(u:unit, len:int, init:num): ptr -int ELSAPI_chitu_chitu_array_free(els_VmObj* vm); // chitu_array_free(u:unit): 1 -int ELSAPI_chitu_chitu_array_dataptr(els_VmObj* vm); // chitu_array_dataptr(u:unit): ptr -int ELSAPI_chitu_chitu_array_clear(els_VmObj* vm); // chitu_array_clear(u:unit): null -int ELSAPI_chitu_chitu_array_set(els_VmObj* vm); // chitu_array_set(u:unit, n:num): num -int ELSAPI_chitu_chitu_array_cat(els_VmObj* vm); // chitu_array_cat(a:unit, b:unit): int -int ELSAPI_chitu_chitu_array_slice(els_VmObj* vm); // chitu_array_slice(u:unit, start:int, end:int): unit -int ELSAPI_chitu_chitu_array_length(els_VmObj* vm); // chitu_array_length(u:unit): int -int ELSAPI_chitu_chitu_array_copy(els_VmObj* vm); // chitu_array_copy(u:unit): unit -int ELSAPI_chitu_chitu_array_get(els_VmObj* vm); // chitu_array_get(u:unit, i:int) -int ELSAPI_chitu_chitu_array_insert(els_VmObj* vm); // chitu_array_insert(u:unit, i:int, d:double) -int ELSAPI_chitu_chitu_array_print(els_VmObj* vm); // chitu_array_print(u:unit) -// #自定义运算 -int ELSAPI_chitu_chitu_array_cfunct(els_VmObj* vm); // chitu_array_cfunct(u:unit, f:ptr): unit -int ELSAPI_chitu_chitu_array_lsfunct(els_VmObj* vm); // chitu_array_lsfunct(u:unit, f:ptr): unit -// #四则运算 -int ELSAPI_chitu_chitu_array_plus(els_VmObj* vm); // chitu_array_plus(u:unit, n:num): unit -int ELSAPI_chitu_chitu_array_minus(els_VmObj* vm); // chitu_array_minus(u:unit, n:num): unit -int ELSAPI_chitu_chitu_array_mutiplys(els_VmObj* vm); // chitu_array_mutiplys(u:unit, n:num): unit -int ELSAPI_chitu_chitu_array_divide(els_VmObj* vm); // chitu_array_divide(u:unit. n:num): unit -// #取模 -int ELSAPI_chitu_chitu_array_mod(els_VmObj* vm); // chitu_array_mod(u:unit, n:num): unit -// #指数运算 -int ELSAPI_chitu_chitu_array_squre(els_VmObj* vm); // chitu_array_squre(u:unit): unit -int ELSAPI_chitu_chitu_array_sqrt(els_VmObj* vm); // chitu_array_sqrt(u:unit): unit -int ELSAPI_chitu_chitu_array_cube(els_VmObj* vm); // chitu_array_cube(u:unit): unit -int ELSAPI_chitu_chitu_array_cbrt(els_VmObj* vm); // chitu_array_cbrt(u:unit): unit -int ELSAPI_chitu_chitu_array_pow(els_VmObj* vm); // chitu_array_pow(u:unit, n:num): unit -// #杂项 -int ELSAPI_chitu_chitu_array_sum(els_VmObj* vm); // chitu_array_sum(u:unit) -int ELSAPI_chitu_chitu_array_even(els_VmObj* vm); // chitu_array_even(u:unit) -int ELSAPI_chitu_chitu_array_variance(els_VmObj* vm); // chitu_array_variance(u:unit) -int ELSAPI_chitu_chitu_array_standard_deviation(els_VmObj* vm); // chitu_array_standard_deviation(u:unit) -int ELSAPI_chitu_chitu_array_max(els_VmObj* vm); // chitu_array_max(u:unit): number -int ELSAPI_chitu_chitu_array_min(els_VmObj* vm); // chitu_array_min(u:unit): number -// #排序 -int ELSAPI_chitu_chitu_array_sort(els_VmObj* vm); // chitu_array_sort(u:unit): unit -int ELSAPI_chitu_chitu_array_reverse(els_VmObj* vm); // chitu_array_reverse(u:unit): unit -// #随机函数 -int ELSAPI_chitu_chitu_array_srand(els_VmObj* vm); // chitu_array_srand(u:unit, seed:number): unit -int ELSAPI_chitu_chitu_array_random(els_VmObj* vm); // chitu_array_random(u:unit): unit -int ELSAPI_chitu_chitu_array_randint(els_VmObj* vm); // chitu_array_randint(u:unit, start:int, end:int): unit -int ELSAPI_chitu_chitu_array_randfloat(els_VmObj* vm); // chitu_array_randfloat(u:unit, start:num, end:num): unit -int ELSAPI_chitu_chitu_array_choice(els_VmObj* vm); // chitu_array_choice(u:unit): unit -// #类型转化 -int ELSAPI_chitu_chitu_array_tounit(els_VmObj* vm); // chitu_array_tounit(u:unit): unit -int ELSAPI_chitu_chitu_array_fromunit(els_VmObj* vm); // chitu_array_fromunit(u:unit, unit): unit -#ifdef ELS_CONF_TOKEN_EN -static const char LibScript[]={ --27,-68,-107,40,39,115,116,100,108,105,98,39,41,10, -10, --24,-75,-92,-27,-123,-108,32,61,32,123,125,10, -10, --24,-75,-92,-27,-123,-108,46,-26,-101,-76,-26,-108,-71,-23,-102,-113,-26,-100,-70,-26,-107,-80,-25,-89,-115,-27,-83,-112,32,61,32,99,104,105,116,117,95,97,114,114,97,121,95,115,114,97,110,100,10, -10, --26,-106,-71,-26,-77,-107,32,-24,-75,-92,-27,-123,-108,46,-27,-120,-101,-27,-69,-70,-26,-107,-80,-25,-69,-124,40,-23,-107,-65,-27,-70,-90,44,32,-27,-120,-99,-27,-89,-117,-27,-128,-68,41,58,10, -32,32,32,32,-28,-69,-92,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,32,61,32,123,125,10, -32,32,32,32,-23,-107,-65,-27,-70,-90,32,61,32,-23,-107,-65,-27,-70,-90,32,-26,-120,-106,32,48,10, -32,32,32,32,-27,-120,-99,-27,-89,-117,-27,-128,-68,32,61,32,-27,-120,-99,-27,-89,-117,-27,-128,-68,32,-26,-120,-106,32,48,10, -10, -32,32,32,32,99,104,105,116,117,95,97,114,114,97,121,95,99,114,101,97,116,101,40,-26,-106,-80,-27,-81,-71,-24,-79,-95,44,32,-23,-107,-65,-27,-70,-90,44,32,-27,-120,-99,-27,-89,-117,-27,-128,-68,41,10, -10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-27,-120,-96,-23,-103,-92,32,61,32,99,104,105,116,117,95,97,114,114,97,121,95,102,114,101,101,10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-23,-107,-65,-27,-70,-90,32,61,32,99,104,105,116,117,95,97,114,114,97,121,95,108,101,110,103,116,104,10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-25,-76,-94,-27,-68,-107,32,61,32,99,104,105,116,117,95,97,114,114,97,121,95,103,101,116,10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-26,-113,-110,-27,-123,-91,32,61,32,99,104,105,116,117,95,97,114,114,97,121,95,105,110,115,101,114,116,10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-26,-107,-80,-26,-115,-82,-26,-116,-121,-23,-110,-120,32,61,32,99,104,105,116,117,95,97,114,114,97,121,95,100,97,116,97,112,116,114,10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-26,-72,-123,-25,-87,-70,32,61,32,99,104,105,116,117,95,97,114,114,97,121,95,99,108,101,97,114,10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-24,-82,-66,-25,-67,-82,32,61,32,99,104,105,116,117,95,97,114,114,97,121,95,115,101,116,10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-26,-117,-68,-26,-114,-91,32,61,32,99,104,105,116,117,95,97,114,114,97,121,95,99,97,116,10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-26,-119,-109,-27,-115,-80,32,61,32,99,104,105,116,117,95,97,114,114,97,121,95,112,114,105,110,116,10, -10, -32,32,32,32,-26,-106,-71,-26,-77,-107,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-27,-92,-115,-27,-120,-74,40,41,58,10, -32,32,32,32,32,32,32,32,-28,-69,-92,32,-27,-92,-115,-27,-120,-74,-27,-112,-114,-27,-81,-71,-24,-79,-95,32,61,32,-24,-75,-92,-27,-123,-108,46,-27,-120,-101,-27,-69,-70,-26,-107,-80,-25,-69,-124,40,41,10, -32,32,32,32,32,32,32,32,-27,-92,-115,-27,-120,-74,-27,-112,-114,-27,-81,-71,-24,-79,-95,46,95,95,112,116,114,95,95,32,61,32,99,104,105,116,117,95,97,114,114,97,121,95,99,111,112,121,40,-26,-83,-92,41,10, -32,32,32,32,32,32,32,32,-27,-101,-98,32,-27,-92,-115,-27,-120,-74,-27,-112,-114,-27,-81,-71,-24,-79,-95,10, -32,32,32,32,59,10, -10, -32,32,32,32,-26,-106,-71,-26,-77,-107,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-27,-120,-121,-25,-119,-121,40,-27,-68,-128,-27,-89,-117,44,32,-25,-69,-109,-26,-99,-97,41,58,10, -32,32,32,32,32,32,32,32,-28,-69,-92,32,-27,-120,-121,-25,-119,-121,-27,-112,-114,-27,-81,-71,-24,-79,-95,32,61,32,-24,-75,-92,-27,-123,-108,46,-27,-120,-101,-27,-69,-70,-26,-107,-80,-25,-69,-124,40,41,10, -32,32,32,32,32,32,32,32,-28,-69,-92,32,-26,-106,-80,-26,-116,-121,-23,-110,-120,32,61,32,99,104,105,116,117,95,97,114,114,97,121,95,115,108,105,99,101,40,-26,-83,-92,44,32,-27,-68,-128,-27,-89,-117,44,32,-25,-69,-109,-26,-99,-97,41,10, -32,32,32,32,32,32,32,32,-27,-120,-121,-25,-119,-121,-27,-112,-114,-27,-81,-71,-24,-79,-95,46,-27,-120,-96,-23,-103,-92,40,41,10, -10, -32,32,32,32,32,32,32,32,-27,-90,-126,-26,-98,-100,32,-26,-106,-80,-26,-116,-121,-23,-110,-120,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,-27,-120,-121,-25,-119,-121,-27,-112,-114,-27,-81,-71,-24,-79,-95,46,95,95,112,116,114,95,95,32,61,32,-26,-106,-80,-26,-116,-121,-23,-110,-120,10, -32,32,32,32,32,32,32,32,-27,-112,-90,-27,-120,-103,10, -32,32,32,32,32,32,32,32,32,32,32,32,-27,-120,-121,-25,-119,-121,-27,-112,-114,-27,-81,-71,-24,-79,-95,32,61,32,-25,-87,-70,10, -32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,32,32,32,32,-27,-101,-98,32,-27,-120,-121,-25,-119,-121,-27,-112,-114,-27,-81,-71,-24,-79,-95,10, -32,32,32,32,59,10, -10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-24,-80,-125,-25,-108,-88,67,-27,-121,-67,-26,-107,-80,32,61,32,99,104,105,116,117,95,97,114,114,97,121,95,99,102,117,110,99,116,10, -10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-27,-118,-96,32,61,32,99,104,105,116,117,95,97,114,114,97,121,95,112,108,117,115,10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-27,-121,-113,32,61,32,99,104,105,116,117,95,97,114,114,97,121,95,109,105,110,117,115,32,10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-28,-71,-104,32,61,32,99,104,105,116,117,95,97,114,114,97,121,95,109,117,116,105,112,108,121,115,10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-23,-103,-92,32,61,32,99,104,105,116,117,95,97,114,114,97,121,95,100,105,118,105,100,101,10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-27,-113,-106,-26,-88,-95,32,61,32,99,104,105,116,117,95,97,114,114,97,121,95,109,111,100,10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-27,-71,-77,-26,-106,-71,32,61,32,99,104,105,116,117,95,97,114,114,97,121,95,115,113,117,114,101,10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-27,-68,-128,-27,-71,-77,-26,-106,-71,32,61,32,99,104,105,116,117,95,97,114,114,97,121,95,115,113,114,116,10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-25,-85,-117,-26,-106,-71,32,61,32,99,104,105,116,117,95,97,114,114,97,121,95,99,117,98,101,10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-27,-68,-128,-25,-85,-117,-26,-106,-71,32,61,32,99,104,105,116,117,95,97,114,114,97,121,95,99,98,114,116,10, -10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-26,-79,-126,-27,-110,-116,32,61,32,99,104,105,116,117,95,97,114,114,97,121,95,115,117,109,10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-26,-79,-126,-27,-71,-77,-27,-99,-121,-26,-107,-80,32,61,32,99,104,105,116,117,95,97,114,114,97,121,95,101,118,101,110,10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-26,-79,-126,-26,-106,-71,-27,-73,-82,32,61,32,99,104,105,116,117,95,97,114,114,97,121,95,118,97,114,105,97,110,99,101,10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-26,-79,-126,-26,-96,-121,-27,-121,-122,-27,-73,-82,32,61,32,99,104,105,116,117,95,97,114,114,97,121,95,115,116,97,110,100,97,114,100,95,100,101,118,105,97,116,105,111,110,10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-26,-79,-126,-26,-100,-128,-27,-92,-89,-27,-128,-68,32,61,32,99,104,105,116,117,95,97,114,114,97,121,95,109,97,120,10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-26,-79,-126,-26,-100,-128,-27,-80,-113,-27,-128,-68,32,61,32,99,104,105,116,117,95,97,114,114,97,121,95,109,105,110,10, -10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-26,-114,-110,-27,-70,-113,32,61,32,99,104,105,116,117,95,97,114,114,97,121,95,115,111,114,116,10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-27,-128,-110,-25,-67,-82,32,61,32,99,104,105,116,117,95,97,114,114,97,121,95,114,101,118,101,114,115,101,10, -10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-27,-95,-85,-27,-123,-123,-23,-102,-113,-26,-100,-70,-26,-107,-80,32,61,32,99,104,105,116,117,95,97,114,114,97,121,95,114,97,110,100,111,109,10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-27,-95,-85,-27,-123,-123,-23,-102,-113,-26,-100,-70,-26,-107,-76,-26,-107,-80,32,61,32,99,104,105,116,117,95,97,114,114,97,121,95,114,97,110,100,105,110,116,10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-27,-95,-85,-27,-123,-123,-23,-102,-113,-26,-100,-70,-27,-82,-98,-26,-107,-80,32,61,32,99,104,105,116,117,95,97,114,114,97,121,95,114,97,110,100,102,108,111,97,116,10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-23,-102,-113,-26,-100,-70,-23,-128,-119,-26,-117,-87,32,61,32,99,104,105,116,117,95,97,114,114,97,121,95,99,104,111,105,99,101,10, -10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,91,34,58,58,43,34,93,32,61,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-27,-118,-96,10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,91,34,58,58,45,34,93,32,61,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-27,-121,-113,10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,91,34,58,58,42,34,93,32,61,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-28,-71,-104,10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,91,34,58,58,47,34,93,32,61,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-23,-103,-92,10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,91,34,58,58,94,34,93,32,61,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-28,-71,-104,-26,-77,-107,10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,91,34,58,58,38,34,93,32,61,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-26,-117,-68,-26,-114,-91,10, -10, -32,32,32,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,46,-24,-67,-84,-27,-116,-106,-28,-72,-70,-27,-115,-107,-27,-123,-125,32,61,32,99,104,105,116,117,95,97,114,114,97,121,95,116,111,117,110,105,116,10, -10, -32,32,32,32,-27,-101,-98,32,-26,-106,-80,-27,-81,-71,-24,-79,-95,10, -59,10, -10, --24,-75,-92,-27,-123,-108,46,-26,-101,-76,-26,-108,-71,-23,-102,-113,-26,-100,-70,-26,-107,-80,-25,-89,-115,-27,-83,-112,40,40,-26,-105,-74,-23,-105,-76,46,-25,-89,-110,40,41,32,43,32,-26,-105,-74,-23,-105,-76,46,-24,-82,-95,-26,-105,-74,40,41,41,32,94,32,51,41,10, -10, -0}; -#endif -void ElsLib_chitu_libinit(els_VmObj *vm){ - vm_register(vm,"chitu_array_sum",ELSAPI_chitu_chitu_array_sum); - vm_register(vm,"chitu_array_sqrt",ELSAPI_chitu_chitu_array_sqrt); - vm_register(vm,"chitu_array_mod",ELSAPI_chitu_chitu_array_mod); - vm_register(vm,"chitu_array_free",ELSAPI_chitu_chitu_array_free); - vm_register(vm,"chitu_array_random",ELSAPI_chitu_chitu_array_random); - vm_register(vm,"chitu_array_cbrt",ELSAPI_chitu_chitu_array_cbrt); - vm_register(vm,"chitu_array_plus",ELSAPI_chitu_chitu_array_plus); - vm_register(vm,"chitu_array_cfunct",ELSAPI_chitu_chitu_array_cfunct); - vm_register(vm,"chitu_array_pow",ELSAPI_chitu_chitu_array_pow); - vm_register(vm,"chitu_array_lsfunct",ELSAPI_chitu_chitu_array_lsfunct); - vm_register(vm,"chitu_array_print",ELSAPI_chitu_chitu_array_print); - vm_register(vm,"chitu_array_insert",ELSAPI_chitu_chitu_array_insert); - vm_register(vm,"chitu_array_fromunit",ELSAPI_chitu_chitu_array_fromunit); - vm_register(vm,"chitu_array_minus",ELSAPI_chitu_chitu_array_minus); - vm_register(vm,"chitu_array_create",ELSAPI_chitu_chitu_array_create); - vm_register(vm,"chitu_array_cat",ELSAPI_chitu_chitu_array_cat); - vm_register(vm,"chitu_array_choice",ELSAPI_chitu_chitu_array_choice); - vm_register(vm,"chitu_array_copy",ELSAPI_chitu_chitu_array_copy); - vm_register(vm,"chitu_array_clear",ELSAPI_chitu_chitu_array_clear); - vm_register(vm,"chitu_array_srand",ELSAPI_chitu_chitu_array_srand); - vm_register(vm,"chitu_array_set",ELSAPI_chitu_chitu_array_set); - vm_register(vm,"chitu_array_tounit",ELSAPI_chitu_chitu_array_tounit); - vm_register(vm,"chitu_array_squre",ELSAPI_chitu_chitu_array_squre); - vm_register(vm,"chitu_array_randfloat",ELSAPI_chitu_chitu_array_randfloat); - vm_register(vm,"chitu_array_randint",ELSAPI_chitu_chitu_array_randint); - vm_register(vm,"chitu_array_reverse",ELSAPI_chitu_chitu_array_reverse); - vm_register(vm,"chitu_array_slice",ELSAPI_chitu_chitu_array_slice); - vm_register(vm,"chitu_array_sort",ELSAPI_chitu_chitu_array_sort); - vm_register(vm,"chitu_array_get",ELSAPI_chitu_chitu_array_get); - vm_register(vm,"chitu_array_max",ELSAPI_chitu_chitu_array_max); - vm_register(vm,"chitu_array_variance",ELSAPI_chitu_chitu_array_variance); - vm_register(vm,"chitu_array_length",ELSAPI_chitu_chitu_array_length); - vm_register(vm,"chitu_array_dataptr",ELSAPI_chitu_chitu_array_dataptr); - vm_register(vm,"chitu_array_cube",ELSAPI_chitu_chitu_array_cube); - vm_register(vm,"chitu_array_even",ELSAPI_chitu_chitu_array_even); - vm_register(vm,"chitu_array_divide",ELSAPI_chitu_chitu_array_divide); - vm_register(vm,"chitu_array_mutiplys",ELSAPI_chitu_chitu_array_mutiplys); - vm_register(vm,"chitu_array_min",ELSAPI_chitu_chitu_array_min); - vm_register(vm,"chitu_array_standard_deviation",ELSAPI_chitu_chitu_array_standard_deviation); - #ifdef ELS_CONF_TOKEN_EN - vm_dostring(vm,LibScript); - #endif -}; diff --git a/chitu/chitu_base.c b/chitu/chitu_base.c deleted file mode 100755 index 909834de5737ec8976f1ba6f4a332100988b7ee3..0000000000000000000000000000000000000000 --- a/chitu/chitu_base.c +++ /dev/null @@ -1,142 +0,0 @@ -#include "chitu_base.h" - -static int chitu_array_size = sizeof(chitu_array); -//static int chitu_matrix_size = sizeof(chitu_matrix); - -#define malloc_array() malloc(chitu_array_size) -//#define malloc_matrix() malloc(chitu_matrix_size) - -//数组的创建和操作 -chitu_array *chitu_array_create(uint64_t len, double init) -{ - chitu_array *newa = malloc_array(); - - if (len <= 0) - { - newa->val = NULL; - newa->length = 0; - } - else - { - newa->val = malloc(sizeof(double) * len); - newa->length = len; - - for (uint64_t i = 0; i < len; i++) - newa->val[i] = init; - } - - return newa; -} - -void chitu_array_free(chitu_array *a) -{ - if (a->val != NULL) - free(a->val); - a->val = NULL; - a->length = 0; - free(a); -} - -inline void *chitu_array_dataptr(chitu_array *a) -{ - return a != NULL ? a->val : NULL; -} - -void chitu_array_clear(chitu_array *a) -{ - - if (a->val != NULL) - free(a->val); - a->val = NULL; - a->length = 0; -} - -inline uint64_t chitu_array_length(chitu_array *a) -{ - return a->length; -} - -inline bool chitu_array_get(chitu_array *a, uint64_t index, double *data) -{ - uint64_t len = a->length; - if (index <0 || index >= len) - return false; - *data = a->val[index]; - return true; -} - -inline bool chitu_array_insert(chitu_array *a, uint64_t index, double data) -{ - uint64_t len = a->length; - if (index <0 || index >= len) - return false; - a->val[index] = data; - return true; -} - -void chitu_array_set(chitu_array *a, double n) -{ - for (uint64_t i = 0; i < a->length; i++) - a->val[i] += n; -} - -void *chitu_array_cat(chitu_array *a, chitu_array *b) -{ - uint64_t i = 0; - chitu_array *newa = malloc_array(); - newa->length = a->length + b->length; - newa->val = malloc(sizeof(double) * newa->length); - - for (; i < a->length; i++) - newa->val[i] = a->val[i]; - - for (; i < newa->length; i++) - newa->val[i] = b->val[i - a->length]; - - return newa; -} - -void chitu_array_print(chitu_array *a) -{ - for (uint64_t i = 0; i < a->length; i++) - { - if (i % 5 == 0 && i != 0) - putchar('\n'); - printf("%.8f ", a->val[i]); - } - putchar('\n'); -} - -void *chitu_array_copy(chitu_array *a) -{ - chitu_array *newa = malloc_array(); - newa->length = a->length; - newa->val = malloc(sizeof(double) * newa->length); - - for (uint64_t i = 0; i < newa->length; i++) - newa->val[i] = a->val[i]; - - return newa; -} - -void *chitu_array_slice(chitu_array *a, uint64_t start, uint64_t end) -{ - if (end <= start || start <0 || end >= a->length) - return chitu_array_create(0, 0); - - chitu_array *newa = malloc_array(); - newa->length = end - start; - newa->val = malloc(sizeof(double) * newa->length); - - for (uint64_t i = start; i < end; i++) - newa->val[i - start] = a->val[i]; - - return newa; -} - -void chitu_array_cfunct(chitu_array *a, double ( *cfunct)(double)) -{ - for (uint64_t i = 0; i < a->length; i++) - a->val[i] = cfunct(a->val[i]); -} - diff --git a/chitu/chitu_base.h b/chitu/chitu_base.h deleted file mode 100755 index 75d1eed88f0197ab53ff3a0f7cf37c5aa5905e01..0000000000000000000000000000000000000000 --- a/chitu/chitu_base.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef CHITU_BASE_H__ -#define CHITU_BASE_H__ - -#include -#include -#include -#include -#include - -typedef struct _chitu_array chitu_array; -typedef struct _chitu_matrix chitu_matrix; - -struct _chitu_array -{ - double *val; - uint64_t length; -}; - -struct _chitu_matrix -{ - double **val; - uint64_t width; - uint64_t height; -}; - -//数组的创建和操作 -chitu_array *chitu_array_create(uint64_t len, double init); -void chitu_array_free(chitu_array *a); -void *chitu_array_dataptr(chitu_array *a); -void chitu_array_clear(chitu_array *a); -uint64_t chitu_array_length(chitu_array *a); -bool chitu_array_get(chitu_array *a, uint64_t index, double *data); -bool chitu_array_insert(chitu_array *a, uint64_t index, double data); -void chitu_array_set(chitu_array *a, double n); -void *chitu_array_cat(chitu_array *a, chitu_array *b); -void chitu_array_print(chitu_array *a); -void *chitu_array_copy(chitu_array *a); -void *chitu_array_slice(chitu_array *a, uint64_t start, uint64_t end); - -//自定义运算 -void chitu_array_cfunct(chitu_array *a, double ( *cfunct)(double)); - - - -#endif diff --git a/chitu/chitu_math.c b/chitu/chitu_math.c deleted file mode 100755 index 992a5b74b8a0f314aeed11e22204ff2754062001..0000000000000000000000000000000000000000 --- a/chitu/chitu_math.c +++ /dev/null @@ -1,276 +0,0 @@ -#include "chitu_math.h" -#include - -#define CHITU_MUT 25214903917ULL -#define CHITU_ADD 11ULL -#define CHITU_MOD 281474976710656ULL -#define CHITU_RAND_MAX CHITU_MOD - -uint64_t chitu_seed = 33; -double chitu_odt = 1 / 3; - -inline void chitu_srand(uint64_t x) -{ - chitu_seed = x; -} - -inline uint64_t chitu_rand() -{ - chitu_seed = (chitu_seed * CHITU_MUT + CHITU_ADD) % CHITU_MOD; - return chitu_seed; -} - -inline double chitu_random() -{ - - return (double)chitu_rand() / (double)CHITU_RAND_MAX; -} - -inline uint64_t chitu_randint(int64_t start, int64_t end) -{ - return ((end - start) * chitu_random() + start); -} - -inline double chitu_randfloat(double start, double end) -{ - return ((end - start) * chitu_random() + start); -} - -//通用数学部分 - -inline double chitu_squre(double x) -{ - return x*x; -} - -inline double chitu_sqrt(double x) -{ - return sqrt(x); -} - -inline double chitu_cube(double x) -{ - return x*x*x; -} - -inline double chitu_cbrt(double x) -{ - return exp(log(x) * chitu_odt); -} - -inline double chitu_pow(double x, double n) -{ - return pow(x, n); -} - -double chitu_array_sum(chitu_array *a) -{ - double output = 0; - for (uint64_t i = 0; i < a->length; i++) - output += a->val[i]; - return output; -} - -inline double chitu_array_even(chitu_array *a) -{ - return chitu_array_sum(a) / a->length; -} - -double chitu_array_variance(chitu_array *a) -{ - double a_even = chitu_array_even(a); - double output = 0; - - for (uint64_t i = 0; i < a->length; i++) - output += pow(a->val[i] - a_even, 2); - - return output / a->length; -} - -inline double chitu_array_standard_deviation(chitu_array *a) -{ - return chitu_sqrt(chitu_array_variance(a)); -} - -void chitu_array_max(chitu_array *a, double *result) -{ - double n = DBL_MIN; - - if (a->length == 0) - { - result = NULL; - return; - } - - for (uint64_t i = 0; i < a->length; i++) - if (a->val[i] > n) - n = a->val[i]; - *result = n; -} - -void chitu_array_min(chitu_array *a, double *result) -{ - double n = DBL_MAX; - - if (a->length == 0) - { - result = NULL; - return; - } - - for (uint64_t i = 0; i < a->length; i++) - if (a->val[i] < n) - n = a->val[i]; - *result = n; -} - -int sort_cmp(const void *a, const void *b) -{ - double front, tear; - front = *(double *)a; - tear = *(double *)b; - return front > tear ? 1 : -1; -} - -void chitu_array_sort(chitu_array *a) -{ - qsort(a->val, a->length, sizeof(double), sort_cmp); -} - -void chitu_array_reverse(chitu_array *a) -{ - double tmp; - for (uint64_t i = 0; i < a->length / 2; i++) - { - tmp = a->val[i]; - a->val[i] = a->val[a->length - 1 - i]; - a->val[a->length - 1 - i] = tmp; - } -} - -void chitu_array_random(chitu_array *a) -{ - for (uint64_t i = 0; i < a->length; i ++) - a->val[i] = chitu_random(); -} - -void chitu_array_randint(chitu_array *a, int64_t start, int64_t end) -{ - for (uint64_t i = 0; i < a->length; i ++) - a->val[i] = chitu_randint(start, end); -} - -void chitu_array_randfloat(chitu_array *a, double start, double end) -{ - for (uint64_t i = 0; i < a->length; i++) - a->val[i] = chitu_randfloat(start, end); -} - -inline double chitu_array_choice(chitu_array *a) -{ - return a->val[chitu_randint(0, a->length)]; -} - -//四则运算 - //对单个数字运算 -void chitu_array_plus(chitu_array *a, double n) -{ - for (uint64_t i = 0; i < a->length; i++) - a->val[i] += n; -} - -void chitu_array_minus(chitu_array *a, double n) -{ - for (uint64_t i = 0; i < a->length; i++) - a->val[i] -= n; -} - -void chitu_array_mutiplys(chitu_array *a, double n) -{ - for (uint64_t i = 0; i < a->length; i++) - a->val[i] *= n; -} - -void chitu_array_divide(chitu_array *a, double n) -{ - for (uint64_t i = 0; i < a->length; i++) - a->val[i] /= n; -} - -void chitu_array_mod(chitu_array *a, double n) -{ - for (uint64_t i = 0; i < a->length; i++) - a->val[i] = fmod(a->val[i], n); -} - //对数组运算 -void chitu_array_plusa(chitu_array *a, chitu_array *b) -{ - uint64_t stopindex = a->length < b->length ? a->length : b->length; - - for (uint64_t i = 0; i < stopindex; i++) - a->val[i] += b->val[i]; -} - -void chitu_array_minusa(chitu_array *a, chitu_array *b) -{ - uint64_t stopindex = a->length < b->length ? a->length : b->length; - - for (uint64_t i = 0; i < stopindex; i++) - a->val[i] -= b->val[i]; -} - -void chitu_array_mutiplysa(chitu_array *a, chitu_array *b) -{ - uint64_t stopindex = a->length < b->length ? a->length : b->length; - - for (uint64_t i = 0; i < stopindex; i++) - a->val[i] *= b->val[i]; -} - -void chitu_array_dividea(chitu_array *a, chitu_array *b) -{ - uint64_t stopindex = a->length < b->length ? a->length : b->length; - - for (uint64_t i = 0; i < stopindex; i++) - a->val[i] /= b->val[i]; -} - -void chitu_array_moda(chitu_array *a, chitu_array *b) -{ - uint64_t stopindex = a->length < b->length ? a->length : b->length; - - for (uint64_t i = 0; i < stopindex; i++) - a->val[i] = fmod(a->val[i], b->val[i]); -} - - -//指数运算 -void chitu_array_squre(chitu_array *a) -{ - for (uint64_t i = 0; i < a->length; i++) - a->val[i] *= a->val[i]; -} - -void chitu_array_sqrt(chitu_array *a) -{ - for (uint64_t i = 0; i < a->length; i++) - a->val[i] = chitu_sqrt(a->val[i]); -} - -void chitu_array_cube(chitu_array *a) -{ - for (uint64_t i = 0; i < a->length; i++) - a->val[i] = chitu_cube(a->val[i]); -} - -void chitu_array_cbrt(chitu_array *a) -{ - for (uint64_t i = 0; i < a->length; i++) - a->val[i] = chitu_cbrt(a->val[i]); -} - -void chitu_array_pow(chitu_array *a, double n) -{ - for (uint64_t i = 0; i < a->length; i++) - a->val[i] = chitu_pow(a->val[i], n); -} diff --git a/chitu/chitu_math.h b/chitu/chitu_math.h deleted file mode 100755 index 464e25f30925a8f27f9a4a9c67ccd6f663c4b2a5..0000000000000000000000000000000000000000 --- a/chitu/chitu_math.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef CHITU_MATH_H__ -#define CHITU_MATH_H__ - -/* - 这个文件是赤兔模块的数学部分 -*/ - -#include "chitu_base.h" -#include -#include -#include -#include - -//随机数部分 -void chitu_srand(uint64_t x); -uint64_t chitu_rand(); -double chitu_random(); -uint64_t chitu_randint(int64_t start, int64_t end); -double chitu_randfloat(double start, double end); - -//通用数学部分 -double chitu_squre(double x); -double chitu_sqrt(double x); -double chitu_cube(double x); -double chitu_cbrt(double x); -double chitu_pow(double x, double n); - -//array部分 -double chitu_array_sum(chitu_array *a); -double chitu_array_even(chitu_array *a); -double chitu_array_variance(chitu_array *a); -double chitu_array_standard_deviation(chitu_array *a); - -void chitu_array_max(chitu_array *a, double *result); -void chitu_array_min(chitu_array *a, double *result); -void chitu_array_sort(chitu_array *a); -void chitu_array_reverse(chitu_array *a); - -//随机 -void chitu_array_random(chitu_array *a); -void chitu_array_randint(chitu_array *a, int64_t start, int64_t end); -void chitu_array_randfloat(chitu_array *a, double start, double end); -double chitu_array_choice(chitu_array *a); - -//四则运算 - //对单个数字运算 -void chitu_array_plus(chitu_array *a, double n); -void chitu_array_minus(chitu_array *a, double n); -void chitu_array_mutiplys(chitu_array *a, double n); -void chitu_array_divide(chitu_array *a, double n); -void chitu_array_mod(chitu_array *a, double n); - //对数组运算 -void chitu_array_plusa(chitu_array *a, chitu_array *b); -void chitu_array_minusa(chitu_array *a, chitu_array *b); -void chitu_array_mutiplysa(chitu_array *a, chitu_array *b); -void chitu_array_dividea(chitu_array *a, chitu_array *b); -void chitu_array_moda(chitu_array *a, chitu_array *b); - -//指数运算 -void chitu_array_squre(chitu_array *a); -void chitu_array_sqrt(chitu_array *a); -void chitu_array_cube(chitu_array *a); -void chitu_array_cbrt(chitu_array *a); -void chitu_array_pow(chitu_array *a, double n); - -#endif \ No newline at end of file diff --git a/chitu/info b/chitu/info deleted file mode 100755 index 929356d8cac2ef67ff0c7c34fab0960d85a8920c..0000000000000000000000000000000000000000 --- a/chitu/info +++ /dev/null @@ -1,30 +0,0 @@ -{ - info = { - name = "chitu/'赤兔'数学计算模块", - text = "一个高效而优雅的数学计算模块", - version = "23.9.1" - }, - source = { - all = { - "chitu.h", - "chitu.c", - "chitu.els", - "chitu_base.h", - "chitu_base.c", - "chitu_math.c", - "chitu_math.h", - "readme.md" - }, - Ubuntu = { - "makefile", - }, - Windows = { - "makefile", - } - }, - target = { - #Ubuntu = "make ; cp ElsLib_chitu.lsd target/ElsLib_chitu.lsd_Ubuntu ; make clean", - Windows = "make ; cp ElsLib_chitu.lsd target/ElsLib_chitu.lsd_Windows ; make clean", - } -} - diff --git a/chitu/readme.md b/chitu/readme.md deleted file mode 100755 index 1ac8cfdeb4c7cdbbefc4d87e6afcb39c9fc4e2dc..0000000000000000000000000000000000000000 --- a/chitu/readme.md +++ /dev/null @@ -1,195 +0,0 @@ -#!/bin/owls.wiki.losu.tech -# 赤兔文档 -## 简介 -赤兔是一个高性能数学计算模块。起名赤兔,是希望它高效而优雅。通过赤兔,您可以方便地进行大规模数据的储存和计算。 - -下面是一个使用赤兔的简单例子 -```python -引("chitu") - -令 甲 = 赤兔.创建数组(100, 6) #创建一个长度为100个数字的数组,初始值为6 -令 乙 = 赤兔.创建数组(100, 5) #创建一个长度为100个数字的数组,初始值为5 - -甲 = 甲 + 4 #对数组的全部数据加4, 现在全部数据为10 -甲 = 甲 - 乙 #将甲的全部数据按顺序和乙的相减,即甲[0] = 甲[0] - 乙[0], 以此类推 - -甲.插入(5, 67) #将甲的5索引处的数据更改为67, 即甲[5] = 67 -甲.插入(33, 甲.索引(3) + 7) #索引3处的数据,加上7后插入33处 - -甲.打印() #将甲的信息打印到屏幕上,输出略 - -甲.删除() #清除甲和乙的内存占用,此后两者不再可用 -乙.删除() -``` - -## 函数 -### 赤兔.更改随机数种子(种子:正整数): 空 -+ 种子为要更改的种子,该种子将被所有赤兔模块内的随机运算使用。 - -### 赤兔.创建数组(长度, 初始值): 单元 -+ 长度为要创建的数组的长度,单位为个。初始值为要创建的数组的初始值。 -+ 返回一个数组对象。 -+ 当长度和初始值缺省时,会被设置为0. - -## 对象 -### 数组对象 -#### 成员变量 -##### \_\_ptr\_\_ : 指针 -+ 储存数组结构体的指针 -+ 当指针对应的内存被释放后,该变量会被设置为空 - -#### 成员函数 -##### 删除(): 单元 -+ 将数组内存释放并将\_\_ptr\_\_设置为空 -+ 返回释放内存后的数组对象,但此对象不再可用.为防止误操作,建议在调用该函数后将对象设置为空. - -##### 长度(): 整数 -+ 返回数组的实际长度 -+ 当内存被释放时,返回0 - -##### 索引(索引值:整数): 数字 -+ 返回索引值处的数据 -+ 当越界时返回空 - -##### 插入(索引值:整数, 数据:数字): 数字 -+ 将数据插入索引值处.会将原本的数据替换 -+ 当插入成功时,返回插入的数据,否则返回空 - -##### 数据指针(): 指针 -+ 返回储存数据的内存起始指针 -+ 长度可以通过成员函数“长度”获取 - -##### 清空(): 单元 -+ 将数据内存释放,但不会释放数组内存 -+ 使用该方法后,数据不再可访问,但是数组对象可以继续使用 -+ 返回数组对象 - -##### 设置(数据:数字): 数字 -+ 将数组中的数据都设置为该数据 -+ 返回输入的数据 - -##### 拼接(乙:单元): 单元 -+ 乙也是一个数组对象 -+ 将乙的数据拼接到本数组的末端,会为本数组申请一块新内存 -+ 返回本数组对象 - -##### 打印(): 空 -+ 将数组中的所有数据按每五个一行并且保留小数点后8位的格式打印到屏幕上 - -##### 复制(): 单元 -+ 将本对象的数据复制一份,会申请一块新内存并创建一个新对象 -+ 返回新创建的数组对象 - -##### 切片(开始, 结束): 单元 -+ 将本数组切片,切片后的数据包括开始索引而不包括结束索引处数据 -+ 会创建一个新对象,返回新对象 - -##### 调用C函数(函数指针:指针): 单元 -+ 接受一个函数指针,该指针将会被解释为double ( *cfunct)(double)类型并对数组进行遍历求值操作 -示意代码如下 -```c -for (uint64_t i = 0; i < array->length; i++) - array->val[i] = cfunct(array->val[i]); -``` -+ 返回本对象 - -##### 加(甲): 单元 -+ 甲的类型可以是数字,也可以同为数组对象 -+ 若甲为数字,则使用甲对数组中的每一个数据进行运算 -+ 若甲为数组对象,则按索引在两个数组之间运算,结果保存在本数组中。若两数组长度不相等,运算到较短数组的尽头即停止 -+ 返回本数组 - -##### 减(甲): 单元 -+ 甲的类型可以是数字,也可以同为数组对象 -+ 若甲为数字,则使用甲对数组中的每一个数据进行运算 -+ 若甲为数组对象,则按索引在两个数组之间运算,结果保存在本数组中。若两数组长度不相等,运算到较短数组的尽头即停止 -+ 返回本数组 - -##### 乘(甲): 单元 -+ 甲的类型可以是数字,也可以同为数组对象 -+ 若甲为数字,则使用甲对数组中的每一个数据进行运算 -+ 若甲为数组对象,则按索引在两个数组之间运算,结果保存在本数组中。若两数组长度不相等,运算到较短数组的尽头即停止 -+ 返回本数组 - -##### 除(甲): 单元 -+ 甲的类型可以是数字,也可以同为数组对象 -+ 若甲为数字,则使用甲对数组中的每一个数据进行运算 -+ 若甲为数组对象,则按索引在两个数组之间运算,结果保存在本数组中。若两数组长度不相等,运算到较短数组的尽头即停止 -+ 返回本数组 - -##### 取模(甲): 单元 -+ 甲的类型可以是数字,也可以同为数组对象 -+ 若甲为数字,则使用甲对数组中的每一个数据进行运算 -+ 若甲为数组对象,则按索引在两个数组之间运算,结果保存在本数组中。若两数组长度不相等,运算到较短数组的尽头即停止 -+ 返回本数组 - -##### 平方(): 单元 -+ 对数组中所有数据进行平方运算 -+ 返回本数组 - -##### 开平方(): 单元 -+ 对数组中所有数据进行开平方运算 -+ 返回本数组 - -##### 立方(): 单元 -+ 对数组中所有数据进行立方运算 -+ 返回本数组 - -##### 开立方(): 单元 -+ 对数组中所有数据进行开立方运算 -+ 返回本数组 - -#### 求和(): 数字 -+ 返回数组中所有数据的和 -+ 返回结果 - -#### 求平均数(): 数字 -+ 返回数组中所有数据的平均数 -+ 返回结果 - -#### 求方差(): 数字 -+ 返回数组中所有数据的方差 -+ 返回结果 - -#### 求标准差(): 数字 -+ 返回数组中所有数据的标准差 -+ 返回结果 - -#### 求最大值(): 数字 -+ 返回数组中所有数据的最大值 -+ 返回结果 - -#### 求最小值(): 数字 -+ 返回数组中所有数据的最小值 -+ 返回结果 - -#### 排序(): 单元 -+ 将数组中的数据按正序排列 -+ 返回本数组 - -#### 倒置(): 单元 -+ 将数组中的数据的顺序颠倒 -+ 返回本数组 - -#### 填充随机数(): 单元 -+ 将数组中的数据填充为随机数,随机数是区间为[0, 1)的小数 -+ 返回本数组 - -#### 填充随机整数(开始:整数, 结束:整数): 单元 -+ 将数组中的数据填充为随机数,随机数是区间为[开始, 结束)的整数 -+ 返回本数组 - -#### 填充随机实数(开始:整数, 结束:整数): 单元 -+ 将数组中的数据填充为随机数,随机数是区间为[开始, 结束)的实数 -+ 返回本数组 - -#### 随机选择(): 数字 -+ 随机返回数组中的一个数字 -+ 当数组没有任何数据时,返回空 - -##### 转化为单元(): 单元 -+ 将数组中储存的数据放入一个新单元中 -+ 单元的索引从1开始 - -#### 重载的运算符 -重载了+、-、*、/、^、&运算符,可以对数字和数组对象进行运算,详情参见对应的成员函数 diff --git a/lsnput/.keep b/lsnput/.keep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/lsnput/ELS_lsnput.c b/lsnput/ELS_lsnput.c old mode 100755 new mode 100644 diff --git a/lsnput/ELS_lsnput.h b/lsnput/ELS_lsnput.h old mode 100755 new mode 100644 diff --git a/lsnput/Ubuntu/.keep b/lsnput/Ubuntu/.keep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/lsnput/Ubuntu/makefile b/lsnput/Ubuntu/makefile new file mode 100644 index 0000000000000000000000000000000000000000..865925f41db1e688224976f03c84fea4edb17f74 --- /dev/null +++ b/lsnput/Ubuntu/makefile @@ -0,0 +1,14 @@ +OBJ = ElsLib_lsnput.lsd +BASE = Els_lsnput.o lsnput.o +CFLAGS= -O3 -std=c99 -Wall -DLOSU_LINUX -I ../buildenv -fPIC +CC=gcc +T=./ElsLib_lsnput.lsd + + +all: $T + +$T: $(OBJS) + $(CC) -o $@ $(OBJS) $(BASE) -shared -lm -s -lc -O3 + +clean: + rm -rf $T $(OBJS) $(BASE) core core.* \ No newline at end of file diff --git a/lsnput/WIKI/.keep b/lsnput/WIKI/.keep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/lsnput/WIKI/c.md b/lsnput/WIKI/c.md new file mode 100644 index 0000000000000000000000000000000000000000..77d031359da3e8b2c6c5d14efb1aab074b9dd9d8 --- /dev/null +++ b/lsnput/WIKI/c.md @@ -0,0 +1,114 @@ +# lsnput C层文档 + +lsnput的C层被设计为是平台无关的,但是目前只有Windows实现。 +欲使用lsnput的C层代码,可包含lsnput.h,之后编译lsnput.c。 + +## 获取和设置鼠标位置 + +想要获取鼠标位置,需要先创建一个MousePosition对象,之后将MousePosition*传递给GetMousePosition。 +想要设置鼠标位置,需要填写好MousePosition对象,之后将它的指针传递给SetMousePosion。 + +这两个函数的使用例程如下 + +```c +#include "lsnput.h" + +#include + +int main() +{ + MousePosition p; + + GetMousePosition(&p); //获取坐标 + printf("the position of mouse is x:%u, y:%u.\n", p.x, p.y); //打印坐标。中文字面量有乱码等问题,此处采用英文。 + + //将坐标都向正方形移动5个像素 + p.x += 5; + p.y += 5; + + SetMousePosition(&p); //设置新坐标。此时鼠标应向右下角移动。 + + return 0; +} + +``` + +## 设置鼠标事件 + +设置鼠标事件,需要用到MouseAct函数和MouseEvent类型。其原型如下: + +```c +typedef struct { + uint8_t type; //鼠标事件的类型 + uint8_t slide; //鼠标中键滑动的距离。当type为LSNPUT_MOUSE_MID | LSNPUT_MOUSE_DOWN此值才有效。 +} MouseEvent; + + +bool MouseAct(MouseEvent *event); //设置鼠标事件 +``` + +MouseEvent的type成员可以有以下可能值: + ++ LSNPUT_MOUSE_LEFT 鼠标的左键 ++ LSNPUT_MOUSE_RIGHT 鼠标的右键 ++ LSNPUT_MOUSE_MID 鼠标的中键 ++ LSNPUT_MOUSE_UP 鼠标向上 ++ LSNPUT_MOUSE_DOWN 鼠标向下 + +这些值直接可以通过|运算符拼接 + +下面是一个例程 + +```c +#include "lsnput.h" + +int main() +{ + MouseEvent e; + + e.type = LSNPUT_MOUSE_LEFT | LSNPUT_MOUSE_DOWN; //类型为左键向下,即摁下左键 + MouseEvent(&e); + + e.type = LSNPUT_MOUSE_LEFT | LSNPUT_MOUSE_UP; //摁下左键后,要恢复左键 + MouseEvent(&e); + + return 0; +} + +``` + +## 高层API + +lsnput封装了MouseClick函数,将鼠标移到指定位置并摁下相应的键。该函数不能处理中键的滚动。 +MouseClick函数中会调用SetMousePosition、MouseAct,将鼠标移到对应位置,将对应键摁下并抬起。 + +原型如下 + +```c + +bool MouseClick(MousePosition *p, uint64_t type); //将鼠标移到指定位置,并点击相应的键 + +``` + +下面是一个例程 + +```c +#include "lsnput.h" + +int main() +{ + MousePosition p; + + GetMousePosition(&p); //获取当前位置 + + //移动鼠标位置 + p.x += 25; + p.y += 25; + + //按下鼠标左键 + MouseClick(&p, LSNPUT_MOUSE_LEFT); + + return 0; +} + +``` diff --git a/lsnput/WIKI/script.md b/lsnput/WIKI/script.md new file mode 100644 index 0000000000000000000000000000000000000000..be8d8e8a6458cf7e2515c6632d3819ff732e3e7f --- /dev/null +++ b/lsnput/WIKI/script.md @@ -0,0 +1,53 @@ +# lsnput脚本层文档 + +本模块提供了监听、操作键盘和鼠标的功能。目前仅实现Windows平台下鼠标的监听和操作。计划在2.0.0.1版本发布Windows平台下键盘的监听和操作功能。 + +模块通过构造对象来组织代码。 + +## 获取鼠标位置 + +该函数的返回值是一个单元,x轴值储存在x成员中,y轴值储存在y成员中. + +下面是例程 + +```c +引("lsnput") + +令 鼠标 = 键鼠事件.鼠标() +位置 = 鼠标.位置() + +打印(位置.x) +打印(位置.y) + +``` + +## 更改鼠标位置 + +下面是例程 + +```c +引('lsnput') + +令 鼠标 = 键鼠事件.鼠标() + +鼠标.设置(0, 0) #鼠标会被设置到0, 0处 +``` + +## 控制鼠标点击 + +下面是例程 + +```c +引("lsnput") + +令 鼠标 = 键鼠事件.鼠标() + +鼠标.点击('left') #会点击一下左键 +""" +点击这个函数有两个参数,第一个是按键的字符串,默认是left.其他可能值有right、mid +第二个是点击的次数 +""" + +``` + + diff --git "a/lsnput/WIKI/\345\216\206\345\217\262/.keep" "b/lsnput/WIKI/\345\216\206\345\217\262/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/lsnput/WIKI/\345\216\206\345\217\262/1.17.0.1" "b/lsnput/WIKI/\345\216\206\345\217\262/1.17.0.1" new file mode 100644 index 0000000000000000000000000000000000000000..d8a8008ce1e3431ccf51e6b884dcb30eed3b4521 --- /dev/null +++ "b/lsnput/WIKI/\345\216\206\345\217\262/1.17.0.1" @@ -0,0 +1 @@ +1.17.0.1版本重构了脚本层代码,使用面向对象语法组织代码,更加人性化 \ No newline at end of file diff --git "a/lsnput/WIKI/\345\216\206\345\217\262/1.7.0.0.md" "b/lsnput/WIKI/\345\216\206\345\217\262/1.7.0.0.md" new file mode 100644 index 0000000000000000000000000000000000000000..4e7886e7a4508a6f5a98b09b4f8a21ca371a1078 --- /dev/null +++ "b/lsnput/WIKI/\345\216\206\345\217\262/1.7.0.0.md" @@ -0,0 +1,6 @@ +# 1.7.0.0 版本文档 + +这是lsnput的第一个发行版,只完成了Windows平台下的鼠标位置获取与设置、鼠标事件的设置。鼠标事件的监听和键盘系列的实现还在酝酿。 + +本模块在设计时的受众主要是Windows平台下的普通用户,并非开发者。但是C层代码为开发者精心设置了接口。这样lsnput的脚本层和C层都可以是一个跨平台的鼠标键盘处理模块,成为编程人员的好帮手。 + diff --git a/lsnput/Windows/.keep b/lsnput/Windows/.keep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/lsnput/Windows/makefile b/lsnput/Windows/makefile old mode 100755 new mode 100644 index cb9738d5e3ef5d22f2d77cdee6b11a28cf5cfcfa..99cdbd29a70bf8463983c3faa0bccd5447ec5313 --- a/lsnput/Windows/makefile +++ b/lsnput/Windows/makefile @@ -1,13 +1,9 @@ - -OBJS = ELS_lsnput.o lsnput.o -CFLAGS = -O3 -std=c99 -Wall -DLOSU_WINDOWS -I ../buildenv -fPIC -CC = x86_64-w64-mingw32-gcc -T = ElsLib_lsnput.lsd - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -L ../buildenv -l:libeasylosu.dll -lm -static -shared -s - -clean: - rm -rf $(OBJS) $(T) \ No newline at end of file +OBJ = ElsLib_lsnput.lsd +BASE = Els_lsnput.o lsnput.o +CFLAGE = -O3 -std=c99 -Wall -DLOSU_WINDOWS -I ../buildenv -fPIC -L ../buildenv -l:libeasylosu.dll -lUrlmon -lUser32 -lkernel32 -lWininet -lm -static -shared -s +CC = gcc + +OBJ: + $(CC) Els_lsnput.c lsnput.c -c $(CFLAGE) + $(CC) -o $(OBJ) $(BASE) $(CFLAGE) + \ No newline at end of file diff --git a/lsnput/lsnput.c b/lsnput/lsnput.c old mode 100755 new mode 100644 diff --git a/lsnput/lsnput.els b/lsnput/lsnput.els old mode 100755 new mode 100644 diff --git a/lsnput/lsnput.h b/lsnput/lsnput.h old mode 100755 new mode 100644 index 10cb4450f81f127971f7f5e0ed9b8cc2539fea66..916bab81fc272d6a6bc01bec1be0ecb300d4d0c1 --- a/lsnput/lsnput.h +++ b/lsnput/lsnput.h @@ -1,3 +1,36 @@ -#include "els.h" -void ElsLib_lsnput_libinit(els_VmObj *vm){ -}; +#ifndef LSNPUT_H_ +#define LSNPUT_H_ + +/* + 洛书的监听、操作鼠标和键盘的模块 + 作者:Matriller + 立项时间:2023-9-29 + 历史维护者:Matriller + 版本:1.7.0.1 +*/ + +#include +#include + +#define LSNPUT_MOUSE_LEFT 0b00000001 +#define LSNPUT_MOUSE_RIGHT 0b00000010 +#define LSNPUT_MOUSE_MID 0b00000100 +#define LSNPUT_MOUSE_UP 0b00001000 +#define LSNPUT_MOUSE_DOWN 0b00010000 + +typedef struct { + uint32_t x; //鼠标的x轴坐标 + uint32_t y; //鼠标的y轴坐标 +} MousePosition; + +typedef struct { + uint8_t type; //鼠标事件的类型 + uint8_t slide; //鼠标中键滑动的距离。当type为LSNPUT_MOUSE_MID | LSNPUT_MOUSE_DOWN此值才有效。 +} MouseEvent; + +bool GetMousePosition(MousePosition *position); //获取鼠标位置 +bool SetMousePosition(MousePosition *position); //设置鼠标位置 +bool MouseAct(MouseEvent *event); //设置鼠标事件 +bool MouseClick(MousePosition *p, uint64_t type); //将鼠标移到指定位置,并点击相应的键 + +#endif \ No newline at end of file diff --git a/lsnput/lsnput_script.h b/lsnput/lsnput_script.h old mode 100755 new mode 100644 diff --git a/lsnput/readme.md b/lsnput/readme.md old mode 100755 new mode 100644 index 59edeb294e471815f0f93ff54bfed677434032b4..be8d8e8a6458cf7e2515c6632d3819ff732e3e7f --- a/lsnput/readme.md +++ b/lsnput/readme.md @@ -1,54 +1,53 @@ -#!/bin/owls.wiki.losu.tech -# lsnput脚本层文档 - -本模块提供了监听、操作键盘和鼠标的功能。目前仅实现Windows平台下鼠标的监听和操作。计划在2.0.0.1版本发布Windows平台下键盘的监听和操作功能。 - -模块通过构造对象来组织代码。 - -## 获取鼠标位置 - -该函数的返回值是一个单元,x轴值储存在x成员中,y轴值储存在y成员中. - -下面是例程 - -```c -引("lsnput") - -令 鼠标 = 键鼠事件.鼠标() -位置 = 鼠标.位置() - -打印(位置.x) -打印(位置.y) - -``` - -## 更改鼠标位置 - -下面是例程 - -```c -引('lsnput') - -令 鼠标 = 键鼠事件.鼠标() - -鼠标.设置(0, 0) #鼠标会被设置到0, 0处 -``` - -## 控制鼠标点击 - -下面是例程 - -```c -引("lsnput") - -令 鼠标 = 键鼠事件.鼠标() - -鼠标.点击('left') #会点击一下左键 -""" -点击这个函数有两个参数,第一个是按键的字符串,默认是left.其他可能值有right、mid -第二个是点击的次数 -""" - -``` - - +# lsnput脚本层文档 + +本模块提供了监听、操作键盘和鼠标的功能。目前仅实现Windows平台下鼠标的监听和操作。计划在2.0.0.1版本发布Windows平台下键盘的监听和操作功能。 + +模块通过构造对象来组织代码。 + +## 获取鼠标位置 + +该函数的返回值是一个单元,x轴值储存在x成员中,y轴值储存在y成员中. + +下面是例程 + +```c +引("lsnput") + +令 鼠标 = 键鼠事件.鼠标() +位置 = 鼠标.位置() + +打印(位置.x) +打印(位置.y) + +``` + +## 更改鼠标位置 + +下面是例程 + +```c +引('lsnput') + +令 鼠标 = 键鼠事件.鼠标() + +鼠标.设置(0, 0) #鼠标会被设置到0, 0处 +``` + +## 控制鼠标点击 + +下面是例程 + +```c +引("lsnput") + +令 鼠标 = 键鼠事件.鼠标() + +鼠标.点击('left') #会点击一下左键 +""" +点击这个函数有两个参数,第一个是按键的字符串,默认是left.其他可能值有right、mid +第二个是点击的次数 +""" + +``` + + diff --git a/random/ELS_random.c b/random/ELS_random.c index a43d1d9d229f19e385eb49e4d566b74249c9fe72..f2ce3e55b79a66e3772d5199174ea830a79b3936 100755 --- a/random/ELS_random.c +++ b/random/ELS_random.c @@ -80,3 +80,21 @@ int ELSAPI_random_percent(els_VmObj *vm) arg_returnnull(vm); return 1; } + +void ElsLib_random_libinit(els_VmObj *vm) +{ + LosuObj lib = obj_newunit(vm); + + obj_setunit(vm, lib, obj_newstr(vm, "randseed"), obj_newfunction(vm, ELSAPI_random_randseed)); + obj_setunit(vm, lib, obj_newstr(vm, "random"), obj_newfunction(vm, ELSAPI_random_random)); + obj_setunit(vm, lib, obj_newstr(vm, "randint"), obj_newfunction(vm, ELSAPI_random_randint)); + obj_setunit(vm, lib, obj_newstr(vm, "randfloat"), obj_newfunction(vm, ELSAPI_random_randfloat)); + obj_setunit(vm, lib, obj_newstr(vm, "normal"), obj_newfunction(vm, ELSAPI_random_normal)); + obj_setunit(vm, lib, obj_newstr(vm, "srand"), obj_newfunction(vm, ELSAPI_random_srand)); + obj_setunit(vm, lib, obj_newstr(vm, "randstr"), obj_newfunction(vm, ELSAPI_random_randstr)); + obj_setunit(vm, lib, obj_newstr(vm, "randbytes"), obj_newfunction(vm, ELSAPI_random_randbytes)); + obj_setunit(vm, lib, obj_newstr(vm, "percent"), obj_newfunction(vm, ELSAPI_random_percent)); + + vm_setval(vm, "random", lib); + vm_dostring(vm, random_script); +} diff --git a/random/ELS_random.h b/random/ELS_random.h index aa731305099215eae695f1fe4abb5ecb940d391a..5cf105eb74509e3129dcfd944412650f858933fa 100755 --- a/random/ELS_random.h +++ b/random/ELS_random.h @@ -3,6 +3,8 @@ #include "els.h" #include "ELS_random_script.h" +#include "random.h" +#include "lc.h" #include @@ -16,22 +18,4 @@ int ELSAPI_random_randstr(els_VmObj *vm); int ELSAPI_random_randbytes(els_VmObj *vm); int ELSAPI_random_percent(els_VmObj *vm); -void ElsLib_random_libinit(els_VmObj *vm) -{ - LosuObj lib = obj_newunit(vm); - - obj_setunit(vm, lib, obj_newstr(vm, "randseed"), obj_newfunction(vm, ELSAPI_random_randseed)); - obj_setunit(vm, lib, obj_newstr(vm, "random"), obj_newfunction(vm, ELSAPI_random_random)); - obj_setunit(vm, lib, obj_newstr(vm, "randint"), obj_newfunction(vm, ELSAPI_random_randint)); - obj_setunit(vm, lib, obj_newstr(vm, "randfloat"), obj_newfunction(vm, ELSAPI_random_randfloat)); - obj_setunit(vm, lib, obj_newstr(vm, "normal"), obj_newfunction(vm, ELSAPI_random_normal)); - obj_setunit(vm, lib, obj_newstr(vm, "srand"), obj_newfunction(vm, ELSAPI_random_srand)); - obj_setunit(vm, lib, obj_newstr(vm, "randstr"), obj_newfunction(vm, ELSAPI_random_randstr)); - obj_setunit(vm, lib, obj_newstr(vm, "randbytes"), obj_newfunction(vm, ELSAPI_random_randbytes)); - obj_setunit(vm, lib, obj_newstr(vm, "percent"), obj_newfunction(vm, ELSAPI_random_percent)); - - vm_setval(vm, "random", &lib); - vm_dostring(vm, random_script); -} - #endif \ No newline at end of file diff --git a/random/info b/random/info index 8f5ecbea8b9826cf81a7787f922385a6471210c0..ee73ccc08653c840e57b84c6cf47ae1735a3e435 100755 --- a/random/info +++ b/random/info @@ -28,4 +28,4 @@ Ubuntu = "make ; cp ElsLib_random.lsd target/ElsLib_random.lsd_Ubuntu ; make clean", Windows = "make ; cp ElsLib_random.lsd target/ElsLib_random.lsd_Windows ; make clean", } -} \ No newline at end of file +} diff --git a/random/random.c b/random/random.c index 882bff27cf874ab04e72f2cd9a31f2bbf53f0051..142c6c90dfe7c6d2b3781329ef4766f2b82820c9 100755 --- a/random/random.c +++ b/random/random.c @@ -5,10 +5,7 @@ #include #include #include - -#define bool int -#define true 1 -#define false 0 +#include #define PI 3.141592653589793 #define E 2.718281828459045 @@ -19,7 +16,7 @@ uint64_t randseed() uint64_t output = 0; seed = malloc(8); - output += *seed; + output += *(uint64_t *)(void *)seed; output += time(NULL); output += clock(); free(seed); @@ -27,7 +24,7 @@ uint64_t randseed() return output; } -inline uint64_t _randint(uint64_t seed, uint64_t start, uint64_t end) +uint64_t _randint(uint64_t seed, uint64_t start, uint64_t end) { return (_random(seed) * (end - start)) + start; } @@ -44,7 +41,7 @@ double _normal(uint64_t seed, double mu, double sigma) return output * sigma + mu; } -inline uint64_t randint(uint64_t start, uint64_t end) +uint64_t randint(uint64_t start, uint64_t end) { return _randint(rand48(), start, end); } diff --git a/random/random.h b/random/random.h index ecf79a139c027a9a85c8e6761dcd85d66e296e6e..ebf55abc5d245b9137126ee31eff384789cd029e 100755 --- a/random/random.h +++ b/random/random.h @@ -1,3 +1,14 @@ #include "els.h" -void ElsLib_random_libinit(els_VmObj *vm){ -}; + +#include +#include + +uint64_t randseed(); + +inline uint64_t randint(uint64_t start, uint64_t end); + +double randfloat(double start, double end); + +double normal(double mu, double sigma); + +bool percent(double rate);