diff --git a/.gitignore b/.gitignore deleted file mode 100755 index 82940fc823ad3ee0468d6571f24b6d04503bca7c..0000000000000000000000000000000000000000 --- a/.gitignore +++ /dev/null @@ -1,9 +0,0 @@ -.lpkg -.keygen -target/ -/buildenv/ -/.repo/release/ -/.repo/tmp/ -/.repo/.index -/.repo/install.sh -/losu_core/els_version.h \ No newline at end of file diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 02c0ee7a112aafb4026fc3270a44b7d33578d331..0000000000000000000000000000000000000000 --- a/.gitmodules +++ /dev/null @@ -1,4 +0,0 @@ -[submodule "preversion"] - url = https://gitee.com/chen-chaochen/lpk - path = preversion - diff --git a/.img/Q.jpg b/.img/Q.jpg deleted file mode 100755 index 3d3057be62f343bccd7ad2a0c79be8adc5342e8b..0000000000000000000000000000000000000000 Binary files a/.img/Q.jpg and /dev/null differ diff --git a/.img/framework.png b/.img/framework.png deleted file mode 100755 index 39a200c070818de8022028200ce2d13da9c67663..0000000000000000000000000000000000000000 Binary files a/.img/framework.png and /dev/null differ diff --git a/.img/logo.jpg b/.img/logo.jpg deleted file mode 100755 index 9819fab674a12f771e6745707cfdaf5d32bdb3ff..0000000000000000000000000000000000000000 Binary files a/.img/logo.jpg and /dev/null differ diff --git a/.img/losu-w601-class.png b/.img/losu-w601-class.png deleted file mode 100755 index 0e7cf5ef3df00c7cf09f734192005e117fb2ebb3..0000000000000000000000000000000000000000 Binary files a/.img/losu-w601-class.png and /dev/null differ diff --git a/.img/losurepl_example.png b/.img/losurepl_example.png deleted file mode 100755 index 88a35c1409b666fc46d2a2342290c448fd055139..0000000000000000000000000000000000000000 Binary files a/.img/losurepl_example.png and /dev/null differ diff --git a/.repo/.build b/.repo/.build deleted file mode 100755 index 9e54b2b7b41b77623ffe3396b8f0685026434614..0000000000000000000000000000000000000000 --- a/.repo/.build +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh -cd $1 -losu -r lpt confsrc $1 -losu -r lpkg make -losu -r lpkg md5sum -cd .. diff --git a/.repo/.check b/.repo/.check deleted file mode 100755 index 54891a18be84ebed635b3d8792f908cdc4e3c3c2..0000000000000000000000000000000000000000 --- a/.repo/.check +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -cd $1 -md5sum -c .keygen -exit $? \ No newline at end of file diff --git a/.repo/.package b/.repo/.package deleted file mode 100755 index ff451bedcff84cd4beafd061b580dd9763ae560d..0000000000000000000000000000000000000000 --- a/.repo/.package +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/sh -sudo rm .repo/release/* - -# 打包 Ubuntu 发行版 - -sudo rm -rf .repo/tmp/* -sudo cp -r .repo/packscript/Ubuntu/* .repo/tmp/ -sudo mkdir .repo/tmp/lib -sudo mkdir .repo/tmp/bin -sudo mkdir .repo/tmp/els -sudo mkdir .repo/tmp/els/lib - - -sudo chmod 777 .repo/tmp/DEBIAN/control -sudo echo "Version:$(date +%y).$(date +%m).$(date +%d)" >> .repo/tmp/DEBIAN/control -# sudo echo "Version:$(date +%y).$(date +%m).$(expr $(expr $(date +%d) % 7) - 1)" >> .repo/tmp/DEBIAN/control - - -sudo cp losu/target/losu_Ubuntu .repo/tmp/bin/losu -sudo cp losu_core/target/libeasylosu.so_Ubuntu .repo/tmp/lib/libeasylosu.so - -sudo cp std/target/ElsLib_std.lsd_Ubuntu .repo/tmp/els/lib/ElsLib_std.lsd -sudo cp stdbyte/target/ElsLib_stdbyte.lsd_Ubuntu .repo/tmp/els/lib/ElsLib_stdbyte.lsd -sudo cp stdfile/target/ElsLib_stdfile.lsd_Ubuntu .repo/tmp/els/lib/ElsLib_stdfile.lsd -sudo cp stdlib/target/ElsLib_stdlib.lsd_Ubuntu .repo/tmp/els/lib/ElsLib_stdlib.lsd -sudo cp stdmath/target/ElsLib_stdmath.lsd_Ubuntu .repo/tmp/els/lib/ElsLib_stdmath.lsd -sudo cp stdstring/target/ElsLib_stdstring.lsd_Ubuntu .repo/tmp/els/lib/ElsLib_stdstring.lsd -sudo cp stdsys/target/ElsLib_stdsys.lsd_Ubuntu .repo/tmp/els/lib/ElsLib_stdsys.lsd -sudo cp stdthread/target/ElsLib_stdthread.lsd_Ubuntu .repo/tmp/els/lib/ElsLib_stdthread.lsd -sudo cp stdtime/target/ElsLib_stdtime.lsd_Ubuntu .repo/tmp/els/lib/ElsLib_stdtime.lsd -sudo cp stdvm/target/ElsLib_stdvm.lsd_Ubuntu .repo/tmp/els/lib/ElsLib_stdvm.lsd -# sudo cp lsrepo/target/ElsLib_lsrepo.lsd_Ubuntu .repo/tmp/els/lib/ElsLib_lsrepo.lsd -# sudo cp lpkg/target/ElsLib_lpkg.lsd_Ubuntu .repo/tmp/els/lib/ElsLib_lpkg.lsd -sudo cp lpt/target/ElsLib_lpt.lsd_Ubuntu .repo/tmp/els/lib/ElsLib_lpt.lsd - - -sudo chmod 755 -R .repo/tmp -sudo dpkg -b .repo/tmp .repo/release/losu_Ubuntu.deb -sudo rm -rf .repo/tmp/* - - - - - - -# 打包 Windows 发行版 - -sudo rm -rf .repo/tmp/* -sudo cp -r .repo/packscript/Windows/* .repo/tmp/ -sudo mkdir .repo/tmp/lib - -sudo cp losu/target/losu.exe .repo/tmp/losu.exe -sudo cp losu_core/target/libeasylosu.dll .repo/tmp/libeasylosu.dll - -sudo cp std/target/ElsLib_std.lsd_Windows .repo/tmp/lib/ElsLib_std.lsd -sudo cp stdbyte/target/ElsLib_stdbyte.lsd_Windows .repo/tmp/lib/ElsLib_stdbyte.lsd -sudo cp stdfile/target/ElsLib_stdfile.lsd_Windows .repo/tmp/lib/ElsLib_stdfile.lsd -sudo cp stdlib/target/ElsLib_stdlib.lsd_Windows .repo/tmp/lib/ElsLib_stdlib.lsd -sudo cp stdmath/target/ElsLib_stdmath.lsd_Windows .repo/tmp/lib/ElsLib_stdmath.lsd -sudo cp stdstring/target/ElsLib_stdstring.lsd_Windows .repo/tmp/lib/ElsLib_stdstring.lsd -sudo cp stdsys/target/ElsLib_stdsys.lsd_Windows .repo/tmp/lib/ElsLib_stdsys.lsd -sudo cp stdthread/target/ElsLib_stdthread.lsd_Windows .repo/tmp/lib/ElsLib_stdthread.lsd -sudo cp stdtime/target/ElsLib_stdtime.lsd_Windows .repo/tmp/lib/ElsLib_stdtime.lsd -sudo cp stdvm/target/ElsLib_stdvm.lsd_Windows .repo/tmp/lib/ElsLib_stdvm.lsd -# sudo cp lsrepo/target/ElsLib_lsrepo.lsd_Windows .repo/tmp/lib/ElsLib_lsrepo.lsd -# sudo cp lpkg/target/ElsLib_lpkg.lsd_Windows .repo/tmp/lib/ElsLib_lpkg.lsd -sudo cp lpt/target/ElsLib_lpt.lsd_Windows .repo/tmp/lib/ElsLib_lpt.lsd - -sudo chmod 0755 -R .repo/tmp -cd .repo/tmp/ -zip -r ../../.repo/release/losu_Windows.zip * -cd ../../ - -sudo rm -rf .repo/tmp/* - - diff --git a/.repo/.repo b/.repo/.repo deleted file mode 100755 index 750fd2a0cd8c6b4469ac25de39600967fef486f5..0000000000000000000000000000000000000000 --- a/.repo/.repo +++ /dev/null @@ -1,25 +0,0 @@ -base64 -binary -document -hash -losu -losu_core -lpkg -lpt -lsmath -lsnput -lsrepo -lssys -owls -random -socket -std -stdbyte -stdfile -stdlib -stdmath -stdstring -stdsys -stdthread -stdtime -stdvm diff --git a/.repo/.update b/.repo/.update deleted file mode 100755 index 30576801e9ee56f3a58fc6ee6afa25597649346a..0000000000000000000000000000000000000000 --- a/.repo/.update +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -git pull origin master -git submodule init -git submodule update diff --git a/.repo/packscript/Ubuntu/DEBIAN/control b/.repo/packscript/Ubuntu/DEBIAN/control deleted file mode 100755 index 046924cb77d1e5e8ec537df4f87b51540f7e8933..0000000000000000000000000000000000000000 --- a/.repo/packscript/Ubuntu/DEBIAN/control +++ /dev/null @@ -1,6 +0,0 @@ -Package: tech.losu -Maintainer: chen-chaochen -Depends: rlwrap -Architecture: amd64 -Priority: optional -Description: 洛书编程语言 Ubuntu 发行版 diff --git a/.repo/packscript/Ubuntu/els/help b/.repo/packscript/Ubuntu/els/help deleted file mode 100755 index f556a482bb0c9a077d1691e4a230996fc62339c4..0000000000000000000000000000000000000000 --- a/.repo/packscript/Ubuntu/els/help +++ /dev/null @@ -1,24 +0,0 @@ -LPT · Losu Packages Tool —— 模块管理工具 -洛书模块管理工具,是一款轻量高效的跨平台模块管理器,支持模块的下载,安装,查找,升级,卸载,更新,接口胶水生成等多种功能 - -运行方法 - -losu -r lpt [参数列表] - - -lpt help # 查看帮助文档 -lpt update # 下载远程列表,检测更新 -lpt upgrade # 自动化更新 -lpt list # 列举已安装的模块 - -lpt install [模块名] # 安装模块 -lpt remove [模块名] # 卸载模块 -lpt autoremove # 卸载所有被废弃的模块 - -lpt search [关键字] # 查找并列举所有相关的模块 -lpt show [模块] # 显示模块的详细信息 -lpt wiki [模块] # 下载模块的readme文件 - -lpt source [模块] [可选/分支] # 拉取模块源代码 -lpt confsrc [文件] # 根据脚本文件生成 C/C++ 接口 -lpt confpro [文件] # 根据工程文件批量生成 C/C++ 接口 diff --git a/.repo/packscript/Ubuntu/els/lpt.conf b/.repo/packscript/Ubuntu/els/lpt.conf deleted file mode 100755 index 29c7feb48407913fa6792c52b3081d3390652081..0000000000000000000000000000000000000000 --- a/.repo/packscript/Ubuntu/els/lpt.conf +++ /dev/null @@ -1 +0,0 @@ -https://losu.tech/archive/lasted/ Ubuntu \ No newline at end of file diff --git a/.repo/packscript/Windows/help b/.repo/packscript/Windows/help deleted file mode 100755 index f556a482bb0c9a077d1691e4a230996fc62339c4..0000000000000000000000000000000000000000 --- a/.repo/packscript/Windows/help +++ /dev/null @@ -1,24 +0,0 @@ -LPT · Losu Packages Tool —— 模块管理工具 -洛书模块管理工具,是一款轻量高效的跨平台模块管理器,支持模块的下载,安装,查找,升级,卸载,更新,接口胶水生成等多种功能 - -运行方法 - -losu -r lpt [参数列表] - - -lpt help # 查看帮助文档 -lpt update # 下载远程列表,检测更新 -lpt upgrade # 自动化更新 -lpt list # 列举已安装的模块 - -lpt install [模块名] # 安装模块 -lpt remove [模块名] # 卸载模块 -lpt autoremove # 卸载所有被废弃的模块 - -lpt search [关键字] # 查找并列举所有相关的模块 -lpt show [模块] # 显示模块的详细信息 -lpt wiki [模块] # 下载模块的readme文件 - -lpt source [模块] [可选/分支] # 拉取模块源代码 -lpt confsrc [文件] # 根据脚本文件生成 C/C++ 接口 -lpt confpro [文件] # 根据工程文件批量生成 C/C++ 接口 diff --git a/.repo/packscript/Windows/install.bat b/.repo/packscript/Windows/install.bat deleted file mode 100755 index cc14f2ec14899d270e2f2e24a61782f7a4b1aef1..0000000000000000000000000000000000000000 --- a/.repo/packscript/Windows/install.bat +++ /dev/null @@ -1,4 +0,0 @@ -echo "Start Set Env,Please MAKE SURE at Administer" -setx /m "PATH" "%PATH%;%~dp0;" -setx /m "LPTROOT" %~dp0 -pause \ No newline at end of file diff --git a/.repo/packscript/Windows/lpt.conf b/.repo/packscript/Windows/lpt.conf deleted file mode 100755 index febfd53e4474768a3ee50acba84b81eaf6a1c0f3..0000000000000000000000000000000000000000 --- a/.repo/packscript/Windows/lpt.conf +++ /dev/null @@ -1 +0,0 @@ -https://losu.tech/archive/lasted/ Windows \ No newline at end of file diff --git a/.repo/upscript/lsupdate.bat b/.repo/upscript/lsupdate.bat deleted file mode 100755 index cbb49caf8cc7b9dbcf8777088a42fffb51cb5164..0000000000000000000000000000000000000000 --- a/.repo/upscript/lsupdate.bat +++ /dev/null @@ -1,11 +0,0 @@ -@echo off -echo "ʼظ°" -curl -o %LPTROOT%tmp.zip https://losu.tech/archive/lasted/.repo/release/losu_Windows.zip - -echo "ʼ" - -7z x -y -r "%LPTROOT%tmp.zip" -o"%LPTROOT%" - -del "%LPTROOT%tmp.zip" -echo "" -del "%LPTROOT%lsupdate.bat" diff --git a/.repo/upscript/lsupdate_Ubuntu b/.repo/upscript/lsupdate_Ubuntu deleted file mode 100755 index 80510ecb25d556a61b73f21b212bb1a0b586648c..0000000000000000000000000000000000000000 --- a/.repo/upscript/lsupdate_Ubuntu +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -echo "开始下载更新包" -wget --no-check-certificate -q --show-progress https://losu.tech/archive/lasted/.repo/release/losu_Ubuntu.deb -O /tmp/losu_tmp.deb -# wget --no-check-certificate -q --show-progress http://127.0.0.1:8000/.repo/release/losu_Ubuntu.deb -O /tmp/losu_tmp.deb -echo "开始安装......" -sudo dpkg -i /tmp/losu_tmp.deb -sudo rm /tmp/losu_tmp.deb -sudo rm /bin/lsupdate -echo "完成" diff --git a/COPYRIGHT b/COPYRIGHT new file mode 100755 index 0000000000000000000000000000000000000000..da094f27d259bbdd3919952c41f28fce1bfac854 --- /dev/null +++ b/COPYRIGHT @@ -0,0 +1,37 @@ + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. diff --git a/LICENSE b/LICENSE index 7eaa3ada010f557a1ce202ced2fc237bae76a367..41b4934e7f5e2132da7ac0a9f53ae4ad5ce8bc51 100755 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020-2024 chen-chaochen +Copyright (c) 2020-now chen-chaochen Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.MD b/README.MD new file mode 100755 index 0000000000000000000000000000000000000000..ff27a35909b9c4a55df6dcacd2e27b5538192c54 --- /dev/null +++ b/README.MD @@ -0,0 +1,66 @@ +#!/bin/wiki.losu.tech +# Readme of Losu-Language + +## Losu Language + +Losu is a programming language that is designed to be easy to learn and use. It is a simple language that has a small number of keywords and a straightforward syntax. Losu is also designed to be portable, so it can be run on any platform that has a compatible interpreter. + +Losu is a simple language that has a small number of keywords and a straightforward syntax. It is designed to be easy to learn and use, and it is also designed to be portable, so it can be run on any platform that has a compatible interpreter. + +``` +/ +|- doc +|- include +|- core +|- losuh +|- losuc +|- lpkg +|- package + |- +``` + ++ xmake ++ cmake -> make -> build + +```python +lpkg.project{ + name: "", + object: "", +} + +``` + +```sh +make install +make config + lpkg +make +``` + +## use lpkg to manage your project and run file with the extension of .els + +```sh +# build the environment +make + +# creat a new directory to manage your package +mkdir package + +# lpkg must run in the package directory +cd package + +# write your code in losu +vim main.els + +# config the package +lpkg config + +# make the package +lpkg make + +# run your file +./your-executable-file + +# clean your package +lpkg clean +``` \ No newline at end of file diff --git a/base64/Ubuntu/makefile b/base64/Ubuntu/makefile deleted file mode 100755 index a3b25e493be0b522c18b5141ac661e1ea2394b39..0000000000000000000000000000000000000000 --- a/base64/Ubuntu/makefile +++ /dev/null @@ -1,13 +0,0 @@ -OBJS = base.o base64.o -CFLAGS= -O3 -std=c99 -Wall -DLOSU_LINUX -I ../buildenv -fPIC -CC=x86_64-linux-gnu-gcc -T=./ElsLib_base64.lsd - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -shared -lm -s - -clean: - rm -rf $T $(OBJS) core core.* \ No newline at end of file diff --git a/base64/Windows/makefile b/base64/Windows/makefile deleted file mode 100755 index 2fc72255aa69cb2e4729eb53012d78569f20e71e..0000000000000000000000000000000000000000 --- a/base64/Windows/makefile +++ /dev/null @@ -1,17 +0,0 @@ -BASE = base.o -MAIN = base64.o -OBJS = $(BASE) $(MAIN) -CFLAGS= -O3 -std=c99 -Wall -DLOSU_WINDOWS -I ../buildenv -fPIC -CC=x86_64-w64-mingw32-gcc -T=ElsLib_base64.lsd - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -lm -static -shared -s -L ../buildenv -l:libeasylosu.dll - -clean: - rm -rf $T - rm -rf $(BASE) - rm -rf $(MAIN) \ No newline at end of file diff --git a/base64/base.c b/base64/base.c deleted file mode 100755 index c3e5c65c5d2aac0d94c82e36382c543658f6b397..0000000000000000000000000000000000000000 --- a/base64/base.c +++ /dev/null @@ -1,116 +0,0 @@ -#include "base.h" - -int _decode(uint8_t x) -{ - /* - 该函数用于从编码表(LOSU_BASE64_CODE_TABLE)中查找对应字符的序号 - 在Base64Decode函数中,这大概率是性能制约部分 - 如需优化,可考虑使用二叉查找树进行优化 - */ - for (int i=0; i> 2); //第一个byte的前6bit - buffer[j+1] = _encode(((content[i] & 0x3) << 4) + ((content[i+1] & 0xf0) >> 4)); //第一个字节的后2bit和第二个字节的前4bit - buffer[j+2] = _encode(((content[i+1] & 0xf) << 2) + ((content[i+2] & 0xc0) >> 6)); //第二个字节的后4bit和第三个字节的前2bit - buffer[j+3] = _encode(content[i+2] & 0x3f); //第三个字节的后6bit - } - - //填充 - switch (left) - { - case 0: - { - //长度正好时 - *((char*)&buffer[j]) = '\0'; - break; - } - case 1: - { - //剩余一个字节 - buffer[j] = _encode((content[i] & 0xfc) >> 2); //第一个byte的前6bit - buffer[j+1] = _encode((content[i] & 0x3) << 4); //第一个字节的后2bit和第二个字节的前4bit - //填充 - buffer[j+2] = LOSU_BASE64_CODE_PADDING; - buffer[j+3] = LOSU_BASE64_CODE_PADDING; - *((char*)&buffer[j+4]) = '\0'; - break; - } - case 2: - { - //剩余两个字节 - buffer[j] = _encode((content[i] & 0xfc) >> 2); //第一个byte的前6bit - buffer[j+1] = _encode(((content[i] & 0x3) << 4) + ((content[i+1] & 0xf0) >> 4)); //第一个字节的后2bit和第二个字节的前4bit - buffer[j+2] = _encode((content[i+1] & 0xf) << 2); //第二个字节的后4bit - //填充 - buffer[j+3] = LOSU_BASE64_CODE_PADDING; - *((char*)&buffer[j+4]) = '\0'; - break; - } - } - - return buffer; //记得free!!!!!! -} - -uint8_t *Base64Decode(uint8_t *content, int length) -{ - //创建缓冲区 - int buffersize = (length / 4) * 3; - uint8_t *buffer = malloc(buffersize+sizeof(char)); - memset(buffer, 0, buffersize+sizeof(char)); - - //计算填充字符个数 - int left = 0; - if (content[length-1]==LOSU_BASE64_CODE_PADDING) - left++; - if (content[length-2]==LOSU_BASE64_CODE_PADDING) - left++; - - //解码 - int i, j, i_max; - i_max = left == 0 ? length : length - 4; - for (i=j=0; i> 4); //第一个byte的后6bit和第二个byte的第3到第4bit - buffer[j+1] = ((_decode(content[i+1]) & 0xf) << 4) + ((_decode(content[i+2]) & 0x3c) >> 2); //第二个byte的第5到第8bit和第三个byte的第3到第6bit - buffer[j+2] = ((_decode(content[i+2]) & 0x3) << 6) + ((_decode(content[i+3]) & 0x3f)); //第三个byte的第7到第8个bit和第四个byte的第3到第8bit - } - - //处理填充的区块 - switch (left) - { - case 0: - { - *((char*)&buffer[j]) = '\0'; - break; - } - case 1: - { - buffer[j] = ((_decode(content[i]) & 0x3f) << 2) + ((_decode(content[i+1]) & 0x30) >> 4); //第一个byte的后6bit和第二个byte的第3到第4bit - buffer[j+1] = ((_decode(content[i+1]) & 0xf) << 4) + ((_decode(content[i+2]) & 0x3c) >> 2); //第二个byte的第5到第8bit和第三个byte的第3到第6bit - *((char*)&buffer[j+2]) = '\0'; - } - case 2: - { - buffer[j] = ((_decode(content[i]) & 0x3f) << 2) + ((_decode(content[i+1]) & 0x30) >> 4); //第一个byte的后6bit和第二个byte的第3到第4bit - buffer[j+1] = ((_decode(content[i+1]) & 0xf) << 4); //第二个byte的第5到第8bit - break; - } - } - - return buffer; -} \ No newline at end of file diff --git a/base64/base.h b/base64/base.h deleted file mode 100755 index 9c7946ab430f0f3672d3b12baffb4b2e5943b2c5..0000000000000000000000000000000000000000 --- a/base64/base.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef LOSU_BASE_H__ -#define LOSU_BASE_H__ - -#define LOSU_BASE64_CODE_TABLE "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" -#define LOSU_BASE64_CODE_PADDING (uint8_t)'=' - -#include -#include -#include -#include - - -#define _encode(x) ((unsigned char*)LOSU_BASE64_CODE_TABLE)[(uint8_t)x] - -int _decode(uint8_t x); - -uint8_t *Base64Encode(uint8_t *content, int length); -uint8_t *Base64Decode(uint8_t *content, int length); - -#endif \ No newline at end of file diff --git a/base64/base64.c b/base64/base64.c deleted file mode 100755 index 55a8c99ac7551cf88985d671c3a38d70fa5f4116..0000000000000000000000000000000000000000 --- a/base64/base64.c +++ /dev/null @@ -1,63 +0,0 @@ -#include "base64.h" -#include "base.h" - -#include - -/* - base64维护须知: - 底层函数原型如下 - - uint8_t *Base64Encode(uint8_t *content, int length); - uint8_t *Base64Encode(uint8_t *content, int length); - - 1. 这两个函数的content参数都是要编码或解码的文本,为避免编译器警告,可以强制转换为(void)型指针来传递const char*类型的指针 - length参数则是content的字节数,注意是字节数! - 2. 两个函数的返回值均使用stdlib中的malloc来动态分配内存,一定要记得free!!!!!! -*/ - -int ELSAPI_base64_capi_b64encode(els_VmObj* vm) -{ - const char *content; - if (arg_gettype(vm, 1)==ELS_API_TYPE_STRING || arg_gettype(vm, 1)==ELS_API_TYPE_NUMBER) - { - content = arg_getstr(vm, 1); - void *result = Base64Encode((void*)content, sizeof(char)*strlen(content)); - arg_returnstr(vm, result); - free(result); - } - else - arg_returnnull(vm); - return 1; -} - -int ELSAPI_base64_capi_b64decode(els_VmObj* vm) -{ - const char *content; - if (arg_gettype(vm, 1)==ELS_API_TYPE_STRING || arg_gettype(vm, 1)==ELS_API_TYPE_NUMBER) - { - content = arg_getstr(vm, 1); - void *result = Base64Decode((void*)content, sizeof(char)*strlen(content)); - arg_returnstr(vm, result); - free(result); - } - else - arg_returnnull(vm); - return 1; -} - -int ELSAPI_base64_capi_b64encodep(els_VmObj* vm) // capi_b64encodep(p:ptr, len:int) -{ - void *ptr; - uint64_t len; - if (arg_gettype(vm, 1)==ELS_API_TYPE_PTR || arg_gettype(vm, 1)==ELS_API_TYPE_NUMBER) - { - ptr = arg_getptr(vm, 1); - len = arg_getnum(vm, 2); - void *result = Base64Encode(ptr, len); - arg_returnstr(vm, result); - free(result); - } - else - arg_returnnull(vm); - return 1; -} diff --git a/base64/base64.els b/base64/base64.els deleted file mode 100755 index e33bd66088d5a9eb5936e42efdc0f0c8c4c6c186..0000000000000000000000000000000000000000 --- a/base64/base64.els +++ /dev/null @@ -1,31 +0,0 @@ -#!declare -capi_b64encode(s:str) -capi_b64decode(s:str) -capi_b64encodep(p:ptr, len:int) - -#!end - -#!script -import("stdlib") - -base64 = { - -} - -def base64.encode(s): - rt capi_b64encode(s) -; - -def base64.decode(s): - rt capi_b64decode(s) -; - -def base64.encodep(p, len): - rt capi_b64encodep(p, len) -; - -base64.编码 = base64.encode -base64.解码 = base64.decodep -base64.编码指针 = base64.encodep - -#!end \ No newline at end of file diff --git a/base64/base64.h b/base64/base64.h deleted file mode 100755 index 6b8b70968535f8af1505398a330a78570edabab5..0000000000000000000000000000000000000000 --- a/base64/base64.h +++ /dev/null @@ -1,38 +0,0 @@ -#include "els.h" -int ELSAPI_base64_capi_b64encode(els_VmObj* vm); // capi_b64encode(s:str) -int ELSAPI_base64_capi_b64decode(els_VmObj* vm); // capi_b64decode(s:str) -int ELSAPI_base64_capi_b64encodep(els_VmObj* vm); // capi_b64encodep(p:ptr, len:int) -#ifdef ELS_CONF_TOKEN_EN -static const char LibScript[]={ -105,109,112,111,114,116,40,34,115,116,100,108,105,98,34,41,10, -10, -98,97,115,101,54,52,32,61,32,123,10, -10, -125,10, -10, -100,101,102,32,98,97,115,101,54,52,46,101,110,99,111,100,101,40,115,41,58,10, -32,32,32,32,114,116,32,99,97,112,105,95,98,54,52,101,110,99,111,100,101,40,115,41,10, -59,10, -10, -100,101,102,32,98,97,115,101,54,52,46,100,101,99,111,100,101,40,115,41,58,10, -32,32,32,32,114,116,32,99,97,112,105,95,98,54,52,100,101,99,111,100,101,40,115,41,10, -59,10, -10, -100,101,102,32,98,97,115,101,54,52,46,101,110,99,111,100,101,112,40,112,44,32,108,101,110,41,58,10, -32,32,32,32,114,116,32,99,97,112,105,95,98,54,52,101,110,99,111,100,101,112,40,112,44,32,108,101,110,41,10, -59,10, -10, -98,97,115,101,54,52,46,-25,-68,-106,-25,-96,-127,32,61,32,98,97,115,101,54,52,46,101,110,99,111,100,101,10, -98,97,115,101,54,52,46,-24,-89,-93,-25,-96,-127,32,61,32,98,97,115,101,54,52,46,100,101,99,111,100,101,112,10, -98,97,115,101,54,52,46,-25,-68,-106,-25,-96,-127,-26,-116,-121,-23,-110,-120,32,61,32,98,97,115,101,54,52,46,101,110,99,111,100,101,112,10, -10, -0}; -#endif -void ElsLib_base64_libinit(els_VmObj *vm){ - vm_register(vm,"capi_b64encode",ELSAPI_base64_capi_b64encode); - vm_register(vm,"capi_b64encodep",ELSAPI_base64_capi_b64encodep); - vm_register(vm,"capi_b64decode",ELSAPI_base64_capi_b64decode); - #ifdef ELS_CONF_TOKEN_EN - vm_dostring(vm,LibScript); - #endif -}; diff --git a/base64/info b/base64/info deleted file mode 100755 index 0b5551fd205e4b90af5415b556da42ad2f204268..0000000000000000000000000000000000000000 --- a/base64/info +++ /dev/null @@ -1,23 +0,0 @@ -{ - info = { - name = "base64/base64编解码模块", - text = "base64编解码模块", - version = "23.9.1", - }, - source = { - all = { - "base64.els", - "base64.h", - "base64.c", - "base.c", - "base.h", - "readme.md", - }, - Ubuntu = {"makefile"}, - Windows = {"makefile"}, - }, - target = { - Ubuntu = "make ; cp ElsLib_base64.lsd target/ElsLib_base64.lsd_Ubuntu ; make clean", - Windows = "make ; cp ElsLib_base64.lsd target/ElsLib_base64.lsd_Windows ; make clean", - } -} \ No newline at end of file diff --git a/base64/readme.md b/base64/readme.md deleted file mode 100755 index 205a6031b232dd36ef4787c965937616a81a8d0f..0000000000000000000000000000000000000000 --- a/base64/readme.md +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/owls.wiki.losu.tech -# wiki for base64 - -# 简介 -这是一个用于base64编解码的模块,不依赖任何第三方文件,可以用于任何实现了c99标准的平台。 - -# 函数 -## base64.encode(s:str)->str -### 参数 -1. s 要进行编码的字符串 -### 返回值 -1. 当s的类型为字符串或数字时,返回对应的base64编码。数字将转化为字符串处理。 -2. 当s的类型不正确时,返回null - -## base64.decode(s:str)->str -### 参数 -1. s 要进行解码的字符串 -### 返回值 -1. 当s的类型为字符串或数字时,返回对应的解码字符串。数字将转化为字符串处理。 -2. 当s的类型不正确时,返回null - diff --git a/binary/Ubuntu/makefile b/binary/Ubuntu/makefile deleted file mode 100755 index 29e26a88e11533c5db4ccd2c7c9e3094cb59c9fa..0000000000000000000000000000000000000000 --- a/binary/Ubuntu/makefile +++ /dev/null @@ -1,13 +0,0 @@ -OBJS = binary.o losubinary.o -CFLAGS= -O3 -std=c99 -Wall -DLOSU_LINUX -I ../buildenv -fPIC -CC=x86_64-linux-gnu-gcc -T=./ElsLib_binary.lsd - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -shared -lm -s -lc - -clean: - rm -rf $T $(OBJS) core core.* \ No newline at end of file diff --git a/binary/Windows/makefile b/binary/Windows/makefile deleted file mode 100755 index a6b1b678a6291cc1b4793d59ba91ea4e1cefa9cf..0000000000000000000000000000000000000000 --- a/binary/Windows/makefile +++ /dev/null @@ -1,17 +0,0 @@ -BASE = losubinary.o -MAIN = binary.o -OBJS = $(BASE) $(MAIN) -CFLAGS= -O3 -std=c99 -Wall -DLOSU_WINDOWS -I ../buildenv -fPIC -CC=x86_64-w64-mingw32-gcc -T=ElsLib_binary.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) diff --git a/binary/binary.c b/binary/binary.c deleted file mode 100755 index 47450725b1db3b83be682a3f7508f0a78e299e93..0000000000000000000000000000000000000000 --- a/binary/binary.c +++ /dev/null @@ -1,895 +0,0 @@ -#include "binary.h" -#include "losubinary.h" - -#include - -#ifdef LOSU_WINDOWS - -static void __print(const char *s) -{ - /* - 为Windows设计 - 会进行utf8到gbk的编码转化 - */ - char *tmp = vm_win_togbk(s); - printf("%s", tmp); - free(tmp); -} - -#else -#ifdef LOSU_LINUX - -static inline void __print(const char *s) -{ - /* - 为Linux设计 - 会进行utf8到gbk的编码转化 - */ - - printf("%s", s); -} - -#endif -#endif - -int ELSAPI_binary_binary_create(els_VmObj* vm) -{ - /* - 创建一块二进制内存储存区 - - # 参数 - 1. size:int 要创建的储存区的大小 - - # 返回值 - 1. 返回创建的储存区的指针 - */ - - uint64_t size = arg_getnum(vm, 1); - - arg_returnptr(vm, (void *)barray_create(size)); - return 1; -} - -int ELSAPI_binary_binary_free(els_VmObj* vm) -{ - /* - 释放为储存区分配的内存 - - # 参数 - 1. p:ptr 储存区的指针 - - #返回值 - 无 - */ - - barray *array = (void*)arg_getptr(vm, 1); - - barray_free(array); - return 1; -} - -int ELSAPI_binary_binary_writef(els_VmObj* vm) -{ - /* - 将二进制储存区的数据写入指定的文件中 - - # 参数 - 1. p:ptr 二进制储存区的指针 - 2. fname:str 要写入的文件的名称 - 3. len:int 要写入的字节数,缺省时为储存的数据的大小 - - # 返回值 - 1. 写入的实际字节数 - */ - - barray *a = (void*)arg_getptr(vm, 1); - const char *fname = arg_getstr(vm, 2); - uint64_t len; - FILE *fp = fopen(fname, "wb"); - - if (fp == NULL) - { - arg_returnnull(vm); - return 1; - } - - if (arg_gettype(vm, 3) == ELS_API_TYPE_NUMBER) - len = arg_getnum(vm, 3); - else - len = a->length; - - if (len >= a->length) - len = a->length; - - fseek(fp, 0, SEEK_SET); - fwrite(a->val, 1, len, fp); - - fclose(fp); - arg_returnnum(vm, len); - - return 1; -} - -int ELSAPI_binary_binary_writem(els_VmObj* vm) -{ - /* - 将储存区的数据以指定字节数写入内存中 - - # 参数 - 1. p:ptr 储存区的指针 - 2. m:ptr 要写入的内存的指针 - 3. len:int 要写入的字节数 - - # 返回值 - 1. 写入的实际字节数 - 2. 当len<0时,返回null - */ - barray *a = (void*)arg_getptr(vm, 1); - uint8_t *p = (void*)arg_getptr(vm, 2); - uint64_t len = arg_getnum(vm, 3); - - if (len >= a->length) - len = a->length; - - else if (len < 0) - { - arg_returnnull(vm); - return 1; - } - - for (uint64_t i = 0; i < len; i++) - p[i] = a->val[i]; - - arg_returnnum(vm, len); - - return 1; -} - -int ELSAPI_binary_binary_readf(els_VmObj* vm) -{ - /* - 从文件中读取指定字节数 - 原本的数据会被释放 - - # 参数 - 1. p:ptr 储存区指针 - 2. fname:str 要读取的文件名 - 3. len:int 要读取的字节数 - - 当len缺省时,会被设置为文件大小 - - # 返回值 - 1. 新的储存区的指针 - 2. 当打开文件失败时返回null - */ - barray *a = (void*)arg_getptr(vm, 1); - const char *fname = arg_getstr(vm, 2); - uint64_t len; - FILE *fp = fopen(fname, "rb"); - uint64_t flen; - - if (fp == NULL) - { - arg_returnnull(vm); - return 1; - } - - fseek(fp, 0, SEEK_END); - flen = ftell(fp); - - if (arg_gettype(vm, 3) == ELS_API_TYPE_NUMBER) - len = (len = arg_getnum(vm, 3)) <= 0 ? flen : len; - else - len = flen; - - if (flen < len) - len = flen; - - free(a->val); - a->val = malloc(len); - - fseek(fp, 0, SEEK_SET); - fread(a->val, 1, len, fp); - - fclose(fp); - a->length = len; - arg_returnptr(vm, (void*)a); - return 1; -} - -int ELSAPI_binary_binary_readm(els_VmObj* vm) -{ - /* - 从内存中读取指定字节的数据 - - # 参数 - 1. p:ptr 储存区的指针 - 2. m:ptr 要读取的内存的指针 - 3. len:int 要读取的字节数 - - # 返回值 - 1. 新的储存区的指针 - 2. 当len的值<=0、m为0或NULL时,返回null - */ - barray *a = (void*)arg_getptr(vm, 1); - uint8_t *p = (void*)arg_getptr(vm, 2); - uint64_t len = arg_getnum(vm, 3); - - if (len <= 0 || p == 0 || p == NULL) - { - arg_returnnull(vm); - return 1; - } - - if (!(len==a->length)) - a = barray_change(a, len); - - for (uint64_t i = 0; i < len; i++) - a->val[i] = p[i]; - - arg_returnptr(vm, (void*)a); - - return 1; -} - -int ELSAPI_binary_binary_get(els_VmObj* vm) -{ - /* - 从储存区的指定位置读取指定个数的字节 - - # 参数 - 1. p:ptr 储存区指针 - 2. i:int 索引 - 3. size:int 读取的字节个数 - - # 返回值 - 1. 读取的字节值 - 2. 当索引越界时,返回null - */ - barray *a = (void*)arg_getptr(vm, 1); - uint64_t index = arg_getnum(vm, 2); - uint64_t size = arg_getnum(vm, 3); - uint64_t output = 0; - uint64_t alen = a->length; - - if (index <0 || index + size > alen) - arg_returnnull(vm); - else - { - memcpy(&output, a->val + index, size); - arg_returnnum(vm, output); - } - - return 1; -} - -int ELSAPI_binary_binary_insert(els_VmObj* vm) -{ - /* - 向储存区的指定位置插入指定个数的字节 - 会替换掉原本的字节 - - # 参数 - 1. p:ptr 储存区的指针 - 2. i:int 索引 - 3. d:要插入的数据 - 4. size:int 要写入的数据的大小,单位为字节 - - # 返回值 - 1. 实际插入的数据 - */ - barray *a = (void*)arg_getptr(vm, 1); - uint64_t index = arg_getnum(vm, 2); - uint64_t n = arg_getnum(vm, 3); - uint8_t size = arg_getnum(vm, 4); - uint64_t alen = a->length; - - if (index <0 || index + size > alen) - arg_returnnull(vm); - else - { - memcpy(a->val + index, &n, size); - arg_returnnum(vm, n); - } - - return 1; -} - -int ELSAPI_binary_binary_insertp(els_VmObj* vm) -{ - /* - 向储存区的指定位置插入指定个数的字节 - 会替换掉原本的字节 - - # 参数 - 1. a:ptr 储存区的指针 - 2. i:int 索引 - 3. p:要插入的数据 - 4. size:int 要写入的数据的大小,单位为字节 - - # 返回值 - 1. 实际插入的数据 - */ - barray *a = (void*)arg_getptr(vm, 1); - uint64_t index = arg_getnum(vm, 2); - void *p = arg_getptr(vm, 3); - uint64_t size = arg_getnum(vm, 4); - uint64_t alen = a->length; - - if (index <0 || index + size > alen) - arg_returnnull(vm); - else - { - memcpy(a->val + index, p, size); - arg_returnptr(vm, p); - } - - return 1; -} - -int ELSAPI_binary_binary_cat(els_VmObj* vm) -{ - /* - 将b附加到a尾 - 这会改变a的值,不会改变b的值 - - # 参数 - 1. a:ptr 被附加的储存区指针 - 2. b:ptr 用于附加的储存区指针 - - # 返回值 - 1. 返回a的新指针值 - */ - barray *a = (void*)arg_getptr(vm, 1); - barray *b = (void*)arg_getptr(vm, 2); - barray *n = barray_create(a->length + b->length); - - memcpy(n->val, a->val, a->length); - memcpy(n->val + a->length, b->val, b->length); - barray_free(a); - - arg_returnptr(vm, (void*)n); - return 1; -} - -int ELSAPI_binary_binary_replace(els_VmObj* vm) -{ - /* - 将b中的数据从start处开始赋盖a中的数据,会覆盖len个字节 - 覆盖到a的结尾处后会停止覆盖 - - # 参数 - 1. a:ptr 被覆盖的储存区指针 - 2. b:ptr 用于覆盖的储存区指针 - 3. start 覆盖的起始位置 - 4. len 覆盖的字节数 - - # 返回值 - 1. 返回a的新指针值 - */ - barray *a = (void*)arg_getptr(vm, 1); - barray *b = (void*)arg_getptr(vm, 2); - uint64_t start = arg_getnum(vm, 3); - uint64_t len = arg_getnum(vm, 4); - - if (start < 0 || start > a->length || len <= 0) - { - arg_returnptr(vm, (void* )a); - return 1; - } - - if (start + len > a->length) - len = a->length - start; - - memcpy(a->val + start, b->val, len); - arg_returnptr(vm, (void*)a); - return 1; -} - -int ELSAPI_binary_binary_length(els_VmObj* vm) -{ - /* - 返回储存区的大小 - - # 参数 - 无 - - # 返回值 - 1. 储存区的大小 - */ - barray * a = (void*)arg_getptr(vm, 1); - arg_returnnum(vm, a->length); - return 1; -} - -int ELSAPI_binary_binary_change(els_VmObj* vm) -{ - /* - 改变储存区的大小 - 在扩大后,数据会被全部复制 - 在缩小后,数据会被截断 - - # 参数 - 1. p:ptr 储存区的指针 - 2. len:int 指定的大小 - - # 返回值 - 1. 新的储存区指针 - */ - barray *a = (void*)arg_getptr(vm, 1); - uint64_t len = arg_getnum(vm, 2); - barray_change(a, len); - - arg_returnptr(vm, (void*)a); - - return 1; -} - -int ELSAPI_binary_binary_copy(els_VmObj* vm) -{ - /* - 将储存区复制 - 不会改动原储存区的数据 - - # 参数 - 1. p:ptr 要复制的储存区指针 - - # 返回值 - 1. 新创建的储存区指针 - */ - barray *a = (void*)arg_getptr(vm, 1); - barray *newa =barray_create(a->length); - - for (uint64_t i = 0; i < a->length; i++) - newa->val[i] = a->val[i]; - - arg_returnptr(vm, (void*)newa); - - return 1; -} - -int ELSAPI_binary_binary_set(els_VmObj* vm) -{ - /* - 将储存区内的所有数据设置为n - - # 参数 - 1. p:ptr 储存区的指针 - 2. n:int 要设置的数据 - - # 返回值 - 1. 修改后的储存区指针 - */ - barray *a = (void*)arg_getptr(vm, 1); - uint8_t n = (long long)arg_getnum(vm, 2); - barray_set(a, n); - arg_returnnum(vm, 1); - return 1; -} - -int ELSAPI_binary_binary_slice(els_VmObj* vm) -{ - /* - 将储存区切片 - start和end处的数据都将被包括 - - # 参数 - 1. p:ptr 储存区指针 - 2. start:int 切片起始处 - 3. end:int 切片终止处 - - # 返回值 - 1. 新创建的储存区对象 - */ - barray *a = (void*)arg_getptr(vm, 1); - uint64_t start = arg_getnum(vm, 2); - uint64_t end = arg_getnum(vm, 3); - - if (start <0 || end < start || start > a->length) - { - arg_returnnull(vm); - return 1; - } - - if (start == end) - { - barray *b = barray_create(1); - b->val[0] = a->val[start]; - arg_returnptr(vm, (void*)b); - return 1; - } - - barray *b = barray_slice(a, start, end); - arg_returnptr(vm, (void*)b); - - return 1; -} - -int ELSAPI_binary_binary_tounit(els_VmObj* vm) -{ - /* - 将储存区中的数据按字节转化为洛书number类型数据并储存到unit中返回 - 返回的unit从1开始索引 - - # 参数 - 1. p:ptr 储存区的指针 - - # 返回值 - 1. 转化而成的unit - */ - - barray *a = (void*)arg_getptr(vm, 1); - LosuObj unit = obj_newunit(vm); - uint64_t i; - - for (i = 0; i < a->length; i++) - obj_setunit(vm, unit, obj_newnum(vm, i + 1), obj_newnum(vm, a->val[i])); - obj_setunit(vm, unit, obj_newnum(vm, i + 1), obj_newnull(vm)); - - arg_return(vm, unit); - - return 1; -} - -int ELSAPI_binary_binary_print(els_VmObj* vm) -{ - /* - 将储存区中的数据按字节以16进制大写的格式打印到控制台 - - # 参数 - 1. p:ptr 储存区的指针 - - # 返回值 - 1. 打印的字节数 - */ - barray *a = (void *)arg_getptr(vm, 1); - uint64_t i, j; - char buffer[16]; - - for (i = 0; i + 8 < a->length; i += 8) - { - for (j = 0; j < 7; j ++) - { - sprintf(buffer, "0x%-3X", a->val[i + j]); - __print(buffer); - } - sprintf(buffer, "0x%-3X\n", a->val[i + j]); - __print(buffer); - } - - for (; i < a->length; i++) - { - sprintf(buffer, "0x%-3X", a->val[i]); - __print(buffer); - } - - __print("\n"); - arg_returnnum(vm, i); - return 1; -} - -int ELSAPI_binary_binary_printf(els_VmObj* vm) -{ - /* - 将储存区中的数据按字节以16进制大写的格式写入文件 - - # 参数 - 1. p:ptr 储存区的指针 - 2. fname:str 要写入的文件的名称 - - # 返回值 - 1. 写入的字节数 - */ - - barray *a = (void *)arg_getptr(vm, 1); - const char *fname = arg_getstr(vm, 2); - uint64_t i, j; - FILE *fp = fopen(fname, "w"); - - if (fp == NULL) - { - arg_returnnull(vm); - return 1; - } - - for (i = 0; i + 8 < a->length; i += 8) - { - for (j = 0; j < 7; j ++) - fprintf(fp, "0x%-3X", a->val[i + j]); - fprintf(fp, "0x%-3X\n", a->val[i + j]); - } - - for (; i < a->length; i++) - fprintf(fp, "0x%-3X", a->val[i]); - - fprintf(fp, "\n"); - fclose(fp); - arg_returnnum(vm, i); - return 1; -} - -int ELSAPI_binary_binary_prints(els_VmObj* vm) -{/* - 将储存区中的数据按字节以16进制大写的格式转化成字符串并返回 - - # 参数 - 1. p:ptr 储存区的指针 - - # 返回值 - 1. 转化后的字符串 - */ - barray *a = (void *)arg_getptr(vm, 1); - uint64_t i, j; - char *buffer = malloc(a->length * (6 * sizeof(char))); - char tmp[16]; - uint64_t index = 0; - - for (i = 0; i + 8 < a->length; i += 8) - { - for (j = 0; j < 7; j ++) - { - sprintf(tmp, "0x%-3X", a->val[i + j]); - strcpy(buffer + index, tmp); - index += strlen(tmp); - } - sprintf(tmp, "0x%-3X\n", a->val[i + j]); - strcpy(buffer + index, tmp); - index += strlen(tmp); - } - - for (; i < a->length; i++) - { - sprintf(tmp, "0x%-3X", a->val[i]); - strcpy(buffer + index, tmp); - index += strlen(tmp); - } - - arg_returnstr(vm, buffer); - free(buffer); - return 1; -} - -int ELSAPI_binary_binary_scans(els_VmObj* vm) -{ - /* - 接受一个字符串,里面储存着十六进制数字,相互以空白字符分割,返回生成的二进制储存区 - - # 参数 - 1. p:ptr 二进制储存区的指针 - 2. s:str 要处理的字符串 - - # 返回值 - 1. 二进制储存区的指针 - */ - barray *a = (void *)arg_getptr(vm, 1); - const char *s = arg_getstr(vm, 2); - char ch; - uint64_t index = 0; - uint32_t n; - uint64_t slen = strlen(s); - - for (uint64_t i = 0; i < slen; i++) - { - if ((ch = s[i]) == '\0') - break; - else if (isspace(ch)==0) - { - if (index > a->length) - a = barray_change(a, a->length+1024); - sscanf(s+i, "0x%X", &n); - a->val[index] = (uint8_t)n; - - for (;i < slen; i++) - if (isspace((ch = s[i])) != 0) - break; - index++; - } - } - - a->length = index; - arg_returnptr(vm, (void *)a); - return 1; -} - -int ELSAPI_binary_binary_fromunit(els_VmObj* vm) -{ - /* - 接受一个unit,从1处开始索引,直至索引到null。将索引范围内所有属于number类型的数据储存到储存区中。 - 对储存区中的数据每8字节转化一个number型数据 - - 将会覆盖储存区原有的数据 - - # 参数 - 1. p:ptr 储存区指针 - 2. u:unit 要转化的unit - - # 返回值 - 1. 新的储存区指针 - */ - if (!(arg_gettype(vm, 1) == ELS_API_TYPE_UNIT) && !(arg_gettype(vm, 2) == ELS_API_TYPE_UNIT)) - { - arg_returnnull(vm); - return 1; - } - - barray *old = (void*)arg_getptr(vm, 1); - barray *n = NULL; - LosuObj *unit = arg_get(vm, 2); - uint64_t unitlen = 0; - uint64_t newlen = 1024; - - n = barray_create(newlen); - - //释放之前的内存 - barray_free(old); - - //获取unit的大小 - for (uint64_t i = 1; ; i++) - { - LosuObj *val = obj_indexunit(vm, *unit, obj_newnum(vm, i)); - int type = obj_type(vm, val); - - if (type == ELS_API_TYPE_NUMBER) - { - if (unitlen >= newlen - 1) - n = barray_change(n, newlen + 1024); - - barray_insert(n, unitlen, obj_tonum(vm, val)); - unitlen++; - continue; - } - - break; - } - n->length = unitlen; - arg_returnptr(vm, (void*)n); - - return 1; -} - -int ELSAPI_binary_binary_tostr(els_VmObj* vm) -{ - /* - 将储存区的数据直接以字符串形式返回 - 会在末尾附加'\0' - - # 参数 - 1. p:ptr 储存区指针 - - # 返回值 - 1. 转化后的字符串 - */ - barray *a = (void*)arg_getptr(vm, 1); - char *tmp = malloc(a->length + sizeof(char)); - - memcpy(tmp, a->val, a->length); - tmp[a->length / sizeof(char) + 1] = '\0'; - arg_returnstr(vm, tmp); - free(tmp); - - return 1; -} - -int ELSAPI_binary_binary_fromstr(els_VmObj* vm) -{ - /* - 将字符串直接转化为储存区数据 - 会去除末尾附加的'\0' - - # 参数 - 1. p:ptr 储存区指针 - 2. s:str 被转化的字符串 - - # 返回值 - 1. 新的储存区指针 - */ - barray *a = (void*)arg_getptr(vm, 1); - const char *str = arg_getstr(vm, 2); - uint64_t slen = strlen(str); - uint64_t cpylen = slen * sizeof(char); - - free(a->val); - a->val = malloc(cpylen); - memcpy(a->val, str, cpylen); - a->length = cpylen; - - arg_returnptr(vm, (void*)a); - - return 1; -} - -int ELSAPI_binary_binary_tonum(els_VmObj* vm) -{ - /* - 将储存区数据转化为洛书number类型,结果储存在unit中,从1开始索引 - - # 参数 - 1. p:ptr 储存区指针 - - # 返回值 - 1. 返回储存结果的unit - */ - barray *a = (void*)arg_getptr(vm, 1); - LosuObj unit = obj_newunit(vm); - - for (uint64_t i = 0; i < a->length; i += sizeof(double)) - { - obj_setunit(vm, unit, obj_newnum(vm, i / sizeof(double)), obj_newnum(vm, *(double*)(void*)(a->val+i))); - } - - arg_return(vm, unit); - - return 1; -} - -int ELSAPI_binary_binary_fromnum(els_VmObj* vm) -{ - /* - 将储存在unit中的洛书number型数据储存在储存区中 - 从unit的1处开始索引,直至索引到null - 每个number型数据占8字节 - - # 参数 - 1. p:ptr 储存区指针 - 2. u:unit 储存着洛书numbe型数据的单元 - - # 返回值 - 1. 新的储存区指针 - */ - barray *old = (void*)arg_getptr(vm, 1); - barray *n = NULL; - LosuObj *unit = arg_get(vm, 2); - uint64_t unitlen = 0; - uint64_t newlen = 1024; - - n = barray_create(newlen); - - //释放之前的内存 - barray_free(old); - - for (uint64_t i = 1; ; i++) - { - LosuObj *val = obj_indexunit(vm, *unit, obj_newnum(vm, i)); - int type = obj_type(vm, val); - - if (type == ELS_API_TYPE_NUMBER) - { - if (unitlen >= newlen - 1) - n = barray_change(n, newlen + 1024); - - *(double *)(void*)(n->val+unitlen) = obj_tonum(vm, val); - unitlen += sizeof(double); - continue; - } - - break; - } - n->length = unitlen; - arg_returnptr(vm, (void*)n); - - return 1; -} - -int ELSAPI_binary_binary_toptr(els_VmObj* vm) -{ - /* - 将储存区数据转化为洛书pointer类型,结果储存在unit中,从1开始索引 - - # 参数 - 1. p:ptr 储存区指针 - - # 返回值 - 1. 返回储存结果的unit - */ - - barray *a = (void*)arg_getptr(vm, 1); - LosuObj unit = obj_newunit(vm); - - for (uint64_t i = 0; i < a->length; i += sizeof(void*)) - { - obj_setunit(vm, unit, obj_newnum(vm, i / sizeof(void*)), obj_newptr(vm, (void*)a->val+i)); - } - - arg_return(vm, unit); - return 1; -} diff --git a/binary/binary.els b/binary/binary.els deleted file mode 100755 index 72b1bab35098ec7a1c32ec15a1989a195d0d108f..0000000000000000000000000000000000000000 --- a/binary/binary.els +++ /dev/null @@ -1,330 +0,0 @@ -#!declare -binary_create( size:int ): ptr #创建一块二进制储存区,返回对应的指针,size的单位是字节 -binary_free( p:ptr ): null #释放一块二进制储存区的内存 -binary_writef( p:ptr, fname:str, n:int): [int/null] #向文件写入二进制数据,fname是文件名,mode是"r"、"w"、"a"的其中一个 -binary_writem( p:ptr, m:ptr, len:int ): [int/null] #向内存写入指定数量的字节 -binary_readf( p:ptr, fname:str, len:int): [int/null] #从文件读取指定数量的字节 -binary_readm( p:ptr, m:ptr, len:int ): [int/null] #从内存读取指定数量的字节 -binary_get( p:ptr, i:int ): [int/null] #获取储存区中指定位置的数据 -binary_insert( p:ptr, i:int, d:int, size:int): [int/null] #将指定数据写入储存区的指定位置, size为要写入的数据的大小,单位为字节 -binary_insertp( a:ptr, i:int, p:int, size:int): [int/null] -binary_cat( a:ptr, b:ptr ): ptr #将b附加到a末尾 -binary_replace( a:ptr, b:ptr, start:int, len:int ): ptr #从start处开始,将b中的len个字节的数据替换a中的数据,返回修改后a的指针 -binary_length( p:ptr ): int #返回储存区的长度 -binary_change( p:ptr, len:int ): [int/null] #改变储存区的大小 -binary_copy( a:ptr, b:ptr ): [int/null] #将a中的数据储存到b中 -binary_set( p:ptr, n:int ): [int/null] #将储存区中的数据都设置为n -binary_slice( p:ptr, start:int, end:int ): ptr #将储存区切片 -binary_print(): int -binary_printf( p:ptr, fname:str): int -binary_prints( p:ptr ): str -binary_scans( p:ptr, s:str ): ptr - -binary_tounit( p:ptr ): [unit/null] #将二进制储存区中的数据储存到指定的单元中 -binary_fromunit( u:unit ): ptr #将单元中的数据储存到为二进制储存区中 -binary_tostr( p:ptr ): str #将二进制储存区中的数据转化为字符串型 -binary_fromstr( p:ptr, s:str ): [int/null] -binary_tonum( p:ptr ): unit #将二进制储存区中的数据转化为字符串型 -binary_fromnum( p:ptr, u:unit ): [int/null] -binary_toptr( p:ptr ): unit #将二进制储存区中的数据转化为字符串型 -binary_fromnum( p:ptr, s:str ): [int/null] -#!end - -#!script -import("stdlib") - -var binary = {} - -def binary.create(size): - var new = {} - size = size or 0 - - if size<=0: - new.__ptr__ = null - else - new.__ptr__ = binary_create(size) - ; - - def new.free(): - if not this.__ptr__: - rt null - ; - - var p = this.__ptr__ - this.__ptr__ = null - rt binary_free(p) - ; - - def new.writef(fname, n): - if not this.__ptr__: - rt null - ; - - if not fname or fname=='': - rt null - ; - mode = mode or 'rb' - rt binary_writef(this.__ptr__, fname, n) - ; - - def new.writem(p, n): - if not this.__ptr__: - rt null - ; - - if not fname or fname=='': - rt null - ; - - mode = mode or 'rb' - rt binary_writef(this.__ptr__, p, n) - ; - - def new.tounit(): - if not this.__ptr__: - rt null - ; - - rt binary_tounit(this.__ptr__) - ; - - def new.fromunit(u): - if not this.__ptr__: - rt null - ; - - if not u: - rt null - ; - - this.__ptr__ = binary_fromunit(this.__ptr__, u) - rt this - ; - - def new.print(): - if not this.__ptr__: - rt null - ; - - rt binary_print(this.__ptr__) - ; - - def new.printfile(fname): - if not this.__ptr__: - rt null - ; - - rt binary_printf(this.__ptr__, fname) - ; - - def new.prints(): - if not this.__ptr__: - rt null - ; - - rt binary_prints(this.__ptr__) - ; - - def new.scans(s): - if not this.__ptr__: - rt null - ; - - this.__ptr__ = binary_scans(this.__ptr__, s) - rt this - ; - - def new.set(n): - if not this.__ptr__: - rt null - ; - - rt binary_set(this.__ptr__, n) - ; - - def new.get(index, size): - if not this.__ptr__: - rt null - ; - - size = int(size or 1) - if size<1 or size>8: - rt null - ; - - rt binary_get(this.__ptr__, index, size) - ; - - def new.insert(index, val, size): - if not this.__ptr__: - rt null - ; - - size = int(size or 1) - if size > 8 or size < 1: - rt null - ; - - rt binary_insert(this.__ptr__, index, val, size) - ; - - def new.insertp(index, p, size): - if not this.__ptr__: - rt null - ; - - size = int(size or 1) - if size < 1: - rt null - ; - - rt binary_insertp(this.__ptr__, index, p, size) - ; - - def new.cat(b): - if not this.__ptr__ or not b.__ptr__: - rt null - ; - - this.__ptr__ = binary_cat(this.__ptr__, b.__ptr__) - rt this - ; - - def new.replace(b, start, len): - """ - 从start处开始,将b中的len个字节的数据替换a中的数据 - 当b省略时,函数终止运行 - 当start省略时,会被设为0 - 当len省略时,会被设为b的长度 - 返回修改后的本对象 - """ - if not a.__ptr__ or not b.__ptr__: - rt null - ; - - start = start or 0 - len = len or b.length() - this.__ptr__ = binary_replace(this.__ptr__, b.__ptr__, start, len) - rt this - ; - - def new.writem(p, len): - if not this.__ptr__: - rt null - ; - - rt binary_writem(this.__ptr__, p, len) - ; - - def new.readm(p, len): - if not this.__ptr__: - rt null - ; - - this.__ptr__ = binary_readm(this.__ptr__, p, len) - rt this - ; - - def new.writef(fname, len): - if not this.__ptr__: - rt null - ; - - rt binary_writef(this.__ptr__, fname, len) - ; - - def new.readf(fname, len): - if not this.__ptr__: - rt null - ; - - this.__ptr__ = binary_readf(this.__ptr__, fname, len) - rt this - ; - - def new.length(): - if not this.__ptr__: - rt null - ; - - rt binary_length(this.__ptr__) - ; - - def new.copy(): - if not this.__ptr__: - rt null - ; - - var b = binary.create() - b.__ptr__ = binary_copy(this.__ptr__) - rt b - ; - - def new.change(len): - if not this.__ptr__: - rt null - ; - - this.__ptr__ = binary_change(this.__ptr__, len) - rt this - ; - - def new.slice(start, end): - if not this.__ptr__ or not start or not end: - rt null - ; - var b = binary.create() - b.__ptr__ = binary_slice(this.__ptr__, start, end) - rt b - ; - - def new.tostr(): - if not this.__ptr__: - rt null - ; - - rt binary_tostr(this.__ptr__) - ; - - def new.tonum(): - if not this.__ptr__: - rt null - ; - - rt binary_tonum(this.__ptr__) - ; - - def new.toptr(): - if not this.__ptr__: - rt null - ; - - rt binary_toptr(this.__ptr__) - ; - - def new.fromstr(s): - if not this.__ptr__: - rt null - ; - - this.__ptr__ = binary_fromstr(this.__ptr__, s) - rt this - ; - - def new.fromnum(u): - if not this.__ptr__: - rt null - ; - - this.__ptr__ = binary_fromnum(this.__ptr__, u) - rt this - ; - - rt new -; - -def binary.valhex(s): - rt val(s) -; - -#!end diff --git a/binary/binary.h b/binary/binary.h deleted file mode 100755 index 49423c9df8d2c7dbba210f8ef78f227339012414..0000000000000000000000000000000000000000 --- a/binary/binary.h +++ /dev/null @@ -1,361 +0,0 @@ -#include "els.h" -int ELSAPI_binary_binary_create(els_VmObj* vm); // binary_create( size:int ): ptr #创建一块二进制储存区,返回对应的指针,size的单位是字节 -int ELSAPI_binary_binary_free(els_VmObj* vm); // binary_free( p:ptr ): null #释放一块二进制储存区的内存 -int ELSAPI_binary_binary_writef(els_VmObj* vm); // binary_writef( p:ptr, fname:str, n:int): [int/null] #向文件写入二进制数据,fname是文件名,mode是"r"、"w"、"a"的其中一个 -int ELSAPI_binary_binary_writem(els_VmObj* vm); // binary_writem( p:ptr, m:ptr, len:int ): [int/null] #向内存写入指定数量的字节 -int ELSAPI_binary_binary_readf(els_VmObj* vm); // binary_readf( p:ptr, fname:str, len:int): [int/null] #从文件读取指定数量的字节 -int ELSAPI_binary_binary_readm(els_VmObj* vm); // binary_readm( p:ptr, m:ptr, len:int ): [int/null] #从内存读取指定数量的字节 -int ELSAPI_binary_binary_get(els_VmObj* vm); // binary_get( p:ptr, i:int ): [int/null] #获取储存区中指定位置的数据 -int ELSAPI_binary_binary_insert(els_VmObj* vm); // binary_insert( p:ptr, i:int, d:int, size:int): [int/null] #将指定数据写入储存区的指定位置, size为要写入的数据的大小,单位为字节 -int ELSAPI_binary_binary_insertp(els_VmObj* vm); // binary_insertp( a:ptr, i:int, p:int, size:int): [int/null] -int ELSAPI_binary_binary_cat(els_VmObj* vm); // binary_cat( a:ptr, b:ptr ): ptr #将b附加到a末尾 -int ELSAPI_binary_binary_replace(els_VmObj* vm); // binary_replace( a:ptr, b:ptr, start:int, len:int ): ptr #从start处开始,将b中的len个字节的数据替换a中的数据,返回修改后a的指针 -int ELSAPI_binary_binary_length(els_VmObj* vm); // binary_length( p:ptr ): int #返回储存区的长度 -int ELSAPI_binary_binary_change(els_VmObj* vm); // binary_change( p:ptr, len:int ): [int/null] #改变储存区的大小 -int ELSAPI_binary_binary_copy(els_VmObj* vm); // binary_copy( a:ptr, b:ptr ): [int/null] #将a中的数据储存到b中 -int ELSAPI_binary_binary_set(els_VmObj* vm); // binary_set( p:ptr, n:int ): [int/null] #将储存区中的数据都设置为n -int ELSAPI_binary_binary_slice(els_VmObj* vm); // binary_slice( p:ptr, start:int, end:int ): ptr #将储存区切片 -int ELSAPI_binary_binary_print(els_VmObj* vm); // binary_print(): int -int ELSAPI_binary_binary_printf(els_VmObj* vm); // binary_printf( p:ptr, fname:str): int -int ELSAPI_binary_binary_prints(els_VmObj* vm); // binary_prints( p:ptr ): str -int ELSAPI_binary_binary_scans(els_VmObj* vm); // binary_scans( p:ptr, s:str ): ptr -int ELSAPI_binary_binary_tounit(els_VmObj* vm); // binary_tounit( p:ptr ): [unit/null] #将二进制储存区中的数据储存到指定的单元中 -int ELSAPI_binary_binary_fromunit(els_VmObj* vm); // binary_fromunit( u:unit ): ptr #将单元中的数据储存到为二进制储存区中 -int ELSAPI_binary_binary_tostr(els_VmObj* vm); // binary_tostr( p:ptr ): str #将二进制储存区中的数据转化为字符串型 -int ELSAPI_binary_binary_fromstr(els_VmObj* vm); // binary_fromstr( p:ptr, s:str ): [int/null] -int ELSAPI_binary_binary_tonum(els_VmObj* vm); // binary_tonum( p:ptr ): unit #将二进制储存区中的数据转化为字符串型 -int ELSAPI_binary_binary_fromnum(els_VmObj* vm); // binary_fromnum( p:ptr, u:unit ): [int/null] -int ELSAPI_binary_binary_toptr(els_VmObj* vm); // binary_toptr( p:ptr ): unit #将二进制储存区中的数据转化为字符串型 -int ELSAPI_binary_binary_fromnum(els_VmObj* vm); // binary_fromnum( p:ptr, s:str ): [int/null] -#ifdef ELS_CONF_TOKEN_EN -static const char LibScript[]={ -105,109,112,111,114,116,40,34,115,116,100,108,105,98,34,41,10, -10, -118,97,114,32,98,105,110,97,114,121,32,61,32,123,125,10, -10, -100,101,102,32,98,105,110,97,114,121,46,99,114,101,97,116,101,40,115,105,122,101,41,58,10, -32,32,32,32,118,97,114,32,110,101,119,32,61,32,123,125,10, -32,32,32,32,115,105,122,101,32,61,32,115,105,122,101,32,111,114,32,48,10, -32,32,32,32,10, -32,32,32,32,105,102,32,115,105,122,101,60,61,48,58,10, -32,32,32,32,32,32,32,32,110,101,119,46,95,95,112,116,114,95,95,32,61,32,110,117,108,108,10, -32,32,32,32,101,108,115,101,10, -32,32,32,32,32,32,32,32,110,101,119,46,95,95,112,116,114,95,95,32,61,32,98,105,110,97,114,121,95,99,114,101,97,116,101,40,115,105,122,101,41,10, -32,32,32,32,59,10, -10, -32,32,32,32,100,101,102,32,110,101,119,46,102,114,101,101,40,41,58,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,116,104,105,115,46,95,95,112,116,114,95,95,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,32,32,32,32,118,97,114,32,112,32,61,32,116,104,105,115,46,95,95,112,116,114,95,95,10, -32,32,32,32,32,32,32,32,116,104,105,115,46,95,95,112,116,114,95,95,32,61,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,114,116,32,98,105,110,97,114,121,95,102,114,101,101,40,112,41,10, -32,32,32,32,59,10, -10, -32,32,32,32,100,101,102,32,110,101,119,46,119,114,105,116,101,102,40,102,110,97,109,101,44,32,110,41,58,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,116,104,105,115,46,95,95,112,116,114,95,95,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,102,110,97,109,101,32,111,114,32,102,110,97,109,101,61,61,39,39,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -32,32,32,32,32,32,32,32,109,111,100,101,32,61,32,109,111,100,101,32,111,114,32,39,114,98,39,10, -32,32,32,32,32,32,32,32,114,116,32,98,105,110,97,114,121,95,119,114,105,116,101,102,40,116,104,105,115,46,95,95,112,116,114,95,95,44,32,102,110,97,109,101,44,32,110,41,10, -32,32,32,32,59,10, -10, -32,32,32,32,100,101,102,32,110,101,119,46,119,114,105,116,101,109,40,112,44,32,110,41,58,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,116,104,105,115,46,95,95,112,116,114,95,95,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,102,110,97,109,101,32,111,114,32,102,110,97,109,101,61,61,39,39,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,32,32,32,32,109,111,100,101,32,61,32,109,111,100,101,32,111,114,32,39,114,98,39,10, -32,32,32,32,32,32,32,32,114,116,32,98,105,110,97,114,121,95,119,114,105,116,101,102,40,116,104,105,115,46,95,95,112,116,114,95,95,44,32,112,44,32,110,41,10, -32,32,32,32,59,10, -10, -32,32,32,32,100,101,102,32,110,101,119,46,116,111,117,110,105,116,40,41,58,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,116,104,105,115,46,95,95,112,116,114,95,95,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,32,32,32,32,114,116,32,98,105,110,97,114,121,95,116,111,117,110,105,116,40,116,104,105,115,46,95,95,112,116,114,95,95,41,10, -32,32,32,32,59,10, -10, -32,32,32,32,100,101,102,32,110,101,119,46,102,114,111,109,117,110,105,116,40,117,41,58,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,116,104,105,115,46,95,95,112,116,114,95,95,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,117,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,32,32,32,32,116,104,105,115,46,95,95,112,116,114,95,95,32,61,32,98,105,110,97,114,121,95,102,114,111,109,117,110,105,116,40,116,104,105,115,46,95,95,112,116,114,95,95,44,32,117,41,10, -32,32,32,32,32,32,32,32,114,116,32,116,104,105,115,10, -32,32,32,32,59,10, -10, -32,32,32,32,100,101,102,32,110,101,119,46,112,114,105,110,116,40,41,58,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,116,104,105,115,46,95,95,112,116,114,95,95,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,32,32,32,32,114,116,32,98,105,110,97,114,121,95,112,114,105,110,116,40,116,104,105,115,46,95,95,112,116,114,95,95,41,10, -32,32,32,32,59,10, -10, -32,32,32,32,100,101,102,32,110,101,119,46,112,114,105,110,116,102,105,108,101,40,102,110,97,109,101,41,58,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,116,104,105,115,46,95,95,112,116,114,95,95,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,32,32,32,32,114,116,32,98,105,110,97,114,121,95,112,114,105,110,116,102,40,116,104,105,115,46,95,95,112,116,114,95,95,44,32,102,110,97,109,101,41,10, -32,32,32,32,59,10, -10, -32,32,32,32,100,101,102,32,110,101,119,46,112,114,105,110,116,115,40,41,58,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,116,104,105,115,46,95,95,112,116,114,95,95,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,32,32,32,32,114,116,32,98,105,110,97,114,121,95,112,114,105,110,116,115,40,116,104,105,115,46,95,95,112,116,114,95,95,41,10, -32,32,32,32,59,10, -10, -32,32,32,32,100,101,102,32,110,101,119,46,115,99,97,110,115,40,115,41,58,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,116,104,105,115,46,95,95,112,116,114,95,95,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,32,32,32,32,116,104,105,115,46,95,95,112,116,114,95,95,32,61,32,98,105,110,97,114,121,95,115,99,97,110,115,40,116,104,105,115,46,95,95,112,116,114,95,95,44,32,115,41,10, -32,32,32,32,32,32,32,32,114,116,32,116,104,105,115,10, -32,32,32,32,59,10, -10, -32,32,32,32,100,101,102,32,110,101,119,46,115,101,116,40,110,41,58,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,116,104,105,115,46,95,95,112,116,114,95,95,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,32,32,32,32,114,116,32,98,105,110,97,114,121,95,115,101,116,40,116,104,105,115,46,95,95,112,116,114,95,95,44,32,110,41,10, -32,32,32,32,59,10, -10, -32,32,32,32,100,101,102,32,110,101,119,46,103,101,116,40,105,110,100,101,120,44,32,115,105,122,101,41,58,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,116,104,105,115,46,95,95,112,116,114,95,95,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,32,32,32,32,115,105,122,101,32,61,32,105,110,116,40,115,105,122,101,32,111,114,32,49,41,10, -32,32,32,32,32,32,32,32,105,102,32,115,105,122,101,60,49,32,111,114,32,115,105,122,101,62,56,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,32,32,32,32,114,116,32,98,105,110,97,114,121,95,103,101,116,40,116,104,105,115,46,95,95,112,116,114,95,95,44,32,105,110,100,101,120,44,32,115,105,122,101,41,10, -32,32,32,32,59,10, -10, -32,32,32,32,100,101,102,32,110,101,119,46,105,110,115,101,114,116,40,105,110,100,101,120,44,32,118,97,108,44,32,115,105,122,101,41,58,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,116,104,105,115,46,95,95,112,116,114,95,95,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,32,32,32,32,115,105,122,101,32,61,32,105,110,116,40,115,105,122,101,32,111,114,32,49,41,10, -32,32,32,32,32,32,32,32,105,102,32,115,105,122,101,32,62,32,56,32,111,114,32,115,105,122,101,32,60,32,49,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,32,32,32,32,114,116,32,98,105,110,97,114,121,95,105,110,115,101,114,116,40,116,104,105,115,46,95,95,112,116,114,95,95,44,32,105,110,100,101,120,44,32,118,97,108,44,32,115,105,122,101,41,10, -32,32,32,32,59,10, -10, -32,32,32,32,100,101,102,32,110,101,119,46,105,110,115,101,114,116,112,40,105,110,100,101,120,44,32,112,44,32,115,105,122,101,41,58,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,116,104,105,115,46,95,95,112,116,114,95,95,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,32,32,32,32,115,105,122,101,32,61,32,105,110,116,40,115,105,122,101,32,111,114,32,49,41,10, -32,32,32,32,32,32,32,32,105,102,32,115,105,122,101,32,60,32,49,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,32,32,32,32,114,116,32,98,105,110,97,114,121,95,105,110,115,101,114,116,112,40,116,104,105,115,46,95,95,112,116,114,95,95,44,32,105,110,100,101,120,44,32,112,44,32,115,105,122,101,41,10, -32,32,32,32,59,10, -10, -32,32,32,32,100,101,102,32,110,101,119,46,99,97,116,40,98,41,58,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,116,104,105,115,46,95,95,112,116,114,95,95,32,111,114,32,110,111,116,32,98,46,95,95,112,116,114,95,95,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -32,32,32,32,32,32,32,32,10, -32,32,32,32,32,32,32,32,116,104,105,115,46,95,95,112,116,114,95,95,32,61,32,98,105,110,97,114,121,95,99,97,116,40,116,104,105,115,46,95,95,112,116,114,95,95,44,32,98,46,95,95,112,116,114,95,95,41,10, -32,32,32,32,32,32,32,32,114,116,32,116,104,105,115,10, -32,32,32,32,59,10, -10, -32,32,32,32,100,101,102,32,110,101,119,46,114,101,112,108,97,99,101,40,98,44,32,115,116,97,114,116,44,32,108,101,110,41,58,10, -32,32,32,32,32,32,32,32,34,34,34,10, -32,32,32,32,32,32,32,32,32,32,32,32,-28,-69,-114,115,116,97,114,116,-27,-92,-124,-27,-68,-128,-27,-89,-117,-17,-68,-116,-27,-80,-122,98,-28,-72,-83,-25,-102,-124,108,101,110,-28,-72,-86,-27,-83,-105,-24,-118,-126,-25,-102,-124,-26,-107,-80,-26,-115,-82,-26,-101,-65,-26,-115,-94,97,-28,-72,-83,-25,-102,-124,-26,-107,-80,-26,-115,-82,10, -32,32,32,32,32,32,32,32,32,32,32,32,-27,-67,-109,98,-25,-100,-127,-25,-107,-91,-26,-105,-74,-17,-68,-116,-27,-121,-67,-26,-107,-80,-25,-69,-120,-26,-83,-94,-24,-65,-112,-24,-95,-116,10, -32,32,32,32,32,32,32,32,32,32,32,32,-27,-67,-109,115,116,97,114,116,-25,-100,-127,-25,-107,-91,-26,-105,-74,-17,-68,-116,-28,-68,-102,-24,-94,-85,-24,-82,-66,-28,-72,-70,48,10, -32,32,32,32,32,32,32,32,32,32,32,32,-27,-67,-109,108,101,110,-25,-100,-127,-25,-107,-91,-26,-105,-74,-17,-68,-116,-28,-68,-102,-24,-94,-85,-24,-82,-66,-28,-72,-70,98,-25,-102,-124,-23,-107,-65,-27,-70,-90,10, -32,32,32,32,32,32,32,32,32,32,32,32,-24,-65,-108,-27,-101,-98,-28,-65,-82,-26,-108,-71,-27,-112,-114,-25,-102,-124,-26,-100,-84,-27,-81,-71,-24,-79,-95,10, -32,32,32,32,32,32,32,32,34,34,34,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,97,46,95,95,112,116,114,95,95,32,111,114,32,110,111,116,32,98,46,95,95,112,116,114,95,95,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,32,32,32,32,115,116,97,114,116,32,61,32,115,116,97,114,116,32,111,114,32,48,10, -32,32,32,32,32,32,32,32,108,101,110,32,61,32,108,101,110,32,111,114,32,98,46,108,101,110,103,116,104,40,41,10, -32,32,32,32,32,32,32,32,116,104,105,115,46,95,95,112,116,114,95,95,32,61,32,98,105,110,97,114,121,95,114,101,112,108,97,99,101,40,116,104,105,115,46,95,95,112,116,114,95,95,44,32,98,46,95,95,112,116,114,95,95,44,32,115,116,97,114,116,44,32,108,101,110,41,10, -32,32,32,32,32,32,32,32,114,116,32,116,104,105,115,10, -32,32,32,32,59,10, -10, -32,32,32,32,100,101,102,32,110,101,119,46,119,114,105,116,101,109,40,112,44,32,108,101,110,41,58,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,116,104,105,115,46,95,95,112,116,114,95,95,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,32,32,32,32,114,116,32,98,105,110,97,114,121,95,119,114,105,116,101,109,40,116,104,105,115,46,95,95,112,116,114,95,95,44,32,112,44,32,108,101,110,41,10, -32,32,32,32,59,10, -10, -32,32,32,32,100,101,102,32,110,101,119,46,114,101,97,100,109,40,112,44,32,108,101,110,41,58,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,116,104,105,115,46,95,95,112,116,114,95,95,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,32,32,32,32,116,104,105,115,46,95,95,112,116,114,95,95,32,61,32,98,105,110,97,114,121,95,114,101,97,100,109,40,116,104,105,115,46,95,95,112,116,114,95,95,44,32,112,44,32,108,101,110,41,10, -32,32,32,32,32,32,32,32,114,116,32,116,104,105,115,10, -32,32,32,32,59,10, -10, -32,32,32,32,100,101,102,32,110,101,119,46,119,114,105,116,101,102,40,102,110,97,109,101,44,32,108,101,110,41,58,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,116,104,105,115,46,95,95,112,116,114,95,95,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,32,32,32,32,114,116,32,98,105,110,97,114,121,95,119,114,105,116,101,102,40,116,104,105,115,46,95,95,112,116,114,95,95,44,32,102,110,97,109,101,44,32,108,101,110,41,10, -32,32,32,32,59,10, -10, -32,32,32,32,100,101,102,32,110,101,119,46,114,101,97,100,102,40,102,110,97,109,101,44,32,108,101,110,41,58,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,116,104,105,115,46,95,95,112,116,114,95,95,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,32,32,32,32,116,104,105,115,46,95,95,112,116,114,95,95,32,61,32,98,105,110,97,114,121,95,114,101,97,100,102,40,116,104,105,115,46,95,95,112,116,114,95,95,44,32,102,110,97,109,101,44,32,108,101,110,41,10, -32,32,32,32,32,32,32,32,114,116,32,116,104,105,115,10, -32,32,32,32,59,10, -10, -32,32,32,32,100,101,102,32,110,101,119,46,108,101,110,103,116,104,40,41,58,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,116,104,105,115,46,95,95,112,116,114,95,95,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,32,32,32,32,114,116,32,98,105,110,97,114,121,95,108,101,110,103,116,104,40,116,104,105,115,46,95,95,112,116,114,95,95,41,10, -32,32,32,32,59,10, -10, -32,32,32,32,100,101,102,32,110,101,119,46,99,111,112,121,40,41,58,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,116,104,105,115,46,95,95,112,116,114,95,95,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,32,32,32,32,118,97,114,32,98,32,61,32,98,105,110,97,114,121,46,99,114,101,97,116,101,40,41,10, -32,32,32,32,32,32,32,32,98,46,95,95,112,116,114,95,95,32,61,32,98,105,110,97,114,121,95,99,111,112,121,40,116,104,105,115,46,95,95,112,116,114,95,95,41,10, -32,32,32,32,32,32,32,32,114,116,32,98,10, -32,32,32,32,59,10, -10, -32,32,32,32,100,101,102,32,110,101,119,46,99,104,97,110,103,101,40,108,101,110,41,58,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,116,104,105,115,46,95,95,112,116,114,95,95,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,32,32,32,32,116,104,105,115,46,95,95,112,116,114,95,95,32,61,32,98,105,110,97,114,121,95,99,104,97,110,103,101,40,116,104,105,115,46,95,95,112,116,114,95,95,44,32,108,101,110,41,10, -32,32,32,32,32,32,32,32,114,116,32,116,104,105,115,10, -32,32,32,32,59,10, -10, -32,32,32,32,100,101,102,32,110,101,119,46,115,108,105,99,101,40,115,116,97,114,116,44,32,101,110,100,41,58,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,116,104,105,115,46,95,95,112,116,114,95,95,32,111,114,32,110,111,116,32,115,116,97,114,116,32,111,114,32,110,111,116,32,101,110,100,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -32,32,32,32,32,32,32,32,118,97,114,32,98,32,61,32,98,105,110,97,114,121,46,99,114,101,97,116,101,40,41,10, -32,32,32,32,32,32,32,32,98,46,95,95,112,116,114,95,95,32,61,32,98,105,110,97,114,121,95,115,108,105,99,101,40,116,104,105,115,46,95,95,112,116,114,95,95,44,32,115,116,97,114,116,44,32,101,110,100,41,10, -32,32,32,32,32,32,32,32,114,116,32,98,10, -32,32,32,32,59,10, -10, -32,32,32,32,100,101,102,32,110,101,119,46,116,111,115,116,114,40,41,58,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,116,104,105,115,46,95,95,112,116,114,95,95,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,32,32,32,32,114,116,32,98,105,110,97,114,121,95,116,111,115,116,114,40,116,104,105,115,46,95,95,112,116,114,95,95,41,10, -32,32,32,32,59,10, -10, -32,32,32,32,100,101,102,32,110,101,119,46,116,111,110,117,109,40,41,58,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,116,104,105,115,46,95,95,112,116,114,95,95,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,32,32,32,32,114,116,32,98,105,110,97,114,121,95,116,111,110,117,109,40,116,104,105,115,46,95,95,112,116,114,95,95,41,10, -32,32,32,32,59,10, -10, -32,32,32,32,100,101,102,32,110,101,119,46,116,111,112,116,114,40,41,58,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,116,104,105,115,46,95,95,112,116,114,95,95,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,32,32,32,32,114,116,32,98,105,110,97,114,121,95,116,111,112,116,114,40,116,104,105,115,46,95,95,112,116,114,95,95,41,10, -32,32,32,32,59,10, -10, -32,32,32,32,100,101,102,32,110,101,119,46,102,114,111,109,115,116,114,40,115,41,58,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,116,104,105,115,46,95,95,112,116,114,95,95,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,32,32,32,32,116,104,105,115,46,95,95,112,116,114,95,95,32,61,32,98,105,110,97,114,121,95,102,114,111,109,115,116,114,40,116,104,105,115,46,95,95,112,116,114,95,95,44,32,115,41,10, -32,32,32,32,32,32,32,32,114,116,32,116,104,105,115,10, -32,32,32,32,59,10, -10, -32,32,32,32,100,101,102,32,110,101,119,46,102,114,111,109,110,117,109,40,117,41,58,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,116,104,105,115,46,95,95,112,116,114,95,95,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,32,32,32,32,116,104,105,115,46,95,95,112,116,114,95,95,32,61,32,98,105,110,97,114,121,95,102,114,111,109,110,117,109,40,116,104,105,115,46,95,95,112,116,114,95,95,44,32,117,41,10, -32,32,32,32,32,32,32,32,114,116,32,116,104,105,115,10, -32,32,32,32,59,10, -10, -32,32,32,32,114,116,32,110,101,119,10, -59,10, -10, -100,101,102,32,98,105,110,97,114,121,46,118,97,108,104,101,120,40,115,41,58,10, -32,32,32,32,114,116,32,118,97,108,40,115,41,10, -59,10, -10, -0}; -#endif -void ElsLib_binary_libinit(els_VmObj *vm){ - vm_register(vm,"binary_tounit",ELSAPI_binary_binary_tounit); - vm_register(vm,"binary_fromunit",ELSAPI_binary_binary_fromunit); - vm_register(vm,"binary_insertp",ELSAPI_binary_binary_insertp); - vm_register(vm,"binary_readf",ELSAPI_binary_binary_readf); - vm_register(vm,"binary_prints",ELSAPI_binary_binary_prints); - vm_register(vm,"binary_writef",ELSAPI_binary_binary_writef); - vm_register(vm,"binary_readm",ELSAPI_binary_binary_readm); - vm_register(vm,"binary_fromnum",ELSAPI_binary_binary_fromnum); - vm_register(vm,"binary_cat",ELSAPI_binary_binary_cat); - vm_register(vm,"binary_tostr",ELSAPI_binary_binary_tostr); - vm_register(vm,"binary_copy",ELSAPI_binary_binary_copy); - vm_register(vm,"binary_scans",ELSAPI_binary_binary_scans); - vm_register(vm,"binary_print",ELSAPI_binary_binary_print); - vm_register(vm,"binary_free",ELSAPI_binary_binary_free); - vm_register(vm,"binary_create",ELSAPI_binary_binary_create); - vm_register(vm,"binary_tonum",ELSAPI_binary_binary_tonum); - vm_register(vm,"binary_insert",ELSAPI_binary_binary_insert); - vm_register(vm,"binary_set",ELSAPI_binary_binary_set); - vm_register(vm,"binary_toptr",ELSAPI_binary_binary_toptr); - vm_register(vm,"binary_fromstr",ELSAPI_binary_binary_fromstr); - vm_register(vm,"binary_printf",ELSAPI_binary_binary_printf); - vm_register(vm,"binary_slice",ELSAPI_binary_binary_slice); - vm_register(vm,"binary_replace",ELSAPI_binary_binary_replace); - vm_register(vm,"binary_change",ELSAPI_binary_binary_change); - vm_register(vm,"binary_get",ELSAPI_binary_binary_get); - vm_register(vm,"binary_length",ELSAPI_binary_binary_length); - vm_register(vm,"binary_writem",ELSAPI_binary_binary_writem); - #ifdef ELS_CONF_TOKEN_EN - vm_dostring(vm,LibScript); - #endif -}; diff --git a/binary/info b/binary/info deleted file mode 100755 index 463eed676d9346ba335432d067ae2ed6412820b4..0000000000000000000000000000000000000000 --- a/binary/info +++ /dev/null @@ -1,27 +0,0 @@ -{ - info = { - name = "binary/轻量级二进制操作模块", - text = "一个轻量级二进制操作模块", - version = "23.10.1" - }, - source = { - all = { - "binary.h", - "binary.c", - "binary.els", - "losubinary.h", - "losubinary.c", - "readme.md" - }, - Ubuntu = { - "makefile", - }, - Windows = { - "makefile", - } - }, - target = { - Ubuntu = "make ; cp ElsLib_binary.lsd target/ElsLib_binary.lsd_Ubuntu ; make clean", - Windows = "make ; cp ElsLib_binary.lsd target/ElsLib_binary.lsd_Windows ; make clean", - } -} \ No newline at end of file diff --git a/binary/losubinary.c b/binary/losubinary.c deleted file mode 100755 index b0d09a0cdcaf24667fbecfd5b53849ccdfe15d65..0000000000000000000000000000000000000000 --- a/binary/losubinary.c +++ /dev/null @@ -1,92 +0,0 @@ -#include "losubinary.h" - -inline barray *barray_create(uint64_t len) -{ - barray *output = malloc(sizeof(barray)); - output->val = malloc(len); - output->length = len; - return output; -} - -barray *barray_set(barray *array, uint8_t n) -{ - for (uint64_t i = 0; i < array->length; i++) - array->val[i] = n; - return array; -} - -barray *barray_change(barray *front, uint64_t len) -{ - uint8_t *oldval = NULL; - uint8_t *newval = NULL; - uint64_t stopindex; - - if (len > front->length) - stopindex = len; - else if (len == front->length) - return front; - else - stopindex = front->length; - - oldval = front->val; - newval = malloc(len); - for (uint64_t i = 0; i < stopindex; i++) - newval[i] = front->val[i]; - free(oldval); - front->val = newval; - front->length = len; - return front; -} - -barray *barray_slice(barray *array, uint64_t start, uint64_t end) -{ - barray *newarray = barray_create(end - start + 1); - - start = start >= array->length ? array->length - 1 : start; - end = end >= array->length ? array->length - 1 : end; - - for (uint64_t i = start; i <= end; i++) - newarray->val[i - start] = array->val[i]; - - return newarray; -} - -inline uint64_t barray_length(barray *array) -{ - return array->length; -} - -inline uint8_t barray_get(barray *array, uint64_t index) -{ - return array->val[index]; -} - -inline uint8_t *barray_getx(barray *array, uint64_t index) -{ - return array->val + index; -} - -inline uint8_t barray_insert(barray* array, uint64_t index, uint8_t n) -{ - array->val[index] = n; - return n; -} - -barray *barray_copy(barray *a, barray *b) -{ - uint64_t cpy_len; - - if (b == NULL) - b = barray_create(barray_length(a)); - - cpy_len = a->length >= b->length ? b->length : a->length; - - memcpy(b->val, a->val, cpy_len); - return b; -} - -void barray_free(barray *array) -{ - free(array->val); - free(array); -} \ No newline at end of file diff --git a/binary/losubinary.h b/binary/losubinary.h deleted file mode 100755 index 9c6a7df89ea09db46413af9a29b74995b5bfc058..0000000000000000000000000000000000000000 --- a/binary/losubinary.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef LOSU_BINARY_H__ -#define LOSU_BINARY_H__ - - -/* - 用于为洛书提供二进制操作 -*/ - -#include -#include -#include -#include - -typedef struct { - uint8_t *val; - uint64_t length; -} barray; - -barray *barray_create(uint64_t len); -barray *barray_set(barray *array, uint8_t n); -barray *barray_change(barray *front, uint64_t len); -barray *barray_slice(barray *array, uint64_t start, uint64_t end); -uint64_t barray_length(barray* array); -uint8_t barray_get(barray *array, uint64_t index); -uint8_t *barray_getx(barray* array, uint64_t index); -uint8_t barray_insert(barray* array, uint64_t index, uint8_t n); -barray *barray_copy(barray *a, barray *b); -void barray_free(barray *array); - -#endif \ No newline at end of file diff --git a/binary/readme.md b/binary/readme.md deleted file mode 100755 index b226fe7ec4a08c14d1a053a4f3e6378a271d35bf..0000000000000000000000000000000000000000 --- a/binary/readme.md +++ /dev/null @@ -1,318 +0,0 @@ -#!/bin/owls.wiki.losu.tech -# wiki for binary - -这是一个二进制数据储存及操作模块 - -使用示例 -```python -import("binary") - -var barray = binary.create(24) #创建一个24字节大小的储存区 -barray.set(0) #将储存区数据全部设置为0 -barray.insert(0, 1) #将储存区的0索引处设置为1 -barray.insert(1, 78) #将储存区的1索引处设置为78 -barray.print() - -"""上面的输出 -0x1 0x4E 0x0 0x0 0x0 0x0 0x0 0x0 -0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 -0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 -""" - -barray.free() #储存区要手动回收内存 - -``` - -# 函数 -## binary.create(size:int): unit -创建一个大小为size字节的二进制储存区,并封装到一个洛书对象中。 -该对象有如下成员函数 - -### this.free() - -释放创建的二进制储存区,调用该成员函数后,对象会不可用。 -### this.writef(fname:str, n:int) -向名为fname的文件中写入n字节 - -### this.writem(p:ptr, n:int): int -向p指针写入n字节 - -### this.tounit(): unit -将储存区中的数据按字节转化为洛书number类型数据并储存到unit中返回 -返回的unit从1开始索引 -#### 参数 - 无 -#### 返回值 - 1. 转化而成的unit - -### this.fromunit(u): unit -接受一个unit,从1处开始索引,直至索引到null。将索引范围内所有属于number类型的数据储存到储存区中。 -对储存区中的数据每8字节转化一个number型数据 - -将会覆盖储存区原有的数据 -#### 参数 - 1. u:uint 要转化的unit -#### 返回值 - 1. 对象本身 - -### this.print(): null -将储存区中的数据按字节以16进制大写的格式打印到控制台 -#### 参数 - 无 -#### 返回值 - 1. 打印的字节数 - -### this.printfile(fname): int -将储存区中的数据按字节以16进制大写的格式写入文件 -#### 参数 - 1. fname:str 要写入的文件的名称 -#### 返回值 - 1. 写入的字节数 - -### this.prints(): str -将储存区中的数据按字节以16进制大写的格式转化成字符串并返回 -#### 参数 - 无 -#### 返回值 - 1. 转化后的字符串 - -### this.scans(s:str): unit -接受一个字符串,从里面扫描所有16进制数字并储存到储存区中。数字之间以空白字符分隔。 - -#### 参数 - 1. s:str 要被扫描的字符串 - -#### 返回值 - 调用函数的对象本身 -#### 例子 -```python -import('binary') - -var hexstr = "0xE4 0xBD 0xA0 0xE5 0xA5 0xBD 0xEF 0xBC 0x8C 0xE6 0xB4 0x9B 0xE4 0xB9 0xA6 0xEF 0xBC 0x81" - -var array = binary.create(1) -array.scans(hexstr) - -array.print() - -"""上面的输出 -0xE4 0xBD 0xA0 0xE5 0xA5 0xBD 0xEF 0xBC -0x8C 0xE6 0xB4 0x9B 0xE4 0xB9 0xA6 0xEF -0xBC 0x81 -""" - -print(array.tostr()) - -"""上面的输出 -你好,洛书! -""" - -``` - -### this.set(n:int): int -将储存区内的所有数据设置为n -#### 参数 - 1. n:int 要设置的数据 -#### 返回值 - 1. 实际设置的数据 - -### this.get(index:int, size:int): int -从储存区的指定位置读取size个字节 -1<=size<=8 - -#### 参数 - 1. i:int 索引 - 2. size:int 要读取的字节数 - -#### 返回值 - 1. 读取的字节值 - 2. 当索引越界时,返回null - -### this.insert(index:int, d:int, size:int): int -向储存区的指定位置插入size个字节 -会替换掉原本的字节 -1<=size<=8 - -#### 参数 - 1. i:int 索引 - 2. d:要插入的数据 - 3. size:int 要读取的字节数 - -#### 返回值 - 1. 实际插入的数据 - -### this.insertp(index:int, p:ptr, size:int): int -读取p指针的size个字节,插入储存区的index处 -会替换掉原本的字节 -size>=1 - -#### 参数 - 1. i:int 索引 - 2. p:要插入的指针 - 3. size:int 要读取的字节数 - -#### 返回值 - 1. 被读取的指针 - -### this.cat(b:unit): unit -在该储存区的末尾附加上b中储存区的所有数据 - -#### 参数 - 1. b 用于附加的对象 - -#### 返回值 - 1. 调用该方法的对象本身 - -### this.replace(b:unit, start:int, len:int): unit -将b中的数据从start处开始赋盖a中的数据,会覆盖len个字节 -覆盖到a的结尾处后会停止覆盖 - -#### 参数 - 1. b:ptr 用于覆盖的储存区指针 - 2. start 覆盖的起始位置 - 3. len 覆盖的字节数 - -#### 返回值 - 1. 调用函数的对象本身 - -### this.writem(p:ptr, len:int): int -将储存区的数据以指定字节数写入内存中 - -#### 参数 - 1. m:ptr 要写入的内存的指针 - 2. len:int 要写入的字节数 - -#### 返回值 - 1. 写入的实际字节数 - 2. 当len<0时,返回null - -### this.readm(p:ptr, len:int): int -从内存中读取指定字节的数据 - -#### 参数 - 1. m:ptr 要读取的内存的指针 - 2. len:int 要读取的字节数 - -#### 返回值 - 1. 调用函数的对象本身 - 2. 当len的值<=0、m为0或NULL时,返回null - -### this.writef(fname:str, len:int): int -将二进制储存区的数据写入指定的文件中 - -#### 参数 - 1. fname:str 要写入的文件的名称 - 2. len:int 要写入的字节数,缺省时为储存的数据的大小 - -#### 返回值 - 1. 写入的实际字节数 - -### this.readf(fname:str, len): unit -从文件中读取指定字节数 -原本的数据会被释放 - -#### 参数 - 1. fname:str 要读取的文件名 - 2. len:int 要读取的字节数 - - 当len缺省时,会被设置为文件大小 - -#### 返回值 - 1. 新的储存区的指针 - 2. 当打开文件失败时返回null - -### this.length(): int -返回对应储存区的大小 - -### this.copy() -将储存区复制 -不会改动原储存区的数据 - -#### 参数 - 无 - -#### 返回值 - 1. 新创建的对象 - -### this.change(len:int): int -改变储存区的大小 -在扩大后,数据会被全部复制 -在缩小后,数据会被截断 - -#### 参数 - 1. len:int 指定的大小 - -#### 返回值 - 1. 新的储存区指针 - -### this.slice(start:int, end:int): unit -将储存区切片 -start和end处的数据都将被包括 - -#### 参数 - 1. start:int 切片起始处 - 2. end:int 切片终止处 - -#### 返回值 - 1. 新创建的储存区对象 - -### this.tostr(): str -将储存区的数据直接以字符串形式返回 -会在末尾附加'\0' - -#### 参数 - 无 - -#### 返回值 - 1. 转化后的字符串 - -### this.tonum(): unit -将储存区数据转化为洛书number类型,结果储存在unit中,从1开始索引 - -#### 参数 - 无 - -#### 返回值 - 1. 返回储存结果的unit - -### this.toptr(): unit -将储存区数据转化为洛书pointer类型,结果储存在unit中,从1开始索引 - -#### 参数 - 无 - -#### 返回值 - 1. 返回储存结果的unit - -### this.fromstr(s:unit): unit -将字符串直接转化为储存区数据 -会去除末尾附加的'\0' - -#### 参数 - 1. s:str 被转化的字符串 - -#### 返回值 - 1. 新的储存区指针 - -### this.fromnum(u:unit): unit -接受一个unit,从1处开始索引,直至索引到null。将索引范围内所有属于number类型的数据储存到储存区中。 - -对储存区中的数据每8字节转化一个number型数据 - -将会覆盖储存区原有的数据 - -#### 参数 - 1. u:unit 要转化的unit - -#### 返回值 - 1. 新的储存区指针 - -## binary.hexval(s:str): number -将一个16进制的字符串转化为number类型 - -例 -```python -import('binary') - -var n = binary.valhex("0xFF") #输出为255 -``` \ No newline at end of file diff --git a/bridge/Windows/lsffi_asm_linux.S b/bridge/Windows/lsffi_asm_linux.S deleted file mode 100644 index 13a4cc016a7e37ef8b68a8aaec2d740147951893..0000000000000000000000000000000000000000 --- a/bridge/Windows/lsffi_asm_linux.S +++ /dev/null @@ -1,190 +0,0 @@ -/* -MIT License - -Copyright (c) 2023-2024 Matriller - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - - /* - 出于性能考虑,此处采用汇编代码 - */ - - .text - -/* - lsffi_cdel_intargs6 -*/ - .globl lsffi_cdel_intargs6 - .type llsffi_cdel_intargs6, @function -lsffi_cdel_intargs6: - /* - uint64_t lsffi_cdel_intargs6(uint64_t args[6], void *fun); - */ - endbr64 - movq %rdi, %rbx //将参数指针保存在rbx中 - movq %rsi, %r15 //将函数指针保存在r15中 - - //传参 - movq 0(%rbx), %rdi //第一个参数,剩下的以此类推 - movq 8(%rbx), %rsi - movq 16(%rbx), %rdx - movq 24(%rbx), %rcx - movq 36(%rbx), %r8 - movq 40(%rbx), %r9 - - call *%r15 //函数调用 - ret //返回 - - /* - 按寄存器传递的参数,传递顺序在Linux和Windows平台是不同的 - */ - -/* - uint64_numlist_reverse -*/ - -uint64_numlist_reverse: - /* - void numlist_reverse(uint64_t *num, uint64_t len); - - Linux cdel调用约定: - num参数储存在rdi中 - len参数储存在rsi中 - - 原理即交换内存实现数组反转.如有一个名为a,长度为n的int数组,用C实现如下: - for (int i = 0; i < n / 2; i ++) - { - int mid = a[i]; - a[i] = a[n - i - 1]; - a[n - i - 1] = mid; - } - - 汇编中使用三个寄存器实现这个算法 - 一是基址寄存器,用于保存数组的基址 - 二是前偏移寄存器,用于保存较小的偏移 - 三是后偏移寄存器,用于保存较大的偏移 - 每次循环时,将基址和前偏移相加,读取前数。之后将基址与后偏移相加,读取后数。 - 将前数存到后数的内存区,将后数存到前数的内存区,完成一轮交换。之后将前偏移值加8字节, - 将后偏移值加8字节。 - 循环退出的条件是前偏移地址大于等于后偏移地址。大于即n为偶数的情况,此时最中间的数不用移动。 - 等于即n为奇数的情况,此时所有数均已交换,并且没有最中间的数。 - */ - endbr64 //Linux程序中得有这行代码 - - cmp $0, %rsi //检查len参数是否为0,是则直接返回函数 - je ..LUINT64_NUMLIST_REVERSE_L1_END - - /* - 这段代码中的基址寄存器是rdi,前偏移寄存器是rcx,后偏移寄存器是rsi - */ - - dec %rsi //%rsi中储存着len参数 - imulq $8, %rsi //这一条指令和上一条是在计算最后一个数字的偏移量,减去1是避免差一错误 - movq $0, %rcx //rcx用于计数 -.LUINT64_NUMLIST_REVERSE_L1: - movq (%rdi, %rcx), %r14 //读取前数 - movq (%rdi, %rsi), %r15 //读取后数 - movq %r15, (%rdi, %rcx) //后数存至前数内存区域 - movq %r14, (%rdi, %rsi) //前数存至后数内存区域 - addq $8, %rcx //前偏移地址加8字节 - subq $8, %rsi //后偏移地址减8字节 - cmp %rsi, %rcx //比较前指针和后指针的值,如果前指针大于或等于后指针,则 - jl .LUINT64_NUMLIST_REVERSE_L1 -..LUINT64_NUMLIST_REVERSE_L1_END: - ret - -/* - lsffi_cdel_intargsx__维护须知 - 1. 在amd64计算机中,无论整形参数长度如何,都使用pushq,即压入8字节 - 2. 在ret之前,要调用leave清理栈桢 - 3. 在leave之前,要将rsp加上向栈中压入的参数的总字节数,即压入的参数的8倍 - 4. leave命令之前不可删去pushq %rbp和movq %rsp, %rbp两条指令,会导致程序异常 -*/ - - .globl lsffi_cdel_intargsx__ - .type lsffi_cdel_intargsx__, @function -lsffi_cdel_intargsx__: - /* - uint64_t lsffi_cdel_intargsx(uint64_t args[6], uint64_t *eargs, void *fun, uint64_t len); - */ - endbr64 - pushq %rbp - movq %rsp, %rbp - - movq %rdi, %r10 //r10保存前6个参数指针 - movq %rsi, %r11 //r11保存其余参数指针 - movq %rdx, %r12 //r12保存函数指针 - movq %rcx, %r13 //r13保存其余参数个数 - - //调用uint64_numlist_reverse函数 - movq %r11, %rdi //要反转的数组基址 - movq %r13, %rsi //元素个数 - call uint64_numlist_reverse //函数调用 - - //压栈传入的参数 - movq %r13, %rcx - movq $0, %r14 //相对r11的寻址偏移 -.L1: - movq (%r11, %r14), %r15 - pushq %r15 - addq $8, %r14 //每循环一次,r14加8字节,即相对r11多偏移8字节,即访问下一个64位数 - loop .L1 - - //按寄存器传递的参数 - movq 0(%r10), %rdi //第一个参数,剩下的以此类推 - movq 8(%r10), %rsi - movq 16(%r10), %rdx - movq 24(%r10), %rcx - movq 32(%r10), %r8 - movq 40(%r10), %r9 - call *%r12 //函数调用 - - //清理栈桢 - imulq $8, %r13 //计算压栈传参的字节数 - addq %r13, %rsp //向rsp加上该字节数 - leave //清理栈桢 - ret //函数返回 - - -/* - lsffi_cdel_floatargs8 -*/ - - .globl lsffi_cdel_floatargs8 - .type lsffi_cdel_floatargs8, @function -lsffi_cdel_floatargs8: - endbr64 - //保存数据 - movq %rdi, %rbx //rbx存储参数指针 - movq %rsi, %rax //rax存储函数指针 - - //传参 - movq 56(%rbx), %xmm7 - movq 48(%rbx), %xmm6 - movq 40(%rbx), %xmm5 - movq 32(%rbx), %xmm4 - movq 24(%rbx), %xmm3 - movq 16(%rbx), %xmm2 - movq 8(%rbx), %xmm1 - movq 0(%rbx), %xmm0 - - //函数调用 - call *%rax - ret diff --git a/bridge/Windows/lsffi_asm_win.S b/bridge/Windows/lsffi_asm_win.S deleted file mode 100644 index 36073c87f762d021c94a1a44966fb6f737252134..0000000000000000000000000000000000000000 --- a/bridge/Windows/lsffi_asm_win.S +++ /dev/null @@ -1,176 +0,0 @@ -/* -MIT License - -Copyright (c) 2023-2024 Matriller - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - .text - .globl lsffi_cdel_intargs6 -lsffi_cdel_intargs6: - movq %rcx, %rbx //rbx保存前6个参数指针 - movq %rdx, %r11 //r11保存函数指针 - - movq 0(%rbx), %rcx - movq 8(%rbx), %rdx - movq 16(%rbx), %r8 - movq 24(%rbx), %r9 - - movq 32(%rbx), %r12 //X86架构不允许内存直接直接传递数据 - movq %r12, -16(%rsp) - movq 40(%rbx), %r12 - movq %r12, -8(%rsp) - - subq $48, %rsp - call *%r11 - addq $48, %rsp - - ret - -uint64_numlist_reverse: - /* - void numlist_reverse(uint64_t *num, uint64_t len); - - Linux cdel调用约定: - num参数储存在rdi中 - len参数储存在rsi中 - - 原理即交换内存实现数组反转.如有一个名为a,长度为n的int数组,用C实现如下: - for (int i = 0; i < n / 2; i ++) - { - int mid = a[i]; - a[i] = a[n - i - 1]; - a[n - i - 1] = mid; - } - - 汇编中使用三个寄存器实现这个算法 - 一是基址寄存器,用于保存数组的基址 - 二是前偏移寄存器,用于保存较小的偏移 - 三是后偏移寄存器,用于保存较大的偏移 - 每次循环时,将基址和前偏移相加,读取前数。之后将基址与后偏移相加,读取后数。 - 将前数存到后数的内存区,将后数存到前数的内存区,完成一轮交换。之后将前偏移值加8字节, - 将后偏移值加8字节。 - 循环退出的条件是前偏移地址大于等于后偏移地址。大于即n为偶数的情况,此时最中间的数不用移动。 - 等于即n为奇数的情况,此时所有数均已交换,并且没有最中间的数。 - */ - cmp $0, %rsi //检查len参数是否为0,是则直接返回函数 - je .LUINT64_NUMLIST_REVERSE_L1_END - - /* - 这段代码中的基址寄存器是rdi,前偏移寄存器是rcx,后偏移寄存器是rsi - */ - - dec %rsi //%rsi中储存着len参数 - imulq $8, %rsi //这一条指令和上一条是在计算最后一个数字的偏移量,减去1是避免差一错误 - movq $0, %rcx //rcx用于计数 -.LUINT64_NUMLIST_REVERSE_L1: - movq (%rdi, %rcx), %r14 //读取前数 - movq (%rdi, %rsi), %r15 //读取后数 - movq %r15, (%rdi, %rcx) //后数存至前数内存区域 - movq %r14, (%rdi, %rsi) //前数存至后数内存区域 - addq $8, %rcx //前偏移地址加8字节 - subq $8, %rsi //后偏移地址减8字节 - cmp %rsi, %rcx //比较前指针和后指针的值,如果前指针大于或等于后指针,则 - jl .LUINT64_NUMLIST_REVERSE_L1 -.LUINT64_NUMLIST_REVERSE_L1_END: - ret - - - .globl lsffi_cdel_intargsx__ -lsffi_cdel_intargsx__: - movq %rcx, %rbx //rbx保存前6个参数指针 - movq %rdx, %r10 //r10保存其余参数指针 - movq %r8, %r11 //r11保存函数指针 - movq %r9, %r12 //r12保存其余参数个数 - - //调用uint64_numlist_reverse函数 - movq %r10, %rdi - movq %r12, %rsi - call uint64_numlist_reverse - - //调整rsp位置 - movq $6, %r15 - addq %r12, %r15 - imulq $8, %r15 - subq %r15, %rsp - - //检查是否有要通过栈传递的参数 - cmp $0, %r12 - je .L1_END - - //通过栈传递参数 - movq %r12, %rcx - movq $0, %r13 //相对r10的参数寻址偏移 - movq %r15, %r14 //参数的目的偏移,即在栈中的偏移 -.L1: - movq (%r10, %r13), %rdx //从内存读取参数 - addq $8, %r13 //增加参数的源内存偏移 - subq $8, %r14 - movq %rdx, (%rsp, %r14) //将参数移入栈中 - loop .L1 //循环 -.L1_END: - - //按寄存器传递的参数 - movq 0(%rbx), %rcx - movq 8(%rbx), %rdx - movq 16(%rbx), %r8 - movq 24(%rbx), %r9 - - movq 32(%rbx), %r12 //X86架构不允许内存直接直接传递数据 - movq %r12, 32(%rsp) - movq 40(%rbx), %r12 - movq %r12, 40(%rsp) - - call *%r11 //函数调用 - addq %r15, %rsp //恢复栈桢 - - ret - -/* - lsffi_cdel_floatargs8 -*/ - - .globl lsffi_cdel_floatargs8 -lsffi_cdel_floatargs8: - //保存数据 - movq %rcx, %rbx //rbx存储参数指针 - movq %rdx, %r10 //r10存储函数指针 - - //传参 - movq 56(%rbx), %xmm7 - movq 48(%rbx), %xmm6 - movq 40(%rbx), %xmm5 - movq 32(%rbx), %xmm4 - movq 24(%rbx), %xmm3 - movq 16(%rbx), %xmm2 - movq 8(%rbx), %xmm1 - movq 0(%rbx), %xmm0 - - movq %r10, %rax - - //调整栈帧 - subq $64, %rsp - - //函数调用 - call *%r10 - - //调整栈帧 - addq $64, %rsp - - ret diff --git a/bridge/Windows/makefile b/bridge/Windows/makefile deleted file mode 100644 index 16bb0a515966e8e0844a4dea0d1a4c52aff9e2ee..0000000000000000000000000000000000000000 --- a/bridge/Windows/makefile +++ /dev/null @@ -1,11 +0,0 @@ -T = ElsLib_bridge.lsd -CFLAGS = -O2 -std=c99 -DELS_CONF_OS_WINDOWS -I ../buildenv -L ../buildenv -fPIC -s -l:libeasylosu.dll -CPPFLAGS = -O3 -std=c++11 -DELS_CONF_OS_WINDOWS -I ./include -I ../buildenv - -all: $T - -$T: - gcc lsffi.c lsffi_asm_win.S bridge.c -o $(T) -shared $(CFLAGS) - -clean: - rm *.o diff --git a/bridge/bridge.c b/bridge/bridge.c deleted file mode 100644 index 3d3273a09d6e1e89e01571781c1e4399908bdbe0..0000000000000000000000000000000000000000 --- a/bridge/bridge.c +++ /dev/null @@ -1,303 +0,0 @@ -#include "els.h" -#include "bridge.h" -#include "lsffi.h" - -#include -#include -#include - -#define unit_arg(x) x+1 - -static double lsptr_to_c(els_VmObj *vm, LosuObj *p) -{ - double output; - void *ptr = obj_toptr(vm, p); - output = *((double*)&ptr); - return output; -} - -// int - -int ELSAPI_bridge_bridge_c_cint8(els_VmObj* vm) // bridge_c_cint8() -{ - LosuObj output; - int type = arg_gettype(vm, unit_arg(1)); - - if (type == ELS_API_TYPE_NUMBER) - { - int64_t n = (int8_t)arg_getnum(vm, unit_arg(1)); - output = obj_newbyte(vm, (char*)&n, 8); - } - else if (type == ELS_API_TYPE_PTR) - { - output = obj_newnum(vm, lsptr_to_c(vm, arg_get(vm, unit_arg(1)))); - } - else - { - output = obj_newnull(vm); - } - - arg_return(vm, output); - - return 1; -} - -int ELSAPI_bridge_bridge_c_cint16(els_VmObj* vm) // bridge_c_cint16() -{ - LosuObj output; - int type = arg_gettype(vm, unit_arg(1)); - - if (type == ELS_API_TYPE_NUMBER) - { - int64_t n = (int16_t)arg_getnum(vm, unit_arg(1)); - output = obj_newbyte(vm, (char*)&n, 8); - } - else if (type == ELS_API_TYPE_PTR) - { - output = obj_newnum(vm, lsptr_to_c(vm, arg_get(vm, unit_arg(1)))); - } - else - { - output = obj_newnull(vm); - } - - arg_return(vm, output); - - return 1; -} - -int ELSAPI_bridge_bridge_c_cint32(els_VmObj* vm) // bridge_c_cint32() -{ - LosuObj output; - int type = arg_gettype(vm, unit_arg(1)); - - if (type == ELS_API_TYPE_NUMBER) - { - int64_t n = (int32_t)arg_getnum(vm, unit_arg(1)); - output = obj_newbyte(vm, (char*)&n, 8); - } - else if (type == ELS_API_TYPE_PTR) - { - output = obj_newnum(vm, lsptr_to_c(vm, arg_get(vm, unit_arg(1)))); - } - else - { - output = obj_newnull(vm); - } - - arg_return(vm, output); - - return 1; -} - -int ELSAPI_bridge_bridge_c_cint64(els_VmObj* vm) // bridge_c_cint64() -{ - LosuObj output; - int type = arg_gettype(vm, unit_arg(1)); - - if (type == ELS_API_TYPE_NUMBER) - { - int64_t n = (int64_t)arg_getnum(vm, unit_arg(1)); - output = obj_newbyte(vm, (char*)&n, 8); - } - else if (type == ELS_API_TYPE_PTR) - { - output = obj_newnum(vm, lsptr_to_c(vm, arg_get(vm, unit_arg(1)))); - } - else - { - output = obj_newnull(vm); - } - - arg_return(vm, output); - - return 1; -} - -// float - -int ELSAPI_bridge_bridge_c_cfloat32(els_VmObj* vm) // bridge_c_cint8() -{ - LosuObj output; - int type = arg_gettype(vm, unit_arg(1)); - - if (type == ELS_API_TYPE_NUMBER) - { - float n = arg_getnum(vm, unit_arg(1)); - uint64_t tmp = *((uint64_t*)&n); - output = obj_newbyte(vm, (char*)&n, 8); - } - else if (type == ELS_API_TYPE_PTR) - { - output = obj_newnum(vm, lsptr_to_c(vm, arg_get(vm, unit_arg(1)))); - } - else - { - output = obj_newnull(vm); - } - - arg_return(vm, output); - - return 1; -} - -int ELSAPI_bridge_bridge_c_cfloat64(els_VmObj* vm) // bridge_c_cint8() -{ - LosuObj output; - int type = arg_gettype(vm, unit_arg(1)); - - if (type == ELS_API_TYPE_NUMBER) - { - double n = arg_getnum(vm, unit_arg(1)); - output = obj_newbyte(vm, (char*)&n, 8); - } - else if (type == ELS_API_TYPE_PTR) - { - output = obj_newnum(vm, lsptr_to_c(vm, arg_get(vm, unit_arg(1)))); - } - else - { - output = obj_newnull(vm); - } - - arg_return(vm, output); - - return 1; -} - -// string - -int ELSAPI_bridge_bridge_c_cstr(els_VmObj* vm) // bridge_c_cint8() -{ - LosuObj output; - int type = arg_gettype(vm, unit_arg(1)); - - if (type == ELS_API_TYPE_STRING) - { - char* p = (char*)arg_getstr(vm, unit_arg(1)); - output = obj_newbyte(vm, (char*)&p, 8); - } - else if (type == ELS_API_TYPE_PTR) - { - output = obj_newnum(vm, lsptr_to_c(vm, arg_get(vm, unit_arg(1)))); - } - else - { - output = obj_newnull(vm); - } - - arg_return(vm, output); - - return 1; -} - -// ptr -int ELSAPI_bridge_bridge_c_cptr(els_VmObj* vm) // bridge_c_cint8() -{ - LosuObj output; - int type = arg_gettype(vm, unit_arg(1)); - - if (type == ELS_API_TYPE_STRING) - { - char* p = (char*)arg_getstr(vm, unit_arg(1)); - output = obj_newbyte(vm, (char*)&p, 8); - } - else if (type == ELS_API_TYPE_BYTE) - { - char* p = (char*)arg_getbyte(vm, unit_arg(1)); - output = obj_newbyte(vm, (char*)&p, 8); - } - else if (type == ELS_API_TYPE_PTR) - { - char* p = (char*)arg_getptr(vm, unit_arg(1)); - output = obj_newbyte(vm, (char*)&p, 8); - } - else - { - output = obj_newnull(vm); - } - - arg_return(vm, output); - - return 1; -} - -int ELSAPI_bridge_bridge_c_iif(els_VmObj* vm) // bridge_c_iaf() #int arg function -{ - /* - 多参函数 - 第一个参数恒为ptr类型的c函数指针 - 其余参数均为number类型的参数 - */ - uint32_t argn = arg_num(vm) - 1; - char __tmp[8]; - LosuObj loutput = obj_newbyte(vm, (char*)__tmp, 8); - uint64_t *output = (uint64_t*)obj_tobyte(vm, &loutput); - arg_return(vm, loutput); - - switch (argn) - { - case 0: - { - arg_returnnull(vm); - return 1; - } - case 1: - { - uint64_t args[6] = {0}; - void *fp = arg_getptr(vm, unit_arg(1)); - *output = lsffi_cdel_intargs6(args, fp); - - arg_return(vm, loutput); - return 1; - } - default: - { - void *fp = arg_getptr(vm, unit_arg(1)); - - argn--; - - //函数调用 - if (argn <= 6) - { - uint64_t args[6] = {0}; - - //参数传递 - for (int i = 0; i < argn; i ++) - { - if (arg_gettype(vm, i + 3) != ELS_API_TYPE_BYTE) - { - return 0; - } - - void *p = (void*)arg_getbyte(vm, i + 3); - args[i] = *((uint64_t*)p); - } - - *output = lsffi_cdel_intargs6(args, fp); - } - else - { - uint64_t *args = malloc(sizeof(uint64_t) * argn); - //参数传递 - - for (int i = 0; i < argn; i ++) - { - if (arg_gettype(vm, i + 3) != ELS_API_TYPE_BYTE) - { - return 0; - } - - void *p = (void*)arg_getbyte(vm, i + 3); - args[i] = *((uint64_t*)p); - } - - *output = lsffi_cdel_intargsx(args, args + 6, fp, argn - 6); - free(args); - } - - } - } - - return 1; -} diff --git a/bridge/bridge.els b/bridge/bridge.els deleted file mode 100644 index 1f9c74e9da574867d24f21b59fa4f120d436af73..0000000000000000000000000000000000000000 --- a/bridge/bridge.els +++ /dev/null @@ -1,45 +0,0 @@ -#!declare - -bridge_c_cint8() -bridge_c_cint16() -bridge_c_cint32() -bridge_c_cint64() - -bridge_c_cfloat32() -bridge_c_cfloat64() - -bridge_c_cstr() -bridge_c_cptr() - -bridge_c_iif(...) #int output int arg function - -#!end - -#!script - -var bridge = { - -} - -bridge.c = { - #从洛书数据类型转换到C数据类型 - int = bridge_c_cint32, - int8 = bridge_c_cint8, - int16 = bridge_c_cint16, - int32 = bridge_c_cint32, - int64 = bridge_c_cint64, - char = bridge_c_cint8, - short = bridge_c_cint16, - float32 = bridge_c_cfloat32, - float64 = bridge_c_cfloat64, - float = bridge_c_cfloat32, - double = bridge_c_cfloat64, - str = bridge_c_cstr, - ptr = bridge_c_cptr, - - #接口函数 - iif = bridge_c_iif, #int返回值、int参数的函数(int int function) -} - -#!end - diff --git a/bridge/bridge.h b/bridge/bridge.h deleted file mode 100644 index 9b388cc6cae386142803c55c5daaee256cb2c798..0000000000000000000000000000000000000000 --- a/bridge/bridge.h +++ /dev/null @@ -1,43 +0,0 @@ -#include "els.h" -int ELSAPI_bridge_bridge_c_cint8(els_VmObj* vm); // bridge_c_cint8() -int ELSAPI_bridge_bridge_c_cint16(els_VmObj* vm); // bridge_c_cint16() -int ELSAPI_bridge_bridge_c_cint32(els_VmObj* vm); // bridge_c_cint32() -int ELSAPI_bridge_bridge_c_cint64(els_VmObj* vm); // bridge_c_cint64() -int ELSAPI_bridge_bridge_c_cfloat32(els_VmObj* vm); // bridge_c_cfloat32() -int ELSAPI_bridge_bridge_c_cfloat64(els_VmObj* vm); // bridge_c_cfloat64() -int ELSAPI_bridge_bridge_c_cstr(els_VmObj* vm); // bridge_c_cstr() -int ELSAPI_bridge_bridge_c_iif(els_VmObj* vm); // bridge_c_iif(...) #int output int arg function -#ifdef ELS_CONF_TOKEN_EN -static const char LibScript[]={ -10, -118,97,114,32,98,114,105,100,103,101,32,61,32,123,10, -10, -125,10, -10, -98,114,105,100,103,101,46,99,32,61,32,123,10, -32,32,32,32,105,110,116,32,61,32,98,114,105,100,103,101,95,99,95,99,105,110,116,51,50,44,10, -32,32,32,32,105,110,116,56,32,61,32,98,114,105,100,103,101,95,99,95,99,105,110,116,56,44,10, -32,32,32,32,105,110,116,49,54,32,61,32,98,114,105,100,103,101,95,99,95,99,105,110,116,49,54,44,10, -32,32,32,32,105,110,116,51,50,32,61,32,98,114,105,100,103,101,95,99,95,99,105,110,116,51,50,44,10, -32,32,32,32,105,110,116,54,52,32,61,32,98,114,105,100,103,101,95,99,95,99,105,110,116,54,52,44,10, -32,32,32,32,102,108,111,97,116,51,50,32,61,32,98,114,105,100,103,101,95,99,95,99,102,108,111,97,116,51,50,44,10, -32,32,32,32,102,108,111,97,116,54,52,32,61,32,98,114,105,100,103,101,95,99,95,99,102,108,111,97,116,54,52,44,10, -32,32,32,32,115,116,114,32,61,32,98,114,105,100,103,101,95,99,95,99,115,116,114,44,10, -32,32,32,32,105,105,102,32,61,32,98,114,105,100,103,101,95,99,95,105,105,102,44,10, -125,10, -10, -0}; -#endif -void ElsLib_bridge_libinit(els_VmObj *vm){ - vm_register(vm,"bridge_c_cint16",ELSAPI_bridge_bridge_c_cint16); - vm_register(vm,"bridge_c_cint8",ELSAPI_bridge_bridge_c_cint8); - vm_register(vm,"bridge_c_cstr",ELSAPI_bridge_bridge_c_cstr); - vm_register(vm,"bridge_c_cfloat32",ELSAPI_bridge_bridge_c_cfloat32); - vm_register(vm,"bridge_c_cint32",ELSAPI_bridge_bridge_c_cint32); - vm_register(vm,"bridge_c_cfloat64",ELSAPI_bridge_bridge_c_cfloat64); - vm_register(vm,"bridge_c_iif",ELSAPI_bridge_bridge_c_iif); - vm_register(vm,"bridge_c_cint64",ELSAPI_bridge_bridge_c_cint64); - #ifdef ELS_CONF_TOKEN_EN - vm_dostring(vm,LibScript); - #endif -}; diff --git a/bridge/demo.els b/bridge/demo.els deleted file mode 100644 index 4d2c5dfef81423c3ae43d60d69e50fc43397e4dc..0000000000000000000000000000000000000000 --- a/bridge/demo.els +++ /dev/null @@ -1,13 +0,0 @@ -import "xkit" -import "bridge" - -var lib = xkit.system.sharedlib.load("demo.dll") -var fp = xkit.system.sharedlib.getprocaddress(lib, "puts") - -var n = bridge.c.int32(9) -xkit.system.io.println(n) - -var res = bridge.c.iif(fp, n) -var res = bridge.c.iif(fp, res) - -print("finish..") diff --git a/bridge/info b/bridge/info deleted file mode 100644 index 88efee1ec7a8b601262db990f07e35d56566ac59..0000000000000000000000000000000000000000 --- a/bridge/info +++ /dev/null @@ -1,28 +0,0 @@ -{ - type = "normal", - info = { - name = "bridge", - text = "洛书的其他语言接口", - version = "24.3.31" - }, - source = { - all = { - "info", - "bridge.c", - "bridge.h", - "bridge.els", - "demo.els", - "lsffi.c", - "lsffi.h", - "readme.md", - }, - Windows ={ - "makefile", - "lsffi_asm_linux.S", - "lsffi_asm_win.S" - }, - }, - target={ - Windows = "make ; cp ElsLib_bridge.lsd target/ElsLib_bridge.lsd_Windows ; make clean", - } -} diff --git a/bridge/lsffi.c b/bridge/lsffi.c deleted file mode 100644 index b84914b4d5ac419aaedae8e147f9800e6f4d1427..0000000000000000000000000000000000000000 --- a/bridge/lsffi.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "lsffi.h" - -extern uint64_t lsffi_cdel_intargsx__(uint64_t args[6], uint64_t *eargs, void *fun, uint64_t len); - -uint64_t lsffi_cdel_intargsx(uint64_t args[6], uint64_t *eargs, void *fun, uint64_t len) -{ - return lsffi_cdel_intargsx__(args, eargs, fun, len); -} diff --git a/bridge/lsffi.h b/bridge/lsffi.h deleted file mode 100644 index 65710746636ae931358297980ba7ef5eed2bba40..0000000000000000000000000000000000000000 --- a/bridge/lsffi.h +++ /dev/null @@ -1,87 +0,0 @@ -#ifndef LSFFI_H_ -#define LSFFI_H_ - -#include - -#define LSFFI_INTRET 0 -#define LSFFI_FLOATRET 1 - -/* - CDEL部分 - - CDEL在Linux的整形传参顺序: - 参数顺序(按C语言参数列表顺序从左到右) 传入的寄存器 - 1 rdi - 2 rsi - 3 rdx - 4 rcx - 5 r8 - 6 r9 - - 6个以上参数通过压栈传递,而且是从右自左压栈 - 如有如下几个要压栈的参数,...是前6个传入寄存器的参数 - (... , 1, 2, 3) - 汇编压栈方式如下 - pushq $3 - pushq $2 - pushq $1 - 这样函数在用pop将参数从栈中弹出时,就会将参数顺序恢复到自左向右的状态 - - CDEL在Windows的整形传参顺序: - 参数顺序(按C语言参数列表顺序从左到右) 传入的寄存器 - 1 rcx - 2 rdx - 3 r8 - 4 r9 - - 在Windows平台下,CDEL只有前面4个参数是传入寄存器的,其余参数均传入栈中 - Windows平台要求函数调用者调整栈帧位置并传参。如传递如下参数 - (1, 2, 3, 4, 5, 6) - 对应汇编代码如下 - subq $48, %rsp //调整栈帧位置,即将栈帧减去参数的总字节数,包括传入寄存器的参数 - - movq $40, 16(%rsp) //栈帧自上往下递增,即内存地址在递减 - movq $32, 8(%rsp) - movq $4, %r9 - movq $3, %r8 - movq $2, %rdx - movq $1, %rcx - - call FUNCTION //假设有一个叫FUNCTION的函数 - addq $48, %rsp //在函数结尾,函数要恢复栈帧 - ret //函数返回 -*/ - -uint64_t lsffi_cdel_intargs6(uint64_t args[6], void *fun); -/* - 此函数用于Linux cdel的整形传参,且最多传参数为6个 - - @arg args: - 要传入的参数,是一个长度为6的64位整形数组,不一定是无符号类型 - @arg fun: - 要调用的函数指针 - - @output: - 会将fun的值当做函数指针来调用,返回值即该函数的返回值 -*/ - -uint64_t lsffi_cdel_intargsx(uint64_t args[6], uint64_t *eargs, void *fun, uint64_t len); -/* - 此函数用于Linux cdel的整形传参,无参数传递上限。 - - @arg args: - 要传入的参数,是一个长度为6的64位整形数组,不一定是无符号类型 - @arg eargs: - 额外的参数,当len不为空时才会被使用 - @arg fun: - 要调用的函数指针 - @arg len: - 额外参数的个数,当无额外参数时需要设为0,否则会引发错误 - - @output: - 会将fun的值当做函数指针来调用,返回值即该函数的返回值 -*/ - -double lsffi_cdel_floatargs8(double args[8], void *fun); - -#endif \ No newline at end of file diff --git a/bridge/readme.md b/bridge/readme.md deleted file mode 100644 index 3bd37828f7d13d85886324df448d4fad37dce7a2..0000000000000000000000000000000000000000 --- a/bridge/readme.md +++ /dev/null @@ -1,54 +0,0 @@ -# bridge模块文档 - -```python -bridge.c = { - #从洛书数据类型转换到C数据类型 - int = bridge_c_cint32, - int8 = bridge_c_cint8, - int16 = bridge_c_cint16, - int32 = bridge_c_cint32, - int64 = bridge_c_cint64, - char = bridge_c_cint8, - short = bridge_c_cint16, - float32 = bridge_c_cfloat32, - float64 = bridge_c_cfloat64, - float = bridge_c_cfloat32, - double = bridge_c_cfloat64, - str = bridge_c_cstr, - ptr = bridge_c_cptr, - - #接口函数 - iif = bridge_c_iif, #int返回值、int参数的函数(int int function) -} -``` - - -例程(Windows): - -```python -""" - 使用printf进行格式化输出 -""" - -import "bridge" -import "sharedlib" - -var lib = sharedlib.load("C:\\Windows\\System32\\msvcrt.dll") #加载动态库 -var function = sharedlib.sys(lib, "printf") #获取printf函数 - -#将洛书类型转换为C类型 -var pattern = bridge.c.str("str:\%s, number:\%d\n") -var s = bridge.c.str("Hello losu!") -var n = bridge.c.int(1024) - -#函数调用 -bridge.c.iif(function, pattern, s, n) - - -``` - -最后的输出 - -```shell -str:Hello losu!, number:1024 -``` \ No newline at end of file diff --git a/bytemaster/Windows/makefile b/bytemaster/Windows/makefile deleted file mode 100644 index 4ee859aa8bc295b02acc550b21efb649ef26542e..0000000000000000000000000000000000000000 --- a/bytemaster/Windows/makefile +++ /dev/null @@ -1,11 +0,0 @@ -T = ElsLib_bytemaster.lsd -CFLAGS = -O2 -std=c99 -DELS_CONF_OS_WINDOWS -I ../buildenv -L ../buildenv -fPIC -s -l:libeasylosu.dll -CPPFLAGS = -O3 -std=c++11 -DELS_CONF_OS_WINDOWS -I ./include -I ../buildenv - -all: $T - -$T: - gcc bytemaster.c -o $(T) -shared $(CFLAGS) - -clean: - rm *.o diff --git a/bytemaster/bytemaster.c b/bytemaster/bytemaster.c deleted file mode 100644 index 2e6b6454c102403a951ad3c834f1dfd06ca21a01..0000000000000000000000000000000000000000 --- a/bytemaster/bytemaster.c +++ /dev/null @@ -1,63 +0,0 @@ -#include "bytemaster.h" - -#include -#include - -#define unit_arg(x) x+1 -#define unit_atype(vm, x) arg_gettype(vm, x+1) - -int ELSAPI_bytemaster_bytemaster_alloc(els_VmObj* vm) // mem_alloc(length:int) -{ - int type = arg_gettype(vm, unit_arg(1)); - - if (type == ELS_API_TYPE_NUMBER) - { - size_t l = arg_getnum(vm, unit_arg(1)); - void *m = calloc(l, sizeof(char)); - arg_returnbyte(vm, m, l); - free(m); - } - else - arg_returnnull(vm); - return 1; -} - -int ELSAPI_bytemaster_bytemaster_write(els_VmObj* vm) // mem_write(m:byte, index:int, data:[int/byte/str]) -{ - if (unit_atype(vm, 1) == ELS_API_TYPE_BYTE && unit_atype(vm, 2) == ELS_API_TYPE_NUMBER && unit_atype(vm, 3) != ELS_API_TYPE_NULL) - { - char *m = (char*)arg_getbyte(vm, unit_arg(1)); - size_t index = arg_getnum(vm, unit_arg(2)); - - if (unit_atype(vm, 3) == ELS_API_TYPE_NUMBER) - { - char ch = arg_getnum(vm, unit_arg(3)); - m[index] = ch; - } - else if (unit_atype(vm, 3) == ELS_API_TYPE_STRING) - { - const char *s = arg_getstr(vm, unit_arg(3)); - sprintf(m + index, "%s", s); - } - - arg_return(vm, *arg_get(vm, unit_arg(1))); - } - else - arg_returnnull(vm); - return 1; -} - -int ELSAPI_bytemaster_bytemaster_read(els_VmObj* vm) // bytemaster_read(m:byte, index:int, size:int) -{ - if (unit_atype(vm, 1) == ELS_API_TYPE_BYTE && unit_atype(vm, 2) == ELS_API_TYPE_NUMBER && unit_atype(vm, 3) == ELS_API_TYPE_NUMBER) - { - char *m = (char*)arg_getbyte(vm, unit_arg(1)); - size_t index = arg_getnum(vm, unit_arg(2)); - size_t msize = arg_getnum(vm, unit_arg(3)); - - arg_returnbyte(vm, m + index, msize); - } - else - arg_returnnull(vm); - return 1; -} diff --git a/bytemaster/bytemaster.els b/bytemaster/bytemaster.els deleted file mode 100644 index 97ad388956eb5a1ae94e56418e492721e1025cc0..0000000000000000000000000000000000000000 --- a/bytemaster/bytemaster.els +++ /dev/null @@ -1,17 +0,0 @@ -#!declare - -bytemaster_alloc(length:int) -bytemaster_write(m:byte, index:int, data:[int/byte/str]) -bytemaster_read(m:byte, index:int, size:int) - -#!end - -#!script - -var bytemaster = { - alloc = bytemaster_alloc, - write = bytemaster_write, - read = bytemaster_read -} - -#!end diff --git a/bytemaster/bytemaster.h b/bytemaster/bytemaster.h deleted file mode 100644 index ca99167c155e1e5b3e429fcd934e06436f6df5df..0000000000000000000000000000000000000000 --- a/bytemaster/bytemaster.h +++ /dev/null @@ -1,23 +0,0 @@ -#include "els.h" -int ELSAPI_bytemaster_bytemaster_alloc(els_VmObj* vm); // bytemaster_alloc(length:int) -int ELSAPI_bytemaster_bytemaster_write(els_VmObj* vm); // bytemaster_write(m:byte, index:int, data:[int/byte/str]) -int ELSAPI_bytemaster_bytemaster_read(els_VmObj* vm); // bytemaster_read(m:byte, index:int, size:int) -#ifdef ELS_CONF_TOKEN_EN -static const char LibScript[]={ -10, -118,97,114,32,98,121,116,101,109,97,115,116,101,114,32,61,32,123,10, -32,32,32,32,97,108,108,111,99,32,61,32,98,121,116,101,109,97,115,116,101,114,95,97,108,108,111,99,44,10, -32,32,32,32,119,114,105,116,101,32,61,32,98,121,116,101,109,97,115,116,101,114,95,119,114,105,116,101,44,10, -32,32,32,32,114,101,97,100,32,61,32,98,121,116,101,109,97,115,116,101,114,95,114,101,97,100,10, -125,10, -10, -0}; -#endif -void ElsLib_bytemaster_libinit(els_VmObj *vm){ - vm_register(vm,"bytemaster_read",ELSAPI_bytemaster_bytemaster_read); - vm_register(vm,"bytemaster_write",ELSAPI_bytemaster_bytemaster_write); - vm_register(vm,"bytemaster_alloc",ELSAPI_bytemaster_bytemaster_alloc); - #ifdef ELS_CONF_TOKEN_EN - vm_dostring(vm,LibScript); - #endif -}; diff --git a/bytemaster/demo.els b/bytemaster/demo.els deleted file mode 100644 index a90118786f71181800acf4cf4c96a9ce3837e575..0000000000000000000000000000000000000000 --- a/bytemaster/demo.els +++ /dev/null @@ -1,6 +0,0 @@ -import "bytemaster" -var a = bytemaster.alloc(32) -bytemaster.write(a, 3, "Hello world!") -var s = byte.tostr(bytemaster.read(null, a, 3, length("Hello world!"))) -print(s) - diff --git a/bytemaster/info b/bytemaster/info deleted file mode 100644 index b9733d891de776141a098f125bf3acdad07bfe5c..0000000000000000000000000000000000000000 --- a/bytemaster/info +++ /dev/null @@ -1,24 +0,0 @@ -{ - type = "normal", - info = { - name = "bytemaster", - text = "洛书的byte操作库", - version = "24.4.4" - }, - source = { - all = { - "info", - "bytemaster.c", - "bytemaster.h", - "bytemaster.els", - "demo.els", - "readme.md", - }, - Windows ={ - "makefile", - }, - }, - target={ - Windows = "make ; cp ElsLib_bytemaster.lsd target/ElsLib_bytemaster.lsd_Windows ; make clean", - } -} diff --git a/bytemaster/readme.md b/bytemaster/readme.md deleted file mode 100644 index 836c69c09fc53c3bb1be8ebeb248df5b17f622ac..0000000000000000000000000000000000000000 --- a/bytemaster/readme.md +++ /dev/null @@ -1,30 +0,0 @@ -# bytemaster模块文档 - -bytemaster是一个byte操作库,用于在脚本层面对byte进行类似c的操作。 - -## 函数列表 - -### bytemaster.alloc - -bytemaster.alloc(length:int) - -分配一块长为length的内存,以byte形式返回。 - -### bytemaster.write - -bytemaster.write(m:byte, index:int, data:[int/byte/str]) - -对byte类型数据m,从第index号偏移起,写入data。 - -当data类型为int时,被转换为char。当data类型为byte时,当前版本不做处理。当data类型为str时,将字符串整个写入。 - -### bytemaster.read - -bytemaster.read(m:byte, index:int, size:int) - -对byte类型数据m,从第index号偏移起,读取size个字节,以byte形式返回。 - -## 贡献者名单 - -2024-4-4 成天宇 创始模块 -2024-4-4 张耀源 优化代码逻辑 \ No newline at end of file diff --git a/core/losu.c b/core/losu.c new file mode 100755 index 0000000000000000000000000000000000000000..40eace5c47f6d646033003193ec0c56f0d62ca32 --- /dev/null +++ b/core/losu.c @@ -0,0 +1,256 @@ +/* + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +/* This file implements Losu's various built-in functions and environment + * variables, including import argc/argv and initialization through the vm_init + * function. */ + +#include "losu.h" +#include "losu_errmsg.h" +#include "losu_gc.h" +#include "losu_object.h" +#include "losu_syntax.h" +#include "losu_vm.h" +#include +#include +#include + +_l_size_t LosuVersionNum = 512; /* 2*(16^2) + 0*(16^1) + 0*(16^0 )*/ +const char LosuVersion[] = "2.0.0"; /* Version */ +const char LosuCopyright[] + = "MIT LICENSE (C) chen-chaochen 2022 ~ now"; /* (C)copy */ +const char LosuBuild[] + = "Build (" __DATE__ "," __TIME__ + ") CC = " __VERSION__; /* Build info, date,time,patch ... */ + +const char LosuArch[] + = __config_losucore_platform_name; /* Arch Info,Os and CPU*/ + +const char *LosuTypeSystem[] = { + "null", "number", "string", "function", "unit", "pointer", "unkown", NULL, +}; + +/* class new */ +/* demo.els + +Student = { + __init__: def(self,name): + self.name = name + ... + , + sayhello: def(self): + print("hello,my name is %s" % self.name) + ... + , + } +) +var s1 = new(Student,"chen") +*/ + +static int32_t +__losuInlineFnew (LosuVm *vm) +{ + int32_t args = arg_num (vm); + + LosuObj *class = arg_get (vm, 1); + LosuObj *func = (LosuObj *)&_inlineNullObj; + LosuObj newobj = obj_newunit (vm); + + /* check if unit? */ + if (obj_type (vm, (class)) != LosuTypeDefine_unit) + vm_error (vm, LosuErrorCode_Runtime, + __config_losucore_errmsg_msgInvalidNewobj); + + /* copy class to newobj */ + { + LosuNode *p = obj_unit_first (vm, *class); + while (p != NULL) + { + obj_setunit (vm, newobj, obj_unit_nodekey (vm, p), + obj_unit_nodevalue (vm, p)); + p = obj_unit_next (vm, *class, p); + } + } + + /* call __init__ ,if exsist*/ + func = obj_indexunitbystr (vm, newobj, "__init__"); + if (obj_type (vm, func) == LosuTypeDefine_function) + { + + stack_push (vm, *func); + stack_push (vm, newobj); + for (int32_t i = 2; i <= args; i++) + stack_push (vm, *arg_get (vm, i)); + stack_call (vm, args, 0); + } + + /* reset vm */ + arg_return (vm, newobj); + return 1; +} + +static int32_t +__losuInlineFclass (LosuVm *vm) +{ + /* + class("Student",Animal,Person, + { + + } + ) + */ + const char *cname = arg_getstr (vm, 1); + int32_t nfcls = arg_num (vm) - 2; + LosuObj *fcls = NULL; + LosuObj *aimcls = NULL; + + /* check if arg type right? */ + if (nfcls < 0 || cname == NULL) + return 0; + aimcls = arg_get (vm, nfcls + 2); + if (obj_type (vm, aimcls) != LosuTypeDefine_unit) + return 0; + + /* copy fcls */ + for (int32_t i = 0; i < nfcls; i++) + { + fcls = arg_get (vm, i + 1); + LosuNode *p = obj_unit_first (vm, *fcls); + while (p != NULL) + { + obj_setunit (vm, *aimcls, obj_unit_nodekey (vm, p), + obj_unit_nodevalue (vm, p)); + p = obj_unit_next (vm, *fcls, p); + } + p = NULL; + } + + /* Set Type */ + obj_setunitbystr (vm, *aimcls, "::type", obj_newstr (vm, (char *)cname)); + /* Set Global */ + vm_setval (vm, cname, *aimcls); + return 0; +} + +/* from import */ +/* from "xxx" import "xxx" */ + +LosuPackage_t *LosuPackages; + +static LosuModule *nowlib = NULL; +static const char *nowlibname = NULL; + +static int32_t +__losuInlineFfrom (LosuVm *vm) +{ + const char *libname = arg_getstr (vm, 1); + for (int32_t i = 0; LosuPackages[i].name != NULL; i++) + { + if (strcmp (LosuPackages[i].name, libname) == 0) + { + nowlib = LosuPackages[i].loadfunc (vm); + nowlibname = libname; + return 0; + } + } + vm_error (vm, LosuErrorCode_Library, + __config_losucore_errmsg_msgInvalidLibrary, libname); + return 0; +} + +static int32_t +__losuInlineFimport (LosuVm *vm) +{ + const char *libname = arg_getstr (vm, 1); + /* no from,load all submod */ + if (nowlib == NULL) + { + for (int32_t i = 0; LosuPackages[i].name != NULL; i++) + { + if (strcmp (LosuPackages[i].name, libname) == 0) + { + LosuModule *mod = LosuPackages[i].loadfunc (vm); + for (int32_t j = 0; mod[j].name != NULL; j++) + mod[j].construct (vm); + return 0; + } + } + vm_error (vm, LosuErrorCode_Library, + __config_losucore_errmsg_msgInvalidLibrary, libname); + } + else + { + for (int32_t i = 0; nowlib[i].name != NULL; i++) + { + if (strcmp (nowlib[i].name, libname) == 0) + { + nowlib[i].construct (vm); + nowlib = NULL; + nowlibname = NULL; + return 0; + } + } + vm_error (vm, LosuErrorCode_Library, + __config_losucore_errmsg_msgInvalidSubLibrary, libname, + nowlibname); + nowlib = NULL; + } + return 0; +} + +LosuExtern int32_t +vm_init (LosuVm *vm, int32_t argc, const char **argv) +{ + /* set args.n & args[] */ + LosuObj o = obj_newunit (vm); + obj_setunitbystr (vm, o, "n", obj_newnum (vm, argc)); + for (int32_t i = 0; i < argc; i++) + obj_setunitbynum (vm, o, i + 1, + obj_newstr (vm, charset_newObj_toLosu (vm, argv[i]))); + vm_setval (vm, "args", o); + + vm_setval (vm, "new", obj_newfunction (vm, __losuInlineFnew)); + vm_setval (vm, "class", obj_newfunction (vm, __losuInlineFclass)); + vm_setval (vm, "from", obj_newfunction (vm, __losuInlineFfrom)); + vm_setval (vm, "import", obj_newfunction (vm, __losuInlineFimport)); + + gc_setmax (vm, __config_losucore_gc_defaultsize); + return 0; +} diff --git a/core/losu_api.c b/core/losu_api.c new file mode 100755 index 0000000000000000000000000000000000000000..cb16300a985a59b7f2f07474e2ae1eedc66d76ca --- /dev/null +++ b/core/losu_api.c @@ -0,0 +1,1298 @@ +/* + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ +/** + * Losu API + */ + +#include "losu_api.h" +#include "losu_bytecode.h" +#include "losu_errmsg.h" +#include "losu_gc.h" +#include "losu_malloc.h" +#include "losu_object.h" +#include "losu_syntax.h" +#include "losu_vm.h" +#include +#include +#include +#include +#include + +#ifndef define_source_losu_api +#define define_source_losu_api + +/* Vm APIs */ + +/** + * @brief Create a new LosuVm + * @param stacksize The size of the stack + * @return LosuVm* A pointer to the new LosuVm + */ +LosuExtern LosuVm * +vm_create (int32_t size) +{ + __longjump lj = (__longjump){ + .err = 0, + .pre = NULL, + }; + if (size <= 0) + return NULL; + LosuVm *vm = __losu_mem_new (NULL, LosuVm); + if (vm == NULL) + return NULL; + *vm = (LosuVm){ + .mainthread = vm, + .stack = NULL, + .strpool = (__vmStrseg){ + .size = 0, + .nsize = 0, + .strobj = NULL, + }, + .bufftmp = NULL, + .nbufftmp = 0, + .inspool = NULL, + .funcpool = NULL, + .hashpool = NULL, + .nblocks = sizeof(LosuVm), + .errjmp = &lj, + .emjmp = NULL, + .gcDymax = 1, + .gcMax = SIZE_MAX, + .gcHook = 0, + .name = NULL, + }; + + LosuObj *oldbase = vm->base; + LosuObj *oldtop = vm->top; + if (setjmp (lj.jmpflag) == 0) + { + vm->global = __losu_objUnit_new (vm, 0); + __losu_vmHeap_init (vm, size); + __losu_objStringPool_init (vm); + __losu_syntaxLex_init (vm); + } + else + { + vm->base = oldbase; + vm->top = oldtop; + if (vm->top - vm->stack < vm->stacksize - 1) + vm->stackmax = vm->stack + (vm->stacksize - 1); + } + + vm->errjmp = lj.pre; + + if (lj.err != 0) + { + vm_close (vm); + return NULL; + } + + return vm; +} + +/** + * @brief Initialize a LosuVm, Load all inline-functions + * @param vm A pointer to the LosuVm + * @return int 0 if successful, non-zero otherwise + */ +LosuExtern int32_t vm_init (LosuVm *vm,int32_t argc,const char** argv); + +/** + * @note This API is deprecated and it is recommended to use the alternative + * option in Losu API 2.0 + * @brief Fork a LosuVm, The forked VM shares a global variable table with the + * original VM, but has a different Runspace, Local variables, and Stack. + * @param vm A pointer to the original LosuVm + * @param size The size of the stack + * @return LosuVm* A pointer to the new LosuVm + */ +LosuExtern LosuVm * +vm_fork (LosuVm *oldvm, int32_t size) +{ + __longjump lj = (__longjump){ + .err = 0, + .pre = NULL, + }; + if (size <= 0) + return NULL; + LosuVm *vm = __losu_mem_new (NULL, LosuVm); + if (vm == NULL) + return NULL; + *vm = (LosuVm){ + .mainthread = oldvm, + .stack = NULL, + .strpool = (__vmStrseg){ + .size = 0, + .nsize = 0, + .strobj = NULL, + }, + .bufftmp = NULL, + .nbufftmp = 0, + .inspool = NULL, + .funcpool = NULL, + .hashpool = NULL, + .nblocks = sizeof(LosuVm), + .errjmp = &lj, + .emjmp = NULL, + .gcDymax = 1, + .gcMax = SIZE_MAX, + .gcHook = 0, + }; + + LosuObj *oldbase = vm->base; + LosuObj *oldtop = vm->top; + if (setjmp (lj.jmpflag) == 0) + { + vm->global = oldvm->global; + __losu_vmHeap_init (vm, size); + __losu_objStringPool_init (vm); + __losu_syntaxLex_init (vm); + } + else + { + vm->base = oldbase; + vm->top = oldtop; + if (vm->top - vm->stack < vm->stacksize - 1) + vm->stackmax = vm->stack + (vm->stacksize - 1); + } + + vm->errjmp = lj.pre; + + if (lj.err != 0) + { + vm_close (vm); + return NULL; + } + + return vm; +} + +/** + * @brief Destroy a LosuVm, Exit with 0, adn jump to caller function. + * @param vm A pointer to the LosuVm + */ +LosuExtern void +vm_stop (LosuVm *vm) +{ + __losu_vmHeap_break (vm, 0); +} + +/** + * @brief Set LosuVm Error, Exit with ecode, adn jump to caller function. + * @param vm A pointer to the LosuVm + * @param ecode Error Code + * @param estr Error String + */ +LosuExtern void +vm_error (LosuVm *vm, int32_t ecode, const char *estr, ...) +{ + + memset (vm->staticbuff, 0, sizeof (vm->staticbuff)); + va_list ap; + va_start (ap, estr); + vsprintf ((char *)(vm->staticbuff), estr, ap); + + char *tmp = charset_toSys ((const char *)vm->staticbuff); + if (tmp == NULL) + tmp = (char *)vm->staticbuff; + + fprintf (stderr, "Runtime Error: %s\n at line %d of '%s'\n", tmp, + __losuApigetline (vm, vm->top - 1), + vm->name != NULL ? vm->name : ""); + + /* if not Native UTF8, free block */ + if (tmp != (char *)(vm->staticbuff)) + __losu_mem_free (NULL, tmp); + + va_end (ap); + __losu_vmHeap_break (vm, ecode); +} + +/** + * @brief Set LosuVm Warning, Not exit + * @param vm A pointer to the LosuVm + * @param estr Error String + */ +LosuExtern void +vm_warning (LosuVm *vm, const char *estr, ...) +{ + memset (vm->staticbuff, 0, sizeof (vm->staticbuff)); + va_list ap; + va_start (ap, estr); + vsprintf ((char *)(vm->staticbuff), estr, ap); + + char *tmp = charset_toSys ((const char *)vm->staticbuff); + if (tmp == NULL) + tmp = (char *)vm->staticbuff; + + fprintf (stderr, "Runtime Warning: %s\n at line %d of '%s'\n", tmp, + __losuApigetline (vm, vm->top - 1), + vm->name != NULL ? vm->name : ""); + + /* if not Native UTF8, free block */ + if (tmp != (char *)(vm->staticbuff)) + __losu_mem_free (NULL, tmp); + + va_end (ap); +} + +/** + * @brief Load a Losu file, and execute it. + * @param vm A pointer to the LosuVm + * @param filename The name of the file + * @return int32_t 0 if successful, non-zero otherwise + */ +LosuExtern int32_t +vm_dofile (LosuVm *vm, const char *f) +{ + int32_t i; + if (!(i = vm_loadfile (vm, f))) + return vm_execute (vm, 0, -1, f); + return i; +} + +/** + * @brief Load a string, and execute it . + * @param vm A pointer to the LosuVm + * @param str The Losu string + * @param n The name of the string + * @return int32_t 0 if successful, non-zero otherwise + */ +LosuExtern int32_t +vm_dostring (LosuVm *vm, const char *s, const char *n) +{ + int32_t i; + if (!(i = vm_loadstring (vm, s, n))) + return vm_execute (vm, 0, -1, n); + return i; +} + +/** + * @brief Load Byte-code, and execute it. + * @param vm A pointer to the LosuVm + * @param byte The Byte-code + * @param n The name of the Byte-code + * @return int32_t 0 if successful, non-zero otherwise + */ +LosuExtern int32_t +vm_dobyte (LosuVm *vm, const char *byte, size_t len, const char *name) +{ + int32_t i; + if (!(i = vm_loadbyte (vm, byte, len, name))) + return vm_execute (vm, 0, -1, name); + return i; +} + +/** + * @brief Load a Losu file, `NOT` execute it. + * @param vm A pointer to the LosuVm + * @param filename The name of the file + * @return int32_t 0 if successful, non-zero otherwise + */ +int32_t +vm_loadfile (LosuVm *vm, const char *f) +{ + return __losu_syntaxIO_loadfile (vm, f); +} + +/** + * @brief Load a string, `NOT` execute it. + * @param vm A pointer to the LosuVm + * @param str The Losu string + * @return int32_t 0 if successful, non-zero otherwise + */ +LosuExtern int32_t +vm_loadstring (LosuVm *vm, const char *s, const char *name) +{ + return __losu_syntaxIO_loadstring (vm, s, strlen (s), name); +} + +/** + * @brief Load Byte-code, `NOT` execute it. + * @param vm A pointer to the LosuVm + * @param byte The Byte-code + * @param len The length of the Byte-code + * @param name The name of the Byte-code + */ +LosuExtern int32_t +vm_loadbyte (LosuVm *vm, const char *byte, size_t len, const char *name) +{ + return __losu_syntaxIO_loadstring (vm, byte, len, name); +} + +/** + * @brief In 'Protected Mode', call a function on the stack and specify the + * number of arguments and return values."Protected Mode' creates a protected + * call stack for each call and jumps to the top of that stack when an error is + * thrown + * @param vm A pointer to the LosuVm + * @param narg The number of arguments + * @param nres The number of return values + * @param name The name of the function + * @return int 0 if successful, non-zero otherwise + */ +int32_t +vm_execute (LosuVm *vm, int32_t narg, int32_t nres, const char *name) +{ + const char *on = vm->name; + vm->name = name; + int32_t i = __losu_vmHeap_callS (vm, narg, nres); + vm->name = on; + return i; +} + +/** + * @brief Get a value from the global variable table in vm. + * @param vm A pointer to the LosuVm + * @param name The name of the variable + * @return LosuObj* A pointer to the value + */ +LosuExtern LosuObj * +vm_getval (LosuVm *vm, const char *name) +{ + return (LosuObj *)__losu_objUnit_getstr (vm->global, + __losu_objString_new (vm, name)); +} + +/** + * @brief Set a value in the global variable table in vm. + * @param vm A pointer to the LosuVm + * @param name The name of the variable + * @param val The value to set + */ +LosuExtern void +vm_setval (LosuVm *vm, const char *name, LosuObj val) +{ + LosuObj key = (LosuObj){ + .type = LosuTypeDefine_string, + .value.str = __losu_objString_new (vm, name), + }; + *__losu_objUnit_set (vm, vm->global, &key) = val; +} + +/** + * @brief Closes the specified LosuVm, reclaiming all the memory space it + * belongs to; only the 'Root VM' reclaims the global variable table + * @param vm A pointer to the LosuVm + */ +LosuExtern void +vm_close (LosuVm *vm) +{ + if (vm->mainthread != vm) + vm->global = NULL; + + __losu_gc_collect (vm, 1); + __losu_objStringPool_deinit (vm); + + if (vm->stack) + { + __losu_mem_free (vm, vm->stack); + vm->nblocks -= (vm->stackmax - vm->stack + 1) * sizeof (LosuObj); + } + if (vm->bufftmp) + { + __losu_mem_free (vm, vm->bufftmp); + vm->nblocks -= vm->nbufftmp * sizeof (char); + } + __losu_mem_free (vm, vm); +} + +/* GC APIs */ + +/** + * @brief Set the maximum amount of memory for the GC + * @param vm A pointer to the LosuVm + * @param size The maximum amount of memory for the GC + */ +LosuExtern void +gc_setmax (LosuVm *vm, _l_gcint size) +{ + vm->gcMax = vm->gcDymax = size; +} + +/** + * @brief Get the amount of memory used by the GC + * @param vm A pointer to the LosuVm + * @return _l_gcint The amount of memory used by the GC + */ +LosuExtern _l_gcint +gc_getmemNow (LosuVm *vm) +{ + return vm->nblocks; +} + +/** + * @brief Get the maximum amount of memory for the GC + * @param vm A pointer to the LosuVm + * @return _l_gcint The maximum amount of memory for the GC + */ +LosuExtern _l_gcint +gc_getmemMax (LosuVm *vm) +{ + return vm->gcHook; +} + +/** + * @brief Collect the garbage + * @param vm A pointer to the LosuVm + * @return _l_bool 1 if collection operation performed, 0 if collection + * operation not performed + */ +LosuExtern _l_bool +gc_collect (LosuVm *vm) +{ + return __losu_gc_checkClt (vm); +} + +/* Arg APIs */ + +/** + * @brief Get an argument from the call-stack + * @param vm A pointer to the LosuVm + * @param idx The index of the argument + * @return LosuObj* A pointer to the argument + */ +LosuExtern LosuObj * +arg_get (LosuVm *vm, int idx) +{ + if (idx > 0) + { + LosuObj *o = vm->base + (idx - 1); + if (o >= vm->top) + ovtype (o) = LosuTypeDefine_null; + return o; + } + return (LosuObj *)(&_inlineNullObj); +} + +/** + * @brief Return an argument from the call-stack + * @param vm A pointer to the LosuVm + * @param obj The argument to return + */ +LosuExtern void +arg_return (LosuVm *vm, LosuObj obj) +{ + *(vm->top) = (obj); + if (vm->top == vm->stackmax) + vm_error (vm, LosuErrorCode_Heap, + __config_losucore_errmsg_msgStackOverflow); + vm->top++; +} + +/** + * @brief Get the number of arguments in the call-stack + * @param vm A pointer to the LosuVm + * @return int32_t The number of arguments + */ +LosuExtern int32_t +arg_num (LosuVm *vm) +{ + return (int32_t)(vm->top - vm->base); +} + +/** + * @brief Get an number type (_l_number) argument from the call-stack + * @param vm A pointer to the LosuVm + * @param idx The index of the argument + * @return _l_number The argument + */ +/* Arg_get APIs */ +LosuExtern _l_number +arg_getnum (LosuVm *vm, int idx) +{ + return obj_tonum (vm, arg_get (vm, idx)); +} + +/** + * @brief Get an string type (const char*) argument from the call-stack + * @param vm A pointer to the LosuVm + * @param idx The index of the argument + * @return const char* The argument + */ +LosuExtern const char * +arg_getstr (LosuVm *vm, int idx) +{ + return obj_tostr (vm, arg_get (vm, idx)); +} + +/** + * @brief Get a pointer type (char*) argument from the call-stack + * @param vm A pointer to the LosuVm + * @param idx The index of the argument + * @return char* The argument + */ +LosuExtern char * +arg_getptr (LosuVm *vm, int idx) +{ + return obj_toptr (vm, arg_get (vm, idx)); +} + +/** + * @brief Get a function type (LosuApi) argument from the call-stack + * @param vm A pointer to the LosuVm + * @param idx The index of the argument + * @return LosuApi The argument + */ +LosuExtern LosuApi +arg_getfunc (LosuVm *vm, int idx) +{ + return obj_tofunction (vm, arg_get (vm, idx)); +} + +/** + * @brief Get the specified parameter type (Defined value) from the call-stack, + * @param vm A pointer to the LosuVm + * @param idx The index of the argument + * @return int The type of the argument + */ +LosuExtern int +arg_gettype (LosuVm *vm, int idx) +{ + return obj_type (vm, arg_get (vm, idx)); +} + +/** + * @brief Get the specified parameter type (Defined value) from the call-stack, + * @param vm A pointer to the LosuVm + * @param idx The index of the argument + * @return const char* The type of the argument + */ +LosuExtern const char * +arg_gettypeStr (LosuVm *vm, int idx) +{ + return obj_typeStr (vm, arg_get (vm, idx)); +} + +/** + * @brief Return a number type (_l_number) argument to the call-stack + * @param vm A pointer to the LosuVm + * @param num The argument to return + */ +/* Arg_return APIs */ +LosuExtern void +arg_returnnum (LosuVm *vm, _l_number num) +{ + arg_return (vm, obj_newnum (vm, num)); +} + +/** + * @brief Return a string type (const char*) argument to the call-stack + * @param vm A pointer to the LosuVm + * @param str The argument to return + */ +LosuExtern void +arg_returnstr (LosuVm *vm, const char *str) +{ + arg_return (vm, obj_newstr (vm, (char *)str)); +} + +/** + * @brief Return a string type (const char*) argument to the call-stack + * @param vm A pointer to the LosuVm + * @param str The argument to return + * @param len The length of the string + */ +LosuExtern void +arg_returnstrlen (LosuVm *vm, const char *str, size_t len) +{ + arg_return (vm, obj_newstrlen (vm, (char *)str, len)); +} + +/** + * @brief Return a cAPIfunction type (LosuApi) argument to the call-stack + * @param vm A pointer to the LosuVm + * @param func The argument to return + */ +LosuExtern void +arg_returnfunc (LosuVm *vm, LosuApi func) +{ + arg_return (vm, obj_newfunction (vm, func)); +} + +/** + * @brief Return a pointer type (char*) argument to the call-stack + * @param vm A pointer to the LosuVm + * @param ptr The argument to return + */ +LosuExtern void +arg_returnptr (LosuVm *vm, char *ptr) +{ + arg_return (vm, obj_newptr (vm, ptr)); +} + +/** + * @brief Return a null type (void) argument to the call-stack + * @param vm A pointer to the LosuVm + */ +LosuExtern void +arg_returnnull (LosuVm *vm) +{ + arg_return (vm, obj_newnull (vm)); +} + +/* obj_xxx APIs */ +/** + * @brief Convert 'LosuObj' to C-Type representation of string ( const char* ) + * @param vm A pointer to the LosuVm + * @param obj The target object + * @return const char* The target object's C-Type ( const char* ) + */ +LosuExtern const char * +obj_tostr (LosuVm *vm, LosuObj *obj) +{ +#define tostring(o) \ + ((ovtype (o) != LosuTypeDefine_string) \ + && (__losu_vmCore_Tostr (vm, o, 0) != 0)) + + return (obj == NULL || tostring (obj)) ? "" : ovSstr (obj); +#undef tostring +} + +/** + * @brief Convert 'LosuObj' to C-Type representation of number ( + * _l_number ) + * @param vm A pointer to the LosuVm + * @param obj The target object + * @return _l_number The target object's C-Type ( _l_number ) + */ +LosuExtern _l_number +obj_tonum (LosuVm *vm, LosuObj *obj) +{ +#define tonumber(o) \ + ((ovtype (o) != LosuTypeDefine_number) \ + && (__losu_vmCore_Tonum (vm, o, 0)) != 0) + + return (obj == NULL || tonumber (obj)) ? 0 : ovnumber (obj); + +#undef tonumber +} + +/** + * @brief Convert 'LosuObj' to C-Type representation of pointer ( char* ) + * @param vm A pointer to the LosuVm + * @param obj The target object + * @return char* The target object's C-Type ( char* ) + */ +LosuExtern char * +obj_toptr (LosuVm *vm, LosuObj *obj) +{ + return (ovtype (obj) == LosuTypeDefine_ptr ? obj->value.ptr : NULL); +} + +/** + * @brief Convert 'LosuObj' to C-Type representation of function ( LosuApi ) + * @param vm A pointer to the LosuVm + * @param obj The target object + * @return LosuApi The target object's C-Type ( LosuApi ) + */ +LosuExtern LosuApi +obj_tofunction (LosuVm *vm, LosuObj *obj) +{ + return (ovtype (obj) == LosuTypeDefine_function + ? (ovfunc (obj)->isC ? ovfunc (obj)->func.capi : NULL) + : NULL); +} + +/** + * @brief Get the type of 'LosuObj' + * @param vm A pointer to the LosuVm + * @param obj The target object + * @return int The type of the target object + */ +LosuExtern int +obj_type (LosuVm *vm, LosuObj *obj) +{ + return ovtype (obj); +} + +/** + * @brief Get the type of 'LosuObj' + * @param vm A pointer to the LosuVm + * @param obj The target object + * @return const char* The type of the target object + */ +LosuExtern const char * +obj_typeStr (LosuVm *vm, LosuObj *obj) +{ + + if (ovtype (obj) < LosuTypeDefine_mark) + { + if (ovtype (obj) == LosuTypeDefine_unit) + { + LosuObj *o = obj_indexunitbystr (vm, *obj, "::type"); + if (ovtype (o) == LosuTypeDefine_string) + return obj_tostr (vm, o); + } + return LosuTypeSystem[ovtype (obj)]; + } + else + return LosuTypeSystem[6]; +} + +/** + * @brief Create a new LosuObj of type string + * @note The string will be copied to the LosuVm's memory + * @param vm A pointer to the LosuVm + * @param str The string to create the LosuObj from + * @return LosuObj The new LosuObj + */ +LosuExtern LosuObj +obj_newstr (LosuVm *vm, char *str) +{ + return (LosuObj){ + .type = LosuTypeDefine_string, + .value.str = __losu_objString_new (vm, str), + }; +} + +/** + * @brief Create a new LosuObj of type string with length + * @note The string will be copied to the LosuVm's memory + * @param vm A pointer to the LosuVm + * @param str The string to create the LosuObj from + * @param len The length of the string + * @return LosuObj The new LosuObj + */ +LosuExtern LosuObj +obj_newstrlen (LosuVm *vm, char *str, size_t len) +{ + return (LosuObj){ + .type = LosuTypeDefine_string, + .value.str = __losu_objString_newstr (vm, str, len), + }; +} + +/** + * @brief Get the length of a LosuObj of type string + * @param vm A pointer to the LosuVm + * @param obj The target object + * @return size_t The length of the target object + */ +LosuExtern size_t +obj_getstrlen (LosuVm *vm, LosuObj *obj) +{ + return (ovtype (obj) == LosuTypeDefine_string ? ovIstr (obj)->len : 0); +} + +/** + * @brief Create a new LosuObj of type number + * @param vm A pointer to the LosuVm + * @param num The number to create the LosuObj from + * @return LosuObj The new LosuObj + */ +LosuExtern LosuObj +obj_newnum (LosuVm *vm, _l_number num) +{ + return (LosuObj){ + .type = LosuTypeDefine_number, + .value.num = num, + }; +} + +/** + * @brief Create a new LosuObj of type function + * @param vm A pointer to the LosuVm + * @param func The function to create the LosuObj from + * @return LosuObj The new LosuObj + */ +LosuExtern LosuObj +obj_newfunction (LosuVm *vm, LosuApi func) +{ + _inlineFunction *f = __losu_objFunc_new (vm, 0); + f->isC = 1; + f->func.capi = func; + return (LosuObj){ + .type = LosuTypeDefine_function, + .value.func = f, + }; +} + +/** + * @brief Create a new LosuObj of type unit + * @param vm A pointer to the LosuVm + * @return LosuObj The new LosuObj + */ +LosuExtern LosuObj +obj_newnull (LosuVm *vm) +{ + return (LosuObj){ + .type = LosuTypeDefine_null, + }; +} + +/** + * @brief Create a new LosuObj of type unit + * @param vm A pointer to the LosuVm + * @return LosuObj The new LosuObj + */ +LosuExtern LosuObj +obj_newunit (LosuVm *vm) +{ + return (LosuObj){ + .type = LosuTypeDefine_unit, + .value.hash = __losu_objUnit_new (vm, 0), + }; +} + +/** + * @brief Create a new LosuObj of type pointer + * @param vm A pointer to the LosuVm + * @param ptr A byte type (const char*) argument to the call-stack + * @note The pointer `WON'T` be copied to the LosuVm's memory + * @return LosuObj The new LosuObj + */ +LosuExtern LosuObj +obj_newptr (LosuVm *vm, char *ptr) +{ + return (LosuObj){ + .type = LosuTypeDefine_ptr, + .value.ptr = ptr, + }; +} + +/** + * @brief Inedx a LosuObj from target unit + * @param vm A pointer to the LosuVm + * @param unit The target unit + * @param key The key to index + * @return LosuObj The indexed object, if not found, return a LosuObj (type + * null) + */ +LosuExtern LosuObj * +obj_indexunit (LosuVm *vm, LosuObj unit, LosuObj key) +{ + if (unit.type == LosuTypeDefine_unit) + return (LosuObj *)__losu_objUnit_get (ovhash ((&unit)), &key); + return (LosuObj *)&_inlineNullObj; +} + +/** + * @brief Inedx a LosuObj from target unit by number-key ( Based on API: + * `obj_indexunit` ) + * @param vm A pointer to the LosuVm + * @param unit The target unit + * @param i The number-key + * @return LosuObj The indexed object + */ +LosuExtern LosuObj * +obj_indexunitbynum (LosuVm *vm, LosuObj unit, _l_number i) +{ + if (unit.type == LosuTypeDefine_unit) + return (LosuObj *)__losu_objUnit_getnum (ovhash ((&unit)), i); + return (LosuObj *)&_inlineNullObj; +} + +/** + * @brief Inedx a LosuObj from target unit by string-key ( Based on API: + * `obj_indexunit` ) + * @param vm A pointer to the LosuVm + * @param unit The target unit + * @param s The string-key + * @return LosuObj The indexed object + */ +LosuExtern LosuObj * +obj_indexunitbystr (LosuVm *vm, LosuObj unit, char *s) +{ + LosuObj o = obj_newstr (vm, s); + if (unit.type == LosuTypeDefine_unit) + return (LosuObj *)__losu_objUnit_getstr (ovhash ((&unit)), ovIstr ((&o))); + return (LosuObj *)&_inlineNullObj; +} + +/** + * @brief Set a LosuObj to target unit, unit[key] = value + * @param vm A pointer to the LosuVm + * @param unit The target unit + * @param key The key to set + * @param value The value to set + */ +LosuExtern void +obj_setunit (LosuVm *vm, LosuObj unit, LosuObj key, LosuObj value) +{ + if (unit.type == LosuTypeDefine_unit) + *__losu_objUnit_set (vm, ovhash ((&unit)), &key) = value; +} + +/** + * @brief Set a LosuObj to target unit, unit[key] = value ( Based on API: + * `obj_setunit` ) + * @param vm A pointer to the LosuVm + * @param unit The target unit + * @param key The key to set + * @param value The value to set + */ +LosuExtern void +obj_setunitbynum (LosuVm *vm, LosuObj unit, _l_number key, LosuObj value) +{ + if (unit.type == LosuTypeDefine_unit) + *__losu_objUnit_setnum (vm, ovhash ((&unit)), key) = value; +} + +/** + * @brief Set a LosuObj to target unit, unit[key] = value ( Based on API: + * `obj_setunit` ) + * @param vm A pointer to the LosuVm + * @param unit The target unit + * @param key The key to set + * @param value The value to set + */ +LosuExtern void +obj_setunitbystr (LosuVm *vm, LosuObj unit, char *key, LosuObj value) +{ + if (unit.type == LosuTypeDefine_unit) + *__losu_objUnit_setstr (vm, ovhash ((&unit)), + __losu_objString_new (vm, key)) + = value; +} + +/** + * @brief Get the 'First-Node' of an unit , First-Node is the 'Logic-First' of + * the unit, you can use API:`obj_unit_next` to get the next node, until NULL + * @param vm A pointer to the LosuVm + * @param unit The target unit + * @return LosuNode* The first node of the unit, if not found, return NULL + */ +LosuExtern LosuNode * +obj_unit_first (LosuVm *vm, LosuObj unit) +{ + if (ovtype (&unit) == LosuTypeDefine_unit) + return (LosuNode *)__losu_objUnit_getnext (ovhash ((&unit)), + (LosuObj *)&_inlineNullObj); + return NULL; +} + +/** + * @brief Locate Node with key of an unit, if not found, return NULL + * @note This function is used to locate a node in a unit, it is not a + * 'Always-Safe' function,it may return `NULL` + * @param vm A pointer to the LosuVm + * @param unit The target unit + * @param key The key to locat + * @return LosuNode The located node, if not found, return NULL + */ +LosuExtern LosuNode +obj_unit_location (LosuVm *vm, LosuObj unit, LosuObj key) +{ + LosuNode n; + n.key = key; + if (unit.type == LosuTypeDefine_unit) + n.value = *__losu_objUnit_get (ovhash ((&unit)), &key); + else + n.value = _inlineNullObj; + return n; +} + +/** + * @brief Get the next node of an unit, if not found, return NULL + * @param vm A pointer to the LosuVm + * @param unit The target unit + * @param n The current node + * @return LosuNode* The next node, if not found, return NULL + */ +LosuExtern LosuNode * +obj_unit_next (LosuVm *vm, LosuObj unit, LosuNode *n) +{ + if (unit.type == LosuTypeDefine_unit) + return (LosuNode *)__losu_objUnit_getnext (ovhash ((&unit)), (&(n->key))); + return NULL; +} + +/** + * @brief Get the key of an node + * @param vm A pointer to the LosuVm + * @param n The target node + * @return LosuObj The key of the node + */ +LosuExtern LosuObj +obj_unit_nodekey (LosuVm *vm, LosuNode *n) +{ + return n->key; +} + +/** + * @brief Get the value of an node + * @param vm A pointer to the LosuVm + * @param n The target node + * @return LosuObj The value of the node + */ +LosuExtern LosuObj +obj_unit_nodevalue (LosuVm *vm, LosuNode *n) +{ + return n->value; +} + +/* Stack APIs */ +/** + * @brief Push a LosuObj to the call-stack + * @param vm A pointer to the LosuVm + * @param o The LosuObj to push + */ +LosuExtern void +stack_push (LosuVm *vm, LosuObj o) +{ + *(vm->top) = o; + if (vm->top == vm->stackmax) + vm_error (vm, LosuErrorCode_Heap, + __config_losucore_errmsg_msgStackOverflow); + vm->top++; +} + +/** + * @brief Pop a LosuObj from the call-stack + * @param vm A pointer to the LosuVm + * @param i The index of the LosuObj to pop + * @return LosuObj The popped LosuObj + */ +LosuExtern void +stack_pop (LosuVm *vm, int i) +{ + vm->top -= i; + if (vm->top < vm->stack) + vm->top = vm->stack; +} + +/** + * @brief Call a function in the call-stack, NOT in `Protected Mode`, Jump to + * the top of the stack of the current environment when an error occurs + * @param vm A pointer to the LosuVm + * @param argnum The number of arguments + * @param resnum The number of results + */ +LosuExtern void +stack_call (LosuVm *vm, int argnum, int resnum) +{ + __losu_vmHeap_call (vm, vm->top - (argnum + 1), resnum); +} + +/* Charset API s */ +#ifdef __config_losucore_encode_winGBK +#include +#endif + +/** + * @brief Convert a Losu(UTF-8) string to Sys(GBK/UTF8) string + * @note This function is used to convert a UTF-8 string to GBK string, it will + * malloc dynamic memory, so you need to free it after use. If Sys-charset is + * UTF8 too, it will return the same char*. + * @param s The UTF-8 string to convert + * @return char* The Sys string, if failed, return NULL. + */ +LosuExtern char * +charset_toSys (const char *s) +{ +#ifdef __config_losucore_encode_nativeUTF8 + return (char *)s; +#endif + +#ifdef __config_losucore_encode_winGBK + return __losuWintoGBK (s); +#endif +} + +/** + * @brief Convert a Sys(GBK/UTF8) string to Losu(UTF-8) string + * @note This function is used to convert a GBK string to UTF-8 string, it will + * malloc dynamic memory, so you need to free it after use.If Sys-charset is + * UTF8 too, it will return the same char* + * @param s The GBK string to convert + * @return char* The UTF-8 string, if failed, return NULL + */ +LosuExtern char * +charset_toLosu (const char *s) +{ +#ifdef __config_losucore_encode_nativeUTF8 + return (char *)s; +#endif + +#ifdef __config_losucore_encode_winGBK + return __losuWintoUTF8 (s); +#endif +} + +/** + * @brief Create a new LosuObj from a GBK string, and convert to UTF-8 + * @note This function is used to create a new LosuObj from a GBK string, and + * convert to UTF-8, it will use LosuVm memory pool to allocate memory, so you + * don't need to free it after use when Losu's GC is working + * @param vm A pointer to the LosuVm + * @param s The UTF-8 string to convert + * @return char* The string C-Type of new LosuObj ( char* ), if failed, return + * NULL + */ +LosuExtern char * +charset_newObj_toLosu (LosuVm *vm, const char *s) +{ + char *t = charset_toLosu (s); + if (t == NULL) + return NULL; + LosuObj o = obj_newstr (vm, t); + if (t != s) + __losu_mem_free (NULL, t); + return ovSstr ((&o)); +} + +/** + * @brief Create a new LosuObj from a UTF-8 string, and convert to GBK + * @note This function is used to create a new LosuObj from a UTF-8 string, and + * convert to GBK, it will use LosuVm memory pool to allocate memory, so you + * don't need to free it after use when Losu's GC is working + * @param vm A pointer to the LosuVm + * @param s The UTF-8 string to convert + * @return char* The string C-Type of new LosuObj ( char* ), if failed, return + * NULL + */ +LosuExtern char * +charset_newObj_toSys (LosuVm *vm, const char *s) +{ + char *t = charset_toSys (s); + if (t == NULL) + return NULL; + LosuObj o = obj_newstr (vm, t); + if (t != s) + __losu_mem_free (NULL, t); + return ovSstr ((&o)); +} + +#endif + +#ifndef define_source_losu_inline +#define define_source_losu_inline + +#ifdef __config_losucore_encode_winGBK +#include +#include +static char * +__losuWintoGBK (const char *str) +{ + int len = MultiByteToWideChar (CP_UTF8, 0, str, -1, NULL, 0); + wchar_t *strUnicode + = (wchar_t *)__losu_mem_malloc (NULL, len * sizeof (wchar_t *)); + wmemset (strUnicode, 0, len); + MultiByteToWideChar (CP_UTF8, 0, str, -1, strUnicode, len); + len = WideCharToMultiByte (CP_ACP, 0, strUnicode, -1, NULL, 0, NULL, NULL); + char *strGbk = (char *)__losu_mem_malloc (NULL, len * sizeof (char *)); + memset (strGbk, 0, len); + WideCharToMultiByte (CP_ACP, 0, strUnicode, -1, strGbk, len, NULL, NULL); + __losu_mem_free (NULL, strUnicode); + strUnicode = NULL; + return strGbk; +} +static char * +__losuWintoUTF8 (const char *str) +{ + int len = MultiByteToWideChar (CP_ACP, 0, str, -1, NULL, 0); + wchar_t *strUnicode + = (wchar_t *)__losu_mem_malloc (NULL, len * sizeof (wchar_t *)); + wmemset (strUnicode, 0, len); + MultiByteToWideChar (CP_ACP, 0, str, -1, strUnicode, len); + len = WideCharToMultiByte (CP_UTF8, 0, strUnicode, -1, NULL, 0, NULL, NULL); + char *strutf8 = (char *)__losu_mem_malloc (NULL, len * sizeof (char *)); + memset (strutf8, 0, len); + WideCharToMultiByte (CP_UTF8, 0, strUnicode, -1, strutf8, len, NULL, NULL); + __losu_mem_free (NULL, strUnicode); + strUnicode = NULL; + return strutf8; +} + +#endif + +static int32_t +__losuApigetline (LosuVm *vm, LosuObj *obj) +{ + while (1) + { + /* printf ("stack:%p\t%p\n", vm->stack, obj); */ + if (!(obj && ovtype (obj) == LosuTypeDefine_mark + && !ovcall (obj)->func->isC)) + obj--; + else + break; + if (obj < vm->stack) + return -1; + } + + return __losuApitryline (ovcall (obj)->func->func.sdef->lineinfo, + __losuApicurrentpc (obj)); +} + +static int32_t +__losuApicurrentpc (LosuObj *obj) +{ + + if (ovcall (obj)->pc) + return (*(ovcall (obj)->pc) - ovcall (obj)->func->func.sdef->code) - 1; + else + return -1; +} +static int32_t +__losuApitryline (int32_t *lineinfo, int32_t pc) +{ + + int32_t refi = 0; + int32_t refline = 1; + if (lineinfo == NULL || pc == -1) + return -1; + if (lineinfo[refi] < 0) + refline += -lineinfo[refi++]; + while (lineinfo[refi] > pc) + { + refline--; + refi--; + if (lineinfo[refi] < 0) + refline -= -lineinfo[refi++]; + } + + while (1) + { + int32_t nextline = refline + 1; + int32_t nexref = refi + 1; + if (lineinfo[nexref] < 0) + nextline += -lineinfo[nexref++]; + if (lineinfo[nexref] > pc) + break; + refline = nextline; + refi = nexref; + } + + return refline; +} + +#endif diff --git a/core/losu_gc.c b/core/losu_gc.c new file mode 100755 index 0000000000000000000000000000000000000000..e158838cf7640b5c19cbca3f347cb62cca3a4484 --- /dev/null +++ b/core/losu_gc.c @@ -0,0 +1,330 @@ +/* + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +/** + * Losu Gc, a garbage collector for Losu Automated Memory Management. + * Using the 'Mark-Clean'. + */ + +#include "losu_gc.h" +#include "losu.h" +#include "losu_errmsg.h" +#include "losu_malloc.h" +#include "losu_object.h" +#include + +#ifndef define_source_losu_gc_api +#define define_source_losu_gc_api + +/* static segment */ +/* static segment */ +static void __losuGcMark (LosuVm *vm); +static void __losuGcmarkObj (_inlineGc *gc, LosuObj *o); +static void __losuGcmarkStack (LosuVm *vm, _inlineGc *gc); +static void __losuGcmarkFunc (_inlineGc *gc, _inlineFunction *f); +static void __losuGcmarkScode (_inlineScode *f); + +static void __losuGcCollect (LosuVm *vm); +static void __losuGccollectScode (LosuVm *vm); +static void __losuGccollectFunc (LosuVm *vm); +static void __losuGccollectUnit (LosuVm *vm); +static void __losuGccollectString (LosuVm *vm, _l_bool all); + +static void __losuGcAdjbuff (LosuVm *vm); + +void +__losu_gc_collect (LosuVm *vm, _l_bool all) +{ + __losuGccollectString (vm, all); + __losuGccollectUnit (vm); + __losuGccollectScode (vm); + __losuGccollectFunc (vm); +} + +_l_bool +__losu_gc_checkClt (LosuVm *vm) +{ + if (vm->nblocks > vm->gcHook) + vm->gcHook = vm->nblocks; + if (vm->nblocks >= vm->gcDymax) + { + __losuGcCollect (vm); + if (vm->gcDymax > vm->gcMax) + vm->gcDymax = vm->gcMax; + return 1; + } + return 0; +} + +#endif /* define_source_losu_gc_api */ + +#ifndef define_source_losu_gc_mark +#define define_source_losu_gc_mark +static void +__losuGcMark (LosuVm *vm) +{ + _inlineGc gc; + gc.func = NULL; + gc.unit = vm->global; + vm->global->mark = NULL; + __losuGcmarkStack (vm, &gc); + while (1) + { + if (gc.func) + { + _inlineFunction *f = gc.func; + gc.func = f->mark; + for (int32_t i = 0; i < f->nclosure; i++) + __losuGcmarkObj (&gc, &f->closure[i]); + } + else if (gc.unit) + { + _inlineHash *h = gc.unit; + gc.unit = h->mark; + for (int32_t i = 0; i < h->size; i++) + { + LosuNode *n = &h->node[i]; + if (ovtype ((&n->key)) != LosuTypeDefine_null) + { + if (ovtype ((&n->value)) == LosuTypeDefine_null) + { + /* __losu_objUnit_remove (h, &n->key); */ + ovtype ((&n->key)) = LosuTypeDefine_number; + ovnumber ((&n->key)) = 0; + } + __losuGcmarkObj (&gc, &n->key); + __losuGcmarkObj (&gc, &n->value); + } + } + } + else + break; + } +} + +static void +__losuGcmarkObj (_inlineGc *gc, LosuObj *o) +{ + switch (ovtype ((o))) + { + case LosuTypeDefine_string: + case LosuTypeDefine_byte: + { + ovIstr (o)->marked = 1; + break; + } + case LosuTypeDefine_mark: + { + __losuGcmarkFunc (gc, ovcall (o)->func); + break; + } + case LosuTypeDefine_function: + { + __losuGcmarkFunc (gc, ovfunc (o)); + break; + } + case LosuTypeDefine_unit: + { + if (!(ovhash (o)->mark != ovhash (o))) + { + ovhash (o)->mark = gc->unit; + gc->unit = ovhash (o); + } + break; + } + default: + break; + } +} + +static void +__losuGcmarkStack (LosuVm *vm, _inlineGc *gc) +{ + LosuObj *o; + for (o = vm->stack; o < vm->top; o++) + __losuGcmarkObj (gc, o); +} + +static void +__losuGcmarkFunc (_inlineGc *gc, _inlineFunction *f) +{ + if (f->mark == f) + { + if (!f->isC) + __losuGcmarkScode (f->func.sdef); + f->mark = gc->func; + gc->func = f; + } +} + +static void +__losuGcmarkScode (_inlineScode *f) +{ + if (!f->marked) + { + f->marked = 1; + f->src->marked = 1; + for (int32_t i = 0; i < f->nlcstr; i++) + f->lcstr[i]->marked = 1; + for (int32_t i = 0; i < f->nlcscode; i++) + __losuGcmarkScode (f->lcscode[i]); + for (int32_t i = 0; i < f->nlocalvar; i++) + f->localvar[i].name->marked = 1; + } +} +#endif /* define_source_losu_gc_mark */ + +#ifndef define_source_losu_gc_collect +#define define_source_losu_gc_collect + +static void +__losuGcCollect (LosuVm *vm) +{ + __losuGcMark (vm); + __losu_gc_collect (vm, 0); + __losuGcAdjbuff (vm); + vm->gcDymax *= 2; +} + +static void +__losuGccollectScode (LosuVm *vm) +{ + _inlineScode **f = &vm->inspool; + _inlineScode *next; + while ((next = *f) != NULL) + { + if (next->marked) + { + /* printf ("Gc: %p\n",next); */ + next->marked = 0; + f = &next->next; + } + else + { + *f = next->next; + __losu_objFunc_scodeFree (vm, next); + } + } +} + +static void +__losuGccollectFunc (LosuVm *vm) +{ + _inlineFunction **f = &vm->funcpool; + _inlineFunction *next; + while ((next = *f) != NULL) + { + if (next->mark != next) + { + next->mark = next; + f = &next->next; + } + else + { + *f = next->next; + __losu_objFunc_free (vm, next); + } + } +} + +static void +__losuGccollectUnit (LosuVm *vm) +{ + _inlineHash **h = &vm->hashpool; + _inlineHash *next; + while ((next = *h) != NULL) + { + if (next->mark != next) + { + next->mark = next; + h = &next->next; + } + else + { + *h = next->next; + __losu_objUnit_free (vm, next); + } + } +} +static void +__losuGccollectString (LosuVm *vm, _l_bool all) +{ +#define sizestring(l) ((sizeof (_inlineString) + (l + 1 - 4) * sizeof (char))) + + for (int32_t i = 0; i < vm->strpool.size; i++) + { + _inlineString **s = &vm->strpool.strobj[i]; + _inlineString *next; + while ((next = *s) != NULL) + { + if (next->marked && !all) + { + if (next->marked < CONSTMARK) + next->marked = 0; + s = &next->next; + } + else + { + *s = next->next; + vm->strpool.nsize--; + vm->nblocks -= sizestring (next->len); + __losu_mem_free (vm, next); + } + } + } + if (vm->strpool.nsize < vm->strpool.size / 4 && vm->strpool.size > 8) + __losu_objStringPool_resize (vm, &vm->strpool, vm->strpool.size / 2); + +#undef sizestring +} + +static void +__losuGcAdjbuff (LosuVm *vm) +{ + if (vm->bufftmp) + { + vm->nblocks -= vm->nbufftmp * sizeof (char); + vm->nbufftmp = 0; + __losu_mem_free (vm, vm->bufftmp); + vm->bufftmp = NULL; + } +} + +#endif /* define_source_losu_gc_collect */ diff --git a/core/losu_malloc.c b/core/losu_malloc.c new file mode 100755 index 0000000000000000000000000000000000000000..744b558aad6ed919f7646ec0bdd3d93eb160baba --- /dev/null +++ b/core/losu_malloc.c @@ -0,0 +1,95 @@ +/* + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#include "losu_malloc.h" +#include "losu.h" +#include "losu_errmsg.h" +#include +#include + +/** + * @brief realloc memory, if old is NULL, it is equivalent to malloc, if size + * is 0, it is equivalent to free + * @param vm LosuVm + * @param old old pointer + * @param size new size + * @return new pointer, if failed, return NULL + */ +void * +__losu_mem_realloc (LosuVm *vm, void *old, _l_size_t size) +{ + void *new = NULL; + if (size == 0) + { + if (old != NULL) + __config_losucore_mem_free (old); + return NULL; + } + + new = (void *)(__config_losucore_mem_realloc (old, size)); + if (new == NULL) + { + if (vm) + vm_error (vm, LosuErrorCode_Mem, + __config_losucore_errmsg_msgReallocFailed, old, size); + return NULL; + } + return new; +} + +void * +__losu_mem_grow (LosuVm *vm, void *block, _l_size_t i_num, int inc, + _l_size_t size, _l_size_t limit, const char *errormsg) +{ + /* + size_t newn = issues_num + inc; + if (issues_num >= limit - inc) + vm_error (vm, errormsg, ELS_ERRORBACK_RUN); + if ((newn ^ issues_num) <= issues_num || (issues_num > 0 && newn < 4)) + return block; + else + return els_Mem_realloc (vm, block, els_Object_power2 (newn) * size); + */ + + _l_size_t newn = i_num + inc; + if (newn >= limit) + vm_error (vm, LosuErrorCode_Mem, errormsg); + return __losu_mem_realloc (vm, block, newn * size); +} diff --git a/core/losu_object.c b/core/losu_object.c new file mode 100755 index 0000000000000000000000000000000000000000..ccbffa09e5037a2cabdb6ab9a8793a6c85049e41 --- /dev/null +++ b/core/losu_object.c @@ -0,0 +1,573 @@ +/* + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#include "losu_object.h" +#include "losu.h" +#include "losu_errmsg.h" +#include "losu_malloc.h" +#include +#include +#include +#include +#include +#include + +#ifndef __inline_static_segment +#define __inline_static_segment + +static LosuNode *__losuObjectUnitMainpoint (_inlineHash *t, LosuObj *key); +static void __losuObjectUnitSetvector (LosuVm *vm, _inlineHash *t, + int32_t size); +static int32_t __losuObjectUnitGetnsize (_inlineHash *t); +static void __losuObjectUnitRehash (LosuVm *vm, _inlineHash *t); + +#endif /* __inline_static_segment */ + +#ifndef define_source_losuobject_obj +#define define_source_losuobject_obj + +const LosuObj _inlineNullObj = { + .type = LosuTypeDefine_null, + .value = { NULL }, +}; + +_l_bool +__losu_object_isObjEqual (const LosuObj *t1, const LosuObj *t2) +{ + if (ovtype (t1) != ovtype (t2)) + { + if (ovtype (t1) == LosuTypeDefine_number + && ovtype (t2) == LosuTypeDefine_string) + return ovnumber (t1) == ostr2num (ovSstr (t2), NULL); + else if (ovtype (t2) == LosuTypeDefine_number + && ovtype (t1) == LosuTypeDefine_string) + return ovnumber (t2) == ostr2num (ovSstr (t1), NULL); + else + return 0; + } + switch (ovtype (t1)) + { + case LosuTypeDefine_byte: + case LosuTypeDefine_string: + return ovIstr (t1)->len == ovIstr (t2)->len + ? !memcmp (ovSstr (t1), ovSstr (t2), ovIstr (t1)->len) + : 0; + case LosuTypeDefine_number: + return ovnumber (t1) == ovnumber (t2); + /* case LosuTypeDefine_string: + return ovIstr (t1)->hash == ovIstr (t2)->hash + ? !strcmp (ovSstr (t1), ovSstr (t2)) + : 0; */ + case LosuTypeDefine_unit: + return ovhash (t1) == ovhash (t2); + case LosuTypeDefine_function: + return ovfunc (t1) == ovfunc (t2); + default: + return 0; + } +} + +_l_bool +__losu_object_str2num (const char *s, _l_number *n) +{ + char *endp; + _l_number res = ostr2num (s, &endp); + if (endp == s) + return 0; + while (isspace ((uint8_t)*endp)) + endp++; + if (*endp != '\0') + return 0; + *n = res; + return 1; +} + +#endif + +#ifndef define_source_losuobject_string +#define define_source_losuobject_string + +/* declare segment */ +#define sizestring(l) ((sizeof (_inlineString) + (l + 1 - 4) * sizeof (char))) +static _l_hash losuhash (const char *s, _l_size_t l); + +static _l_hash +losuhash (const char *s, _l_size_t len) +{ + _l_size_t h = len; + _l_size_t step = (len >> 5) | 1; + for (; len >= step; len -= step) + h = h ^ ((h << 5) + (h >> 2) + (unsigned char)*(s++)); + return (_l_hash)h; +} + +void +__losu_objStringPool_init (LosuVm *vm) +{ + vm->strpool.strobj = __losu_mem_newvector (vm, 1, _inlineString *); + vm->nblocks += sizeof (_inlineString *); + vm->strpool.size = 1; + vm->strpool.nsize = 0; + vm->strpool.strobj[0] = NULL; +} + +void +__losu_objStringPool_resize (LosuVm *vm, __vmStrseg *strpool, _l_hash s) +{ + _inlineString **newstrobj = __losu_mem_newvector (vm, s, _inlineString *); + /* for (_l_hash i = 0; i < s; i++) + newstrobj[i] = NULL; */ + memset (newstrobj, 0, s * sizeof (_inlineString *)); + for (_l_hash i = 0; i < strpool->size; i++) + { + _inlineString *p = strpool->strobj[i]; + while (p) + { + _inlineString *next = p->next; + _l_hash h = p->hash; + _l_hash h1 = h & (s - 1); + p->next = newstrobj[h1]; + newstrobj[h1] = p; + p = next; + } + } + __losu_mem_free (vm, strpool->strobj); + vm->nblocks += (s - strpool->size) * sizeof (_inlineString *); + strpool->size = s; + strpool->strobj = newstrobj; +} + +void +__losu_objStringPool_deinit (LosuVm *vm) +{ + vm->nblocks -= vm->strpool.size * sizeof (_inlineString *); + __losu_mem_free (vm, vm->strpool.strobj); +} + +_inlineString * +__losu_objString_new (LosuVm *vm, const char *s) +{ + return __losu_objString_newstr (vm, s, strlen (s)); +} +_inlineString * +__losu_objString_newconst (LosuVm *vm, const char *s) +{ + _inlineString *ts = __losu_objString_newstr (vm, s, strlen (s)); + if (!ts->marked) + ts->marked = CONSTMARK; + return ts; +} +_inlineString * +__losu_objString_newstr (LosuVm *vm, const char *s, _l_size_t len) +{ + _l_hash h = losuhash (s, len); + _l_hash h1 = h & (vm->strpool.size - 1); + _inlineString *ts; + for (ts = vm->strpool.strobj[h1]; ts; ts = ts->next) + { + if (ts->hash == h) + if (ts->len == len && (memcmp (s, ts->str, len) == 0)) + return ts; + } + ts = (_inlineString *)__losu_mem_malloc (vm, sizestring (len)); + ts->marked = 0; + ts->next = NULL; + ts->len = len; + ts->hash = h; + ts->cstidx = 0; + memcpy (ts->str, s, len); + ts->str[len] = '\0'; + vm->nblocks += sizestring (len); + + ts->next = vm->strpool.strobj[h1]; + vm->strpool.strobj[h1] = ts; + vm->strpool.nsize++; + if (vm->strpool.nsize > vm->strpool.size + && vm->strpool.size < __config_losucore_vm_strpoolMax / 2 + 1) + __losu_objStringPool_resize (vm, &vm->strpool, vm->strpool.size * 2); + + return ts; +} + +#undef sizestring +#endif /* define_source_losuobject_string */ + +#ifndef define_source_losuobject_func +#define define_source_losuobject_func +#define sizeInlineFunction(n) \ + (sizeof (_inlineFunction) + sizeof (LosuObj) * ((n))) + +_inlineScode *f; +#define sizeInlineScode(f) \ + ((sizeof (_inlineScode) + f->nlcnum * sizeof (_l_number) \ + + f->nlcstr * sizeof (_inlineString *) \ + + f->nlcscode * sizeof (_inlineScode *) \ + + f->ncode * sizeof (vmInstruction) \ + + f->nlocalvar * sizeof (_inlineLocalvar) \ + + f->nlineinfo * sizeof (int32_t))) + +_inlineScode * +__losu_objFunc_scodeNew (LosuVm *vm) +{ + _inlineScode *f = __losu_mem_new (vm, _inlineScode); + /* printf("new code %p\n", f); */ + memset ((void *)f, 0, sizeof (_inlineScode)); + f->marked = 0; + f->next = vm->inspool; + vm->inspool = f; + return f; +} +void +__losu_objFunc_scodeFree (LosuVm *vm, _inlineScode *f) +{ + /* printf("free code %p\n", f); */ + + if (f->ncode > 0) + vm->nblocks -= sizeInlineScode (f); + __losu_mem_free (vm, f->code); + __losu_mem_free (vm, f->localvar); + __losu_mem_free (vm, f->lcstr); + __losu_mem_free (vm, f->lcnum); + __losu_mem_free (vm, f->lcscode); + __losu_mem_free (vm, f->lineinfo); + __losu_mem_free (vm, f); +} + +_inlineFunction * +__losu_objFunc_new (LosuVm *vm, int32_t issnum) +{ + _l_size_t size = sizeInlineFunction (issnum); + _inlineFunction *f = (_inlineFunction *)__losu_mem_malloc (vm, size); + /* printf("new func %p\n", f); */ + f->next = vm->funcpool; + vm->funcpool = f; + f->mark = f; + f->nclosure = issnum; + vm->nblocks += size; + return f; +} +void +__losu_objFunc_free (LosuVm *vm, _inlineFunction *f) +{ + vm->nblocks -= sizeInlineFunction (f->nclosure); + /* printf("free func %p\n", f); */ + __losu_mem_free (vm, f); +} + +#undef sizeInlineFunction +#undef sizeInlineScode +#endif /* define_source_losuobject_func */ + +#ifndef define_source_losuobject_unit +#define define_source_losuobject_unit + +#define sizeInlineHash(n) (sizeof (_inlineHash) + sizeof (LosuNode) * (n)) + +const LosuObj * +__losu_objUnit_getglobal (LosuVm *vm, const char *name) +{ + return __losu_objUnit_getstr (vm->global, __losu_objString_new (vm, name)); +} +const LosuObj * +__losu_objUnit_get (_inlineHash *t, LosuObj *key) +{ + switch (ovtype (key)) + { + case LosuTypeDefine_number: + return __losu_objUnit_getnum (t, ovnumber (key)); + case LosuTypeDefine_string: + return __losu_objUnit_getstr (t, ovIstr (key)); + default: + return __losu_objUnit_getany (t, key); + } +} +const LosuObj * +__losu_objUnit_getany (_inlineHash *t, LosuObj *key) +{ + LosuNode *n = __losuObjectUnitMainpoint (t, key); + if (n) + { + do + { + if (__losu_object_isObjEqual ((const LosuObj *)(key), + (const LosuObj *)(&n->key))) + return (const LosuObj *)&n->value; + n = n->next; + } + while (n); + } + return (const LosuObj *)&_inlineNullObj; +} + +const LosuObj * +__losu_objUnit_getnum (_inlineHash *t, _l_number key) +{ + LosuNode *n = &t->node[(_l_hash)(key) & (t->size - 1)]; + do + { + if (ovtype ((&n->key)) == LosuTypeDefine_number + && ovnumber ((&n->key)) == key) + return (const LosuObj *)&n->value; + n = n->next; + } + while (n); + return (const LosuObj *)&_inlineNullObj; +} +const LosuObj * +__losu_objUnit_getstr (_inlineHash *t, _inlineString *key) +{ + LosuNode *n = &t->node[key->hash & (t->size - 1)]; + + do + { + + if (ovtype ((&n->key)) == LosuTypeDefine_string + && ovIstr ((&n->key))->hash == key->hash) + if (!strcmp (ovIstr ((&n->key))->str, key->str)) + return (const LosuObj *)&n->value; + + n = n->next; + } + while (n); + return (const LosuObj *)&_inlineNullObj; +} +const LosuNode * +__losu_objUnit_getnext (_inlineHash *t, LosuObj *key) +{ + int32_t i; + if (ovtype (key) == LosuTypeDefine_null) + i = 0; + else + { + const LosuObj *v = __losu_objUnit_get (t, key); + if (v == &_inlineNullObj) + return NULL; + i = (int32_t)(((char *)v - (char *)(&t->node[0].value)) + / sizeof (LosuNode) + + 1); + } + for (; i < t->size; i++) + { + LosuNode *n = &(t->node[i]); + if (ovtype ((&n->value)) != LosuTypeDefine_null) + return n; + } + + return NULL; +} + +_inlineHash * +__losu_objUnit_new (LosuVm *vm, int32_t size) +{ + + _inlineHash *t = __losu_mem_new (vm, _inlineHash); + t->next = vm->hashpool; + vm->hashpool = t; + t->mark = t; + t->size = 0; + vm->nblocks += sizeInlineHash (0); + t->node = NULL; + { + int32_t p = 4; + while (p <= size) + p <<= 1; + size = p; + } + __losuObjectUnitSetvector (vm, t, size); + return t; +} +void +__losu_objUnit_remove (_inlineHash *t, LosuObj *key) +{ + ovtype (key) = LosuTypeDefine_number; + ovnumber (key) = 0; +} +void +__losu_objUnit_free (LosuVm *vm, _inlineHash *t) +{ + vm->nblocks -= sizeInlineHash (t->size); + __losu_mem_free (vm, t->node); + __losu_mem_free (vm, t); +} + +LosuObj * +__losu_objUnit_set (LosuVm *vm, _inlineHash *t, LosuObj *key) +{ + LosuNode *mp = __losuObjectUnitMainpoint (t, key); + LosuNode *n = mp; + if (!mp) + vm_error (vm, LosuErrorCode_Runtime, + __config_losucore_errmsg_msgInvalidUnitIndex); + do + { + if (__losu_object_isObjEqual (key, &n->key)) + return &n->value; + n = n->next; + } + while (n); + if (ovtype ((&mp->key)) != LosuTypeDefine_null) + { + LosuNode *oth; + n = t->free; + if (mp > n && (oth = __losuObjectUnitMainpoint (t, &mp->key)) != mp) + { + while (oth->next != mp) + oth = oth->next; + oth->next = n; + *n = *mp; + mp->next = NULL; + } + else + { + n->next = mp->next; + mp->next = n; + mp = n; + } + } + mp->key = *key; + while (1) + { + if (ovtype ((&t->free->key)) == LosuTypeDefine_null) + return &mp->value; + else if (t->free == t->node) + break; + else + (t->free)--; + } + __losuObjectUnitRehash (vm, t); + return __losu_objUnit_set (vm, t, key); +} + +LosuObj * +__losu_objUnit_setnum (LosuVm *vm, _inlineHash *t, _l_number key) +{ + LosuObj idx = (LosuObj){ + .type = LosuTypeDefine_number, + .value.num = key, + }; + return __losu_objUnit_set (vm, t, &idx); +} +LosuObj * +__losu_objUnit_setstr (LosuVm *vm, _inlineHash *t, _inlineString *key) +{ + LosuObj idx = (LosuObj){ + .type = LosuTypeDefine_string, + .value.str = key, + }; + return __losu_objUnit_set (vm, t, &idx); +} + +static LosuNode * +__losuObjectUnitMainpoint (_inlineHash *t, LosuObj *key) +{ + _l_size_t h; + switch (key->type) + { + case LosuTypeDefine_number: + h = (_l_size_t)(ovnumber (key)); + break; + case LosuTypeDefine_string: + case LosuTypeDefine_byte: + h = (_l_size_t)(ovIstr (key)->hash); + break; + case LosuTypeDefine_unit: + h = (_l_size_t)((size_t)(ovhash (key))); + break; + case LosuTypeDefine_function: + h = (_l_size_t)((size_t)(ovfunc (key))); + break; + default: + return NULL; + } + return &t->node[h & (t->size - 1)]; +} +static void +__losuObjectUnitSetvector (LosuVm *vm, _inlineHash *t, int32_t size) +{ + int32_t i; + if (size > INT32_MAX) + vm_error (vm, LosuErrorCode_Runtime, + __config_losucore_errmsg_msgVectorOverflow); + t->node = __losu_mem_newvector (vm, size, LosuNode); + for (i = 0; i < size; i++) + { + ovtype ((&t->node[i].key)) = ovtype ((&t->node[i].value)) + = LosuTypeDefine_null; + t->node[i].next = NULL; + } + vm->nblocks += (sizeInlineHash (size)) - (sizeInlineHash (t->size)); + t->size = size; + t->free = &t->node[size - 1]; +} +static int32_t +__losuObjectUnitGetnsize (_inlineHash *t) +{ + LosuNode *v = t->node; + int32_t s = t->size; + int32_t use = 0; + int32_t i; + for (i = 0; i < s; i++) + if (ovtype ((&v[i].value)) != LosuTypeDefine_null) + use++; + return use; +} +static void +__losuObjectUnitRehash (LosuVm *vm, _inlineHash *t) +{ + int32_t osize = t->size; + LosuNode *onode = t->node; + int32_t uszie = __losuObjectUnitGetnsize (t); + int32_t i; + if (uszie >= osize - osize / 4) + __losuObjectUnitSetvector (vm, t, osize * 2); + else if (uszie <= osize / 4 && osize > 4) + __losuObjectUnitSetvector (vm, t, osize / 2); + else + __losuObjectUnitSetvector (vm, t, osize); + + for (i = 0; i < osize; i++) + if (ovtype ((&((onode + i)->value))) != LosuTypeDefine_null) + *__losu_objUnit_set (vm, t, &(onode + i)->key) + = ((LosuNode *)(onode + i))->value; + __losu_mem_free (vm, onode); +} + +#undef sizeInlineHash +#endif diff --git a/core/losu_syntax.c b/core/losu_syntax.c new file mode 100755 index 0000000000000000000000000000000000000000..3ddb602f46619697c036dd0b3697306240267147 --- /dev/null +++ b/core/losu_syntax.c @@ -0,0 +1,3647 @@ +/* + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +/* + This is the syntax analysis code for Losu, the complete compiler + implementation, consisting of Lexer, Parser & Codegen. Parses script code + written using Losu and converts it to in-memory bytecode form +*/ + +#include "losu_syntax.h" +#include "losu_bytecode.h" +#include "losu_errmsg.h" +#include "losu_gc.h" +#include "losu_malloc.h" +#include "losu_object.h" +#include "losu_vm.h" +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef define_source_losusyntax_staticseg +#define define_source_losusyntax_staticseg +/* static segment */ + +/* IO */ +static void __losuSyntaxError (_syntaxLex *lex, const char *msg, ...); + +/* Lexer */ +static void __losuSyntaxLexSetin (LosuVm *vm, _syntaxLex *lex, _syntaxIO *io, + _inlineString *src); +static int16_t __losuSyntaxLexNext (_syntaxLex *lex, _syntaxTkvalue *tkv); +static void __losuSyntaxLexTtS (int16_t tk, char *s); + +/* Parser */ +static void __losuSyntaxParError (_syntaxLex *lex, int16_t tk); +static void __losuSyntaxParNewfunc (_syntaxLex *lex, _syntaxFunc *func); +static void __losuSyntaxParDelfunc (_syntaxLex *lex); +static void __losuSyntaxParNext (_syntaxLex *lex); +static _l_bool __losuSyntaxParCheckBlock (int16_t tk); +static void __losuSyntaxParCheck (_syntaxLex *lex, int16_t tk); +static void __losuSyntaxParCheckCondtion (_syntaxLex *lex, _l_bool c, + const char *s); +static void __losuSyntaxParCheckMatch (_syntaxLex *lex, int16_t l, int16_t r, + int32_t line); +static _inlineString *__losuSyntaxParCheckName (_syntaxLex *lex); +static void __losuSyntaxParCheckLimit (_syntaxLex *lex, int32_t v, int32_t l, + const char *errmsg); + +static void __losuSyntaxParNewlcvar (_syntaxLex *lex, _inlineString *name, + int16_t i); +static void __losuSyntaxParRemovelcvar (_syntaxLex *lex, int16_t i); +static _l_bool __losuSyntaxParStat (_syntaxLex *lex); +static void __losuSyntaxParStatIf (_syntaxLex *lex, int32_t line); +static void __losuSyntaxParStatWith (_syntaxLex *lex, int32_t line); +static void __losuSyntaxParStatBlock (_syntaxLex *lex); +static void __losuSyntaxParStatFor (_syntaxLex *lex, int32_t line); +static void __losuSyntaxParStatLoop (_syntaxLex *lex, int32_t line); +static void __losuSyntaxParStatUntil (_syntaxLex *lex, int32_t line); +static void __losuSyntaxParStatFunc (_syntaxLex *lex, int32_t line); +static void __losuSyntaxParStatVar (_syntaxLex *lex); +static void __losuSyntaxParStatName (_syntaxLex *lex); +static void __losuSyntaxParStatReturn (_syntaxLex *lex); +static void __losuSyntaxParStatBreak (_syntaxLex *lex); +static void __losuSyntaxParEnterbreak (_syntaxFunc *func, _syntaxBreak *br); +static void __losuSyntaxParLeavebreak (_syntaxFunc *func, _syntaxBreak *br); +static void __losuSyntaxParStatForNum (_syntaxLex *lex, _inlineString *vname); +static void __losuSyntaxParStatForObj (_syntaxLex *lex, _inlineString *vname); +static void __losuSyntaxParStatForBody (_syntaxLex *lex, _l_bool isO); +static _l_bool __losuSyntaxParStatFuncName (_syntaxLex *lex, _syntaxExp *v); +static void __losuSyntaxParStatFuncBody (_syntaxLex *lex, _l_bool nself, + int32_t line); +static void __losuSyntaxParStatFuncParlist (_syntaxLex *lex); +static int32_t __losuSyntaxParStatNameAssment (_syntaxLex *lex, _syntaxExp *v, + int32_t nvar); +static int32_t __losuSyntaxParExplist (_syntaxLex *lex); +static void __losuSyntaxParAdStack (_syntaxLex *lex, int32_t nv, int32_t ne); +static void __losuSyntaxParAdLcvar (_syntaxLex *lex, int32_t nv); +static void __losuSyntaxParVarFunc (_syntaxLex *lex, _syntaxExp *v); +static void __losuSyntaxParExp (_syntaxLex *lex); +static void __losuSyntaxParSvar (_syntaxLex *lex, _inlineString *n, + _syntaxExp *v); +static int32_t __losuSyntaxParStrconst (_syntaxFunc *func, _inlineString *s); +static int32_t __losuSyntaxParSubExp (_syntaxLex *lex, _syntaxExp *v, int l); +static void __losuSyntaxParExpFargs (_syntaxLex *lex, _l_bool slf); +static int32_t __losuSyntaxParExpVarlevel (_syntaxLex *lex, _inlineString *n, + _syntaxExp *v); +static void __losuSyntaxParSimpleExp (_syntaxLex *lex, _syntaxExp *v); +static void __losuSyntaxParUnitConstructor (_syntaxLex *lex); +static int32_t __losuSyntaxParUnitMapfield (_syntaxLex *lex); +static int32_t __losuSyntaxParUnitListfield (_syntaxLex *lex); + +/* Codegen */ +static int32_t __losuSyntaxCgenCodearg (_syntaxFunc *func, vmIns_OP o, + int32_t arg1, int32_t arg2); +static void __losuSyntaxCgenConcat (_syntaxFunc *func, int32_t *l1, + int32_t l2); +static int32_t __losuSyntaxCgenJump (_syntaxFunc *func); +static void __losuSyntaxCgenPalist (_syntaxFunc *func, int32_t list, + int32_t target); +static int32_t __losuSyntaxCgenGetL (_syntaxFunc *func); +static void __losuSyntaxCgenGoT (_syntaxFunc *func, _syntaxExp *v, + int32_t keep); +static void __losuSyntaxCgenGoF (_syntaxFunc *func, _syntaxExp *v, + int32_t keep); +static void __losuSyntaxCgenTostack (_syntaxLex *lex, _syntaxExp *v, + int32_t o); +static void __losuSyntaxCgenAdStack (_syntaxFunc *func, int32_t n); +static void __losuSyntaxCgenSetVar (_syntaxLex *lex, _syntaxExp *var); +static _l_bool __losuSyntaxCgenIsopen (_syntaxFunc *func); +static void __losuSyntaxCgenSetNcallr (_syntaxFunc *func, int32_t nres); +static void __losuSyntaxCgenNumber (_syntaxFunc *func, _l_number f); +static void __losuSyntaxCgenDtStack (_syntaxFunc *func, int32_t dt); +static void __losuSyntaxCgenPrefix (_syntaxLex *lex, vmIns_UnOp op, + _syntaxExp *v); +static void __losuSyntaxCgenInfix (_syntaxLex *lex, vmIns_BinOp op, + _syntaxExp *v); +static void __losuSyntaxCgenPosfix (_syntaxLex *lex, vmIns_BinOp op, + _syntaxExp *v1, _syntaxExp *v2); +static int32_t __losuSyntaxCgenGetJump (_syntaxFunc *func, int32_t pc); +static void __losuSyntaxCgenFixJump (_syntaxFunc *func, int32_t pc, + int32_t dt); +static void __losuSyntaxCgenPlistfunc (_syntaxFunc *func, int32_t list, + int32_t tg, vmIns_OP ins, + int32_t instg); +static void __losuSyntaxCgenGo (_syntaxFunc *func, _syntaxExp *v, int32_t inv, + vmIns_OP jump); +static _l_bool __losuSyntaxCgenDischarge (_syntaxFunc *func, _syntaxExp *v); +static _l_bool __losuSyntaxCgenNeedval (_syntaxFunc *func, int32_t l, + vmIns_OP v); +static vmIns_OP __losuSyntaxCgenJumpInvert (vmIns_OP op); + +#endif /* define_source_losusyntax_staticseg */ + +#ifndef define_source_losusyntax_io +#define define_source_losusyntax_io + +#define EOZ (-1) + +int32_t +__losu_syntaxIO_doload (LosuVm *vm, _syntaxIO *io) +{ + /* _l_gcint oldblock; */ + int32_t sta; + __losu_gc_checkClt (vm); + + LosuObj *oldbase = vm->base; + LosuObj *oldtop = vm->top; + __longjump lj = { + .err = 0, + .pre = vm->errjmp, + }; + vm->errjmp = &lj; + if (setjmp (lj.jmpflag) == 0) + { + _inlineScode *fcd = io->bin ? __losu_syntaxIrload_load (vm, io) + : __losu_syntaxParser_parse (vm, io); + _inlineFunction *f = __losu_objFunc_new (vm, 0); + ovtype ((vm->top)) = LosuTypeDefine_function; + ovfunc ((vm->top)) = f; + vm->top++; + f->func.sdef = fcd; + f->isC = 0; + } + else + { + vm->base = oldbase; + vm->top = oldtop; + if (vm->top - vm->stack < vm->stacksize - 1) + vm->stackmax = vm->stack + (vm->stacksize - 1); + } + vm->errjmp = lj.pre; + sta = lj.err; + /* if (sta == 0) + vm->gcDymax += (vm->nblocks - oldblock); + else */ + if (sta == LosuErrorCode_Runtime) + sta = LosuErrorCode_Syntax; + return sta; +} + +int32_t +__losu_syntaxIO_loadfile (LosuVm *vm, const char *fn) +{ + _syntaxIO io = { 0 }; + int32_t sta; + FILE *f = fopen (fn, "rb"); + if (f == NULL) + return LosuErrorCode_File; + __losu_syntaxIO_openH (&io, (void *)f, fn); + + /* bin or txt */ + int32_t c = fgetc (f); + if (c == 0) /* bin */ + io.bin = 1; + ungetc (c, f); + + const char *on = vm->name; + vm->name = fn; + sta = __losu_syntaxIO_doload (vm, &io); + vm->name = on; + fclose (f); + return sta; +} + +int32_t +__losu_syntaxIO_loadstring (LosuVm *vm, const char *str, _l_size_t len, + const char *name) +{ + _syntaxIO io = { 0 }; + __losu_syntaxIO_openS (&io, str, len, name); + + /* bin or txt */ + if (io.p[0] == 0) + io.bin = 1; + + const char *on = vm->name; + vm->name = name; + int32_t sta = __losu_syntaxIO_doload (vm, &io); + vm->name = on; + return sta; +} + +int16_t +__losu_syntaxIOS_fillbuff (_syntaxIO *io) +{ + return EOZ; +} +int16_t +__losu_syntaxIOH_fillbuff (_syntaxIO *io) +{ + _l_size_t n = 0; + if (feof ((FILE *)(io->h))) + return EOZ; + n = fread (io->buff, sizeof (char), __config_losucore_vm_iobuff, + (FILE *)(io->h)); + if (!n) + return EOZ; + io->size = n - 1; + io->p = io->buff; + return (int16_t)(*(io->p++)); +} + +void +__losu_syntaxIO_openH (_syntaxIO *io, void *h, const char *name) +{ + if (h) + { + io->size = 0; + io->p = io->buff; + io->fillbuff = __losu_syntaxIOH_fillbuff; + io->h = h; + io->name = name; + } +} + +void +__losu_syntaxIO_openS (_syntaxIO *io, const char *p, _l_size_t size, + const char *name) +{ + io->size = (p == NULL) ? 0 : size; + io->p = (const unsigned char *)p; + io->fillbuff = __losu_syntaxIOS_fillbuff; + io->name = name; +} + +static void +__losuSyntaxError (_syntaxLex *lex, const char *msg, ...) +{ + memset (lex->vm->staticbuff, 0, sizeof (lex->vm->staticbuff)); + va_list ap; + va_start (ap, msg); + vsprintf ((char *)(lex->vm->staticbuff), msg, ap); + fprintf (stderr, "Syntax Error: %s\n at line %d of '%s' \n", + lex->vm->staticbuff, lex->linenumber, + lex->io->name != NULL ? lex->io->name : ""); + va_end (ap); + __losu_vmHeap_break (lex->vm, LosuErrorCode_Syntax); +} + +#undef EOZ +#endif /* define_source_losusyntax_io */ + +#ifndef define_source_losusyntax_lexer +#define define_source_losusyntax_lexer + +/* declare segment */ +#define EOZ -1 +#define next(Lex) (Lex->current = __losu_syntaxIO_getc (Lex->io)) +#define save(vm, c, l) (vm->bufftmp[l++] = (unsigned char)c) +#define save_next(vm, Lex, l) (save (vm, Lex->current, l), next (Lex)) +#define incline(Lex) ((Lex->linenumber)++) +static void checkbuffer (LosuVm *vm, _l_size_t n, _l_size_t len); + +/* data segment */ +struct +{ + const char *str; + int16_t key; + int8_t idt; /* idt or not? */ +} static const __keyword[] = { + + { "and", TOKEN_AND, 0 }, + { "not", TOKEN_NOT, 0 }, + { "or", TOKEN_OR, 0 }, + + { "local", TOKEN_BLOCK, 1 }, + + { "if", TOKEN_IF, 1 }, + { "else", TOKEN_ELSE, 1 }, + { "elif", TOKEN_ELSEIF, 1 }, + { "pass", TOKEN_END, -1 }, + + { "def", TOKEN_FUNCTION, 1 }, + { "...", TOKEN_ARG, 0 }, + + { "var", TOKEN_VAR, 0 }, + { "null", TOKEN_NULL, 0 }, + + { "return", TOKEN_RETURN, 0 }, + { "break", TOKEN_BREAK, 0 }, + + { "with", TOKEN_WITH, 1 }, + { "until", TOKEN_UNTIL, 1 }, + { "loop", TOKEN_LOOP, 0 }, + { "to", TOKEN_TO, 0 }, + + { "for", TOKEN_FOR, 1 }, + + { "==", TOKEN_EQ, 0 }, + { ">=", TOKEN_GE, 0 }, + { "<=", TOKEN_LE, 0 }, + { "!=", TOKEN_NE, 0 }, + { "!=", TOKEN_NE, 0 }, + { "&", TOKEN_CONCAT, 0 }, + +#ifdef __config_losucore_feature_chKeyword + { "且", TOKEN_AND, 0 }, + { "非", TOKEN_NOT, 0 }, + { "或", TOKEN_OR, 0 }, + + { "如果", TOKEN_IF, 0 }, + { "否则", TOKEN_ELSE, 0 }, + { "另外", TOKEN_ELSEIF, 0 }, + + { "定义", TOKEN_FUNCTION, 0 }, + + { "令", TOKEN_VAR, 0 }, + { "空", TOKEN_NULL, 0 }, + + { "返回", TOKEN_RETURN, 0 }, + { "跳出", TOKEN_BREAK, 0 }, + + { "满足", TOKEN_WITH, 0 }, + { "直到", TOKEN_UNTIL, 0 }, + { "重复", TOKEN_LOOP, 0 }, + { "至", TOKEN_TO, 0 }, + + { "计次", TOKEN_FOR, 0 }, + + /* Only chKeyword */ + { "__极值__", TOKEN_FOR_MAX, 0 }, + { "__步幅__", TOKEN_FOR_STEP, 0 }, + { "__此__", TOKEN_FOR_THIS, 0 }, + { "此", TOKEN_THIS, 0 }, + { "构造", TOKEN_CONST, 0 }, + { "变参", TOKEN_VARARG, 0 }, + { "属", TOKEN_IN, 0 }, +#endif + +}; + +/* code segment */ +void +checkbuffer (LosuVm *vm, _l_size_t n, _l_size_t len) +{ + _l_size_t nlen = n + len; + if (nlen <= vm->nbufftmp) + return; + __losu_mem_reallocvector (vm, vm->bufftmp, nlen, unsigned char); + vm->nblocks += (nlen - vm->nbufftmp) * sizeof (char); + vm->nbufftmp = nlen; +} + +void +__losu_syntaxLex_init (LosuVm *vm) +{ + for (int16_t i = 0; i < sizeof (__keyword) / sizeof (__keyword[0]); i++) + { + _inlineString *s = __losu_objString_new (vm, __keyword[i].str); + s->marked = __keyword[i].key; + } +} + +static void +__losuSyntaxLexTtS (int16_t tk, char *s) +{ + if (tk < 256) + { + s[0] = (unsigned char)tk; + s[1] = '\0'; + } + else + { + int16_t i; + for (i = 0; i < sizeof (__keyword) / sizeof (__keyword[0]); i++) + if (__keyword[i].key == tk) + break; + strcpy (s, __keyword[i].str); + } +} + +static void +__losuSyntaxLexSetin (LosuVm *vm, _syntaxLex *lex, _syntaxIO *io, + _inlineString *src) +{ + lex->vm = vm; + lex->tkahead.token = TOKEN_EOZ; + lex->io = io; + lex->fs = NULL; + lex->lastline = lex->linenumber = 1; + lex->source = src; + next (lex); +} + +static uint8_t +__utf8CheckLen (uint8_t c) +{ + /** 单字节序列的 leader byte 总是在(0-127)范围内。 + * 两字节序列的 leader byte 在(194-223)范围内。 + * 三字节序列的 leader byte 在(224-239)范围内。 + * 四字节序列的 leader byte 在(240-247)范围内。 + * */ + uint8_t len = 0; + if (c < 0x80) + { /* then UTF-8 单字节 */ + len = 1; + } + else if (c >= 0xC2 && c <= 0xDF) + { /* then 首字节 UTF-8 占用2个字节 */ + len = 2; + } + else if (c >= 0xE0 && c <= 0xEF) + { /* then 首字节 UTF-8 占用3个字节 */ + len = 3; + } + else if (c >= 0xF0 && c <= 0xF7) + { /* then 首字节 UTF-8 占用4个字节 */ + len = 4; + } + + return len; +} + +static unsigned char * +__lexReadname (_syntaxLex *lex) +{ + LosuVm *vm = lex->vm; + _l_size_t l = 0; + do + { + uint8_t len = __utf8CheckLen ((uint8_t)(lex->current)); + for (uint8_t i = 0; i < len; i++) + { + checkbuffer (vm, l, 32); + save_next (vm, lex, l); + } + } + while (isalnum (lex->current) || lex->current == '_' + || __utf8CheckLen ((uint8_t)(lex->current)) > 1); + save (vm, '\0', l); + return vm->bufftmp; +} + +static void +__lexReadnumber (_syntaxLex *lex, _l_bool dot, _syntaxTkvalue *tkv) +{ + LosuVm *vm = lex->vm; + _l_size_t l = 0; + checkbuffer (vm, l, 32); + if (dot) + save (vm, '.', l); + while (isdigit (lex->current)) + { + checkbuffer (vm, l, 32); + save_next (vm, lex, l); + } + if (lex->current == '.') + { + save_next (vm, lex, l); + if (lex->current == '.') + { + save (vm, '\0', l); + __losuSyntaxError (lex, __config_losucore_errmsg_msgInvalidNumber, + vm->bufftmp); + } + } + while (isdigit (lex->current)) + { + checkbuffer (vm, l, 32); + save_next (vm, lex, l); + } + if (lex->current == 'e' || lex->current == 'E') + { + save_next (vm, lex, l); + if (lex->current == '+' || lex->current == '-') + save_next (vm, lex, l); + while (isdigit (lex->current)) + { + checkbuffer (vm, l, 32); + save_next (vm, lex, l); + } + } + save (vm, '\0', l); + if (!__losu_object_str2num ((const char *)vm->bufftmp, &tkv->num)) + __losuSyntaxError (lex, __config_losucore_errmsg_msgInvalidNumber, + vm->bufftmp); +} + +static _l_bool +__lexReadstring (_syntaxLex *lex, uint8_t del, _syntaxTkvalue *tkv) +{ + LosuVm *vm = lex->vm; + _l_size_t l = 0; + checkbuffer (vm, l, 32); + save_next (vm, lex, l); + if (lex->current != del) + { + while (lex->current != del) + { + if (lex->current == EOZ || lex->current == '\n') + __losuSyntaxError (lex, __config_losucore_errmsg_msgMissStrEnd, + del); /* missing terminating character %c */ + + checkbuffer (vm, l, 32); + + if (lex->current == '%') + { + next (lex); + uint8_t t = 0; + if (!(('0' <= lex->current && lex->current <= '9') + || ('a' <= lex->current && lex->current <= 'f') + || ('A' <= lex->current && lex->current <= 'F'))) + __losuSyntaxError ( + lex, __config_losucore_errmsg_msgInvalidEscapeHex); + /* % used with no following hex digits */ + switch (lex->current) + { + case 'A': + case 'a': + t = 16 * 10; + break; + case 'B': + case 'b': + t = 16 * 11; + break; + case 'C': + case 'c': + t = 16 * 12; + break; + case 'D': + case 'd': + t = 16 * 13; + break; + case 'E': + case 'e': + t = 16 * 14; + break; + case 'F': + case 'f': + t = 16 * 15; + break; + + default: + t = 16 * (lex->current - '0'); + } + next (lex); + if (!(('0' <= lex->current && lex->current <= '9') + || ('a' <= lex->current && lex->current <= 'f') + || ('A' <= lex->current && lex->current <= 'F'))) + __losuSyntaxError ( + lex, __config_losucore_errmsg_msgInvalidEscapeHex); + /* % used with no following hex digits */ + switch (lex->current) + { + case 'A': + case 'a': + t += 10; + break; + case 'B': + case 'b': + t += 11; + break; + case 'C': + case 'c': + t += 12; + break; + case 'D': + case 'd': + t += 13; + break; + case 'E': + case 'e': + t += 14; + break; + case 'F': + case 'f': + t += 15; + break; + + default: + t += (lex->current - '0'); + } + save (vm, (unsigned char)t, l); + next (lex); + continue; + } + + if (lex->current == '\\') + { + next (lex); + switch (lex->current) + { + case 'a': + save (vm, '\a', l); + next (lex); + break; + case 'b': + save (vm, '\b', l); + next (lex); + break; + case 'f': + save (vm, '\f', l); + next (lex); + break; + case 'n': + save (vm, '\n', l); + next (lex); + break; + case 'r': + save (vm, '\r', l); + next (lex); + break; + case 't': + save (vm, '\t', l); + next (lex); + break; + case 'v': + save (vm, '\v', l); + next (lex); + break; + case '\\': + save (vm, '\\', l); + next (lex); + break; + case '\'': + save (vm, '\'', l); + next (lex); + break; + case '\"': + save (vm, '\"', l); + next (lex); + break; + case '\r': + save (vm, '\n', l); + next (lex); + incline (lex); + if (lex->current == '\n') + next (lex); + break; + case '\n': + save (vm, '\n', l); + next (lex); + incline (lex); + break; + case 'u': + { + uint8_t i = 1, clen = 1; + volatile uint8_t t = 0; + while (1) + { + + next (lex); + if (!(('0' <= lex->current && lex->current <= '9') + || ('a' <= lex->current && lex->current <= 'f') + || ('A' <= lex->current && lex->current <= 'F'))) + __losuSyntaxError ( + lex, + __config_losucore_errmsg_msgInvalidEscapeHex); + /* % used with no following hex digits */ + switch (lex->current) + { + case 'A': + case 'a': + t = 16 * 10; + break; + case 'B': + case 'b': + t = 16 * 11; + break; + case 'C': + case 'c': + t = 16 * 12; + break; + case 'D': + case 'd': + t = 16 * 13; + break; + case 'E': + case 'e': + t = 16 * 14; + break; + case 'F': + case 'f': + t = 16 * 15; + break; + + default: + t = 16 * (lex->current - '0'); + } + next (lex); + if (!(('0' <= lex->current && lex->current <= '9') + || ('a' <= lex->current && lex->current <= 'f') + || ('A' <= lex->current && lex->current <= 'F'))) + __losuSyntaxError ( + lex, + __config_losucore_errmsg_msgInvalidEscapeHex); + /* % used with no following hex digits */ + switch (lex->current) + { + case 'A': + case 'a': + t += 10; + break; + case 'B': + case 'b': + t += 11; + break; + case 'C': + case 'c': + t += 12; + break; + case 'D': + case 'd': + t += 13; + break; + case 'E': + case 'e': + t += 14; + break; + case 'F': + case 'f': + t += 15; + break; + + default: + t += (lex->current - '0'); + } + if (i == 1) + clen = __utf8CheckLen (t); + if (clen == 0) + { + __losuSyntaxError ( + lex, + __config_losucore_errmsg_msgInvalidEscapeUtf8); + break; + } + save (vm, t, l); + if (i >= clen) + break; + i++; + } + next (lex); + break; + } + default: + save_next (vm, lex, l); + } + continue; + } + save_next (vm, lex, l); + } + save_next (vm, lex, l); + save (vm, '\0', l); + tkv->s = __losu_objString_newstr (vm, (const char *)(vm->bufftmp) + 1, + l - 3); + return 0; + } + else + { + save_next (vm, lex, l); + if (lex->current != del) + { + save (vm, '\0', l); + tkv->s = __losu_objString_newstr ( + vm, (const char *)(vm->bufftmp) + 1, l - 3); + return 0; + } + else + { + while (1) + { + next (lex); + if (lex->current == '\n') + (lex->linenumber)++; + if (lex->current == EOZ) + __losuSyntaxError ( + lex, __config_losucore_errmsg_msgInvalidBlockComment); + if (lex->current == del) + { + next (lex); + if (lex->current == del) + { + next (lex); + if (lex->current == del) + { + next (lex); + return 1; + } + } + } + } + } + } +} + +static void +__lexReadPurestring (_syntaxLex *lex, uint8_t del, _syntaxTkvalue *tkv) +{ + LosuVm *vm = lex->vm; + _l_size_t l = 0; + checkbuffer (vm, l, 32); + save_next (vm, lex, l); + while (lex->current != del) + { + if (lex->current == '\n' || lex->current == EOZ) + __losuSyntaxError (lex, __config_losucore_errmsg_msgMissStrEnd, del); + checkbuffer (vm, l, 32); + save_next (vm, lex, l); + } + save_next (vm, lex, l); + save (vm, '\0', l); + tkv->s + = __losu_objString_newstr (vm, (const char *)(vm->bufftmp) + 1, l - 3); +} + +static int16_t +__losuSyntaxLexNext (_syntaxLex *lex, _syntaxTkvalue *tkv) +{ + if (lex->_syntaxLexIdt.tmp > 0) + { + lex->_syntaxLexIdt.tmp--; + lex->_syntaxLexIdt.nowidt--; + return TOKEN_END; + } + while (1) + { + + switch (lex->current) + { + /* comment */ + case '#': + { + while (lex->current != '\n') + { + next (lex); + if (lex->current == EOZ) + return TOKEN_EOZ; + } + break; + } + case ';': + { + next ((lex)); + continue; + } + /* line++ */ + case '\n': + { + next (lex); + incline (lex); + /* check idt */ + lex->_syntaxLexIdt.read = 0; + uint8_t i = 0; + while (1) + { + /* printf ("P:%c\n", lex->current == EOZ ? '@' : lex->current); + */ + switch (lex->current) + { + case '\n': + { + lex->_syntaxLexIdt.read = 0; + incline (lex); + break; + } + case ' ': + { + lex->_syntaxLexIdt.read++; + break; + } + case '\t': + { + lex->_syntaxLexIdt.read += lex->_syntaxLexIdt.size; + break; + } + default: + { + /* printf ("line:%d,idt:%d\n", lex->linenumber, + lex->_syntaxLexIdt.nowidt); */ + i = 1; + /* if (lex->current == '}' || lex->current == ')') + { + i = 2; + lex->_syntaxLexIdt.nowidt--; + } */ + if (lex->_syntaxLexIdt.read + < lex->_syntaxLexIdt.nowidt + * lex->_syntaxLexIdt.size) /* need idt */ + { + if (lex->_syntaxLexIdt.read + % lex->_syntaxLexIdt.size) /* not muti */ + __losuSyntaxError ( + lex, + __config_losucore_errmsg_msgInvalidIdtMutiple, + lex->_syntaxLexIdt.size, + lex->_syntaxLexIdt.read); + lex->_syntaxLexIdt.tmp + = lex->_syntaxLexIdt.nowidt + - lex->_syntaxLexIdt.read + / lex->_syntaxLexIdt.size; + if (lex->current == '}' || lex->current == ')') + lex->_syntaxLexIdt.tmp--; + if (lex->_syntaxLexIdt.tmp > 0) + { + lex->_syntaxLexIdt.tmp--; + lex->_syntaxLexIdt.nowidt--; + return TOKEN_END; + } + } + /* if (i == 2) + lex->_syntaxLexIdt.nowidt++; */ + break; + } + } + if (i) + break; + next (lex); + } + continue; + } + case EOZ: + { + if (lex->_syntaxLexIdt.nowidt) + { + lex->_syntaxLexIdt.tmp = lex->_syntaxLexIdt.nowidt; + lex->_syntaxLexIdt.tmp--; + lex->_syntaxLexIdt.nowidt--; + return TOKEN_END; + } + return TOKEN_EOZ; + } + /* case ':': + { + return ':'; + } */ + case '{': + { + next (lex); + lex->_syntaxLexIdt.nowidt++; + return '{'; + } + case '}': + { + next (lex); + lex->_syntaxLexIdt.nowidt--; + return '}'; + } + case '(': + { + next (lex); + lex->_syntaxLexIdt.nowidt++; + return '('; + } + case ')': + { + next (lex); + lex->_syntaxLexIdt.nowidt--; + return ')'; + } + + /* next */ + case '\r': + case '\t': + case ' ': + case '\0': + { + next (lex); + continue; + } + + /* string */ + case '\'': + case '\"': + { + if (__lexReadstring (lex, lex->current, tkv)) + continue; + return TOKEN_STRING; + } + case '$': + { + next (lex); + if (lex->current == '\'' || lex->current == '\"') + { + __lexReadPurestring (lex, lex->current, tkv); + return TOKEN_STRING; + } + else + __losuSyntaxError ( + lex, __config_losucore_errmsg_msgInvalidPureString); + } + + /* < = > */ + case '<': + { + next (lex); + if (lex->current == '=') + { + next (lex); + return TOKEN_LE; + } + else if (lex->current == '<') + { + next (lex); + return TOKEN_BLOCK; + } + else + return '<'; + } + case '=': + { + next (lex); + if (lex->current != '=') + return '='; + else + { + next (lex); + return TOKEN_EQ; + } + } + case '>': + { + next (lex); + if (lex->current == '=') + { + next (lex); + return TOKEN_GE; + } + /* else if (lex->current == '>') + { + next (lex); + return TOKEN_ENDB; + } */ + else + return '>'; + } + + /* & or && */ + case '&': + { + next (lex); +#ifdef __config_losucore_feature_cStyle + if (lex->current == '&') + { + next (lex); + return TOKEN_AND; + } + else +#endif + return TOKEN_CONCAT; + } + + /* || */ + case '|': + { + next (lex); +#ifdef __config_losucore_feature_cStyle + if (lex->current == '|') + { + next (lex); + return TOKEN_OR; + } + else +#endif + return '|'; + } + + /* != or ! */ + case '!': + { + next (lex); + if (lex->current == '=') + { + next (lex); + return TOKEN_NE; + } + +#ifdef __config_losucore_feature_cStyle + else + return TOKEN_NOT; +#endif + } + case '.': + { + next (lex); + if (lex->current == '.') + { + next (lex); + if (lex->current == '.') + { + next (lex); + return TOKEN_ARG; + } + else + __losuSyntaxError ( + lex, __config_losucore_errmsg_msgUnknownSymbol, ".."); + } + if (isdigit (lex->current)) + { + __lexReadnumber (lex, 1, tkv); + return TOKEN_NUMBER; + } + else + return '.'; + } + + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + { + __lexReadnumber (lex, 0, tkv); + return TOKEN_NUMBER; + } + + default: + { + if (!isalpha (lex->current) && lex->current != '_' + && lex->current < 0x80) + { + int16_t c = lex->current; + next (lex); + return c; + } + _inlineString *ts = __losu_objString_new ( + lex->vm, (const char *)__lexReadname (lex)); + + if (ts->marked > 255) + { + { // do idt + for (int32_t i = 0; + i < sizeof (__keyword) / sizeof (__keyword[0]); i++) + if (__keyword[i].key == ts->marked) + { + lex->_syntaxLexIdt.nowidt += __keyword[i].idt; + break; + } + } +#ifdef __config_losucore_feature_chKeyword + switch (ts->marked) + { + case TOKEN_THIS: + { + tkv->s = __losu_objString_new (lex->vm, "self"); + return TOKEN_NAME; + } + case TOKEN_VARARG: + { + tkv->s = __losu_objString_new (lex->vm, "arg"); + return TOKEN_NAME; + } + case TOKEN_FOR_MAX: + { + tkv->s = __losu_objString_new (lex->vm, "__MAX__"); + return TOKEN_NAME; + } + case TOKEN_FOR_STEP: + { + tkv->s = __losu_objString_new (lex->vm, "__STEP__"); + return TOKEN_NAME; + } + case TOKEN_FOR_THIS: + { + tkv->s = __losu_objString_new (lex->vm, "__THIS__"); + return TOKEN_NAME; + } + case TOKEN_CONST: + { + tkv->s = __losu_objString_new (lex->vm, "__init__"); + return TOKEN_NAME; + } + case TOKEN_IN: + { + tkv->s = __losu_objString_new (lex->vm, "in"); + return TOKEN_NAME; + } + } + +#endif + + return ts->marked; + } + tkv->s = ts; + return TOKEN_NAME; + } + } + } +} + +/* undef segment */ +#undef EOZ +#undef next +#undef save +#undef save_next +#undef incline + +#endif /* define_source_losusyntax_lexer */ + +#ifndef define_source_losusyntax_parser +#define define_source_losusyntax_parser + +/* declare sgement */ +#define NO_JUMP -1 +#define __losuSyntaxParBlock(lex) \ + { \ + __losuSyntaxParStatBlock (lex); \ + } + +/* code segment */ + +_inlineScode * +__losu_syntaxParser_parse (LosuVm *vm, _syntaxIO *io) +{ + _syntaxLex lex = { ._syntaxLexIdt = { + .nowidt = 0, + .read = 0, + .size = 4, + .tmp = 0, + } }; + _syntaxFunc func; + + lex.deepth = 0; + _l_bool islast = 0; + + __losuSyntaxLexSetin (vm, &lex, io, __losu_objString_new (vm, io->name)); + __losuSyntaxParNewfunc (&lex, &func); + __losuSyntaxParNext (&lex); + while (!islast && !__losuSyntaxParCheckBlock (lex.tk.token)) + islast = __losuSyntaxParStat ((_syntaxLex *)(&lex)); + __losuSyntaxParCheckCondtion (&lex, (lex.tk.token != TOKEN_ELSEIF), + __config_losucore_errmsg_msgInvalidElif); + __losuSyntaxParCheckCondtion (&lex, (lex.tk.token != TOKEN_ELSE), + __config_losucore_errmsg_msgInvalidElse); + __losuSyntaxParCheckCondtion (&lex, (lex.tk.token == TOKEN_EOZ), + __config_losucore_errmsg_msgMissingEOZ); + __losuSyntaxParDelfunc (&lex); + return func.fcode; +} + +static void +__losuSyntaxParError (_syntaxLex *lex, int16_t tk) +{ + char t[8]; + __losuSyntaxLexTtS (tk, t); + __losuSyntaxError (lex, __config_losucore_errmsg_msgParserError, t); +} + +static void +__losuSyntaxParNewfunc (_syntaxLex *lex, _syntaxFunc *func) +{ + _inlineScode *f = (_inlineScode *)__losu_objFunc_scodeNew (lex->vm); + func->prev = lex->fs; + func->lexer = lex; + func->vm = lex->vm; + func->stacklevel = 0; + func->naloc = 0; + func->nclosure = 0; + func->breakl = NULL; + func->fcode = f; + func->pc = 0; + func->lasttarget = 0; + func->lastline = 0; + func->jump = NO_JUMP; + + lex->fs = func; + + /* *f = (_inlineScode){ */ + f->src = lex->source; + f->code = NULL; + f->maxstacksize = 0; + f->narg = 0; + f->isVarg = 0; + f->marked = 0; + /* }; */ +} + +static void +__losuSyntaxParDelfunc (_syntaxLex *lex) +{ + LosuVm *vm = lex->vm; + _syntaxFunc *func = lex->fs; + _inlineScode *f = func->fcode; + __losuSyntaxCgenCodearg0 (func, INS_END); + __losuSyntaxCgenGetL (func); + __losuSyntaxParRemovelcvar (lex, func->naloc); + __losu_mem_reallocvector (vm, f->localvar, f->nlocalvar, _inlineLocalvar); + __losu_mem_reallocvector (vm, f->code, func->pc, vmInstruction); + __losu_mem_reallocvector (vm, f->lcstr, f->nlcstr, _inlineString *); + __losu_mem_reallocvector (vm, f->lcnum, f->nlcnum, _l_number); + __losu_mem_reallocvector (vm, f->lcscode, f->nlcscode, _inlineScode *); + __losu_mem_reallocvector (vm, f->lineinfo, f->nlineinfo + 1, int32_t); + f->lineinfo[f->nlineinfo++] = INT32_MAX; + +#define codesize(f) \ + (sizeof (_inlineScode) + f->nlcnum * sizeof (_l_number) \ + + f->nlcstr * sizeof (_inlineString *) \ + + f->nlcscode * sizeof (_inlineScode *) \ + + f->ncode * sizeof (vmInstruction) \ + + f->nlocalvar * sizeof (_inlineLocalvar) \ + + f->nlineinfo * sizeof (int32_t)) + f->ncode = func->pc; + vm->nblocks += codesize (f); +#undef codesize + + lex->fs = func->prev; +} + +static void +__losuSyntaxParCheck (_syntaxLex *lex, int16_t tk) +{ + if (lex->tk.token != tk) + __losuSyntaxParError (lex, tk); + __losuSyntaxParNext (lex); +} + +static _l_bool +__losuSyntaxParCheckBlock (int16_t tk) +{ + switch (tk) + { + case TOKEN_ELSE: + case TOKEN_ELSEIF: + case TOKEN_END: + /* case TOKEN_ENDB: */ + case TOKEN_TO: + case TOKEN_EOZ: + return 1; + default: + return 0; + } +} + +static void +__losuSyntaxParCheckCondtion (_syntaxLex *lex, _l_bool c, const char *s) +{ + if (!c) + __losuSyntaxError (lex, s); +} + +static void +__losuSyntaxParCheckMatch (_syntaxLex *lex, int16_t l, int16_t r, int32_t line) +{ + if (lex->tk.token != r) + { + char tl[8], tr[8]; + __losuSyntaxLexTtS (l, tl); + __losuSyntaxLexTtS (r, tr); + __losuSyntaxError (lex, __config_losucore_errmsg_msgCheckMatch, tl, line, + tr); + } + __losuSyntaxParNext (lex); +} + +static _inlineString * +__losuSyntaxParCheckName (_syntaxLex *lex) +{ + _inlineString *ts; + __losuSyntaxParCheckCondtion (lex, lex->tk.token == TOKEN_NAME, + __config_losucore_errmsg_msgCheckName); + ts = lex->tk.info.s; + __losuSyntaxParNext (lex); + return ts; +} + +static void +__losuSyntaxParCheckLimit (_syntaxLex *lex, int32_t v, int32_t l, + const char *errmsg) +{ + if (v <= l) + return; + /* sprintf ((char *)lex->vm->staticbuff, + __config_losucore_errmsg_msgCheckLimit, errmsg, l); + __losuSyntaxError (lex, (const char *)lex->vm->staticbuff); */ + __losuSyntaxError (lex, __config_losucore_errmsg_msgCheckLimit, errmsg, l); +} + +static void +__losuSyntaxParNewlcvar (_syntaxLex *lex, _inlineString *name, int16_t i) +{ + _syntaxFunc *func = lex->fs; + _inlineScode *f = func->fcode; + + /* check limit? */ + __losuSyntaxParCheckLimit (lex, func->naloc + i + 1, vmOl_MaxLocalvar, + __config_losucore_errmsg_msgCheckLimitTMlocvar); + + __losu_mem_growvector (lex->vm, f->localvar, f->nlocalvar, 1, + _inlineLocalvar, vmIns_MaxA, + __config_losucore_errmsg_msgVectorOverflow); + f->localvar[f->nlocalvar].name = name; + func->aloc[func->naloc + i] = f->nlocalvar++; +} + +static void +__losuSyntaxParRemovelcvar (_syntaxLex *lex, int16_t i) +{ + _syntaxFunc *func = lex->fs; + while (i--) + func->fcode->localvar[func->aloc[--(func->naloc)]].endpc = func->pc; +} + +static void +__losuSyntaxParNext (_syntaxLex *lex) +{ + + lex->lastline = lex->linenumber; + if (lex->tkahead.token != TOKEN_EOZ) + { + lex->tk = lex->tkahead; + lex->tkahead.token = TOKEN_EOZ; + } + else + lex->tk.token + = __losuSyntaxLexNext (lex, (_syntaxTkvalue *)(&(lex->tk.info))); + /* printf ("tk:%d\n", lex->tk.token); + if (lex->tk.token < 128) + printf ("\tvalue:%c\n", lex->tk.token); */ +} + +static _l_bool +__losuSyntaxParStat (_syntaxLex *lex) +{ + int32_t line = lex->linenumber; + /* printf ("TK:%d\n", lex->tk.token); */ + switch (lex->tk.token) + { + case TOKEN_IF: + { + lex->deepth++; + __losuSyntaxParStatIf (lex, line); + lex->deepth--; + return 0; + } + case TOKEN_WITH: + { + lex->deepth++; + __losuSyntaxParStatWith (lex, line); + lex->deepth--; + return 0; + } + case TOKEN_BLOCK: + { + lex->deepth++; + __losuSyntaxParNext (lex); + __losuSyntaxParCheckMatch (lex, TOKEN_BLOCK, ':', line); + __losuSyntaxParStatBlock (lex); + __losuSyntaxParCheckMatch (lex, TOKEN_BLOCK, TOKEN_END, line); + lex->deepth--; + return 0; + } + case TOKEN_FOR: + { + lex->deepth++; + __losuSyntaxParStatFor (lex, line); + lex->deepth--; + return 0; + } + case TOKEN_LOOP: + { + lex->deepth++; + __losuSyntaxParStatLoop (lex, line); + lex->deepth--; + return 0; + } + case TOKEN_UNTIL: + { + lex->deepth++; + __losuSyntaxParStatUntil (lex, line); + lex->deepth--; + return 0; + } + case TOKEN_FUNCTION: + { + lex->deepth++; + __losuSyntaxParStatFunc (lex, line); + lex->deepth--; + return 0; + } + case TOKEN_VAR: + { + __losuSyntaxParStatVar (lex); + return 0; + } + case TOKEN_NAME: + { + __losuSyntaxParStatName (lex); + return 0; + } + case TOKEN_RETURN: + { + __losuSyntaxParStatReturn (lex); + return 1; + } + case TOKEN_BREAK: + { + __losuSyntaxParStatBreak (lex); + return 1; + } + default: + { + __losuSyntaxError (lex, __config_losucore_errmsg_msgInvalidExp); + return 0; + } + } +} +static void +__losuSyntaxParStatIf (_syntaxLex *lex, int32_t line) +{ + +#define condition(lex, v) \ + { \ + __losuSyntaxParSubExp ((lex), (v), -1); \ + __losuSyntaxCgenGoT ((lex)->fs, (v), 0); \ + } + +#define then(lex, v) \ + { \ + __losuSyntaxParNext ((lex)); \ + condition ((lex), (v)); \ + __losuSyntaxParCheck ((lex), ':'); \ + __losuSyntaxParBlock ((lex)); \ + } + + _syntaxFunc *func = lex->fs; + _syntaxExp v; + int32_t el = NO_JUMP; + then (lex, &v); + while (lex->tk.token == TOKEN_END) + { + __losuSyntaxParNext (lex); + if (lex->tk.token == TOKEN_ELSEIF) + { + __losuSyntaxCgenConcat (func, &el, __losuSyntaxCgenJump (func)); + __losuSyntaxCgenPalist (func, v.value._bool.f, + __losuSyntaxCgenGetL (func)); + then (lex, &v); + } + else if (lex->tk.token == TOKEN_ELSE) + { + lex->tkahead.token = __losuSyntaxLexNext ( + lex, (_syntaxTkvalue *)(&(lex->tkahead.info))); + if (lex->tkahead.token == ':') + __losuSyntaxParNext (lex); + + __losuSyntaxCgenConcat (func, &el, __losuSyntaxCgenJump (func)); + __losuSyntaxCgenPalist (func, v.value._bool.f, + __losuSyntaxCgenGetL (func)); + __losuSyntaxParNext (lex); + __losuSyntaxParBlock (lex); + __losuSyntaxCgenPalist (func, el, __losuSyntaxCgenGetL (func)); + __losuSyntaxParCheckMatch (lex, TOKEN_IF, TOKEN_END, line); + break; + } + else + { + __losuSyntaxCgenConcat (func, &el, v.value._bool.f); + __losuSyntaxCgenPalist (func, el, __losuSyntaxCgenGetL (func)); + break; + } + } + + /* while (lex->tk.token == TOKEN_ELSEIF) + { + __losuSyntaxCgenConcat (func, &el, __losuSyntaxCgenJump (func)); + __losuSyntaxCgenPalist (func, v.value._bool.f, + __losuSyntaxCgenGetL (func)); + then (lex, &v); + } + if (lex->tk.token == TOKEN_ELSE) + { + lex->tkahead.token = __losuSyntaxLexNext ( + lex, (_syntaxTkvalue *)(&(lex->tkahead.info))); + if (lex->tkahead.token == ':') + __losuSyntaxParNext (lex); + + __losuSyntaxCgenConcat (func, &el, __losuSyntaxCgenJump (func)); + __losuSyntaxCgenPalist (func, v.value._bool.f, + __losuSyntaxCgenGetL (func)); + __losuSyntaxParNext (lex); + __losuSyntaxParBlock (lex); + } + else + __losuSyntaxCgenConcat (func, &el, v.value._bool.f); + + + __losuSyntaxCgenPalist (func, el, __losuSyntaxCgenGetL (func)); + __losuSyntaxParCheckMatch (lex, TOKEN_IF, TOKEN_END, line);*/ + +/* undef segment */ +#undef condition +#undef then +} +static void +__losuSyntaxParStatWith (_syntaxLex *lex, int32_t line) +{ +#define condition(lex, v) \ + { \ + __losuSyntaxParSubExp ((lex), (v), -1); \ + __losuSyntaxCgenGoT ((lex)->fs, (v), 0); \ + } + + _syntaxFunc *func = lex->fs; + _syntaxExp v; + int32_t with = __losuSyntaxCgenGetL (func); + _syntaxBreak br; + __losuSyntaxParEnterbreak (func, &br); + __losuSyntaxParNext (lex); + condition (lex, &v); + __losuSyntaxParCheck (lex, ':'); + __losuSyntaxParBlock (lex); + __losuSyntaxCgenPalist (func, __losuSyntaxCgenJump (func), with); + __losuSyntaxCgenPalist (func, v.value._bool.f, __losuSyntaxCgenGetL (func)); + __losuSyntaxParCheckMatch (lex, TOKEN_WITH, TOKEN_END, line); + __losuSyntaxParLeavebreak (func, &br); + +#undef condition +} +static void +__losuSyntaxParStatBlock (_syntaxLex *lex) +{ + _syntaxFunc *func = lex->fs; + int naloc = func->naloc; + _l_bool is = 0; + while (!is && !__losuSyntaxParCheckBlock (lex->tk.token)) + is = __losuSyntaxParStat (lex); + __losuSyntaxCgenAdStack (func, func->naloc - naloc); + __losuSyntaxParRemovelcvar (lex, func->naloc - naloc); +} +static void +__losuSyntaxParStatFor (_syntaxLex *lex, int32_t line) +{ + _syntaxFunc *func = lex->fs; + _inlineString *name; + _syntaxBreak br; + __losuSyntaxParEnterbreak (func, &br); + __losuSyntaxParNext (lex); + name = __losuSyntaxParCheckName (lex); + switch (lex->tk.token) + { + case '=': + case TOKEN_TO: + { + __losuSyntaxParStatForNum (lex, name); + break; + } + case ',': + { + __losuSyntaxParStatForObj (lex, name); + break; + } + default: + __losuSyntaxError (lex, __config_losucore_errmsg_msgInvalidForExp); + } + __losuSyntaxParCheckMatch (lex, TOKEN_FOR, TOKEN_END, line); + __losuSyntaxParLeavebreak (func, &br); +} +static void +__losuSyntaxParStatLoop (_syntaxLex *lex, int32_t line) +{ +#define condition(lex, v) \ + { \ + __losuSyntaxParSubExp ((lex), (v), -1); \ + __losuSyntaxCgenGoT ((lex)->fs, (v), 0); \ + } + + _syntaxFunc *func = lex->fs; + int32_t loop = __losuSyntaxCgenGetL (func); + _syntaxExp v; + _syntaxBreak br; + __losuSyntaxParEnterbreak (func, &br); + __losuSyntaxParNext (lex); + __losuSyntaxParBlock (lex); + __losuSyntaxParCheckMatch (lex, TOKEN_LOOP, TOKEN_TO, line); + condition (lex, &v); + __losuSyntaxCgenPalist (func, v.value._bool.f, loop); + __losuSyntaxParLeavebreak (func, &br); + +#undef condition +} +static void +__losuSyntaxParStatUntil (_syntaxLex *lex, int32_t line) +{ +#define condition(lex, v) \ + { \ + __losuSyntaxParSubExp ((lex), (v), -1); \ + __losuSyntaxCgenGoF ((lex)->fs, (v), 0); \ + } + + _syntaxFunc *func = lex->fs; + _syntaxExp v; + int32_t unt = __losuSyntaxCgenGetL (func); + _syntaxBreak br; + __losuSyntaxParEnterbreak (func, &br); + __losuSyntaxParNext (lex); + condition (lex, &v); + __losuSyntaxParCheck (lex, ':'); + __losuSyntaxParBlock (lex); + __losuSyntaxCgenPalist (func, __losuSyntaxCgenJump (func), unt); + __losuSyntaxCgenPalist (func, v.value._bool.t, __losuSyntaxCgenGetL (func)); + __losuSyntaxParCheckMatch (lex, TOKEN_UNTIL, TOKEN_END, line); + __losuSyntaxParLeavebreak (func, &br); + +#undef condition +} +static void +__losuSyntaxParStatFunc (_syntaxLex *lex, int32_t line) +{ + _syntaxExp v; + __losuSyntaxParNext (lex); + __losuSyntaxParStatFuncBody (lex, __losuSyntaxParStatFuncName (lex, &v), + line); + __losuSyntaxCgenSetVar (lex, &v); +} +static void +__losuSyntaxParStatVar (_syntaxLex *lex) +{ +#define isSet(lex, c) \ + ((lex->tk.token == c) ? (__losuSyntaxParNext (lex), 1) : 0) + + if (lex->deepth == 0) /* global */ + { + __losuSyntaxParNext (lex); + __losuSyntaxParStatName (lex); + return; + } + int32_t nv = 0, ne = 0; + do + { + __losuSyntaxParNext (lex); + __losuSyntaxParNewlcvar (lex, __losuSyntaxParCheckName (lex), nv++); + } + while (lex->tk.token == ','); + if (isSet (lex, '=')) + ne = __losuSyntaxParExplist (lex); + else + ne = 0; + __losuSyntaxParAdStack (lex, nv, ne); + __losuSyntaxParAdLcvar (lex, nv); + +#undef isSet +} +static void +__losuSyntaxParStatName (_syntaxLex *lex) +{ + _syntaxFunc *func = lex->fs; + _syntaxExp v; + __losuSyntaxParVarFunc (lex, &v); + if (v.type == VE) + { + __losuSyntaxParCheckCondtion (lex, __losuSyntaxCgenIsopen (func), + __config_losucore_errmsg_msgInvalidExp); + __losuSyntaxCgenSetNcallr (func, 0); + } + else + __losuSyntaxCgenAdStack (func, + __losuSyntaxParStatNameAssment (lex, &v, 1)); +} +static void +__losuSyntaxParStatReturn (_syntaxLex *lex) +{ + _syntaxFunc *func = lex->fs; + __losuSyntaxParNext (lex); + if (!__losuSyntaxParCheckBlock (lex->tk.token)) + __losuSyntaxParExplist (lex); + __losuSyntaxCgenCodearg1 (func, INS_RETURN, lex->fs->naloc); + func->stacklevel = func->naloc; +} +static void +__losuSyntaxParStatBreak (_syntaxLex *lex) +{ + _syntaxFunc *func = lex->fs; + _syntaxBreak *br = func->breakl; + int32_t c = func->stacklevel; + __losuSyntaxParNext (lex); + if (br) /* break lable is exsist */ + { + __losuSyntaxCgenAdStack (func, c - br->stacklevel); + __losuSyntaxCgenConcat (func, &br->breaklist, + __losuSyntaxCgenJump (func)); + __losuSyntaxCgenAdStack (func, br->stacklevel - c); + } +} + +static void +__losuSyntaxParEnterbreak (_syntaxFunc *func, _syntaxBreak *br) +{ + br->stacklevel = func->stacklevel; + br->breaklist = NO_JUMP; + br->pre = func->breakl; + func->breakl = br; +} +static void +__losuSyntaxParLeavebreak (_syntaxFunc *func, _syntaxBreak *br) +{ + func->breakl = br->pre; + __losuSyntaxCgenPalist (func, br->breaklist, __losuSyntaxCgenGetL (func)); +} + +static void +__losuSyntaxParStatForNum (_syntaxLex *lex, _inlineString *vname) +{ + /* __losuSyntaxParCheck (lex, TOKEN_TO); */ + __losuSyntaxParNext (lex); + __losuSyntaxParExp (lex); + __losuSyntaxParCheck (lex, ','); + __losuSyntaxParExp (lex); + if (lex->tk.token == ',') /* step */ + { + __losuSyntaxParNext (lex); + __losuSyntaxParExp (lex); + } + else + __losuSyntaxCgenNumber (lex->fs, 1); + + __losuSyntaxParNewlcvar (lex, vname, 0); + __losuSyntaxParNewlcvar (lex, __losu_objString_newconst (lex->vm, "__MAX__"), + 1); + __losuSyntaxParNewlcvar (lex, + __losu_objString_newconst (lex->vm, "__STEP__"), 2); + + __losuSyntaxParStatForBody (lex, 0); +} +static void +__losuSyntaxParStatForObj (_syntaxLex *lex, _inlineString *idx) +{ + _inlineString *val; + __losuSyntaxParNext (lex); + val = __losuSyntaxParCheckName (lex); + __losuSyntaxParCheckCondtion ( + lex, + (lex->tk.token == TOKEN_NAME && !strcmp (lex->tk.info.s->str, "in")), + __config_losucore_errmsg_msgInvalidForExp); + __losuSyntaxParNext (lex); + __losuSyntaxParExp (lex); + + __losuSyntaxParNewlcvar (lex, + __losu_objString_newconst (lex->vm, "__THIS__"), 0); + __losuSyntaxParNewlcvar (lex, idx, 1); + __losuSyntaxParNewlcvar (lex, val, 2); + __losuSyntaxParStatForBody (lex, 1); +} +static void +__losuSyntaxParStatForBody (_syntaxLex *lex, _l_bool isO) +{ + struct + { + vmIns_OP pre; + vmIns_OP loop; + } const _inline_ins[] = { + { INS_FORPREP, INS_FORLOOP }, + { INS_LFORPREP, INS_LFORLOOP }, + }; + + _syntaxFunc *func = lex->fs; + int32_t prep + = __losuSyntaxCgenCodearg1 (func, _inline_ins[isO].pre, NO_JUMP); + int32_t block = __losuSyntaxCgenGetL (func); + __losuSyntaxParCheck (lex, ':'); + __losuSyntaxParAdLcvar (lex, 3); + __losuSyntaxParBlock (lex); + __losuSyntaxCgenPalist ( + func, __losuSyntaxCgenCodearg1 (func, _inline_ins[isO].loop, NO_JUMP), + block); + __losuSyntaxCgenPalist (func, prep, __losuSyntaxCgenGetL (func)); + __losuSyntaxParRemovelcvar (lex, 3); +} + +static _l_bool +__losuSyntaxParStatFuncName (_syntaxLex *lex, _syntaxExp *v) +{ + _l_bool i = 0; + __losuSyntaxParSvar (lex, __losuSyntaxParCheckName (lex), v); + while (lex->tk.token == '.') + { + __losuSyntaxParNext (lex); + __losuSyntaxCgenTostack (lex, v, 1); + __losuSyntaxCgenCodearg1 ( + lex->fs, INS_PUSHSTRING, + __losuSyntaxParStrconst (lex->fs, __losuSyntaxParCheckName (lex))); + v->type = VI; + i = 1; + } + return i; +} +static void +__losuSyntaxParStatFuncBody (_syntaxLex *lex, _l_bool nself, int32_t line) +{ + + _syntaxFunc nfs; + + __losuSyntaxParNewfunc (lex, &nfs); + nfs.fcode->defedline = line; + __losuSyntaxParCheck (lex, '('); + if (nself) + { + __losuSyntaxParNewlcvar (lex, + __losu_objString_newconst (lex->vm, "self"), 0); + __losuSyntaxParAdLcvar (lex, 1); + } + __losuSyntaxParStatFuncParlist (lex); + __losuSyntaxParCheck (lex, ')'); + __losuSyntaxParCheck (lex, ':'); + + while (!__losuSyntaxParCheckBlock (lex->tk.token)) + if (__losuSyntaxParStat (lex)) + break; + __losuSyntaxParCheckMatch (lex, TOKEN_FUNCTION, TOKEN_END, line); + __losuSyntaxParDelfunc (lex); + + /* push func */ + _syntaxFunc *func = lex->fs; + _inlineScode *f = func->fcode; + for (int32_t i = 0; i < nfs.nclosure; i++) + __losuSyntaxCgenTostack (lex, &(nfs.closure[i]), 1); + __losu_mem_growvector (lex->vm, f->lcscode, f->nlcscode, 1, _inlineScode *, + vmIns_MaxA, + __config_losucore_errmsg_msgVectorOverflow); + f->lcscode[f->nlcscode++] = nfs.fcode; + __losuSyntaxCgenCodearg2 (func, INS_PUSHFUNCTION, f->nlcscode - 1, + nfs.nclosure); +} +static void +__losuSyntaxParStatFuncParlist (_syntaxLex *lex) +{ +#define option(lex) \ + ((lex->tk.token == ',') ? (__losuSyntaxParNext (lex), 1) : 0) + + _l_bool isV = 0; + int32_t np = 0; + _syntaxFunc *func = lex->fs; + if (lex->tk.token != ')') + { + do + { + switch (lex->tk.token) + { + case TOKEN_ARG: + { + __losuSyntaxParNext (lex); + isV = 1; + break; + } + case TOKEN_NAME: + { + __losuSyntaxParNewlcvar (lex, __losuSyntaxParCheckName (lex), + np++); + break; + } + default: + { + __losuSyntaxError (lex, __config_losucore_errmsg_msgCheckName); + } + } + } + while (option (lex)); + } + __losuSyntaxParAdLcvar (lex, np); + func->fcode->narg = func->naloc; + func->fcode->isVarg = isV; + if (isV) + { + __losuSyntaxParNewlcvar (lex, __losu_objString_newconst (lex->vm, "arg"), + 0); + __losuSyntaxParAdLcvar (lex, 1); + } + __losuSyntaxCgenDtStack (func, func->naloc); + +#undef option +} + +static int32_t +__losuSyntaxParStatNameAssment (_syntaxLex *lex, _syntaxExp *v, int32_t nvar) +{ + int32_t left = 0; + if (lex->tk.token == ',') + { + _syntaxExp nv; + __losuSyntaxParNext (lex); + __losuSyntaxParVarFunc (lex, &nv); + __losuSyntaxParCheckCondtion (lex, (nv.type != VE), + __config_losucore_errmsg_msgInvalidExp); + left = __losuSyntaxParStatNameAssment (lex, &nv, nvar + 1); + } + else + { + int32_t nexp = 0; + if (lex->tk.token == '=') + { + __losuSyntaxParNext (lex); + nexp = __losuSyntaxParExplist (lex); + } + __losuSyntaxParAdStack (lex, nvar, nexp); + } + if (v->type != VI) + __losuSyntaxCgenSetVar (lex, v); + else + { + __losuSyntaxCgenCodearg2 (lex->fs, INS_SETUNIT, left + nvar + 2, 1); + left += 2; + } + return left; +} + +static int32_t +__losuSyntaxParExplist (_syntaxLex *lex) +{ + int32_t n = 1; + _syntaxExp v; + __losuSyntaxParSubExp (lex, &v, -1); + while (lex->tk.token == ',') + { + __losuSyntaxCgenTostack (lex, &v, 1); + __losuSyntaxParNext (lex); + __losuSyntaxParSubExp (lex, &v, -1); + n++; + } + __losuSyntaxCgenTostack (lex, &v, 0); + return n; +} +static void +__losuSyntaxParAdStack (_syntaxLex *lex, int32_t nv, int32_t ne) +{ + _syntaxFunc *func = lex->fs; + int32_t d = ne - nv; + if (ne > 0 && __losuSyntaxCgenIsopen (func)) + { + d--; + if (d <= 0) + { + __losuSyntaxCgenSetNcallr (func, -d); + d = 0; + } + else + __losuSyntaxCgenSetNcallr (func, 0); + } + __losuSyntaxCgenAdStack (func, d); +} +static void +__losuSyntaxParAdLcvar (_syntaxLex *lex, int32_t nv) +{ + while (nv--) + lex->fs->fcode->localvar[lex->fs->aloc[lex->fs->naloc++]].startpc + = lex->fs->pc; +} +static void +__losuSyntaxParVarFunc (_syntaxLex *lex, _syntaxExp *v) +{ +#define lookahead(lex) \ + { \ + (lex)->tkahead.token = __losuSyntaxLexNext ( \ + lex, (_syntaxTkvalue *)(&((lex)->tkahead.info))); \ + } + + __losuSyntaxParSvar (lex, __losuSyntaxParCheckName (lex), v); + while (1) + { + switch (lex->tk.token) + { + case '.': + { + __losuSyntaxParNext (lex); + lookahead (lex); + switch (lex->tkahead.token) + { + case '(': + case '{': + case TOKEN_STRING: + { + int32_t name = __losuSyntaxParStrconst ( + lex->fs, __losuSyntaxParCheckName (lex)); + __losuSyntaxCgenTostack (lex, v, 1); + __losuSyntaxCgenCodearg1 (lex->fs, INS_PUSHSELF, name); + __losuSyntaxParExpFargs (lex, 1); + v->type = VE; + v->value._bool.t = v->value._bool.f = NO_JUMP; + break; + } + default: + { + __losuSyntaxCgenTostack (lex, v, 1); + __losuSyntaxCgenCodearg1 ( + lex->fs, INS_PUSHSTRING, + __losuSyntaxParStrconst ( + lex->fs, __losuSyntaxParCheckName (lex))); + v->type = VI; + break; + } + } + break; + } + case '[': + { + __losuSyntaxParNext (lex); + __losuSyntaxCgenTostack (lex, v, 1); + v->type = VI; + __losuSyntaxParExp (lex); + __losuSyntaxParCheck (lex, ']'); + break; + } + case '(': + case TOKEN_STRING: + case '{': + { + __losuSyntaxCgenTostack (lex, v, 1); + __losuSyntaxParExpFargs (lex, 0); + v->type = VE; + v->value._bool.f = v->value._bool.t = NO_JUMP; + break; + } + default: + return; + } + } + +#undef lookahead +} + +static void +__losuSyntaxParExp (_syntaxLex *lex) +{ + _syntaxExp v; + __losuSyntaxParSubExp (lex, &v, -1); + __losuSyntaxCgenTostack (lex, &v, 1); +} +static int32_t +__losuSyntaxParExpVarlevel (_syntaxLex *lex, _inlineString *n, _syntaxExp *v) +{ + _syntaxFunc *func; + int32_t lev = 0; + for (func = lex->fs; func; func = func->prev) + { + for (int32_t i = func->naloc - 1; i >= 0; i--) + { + if (n == func->fcode->localvar[func->aloc[i]].name) + { + v->type = VL; + v->value.index = i; + return lev; + } + } + lev++; + } + v->type = VG; + return -1; +} + +static void +__losuSyntaxParSvar (_syntaxLex *lex, _inlineString *n, _syntaxExp *var) +{ + int32_t l = __losuSyntaxParExpVarlevel (lex, n, var); + if (l >= 1) + { + { /* push closure */ + _syntaxFunc *func = lex->fs; + _syntaxExp v; + int32_t l = __losuSyntaxParExpVarlevel (lex, n, &v); + if (l == -1) + v.value.index = __losuSyntaxParStrconst (func->prev, n); + else if (l != 1) + __losuSyntaxError (lex, __config_losucore_errmsg_msgInvalidClosure, + n->str); + + /* index closure */ + int16_t c = -1; + for (int16_t i = 0; i < func->nclosure; i++) + if (func->closure[i].type == v.type + && func->closure[i].value.index == v.value.index) + { + c = i; + break; + } + if (c < 0) + { + func->closure[func->nclosure] = v; + c = func->nclosure++; + } + __losuSyntaxCgenCodearg1 (func, INS_PUSHUPVALUE, c); + } + var->type = VE; + var->value._bool.t = var->value._bool.f = NO_JUMP; + } + else if (l == -1) + var->value.index = __losuSyntaxParStrconst (lex->fs, n); +} +static int32_t +__losuSyntaxParStrconst (_syntaxFunc *func, _inlineString *s) +{ + _inlineScode *f = func->fcode; + int32_t c = s->cstidx; + if (c >= f->nlcstr || f->lcstr[c] != s) + { + __losu_mem_growvector (func->vm, f->lcstr, f->nlcstr, 1, _inlineString *, + vmIns_MaxU, + __config_losucore_errmsg_msgVectorOverflow); + c = f->nlcstr++; + s->cstidx = c; + f->lcstr[c] = s; + } + return c; +} + +static int32_t +__losuSyntaxParSubExp (_syntaxLex *lex, _syntaxExp *v, int l) +{ +#define getunop(v, op) \ + { \ + switch (op) \ + { \ + case TOKEN_NOT: \ + v = INS_UNOP_NOT; \ + break; \ + case '-': \ + v = INS_UNOP_NEG; \ + break; \ + default: \ + v = INS_UNOP_NULL; \ + break; \ + } \ + } + +#define getbinop(v, op) \ + { \ + switch (op) \ + { \ + case '+': \ + v = INS_BINOP_ADD; \ + break; \ + case '-': \ + v = INS_BINOP_SUB; \ + break; \ + case '*': \ + v = INS_BINOP_MULT; \ + break; \ + case '/': \ + v = INS_BINOP_DIV; \ + break; \ + case '^': \ + v = INS_BINOP_POW; \ + break; \ + case TOKEN_CONCAT: \ + v = INS_BINOP_CONCAT; \ + break; \ + case TOKEN_EQ: \ + v = INS_BINOP_EQ; \ + break; \ + case TOKEN_NE: \ + v = INS_BINOP_NE; \ + break; \ + case '<': \ + v = INS_BINOP_LT; \ + break; \ + case TOKEN_LE: \ + v = INS_BINOP_LE; \ + break; \ + case '>': \ + v = INS_BINOP_GT; \ + break; \ + case TOKEN_GE: \ + v = INS_BINOP_GE; \ + break; \ + case TOKEN_AND: \ + v = INS_BINOP_AND; \ + break; \ + case TOKEN_OR: \ + v = INS_BINOP_OR; \ + break; \ + default: \ + v = INS_BINOP_NULL; \ + break; \ + } \ + } + + struct + { + char left; + char right; + } const priority[] = { + { 5, 5 }, /* + */ + { 5, 5 }, /* - */ + { 6, 6 }, /* * */ + { 6, 6 }, /* / */ + { 9, 8 }, /* ^ */ + { 4, 3 }, /* & */ + + { 2, 2 }, /* != */ + { 2, 2 }, /* == */ + + { 2, 2 }, /* < */ + { 2, 2 }, /* <= */ + { 2, 2 }, /* > */ + { 2, 2 }, /* >= */ + + { 1, 1 }, /* and */ + { 1, 1 }, /* or */ + }; + + int op, uop; + getunop (uop, lex->tk.token); + if (uop != INS_UNOP_NULL) + { + __losuSyntaxParNext (lex); + __losuSyntaxParSubExp (lex, v, 7); + __losuSyntaxCgenPrefix (lex, uop, v); + } + else + __losuSyntaxParSimpleExp (lex, v); + + getbinop (op, lex->tk.token); + /* printf ("\top:%d\n", op); */ + while (op != INS_BINOP_NULL && priority[op].left > l) + { + _syntaxExp v2; + int l2; + __losuSyntaxParNext (lex); + __losuSyntaxCgenInfix (lex, op, v); + l2 = __losuSyntaxParSubExp (lex, &v2, priority[op].right); + __losuSyntaxCgenPosfix (lex, op, v, &v2); + op = l2; + } + return op; + +#undef getunop +#undef getbinop +} +static void +__losuSyntaxParExpFargs (_syntaxLex *lex, _l_bool slf) +{ + _syntaxFunc *func = lex->fs; + int sl = func->stacklevel - slf - 1; + int line = lex->linenumber; + switch (lex->tk.token) + { + case '(': + { + __losuSyntaxParNext (lex); + if (lex->tk.token != ')') + __losuSyntaxParExplist (lex); + __losuSyntaxParCheckMatch (lex, '(', ')', line); + break; + } + case '{': + { + __losuSyntaxParUnitConstructor (lex); + break; + } + case TOKEN_STRING: + { + __losuSyntaxCgenCodearg1 ( + lex->fs, INS_PUSHSTRING, + __losuSyntaxParStrconst (lex->fs, lex->tk.info.s)); + __losuSyntaxParNext (lex); + break; + } + default: + { + __losuSyntaxError (lex, __config_losucore_errmsg_msgExpectedFarg); + break; + } + } + func->stacklevel = sl; + __losuSyntaxCgenCodearg2 (func, INS_CALL, sl, 255); +} + +static void +__losuSyntaxParSimpleExp (_syntaxLex *lex, _syntaxExp *v) +{ + _syntaxFunc *func = lex->fs; + switch (lex->tk.token) + { + case TOKEN_NUMBER: + { + _l_number n = lex->tk.info.num; + __losuSyntaxParNext (lex); + __losuSyntaxCgenNumber (func, n); + break; + } + case TOKEN_STRING: + { + __losuSyntaxCgenCodearg1 ( + lex->fs, INS_PUSHSTRING, + __losuSyntaxParStrconst (lex->fs, lex->tk.info.s)); + __losuSyntaxParNext (lex); + break; + } + case TOKEN_NULL: + { + __losuSyntaxCgenAdStack (func, -1); + __losuSyntaxParNext (lex); + break; + } + case TOKEN_FUNCTION: + { + lex->deepth++; + __losuSyntaxParNext (lex); + __losuSyntaxParStatFuncBody (lex, 0, lex->linenumber); + lex->deepth--; + break; + } + case TOKEN_NAME: + { + __losuSyntaxParVarFunc (lex, v); + return; + } + case '{': + { + __losuSyntaxParUnitConstructor (lex); + break; + } + case '(': + { + __losuSyntaxParNext (lex); + __losuSyntaxParSubExp (lex, v, -1); + __losuSyntaxParCheck (lex, ')'); + return; + } + default: + { + __losuSyntaxError (lex, __config_losucore_errmsg_msgInvalidExp); + return; + } + } + v->type = VE; + v->value._bool.t = v->value._bool.f = NO_JUMP; +} +static void +__losuSyntaxParUnitConstructor (_syntaxLex *lex) +{ + _syntaxFunc *func = lex->fs; + int32_t line = lex->linenumber; + int32_t pc = __losuSyntaxCgenCodearg1 (func, INS_CREATEUNIT, 0); + int32_t niss; + __losuSyntaxParCheck (lex, '{'); + switch (lex->tk.token) + { + case '}': + { + niss = 0; + break; + } + case TOKEN_NAME: + { + lex->tkahead.token = __losuSyntaxLexNext ( + lex, (_syntaxTkvalue *)(&(lex->tkahead.info))); + if (lex->tkahead.token == ',') + goto case_default; + niss = __losuSyntaxParUnitMapfield (lex); + break; + } + case '[': + { + niss = __losuSyntaxParUnitMapfield (lex); + break; + } + default: + { + case_default: + niss = __losuSyntaxParUnitListfield (lex); + break; + } + } + __losuSyntaxParCheckMatch (lex, '{', '}', line); + cgIns_SetU (func->fcode->code[pc], niss); +} + +static int32_t +__losuSyntaxParUnitMapfield (_syntaxLex *lex) +{ + _syntaxFunc *func = lex->fs; + int32_t n = 1; + switch (lex->tk.token) + { + case TOKEN_NAME: + { + __losuSyntaxCgenCodearg1 ( + lex->fs, INS_PUSHSTRING, + __losuSyntaxParStrconst (lex->fs, __losuSyntaxParCheckName (lex))); + break; + } + case '[': + { + __losuSyntaxParNext (lex); + __losuSyntaxParExp (lex); + __losuSyntaxParCheck (lex, ']'); + break; + } + default: + { + __losuSyntaxError (lex, __config_losucore_errmsg_msgCheckName); + } + } + + __losuSyntaxParCheck (lex, ':'); + /* __losuSyntaxParNext (lex); */ + + __losuSyntaxParExp (lex); + + while (lex->tk.token == ',') + { + __losuSyntaxParNext (lex); + if (lex->tk.token == '}') + break; + switch (lex->tk.token) + { + case TOKEN_NAME: + { + __losuSyntaxCgenCodearg1 ( + lex->fs, INS_PUSHSTRING, + __losuSyntaxParStrconst (lex->fs, + __losuSyntaxParCheckName (lex))); + break; + } + case '[': + { + __losuSyntaxParNext (lex); + __losuSyntaxParExp (lex); + __losuSyntaxParCheck (lex, ']'); + break; + } + default: + { + __losuSyntaxError (lex, __config_losucore_errmsg_msgCheckName); + } + } + __losuSyntaxParCheck (lex, ':'); + /* __losuSyntaxParNext (lex); */ + + __losuSyntaxParExp (lex); + n++; + if (n % vmOl_MaxSetmap == 0) + __losuSyntaxCgenCodearg1 (func, INS_SETMAP, vmOl_MaxSetmap); + } + __losuSyntaxCgenCodearg1 (func, INS_SETMAP, n % vmOl_MaxSetmap); + return n; +} +static int32_t +__losuSyntaxParUnitListfield (_syntaxLex *lex) +{ + _syntaxFunc *func = lex->fs; + int32_t n = 1; + __losuSyntaxParExp (lex); + while (lex->tk.token == ',') + { + __losuSyntaxParNext (lex); + if (lex->tk.token == '}') + break; + __losuSyntaxParExp (lex); + n++; + if (n % vmOl_MaxSetlist == 0) + __losuSyntaxCgenCodearg2 (func, INS_SETLIST, n / vmOl_MaxSetlist - 1, + vmOl_MaxSetlist); + } + __losuSyntaxCgenCodearg2 (func, INS_SETLIST, n / vmOl_MaxSetlist, + n % vmOl_MaxSetlist); + return n; +} + +#undef NO_JUMP +#undef __losuSyntaxParBlock +#endif /* define_source_losusyntax_parser */ + +#ifndef define_source_losusyntax_codegen +#define define_source_losusyntax_codegen +#define NO_JUMP -1 + +static const struct +{ + vmIns_OP op; + int arg; +} _alops[] = { { INS_ADD, 0 }, { INS_SUB, 0 }, + { INS_MULT, 0 }, { INS_DIV, 0 }, + { INS_POW, 0 }, { INS_CONCAT, 0 }, + { INS_JMPNE, NO_JUMP }, { INS_JMPEQ, NO_JUMP }, + { INS_JMPLT, NO_JUMP }, { INS_JMPLE, NO_JUMP }, + { INS_JMPGT, NO_JUMP }, { INS_JMPGE, NO_JUMP } }; + +#define iO INS_MODE_OP +#define iBA INS_MODE_IBA +#define iU INS_MODE_IU +#define iS INS_MODE_IS +#define V 0 /* V means variable */ +static const struct +{ + vmIns_Mode op; + int8_t push; + int8_t pop; +} _vmops[] = { + { iO, 0, 0 }, /* INS_END */ + { iU, 0, 0 }, /* INS_RETURN */ + + { iBA, 0, 0 }, /* INS_CALL */ + + { iU, V, 0 }, /* INS_PUSHNULL */ + { iU, V, 0 }, /* INS_POP */ + + { iU, 1, 0 }, /* INS_PUSHSTRING */ + { iU, 1, 0 }, /* INS_PUSHNUM */ + { iU, 1, 0 }, /* INS_PUSHUPVALUE */ + { iBA, V, 0 }, /* INS_PUSHFUNCTION */ + { iU, 2, 1 }, /* INS_PUSHSELF */ + + { iU, 1, 0 }, /* INS_GETLOCAL */ + { iU, 1, 0 }, /* INS_GETGLOBAL */ + { iU, 0, 1 }, /* INS_SETLOCAL */ + { iU, 0, 1 }, /* INS_SETGLOBAL */ + + { iU, 1, 0 }, /* INS_CREATEUNIT */ + { iBA, V, 0 }, /* INS_SETUNIT */ + { iO, 1, 2 }, /* INS_GETUNIT */ + { iBA, V, 0 }, /* INS_SETLIST */ + { iU, V, 0 }, /* INS_SETMAP */ + + { iO, 1, 2 }, /* INS_ADD */ + { iO, 1, 2 }, /* INS_SUB */ + { iO, 1, 2 }, /* INS_MULT */ + { iO, 1, 2 }, /* INS_DIV */ + { iO, 1, 2 }, /* INS_POW */ + { iO, 1, 2 }, /* INS_CONCAT */ + { iO, 1, 1 }, /* INS_MINUS */ + { iO, 1, 1 }, /* INS_NOT */ + + { iS, 0, 2 }, /* INS_JMPNE */ + { iS, 0, 2 }, /* INS_JMPEQ */ + { iS, 0, 2 }, /* INS_JMPLT */ + { iS, 0, 2 }, /* INS_JMPLE */ + { iS, 0, 2 }, /* INS_JMPGT */ + { iS, 0, 2 }, /* INS_JMPGE */ + + { iS, 0, 1 }, /* INS_JMPT */ + { iS, 0, 1 }, /* INS_JMPF */ + { iS, 0, 1 }, /* INS_JMPONT */ + { iS, 0, 1 }, /* INS_JMPONF */ + { iS, 0, 0 }, /* INS_JMP */ + { iO, 0, 0 }, /* INS_PUSHNULLJMP */ + + { iS, 0, 0 }, /* INS_FORPREP */ + { iS, 0, 3 }, /* INS_FORLOOP */ + { iS, 2, 0 }, /* INS_LFORPREP */ + { iS, 0, 3 }, /* INS_LFORLOOP */ + +}; + +#undef iO +#undef iBA +#undef iU +#undef iS +#undef V + +static int32_t +__losuSyntaxCgenCodearg (_syntaxFunc *func, vmIns_OP o, int32_t arg1, + int32_t arg2) +{ + _syntaxLex *lex = func->lexer; + _inlineScode *f = func->fcode; + vmInstruction i = func->pc > func->lasttarget + ? func->fcode->code[func->pc - 1] + : ((vmInstruction)INS_END); + int32_t dt = _vmops[o].push - _vmops[o].pop; + _l_bool optd = 0; + + switch (o) + { + case INS_PUSHFUNCTION: /* V */ + { + dt = -arg2 + 1; + break; + } + case INS_SETUNIT: + { + dt = -arg2; + break; + } + case INS_SETLIST: + { + if (arg2 == 0) + return NO_JUMP; + dt = -arg2; + break; + } + case INS_SETMAP: + { + if (arg1 == 0) + return NO_JUMP; + dt = -2 * arg1; + break; + } + case INS_PUSHNULL: + { + if (arg1 == 0) + return NO_JUMP; + dt = arg1; + switch (cgIns_GetOp (i)) + { + case INS_PUSHNULL: + cgIns_SetU (i, cgIns_GetU (i) + arg1); + optd = 1; + break; + default: + break; + } + break; + } + case INS_POP: /* V */ + { + if (arg1 == 0) + return NO_JUMP; + dt = -arg1; + switch (cgIns_GetOp (i)) + { + case INS_SETUNIT: + { + cgIns_SetB (i, cgIns_GetB (i) + arg1); + optd = 1; + break; + } + default: + break; + } + break; + } + case INS_JMPNE: + { + if (i == cgIns_NewU (INS_PUSHNULL, 1)) + { + i = cgIns_NewS (INS_JMPT, NO_JUMP); + optd = 1; + } + break; + } + case INS_JMPEQ: + { + if (i == cgIns_NewU (INS_PUSHNULL, 1)) + { + i = cgIns_NewOp (INS_NOT); + dt = -1; + optd = 1; + } + break; + } + case INS_JMPT: + case INS_JMPONT: + { + switch (cgIns_GetOp (i)) + { + case INS_NOT: + { + i = cgIns_NewS (INS_JMPF, NO_JUMP); + optd = 1; + break; + } + case INS_PUSHNULL: + { + if (cgIns_GetU (i) == 1) + { + func->pc--; + __losuSyntaxCgenDtStack (func, -1); + return NO_JUMP; + } + break; + } + default: + break; + } + break; + } + case INS_JMPF: + case INS_JMPONF: + { + switch (cgIns_GetOp (i)) + { + case INS_NOT: + { + i = cgIns_NewS (INS_JMPT, NO_JUMP); + optd = 1; + break; + } + case INS_PUSHNULL: + { + if (cgIns_GetU (i) == 1) + { + i = cgIns_NewS (INS_JMP, NO_JUMP); + optd = 1; + } + break; + } + default: + break; + } + break; + } + default: + break; + } + + __losuSyntaxCgenDtStack (func, dt); + if (optd) + { + func->fcode->code[func->pc - 1] = i; + return func->pc - 1; + } + switch (_vmops[o].op) + { + case INS_MODE_OP: + { + i = cgIns_NewOp (o); + break; + } + case INS_MODE_IU: + { + i = cgIns_NewU (o, arg1); + break; + } + case INS_MODE_IS: + { + i = cgIns_NewS (o, arg1); + break; + } + case INS_MODE_IBA: + { + i = cgIns_NewAB (o, arg1, arg2); + break; + } + default: + break; + } + + /* lineinfo */ + { + if (lex->lastline > func->lastline) + { + __losu_mem_growvector (func->vm, f->lineinfo, f->nlineinfo, 2, int32_t, + vmOl_MaxInt32_t, + __config_losucore_errmsg_msgVectorOverflow); + if (lex->lastline > func->lastline + 1) + f->lineinfo[f->nlineinfo++] + = -(lex->lastline - (func->lastline + 1)); + f->lineinfo[f->nlineinfo++] = func->pc; + func->lastline = lex->lastline; + } + } + + __losu_mem_growvector (func->vm, func->fcode->code, func->pc, 1, + vmInstruction, vmOl_MaxInt32_t, + __config_losucore_errmsg_msgVectorOverflow); + func->fcode->code[func->pc] = i; + return func->pc++; +} + +static void +__losuSyntaxCgenConcat (_syntaxFunc *func, int32_t *l1, int32_t l2) +{ + if (*l1 == NO_JUMP) + *l1 = l2; + else + { + int32_t l = *l1; + while (1) + { + int32_t n = __losuSyntaxCgenGetJump (func, l); + if (n == NO_JUMP) + { + __losuSyntaxCgenFixJump (func, l, l2); + return; + } + l = n; + } + } +} + +static int32_t +__losuSyntaxCgenJump (_syntaxFunc *func) +{ + int32_t j = __losuSyntaxCgenCodearg1 (func, INS_JMP, NO_JUMP); + if (j == func->lasttarget) + { + __losuSyntaxCgenConcat (func, &j, func->jump); + func->jump = NO_JUMP; + } + return j; +} +static void +__losuSyntaxCgenPalist (_syntaxFunc *func, int32_t list, int32_t tg) +{ + if (tg == func->lasttarget) + __losuSyntaxCgenConcat (func, &func->jump, list); + else + __losuSyntaxCgenPlistfunc (func, list, tg, INS_END, 0); +} +static int32_t +__losuSyntaxCgenGetL (_syntaxFunc *func) +{ + if (func->pc != func->lasttarget) + { + int32_t ltg = func->lasttarget; + func->lasttarget = func->pc; + __losuSyntaxCgenPalist (func, func->jump, ltg); + func->jump = NO_JUMP; + } + return func->pc; +} +static void +__losuSyntaxCgenGoT (_syntaxFunc *func, _syntaxExp *v, int32_t keep) +{ + __losuSyntaxCgenGo (func, v, 1, keep ? INS_JMPONF : INS_JMPF); +} +static void +__losuSyntaxCgenGoF (_syntaxFunc *func, _syntaxExp *v, int32_t keep) +{ + __losuSyntaxCgenGo (func, v, 0, keep ? INS_JMPONT : INS_JMPT); +} +static void +__losuSyntaxCgenTostack (_syntaxLex *lex, _syntaxExp *v, int32_t o) +{ +#define codelab(func, op, arg) \ + (__losuSyntaxCgenGetL (func), __losuSyntaxCgenCodearg1 (func, op, arg)) + + _syntaxFunc *func = lex->fs; + if (!__losuSyntaxCgenDischarge (func, v)) + { + vmIns_OP pre = cgIns_GetOp (func->fcode->code[func->pc - 1]); + if (!vmIns_Isjump (pre) && v->value._bool.f == NO_JUMP + && v->value._bool.t == NO_JUMP) + { + if (o) + __losuSyntaxCgenSetNcallr (func, 1); + } + else + { + int32_t final; + int32_t j = NO_JUMP; + int32_t pn = NO_JUMP; + int32_t pl = NO_JUMP; + if (vmIns_Isjump (pre) + || __losuSyntaxCgenNeedval (func, v->value._bool.f, INS_JMPONF) + || __losuSyntaxCgenNeedval (func, v->value._bool.t, INS_JMPONT)) + { + if (vmIns_Isjump (pre)) + __losuSyntaxCgenConcat (func, &v->value._bool.t, func->pc - 1); + else + { + j = codelab (func, INS_JMP, NO_JUMP); + __losuSyntaxCgenAdStack (func, 1); + } + pn = codelab (func, INS_PUSHNULLJMP, 0); + pl = codelab (func, INS_PUSHNUM, 1); + __losuSyntaxCgenPalist (func, j, __losuSyntaxCgenGetL (func)); + } + final = __losuSyntaxCgenGetL (func); + __losuSyntaxCgenPlistfunc (func, v->value._bool.f, pn, INS_JMPONF, + final); + __losuSyntaxCgenPlistfunc (func, v->value._bool.t, pl, INS_JMPONT, + final); + v->value._bool.f = v->value._bool.t = NO_JUMP; + } + } + +#undef codelab +} +static void +__losuSyntaxCgenAdStack (_syntaxFunc *func, int32_t n) +{ + if (n > 0) + __losuSyntaxCgenCodearg1 (func, INS_POP, n); + else + __losuSyntaxCgenCodearg1 (func, INS_PUSHNULL, -n); +} +static void +__losuSyntaxCgenSetVar (_syntaxLex *lex, _syntaxExp *var) +{ + _syntaxFunc *func = lex->fs; + switch (var->type) + { + case VL: + __losuSyntaxCgenCodearg1 (func, INS_SETLOCAL, var->value.index); + break; + case VG: + __losuSyntaxCgenCodearg1 (func, INS_SETGLOBAL, var->value.index); + break; + case VI: + __losuSyntaxCgenCodearg2 (func, INS_SETUNIT, 3, 3); + break; + default: + break; + } +} +static _l_bool +__losuSyntaxCgenIsopen (_syntaxFunc *func) +{ + vmInstruction i = func->pc > func->lasttarget + ? func->fcode->code[func->pc - 1] + : ((vmInstruction)INS_END); + if (cgIns_GetOp (i) == INS_CALL && cgIns_GetB (i) == 255) + return 1; + else + return 0; +} +static void +__losuSyntaxCgenSetNcallr (_syntaxFunc *func, int32_t nres) +{ + if (__losuSyntaxCgenIsopen (func)) + { + cgIns_SetB (func->fcode->code[func->pc - 1], nres); + __losuSyntaxCgenDtStack (func, nres); + } +} +static void +__losuSyntaxCgenNumber (_syntaxFunc *func, _l_number n) +{ + _inlineScode *fc = func->fcode; + int32_t c = fc->nlcnum; + /* + int lim = c < LOOKBACKNUMS ? 0 : c - LOOKBACKNUMS; + while (--c >= lim) + */ + int32_t lim = c < vmOl_MaxNumberRef ? 0 : c - vmOl_MaxNumberRef; + while (--c >= lim) + if (fc->lcnum[c] == n) + { + __losuSyntaxCgenCodearg1 (func, INS_PUSHNUM, c); + return; + } + + __losu_mem_growvector (func->vm, fc->lcnum, fc->nlcnum, 1, _l_number, + vmIns_MaxU, + __config_losucore_errmsg_msgVectorOverflow); + c = fc->nlcnum++; + fc->lcnum[c] = n; + __losuSyntaxCgenCodearg1 (func, INS_PUSHNUM, c); +} +static void +__losuSyntaxCgenDtStack (_syntaxFunc *func, int32_t dt) +{ + func->stacklevel += dt; + if (func->stacklevel > func->fcode->maxstacksize) + { + if (func->stacklevel > vmOl_MaxStack) + __losuSyntaxError (func->lexer, + __config_losucore_errmsg_msgTooComplexExp); + func->fcode->maxstacksize = func->stacklevel; + } +} +static void +__losuSyntaxCgenPrefix (_syntaxLex *lex, vmIns_UnOp op, _syntaxExp *v) +{ +#define swap(v) \ + { \ + int32_t tmp = v->value._bool.f; \ + v->value._bool.f = v->value._bool.t; \ + v->value._bool.t = tmp; \ + } + + _syntaxFunc *func = lex->fs; + if (op == INS_UNOP_NEG) + { + __losuSyntaxCgenTostack (lex, v, 1); + __losuSyntaxCgenCodearg0 (func, INS_NEG); + } + else + { + vmInstruction *pre; + __losuSyntaxCgenDischarge (func, v); + if (v->value._bool.t == NO_JUMP && v->value._bool.f == NO_JUMP) + __losuSyntaxCgenSetNcallr (func, 1); + + pre = &(func->fcode->code[func->pc - 1]); + if (vmIns_Isjump (cgIns_GetOp ((*pre)))) + cgIns_SetOp ((*pre), + __losuSyntaxCgenJumpInvert (cgIns_GetOp ((*pre)))); + else + __losuSyntaxCgenCodearg0 (func, INS_NOT); + + swap (v); + } + +#undef swap +} +static void +__losuSyntaxCgenInfix (_syntaxLex *lex, vmIns_BinOp op, _syntaxExp *v) +{ + _syntaxFunc *func = lex->fs; + switch (op) + { + case INS_BINOP_AND: + { + __losuSyntaxCgenGoT (func, v, 1); + break; + } + case INS_BINOP_OR: + { + __losuSyntaxCgenGoF (func, v, 1); + break; + } + default: + { + __losuSyntaxCgenTostack (lex, v, 1); + break; + } + } +} +static void +__losuSyntaxCgenPosfix (_syntaxLex *lex, vmIns_BinOp op, _syntaxExp *v1, + _syntaxExp *v2) +{ + _syntaxFunc *func = lex->fs; + switch (op) + { + case INS_BINOP_AND: + { + __losuSyntaxCgenDischarge (func, v2); + if (v2->value._bool.t == NO_JUMP && v2->value._bool.f == NO_JUMP) + __losuSyntaxCgenSetNcallr (func, 1); + v1->value._bool.t = v2->value._bool.t; + __losuSyntaxCgenConcat (func, &v1->value._bool.f, v2->value._bool.f); + break; + } + case INS_BINOP_OR: + { + __losuSyntaxCgenDischarge (func, v2); + if (v2->value._bool.t == NO_JUMP && v2->value._bool.f == NO_JUMP) + __losuSyntaxCgenSetNcallr (func, 1); + v1->value._bool.f = v2->value._bool.f; + __losuSyntaxCgenConcat (func, &v1->value._bool.t, v2->value._bool.t); + break; + } + default: + { + __losuSyntaxCgenTostack (lex, v2, 1); + __losuSyntaxCgenCodearg1 (func, _alops[op].op, _alops[op].arg); + break; + } + } +} + +static int32_t +__losuSyntaxCgenGetJump (_syntaxFunc *func, int32_t pc) +{ + int32_t o = cgIns_GetS (func->fcode->code[pc]); + if (o == NO_JUMP) + return NO_JUMP; + else + return (pc + 1) + o; +} +static void +__losuSyntaxCgenFixJump (_syntaxFunc *func, int32_t pc, int32_t dt) +{ + vmInstruction *jmp = &func->fcode->code[pc]; + if (dt == NO_JUMP) + cgIns_SetS ((*jmp), NO_JUMP); + else + { + int32_t o = dt - (pc + 1); + if (abs (o) > vmIns_MaxS) + __losuSyntaxError (func->lexer, + __config_losucore_errmsg_msgInvalidJump); + cgIns_SetS ((*jmp), o); + } +} +static void +__losuSyntaxCgenPlistfunc (_syntaxFunc *func, int32_t list, int32_t tg, + vmIns_OP ins, int32_t instg) +{ + vmInstruction *code = func->fcode->code; + while (list != NO_JUMP) + { + int32_t next = __losuSyntaxCgenGetJump (func, list); + vmInstruction *i = &code[list]; + vmIns_OP op = cgIns_GetOp ((*i)); + if (op == ins) + __losuSyntaxCgenFixJump (func, list, instg); + else + { + __losuSyntaxCgenFixJump (func, list, tg); + if (op == INS_JMPONT) + cgIns_SetOp ((*i), INS_JMPT); + else if (op == INS_JMPONF) + cgIns_SetOp ((*i), INS_JMPF); + } + list = next; + } +} +static void +__losuSyntaxCgenGo (_syntaxFunc *func, _syntaxExp *v, int32_t inv, + vmIns_OP jump) +{ + int32_t prepc; + vmInstruction *pre; + int32_t *golist, *exitlist; + if (!inv) + { + golist = &v->value._bool.f; + exitlist = &v->value._bool.t; + } + else + { + golist = &v->value._bool.t; + exitlist = &v->value._bool.f; + } + __losuSyntaxCgenDischarge (func, v); + if (v->value._bool.t == NO_JUMP && v->value._bool.f == NO_JUMP) + __losuSyntaxCgenSetNcallr (func, 1); + prepc = func->pc - 1; + pre = &func->fcode->code[prepc]; + if (!vmIns_Isjump (cgIns_GetOp (*pre))) + prepc = __losuSyntaxCgenCodearg1 (func, jump, NO_JUMP); + else if (inv) + cgIns_SetOp (*pre, __losuSyntaxCgenJumpInvert (cgIns_GetOp (*pre))); + __losuSyntaxCgenConcat (func, exitlist, prepc); + __losuSyntaxCgenPalist (func, *golist, __losuSyntaxCgenGetL (func)); + *golist = NO_JUMP; +} +static _l_bool +__losuSyntaxCgenDischarge (_syntaxFunc *func, _syntaxExp *v) +{ + switch (v->type) + { + case VL: + { + __losuSyntaxCgenCodearg1 (func, INS_GETLOCAL, v->value.index); + break; + } + case VG: + { + __losuSyntaxCgenCodearg1 (func, INS_GETGLOBAL, v->value.index); + break; + } + case VI: + { + __losuSyntaxCgenCodearg0 (func, INS_GETUNIT); + break; + } + case VE: + { + return 0; + } + default: + break; + } + v->type = VE; + v->value._bool.t = v->value._bool.f = NO_JUMP; + return 1; +} +static _l_bool +__losuSyntaxCgenNeedval (_syntaxFunc *func, int32_t l, vmIns_OP op) +{ + for (; l != NO_JUMP; l = __losuSyntaxCgenGetJump (func, l)) + if (cgIns_GetOp (func->fcode->code[l]) != op) + return 1; + return 0; +} +static vmIns_OP +__losuSyntaxCgenJumpInvert (vmIns_OP op) +{ + switch (op) + { + case INS_JMPNE: + return INS_JMPEQ; + case INS_JMPEQ: + return INS_JMPNE; + + case INS_JMPLT: + return INS_JMPGE; + case INS_JMPLE: + return INS_JMPGT; + + case INS_JMPGT: + return INS_JMPLE; + case INS_JMPGE: + return INS_JMPLT; + + case INS_JMPT: + case INS_JMPONT: + return INS_JMPF; + + case INS_JMPF: + case INS_JMPONF: + return INS_JMPT; + + default: + return INS_END; + } +} + +#undef NO_JUMP + +#endif /* define_source_losusyntax_codegen */ + +#ifndef define_source_losusyntax_irload +#define define_source_losusyntax_irload + +#define EOZ (-1) + +static _l_bool __losuSyntaxIrLoadHead (LosuVm *vm, _syntaxIO *io); +static _inlineScode *__losuSyntaxIrLoadFunc (LosuVm *vm, _syntaxIO *io, + _l_bool diff); +static _inlineString *__losuSyntaxIrLoadString (LosuVm *vm, _syntaxIO *io, + _l_bool diff); +/* static _l_number __losuSyntaxIrLoadNumber (LosuVm *vm, _syntaxIO *io, + _l_bool diff); */ +static int32_t __losuSyntaxIrLoadInt32 (LosuVm *vm, _syntaxIO *io, + _l_bool diff); +static size_t __losuSyntaxIrLoadSizet (LosuVm *vm, _syntaxIO *io, + _l_bool diff); + +static void __losuSyntaxIrLoadConst (LosuVm *vm, _inlineScode *fs, + _syntaxIO *io, _l_bool diff); +static void __losuSyntaxIrLoadIns (LosuVm *vm, _inlineScode *fs, _syntaxIO *io, + _l_bool diff); +static void __losuSyntaxIrLoadLine (LosuVm *vm, _inlineScode *fs, + _syntaxIO *io, _l_bool diff); +static void __losuSyntaxIrLoadLcvar (LosuVm *vm, _inlineScode *fs, + _syntaxIO *io, _l_bool diff); + +static int32_t __losuSyntaxIrLoadByte (LosuVm *vm, _syntaxIO *io); +static void __losuSyntaxIrLoadBlock (LosuVm *vm, void *b, size_t size, + _syntaxIO *io, _l_bool diff); +static void __losuSyntaxIrLoadVector (LosuVm *vm, void *b, int m, size_t size, + _syntaxIO *io, _l_bool diff); + +static uint8_t __losuSyntaxIrIOgetc (LosuVm *vm, _syntaxIO *io); + +static void __losuSyntaxIrError (LosuVm *vm, const char *msg, ...); + +_inlineScode * +__losu_syntaxIrload_load (LosuVm *vm, _syntaxIO *io) +{ + _inlineScode *fs = NULL; + /* load magic */ + int32_t n = __losu_syntaxIO_getint32 (io); + if (n == 0) + fs = __losuSyntaxIrLoadFunc (vm, io, __losuSyntaxIrLoadHead (vm, io)); + else + __losuSyntaxIrError (vm, + __config_losucore_errmsg_msgIllegalBytecodeFormat); + n = __losu_syntaxIO_getint32 (io); + if (n != EOZ) + __losuSyntaxIrError (vm, + __config_losucore_errmsg_msgIllegalBytecodeFormat); + return fs; +} + +static _l_bool +__losuSyntaxIrLoadHead (LosuVm *vm, _syntaxIO *io) +{ + int32_t _diff = 1; + uint8_t _diffc = *(uint8_t *)(&_diff); + + /* Load Endianness */ + _l_bool diff = (_diffc != __losuSyntaxIrIOgetc (vm, io)); + + /* Load Version */ + { + _l_size_t v = __losuSyntaxIrLoadSizet (vm, io, diff); + if (v != LosuVersionNum) + __losuSyntaxIrError ( + vm, __config_losucore_errmsg_msgInvalidVmBytecodeVersion, + LosuVersionNum, v); + } + + /* Load Vm-bitsize */ + { + int32_t fbit; /* file bit size */ + fbit = __losuSyntaxIrIOgetc (vm, io); + if (fbit != sizeof (vmInstruction)) + __losuSyntaxIrError (vm, __config_losucore_errmsg_msgInvalidVmInsSize, + fbit * 8, sizeof (vmInstruction) * 8); + + return diff; + } +} + +static _inlineScode * +__losuSyntaxIrLoadFunc (LosuVm *vm, _syntaxIO *io, _l_bool diff) +{ + _inlineScode *fc = __losu_objFunc_scodeNew (vm); + fc->src = __losuSyntaxIrLoadString (vm, io, diff); + fc->defedline = __losuSyntaxIrLoadInt32 (vm, io, diff); + fc->narg = __losuSyntaxIrLoadInt32 (vm, io, diff); + fc->isVarg = __losuSyntaxIrLoadByte (vm, io); + fc->maxstacksize = __losuSyntaxIrLoadInt32 (vm, io, diff); + + __losuSyntaxIrLoadLcvar (vm, fc, io, diff); + __losuSyntaxIrLoadLine (vm, fc, io, diff); + __losuSyntaxIrLoadConst (vm, fc, io, diff); + __losuSyntaxIrLoadIns (vm, fc, io, diff); + + return fc; +} + +static _inlineString * +__losuSyntaxIrLoadString (LosuVm *vm, _syntaxIO *io, _l_bool diff) +{ + size_t s = __losuSyntaxIrLoadSizet (vm, io, diff); + if (s == 0) + return NULL; + else + { + if (s > vm->nbufftmp) + { + __losu_mem_reallocvector (vm, vm->bufftmp, s, unsigned char); + vm->nblocks += (s - vm->nbufftmp) * sizeof (unsigned char); + vm->nbufftmp = s; + memset (vm->bufftmp, 0, s); + } + __losuSyntaxIrLoadBlock (vm, vm->bufftmp, s, io, 0); + return __losu_objString_newstr (vm, (const char *)vm->bufftmp, s - 1); + } +} + +/* static _l_number +__losuSyntaxIrLoadNumber (LosuVm *vm, _syntaxIO *io, _l_bool diff) +{ + _l_number n; + __losuSyntaxIrLoadBlock (vm, &n, sizeof (_l_number), io, diff); + return n; +} */ + +static int32_t +__losuSyntaxIrLoadInt32 (LosuVm *vm, _syntaxIO *io, _l_bool diff) +{ + int32_t n; + __losuSyntaxIrLoadBlock (vm, &n, sizeof (int32_t), io, diff); + return n; +} + +static size_t +__losuSyntaxIrLoadSizet (LosuVm *vm, _syntaxIO *io, _l_bool diff) +{ + size_t n = 0; + _l_size_t t; + __losuSyntaxIrLoadBlock (vm, &t, sizeof (_l_size_t), io, diff); + n = t; + return n; +} + +static void +__losuSyntaxIrLoadConst (LosuVm *vm, _inlineScode *fs, _syntaxIO *io, + _l_bool diff) +{ + /* load string */ + fs->nlcstr = __losuSyntaxIrLoadInt32 (vm, io, diff); + fs->lcstr = __losu_mem_newvector (vm, fs->nlcstr, _inlineString *); + for (int32_t i = 0; i < fs->nlcstr; i++) + fs->lcstr[i] = __losuSyntaxIrLoadString (vm, io, diff); + + /* load num */ + fs->nlcnum = __losuSyntaxIrLoadInt32 (vm, io, diff); + fs->lcnum = __losu_mem_newvector (vm, fs->nlcnum, _l_number); + __losuSyntaxIrLoadVector (vm, fs->lcnum, fs->nlcnum, sizeof (_l_number), io, + diff); + + /* load func */ + fs->nlcscode = __losuSyntaxIrLoadInt32 (vm, io, diff); + fs->lcscode = __losu_mem_newvector (vm, fs->nlcscode, _inlineScode *); + for (int32_t i = 0; i < fs->nlcscode; i++) + fs->lcscode[i] = __losuSyntaxIrLoadFunc (vm, io, diff); +} + +static void +__losuSyntaxIrLoadIns (LosuVm *vm, _inlineScode *fs, _syntaxIO *io, + _l_bool diff) +{ + int32_t n = __losuSyntaxIrLoadInt32 (vm, io, diff); + fs->code = __losu_mem_newvector (vm, n, vmInstruction); + __losuSyntaxIrLoadVector (vm, fs->code, n, sizeof (vmInstruction), io, diff); + fs->ncode = n; + vm->nblocks += (sizeof (_inlineScode) + fs->nlcnum * sizeof (_l_number) + + fs->nlcstr * sizeof (_inlineString *) + + fs->nlcscode * sizeof (_inlineScode *) + + fs->ncode * sizeof (vmInstruction) + + fs->nlocalvar * sizeof (_inlineLocalvar) + + fs->nlineinfo * sizeof (int32_t)); +} + +static void +__losuSyntaxIrLoadLine (LosuVm *vm, _inlineScode *fs, _syntaxIO *io, + _l_bool diff) +{ + fs->nlineinfo = __losuSyntaxIrLoadInt32 (vm, io, diff); + fs->lineinfo = __losu_mem_newvector (vm, fs->nlineinfo, int32_t); + __losuSyntaxIrLoadVector (vm, fs->lineinfo, fs->nlineinfo, sizeof (int32_t), + io, diff); +} + +static void +__losuSyntaxIrLoadLcvar (LosuVm *vm, _inlineScode *fs, _syntaxIO *io, + _l_bool diff) +{ + fs->nlocalvar = __losuSyntaxIrLoadInt32 (vm, io, diff); + fs->localvar = __losu_mem_newvector (vm, fs->nlocalvar, _inlineLocalvar); + for (int32_t i = 0; i < fs->nlocalvar; i++) + { + fs->localvar[i].name = __losuSyntaxIrLoadString (vm, io, diff); + fs->localvar[i].startpc = __losuSyntaxIrLoadInt32 (vm, io, diff); + fs->localvar[i].endpc = __losuSyntaxIrLoadInt32 (vm, io, diff); + } +} + +static int32_t +__losuSyntaxIrLoadByte (LosuVm *vm, _syntaxIO *io) +{ + return (int32_t)__losuSyntaxIrIOgetc (vm, io); +} + +static void +__losuSyntaxIrLoadBlock (LosuVm *vm, void *b, size_t size, _syntaxIO *io, + _l_bool diff) +{ + if (diff) + { + uint8_t *p = (uint8_t *)(b + size - 1); + while (size--) + *(p--) = __losuSyntaxIrIOgetc (vm, io); + } + else + { + uint8_t *p = (uint8_t *)b; + while (size--) + *(p++) = __losuSyntaxIrIOgetc (vm, io); + } +} +static void +__losuSyntaxIrLoadVector (LosuVm *vm, void *b, int m, size_t size, + _syntaxIO *io, _l_bool diff) +{ + if (diff) + { + uint8_t *p = (uint8_t *)(b + m * size - 1); + while (m--) + { + __losuSyntaxIrLoadBlock (vm, p, size, io, diff); + p -= size; + } + } + else + { + uint8_t *p = (uint8_t *)b; + while (m--) + { + __losuSyntaxIrLoadBlock (vm, p, size, io, diff); + p += size; + } + } +} + +static uint8_t +__losuSyntaxIrIOgetc (LosuVm *vm, _syntaxIO *io) +{ + int16_t c = __losu_syntaxIO_getc (io); + + if (c == EOZ) + __losuSyntaxIrError (vm, + __config_losucore_errmsg_msgIllegalBytecodeFormat); + return (uint8_t)c; +} + +static void +__losuSyntaxIrError (LosuVm *vm, const char *msg, ...) +{ + memset (vm->staticbuff, 0, sizeof (vm->staticbuff)); + va_list ap; + va_start (ap, msg); + vsprintf ((char *)(vm->staticbuff), msg, ap); + fprintf (stderr, "Bytecode Error: %s\n at '%s'\n", vm->staticbuff, + vm->name != NULL ? vm->name : ""); + va_end (ap); + __losu_vmHeap_break (vm, LosuErrorCode_Syntax); +} + +#undef EOZ + +#endif diff --git a/core/losu_vm.c b/core/losu_vm.c new file mode 100755 index 0000000000000000000000000000000000000000..204d7d3f2fece5f50cf78b181dc358a307bc35ab --- /dev/null +++ b/core/losu_vm.c @@ -0,0 +1,1048 @@ +/* + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +/** + * An ultra-lightweight stacked virtual machine + * consisting of vmHeap,vmCore + */ + +#include "losu_vm.h" +#include "losu.h" +#include "losu_bytecode.h" +#include "losu_errmsg.h" +#include "losu_gc.h" +#include "losu_malloc.h" +#include "losu_object.h" +#include "losu_syntax.h" +#include +#include +#include +#include +#include + +#ifndef define_source_losu_vm +#define define_source_losu_vm +/* static segment */ +static LosuObj *__losuVmheapCallCapi (LosuVm *vm, _inlineFunction *cl, + LosuObj *base); +/* static segment */ +static LosuObj *__losuVmcoreExec (LosuVm *vm, const _inlineFunction *func, + LosuObj *base); +static const LosuObj *__losuVmcoreGetunit (LosuVm *vm, LosuObj *obj); +static void __losuVmcoreSetunit (LosuVm *vm, LosuObj *t, LosuObj *key); +static const LosuObj *__losuVmcoreGetglobal (LosuVm *vm, _inlineString *name); +static void __losuVmcoreSetglobal (LosuVm *vm, _inlineString *name); +static _l_bool __losuVmcoreLessthan (LosuVm *vm, const LosuObj *l, + const LosuObj *r, LosuObj *top); +static void __losuVmcoreStrconcat (LosuVm *vm, LosuObj *top); +static _l_bool __losuVmcoreStrisLess (const _inlineString *ls, + const _inlineString *rs); + +static void __losuVmcoreAdjVarg (LosuVm *vm, LosuObj *base, int32_t nfixarg); +static _inlineFunction *__losuVmcoreFunction (LosuVm *vm, int32_t niss); +#endif /* define_source_losu_vm */ + +#ifndef define_source_losu_vm_heap +#define define_source_losu_vm_heap + +#define __rstoreStackLimit(vm) \ + { \ + if (vm->top - vm->stack < vm->stacksize - 1) \ + vm->stackmax = vm->stack + (vm->stacksize - 1); \ + } + +void +__losu_vmHeap_init (LosuVm *vm, int32_t size) +{ + vm->stack = __losu_mem_newvector (vm, size, LosuObj); + vm->nblocks += size * sizeof (LosuObj); + vm->stackmax = vm->stack + size - 1; + vm->stacksize = size; + vm->base = vm->top = vm->stack; +} + +void +__losu_vmHeap_check (LosuVm *vm, int32_t size) +{ + if (vm->stackmax - vm->top <= size) + vm_error (vm, LosuErrorCode_Heap, + __config_losucore_errmsg_msgStackOverflow); +} +void +__losu_vmHeap_break (LosuVm *vm, int16_t ecode) +{ + if (vm->errjmp) + { + vm->errjmp->err = ecode; + longjmp (vm->errjmp->jmpflag, 1); + } + else + { + if (vm->emjmp) + longjmp (vm->emjmp->jmpflag, 1); + exit (LosuErrorCode_Over); + } +} +void +__losu_vmHeap_adjTop (LosuVm *vm, LosuObj *base, int32_t size) +{ + int32_t diff = size - (vm->top - base); + if (diff <= 0) + vm->top = base + size; + else + { + __losu_vmHeap_check (vm, diff); + while (diff--) + ovtype ((vm->top++)) = LosuTypeDefine_null; + } +} +int32_t +__losu_vmHeap_callS (LosuVm *vm, int32_t arg, int32_t nres) +{ + LosuObj *func = vm->top - arg - 1; + int32_t sta = 0; + LosuObj *oldBase = vm->base; + LosuObj *oldTop = vm->top; + __longjump jmp = { + .err = 0, + .pre = vm->errjmp, + }; + vm->errjmp = &jmp; + if (setjmp (jmp.jmpflag) == 0) + __losu_vmHeap_call (vm, func, nres); + else + { + vm->base = oldBase; + vm->top = oldTop; + __rstoreStackLimit (vm); + } + vm->errjmp = jmp.pre; + sta = jmp.err; + vm->top = func; + return sta; +} +void +__losu_vmHeap_call (LosuVm *vm, LosuObj *func, int32_t nres) +{ + LosuObj *fres; + _inlineCallinfo cinfo; + _inlineFunction *fc; + if (ovtype ((func)) != LosuTypeDefine_function) + { + if (ovtype (func) == LosuTypeDefine_unit) + { + /* get overload func */ + LosuObj *tfunc = obj_indexunitbystr (vm, *func, "::()"); + if (ovtype (tfunc) != LosuTypeDefine_function) + vm_error (vm, LosuErrorCode_Runtime, + __config_losucore_errmsg_msgInvalidOverload, "()"); + + /* copy stack args */ + vm->top++; + for (LosuObj *i = vm->top - 1; i > func; i--) + *i = *(i - 1); + + /* set tfunc */ + *func = *tfunc; + } + else + vm_error (vm, LosuErrorCode_Runtime, + __config_losucore_errmsg_msgCalledNotFunc); + } + + fc = ovfunc ((func)); + cinfo.func = fc; + ovcall ((func)) = &cinfo; + ovtype ((func)) + = LosuTypeDefine_mark; /* mark function from GC, when calling */ + + fres = (fc->isC) ? (__losuVmheapCallCapi (vm, fc, func + 1)) + : (__losuVmcoreExec (vm, fc, func + 1)); + if (nres == -1) + { + while (fres < vm->top) + *func++ = *fres++; + vm->top = func; + } + else + { + for (; nres > 0 && fres < vm->top; nres--) + *func++ = *fres++; + vm->top = func; + __losu_vmHeap_check (vm, nres); + for (; nres > 0; nres--) + { + ovtype ((vm->top)) = LosuTypeDefine_null; + vm->top++; + } + } + /* __losu_gc_checkClt (vm); */ +} + +static LosuObj * +__losuVmheapCallCapi (LosuVm *vm, _inlineFunction *cl, LosuObj *base) +{ + int32_t nc = cl->nclosure; + LosuObj *oldBase = vm->base; + int32_t n = 0; + vm->base = base; + __losu_vmHeap_check (vm, nc); + for (n = 0; n < nc; n++) + *(vm->top++) = cl->closure[n]; + n = ((*cl->func.capi) (vm)); + vm->base = oldBase; + return vm->top - n; +} + +#undef __rstoreStackLimit +#endif /* define_source_losu_vm_heap */ + +#ifndef define_source_losu_vm_core +#define define_source_losu_vm_core + +static LosuObj * +__losuVmcoreExec (LosuVm *vm, const _inlineFunction *func, LosuObj *base) +{ +#define tonumber(o) \ + ((ovtype (o) != LosuTypeDefine_number) \ + && (__losu_vmCore_Tonum (vm, o, 1)) != 0) +#define tostring(o) \ + ((ovtype (o) != LosuTypeDefine_string) \ + && (__losu_vmCore_Tostr (vm, o, 1) != 0)) +#define dojmp(pc, i) \ + { \ + pc += cgIns_GetS (i); \ + } + + /* printf("P1\n"); */ + + /* Coro Env */ + LosuObj *top; + const _inlineScode *fcode = (const _inlineScode *)func->func.sdef; + const vmInstruction *pc = (const vmInstruction *)fcode->code; + const _inlineString **lcstr = (const _inlineString **)fcode->lcstr; + const _l_number *lcnum = (const _l_number *)fcode->lcnum; + const LosuObj *closure = (const LosuObj *)func->closure; + const _inlineScode **lcfcode = (const _inlineScode **)fcode->lcscode; + + ovcall ((base - 1))->pc = &pc; + + /* Check Stack & Adj Varlist */ + __losu_vmHeap_check (vm, fcode->maxstacksize + 8); + if (fcode->isVarg) + __losuVmcoreAdjVarg (vm, base, fcode->narg); + else + __losu_vmHeap_adjTop (vm, base, fcode->narg); + top = vm->top; + + while (1) + { + const vmInstruction i = *pc++; + /* printf("Op:\t%d\n",cgIns_GetOp (i)); */ + switch (cgIns_GetOp (i)) + { + case INS_END: + { + vm->top = top; + return top; + } + case INS_RETURN: + { + vm->top = top; + return base + cgIns_GetU (i); + } + case INS_CALL: + { + int16_t nres = cgIns_GetB (i); + if (nres == 255) + nres = -1; + vm->top = top; + __losu_vmHeap_call (vm, base + cgIns_GetA (i), nres); + top = vm->top; + __losu_gc_checkClt (vm); + break; + } + case INS_PUSHNULL: + { + vmIns_U n = cgIns_GetU (i); + do + { + ovtype ((top++)) = LosuTypeDefine_null; + } + while (--n > 0); + break; + } + case INS_POP: + { + top -= cgIns_GetU (i); + break; + } + case INS_PUSHSTRING: + { + ovtype (top) = LosuTypeDefine_string; + ovIstr (top) = (_inlineString *)lcstr[cgIns_GetU (i)]; + top++; + break; + } + case INS_PUSHNUM: + { + ovtype (top) = LosuTypeDefine_number; + ovnumber (top) = lcnum[cgIns_GetU (i)]; + top++; + break; + } + case INS_PUSHUPVALUE: + { + *top++ = closure[cgIns_GetU (i)]; + break; + } + case INS_GETLOCAL: + { + *top++ = *(base + cgIns_GetU (i)); + break; + } + case INS_GETGLOBAL: + { + vm->top = top; + *top = *__losuVmcoreGetglobal ( + vm, (_inlineString *)lcstr[cgIns_GetU (i)]); + top++; + break; + } + case INS_GETUNIT: + { + vm->top = top; + top--; + *(top - 1) = *__losuVmcoreGetunit (vm, top - 1); + break; + } + case INS_PUSHSELF: + { + LosuObj tmp; + tmp = *(top - 1); + ovtype (top) = LosuTypeDefine_string; + ovIstr ((top++)) = (_inlineString *)lcstr[cgIns_GetU (i)]; + vm->top = top; + *(top - 2) = *__losuVmcoreGetunit (vm, top - 2); + *(top - 1) = tmp; + break; + } + case INS_CREATEUNIT: + { + vm->top = top; + __losu_gc_checkClt (vm); + ovhash (top) = __losu_objUnit_new (vm, cgIns_GetU (i)); + ovtype (top) = LosuTypeDefine_unit; + top++; + break; + } + case INS_SETLOCAL: + { + *(base + cgIns_GetU (i)) = *(--top); + break; + } + case INS_SETGLOBAL: + { + vm->top = top; + __losuVmcoreSetglobal (vm, (_inlineString *)lcstr[cgIns_GetU (i)]); + top--; + break; + } + case INS_SETUNIT: + { + LosuObj *t = top - cgIns_GetA (i); + vm->top = top; + __losuVmcoreSetunit (vm, t, t + 1); + top -= cgIns_GetB (i); + break; + } + case INS_SETLIST: + { + uint32_t aux = cgIns_GetA (i) * vmOl_MaxSetlist; + vmIns_B n = cgIns_GetB (i); + _inlineHash *arr = ovhash ((top - n - 1)); + vm->top = top - n; + for (; n; n--) + *__losu_objUnit_setnum (vm, arr, aux + n) = *(--top); + break; + } + case INS_SETMAP: + { + vmIns_U n = cgIns_GetU (i); + LosuObj *ftop = top - 2 * n; + _inlineHash *arr = ovhash ((ftop - 1)); + vm->top = ftop; + for (; n; n--) + { + top -= 2; + *__losu_objUnit_set (vm, arr, top) = *(top + 1); + } + break; + } + case INS_ADD: + { + + if (tonumber ((top - 2)) || tonumber ((top - 1))) + { + /* __losu_vmHeap_check (vm, 6); */ + top += 2; + vm->top = top; + *(top - 1) = (LosuObj){ + .type = LosuTypeDefine_string, + .value.str = __losu_objString_new (vm, "::+"), + }; + *(top - 2) = *(top - 4); + *(top) = *__losuVmcoreGetunit (vm, top - 2); + top += 3; + vm->top = top; + *(top - 2) = *(top - 7); + *(top - 1) = *(top - 6); + + if (ovtype ((top - 3)) != LosuTypeDefine_function) + vm_error (vm, LosuErrorCode_Runtime, + __config_losucore_errmsg_msgInvalidOverload, "+"); + + __losu_vmHeap_call (vm, top - 3, 1); + *(top - 7) = *(vm->top - 1); + top -= 6; + vm->top = top; + break; + } + else + ovnumber ((top - 2)) += ovnumber ((top - 1)); + top--; + break; + } + case INS_SUB: + { + if (tonumber ((top - 2)) || tonumber ((top - 1))) + { + top += 2; + vm->top = top; + *(top - 1) = (LosuObj){ + .type = LosuTypeDefine_string, + .value.str = __losu_objString_new (vm, "::-"), + }; + *(top - 2) = *(top - 4); + *(top) = *__losuVmcoreGetunit (vm, top - 2); + top += 3; + vm->top = top; + *(top - 2) = *(top - 7); + *(top - 1) = *(top - 6); + if (ovtype ((top - 3)) != LosuTypeDefine_function) + vm_error (vm, LosuErrorCode_Runtime, + __config_losucore_errmsg_msgInvalidOverload, "-"); + __losu_vmHeap_call (vm, top - 3, 1); + *(top - 7) = *(vm->top - 1); + top -= 6; + vm->top = top; + break; + } + else + ovnumber ((top - 2)) -= ovnumber ((top - 1)); + top--; + break; + } + case INS_MULT: + { + if (tonumber ((top - 2)) || tonumber ((top - 1))) + { + top += 2; + vm->top = top; + *(top - 1) = (LosuObj){ + .type = LosuTypeDefine_string, + .value.str = __losu_objString_new (vm, "::*"), + }; + *(top - 2) = *(top - 4); + *(top) = *__losuVmcoreGetunit (vm, top - 2); + top += 3; + vm->top = top; + *(top - 2) = *(top - 7); + *(top - 1) = *(top - 6); + if (ovtype ((top - 3)) != LosuTypeDefine_function) + vm_error (vm, LosuErrorCode_Runtime, + __config_losucore_errmsg_msgInvalidOverload, "*"); + __losu_vmHeap_call (vm, top - 3, 1); + *(top - 7) = *(vm->top - 1); + top -= 6; + vm->top = top; + break; + } + else + ovnumber ((top - 2)) *= ovnumber ((top - 1)); + top--; + break; + } + case INS_DIV: + { + if (tonumber ((top - 2)) || tonumber ((top - 1))) + { + top += 2; + vm->top = top; + *(top - 1) = (LosuObj){ + .type = LosuTypeDefine_string, + .value.str = __losu_objString_new (vm, "::/"), + }; + *(top - 2) = *(top - 4); + *(top) = *__losuVmcoreGetunit (vm, top - 2); + top += 3; + vm->top = top; + *(top - 2) = *(top - 7); + *(top - 1) = *(top - 6); + if (ovtype ((top - 3)) != LosuTypeDefine_function) + vm_error (vm, LosuErrorCode_Runtime, + __config_losucore_errmsg_msgInvalidOverload, "/"); + __losu_vmHeap_call (vm, top - 3, 1); + *(top - 7) = *(vm->top - 1); + top -= 6; + vm->top = top; + break; + } + else + ovnumber ((top - 2)) /= ovnumber ((top - 1)); + top--; + break; + } + case INS_POW: + { + if (tonumber ((top - 2)) || tonumber ((top - 1))) + { + top += 2; + vm->top = top; + *(top - 1) = (LosuObj){ + .type = LosuTypeDefine_string, + .value.str = __losu_objString_new (vm, "::^"), + }; + *(top - 2) = *(top - 4); + *(top) = *__losuVmcoreGetunit (vm, top - 2); + top += 3; + vm->top = top; + *(top - 2) = *(top - 7); + *(top - 1) = *(top - 6); + if (ovtype ((top - 3)) != LosuTypeDefine_function) + vm_error (vm, LosuErrorCode_Runtime, + __config_losucore_errmsg_msgInvalidOverload, "^"); + __losu_vmHeap_call (vm, top - 3, 1); + *(top - 7) = *(vm->top - 1); + top -= 6; + vm->top = top; + break; + } + else + ovnumber ((top - 2)) + = pow (ovnumber ((top - 2)), ovnumber ((top - 1))); + top--; + break; + } + case INS_CONCAT: + { + __losuVmcoreStrconcat (vm, top); + top--; + vm->top = top; + __losu_gc_checkClt (vm); + break; + } + case INS_NEG: + { + if (tonumber ((top - 1))) + { + vm->top = top; + LosuObj *func = obj_indexunitbystr (vm, *(top - 1), "::-x"); + if (ovtype (func) == LosuTypeDefine_null) + vm_error (vm, LosuErrorCode_Runtime, + __config_losucore_errmsg_msgInvalidOverload, + "::-x"); + stack_push (vm, *func); /* push function */ + stack_push (vm, *(top - 1)); /* push operand */ + stack_call (vm, 1, 1); + *(top - 1) = *(vm->top - 1); + vm->top = top; + } + else + ovnumber ((top - 1)) = -ovnumber ((top - 1)); + break; + } + case INS_NOT: + { + ovtype ((top - 1)) = (ovtype ((top - 1)) == LosuTypeDefine_null) + ? LosuTypeDefine_number + : LosuTypeDefine_null; + ovnumber ((top - 1)) = 1; + break; + } + case INS_JMPNE: + { + top -= 2; + if (!__losu_object_isObjEqual (top, top + 1)) + dojmp (pc, i); + break; + } + case INS_JMPEQ: + { + top -= 2; + if (__losu_object_isObjEqual (top, top + 1)) + dojmp (pc, i); + break; + } + case INS_JMPLT: + { + top -= 2; + if (__losuVmcoreLessthan (vm, top, top + 1, top + 2)) + dojmp (pc, i); + break; + } + case INS_JMPLE: + { + top -= 2; + if (!__losuVmcoreLessthan (vm, top + 1, top, top + 2)) + dojmp (pc, i); + break; + } + case INS_JMPGT: + { + top -= 2; + if (__losuVmcoreLessthan (vm, top + 1, top, top + 2)) + dojmp (pc, i); + break; + } + case INS_JMPGE: + { + top -= 2; + if (!__losuVmcoreLessthan (vm, top, top + 1, top + 2)) + dojmp (pc, i); + break; + } + case INS_JMPT: + { + if (ovtype ((--top)) != LosuTypeDefine_null) + dojmp (pc, i); + break; + } + case INS_JMPF: + { + if (ovtype ((--top)) == LosuTypeDefine_null) + dojmp (pc, i); + break; + } + case INS_JMPONT: + { + if (ovtype ((top - 1)) == LosuTypeDefine_null) + top--; + else + dojmp (pc, i); + break; + } + case INS_JMPONF: + { + if (ovtype ((top - 1)) != LosuTypeDefine_null) + top--; + else + dojmp (pc, i); + break; + } + case INS_JMP: + { + dojmp (pc, i); + break; + } + case INS_PUSHNULLJMP: + { + ovtype ((top++)) = LosuTypeDefine_null; + pc++; + break; + } + case INS_FORPREP: + { + if (tonumber ((top - 1))) + vm_error (vm, LosuErrorCode_Runtime, + __config_losucore_errmsg_msgInvalidForstep); + if (tonumber ((top - 2))) + vm_error (vm, LosuErrorCode_Runtime, + __config_losucore_errmsg_msgInvalidFormax); + if (tonumber ((top - 3))) + vm_error (vm, LosuErrorCode_Runtime, + __config_losucore_errmsg_msgInvalidForinit); + if (ovnumber ((top - 1)) > 0 + ? ovnumber ((top - 3)) > ovnumber ((top - 2)) + : ovnumber ((top - 3)) < ovnumber ((top - 2))) + { + top -= 3; + dojmp (pc, i); + } + break; + } + case INS_FORLOOP: + { + if (ovtype ((top - 3)) != LosuTypeDefine_number) + vm_error (vm, LosuErrorCode_Runtime, + __config_losucore_errmsg_msgInvalidForstep); + ovnumber ((top - 3)) += ovnumber ((top - 1)); + if (ovnumber ((top - 1)) > 0 + ? ovnumber ((top - 3)) > ovnumber ((top - 2)) + : ovnumber ((top - 3)) < ovnumber ((top - 2))) + top -= 3; + else + dojmp (pc, i); + break; + } + case INS_LFORPREP: + { + LosuNode *node; + if (ovtype ((top - 1)) != LosuTypeDefine_unit) + vm_error (vm, LosuErrorCode_Runtime, + __config_losucore_errmsg_msgInvalidForobj); + node = (LosuNode *)__losu_objUnit_getnext ( + ovhash ((top - 1)), (LosuObj *)&_inlineNullObj); + if (node == NULL) + { + top--; + dojmp (pc, i); + } + else + { + top += 2; + *(top - 2) = node->key; + *(top - 1) = node->value; + } + break; + } + case INS_LFORLOOP: + { + LosuNode *node; + node = (LosuNode *)__losu_objUnit_getnext (ovhash ((top - 3)), + top - 2); + if (node == NULL) + top -= 3; + else + { + *(top - 2) = node->key; + *(top - 1) = node->value; + dojmp (pc, i); + } + break; + } + case INS_PUSHFUNCTION: + { + vm->top = top; + { + _inlineFunction *func + = __losuVmcoreFunction (vm, cgIns_GetB (i)); + func->func.sdef = (_inlineScode *)lcfcode[cgIns_GetA (i)]; + func->isC = 0; + } + top = vm->top; + __losu_gc_checkClt (vm); + break; + } + default: + { + vm_error (vm, LosuErrorCode_Runtime, + __config_losucore_errmsg_msgInvalidBytecode); + } + } + } + +#undef tonumber +#undef tostring +#undef dojmp +} + +_l_bool +__losu_vmCore_Tonum (LosuVm *vm, LosuObj *obj, _l_bool isCore) +{ + if (ovtype (obj) != LosuTypeDefine_string) + { + if (ovtype (obj) == LosuTypeDefine_unit) + { + LosuObj *func = obj_indexunitbystr (vm, *obj, "::->num"); + if (ovtype (func) == LosuTypeDefine_function) + { + LosuObj *oldtop = vm->top; + if (isCore) + vm->top = obj + 4; + __losu_vmHeap_check (vm, 16); + stack_push (vm, *func); + stack_push (vm, *obj); + stack_call (vm, 1, 1); + *obj = *(vm->top - 1); + vm->top = oldtop; + return 0; + } + } + return 1; + } + else + { + if (!__losu_object_str2num (ovSstr (obj), &ovnumber (obj))) + return 1; + ovtype (obj) = LosuTypeDefine_number; + return 0; + } +} + +_l_bool +__losu_vmCore_Tostr (LosuVm *vm, LosuObj *obj, _l_bool isCore) +{ + if (ovtype (obj) != LosuTypeDefine_number) + { + if (ovtype (obj) == LosuTypeDefine_unit) + { + LosuObj *func = obj_indexunitbystr (vm, *obj, "::->str"); + if (ovtype (func) == LosuTypeDefine_function) + { + LosuObj *oldtop = vm->top; + if (isCore) + vm->top = obj + 4; + __losu_vmHeap_check (vm, 16); + stack_push (vm, *func); + stack_push (vm, *obj); + stack_call (vm, 1, 1); + *obj = *(vm->top - 1); + vm->top = oldtop; + return 0; + } + } + return 1; + } + else + { + char s[32] = { 0 }; + sprintf (s, "%.16g", ovnumber (obj)); + ovtype (obj) = LosuTypeDefine_string; + ovIstr (obj) = __losu_objString_new (vm, s); + return 0; + } +} + +static const LosuObj * +__losuVmcoreGetunit (LosuVm *vm, LosuObj *obj) +{ + if (ovtype (obj) == LosuTypeDefine_null) + return &_inlineNullObj; + if (ovtype (obj) == LosuTypeDefine_unit) + { + const LosuObj *h = __losu_objUnit_get (ovhash (obj), vm->top - 1); + if (ovtype (h) == LosuTypeDefine_null) + return &_inlineNullObj; + return h; + } + return &_inlineNullObj; +} + +static void +__losuVmcoreSetunit (LosuVm *vm, LosuObj *t, LosuObj *key) +{ + if (ovtype (t) == LosuTypeDefine_unit) + *__losu_objUnit_set (vm, ovhash (t), key) = *(vm->top - 1); + else + vm_error (vm, LosuErrorCode_Runtime, + __config_losucore_errmsg_msgInvalidSetobj); +} + +static const LosuObj * +__losuVmcoreGetglobal (LosuVm *vm, _inlineString *name) +{ + return __losu_objUnit_getstr (vm->global, name); +} + +static void +__losuVmcoreSetglobal (LosuVm *vm, _inlineString *name) +{ + const LosuObj *oval = __losu_objUnit_getstr (vm->global, name); + if (oval != &_inlineNullObj) + *((LosuObj *)oval) = *(vm->top - 1); + else + { + LosuObj key = (LosuObj){ + .type = LosuTypeDefine_string, + .value.str = name, + }; + *__losu_objUnit_set (vm, vm->global, &key) = *(vm->top - 1); + } +} + +static _l_bool +__losuVmcoreLessthan (LosuVm *vm, const LosuObj *l, const LosuObj *r, + LosuObj *top) +{ + if (ovtype (l) != ovtype (r)) + { + if (ovtype (l) == LosuTypeDefine_number + && ovtype (r) == LosuTypeDefine_string) + return ovnumber (l) < ostr2num (ovSstr (r), NULL); + else if (ovtype (r) == LosuTypeDefine_number + && ovtype (l) == LosuTypeDefine_string) + return ostr2num (ovSstr (l), NULL) < ovnumber (r); + else + return 0; + } + switch (ovtype (l)) + { + case LosuTypeDefine_number: + return ovnumber (l) < ovnumber (r); + case LosuTypeDefine_string: + return __losuVmcoreStrisLess (ovIstr (l), ovIstr (r)); + default: + break; + } + return ovtype (r) != LosuTypeDefine_null + || ovtype (l) != LosuTypeDefine_null; +} + +static void +__losuVmcoreStrconcat (LosuVm *vm, LosuObj *top) +{ +#define tostring(o) \ + ((ovtype (o) != LosuTypeDefine_string) \ + && (__losu_vmCore_Tostr (vm, o, 1) != 0)) + + if (tostring ((top - 2)) || tostring ((top - 1))) + { + top += 2; + vm->top = top; + *(top - 1) = (LosuObj){ + .type = LosuTypeDefine_string, + .value.str = __losu_objString_new (vm, "::&"), + }; + *(top - 2) = *(top - 4); + *(top) = *__losuVmcoreGetunit (vm, top - 2); + + top += 3; + vm->top = top; + *(top - 2) = *(top - 7); + *(top - 1) = *(top - 6); + if (ovtype ((top - 3)) != LosuTypeDefine_function) + vm_error (vm, LosuErrorCode_Runtime, + __config_losucore_errmsg_msgInvalidOverload, "&"); + __losu_vmHeap_call (vm, top - 3, 1); + *(top - 7) = *(vm->top - 1); + top -= 6; + vm->top = top; + return; + } + else if (ovIstr ((top - 1))->len > 0) + { + _l_size_t p; + _l_size_t nl = ovIstr ((top - 2))->len + ovIstr ((top - 1))->len; + if (nl > vmOl_MaxStrlen) + vm_error (vm, LosuErrorCode_Runtime, + __config_losucore_errmsg_msgStrlenOverflow); + if (nl > vm->nbufftmp) + { + __losu_mem_reallocvector (vm, vm->bufftmp, nl, unsigned char); + vm->nblocks += (nl - vm->nbufftmp) * sizeof (char); + vm->nbufftmp = nl; + } + + p = ovIstr ((top - 2))->len; + memcpy (vm->bufftmp, ovSstr ((top - 2)), p); + memcpy (vm->bufftmp + p, ovSstr ((top - 1)), ovIstr ((top - 1))->len); + ovIstr ((top - 2)) + = __losu_objString_newstr (vm, (const char *)(vm->bufftmp), nl); + } + /* top--; */ +#undef tostring +} + +static _l_bool +__losuVmcoreStrisLess (const _inlineString *ls, const _inlineString *rs) +{ + + const void *l = (const void *)(ls->str); + const void *r = (const void *)(rs->str); + _l_size_t ll = ls->len; + _l_size_t lr = rs->len; + _l_size_t ml = ll < lr ? ll : lr; + int32_t i = memcmp (l, r, ml); + + return i < 0 ? 1 : ((i == 0) ? (ll < lr) : 0); +} + +void +__losuVmcoreAdjVarg (LosuVm *vm, LosuObj *base, int32_t nfixarg) +{ + int32_t nv = (vm->top - base) - nfixarg; + if (nv < 0) + __losu_vmHeap_adjTop (vm, base, nfixarg); + + { + LosuObj *felem = base + nfixarg; + int32_t i; + _inlineHash *hunit = __losu_objUnit_new (vm, 0); + for (i = 0; felem + i < vm->top; i++) + *__losu_objUnit_setnum (vm, hunit, i + 1) = *(felem + i); + + *__losu_objUnit_setstr (vm, hunit, __losu_objString_new (vm, "n")) + = (LosuObj){ + .type = LosuTypeDefine_number, + .value.num = i, + }; +#ifdef __config_losucore_feature_chKeyword + *__losu_objUnit_setstr (vm, hunit, __losu_objString_new (vm, "个数")) + = (LosuObj){ + .type = LosuTypeDefine_number, + .value.num = i, + }; +#endif + vm->top = felem; + ovtype ((vm->top)) = LosuTypeDefine_unit; + ovhash ((vm->top)) = hunit; + if (vm->top == vm->stackmax) + __losu_vmHeap_check (vm, 1); + vm->top++; + } +} + +static _inlineFunction * +__losuVmcoreFunction (LosuVm *vm, int32_t niss) +{ + _inlineFunction *f = __losu_objFunc_new (vm, niss); + vm->top -= niss; + while (niss--) + f->closure[niss] = *(vm->top + niss); + ovfunc ((vm->top)) = f; + ovtype ((vm->top)) = LosuTypeDefine_function; + if (vm->top == vm->stackmax) + __losu_vmHeap_check (vm, 1); + vm->top++; + return f; +} + +#endif /* define_source_losu_vm_core */ diff --git a/core/losuh.c b/core/losuh.c new file mode 100755 index 0000000000000000000000000000000000000000..2d16cb2e2a8d94c836f632b36c1ad5b1f9a049cd --- /dev/null +++ b/core/losuh.c @@ -0,0 +1,145 @@ +/* + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +/* + This document is part of the Losu Community OSPP - 2024 subject results + contributed by Dongqiao Huang @ NEUQ, following MIT LICENSE Contributed to + the Losu Community. + + The MIT LICENSE is as follows + -------------------- + Copyright 2024 Dongqiao Huang + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +/* + This file is about liblosuh's API, which is a library for the losuh + */ + +#include "losuh.h" + +void +__losuhAPI_regNumber (LosuVm *vm, const char *name, _l_number num) +{ + vm_setval (vm, name, obj_newnum (vm, num)); +} + +void +__losuhAPI_regString (LosuVm *vm, const char *name, const char *str) +{ + vm_setval (vm, name, obj_newstr (vm, (char *)str)); +} + +void +__losuhAPI_regFunc (LosuVm *vm, const char *name, LosuApi func) +{ + vm_setval (vm, name, obj_newfunction (vm, func)); +} + +void +__losuhAPI_regScript (LosuVm *vm, const char *name, const char *byte, + size_t len) +{ + vm_dobyte (vm, byte, len, name); +} + +void +__losuhAPI_regObject (LosuVm *vm, const char *name, LosuObj obj) +{ + vm_setval (vm, name, obj); +} + +void +__losuhAPI_regClass (LosuVm *vm, const char *name, LosuObj cls) +{ + obj_setunitbystr (vm, cls, "::type", obj_newstr (vm, (char *)name)); + vm_setval (vm, name, cls); +} + +void +__losuhAPI_regObjNumber (LosuVm *vm, LosuObj obj, const char *name, + _l_number num) +{ + obj_setunitbystr (vm, obj, (char *)name, obj_newnum (vm, num)); +} +void +__losuhAPI_regObjString (LosuVm *vm, LosuObj obj, const char *name, + const char *str) +{ + obj_setunitbystr (vm, obj, (char *)name, obj_newstr (vm, (char *)str)); +} + +void +__losuhAPI_regObjObject (LosuVm *vm, LosuObj obj, const char *name, + LosuObj obj2) +{ + obj_setunitbystr (vm, obj, (char *)name, obj2); +} + +void +__losuhAPI_regObjClass (LosuVm *vm, LosuObj obj, const char *name, + const char *type, LosuObj cls) +{ + obj_setunitbystr (vm, cls, "::type", obj_newstr (vm, (char *)type)); + obj_setunitbystr (vm, obj, (char *)name, cls); +} + +void +__losuhAPI_regObjFunc (LosuVm *vm, LosuObj obj, const char *name, LosuApi func) +{ + obj_setunitbystr (vm, obj, (char *)name, obj_newfunction (vm, func)); +} \ No newline at end of file diff --git a/core/makefile b/core/makefile new file mode 100755 index 0000000000000000000000000000000000000000..0ed02fc7491020357ee454942475a40b55318ebb --- /dev/null +++ b/core/makefile @@ -0,0 +1,49 @@ +PkgObj=$(LosuSDK_Obj)/sdk/liblosu + +cc=cc + +CIncFile= $(shell ls $(LosuSDK_Include)/*.h) + +cWarning= -Wall +cStd= -std=c99 +cOpt= -O2 +cInclude= -I$(LosuSDK_Include) -Iinclude +cLink= -lm +cFlags= $(cWarning) $(cStd) $(cOpt) $(cInclude) + +$(LosuSDK_Lib)/liblosu.a : \ + $(PkgObj)/losu_api.o\ + $(PkgObj)/losu.o\ + $(PkgObj)/losu_gc.o\ + $(PkgObj)/losuh.o\ + $(PkgObj)/losu_malloc.o\ + $(PkgObj)/losu_object.o\ + $(PkgObj)/losu_syntax.o\ + $(PkgObj)/losu_vm.o\ + + ar crs $@ $^ + +$(PkgObj)/losu_api.o: losu_api.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ + +$(PkgObj)/losu.o: losu.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ + +$(PkgObj)/losu_gc.o: losu_gc.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ + +$(PkgObj)/losuh.o: losuh.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ + +$(PkgObj)/losu_malloc.o: losu_malloc.c $(CIncFile) + + $(cc) $(cFlags) -c $< -o $@ + +$(PkgObj)/losu_object.o: losu_object.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ + +$(PkgObj)/losu_syntax.o: losu_syntax.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ + +$(PkgObj)/losu_vm.o: losu_vm.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ \ No newline at end of file diff --git a/core/target/x86_64-linux-gnu.mk b/core/target/x86_64-linux-gnu.mk new file mode 100755 index 0000000000000000000000000000000000000000..ee36a971cdb6a984161f8c411db6b5063e354dc7 --- /dev/null +++ b/core/target/x86_64-linux-gnu.mk @@ -0,0 +1,56 @@ +PkgTarget=$(LosuSDK_Build)/target +PkgObj=$(LosuSDK_Build)/obj/target/liblosu + +cc=x86_64-linux-gnu-gcc + +CIncFile= $(shell ls $(LosuSDK_Include)/*.h) + +cWarning= -Wall +cStd= -std=c99 +cOpt= -O2 +cInclude= -I$(LosuSDK_Include) -Iinclude + +cFlags= $(cWarning) $(cStd) $(cOpt) $(cInclude) + +$(PkgTarget)/liblosu.a:\ + $(PkgObj)/.keep\ + $(PkgObj)/losu_api.o\ + $(PkgObj)/losu.o\ + $(PkgObj)/losu_gc.o\ + $(PkgObj)/losuh.o\ + $(PkgObj)/losu_malloc.o\ + $(PkgObj)/losu_object.o\ + $(PkgObj)/losu_syntax.o\ + $(PkgObj)/losu_vm.o\ + + + ar crs $@ $^ + +$(PkgObj)/.keep: + mkdir -p $(PkgObj) + touch $@ + +$(PkgObj)/losu_api.o: losu_api.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ + +$(PkgObj)/losu.o: losu.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ + +$(PkgObj)/losu_gc.o: losu_gc.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ + +$(PkgObj)/losuh.o: losuh.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ + +$(PkgObj)/losu_malloc.o: losu_malloc.c $(CIncFile) + + $(cc) $(cFlags) -c $< -o $@ + +$(PkgObj)/losu_object.o: losu_object.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ + +$(PkgObj)/losu_syntax.o: losu_syntax.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ + +$(PkgObj)/losu_vm.o: losu_vm.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ \ No newline at end of file diff --git a/core/target/x86_64-w64-mingw32.mk b/core/target/x86_64-w64-mingw32.mk new file mode 100755 index 0000000000000000000000000000000000000000..1d6773d0e18fd97c84d4dfbab05c39882dafb709 --- /dev/null +++ b/core/target/x86_64-w64-mingw32.mk @@ -0,0 +1,56 @@ +PkgTarget=$(LosuSDK_Build)/target +PkgObj=$(LosuSDK_Build)/obj/target/liblosu + +cc=x86_64-w64-mingw32-gcc + +CIncFile= $(shell ls $(LosuSDK_Include)/*.h) + +cWarning= -Wall +cStd= -std=c99 +cOpt= -O2 +cInclude= -I$(LosuSDK_Include) -Iinclude + +cFlags= $(cWarning) $(cStd) $(cOpt) $(cInclude) + +$(PkgTarget)/liblosu.a:\ + $(PkgObj)/.keep\ + $(PkgObj)/losu_api.o\ + $(PkgObj)/losu.o\ + $(PkgObj)/losu_gc.o\ + $(PkgObj)/losuh.o\ + $(PkgObj)/losu_malloc.o\ + $(PkgObj)/losu_object.o\ + $(PkgObj)/losu_syntax.o\ + $(PkgObj)/losu_vm.o\ + + + ar crs $@ $^ + +$(PkgObj)/.keep: + mkdir -p $(PkgObj) + touch $@ + +$(PkgObj)/losu_api.o: losu_api.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ + +$(PkgObj)/losu.o: losu.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ + +$(PkgObj)/losu_gc.o: losu_gc.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ + +$(PkgObj)/losuh.o: losuh.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ + +$(PkgObj)/losu_malloc.o: losu_malloc.c $(CIncFile) + + $(cc) $(cFlags) -c $< -o $@ + +$(PkgObj)/losu_object.o: losu_object.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ + +$(PkgObj)/losu_syntax.o: losu_syntax.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ + +$(PkgObj)/losu_vm.o: losu_vm.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ \ No newline at end of file diff --git a/lsnput/.keep b/demo/.keep old mode 100644 new mode 100755 similarity index 100% rename from lsnput/.keep rename to demo/.keep diff --git a/demo/helloworld/config b/demo/helloworld/config new file mode 100755 index 0000000000000000000000000000000000000000..c15625f16d7c3bf46161a08814a60680f338d5b2 --- /dev/null +++ b/demo/helloworld/config @@ -0,0 +1,8 @@ +main = { + name: "helloworld", + target: "x86_64-linux-gnu.mk", + # target: "x86_64-w64-mingw32.mk", + pkgs : { + "helloworld", + }, +} diff --git a/demo/helloworld/main.c b/demo/helloworld/main.c new file mode 100755 index 0000000000000000000000000000000000000000..55ba2a12375cdf77e31a4c95a4eea6b238962e8a --- /dev/null +++ b/demo/helloworld/main.c @@ -0,0 +1,29 @@ +#include "losu.h" +#include +#include + +/* need config */ +#include "pkgs.inc" + +/* need losuc -c main.els */ +static const char __main__[] = +#include "main.els.inc" + ; + +/* main */ +int32_t +main (int32_t argc, const char **argv) +{ + int32_t i = 0; + LosuVm *vm = vm_create (1024); + if (vm) + { + LosuPackages = &_inlinePkgs[0]; + vm_init (vm, argc, argv); + i = vm_dobyte (vm,__main__,sizeof(__main__),"main.els"); + } + else + i = -1; + vm_close(vm); + return i; +} \ No newline at end of file diff --git a/demo/helloworld/main.els b/demo/helloworld/main.els new file mode 100755 index 0000000000000000000000000000000000000000..d64f9ba0c9f83032e4799ad07988b9917b8a7b8b --- /dev/null +++ b/demo/helloworld/main.els @@ -0,0 +1,2 @@ +import "helloworld" +hello() \ No newline at end of file diff --git a/demo/helloworld/target/x86_64-linux-gnu.mk b/demo/helloworld/target/x86_64-linux-gnu.mk new file mode 100755 index 0000000000000000000000000000000000000000..213c80aab74023fe5824414951e9ef5113b53afa --- /dev/null +++ b/demo/helloworld/target/x86_64-linux-gnu.mk @@ -0,0 +1,14 @@ +cc=x86_64-linux-gnu-gcc + +cWarning= -Wall +cStd= -std=c99 +cOpt= -O2 +cInclude= -I$(LosuSDK_Include) +cFlags= $(cWarning) $(cStd) $(cOpt) $(cInclude) +cLink= -L $(LosuSDK_Build)/target -llosucore -lm + +$(main.out): main.els + losuc -c main.els + + $(cc) -o $@ $(cFlags) main.c $(cLink) + \ No newline at end of file diff --git a/demo/helloworld/target/x86_64-w64-mingw32.mk b/demo/helloworld/target/x86_64-w64-mingw32.mk new file mode 100755 index 0000000000000000000000000000000000000000..1c9427093227af59b7dfcae626e6e6fe8e512ef7 --- /dev/null +++ b/demo/helloworld/target/x86_64-w64-mingw32.mk @@ -0,0 +1,14 @@ +cc=x86_64-w64-mingw32-gcc + +cWarning= -Wall +cStd= -std=c99 +cOpt= -Os +cInclude= -I$(LosuSDK_Include) +cFlags= $(cWarning) $(cStd) $(cOpt) $(cInclude) +cLink= -lm -L $(LosuSDK_Build)/target -llosucore + +$(main.out): main.els + losuc -c main.els + + $(cc) -o $@ $(cFlags) main.c $(cLink) + \ No newline at end of file diff --git a/lsnput/Ubuntu/.keep b/doc/.keep similarity index 100% rename from lsnput/Ubuntu/.keep rename to doc/.keep diff --git "a/document/1-1-\345\234\250\347\272\277\346\234\215\345\212\241.md" "b/document/1-1-\345\234\250\347\272\277\346\234\215\345\212\241.md" deleted file mode 100755 index ff909c7687cad5c10d157d72c1752ba66cca5791..0000000000000000000000000000000000000000 --- "a/document/1-1-\345\234\250\347\272\277\346\234\215\345\212\241.md" +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/owls.wiki.losu.tech - -# 1-1-在线服务 -## 1-1-1-了解洛书的在线服务 -洛书编程语言作为一种简洁、易学、高效的编程语言,在发布以来获得了广泛的关注。 - -为了更好地服务关注者,我们特地为洛书创建了丰富的在线服务站点, -您可以通过浏览器在线体验洛书的大部分功能而无需在本地安装相应环境,旨在为新用户降低门槛,为老用户提供便利。 - - - -## 1-1-2-服务内容 -目前,我们大致支持了以下服务 - -+ 软件下载:您可以在这里下载洛书编程语言的最新版本,以便在您的计算机上安装和使用。 -+ 代码索引:我们为您提供了各个版本的代码索引服务,方便您快速查找和使用。 -+ 在线运行:您可以在线编写和运行洛书代码,实时查看运行结果,方便您进行学习和调试。 -+ 模块查找:我们为您提供了在线的模块查询服务,可以使用图形化界面快速了解模块信息 -+ 文档预览:快速预览洛书的在线文档 -+ 自动更新:自动化模块更新与版本发布 - -## 1-1-3-反馈 -我们希望通过线服务,帮助您更好地学习和使用洛书编程语言,提高您的编程效率和开发质量。 -如果您有任何问题或建议,请随时联系我们,我们将竭诚为您服务。 - diff --git "a/document/1-2-\344\270\213\350\275\275\344\270\216\345\256\211\350\243\205.md" "b/document/1-2-\344\270\213\350\275\275\344\270\216\345\256\211\350\243\205.md" deleted file mode 100755 index c3a7d0a8542035c0b2414fde812af0b40742072d..0000000000000000000000000000000000000000 --- "a/document/1-2-\344\270\213\350\275\275\344\270\216\345\256\211\350\243\205.md" +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/owls.wiki.losu.tech - -# 1-2-下载与安装 -## 1-2-1-为 Windows 设备安装 - -### 1-2-1-1-系统要求 -1. Windows 64位版本,支持通用 CRT -2. 支持 curl ,一般而言,满足 1 的系统都满足此条件 -3. 安装 7z ,您可以访问 7z [官网](https://www.7-zip.org/)进行安装 - -### 1-2-1-2-下载二进制压缩包 -+ 途径一(最新版本):访问 [洛书官网](https://losu.tech) ——> 下载 ——> Windows -+ 途径二(指定版本):访问 [服务中心](https://losu.tech/studio) ——> 选择版本 ——> 下载安装包 ——> 下载Windows的压缩包 - -### 1-2-1-3-开始安装 -1. 解压压缩包到需要的目录(尽量不要C盘),比如 D:\losu,此时解释器为 D:\losu\losu.exe -2. 配置环境变量,您可以采用以下两种方式配置 - + 以管理员模式运行 install.bat - + 手动添加 ```D:\losu\``` 到环境变量 PATH 、 LPTROOT 中 - > 解释: PATH 变量负责 让系统找到losu.exe,这样才能使用 losu 命令,如果不准备使用这条命令,可以不添加 -3. 打开终端,输入命令 losu ,进入REPL交互式运行模式 -4. 输入 ```打印('你好,洛书编程语言!')``` ,验证是否正常工作。 - - -## 1-2-2-为 Ubuntu/Debian 等 Linux 设备安装 -### 1-2-2-1-系统要求 - -+ 64 位 Linux 发行版, x86处理器 -+ 支持```Ubuntu GLIBC 2.27-3ubuntu1.6) 2.27``` -+ 采用dpkg作为包管理器 -+ 常见问题 - 1. 如何获取 glibc 版本? - + 打开终端,输入 ldd --version。 - + Linux 分支采用 Ubuntu 18.04.6 LTS 作为编译环境,GCC 7.5.0 GLIBC 2.27 - + 一般而言,Debian 系列高于此版本的系统都可以运行,这包括 Ubuntu,Deepin,UOS,OpenKylin等常见发行版 - 2. 如果是非 dpkg 的发行版怎么办? - + ```ar -vx xxx.deb```,解压出 data.tar.gz/data.tar,xz 压缩文件 - + 解压data,把里面的内容复制到根目录,即可 - + 使用工具转换出rpm包 - -### 1-2-2-2-下载二进制安装包 -+ 途径一(最新版本):访问 [洛书官网](https://losu.tech) ——> 下载 ——> Linux -+ 途径二(指定版本):访问 [服务中心](https://losu.tech/studio) ——> 选择版本 ——> 下载安装包 ——> 下载 Linux 的压缩包 - -### 1-2-2-3-开始安装 -1. 安装软件包,可以使用命令行或系统自带的图像化工具 -2. 安装```rlwrap```工具,方便交互式运行 -3. 打开终端,输入命令```rlwrap losu```,进入REPL交互式运行模式 -4. 输入```打印('你好,洛书编程语言!')```,验证是否正常工作。 - - - -## 1-2-3-为MCU、IOT芯片、开发板等非常规平台安装 -+ 访问 [服务中心](https://losu.tech/studio) ——> 选择版本 ——> 下载安装包 ——> 下载相应设备的固件 -+ 烧录固件,复位设备。 \ No newline at end of file diff --git "a/document/1-3-\345\210\235\350\257\206\346\250\241\345\235\227\347\256\241\347\220\206\345\231\250.md" "b/document/1-3-\345\210\235\350\257\206\346\250\241\345\235\227\347\256\241\347\220\206\345\231\250.md" deleted file mode 100755 index 9562d8c46f9de0ab2082caf97f82f834c2a8881a..0000000000000000000000000000000000000000 --- "a/document/1-3-\345\210\235\350\257\206\346\250\241\345\235\227\347\256\241\347\220\206\345\231\250.md" +++ /dev/null @@ -1,129 +0,0 @@ -#!/bin/owls.wiki.losu.tech - -# 1-3-初识模块管理器 -洛书模块管理器 Lpt(Losu Package Tool),是随洛书安装的模块管理工具,是洛书的重要组成部分, -它包含了常规模块管理器的查找、安装、卸载、升级等基本功能,还提供了文档、配置、克隆、回退等独特功能,LPT存在的意义是为用户提供命令化的高效服务 - - -## 1-3-1-基础知识 - -### 1-3-1-1-环境变量 LPTROOT - -+ LPTROOT是模块管理器工作的根目录。 -+ 在LINUX平台上,它被锁定为 /els 目录,而在windows上,它通常为解释器主程序所在目录,需要在安装解释器时由安装脚本或用户设置 - -### 1-3-1-2-了解 lpt.conf -+ 该文件位于 ```$LPTROOT/lpt.conf```,通常包含以下内容 ```[软件源] [架构]```, 如 ```https://losu.tech/archive/lasted/ Ubuntu``` -+ 其中```https://losu.tech/archive/lasted/```指洛书的官方更新源,ubuntu指当前的二进制架构 -+ 一般地,lpt.conf的内容并不需要被修改,除非您有第三方模块的安装需求或希望指定使用某一版本的软件源 -+ 官方的历史版本源地址一般为```https://losu.tech/archive/[X.x]```, X.x为对应版本的主次版本号,如 24.1 - -## 1-3-2-开始使用 -### 1-3-2-1-了解基本功能 -+ 洛书的模块管理器具有以下基础功能 - + 查找模块与获取基本信息 - + 安装、卸载、升级模块,拓展洛书的功能 - + 版本更新 - + 版本锁定 -+ 接下来,我们将为您介绍如何使用这些功能 -> linux用户注意使用 sudo 进行提权,在完成以下操作前请配置好lpt.conf - -### 1-3-2-2-查找模块与获取信息 -1. 查找模块 - - 您可以使用命令 `losu -r lpt search [关键词]` 查找包含关键词的模块 - -
样例 - - ``` - root@cthree-ThinkpadZ13:~# losu -r lpt search std - /els/remote.list 100%[=================================================================>] 16.81K --.-KB/s 用时 0.03s - stdtime/2.0.0 - stdfile/2.0.0 - stdsys/2.0.0 - stdmath/2.0.0 - stdstring/2.0.0 - stdlib/2.0.0 - stdbyte/2.0.0 - std/2.0.0 - stdthread/2.0.0 - stdvm/2.0.0 - ``` -
- -2. 获取信息 - - 您可以根据查找出的信息,使用 show 命令获取模块的基本信息 - - `losu -r lpt show [模块名]` -
样例 - - ``` - root@cthree-ThinkpadZ13:~# losu -r lpt show std - /els/remote.list 100%[=================================================================>] 16.81K --.-KB/s 用时 0.04s - 模块 std 的相信信息如下 - 名称: std/标准库(IO) - 介绍: 标准库 stdlib 的一部分,基本函数部分 - 版本: 2.0.0 - 模式: const - 二进制分发的分支: - Windows - Ubuntu - 源代码及支持的分支: - Windows: - std.c - makefile - all: - std.els - std.h - Ubuntu: - std.c - makefile - ``` -
- - - -### 1-3-2-3-安装、卸载升级模块 -1. 模块的安装,`losu -r lpt install [模块名]` -2. 模块的卸载,`losu -r lpt remove [模块名]` -3. 模块的升级,`losu -r lpt update`,生成可更新列表,然后`losu -r lpt upgrade`,进行自动化升级 -4. 免交互执行,在lpt 安装与卸载时会有用户交互,如需跳过交互,仅需在命令后补上交互的内容即可,如 `losu -r lpt install y`,但是请注意,跳过交互仅对常规模块的操作有效,当您试图安装一个前瞻版本的模块或修改一个锁定模块时,它不会生效。自动化更新对前瞻版本也不会生效 -5. lpt对 内核、标准库等不起作用,它们在一个版本内属于 const 锁定模块,不允许被改变 - - -### 1-3-2-4-版本更新 -1. 检查更新 `losu -r lpt update`,出现提示,说明当前内核版本与软件源所采用的版本不一致 - -``` -root@cthree-ThinkpadZ13:/home/cthree# losu -r lpt update -/els/remote.list 100%[=================================================================>] 16.81K --.-KB/s 用时 0.03s -[WARN/警告] LPT : 当前内核的版本与软件源版本存在差异: -24.1.0 ——> 24.2.0 -[TRY] 正在尝试下载更新脚本: https://losu.tech/archive/lasted/./.repo/upscript/lsupdate_Ubuntu -/bin/lsupdate 100%[=================================================================>] 410 --.-KB/s 用时 0s -[OK] -[ERROR/错误] LPT: 更新脚本已下载,运行 lsupdate 命令可以完成版本修正,或更换软件源后再运行LPT - -``` -2. 此时,如果想更新内核,需要执行 `lsupdate` 进行更新 -3. 更新后的软件源可能会被重置到 lasted 分支,如果需要使用旧版本的源,需要手动修改 lpt.conf文件 -4. 根据洛书的发布标准,我们强烈建议您安装最新的版本,并定时进行更新操作,这有利于您获取最新的支持、功能并减少bug的困扰 - -### 1-3-2-5-版本回退与锁定 -如果您希望获得 旧版本/稳定版本 的洛书环境,您可以考虑将洛书回退并锁定至旧版本 -+ 如果您有这方面的需求,我们建议将版本锁定到 STS 或 LTS 版本,这通常意味着 - - 固定的内核与运行环境 - - 充分的反馈与已解决的问题 - - 更长期的在线源服务( 3 ~ 12 个月) - -+ 回退与锁定的操作方法 - - 修改 lpt.conf 将软件源改为所需要的软件源 - - 运行 `losu -r lpt update`,下载更新脚本,随后运行 `lsupdate`,切换到指定版本的镜像源 - - 检查 lpt.conf,观察其软件源是否是对应版本的软件源 - - 运行 `losu -r lpt update`,检查需要回退版本的模块以及旧版源中缺失的模块 - - 确认要回退后,运行 `losu -r lpt upgrade`,开始回退所有第三方模块 - - 运行 `losu -r lpt autoremove`,卸载所有已经缺失的模块 - -### 1-3-2-6-其他基础操作 -+ `losu -r lpt help`,获取帮助 -+ `losu -r lpt list`,列出本地安装列表 -+ `losu -r lpt wiki [模块名]`,获取模块的readme.md -+ `losu -r lpt clone [模块名]`,获取模块的仓库工程 diff --git "a/document/2-1-\344\275\240\345\245\275\346\264\233\344\271\246.md" "b/document/2-1-\344\275\240\345\245\275\346\264\233\344\271\246.md" deleted file mode 100755 index 0bc1187e21370901b5fbcd9748d3b6bb6339da99..0000000000000000000000000000000000000000 --- "a/document/2-1-\344\275\240\345\245\275\346\264\233\344\271\246.md" +++ /dev/null @@ -1,118 +0,0 @@ -#!/bin/owls.wiki.losu.tech - -# 前言 -## 致读者 -尊敬的读者: -欢迎来到洛书编程语言的语法教程。洛书编程语言是一种新兴的、富有创新性的编程语言,它致力于让编程更加容易,更加高效。在这个教程中,我们将引导您逐步掌握洛书编程语言的基本语法和核心概念,让您轻松掌握这门强大的编程工具。 - -本教程的目标是帮助您了解洛书编程语言的基本语法规则和编程模式,从而能够编写出正确、有效的代码。我们不仅将为您展示如何使用洛书编程语言进行基本的编程操作,还将分享概念和技巧,以帮助您在编程过程中获得更多的乐趣和成就感。在本教程的编写过程中,我们尽可能地采用了简洁明了的语言,以便于您理解和掌握洛书编程语言。我们还为您准备了一些示例代码,以便于您更好地理解所学内容。 - -本教程的教学环境为 “洛书在线运行平台” ,您可以访问 [https://losu.tech/playground](https://losu.tech/playground) 以前往。 - -最后,请务必遵循洛书编程语言的语法规则和良好的编程习惯,以确保您的代码能够正确地运行。如果您在学习过程中遇到了任何问题或困惑,请随时联系我们,我们将尽力为您提供帮助。 - -祝您学习愉快! - - -## 洛书关键词一览表 -洛书拥有完整的utf-8编码支持,这意味着您可以使用 英文、中文、emoji 等符合进行编程,洛书官方对中文编程功能进行了支持,在此,我们为您奉上洛书中英文关键词一览表 - -|英文|中文| -|--|--| -|import| 引| -| $、var|令| -|null|空| -|and| 且| -|def|方法 -|return| 回| -|or| 或| -|not| 非| -|for| 计次、列举| -|loop| 重复| -|to| 至| -|with| 当| -|break| 跳出| -|return| 回| -|if| 如果| -|elif| 另外| -|else| 否则| -|arg|变参| -|this|此| -|block|代码块| -|class|构造| -|pass|;| - - - -# 2-1-你好,洛书 -## 2-1-1-第一个洛书程序 -打印“hello world”是C语言之后的惯用案例,洛书例子打印的是中文“你好,洛书!” - -### 2-1-1-1-从终端交互开始 -1. 打开终端,输入命令`losu`,Linux 用户推荐使用```rlwrap losu``` -2. 输入 ```print('Hello,World!')```,回车 -3. 输入 ```打印('你好,洛书')```,回车 - -### 2-1-1-2-从文件开始 -创建 `hello.els`,内容如下 - -```python -# 这里是注释 -import 'stdlib' -print("Hello,Losu world!") -``` - -其中 `#`开始的是行注释,`import`函数导入了`stdlib`模块,然后使用其中的`print`函数输出文字 - -那么,使用中文函数的写法如下 -```python -引('stdlib') -打印('你好,洛书编程世界!') -``` - -您可以使用命令 ```losu [文件名]```的方式运行一个洛书程序 - - - - -### 2-1-1-3-洛书在线运行平台 - - - -+ 您可以通过访问[https://losu.tech/playground](https://losu.tech/playground)前往洛书在线运行平台 - -+ 在线运行平台的特点包括 - - 免安装,免配置,点开即用,不用引用模块 - - 纯云端运行,不占用本地资源 - -+ 点击运行图标,即可看到运行效果 - -## 2-1-2-命令行参数 -### 2-1-2-1-查看版本 -+ 使用命令 ```losu -v```查看详细的版本信息,包括构建相关的信息 -+ 使用命令 ```losu -V```查看简略的版本信息 - -### 2-1-2-2-运行模块 -+ 洛书可以通过解释器将模块以程序的形式执行 -+ ```losu -r [名称]``` - -## 2-1-3-工程与模块化(非强制) -## 2-1-3-1-洛书是一门完全模块化设计的编程语言 -洛书采用完全的单位化设计,以模块的形式组织代码,模块可以是一个脚本,也可以是一个预编译的二进制库,洛书发行版自身便是由 `losu_core 内核模块`、`losu 解释器模块`、`stdlib 标准库`与`lpt 模块管理器模块`等模块组合而成 - -## 2-1-3-2-模块管理工具 -洛书包管理工具`Losu Packages Tool`,简称`lpt`,是为洛书设计的一款集 查找、安装、卸载、更新、配置、开发、获取文档等功能于一身的开发工具。其由洛书本身进行实现,具体轻量化、跨平台、易拓展等多种优点。 - -## 2-1-3-3-洛书工程 -+ 洛书拥有一定的工程化机制,可以根据工程实现独立化的运行环境 -+ 一个完整的工程目录包括 -``` -工程/ -|—— main.els # 主脚本 -|—— LICENSE # 版权文件 -|—— lib/ -| |—— xxx.lsd # 依赖的模块 -| |—— ······ -|—— README.MD -``` -+ 洛书的解释器在执行工程时会优先选择工程内部的模块(优先同目录,后lib/)进行执行,在工程内缺失依赖模块时会尝试从本地加载模块,因此,通过这种容器化机制,可以方便地实现各个工程间独立的运行环境。 diff --git "a/document/2-2-\347\250\213\345\272\217\347\273\223\346\236\204.md" "b/document/2-2-\347\250\213\345\272\217\347\273\223\346\236\204.md" deleted file mode 100755 index cdf265fb097c20be2e496fd482c85b9450642e2f..0000000000000000000000000000000000000000 --- "a/document/2-2-\347\250\213\345\272\217\347\273\223\346\236\204.md" +++ /dev/null @@ -1,310 +0,0 @@ -#!/bin/owls.wiki.losu.tech -# 2-程序结构 - -洛书和其他编程语言一样,也是由小型结构组合成一个大型程序。 - -洛书采用精简的设计结构,一切洛书程序都是由 变量、数据与语句构成的,本章会向您介绍 变量与数据的相关信息 - -# 2.1-注释 -洛书支持两种方式对代码进行注释 -## 2.1.1-单行注释 -+ `#`后的一行所有内容都会被视作注释,不产生任何作用 -```python -# 这是单行注释 -``` -## 2.1.2-多行注释 -+ ```"""```或```'''```符号包围的区域内,所有的内容都会被视作注释 -```python -''' -这里是注释~ -多行注释 -''' - -""" -这里也是注释! -""" -``` - -# 2.2-全局变量 -全局变量是在全局作用域中声明的变量,其声明方式为 ```var 变量名``` - -```js -var a -a = "hello" -var b = "losu" -var c,d = "hello","losu" - -``` -全局变量在程序的任何地方都可以使用 —— 哪怕全局变量的声明与使用位于不同的源文件中,只要它们位于同一个虚拟机进程内即可;按照洛书语法规范,您在使用变量前应先对它进行声明,但是全局变量并不要求“先声明再使用”。如果您使用了一个未被声明的变量,它会被放置在全局变量中。 - -``` -在洛书中,所有未被赋值的变量都属于 null(空) 类型,它们不会被GC标记,不会占用运行时内存 -``` - - -# 2.3-局部变量与作用域 -## 2.3.1-局部变量 -+ 局部变量是在局部作用域内被声明的变量 -+ 局部变量的作用域是其所在作用域与其相邻的子作用域 -+ 与全局变量一样,局部变量也是用`var`函数进行的声明 - -## 2.3.2-作用域 -+ 洛书支持利用`block`关键字指定块状作用域 -+ 作用域可以相互嵌套 -+ 每一个作用域的局部对象在离开时会被GC销毁 - -## 2.3.3-样例 -### 2.3.3.1-样例一 -```python -# 在线运行平台无需引用标准库 -# import('stdlib') - -var 😏 = "hello" # 全局变量 😏 -block - # 一个块状作用域 - var 😏 = "hi" # 局部变量 😏 - print(😏) # 优先访问局部变量 -; -print(😏) # 局部变量被销毁,访问全局变量 -``` -![运行效果](./img/2.3.3.1.png) - -### 2.3.3.2-样例二 -```python -# 在线运行平台无需引用标准库 -# import('stdlib') - -var 😏 = "hello" # 全局变量 😏 -block - # 一个块状作用域 - var 😏 = "hi" # 局部变量 😏 - var a = "hee" - print(😏) # 优先访问局部变量 - block - # 再来一个作用域 - print(😏) # 查找作用域,发现局部变量 😏,优先访问 - var a = "heiii" # 查找作用域,发现当前块状作用域的局部变量 a,优先访问 - print(a) - ; - print(a) # 局部 a 被销毁,找到当前的 a -; -print(😏) # 局部变量被销毁,访问全局变量 -``` -![运行效果](./img/2.3.3.2.png) - -#!/bin/owls.wiki.losu.tech -# 2.4-函数与闭包 -洛书的函数本质上是一种`function`类型的变量 -## 2.4.1-函数声明 -函数声明一般以`def`关键字开始,语法如下,可以使用`return`关键词返回数据,如果没有返回值,则默认是`null`类型 - -```python -def 函数名(参数列表): - # 函数体 -; -``` - -如下面的例子 - -```python -方法 ➕(数字1,数字2): - 回 数字1 + 数字2 -; - -🙋(➕(1,3)) - -``` -![2.4.1.1](./img/2.4.1.1.png) - -## 2.4.2-闭包 -洛书支持高阶函数与闭包,与块状作用域不同,函数中的闭包变量应位于全局变量或相邻作用域内 -```python -方法 ➕(数字1,数字2): - var ➕➕ # 声明局部变量 - def ➕➕(): # 这个函数是一个局部变量 - var ➕➕➕ - var 数字1,数字2 = 数字1,数字2 - ''' - 如果注释上一行,会引起报错 - 闭包变量必须是全局变量 或 位于 上一级作用域中 ,变量 数字1 不满足此条件 - ''' - def ➕➕➕(): - 回 数字1 + 数字2 - ; - return ➕➕➕() - ; - - return ➕➕() -; - -🙋(➕(1,3)) -``` -![2.4.2.1](./img/2.4.2.1.png) - -## 2.4.3-函数的覆盖与重写 - -洛书的函数本质是一个变量,因此,您可以在运行时动态修改函数内容 -```python - -方法 ➕(数字1,数字2): - 回 数字1 + 数字2 -; -🙋(➕(1,3)) - -方法 ➕(数字1,数字2): - 回 数字1 - 数字2 -; -🙋(➕(1,3)) - -``` -![2.4.3.1](./img//2.4.3.1.png) - -#!/bin/owls.wiki.losu.tech - -# 2.5-数据类型 -## 2.5.1-洛书数据类型 -洛书包含以下数据类型 -+ 空 null,一切未被赋值、声明的变量都是null -+ 字符串 string -+ 数字 number -+ 函数 function -+ 单元 unit -+ 指针 ptr -+ 字节 byte - -其中,用户可以在脚本层面创建与修改除指针外的所有数据类型,并可在C-脚本接口层面操作指针变量 -您可以使用 type/类型 函数来获取一个变量的数据类型 - -```python -# 在线平台拥有 🔧 函数, 🔧 == type - -🙋(🔧(12.33)) # number -🙋(🔧(🔧)) # type本身是 function -🙋(🔧(🔧())) # type的返回值是string - -``` -![2.5.1.1](./img/2.5.1.1.png) - -## 2.5.2-洛书变量类型的转换 -洛书的字符串与数字支持动态类型转换,同时支持运算符重载(见后续章节),动态转换会改变变量的数据类型 -```python -🍎 = "6" -🙋(🍎) -🙋(🔧(🍎)) -🍎 = 🍎 + 1 -🙋(🍎) -🙋(🔧(🍎)) -``` -![2.5.2.1](./img/2.5.2.1.png) -## 2.5.3-运算符 -### 2.5.3.1-算数运算符 -```python -数字运算(支持重载) + - * / ^ -字符串拼接(支持重载) & -字符串截取 [] # 越界检查返回 '\0' -数组索引 [] -成员访问 . -``` -样例如下 -```python -🍎 = "hello" -🍎 = 🍎 & "洛书" - -🍌 = 1 -🍌 = (🍌+1)^2 - -🙋(🍎) -🙋(🍎[1]) -🙋(🍌) -``` -![2.5.3.1](./img/2.5.3.1.png) -### 2.5.3.2-逻辑运算符 -1. 洛书的运算符返回 null 表示不成立,返回非null 表示逻辑成立 -2. 不同的运算符逻辑成立时返回的值不同 -3. 逻辑运算符及其返回值如下 - -|运算符|成立条件|返回值| -|---|---|---| -|a == b|a与b相等|非null值| -|a != b|a与b不相同|非null值| -|a > b|a大于b,包括a的字符串模式"大于"b|非null值| -|a >= b|类推|非null值| -|a < b|类推|非null值| -|a <= b|类推|非null值| -| a \|\| b |等效于 or 关键词| 返回第一个非null对象的值或null | -|a && b|等效与 and 关键词|返回b,或第一个null对象| -|!a|等效于 not a|返回 非 a| - -运行样例 -```python -if 1=="1": - print("1:\t√") -; - -if 1<2 : print("2:\t√") ; - -if "abc"<"bcd": print("3:\t√") ; - - -print(a or 1) # 1 -a = 1 # a = 1 -print(a or 2) # 1 - - -def func1(): print("func1") return 1 ; -def func2(): print("func2") return null ; -def func3(): print("func3") return 2 ; - -a = func1() and func2() and func3() # 运行到func2时就结束了,不会调用func3 - -``` -![2.5.3.2](./img/2.5.3.2.png) - - - - -# 2.6-匿名函数与可变参数 -## 2.6.1-匿名函数 -上一节介绍了函数值的基本用法,既然函数可被视为值,那么,在洛书中,是否可以像声明基本类型字面量那样,以赋值的方式创建函数变量?答案是可以 -```python -🐶 = def(): - print("汪汪汪") -; - -🐶() -``` -![2.6.1.1](./img/2.6.1.1.png) - -因此您也可以获得这种功能 -```python -def 📢(指定函数): - 指定函数() # 调用指定函数 -; -📢( - def(): - print('hello') - ; -) - -``` -![2.6.1.2](./img/2.6.1.2.png) - -## 2.6.2-可变参数 -洛书支持可变参数列表,您可以通过 arg/变参 数组获取可变参数 -```python -def 🚂(火车名,...): - 🙋(火车名) - for i=1,arg.n : # arg.n代表参数个数,等价于 变参.个数 - 🙋("车厢"&i&"坐着"&变参[i]) - ; -; - -🚂("K100",'Kate',"小明","李华") -``` -![2.6.2.1](./img/2.6.2.1.png) - -``` -在部分模块中,洛书的可变参数机制可能会被关闭,请关注模块文档以获取替代方案 -``` - - diff --git "a/document/2-3-\350\257\255\345\217\245.md" "b/document/2-3-\350\257\255\345\217\245.md" deleted file mode 100755 index 5b2d8ccd24dcb0b20ae514eae65959a713ebf6c5..0000000000000000000000000000000000000000 --- "a/document/2-3-\350\257\255\345\217\245.md" +++ /dev/null @@ -1,193 +0,0 @@ -#!/bin/owls.wiki.losu.tech -# 3-语句 -语句是程序设计中的重要部分,它起到操作程序走向的作用 -洛书的语句主要分为 -+ 循环语句 - - `当 ...` 型循环 - - `直到` 型循环 - - `计次` 型循环 - - `列举` 型循环 -+ 条件语句 - - `if` 如果 型条件语句 - - `elif` 另外 型条件语句 - - `else` 否则 型条件语句 - -本章我们将详细讲解它们 - -# 3.1-循环语句(1) -` with / 当 ` 型循环语句是一种重要的循环语句,它的语法如下 -```python - -with [条件表达式] : - # 语句内容 -; - -当 [条件表达式] : - # 语句内容 -; - -``` - -它会首先判断条件表达式是否成立(即表达式的值不是 null ),如果成立,执行语句内容,然后重复至表达式不成立(值 为 null) - -```python - -🔢 = 1 -with 🔢 <= 10 : - 🙋("你好x"&🔢) - 🔢 = 🔢 + 1 -; - -``` -![3.1.1](./img/3.1.1.png) - - - -# 3.2-循环语句(2) -` loop / 直到 ` 型循环语句是一种重要的循环语句,它的语法如下 -```python - -loop - # 语句内容 -to [条件表达式] - -重复 - # 语句内容 -至 [条件表达式] - -``` - -它会先执行语句内容,判断条件表达式是否成立,如果成立,退出循环,如果不成立,重复前一过程 - -```python - -🔢 = 1 -重复 - 🙋("你好x"&🔢) - 🔢 = 🔢 + 1 -至 🔢>10 - -``` -![3.2.1](./img/3.2.1.png) - - - - -# 3.3-循环语句(3) -` for 列举 ` 型循环语句是一种重要的循环语句,它的语法如下 -```python -for 循环变量 = 起始值,最终值[,每次增加的数] : # []内代表可以省略 - # 循环语句 -; - -计次 循环变量 = 起始值,最终值[,每次增加的数] : # []内代表可以省略 - # 循环语句 -; -``` - -它会逐步进行循环,直到循环变量变为目标值 - -```python -计次 ⏱️ = 1,10 : - 🙋("你好x"&⏱️) -; - -``` -![3.3.1](./img/3.3.1.png) - - -```python -计次 ⏱️ = 1,10,2 : - 🙋("你好x"&⏱️) -; -``` -![3.3.2](./img/3.3.2.png) - - -如果计次条件永远不可能到达,洛书会直接跳过这个语句 -```python -计次 ⏱️ = 1,10,-1 : - 🙋("你好x"&⏱️) -; -🙋('👋') -``` -![3.3.3](./img/3.3.3.png) - -计次循环拥有以下宏变量,用来获取循环体的一些属性 -``` -变量名 作用 -__MAX__ 计次的目标次数 -__STEP__ 每次增加的步幅 - -__极值__ 同 __MAX__ -__步幅__ 同 __STEP__ - -``` - -# 3.4-循环语句(4) -` for 列举 ` 型循环语句是一种重要的循环语句,它的语法如下 -```python -for 脚标,值 =/in 被列举的对象 : - # 循环语句 -; - -列举 脚标,值 =/in 被列举的对象 : - # 循环语句 -; -``` - -它会列举对象的每一个值,如果对象不存在,会引起报错 -```python -列举 姓名,年龄 = { - 小红 = 14, - 李华 = 15, - 小张 = 11, - } : - 打印(姓名,":",年龄) -; -``` -![3.4.1](./img/3.4.1.png) - -```python -students = { - Kate = 12, - Tom = 10, - Jack = 15, -} -for name,age in students: - print(name,":",age) -; -``` -![3.4.2](./img/3.4.2.png) - - -前文所讲的所有的循环语句,都可以使用 break 关键字提前跳出 - -# 3.5-条件语句 -条件语句的语法如下,[]号内代表可以省略 -```python -如果 条件1 : - # 满足条件1,执行语句1 -[另外 条件2:] - # 不满足条件1,满足条件2 执行语句2 -[另外 条件3:] - # 不满足条件1与条件2,满足条件3 执行语句3 -# 类推······ -否则 - # 不满足前面所有条件 -; - -``` - -以一个计算绝对值的程序为例 -```python -🔢 = 12.23 - -# 🔢 = -12.23 # 换个负数试试? - -如果 🔢<0 : - 🔢 = - 🔢 -; -🙋(🔢) -``` -![3.5.1](./img/3.5.1.png) \ No newline at end of file diff --git "a/document/2-4-\346\225\260\347\273\204.md" "b/document/2-4-\346\225\260\347\273\204.md" deleted file mode 100755 index 593c6888f14e015f684a38b0fb2cf12b59467974..0000000000000000000000000000000000000000 --- "a/document/2-4-\346\225\260\347\273\204.md" +++ /dev/null @@ -1,65 +0,0 @@ -#!/bin/owls.wiki.losu.tech -# 4-数组 -## 4.1-数组的模型 -数组是一种特殊类型的变量,数组可以抽象为内存中的一段连续地址 -## 4.2-数组的创建与使用 -```python -# 声明一个空数组 -🚂 = {} -# 声明一个带初始值的数组 -🚅 = {"小明","李华","小军","小红"} # 洛书的数组编号默认从 1 开始 - -🙋(🚅[1],🚅[2],🚅[3],🚅[4]) - -``` -![4.2.1](./img/4.2.1.png) - -您可以修改数组指定位置的内容 -```python -🚂 = {} -🚂[1]=2 -🚂[ 🚂[1] ]=3 -🙋(🚂[1],🚂[2]) - -``` -![4.2.2](./img/4.2.2.png) - -数组的本质是一段内存地址,修改数组中的内容本质是修改内存中对应的内容 -```python -🦸 = {"诸葛亮","后羿","小乔","钟馗","马超"} -🏆 = 🦸 -🏆[1]="赵怀真" # 修改的是内存中的内容 🦸[1] 会随之改变 -🙋(🦸[1]) -``` -![4.2.3](./img/4.2.3.png) - -## 4.3-数组的销毁 -与销毁所有变量一样,直接赋值为 null,需要注意的是,一个变量名赋值为null并不会引起数组中内容的回收,只有在一个数组所有的变量名都被赋值null时,垃圾回收器才会回收这处空间 - -``` -很像伏地魔的魂器,每一个变量名只是一个魂器,只有摧毁全部魂器才能干掉他 -``` - -```python -🎩={1,2,3,4} -🧹 = 🎩 - -🎩 = null -🙋(🎩[1]) # 啥也不输出,因为 🎩 被干掉了 -🙋(🧹[1]) - -``` -![4.3.1](./img/4.3.1.png) - -## 4.4-特殊用法 -洛书的数组脚标不局限于数字,也可以是其他数据类型 -```python -🧙‍♀️={} -🧙‍♀️["🎩"]="女巫的帽子" -🧙‍♀️["🧹"]="女巫的飞天扫把" -🧙‍♀️["💬"]=🙋 - -🧙‍♀️["💬"](🧙‍♀️["🎩"],🧙‍♀️["🧹"]) - -``` -![4.4.1](./img/4.4.1.png) \ No newline at end of file diff --git "a/document/2-5-\345\257\271\350\261\241.md" "b/document/2-5-\345\257\271\350\261\241.md" deleted file mode 100755 index 87022fe5c28467491c650155af7d7710d6a7d12a..0000000000000000000000000000000000000000 --- "a/document/2-5-\345\257\271\350\261\241.md" +++ /dev/null @@ -1,135 +0,0 @@ -#!/bin/owls.wiki.losu.tech -# 5-对象 -## 5.1-对象的模型 -对象的本质与数组一样,也是一段特殊的内存地址,对象由属性与行为组成 -## 5.2-对象的创建与使用 -```python -# 创建一个空对象,并设置属性 -🐺 = {} -🐺.🔈 = "嗷呜" - -# 另一种创建方式 -🐶 = { - 🔈 = "汪汪", -} - -🙋("🐶:",🐶.🔈) -🙋("🐺:",🐺.🔈) - -``` -![5.2.1](./img/5.2.1.png) - -## 5.3-成员函数与this指针 -成员函数决定了一个对象的行为,当我们声明/调用成员函数时,洛书会为其添加指向当前对象的this指针 - -```python -🐺 = {} -🐺.💬 = "嗷呜" -def 🐺.🔈(): - # this == 🐺 - 🙋(this.💬) -; - -🐺.🔈() - -``` -![5.3.1](./img/5.3.1.png) - -## 5.4-匿名函数与this指针 -当成员函数被隐式调用,或者以匿名函数的形式被赋值时,洛书不会自动处理this指针,需要用户手动处理 - -```python -🐺 = {} -🐺.💬 = "嗷呜" -🐺.🔈=def(this): # 匿名函数 - # this == 🐺 - 🙋(this.💬) -; -🐕 = 🐺.🔈 - -🐺.🔈() # 显式调用,自动传this -🐕(🐺) # 隐式调用,手动传this -``` -![5.4.1](./img/5.4.1.png) - -## 5.5-用函数生成对象 -我们可以将利用函数,动态地生成不同对象,实现面向对象编程 - -```python -def 🐕(💬): - var tmp={} # 创建一个局部变量,代表一个空对象 - tmp.💬 = 💬 # 设定属性 - def tmp.🔈(): - 🙋(this.💬) # 设定行为 - ; - return tmp # 将这个对象作为返回值返回 -; - -# 生成对象 -🐶,🐺 = 🐕("🐶:\t汪汪"),🐕("🐺:\t嗷呜") - -🐶.🔈() -🐺.🔈() - -``` -![5.5.1](./img/5.5.1.png) - -## 5.6 对象与数组 -对象与数组是unit类型的两种表现形式,其在一定程度上可以通用,`对象.属性`与`对象["属性"]`会访问同一片内存地址 - -```python -🐺 = {} -🐺.💬 = "嗷呜" -🙋(🐺['💬']) -``` -![5.6.1](./img/5.6.1.png) - -虽然洛书允许在运行时将对象与数组进行通用,但是,在声明时是不可以混合声明的,比如下面的写法就是一个错误的样例 -```python -🐺 = { - 1,2,3 - 💬 = "汪汪" -} -``` -![5.6.2](./img/5.6.2.png) - -## 5.7-嵌套对象 -对象中的某一属性也可以是对象,在这种情况下,我们称之为嵌套对象。 -```python -方法 🌏(🧬): - 令 🗒️ - 如果 🧬 == "狗": - def 🗒️(💬): - var tmp = {} - tmp.💬=💬 - def tmp.🔈(): - 🙋(this.💬) - ; - return tmp - ; - 另外 🧬 == "鱼" : - def 🗒️(💬): - var tmp = {} - tmp.💬=💬 - def tmp.🫧(): - 🙋(this.💬) - ; - return tmp - ; - ; - 回 🗒️ -; -令 狗狗,小鱼 = 🌏("狗"),🌏("鱼") -# 狗狗 和 小鱼 是两个函数,它们可以创建具体的对象 - - -🐶 = 狗狗("汪汪") -🐟 = 小鱼('bulubulu') - -🐶.🔈() -🐟.🫧() - -``` - -![5.7.1](./img/5.7.1.png) - diff --git "a/document/2-6-\350\277\220\347\256\227\347\254\246\351\207\215\350\275\275.md" "b/document/2-6-\350\277\220\347\256\227\347\254\246\351\207\215\350\275\275.md" deleted file mode 100755 index 2096c389f0e23948240b92dd4e43789b596bf90a..0000000000000000000000000000000000000000 --- "a/document/2-6-\350\277\220\347\256\227\347\254\246\351\207\215\350\275\275.md" +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/owls.wiki.losu.tech -# 6-运算符重载 -让我假设一种场景,我们有两个学生对象,他们有一个共同的属性 年龄,我们想对他们的年龄求和,通常,我们可以这样写 -```python -def 🏫(姓名,年龄): - var this = {} - this.姓名 = 姓名 - this.年龄 = 年龄 - 回 this -; -👦 = 🏫("小明",12) -👩‍🦰 = 🏫("小红",16) -🙋((👦.年龄+👩‍🦰.年龄)) - -``` - -我们可以采用更简单的方式 - -```python -def 🏫(姓名,年龄): - var this = {} - this.姓名 = 姓名 - this.年龄 = 年龄 - this["::+"] = def(参数1,参数2): - 回 (参数1.年龄 或 参数1) + (参数2.年龄 或 参数2) - ; - 回 this -; - -👦 = 🏫("小明",12) -👩‍🦰 = 🏫("小红",16) -🙋(👦 + 👩‍🦰) -🙋(👦 + 10) -``` - -![6.1](./img/6.1.png) - -洛书支持重载的运算符有```+ - * / ^ & ``` \ No newline at end of file diff --git "a/document/2-7-\346\236\204\351\200\240\345\207\275\346\225\260.md" "b/document/2-7-\346\236\204\351\200\240\345\207\275\346\225\260.md" deleted file mode 100755 index 36cdd8fbd633e1664bfdb4fdf1d7af52dfb2c1ce..0000000000000000000000000000000000000000 --- "a/document/2-7-\346\236\204\351\200\240\345\207\275\346\225\260.md" +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/owls.wiki.losu.tech -# 7- 构造函数语法糖 - -+ 洛书支持构造函数语法,通过内核函数 new 创建对象 - -```python -Student = {} -def Student.class(name,age): - # 构造函数,显示声明,默认传递 this 指针,等同于 Student.class = def(this,name,age): ... ; - return { - name = name, - age = age, - sayhello = Student.sayhello, - } -; -def Student.sayhello(): - print("Hello,I'm ",this.name,",",this.age) -; - -s = new(Student,'ccc',18) # 语法糖,如果被调用对象是一个unit,自动尝试调用 .class 成员,传递this指针指向 Student -s.sayhello() -``` - diff --git "a/document/2-8-\350\275\254\344\271\211\345\255\227\347\254\246.md" "b/document/2-8-\350\275\254\344\271\211\345\255\227\347\254\246.md" deleted file mode 100755 index 25880db1b054608b861a93b46b455381e425ec09..0000000000000000000000000000000000000000 --- "a/document/2-8-\350\275\254\344\271\211\345\255\227\347\254\246.md" +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/owls.wiki.losu.tech -# 8-转义字符 -## 什么是转义字符? -+ 转义字符(Escape Character)是指在ASCII码和Unicode等字符集中的无法被键盘录入的字符、被当作特殊用途而需要转换回它原来的意义的字符。而转义字符的转义是指字符已经被转换了意义。 -+ 和其他主流编程语言一样,洛书也支持使用转义字符 -## 以'\\'为标志的转义字符 -+ 洛书支持以'\\'为标志的转义字符,该类转义字符遵循以下规则 - 1. '\\' + 关键字母,其含义与C语言中相同,包括: - - |表达式| - |----| - |\\a| - |\\b| - |\\f| - |\\f| - |\\n| - |\\r| - |\\t| - |\\v| - 2. '\\' + 十进制数字(0~255),表示相应ASCII码的字符 - 3. '\\' + 其他字符,相当于字符本身 - -## 以 '%' 为标志的转义字符 -+ 洛书支持以'\\'为标志的转义字符,该类转义字符遵循以下规则: - - 遵循 '%'+ 两位16进制数字组成,表示相应 ASCII 码的字符 - - -## 样例 -```python -print("hello\nworld") -print('hello') -print('%68%65%6c%6c%6F') -print('\104\101\108\108\111') -``` \ No newline at end of file diff --git "a/document/3-1-\346\250\241\345\235\227\345\214\226\344\270\216\345\267\245\347\250\213\347\256\241\347\220\206.md" "b/document/3-1-\346\250\241\345\235\227\345\214\226\344\270\216\345\267\245\347\250\213\347\256\241\347\220\206.md" deleted file mode 100755 index 230b662566e62a259f0842e915fd7fd7e7bb4d25..0000000000000000000000000000000000000000 --- "a/document/3-1-\346\250\241\345\235\227\345\214\226\344\270\216\345\267\245\347\250\213\347\256\241\347\220\206.md" +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/owls.wiki.losu.tech - -# 3-1-模块化与工程管理 -## 3-1-1-洛书是一门完全模块化的编程语言 -+ 洛书是一门完全模块化的编程语言,这是指 - - 洛书的包括标准库在内的功能,全部以模块的形式向内核提供 - - 洛书的模块可以被自由的增删替换而不影响内核功能 - - 洛书的内核本质也是一个模块,也可以被替换为不同版本的实现 - - 洛书的所有模块遵循同一套模块管理机制,可以使用相关工具进行统一管理 -+ 完全模块化机制是洛书的一大特色,通过这种机制,洛书可以实现: - - 轻松的功能裁剪与拓展 - - 快速的跨平台移植与适配 - - 自动化构建与更新 - - 统一的拓展标准与模块生态 - - 良好的跨版本兼容性 - -## 3-1-2-洛书的工程管理 -### 3-1-2-1-洛书的项目工程 -+ 洛书是以纯文本形式存在的脚本语言,它在运行过程中不会产生临时文件 -+ 您可以像使用其他脚本一样使用洛书脚本编写软件 -+ 你可以使用 git 等版本管理工具 -### 3-1-2-2-洛书的模块工程 -+ 一个完整的洛书的模块工程包括: - + 模块信息文件 `info` - + 模块的脚本文件 `xxx.els` - + 模块的实现(C/C++) `xxx.c/xxx.cpp` - + 模块的胶水接口头文件 `xxx.h` - + 构建脚本或 makefile - + 洛书模块工程可以: - + 构建出目标文件 - + 贡献到软件源 - + 从而实现: - - 拓展洛书的功能 - - 丰富洛书的模块生态 - -+ 一个精简的洛书模块工程包括: - + 模块的脚本文件 - + 模块的实现 - + 模块的胶水接口头文件 - diff --git "a/document/3-2-\346\250\241\345\235\227\347\256\241\347\220\206\345\231\250\347\232\204\350\277\233\351\230\266.md" "b/document/3-2-\346\250\241\345\235\227\347\256\241\347\220\206\345\231\250\347\232\204\350\277\233\351\230\266.md" deleted file mode 100755 index 1baec431018a58c6034e6d84a567e617dd4076af..0000000000000000000000000000000000000000 --- "a/document/3-2-\346\250\241\345\235\227\347\256\241\347\220\206\345\231\250\347\232\204\350\277\233\351\230\266.md" +++ /dev/null @@ -1,155 +0,0 @@ -#!/bin/owls.wiki.losu.tech - -# 3-2-模块管理器的进阶 -## 3-2-1-获取模块源码 -### 3-2-1-1-获取精简的源码 -+ 本方法适合获取模块的精简工程,方便对模块进行快速的移植与修改 -1. 在工作目录打开终端 -2. 输入命令 `losu -r lpt source [模块] [平台]`获取指定平台的源码 -3. 如果平台未被指定,则默认下载当前平台的代码 -``` -root@cthree-ThinkpadZ13:~# losu -r lpt source std Ubuntu -/els/remote.list 100%[==============================================================================================>] 16.81K --.-KB/s 用时 0.03s -找到了以下结果 -名称: std/标准库(IO) -介绍: 标准库 stdlib 的一部分,基本函数部分 -版本: 2.0.0 -[TRY] https://losu.tech/archive/lasted/std/Ubuntu/std.c -std/std.c 100%[==============================================================================================>] 2.77K --.-KB/s 用时 0s -[OK] -[TRY] https://losu.tech/archive/lasted/std/Ubuntu/makefile -std/makefile 100%[==============================================================================================>] 229 --.-KB/s 用时 0s -[OK] -[TRY] https://losu.tech/archive/lasted/std/std.els -std/std.els 100%[==============================================================================================>] 1.13K --.-KB/s 用时 0s -[OK] -[TRY] https://losu.tech/archive/lasted/std/std.h -std/std.h 100%[==============================================================================================>] 3.11K --.-KB/s 用时 0s -[OK] -下载完成 -root@cthree-ThinkpadZ13:~# ls std -R -std: -makefile std.c std.els std.h -``` -### 3-2-1-2-克隆完整代码 -+ 本方法会克隆完整的模块工程,包括info信息文件等内容 -1. 在工作目录打开终端 -2. 输入命令 `losu -r lpt clone [模块名]` -``` -root@cthree-ThinkpadZ13:~# losu -r lpt clone std -/els/remote.list 100%[==============================================================================================>] 16.81K --.-KB/s 用时 0.03s -找到了以下结果 -名称: std/标准库(IO) -介绍: 标准库 stdlib 的一部分,基本函数部分 -版本: 2.0.0 -[TRY] info -std/info 100%[==============================================================================================>] 606 --.-KB/s 用时 0s -[OK] -[TRY] https://losu.tech/archive/lasted/std/std.els -std/std.els 100%[==============================================================================================>] 1.13K --.-KB/s 用时 0s -[OK] -[TRY] https://losu.tech/archive/lasted/std/std.h -std/std.h 100%[==============================================================================================>] 3.11K --.-KB/s 用时 0s -[OK] -[TRY] https://losu.tech/archive/lasted/std/Windows/std.c -std/Windows/std.c 100%[==============================================================================================>] 3.04K --.-KB/s 用时 0s -[OK] -[TRY] https://losu.tech/archive/lasted/std/Windows/makefile -std/Windows/makefile 100%[==============================================================================================>] 306 --.-KB/s 用时 0s -[OK] -[TRY] https://losu.tech/archive/lasted/std/Ubuntu/std.c -std/Ubuntu/std.c 100%[==============================================================================================>] 2.77K --.-KB/s 用时 0s -[OK] -[TRY] https://losu.tech/archive/lasted/std/Ubuntu/makefile -std/Ubuntu/makefile 100%[==============================================================================================>] 229 --.-KB/s 用时 0s -[OK] -克隆完成 -root@cthree-ThinkpadZ13:~# ls -R std -std: -info std.els std.h Ubuntu Windows - -std/Ubuntu: -makefile std.c - -std/Windows: -makefile std.c -root@cthree-ThinkpadZ13:~# -``` - -## 3-2-2-胶水代码生成 -+ lpt 提供了根据脚本生产 C 头文件的功能,方便在模块制作时根据脚本层的信息,快速生成C/C++接口 -+ 如此一来,模块开发者便可专注于模块的 C/C++ 实现,而无需考虑如何将其对接到洛书脚本 -### 3-2-2-1-为单独的脚本文件生成胶水代码 -1. 编写要配置的脚本文件 - -
参考样例 - -```python -''' -文件必须遵循以下格式规范 - 1. 结尾留出至少一行空行 - 2. 所有的 C-洛书 API函数声明写在 #!declare ... #!end 段中,没有则不填 - 3. 封装脚本写在 #!script ... #!end 段中,没有则不填 - 4. 中文封装层写在 #!script-cn ... #!end 段中,没有则不填,中文封装段的代码可以在编译时通过宏将其屏蔽 -下面是洛书标准库中时间模块部分的脚本文件 stdtime.els -''' -#!declare -stdtime_getyear():int '获取年' -stdtime_getmon():int '获取月' -stdtime_getday():int '获取日' -stdtime_gethour():int '获取时' -stdtime_getmin():int '获取分' -stdtime_getsec():int '获取秒' -stdtime_getdate():int '获取周几' -stdtime_clock():int '获取计时器程序从运行开始的毫秒计时' -#!end - -#!script - -# time 结构类 -time = { - year = stdtime_getyear, - mon = stdtime_getmon, - day = stdtime_getday, - hour = stdtime_gethour, - min = stdtime_getmin, - sec = stdtime_getsec, - date = stdtime_getdate, - clock = stdtime_clock, -} -#!end -#!script-cn -时间 = { - 年 = stdtime_getyear, - 月 = stdtime_getmon, - 日 = stdtime_getday, - 时 = stdtime_gethour, - 分 = stdtime_getmin, - 秒 = stdtime_getsec, - 周几 = stdtime_getdate, - 计时 = stdtime_clock, -} -#!end - -``` - -
- -2. 运行 `losu -r lpt confsrc [文件名(不包括拓展名)]`,如为 stdtime.els 生成,就为 `losu -r lpt confsc stdtime` -### 3-2-2-2-为多个文件生成胶水代码 -1. 编写各个脚本文件 -2. 编写工程集合文件 -```python -''' -文件名 : 任意 例如 pro.txt -格式规范 - 1. 采用洛书脚本编写一个 project 对象 - 2. 成员为各个要配置的模块文件名,值 为路径(不包括拓展名) -''' -project = { - stdtime = "stdtime", -} - -``` -3. 运行 `losu -r lpt confpro [集合文件全名]` -# \ No newline at end of file diff --git "a/document/3-3-\345\210\233\345\273\272\344\270\200\344\270\252\346\250\241\345\235\227\345\267\245\347\250\213.md" "b/document/3-3-\345\210\233\345\273\272\344\270\200\344\270\252\346\250\241\345\235\227\345\267\245\347\250\213.md" deleted file mode 100755 index 396931ffd904f35ba8ec0f8c5788944c9073d033..0000000000000000000000000000000000000000 --- "a/document/3-3-\345\210\233\345\273\272\344\270\200\344\270\252\346\250\241\345\235\227\345\267\245\347\250\213.md" +++ /dev/null @@ -1,93 +0,0 @@ -#!/bin/owls.wiki.losu.tech - -# 3-3-创建一个模块工程 -+ 本文将以 stdtime 模块为例,详细讲解怎么创建一个洛书模块工程、完成模块实现、构建出二进制的全过程 -## 3-3-1-编写接口 -### 3-3-1-1-直接编写 C/C++ 接口 -+ 此方法需要掌握洛书 API 的详细加载机制,了解内核相关部分的工作原理,难度高,操作复杂,不推荐采用 -### 3-3-1-2-通过 lpt 生成 接口 -#### 3-3-1-2-1-编写 stdtime.els -+ 同 3-2 例,详情略 -#### 3-3-1-2-2-生成接口 -+ `losu -r lpt confscr stdtime`,大致生成以下文件 -```C -// stdime.h -#include "els.h" -int ELSAPI_stdtime_stdtime_getyear(els_VmObj* vm); // stdtime_getyear():int '获取年' -int ELSAPI_stdtime_stdtime_getmon(els_VmObj* vm); // stdtime_getmon():int '获取月' -int ELSAPI_stdtime_stdtime_getday(els_VmObj* vm); // stdtime_getday():int '获取日' -int ELSAPI_stdtime_stdtime_gethour(els_VmObj* vm); // stdtime_gethour():int '获取时' -int ELSAPI_stdtime_stdtime_getmin(els_VmObj* vm); // stdtime_getmin():int '获取分' -int ELSAPI_stdtime_stdtime_getsec(els_VmObj* vm); // stdtime_getsec():int '获取秒' -int ELSAPI_stdtime_stdtime_getdate(els_VmObj* vm); // stdtime_getdate():int '获取周几' -int ELSAPI_stdtime_stdtime_clock(els_VmObj* vm); // stdtime_clock():int '获取计时器程序从运行开始的毫秒计时' -#ifdef ELS_CONF_TOKEN_EN -static const char LibScript[]={ -10, -35,32,116,105,109,101,32,-25,-69,-109,-26,-98,-124,-25,-79,-69,10, -116,105,109,101,32,61,32,123,10, -32,32,32,32,121,101,97,114,32,61,32,115,116,100,116,105,109,101,95,103,101,116,121,101,97,114,44,10, -32,32,32,32,109,111,110,32,32,61,32,115,116,100,116,105,109,101,95,103,101,116,109,111,110,44,10, -32,32,32,32,100,97,121,32,32,61,32,115,116,100,116,105,109,101,95,103,101,116,100,97,121,44,10, -32,32,32,32,104,111,117,114,32,61,32,115,116,100,116,105,109,101,95,103,101,116,104,111,117,114,44,10, -32,32,32,32,109,105,110,32,32,61,32,115,116,100,116,105,109,101,95,103,101,116,109,105,110,44,10, -32,32,32,32,115,101,99,32,32,61,32,115,116,100,116,105,109,101,95,103,101,116,115,101,99,44,10, -32,32,32,32,100,97,116,101,32,61,32,115,116,100,116,105,109,101,95,103,101,116,100,97,116,101,44,10, -32,32,32,32,99,108,111,99,107,32,32,32,61,32,115,116,100,116,105,109,101,95,99,108,111,99,107,44,10, -125,10, -0}; -#endif -#ifdef ELS_CONF_TOKEN_CN -static const char LibScript_cn[]={ --26,-105,-74,-23,-105,-76,32,61,32,123,10, -32,32,32,32,-27,-71,-76,32,32,32,61,32,115,116,100,116,105,109,101,95,103,101,116,121,101,97,114,44,10, -32,32,32,32,-26,-100,-120,32,32,32,61,32,115,116,100,116,105,109,101,95,103,101,116,109,111,110,44,10, -32,32,32,32,-26,-105,-91,32,32,32,61,32,115,116,100,116,105,109,101,95,103,101,116,100,97,121,44,10, -32,32,32,32,-26,-105,-74,32,32,32,61,32,115,116,100,116,105,109,101,95,103,101,116,104,111,117,114,44,10, -32,32,32,32,-27,-120,-122,32,32,32,61,32,115,116,100,116,105,109,101,95,103,101,116,109,105,110,44,10, -32,32,32,32,-25,-89,-110,32,32,32,61,32,115,116,100,116,105,109,101,95,103,101,116,115,101,99,44,10, -32,32,32,32,-27,-111,-88,-27,-121,-96,32,61,32,115,116,100,116,105,109,101,95,103,101,116,100,97,116,101,44,10, -32,32,32,32,-24,-82,-95,-26,-105,-74,32,61,32,115,116,100,116,105,109,101,95,99,108,111,99,107,44,10, -125,10, -0}; -#endif -void ElsLib_stdtime_libinit(els_VmObj *vm){ - vm_register(vm,"stdtime_getyear",ELSAPI_stdtime_stdtime_getyear); - vm_register(vm,"stdtime_clock",ELSAPI_stdtime_stdtime_clock); - vm_register(vm,"stdtime_getday",ELSAPI_stdtime_stdtime_getday); - vm_register(vm,"stdtime_getdate",ELSAPI_stdtime_stdtime_getdate); - vm_register(vm,"stdtime_gethour",ELSAPI_stdtime_stdtime_gethour); - vm_register(vm,"stdtime_getmin",ELSAPI_stdtime_stdtime_getmin); - vm_register(vm,"stdtime_getsec",ELSAPI_stdtime_stdtime_getsec); - vm_register(vm,"stdtime_getmon",ELSAPI_stdtime_stdtime_getmon); - #ifdef ELS_CONF_TOKEN_EN - vm_dostring(vm,LibScript); - #endif - #ifdef ELS_CONF_TOKEN_CN - vm_dostring(vm,LibScript_cn); - #endif -}; - -``` - -## 3-3-2-编写C/C++实现 -+ 找到接口文件的头部声明,将这些函数在 stdtime.c 中逐个实现 -```C++ -int ELSAPI_stdtime_stdtime_getyear(els_VmObj* vm); // stdtime_getyear():int '获取年' -int ELSAPI_stdtime_stdtime_getmon(els_VmObj* vm); // stdtime_getmon():int '获取月' -int ELSAPI_stdtime_stdtime_getday(els_VmObj* vm); // stdtime_getday():int '获取日' -int ELSAPI_stdtime_stdtime_gethour(els_VmObj* vm); // stdtime_gethour():int '获取时' -int ELSAPI_stdtime_stdtime_getmin(els_VmObj* vm); // stdtime_getmin():int '获取分' -int ELSAPI_stdtime_stdtime_getsec(els_VmObj* vm); // stdtime_getsec():int '获取秒' -int ELSAPI_stdtime_stdtime_getdate(els_VmObj* vm); // stdtime_getdate():int '获取周几' -int ELSAPI_stdtime_stdtime_clock(els_VmObj* vm); // stdtime_clock():int '获取计时器程序从运行开始的毫秒计时' -``` -## 3-3-3-编写编译脚本 -+ 我们建议采用 makefile,并且将依赖的 els.h 等头文件放在 ../buildenv目录下 -+ 您可以使用 lpt 获取 losu_core的源码,从而获取这些头文件 - -## 3-3-4-构建 -+ 运行脚本,编译出二进制 -+ 洛书模块的命名标准是 `ElsLib_[模块名].lsd` -+ 当模块被加载时调用其中的`ElsLib_[模块名]_libinit`进行环境初始化 - diff --git "a/document/3-4-\346\250\241\345\235\227\345\267\245\345\205\267\347\232\204\344\275\277\347\224\250.md" "b/document/3-4-\346\250\241\345\235\227\345\267\245\345\205\267\347\232\204\344\275\277\347\224\250.md" deleted file mode 100755 index 8cf9f229705cfc3f7f2615d7adc2a25219ae79e3..0000000000000000000000000000000000000000 --- "a/document/3-4-\346\250\241\345\235\227\345\267\245\345\205\267\347\232\204\344\275\277\347\224\250.md" +++ /dev/null @@ -1,92 +0,0 @@ -#!/bin/owls.wiki.losu.tech - -# 3-4-模块工具的使用 -## 3-4-1-了解 LPKG -+ LPKG 是洛书的开发者模块工具,适合开发者完成对模块的开发、管理、分支、构建等操作 -+ 运行要求: Linux或MinGW 环境,正确安装洛书并可用 -+ 安装: 使用 Lpt 一键安装 `losu -r lpt install lpkg` - -## 3-4-2-使用 LPKG -### 3-4-2-1-编写 info 文件 -+ info 信息文件是模块工程的核心文件,也是LPKG等工具工作的重要依据,其遵循洛书语法,包含以下内容 -```python -{ - type = "模块类型" - # 可选 - # const-锁定,不能被 lpt 更改,只能随版本更新而更新 - # normal-常规,常规模块 - # pre-预览,预览版本模块,在安装前会强制确认操作,不能由自动升级安装 - info={ - name = "模块名", - text = "一句话简介", - version = "版本号", - #name = "document/文档", - #text = "洛书的文档手册,从入门到入坑", - #version = "2.0.0", - }, - source = { # 源码列表 - all = { - # 通用平台源码 - }, - # 各个分支的源码列表 - # Ubuntu = {}, ... - }, - target = { # 各个分支的构建脚本 - - } -} -``` -+ 下面是一个样例,您也可以通过洛书在线服务下载模块的info文件 -```Python -# 标准库 std 模块的 info -{ - type = "const", - info={ - name="std/标准库(IO)", - text="标准库 stdlib 的一部分,基本函数部分", - version = "2.0.0", - }, - source={ - all = { - "std.els", - "std.h", - }, - Ubuntu = { - "std.c", - "makefile", - }, - Windows = { - "std.c", - "makefile", - } - }, - target={ - Ubuntu = "make ; cp ElsLib_std.lsd target/ElsLib_std.lsd_Ubuntu ; make clean", - Windows = "make ; cp ElsLib_std.lsd target/ElsLib_std.lsd_Windows ; make clean", - }, -} -``` - -### 3-4-2-2-检出分支代码 -+ `losu -r lpkg checkout [分支名]` -+ 根据 info 文件,将分支文件夹中的代码复制到工作目录下 - -### 3-4-2-3-合并分支代码 -+ `losu -r lpkg commit [分支名]` -+ 根据 info 文件,将工作目录下的代码同步到分支文件夹下 - -### 3-4-2-4-清理工作区 -+ `losu -r lpkg clean` -+ 清空工作区中的分支代码,仅保存通用分支的源代码,方便进行其他操作 - -### 3-4-2-5-构建二进制 -+ `losu -r lpkg make` -+ 根据 target 对象,构建模块的二进制文件,并将其放到 target 目录中 - -### 3-4-2-6-MD5计算 -+ `losu -r lpkg md5sum` -+ 根据 info 文件,计算所有已合并的代码MD5 - -### 3-4-2-7-MD5检验 -+ `losu -r lpkg md5check` -+ 检查所有已合并文件的MD5值 \ No newline at end of file diff --git "a/document/4-2-\345\206\205\346\240\270\347\232\204\347\247\273\346\244\215.md" "b/document/4-2-\345\206\205\346\240\270\347\232\204\347\247\273\346\244\215.md" deleted file mode 100755 index fbab6319022e59c8930f98d774525c971916a720..0000000000000000000000000000000000000000 --- "a/document/4-2-\345\206\205\346\240\270\347\232\204\347\247\273\346\244\215.md" +++ /dev/null @@ -1,83 +0,0 @@ -#!/bin/owls.wiki.losu.tech - -# 4-2-内核的移植 -## 4-2-1-内核代码的组成 -+ 洛书的内核是由100%的C语言代码组成,且 - - 除LibC外,无任何第三方依赖 - - -std = c99 - - 可由宏开关进行裁剪 - - 包含适合Windows GBK-UTF8 兼容转换层 - -## 4-2-2-内核移植所需的工作 -### 4-2-2-1-宏定义开关 -```C++ -#ifdef ELS_CONF_OS_LINUX // 平台 总定义宏 - #ifndef LOSU_LINUX // 旧版本兼容 宏 - #define LOSU_LINUX 1 - #endif - #define ELS_CONF_TOKEN_CN 1 // 中文关键词开关 - #define ELS_CONF_TOKEN_EN 1 // 英文关键词开关 - #define ELS_CONF_LIBAPI_DL 1 // 模块加载方式设定为 DL , Windows 平台可设为 ELS_CONF_LIBAPI_WIN32 - #define ELS_CONF_LIBAPI_ELF 1 // 开启内置模块开关 - #define ELS_CONF_GC_ENABLE 1 // 设置 GC 为可用 - #define ELS_VM_STACK_SIZE 1024 // 虚拟机运行时栈大小 - #define ELS_BUFF_TMP_SIZE 1024*1024 // 字符串缓冲区大小 - #define ELS_VMIO_SIZE 64 // IO缓冲区大小 - #define ELS_HEAPMEM_REALLOC realloc // 内存管理函数 - #define ELS_HEAPMEM_FREE free -#endif - -``` - -+ 在内核源代码中,已经写好了 Windows、Linux、EmbeddedOs(裸机、Iot、RTOS等)这三种平台的样例,您仅需参照下面的介绍进行定制化修改即可 -### 4-2-2-2-中英文关键词开关 - -+ `ELS_CONF_TOKEN_CN `与`ELS_CONF_TOKEN_EN` -+ 可以选择关闭 `ELS_CONF_TOKEN_CN` 或 `ELS_CONF_TOKEN_EN` 宏,剔除相应语言的关键词,获得更精简的内核 -+ 至少应该保留一个宏以免出现不可用的内核 - -### 4-2-2-3-垃圾回收器 -+ 洛书拥有良好基于 标记-清除 算法的 垃圾回收器,可以最大限度上规避脚本层与API接口层的内存泄漏,维护脚本良好的运行内存环境 -+ `ELS_CONF_GC_ENABLE`可选 空、1、2 三个值,分别对应关闭、常规(推荐)、满载三个状态 - + 关闭状态,GC不会被编译到二进制文件中,与GC相关的模块也无法正常使用,性能优先 - + 常规状态,GC按照如下流程工作,在性能与空间之间保持良好的平衡 - ``` - 内存更改 ——触发——> 空间检测 ——超出阈值——> 回收 ——调整阈值——> 退出 - | - ——正常范围——> 退出 - ``` - + 满载状态,虚拟机逐指令触发GC检测流程 - -+ 洛书的 GC 支持设置最大上阈值,当内存占用达到最大上阈值后,阈值将不会进一步扩大,避免出现阈值溢出引发的GC失效 - -### 4-2-2-4-模块加载方式 -+ 洛书的模块加载方式主要有三种 - - 基于 libdl 的动态库加载,适合 Linux 平台 - - 基于 win32API 的动态库加载,适合 Windows 平台 - - 将模块打包进内核二进制的 ELF 接口 - -+ 这三种加载方式仅在内核构建时有区别,对于脚本用户而言,都是统一使用 `import` 函数进行引用 -### 4-2-2-5-虚拟机栈大小 -+ 一般而言,虚拟机的栈大小是在创建虚拟机对象时指定的 -+ `ELS_VM_STACK_SIZE`的作用是在其未指定或指定为非法值时的缺省 - -### 4-2-2-6-字符串缓冲区大小 -+ `ELS_BUFF_TMP_SIZE`主要用来维护内核中的字符串缓冲区 -+ 这个缓冲区可以为内核数据的转储,交换、共享提供一个公共的空间 - -### 4-2-2-7-IO缓冲区大小 -+ `ELS_VMIO_SIZE`是解释器文本IO缓冲区的大小,是指解释器在解释文件时,每次读取的字节数量 -+ 它的值越大读取次数越少,反之读取越频繁 -+ 这个值仅会影响脚本的加载速度,不影响脚本的运行速度 -+ 在常规平台上,其影响微乎其微 - -### 4-2-2-8-内存管理函数 -+ 洛书的内存管理只需要两个函数 - - `ELS_HEAPMEM_REALLOC`,对应标准C的`realloc`函数,可以替换成所在平台的对应实现 - - `ELS_HEAPMEM_FREE`,对应 标准C 的 `free`,同理 - -### 4-2-2-9-旧版兼容宏 -+ 仅在 Windows 与 Linux 出现,后期将会逐步移除 -+ 不建议再新的工程中使用兼容宏的相关依赖 - - diff --git "a/document/4-4-1-\350\231\232\346\213\237\346\234\272\345\257\271\350\261\241-els_VmObj.md" "b/document/4-4-1-\350\231\232\346\213\237\346\234\272\345\257\271\350\261\241-els_VmObj.md" deleted file mode 100755 index ba4a68364a9e509a0b988e919d453d0ef2c29bbb..0000000000000000000000000000000000000000 --- "a/document/4-4-1-\350\231\232\346\213\237\346\234\272\345\257\271\350\261\241-els_VmObj.md" +++ /dev/null @@ -1,74 +0,0 @@ -#!/bin/owls.wiki.losu.tech - -# 4-4-1-虚拟机对象-els_VmObj -## 4-4-1-1-概述 -1. 对象API是以 vm_ 为前缀的一系列函数。 -2. 对象API提供了在 C 中创建、管理、销毁虚拟机的一系列操作。 -## 4-4-1-2-数据类型 -```C++ -struct els_VmObj -{ - // -}; -typedef struct els_VmObj els_VmObj; -``` -+ 一般而言,其以指针的形式被使用 `els_VmObj*`,它指向的是一个存放在内存中的虚拟机对象 -## 4-4-1-3-对象API -### 4-4-1-3-1-创建虚拟机对象 -+ 原型 -```C++ -ELS_API els_VmObj* vm_create(int stacksize); -``` -+ 功能: - 1. 在内存中申请一块空余地址,创建一个运行时栈大小为 stacksize 的虚拟机 - 2. 如果创建失败,返回 NULL,否则返回虚拟机对象的指针 - -### 4-4-1-3-2-fork虚拟机 - -> 此API在多线程与协程相关章节会详细讲解 - -+ `ELS_API els_VmObj* vm_fork(els_VmObj*vm,int size);` -+ 功能:并将vm指向的虚拟机分支到新的空间,并设置运行时栈为 size - -### 4-4-1-3-3-打断运行 -+ `ELS_API void vm_stop(els_VmObj*vm);` -+ 打断指定虚拟机的运行,即使是在死循环中 -+ 这不会销毁虚拟机对象,该对象仍可被重新传入执行指令 - -### 4-4-1-3-4-报错 -+ `ELS_API void vm_error(els_VmObj* vm,const char* einfo,int e );` -+ 打断运行,输出错误信息 einfo,并将虚拟机的返回值设为 e -+ 这不会销毁虚拟机对象,该对象仍可被重新传入执行指令 - -### 4-4-1-3-5-执行脚本 -+ 用 vm 虚拟机执行 f 文件 -+ `ELS_API int vm_dofile(els_VmObj* vm,const char* f);` - -+ 用 vm 虚拟机执行字符串 s -+ `ELS_API int vm_dostring(els_VmObj*vm,const char* s );` - - -### 4-4-1-3-6-获取设定全局变量 -> 关于 LosuObj 类型,请参考相关章节 - -+ 获取 vm 中变量名为 s 的全局变量,返回它对应的 LosuObj 的指针 -+ `ELS_API LosuObj* vm_getval(els_VmObj* vm,const char*s);` - -+ 设定 vm 中变量 s 的值为 o -+ `ELS_API void vm_setval(els_VmObj *vm,const char* s ,LosuObj o );` - -+ 在 vm 中注册 C 函数 cfunc 为脚本函数 s -+ `ELS_API void vm_register(els_VmObj* vm,const char* s,VmCapi cfunc);` - -### 4-4-1-3-7-垃圾回收 -> 有关垃圾回收器的相关内容,可以参考内核原理的相关章节 - -+ 设定 vm 的最大 GC 上阈值为 max -+ `ELS_API void vm_setGC(els_VmObj* vm,unsigned long max);` - -+ 获取 vm 占用资源的相对值(当前资源 - 创建时资源) -+ `ELS_API unsigned long vm_getmem(els_VmObj*vm);` - -### 4-4-1-3-8-销毁虚拟机 -+ 打断虚拟机的一切活动,强行回收虚拟机的相关资源 -+ `ELS_API void vm_close(els_VmObj*vm);` \ No newline at end of file diff --git "a/document/4-4-2-\346\264\233\344\271\246\345\257\271\350\261\241-LosuObj.md" "b/document/4-4-2-\346\264\233\344\271\246\345\257\271\350\261\241-LosuObj.md" deleted file mode 100755 index dd1089f336b275fc84c32e3dbc78e268eeabe6c1..0000000000000000000000000000000000000000 --- "a/document/4-4-2-\346\264\233\344\271\246\345\257\271\350\261\241-LosuObj.md" +++ /dev/null @@ -1,91 +0,0 @@ -#!/bin/owls.wiki.losu.tech - -# 4-4-2-洛书对象-LosuObj -## 4-4-2-1-概述 -+ 对象API是以 obj_ 为前缀的一系列函数。 -+ 对象API提供了在 C 中访问 脚本 对象的一系列接口。在模块开发中占用很高的使用频率。 -+ 对象API本身也是使用面向对象的思想设计的,这些函数的参数排列都是基于 els_VmObj 与 被操作对象 - -## 4-4-2-2-数据类型 -```C++ -typedef struct - { - // 建议使用 API 访问内部成员,以获取最大向后兼容性 - } StackObj; -typedef StackObj LosuObj; -``` -## 4-4-2-3-对象API - -### 4-4-2-3-1-转换型 API -+ 这一类 API 可以将 LosuObj 转换为 Ctype,实现 洛书 到 C 的数据传递 -+ 获取 LosuObj 的内部类型 - - `ELS_API int obj_type(els_VmObj* vm,LosuObj* o);` - - 返回值与类型的参考详见 `els.h`中 ELS_API_TYPE_ 变量 - -+ 转换函数 - -```C++ -ELS_API const char* obj_tostr(els_VmObj* ,LosuObj *); -ELS_API Number obj_tonum(els_VmObj* ,LosuObj* ); -ELS_API char* obj_toptr(els_VmObj*,LosuObj*); -ELS_API VmCapi obj_tofunction(els_VmObj*,LosuObj*); -ELS_API const char* obj_tobyte(els_VmObj *,LosuObj *); -``` -### 4-4-2-3-2-创建型 API -+ 这一类 API 可以将 Ctype 转换为 LosuObj,实现 C 到 洛书 的数据传递 -+ 该类 API 会创建 LosuObj 到虚拟机中,但其不会被标记,如果不被绑定到某一脚本结点上,其会在下一个周期被回收 - -```C++ -ELS_API LosuObj obj_newstr(els_VmObj* ,char* ); -ELS_API LosuObj obj_newnum(els_VmObj* ,Number ); -ELS_API LosuObj obj_newfunction(els_VmObj*,els_C_API_function ); -ELS_API LosuObj obj_newnull(els_VmObj* ); -ELS_API LosuObj obj_newunit(els_VmObj* ); -ELS_API LosuObj obj_newptr(els_VmObj*,char* ); -ELS_API LosuObj obj_newbyte(els_VmObj*,char*,size_t ); - -``` - -### 4-4-2-3-3-索引型API -+ 这一类 API 主要是针对 对象与数组 的成员 访问与修改 - -```C++ -ELS_API LosuObj* obj_indexunit(els_VmObj*vm,LosuObj o ,LosuObj key); // 获取 o[key] 或 o.key -ELS_API void obj_setunit(els_VmObj*vm,LosuObj o,LosuObj key,LosuObj v); // o.key = v -``` -+ 为了更方便地进行索引,同时支持 -```C++ -ELS_API LosuObj* obj_indexunitbynum(els_VmObj*vm,LosuObj unit,Number i); -ELS_API LosuObj* obj_indexunitbystr(els_VmObj*vm,LosuObj unit,char* s); -ELS_API void obj_setunitbynum(els_VmObj*,LosuObj unit,Number key ,LosuObj value); -ELS_API void obj_setunitbystr(els_VmObj*,LosuObj unit,char* key ,LosuObj value); -``` - -### 4-4-2-3-4-unit遍历API - -+ 用以遍历数组或对象型的unit - -```C++ -ELS_API Node * obj_unit_first(els_VmObj*vm,LosuObj unit); // 获取第一个结点 -ELS_API Node obj_unit_location(els_VmObj*vm,LosuObj unit,LosuObj key); // 根据 key 值定位到结点 -ELS_API Node * obj_unit_next(els_VmObj*vm,LosuObj unit,Node*n); // 获取下一个结点 -ELS_API LosuObj obj_unit_nodekey(els_VmObj*vm,Node* n); // 获取 key -ELS_API LosuObj obj_unit_nodevalue(els_VmObj*vm,Node* n); // 获取 value -``` - -+ 样例 - -```C++ -int ELSAPI_test_test(els_VmObj* vm){ //对应脚本函数 test() - LosuObj u = *arg_get(vm,1); - Node * n = obj_unit_first(vm,u); - while (n!=NULL) - { - LosuObj k = obj_unit_nodekey(vm,n),v = obj_unit_nodekey(vm,n); - printf("key: %s \t val: %s\n",obj_tostr(vm,&k),obj_tostr(vm,&v)); - n = obj_unit_next(vm,u,n); - } - return 0; -} - -``` \ No newline at end of file diff --git "a/document/4-4-3-\345\217\202\346\225\260\344\274\240\351\200\222.md" "b/document/4-4-3-\345\217\202\346\225\260\344\274\240\351\200\222.md" deleted file mode 100755 index 529d1a34e137a33e634af0060b9dfea42f5ae3bd..0000000000000000000000000000000000000000 --- "a/document/4-4-3-\345\217\202\346\225\260\344\274\240\351\200\222.md" +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/owls.wiki.losu.tech - -# 4-4-3-参数传递 -## 4-4-3-1-概述 -+ 对象API是以 arg_ 为前缀的一系列函数。 -+ 对象API提供了在 C-API 函数中获取参数与返回数值的一系列接口。在模块开发中占用最高的频率。 -## 4-4-3-2-数据类型 -+ C-API 接口函数 -```C -int myfunc(els_VmObj* vm){ - // 功能实现 - return i; // 代表返回值的个数 -} -``` -+ 注册方式`vm_register(vm,"myfunc",myfunc);` -+ 脚本调用方式`myfunc(arg1,arg2)` - -## 4-4-3-3-对象API -### 4-4-3-3-1-获取参数 -+ 获取参数个数 -```C -ELS_API int arg_num(els_VmObj*vm); -``` -+ 获取第 i 个参数 -```C -ELS_API LosuObj* arg_get(els_VmObj*vm,int i); -``` - -+ 获取第 i 个参数 的指定Ctype -```C -ELS_API Number arg_getnum(els_VmObj*vm,int i ); -ELS_API const char* arg_getstr(els_VmObj*vm,int i); -ELS_API const char* arg_getbyte(els_VmObj*vm,int i); -ELS_API char* arg_getptr(els_VmObj*vm,int i); -ELS_API VmCapi arg_getfunc(els_VmObj*vm,int i); -ELS_API int arg_gettype(els_VmObj*vm,int i); -``` -### 4-4-3-3-2-返回值 -+ 返回 LosuObj -```C -ELS_API void arg_return(els_VmObj *,LosuObj ); -``` - -+ 将 Ctype 作为 LosuObj 返回 -```C -ELS_API void arg_returnnum(els_VmObj*,Number); -ELS_API void arg_returnstr(els_VmObj*,const char* ); -ELS_API void arg_returnfunc(els_VmObj*,VmCapi ); -ELS_API void arg_returnptr(els_VmObj*,char* ); -ELS_API void arg_returnnull(els_VmObj*); -ELS_API void arg_returnbyte(els_VmObj*,char* ,size_t); -``` diff --git "a/document/5-1-1-\344\272\206\350\247\243\346\264\233\344\271\246\347\244\276\345\214\272.md" "b/document/5-1-1-\344\272\206\350\247\243\346\264\233\344\271\246\347\244\276\345\214\272.md" deleted file mode 100755 index 0dcbac00a64a3fcfeba98b8f1d31b6203634e7e9..0000000000000000000000000000000000000000 --- "a/document/5-1-1-\344\272\206\350\247\243\346\264\233\344\271\246\347\244\276\345\214\272.md" +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/owls.wiki.losu.tech - -# 5-1-1-了解洛书社区 - -## 5-1-1-1-欢迎来到洛书编程语言的开源社区! - -洛书编程语言开源社区是一个开放、创新、协作、平等的社区,致力于推动洛书编程语言的开发、应用和普及。 -我们欢迎所有对洛书编程语言感兴趣的朋友加入我们的社区,共同探讨编程的奥秘,共享技术的乐趣。 - -## 5-1-1-2-在洛书编程语言开源社区,您可以: - -1. 参与开发:我们欢迎您为洛书编程语言的发展贡献力量,无论是提交新的功能、修复bug,还是优化性能,我们都非常期待您的参与。 -2. 分享经验:您可以在社区中分享您的洛书编程经验、心得体会,或者发布您自己的项目和作品,让更多的人了解和欣赏。 -3. 学习交流:这里聚集了众多的洛书编程爱好者,您可以与其他成员一起学习、交流,共同提高编程技能。 -4. 获得支持:如果您在开发过程中遇到问题或困难,可以在社区寻求帮助,我们的成员会尽力提供支持和解答。 -5. 参与活动:参与社区举办的开源活动,体验开源社区的精神与乐趣 - -## 5-1-1-2-社区守则 -+ 洛书编程语言开源社区守则 - 1. 尊重与友善:我们欢迎各种不同的观点和意见,但请保持尊重和友善的态度。避免使用侮辱性、攻击性或贬低他人的言辞。 - 2. 开放与包容:我们鼓励多元化的思想和合作。请尊重不同的观点和文化,以建设性的方式参与讨论。 - 3. 信息准确性:在分享信息或回答问题时,请尽可能提供准确和可靠的信息。避免传播不实或误导性的内容。 - 4. 版权与授权:请确保您分享的代码、作品或其他内容不侵犯任何版权或知识产权。遵守相关的许可协议,并尊重他人的劳动成果。 - 5. 不发布垃圾信息:禁止发布广告、垃圾邮件、恶意软件或任何形式的垃圾信息。 - 6. 避免违规行为:禁止进行任何违反法律法规的行为,包括但不限于发布违法内容、进行欺诈活动等。 - 7. 维护社区秩序:请遵守社区的管理规定,维护社区的秩序和整洁。 - 8. 积极参与:鼓励成员积极参与社区活动,分享经验、提供帮助和支持。共同推动社区的发展和进步。 - 9. 保持中立:在涉及争议性话题时,请保持中立和客观,避免偏见和主观臆断。 - 10. 保护个人隐私:尊重他人的隐私,不公开他人的个人信息,除非得到对方的明确授权或符合法律法规的要求。 -+ 让我们携手共建洛书编程语言开源社区的美好未来,共同维护一个友好、互助、和谐的社区环境! - diff --git "a/document/5-1-2-\347\211\210\346\234\254\345\217\221\345\270\203\350\247\204\345\210\231.md" "b/document/5-1-2-\347\211\210\346\234\254\345\217\221\345\270\203\350\247\204\345\210\231.md" deleted file mode 100755 index 2c39665dae2a419119bd2437b7978e9c11e8ae5b..0000000000000000000000000000000000000000 --- "a/document/5-1-2-\347\211\210\346\234\254\345\217\221\345\270\203\350\247\204\345\210\231.md" +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/owls.wiki.losu.tech -# 5-1-2-版本发布与维护 -## 5-1-2-1-发布原则 -+ 洛书采用 阶段性版本+滚动更新 相结合的发布方式,尽可能在更新与稳定之间取得良好的平衡 -+ 洛书采用 [年].[月].[周] 的版本编号标准,通过编号,可以快速推测出发布时间信息 -## 5-1-2-2-阶段性发布 -+ 洛书的阶段性版本意味着 - - 它自上一个阶段版本以来的更新经过了前阶段多个版本的检测 - - 它将被单独保留在软件源中,并享受在线服务的支持 - - 按照保留时间,它可分为 - - Monthly 将获得1个月的保留,过期后会被放弃支持 - - 它不会接受代码提交与问题反馈 - - 它不会再享受自动集成服务,其二进制文件不会得到更新 - - 它的 lsupdate 目标将会被指向最新的滚动更新版本 - - Semi-annual 将在软件源中获取6个月的支持,过期后会被放弃支持 - - 它不会接受代码提交与问题反馈 - - 它不会再享受自动集成服务,其二进制文件不会得到更新 - - 它的 lsupdate 目标将会被指向下一个Semi-annual版本 - - Stable,强大可靠的稳定版本,将在软件源中获取12个月以上的支持 - - 它接受除新内核特性以外的一切代码提交与问题反馈,包括 模块更新、漏洞修复、文档纠正 - - 它将持续享受自动集成服务,但不会再得到版本的升级 - - 它的 lsupdate 将会被指向下一个 Stable 版本 - - -## 5-1-2-3-滚动更新 -+ 得益于 洛书持续交付系统 ,洛书的滚动更新得到了前所未有的加强。目前,洛书的滚动更新主要包括三个部分 - - 每日构建: 分析前日的所有更改,并对增量部分进行构建,适合模块的更新与发布 - - 每周推送: 每周进行一次版本增量,生成更新包,用以新特性的推送与测试 - - 每月更新: 每月进行一次打包,将上月所有工作备份,发布阶段性版本 -+ 对于滚动更新版本,其每月的第一份发行版本是其上一月更新的阶段性版本 - diff --git "a/document/5-1-3-\344\272\244\346\265\201\344\270\216\345\220\210\344\275\234.md" "b/document/5-1-3-\344\272\244\346\265\201\344\270\216\345\220\210\344\275\234.md" deleted file mode 100755 index 9452ec9e7a60c678cc39cee1cd1f3dda04c65dce..0000000000000000000000000000000000000000 --- "a/document/5-1-3-\344\272\244\346\265\201\344\270\216\345\220\210\344\275\234.md" +++ /dev/null @@ -1,69 +0,0 @@ -#!/bin/owls.wiki.losu.tech - -# 5-1-3-交流与合作 -## 5-1-3-1-交流平台 -+ 洛书社区为您准备了广泛而全面的交流渠道,包括直播、论坛、Issue、交流群等途径 -+ 您可以通过以下途径参与社区交流 - - 社区直播(关注社区动态,了解直播活动) - - [开源论坛](https://zh-lang.osanswer.net/c/losu/),发帖、分享与叠甲 - - [Issue](https://gitee.com/chen-chaochen/lpk/issues) - - QQ 群 - - ![5-1-3-1](./img/5-1-3-1.jpg) - - 作者邮箱 3174025065@qq.com - - Gitee 私信 @chen-chaochen - -## 5-1-3-2-社区合作 -+ 洛书是一个开放的社区,我们期待与您的合作,您可以选择 - + 友链 - + 定向赞助者 - + 在项目中使用 -## 5-1-3-2-1-友链 - -+ [凹语言](https://wa-lang.org/) -+ [草蟒编程语言](https://www.grasspy.cn/) -+ [CovScript](https://unicov.cn/covscript/) - -
-说明 - -+ 友链的要求: - 1. 基于洛书或洛书相关的项目 - 2. 编程语言与编译器相关的国内项目 - 3. 其他与根软件相关的项目 -+ 友链的展示 - 1. 友链将出现在洛书的官网、文档、发行公告等相关信息之中 - 2. 因客观原因,某些场合不适合一次性列出所有友链,这种情况下,我们将从友链中抽取一部分进行展示 -+ 加入方式 - 1. 联系我们,提供项目简介、链接与联系方式,等待审核 - 2. 审核通过后我们会第一时间向您回复 - - -
- -## 5-1-3-2-1-定向赞助者 - - -
-说明 - - -+ 什么情况下会有定向赞助 - 1. 在向 洛书 项目提出需求时,可以通过附加赞助以提高该需求的优先级。这样可以让我们更快地满足您的需求,并且也可以帮助我们项目得到更多资金支持。 - 2. 希望针对性支持洛书社区的某方面困难时,也可以进行定向赞助,这有利于我们解决部分重点问题,促进项目健康发展 - -+ 哪些行为可以算作定向赞助 - 1. 开源捐赠,这有利于我们获得项目资金 - 2. 技术支持与贡献,协助我们解决技术难题 - 3. 基础设施,如服务器、算力、测试平台等开发时所需的软硬件资源 - 4. 开源活动,为社区举办开源活动提供场地、资金、人员等支持 - -
- -## 5-1-3-2-2-在项目中使用 - -+ 洛书是一个遵循 MIT LICENSE 的开源项目,您可以在遵循 MIT LICENSE 的前提下,在您的项目中自由地使用洛书,包括但不限于 - + 复制、使用、分发二进制文件 - + 复制、使用、修改、分发源代码 - + 基于源码构建二进制文件,并对其使用或分发 - - diff --git "a/document/5-2-1-\350\264\241\347\214\256\345\216\237\345\210\231.md" "b/document/5-2-1-\350\264\241\347\214\256\345\216\237\345\210\231.md" deleted file mode 100755 index bbb9507bc6d7ec1d9d06edbe16d4e7ff04169418..0000000000000000000000000000000000000000 --- "a/document/5-2-1-\350\264\241\347\214\256\345\216\237\345\210\231.md" +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/owls.wiki.losu.tech - -# 5-2-1-贡献原则 -+ 我们诚挚地感谢您的每一份贡献,了解我们的贡献原则有利于以正确的方式参与到洛书的贡献当中 - -## 5-2-1-1-尊重我们的劳动 - -+ 洛书源码使用遵循 MIT协议,无需额外授权。 -+ 使用者在使用 洛书 时,请务必遵守 MIT 开源协议,不得有超越该协议的行为或者意图。 - -## 5-2-1-2-认可我们的协议 -+ 如果您希望向洛书项目直接贡献代码,这意味着 - + 它将被合并入洛书[开源仓库](https://gitee.com/chen-chaochen/lpk) - + 它将被遵循 MIT LICENSE 开源 - + 已在洛书代码仓库中公开的源代码、文档、图纸等版权将属于洛书项目 -## 5-2-1-3-尊重他人的知识产权 - -+ 您应确保您贡献的代码不会侵犯他人知识产权,包括但不仅限于以下情况: - + 遵循与 MIT LICENSE 不兼容协议的代码 - + 非法反编译软件获得的源码 - + 他人受著作权保护的代码 - -+ 洛书不会对您的行为提供任何担保,一旦发现您的贡献存在侵权行为,我们将立即移除所有被涉及的代码,并永久拒绝您的贡献 - -## 5-2-1-4-保护好自身劳动成果 -+ 任何不被合并入主仓库的间接贡献所有权仍归作者本身所有 -+ 洛书不会对其的知识产权保护采取任何行动 -+ 如果您的贡献的所有权并没有被移交洛书项目,请注意采取相应的版权保护措施 - -# 附录-MIT LICENSE - - -``` -MIT License - -Copyright (c) 2020-2024 chen-chaochen - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -``` diff --git "a/document/5-2-2-1-\350\264\241\347\214\256\346\250\241\345\235\227.md" "b/document/5-2-2-1-\350\264\241\347\214\256\346\250\241\345\235\227.md" deleted file mode 100755 index faa91106d957edc8662c224f101939f7f1b19958..0000000000000000000000000000000000000000 --- "a/document/5-2-2-1-\350\264\241\347\214\256\346\250\241\345\235\227.md" +++ /dev/null @@ -1,129 +0,0 @@ -#!/bin/owls.wiki.losu.tech - -# 5-2-2-1-贡献模块 -+ 每一个模块都可以让洛书的功能更进一步,模块是洛书功能的唯一实现 -+ 有关创建模块工程,可参考 [3-3-创建一个模块工程](./3-3-创建一个模块工程.md) - -## 5-2-2-1-1-环境要求 -1. 方案一:标准 构建 环境 ( 官方构建环境 ) - + 正确安装 洛书 - + OS `Ubuntu 18.04.6 LTS` - + CC - - `gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)` - - `gcc version 7.3-win32` -2. 方案二:Linux开发环境 ( 适合 Linux 或 WSL 用户 ) - + 正确安装洛书 - + OS `Linux Amd64 or WSL` - + CC `GCC & GCC-win32(x86_64-w64-mingw32-gcc)` - -3. 方案三:Windows 开发环境 (最低兼容环境) - + 正确安装洛书 - + OS `Windows x64` - + CC `mingw32-w64` - + Shell `git bash` - - -## 5-2-2-1-2-完善已有的模块 -### 1-查看已有的模块 -+ 前往 [洛书在线服务](https://losu.tech/studio),查看各个模块的简介、文档与代码信息 - -### 2-下载模块的源工程 -在工作目录打开终端,输入 `losu -r lpt clone [模块名]`,克隆整个工程目录 - -### 3-完成更改 -> 做出更改时一定不要忘记同步修改 info 文件,否则 lpkg lpt等工具可能无法正常工作 - -+ 完善脚本接口 - 1. 打开工程中的脚本文件,完成更改 - 2. 使用 lpt 的 confsrc 功能更新胶水代码 - -+ 完善已有的分支实现 - 1. 使用 lpkg 将目标分支检出到工程的根目录下 - 2. 完成所希望的更改 - 3. 使用 lpkg 将更改后的结果提交到分支 - -+ 新建一个分支实现 - 1. 在工程根目录下完成更改 - 2. 使用 lpkg 将更改提交到新分支 - -### 4-检查更改 -1. 更改部分的功能与问题测试 -2. 更改部分与原有代码的兼容性测试 -3. 更改部分的构建可行性测试 - -### 5-提交贡献 -+ fork-pr 提交 - 1. fork 洛书的仓库,并将 fork仓库克隆到本地 - 2. 将 更改 推送到 fork 仓库 - 3. 发起 PR -+ Gitee 在线提交(轻量级 Pr) - 1. 在线服务 ——> 选择模块 ——> 查看代码,前往模块源码地址 - 2. 使用 gitee 的在线提交功能,上传代码到适当位置 - 3. 上传后自动生成轻量级 PR - -## 5-2-2-1-2-贡献新的模块 -### 1-新建与命名 -1. 创建以模块名命名的文件夹,并作为工作目录 -2. 模块的命名规则 - + 只能由 小写英文字母、数字与 _ 组成,不得包含空格、标点、中文等特殊字符,且不得以数字开头 - + 不得与已有模块命名冲突 -### 2-编写 info 文件 -+ info 文件模块 -```python -{ - type = "模块类型" - # 可选 - # const-锁定,不能被 lpt 更改,只能随版本更新而更新,一般用于内核与标准款 - # normal-常规,常规模块 - # pre-预览,预览版本模块,在安装前会强制确认操作,不能由自动升级安装 - info={ - name = "模块名", # 格式 英文名/中文名 如 owls/轻量级wiki建站工具 - text = "一句话简介", # 简明扼要, - version = "版本号", # 建议格式 年.月.日 如 24.1.13 - #name = "document/文档", - #text = "洛书的文档手册,从入门到入坑", - #version = "2.0.0", - }, - source = { # 源码列表 - all = { - # 通用平台源码 - }, - # 各个分支的源码列表 - # Ubuntu = {}, - # WIndows = {}, - # ... - }, - target = { - # 各个分支的构建脚本 - } -} -``` - - -### 3-编写readme.md -+ 在工作目录下创建 readme.md,内容为模块的文档,包括但不限于 - + 模块作者 - + 模块介绍 - + 模块用法 - + 模块API -+ 文档格式要求 - + 首行 `#!/bin/owls.wiki.losu.tech` - + 编码格式 `utf-8` - + 换行符 `LF` -+ 注意:没有 Readme 的模块不会得到接受! - -### 4-开发与测试 -1. 编写脚本接口 -2. 生成胶水代码 -3. 编写平台实现 (如果存在) -4. 测试模块 - -### 5-提交贡献 -+ fork-pr 提交 - 1. fork 洛书的仓库,并将 fork仓库克隆到本地 - 2. 将 更改 推送到 fork 仓库 - 3. 发起 PR -+ Gitee 在线提交(轻量级 Pr) - 1. 在线服务 ——> 选择模块 ——> 查看代码,前往模块源码地址 - 2. 使用 gitee 的在线提交功能,上传代码到适当位置 - 3. 上传后自动生成轻量级 PR \ No newline at end of file diff --git "a/document/5-2-2-2-\351\200\202\351\205\215\344\270\216\347\247\273\346\244\215.md" "b/document/5-2-2-2-\351\200\202\351\205\215\344\270\216\347\247\273\346\244\215.md" deleted file mode 100755 index 6f114129a76ed02c0501e5c3b2f7da5163d910d6..0000000000000000000000000000000000000000 --- "a/document/5-2-2-2-\351\200\202\351\205\215\344\270\216\347\247\273\346\244\215.md" +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/owls.wiki.losu.tech - -# 5-2-2-2-适配与移植 - - - diff --git a/document/LICENSE.md b/document/LICENSE.md deleted file mode 100755 index 8f734859d5a4dab7e22f6c822415de7c5c8fdf71..0000000000000000000000000000000000000000 --- a/document/LICENSE.md +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/owls.wiki.losu.tech - -``` -MIT License - -Copyright (c) 2020-2024 chen-chaochen - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -``` diff --git a/document/img/1.1.3.png b/document/img/1.1.3.png deleted file mode 100755 index 3ee1bd97be73cf601b49f832e82b9f22254d80b1..0000000000000000000000000000000000000000 Binary files a/document/img/1.1.3.png and /dev/null differ diff --git a/document/img/2.3.3.1.png b/document/img/2.3.3.1.png deleted file mode 100755 index a03d6ee8ad818ec4f80b22cbf88972036f41865e..0000000000000000000000000000000000000000 Binary files a/document/img/2.3.3.1.png and /dev/null differ diff --git a/document/img/2.3.3.2.png b/document/img/2.3.3.2.png deleted file mode 100755 index dd31a84e728d186b1ba824bf2ea96d56a3ce0c49..0000000000000000000000000000000000000000 Binary files a/document/img/2.3.3.2.png and /dev/null differ diff --git a/document/img/2.4.1.1.png b/document/img/2.4.1.1.png deleted file mode 100755 index b982d601eb3c3c872dd4f0426a36f8c4ecf210ab..0000000000000000000000000000000000000000 Binary files a/document/img/2.4.1.1.png and /dev/null differ diff --git a/document/img/2.4.2.1.png b/document/img/2.4.2.1.png deleted file mode 100755 index 09a11f5c3b54e86c6229615e935262bc9a5af25d..0000000000000000000000000000000000000000 Binary files a/document/img/2.4.2.1.png and /dev/null differ diff --git a/document/img/2.4.3.1.png b/document/img/2.4.3.1.png deleted file mode 100755 index 1ab1a2c20c88d5432a93f842019cf615b14a85cf..0000000000000000000000000000000000000000 Binary files a/document/img/2.4.3.1.png and /dev/null differ diff --git a/document/img/2.5.1.1.png b/document/img/2.5.1.1.png deleted file mode 100755 index 4d96d13cbd72df8119b446e71a1136d777dfee8e..0000000000000000000000000000000000000000 Binary files a/document/img/2.5.1.1.png and /dev/null differ diff --git a/document/img/2.5.2.1.png b/document/img/2.5.2.1.png deleted file mode 100755 index 59c9fd173eebd352045ae8aa81e0b39414aad5e8..0000000000000000000000000000000000000000 Binary files a/document/img/2.5.2.1.png and /dev/null differ diff --git a/document/img/2.5.3.1.png b/document/img/2.5.3.1.png deleted file mode 100755 index 5259e329fa6381a3b62cfc88b68ea3772e51d776..0000000000000000000000000000000000000000 Binary files a/document/img/2.5.3.1.png and /dev/null differ diff --git a/document/img/2.5.3.2.png b/document/img/2.5.3.2.png deleted file mode 100755 index 81f4374f86308b621567a62502ae7286a3983a60..0000000000000000000000000000000000000000 Binary files a/document/img/2.5.3.2.png and /dev/null differ diff --git a/document/img/2.6.1.1.png b/document/img/2.6.1.1.png deleted file mode 100755 index 9468668e71c3891a65606fedcbb5c58c05abeb0c..0000000000000000000000000000000000000000 Binary files a/document/img/2.6.1.1.png and /dev/null differ diff --git a/document/img/2.6.1.2.png b/document/img/2.6.1.2.png deleted file mode 100755 index 3775fec7303f34d74b7d11c7d9f82fe8f4b28eef..0000000000000000000000000000000000000000 Binary files a/document/img/2.6.1.2.png and /dev/null differ diff --git a/document/img/2.6.2.1.png b/document/img/2.6.2.1.png deleted file mode 100755 index ee43ae2e3c354f2bbe0475af663571cd8c8c5606..0000000000000000000000000000000000000000 Binary files a/document/img/2.6.2.1.png and /dev/null differ diff --git a/document/img/3.1.1.png b/document/img/3.1.1.png deleted file mode 100755 index 14e6bce2a2f625bbab3fb0d2de9c2482bdcb60b1..0000000000000000000000000000000000000000 Binary files a/document/img/3.1.1.png and /dev/null differ diff --git a/document/img/3.2.1.png b/document/img/3.2.1.png deleted file mode 100755 index 25c36cd33028ad70186e596642e9f09732b3198a..0000000000000000000000000000000000000000 Binary files a/document/img/3.2.1.png and /dev/null differ diff --git a/document/img/3.3.1.png b/document/img/3.3.1.png deleted file mode 100755 index 4bfb011be563624846ba95c0a6c40accd2f58335..0000000000000000000000000000000000000000 Binary files a/document/img/3.3.1.png and /dev/null differ diff --git a/document/img/3.3.2.png b/document/img/3.3.2.png deleted file mode 100755 index 5b3a12364ff4f2e320e78d40fada327a04187dc6..0000000000000000000000000000000000000000 Binary files a/document/img/3.3.2.png and /dev/null differ diff --git a/document/img/3.3.3.png b/document/img/3.3.3.png deleted file mode 100755 index 56e536806e27b1e613d03a7de54a3c3557f65e5b..0000000000000000000000000000000000000000 Binary files a/document/img/3.3.3.png and /dev/null differ diff --git a/document/img/3.4.1.png b/document/img/3.4.1.png deleted file mode 100755 index 10b62cbcff0bc392eeaf53cea3940f0aa6745492..0000000000000000000000000000000000000000 Binary files a/document/img/3.4.1.png and /dev/null differ diff --git a/document/img/3.4.2.png b/document/img/3.4.2.png deleted file mode 100755 index 50ad329902079f5648fccd7fbcaab3f3c0f5e818..0000000000000000000000000000000000000000 Binary files a/document/img/3.4.2.png and /dev/null differ diff --git a/document/img/3.5.1.png b/document/img/3.5.1.png deleted file mode 100755 index 741917fff4b50348a6727d90d5703a0fd861e292..0000000000000000000000000000000000000000 Binary files a/document/img/3.5.1.png and /dev/null differ diff --git a/document/img/4.2.1.png b/document/img/4.2.1.png deleted file mode 100755 index bff85989e8dedb143a16f6807169ca1e147ab4d5..0000000000000000000000000000000000000000 Binary files a/document/img/4.2.1.png and /dev/null differ diff --git a/document/img/4.2.2.png b/document/img/4.2.2.png deleted file mode 100755 index 6cf4714678c88d1d88e9bdbf7891d5aab05398e2..0000000000000000000000000000000000000000 Binary files a/document/img/4.2.2.png and /dev/null differ diff --git a/document/img/4.2.3.png b/document/img/4.2.3.png deleted file mode 100755 index 3c88ba6624696edd93e4006ecf7d5ae19dbea1fc..0000000000000000000000000000000000000000 Binary files a/document/img/4.2.3.png and /dev/null differ diff --git a/document/img/4.3.1.png b/document/img/4.3.1.png deleted file mode 100755 index 0b4c7c28e94dbdbdc6be9ad43d78426a89ab8be9..0000000000000000000000000000000000000000 Binary files a/document/img/4.3.1.png and /dev/null differ diff --git a/document/img/4.4.1.png b/document/img/4.4.1.png deleted file mode 100755 index 494f6b1ea253a847bf9ca8ab657d115cbf88f7d2..0000000000000000000000000000000000000000 Binary files a/document/img/4.4.1.png and /dev/null differ diff --git a/document/img/5-1-3-1.jpg b/document/img/5-1-3-1.jpg deleted file mode 100755 index 3d3057be62f343bccd7ad2a0c79be8adc5342e8b..0000000000000000000000000000000000000000 Binary files a/document/img/5-1-3-1.jpg and /dev/null differ diff --git a/document/img/5-2-3.jpg b/document/img/5-2-3.jpg deleted file mode 100755 index 9fb283f514e769539f5b0f7ba23c312d827965e8..0000000000000000000000000000000000000000 Binary files a/document/img/5-2-3.jpg and /dev/null differ diff --git a/document/img/5.2.1.png b/document/img/5.2.1.png deleted file mode 100755 index bed4186d28e2f9df6a27e5a087da07240e16cf19..0000000000000000000000000000000000000000 Binary files a/document/img/5.2.1.png and /dev/null differ diff --git a/document/img/5.3.1.png b/document/img/5.3.1.png deleted file mode 100755 index 1ba8d1749afbf2c861a733e3cbc3fd9b14d6d00c..0000000000000000000000000000000000000000 Binary files a/document/img/5.3.1.png and /dev/null differ diff --git a/document/img/5.4.1.png b/document/img/5.4.1.png deleted file mode 100755 index 1ba8d1749afbf2c861a733e3cbc3fd9b14d6d00c..0000000000000000000000000000000000000000 Binary files a/document/img/5.4.1.png and /dev/null differ diff --git a/document/img/5.5.1.png b/document/img/5.5.1.png deleted file mode 100755 index 05caf5ee68fd01455dcb2207d56d9141af324f46..0000000000000000000000000000000000000000 Binary files a/document/img/5.5.1.png and /dev/null differ diff --git a/document/img/5.6.1.png b/document/img/5.6.1.png deleted file mode 100755 index e04c4f13db7e23e3482135eef855c2a8b71fa5cd..0000000000000000000000000000000000000000 Binary files a/document/img/5.6.1.png and /dev/null differ diff --git a/document/img/5.6.2.png b/document/img/5.6.2.png deleted file mode 100755 index 5d2a5db17bb2e1128e1548aaa84c7a85f1b4d676..0000000000000000000000000000000000000000 Binary files a/document/img/5.6.2.png and /dev/null differ diff --git a/document/img/5.7.1.png b/document/img/5.7.1.png deleted file mode 100755 index 492cbe74547f5bb3001a09a24079ba141c06aa2e..0000000000000000000000000000000000000000 Binary files a/document/img/5.7.1.png and /dev/null differ diff --git a/document/img/6.1.png b/document/img/6.1.png deleted file mode 100755 index 15db4ccee85f1012b6b32cfbe9b1280fe9e48df5..0000000000000000000000000000000000000000 Binary files a/document/img/6.1.png and /dev/null differ diff --git a/document/index.md b/document/index.md deleted file mode 100755 index a4eaa3e2846baf6f6d92b4c06371ea94f7257c4d..0000000000000000000000000000000000000000 --- a/document/index.md +++ /dev/null @@ -1,95 +0,0 @@ -#!/bin/owls.wiki.losu.tech - -# 欢迎 - -+ 欢迎来到洛书文档中心! -+ 本站基于 [OWLS](./owls.md) Wiki 工具构建 -+ 洛书是一个遵循 [MIT LICENSE](./LICENSE.md) 的开源软件。 - - -# 本站提供哪些文档? - -## 1 - 入门指南 - -+ [1-1-在线服务](./1-1-在线服务.md) -+ [1-2-下载与安装](./1-2-下载与安装.md) -+ [1-3-初识模块管理器](./1-3-初识模块管理器.md) - -## 2 - 语法手册 -+ [2-1-你好洛书.md](./2-1-你好洛书.md) -+ [2-2-程序结构.md](./2-2-程序结构.md) -+ [2-3-语句.md](./2-3-语句.md) -+ [2-4-数组.md](./2-4-数组.md) -+ [2-5-对象.md](./2-5-对象.md) -+ [2-6-运算符重载.md](./2-6-运算符重载.md) -+ [2-7-构造函数.md](./2-7-构造函数.md) -+ [2-8-转义字符](./2-8-转义字符.md) - -## 3 - 开发环境与工具链 -+ [3-1-模块化与工程管理](./3-1-模块化与工程管理.md) -+ [3-2-模块管理器的进阶](./3-2-模块管理器的进阶.md) -+ [3-3-创建一个模块工程](./3-3-创建一个模块工程.md) -+ [3-4-模块工具的使用](./3-4-模块工具的使用.md) - - -## 4 - 内核与模块开发 -+ 4-1-内核原理 - - B站专栏 -+ [4-2-内核的移植](./4-2-内核的移植.md) -+ 4-3-配置和高级功能 - - 4-3-1-内存管理器 - - 4-3-2-垃圾回收器 - - 4-3-3-虚拟机堆栈 - - 4-3-4-多线程模型与锁 - - 4-3-5-协程与并发 -+ 4-4-虚拟机API参考 - - [4-4-1-虚拟机对象-els_VmObj](./4-4-1-虚拟机对象-els_VmObj.md) - - [4-4-2-洛书对象-LosuObj](./4-4-2-洛书对象-LosuObj.md) - - [4-4-3-参数传递](./4-4-3-参数传递.md) - - -## 5 - 社区与贡献 - -
- - -+ 5-1-洛书社区 - + [5-1-1-了解洛书社区](./5-1-1-了解洛书社区.md) - + [5-1-2-版本发布与维护](./5-1-2-版本发布规则.md) - + [5-1-3-交流与合作](./5-1-3-交流与合作.md) - -+ 5-2-贡献指南 - + [5-2-1-贡献原则](./5-2-1-贡献原则.md) - + 5-2-2-贡献代码 - - [5-2-2-1-贡献模块](./5-2-2-1-贡献模块.md) - - - 5-2-2-2-适配与移植 - - - 5-2-2-3-贡献内核 - + 5-2-3-并不是只有代码才算贡献,您也可以 - - 参与洛书社区的开源活动 - - 在公司产品、个人项目或比赛中使用洛书 - - 向我们反馈问题,提交 issue - - 捐赠项目 - - ![捐赠项目](./img/5-2-3.jpg) - - -## 6-专栏教程 - -## 7-活动回顾 - - - -# 附录 - 相关资源 -+ [洛书在线服务中心](https://losu.tech/studio/) -+ [洛书在线运行平台](https://losu.tech/playground/) -+ [洛书代码源](https://losu.tech/archive/) -+ [下载中心](https://losu.tech/archive/lasted/.repo/release/) -+ [开源仓库](https://gitee.com/chen-chaochen/lpk) - -# 版权 -+ 洛书是一个由个人发起的开源项目,作者是[@chen-chaochen](https://gitee.com/chen-chaochen),并基于 MIT LICENSE 分发 -+ 加入 [PLOC](https://gitee.com/ploc-org) 社区,一起参与国产编程语言共建之路 - - diff --git a/document/info b/document/info deleted file mode 100755 index 0e68c88d10c47c6fff7a8690d32fc54b47b16958..0000000000000000000000000000000000000000 --- a/document/info +++ /dev/null @@ -1,13 +0,0 @@ -{ - info={ - name = "document/洛书文档中心", - text = "洛书的文档手册,从入门到入坑", - version = "24.2.5", - }, - source = { - all = { - }, - }, - type = "const", - target = {} -} \ No newline at end of file diff --git a/document/owls.md b/document/owls.md deleted file mode 100755 index 2fbca5a30d5a3b3b2ffd8a6f461357ef84494c60..0000000000000000000000000000000000000000 --- a/document/owls.md +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/owls.wiki.losu.tech - -# owls · wiki服务黑魔法 -## OWLS可以做什么? -+ OWLS是一个基于洛书实现的wiki建站服务工具,可以让您利用markdown文档生成精美的web网页 -## OWLS有哪些特色? -+ 更轻量、快速的选择 - - 基于高效的 losu script,完全由其标准库书写,仅需数十KB的资源需求 - - 支持多种markdown引擎 - - 通过洛书模块工具一键部署 -+ 满足个性化需求 - - 原生html模块支持 - - 支持工程自定义模板 -+ 无中间文件 - - 无html输出生成 - - 适合git版本管理机制 - - 保持源码整洁度 -+ 开源开放便捷 - - MIT LICENSE 许可 - - 支持 lpt 一键安装 - - 自由地修改与分发 - - -## 附录 -``` -本站采用 marked.js 提供MarkDown渲染服务 - * marked v6.0.0 - a markdown parser - * Copyright (c) 2011-2023, Christopher Jeffrey. (MIT Licensed) - * https://github.com/markedjs/marked - -owls classic主题 -``` \ No newline at end of file diff --git a/document/readme.md b/document/readme.md deleted file mode 100755 index a4eaa3e2846baf6f6d92b4c06371ea94f7257c4d..0000000000000000000000000000000000000000 --- a/document/readme.md +++ /dev/null @@ -1,95 +0,0 @@ -#!/bin/owls.wiki.losu.tech - -# 欢迎 - -+ 欢迎来到洛书文档中心! -+ 本站基于 [OWLS](./owls.md) Wiki 工具构建 -+ 洛书是一个遵循 [MIT LICENSE](./LICENSE.md) 的开源软件。 - - -# 本站提供哪些文档? - -## 1 - 入门指南 - -+ [1-1-在线服务](./1-1-在线服务.md) -+ [1-2-下载与安装](./1-2-下载与安装.md) -+ [1-3-初识模块管理器](./1-3-初识模块管理器.md) - -## 2 - 语法手册 -+ [2-1-你好洛书.md](./2-1-你好洛书.md) -+ [2-2-程序结构.md](./2-2-程序结构.md) -+ [2-3-语句.md](./2-3-语句.md) -+ [2-4-数组.md](./2-4-数组.md) -+ [2-5-对象.md](./2-5-对象.md) -+ [2-6-运算符重载.md](./2-6-运算符重载.md) -+ [2-7-构造函数.md](./2-7-构造函数.md) -+ [2-8-转义字符](./2-8-转义字符.md) - -## 3 - 开发环境与工具链 -+ [3-1-模块化与工程管理](./3-1-模块化与工程管理.md) -+ [3-2-模块管理器的进阶](./3-2-模块管理器的进阶.md) -+ [3-3-创建一个模块工程](./3-3-创建一个模块工程.md) -+ [3-4-模块工具的使用](./3-4-模块工具的使用.md) - - -## 4 - 内核与模块开发 -+ 4-1-内核原理 - - B站专栏 -+ [4-2-内核的移植](./4-2-内核的移植.md) -+ 4-3-配置和高级功能 - - 4-3-1-内存管理器 - - 4-3-2-垃圾回收器 - - 4-3-3-虚拟机堆栈 - - 4-3-4-多线程模型与锁 - - 4-3-5-协程与并发 -+ 4-4-虚拟机API参考 - - [4-4-1-虚拟机对象-els_VmObj](./4-4-1-虚拟机对象-els_VmObj.md) - - [4-4-2-洛书对象-LosuObj](./4-4-2-洛书对象-LosuObj.md) - - [4-4-3-参数传递](./4-4-3-参数传递.md) - - -## 5 - 社区与贡献 - -
- - -+ 5-1-洛书社区 - + [5-1-1-了解洛书社区](./5-1-1-了解洛书社区.md) - + [5-1-2-版本发布与维护](./5-1-2-版本发布规则.md) - + [5-1-3-交流与合作](./5-1-3-交流与合作.md) - -+ 5-2-贡献指南 - + [5-2-1-贡献原则](./5-2-1-贡献原则.md) - + 5-2-2-贡献代码 - - [5-2-2-1-贡献模块](./5-2-2-1-贡献模块.md) - - - 5-2-2-2-适配与移植 - - - 5-2-2-3-贡献内核 - + 5-2-3-并不是只有代码才算贡献,您也可以 - - 参与洛书社区的开源活动 - - 在公司产品、个人项目或比赛中使用洛书 - - 向我们反馈问题,提交 issue - - 捐赠项目 - - ![捐赠项目](./img/5-2-3.jpg) - - -## 6-专栏教程 - -## 7-活动回顾 - - - -# 附录 - 相关资源 -+ [洛书在线服务中心](https://losu.tech/studio/) -+ [洛书在线运行平台](https://losu.tech/playground/) -+ [洛书代码源](https://losu.tech/archive/) -+ [下载中心](https://losu.tech/archive/lasted/.repo/release/) -+ [开源仓库](https://gitee.com/chen-chaochen/lpk) - -# 版权 -+ 洛书是一个由个人发起的开源项目,作者是[@chen-chaochen](https://gitee.com/chen-chaochen),并基于 MIT LICENSE 分发 -+ 加入 [PLOC](https://gitee.com/ploc-org) 社区,一起参与国产编程语言共建之路 - - diff --git a/hash/MD5.c b/hash/MD5.c deleted file mode 100755 index 5280beb0e7494e96b944251ec82ed9f2944c8ff9..0000000000000000000000000000000000000000 --- a/hash/MD5.c +++ /dev/null @@ -1,183 +0,0 @@ -#include "MD5.h" - -unsigned char PADDING[]={0x80,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; - -void MD5Init(MD5_CTX *context) -{ - context->count[0] = 0; - context->count[1] = 0; - context->state[0] = 0x67452301; - context->state[1] = 0xEFCDAB89; - context->state[2] = 0x98BADCFE; - context->state[3] = 0x10325476; -} - -void MD5Update(MD5_CTX *context,unsigned char *input,unsigned int inputlen) -{ - unsigned int i = 0,index = 0,partlen = 0; - index = (context->count[0] >> 3) & 0x3F; - partlen = 64 - index; - context->count[0] += inputlen << 3; - if(context->count[0] < (inputlen << 3)) - context->count[1]++; - context->count[1] += inputlen >> 29; - - if(inputlen >= partlen) - { - memcpy(&context->buffer[index],input,partlen); - MD5Transform(context->state,context->buffer); - for(i = partlen;i+64 <= inputlen;i+=64) - MD5Transform(context->state, input + i); - index = 0; - } - else - i = 0; - memcpy(&context->buffer[index],&input[i],inputlen-i); -} -void MD5Final(MD5_CTX *context,unsigned char *digest) -{ - unsigned int index = 0,padlen = 0; - unsigned char bits[8]; - index = (context->count[0] >> 3) & 0x3F; - padlen = (index < 56)?(56-index):(120-index); - MD5Encode(bits,context->count,8); - MD5Update(context,PADDING,padlen); - MD5Update(context,bits,8); - MD5Encode(digest,context->state,16); -} -void MD5Encode(unsigned char *output,unsigned int *input,unsigned int len) -{ - unsigned int i = 0,j = 0; - while(j < len) - { - output[j] = input[i] & 0xFF; - output[j+1] = (input[i] >> 8) & 0xFF; - output[j+2] = (input[i] >> 16) & 0xFF; - output[j+3] = (input[i] >> 24) & 0xFF; - i++; - j+=4; - } -} -void MD5Decode(unsigned int *output,unsigned char *input,unsigned int len) -{ - unsigned int i = 0,j = 0; - while(j < len) - { - output[i] = (input[j]) | - (input[j+1] << 8) | - (input[j+2] << 16) | - (input[j+3] << 24); - i++; - j+=4; - } -} -void MD5Transform(unsigned int *state,unsigned char *block) -{ - unsigned int a = state[0]; - unsigned int b = state[1]; - unsigned int c = state[2]; - unsigned int d = state[3]; - unsigned int x[64]; - MD5Decode(x,block,64); - FF(a, b, c, d, x[ 0], 7, 0xd76aa478); /* 1 */ - FF(d, a, b, c, x[ 1], 12, 0xe8c7b756); /* 2 */ - FF(c, d, a, b, x[ 2], 17, 0x242070db); /* 3 */ - FF(b, c, d, a, x[ 3], 22, 0xc1bdceee); /* 4 */ - FF(a, b, c, d, x[ 4], 7, 0xf57c0faf); /* 5 */ - FF(d, a, b, c, x[ 5], 12, 0x4787c62a); /* 6 */ - FF(c, d, a, b, x[ 6], 17, 0xa8304613); /* 7 */ - FF(b, c, d, a, x[ 7], 22, 0xfd469501); /* 8 */ - FF(a, b, c, d, x[ 8], 7, 0x698098d8); /* 9 */ - FF(d, a, b, c, x[ 9], 12, 0x8b44f7af); /* 10 */ - FF(c, d, a, b, x[10], 17, 0xffff5bb1); /* 11 */ - FF(b, c, d, a, x[11], 22, 0x895cd7be); /* 12 */ - FF(a, b, c, d, x[12], 7, 0x6b901122); /* 13 */ - FF(d, a, b, c, x[13], 12, 0xfd987193); /* 14 */ - FF(c, d, a, b, x[14], 17, 0xa679438e); /* 15 */ - FF(b, c, d, a, x[15], 22, 0x49b40821); /* 16 */ - - /* Round 2 */ - GG(a, b, c, d, x[ 1], 5, 0xf61e2562); /* 17 */ - GG(d, a, b, c, x[ 6], 9, 0xc040b340); /* 18 */ - GG(c, d, a, b, x[11], 14, 0x265e5a51); /* 19 */ - GG(b, c, d, a, x[ 0], 20, 0xe9b6c7aa); /* 20 */ - GG(a, b, c, d, x[ 5], 5, 0xd62f105d); /* 21 */ - GG(d, a, b, c, x[10], 9, 0x2441453); /* 22 */ - GG(c, d, a, b, x[15], 14, 0xd8a1e681); /* 23 */ - GG(b, c, d, a, x[ 4], 20, 0xe7d3fbc8); /* 24 */ - GG(a, b, c, d, x[ 9], 5, 0x21e1cde6); /* 25 */ - GG(d, a, b, c, x[14], 9, 0xc33707d6); /* 26 */ - GG(c, d, a, b, x[ 3], 14, 0xf4d50d87); /* 27 */ - GG(b, c, d, a, x[ 8], 20, 0x455a14ed); /* 28 */ - GG(a, b, c, d, x[13], 5, 0xa9e3e905); /* 29 */ - GG(d, a, b, c, x[ 2], 9, 0xfcefa3f8); /* 30 */ - GG(c, d, a, b, x[ 7], 14, 0x676f02d9); /* 31 */ - GG(b, c, d, a, x[12], 20, 0x8d2a4c8a); /* 32 */ - - /* Round 3 */ - HH(a, b, c, d, x[ 5], 4, 0xfffa3942); /* 33 */ - HH(d, a, b, c, x[ 8], 11, 0x8771f681); /* 34 */ - HH(c, d, a, b, x[11], 16, 0x6d9d6122); /* 35 */ - HH(b, c, d, a, x[14], 23, 0xfde5380c); /* 36 */ - HH(a, b, c, d, x[ 1], 4, 0xa4beea44); /* 37 */ - HH(d, a, b, c, x[ 4], 11, 0x4bdecfa9); /* 38 */ - HH(c, d, a, b, x[ 7], 16, 0xf6bb4b60); /* 39 */ - HH(b, c, d, a, x[10], 23, 0xbebfbc70); /* 40 */ - HH(a, b, c, d, x[13], 4, 0x289b7ec6); /* 41 */ - HH(d, a, b, c, x[ 0], 11, 0xeaa127fa); /* 42 */ - HH(c, d, a, b, x[ 3], 16, 0xd4ef3085); /* 43 */ - HH(b, c, d, a, x[ 6], 23, 0x4881d05); /* 44 */ - HH(a, b, c, d, x[ 9], 4, 0xd9d4d039); /* 45 */ - HH(d, a, b, c, x[12], 11, 0xe6db99e5); /* 46 */ - HH(c, d, a, b, x[15], 16, 0x1fa27cf8); /* 47 */ - HH(b, c, d, a, x[ 2], 23, 0xc4ac5665); /* 48 */ - - /* Round 4 */ - II(a, b, c, d, x[ 0], 6, 0xf4292244); /* 49 */ - II(d, a, b, c, x[ 7], 10, 0x432aff97); /* 50 */ - II(c, d, a, b, x[14], 15, 0xab9423a7); /* 51 */ - II(b, c, d, a, x[ 5], 21, 0xfc93a039); /* 52 */ - II(a, b, c, d, x[12], 6, 0x655b59c3); /* 53 */ - II(d, a, b, c, x[ 3], 10, 0x8f0ccc92); /* 54 */ - II(c, d, a, b, x[10], 15, 0xffeff47d); /* 55 */ - II(b, c, d, a, x[ 1], 21, 0x85845dd1); /* 56 */ - II(a, b, c, d, x[ 8], 6, 0x6fa87e4f); /* 57 */ - II(d, a, b, c, x[15], 10, 0xfe2ce6e0); /* 58 */ - II(c, d, a, b, x[ 6], 15, 0xa3014314); /* 59 */ - II(b, c, d, a, x[13], 21, 0x4e0811a1); /* 60 */ - II(a, b, c, d, x[ 4], 6, 0xf7537e82); /* 61 */ - II(d, a, b, c, x[11], 10, 0xbd3af235); /* 62 */ - II(c, d, a, b, x[ 2], 15, 0x2ad7d2bb); /* 63 */ - II(b, c, d, a, x[ 9], 21, 0xeb86d391); /* 64 */ - state[0] += a; - state[1] += b; - state[2] += c; - state[3] += d; -} - -void MD5(MD5_t *task) -{ - MD5_CTX md5; - unsigned char *encrypt = (void*)task->content; - unsigned char decrypt[16]; - - MD5Init(&md5); - MD5Update(&md5, encrypt, strlen((void*)encrypt)); - MD5Final(&md5, decrypt); - - for (int i=0;i<16;i++) - sprintf((void*)(&task->result[i*2]), "%02X", decrypt[i]); -} - -void MD5_FromString(const char* content, char* buffer) -{ - MD5_t task; - task.content = (unsigned char*)content; - MD5(&task); - - for (int i=0;i<32;i++) - buffer[i] = task.result[i]; -} diff --git a/hash/MD5.h b/hash/MD5.h deleted file mode 100755 index e9b99db993d9a23799712c0648b69a3799da6002..0000000000000000000000000000000000000000 --- a/hash/MD5.h +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef LOSU_MD5_H__ -#define LOSU_MD5_H__ - -#include -#include -#include -#include - -/* - 使用方法: - 创建MD5_t - 将MD5_t的指针放入MD5函数 - 从MD5_t的result中得到结果 -*/ - -typedef struct -{ - unsigned int count[2]; - unsigned int state[4]; - unsigned char buffer[64]; -}MD5_CTX; - -typedef struct -{ - const unsigned char* content; - char result[33]; -}MD5_t; - -#define F(x,y,z) ((x & y) | (~x & z)) -#define G(x,y,z) ((x & z) | (y & ~z)) -#define H(x,y,z) (x^y^z) -#define I(x,y,z) (y ^ (x | ~z)) -#define ROTATE_LEFT(x,n) ((x << n) | (x >> (32-n))) -#define FF(a,b,c,d,x,s,ac) \ - { \ - a += F(b,c,d) + x + ac; \ - a = ROTATE_LEFT(a,s); \ - a += b; \ - } -#define GG(a,b,c,d,x,s,ac) \ - { \ - a += G(b,c,d) + x + ac; \ - a = ROTATE_LEFT(a,s); \ - a += b; \ - } -#define HH(a,b,c,d,x,s,ac) \ - { \ - a += H(b,c,d) + x + ac; \ - a = ROTATE_LEFT(a,s); \ - a += b; \ - } -#define II(a,b,c,d,x,s,ac) \ - { \ - a += I(b,c,d) + x + ac; \ - a = ROTATE_LEFT(a,s); \ - a += b; \ - } -void MD5Init(MD5_CTX *context); -void MD5Update(MD5_CTX *context,unsigned char *input,unsigned int inputlen); -void MD5Final(MD5_CTX *context,unsigned char *digest); -void MD5Transform(unsigned int *state,unsigned char *block); -void MD5Encode(unsigned char *output,unsigned int *input,unsigned int len); -void MD5Decode(unsigned int *output,unsigned char *input,unsigned int len); -void MD5(MD5_t *task); -void MD5_FromString(const char* content, char* result); - -#endif \ No newline at end of file diff --git a/hash/SHA256.c b/hash/SHA256.c deleted file mode 100755 index f65f34e25c5aa9aea6fc53982384d1943f935d55..0000000000000000000000000000000000000000 --- a/hash/SHA256.c +++ /dev/null @@ -1,121 +0,0 @@ -// SHA256.c - -#include "SHA256.h" - -#define rightrotate(w, n) ((w >> n) | (w) << (32-(n))) -#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ -#define copy_uint32(p, val) *((uint32_t *)p) = __builtin_bswap32((val))//gcc 内建函数__builtin_bswap32, -#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ -#define copy_uint32(p, val) *((uint32_t *)p) = (val) -#else -#error "Unsupported target architecture endianess!" -#endif - -static const uint32_t k[64] = { - 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, - 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, - 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, - 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, - 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, - 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, - 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, - 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 -}; - -void __SHA256__(const unsigned char *data, size_t len, unsigned char *out) { - uint32_t h0 = 0x6a09e667; - uint32_t h1 = 0xbb67ae85; - uint32_t h2 = 0x3c6ef372; - uint32_t h3 = 0xa54ff53a; - uint32_t h4 = 0x510e527f; - uint32_t h5 = 0x9b05688c; - uint32_t h6 = 0x1f83d9ab; - uint32_t h7 = 0x5be0cd19; - int r = (int)(len * 8 % 512); - int append = ((r < 448) ? (448 - r) : (448 + 512 - r)) / 8; - size_t new_len = len + append + 8; // 原始数据+填充+64bit位数 - unsigned char buf[new_len]; - //将内存(字符串)前n个字节清零 - memset(buf + len, 0, sizeof(char)*append); - if (len > 0) { - memcpy(buf, data, len); - } - buf[len] = (unsigned char)0x80; - uint64_t bits_len = len * 8; - for (int i = 0; i < 8; i++) { - buf[len + append + i] = (bits_len >> ((7 - i) * 8)) & 0xff; - } - uint32_t w[64]; - memset(w, 0, sizeof(uint32_t)*64); - size_t chunk_len = new_len / 64; //分512bit区块 - for (int idx = 0; idx < chunk_len; idx++) { - uint32_t val = 0; - for (int i = 0; i < 64; i++) { //将块分解为16个32-bit的big-endian的字,记为w[0], …, w[15] - val = val | (*(buf + idx * 64 + i) << (8 * (3 - i))); - if (i % 4 == 3) { - w[i / 4] = val; - val = 0; - } - } - for (int i = 16; i < 64; i++) { //前16个字直接由以上消息的第i个块分解得到,其余的字由如下迭代公式得到: - uint32_t s0 = rightrotate(w[i - 15], 7) ^ rightrotate(w[i - 15], 18) ^ (w[i - 15] >> 3); - uint32_t s1 = rightrotate(w[i - 2], 17) ^ rightrotate(w[i - 2], 19) ^ (w[i - 2] >> 10); - w[i] = w[i - 16] + s0 + w[i - 7] + s1; - } - - uint32_t a = h0; - uint32_t b = h1; - uint32_t c = h2; - uint32_t d = h3; - uint32_t e = h4; - uint32_t f = h5; - uint32_t g = h6; - uint32_t h = h7; - for (int i = 0; i < 64; i++) {// - uint32_t s_1 = rightrotate(e, 6) ^ rightrotate(e, 11) ^ rightrotate(e, 25); - uint32_t ch = (e & f) ^ (~e & g); - uint32_t temp1 = h + s_1 + ch + k[i] + w[i]; - uint32_t s_0 = rightrotate(a, 2) ^ rightrotate(a, 13) ^ rightrotate(a, 22); - uint32_t maj = (a & b) ^ (a & c) ^ (b & c); - uint32_t temp2 = s_0 + maj; - h = g; - g = f; - f = e; - e = d + temp1; - d = c; - c = b; - b = a; - a = temp1 + temp2; - } - h0 += a; - h1 += b; - h2 += c; - h3 += d; - h4 += e; - h5 += f; - h6 += g; - h7 += h; - } - copy_uint32(out, h0); - copy_uint32(out + 1, h1); - copy_uint32(out + 2, h2); - copy_uint32(out + 3, h3); - copy_uint32(out + 4, h4); - copy_uint32(out + 5, h5); - copy_uint32(out + 6, h6); - copy_uint32(out + 7, h7); -} - -void SHA256(SHA256_t *task) -{ - /* - - */ - const unsigned char *content = task->content; - unsigned char buffer[32]; - memset(buffer, 0, 32); - __SHA256__(content, strlen((void*)content), buffer); - - for (int i=0; i<32; i++) - sprintf((char*)&(task->result[i*2]), "%02X", buffer[i]); -} \ No newline at end of file diff --git a/hash/SHA256.h b/hash/SHA256.h deleted file mode 100755 index 92f52efbeebfe0c5ad126555d6271fb40d977e17..0000000000000000000000000000000000000000 --- a/hash/SHA256.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef LOSU_SHA256_H__ -#define LOSU_SHA256_H__ - -/* - 使用方法: - 1.构造SHA256_t - 2.传入void SHA256(SHA256_t *task)中 - 3.从SHA256_t.result中得到结果 -*/ - - -#include -#include -#include -#include - -typedef struct -{ - const unsigned char *content; - unsigned char result[65]; -} SHA256_t; - -void __SHA256__(const unsigned char *data, size_t len, unsigned char *out); -void SHA256(SHA256_t *task); - -#endif \ No newline at end of file diff --git a/hash/SHA384.c b/hash/SHA384.c deleted file mode 100755 index a6498d66db77378951d25ea3548475a997aaa322..0000000000000000000000000000000000000000 --- a/hash/SHA384.c +++ /dev/null @@ -1,172 +0,0 @@ -#include "SHA384.h" - -uint64_t Ch(uint64_t X, uint64_t Y, uint64_t Z) -{ - return (X & Y) ^ ((~X) & Z); -} - -uint64_t Maj(uint64_t X, uint64_t Y, uint64_t Z) -{ - return (X & Y) ^ (X & Z) ^ (Y & Z); -} - -/* 循环向右移动offset个比特位 */ -uint64_t ROTR(uint64_t X, uint64_t offset) -{ - return (X >> offset) | (X << (64 - offset)); -} - -/* 向右移动offset个比特位 */ -uint64_t SHR(uint64_t X, uint64_t offset) -{ - return X >> offset; -} - -/* SIGMA0 */ -uint64_t SIGMA0(uint64_t X) -{ - return ROTR(X, 28) ^ ROTR(X, 34) ^ ROTR(X, 39); -} - -/* SIGMA1 */ -uint64_t SIGMA1(uint64_t X) -{ - return ROTR(X, 14) ^ ROTR(X, 18) ^ ROTR(X, 41); -} - -/* sigma0, different from SIGMA0 */ -uint64_t sigma0(uint64_t X) -{ - return ROTR(X, 1) ^ ROTR(X, 8) ^ SHR(X, 7); -} - -/* sigma1, different from SIGMA1 */ -uint64_t sigma1(uint64_t X) -{ - return ROTR(X, 19) ^ ROTR(X, 61) ^ SHR(X, 6); -} - - - -/* 此处的inlen用int不合理 但我们只是研究学习算法 不作为实际应用 */ -int sha2_384(unsigned char *out, const unsigned char* in, const long long inlen) -{ - ASSERT_RETURN_INT(out && in && (inlen >= 0), 1); - int i = 0, j = 0, t = 0; - - // step 1: 字节填充(Append Padding Bytes) - // 数据先补上1个1比特,再补上k个0比特,使得补位后的数据比特数(n+1+k)满足(n+1+k) mod 1024 = 896,k取最小正整数 - int iX = inlen / HASH_BLOCK_SIZE; - int iY = inlen % HASH_BLOCK_SIZE; - iX = (iY < HASH_LEN_OFFSET) ? iX : (iX + 1); - - int iLen = (iX + 1) * HASH_BLOCK_SIZE; - unsigned char* X = malloc(iLen); - memcpy(X, in, inlen); - // 先补上1个1比特+7个0比特 - X[inlen] = 0x80; - // 再补上(k-7)个0比特 - for (i = inlen + 1; i < (iX * HASH_BLOCK_SIZE + HASH_LEN_OFFSET); i++) - { - X[i] = 0; - } - - // step 2: 追加长度信息(Append Length) [此处inlen是按int处理的p[0~7]直接写死0 ] - uint8_t *pLen = X + (iX * HASH_BLOCK_SIZE + HASH_LEN_OFFSET); - uint64_t iTempLen = inlen << 3; - uint8_t *pTempLen = (void*)&iTempLen; - pLen[0] = 0; pLen[1] = 0; pLen[2] = 0; pLen[3] = 0; - pLen[4] = 0; pLen[5] = 0; pLen[6] = 0; pLen[7] = 0; - pLen[8] = pTempLen[7]; pLen[9] = pTempLen[6]; pLen[10] = pTempLen[5]; pLen[11] = pTempLen[4]; - pLen[12] = pTempLen[3]; pLen[13] = pTempLen[2]; pLen[14] = pTempLen[1]; pLen[15] = pTempLen[0]; - - // Step 3. 初始化MD Buffer(Initialize MD Buffer) - uint64_t H0 = 0xCBBB9D5DC1059ED8; - uint64_t H1 = 0x629A292A367CD507; - uint64_t H2 = 0x9159015A3070DD17; - uint64_t H3 = 0x152FECD8F70E5939; - uint64_t H4 = 0x67332667FFC00B31; - uint64_t H5 = 0x8EB44A8768581511; - uint64_t H6 = 0xDB0C2E0D64F98FA7; - uint64_t H7 = 0x47B5481DBEFA4FA4; - - uint64_t M[HASH_BLOCK_SIZE / 8] = { 0 }; - uint64_t W[HASH_ROUND_NUM] = { 0 }; - - // step 4: 处理消息块(Process Message in 64-Byte Blocks) - for (i = 0; i < iLen / HASH_BLOCK_SIZE; i++) - { - /* Copy block i into M. */ - for (j = 0; j < HASH_BLOCK_SIZE; j = j + 8) - { - uint64_t k = i * HASH_BLOCK_SIZE + j; - M[j / 8] = ((uint64_t)X[k] << 56) | ((uint64_t)X[k + 1] << 48) | ((uint64_t)X[k + 2] << 40) | ((uint64_t)X[k + 3] << 32) - | ((uint64_t)X[k + 4] << 24) | ((uint64_t)X[k + 5] << 16) | ((uint64_t)X[k + 6] << 8) | (uint64_t)X[k + 7]; - } - - /* W[t]=M[t]; t:[0,15] */ - for (t = 0; t <= 15; t++) - { - W[t] = M[t]; - } - /* W[t] = sigma1(W[t - 2]) + W[t - 7] + sigma0(W[t - 15]) + W[t - 16]; t:[16,63] */ - for (t = 16; t < HASH_ROUND_NUM; t++) - { - W[t] = sigma1(W[t - 2]) + W[t - 7] + sigma0(W[t - 15]) + W[t - 16]; - } - - uint64_t A = H0; - uint64_t B = H1; - uint64_t C = H2; - uint64_t D = H3; - uint64_t E = H4; - uint64_t F = H5; - uint64_t G = H6; - uint64_t H = H7; - - for (t = 0; t < HASH_ROUND_NUM; t++) - { - uint64_t T1 = H + SIGMA1(E) + Ch(E, F, G) + SHA384_K[t] + W[t]; - uint64_t T2 = SIGMA0(A) + Maj(A, B, C); - H = G; - G = F; - F = E; - E = D + T1; - D = C; - C = B; - B = A; - A = T1 + T2; - } - - H0 = H0 + A; - H1 = H1 + B; - H2 = H2 + C; - H3 = H3 + D; - H4 = H4 + E; - H5 = H5 + F; - H6 = H6 + G; - H7 = H7 + H; - } - - // step 5: 输出 - uint64_t* pOut = (void*)(uint8_t*)out; - pOut[0] = __bswap_64(H0); - pOut[1] = __bswap_64(H1); - pOut[2] = __bswap_64(H2); - pOut[3] = __bswap_64(H3); - pOut[4] = __bswap_64(H4); - pOut[5] = __bswap_64(H5); - free(X); - - return 0; -} - -void SHA384(SHA384_t *task) -{ - const unsigned char *content = (void*)task->content; - unsigned char result[48]; - sha2_384(result, content, strlen((void*)content)); - - for (int i=0;i<48;i++) - sprintf((char*)&task->result[i*2], "%02X", result[i]); -} \ No newline at end of file diff --git a/hash/SHA384.h b/hash/SHA384.h deleted file mode 100755 index 919836a9fed3697ca404d9017db8d613878f7fa4..0000000000000000000000000000000000000000 --- a/hash/SHA384.h +++ /dev/null @@ -1,96 +0,0 @@ -#ifndef LOSU_SHA384_H__ -#define LOSU_SHA384_H__ - -/* - 使用方法 - 1.创建SHA384_t - 2.放入void SHA382(SHA384_t *task) - 3.从SHA384_t.result得到结果 -*/ - -#include -#include -#include -#include - -#ifndef HASH_BLOCK_SIZE -#define HASH_BLOCK_SIZE 128 /* 1024 bits = 128 bytes */ -#endif - -#ifndef HASH_LEN_SIZE -#define HASH_LEN_SIZE 16 /* 128 bits = 16 bytes */ -#endif - -#ifndef HASH_LEN_OFFSET -#define HASH_LEN_OFFSET 112 /* 128 bytes - 16 bytes */ -#endif - -#ifndef HASH_ROUND_NUM -#define HASH_ROUND_NUM 80 -#endif - -typedef struct -{ - uint64_t high; /* high 64 bits */ - uint64_t low; /* low 64 bits */ -} uint128_t; - -typedef struct -{ - /* - 高层结构 - */ - const unsigned char *content; - unsigned char result[97]; -} SHA384_t; - -/* SHA512 Constants */ -static const uint64_t SHA384_K[HASH_ROUND_NUM] = -{ - 0x428A2F98D728AE22, 0x7137449123EF65CD, 0xB5C0FBCFEC4D3B2F, 0xE9B5DBA58189DBBC, - 0x3956C25BF348B538, 0x59F111F1B605D019, 0x923F82A4AF194F9B, 0xAB1C5ED5DA6D8118, - 0xD807AA98A3030242, 0x12835B0145706FBE, 0x243185BE4EE4B28C, 0x550C7DC3D5FFB4E2, - 0x72BE5D74F27B896F, 0x80DEB1FE3B1696B1, 0x9BDC06A725C71235, 0xC19BF174CF692694, - 0xE49B69C19EF14AD2, 0xEFBE4786384F25E3, 0x0FC19DC68B8CD5B5, 0x240CA1CC77AC9C65, - 0x2DE92C6F592B0275, 0x4A7484AA6EA6E483, 0x5CB0A9DCBD41FBD4, 0x76F988DA831153B5, - 0x983E5152EE66DFAB, 0xA831C66D2DB43210, 0xB00327C898FB213F, 0xBF597FC7BEEF0EE4, - 0xC6E00BF33DA88FC2, 0xD5A79147930AA725, 0x06CA6351E003826F, 0x142929670A0E6E70, - 0x27B70A8546D22FFC, 0x2E1B21385C26C926, 0x4D2C6DFC5AC42AED, 0x53380D139D95B3DF, - 0x650A73548BAF63DE, 0x766A0ABB3C77B2A8, 0x81C2C92E47EDAEE6, 0x92722C851482353B, - 0xA2BFE8A14CF10364, 0xA81A664BBC423001, 0xC24B8B70D0F89791, 0xC76C51A30654BE30, - 0xD192E819D6EF5218, 0xD69906245565A910, 0xF40E35855771202A, 0x106AA07032BBD1B8, - 0x19A4C116B8D2D0C8, 0x1E376C085141AB53, 0x2748774CDF8EEB99, 0x34B0BCB5E19B48A8, - 0x391C0CB3C5C95A63, 0x4ED8AA4AE3418ACB, 0x5B9CCA4F7763E373, 0x682E6FF3D6B2B8A3, - 0x748F82EE5DEFB2FC, 0x78A5636F43172F60, 0x84C87814A1F0AB72, 0x8CC702081A6439EC, - 0x90BEFFFA23631E28, 0xA4506CEBDE82BDE9, 0xBEF9A3F7B2C67915, 0xC67178F2E372532B, - 0xCA273ECEEA26619C, 0xD186B8C721C0C207, 0xEADA7DD6CDE0EB1E, 0xF57D4F7FEE6ED178, - 0x06F067AA72176FBA, 0x0A637DC5A2C898A6, 0x113F9804BEF90DAE, 0x1B710B35131C471B, - 0x28DB77F523047D84, 0x32CAAB7B40C72493, 0x3C9EBE0A15C9BEBC, 0x431D67C49C100D4C, - 0x4CC5D4BECB3E42B6, 0x597F299CFC657E2A, 0x5FCB6FAB3AD6FAEC, 0x6C44198C4A475817 -}; - -/* Swap bytes in 64 bit value. 0x0123456789ABCDEF -> 0xEFCDAB8967452301*/ -#define __bswap_64(x) \ - ((((x) & 0xff00000000000000ull) >> 56) \ - | (((x) & 0x00ff000000000000ull) >> 40) \ - | (((x) & 0x0000ff0000000000ull) >> 24) \ - | (((x) & 0x000000ff00000000ull) >> 8) \ - | (((x) & 0x00000000ff000000ull) << 8) \ - | (((x) & 0x0000000000ff0000ull) << 24) \ - | (((x) & 0x000000000000ff00ull) << 40) \ - | (((x) & 0x00000000000000ffull) << 56)) - -#define ASSERT_RETURN_INT(x, d) if(!(x)) { return d; } - -uint64_t Ch(uint64_t X, uint64_t Y, uint64_t Z); -uint64_t Maj(uint64_t X, uint64_t Y, uint64_t Z); -uint64_t ROTR(uint64_t X, uint64_t offset); -uint64_t SHR(uint64_t X, uint64_t offset); -uint64_t SIGMA0(uint64_t X); -uint64_t SIGMA1(uint64_t X); -uint64_t sigma0(uint64_t X); -uint64_t sigma1(uint64_t X); -int sha2_384(unsigned char *out, const unsigned char* in, const long long inlen); -void SHA384(SHA384_t *task); - -#endif \ No newline at end of file diff --git a/hash/SHA512.c b/hash/SHA512.c deleted file mode 100755 index 5a16d3be45794b632f11be961c10fc635de09663..0000000000000000000000000000000000000000 --- a/hash/SHA512.c +++ /dev/null @@ -1,191 +0,0 @@ -#include -#include -#include -#include "SHA512.h" - -// 循环右移(64位) -#define SHA512_ROR64( value, bits ) (((value) >> (bits)) | ((value) << (64 - (bits)))) - -////////////////////////////////////////////////////// -// // -// SHA512_CH,:Maj操作 // -// SHA512_S:循环右移 SHA512_R:同2**128除余右移 // -// SHA512_Sigma0:Sigma0函数 // -// SHA512_Sigma1:Sigma2函数 // -// SHA512_Gamma0:Gamma0函数 // -// SHA512_Gamma1:Gamma1函数 // -////////////////////////////////////////////////////// - -#define SHA512_CH( x, y, z ) (z ^ (x & (y ^ z))) -#define SHA512_Maj(x, y, z ) (((x | y) & z) | (x & y)) -#define SHA512_S( x, n ) SHA512_ROR64( x, n ) -#define SHA512_R( x, n ) (((x)&0xFFFFFFFFFFFFFFFFULL)>>((unsigned long long)n)) -#define SHA512_Sigma0( x ) (SHA512_S(x, 28) ^ SHA512_S(x, 34) ^ SHA512_S(x, 39)) -#define SHA512_Sigma1( x ) (SHA512_S(x, 14) ^ SHA512_S(x, 18) ^ SHA512_S(x, 41)) -#define SHA512_Gamma0( x ) (SHA512_S(x, 1) ^ SHA512_S(x, 8) ^ SHA512_R(x, 7)) -#define SHA512_Gamma1( x ) (SHA512_S(x, 19) ^ SHA512_S(x, 61) ^ SHA512_R(x, 6)) - -#define Sha512Round( a, b, c, d, e, f, g, h, i ) \ - t0 = h + SHA512_Sigma1(e) + SHA512_CH(e, f, g) + K[i] + W[i]; \ - t1 = SHA512_Sigma0(a) + SHA512_Maj(a, b, c); \ - d += t0; \ - h = t0 + t1; - -// 用于补齐的数,最多补128字节也就是1024bit -unsigned char SHA512_PADDING[] = { - 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -}; - -void SHA512Init(SHA512_CB *context) { - context->count[0] = 0; - context->count[1] = 0; - context->state[0] = 0x6a09e667f3bcc908ULL; - context->state[1] = 0xbb67ae8584caa73bULL; - context->state[2] = 0x3c6ef372fe94f82bULL; - context->state[3] = 0xa54ff53a5f1d36f1ULL; - context->state[4] = 0x510e527fade682d1ULL; - context->state[5] = 0x9b05688c2b3e6c1fULL; - context->state[6] = 0x1f83d9abfb41bd6bULL; - context->state[7] = 0x5be0cd19137e2179ULL; -} - -void SHA512Update(SHA512_CB *context, unsigned char *input, unsigned long long inputlen) { - unsigned long long index = 0, partlen = 0, i = 0; // i记录input的当前位置(初始为0) - index = (context->count[1] >> 3) & 0x7F; //index:总字长除127(11111111)取余后的余数 - partlen = 128 - index; //partlen:同128相差的长度 - context->count[1] += inputlen << 3; //更新count - - // 统计字符的bit长度,如果小于说明类型溢出了(64bit)无法装下了 - // 由于最后留下128bit填充字符长度,因而必须引入count[1]保存 - // 64bit+64bit=128bit - if (context->count[1] < (inputlen << 3)) - context->count[0]++; - //右移动61位后就是count[0]应该记录的值。(左移3位,溢出的就是右移动61位的) - context->count[0] += inputlen >> 61; - - ////////////////////////////////////////////////////////// - // // - // 如果此次更新的长度,大于原长度同128做差的值, // - // .ie. 加上刚更新的长度满足了128Bytes(1024位) // - // 因而可以进行一次加密循环 // - // // - ////////////////////////////////////////////////////////// - - if (inputlen >= partlen) - { - //将缺的partlen个字节数据加入缓冲区 - memcpy(&context->buffer[index], input, partlen); - SHA512Transform(context->state, context->buffer); - - // 如果输入的字,还可以进行(还有整128字的)就继续进行一次加密循环 - - for (i = partlen; i + 128 <= inputlen; i += 128) - SHA512Transform(context->state, &input[i]); - // 将当前位置设为0 - index = 0; - } - else - { - i = 0; - } - // 重新设置buffer区(处理过的字被覆盖成新字) - memcpy(&context->buffer[index], &input[i], inputlen - i); -} - -void SHA512Final(SHA512_CB *context, unsigned char *digest) { - unsigned int index = 0, padlen = 0; - unsigned char bits[16]; // 记录字长信息 - index = (context->count[1] >> 3) & 0x7F; // 字长除127(11111111)取余长度 - padlen = (index < 112) ? (112 - index) : (240 - index); // 补齐的字长 - SHA512Encode(bits, context->count, 16); - SHA512Update(context, SHA512_PADDING, padlen); - SHA512Update(context, bits, 16); - SHA512Encode(digest, context->state, 64); -} - -void SHA512Encode(unsigned char *output, unsigned long long *input, unsigned long long len) { - unsigned long long i = 0, j = 0; - while (j < len) - { - output[j+7] = input[i] & 0xFF; - output[j + 6] = (input[i] >> 8) & 0xFF; //0xFF:11111111 - output[j + 5] = (input[i] >> 16) & 0xFF; - output[j + 4] = (input[i] >> 24) & 0xFF; - output[j + 3] = (input[i] >> 32) & 0xFF; - output[j + 2] = (input[i] >> 40) & 0xFF; - output[j + 1] = (input[i] >> 48) & 0xFF; - output[j] = (input[i] >> 56) & 0xFF; - i++; - j += 8; - } -} - - -void SHA512Decode(unsigned long long *output, unsigned char *input, unsigned long long len) { - unsigned long long i = 0, j = 0; - while (j < len) - { - output[i] = ((unsigned long long)input[j+7]) | - ((unsigned long long)input[j + 6] << 8) | - ((unsigned long long)input[j + 5] << 16) | - ((unsigned long long)input[j + 4] << 24) | - ((unsigned long long)input[j + 3] << 32) | - ((unsigned long long)input[j + 2] << 40) | - ((unsigned long long)input[j + 1] << 48) | - ((unsigned long long)input[j] << 56); - i++; - j += 8; - } -} - -void SHA512Transform(unsigned long long *state, unsigned char *block) { - unsigned long long SHA512_S[8]; - unsigned long long W[80]; - unsigned long long t0; - unsigned long long t1; - int i = 0; - - // 把state的值复制给S - for ( i = 0; i < 8; i++ ) - SHA512_S[i] = state[i]; - - // 将字符数组保存的编码转为unsigned long long - SHA512Decode(W, block, 128); - - for ( i = 16; i < 80; i++ ) - W[i] = SHA512_Gamma1(W[i - 2]) + W[i - 7] + SHA512_Gamma0(W[i - 15]) + W[i - 16]; - - for ( i = 0; i < 80; i += 8 ) - { - Sha512Round(SHA512_S[0], SHA512_S[1], SHA512_S[2], SHA512_S[3], SHA512_S[4], SHA512_S[5], SHA512_S[6], SHA512_S[7], i + 0); - Sha512Round(SHA512_S[7], SHA512_S[0], SHA512_S[1], SHA512_S[2], SHA512_S[3], SHA512_S[4], SHA512_S[5], SHA512_S[6], i + 1); - Sha512Round(SHA512_S[6], SHA512_S[7], SHA512_S[0], SHA512_S[1], SHA512_S[2], SHA512_S[3], SHA512_S[4], SHA512_S[5], i + 2); - Sha512Round(SHA512_S[5], SHA512_S[6], SHA512_S[7], SHA512_S[0], SHA512_S[1], SHA512_S[2], SHA512_S[3], SHA512_S[4], i + 3); - Sha512Round(SHA512_S[4], SHA512_S[5], SHA512_S[6], SHA512_S[7], SHA512_S[0], SHA512_S[1], SHA512_S[2], SHA512_S[3], i + 4); - Sha512Round(SHA512_S[3], SHA512_S[4], SHA512_S[5], SHA512_S[6], SHA512_S[7], SHA512_S[0], SHA512_S[1], SHA512_S[2], i + 5); - Sha512Round(SHA512_S[2], SHA512_S[3], SHA512_S[4], SHA512_S[5], SHA512_S[6], SHA512_S[7], SHA512_S[0], SHA512_S[1], i + 6); - Sha512Round(SHA512_S[1], SHA512_S[2], SHA512_S[3], SHA512_S[4], SHA512_S[5], SHA512_S[6], SHA512_S[7], SHA512_S[0], i + 7); - } - - // Feedback - for ( i = 0; i < 8; i++ ) - state[i] = state[i] + SHA512_S[i]; -} - -void SHA512(SHA512_t *task) -{ - const unsigned char *content = task->content; - unsigned char result[64]; - SHA512_CB sha512; - - SHA512Init(&sha512); - SHA512Update(&sha512, (unsigned char*)content, strlen((char*)content)); - SHA512Final(&sha512, result); - - //将结果转化为字符串 - for (int i=0; i<64; i++) - sprintf((char*)&(task->result[i*2]), "%02X", result[i]); -} \ No newline at end of file diff --git a/hash/SHA512.h b/hash/SHA512.h deleted file mode 100755 index 52eddbd897512e20bf3b9ec7f213f741c62f3612..0000000000000000000000000000000000000000 --- a/hash/SHA512.h +++ /dev/null @@ -1,72 +0,0 @@ -#ifndef LOSU_SHA512_H__ -#define LOSU_SHA512_H__ - -////////////////////////////////////////////////////////// -// SHA512_CB(control block) // -// SHA512_CB:SHA512控制块,包含算法运算过程中将用到的信息// -// count[2]:记录128位的数字长度(两个64位) // -// state[8]:A-H八个初始常量(64bit) // -// buffer[128]:用于每次运算的1024bit // -// // -////////////////////////////////////////////////////////// - -typedef struct -{ - unsigned long long count[2]; - unsigned long long state[8]; - unsigned char buffer[128]; -} SHA512_CB; - -typedef struct -{ - const unsigned char *content; - unsigned char result[1014]; -} SHA512_t; - - - -// 每次子循环中用到的常量 -// 后面加ULL表示long long -static const unsigned long long K[80] = { - 0x428a2f98d728ae22ULL, 0x7137449123ef65cdULL, 0xb5c0fbcfec4d3b2fULL, 0xe9b5dba58189dbbcULL, - 0x3956c25bf348b538ULL, 0x59f111f1b605d019ULL, 0x923f82a4af194f9bULL, 0xab1c5ed5da6d8118ULL, - 0xd807aa98a3030242ULL, 0x12835b0145706fbeULL, 0x243185be4ee4b28cULL, 0x550c7dc3d5ffb4e2ULL, - 0x72be5d74f27b896fULL, 0x80deb1fe3b1696b1ULL, 0x9bdc06a725c71235ULL, 0xc19bf174cf692694ULL, - 0xe49b69c19ef14ad2ULL, 0xefbe4786384f25e3ULL, 0x0fc19dc68b8cd5b5ULL, 0x240ca1cc77ac9c65ULL, - 0x2de92c6f592b0275ULL, 0x4a7484aa6ea6e483ULL, 0x5cb0a9dcbd41fbd4ULL, 0x76f988da831153b5ULL, - 0x983e5152ee66dfabULL, 0xa831c66d2db43210ULL, 0xb00327c898fb213fULL, 0xbf597fc7beef0ee4ULL, - 0xc6e00bf33da88fc2ULL, 0xd5a79147930aa725ULL, 0x06ca6351e003826fULL, 0x142929670a0e6e70ULL, - 0x27b70a8546d22ffcULL, 0x2e1b21385c26c926ULL, 0x4d2c6dfc5ac42aedULL, 0x53380d139d95b3dfULL, - 0x650a73548baf63deULL, 0x766a0abb3c77b2a8ULL, 0x81c2c92e47edaee6ULL, 0x92722c851482353bULL, - 0xa2bfe8a14cf10364ULL, 0xa81a664bbc423001ULL, 0xc24b8b70d0f89791ULL, 0xc76c51a30654be30ULL, - 0xd192e819d6ef5218ULL, 0xd69906245565a910ULL, 0xf40e35855771202aULL, 0x106aa07032bbd1b8ULL, - 0x19a4c116b8d2d0c8ULL, 0x1e376c085141ab53ULL, 0x2748774cdf8eeb99ULL, 0x34b0bcb5e19b48a8ULL, - 0x391c0cb3c5c95a63ULL, 0x4ed8aa4ae3418acbULL, 0x5b9cca4f7763e373ULL, 0x682e6ff3d6b2b8a3ULL, - 0x748f82ee5defb2fcULL, 0x78a5636f43172f60ULL, 0x84c87814a1f0ab72ULL, 0x8cc702081a6439ecULL, - 0x90befffa23631e28ULL, 0xa4506cebde82bde9ULL, 0xbef9a3f7b2c67915ULL, 0xc67178f2e372532bULL, - 0xca273eceea26619cULL, 0xd186b8c721c0c207ULL, 0xeada7dd6cde0eb1eULL, 0xf57d4f7fee6ed178ULL, - 0x06f067aa72176fbaULL, 0x0a637dc5a2c898a6ULL, 0x113f9804bef90daeULL, 0x1b710b35131c471bULL, - 0x28db77f523047d84ULL, 0x32caab7b40c72493ULL, 0x3c9ebe0a15c9bebcULL, 0x431d67c49c100d4cULL, - 0x4cc5d4becb3e42b6ULL, 0x597f299cfc657e2aULL, 0x5fcb6fab3ad6faecULL, 0x6c44198c4a475817ULL -}; -// 初始化函数,初始化SHA_CB的各个值 -void SHA512Init(SHA512_CB *context); - -// 将数据加入 -void SHA512Update(SHA512_CB *context, unsigned char *input, unsigned long long inputlen); - -// 处理完最后再调用,这个处理尾数 -void SHA512Final(SHA512_CB *context, unsigned char *digest); - -// 加密处理函数:Hash加密的核心工厂 -void SHA512Transform(unsigned long long *state, unsigned char *block); - -// 编码函数:将整型编码转为字符 -void SHA512Encode(unsigned char *output, unsigned long long *input, unsigned long long len); - -// 解码函数:将字符数组保存的编码转为整型 -void SHA512Decode(unsigned long long *output, unsigned char *input, unsigned long long len); - -//总处理函数 -void SHA512(SHA512_t *task); -#endif \ No newline at end of file diff --git a/hash/Ubuntu/makefile b/hash/Ubuntu/makefile deleted file mode 100755 index b8c7529d14b0662ac2b159869275c0f358802d35..0000000000000000000000000000000000000000 --- a/hash/Ubuntu/makefile +++ /dev/null @@ -1,13 +0,0 @@ -OBJS = hash.o MD5.o SHA256.o SHA384.o SHA512.o -CFLAGS= -O3 -std=c99 -Wall -DLOSU_LINUX -I ../buildenv -fPIC -CC=x86_64-linux-gnu-gcc -T=./ElsLib_hash.lsd - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -shared -lm -s - -clean: - rm -rf $T $(OBJS) core core.* \ No newline at end of file diff --git a/hash/Windows/makefile b/hash/Windows/makefile deleted file mode 100755 index 2e0eb487a6dd012d622677e2387d4bebe3fff81d..0000000000000000000000000000000000000000 --- a/hash/Windows/makefile +++ /dev/null @@ -1,13 +0,0 @@ -OBJS = hash.o MD5.o SHA256.o SHA384.o SHA512.o -CFLAGS= -O3 -std=c99 -Wall -DLOSU_WINDOWS -I ../buildenv -fPIC -CC=x86_64-w64-mingw32-gcc -T=ElsLib_hash.lsd - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -L ../buildenv -l:libeasylosu.dll -lm -static -shared -s - -clean: - rm -rf $T $(OBJS) core core.* \ No newline at end of file diff --git a/hash/hash.c b/hash/hash.c deleted file mode 100755 index 68a9764e216ef80817c4d36da0e624afff2a08f7..0000000000000000000000000000000000000000 --- a/hash/hash.c +++ /dev/null @@ -1,68 +0,0 @@ -#include "hash.h" -#include "MD5.h" -#include "SHA256.h" -#include "SHA384.h" -#include "SHA512.h" - -int ELSAPI_hash_md5(els_VmObj* vm) -{ - /* - md5算法接口 - - # 参数 - 1.content 要摘要的字符串 - - # 返回值 - 1.result 对应的MD5值 - */ - MD5_t task; - task.content = (void*)arg_getstr(vm, 1); - MD5(&task); - arg_returnstr(vm, task.result); - return 1; -} - -int ELSAPI_hash_sha256(els_VmObj* vm) -{ - /* - sha256算法接口 - - # 参数 - 1.content 要摘要的字符串 - - # 返回值 - 1.result 对应的sha256值 - */ - SHA256_t task; - task.content = (void*)arg_getstr(vm, 1); - SHA256(&task); - arg_returnstr(vm, (void*)task.result); - return 1; -} - -int ELSAPI_hash_sha384(els_VmObj* vm) -{ - /* - sha384算法接口 - - # 参数 - 1.content 要摘要的字符串 - - # 返回值 - 1.result 对应的sha384值 - */ - SHA384_t task; - task.content = (void*)arg_getstr(vm, 1); - SHA384(&task); - arg_returnstr(vm, (void*)task.result); - return 1; -} - -int ELSAPI_hash_sha512(els_VmObj* vm) -{ - SHA512_t task; - task.content = (void*)arg_getstr(vm, 1); - SHA512(&task); - arg_returnstr(vm, (void*)task.result); - return 1; -} \ No newline at end of file diff --git a/hash/hash.els b/hash/hash.els deleted file mode 100755 index 5cc0293c0fa22fad21256b23fefdef2eabcaface..0000000000000000000000000000000000000000 --- a/hash/hash.els +++ /dev/null @@ -1,6 +0,0 @@ -#!declare -md5( content:string ): string #md5摘要算法接口,接受一个字符串,返回对应的MD5值 -sha256( content:string ): string #sha256摘要算法接口,接受一个字符串,返回对应的sha256值 -sha384( content:string ): string #sha384摘要算法接口,接受一个字符串,返回对应的sha384值 -sha512( content:string ): string #sha512摘要算法接口,接受一个字符串,返回对应的sha512值 -#!end \ No newline at end of file diff --git a/hash/hash.h b/hash/hash.h deleted file mode 100755 index 209b3b5f1e7d8e95ec14c1c930eed0f09b1d8780..0000000000000000000000000000000000000000 --- a/hash/hash.h +++ /dev/null @@ -1,11 +0,0 @@ -#include "els.h" -int ELSAPI_hash_md5(els_VmObj* vm); // md5( content:string ): string #md5摘要算法接口,接受一个字符串,返回对应的MD5值 -int ELSAPI_hash_sha256(els_VmObj* vm); // sha256( content:string ): string #sha256摘要算法接口,接受一个字符串,返回对应的sha256值 -int ELSAPI_hash_sha384(els_VmObj* vm); // sha384( content:string ): string #sha384摘要算法接口,接受一个字符串,返回对应的sha384值 -int ELSAPI_hash_sha512(els_VmObj* vm); // sha512( content:string ): string #sha512摘要算法接口,接受一个字符串,返回对应的sha512值 -void ElsLib_hash_libinit(els_VmObj *vm){ - vm_register(vm,"sha256",ELSAPI_hash_sha256); - vm_register(vm,"sha384",ELSAPI_hash_sha384); - vm_register(vm,"md5",ELSAPI_hash_md5); - vm_register(vm,"sha512",ELSAPI_hash_sha512); -}; diff --git a/hash/info b/hash/info deleted file mode 100755 index 1970a038995fac6bdb2c79319d7e8503a595d330..0000000000000000000000000000000000000000 --- a/hash/info +++ /dev/null @@ -1,29 +0,0 @@ -{ - info = { - name = "hash/哈希模块", - text = "哈希算法模块", - version = "23.9.5", - }, - source = { - all = { - "hash.c", - "hash.els", - "hash.h", - "MD5.c", - "MD5.h", - "SHA256.c", - "SHA256.h", - "SHA384.h", - "SHA384.c", - "SHA512.h", - "SHA512.c", - "readme.md", - }, - Ubuntu = {"makefile"}, - Windows = {"makefile"}, - }, - target={ - Ubuntu = "make ; cp ElsLib_hash.lsd target/ElsLib_hash.lsd_Ubuntu ; make clean", - Windows = "make ; cp ElsLib_hash.lsd target/ElsLib_hash.lsd_Windows ; make clean", - } -} \ No newline at end of file diff --git a/hash/readme.md b/hash/readme.md deleted file mode 100755 index c1f4c486d27fbb293458c7aa90e7c26c4d2e279c..0000000000000000000000000000000000000000 --- a/hash/readme.md +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/owls.wiki.losu.tech -# wiki for hash - -## 模块简介 -这是一个哈希模块,目前实现了md5、sha256、sha384、sha512摘要算法 - -## 函数详解 -### md5( content:string ): string -+ 该函数无中文版本 -+ 参数 -1. content 要进行md5摘要的内容,因洛书内部统一采用utf-8,所以编码一致 -+ 返回值 -1. 返回32字符的大写md5值 - -### sha256( content:string ):string -+ 该函数无中文版本 -+ 参数 -1. content 要进行sha256摘要的内容 -+ 返回值 -1. 返回64字符的大写sha256值 - -### sha384( content:string ):string -+ 该函数无中文版本 -+ 参数 -1. content 要进行sha256摘要的内容 -+ 返回值 -1. 返回96字符的大写sha384值 - -### sha512( content:string ):string -+ 该函数无中文版本 -+ 参数 -1. content 要进行sha256摘要的内容 -+ 返回值 -1. 返回128字符的大写sha512值 \ No newline at end of file diff --git a/include/losu.h b/include/losu.h new file mode 100755 index 0000000000000000000000000000000000000000..afff726fc4cf993a305110e6dae31e06b178c8c3 --- /dev/null +++ b/include/losu.h @@ -0,0 +1,510 @@ +/* + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +/* + * To introduce Losu into your project, you simply reference this header file + * in the project source code and link the Losu kernel to the target binary + */ + +#ifndef define_included_losu_h +#define define_included_losu_h +#include +#include +#include +#include + +/*! Include LosuConfig + + Include losuconfig.h to configure Losu-Language. + If you don't have losuconfig.h, it will use the default configuration +*/ +#ifndef define_included_losuconfig_h +/* try to include losuconfig.h */ +#ifdef __has_include +#if __has_include("losu_config.h") +#include "losu_config.h" +#endif /* __has_include("losuconfig.h") */ +#else +#include "losu_config.h" +#endif /* __has_include */ + +/* if losuconfig.h is not found, error*/ + +#ifndef define_included_losuconfig_h +#error "Configuration file not found 'losu_config.h'" +#endif /* define_included_losuconfig_h */ +#endif /* define_included_losuconfig_h */ + +/* check config is right? */ + +/*! Limit Vsize_t of Losu-Language + + Losu-Language uses Vsize_t to store the size of variables. + Losu 2.x dropped support for 16-bit processors (still works fine on some + devices),and limiting the instruction set length of the Losu-VM to 32-bit + (new standard, NOT v1.x ). This will improve the performance and + generalizability of Losu code to some extent! + + Q: Does using 32-bit instructions have any negative effect on the + modernization properties of Losu? Does it appear: + 1. only 32-bit executables can be fetched + 2. not be able to access memory space beyond 4G + 3. not being able to use supported libraries on 64-bit systems + 4. ...... + A: No, Losu 2.x does not have any of these problems. + The impact of 32-bit instructions is limited to internal LosuVM,which we can + implement: + 1. provide 64-bit executables + 2. provide more than 4G of memory space for the application + 3. work in coordination with the 64-bit support libraries on the system + + However,As an advanced feature, 64-bit Universal Instruction Set (UIS) + support has been added to Losu 2.x,and is enabled by default on 64-bit + systems, providing better performance, more features and more room for + expansion. + +*/ +#ifndef define_file_losu_h__inline__vsize_t +#define define_file_losu_h__inline__vsize_t + +/* define LosuVmInlineType (ISO-Ctype to Losu-VmCtype) */ + +typedef double _l_number; +typedef uint8_t _l_bool; +typedef uint64_t _l_size_t; +typedef uint32_t _l_hash; +typedef int64_t _l_gcint; + +/* define Losu BitSize as */ +#ifndef vmIns_SizeIns +#ifndef __config_losucore_vm_bitsize +#define __config_losucore_vm_bitsize (__SIZEOF_SIZE_T__ * 8) +#endif /* __config_losucore_vm_bitsize */ + +#define vmIns_SizeIns __config_losucore_vm_bitsize + +#if vmIns_SizeIns == 32 +#define define_file_losu_h_vmbitsize +typedef uint32_t vmInstruction; +#endif /* vmIns_SizeIns == 32 */ + +#if vmIns_SizeIns == 64 +#define define_file_losu_h_vmbitsize +typedef uint64_t vmInstruction; +#endif /* vmIns_SizeIns == 64 */ + +#ifndef define_file_losu_h_vmbitsize +#error "vmIns_SizeIns must be 32 or 64" +#endif /* define_file_losu_h_vmbitsize */ + +#endif /* vmIns_SizeIns */ + +#endif /* define_file_losu_h__inline__vsize_t */ + +/*! Losu Error-Code Subsystem + + Losu 2.x uses a new error-code subsystem,which is more flexible and + powerful,than the old error-code system. + + In the new version, Losu returns different values for different types of + errors and puts the VM in an "error" state, which can be caught and handled + by higher-level programs. +*/ +#ifndef define_file_losu_h__inline__LosuErrorCode +#define define_file_losu_h__inline__LosuErrorCode + +#define LosuErrorCode_Ok 0 /* Success */ +#define LosuErrorCode_Runtime 1 /* Runtime Error */ +#define LosuErrorCode_File 2 /* File Error */ +#define LosuErrorCode_Syntax 3 /* Syntax error */ +#define LosuErrorCode_Mem 4 /* Memory error */ +#define LosuErrorCode_Heap 5 /* Stack Overflow */ +#define LosuErrorCode_Library 6 /* Module loading */ +#define LosuErrorCode_Over -1 /* Catastrophic crash */ + +#endif /* define_file_losu_h__inline__LosuErrorCode */ + +/*! Define Losu Vtype + Losu Vtype is a type that can be used by LosuVm to store different types of + data. It can be abstracted into a unified LosuObj and its aliases, including + strings, numbers, functions, maps, and many other built-in types. +*/ +#ifndef define_file_losu_h__inline__LosuVtype +#define define_file_losu_h__inline__LosuVtype + +/* LosuVm */ +typedef struct LosuVm LosuVm; +/* losuObj */ +typedef struct LosuObj LosuObj; +/* _inlineString */ +typedef struct _inlineString _inlineString; +/* _inlineFunction */ +typedef struct _inlineFunction _inlineFunction; +/* _inlineHash */ +typedef struct _inlineHash _inlineHash; +/* _inlineCallinfo */ +typedef struct _inlineCallinfo _inlineCallinfo; +/* _inlineLocalvar */ +typedef struct _inlineLocalvar _inlineLocalvar; +/* LosuNode */ +typedef struct LosuNode LosuNode; +/* LosuApi */ +typedef int32_t (*LosuApi) (LosuVm *vm); +/* _inlineScode */ +typedef struct _inlineScode _inlineScode; +/* LosuModule */ +typedef struct LosuModule LosuModule; +/* */ +typedef struct LosuPackage_t LosuPackage_t; + +#define LosuTypeDefine_null 0 +#define LosuTypeDefine_number 1 +#define LosuTypeDefine_string 2 +#define LosuTypeDefine_function 3 +#define LosuTypeDefine_unit 4 +#define LosuTypeDefine_ptr 5 +#define LosuTypeDefine_mark 6 +#define LosuTypeDefine_byte 7 + +#endif /* define_file_losu_h__inline__LosuVtype */ + +/*! Declare Export Info, such as copyright,version,API ... + We use `LosuExtern` to export external declarations that follow the C ABI + rules, whether they are integrated into a C or C++ project. +*/ +#ifndef define_file_losu_h__inline__LosuExternInfo +#define define_file_losu_h__inline__LosuExternInfo + +/* check if g++ */ +#ifndef LosuExtern +#ifdef __cplusplus +#define LosuExtern extern "C" +#else +#define LosuExtern extern +#endif +#endif /* LosuExtern */ + +/* Export Value */ +LosuExtern _l_size_t LosuVersionNum; +LosuExtern const char LosuVersion[]; /* Version */ +LosuExtern const char LosuCopyright[]; /* (C)copy */ +LosuExtern const char LosuBuild[]; /* Build info, date,time,patch ... */ +LosuExtern const char LosuArch[]; /* Arch Info,Os and CPU*/ +LosuExtern const char *LosuTypeSystem[]; /* Type System Info */ +LosuExtern LosuPackage_t *LosuPackages; /* Losu Packages */ + +#ifndef define_file_losu_h__inline__losuapi +#define define_file_losu_h__inline__losuapi +/* Export Losu API */ + +/* API: vm_xxx create, control, and manage VM APIs */ + +LosuExtern LosuVm *vm_create (int stacksize); +LosuExtern int vm_init (LosuVm *vm, int32_t argc, const char **argv); +LosuExtern LosuVm *vm_fork (LosuVm *vm, int size); +LosuExtern void vm_stop (LosuVm *vm); +LosuExtern void vm_error (LosuVm *vm, int ecode, const char *estr, ...); +LosuExtern void vm_warning (LosuVm *vm, const char *estr, ...); +LosuExtern int32_t vm_dofile (LosuVm *vm, const char *filename); +LosuExtern int32_t vm_dostring (LosuVm *vm, const char *str, const char *name); +LosuExtern int32_t vm_dobyte (LosuVm *vm, const char *byte, size_t len, + const char *name); +LosuExtern int32_t vm_loadfile (LosuVm *vm, const char *f); +LosuExtern int32_t vm_loadstring (LosuVm *vm, const char *s, const char *name); +LosuExtern int32_t vm_loadbyte (LosuVm *vm, const char *byte, size_t len, + const char *name); +LosuExtern int32_t vm_execute (LosuVm *vm, int32_t narg, int32_t nres, + const char *name); +LosuExtern LosuObj *vm_getval (LosuVm *vm, const char *name); +LosuExtern void vm_setval (LosuVm *vm, const char *name, LosuObj val); +LosuExtern void vm_close (LosuVm *vm); + +/* API: gc_xxx: Manage GC workflow APIs */ + +LosuExtern void gc_setmax (LosuVm *vm, _l_gcint size); +LosuExtern _l_gcint gc_getmemNow (LosuVm *vm); +LosuExtern _l_gcint gc_getmemMax (LosuVm *vm); +LosuExtern _l_bool gc_collect (LosuVm *vm); + +/* API: arg_xxx: Operation arguments on the call-stack APIs */ + +LosuExtern LosuObj *arg_get (LosuVm *vm, int idx); +LosuExtern void arg_return (LosuVm *vm, LosuObj obj); +LosuExtern int32_t arg_num (LosuVm *vm); +LosuExtern _l_number arg_getnum (LosuVm *vm, int idx); +LosuExtern const char *arg_getstr (LosuVm *vm, int idx); +LosuExtern char *arg_getptr (LosuVm *vm, int idx); +LosuExtern LosuApi arg_getfunc (LosuVm *vm, int idx); +LosuExtern int arg_gettype (LosuVm *vm, int idx); +LosuExtern const char *arg_gettypeStr (LosuVm *vm, int idx); +LosuExtern void arg_returnnum (LosuVm *vm, _l_number num); +LosuExtern void arg_returnstr (LosuVm *vm, const char *str); +LosuExtern void arg_returnstrlen (LosuVm *vm, const char *str, size_t len); +LosuExtern void arg_returnfunc (LosuVm *vm, LosuApi func); +LosuExtern void arg_returnptr (LosuVm *vm, char *ptr); +LosuExtern void arg_returnnull (LosuVm *vm); + +/* API: obj_xxx: Create and edit LosuObj APIs */ + +LosuExtern const char *obj_tostr (LosuVm *vm, LosuObj *obj); +LosuExtern _l_number obj_tonum (LosuVm *vm, LosuObj *obj); +LosuExtern char *obj_toptr (LosuVm *vm, LosuObj *obj); +LosuExtern LosuApi obj_tofunction (LosuVm *vm, LosuObj *obj); +LosuExtern int obj_type (LosuVm *vm, LosuObj *obj); +LosuExtern const char *obj_typeStr (LosuVm *vm, LosuObj *obj); +LosuExtern LosuObj obj_newstr (LosuVm *vm, char *str); +LosuExtern LosuObj obj_newstrlen (LosuVm *vm, char *str, size_t len); +LosuExtern size_t obj_getstrlen (LosuVm *vm, LosuObj *obj); +LosuExtern LosuObj obj_newnum (LosuVm *vm, _l_number num); +LosuExtern LosuObj obj_newfunction (LosuVm *vm, LosuApi func); +LosuExtern LosuObj obj_newnull (LosuVm *vm); +LosuExtern LosuObj obj_newunit (LosuVm *vm); +LosuExtern LosuObj obj_newptr (LosuVm *vm, char *ptr); +LosuExtern LosuObj *obj_indexunit (LosuVm *vm, LosuObj unit, LosuObj key); +LosuExtern LosuObj *obj_indexunitbynum (LosuVm *vm, LosuObj unit, _l_number i); +LosuExtern LosuObj *obj_indexunitbystr (LosuVm *vm, LosuObj unit, char *s); +LosuExtern void obj_setunit (LosuVm *vm, LosuObj unit, LosuObj key, + LosuObj value); +LosuExtern void obj_setunitbynum (LosuVm *vm, LosuObj unit, _l_number key, + LosuObj value); +LosuExtern void obj_setunitbystr (LosuVm *vm, LosuObj unit, char *key, + LosuObj value); +LosuExtern LosuNode *obj_unit_first (LosuVm *vm, LosuObj unit); +LosuExtern LosuNode obj_unit_location (LosuVm *vm, LosuObj unit, LosuObj key); +LosuExtern LosuNode *obj_unit_next (LosuVm *vm, LosuObj unit, LosuNode *n); +LosuExtern LosuObj obj_unit_nodekey (LosuVm *vm, LosuNode *n); +LosuExtern LosuObj obj_unit_nodevalue (LosuVm *vm, LosuNode *n); + +/* API: stack_xxx: Stack Opereatetion APIs */ + +LosuExtern void stack_push (LosuVm *vm, LosuObj o); +LosuExtern void stack_pop (LosuVm *vm, int i); +LosuExtern void stack_call (LosuVm *vm, int argnum, int resnum); + +/* API: charset_xxx: Charset APIs, */ +LosuExtern char *charset_toSys (const char *s); +LosuExtern char *charset_toLosu (const char *s); +LosuExtern char *charset_newObj_toLosu (LosuVm *vm, const char *s); +LosuExtern char *charset_newObj_toSys (LosuVm *vm, const char *s); + +#endif /* define_file_losu_h__inline__losuapi */ + +#endif /* define_file_losu_h__inline__LosuExternInfo */ + +/*! Define the Struct of LosuVtype + We define LosuVtype using typedef and structs, which store information about + individual objects at runtime in the virtual machine +*/ +#ifndef define_file_losu_h__inline__LosuVtypeDefine +#define define_file_losu_h__inline__LosuVtypeDefine + +typedef struct LosuObj +{ + uint8_t type; /* type of the object */ + union + { + struct _inlineString *str; /* string type*/ + struct _inlineFunction *func; /* function type*/ + struct _inlineHash *hash; /* hash type*/ + struct _inlineCallinfo *call; /* callinfo type*/ + _l_number num; /* number type*/ + void *ptr; /* pointer type*/ + } value; +} LosuObj; + +typedef struct _inlineString +{ + _l_hash hash; /* Hash Value*/ + int32_t cstidx; /* Const Index*/ + size_t len; /* Length of the string*/ + struct _inlineString *next; /* Next StringObj (in equal-key link list) */ + int16_t marked; /* Marked for GC*/ + char str[4]; /* Memory space for string value*/ +} _inlineString; + +typedef struct _inlineFunction +{ + union + { + LosuApi capi; /* C-API */ + struct _inlineScode *sdef; /* Losu Script `def` */ + } func; /* function segment */ + struct _inlineFunction *next; /* Next FunctionObj (in equal-key link list) */ + struct _inlineFunction + *mark; /* Mark link when GC working, default o.mark == o */ + _l_bool isC; /* Is C-API, 1 if is, 0 if not */ + int32_t nclosure; /* Number of closure upvalue */ + struct LosuObj closure[1]; /* Closure upvalue segment */ +} _inlineFunction; + +typedef struct LosuNode +{ + struct LosuObj key; + struct LosuObj value; + struct LosuNode *next; +} LosuNode; + +typedef struct _inlineHash +{ + int32_t size; + struct LosuNode *node; + struct LosuNode *free; /* Free node point */ + struct _inlineHash *next; /* Next HashObj (in equal-key link list) */ + struct _inlineHash + *mark; /* Mark link when GC working, default o.mark == o */ +} _inlineHash; + +typedef struct _inlineCallinfo +{ + struct _inlineFunction *func; /* Calle */ + const vmInstruction **pc; /* Current PC of Calle */ +} _inlineCallinfo; + +typedef struct _inlineLocalvar +{ + struct _inlineString *name; /* Name of the local variable */ + int startpc; + int endpc; +} _inlineLocalvar; + +typedef struct _inlineScode +{ + /* Local segment */ + /* Number */ + _l_number *lcnum; /* Number used by this function */ + int32_t nlcnum; /* Number of lcnum */ + + /* String */ + struct _inlineString **lcstr; /* String used by this function */ + int32_t nlcstr; /* Number of lcstr */ + + /* Function */ + struct _inlineScode **lcscode; /* Inline-function of this function */ + int32_t nlcscode; /* Number of lcscode */ + + /* Local Var */ + struct _inlineLocalvar *localvar; /* Localvar used by this function */ + int32_t nlocalvar; /* Number of localvars */ + + /* Instruction Segment */ + vmInstruction *code; /* Instruction of this function */ + int32_t ncode; /* Number of code (MAX == INT_MAX,C-type) */ + + /* Arg Segment */ + int8_t narg; /* Number of arguments */ + _l_bool isVarg; /* is ... */ + int16_t maxstacksize; + + /* Lineinfo Segment */ + int32_t *lineinfo; + int32_t nlineinfo; + int32_t defedline; + + /* Data Segment */ + struct _inlineScode *next; /* Next ScodeObj (in equal-key link list) */ + struct _inlineString *src; /* Source code */ + + /* Gc Segment */ + _l_bool marked; + +} _inlineScode; + +typedef struct LosuModule +{ + const char *name; + LosuApi construct; +} LosuModule; + +#ifndef __config_losucore_vm_vmbuff +#define __config_losucore_vm_vmbuff 128 +#endif + +typedef struct __longjump __longjump; +typedef struct __vmStrseg +{ + _l_hash size; + _l_hash nsize; + _inlineString **strobj; +} __vmStrseg; + +typedef struct LosuVm +{ + LosuVm *mainthread; /* Root-Vm */ + LosuObj *top, *stack, *stackmax, *base; + int32_t stacksize; + + __longjump *errjmp; + __longjump *emjmp; /* 紧急跳转,跳转到虚拟机的创建者处 */ + + unsigned char *bufftmp; + _l_size_t nbufftmp; + + _inlineScode *inspool; /* InstructionObj */ + _inlineFunction *funcpool; /* FunctionObj */ + _inlineHash *hashpool; /* HashObj (unit) */ + __vmStrseg strpool; /* StringObj (string) */ + + _inlineHash *global; /* global var-table */ + + _l_gcint gcDymax; /* Dynatic Max Limit */ + _l_gcint nblocks; /* Now size */ + _l_gcint gcMax; /* All Max */ + _l_gcint gcHook; /* hookMax */ + + unsigned char staticbuff[__config_losucore_vm_vmbuff]; + const char *name; + +} LosuVm; + +typedef struct __longjump +{ + __longjump *pre; + jmp_buf jmpflag; + volatile int16_t err; +} __longjump; + +typedef struct LosuPackage_t +{ + const char *name; + LosuModule *(*loadfunc) (); +} LosuPackage_t; +#endif + +#endif /* define_included_losu_h */ diff --git a/include/losu_api.h b/include/losu_api.h new file mode 100755 index 0000000000000000000000000000000000000000..fa7e5c49cbf36f02378c3a201672cc8b77534151 --- /dev/null +++ b/include/losu_api.h @@ -0,0 +1,56 @@ +/* + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ +/** + * Losu API + */ + +#include "losu.h" + +#ifndef define_included_losu_api_h +#define define_included_losu_api_h +static int32_t __losuApigetline (LosuVm* vm,LosuObj *obj); +static int32_t __losuApicurrentpc (LosuObj *obj); +static int32_t __losuApitryline (int32_t *lineinfo, int32_t pc); + +#ifdef __config_losucore_encode_winGBK +static char *__losuWintoGBK (const char *str); +static char *__losuWintoUTF8 (const char *str); +#endif +#endif \ No newline at end of file diff --git a/include/losu_bytecode.h b/include/losu_bytecode.h new file mode 100755 index 0000000000000000000000000000000000000000..a4f841976e1cee0a0f354cce6213b7d9099aa52a --- /dev/null +++ b/include/losu_bytecode.h @@ -0,0 +1,256 @@ +/* + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +/** + * This set of code files (losuBytecode.h & losuBytecode.c) defines the + * bytecode subsystem of Losu, including the V-MIS (Virtual Machine Instruction + * Set), Instruction-Formats, Arithmetic&Logical Instructions. + */ + +#ifndef define_included_losubytecode_h +#define define_included_losubytecode_h +#include "losu.h" + +/** + * Ins = { + * OP + * OP + U + * OP + S + * OP + B + A + * } + * OP: 6 bit uint8_t + * B: 8 bit uint8_t + * A: 18/32 bit uint32_t + * U: 26/32 bit uint32_t + * S: /32bit + * */ +typedef uint8_t vmIns_OP; +typedef uint32_t vmIns_U; +typedef int32_t vmIns_S; +typedef uint32_t vmIns_A; +typedef uint8_t vmIns_B; + +/* Size of VmIns */ +#define vmIns_SizeOP 6 +#define vmIns_SizeB 8 +#define vmIns_SizeA \ + (vmIns_SizeIns - vmIns_SizeOP - vmIns_SizeB) /* 18 or 32 \ + */ +#define vmIns_SizeU (vmIns_SizeIns - vmIns_SizeOP) /* 26 or 32 */ + +/* if size_X > 32 it will overflow from check, limit to 32 bit Max*/ +#if vmIns_SizeU > 32 +#undef vmIns_SizeU +#define vmIns_SizeU 32 +#endif /* vmIns_SizeU > 32 */ +#if vmIns_SizeA > 32 +#undef vmIns_SizeA +#define vmIns_SizeA 32 +#endif /* vmIns_SizeA > 32 */ + +/* Pos of VmIns*/ +#define vmIns_PosOP 0 +#define vmIns_PosU vmIns_SizeOP +#define vmIns_PosB vmIns_SizeOP +#define vmIns_PosA (vmIns_SizeOP + vmIns_SizeB) + +/* Max argument size, */ +#define vmIns_MaxU (((vmInstruction)(1) << vmIns_SizeU) - 1) +#define vmIns_MaxS (vmIns_MaxU >> 1) +#define vmIns_MaxB (((vmInstruction)(1) << vmIns_SizeB) - 1) +#define vmIns_MaxA (((vmInstruction)(1) << vmIns_SizeA) - 1) + +/* Vm Opereate Limits */ +#define vmOl_MaxStack 255 /* Maximum stack depth for a single expression */ +#define vmOl_MaxLocalvar 128 /* < vmOl_MaxStack */ +#define vmOl_MaxClosure 32 /* < vmOl_MaxStack */ +#define vmOl_MaxVared2left 64 /* < vmOl_MaxReturn */ +#define vmOl_MaxFuncarg 32 +#define vmOl_MaxSetlist 32 /* < vmOl_MaxStack / 4 */ +#define vmOl_MaxSetmap (vmOl_MaxSetlist / 2) +#define vmOl_MaxLookback 32 /* space cost to reduce time for codegen */ +#define vmOl_MaxReturn 255 +#define vmOl_MaxStrlen SIZE_MAX +#define vmOl_MaxSize_t SIZE_MAX +#define vmOl_MaxInt32_t INT_MAX +#define vmOl_MaxNumberRef 0 /* synatx number max */ + +/* Codegen Ins-set */ + +/* Mask-Ins */ +#define cgIns_Mask1(n, p) \ + ((~((~(vmInstruction)0) << n)) << p) /* lmov n bit 1 to p */ +#define cgIns_Mask0(n, p) (~cgIns_Mask1 (n, p)) /* lmov n bit 0 to p */ + +/* Bcode-Ins */ +#define cgIns_NewOp(op) ((vmInstruction)(op)) +#define cgIns_GetOp(i) ((vmIns_OP)((i) & cgIns_Mask1 (vmIns_SizeOP, 0))) +#define cgIns_SetOp(i, op) \ + ((i) = (((vmInstruction)(i) & cgIns_Mask0 (vmIns_SizeOP, 0)) \ + | (vmInstruction)(op))) + +#define cgIns_NewU(op, u) \ + ((vmInstruction)(op) | ((vmInstruction)(u) << vmIns_PosU)) +#define cgIns_GetU(i) ((vmIns_U)((vmInstruction)(i) >> vmIns_PosU)) +#define cgIns_SetU(i, u) \ + ((i) = (((i) & cgIns_Mask0 (vmIns_SizeU, vmIns_PosU)) \ + | ((vmInstruction)(u) << vmIns_PosU))) + +#define cgIns_NewS(op, s) (cgIns_NewU ((op), (s) + vmIns_MaxS)) +#define cgIns_GetS(i) ((vmIns_S)(cgIns_GetU (i) - vmIns_MaxS)) +#define cgIns_SetS(i, s) (cgIns_SetU (i, (s) + vmIns_MaxS)) + +#define cgIns_NewAB(op, a, b) \ + (((vmInstruction)(op)) | ((vmInstruction)(a) << vmIns_PosA) \ + | ((vmInstruction)(b) << vmIns_PosB)) +#define cgIns_GetA(i) (((vmIns_A)((i) >> vmIns_PosA))) +#define cgIns_SetA(i, a) \ + ((i) = (((i) & cgIns_Mask0 (vmIns_SizeA, vmIns_PosA)) \ + | ((vmInstruction)(a) << vmIns_PosA))) +#define cgIns_GetB(i) \ + ((vmIns_B)(((i) >> vmIns_PosB) /* & cgIns_Mask1 (vmIns_SizeB, 0) */)) +#define cgIns_SetB(i, b) \ + ((i) = (((i) & cgIns_Mask0 (vmIns_SizeB, vmIns_PosB)) \ + | ((vmInstruction)(b) << vmIns_PosB))) + +/* Op-code */ +typedef enum +{ + INS_END, /* iO 0 0 */ + INS_RETURN, /* iU 0 0 */ + + INS_CALL, /* iBA 0 0 */ + + INS_PUSHNULL, /* iU V 0 */ + INS_POP, /* iU V 0 */ + + INS_PUSHSTRING, /* iU 1 0 */ + INS_PUSHNUM, /* iU 1 0 */ + INS_PUSHUPVALUE, /* iU 1 0 */ + INS_PUSHFUNCTION, /* iBA V 0 */ + INS_PUSHSELF, /* iU 2 1 */ + + INS_GETLOCAL, /* iU 1 0 */ + INS_GETGLOBAL, /* iU 1 0 */ + INS_SETLOCAL, /* iU 0 1 */ + INS_SETGLOBAL, /* iU 0 1 */ + + INS_CREATEUNIT, /* iU 1 0 */ + INS_SETUNIT, /* iBA V 0 */ + INS_GETUNIT, /* iBA 1 2 */ + INS_SETLIST, /* iBA V 0 */ + INS_SETMAP, /* iU V 0 */ + + INS_ADD, /* iO 1 2 */ + INS_SUB, /* iO 1 2 */ + INS_MULT, /* iO 1 2 */ + INS_DIV, /* iO 1 2 */ + INS_POW, /* iO 1 2 */ + INS_CONCAT, /* iO 1 2 */ + INS_NEG, /* iO 1 1 */ + INS_NOT, /* iO 1 1 */ + + INS_JMPNE, /* iS 0 2 */ + INS_JMPEQ, /* iS 0 2 */ + INS_JMPLT, /* iS 0 2 */ + INS_JMPLE, /* iS 0 2 */ + INS_JMPGT, /* iS 0 2 */ + INS_JMPGE, /* iS 0 2 */ + + INS_JMPT, /* iS 0 1 */ + INS_JMPF, /* iS 0 1 */ + INS_JMPONT, /* iS 0 1 */ + INS_JMPONF, /* iS 0 1 */ + INS_JMP, /* iS 0 0 */ + + INS_PUSHNULLJMP, /* iO 0 0 */ + + INS_FORPREP, /* iS 0 0 */ + INS_FORLOOP, /* iS 0 3 */ + INS_LFORPREP, /* iS 2 0 */ + INS_LFORLOOP, /* iS 0 3 */ + + vmIns_Number, + +} vmInsList; + +#define vmIns_Isjump(op) ((INS_JMPNE <= (op) && (op) <= INS_JMP)) + +typedef enum +{ + INS_BINOP_ADD, /* + */ + INS_BINOP_SUB, /* - */ + INS_BINOP_MULT, /* * */ + INS_BINOP_DIV, /* / */ + INS_BINOP_POW, /* ^ */ + INS_BINOP_CONCAT, /* & */ + + INS_BINOP_NE, /* != */ + INS_BINOP_EQ, /* == */ + + INS_BINOP_LT, /* < */ + INS_BINOP_LE, /* <= */ + + INS_BINOP_GT, /* > */ + INS_BINOP_GE, /* >= */ + + INS_BINOP_AND, /* and && */ + INS_BINOP_OR, /* or || */ + + INS_BINOP_NULL, +} vmIns_BinOp; + +typedef enum +{ + INS_UNOP_NEG, /* - */ + INS_UNOP_NOT, /* not */ + + INS_UNOP_NULL, +} vmIns_UnOp; + +typedef enum +{ + INS_MODE_OP, + INS_MODE_IU, + INS_MODE_IS, + INS_MODE_IBA, +} vmIns_Mode; + +#endif /* define_included_losubytecode_h */ diff --git a/include/losu_config.h b/include/losu_config.h new file mode 100755 index 0000000000000000000000000000000000000000..9a83e5913c651fb053ae9d7d7a8e0e5127def23c --- /dev/null +++ b/include/losu_config.h @@ -0,0 +1,133 @@ +/* + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +/* +-------------- How to configure the Losu Core ---------------- + 1. The configuration file is named 'losu_config.h'. + 2. You can use predefined OS macros to build ELF for officially supported + platforms + 3. You can also define your own macros to build ELF for other platforms +---- You can refer to the following configuration tree ---- + +__config_losucore_ + platform_ + name: "xxxx" // the name of the platform + template_ + linux: 1x // template of linux + unknow: x0 // template of linux unknow + x64: x1 // template of linux x64 + windows: 2x // template of windows + unknown: x0 // template of windows unknow + x64: x1 // template of windows x64 + oneos: 3x // template of oneos + unknown: x0 // template of oneos unknow + vm_ + bitsize: 32/64 // the bitsize of the virtual machine + iobuff: 32 // io size of the virtual machine, default is 32 + vmbuff: 256 // static buff size of the Vm default is 256 + strpoolMax: 1024 // max size of the string pool + fullcompiler: 1/0 // enable/disable the full compiler + mem_ + realloc: realloc // enable/disable the realloc function + free: free // enable/disable the free function + gc_ + defaultsize: 0 // default size of the GC max + feature_ + chKeyword: 1/0 // enable/disable Chinese keywords + cStyle: 1/0 // enable/disable C style tokens + encode_ 1/0 // only one encode can be enabled + winGBK: 1/0 // enable/disable GBK encoding(need Win32 API) + nativeUTF8: 1/0 // enable/disable native UTF-8 encoding + + */ + +#ifndef define_included_losuconfig_h +#define define_included_losuconfig_h + + +/* default is linux x64*/ +#ifndef __config_losucore_platform_template +#define __config_losucore_platform_template 11 +#endif + +#if __config_losucore_platform_template <0 +#error "the platform template must be greater than 0" +#endif + +/* template for linux-x64 */ +#if __config_losucore_platform_template == 11 +#define __config_losucore_platform_name "linux-x64" + +#define __config_losucore_vm_bitsize 64 +#define __config_losucore_vm_iobuff 1024 +#define __config_losucore_vm_vmbuff 256 +#define __config_losucore_vm_strpoolMax 1024 +#define __config_losucore_vm_fullcompiler 1 + +#define __config_losucore_gc_defaultsize 1024 * 1024 * 128 /* 128M */ + +#define __config_losucore_feature_chKeyword 1 +#define __config_losucore_feature_cStyle 1 + +#define __config_losucore_encode_nativeUTF8 1 + +#endif + +/* template for windows-x64 */ +#if __config_losucore_platform_template == 21 +#define __config_losucore_platform_name "windows-x64" + +#define __config_losucore_vm_bitsize 64 +#define __config_losucore_vm_iobuff 1024 +#define __config_losucore_vm_vmbuff 256 +#define __config_losucore_vm_strpoolMax 1024 +#define __config_losucore_vm_fullcompiler 1 + +#define __config_losucore_gc_defaultsize 1024 * 1024 * 128 /* 128M */ + +#define __config_losucore_feature_chKeyword 1 +#define __config_losucore_feature_cStyle 1 + +#define __config_losucore_encode_winGBK 1 + +#endif + + +#endif diff --git a/include/losu_errmsg.h b/include/losu_errmsg.h new file mode 100755 index 0000000000000000000000000000000000000000..5d0bfb0338e141c4d340b4f1edb8234c7a499406 --- /dev/null +++ b/include/losu_errmsg.h @@ -0,0 +1,110 @@ +/* + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +/* This file defines all of Losu's error messages. */ + +#ifndef define_included_losuerrmsg_h +#define define_included_losuerrmsg_h + +#define __config_losucore_errmsg_msgVectorOverflow "Vector overflow" +#define __config_losucore_errmsg_msgReallocFailed \ + "Fails to reallocate memory successfully when reallocating 0x%p to %zu " \ + "size(B) " + +#define __config_losucore_errmsg_msgInvalidNumber "Invalid number '%s'" +#define __config_losucore_errmsg_msgMissStrEnd \ + "Missing terminating character %c " +#define __config_losucore_errmsg_msgInvalidEscapeHex \ + "%% or \\u used with no following hex digits" + +#define __config_losucore_errmsg_msgInvalidEscapeUtf8 \ + "Invalid UTF-8 escape sequence" +#define __config_losucore_errmsg_msgInvalidBlockComment "Invalid block comment" +#define __config_losucore_errmsg_msgInvalidPureString "Invalid string after $ " +#define __config_losucore_errmsg_msgUnknownSymbol "Unknown symbol '%s'" +#define __config_losucore_errmsg_msgMissingEOZ "Missing EOZ" +#define __config_losucore_errmsg_msgCheckMatch \ + "After '%s'(at line %d) expected '%s'" +#define __config_losucore_errmsg_msgCheckName \ + "Variable name required as [TOKEN_NAME]" +#define __config_losucore_errmsg_msgInvalidExp "Invalid expression" +#define __config_losucore_errmsg_msgParserError "Expected '%s'" +#define __config_losucore_errmsg_msgInvalidForExp "Invalid 'for' expression" +#define __config_losucore_errmsg_msgCheckLimit "Too mant %s (limit %d)" +#define __config_losucore_errmsg_msgCheckLimitTMlocvar "local variables" +#define __config_losucore_errmsg_msgInvalidClosure \ + "Invalid closure `%s` (must be global or in neighboring scope)." +#define __config_losucore_errmsg_msgExpectedFarg "Expected function argument" +#define __config_losucore_errmsg_msgTooComplexExp "Overly complex expressions" +#define __config_losucore_errmsg_msgInvalidJump "Invalid jump, overflow" +#define __config_losucore_errmsg_msgInvalidUnitIndex "Invalid unit index" +#define __config_losucore_errmsg_msgStackOverflow "Stack overflow" +#define __config_losucore_errmsg_msgCalledNotFunc \ + "The object being called is not a function type" +#define __config_losucore_errmsg_msgInvalidOverload \ + " Operators '%s' are not defined how to overload" +#define __config_losucore_errmsg_msgInvalidForstep "Invalid for 'step'" +#define __config_losucore_errmsg_msgInvalidFormax "Invalid for 'max'" +#define __config_losucore_errmsg_msgInvalidForinit "Invalid for 'init'" +#define __config_losucore_errmsg_msgInvalidForobj "Invalid for 'obj'" +#define __config_losucore_errmsg_msgInvalidBytecode "Invalid bytecode" +#define __config_losucore_errmsg_msgInvalidSetobj \ + "Attempting to assign a value to a non-indexed unit" +#define __config_losucore_errmsg_msgStrlenOverflow "String length overflow" +#define __config_losucore_errmsg_msgInvalidNewobj \ + "Invalid new object,The first argument to the `new' function must be a " \ + "unit type." +#define __config_losucore_errmsg_msgInvalidLibrary "Can't find the module '%s'" +#define __config_losucore_errmsg_msgInvalidSubLibrary \ + "Can't find the '%s' in module '%s'" +#define __config_losucore_errmsg_msgIllegalBytecodeFormat \ + "Illegal bytecode format, further execution is denied" +#define __config_losucore_errmsg_msgInvalidVmBytecodeVersion \ + "Invalid bytecode version, need '%d', but '%d' is given" +#define __config_losucore_errmsg_msgInvalidVmInsSize \ + "Invalid Vm-Ins size, need %d-bit, but %d-bit is given" +#define __config_losucore_errmsg_msgInvalidIdtMutiple \ + "Invalid indentation, need Multiples of '%d',but '%d' is given" +#define __config_losucore_errmsg_msgInvalidElif \ + "Invalid if statement, unexpected 'elif'" +#define __config_losucore_errmsg_msgInvalidElse \ + "Invalid if statement, unexpected 'else'" + +#endif /* define_included_losuerrmsg_h */ diff --git a/include/losu_gc.h b/include/losu_gc.h new file mode 100755 index 0000000000000000000000000000000000000000..987be079b1e89c3153008ef043081de1ddf5e84d --- /dev/null +++ b/include/losu_gc.h @@ -0,0 +1,74 @@ +/* + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +/* +Losu Gc, a garbage collector for Losu Automated Memory Management +*/ + +#ifndef define_included_losu_gc_h +#define define_included_losu_gc_h +#include "losu.h" + +/** + * @brief Losu Gc, a garbage collector for Losu Automated Memory Management + * @param vm LosuVm + * @param all If true, all objects will be collected, otherwise only objects + * that are not referenced will be collected + */ +void __losu_gc_collect (LosuVm *vm, _l_bool all); + +/** + * @brief Check if the client is ready to be collected + * @param vm LosuVm + * @return _l_bool 1 if collection operation performed, 0 if collection + * operation not performed + */ +_l_bool __losu_gc_checkClt (LosuVm *vm); + +/* data struct */ +typedef struct _inlineGc +{ + _inlineHash *unit; /* tmark */ + _inlineFunction *func; /* cmark */ +} _inlineGc; + + + +#endif diff --git a/include/losu_malloc.h b/include/losu_malloc.h new file mode 100755 index 0000000000000000000000000000000000000000..c57e4c1fa51c5c872a5663269e40de069b9001f1 --- /dev/null +++ b/include/losu_malloc.h @@ -0,0 +1,84 @@ +/* + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +/* +This set of source code defines the memory management functions for Lowe's +(based on malloc@libc by default), which can be changed to use a specific +memory manager (e.g. bget) + */ + +#ifndef define_included_losuMallloc_h +#define define_included_losuMallloc_h +#include "losu.h" + +#ifndef __config_losucore_mem_realloc +#define __config_losucore_mem_realloc realloc /* use libc realloc */ +#endif + +#ifndef __config_losucore_mem_free +#define __config_losucore_mem_free free /* use libc free */ +#endif + +/** + * @brief realloc memory, if old is NULL, it is equivalent to malloc, if size + * is 0, it is equivalent to free + * @param vm LosuVm + * @param old old pointer + * @param size new size + * @return new pointer, if failed, return NULL + */ +void *__losu_mem_realloc (LosuVm *vm, void *old, _l_size_t size); + +void *__losu_mem_grow (LosuVm *vm, void *block, _l_size_t i_num, int inc, + _l_size_t size, _l_size_t limit, const char *errormsg); + +#define __losu_mem_malloc(vm, s) (__losu_mem_realloc ((vm), NULL, (s))) +#define __losu_mem_free(vm, p) (__losu_mem_realloc ((vm), (p), 0)) +#define __losu_mem_new(vm, t) ((t *)__losu_mem_malloc ((vm), sizeof (t))) +#define __losu_mem_newvector(vm, n, t) \ + ((t *)__losu_mem_malloc ((vm), (n) * sizeof (t))) + +#define __losu_mem_growvector(vm, v, n, i, t, l, e) \ + ((v) = (t *)__losu_mem_grow ((vm), (v), (n), (i), sizeof (t), (l), (e))) + +#define __losu_mem_reallocvector(vm, v, s, t) \ + ((v) = (t *)__losu_mem_realloc ((vm), (v), (s) * sizeof (t))) + +#endif /* define_inluded_losuMalloc_h */ diff --git a/include/losu_object.h b/include/losu_object.h new file mode 100755 index 0000000000000000000000000000000000000000..9c8316dc8c90978b3441d03f5564843950ac430b --- /dev/null +++ b/include/losu_object.h @@ -0,0 +1,114 @@ +/* + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +/* +Object for Losu DataStruct +*/ + +#ifndef define_included_losuobject_h +#define define_included_losuobject_h + +#include "losu.h" + +#ifndef __inlinedefine__losuobject +#define __inlinedefine__losuobject + +LosuExtern const LosuObj _inlineNullObj; +_l_bool __losu_object_isObjEqual (const LosuObj *t1, const LosuObj *t2); +_l_bool __losu_object_str2num (const char *s, _l_number *n); +#define ovtype(o) ((o)->type) +#define ovnumber(o) ((o)->value.num) +#define ovIstr(o) ((o)->value.str) +#define ovSstr(o) ((o)->value.str->str) +#define ovfunc(o) ((o)->value.func) +#define ovhash(o) ((o)->value.hash) +#define ovcall(o) ((o)->value.call) +#define ostr2num(s, p) (strtod ((s), (p))) + +#endif /* __inlinedefine__losuobject */ + +#ifndef __inlinedefine__losustring +#define __inlinedefine__losustring + +#define CONSTMARK 2 +void __losu_objStringPool_init (LosuVm *vm); +void __losu_objStringPool_resize (LosuVm *vm, __vmStrseg *strpool, _l_hash s); +void __losu_objStringPool_deinit (LosuVm *vm); + +_inlineString *__losu_objString_new (LosuVm *vm, const char *s); +_inlineString *__losu_objString_newstr (LosuVm *vm, const char *s, + _l_size_t l); +_inlineString *__losu_objString_newconst (LosuVm *vm, const char *s); + +#endif /* __inlinedefine__losustring */ + +#ifndef __inlinedefine__losufunc +#define __inlinedefine__losufunc + +_inlineScode *__losu_objFunc_scodeNew (LosuVm *vm); +void __losu_objFunc_scodeFree (LosuVm *vm, _inlineScode *f); + +_inlineFunction *__losu_objFunc_new (LosuVm *vm, int32_t issnum); +void __losu_objFunc_free (LosuVm *vm, _inlineFunction *f); + +#endif /* __inlinedefine__losufunc */ + +#ifndef __inlinedefine__losuunit +#define __inlinedefine__losuunit + +const LosuObj *__losu_objUnit_getglobal (LosuVm *vm, const char *name); +const LosuObj *__losu_objUnit_get (_inlineHash *t, LosuObj *key); +const LosuObj *__losu_objUnit_getany (_inlineHash *t, LosuObj *key); +const LosuObj *__losu_objUnit_getnum (_inlineHash *t, _l_number key); +const LosuObj *__losu_objUnit_getstr (_inlineHash *t, _inlineString *key); +const LosuNode *__losu_objUnit_getnext (_inlineHash *t, LosuObj *key); + +_inlineHash *__losu_objUnit_new (LosuVm *vm, int32_t size); +void __losu_objUnit_remove (_inlineHash *t, LosuObj *key); +void __losu_objUnit_free (LosuVm *vm, _inlineHash *t); + +LosuObj *__losu_objUnit_set (LosuVm *vm, _inlineHash *t, LosuObj *key); +LosuObj *__losu_objUnit_setnum (LosuVm *vm, _inlineHash *t, _l_number key); +LosuObj *__losu_objUnit_setstr (LosuVm *vm, _inlineHash *t, + _inlineString *key); + +#endif /* __inlinedefine__losuunit */ + +#endif /* define_included_losu_object_h */ diff --git a/include/losu_syntax.h b/include/losu_syntax.h new file mode 100755 index 0000000000000000000000000000000000000000..d0a3d8a2c68933367b0951c73fb2ff8011fa95d4 --- /dev/null +++ b/include/losu_syntax.h @@ -0,0 +1,294 @@ +/* + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +/* + This is the syntax analysis code for Losu, the complete compiler + implementation, consisting of Lexer, Parser & Codegen. Parses script code + written using Losu and converts it to in-memory bytecode form +*/ + +#ifndef define_included_losusyntax_h +#define define_included_losusyntax_h + +#include "losu.h" +#include "losu_bytecode.h" +typedef struct _syntaxFunc _syntaxFunc; +typedef struct _syntaxExp _syntaxExp; +typedef struct _syntaxBreak _syntaxBreak; +typedef struct _syntaxLex _syntaxLex; +typedef struct _syntaxToken _syntaxToken; +typedef struct _syntaxIO _syntaxIO; + +enum _syntaxExpType +{ + VG, /* global var */ + VL, /* local var*/ + VI, /* index var */ + VE, /* expression (math.) */ +}; + +typedef union +{ + _l_number num; + _inlineString *s; +} _syntaxTkvalue; + +typedef struct _syntaxToken +{ + int16_t token; + _syntaxTkvalue info; +} _syntaxToken; +typedef struct _syntaxExp +{ + uint8_t type; + union + { + int32_t index; + struct + { + int32_t t; + int32_t f; + } _bool; + } value; +} _syntaxExp; + +typedef struct _syntaxBreak +{ + struct _syntaxBreak *pre; + int32_t breaklist; + int32_t stacklevel; +} _syntaxBreak; + +typedef struct _syntaxLex +{ + int16_t current; /* current tk */ + int16_t deepth; /* deepth of stack-syntax */ + struct _syntaxToken tk; /* token now */ + struct _syntaxToken tkahead; /* token ahead */ + struct _syntaxFunc *fs; + struct LosuVm *vm; + struct _syntaxIO *io; /* io */ + int32_t linenumber; + int32_t lastline; /* last line */ + _inlineString *source; + struct _syntaxLexIdt + { + int32_t read; /* readed */ + int32_t nowidt; /* now idt */ + int32_t size; /* size of idt */ + int32_t tmp; /* temp */ + } _syntaxLexIdt; +} _syntaxLex; + +typedef struct _syntaxFunc +{ + struct _inlineScode *fcode; + struct _inlineString *source; + struct _syntaxFunc *prev; + struct _syntaxLex *lexer; + struct LosuVm *vm; + int32_t pc; + int32_t lasttarget; + int32_t lastline; + int32_t jump; + int16_t stacklevel; + + int32_t aloc[vmOl_MaxLocalvar]; + int16_t naloc; + + struct _syntaxExp closure[vmOl_MaxClosure]; + int16_t nclosure; + + struct _syntaxBreak *breakl; + +} _syntaxFunc; +#ifndef __config_losucore_vm_iobuff +#define __config_losucore_vm_iobuff 32 +#endif + +typedef struct _syntaxIO +{ + _l_size_t size; /* n number */ + const unsigned char *p; /* p pointer for char */ + int16_t (*fillbuff) (_syntaxIO *); /* */ + void *h; /* f handl=ee_t */ + const char *name; + uint8_t bin; /* binary or not , if bin. 32 or 64*/ + unsigned char buff[__config_losucore_vm_iobuff]; +} _syntaxIO; + +#ifndef __inline_define_losusynIO_h +#define __inline_define_losusynIO_h + +int32_t __losu_syntaxIO_doload (LosuVm *vm, _syntaxIO *io); +int32_t __losu_syntaxIO_loadfile (LosuVm *vm, const char *fn); +int32_t __losu_syntaxIO_loadstring (LosuVm *vm, const char *str, _l_size_t len, + const char *name); +/* + * Losu supports two IO modes: + * 1. Streaming IO + * 2. Handle & buffer IO + */ + +/** + * @brief open a syntaxIO: Handle & buffer IO + * @param io syntaxIO + * @param h handle + * @param name name of handel + */ +void __losu_syntaxIO_openH (_syntaxIO *io, void *h, const char *name); + +/** + * @brief open a syntaxIO: Streaming IO + * @param io syntaxIO + * @param p pointer of char-stream + * @param size size of char-stream + * @param name name of stream + */ +void __losu_syntaxIO_openS (_syntaxIO *io, const char *p, _l_size_t size, + const char *name); + +#define __losu_syntaxIO_getc(io) \ + (((io)->size--) > 0 ? ((int16_t)(*((io)->p++))) : ((io)->fillbuff (io))) + +#define __losu_syntaxIO_getint32(io) \ + (((io)->size--) > 0 ? ((int32_t)(*((io)->p++))) : ((io)->fillbuff (io))) + +#endif /* __inline_define_losusynIO_h */ + +#ifndef __inline_define_losulexer_h +#define __inline_define_losulexer_h + +enum _lexerToken +{ + /* and or not */ + TOKEN_AND = 256, /* tk > uint8_t, use int16_t */ + TOKEN_NOT, + TOKEN_OR, + + /* block end */ + TOKEN_BLOCK, + /* TOKEN_ENDB, */ + + /* if */ + TOKEN_IF, + TOKEN_ELSE, + TOKEN_ELSEIF, + /* TOKEN_END ,*/ + + /* def */ + TOKEN_FUNCTION, + TOKEN_ARG, /* .. */ + + /* var null */ + TOKEN_VAR, + TOKEN_NULL, + + /* return break */ + TOKEN_RETURN, + TOKEN_BREAK, + + /* with until loop to*/ + TOKEN_WITH, + TOKEN_UNTIL, + TOKEN_LOOP, + TOKEN_TO, + + /* for */ + TOKEN_FOR, + + /* == >= <= != &*/ + TOKEN_EQ, + TOKEN_GE, + TOKEN_LE, + TOKEN_NE, + TOKEN_CONCAT, + + TOKEN_NAME, + TOKEN_NUMBER, + TOKEN_STRING, + TOKEN_END, + +/* chKeyword */ +#ifdef __config_losucore_feature_chKeyword + TOKEN_FOR_MAX, + TOKEN_FOR_STEP, + TOKEN_FOR_THIS, + TOKEN_THIS, + TOKEN_CONST, + TOKEN_VARARG, /* arg{} */ + TOKEN_IN, +#endif /* __config_losucore_feature_chKeyword */ + + TOKEN_EOZ, +}; +/* #define TOKEN_END TOKEN_ARG */ + +void __losu_syntaxLex_init (LosuVm *vm); + +#endif /* __inline_define_losulexer_h */ + +#ifndef __inline_define_losuparser_h +#define __inline_define_losuparser_h + +_inlineScode *__losu_syntaxParser_parse (LosuVm *vm, _syntaxIO *io); + +#endif /* __inline_define_losuparser_h */ + +#ifndef __inline_define_losucodegen_h +#define __inline_define_losucodegen_h + +/* marco function */ +#define __losuSyntaxCgenCodearg2 __losuSyntaxCgenCodearg +#define __losuSyntaxCgenCodearg1(fs, o, arg) \ + (__losuSyntaxCgenCodearg (fs, o, arg, 0)) +#define __losuSyntaxCgenCodearg0(fs, o) (__losuSyntaxCgenCodearg (fs, o, 0, 0)) + +/* */ + +#endif /* __inline_define_codegen_h */ +#endif /* define_included_losusyntax_h */ + +#ifndef __inline_define_losuirloader_h +#define __inline_define_losuirloader_h + +_inlineScode *__losu_syntaxIrload_load (LosuVm *vm, _syntaxIO *io); + +#endif /* __inline_define_losuirloader_h */ diff --git a/include/losu_vm.h b/include/losu_vm.h new file mode 100755 index 0000000000000000000000000000000000000000..eef30a89badb24ab65c6799fdf17df8d76302912 --- /dev/null +++ b/include/losu_vm.h @@ -0,0 +1,71 @@ +/* + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +/** + * An ultra-lightweight stacked virtual machine + * consisting of vmHeap, vmHost,vmCore + */ + +#ifndef define_included_losu_vm_h +#define define_included_losu_vm_h + +#include "losu.h" + +#ifndef define_included_losu_vm_heap_h +#define define_included_losu_vm_heap_h + +void __losu_vmHeap_init (LosuVm *vm, int32_t size); +void __losu_vmHeap_check (LosuVm *vm, int32_t size); +void __losu_vmHeap_break (LosuVm *vm, int16_t ecode); +void __losu_vmHeap_adjTop (LosuVm *vm, LosuObj *base, int32_t size); +int32_t __losu_vmHeap_callS (LosuVm *vm, int32_t arg, int32_t nres); +void __losu_vmHeap_call (LosuVm *vm, LosuObj *func, int32_t nres); + +#endif /* define_included_losu_vm_heap_h */ + +#ifndef define_included_losu_vm_core_h +#define define_included_losu_vm_core_h + +_l_bool __losu_vmCore_Tonum (LosuVm *vm, LosuObj *obj, _l_bool isCore); +_l_bool __losu_vmCore_Tostr (LosuVm *vm, LosuObj *obj, _l_bool isCore); + +#endif /* define_included_losu_vm_core_h */ + +#endif /* define_included_losu_vm_h */ diff --git a/include/losuh.h b/include/losuh.h new file mode 100755 index 0000000000000000000000000000000000000000..f909049b9a6d688a7db70b81d8e9b350caa3f5e6 --- /dev/null +++ b/include/losuh.h @@ -0,0 +1,96 @@ +/* + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +/* + This document is part of the Losu Community OSPP - 2024 subject results + contributed by Dongqiao Huang @ NEUQ, following MIT LICENSE Contributed to + the Losu Community. + + The MIT LICENSE is as follows + -------------------- + Copyright 2024 Dongqiao Huang + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +/* + This file is about liblosuh's API, which is a library for the losuh + */ + +#include "losu.h" + +#ifndef define_included_losuh_h +#define define_included_losuh_h + +void __losuhAPI_regNumber (LosuVm *vm, const char *name, _l_number num); +void __losuhAPI_regString (LosuVm *vm, const char *name, const char *str); +void __losuhAPI_regFunc (LosuVm *vm, const char *name, LosuApi func); +void __losuhAPI_regScript (LosuVm *vm, const char *name, const char *byte, + size_t len); +void __losuhAPI_regObject (LosuVm *vm, const char *name, LosuObj obj); +void __losuhAPI_regClass (LosuVm *vm, const char *name, LosuObj cls); +void __losuhAPI_regObjNumber (LosuVm *vm, LosuObj obj, const char *name, + _l_number num); +void __losuhAPI_regObjString (LosuVm *vm, LosuObj obj, const char *name, + const char *str); +void __losuhAPI_regObjObject (LosuVm *vm, LosuObj obj, const char *name, + LosuObj obj2); +void __losuhAPI_regObjClass (LosuVm *vm, LosuObj obj, const char *name, + const char *type, LosuObj cls); +void __losuhAPI_regObjFunc (LosuVm *vm, LosuObj obj, const char *name, + LosuApi func); + +#endif \ No newline at end of file diff --git a/losu-sdk.sh b/losu-sdk.sh new file mode 100755 index 0000000000000000000000000000000000000000..4f72c92dff7f2cfb5b6acbc93aaba82f348c6376 --- /dev/null +++ b/losu-sdk.sh @@ -0,0 +1,7 @@ +#!/bin/sh +export PATH=$PATH:$LosuSDK_Root/build/bin +echo "-------- Init Losu-SDK-"$LosuSDK_Version" --------" +echo "Code@cloc[Force Losu as Python]" +echo "--------------------------------------------------" +cloc ./ --force-lang=python,lsh --force-lang=python,els --force-lang=c,inc --force-lang=python,config +bash diff --git a/losu/Ubuntu/makefile b/losu/Ubuntu/makefile deleted file mode 100755 index 1b3cc221ebbfabfaef4975ec8f3d0df4b329be0e..0000000000000000000000000000000000000000 --- a/losu/Ubuntu/makefile +++ /dev/null @@ -1,21 +0,0 @@ -# DATAOBJ= els_func.o els_string.o els_unit.o els_object.o -# COMPILER= els_codegen.o els_lex.o els_parser.o -# VMAPI= els_api.o -# VMCORE= els_mem.o els_vmcore.o els_vmhost.o els_heap.o els_gc.o -# LIBS= els_libload.o -# OBJS= $(DATAOBJ) $(COMPILER) $(VMAPI) $(VMCORE) $(LIBS) init.o -OBJS = losu.o - -CFLAGS= -O2 -Wall -std=c99 -DLOSU_LINUX -I ../buildenv -fPIC -CC=x86_64-linux-gnu-gcc -T=./losu - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -lm -ldl -L ../buildenv -leasylosu -s -#-rdynamic -clean: - rm -rf $T $(OBJS) core core.* - diff --git a/losu/Windows/logo.o b/losu/Windows/logo.o deleted file mode 100755 index 079b507eb2a385f53c23a14cabdde818ba755948..0000000000000000000000000000000000000000 Binary files a/losu/Windows/logo.o and /dev/null differ diff --git a/losu/Windows/makefile b/losu/Windows/makefile deleted file mode 100755 index eb2d1094cce20b4cfa60804951f4f43885b177ae..0000000000000000000000000000000000000000 --- a/losu/Windows/makefile +++ /dev/null @@ -1,14 +0,0 @@ -OBJS = losu.o - -CFLAGS= -O2 -Wall -std=c99 -DLOSU_WINDOWS -I ../buildenv -fPIC -static -CC=x86_64-w64-mingw32-gcc -T=losu.exe - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) logo.o -L ../buildenv -l:libeasylosu.dll -lm -static -s -#-rdynamic -clean: - rm -rf $T $(OBJS) core core.* diff --git a/losu/info b/losu/info deleted file mode 100755 index 849a4767846e7c8cca4db046cdeac1f3eff0445e..0000000000000000000000000000000000000000 --- a/losu/info +++ /dev/null @@ -1,24 +0,0 @@ -{ - type = "const", - info = { - name = "losu/解释器与REPL", - text = "洛书解释器主程序", - version = "24.1.28", - }, - source = { - all = { - "losu.c", - }, - Ubuntu = { - "makefile", - }, - Windows = { - "makefile", - "logo.o" - }, - }, - target = { - Ubuntu = "make;cp losu target/losu_Ubuntu;make clean", - Windows = "make;cp losu.exe target/losu.exe;make clean", - } -} \ No newline at end of file diff --git a/losu/losu.c b/losu/losu.c deleted file mode 100755 index 186ffc1ab15e6ec24f504705cbbd65c8d07083b9..0000000000000000000000000000000000000000 --- a/losu/losu.c +++ /dev/null @@ -1,143 +0,0 @@ -#include -#include -#include -#include "els.h" - -int els_getargv (els_VmObj *l); -int els_getargc (els_VmObj *l); -void losu_repl(els_VmObj*l); -void losu_run(els_VmObj*l,const char* libfile,int argc,char** argv); - -#ifdef LOSU_WINDOWS -#include -extern char* vm_win_togbk(const char * str); -extern char* vm_win_toutf8(const char* str); -#endif - -#ifdef LOSU_LINUX -#include -#include -#endif - - -#ifdef LOSU_LINUX - -void losu_run(els_VmObj*l,const char* libfile,int argc,char** argv){ - char tmp[512]; - typedef int (*api)(int c,char** v); - sprintf(tmp,"./ElsLib_%s.lsd",libfile); - - void* dlibptr = dlopen(tmp,RTLD_LAZY); - if(dlibptr==NULL){ - sprintf(tmp,"/els/lib/ElsLib_%s.lsd",libfile); - dlibptr = dlopen(tmp,RTLD_LAZY); - } - if(dlibptr==NULL) { - sprintf(tmp,"LibError: Couldn't find Library\t%s\n",libfile); - printf("%s",tmp); - exit(1); - } - - api func = (api)dlsym(dlibptr,"main"); - if(func==NULL){ - sprintf(tmp,"LibError: Couldn't find Main in Library\t%s\n",libfile); - printf("%s",tmp); - exit(1); - } - func(argc,argv); -} -void losu_repl(els_VmObj*l){ - char tmp[1024]; - while(1){ - printf(">>>>"); - fgets(tmp,1024,stdin); - vm_dostring(l,tmp); - } -} - -#endif - -#ifdef LOSU_WINDOWS - -void losu_repl(els_VmObj*l){ - char tmp[1024]; - char *tmp2; - while(1){ - printf(">>>>"); - fgets(tmp,1024,stdin); - tmp2 = vm_win_toutf8(tmp); - vm_dostring(l,tmp2); - free(tmp2); - } -} -void losu_run(els_VmObj*l,const char* libfile,int argc,char** argv){ - char tmp[512]; - typedef int (*api)(int c,char** v); - sprintf(tmp,"./lib/ElsLib_%s.lsd",libfile); - HMODULE dlibptr = LoadLibrary(tmp); - if(dlibptr == NULL){ - sprintf(tmp,"./ElsLib_%s.lsd",libfile); - dlibptr = LoadLibrary(tmp); - } - api func = (api)GetProcAddress(dlibptr,"main"); - if(func==NULL){ - sprintf(tmp,"LibError: Couldn't find Main in Library\t%s\n",libfile); - printf("%s",tmp); - exit(1); - } - func(argc,argv); -} - -#endif - - - -int main(int argc,char** argv) -{ - int s=0; - els_VmObj *l=vm_create(1024); - vm_setGC(l,1024*1024*2); // 2 M 内存限制,超出时会将 GC提升至满功率,引起一定的性能下降 - els_argc = argc; - els_argv = argv; - #ifdef ELS_CONF_TOKEN_EN - vm_register(l,"argv", els_getargv); - vm_register(l,"argc", els_getargc); - #endif - #ifdef ELS_CONF_TOKEN_CN - vm_register(l,"命令行参数", els_getargv); - vm_register(l,"参数个数", els_getargc); - #endif - - - els_lib_init(l); - vm_dostring(l,"import('stdlib')\n"); - if (argc < 2){ - printf("EasyLosu Script %s\t%s\n%s\n%s\n",ELS_VERSION,ELS_COPYRIGHT,ELS_BUILD,ELS_BRANCH); - printf("----------------------------------------------------------------\n"); - - losu_repl(l); - return 0; - }else{ - if(!strcmp(argv[1],"-r")){ - char tmp[256]; - // if(argc>=3) - // losu_run(l,argv[2],argc-2,&argv[2]); - if(argc>=3) { - els_argc = argc-1; - els_argv = (char**)(argv)+1; - sprintf(tmp,"import(\"%s\")",argv[2]); - s = vm_dostring(l,tmp); - } - }else if(!strcmp(argv[1],"-v")){ - printf("EasyLosu Script %s\t%s\n%s\n%s\n",ELS_VERSION,ELS_COPYRIGHT,ELS_BUILD,ELS_BRANCH); - s = 0; - }else if(!strcmp(argv[1],"-V")){ - printf("%s\n",ELS_VERSION); - s = 0; - }else{ - s = vm_dofile (l,argv[1]); - } - } - vm_close(l); - return s; -} diff --git a/losu/readme.md b/losu/readme.md deleted file mode 100755 index d846458deeb51b88bcb34843b567599dcab5c902..0000000000000000000000000000000000000000 --- a/losu/readme.md +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/owls.wiki.losu.tech -# 洛书解释器 -## 解释文件 -``` -losu [文件名] -``` -## 交互式运行 -``` -losu -``` -## 运行模块 -``` -losu -r [模块名] [参数列表] -``` -## 查看版本 -``` -losu -V -``` -## 查看详细构建信息 -``` -losu -v -``` diff --git a/losu_core/Ubuntu/makefile b/losu_core/Ubuntu/makefile deleted file mode 100755 index 7f9316dc2a1fe910df684ae5dd79a88d80263adf..0000000000000000000000000000000000000000 --- a/losu_core/Ubuntu/makefile +++ /dev/null @@ -1,23 +0,0 @@ -# 为 AMD64 处理器的Linux 系统编译可使用的动态库 - -DATAOBJ= els_func.o els_string.o els_unit.o els_object.o -COMPILER= els_codegen.o els_lex.o els_parser.o -VMAPI= els_api.o -VMCORE= els_mem.o els_vmcore.o els_vmhost.o els_heap.o els_gc.o -LIBS= els_libload.o -OBJS= $(DATAOBJ) $(COMPILER) $(VMAPI) $(VMCORE) $(LIBS) els.o - - -CFLAGS= -O2 -Wall -std=gnu99 -DELS_CONF_OS_LINUX -fPIC -CC=x86_64-linux-gnu-gcc -T=libeasylosu.so - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -shared -lm -ldl -s -clean: - rm -f $T $(OBJS) - - diff --git a/losu_core/Windows/makefile b/losu_core/Windows/makefile deleted file mode 100755 index 783316c1d164c9708551d3e73ddb80cb3faa8ebe..0000000000000000000000000000000000000000 --- a/losu_core/Windows/makefile +++ /dev/null @@ -1,23 +0,0 @@ -# 为 AMD64 处理器的Linux 系统编译可使用的动态库 - -DATAOBJ= els_func.o els_string.o els_unit.o els_object.o -COMPILER= els_codegen.o els_lex.o els_parser.o -VMAPI= els_api.o -VMCORE= els_mem.o els_vmcore.o els_vmhost.o els_heap.o els_gc.o -LIBS= els_libload.o -OBJS= $(DATAOBJ) $(COMPILER) $(VMAPI) $(VMCORE) $(LIBS) els.o - - -CFLAGS= -O2 -Wall -std=gnu99 -DELS_CONF_OS_WINDOWS -fPIC -CC=x86_64-w64-mingw32-gcc -T=libeasylosu.dll - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -shared -lm -s -static -clean: - rm -f $T $(OBJS) - - diff --git a/losu_core/els.c b/losu_core/els.c deleted file mode 100755 index dda0f8c0a5010b05a946d131273effe3825936ab..0000000000000000000000000000000000000000 --- a/losu_core/els.c +++ /dev/null @@ -1,196 +0,0 @@ -#include -#include -#include -#include -#include - -#include "els.h" -#include "els_heap.h" -#include "els_func.h" -#include "els_gc.h" -#include "els_mem.h" -#include "els_object.h" -#include "els_vmhost.h" -#include "els_string.h" -#include "els_unit.h" -#include "els_vmcore.h" - -#ifdef __has_include - #if __has_include("els_version.h") - #include "els_version.h" - #else - #define ELS_CORE_VERSION "core_version 2.0.0" - #endif -#else - #define ELS_CORE_VERSION "core_version 2.0.0" -#endif - -#ifndef ELS_CORE_VERSION - #define ELS_CORE_VERSION "core_version 2.0.0" -#endif - -const int ELS_API_TYPE_BYTE =ELS_TYPE_BYTE; -const int ELS_API_TYPE_NULL =ELS_TYPE_NULL; -const int ELS_API_TYPE_NUMBER =ELS_TYPE_NUMBER; -const int ELS_API_TYPE_STRING =ELS_TYPE_STRING; -const int ELS_API_TYPE_UNIT =ELS_TYPE_UNIT; -const int ELS_API_TYPE_FUNCTION =ELS_TYPE_FUNCTION; -const int ELS_API_TYPE_MARK =ELS_TYPE_MARK; -const int ELS_API_TYPE_PTR =ELS_TYPE_PTR; - -#define STR2(x) #x -#define STR(x) STR2(x) - -const char ELS_VERSION[] = ELS_CORE_VERSION; -const char ELS_COPYRIGHT[] = "MIT LICENSE 2022-2023 chen-chaochen"; -const char ELS_BUILD[128]= "Build ("__DATE__","__TIME__") [GCC " STR(__GNUC__) "."STR(__GNUC_MINOR__)"."STR(__GNUC_PATCHLEVEL__)"]"; -char els_buff_tmp[ELS_BUFF_TMP_SIZE]; - -#ifdef ELS_CONF_OS_LINUX - const char ELS_BRANCH[]="Linux Branch"; -#endif -#ifdef ELS_CONF_OS_WINDOWS - const char ELS_BRANCH[]="Windows Branch"; -#endif -#ifdef ELS_CONF_OS_RTTHREAD - const char ELS_BRANCH[]="Rt-thread Branch"; -#endif - -const char *ELS_TYPESYSTEM[]={ - "byte", - "null", - "number", - "string", - "unit", - "function", - "mark", - "pointer" -}; - - -int losu_printf(const char * format){ - #ifdef ELS_CONF_CHAR_GBK - char* tmp = vm_win_togbk(format); - printf("%s\n",tmp); - free(tmp); - return 0; - #else - printf("%s\n",format); - return 0; - #endif -} - -int els_argc; -char** els_argv; - -#ifdef ELS_CONF_OS_LINUX -int els_getargv (els_VmObj *l){ - if (obj_type(l,arg_get(l,1))!=ELS_TYPE_NUMBER) - arg_return(l,obj_newnull(l)); - else{ - int n = (int) obj_tonum(l,arg_get(l,1)); - if (n > els_argc-2) - arg_returnnull(l); - else - arg_return(l,obj_newstr(l,els_argv[n+1])); - } - return 1; -} -int els_getargc (els_VmObj *l){ - arg_return(l,obj_newnum(l,els_argc-2)); - return 1; -} -#endif - - -#ifdef ELS_CONF_OS_WINDOWS -int els_getargv (els_VmObj *l){ - if (obj_type(l,arg_get(l,1))!=ELS_TYPE_NUMBER) - arg_return(l,obj_newnull(l)); - else{ - int n = (int) obj_tonum(l,arg_get(l,1)); - if (n > els_argc-2) - arg_returnnull(l); - else { - char* tmp = vm_win_toutf8((const char*)els_argv[n+1]); - arg_return(l,obj_newstr(l,tmp)); - free(tmp); - } - } - return 1; -} -int els_getargc (els_VmObj *l){ - arg_return(l,obj_newnum(l,els_argc-2)); - return 1; -} -#endif - - -#ifdef ELS_CONF_CHAR_GBK -#include -char *vm_win_togbk(const char *str) -{ - int len = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0); - wchar_t *strUnicode = (wchar_t *)malloc(len * sizeof(wchar_t *)); - wmemset(strUnicode, 0, len); - MultiByteToWideChar(CP_UTF8, 0, str, -1, strUnicode, len); - len = WideCharToMultiByte(CP_ACP, 0, strUnicode, -1, NULL, 0, NULL, NULL); - char *strGbk = (char *)malloc(len * sizeof(char *)); - memset(strGbk, 0, len); - WideCharToMultiByte(CP_ACP, 0, strUnicode, -1, strGbk, len, NULL, NULL); - free(strUnicode); - strUnicode = NULL; - return strGbk; -} -char *vm_win_toutf8(const char *str) -{ - int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0); - wchar_t *strUnicode = (wchar_t *)malloc(len * sizeof(wchar_t *)); - wmemset(strUnicode, 0, len); - MultiByteToWideChar(CP_ACP, 0, str, -1, strUnicode, len); - len = WideCharToMultiByte(CP_UTF8, 0, strUnicode, -1, NULL, 0, NULL, NULL); - char *strutf8 = (char *)malloc(len * sizeof(char *)); - memset(strutf8, 0, len); - WideCharToMultiByte(CP_UTF8, 0, strUnicode, -1, strutf8, len, NULL, NULL); - free(strUnicode); - strUnicode = NULL; - return strutf8; -} -char * obj_toUTF8(els_VmObj*vm,char* str) -{ - char *s = vm_win_toutf8(str); - LosuObj o = obj_newstr(vm,s); - free(s); - return o.value.ts->str; -} -char * obj_toGBK(els_VmObj*vm,char* str) -{ - char *s = vm_win_togbk(str); - LosuObj o = obj_newstr(vm,s); - free(s); - return o.value.ts->str; -} - - - - -#endif - - -int ElsNewApp(int (*func)(els_VmObj*,const char* s),char *s,int stacksize,size_t gcmax,int argc,const char** argv) -{ - int i = 0; - els_VmObj *vm = vm_create(stacksize); - if(vm==NULL) - return ELS_ERRORBACK_OVER; - vm_setGC(vm,gcmax); - els_lib_init(vm); - #ifdef ELS_CONF_TOKEN_EN - vm_register(vm,"argc",els_getargc); - vm_register(vm,"argv",els_getargv); - #endif - i = func(vm,s); - vm_close(vm); - return i; -} - diff --git a/losu_core/els.h b/losu_core/els.h deleted file mode 100755 index 396eed9ecea32d10367c4fc319bae5f89e77a021..0000000000000000000000000000000000000000 --- a/losu_core/els.h +++ /dev/null @@ -1,358 +0,0 @@ -#ifdef LOSU_WINDOWS - #ifndef ELS_CONF_OS_WINDOWS - #define ELS_CONF_OS_WINDOWS - #endif -#endif - -#ifdef LOSU_LINUX - #ifndef ELS_CONF_OS_LINUX - #define ELS_CONF_OS_LINUX - #endif -#endif - - -#ifdef ELS_CONF_OS_WINDOWS - #ifndef LOSU_WINDOWS - #define LOSU_WINDOWS 1 - #endif - #define ELS_CONF_TOKEN_CN 1 - #define ELS_CONF_TOKEN_EN 1 - #define ELS_CONF_LIBAPI_WIN32 1 - #define ELS_CONF_LIBAPI_ELF 1 - #define ELS_CONF_CHAR_GBK 1 - #define ELS_CONF_GC_ENABLE 1 - #define ELS_VM_STACK_SIZE 1024 - #define ELS_BUFF_TMP_SIZE 1024*1024 - #define ELS_VMIO_SIZE 64 - #define ELS_HEAPMEM_REALLOC realloc - #define ELS_HEAPMEM_FREE free -#endif - -#ifdef ELS_CONF_OS_LINUX - #ifndef LOSU_LINUX - #define LOSU_LINUX 1 - #endif - #define ELS_CONF_TOKEN_CN 1 - #define ELS_CONF_TOKEN_EN 1 - #define ELS_CONF_LIBAPI_DL 1 - #define ELS_CONF_LIBAPI_ELF 1 - #define ELS_CONF_GC_ENABLE 1 - #define ELS_VM_STACK_SIZE 1024 - #define ELS_BUFF_TMP_SIZE 1024*1024 - #define ELS_VMIO_SIZE 64 - #define ELS_HEAPMEM_REALLOC realloc - #define ELS_HEAPMEM_FREE free -#endif - -#ifdef ELS_CONF_OS_EMBEDDEDOS - #define ELS_CONF_TOKEN_CN 1 - #define ELS_CONF_TOKEN_EN 1 - #define ELS_CONF_LIBAPI_ELF 1 - #define ELS_CONF_GC_ENABLE 1 - #define ELS_VM_STACK_SIZE 128 - #define ELS_BUFF_TMP_SIZE 1024 - #define ELS_VMIO_SIZE 64 - #define ELS_HEAPMEM_REALLOC // 所在嵌入式 OS 的内存管理函数 - #define ELS_HEAPMEM_FREE // 所在嵌入式 OS 的内存管理函数 -#endif - -#ifdef ELS_CONF_OS_RTTHREAD - #define ELS_CONF_TOKEN_CN 1 - #define ELS_CONF_TOKEN_EN 1 - #define ELS_CONF_LIBAPI_ELF 1 - #define ELS_CONF_GC_ENABLE 1 - #define ELS_VM_STACK_SIZE 128 - #define ELS_BUFF_TMP_SIZE 1024 - #define ELS_VMIO_SIZE 64 - #define ELS_HEAPMEM_REALLOC rt_realloc - #define ELS_HEAPMEM_REALLOC rt_free -#endif - - - -#ifndef __els_limits_h__ -#define __els_limits_h__ - - #include - #include - - // 16/32 位 模式选择(建议 在 32/64位 物理计算机上运行洛书解释器) - #ifndef BITS_SIZE - #if INT_MAX - 20 < 32760 - #define BITS_SIZE 16 - #else - #if INT_MAX > 2147483640L - #define BITS_SIZE 32 - #else - #error "you must define BITS_SIZE with number of bits in an integer" - #endif - #endif - #endif - - - typedef double Number; - typedef unsigned long lint32; - typedef unsigned long Instruction; - #define els_number2str(s, n) sprintf((s), "%.16g", (n)) - #define els_str2number(s, p) strtod((s), (p)) - - #define MAX_SIZET ((size_t)(~(size_t)0) - 2) - #define MAX_INT (INT_MAX - 2) - #define IntPoint(p) ((unsigned long)(p)) -#endif - -#ifndef __els_h__ -#define __els_h__ - - #include - - #define ELS_API extern - #define ELS_REFNULL (-1) - #define ELS_ANYTAG (-1) - #define ELS_MULTRET (-1) - #define NUM_TAGS 6 - - // 错误代码 子系统 - #define ELS_ERRORBACK_RUN 1 // 运行时错误 - #define ELS_ERRORBACK_FILE 2 // 文件错误 - #define ELS_ERRORBACK_SYNTAX 3 // 语法错误 - #define ELS_ERRORBACK_MEM 4 // 内存错误 - #define ELS_ERRORBACK_HEAP 5 // 虚拟机堆栈溢出 - #define ELS_ERRORBACK_LIB 6 // 模块加载 - #define ELS_ERRORBACK_OVER -1 // 灾难性崩溃 - - - // 数据类型 子系统 - #define ELS_TYPE_BYTE 0 - #define ELS_TYPE_NULL 1 - #define ELS_TYPE_NUMBER 2 - #define ELS_TYPE_STRING 3 - #define ELS_TYPE_UNIT 4 - #define ELS_TYPE_FUNCTION 5 - #define ELS_TYPE_MARK 6 - #define ELS_TYPE_PTR 7 - - extern const int ELS_API_TYPE_BYTE ; - extern const int ELS_API_TYPE_NULL ; - extern const int ELS_API_TYPE_NUMBER ; - extern const int ELS_API_TYPE_STRING ; - extern const int ELS_API_TYPE_UNIT ; - extern const int ELS_API_TYPE_FUNCTION ; - extern const int ELS_API_TYPE_MARK ; - extern const int ELS_API_TYPE_PTR ; - - - typedef struct els_VmObj els_VmObj; - typedef int (*els_C_API_function) (els_VmObj *L); - - #define TSPACK 4 // just for fun - - typedef struct - { - int ttype; - union - { - struct TString *ts; - struct ElsCfunc *cl; - struct Hash *a; - struct CallInfo *i; - double n; - char* ptr; - } value; - } StackObj; - - // 数据类型的声明与实现 - typedef struct TString - { - union - { - struct - { - unsigned long hash; - int constindex; - } s; - } u; - size_t len; - struct TString *nexthash; - int marked; - char str[TSPACK]; - } TString; - typedef struct ElsCfunc - { - union - { - els_C_API_function c; - struct els_func_code *l; - } f; - struct ElsCfunc *next; - struct ElsCfunc *mark; - short isC; - short nupvalues; - StackObj upvalue[1]; - } ElsCfunc; - typedef struct Node - { - StackObj key; - StackObj val; - struct Node *next; - } Node; - typedef struct Hash - { - Node *node; - int htag; - int size; - Node *firstfree; - struct Hash *next; - struct Hash *mark; - } Hash; - typedef struct CallInfo - { - struct ElsCfunc *func; - const Instruction **pc; - int lastpc; - int line; - int refi; - } CallInfo; - // Hash = key & (size-1) - - typedef struct LocVar - { - TString *varname; - int startpc; - int endpc; - } LocVar; - - typedef struct els_func_code - { - Number *knum; - int nknum; - struct TString **kstr; - int nkstr; - struct els_func_code **kcodeir; - int nkcodeir; - Instruction *code; - int ncode; - short numparams; - short is_vararg; - short maxstacksize; - short marked; - struct els_func_code *next; - int *lineinfo; - int nlineinfo; - int nlocvars; - struct LocVar *locvars; - int lineDefined; - TString *source; - } els_func_code; - - typedef StackObj LosuObj; - typedef els_C_API_function VmCapi; - - extern const char ELS_VERSION[]; - extern const char ELS_COPYRIGHT[]; - extern const char ELS_BUILD[]; - extern const char ELS_BRANCH[]; - extern char els_buff_tmp[]; - extern int els_argc; - extern char** els_argv; - extern int els_getargv (els_VmObj *l); - extern int els_getargc (els_VmObj *l); - extern int losu_printf(const char *); - - -#endif - - -/*api lib*/ -ELS_API void els_lib_init(els_VmObj* ); // 初始化内核,加载 import 函数 - - -ELS_API int ElsNewApp(int (*func)(els_VmObj*,const char* s),char *s,int stacksize,size_t gcmax,int argc,const char** argv); - -ELS_API els_VmObj* vm_create(int); -ELS_API els_VmObj* vm_fork(els_VmObj*vm,int size); -ELS_API void vm_stop(els_VmObj*); -ELS_API void vm_error(els_VmObj*,const char* ,int ); -ELS_API int vm_dofile(els_VmObj*,const char* ); -ELS_API int vm_dostring(els_VmObj*,const char* ); -ELS_API LosuObj* vm_getval(els_VmObj*,const char* ); -ELS_API void vm_setval(els_VmObj *,const char* ,LosuObj ); -ELS_API void vm_register(els_VmObj*,const char* ,VmCapi ); -ELS_API void vm_close(els_VmObj*); -ELS_API void vm_setGC(els_VmObj*,unsigned long ); -ELS_API els_VmObj* vm_newthread(els_VmObj*); -ELS_API void vm_endthread(els_VmObj*); -ELS_API unsigned long vm_getmem(els_VmObj*); - -ELS_API LosuObj* arg_get(els_VmObj*,int ); -ELS_API void arg_return(els_VmObj *,LosuObj ); -ELS_API int arg_num(els_VmObj*); - -ELS_API Number arg_getnum(els_VmObj*,int ); -ELS_API const char* arg_getstr(els_VmObj*,int ); -ELS_API const char* arg_getbyte(els_VmObj*,int); -ELS_API char* arg_getptr(els_VmObj*,int ); -ELS_API VmCapi arg_getfunc(els_VmObj*,int ); -ELS_API int arg_gettype(els_VmObj*,int); - -ELS_API void arg_returnnum(els_VmObj*,Number); -ELS_API void arg_returnstr(els_VmObj*,const char* ); -ELS_API void arg_returnfunc(els_VmObj*,VmCapi ); -ELS_API void arg_returnptr(els_VmObj*,char* ); -ELS_API void arg_returnnull(els_VmObj*); -ELS_API void arg_returnbyte(els_VmObj*,char* ,size_t); - - -ELS_API const char* obj_tostr(els_VmObj* ,LosuObj *); -ELS_API Number obj_tonum(els_VmObj* ,LosuObj* ); -ELS_API char* obj_toptr(els_VmObj*,LosuObj*); -ELS_API VmCapi obj_tofunction(els_VmObj*,LosuObj*); -ELS_API const char* obj_tobyte(els_VmObj *,LosuObj *); -ELS_API int obj_type(els_VmObj*,LosuObj*); - -ELS_API LosuObj obj_newstr(els_VmObj* ,char* ); -ELS_API LosuObj obj_newnum(els_VmObj* ,Number ); -ELS_API LosuObj obj_newfunction(els_VmObj*,els_C_API_function ); -ELS_API LosuObj obj_newnull(els_VmObj* ); -ELS_API LosuObj obj_newunit(els_VmObj* ); -ELS_API LosuObj obj_newptr(els_VmObj*,char* ); -ELS_API LosuObj obj_newbyte(els_VmObj*,char*,size_t ); - -ELS_API LosuObj* obj_indexunit(els_VmObj*,LosuObj ,LosuObj ); -ELS_API LosuObj* obj_indexunitbynum(els_VmObj*vm,LosuObj unit,Number i); -ELS_API LosuObj* obj_indexunitbystr(els_VmObj*vm,LosuObj unit,char* s); -ELS_API void obj_setunit(els_VmObj*,LosuObj ,LosuObj ,LosuObj ); -ELS_API void obj_setunitbynum(els_VmObj*,LosuObj unit,Number key ,LosuObj value); -ELS_API void obj_setunitbystr(els_VmObj*,LosuObj unit,char* key ,LosuObj value); - - -ELS_API Node * obj_unit_first(els_VmObj*vm,LosuObj unit); -ELS_API Node obj_unit_location(els_VmObj*vm,LosuObj unit,LosuObj key); -ELS_API Node * obj_unit_next(els_VmObj*vm,LosuObj unit,Node*n); -ELS_API LosuObj obj_unit_nodekey(els_VmObj*vm,Node* n); -ELS_API LosuObj obj_unit_nodevalue(els_VmObj*vm,Node* n); - - - -// 栈操作 API 暂时不对其进行拓展,仅提供最基本的功能,可以用于在虚拟机栈上构建函数并调用 -ELS_API void stack_push (els_VmObj*vm,LosuObj o); -ELS_API void stack_pop (els_VmObj*vm,int i); -ELS_API void stack_call (els_VmObj*vm,int argnum,int resnum); - - - -// 下面4个 API 仅在 Windows 内核中被启用,负责字符集的转换。 - // 洛书的内核全部为 utf-8编码,可以使用转换函数,将其转换为 GBK 后传递给 Windows API - // 手动转换函数,转换后的字符串被存放在堆区中,需要手动释放堆区 -ELS_API char* vm_win_togbk(const char * ); -ELS_API char* vm_win_toutf8(const char* ); - // 自动转换函数,转换后的字符串被存放在 Vm 的字符池中,会在下一个周期被 GC 自动回收 ( 如果GC 被 启动) -ELS_API char* obj_toUTF8(els_VmObj*,char*); -ELS_API char* obj_toGBK(els_VmObj*,char* ); - - -ELS_API const char *ELS_TYPESYSTEM[]; -ELS_API char els_buff_tmp[]; - - - diff --git a/losu_core/els_api.c b/losu_core/els_api.c deleted file mode 100755 index cedc3bdec180b15290a9a92fbb8c0e01e9024804..0000000000000000000000000000000000000000 --- a/losu_core/els_api.c +++ /dev/null @@ -1,447 +0,0 @@ -#include - -#include "els.h" -#include "els_heap.h" -#include "els_func.h" -#include "els_gc.h" -#include "els_mem.h" -#include "els_object.h" -#include "els_vmhost.h" -#include "els_string.h" -#include "els_unit.h" -#include "els_vmcore.h" - -#define GCscale(x) ((int)((x) >> 10)) -#define GCunscale(x) ((unsigned long)(x) << 10) -#define api_incr_top(L) incr_top(L) - - -extern int parse_file(els_VmObj *L, const char *filename); -extern int parse_buffer(els_VmObj *L, const char *buff, size_t size, const char *name); - -ELS_API els_VmObj *els_createvm(int stacksize); -ELS_API void els_closevm(els_VmObj *L); -char *vm_win_togbk(const char *str); -ELS_API int els_call(els_VmObj *L, int nargs, int nresults); -extern ElsCfunc *els_Vmcore_csfunction(els_VmObj *L, int issues_num); - -static int currentline(StackObj *f); -static int currentpc(StackObj *f); -static int trygetline(int *lineinfo, int pc, int refline, int *prefi); - - -static int trygetline(int *lineinfo, int pc, int refline, int *prefi) -{ - int refi; - if (lineinfo == NULL || pc == -1) - return -1; /* no line info */ - refi = prefi ? *prefi : 0; - if (lineinfo[refi] < 0) - refline += -lineinfo[refi++]; - while (lineinfo[refi] > pc) - { - refline--; - refi--; - if (lineinfo[refi] < 0) - refline -= -lineinfo[refi--]; - } - for (;;) - { - int nextline = refline + 1; - int nextref = refi + 1; - if (lineinfo[nextref] < 0) - nextline += -lineinfo[nextref++]; - if (lineinfo[nextref] > pc) - break; - refline = nextline; - refi = nextref; - } - if (prefi) - *prefi = refi; - return refline; -} - -static int currentpc(StackObj *f) -{ - CallInfo *ci = f->value.i; - if (ci->pc) - return (*ci->pc - ci->func->f.l->code) - 1; - else - return -1; -} - -static int currentline(StackObj *f) -{ - if (!(f && f->ttype == ELS_TYPE_MARK && !f->value.i->func->isC)) - return currentline(f - 1); - CallInfo *ci = f->value.i; - int *lineinfo = ci->func->f.l->lineinfo; - return trygetline(lineinfo, currentpc(f), 1, NULL); -} - - - - -/*Vm api*/ - -ELS_API els_VmObj *vm_create(int stacksize); -ELS_API els_VmObj* vm_fork(els_VmObj*vm,int size); -ELS_API void vm_close(els_VmObj *vm); - - - -ELS_API void vm_stop(els_VmObj *vm) -{ - els_Heap_breakrun(vm, 0); -} - -ELS_API void vm_error(els_VmObj *vm, const char *s,int errnum) -{ -#ifdef ELS_CONF_CHAR_GBK - char tmp[64]; - sprintf(tmp,"运行时错误: \t%s\n在第\t%d\t行\n",s,currentline(vm->top - 1)); - printf("%s",obj_toGBK(vm,tmp)); - // printf("%s: \t%s\n在第\t%d\t行\n", obj_toGBK(vm,"运行时错误"),obj_toGBK(vm,s), currentline(vm->top - 1)); -#else - printf("运行时错误: \t%s\n在第\t%d\t行\n", s, currentline(vm->top - 1)); -#endif - els_Heap_breakrun(vm, errnum); -} -ELS_API int vm_dofile(els_VmObj *vm, const char *filename) -{ - int i; - if (!(i = parse_file(vm, filename))) - return els_call(vm, 0, ELS_MULTRET); - return i; -} -ELS_API int vm_dostring(els_VmObj *vm, const char *str) -{ - int i; - if (!(i = parse_buffer(vm, str, strlen(str), str))) - return els_call(vm, 0, ELS_MULTRET); - return i; -} -ELS_API LosuObj *vm_getval(els_VmObj *vm, const char *name) -{ - return (LosuObj *)els_Unit_getstr(vm->globalenv, els_string_new(vm, name)); -} -ELS_API void vm_setval(els_VmObj *vm, const char *name, LosuObj o) -{ - const StackObj *oldvalue = els_Unit_getstr(vm->globalenv, els_string_new(vm, name)); - if (oldvalue != &els_Object_nullobject) - { - *(StackObj *)oldvalue = o; - } - else - { - StackObj key; - ttype(&key) = ELS_TYPE_STRING; - tsvalue(&key) = els_string_new(vm, name); - *els_Unit_set(vm, vm->globalenv, &key) = o; - } -} -ELS_API void vm_register(els_VmObj *vm, const char *name, els_C_API_function f) -{ - LosuObj tmp; - tmp.ttype = ELS_TYPE_FUNCTION; - tmp.value.cl = els_Vmcore_csfunction(vm, 0); - tmp.value.cl->isC = 1; - tmp.value.cl->f.c = f; - const StackObj *oldvalue = els_Unit_getstr(vm->globalenv, els_string_new(vm, name)); - if (oldvalue != &els_Object_nullobject) - { - *(StackObj *)oldvalue = tmp; - } - else - { - StackObj key; - ttype(&key) = ELS_TYPE_STRING; - tsvalue(&key) = els_string_new(vm, name); - *els_Unit_set(vm, vm->globalenv, &key) = tmp; - } -} - -ELS_API void vm_setGC(els_VmObj*vm,unsigned long size){ - vm->GCnowmax = size; - vm->GCMAX = size; -} - - -ELS_API unsigned long vm_getmem(els_VmObj*vm){ - return vm->nblocks; -} - - -/* arg */ -ELS_API LosuObj *arg_get(els_VmObj *vm, int i) -{ - if (i >= 0) - { - StackObj *o = vm->Cbase + (i - 1); - if (o >= vm->top) - o->ttype = ELS_TYPE_NULL; - return o; - } - else - return vm->top + i; -} -ELS_API void arg_return(els_VmObj *vm, LosuObj o) -{ - *(vm->top) = (o); - if (vm->top == vm->stack_last) - els_Heap_checkstack(vm, 1); - vm->top++; -} -ELS_API int arg_num(els_VmObj *vm) -{ - return (int)(vm->top - vm->Cbase); -} - - - -ELS_API Number arg_getnum(els_VmObj *vm, int i) -{ - return obj_tonum(vm, arg_get(vm, i)); -} -ELS_API const char *arg_getstr(els_VmObj *vm, int i) -{ - return obj_tostr(vm, arg_get(vm, i)); -} -ELS_API char *arg_getptr(els_VmObj *vm, int i) -{ - return obj_toptr(vm, arg_get(vm, i)); -} -ELS_API VmCapi arg_getfunc(els_VmObj *vm, int i) -{ - return obj_tofunction(vm, arg_get(vm, i)); -} -ELS_API const char* arg_getbyte(els_VmObj*vm,int i) -{ - return obj_tobyte(vm,arg_get(vm,i)); -} -ELS_API int arg_gettype(els_VmObj *vm, int i) -{ - return obj_type(vm, arg_get(vm, i)); -} - - - -ELS_API void arg_returnnum(els_VmObj *vm, Number i) -{ - nvalue(vm->top) = i; - ttype(vm->top) = ELS_TYPE_NUMBER; - if (vm->top == vm->stack_last) - els_Heap_checkstack(vm, 1); - vm->top++; -} -ELS_API void arg_returnstr(els_VmObj *vm, const char *s) -{ - if (s == NULL) - ttype(vm->top) = ELS_TYPE_STRING; - else - { - ttype(vm->top) = ELS_TYPE_STRING; - tsvalue(vm->top) = els_string_newlstr(vm, s, strlen(s)); - } - if (vm->top == vm->stack_last) - els_Heap_checkstack(vm, 1); - vm->top++; -} -// ELS_API void arg_returnfunc(els_VmObj *vm, VmCapi f) -// { -// vm->top->value.cl->f.c = f; -// ttype(vm->top) = ELS_TYPE_FUNCTION; -// if (vm->top == vm->stack_last) -// els_Heap_checkstack(vm, 1); -// vm->top++; -// } -ELS_API void arg_returnfunc(els_VmObj *vm, VmCapi f) -{ - arg_return(vm,obj_newfunction(vm,f)); -} - -ELS_API void arg_returnptr(els_VmObj *vm, char *p) -{ - vm->top->value.ptr = p; - ttype(vm->top) = ELS_TYPE_PTR; - if (vm->top == vm->stack_last) - els_Heap_checkstack(vm, 1); - vm->top++; -} -ELS_API void arg_returnnull(els_VmObj *vm) -{ - ttype(vm->top) = ELS_TYPE_NULL; - if (vm->top == vm->stack_last) - els_Heap_checkstack(vm, 1); - vm->top++; -} -ELS_API void arg_returnbyte(els_VmObj*vm,char* p,size_t len) -{ - arg_return(vm,obj_newbyte(vm,p,len)); -} - - -/* obj */ -ELS_API const char *obj_tostr(els_VmObj *vm, LosuObj *o) -{ - return (o == NULL || tostring(vm, o)) ? "" : svalue(o); -} -ELS_API Number obj_tonum(els_VmObj *vm, LosuObj *o) -{ - return (o == NULL || tonumber(o)) ? 0 : nvalue(o); -} -ELS_API char *obj_toptr(els_VmObj *vm, LosuObj *o) -{ - if (ttype(o) == ELS_TYPE_PTR) - return o->value.ptr; - return NULL; -} -ELS_API VmCapi obj_tofunction(els_VmObj *vm, LosuObj *o) -{ - if (ttype(o) == ELS_TYPE_FUNCTION) - return o->value.cl->f.c; - return NULL; -} -ELS_API int obj_type(els_VmObj *vm, LosuObj *o) -{ - return ttype(o); -} -ELS_API const char* obj_tobyte(els_VmObj *vm,LosuObj *o) -{ - return ttype(o)==ELS_TYPE_BYTE ? svalue(o) : NULL; -} - -ELS_API LosuObj obj_newstr(els_VmObj *vm, char *str) -{ - LosuObj tmp; - tmp.ttype = ELS_TYPE_STRING; - tmp.value.ts = els_string_new(vm, str); - return tmp; -} -ELS_API LosuObj obj_newnum(els_VmObj *vm, Number n) -{ - LosuObj tmp; - tmp.ttype = ELS_TYPE_NUMBER; - tmp.value.n = n; - return tmp; -} -ELS_API LosuObj obj_newfunction(els_VmObj *vm,VmCapi f) -{ - LosuObj tmp; - tmp.ttype = ELS_TYPE_FUNCTION; - tmp.value.cl = els_Vmcore_csfunction(vm, 0); - tmp.value.cl->isC = 1; - tmp.value.cl->f.c = f; - return tmp; -} -ELS_API LosuObj obj_newnull(els_VmObj *vm) -{ - return els_Object_nullobject; -} -ELS_API LosuObj obj_newunit(els_VmObj *vm) -{ - LosuObj tmp; - tmp.ttype = ELS_TYPE_UNIT; - hvalue(&tmp) = els_Unit_new(vm, 0); - hvalue((&tmp))->htag = ELS_TYPE_UNIT; - return tmp; -} -ELS_API LosuObj obj_newptr(els_VmObj *vm, char *p) -{ - LosuObj tmp; - tmp.ttype = ELS_TYPE_PTR; - tmp.value.ptr = p; - return tmp; -} -ELS_API LosuObj obj_newbyte(els_VmObj*vm,char*p,size_t len) -{ - LosuObj o; - o.value.ts = els_string_newlstr(vm,p,len); - o.ttype = ELS_TYPE_BYTE; - return o; - -} - -ELS_API LosuObj *obj_indexunit(els_VmObj *vm, LosuObj unit, LosuObj key) -{ - if (unit.ttype == ELS_TYPE_UNIT) - return (LosuObj *)els_Unit_get(vm, hvalue(&unit), &key); - return NULL; -} -ELS_API void obj_setunit(els_VmObj *vm, LosuObj unit, LosuObj key, LosuObj value) -{ - if (unit.ttype == ELS_TYPE_UNIT) - *els_Unit_set(vm, hvalue(&unit), &key) = value; - return; -} -ELS_API LosuObj* obj_indexunitbynum(els_VmObj*vm,LosuObj unit,Number i){ - if (unit.ttype == ELS_TYPE_UNIT) - return (LosuObj *)els_Unit_getnum(hvalue(&unit),i); - return NULL; -} -ELS_API LosuObj* obj_indexunitbystr(els_VmObj*vm,LosuObj unit,char* s){ - LosuObj key = obj_newstr(vm,s); - if (unit.ttype == ELS_TYPE_UNIT) - return (LosuObj *)els_Unit_get(vm, hvalue(&unit), &key); - return NULL; -} -ELS_API void obj_setunitbynum(els_VmObj*vm,LosuObj unit,Number i ,LosuObj value){ - LosuObj key = obj_newnum(vm,i); - if (unit.ttype == ELS_TYPE_UNIT) - *els_Unit_set(vm, hvalue(&unit), &key) = value; - return; -} -ELS_API void obj_setunitbystr(els_VmObj*vm,LosuObj unit,char* s ,LosuObj value){ - LosuObj key = obj_newstr(vm,s); - if (unit.ttype == ELS_TYPE_UNIT) - *els_Unit_set(vm, hvalue(&unit), &key) = value; - return; -} - - -ELS_API void stack_push (els_VmObj*vm,LosuObj o){ - *(vm->top)=o; - if (vm->top == vm->stack_last) - els_Heap_checkstack(vm, 1); - vm->top++; -} -ELS_API void stack_pop (els_VmObj*vm,int i){ - vm->top-=i; -} -ELS_API void stack_call (els_VmObj*vm,int argnum,int resnum){ - els_Heap_call(vm,vm->top - (argnum+1) ,resnum); -} - -ELS_API Node * obj_unit_first(els_VmObj*vm,LosuObj unit){ - if(obj_type(vm,&unit)!=ELS_TYPE_UNIT) - return NULL; - return els_Unit_next(vm, hvalue(&unit),&els_Object_nullobject); -} -ELS_API Node obj_unit_location(els_VmObj*vm,LosuObj unit,LosuObj key){ - Node n; - if(obj_type(vm,&unit)!=ELS_TYPE_UNIT){ - n.val = obj_newnull(vm); - n.key = obj_newnull(vm); - return n; - } - LosuObj* v = (LosuObj*)els_Unit_get(vm,hvalue(&unit),&key); - if(v==NULL) - n.val = obj_newnull(vm); - else - n.val = *v; - n.key = key; - return n; -} -ELS_API Node * obj_unit_next(els_VmObj*vm,LosuObj unit,Node*n){ - if(obj_type(vm,&unit)!=ELS_TYPE_UNIT) - return NULL; - - return els_Unit_next(vm,hvalue(&unit),(const LosuObj*)(&n->key)); - -} -ELS_API LosuObj obj_unit_nodekey(els_VmObj*vm,Node* n){ - return n->key; -} -ELS_API LosuObj obj_unit_nodevalue(els_VmObj*vm,Node* n){ - return n->val; -} \ No newline at end of file diff --git a/losu_core/els_bytecode.h b/losu_core/els_bytecode.h deleted file mode 100755 index 567b89cc3410347062d7c12f69dd38ecde8349f5..0000000000000000000000000000000000000000 --- a/losu_core/els_bytecode.h +++ /dev/null @@ -1,158 +0,0 @@ -#ifndef __els_bytecode_h__ -#define __els_bytecode_h__ - -#include "els.h" - -#define SIZE_INSTRUCTION 32 - -#define SIZE_B 9 -#define SIZE_OP 6 -#define SIZE_A (SIZE_INSTRUCTION - (SIZE_OP + SIZE_B)) -#define SIZE_U (SIZE_INSTRUCTION - SIZE_OP) - -#define POS_U SIZE_OP -#define POS_B SIZE_OP -#define POS_A (SIZE_OP + SIZE_B) - - - - - -#if SIZE_U < BITS_SIZE - 1 - #define MAX_ARG_U ((1 << SIZE_U) - 1) - #define MAX_ARG_S (MAX_ARG_U >> 1) -#else - #define MAX_ARG_U MAX_INT - #define MAX_ARG_S MAX_INT -#endif - - -#if SIZE_A < BITS_SIZE - 1 - #define MAX_ARG_A ((1 << SIZE_A) - 1) -#else - #define MAX_ARG_A MAX_INT -#endif - - -#if SIZE_B < BITS_SIZE - 1 - #define MAX_ARG_B ((1 << SIZE_B) - 1) -#else - #define MAX_ARG_B MAX_INT -#endif - - - - -#define MAXSTACK 256 //表达式栈上限 -#if MAXSTACK > MAX_ARG_B - #undef MAXSTACK - #define MAXSTACK MAX_ARG_B -#endif - - -#define LFIELDS_PER_FLUSH 64 -#if LFIELDS_PER_FLUSH > (MAXSTACK / 4) - #undef LFIELDS_PER_FLUSH - #define LFIELDS_PER_FLUSH (MAXSTACK / 4) -#endif - -#define RFIELDS_PER_FLUSH (LFIELDS_PER_FLUSH / 2) -#define LOOKBACKNUMS 32 - - -#define MASK1(n,p) ((~((~(Instruction)0)<>POS_U)) -#define SETARG_U(i,u) ((i) = (((i)&MASK0(SIZE_U,POS_U)) | ((Instruction)(u)<>POS_A)) -#define SETARG_A(i,a) ((i) = (((i)&MASK0(SIZE_A,POS_A)) | ((Instruction)(a)<>POS_B) & MASK1(SIZE_B,0))) -#define SETARG_B(i,b) ((i) = (((i)&MASK0(SIZE_B,POS_B)) | ((Instruction)(b)<MAX_ARG_B -#undef MULT_RET -#define MULT_RET MAX_ARG_B -#endif - -#endif diff --git a/losu_core/els_codegen.c b/losu_core/els_codegen.c deleted file mode 100755 index 1f7120bd66516db2225f19e6aaa364b7616342d7..0000000000000000000000000000000000000000 --- a/losu_core/els_codegen.c +++ /dev/null @@ -1,646 +0,0 @@ -#include "stdlib.h" - -#include "els.h" - -#include "els_codegen.h" -#include "els_heap.h" -#include "els_lex.h" -#include "els_mem.h" -#include "els_object.h" -#include "els_bytecode.h" -#include "els_parser.h" -#include "els_vmcore.h" -#include - -#define code_label(fs,op,arg) (els_codegen_getlabel(fs),els_codegen_code_arg1(fs,op,arg)) - -static const struct -{ - ByteIR opcode; - int arg; -} codes[] = { - {BYTECODE_ADD, 0}, - {BYTECODE_SUB, 0}, - {BYTECODE_MULT, 0}, - {BYTECODE_DIV, 0}, - {BYTECODE_POW, 0}, - {BYTECODE_CONCAT, 0}, - {BYTECODE_JMPNE, NO_JUMP}, - {BYTECODE_JMPEQ, NO_JUMP}, - {BYTECODE_JMPLT, NO_JUMP}, - {BYTECODE_JMPLE, NO_JUMP}, - {BYTECODE_JMPGT, NO_JUMP}, - {BYTECODE_JMPGE, NO_JUMP} -}; - - -const struct Bytecodesubframe els_codegen_bytecodesubframe[] = { - {iO, 0, 0}, /* BYTECODE_END */ - {iU, 0, 0}, /* BYTECODE_RETURN */ - {iAB, 0, 0}, /* BYTECODE_CALL */ - {iU, VD, 0}, /* BYTECODE_PUSHNULL */ - {iU, VD, 0}, /* BYTECODE_POP */ - {iU, 1, 0}, /* BYTECODE_PUSHSTRING */ - {iU, 1, 0}, /* BYTECODE_PUSHNUM */ - {iU, 1, 0}, /* BYTECODE_PUSHUPVALUE */ - {iU, 1, 0}, /* BYTECODE_GETLOCAL */ - {iU, 1, 0}, /* BYTECODE_GETGLOBAL */ - {iO, 1, 2}, /* BYTECODE_GETUNIT */ - {iU, 2, 1}, /* BYTECODE_PUSHSELF */ - {iU, 1, 0}, /* BYTECODE_CREATEUNIT */ - {iU, 0, 1}, /* BYTECODE_SETLOCAL */ - {iU, 0, 1}, /* BYTECODE_SETGLOBAL */ - {iAB, VD, 0}, /* BYTECODE_SETUNIT */ - {iAB, VD, 0}, /* BYTECODE_SETLIST */ - {iU, VD, 0}, /* BYTECODE_SETMAP */ - {iO, 1, 2}, /* BYTECODE_ADD */ - {iO, 1, 2}, /* BYTECODE_SUB */ - {iO, 1, 2}, /* BYTECODE_MULT */ - {iO, 1, 2}, /* BYTECODE_DIV */ - {iO, 1, 2}, /* BYTECODE_POW */ - {iO, 1, 2}, /* BYTECODE_CONCAT */ - {iO, 1, 1}, /* BYTECODE_MINUS */ - {iO, 1, 1}, /* BYTECODE_NOT */ - {iS, 0, 2}, /* BYTECODE_JMPNE */ - {iS, 0, 2}, /* BYTECODE_JMPEQ */ - {iS, 0, 2}, /* BYTECODE_JMPLT */ - {iS, 0, 2}, /* BYTECODE_JMPLE */ - {iS, 0, 2}, /* BYTECODE_JMPGT */ - {iS, 0, 2}, /* BYTECODE_JMPGE */ - {iS, 0, 1}, /* BYTECODE_JMPT */ - {iS, 0, 1}, /* BYTECODE_JMPF */ - {iS, 0, 1}, /* BYTECODE_JMPONT */ - {iS, 0, 1}, /* BYTECODE_JMPONF */ - {iS, 0, 0}, /* BYTECODE_JMP */ - {iO, 0, 0}, /* BYTECODE_PUSHNULLJMP */ - {iS, 0, 0}, /* BYTECODE_FORPREP */ - {iS, 0, 3}, /* BYTECODE_FORLOOP */ - {iS, 2, 0}, /* BYTECODE_LFORPREP */ - {iS, 0, 3}, /* BYTECODE_LFORLOOP */ - {iAB, VD, 0} /* BYTECODE_PUSHFUNCTION */ -}; - -int els_codegen_jump(ElsFuncObj *fs) -{ - int j = els_codegen_code_arg1(fs, BYTECODE_JMP, NO_JUMP); - if (j == fs->lasttarget) - { - els_codegen_concat(fs, &j, fs->jlt); - fs->jlt = NO_JUMP; - } - return j; -} - -static void els_codegen_fixjump(ElsFuncObj *fs, int pc, int dest) -{ - Instruction *jmp = &fs->f->code[pc]; - if (dest == NO_JUMP) - SETARG_S(*jmp, NO_JUMP); - else - { - int offset = dest - (pc + 1); - if (abs(offset) > MAX_ARG_S){ - els_codegen_error(fs->ls, "控制结构超出长度限制"); - } - SETARG_S(*jmp, offset); - } -} - -static int els_codegen_getjump(ElsFuncObj *fs, int pc) -{ - int offset = GETARG_S(fs->f->code[pc]); - if (offset == NO_JUMP) - return NO_JUMP; - else - return (pc + 1) + offset; -} - -int els_codegen_getlabel(ElsFuncObj *fs) -{ - if (fs->pc != fs->lasttarget) - { - int lasttarget = fs->lasttarget; - fs->lasttarget = fs->pc; - els_codegen_patchlist(fs, fs->jlt, lasttarget); - fs->jlt = NO_JUMP; - } - return fs->pc; -} - -void els_codegen_deltastack(ElsFuncObj *fs, int delta) -{ - fs->stacklevel += delta; - if (fs->stacklevel > fs->f->maxstacksize) - { - if (fs->stacklevel > MAXSTACK){ - els_codegen_error(fs->ls, "表达式过于复杂"); - } - fs->f->maxstacksize = fs->stacklevel; - } -} - -static int number_constant(ElsFuncObj *fs, Number r) -{ - els_func_code *f = fs->f; - int c = f->nknum; - int lim = c < LOOKBACKNUMS ? 0 : c - LOOKBACKNUMS; - while (--c >= lim) - if (f->knum[c] == r) - return c; - els_Mem_growvector(fs->L, f->knum, f->nknum, 1, Number, "内存单元溢出", MAX_ARG_U); - c = f->nknum++; - f->knum[c] = r; - return c; -} - -void els_codegen_number(ElsFuncObj *fs, Number f) -{ - els_codegen_code_arg1(fs, BYTECODE_PUSHNUM, number_constant(fs, f)); -} - -void els_codegen_adjuststack(ElsFuncObj *fs, int n) -{ - if (n > 0) - els_codegen_code_arg1(fs, BYTECODE_POP, n); - else - els_codegen_code_arg1(fs, BYTECODE_PUSHNULL, -n); -} - -int els_codegen_lastisopen(ElsFuncObj *fs) -{ - Instruction i = next_instruction(fs); - if (GET_OPCODE(i) == BYTECODE_CALL && GETARG_B(i) == MULT_RET) - return 1; - else - return 0; -} - -void els_codegen_setcallreturns(ElsFuncObj *fs, int nresults) -{ - if (els_codegen_lastisopen(fs)) - { - SETARG_B(fs->f->code[fs->pc - 1], nresults); - els_codegen_deltastack(fs, nresults); - } -} - -static int discharge(ElsFuncObj *fs, expdesc *var) -{ - switch (var->k) - { - case VLOCAL: - els_codegen_code_arg1(fs, BYTECODE_GETLOCAL, var->u.index); - break; - case VGLOBAL: - els_codegen_code_arg1(fs, BYTECODE_GETGLOBAL, var->u.index); - break; - case VINDEXED: - els_codegen_code_arg0(fs, BYTECODE_GETUNIT); - break; - case VEXP: - return 0; - } - var->k = VEXP; - var->u.l.t = var->u.l.f = NO_JUMP; - return 1; -} - -static void discharge1(ElsFuncObj *fs, expdesc *var) -{ - discharge(fs, var); - if (var->u.l.t == NO_JUMP && var->u.l.f == NO_JUMP) - els_codegen_setcallreturns(fs, 1); -} - -void els_codegen_storevar(LexObject *ls, const expdesc *var) -{ - ElsFuncObj *fs = ls->fs; - switch (var->k) - { - case VLOCAL: - els_codegen_code_arg1(fs, BYTECODE_SETLOCAL, var->u.index); - break; - case VGLOBAL: - els_codegen_code_arg1(fs, BYTECODE_SETGLOBAL, var->u.index); - break; - case VINDEXED: - els_codegen_code_arg2(fs, BYTECODE_SETUNIT, 3, 3); - break; - default:; - } -} - -static ByteIR invertjump(ByteIR op) -{ - switch (op) - { - case BYTECODE_JMPNE: - return BYTECODE_JMPEQ; - case BYTECODE_JMPEQ: - return BYTECODE_JMPNE; - case BYTECODE_JMPLT: - return BYTECODE_JMPGE; - case BYTECODE_JMPLE: - return BYTECODE_JMPGT; - case BYTECODE_JMPGT: - return BYTECODE_JMPLE; - case BYTECODE_JMPGE: - return BYTECODE_JMPLT; - case BYTECODE_JMPT: - case BYTECODE_JMPONT: - return BYTECODE_JMPF; - case BYTECODE_JMPF: - case BYTECODE_JMPONF: - return BYTECODE_JMPT; - default: - return BYTECODE_END; - } -} - -static void els_codegen_patchlistaux(ElsFuncObj *fs, int list, int target, ByteIR special, int special_target) -{ - Instruction *code = fs->f->code; - while (list != NO_JUMP) - { - int next = els_codegen_getjump(fs, list); - Instruction *i = &code[list]; - ByteIR op = GET_OPCODE(*i); - if (op == special) - els_codegen_fixjump(fs, list, special_target); - else - { - els_codegen_fixjump(fs, list, target); - if (op == BYTECODE_JMPONT) - SET_OPCODE(*i, BYTECODE_JMPT); - else if (op == BYTECODE_JMPONF) - SET_OPCODE(*i, BYTECODE_JMPF); - } - list = next; - } -} - -void els_codegen_patchlist(ElsFuncObj *fs, int list, int target) -{ - if (target == fs->lasttarget) - els_codegen_concat(fs, &fs->jlt, list); - else - els_codegen_patchlistaux(fs, list, target, BYTECODE_END, 0); -} - -static int need_value(ElsFuncObj *fs, int list, ByteIR hasvalue) -{ - for (; list != NO_JUMP; list = els_codegen_getjump(fs, list)) - if (GET_OPCODE(fs->f->code[list]) != hasvalue) - return 1; - return 0; -} - -void els_codegen_concat(ElsFuncObj *fs, int *l1, int l2) -{ - if (*l1 == NO_JUMP) - *l1 = l2; - else - { - int list = *l1; - while(1) - { - int next = els_codegen_getjump(fs, list); - if (next == NO_JUMP) - { - els_codegen_fixjump(fs, list, l2); - return; - } - list = next; - } - } -} - -static void els_codegen_testgo(ElsFuncObj *fs, expdesc *v, int invert, ByteIR jump) -{ - int prevpos; - Instruction *previous; - int *golist, *exitlist; - if (!invert) - { - golist = &v->u.l.f; - exitlist = &v->u.l.t; - } - else - { - golist = &v->u.l.t; - exitlist = &v->u.l.f; - } - discharge1(fs, v); - prevpos = fs->pc - 1; - previous = &fs->f->code[prevpos]; - if (!ISJUMP(GET_OPCODE(*previous))) - prevpos = els_codegen_code_arg1(fs, jump, NO_JUMP); - else - { - if (invert) - SET_OPCODE(*previous, invertjump(GET_OPCODE(*previous))); - } - els_codegen_concat(fs, exitlist, prevpos); - els_codegen_patchlist(fs, *golist, els_codegen_getlabel(fs)); - *golist = NO_JUMP; -} - -void els_codegen_goiftrue(ElsFuncObj *fs, expdesc *v, int keepvalue) -{ - els_codegen_testgo(fs, v, 1, keepvalue ? BYTECODE_JMPONF : BYTECODE_JMPF); -} - -static void els_codegen_goiffalse(ElsFuncObj *fs, expdesc *v, int keepvalue) -{ - els_codegen_testgo(fs, v, 0, keepvalue ? BYTECODE_JMPONT : BYTECODE_JMPT); -} - -void els_codegen_tostack(LexObject *ls, expdesc *v, int onlyone) -{ - ElsFuncObj *fs = ls->fs; - if (!discharge(fs, v)) - { - ByteIR previous = GET_OPCODE(fs->f->code[fs->pc - 1]); - if (!ISJUMP(previous) && v->u.l.f == NO_JUMP && v->u.l.t == NO_JUMP) - { - - if (onlyone) - els_codegen_setcallreturns(fs, 1); - } - else - { - int final; - int j = NO_JUMP; - int p_null = NO_JUMP; - int p_1 = NO_JUMP; - if (ISJUMP(previous) || need_value(fs, v->u.l.f, BYTECODE_JMPONF) || need_value(fs, v->u.l.t, BYTECODE_JMPONT)) - { - - if (ISJUMP(previous)) - els_codegen_concat(fs, &v->u.l.t, fs->pc - 1); - else - { - j = code_label(fs, BYTECODE_JMP, NO_JUMP); - - els_codegen_adjuststack(fs, 1); - } - p_null = code_label(fs, BYTECODE_PUSHNULLJMP, 0); - p_1 = code_label(fs, BYTECODE_PUSHNUM, 1); - els_codegen_patchlist(fs, j, els_codegen_getlabel(fs)); - } - final = els_codegen_getlabel(fs); - els_codegen_patchlistaux(fs, v->u.l.f, p_null, BYTECODE_JMPONF, final); - els_codegen_patchlistaux(fs, v->u.l.t, p_1, BYTECODE_JMPONT, final); - v->u.l.f = v->u.l.t = NO_JUMP; - } - } -} - -void els_codegen_prefix(LexObject *ls, UnOpr op, expdesc *v) -{ - ElsFuncObj *fs = ls->fs; - if (op == OPR_MINUS) - { - els_codegen_tostack(ls, v, 1); - els_codegen_code_arg0(fs, BYTECODE_MINUS); - } - else - { - Instruction *previous; - discharge1(fs, v); - previous = &fs->f->code[fs->pc - 1]; - if (ISJUMP(GET_OPCODE(*previous))) - SET_OPCODE(*previous, invertjump(GET_OPCODE(*previous))); - else - els_codegen_code_arg0(fs, BYTECODE_NOT); - - { - int temp = v->u.l.f; - v->u.l.f = v->u.l.t; - v->u.l.t = temp; - } - } -} - -void els_codegen_infix(LexObject *ls, BinOpr op, expdesc *v) -{ - ElsFuncObj *fs = ls->fs; - switch (op) - { - case OPR_AND: - els_codegen_goiftrue(fs, v, 1); - break; - case OPR_OR: - els_codegen_goiffalse(fs, v, 1); - break; - default: - els_codegen_tostack(ls, v, 1); - } -} - - -void els_codegen_posfix(LexObject *ls, BinOpr op, expdesc *v1, expdesc *v2) -{ - ElsFuncObj *fs = ls->fs; - switch (op) - { - case OPR_AND: - { - discharge1(fs, v2); - v1->u.l.t = v2->u.l.t; - els_codegen_concat(fs, &v1->u.l.f, v2->u.l.f); - break; - } - case OPR_OR: - { - discharge1(fs, v2); - v1->u.l.f = v2->u.l.f; - els_codegen_concat(fs, &v1->u.l.t, v2->u.l.t); - break; - } - default: - { - els_codegen_tostack(ls, v2, 1); - els_codegen_code_arg1(fs, codes[op].opcode, codes[op].arg); - } - } -} - -static void codelineinfo(ElsFuncObj *fs) -{ - els_func_code *f = fs->f; - LexObject *ls = fs->ls; - if (ls->lastline > fs->lastline) - { - els_Mem_growvector(fs->L, f->lineinfo, f->nlineinfo, 2, int, - "代码行数溢出", MAX_INT); - if (ls->lastline > fs->lastline + 1) - f->lineinfo[f->nlineinfo++] = -(ls->lastline - (fs->lastline + 1)); - f->lineinfo[f->nlineinfo++] = fs->pc; - fs->lastline = ls->lastline; - } -} - -int els_codegen_code_arg2(ElsFuncObj *fs, ByteIR o, int arg1, int arg2) -{ - Instruction i = next_instruction(fs); - int delta = els_codegen_bytecodesubframe[o].push - els_codegen_bytecodesubframe[o].pop; - int optm = 0; - switch (o) - { - case BYTECODE_PUSHFUNCTION: - { - delta = -arg2 + 1; - break; - } - case BYTECODE_SETUNIT: - { - delta = -arg2; - break; - } - case BYTECODE_SETLIST: - { - if (arg2 == 0) - return NO_JUMP; - delta = -arg2; - break; - } - case BYTECODE_SETMAP: - { - if (arg1 == 0) - return NO_JUMP; - delta = -2 * arg1; - break; - } - case BYTECODE_PUSHNULL: - { - if (arg1 == 0) - return NO_JUMP; - delta = arg1; - switch (GET_OPCODE(i)) - { - case BYTECODE_PUSHNULL: - SETARG_U(i, GETARG_U(i) + arg1); - optm = 1; - break; - default: - break; - } - break; - } - case BYTECODE_POP: - { - if (arg1 == 0) - return NO_JUMP; - delta = -arg1; - switch (GET_OPCODE(i)) - { - case BYTECODE_SETUNIT: - SETARG_B(i, GETARG_B(i) + arg1); - optm = 1; - break; - default: - break; - } - break; - } - case BYTECODE_JMPNE: - { - if (i == CREATE_U(BYTECODE_PUSHNULL, 1)) - { - i = CREATE_S(BYTECODE_JMPT, NO_JUMP); - optm = 1; - } - break; - } - case BYTECODE_JMPEQ: - { - if (i == CREATE_U(BYTECODE_PUSHNULL, 1)) - { - i = CREATE_0(BYTECODE_NOT); - delta = -1; - optm = 1; - } - break; - } - case BYTECODE_JMPT: - case BYTECODE_JMPONT: - { - switch (GET_OPCODE(i)) - { - case BYTECODE_NOT: - { - i = CREATE_S(BYTECODE_JMPF, NO_JUMP); - optm = 1; - break; - } - case BYTECODE_PUSHNULL: - { - if (GETARG_U(i) == 1) - { - fs->pc--; - els_codegen_deltastack(fs, -1); - return NO_JUMP; - } - break; - } - default: - break; - } - break; - } - case BYTECODE_JMPF: - case BYTECODE_JMPONF: - { - switch (GET_OPCODE(i)) - { - case BYTECODE_NOT: - { - i = CREATE_S(BYTECODE_JMPT, NO_JUMP); - optm = 1; - break; - } - case BYTECODE_PUSHNULL: - { - if (GETARG_U(i) == 1) - { - i = CREATE_S(BYTECODE_JMP, NO_JUMP); - optm = 1; - } - break; - } - default: - break; - } - break; - } - default:break; - } - els_codegen_deltastack(fs, delta); - if (optm) - { - fs->f->code[fs->pc - 1] = i; - return fs->pc - 1; - } - - switch ((enum Mode)els_codegen_bytecodesubframe[o].mode) - { - case iO: - i = CREATE_0(o); - break; - case iU: - i = CREATE_U(o, arg1); - break; - case iS: - i = CREATE_S(o, arg1); - break; - case iAB: - i = CREATE_AB(o, arg1, arg2); - break; - } - codelineinfo(fs); - - els_Mem_growvector(fs->L, fs->f->code, fs->pc, 1, Instruction,"字节码溢出", MAX_INT); - fs->f->code[fs->pc] = i; - return fs->pc++; -} diff --git a/losu_core/els_codegen.h b/losu_core/els_codegen.h deleted file mode 100755 index 2e5aae42d01cfb77b0800d5c04d78b9e49f1d486..0000000000000000000000000000000000000000 --- a/losu_core/els_codegen.h +++ /dev/null @@ -1,60 +0,0 @@ - -#ifndef els_code_h -#define els_code_h - -#include "els_lex.h" -#include "els_object.h" -#include "els_bytecode.h" -#include "els_parser.h" -#include "els_vmcore.h" - -#define NO_JUMP (-1) - -typedef enum BinOpr { - OPR_ADD, OPR_SUB, OPR_MULT, OPR_DIV, OPR_POW, - OPR_CONCAT, - OPR_NE, OPR_EQ, OPR_LT, OPR_LE, OPR_GT, OPR_GE, - OPR_AND, OPR_OR, - OPR_NOBINOPR -} BinOpr; - -typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_NOUNOPR } UnOpr; - - -enum Mode {iO, iU, iS, iAB}; - -#define VD 100 - -extern const struct Bytecodesubframe { - char mode; - unsigned char push; - unsigned char pop; -} els_codegen_bytecodesubframe[]; - - - -int els_codegen_code_arg2 (ElsFuncObj *, ByteIR , int , int ); -int els_codegen_jump (ElsFuncObj *); -void els_codegen_patchlist (ElsFuncObj *, int , int ); -void els_codegen_concat (ElsFuncObj *, int *, int ); -void els_codegen_goiftrue (ElsFuncObj *fs, expdesc *, int ); -int els_codegen_getlabel (ElsFuncObj *); -void els_codegen_deltastack (ElsFuncObj *, int ); -void els_codegen_number (ElsFuncObj *, Number ); -void els_codegen_adjuststack (ElsFuncObj *, int ); -int els_codegen_lastisopen (ElsFuncObj *); -void els_codegen_setcallreturns (ElsFuncObj *, int ); -void els_codegen_tostack (LexObject *, expdesc *, int ); -void els_codegen_storevar (LexObject *, const expdesc *); -void els_codegen_prefix (LexObject *, UnOpr , expdesc *); -void els_codegen_infix (LexObject *, BinOpr , expdesc *); -void els_codegen_posfix (LexObject *, BinOpr , expdesc *, expdesc *); - -#define els_codegen_code_arg0(fs,o) (els_codegen_code_arg2(fs,o,0,0)) -#define els_codegen_code_arg1(fs,o,arg) (els_codegen_code_arg2(fs,o,arg,0)) -#define els_codegen_kstr(ls,c) (els_codegen_code_arg1(ls->fs, BYTECODE_PUSHSTRING, c)) -#define els_codegen_error(ls,msg) els_compiler_error(ls,msg) -#define next_instruction(fs) ( (fs->pc > fs->lasttarget)?(fs->f->code[fs->pc-1]):((Instruction)(BYTECODE_END)) ) -#define els_codegen_kstr(ls,c) (els_codegen_code_arg1(ls->fs, BYTECODE_PUSHSTRING, c)) - -#endif diff --git a/losu_core/els_func.c b/losu_core/els_func.c deleted file mode 100755 index 3e9c2a05b0a38dc7e0870fa2d0da6d81bf98f58c..0000000000000000000000000000000000000000 --- a/losu_core/els_func.c +++ /dev/null @@ -1,72 +0,0 @@ -#include -#include -#include "els.h" -#include "els_func.h" -#include "els_mem.h" -#include "els_vmhost.h" - -#define size_csfunciotn(n) ((int)sizeof(ElsCfunc) + (int)sizeof(StackObj) * ((n)-1)) -#define codeirsize(f) (sizeof(els_func_code) + f->nknum * sizeof(Number) + f->nkstr * sizeof(TString *) + f->nkcodeir * sizeof(els_func_code *) + f->ncode * sizeof(Instruction) + f->nlocvars * sizeof(struct LocVar) + f->nlineinfo * sizeof(int)) - - -els_func_code *els_ScriptFunc_newcodeir(els_VmObj *L) -{ - els_func_code *f = els_Mem_new(L, els_func_code); - memset((void*)f,0,sizeof(els_func_code)); - f->next = L->rootcodeir; - L->rootcodeir = f; - return f; -} - -ElsCfunc *els_ScriptFunc_new_csfunciotn(els_VmObj *L, int issues_num) -{ - int size = size_csfunciotn(issues_num); - ElsCfunc *c = (ElsCfunc *)els_Mem_malloc(L, size); - c->next = L->rootcl; - L->rootcl = c; - c->mark = c; - c->nupvalues = issues_num; - L->nblocks += size; - return c; -} - -void els_ScriptFunc_freecodeir(els_VmObj *L, els_func_code *f) -{ - if (f->ncode > 0) - L->nblocks -= codeirsize(f); - els_Mem_free(L, f->code); - els_Mem_free(L, f->locvars); - els_Mem_free(L, f->kstr); - els_Mem_free(L, f->knum); - els_Mem_free(L, f->kcodeir); - els_Mem_free(L, f->lineinfo); - els_Mem_free(L, f); -} - -void els_ScriptFunc_free_csfunciotn(els_VmObj *L, ElsCfunc *c) -{ - L->nblocks -= size_csfunciotn(c->nupvalues); - els_Mem_free(L, c); -} - - -void els_ScriptFunc_end(els_VmObj *L, els_func_code *f, int pc) -{ - f->ncode = pc; - L->nblocks += codeirsize(f); -} - -const char *els_ScriptFunc_getlocalname(const els_func_code *f, int local_number, int pc) -{ - int i; - for (i = 0; i < f->nlocvars && f->locvars[i].startpc <= pc; i++) - { - if (pc < f->locvars[i].endpc) - { - local_number--; - if (local_number == 0) - return f->locvars[i].varname->str; - } - } - return NULL; -} diff --git a/losu_core/els_func.h b/losu_core/els_func.h deleted file mode 100755 index d9e4d1e70bfb7ee00e29f315e7ec4da010a4cef0..0000000000000000000000000000000000000000 --- a/losu_core/els_func.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef __els_func_h__ -#define __els_func_h__ - -#include "els_object.h" - - -els_func_code *els_ScriptFunc_newcodeir (els_VmObj *); -void els_ScriptFunc_end (els_VmObj *, els_func_code *, int ); -ElsCfunc *els_ScriptFunc_new_csfunciotn (els_VmObj *, int ); -void els_ScriptFunc_freecodeir (els_VmObj *, els_func_code *); -void els_ScriptFunc_free_csfunciotn (els_VmObj *, ElsCfunc *); - -const char *els_ScriptFunc_getlocalname (const els_func_code *, int , int ); - - -#endif \ No newline at end of file diff --git a/losu_core/els_gc.c b/losu_core/els_gc.c deleted file mode 100755 index 3f21f96638bb7a0d2db0ed3f01d963d3775ed6ad..0000000000000000000000000000000000000000 --- a/losu_core/els_gc.c +++ /dev/null @@ -1,297 +0,0 @@ -#include "els.h" - -#include "els_heap.h" -#include "els_func.h" -#include "els_gc.h" -#include "els_mem.h" -#include "els_object.h" -#include "els_vmhost.h" -#include "els_string.h" -#include "els_unit.h" - -#define MINBUFFER 256 -#define strmark(s) \ - { \ - if ((s)->marked == 0) \ - (s)->marked = 1; \ - } -#define VALIDLINK(L, st, n) (NONEXT <= (st) && (st) < (n)) - -typedef struct GcObj -{ - Hash *tmark; - ElsCfunc *cmark; -} GcObj; - -static void markobject(GcObj *st, StackObj *o); - -static void codeirmark(els_func_code *f) -{ - if (!f->marked) - { - int i; - f->marked = 1; - strmark(f->source); - for (i = 0; i < f->nkstr; i++) - strmark(f->kstr[i]); - for (i = 0; i < f->nkcodeir; i++) - codeirmark(f->kcodeir[i]); - for (i = 0; i < f->nlocvars; i++) - strmark(f->locvars[i].varname); - } -} - -static void markstack(els_VmObj *L, GcObj *st) -{ - StackObj* o; - for (o = L->stack; o < L->top; o++) - markobject(st, o); -} - -static void marklock(els_VmObj *L, GcObj *st) -{ - int i; - for (i = 0; i < L->refSize; i++) - { - if (L->refArray[i].st == LOCK) - markobject(st, &L->refArray[i].o); - } -} - -static void mark_csfunciotn(GcObj *st, ElsCfunc *cl) -{ - if (!ismarked(cl)) - { - if (!cl->isC) - codeirmark(cl->f.l); - cl->mark = st->cmark; - st->cmark = cl; - } -} - -static void markobject(GcObj *st, StackObj *o) -{ - switch (ttype(o)) - { - case ELS_TYPE_STRING: - case ELS_TYPE_BYTE: - strmark(tsvalue(o)); - break; - case ELS_TYPE_MARK: - mark_csfunciotn(st, infovalue(o)->func); - break; - case ELS_TYPE_FUNCTION: - mark_csfunciotn(st, clvalue(o)); - break; - case ELS_TYPE_UNIT: - { - if (!ismarked(hvalue(o))) - { - hvalue(o)->mark = st->tmark; - st->tmark = hvalue(o); - } - break; - } - default: - break; - } -} - -static void markall(els_VmObj *L) -{ - GcObj st; - st.cmark = NULL; - st.tmark = L->globalenv; - L->globalenv->mark = NULL; - markstack(L, &st); - marklock(L, &st); - while (1) - { - if (st.cmark) - { - int i; - ElsCfunc *f = st.cmark; - st.cmark = f->mark; - for (i = 0; i < f->nupvalues; i++) - markobject(&st, &f->upvalue[i]); - } - else if (st.tmark) - { - int i; - Hash *h = st.tmark; - st.tmark = h->mark; - for (i = 0; i < h->size; i++) - { - Node *n = node(h, i); - if (ttype(key(n)) != ELS_TYPE_NULL) - { - if (ttype(val(n)) == ELS_TYPE_NULL) - els_Unit_remove(h, key(n)); - markobject(&st, &n->key); - markobject(&st, &n->val); - } - } - } - else - break; - } -} - -static int hasmark(const StackObj *o) -{ - - switch (o->ttype) - { - case ELS_TYPE_STRING: - case ELS_TYPE_BYTE: - return tsvalue(o)->marked; - case ELS_TYPE_UNIT: - return ismarked(hvalue(o)); - case ELS_TYPE_FUNCTION: - return ismarked(clvalue(o)); - default: - return 1; - } -} - -static void invalidaterefs(els_VmObj *L) -{ - int n = L->refSize; - int i; - for (i = 0; i < n; i++) - { - struct Ref *r = &L->refArray[i]; - if (r->st == HOLD && !hasmark(&r->o)) - r->st = COLLECTED; - } -} - -static void collectcodeir(els_VmObj *L) -{ - els_func_code **p = &L->rootcodeir; - els_func_code *next; - while ((next = *p) != NULL) - { - if (next->marked) - { - next->marked = 0; - p = &next->next; - } - else - { - *p = next->next; - els_ScriptFunc_freecodeir(L, next); - } - } -} - -static void collect_csfunciotn(els_VmObj *L) -{ - ElsCfunc **p = &L->rootcl; - ElsCfunc *next; - while ((next = *p) != NULL) - { - if (ismarked(next)) - { - next->mark = next; - p = &next->next; - } - else - { - *p = next->next; - els_ScriptFunc_free_csfunciotn(L, next); - } - } -} - -static void collectunit(els_VmObj *L) -{ - Hash **p = &L->rootunit; - Hash *next; - while ((next = *p) != NULL) - { - if (ismarked(next)) - { - next->mark = next; - p = &next->next; - } - else - { - *p = next->next; - els_Unit_free(L, next); - } - } -} - - - -static void collectstrings(els_VmObj *L, int all) -{ - int i; - for (i = 0; i < L->strpool.size; i++) - { - TString **p = &L->strpool.hash[i]; - TString *next; - while ((next = *p) != NULL) - { - if (next->marked && !all) - { - if (next->marked < FIXMARK) - next->marked = 0; - p = &next->nexthash; - } - else - { - *p = next->nexthash; - L->strpool.nuse--; - L->nblocks -= sizestring(next->len); - els_Mem_free(L, next); - } - } - } - if (L->strpool.nuse < (lint32)(L->strpool.size / 4) && L->strpool.size > 10) - els_string_resize(L, &L->strpool, L->strpool.size / 2); -} - - - -static void checkBufferTmp(els_VmObj *L) -{ - if (L->BufferTmpSize > MINBUFFER * 2) - { - size_t newsize = L->BufferTmpSize / 2; - L->nblocks += (newsize - L->BufferTmpSize) * sizeof(char); - L->BufferTmpSize = newsize; - els_Mem_reallocvector(L, L->BufferTmp, newsize, char); - } -} - - - -static void els_Gc_collectgarbage(els_VmObj *L) -{ - markall(L); - invalidaterefs(L); - els_Gc_collect(L, 0); - checkBufferTmp(L); - L->GCnowmax = 2 * L->nblocks; -} - - - -void els_Gc_collect(els_VmObj *L, int all) -{ - collectstrings(L, all); - collectunit(L); - collectcodeir(L); - collect_csfunciotn(L); -} - -void els_Gc_checkGC(els_VmObj *L) -{ - if (L->nblocks >= L->GCnowmax){ - els_Gc_collectgarbage(L); - if(L->GCnowmax > L->GCMAX) - L->GCnowmax = L->GCMAX; - } -} diff --git a/losu_core/els_gc.h b/losu_core/els_gc.h deleted file mode 100755 index 3cc63dd5fe9c39a7c26c9fb68760ff41704a9783..0000000000000000000000000000000000000000 --- a/losu_core/els_gc.h +++ /dev/null @@ -1,14 +0,0 @@ - - -#ifndef __els_gc_h__ -#define __els_gc_h__ - - -#include "els_object.h" - - -void els_Gc_collect (els_VmObj *, int ); -void els_Gc_checkGC (els_VmObj *); - - -#endif diff --git a/losu_core/els_heap.c b/losu_core/els_heap.c deleted file mode 100755 index bc665d99db904f5f76987379af571665a2c4052c..0000000000000000000000000000000000000000 --- a/losu_core/els_heap.c +++ /dev/null @@ -1,254 +0,0 @@ -#include -#include -#include - - - -#include "els.h" -#include "els_heap.h" -#include "els_gc.h" -#include "els_mem.h" -#include "els_object.h" -#include "els_parser.h" -#include "els_vmhost.h" -#include "els_string.h" -#include "els_unit.h" -#include "els_vmcore.h" - - -#define ELS_MINSTACK 16 - -void els_Heap_init(els_VmObj *L, int stacksize) -{ - L->stack = els_Mem_newvector(L, stacksize, StackObj); - L->nblocks += stacksize * sizeof(StackObj); - L->stack_last = L->stack + (stacksize - 1); - L->stacksize = stacksize; - L->Cbase = L->top = L->stack; -} - -void els_Heap_checkstack(els_VmObj *L, int n) -{ - if (L->stack_last - L->top <= n) - vm_error(L, "虚拟机堆栈溢出",ELS_ERRORBACK_HEAP); -} - -void restore_stack_limit(els_VmObj *L) -{ - if (L->top - L->stack < L->stacksize - 1) - L->stack_last = L->stack + (L->stacksize - 1); -} - -void els_Heap_adjusttop(els_VmObj *L, StackObj* base, int extra) -{ - int diff = extra - (L->top - base); - if (diff <= 0) - L->top = base + extra; - else - { - els_Heap_checkstack(L, diff); - while (diff--) - ttype(L->top++) = ELS_TYPE_NULL; - } -} - -void els_Heap_openstack(els_VmObj *L, StackObj* pos) -{ - int i = L->top - pos; - while (i--) - pos[i + 1] = pos[i]; - incr_top(L); -} - -StackObj* callC_csfunciotn(els_VmObj *L, const struct ElsCfunc *cl, StackObj* base) -{ - int nup = cl->nupvalues; - StackObj* old_Cbase = L->Cbase; - int n; - L->Cbase = base; - els_Heap_checkstack(L, nup + ELS_MINSTACK); - for (n = 0; n < nup; n++) - *(L->top++) = cl->upvalue[n]; - n = ((*cl->f.c)(L)); - L->Cbase = old_Cbase; - return L->top - n; -} - -int els_Heap_call(els_VmObj *L, StackObj* func, int nResults) -{ - StackObj* firstResult; - CallInfo ci; - ElsCfunc *cl; - // if(ttype(func)==ELS_TYPE_UNIT){ - // *func = *obj_indexunit(L,*func,obj_newstr(L,"class")); - // } - if (ttype(func) != ELS_TYPE_FUNCTION) - { - - vm_error(L, "被调用的变量不是函数",ELS_ERRORBACK_RUN); - return 1; - } - cl = clvalue(func); - ci.func = cl; - infovalue(func) = &ci; - ttype(func) = ELS_TYPE_MARK; - firstResult = (cl->isC ? callC_csfunciotn(L, cl, func + 1) : els_Vmcore_execute(L, cl, func + 1)); - if (nResults == ELS_MULTRET) - { - while (firstResult < L->top) - *func++ = *firstResult++; - L->top = func; - } - else - { - for (; nResults > 0 && firstResult < L->top; nResults--) - *func++ = *firstResult++; - L->top = func; - for (; nResults > 0; nResults--) - { - ttype(L->top) = ELS_TYPE_NULL; - incr_top(L); - } - } -#ifdef ELS_CONF_GC_ENABLE - els_Gc_checkGC(L); -#endif - return 0; -} - - -struct CallS -{ - StackObj* func; - int nresults; -}; - -void f_call(els_VmObj *L, void *ud) -{ - struct CallS *c = (struct CallS *)ud; - els_Heap_call(L, c->func, c->nresults); -} - -ELS_API int els_call(els_VmObj *L, int nargs, int nresults) -{ - StackObj* func = L->top - (nargs + 1); - struct CallS c; - int status; - c.func = func; - c.nresults = nresults; - - - StackObj* oldCbase = L->Cbase; - StackObj* oldtop = L->top; - struct els_longjmp lj; - lj.status = 0; - lj.previous = L->errorJmp; - L->errorJmp = &lj; - if (setjmp(lj.b) == 0) - f_call(L, &c); - else - { - L->Cbase = oldCbase; - L->top = oldtop; - restore_stack_limit(L); - } - L->errorJmp = lj.previous; - status = lj.status; - - L->top = func; - return status; -} - -struct ParserS -{ - vm_iobuff *z; - int bin; -}; - -void f_parser(els_VmObj *L, void *ud) -{ - struct ParserS *p = (struct ParserS *)ud; - els_func_code *tf = els_parser_parse(L, p->z); - els_Vmcore_L_csfunciotn(L, tf, 0); -} - -int protectedparser(els_VmObj *L, vm_iobuff *z, int bin) -{ - struct ParserS p; - unsigned long old_blocks; - int status; - p.z = z; - p.bin = bin; -#ifdef ELS_CONF_GC_ENABLE - els_Gc_checkGC(L); -#endif - old_blocks = L->nblocks; - - StackObj* oldCbase = L->Cbase; - StackObj* oldtop = L->top; - struct els_longjmp lj; - lj.status = 0; - lj.previous = L->errorJmp; - L->errorJmp = &lj; - if (setjmp(lj.b) == 0) - f_parser(L, &p); - else - { - L->Cbase = oldCbase; - L->top = oldtop; - restore_stack_limit(L); - } - L->errorJmp = lj.previous; - status = lj.status; - - if (status == 0) - { - L->GCnowmax += (L->nblocks - old_blocks); - } - else if (status == ELS_ERRORBACK_RUN) - status = ELS_ERRORBACK_SYNTAX; - return status; -} - -int parse_file(els_VmObj *L, const char *filename) -{ - vm_iobuff z; - int status; - FILE *f = fopen(filename, "r"); - if (f == NULL) - { - char tmp[256]; - sprintf(tmp, "警告:找不到文件 `%s'", filename); - losu_printf(tmp); - return ELS_ERRORBACK_FILE; - } - els_vmio_Fopen(&z, f, filename); - status = protectedparser(L, &z, 0); - if (f != stdin) - fclose(f); - return status; -} - -int parse_buffer(els_VmObj *L, const char *buff, size_t size, const char *name) -{ - vm_iobuff z; - els_vmio_mopen(&z, buff, size, name); - return protectedparser(L, &z, 0); -} - - -void els_Heap_breakrun(els_VmObj *L, int errcode) -{ - if (L->errorJmp) - { - L->errorJmp->status = errcode; - longjmp(L->errorJmp->b, 1); - } - else - { - losu_printf("无法维持,系统已崩溃\n"); - exit(ELS_ERRORBACK_OVER); - } -} - - diff --git a/losu_core/els_heap.h b/losu_core/els_heap.h deleted file mode 100755 index 5fdeff0d8b5aa948f2af60a653b6099fdd788662..0000000000000000000000000000000000000000 --- a/losu_core/els_heap.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef __els_heap_h__ -#define __els_heap_h__ - -#include "els.h" -#include "els_object.h" - -#define incr_top(L) {if (L->top == L->stack_last) els_Heap_checkstack(L, 1); L->top++;} - -void els_Heap_init (els_VmObj *, int ); -void els_Heap_adjusttop (els_VmObj *, StackObj* , int ); -int els_Heap_call (els_VmObj *, StackObj* , int); - -void els_Heap_checkstack (els_VmObj *, int ); - -void els_Heap_breakrun (els_VmObj *, int ); - - - - -#endif \ No newline at end of file diff --git a/losu_core/els_lex.c b/losu_core/els_lex.c deleted file mode 100755 index b3ef3a1577769a958021c97879b9312d5ef7efb4..0000000000000000000000000000000000000000 --- a/losu_core/els_lex.c +++ /dev/null @@ -1,588 +0,0 @@ -#include -#include -#include -#include "els.h" - -#include "els_lex.h" -#include "els_mem.h" -#include "els_object.h" -#include "els_parser.h" -#include "els_vmhost.h" -#include "els_string.h" -#include "els_unit.h" - -#define next(LS) (LS->current = els_vmio_getc(LS->z)) -#define checkbuffer(L, n, len) \ - if ((len) + (n) > L->BufferTmpSize) \ - els_Object_openspace(L, (len) + (n)) - -#define save(L, c, l) (L->BufferTmp[l++] = (char)c) -#define save_and_next(L, LS, l) (save(L, LS->current, l), next(LS)) - -char laststr[128]; -int lasttokenid; -struct -{ - const char* string; - int key; -}const keyword[] = { -#ifdef ELS_CONF_TOKEN_EN - {"and", TOKEN_AND}, - {"break", TOKEN_BREAK}, - {"block", TOKEN_BLOCK}, - {"else", TOKEN_ELSE}, - {"elif", TOKEN_ELSEIF}, - {"for", TOKEN_FOR}, - {"def", TOKEN_FUNCTION}, - {"if", TOKEN_IF}, - {"var", TOKEN_VAR}, - {"null", TOKEN_NULL}, - {"not", TOKEN_NOT}, - {"or", TOKEN_OR}, - {"loop", TOKEN_LOOP}, - {"rt", TOKEN_RETURN}, - {"return", TOKEN_RETURN}, - {"to", TOKEN_TO}, - {"with", TOKEN_WITH}, - {"pass", TOKEN_END}, -#endif -#ifdef ELS_CONF_TOKEN_CN - {"且", TOKEN_AND}, - {"跳出", TOKEN_BREAK}, - {"代码块", TOKEN_BLOCK}, - {"否则", TOKEN_ELSE}, - {"另外", TOKEN_ELSEIF}, - {"计次", TOKEN_FOR}, - {"列举", TOKEN_FOR}, - {"方法", TOKEN_FUNCTION}, - {"如果", TOKEN_IF}, - {"令", TOKEN_VAR}, - {"空", TOKEN_NULL}, - {"非", TOKEN_NOT}, - {"或", TOKEN_OR}, - {"重复", TOKEN_LOOP}, - {"回", TOKEN_RETURN}, - {"至", TOKEN_TO}, - {"当", TOKEN_WITH}, - {"结束", TOKEN_END}, - {"此", TOKEN_THIS}, - {"__极值__", TOKEN_FOR_MAX}, - {"__步幅__", TOKEN_FOR_STEP}, - {"__此__", TOKEN_FOR_THIS}, - {"变参", TOKEN_VARARG}, - {"构造",TOKEN_CONST}, -#endif - - {";", TOKEN_END}, -}; - -void els_lexer_init(els_VmObj *L) -{ - int i; - for (i = 0; i < sizeof(keyword) / sizeof(keyword[0]); i++) - { - TString *ts = els_string_new(L, keyword[i].string); - ts->marked = keyword[i].key; - } -} - -void els_lexer_token2str(int token, char *s) -{ - if (token < 256) - { - s[0] = (char)(token); - s[1] = '\0'; - /* - 使用sprintf不是一个很好的选择 - sprintf(s,"%c",(char)token); - */ - } - else - { - int i; - for (i = 0; i < sizeof(keyword) / sizeof(keyword[0]); i++) - if ((int)keyword[i].key == token) - break; - ; - strcpy(s, keyword[i].string); - } -} - -#define inclinenumber(LS) (next(LS), ++LS->linenumber) - -void els_lexer_setinput(els_VmObj *L, LexObject *LS, vm_iobuff *z, TString *source) -{ - LS->L = L; - LS->lookahead.token = TOKEN_EOS; - LS->z = z; - LS->fs = NULL; - LS->linenumber = 1; - LS->lastline = 1; - LS->source = source; - next(LS); -} - - -static int utf8_code_bytes( unsigned char byte) -{ - int bytes = 0; - if (byte <= 0x7F) { //then ASCII 占用1个字节 - bytes = 1; - } else if (byte >= 0xC0 && byte <= 0xDF) { // then 首字节 UTF-8 占用2个字节 - bytes = 2; - } else if (byte >= 0xE0 && byte <= 0xEF) { // then 首字节 UTF-8 占用3个字节 - bytes = 3; - } else if (byte >= 0xF0 && byte <= 0xF7) { // then 首字节 UTF-8 占用4个字节 - bytes = 4; - } else if (byte >= 0xF8 && byte <= 0xFB) { // then 首字节 UTF-8 占用5个字节 - bytes = 5; - } else if (byte >= 0xFC && byte <= 0xFD) { // then 首字节 UTF-8 占用6个字节 - bytes = 6; - } else if (byte > 0x7F && byte < 0xC0 ) { // then UTF-8 非首字节 - bytes = 0; - } - - return bytes; -} - -static const char *read_name(LexObject *LS) -{ - els_VmObj *L = LS->L; - size_t l = 0; - do - { - int le = utf8_code_bytes((unsigned char)(LS->current)); - - for (int i = 0;icurrent) || LS->current == '_' || utf8_code_bytes((unsigned char)(LS->current)) > 1); - save(L, '\0', l); - return L->BufferTmp; -} - -static void read_number(LexObject *LS, int comma, SemInfo *seminfo) -{ - char errorinfo[64]; - els_VmObj *L = LS->L; - size_t l = 0; - checkbuffer(L, 10, l); - if (comma) - save(L, '.', l); - while (isdigit(LS->current)) - { - checkbuffer(L, 10, l); - save_and_next(L, LS, l); - } - if (LS->current == '.') - { - save_and_next(L, LS, l); - if (LS->current == '.') - { - save_and_next(L, LS, l); - save(L, '\0', l); - sprintf(errorinfo, "错误的数字格式"); - els_compiler_error(LS, errorinfo); - } - } - while (isdigit(LS->current)) - { - checkbuffer(L, 10, l); - save_and_next(L, LS, l); - } - if (LS->current == 'e' || LS->current == 'E') - { - save_and_next(L, LS, l); - if (LS->current == '+' || LS->current == '-') - save_and_next(L, LS, l); - while (isdigit(LS->current)) - { - checkbuffer(L, 10, l); - save_and_next(L, LS, l); - } - } - save(L, '\0', l); - if (!els_Object_str2d(L->BufferTmp, &seminfo->r)) - { - sprintf(errorinfo, "错误的数字格式,在第 %d 行", LS->linenumber); - els_compiler_error(LS, errorinfo); - } -} - -static int read_string(LexObject *LS, int del, SemInfo *seminfo) -{ - els_VmObj *L = LS->L; - size_t l = 0; - checkbuffer(L, 10, l); - save_and_next(L, LS, l); - if (LS->current != del) - { - - while (LS->current != del) - { - if(LS->current==EOZ) - els_compiler_error(LS,"字符串溢出"); - if(LS->current=='\n') ++ LS->linenumber; - checkbuffer(L, 10, l); - if(LS->current=='%'){ - next(LS); - int t=0; - if(!(('0'<= LS->current && LS->current<='9')||('a'<= LS->current && LS->current<='f')||('A'<= LS->current && LS->current<='F') )) - els_compiler_error(LS,"转义序列超出范围"); - switch (LS->current) - { - case 'A': case 'a': - t = 16*10; - break; - case 'B': case 'b': - t = 16*11; - break; - case 'C': case 'c': - t = 16*12; - break; - case 'D': case 'd': - t = 16*13; - break; - case 'E': case 'e': - t = 16*14; - break; - case 'F': case 'f': - t = 16*15; - break; - - default: - t = 16*(LS->current-'0'); - } - next(LS); - if(!(('0'<= LS->current && LS->current<='9')||('a'<= LS->current && LS->current<='f')||('A'<= LS->current && LS->current<='F') )) - els_compiler_error(LS,"转义序列超出范围"); - switch (LS->current) - { - case 'A': case 'a': - t = t+10; - break; - case 'B': case 'b': - t = t+11; - break; - case 'C': case 'c': - t = t+12; - break; - case 'D': case 'd': - t = t+13; - break; - case 'E': case 'e': - t = t+14; - break; - case 'F': case 'f': - t = t+15; - break; - - default: - t = t+(LS->current-'0'); - } - save(L,(char)(t),l); - next(LS); - continue; - - } - if (LS->current == '\\') - { - next(LS); - switch (LS->current) - { - case 'a': - save(L, '\a', l); - next(LS); - break; - case 'b': - save(L, '\b', l); - next(LS); - break; - case 'f': - save(L, '\f', l); - next(LS); - break; - case 'n': - save(L, '\n', l); - next(LS); - break; - case 'r': - save(L, '\r', l); - next(LS); - break; - case 't': - save(L, '\t', l); - next(LS); - break; - case 'v': - save(L, '\v', l); - next(LS); - break; - case '"': - save(L, '\"', l); - next(LS); - break; - case '\'': - save(L, '\'', l); - next(LS); - break; - case '\n': - save(L, '\n', l); - inclinenumber(LS); - break; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - { - int c = 0; - int i = 0; - do - { - c = 10 * c + (LS->current - '0'); - next(LS); - } while (++i < 3 && isdigit(LS->current)); - if (c != (unsigned char)c) - { - save(L, '\0', l); - els_compiler_error(LS, "转义序列超出范围"); - } - save(L, c, l); - break; - } - default: - save_and_next(L, LS, l); - } - continue; - } - save_and_next(L, LS, l); - } - save_and_next(L, LS, l); - save(L, '\0', l); - seminfo->ts = els_string_newlstr(L, L->BufferTmp + 1, l - 3); - return 0; - }else { - save_and_next(L, LS, l); - if(LS->current!=del){ - save(L, '\0', l); - seminfo->ts = els_string_newlstr(L, L->BufferTmp + 1, l - 3); - return 0; - }else{ - while (1) - { - next(LS); - if(LS->current==del){ - next(LS); - if(LS->current==del){ - next(LS); - if(LS->current==del){ - next(LS); - return 1; - } - } - } - if(LS->current==EOF){ - els_compiler_error(LS,"多行注释出错"); - } - if(LS->current=='\n') ++(LS->linenumber); - } - - } - - } - -} - -int els_lexer_lex(LexObject *LS, SemInfo *seminfo) -{ - while (1) - { - switch (LS->current) - { - case '$': - next(LS); - return TOKEN_VAR; - case '#': - while (LS->current != '\n') - next(LS); - break; - case '^': - next(LS); - return '^'; - case '|': - next(LS); - if (LS->current == '|') - { - next(LS); - return TOKEN_OR; - } - else - return '|'; - case ' ': - case '\t': - case '\r': - next(LS); - continue; - case '\n': - inclinenumber(LS); - continue; - case '-': - next(LS); - return '-'; - case '[': - next(LS); - return '['; - case '=': - next(LS); - if (LS->current != '=') - return '='; - else - { - next(LS); - return TOKEN_EQ; - } - case '<': - next(LS); - if (LS->current != '=') - return '<'; - else - { - next(LS); - return TOKEN_LE; - } - case '>': - next(LS); - if (LS->current != '=') - return '>'; - else - { - next(LS); - return TOKEN_GE; - } - case ';': - next(LS); - return TOKEN_END; - case ':': - next(LS); - return ':'; - case '!': - next(LS); - if (LS->current != '=') - return TOKEN_NOT; - else - { - next(LS); - return TOKEN_NE; - } - case '"': - case '\'': - if (read_string(LS, LS->current, seminfo)) - continue; - return TOKEN_STRING; - case '&': - next(LS); - if (LS->current == '&') - { - next(LS); - return TOKEN_AND; - } - else - return TOKEN_CONCAT; - case '.': - next(LS); - if (LS->current == '.') - { - next(LS); - if (LS->current == '.') - { - next(LS); - return TOKEN_ARG; - } - els_compiler_error(LS, "..不是可识别的字符"); - } - if (!isdigit(LS->current)) - return '.'; - else - { - read_number(LS, 1, seminfo); - return TOKEN_NUMBER; - } - - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - read_number(LS, 0, seminfo); - return TOKEN_NUMBER; - - case EOZ: - return TOKEN_EOS; - - default: - if (!isalpha(LS->current) && LS->current != '_' && (unsigned int)(LS->current) < 0x80) - { - int c = LS->current; - next(LS); - return c; - } - TString *ts = els_string_new(LS->L, read_name(LS)); - if (ts->marked >= FIRST_TOKENID) - { -#ifdef ELS_CONF_TOKEN_CN - switch (ts->marked) - { - case TOKEN_THIS: - { - seminfo->ts = els_string_new(LS->L, "this"); - return TOKEN_NAME; - } - case TOKEN_VARARG: - { - seminfo->ts = els_string_new(LS->L, "arg"); - return TOKEN_NAME; - } - case TOKEN_FOR_MAX: - { - seminfo->ts = els_string_new(LS->L, "__MAX__"); - return TOKEN_NAME; - } - case TOKEN_FOR_STEP: - { - seminfo->ts = els_string_new(LS->L, "__STEP__"); - return TOKEN_NAME; - } - case TOKEN_FOR_THIS: - { - seminfo->ts = els_string_new(LS->L, "__THIS__"); - return TOKEN_NAME; - } - case TOKEN_CONST : - { - seminfo->ts = els_string_new(LS->L, "class"); - return TOKEN_NAME; - } - default: - break; - } -#endif - return ts->marked; - } - seminfo->ts = ts; - return TOKEN_NAME; - } - } -} diff --git a/losu_core/els_lex.h b/losu_core/els_lex.h deleted file mode 100755 index 4dc2e109ecdc473d5bf90d6c269bfc47b048900f..0000000000000000000000000000000000000000 --- a/losu_core/els_lex.h +++ /dev/null @@ -1,87 +0,0 @@ - - -#ifndef els_lex_h -#define els_lex_h - -#include "els_object.h" -#include "els_vmcore.h" - -#define FIRST_TOKENID 256 - -#define TOKEN_LEN 3 * 12 -enum RESERVED -{ - - TOKEN_AND = 256, - TOKEN_BREAK, - TOKEN_BLOCK, - TOKEN_ELSE, - TOKEN_ELSEIF, - TOKEN_END, - TOKEN_FOR, - TOKEN_FUNCTION, - TOKEN_IF, - TOKEN_VAR, - TOKEN_NULL, - TOKEN_NOT, - TOKEN_OR, - TOKEN_LOOP, - TOKEN_RETURN, - TOKEN_THEN, - TOKEN_TO, - TOKEN_WITH, - TOKEN_ARG, - TOKEN_VARARG, - /*18个*/ - - TOKEN_NAME, - TOKEN_CONCAT, - TOKEN_BLOCKTS, - TOKEN_EQ, - TOKEN_GE, - TOKEN_LE, - TOKEN_NE, - TOKEN_NUMBER, - TOKEN_STRING, - TOKEN_EOS, - TOKEN_THIS, - TOKEN_FOR_MAX, - TOKEN_FOR_STEP, - TOKEN_FOR_THIS, - TOKEN_CONST, -}; - -typedef union -{ - Number r; - TString *ts; -} SemInfo; - -typedef struct Token -{ - int token; - SemInfo seminfo; -} Token; - -typedef struct LexObject -{ - int current; - int deepth; - Token t; - Token lookahead; - struct ElsFuncObj *fs; - struct els_VmObj *L; - struct vm_iobuff *z; - int linenumber; - int lastline; - TString *source; -} LexObject; - -void els_lexer_init(els_VmObj *); -void els_lexer_setinput(els_VmObj *L, LexObject *LS, vm_iobuff *z, TString *source); -int els_lexer_lex(LexObject *LS, SemInfo *seminfo); -void els_lexer_checklimit(LexObject *ls, int val, int limit, const char *msg); -void els_lexer_token2str(int token, char *s); -void els_compiler_error(LexObject *ls, const char *buff); - -#endif diff --git a/losu_core/els_libload.c b/losu_core/els_libload.c deleted file mode 100755 index 6df6833dbcc9e04e2b1da7f28efa02be3174885c..0000000000000000000000000000000000000000 --- a/losu_core/els_libload.c +++ /dev/null @@ -1,145 +0,0 @@ - -#include -#include -#include -#include "els.h" -#include "els_vmhost.h" - - -#ifdef ELS_CONF_LIBAPI_ELF - #include "els_libload.h" -#endif - -#ifdef ELS_CONF_LIBAPI_DL // Linux 平台的动态库加载方式 libdl - #include - #include -#endif - -#ifdef ELS_CONF_LIBAPI_WIN32 // Windows 平台的动态库加载方式 win32API - #include -#endif - -static int els_inline_libload(els_VmObj* vm); -static int els_inline_classnew(els_VmObj* vm); - -ELS_API void els_lib_init(els_VmObj *l) -{ - - vm_register(l, "import", els_inline_libload); - vm_register(l, "new", els_inline_classnew); -#ifdef ELS_CONF_TOKEN_CN - vm_register(l, "引", els_inline_libload); -#endif -} - - -// new函数的C语言实现 -static int els_inline_classnew(els_VmObj* vm){ - LosuObj* oldtop = vm->top; - int args = arg_num(vm); - - //判断有没有 class 类型 - LosuObj *class = arg_get(vm,1); - LosuObj *func = obj_indexunit(vm,*class,obj_newstr(vm,"class")); - if(obj_type(vm,class)!=ELS_TYPE_UNIT || func==NULL || obj_type(vm,func)!= ELS_TYPE_FUNCTION){ - vm_error(vm,"new 函数的第一个参数必须为 包含class成员函数的 unit 对象",ELS_ERRORBACK_RUN); - } - stack_push(vm,*func); - stack_push(vm,*class); - for(int i=2;i<=args;i++) - stack_push(vm,*arg_get(vm,i)); - stack_call(vm,args,-1); - // els_call(vm,2,-1); - // els_Heap_call(vm,vm->top-3,-1); - // vm->top++; - // return 1; - return vm->top - oldtop; -} -// import 函数的 C 语言实现 -static int els_inline_libload(els_VmObj *l) -{ - char tmp[512]; -#ifdef ELS_CONF_LIBAPI_ELF - const char * s = arg_getstr(l,1); - for (int i = 0; i < sizeof(els_libload_alllib) / sizeof(els_libload_alllib[0]); i++) - if(!strcmp( els_libload_alllib[i].name,s)){ - els_libload_alllib[i].func(l); - } - -#endif - -#ifdef ELS_CONF_LIBAPI_WIN32 - #ifdef ELS_CONF_LIBAPI_DL - #error "ELS_CONF_LIBAPI_WIN32 与 ELS_CONF_LIBAPI_DL 参数只能选择一个" - #endif - - const char *libfile = arg_getstr(l, 1); - typedef void (*api)(els_VmObj *l); - sprintf(tmp, "./ElsLib_%s.lsd", libfile); // 先尝试加载工作目录的 - HMODULE dlibptr = LoadLibrary(tmp); - if (dlibptr == NULL) - { - sprintf(tmp, "./lib/ElsLib_%s.lsd", libfile); // 尝试加载本地环境的 - dlibptr = LoadLibrary(tmp); - } - sprintf(tmp, "ElsLib_%s_libinit", libfile); - api func = (api)GetProcAddress(dlibptr, tmp); - if (func == NULL) - { - sprintf(tmp, "LibError: Couldn't Load Library \t%s\n", libfile); - vm_error(l, tmp,ELS_ERRORBACK_LIB); - } - func(l); - return 1; -#endif -#ifdef ELS_CONF_LIBAPI_DL - #ifdef ELS_CONF_LIBAPI_WIN32 - #error "ELS_CONF_LIBAPI_WIN32 与 ELS_CONF_LIBAPI_DL 参数只能选择一个" - #endif - - const char *libfile = arg_getstr(l, 1); - typedef void (*api)(els_VmObj *l); - sprintf(tmp, "./ElsLib_%s.lsd", libfile); // 先加载工作目录的 - void *dlibptr = dlopen(tmp, RTLD_LAZY); - if (dlibptr == NULL) - { - char _tmp[256] = {0}; - readlink("/proc/self/exe", _tmp, 256); - int _t = 0; - for (int i = 0; i < strlen(_tmp); i++) - if (_tmp[i] == '/') - _t = i; - - _tmp[_t] = '\0'; - - sprintf(tmp, "%s/ElsLib_%s.lsd", _tmp, libfile); // 加载容器目录的 - dlibptr = dlopen(tmp, RTLD_LAZY); - if (dlibptr == NULL) - { - sprintf(tmp, "%s/lib/ElsLib_%s.lsd", _tmp, libfile); // 加载容器目录的 - dlibptr = dlopen(tmp, RTLD_LAZY); - } - } - if (dlibptr == NULL) - { - sprintf(tmp, "/els/lib/ElsLib_%s.lsd", libfile); // 加载本地环境的 - dlibptr = dlopen(tmp, RTLD_LAZY); - } - if (dlibptr == NULL) - { - sprintf(tmp, "LibError: Couldn't Load Library\t%s\n", libfile); - vm_error(l, tmp,ELS_ERRORBACK_LIB); - } - sprintf(tmp, "ElsLib_%s_libinit", libfile); - api func = (api)dlsym(dlibptr, tmp); - if (func == NULL) - { - sprintf(tmp, "LibError: Couldn't Load Library\t%s\n", libfile); - vm_error(l, tmp,ELS_ERRORBACK_LIB); - } - func(l); - return 1; -#endif - sprintf(tmp, "LibError: Couldn't Load Library \t%s\n", s); - return 1; -} \ No newline at end of file diff --git a/losu_core/els_libload.h b/losu_core/els_libload.h deleted file mode 100755 index f5481342a255bf6dd05d47c72580a79c3c3b2756..0000000000000000000000000000000000000000 --- a/losu_core/els_libload.h +++ /dev/null @@ -1,8 +0,0 @@ -#include "els.h" -struct -{ - char *name; - int (*func)(els_VmObj*vm,...); -} const els_libload_alllib[] = { - -}; \ No newline at end of file diff --git a/losu_core/els_mem.c b/losu_core/els_mem.c deleted file mode 100755 index 3bdc26ed0794c8e01e37c42f9efef17e746fb757..0000000000000000000000000000000000000000 --- a/losu_core/els_mem.c +++ /dev/null @@ -1,42 +0,0 @@ -#include -#include -#include "els.h" - - -#include "els_heap.h" -#include "els_mem.h" -#include "els_object.h" -#include "els_vmhost.h" - - -void *els_Mem_growaux(els_VmObj *vm, void *block, size_t issues_num, int inc, size_t size, const char *errormsg, size_t limit) -{ - size_t newn = issues_num + inc; - if (issues_num >= limit - inc) - vm_error(vm, errormsg,ELS_ERRORBACK_RUN); - if ((newn ^ issues_num) <= issues_num || (issues_num > 0 && newn < 4)) - return block; - else - return els_Mem_realloc(vm, block, els_Object_power2(newn) * size); -} - - -// 全局的内存管理函数,所有内存的申请与回收都从这里走 -void *els_Mem_realloc(els_VmObj *vm, void *block, lint32 size) -{ - if (size == 0) - { - if(block!=NULL) - ELS_HEAPMEM_FREE(block); // 回收指针空间 - return NULL; - } - - block = ELS_HEAPMEM_REALLOC(block, size); //重新分配内存块 - if (block == NULL){ - if (vm) - vm_error(vm, "内存管理器出错:无法获取足够的内存",ELS_ERRORBACK_MEM); - else - return NULL; - } - return block; -} \ No newline at end of file diff --git a/losu_core/els_mem.h b/losu_core/els_mem.h deleted file mode 100755 index f693cc6c09115d55de7af54ca0c624509efd9a43..0000000000000000000000000000000000000000 --- a/losu_core/els_mem.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef __els_mem_h__ -#define __els_mem_h__ - -#include - -#include "els.h" - -void *els_Mem_realloc (els_VmObj *, void *, lint32 ); -void *els_Mem_growaux (els_VmObj *, void *, size_t ,int , size_t , const char *,size_t ); - -#define els_Mem_free(L, b) els_Mem_realloc(L, (b), 0) -#define els_Mem_malloc(L, t) els_Mem_realloc(L, NULL, (t)) -#define els_Mem_new(L, t) ((t *)els_Mem_malloc(L, sizeof(t))) -#define els_Mem_newvector(L, n,t) ((t *)els_Mem_malloc(L, (n)*(lint32)sizeof(t))) - -#define els_Mem_growvector(L, v,issues_num,inc,t,e,l) ((v)=(t *)els_Mem_growaux(L, v,issues_num,inc,sizeof(t),e,l)) -#define els_Mem_reallocvector(L, v,n,t) ((v)=(t *)els_Mem_realloc(L, v,(n)*(lint32)sizeof(t))) - - - -#endif \ No newline at end of file diff --git a/losu_core/els_object.c b/losu_core/els_object.c deleted file mode 100755 index b9954e23aa4d089dc6db2293ef43dfb42892e3e9..0000000000000000000000000000000000000000 --- a/losu_core/els_object.c +++ /dev/null @@ -1,76 +0,0 @@ -#include -#include -#include -#include -#include - -#include "els.h" -#include "els_mem.h" -#include "els_object.h" -#include "els_vmhost.h" - - -const StackObj els_Object_nullobject = { - ELS_TYPE_NULL, {NULL} -}; - -lint32 els_Object_power2(lint32 n) -{ - lint32 p = 4; - while (p <= n) - p <<= 1; - return p; -} - -int els_Object_equalObj(const StackObj *t1, const StackObj *t2) -{ - if (ttype(t1) != ttype(t2)) - { - if( (ttype(t1)==ELS_TYPE_NUMBER&&(ttype(t2)==ELS_TYPE_STRING)) ) - return nvalue(t1) == atof(t2->value.ts->str); - else if( (ttype(t2)==ELS_TYPE_NUMBER&&(ttype(t1)==ELS_TYPE_STRING)) ) - return nvalue(t2)==atof(t1->value.ts->str); - else - return 0; - } - switch (ttype(t1)) - { - case ELS_TYPE_BYTE: - return tsvalue(t1)->len == tsvalue(t2)->len ? !memcmp(t1,t2,tsvalue(t1)->len) : 0; - case ELS_TYPE_NUMBER: - return nvalue(t1) == nvalue(t2); - case ELS_TYPE_STRING: - return tsvalue(t1)->u.s.hash == tsvalue(t2)->u.s.hash? !strcmp(svalue(t1),svalue(t2)) : 0 ; - case ELS_TYPE_UNIT: - return hvalue(t1) == hvalue(t2); - case ELS_TYPE_FUNCTION: - return clvalue(t1) == clvalue(t2); - default: - return 0; - } -} - -char *els_Object_openspace(els_VmObj *L, size_t n) -{ - if (n > L->BufferTmpSize) - { - els_Mem_reallocvector(L, L->BufferTmp, n, char); - L->nblocks += (n - L->BufferTmpSize) * sizeof(char); - L->BufferTmpSize = n; - } - return L->BufferTmp; -} - -int els_Object_str2d(const char *s, Number *result) -{ - char *endptr; - Number res = els_str2number(s, &endptr); - if (endptr == s) - return 0; - while (isspace((unsigned char)*endptr)) - endptr++; - if (*endptr != '\0') - return 0; - *result = res; - return 1; -} \ No newline at end of file diff --git a/losu_core/els_object.h b/losu_core/els_object.h deleted file mode 100755 index d073e810521762d8feff50e519d48ac4aed41911..0000000000000000000000000000000000000000 --- a/losu_core/els_object.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef __els_object_h__ -#define __els_object_h__ - -#include "els.h" - -#define ttype(o) ((o)->ttype) -#define nvalue(o) ((o)->value.n) -#define tsvalue(o) ((o)->value.ts) -#define clvalue(o) ((o)->value.cl) -#define hvalue(o) ((o)->value.a) -#define infovalue(o) ((o)->value.i) -#define svalue(o) (tsvalue(o)->str) - -#define iscfunction(o) (ttype(o) == ELS_TYPE_FUNCTION && clvalue(o)->isC) -#define ismarked(x) ((x)->mark != (x)) - -extern const StackObj els_Object_nullobject; - -char *els_Object_openspace(els_VmObj* , size_t); -int els_Object_equalObj(const StackObj *, const StackObj *); -int els_Object_str2d(const char *, Number *); -lint32 els_Object_power2(lint32 ); - -#endif \ No newline at end of file diff --git a/losu_core/els_parser.c b/losu_core/els_parser.c deleted file mode 100755 index f70d8ba36a95bbc866c0aa38e97616f5fa2443b9..0000000000000000000000000000000000000000 --- a/losu_core/els_parser.c +++ /dev/null @@ -1,1145 +0,0 @@ -#include -#include -#include -#include "els.h" - -#include "els_codegen.h" -#include "els_func.h" -#include "els_lex.h" -#include "els_mem.h" -#include "els_object.h" -#include "els_bytecode.h" -#include "els_parser.h" -#include "els_vmhost.h" -#include "els_string.h" - -typedef struct Constdesc -{ - int n; - int k; -} Constdesc; - -typedef struct Breaklabel -{ - struct Breaklabel *previous; - int breaklist; - int stacklevel; -} Breaklabel; -static const struct -{ - char left; - char right; -} sum_sign_exp[] = { - {5, 5}, {5, 5}, {6, 6}, {6, 6}, {9, 8}, {4, 3}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {1, 1}, {1, 1}}; - -#define UNARY_PRIORITY 7 -#define code_string(ls, s) (els_codegen_kstr(ls, string_constant(ls->fs, s))) -#define lookahead(ls) (ls->lookahead.token = els_lexer_lex(ls, &(ls->lookahead.seminfo))) -#define new_localvarstr(ls, name, n) (new_localvar(ls, els_string_newfixed(ls->L, name), n)) -#define expersion(ls, v) (subexpr(ls, v, -1)) -#define condition(ls, v) (expersion(ls, v), els_codegen_goiftrue(ls->fs, v, 0)) -#define optional(ls, c) (ls->t.token == c ? (next(ls), 1) : 0) - -static void els_parser_error_expected(LexObject *ls, int token); -static void check(LexObject *ls, int c); -static void next(LexObject *ls); -static void check_condition(LexObject *ls, int c, const char *msg); -static void check_match(LexObject *ls, int l, int r, int line); -static int string_constant(ElsFuncObj *fs, TString *s); -static int checkname(LexObject *ls); -static TString *checkstrname(LexObject *ls); -static int els_parser_registerlocalvar(LexObject *ls, TString *varname); -static void new_localvar(LexObject *ls, TString *name, int n); -static void adjustlocalvars(LexObject *ls, int nvars); -static void removelocalvars(LexObject *ls, int nvars); -static int check_iflocal(LexObject *ls, TString *n, expdesc *var); -static void singlevar(LexObject *ls, TString *n, expdesc *var); -static void adjust_mult_assign(LexObject *ls, int nvars, int nexps); -static void enterbreak(ElsFuncObj *fs, Breaklabel *bl); -static void leavebreak(ElsFuncObj *fs, Breaklabel *bl); -static void push_csfunciotn(LexObject *ls, ElsFuncObj *func); -static void open_func(LexObject *ls, ElsFuncObj *fs); -static void close_func(LexObject *ls); -els_func_code *els_parser_parse(els_VmObj *L, vm_iobuff *z); -static int explist1(LexObject *ls); -static void funcargs(LexObject *ls, int slf); -static void var_or_func(LexObject *ls, expdesc *v); -static int recfield(LexObject *ls); -static int listfields(LexObject *ls); -static void constructor(LexObject *ls); -static void simpleexp(LexObject *ls, expdesc *v); -static void exp1(LexObject *ls); -static int getunopr(int op); -static int getbinopr(int op); -static int subexpr(LexObject *ls, expdesc *v, int limit); -static void block(LexObject *ls); -static int check_block(int token); -static int assignment(LexObject *ls, expdesc *v, int nvars); -static void forbody(LexObject *ls, int nvar, ByteIR prepfor, ByteIR loopfor); -static void fornum(LexObject *ls, TString *varname); -static void forlist(LexObject *ls, TString *indexname); -static void test_then_block(LexObject *ls, expdesc *v); -static void parlist(LexObject *ls); -static void body(LexObject *ls, int needself, int line); - -static int els_parser_stat(LexObject *ls); -static void els_parser_stat_with(LexObject *ls, int line); -static void els_parser_stat_loop(LexObject *ls, int line); -static void els_parser_stat_for(LexObject *ls, int line); -static void els_parser_stat_if(LexObject *ls, int line); -static void els_parser_stat_func(LexObject *ls, int line); -static void els_parser_stat_name(LexObject *ls); -static void els_parser_stat_return(LexObject *ls); -static void els_parser_stat_break(LexObject *ls); - -void els_compiler_error(LexObject *ls, const char *buff) -{ - - -#ifdef ELS_CONF_CHAR_GBK - char tmp[256]; - char* t; - sprintf(tmp,"编译错误: \t%s\n影响到第 \t%d\t行\n", buff, ls->linenumber); - t = vm_win_togbk(tmp); - printf("%s",t); - free(t); -#else - printf("编译错误: \t%s\n影响到第 \t%d\t行\n", buff, ls->linenumber); -#endif - els_Heap_breakrun(ls->L, ELS_ERRORBACK_SYNTAX); -} -els_func_code *els_parser_parse(els_VmObj *L, vm_iobuff *z) -{ - struct LexObject lexstate; - struct ElsFuncObj els_parser_stat_funce; - lexstate.deepth = 0; - int islast = 0; - els_lexer_setinput(L, &lexstate, z, els_string_new(L, els_vmio_name(z))); - open_func(&lexstate, &els_parser_stat_funce); - next(&lexstate); - /* this UB will remain in comments,to warn me - * if you use this code and Compile with Compiler likes(gcc version 11.3.0 (Ubuntu 11.3.0-1ubuntu1~22.04) ) - * - * using script to test ' for i=1,100 :;',you will own an error - * - while (!els_parser_stat(&lexstate) && !check_block(((LexObject*)(&lexstate))->t.token)); - */ - while (!islast && !check_block(((LexObject *)(&lexstate))->t.token)) - islast = els_parser_stat(((LexObject *)(&lexstate))); - check_condition(&lexstate, (lexstate.t.token == TOKEN_EOS), "缺少结束符号"); - close_func(&lexstate); - return els_parser_stat_funce.f; -} -static void open_func(LexObject *ls, ElsFuncObj *fs) -{ - els_func_code *f = els_ScriptFunc_newcodeir(ls->L); - fs->prev = ls->fs; - fs->ls = ls; - fs->L = ls->L; - ls->fs = fs; - fs->stacklevel = 0; - fs->nactloc = 0; - fs->nupvalues = 0; - fs->bl = NULL; - fs->f = f; - f->source = ls->source; - fs->pc = 0; - fs->lasttarget = 0; - fs->lastline = 0; - fs->jlt = NO_JUMP; - f->code = NULL; - f->maxstacksize = 0; - f->numparams = 0; - f->is_vararg = 0; -} -static void close_func(LexObject *ls) -{ - els_VmObj *L = ls->L; - ElsFuncObj *fs = ls->fs; - els_func_code *f = fs->f; - els_codegen_code_arg0(fs, BYTECODE_END); - els_codegen_getlabel(fs); - els_Mem_reallocvector(L, f->code, fs->pc, Instruction); - els_Mem_reallocvector(L, f->kstr, f->nkstr, TString *); - els_Mem_reallocvector(L, f->knum, f->nknum, Number); - els_Mem_reallocvector(L, f->kcodeir, f->nkcodeir, els_func_code *); - removelocalvars(ls, fs->nactloc); - els_Mem_reallocvector(L, f->locvars, f->nlocvars, LocVar); - els_Mem_reallocvector(L, f->lineinfo, f->nlineinfo + 1, int); - f->lineinfo[f->nlineinfo++] = MAX_INT; - els_ScriptFunc_end(L, f, fs->pc); - ls->fs = fs->prev; -} -static void els_parser_error_expected(LexObject *ls, int token) -{ - char buff[128], t[9]; - els_lexer_token2str(token, t); - sprintf(buff, "在 %d 行,缺少 `%s' ", ls->linenumber, t); - els_compiler_error(ls, buff); -} -static void check(LexObject *ls, int c) -{ - if (ls->t.token != c) - els_parser_error_expected(ls, c); - next(ls); -} -static void next(LexObject *ls) -{ - ls->lastline = ls->linenumber; - if (ls->lookahead.token != TOKEN_EOS) - { - ls->t = ls->lookahead; - ls->lookahead.token = TOKEN_EOS; - } - else - ls->t.token = els_lexer_lex(ls, &(ls->t.seminfo)); -} -static void check_condition(LexObject *ls, int c, const char *msg) -{ - char err[128]; - sprintf(err, "%s,在第 %d 行", msg, ls->lastline); - if (!c) - els_codegen_error(ls, err); -} -static void check_match(LexObject *ls, int l, int r, int line) -{ - if (ls->t.token != l) - { - if (line == ls->linenumber) - els_parser_error_expected(ls, l); - else - { - char buff[128], tl[8], tr[8]; - els_lexer_token2str(l, tl); - els_lexer_token2str(r, tr); - sprintf(buff, "在第 %d 行,缺少 `%.20s' 以匹配 `%.20s' ", line, tl, tr); - els_codegen_error(ls, buff); - } - } - next(ls); -} -static int string_constant(ElsFuncObj *fs, TString *s) -{ - els_func_code *f = fs->f; - int c = s->u.s.constindex; - if (c >= f->nkstr || f->kstr[c] != s) - { - els_Mem_growvector(fs->L, f->kstr, f->nkstr, 1, TString *, "系统内置索引数组溢出", MAX_ARG_U); - c = f->nkstr++; - f->kstr[c] = s; - s->u.s.constindex = c; - } - return c; -} -static int checkname(LexObject *ls) -{ - return string_constant(ls->fs, checkstrname(ls)); -} -static TString *checkstrname(LexObject *ls) -{ - TString *ts; - check_condition(ls, (ls->t.token == TOKEN_NAME), "缺少变量名"); - ts = ls->t.seminfo.ts; - next(ls); - return ts; -} -static int els_parser_registerlocalvar(LexObject *ls, TString *varname) -{ - els_func_code *f = ls->fs->f; - els_Mem_growvector(ls->L, f->locvars, f->nlocvars, 1, LocVar, "", MAX_INT); - f->locvars[f->nlocvars].varname = varname; - return f->nlocvars++; -} -static void new_localvar(LexObject *ls, TString *name, int n) -{ - ElsFuncObj *fs = ls->fs; - fs->actloc[fs->nactloc + n] = els_parser_registerlocalvar(ls, name); -} -static void adjustlocalvars(LexObject *ls, int nvars) -{ - ElsFuncObj *fs = ls->fs; - while (nvars--) - fs->f->locvars[fs->actloc[fs->nactloc++]].startpc = fs->pc; -} -static void removelocalvars(LexObject *ls, int nvars) -{ - ElsFuncObj *fs = ls->fs; - while (nvars--) - fs->f->locvars[fs->actloc[--fs->nactloc]].endpc = fs->pc; -} -static int check_iflocal(LexObject *ls, TString *n, expdesc *var) -{ - ElsFuncObj *fs; - int level = 0; - for (fs = ls->fs; fs; fs = fs->prev) - { - int i; - for (i = fs->nactloc - 1; i >= 0; i--) - { - if (n == fs->f->locvars[fs->actloc[i]].varname) - { - var->k = VLOCAL; - var->u.index = i; - return level; - } - } - level++; - } - var->k = VGLOBAL; - return -1; -} - -static int indexupvalue(LexObject *ls, expdesc *v) -{ - ElsFuncObj *fs = ls->fs; - int i; - for (i = 0; i < fs->nupvalues; i++) - { - if (fs->upvalues[i].k == v->k && fs->upvalues[i].u.index == v->u.index) - return i; - } - fs->upvalues[fs->nupvalues] = *v; - return fs->nupvalues++; -} -static void pushupvalue(LexObject *ls, TString *n) -{ - ElsFuncObj *fs = ls->fs; - expdesc v; - int level = check_iflocal(ls, n, &v); - if (level == -1) /* global */ - v.u.index = string_constant(fs->prev, n); - else if (level != 1) - { - char tmp[128]; - sprintf(tmp, "闭包变量必须是全局变量 或 位于 上一级作用域中 ,变量 %s 不满足此条件,在第 %d 行", n->str, ls->linenumber - 1); - els_compiler_error(ls, tmp); - } - els_codegen_code_arg1(fs, BYTECODE_PUSHUPVALUE, indexupvalue(ls, &v)); -} -static void singlevar(LexObject *ls, TString *n, expdesc *var) -{ - - int level = check_iflocal(ls, n, var); - if (level >= 1) - { - pushupvalue(ls, n); - var->k = VEXP; - var->u.l.t = var->u.l.f = NO_JUMP; - } - else if (level == -1) - var->u.index = string_constant(ls->fs, n); -} - -static void adjust_mult_assign(LexObject *ls, int nvars, int nexps) -{ - ElsFuncObj *fs = ls->fs; - int diff = nexps - nvars; - if (nexps > 0 && els_codegen_lastisopen(fs)) - { - diff--; - if (diff <= 0) - { - els_codegen_setcallreturns(fs, -diff); - diff = 0; - } - else - els_codegen_setcallreturns(fs, 0); - } - - els_codegen_adjuststack(fs, diff); -} - -static void enterbreak(ElsFuncObj *fs, Breaklabel *bl) -{ - bl->stacklevel = fs->stacklevel; - bl->breaklist = NO_JUMP; - bl->previous = fs->bl; - fs->bl = bl; -} -static void leavebreak(ElsFuncObj *fs, Breaklabel *bl) -{ - fs->bl = bl->previous; - - els_codegen_patchlist(fs, bl->breaklist, els_codegen_getlabel(fs)); -} -static void push_csfunciotn(LexObject *ls, ElsFuncObj *func) -{ - ElsFuncObj *fs = ls->fs; - els_func_code *f = fs->f; - int i; - for (i = 0; i < func->nupvalues; i++) - els_codegen_tostack(ls, &func->upvalues[i], 1); - els_Mem_growvector(ls->L, f->kcodeir, f->nkcodeir, 1, els_func_code *, - "单位对象溢出", MAX_ARG_A); - f->kcodeir[f->nkcodeir++] = func->f; - els_codegen_code_arg2(fs, BYTECODE_PUSHFUNCTION, f->nkcodeir - 1, func->nupvalues); -} -static int explist1(LexObject *ls) -{ - - int n = 1; - expdesc v; - expersion(ls, &v); - while (ls->t.token == ',') - { - els_codegen_tostack(ls, &v, 1); - next(ls); - expersion(ls, &v); - n++; - } - els_codegen_tostack(ls, &v, 0); - return n; -} -static void funcargs(LexObject *ls, int slf) -{ - ElsFuncObj *fs = ls->fs; - int slevel = fs->stacklevel - slf - 1; - int line = ls->linenumber; - switch (ls->t.token) - { - case '(': - { - - next(ls); - if (ls->t.token != ')') - explist1(ls); - check_match(ls, ')', '(', line); - break; - } - case '{': - { - constructor(ls); - break; - } - case TOKEN_STRING: - { - code_string(ls, ls->t.seminfo.ts); - next(ls); - break; - } - default: - { - els_codegen_error(ls, "缺少函数参数"); - break; - } - } - fs->stacklevel = slevel; - els_codegen_code_arg2(fs, BYTECODE_CALL, slevel, MULT_RET); -} -static void var_or_func(LexObject *ls, expdesc *v) -{ - singlevar(ls, checkstrname(ls), v); - while (1) - { - switch (ls->t.token) - { - case '.': - { - next(ls); - lookahead(ls); - if (ls->lookahead.token == '(') - { - int name = checkname(ls); - els_codegen_tostack(ls, v, 1); - els_codegen_code_arg1(ls->fs, BYTECODE_PUSHSELF, name); - funcargs(ls, 1); - v->k = VEXP; - v->u.l.t = v->u.l.f = NO_JUMP; - break; - } - else - { - els_codegen_tostack(ls, v, 1); - els_codegen_kstr(ls, checkname(ls)); - v->k = VINDEXED; - break; - } - } - case '[': - { - next(ls); - els_codegen_tostack(ls, v, 1); - v->k = VINDEXED; - exp1(ls); - check(ls, ']'); - break; - } - case '(': - case TOKEN_STRING: - case '{': - { - els_codegen_tostack(ls, v, 1); - funcargs(ls, 0); - v->k = VEXP; - v->u.l.t = v->u.l.f = NO_JUMP; - break; - } - default: - return; - } - } -} -static int recfield(LexObject *ls) -{ - - ElsFuncObj *fs = ls->fs; - int n = 1; - switch (ls->t.token) - { - case TOKEN_NAME: - { - els_codegen_kstr(ls, checkname(ls)); - break; - } - case '[': - { - next(ls); - exp1(ls); - check(ls, ']'); - break; - } - default: - els_codegen_error(ls, "缺少 变量名 或 '['"); - } - check(ls, '='); - exp1(ls); - while (ls->t.token == ',') - { - next(ls); - if (ls->t.token == '}') - break; - switch (ls->t.token) - { - case TOKEN_NAME: - { - els_codegen_kstr(ls, checkname(ls)); - break; - } - case '[': - { - next(ls); - exp1(ls); - check(ls, ']'); - break; - } - default: - els_codegen_error(ls, "缺少 变量名 或 '['"); - } - check(ls, '='); - exp1(ls); - n++; - if (n % RFIELDS_PER_FLUSH == 0) - els_codegen_code_arg1(fs, BYTECODE_SETMAP, RFIELDS_PER_FLUSH); - } - els_codegen_code_arg1(fs, BYTECODE_SETMAP, n % RFIELDS_PER_FLUSH); - return n; -} -static int listfields(LexObject *ls) -{ - - ElsFuncObj *fs = ls->fs; - int n = 1; - exp1(ls); - while (ls->t.token == ',') - { - next(ls); - if (ls->t.token == '}') - break; - exp1(ls); - n++; - if (n % LFIELDS_PER_FLUSH == 0) - els_codegen_code_arg2(fs, BYTECODE_SETLIST, n / LFIELDS_PER_FLUSH - 1, LFIELDS_PER_FLUSH); - } - els_codegen_code_arg2(fs, BYTECODE_SETLIST, n / LFIELDS_PER_FLUSH, n % LFIELDS_PER_FLUSH); - return n; -} -static void constructor(LexObject *ls) -{ - - ElsFuncObj *fs = ls->fs; - int line = ls->linenumber; - int pc = els_codegen_code_arg1(fs, BYTECODE_CREATEUNIT, 0); - int issues_num; - Constdesc cd; - check(ls, '{'); - switch (ls->t.token) - { - case '}': - { - cd.n = 0; - cd.k = ls->t.token; - break; - } - case TOKEN_NAME: - { - - lookahead(ls); - if (ls->lookahead.token != '=') - goto case_default; - } - case '[': - { - cd.n = recfield(ls); - cd.k = 1; - break; - } - default: - { - case_default: - cd.n = listfields(ls); - cd.k = 0; - break; - } - } - issues_num = cd.n; - check_match(ls, '}', '{', line); - SETARG_U(fs->f->code[pc], issues_num); -} -static void simpleexp(LexObject *ls, expdesc *v) -{ - ElsFuncObj *fs = ls->fs; - switch (ls->t.token) - { - case TOKEN_NUMBER: - { - Number r = ls->t.seminfo.r; - next(ls); - els_codegen_number(fs, r); - break; - } - case TOKEN_STRING: - { - code_string(ls, ls->t.seminfo.ts); - next(ls); - break; - } - case TOKEN_NULL: - { - els_codegen_adjuststack(fs, -1); - next(ls); - break; - } - case '{': - { - constructor(ls); - break; - } - case TOKEN_FUNCTION: - { - ls->deepth++; - next(ls); - body(ls, 0, ls->linenumber); - ls->deepth--; - break; - } - case '(': - { - next(ls); - expersion(ls, v); - check(ls, ')'); - return; - } - case TOKEN_NAME: - { - var_or_func(ls, v); - return; - } - default: - { - char tmp[128]; - sprintf(tmp, "错误的表达式,在第 %d 行", ls->linenumber); - els_codegen_error(ls, tmp); - return; - } - } - v->k = VEXP; - v->u.l.t = v->u.l.f = NO_JUMP; -} -static void exp1(LexObject *ls) -{ - expdesc v; - expersion(ls, &v); - els_codegen_tostack(ls, &v, 1); -} -static int getunopr(int op) -{ - switch (op) - { - case TOKEN_NOT: - return OPR_NOT; - case '-': - return OPR_MINUS; - default: - return OPR_NOUNOPR; - } -} -static int getbinopr(int op) -{ - switch (op) - { - case '+': - return OPR_ADD; - case '-': - return OPR_SUB; - case '*': - return OPR_MULT; - case '/': - return OPR_DIV; - case '^': - return OPR_POW; - case TOKEN_CONCAT: - return OPR_CONCAT; - case TOKEN_NE: - return OPR_NE; - case TOKEN_EQ: - return OPR_EQ; - case '<': - return OPR_LT; - case TOKEN_LE: - return OPR_LE; - case '>': - return OPR_GT; - case TOKEN_GE: - return OPR_GE; - case TOKEN_AND: - return OPR_AND; - case TOKEN_OR: - return OPR_OR; - default: - return OPR_NOBINOPR; - } -} -static int subexpr(LexObject *ls, expdesc *v, int limit) -{ - int op; - int uop = getunopr(ls->t.token); - if (uop != OPR_NOUNOPR) - { - next(ls); - subexpr(ls, v, UNARY_PRIORITY); - els_codegen_prefix(ls, uop, v); - } - else - simpleexp(ls, v); - - op = getbinopr(ls->t.token); - while (op != OPR_NOBINOPR && sum_sign_exp[op].left > limit) - { - expdesc v2; - int nextop; - next(ls); - els_codegen_infix(ls, op, v); - - nextop = subexpr(ls, &v2, sum_sign_exp[op].right); - els_codegen_posfix(ls, op, v, &v2); - op = nextop; - } - return op; -} -static void block(LexObject *ls) -{ - - ElsFuncObj *fs = ls->fs; - int nactloc = fs->nactloc; - int islast = 0; - while (!islast && !check_block(ls->t.token)) - islast = els_parser_stat(ls); - els_codegen_adjuststack(fs, fs->nactloc - nactloc); - removelocalvars(ls, fs->nactloc - nactloc); -} -static int check_block(int token) -{ - switch (token) - { - case TOKEN_ELSE: - case TOKEN_ELSEIF: - case TOKEN_END: - case TOKEN_TO: - case TOKEN_EOS: - return 1; - default: - return 0; - } -} -static int assignment(LexObject *ls, expdesc *v, int nvars) -{ - int left = 0; - if (ls->t.token == ',') - { - expdesc nv; - next(ls); - var_or_func(ls, &nv); - check_condition(ls, (nv.k != VEXP), "语法错误"); - left = assignment(ls, &nv, nvars + 1); - } - else - { - int nexps; - if (ls->t.token == '=') - { - next(ls); - nexps = explist1(ls); - } - else - { - nexps = 0; - } - - adjust_mult_assign(ls, nvars, nexps); - } - if (v->k != VINDEXED) - els_codegen_storevar(ls, v); - else - { - els_codegen_code_arg2(ls->fs, BYTECODE_SETUNIT, left + nvars + 2, 1); - left += 2; - } - return left; -} -static void els_parser_stat_with(LexObject *ls, int line) -{ - - ElsFuncObj *fs = ls->fs; - int while_init = els_codegen_getlabel(fs); - expdesc v; - Breaklabel bl; - enterbreak(fs, &bl); - next(ls); - condition(ls, &v); - check(ls, ':'); - block(ls); - els_codegen_patchlist(fs, els_codegen_jump(fs), while_init); - els_codegen_patchlist(fs, v.u.l.f, els_codegen_getlabel(fs)); - check_match(ls, TOKEN_END, TOKEN_WITH, line); - leavebreak(fs, &bl); -} -static void els_parser_stat_loop(LexObject *ls, int line) -{ - - ElsFuncObj *fs = ls->fs; - int repeat_init = els_codegen_getlabel(fs); - expdesc v; - Breaklabel bl; - enterbreak(fs, &bl); - next(ls); - block(ls); - check_match(ls, TOKEN_TO, TOKEN_LOOP, line); - condition(ls, &v); - els_codegen_patchlist(fs, v.u.l.f, repeat_init); - leavebreak(fs, &bl); -} -static void forbody(LexObject *ls, int nvar, ByteIR prepfor, ByteIR loopfor) -{ - - ElsFuncObj *fs = ls->fs; - int prep = els_codegen_code_arg1(fs, prepfor, NO_JUMP); - int blockinit = els_codegen_getlabel(fs); - check(ls, ':'); - adjustlocalvars(ls, nvar); - block(ls); - els_codegen_patchlist(fs, els_codegen_code_arg1(fs, loopfor, NO_JUMP), blockinit); - els_codegen_patchlist(fs, prep, els_codegen_getlabel(fs)); - removelocalvars(ls, nvar); -} -static void fornum(LexObject *ls, TString *varname) -{ - check(ls, '='); - exp1(ls); - check(ls, ','); - exp1(ls); - if (optional(ls, ',')) - exp1(ls); - else - els_codegen_number(ls->fs, 1); - new_localvar(ls, varname, 0); - new_localvarstr(ls, "__MAX__", 1); - new_localvarstr(ls, "__STEP__", 2); - forbody(ls, 3, BYTECODE_FORPREP, BYTECODE_FORLOOP); -} -static void forlist(LexObject *ls, TString *indexname) -{ - TString *valname; - check(ls, ','); - valname = checkstrname(ls); - check_condition(ls, ls->t.token == '=' || (ls->t.token == TOKEN_NAME && ls->t.seminfo.ts == els_string_new(ls->L, "in")), "`缺少 = 或 in"); - next(ls); - exp1(ls); - new_localvarstr(ls, "__THIS__", 0); - new_localvar(ls, indexname, 1); - new_localvar(ls, valname, 2); - forbody(ls, 3, BYTECODE_LFORPREP, BYTECODE_LFORLOOP); -} -static int funcname(LexObject *ls, expdesc *v) -{ - int i = 0; - singlevar(ls, checkstrname(ls), v); - while (ls->t.token == '.') - { - next(ls); - els_codegen_tostack(ls, v, 1); - els_codegen_kstr(ls, checkname(ls)); - v->k = VINDEXED; - i = 1; - } - return i; -} - -static void els_parser_stat_for(LexObject *ls, int line) -{ - - ElsFuncObj *fs = ls->fs; - TString *varname; - Breaklabel bl; - enterbreak(fs, &bl); - next(ls); - varname = checkstrname(ls); - switch (ls->t.token) - { - case '=': - fornum(ls, varname); - break; - case ',': - forlist(ls, varname); - break; - default: - els_codegen_error(ls, "缺少 '=' 或 ','"); - } - check_match(ls, TOKEN_END, TOKEN_FOR, line); - leavebreak(fs, &bl); -} -static void test_then_block(LexObject *ls, expdesc *v) -{ - - next(ls); - condition(ls, v); - check(ls, ':'); - block(ls); -} -static void els_parser_stat_if(LexObject *ls, int line) -{ - - ElsFuncObj *fs = ls->fs; - expdesc v; - int escapelist = NO_JUMP; - test_then_block(ls, &v); - while (ls->t.token == TOKEN_ELSEIF) - { - els_codegen_concat(fs, &escapelist, els_codegen_jump(fs)); - els_codegen_patchlist(fs, v.u.l.f, els_codegen_getlabel(fs)); - test_then_block(ls, &v); - } - if (ls->t.token == TOKEN_ELSE) - { - els_codegen_concat(fs, &escapelist, els_codegen_jump(fs)); - els_codegen_patchlist(fs, v.u.l.f, els_codegen_getlabel(fs)); - next(ls); - block(ls); - } - else - els_codegen_concat(fs, &escapelist, v.u.l.f); - els_codegen_patchlist(fs, escapelist, els_codegen_getlabel(fs)); - check_match(ls, TOKEN_END, TOKEN_IF, line); -} -static void els_parser_stat_var(LexObject *ls) -{ - if (ls->deepth == 0) - { - next(ls); - els_parser_stat_name(ls); - return; - } - int nvars = 0; - int nexps; - do - { - next(ls); - new_localvar(ls, checkstrname(ls), nvars++); - } while (ls->t.token == ','); - if (optional(ls, '=')) - nexps = explist1(ls); - else - nexps = 0; - adjust_mult_assign(ls, nvars, nexps); - adjustlocalvars(ls, nvars); -} -static void els_parser_stat_func(LexObject *ls, int line) -{ - expdesc v; - next(ls); - int i = funcname(ls, &v); - body(ls, i, line); - els_codegen_storevar(ls, &v); -} - -static void els_parser_stat_name(LexObject *ls) -{ - - ElsFuncObj *fs = ls->fs; - expdesc v; - var_or_func(ls, &v); - if (v.k == VEXP) - { - check_condition(ls, els_codegen_lastisopen(fs), "语法错误"); - els_codegen_setcallreturns(fs, 0); - } - else - { - int left = assignment(ls, &v, 1); - els_codegen_adjuststack(fs, left); - } -} -static void els_parser_stat_return(LexObject *ls) -{ - - ElsFuncObj *fs = ls->fs; - next(ls); - if (!check_block(ls->t.token)) - explist1(ls); - els_codegen_code_arg1(fs, BYTECODE_RETURN, ls->fs->nactloc); - fs->stacklevel = fs->nactloc; -} -static void els_parser_stat_break(LexObject *ls) -{ - - ElsFuncObj *fs = ls->fs; - int currentlevel = fs->stacklevel; - Breaklabel *bl = fs->bl; - next(ls); - if (bl) - { - els_codegen_adjuststack(fs, currentlevel - bl->stacklevel); - els_codegen_concat(fs, &bl->breaklist, els_codegen_jump(fs)); - els_codegen_adjuststack(fs, bl->stacklevel - currentlevel); - } -} -static int els_parser_stat(LexObject *ls) -{ - char tmp[128]; - int line = ls->linenumber; - switch (ls->t.token) - { - case TOKEN_IF: - { - els_parser_stat_if(ls, line); - return 0; - } - case TOKEN_WITH: - { - els_parser_stat_with(ls, line); - return 0; - } - case TOKEN_BLOCK: - { - ls->deepth++; - next(ls); - block(ls); - check_match(ls, TOKEN_END, TOKEN_BLOCK, line); - ls->deepth--; - return 0; - } - case TOKEN_FOR: - { - els_parser_stat_for(ls, line); - return 0; - } - case TOKEN_LOOP: - { - els_parser_stat_loop(ls, line); - return 0; - } - case TOKEN_FUNCTION: - { - ls->deepth++; - els_parser_stat_func(ls, line); - ls->deepth--; - return 0; - } - case TOKEN_VAR: - { - els_parser_stat_var(ls); - return 0; - } - case TOKEN_NAME: - case '%': - { - els_parser_stat_name(ls); - return 0; - } - case TOKEN_RETURN: - { - els_parser_stat_return(ls); - return 1; - } - case TOKEN_BREAK: - { - els_parser_stat_break(ls); - return 1; - } - default: - { - sprintf(tmp, "错误的表达式,在第 %d 行", ls->linenumber); - els_codegen_error(ls, tmp); - return 0; - } - } -} - -static void parlist(LexObject *ls) -{ - short is_vararg = 0; - char tmp[128]; - int nparams = 0; - if (ls->t.token != ')') - { - do - { - switch (ls->t.token) - { - case TOKEN_ARG: - next(ls); - is_vararg = 1; - break; - case TOKEN_NAME: - new_localvar(ls, checkstrname(ls), nparams++); - break; - default: - { - sprintf(tmp, "缺少变量名,在第 %d 行", ls->linenumber); - els_codegen_error(ls, tmp); - } - } - } while (optional(ls, ',')); - } - ElsFuncObj *fs = ls->fs; - adjustlocalvars(ls, nparams); - fs->f->numparams = fs->nactloc; - fs->f->is_vararg = is_vararg; - if (is_vararg) - { - new_localvarstr(ls, "arg", 0); - adjustlocalvars(ls, 1); - } - els_codegen_deltastack(fs, fs->nactloc); -} - -static void body(LexObject *ls, int needself, int line) -{ - ElsFuncObj new_fs; - open_func(ls, &new_fs); - new_fs.f->lineDefined = line; - check(ls, '('); - if (needself) - { - new_localvarstr(ls, "this", 0); - adjustlocalvars(ls, 1); - } - parlist(ls); - check(ls, ')'); - check(ls, ':'); - while (!check_block(ls->t.token)) - if (els_parser_stat(ls)) - break; - check_match(ls, TOKEN_END, TOKEN_FUNCTION, line); - close_func(ls); - push_csfunciotn(ls, &new_fs); -} diff --git a/losu_core/els_parser.h b/losu_core/els_parser.h deleted file mode 100755 index 0e49101d03a8818f18e4921212bc728763610d3d..0000000000000000000000000000000000000000 --- a/losu_core/els_parser.h +++ /dev/null @@ -1,50 +0,0 @@ - -#ifndef els_parser_h -#define els_parser_h - -#include "els_object.h" -#include "els_vmcore.h" - -typedef enum -{ - VGLOBAL, - VLOCAL, - VINDEXED, - VEXP -} expkind; - -typedef struct expdesc -{ - expkind k; - union - { - int index; - struct - { - int t; - int f; - } l; - } u; -} expdesc; - -typedef struct ElsFuncObj -{ - els_func_code *f; - struct ElsFuncObj *prev; - struct LexObject *ls; - struct els_VmObj *L; - int pc; - int lasttarget; - int jlt; - short stacklevel; - short nactloc; - short nupvalues; - int lastline; - struct Breaklabel *bl; - expdesc upvalues[32]; - int actloc[128]; -} ElsFuncObj; - -els_func_code *els_parser_parse(els_VmObj *L, vm_iobuff *z); - -#endif diff --git a/losu_core/els_string.c b/losu_core/els_string.c deleted file mode 100755 index a87b2b989e3aca99e5aa7003977ae0f726e43972..0000000000000000000000000000000000000000 --- a/losu_core/els_string.c +++ /dev/null @@ -1,108 +0,0 @@ -#include - -#include "els.h" - -#include "els_mem.h" -#include "els_object.h" -#include "els_vmhost.h" -#include "els_string.h" - - -void els_string_init(els_VmObj *vm) -{ - vm->strpool.hash = els_Mem_newvector(vm, 1, TString *); - vm->nblocks += sizeof(TString*); - vm->strpool.size = 1; - vm->strpool.nuse = 0; - vm->strpool.hash[0] = NULL; -} - -void els_string_freeall(els_VmObj *vm) -{ - vm->nblocks -= vm->strpool.size * sizeof(TString *); - els_Mem_free(vm, vm->strpool.hash); -} - -static unsigned long hash_s(const char *s, size_t l) -{ - // JS hash算法 - unsigned long h = l; - size_t step = (l >> 5) | 1; - for (; l >= step; l -= step) - h = h ^ ((h << 5) + (h >> 2) + (unsigned char)*(s++)); - return h; -} - -void els_string_resize(els_VmObj *vm, stringunit *treeb, int newsize) -{ - TString **newhash = els_Mem_newvector(vm, newsize, TString *); - int i; - for (i = 0; i < newsize; i++) - newhash[i] = NULL; - - for (i = 0; i < treeb->size; i++) - { - TString *p = treeb->hash[i]; - while (p) - { - TString *next = p->nexthash; - unsigned long h = p->u.s.hash; - int h1 = h & (newsize - 1); - p->nexthash = newhash[h1]; - newhash[h1] = p; - p = next; - } - } - els_Mem_free(vm, treeb->hash); - vm->nblocks += (newsize - treeb->size) * sizeof(TString *); - treeb->size = newsize; - treeb->hash = newhash; -} - -static void newentry(els_VmObj *L, stringunit *tb, TString *ts, int h) -{ - ts->nexthash = tb->hash[h]; - tb->hash[h] = ts; - tb->nuse++; - if (tb->nuse > (lint32)tb->size && tb->size < MAX_INT / 2) - els_string_resize(L, tb, tb->size * 2); -} - -#include -TString *els_string_newlstr(els_VmObj *L, const char *str, size_t l) -{ - unsigned long h = hash_s(str, l); - int h1 = h & (L->strpool.size - 1); - TString *ts; - for (ts = L->strpool.hash[h1]; ts; ts = ts->nexthash) - { - if(ts->u.s.hash==h) - if (ts->len == l && (memcmp(str, ts->str, l) == 0)) - return ts; - } - ts = (TString *)els_Mem_malloc(L, sizestring(l)); - ts->marked = 0; - ts->nexthash = NULL; - ts->len = l; - ts->u.s.hash = h; - ts->u.s.constindex = 0; - memcpy(ts->str, str, l); - ts->str[l] = 0; - L->nblocks += sizestring(l); - newentry(L, &L->strpool, ts, h1); - return ts; -} - -TString *els_string_new(els_VmObj *L, const char *str) -{ - return els_string_newlstr(L, str, strlen(str)); -} - -TString *els_string_newfixed(els_VmObj *L, const char *str) -{ - TString *ts = els_string_new(L, str); - if (ts->marked == 0) - ts->marked = FIXMARK; - return ts; -} - diff --git a/losu_core/els_string.h b/losu_core/els_string.h deleted file mode 100755 index c76b9e5c39640094c978e3bdd1bf398ff4538898..0000000000000000000000000000000000000000 --- a/losu_core/els_string.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef __els_string_h__ -#define __els_string_h__ - - -#include "els_object.h" -#include "els_vmhost.h" -#include -#define FIXMARK 2 -#define RESERVEDMARK 3 -#define sizestring(l) ((long)sizeof(TString) + ((long)(l+1)-TSPACK)*(long)sizeof(char)) - - -void els_string_init (els_VmObj *); -void els_string_resize (els_VmObj *, stringunit *, int ); -void els_string_freeall (els_VmObj *L); - - -TString *els_string_newlstr (els_VmObj *, const char *, size_t ); -TString *els_string_newfixed (els_VmObj *, const char *); -TString *els_string_new(els_VmObj *, const char *); - - -#endif \ No newline at end of file diff --git a/losu_core/els_unit.c b/losu_core/els_unit.c deleted file mode 100755 index 572d60da29e38803b6c94100db61c3bb499f7ab0..0000000000000000000000000000000000000000 --- a/losu_core/els_unit.c +++ /dev/null @@ -1,269 +0,0 @@ -#include "els.h" - -#include -#include "els_mem.h" -#include "els_object.h" -#include "els_vmhost.h" -#include "els_string.h" -#include "els_unit.h" - -#define gcsize(L, n) (sizeof(Hash) + (n) * sizeof(Node)) - -Node *els_Unit_mainposition(const Hash *t, const StackObj *key) -{ - unsigned long h; - switch (key->ttype) - { - case ELS_TYPE_NUMBER: - h = (unsigned long)(long)nvalue(key); - break; - case ELS_TYPE_STRING: - h = tsvalue(key)->u.s.hash; - break; - case ELS_TYPE_UNIT: - h = IntPoint(hvalue(key)); - break; - case ELS_TYPE_FUNCTION: - h = IntPoint(clvalue(key)); - break; - default: - return NULL; - } - return &t->node[h & (t->size - 1)]; -} - -const StackObj *els_Unit_getany(els_VmObj *L, const Hash *t, const StackObj *key) -{ - Node *n = els_Unit_mainposition(t, key); - if(n){ - do - { - if (els_Object_equalObj(key, &n->key)) - return &n->val; - n = n->next; - } while (n); - } - return &els_Object_nullobject; -} - -const StackObj *els_Unit_getnum(const Hash *t, Number key) -{ - Node *n = &t->node[(unsigned long)(long)key & (t->size - 1)]; - do - { - if (ttype(&n->key) == ELS_TYPE_NUMBER && nvalue(&n->key) == key) - return &n->val; - n = n->next; - } while (n); - return &els_Object_nullobject; -} - -const StackObj *els_Unit_getstr(const Hash *t, TString *key) -{ - Node *n = &t->node[key->u.s.hash & (t->size - 1)]; - do - { - if (ttype(&n->key) == ELS_TYPE_STRING && tsvalue(&n->key)->u.s.hash==key->u.s.hash) - if (!strcmp(n->key.value.ts->str, key->str)) - return &n->val; - n = n->next; - } while (n); - return &els_Object_nullobject; -} - -const StackObj *els_Unit_get(els_VmObj *L, const Hash *t, const StackObj *key) -{ - switch (ttype(key)) - { - case ELS_TYPE_NUMBER: - return els_Unit_getnum(t, nvalue(key)); - case ELS_TYPE_STRING: - return els_Unit_getstr(t, tsvalue(key)); - default: - return els_Unit_getany(L, t, key); - } -} - -Node *els_Unit_next(els_VmObj *L, const Hash *t, const StackObj *key) -{ - int i; - if (ttype(key) == ELS_TYPE_NULL) - i = 0; - else - { - const StackObj *v = els_Unit_get(L, t, key); - if (v == &els_Object_nullobject) - vm_error(L, "错误的单元键值",ELS_ERRORBACK_RUN); - i = (int)(((const char *)v - (const char *)(&t->node[0].val)) / sizeof(Node)) + 1; - } - for (; i < t->size; i++) - { - Node *n = node(t, i); - if (ttype(val(n)) != ELS_TYPE_NULL) - return n; - } - return NULL; -} - -void els_Unit_remove(Hash *t, StackObj *key) -{ - if (ttype(key) == ELS_TYPE_NUMBER || (ttype(key) == ELS_TYPE_STRING && tsvalue(key)->len <= 30)) - return; - else - { - Node *mp = els_Unit_mainposition(t, key); - int n = mp - &t->node[0]; - while (els_Unit_getnum(t, n) != &els_Object_nullobject) - { - if (n >= MAX_INT - t->size) - return; - n += t->size; - } - ttype(key) = ELS_TYPE_NUMBER; - nvalue(key) = n; - } -} - -static void setnodevector(els_VmObj *L, Hash *t, lint32 size) -{ - int i; - if (size > MAX_INT) - vm_error(L, "对象储存单元溢出",ELS_ERRORBACK_RUN); - t->node = els_Mem_newvector(L, size, Node); - for (i = 0; i < (int)size; i++) - { - ttype(&t->node[i].key) = ttype(&t->node[i].val) = ELS_TYPE_NULL; - t->node[i].next = NULL; - } - L->nblocks += gcsize(L, size) - gcsize(L, t->size); - t->size = size; - t->firstfree = &t->node[size - 1]; -} - -Hash *els_Unit_new(els_VmObj *L, int size) -{ - Hash *t = els_Mem_new(L, Hash); - t->htag = ELS_TYPE_UNIT; - t->next = L->rootunit; - L->rootunit = t; - t->mark = t; - t->size = 0; - L->nblocks += gcsize(L, 0); - t->node = NULL; - setnodevector(L, t, els_Object_power2(size)); - return t; -} - -void els_Unit_free(els_VmObj *L, Hash *t) -{ - L->nblocks -= gcsize(L, t->size); - els_Mem_free(L, t->node); - els_Mem_free(L, t); -} - -static int numuse(const Hash *t) -{ - Node *v = t->node; - int size = t->size; - int realuse = 0; - int i; - for (i = 0; i < size; i++) - { - if (ttype(&v[i].val) != ELS_TYPE_NULL) - realuse++; - } - return realuse; -} - -static void rehash(els_VmObj *L, Hash *t) -{ - int oldsize = t->size; - Node *nold = t->node; - int issues_num = numuse(t); - int i; - if (issues_num >= oldsize - oldsize / 4) - setnodevector(L, t, (lint32)oldsize * 2); - else if (issues_num <= oldsize / 4 && oldsize > 4) - setnodevector(L, t, oldsize / 2); - else - setnodevector(L, t, oldsize); - for (i = 0; i < oldsize; i++) - { - Node *old = nold + i; - if (ttype(&old->val) != ELS_TYPE_NULL) - *els_Unit_set(L, t, &old->key) = old->val; - } - els_Mem_free(L, nold); -} - -StackObj *els_Unit_set(els_VmObj *L, Hash *t, const StackObj *key) -{ - Node *mp = els_Unit_mainposition(t, key); - Node *n = mp; - if (!mp){ - vm_error(L,"创建一个单元元素时,其索引不能为空值",ELS_ERRORBACK_RUN); - } - do - { - if (els_Object_equalObj(key, &n->key)) - return &n->val; - else - n = n->next; - } while (n); - if (ttype(&mp->key) != ELS_TYPE_NULL) - { - Node *othern; - n = t->firstfree; - if (mp > n && (othern = els_Unit_mainposition(t, &mp->key)) != mp) - { - - while (othern->next != mp) - othern = othern->next; - othern->next = n; - *n = *mp; - mp->next = NULL; - } - else - { - - n->next = mp->next; - mp->next = n; - mp = n; - } - } - mp->key = *key; - while(1) - { - if (ttype(&t->firstfree->key) == ELS_TYPE_NULL) - return &mp->val; - else if (t->firstfree == t->node) - break; - else - (t->firstfree)--; - } - rehash(L, t); - return els_Unit_set(L, t, key); -} - -StackObj *els_Unit_setint(els_VmObj *L, Hash *t, int key) -{ - StackObj index; - ttype(&index) = ELS_TYPE_NUMBER; - nvalue(&index) = key; - return els_Unit_set(L, t, &index); -} - -void els_Unit_setstrnum(els_VmObj *L, Hash *t, TString *key, Number val) -{ - StackObj *value, index; - ttype(&index) = ELS_TYPE_STRING; - tsvalue(&index) = key; - value = els_Unit_set(L, t, &index); - ttype(value) = ELS_TYPE_NUMBER; - nvalue(value) = val; -} - -const StackObj *els_Unit_getglobal(els_VmObj *L, const char *name) -{ - return els_Unit_getstr(L->globalenv, els_string_new(L, name)); -} diff --git a/losu_core/els_unit.h b/losu_core/els_unit.h deleted file mode 100755 index dc99f3e5a63b3db2d3f7b047f64b41c8dab25043..0000000000000000000000000000000000000000 --- a/losu_core/els_unit.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef __els_unit_h__ -#define __els_unit_h__ - -#include "els_object.h" - - -// 节点,下标,值 -#define node(t,i) (&(t)->node[i]) -#define key(n) (&(n)->key) -#define val(n) (&(n)->val) - - -Hash *els_Unit_new (els_VmObj *, int ); -void els_Unit_free (els_VmObj *, Hash *); -void els_Unit_remove (Hash *, StackObj *); - -const StackObj *els_Unit_get (els_VmObj *, const Hash *, const StackObj *); -const StackObj *els_Unit_getnum (const Hash *, Number ); -const StackObj *els_Unit_getstr (const Hash *, TString *); -StackObj *els_Unit_set (els_VmObj *, Hash *, const StackObj *); -StackObj *els_Unit_setint (els_VmObj *, Hash *, int ); -void els_Unit_setstrnum (els_VmObj *, Hash *, TString *, Number ); - -Node * els_Unit_next (els_VmObj *, const Hash *, const StackObj *); - -unsigned long els_Unit_hash (els_VmObj *, const StackObj *); -const StackObj *els_Unit_getglobal (els_VmObj *, const char *); - -#endif \ No newline at end of file diff --git a/losu_core/els_vmcore.c b/losu_core/els_vmcore.c deleted file mode 100755 index 670869c4c43117a88cd2bf5454ecf92aab767adc..0000000000000000000000000000000000000000 --- a/losu_core/els_vmcore.c +++ /dev/null @@ -1,854 +0,0 @@ -#include -#include -#include - -#include "els.h" -#include "els_heap.h" -#include "els_func.h" -#include "els_gc.h" -#include "els_object.h" -#include "els_bytecode.h" -#include "els_vmhost.h" -#include "els_string.h" -#include "els_unit.h" -#include "els_vmcore.h" -#include "els_mem.h" - - - -#define EXTRA_STACK 8 - -int els_Vmcore_tonumber(StackObj *obj) -{ - if (ttype(obj) != ELS_TYPE_STRING) - return 1; - else - { - if (!els_Object_str2d(svalue(obj), &nvalue(obj))) - return 2; - ttype(obj) = ELS_TYPE_NUMBER; - return 0; - } -} - -int els_Vmcore_tostring(els_VmObj *L, StackObj *obj) -{ - if (ttype(obj) != ELS_TYPE_NUMBER) - return 1; - else - { - char s[32]; - els_number2str(s, nvalue(obj)); - tsvalue(obj) = els_string_new(L, s); - ttype(obj) = ELS_TYPE_STRING; - return 0; - } -} - -ElsCfunc *els_Vmcore_csfunction(els_VmObj *L, int issues_num) -{ - ElsCfunc *c = els_ScriptFunc_new_csfunciotn(L, issues_num); - L->top -= issues_num; - while (issues_num--) - c->upvalue[issues_num] = *(L->top + issues_num); - clvalue(L->top) = c; - ttype(L->top) = ELS_TYPE_FUNCTION; - incr_top(L); - return c; -} - -void els_Vmcore_C_csfunciotn(els_VmObj *L, els_C_API_function c, int issues_num) -{ - ElsCfunc *cl = els_Vmcore_csfunction(L, issues_num); - cl->f.c = c; - cl->isC = 1; -} - -void els_Vmcore_L_csfunciotn(els_VmObj *L, els_func_code *l, int issues_num) -{ - ElsCfunc *cl = els_Vmcore_csfunction(L, issues_num); - cl->f.l = l; - cl->isC = 0; -} - -const StackObj *els_Vmcore_getunit(els_VmObj *L, StackObj* t) -{ - if (ttype(t) == ELS_TYPE_NULL) - { - return &els_Object_nullobject; - } - if (ttype(t) == ELS_TYPE_UNIT) - { - const StackObj *h = els_Unit_get(L, hvalue(t), L->top - 1); - if (ttype(h) == ELS_TYPE_NULL) - return &els_Object_nullobject; - return h; - } - return &els_Object_nullobject; -} - -void els_Vmcore_setunit(els_VmObj *L, StackObj* t, StackObj* key) -{ - int tg; - if (ttype(t) == ELS_TYPE_UNIT && (tg = hvalue(t)->htag) == ELS_TYPE_UNIT ) - *els_Unit_set(L, hvalue(t), key) = *(L->top - 1); - else - vm_error(L,"试图向一个非索引对象赋值",ELS_ERRORBACK_RUN); -} - -const StackObj *els_Vmcore_getglobal(els_VmObj *L, TString *s) -{ - return els_Unit_getstr(L->globalenv,s); -} - -void els_Vmcore_setglobal(els_VmObj *L, TString *s) -{ - const StackObj *oldvalue = els_Unit_getstr(L->globalenv, s); - if (oldvalue != &els_Object_nullobject) - { - *(StackObj *)oldvalue = *(L->top - 1); - } - else - { - StackObj key; - ttype(&key) = ELS_TYPE_STRING; - tsvalue(&key) = s; - *els_Unit_set(L, L->globalenv, &key) = *(L->top - 1); - } - -} - -static int els_Vmcore_strcomp(const TString *ls, const TString *rs) -{ - const char *l = ls->str; - size_t ll = ls->len; - const char *r = rs->str; - size_t lr = rs->len; - while (1) - { - int temp = strcoll(l, r); - if (temp != 0) - return temp; - else - { - size_t len = strlen(l); - if (len == ll) - return (len == lr) ? 0 : -1; - else if (len == lr) - return 1; - - len++; - l += len; - ll -= len; - r += len; - lr -= len; - } - } -} - -int els_Vmcore_lessthan(els_VmObj *L, const StackObj *l, const StackObj *r, StackObj* top) -{ - if(ttype(l)!=ttype(r)){ - if(ttype(l)==ELS_TYPE_NUMBER&&ttype(r)==ELS_TYPE_STRING) - return nvalue(l)top = top; - tsvalue(top - 1) = els_string_newlstr(L, "::&", 3); - ttype(top - 1) = ELS_TYPE_STRING; - *(top - 2) = *(top - 4); - *(top) = *els_Vmcore_getunit(L, top - 2); - top += 3; - L->top = top; - *(top - 2) = *(top - 7); - *(top - 1) = *(top - 6); - if(ttype(top-3)!=ELS_TYPE_FUNCTION) - vm_error(L,"& 运算符并未被定义如何重载",ELS_ERRORBACK_RUN); - els_Heap_call(L, top - 3, 1); - *(top - 7) = *(top); - top -= 6; - L->top = top; - return; - } - else if (tsvalue(top - 1)->len > 0) - { - lint32 tl = (lint32)tsvalue(top - 1)->len + (lint32)tsvalue(top - 2)->len; - char *buffer; - if (tl > MAX_SIZET) - vm_error(L, "字符串大小溢出",ELS_ERRORBACK_RUN); - buffer = els_Object_openspace(L, tl); - tl = 0; - size_t l = tsvalue(top - 2)->len; - memcpy(buffer + tl, tsvalue(top - 2)->str, l); - tl += l; - l = tsvalue(top - 1)->len; - memcpy(buffer + tl, tsvalue(top - 1)->str, l); - tl += l; - tsvalue(top - 2) = els_string_newlstr(L, buffer, tl); - } - top--; -} - -static void els_Vmcore_pack(els_VmObj *L, StackObj* firstelem) -{ - int i; - Hash *hunit = els_Unit_new(L, 0); - for (i = 0; firstelem + i < L->top; i++) - *els_Unit_setint(L, hunit, i + 1) = *(firstelem + i); - - els_Unit_setstrnum(L, hunit, els_string_new(L, "n"), i); - #ifdef ELS_CONF_TOKEN_CN - els_Unit_setstrnum(L, hunit, els_string_new(L, "个数"), i); - #endif - L->top = firstelem; - ttype(L->top) = ELS_TYPE_UNIT; - hvalue(L->top) = hunit; - incr_top(L); -} - -static void adjust_varargs(els_VmObj *L, StackObj* base, int nfixargs) -{ - int nvararg = (L->top - base) - nfixargs; - if (nvararg < 0) - els_Heap_adjusttop(L, base, nfixargs); - els_Vmcore_pack(L, base + nfixargs); -} - -#define dojump(pc, i) \ - { \ - int d = GETARG_S(i); \ - pc += d; \ - } - -extern double pow(double x, double y); - - -StackObj* els_Vmcore_execute(els_VmObj *L, const ElsCfunc *cl, StackObj* base) -{ - const els_func_code *const tf = cl->f.l; - StackObj* top; - const Instruction *pc = tf->code; - TString **const kstr = tf->kstr; - infovalue(base - 1)->pc = &pc; - els_Heap_checkstack(L, tf->maxstacksize + EXTRA_STACK); - if (tf->is_vararg) - adjust_varargs(L, base, tf->numparams); - else - els_Heap_adjusttop(L, base, tf->numparams); - top = L->top; - - while (1) - { - const Instruction i = *pc++; - switch (GET_OPCODE(i)) - { - case BYTECODE_END: - { - L->top = top; - return top; - } - case BYTECODE_RETURN: - { - L->top = top; - return base + GETARG_U(i); - } - case BYTECODE_CALL: - { - int nres = GETARG_B(i); - if (nres == MULT_RET) - nres = ELS_MULTRET; - L->top = top; - // printf("STACK Start:\t%lx\n",top); - LosuObj * func = base + GETARG_A(i); - // if(ttype(func)==ELS_TYPE_UNIT){ - // L->top++; - // for(LosuObj* i = L->top-1;i != func;i--) - // *i = *(i-1); - // *func = *obj_indexunit(L,*func,obj_newstr(L,"class")); - // } - - - els_Heap_call(L, func, nres); - - top = L->top; - // printf("STACK End:\t%lx\n",top); - break; - } - case BYTECODE_PUSHNULL: - { - int n = GETARG_U(i); - do - { - ttype(top++) = ELS_TYPE_NULL; - } while (--n > 0); - break; - } - case BYTECODE_POP: - { - top -= GETARG_U(i); - break; - } - case BYTECODE_PUSHSTRING: - { - ttype(top) = ELS_TYPE_STRING; - tsvalue(top) = kstr[GETARG_U(i)]; - top++; - break; - } - case BYTECODE_PUSHNUM: - { - ttype(top) = ELS_TYPE_NUMBER; - nvalue(top) = tf->knum[GETARG_U(i)]; - top++; - break; - } - case BYTECODE_PUSHUPVALUE: - { - *top++ = cl->upvalue[GETARG_U(i)]; - break; - } - case BYTECODE_GETLOCAL: - { - *top++ = *(base + GETARG_U(i)); - break; - } - case BYTECODE_GETGLOBAL: - { - L->top = top; - *top = *els_Vmcore_getglobal(L, kstr[GETARG_U(i)]); - top++; - break; - } - case BYTECODE_GETUNIT: - { - char *tmp; - StackObj tmp2; - StackObj *h; - L->top = top; - top--; - switch (ttype(top - 1)) - { - case ELS_TYPE_STRING: - - h = &tmp2; - tmp = (char *)els_Mem_malloc(L, 2); - if ((int)((*(top)).value.n) > strlen(((*(top - 1)).value.ts->str)) ) - tmp[0]='\0'; - else - tmp[0] = ((*(top - 1)).value.ts->str)[(int)((*(top)).value.n) - 1]; - tmp[1] = '\0'; - h->ttype = ELS_TYPE_STRING; - h->value.ts = els_string_newlstr(L, tmp, 1); - *(top - 1) = *h; - break; - case ELS_TYPE_BYTE: - h = &tmp2; - tmp = (char *)els_Mem_malloc(L, 2); - if ((int)((*(top)).value.n) > (((*(top - 1)).value.ts->len)) ) - tmp[0]='\0'; - else - tmp[0] = ((*(top - 1)).value.ts->str)[(int)((*(top)).value.n) - 1]; - tmp[1] = '\0'; - h->ttype = ELS_TYPE_STRING; - h->value.ts = els_string_newlstr(L, tmp, 1); - *(top - 1) = *h; - break; - default: - *(top - 1) = *els_Vmcore_getunit(L, top - 1); - break; - } - - break; - } - case BYTECODE_PUSHSELF: - { - StackObj receiver; - receiver = *(top - 1); - ttype(top) = ELS_TYPE_STRING; - tsvalue(top++) = kstr[GETARG_U(i)]; - L->top = top; - *(top - 2) = *els_Vmcore_getunit(L, top - 2); - *(top - 1) = receiver; - break; - } - case BYTECODE_CREATEUNIT: - { - L->top = top; -#if ELS_CONF_GC_ENABLE == 1 - els_Gc_checkGC(L); -#endif - hvalue(top) = els_Unit_new(L, GETARG_U(i)); - ttype(top) = ELS_TYPE_UNIT; - top++; - break; - } - case BYTECODE_SETLOCAL: - { - *(base + GETARG_U(i)) = *(--top); - break; - } - case BYTECODE_SETGLOBAL: - { - L->top = top; - els_Vmcore_setglobal(L, kstr[GETARG_U(i)]); - top--; - break; - } - case BYTECODE_SETUNIT: - { - StackObj* t = top - GETARG_A(i); - L->top = top; - els_Vmcore_setunit(L, t, t + 1); - top -= GETARG_B(i); - break; - } - case BYTECODE_SETLIST: - { - int aux = GETARG_A(i) * LFIELDS_PER_FLUSH; - int n = GETARG_B(i); - Hash *arr = hvalue(top - n - 1); - L->top = top - n; - for (; n; n--) - *els_Unit_setint(L, arr, n + aux) = *(--top); - break; - } - case BYTECODE_SETMAP: - { - int n = GETARG_U(i); - StackObj* finaltop = top - 2 * n; - Hash *arr = hvalue(finaltop - 1); - L->top = finaltop; - for (; n; n--) - { - top -= 2; - *els_Unit_set(L, arr, top) = *(top + 1); - } - break; - } - case BYTECODE_ADD: - { - if (tonumber(top - 2) || tonumber(top - 1)) - { - top += 2; - L->top = top; - tsvalue(top - 1) = els_string_newlstr(L, "::+", 3); - ttype(top - 1) = ELS_TYPE_STRING; - *(top - 2) = *(top - 4); - *(top) = *els_Vmcore_getunit(L, top - 2); - top += 3; - L->top = top; - *(top - 2) = *(top - 7); - *(top - 1) = *(top - 6); - if(ttype(top-3)!=ELS_TYPE_FUNCTION) - vm_error(L,"+ 运算符并未被定义如何重载",ELS_ERRORBACK_RUN); - els_Heap_call(L, top - 3, 1); - *(top - 7) = *(top); - top -= 6; - L->top = top; - break; - } - else - nvalue(top - 2) += nvalue(top - 1); - top--; - break; - } - case BYTECODE_SUB: - { - if (tonumber(top - 2) || tonumber(top - 1)) - { - top += 2; - L->top = top; - tsvalue(top - 1) = els_string_newlstr(L, "::-", 3); - ttype(top - 1) = ELS_TYPE_STRING; - *(top - 2) = *(top - 4); - *(top) = *els_Vmcore_getunit(L, top - 2); - top += 3; - L->top = top; - *(top - 2) = *(top - 7); - *(top - 1) = *(top - 6); - if(ttype(top-3)!=ELS_TYPE_FUNCTION) - vm_error(L,"- 运算符并未被定义如何重载",ELS_ERRORBACK_RUN); - els_Heap_call(L, top - 3, 1); - *(top - 7) = *(top); - top -= 6; - L->top = top; - break; - } - else - nvalue(top - 2) -= nvalue(top - 1); - top--; - break; - } - case BYTECODE_MULT: - { - if (tonumber(top - 2) || tonumber(top - 1)) - { - top += 2; - L->top = top; - tsvalue(top - 1) = els_string_newlstr(L, "::*", 3); - ttype(top - 1) = ELS_TYPE_STRING; - *(top - 2) = *(top - 4); - *(top) = *els_Vmcore_getunit(L, top - 2); - top += 3; - L->top = top; - *(top - 2) = *(top - 7); - *(top - 1) = *(top - 6); - if(ttype(top-3)!=ELS_TYPE_FUNCTION) - vm_error(L,"* 运算符并未被定义如何重载",ELS_ERRORBACK_RUN); - els_Heap_call(L, top - 3, 1); - *(top - 7) = *(top); - top -= 6; - L->top = top; - break; - } - else - nvalue(top - 2) *= nvalue(top - 1); - top--; - break; - } - case BYTECODE_DIV: - { - if (tonumber(top - 2) || tonumber(top - 1)) - { - top += 2; - L->top = top; - tsvalue(top - 1) = els_string_newlstr(L, "::/", 3); - ttype(top - 1) = ELS_TYPE_STRING; - *(top - 2) = *(top - 4); - *(top) = *els_Vmcore_getunit(L, top - 2); - top += 3; - L->top = top; - *(top - 2) = *(top - 7); - *(top - 1) = *(top - 6); - if(ttype(top-3)!=ELS_TYPE_FUNCTION) - vm_error(L,"/ 运算符并未被定义如何重载",ELS_ERRORBACK_RUN); - els_Heap_call(L, top - 3, 1); - *(top - 7) = *(top); - top -= 6; - L->top = top; - break; - } - else - nvalue(top - 2) /= nvalue(top - 1); - top--; - break; - } - case BYTECODE_POW: - { - if (tonumber(top - 2) || tonumber(top - 1)) - { - top += 2; - L->top = top; - tsvalue(top - 1) = els_string_newlstr(L, "::^", 3); - ttype(top - 1) = ELS_TYPE_STRING; - *(top - 2) = *(top - 4); - *(top) = *els_Vmcore_getunit(L, top - 2); - top += 3; - L->top = top; - *(top - 2) = *(top - 7); - *(top - 1) = *(top - 6); - if(ttype(top-3)!=ELS_TYPE_FUNCTION) - vm_error(L,"^ 运算符并未被定义如何重载",ELS_ERRORBACK_RUN); - els_Heap_call(L, top - 3, 1); - *(top - 7) = *(top); - top -= 6; - L->top = top; - break; - } - else - nvalue(top - 2) = pow(nvalue(top - 2), nvalue(top - 1)); - top--; - break; - } - case BYTECODE_CONCAT: - { - els_Vmcore_strconc(L, top); - top--; - L->top = top; -#if ELS_CONF_GC_ENABLE == 1 - els_Gc_checkGC(L); -#endif - break; - } - case BYTECODE_MINUS: - { - if (tonumber(top - 1)) - { - ttype(top) = ELS_TYPE_NULL; - } - else - nvalue(top - 1) = -nvalue(top - 1); - break; - } - case BYTECODE_NOT: - { - ttype(top - 1) = (ttype(top - 1) == ELS_TYPE_NULL) ? ELS_TYPE_NUMBER : ELS_TYPE_NULL; - nvalue(top - 1) = 1; - break; - } - case BYTECODE_JMPNE: - { - top -= 2; - if (!els_Object_equalObj(top, top + 1)) - dojump(pc, i); - break; - } - case BYTECODE_JMPEQ: - { - top -= 2; - if (els_Object_equalObj(top, top + 1)) - dojump(pc, i); - break; - } - case BYTECODE_JMPLT: - { - top -= 2; - if (els_Vmcore_lessthan(L, top, top + 1, top + 2)) - dojump(pc, i); - break; - } - case BYTECODE_JMPLE: - { - top -= 2; - if (!els_Vmcore_lessthan(L, top + 1, top, top + 2)) - dojump(pc, i); - break; - } - case BYTECODE_JMPGT: - { - top -= 2; - if (els_Vmcore_lessthan(L, top + 1, top, top + 2)) - dojump(pc, i); - break; - } - case BYTECODE_JMPGE: - { - top -= 2; - if (!els_Vmcore_lessthan(L, top, top + 1, top + 2)) - dojump(pc, i); - break; - } - case BYTECODE_JMPT: - { - if (ttype(--top) != ELS_TYPE_NULL) - dojump(pc, i); - break; - } - case BYTECODE_JMPF: - { - if (ttype(--top) == ELS_TYPE_NULL) - dojump(pc, i); - break; - } - case BYTECODE_JMPONT: - { - if (ttype(top - 1) == ELS_TYPE_NULL) - top--; - else - dojump(pc, i); - break; - } - case BYTECODE_JMPONF: - { - if (ttype(top - 1) != ELS_TYPE_NULL) - top--; - else - dojump(pc, i); - break; - } - case BYTECODE_JMP: - { - dojump(pc, i); - break; - } - case BYTECODE_PUSHNULLJMP: - { - ttype(top++) = ELS_TYPE_NULL; - pc++; - break; - } - case BYTECODE_FORPREP: - { - if (tonumber(top - 1)) - { - vm_error(L, "错误的循环结构,缺少步幅",ELS_ERRORBACK_RUN); - } - if (tonumber(top - 2)) - vm_error(L, "错误的循环结构,缺少极值",ELS_ERRORBACK_RUN); - if (tonumber(top - 3)) - vm_error(L, "错误的循环结构,缺少初值",ELS_ERRORBACK_RUN); - if (nvalue(top - 1) > 0 ? nvalue(top - 3) > nvalue(top - 2) : nvalue(top - 3) < nvalue(top - 2)) - { - top -= 3; - dojump(pc, i); - } - break; - } - case BYTECODE_FORLOOP: - { - - if (ttype(top - 3) != ELS_TYPE_NUMBER) - vm_error(L, "错误的循环结构,缺少步幅",ELS_ERRORBACK_RUN); - nvalue(top - 3) += nvalue(top - 1); - if (nvalue(top - 1) > 0 ? nvalue(top - 3) > nvalue(top - 2) : nvalue(top - 3) < nvalue(top - 2)) - top -= 3; - else - dojump(pc, i); - break; - } - case BYTECODE_LFORPREP: - { - Node *node; - if (ttype(top - 1) != ELS_TYPE_UNIT) - vm_error(L, "错误的循环结构,缺少要列举的对象",ELS_ERRORBACK_RUN); - node = els_Unit_next(L, hvalue(top - 1), &els_Object_nullobject); - if (node == NULL) - { - top--; - dojump(pc, i); - } - else - { - top += 2; - *(top - 2) = *key(node); - *(top - 1) = *val(node); - } - break; - } - case BYTECODE_LFORLOOP: - { - Node *node; - node = els_Unit_next(L, hvalue(top - 3), top - 2); - if (node == NULL) - top -= 3; - else - { - *(top - 2) = *key(node); - *(top - 1) = *val(node); - dojump(pc, i); - } - break; - } - case BYTECODE_PUSHFUNCTION: - { - L->top = top; - els_Vmcore_L_csfunciotn(L, tf->kcodeir[GETARG_A(i)], GETARG_B(i)); - top = L->top; -#if ELS_CONF_GC_ENABLE == 1 - els_Gc_checkGC(L); -#endif - break; - } - default: - { - vm_error(L, "错误的字节码,编译器完整性可能遭到破坏,拒绝进一步地执行",ELS_ERRORBACK_OVER); - } - } -#if ELS_CONF_GC_ENABLE == 2 - els_Gc_checkGC(L); -#endif - } -} - -static int zmfilbuf(vm_iobuff *z) -{ - (void)z; - return EOZ; -} - -vm_iobuff *els_vmio_mopen(vm_iobuff *z, const char *b, size_t size, const char *name) -{ - if (b == NULL) - return NULL; - z->n = size; - z->p = (const unsigned char *)b; - z->filbuf = zmfilbuf; - z->u = NULL; - z->name = name; - return z; -} - -vm_iobuff *els_vmio_sopen(vm_iobuff *z, const char *s, const char *name) -{ - if (s == NULL) - return NULL; - return els_vmio_mopen(z, s, strlen(s), name); -} - -static int zffilbuf(vm_iobuff *z) -{ - size_t n=0; - if (feof((FILE *)(z->u))) - return EOZ; - n = fread((z->buffer),sizeof(char) , ELS_VMIO_SIZE, (FILE *)(z->u)); - if (n == 0) - return EOZ; - z->n = n - 1; - z->p = z->buffer; - return *(z->p++); -} - -vm_iobuff *els_vmio_Fopen(vm_iobuff *z, FILE *f, const char *name) -{ - if (f == NULL) - return NULL; - z->n = 0; - z->p = z->buffer; - z->filbuf = zffilbuf; - z->u = f; - z->name = name; - return z; -} - -size_t els_vmio_read(vm_iobuff *z, void *b, size_t n) -{ - while (n) - { - size_t m; - if (z->n == 0) - { - if (z->filbuf(z) == EOZ) - return n; - els_vmio_ugetc(z); - } - m = (n <= z->n) ? n : z->n; - memcpy(b, z->p, m); - z->n -= m; - z->p += m; - b = (char *)b + m; - n -= m; - } - return 0; -} diff --git a/losu_core/els_vmcore.h b/losu_core/els_vmcore.h deleted file mode 100755 index bfa6dac85d3cbf2caf2ed95ed8797fe026b7a5e3..0000000000000000000000000000000000000000 --- a/losu_core/els_vmcore.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef __els_vm_core_h__ -#define __els_vm_core_h__ - - -#include"els.h" -#include -#include "els_heap.h" -#include "els_object.h" - -#define EOZ (-1) -#define els_vmio_getc(z) (((z)->n--)>0 ? ((int)*((z)->p++)): (z)->filbuf(z)) -#define els_vmio_ugetc(z) (++(z)->n,--(z)->p) -#define els_vmio_name(z) ((z)->name) -#define tonumber(o) ((ttype(o) != ELS_TYPE_NUMBER) && (els_Vmcore_tonumber(o) != 0)) -#define tostring(L,o) ((ttype(o) != ELS_TYPE_STRING) && (els_Vmcore_tostring(L, o) != 0)) - - - -typedef struct vm_iobuff vm_iobuff; -typedef struct vm_iobuff { - size_t n; - const unsigned char* p; - int (*filbuf)(vm_iobuff* z); - FILE* u; - const char *name; - unsigned char buffer[ELS_VMIO_SIZE]; -}vm_iobuff ; -vm_iobuff* els_vmio_Fopen (vm_iobuff* z, FILE* f, const char *name); -vm_iobuff* els_vmio_sopen (vm_iobuff* z, const char* s, const char *name); -vm_iobuff* els_vmio_mopen (vm_iobuff* z, const char* b, size_t size, const char *name); - -int els_Vmcore_tonumber (StackObj *obj); -int els_Vmcore_tostring (els_VmObj *L, StackObj *obj); -const StackObj *els_Vmcore_getunit (els_VmObj *L, StackObj* t); -void els_Vmcore_setunit (els_VmObj *L, StackObj* t, StackObj* key); -const StackObj *els_Vmcore_getglobal (els_VmObj *L, TString *s); -void els_Vmcore_setglobal (els_VmObj *L, TString *s); -StackObj* els_Vmcore_execute (els_VmObj *L, const ElsCfunc *cl, StackObj* base); -void els_Vmcore_C_csfunciotn (els_VmObj *L, els_C_API_function c, int issues_num); -void els_Vmcore_L_csfunciotn (els_VmObj *L, els_func_code *l, int issues_num); -int els_Vmcore_lessthan (els_VmObj *L, const StackObj *l, const StackObj *r, StackObj* top); -void els_Vmcore_strconc (els_VmObj *L,StackObj* top); - - -#endif \ No newline at end of file diff --git a/losu_core/els_vmhost.c b/losu_core/els_vmhost.c deleted file mode 100755 index 69c0053a7db515f7ab83b47730331eae6ec2acd1..0000000000000000000000000000000000000000 --- a/losu_core/els_vmhost.c +++ /dev/null @@ -1,182 +0,0 @@ -#include -#include - -#include "els.h" -#include "els_heap.h" -#include "els_gc.h" -#include "els_lex.h" -#include "els_mem.h" -#include "els_vmhost.h" -#include "els_string.h" -#include "els_unit.h" - -#define api_incr_top(L) incr_top(L) - -static void els_newunit(els_VmObj *L) -{ - hvalue(L->top) = els_Unit_new(L, 0); - ttype(L->top) = ELS_TYPE_UNIT; - api_incr_top(L); -} -static int els_heap_ref(els_VmObj *L, int lock) -{ - int ref; - if (ttype(L->top - 1) == ELS_TYPE_NULL) - ref = ELS_REFNULL; - else - { - if (L->refFree != NONEXT) - { - ref = L->refFree; - L->refFree = L->refArray[ref].st; - } - else - { - els_Mem_growvector(L, L->refArray, L->refSize, 1, struct Ref, "初始化单元溢出", MAX_INT); - L->nblocks += sizeof(struct Ref); - ref = L->refSize++; - } - L->refArray[ref].o = *(L->top - 1); - L->refArray[ref].st = lock ? LOCK : HOLD; - } - L->top--; - return ref; -} - - - - -static void f_elsopen(els_VmObj *L, void *ud) -{ - int stacksize = *(int *)ud; - if (stacksize == 0) - stacksize = ELS_VM_STACK_SIZE; - if(L->mainthread==L) - L->globalenv = els_Unit_new(L, 0); - else - L->globalenv = L->mainthread->globalenv; - els_Heap_init(L, stacksize); - els_string_init(L); - els_lexer_init(L); - els_newunit(L); - els_heap_ref(L, 1); -} - -void restore_stack_limit(els_VmObj *L); -ELS_API els_VmObj *vm_create(int stacksize) -{ - els_VmObj *L = els_Mem_new(NULL, els_VmObj); - if (L == NULL) - return NULL; - L->mainthread = L; - L->stack = NULL; - L->strpool.size = 0; - L->strpool.nuse = 0; - L->strpool.hash = NULL; - L->BufferTmp = NULL; - L->BufferTmpSize = 0; - L->rootcodeir = NULL; - L->rootcl = NULL; - L->rootunit = NULL; - L->refArray = NULL; - L->refSize = 0; - L->refFree = NONEXT; - L->nblocks = sizeof(els_VmObj); - L->GCnowmax = MAX_INT; - L->errorJmp = NULL; - L->GCMAX = 0; - StackObj* oldCbase = L->Cbase; - StackObj* oldtop = L->top; - struct els_longjmp lj; - lj.status = 0; - lj.previous = L->errorJmp; - L->errorJmp = &lj; - if (setjmp(lj.b) == 0) - f_elsopen(L, &stacksize); - else - { - L->Cbase = oldCbase; - L->top = oldtop; - restore_stack_limit(L); - } - L->errorJmp = lj.previous; - int status = lj.status; - - if (status != 0) - { - vm_close(L); - return NULL; - } - - - L->GCnowmax = 0; - return L; -} - -ELS_API els_VmObj* vm_fork(els_VmObj*vm,int stacksize){ - els_VmObj *L = els_Mem_new(NULL, els_VmObj); - if (L == NULL) - return NULL; - L->mainthread = vm; - L->stack = NULL; - L->strpool.size= 0; - L->strpool.nuse = 0; - L->strpool.hash = NULL; - L->BufferTmp = NULL; - L->BufferTmpSize = 0; - L->rootcodeir = NULL; - L->rootcl = NULL; - L->rootunit = NULL; - L->refArray = NULL; - L->refSize = 0; - L->refFree = NONEXT; - L->nblocks = vm->nblocks; - L->GCnowmax = MAX_INT; - L->errorJmp = NULL; - L->GCMAX = 0; - StackObj* oldCbase = L->Cbase; - StackObj* oldtop = L->top; - struct els_longjmp lj; - lj.status = 0; - lj.previous = L->errorJmp; - L->errorJmp = &lj; - if (setjmp(lj.b) == 0) - f_elsopen(L, &stacksize); - else - { - L->Cbase = oldCbase; - L->top = oldtop; - restore_stack_limit(L); - } - L->errorJmp = lj.previous; - int status = lj.status; - - if (status != 0) - { - vm_close(L); - return NULL; - } - - - L->GCnowmax = 0; - return L; -} - -ELS_API void vm_close(els_VmObj *L) -{ - if(L->mainthread!=L) - // L->globalenv = els_Unit_new(L, 0); - L->globalenv = NULL; -#ifdef ELS_CONF_GC_ENABLE - els_Gc_collect(L, 1); -#endif - els_string_freeall(L); - if (L->stack) - L->nblocks -= (L->stack_last - L->stack + 1) * sizeof(StackObj); - els_Mem_free(L, L->stack); - L->nblocks -= (L->refSize) * sizeof(struct Ref); - els_Mem_free(L, L->refArray); - L->nblocks -= (L->BufferTmpSize) * sizeof(char); - els_Mem_free(L, L->BufferTmp); - els_Mem_free(L, L); -} diff --git a/losu_core/els_vmhost.h b/losu_core/els_vmhost.h deleted file mode 100755 index 0c95af78378a1b5c9bf27b9339eb6d3757082ca6..0000000000000000000000000000000000000000 --- a/losu_core/els_vmhost.h +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef __els_vmhost_h__ -#define __els_vmhost_h__ - -#include -#include "els.h" -#include "els_object.h" - - -#define NONEXT -1 -#define HOLD -2 -#define COLLECTED -3 -#define LOCK -4 - - -struct Ref -{ - StackObj o; - int st; -}; - -struct els_longjmp -{ - jmp_buf b; - struct els_longjmp *previous; - volatile int status; -}; - -typedef struct stringunit -{ - int size; - lint32 nuse; - TString **hash; -} stringunit; - - - -struct els_VmObj -{ - struct els_VmObj * mainthread; - StackObj* top; - StackObj* stack; - StackObj* stack_last; - int stacksize; - StackObj* Cbase; - struct els_longjmp *errorJmp; - char *BufferTmp; - size_t BufferTmpSize; - - els_func_code *rootcodeir; - ElsCfunc *rootcl; - Hash *rootunit; - stringunit strpool; - Hash *globalenv; - struct Ref *refArray; - int refSize; - int refFree; - unsigned long GCnowmax; - unsigned long nblocks; - unsigned long GCMAX; -}; - -void els_unit_init(els_VmObj *L); -void els_unit_realtag(els_VmObj *L, int tag); -int els_unit_tag(const StackObj *o); -int els_unit_validevent(int t, int e); - -#endif \ No newline at end of file diff --git a/losu_core/info b/losu_core/info deleted file mode 100755 index ad6c93ecade0d869fe277816d43f43bb38f0687a..0000000000000000000000000000000000000000 --- a/losu_core/info +++ /dev/null @@ -1,37 +0,0 @@ -{ - type = "const", - info = { - name = "losu_core/洛书内核", - text = "洛书解释器内核", - version="24.2.5" - }, - source = { - all ={ - "els.h", "els_codegen.c", - "els_func.h","els_heap.c", - "els_lex.h" ,"els_mem.c", - "els_object.h","els_string.c", - "els_unit.h","els_vmhost.c", - "els_api.c", "els_codegen.h", - "els_gc.c","els_heap.h" , - "els_libload.c", "els_mem.h", - "els_parser.c","els_string.h", - "els_vmcore.c","els_vmhost.h", - "els_bytecode.h","els_func.c", - "els_gc.h", "els_lex.c", - "els_object.c","els_parser.h", - "els_unit.c","els_vmcore.h", "els.c", - "els_version.h","els_libload.h" - }, - Ubuntu = { - "makefile" - }, - Windows ={ - "makefile" - } - }, - target = { - Ubuntu = "make;cp libeasylosu.so target/libeasylosu.so_Ubuntu;make clean", - Windows = "make;cp libeasylosu.dll target/libeasylosu.dll;cp libeasylosu.dll ../buildenv/libeasylosu.dll;make clean;cp *.h ../buildenv/", - } -} \ No newline at end of file diff --git a/losu_core/readme.md b/losu_core/readme.md deleted file mode 100755 index 30706f0bb0862c15c0b93a26cef3520407e4eaf1..0000000000000000000000000000000000000000 --- a/losu_core/readme.md +++ /dev/null @@ -1,135 +0,0 @@ -#!/bin/owls.wiki.losu.tech -# 洛书内核 -## 标准配置宏 -``` C++ -// 文件 els.h - -#ifdef LOSU_WINDOWS - #ifndef ELS_CONF_OS_WINDOWS - #define ELS_CONF_OS_WINDOWS - #endif -#endif - -#ifdef LOSU_LINUX - #ifndef ELS_CONF_OS_LINUX - #define ELS_CONF_OS_LINUX - #endif -#endif - - -#ifdef ELS_CONF_OS_WINDOWS // Windows 平台配置宏 - #ifndef LOSU_WINDOWS // 兼容接口 - #define LOSU_WINDOWS 1 - #endif - #define ELS_CONF_TOKEN_CN 1 // 开启中文关键词与模块支持,删去后模块中文接口将随之关闭 - #define ELS_CONF_TOKEN_EN 1 // 开启英文关键词与模块支持 - #define ELS_CONF_LIBAPI_WIN32 1 // 将 libapi 的实现模式设定为 Win32 - // #define ELS_CONF_LIBAPI_DL 1 // 不开启 dl 库实现(Linux平台开启) - #define ELS_CONF_LIBAPI_ELF 1 // 兼容 elf 模式的 libapi (即被编译到内核中的内置模块) - #define ELS_CONF_CHAR_GBK 1 // 开启 GBK 兼容层 - #define ELS_CONF_GC_ENABLE 1 // 开启 GC - #define ELS_VM_STACK_SIZE 1024 // 虚拟机默认栈大小 (1KB 虚拟内存) - #define ELS_BUFF_TMP_SIZE 1024*1024 // 字符串缓冲区大小 ( 1M ) - #define ELS_VMIO_SIZE 64 // 虚拟机 IO 缓冲区 (64B) - #define ELS_HEAPMEM_REALLOC realloc // 内存管理函数 - #define ELS_HEAPMEM_FREE free -#endif - -``` - -## 虚拟机 API 接口 - -``` C++ -ELS_API void els_lib_init(els_VmObj* ); // 初始化内核,加载 import 函数 - -ELS_API int ElsNewApp(int (*func)(els_VmObj*,const char* s),char *s,int stacksize,size_t gcmax,int argc,const char** argv); - -ELS_API els_VmObj* vm_create(int); -ELS_API els_VmObj* vm_fork(els_VmObj*vm,int size); -ELS_API void vm_stop(els_VmObj*); -ELS_API void vm_error(els_VmObj*,const char* ,int ); -ELS_API int vm_dofile(els_VmObj*,const char* ); -ELS_API int vm_dostring(els_VmObj*,const char* ); -ELS_API LosuObj* vm_getval(els_VmObj*,const char* ); -ELS_API void vm_setval(els_VmObj *,const char* ,LosuObj* ); -ELS_API void vm_register(els_VmObj*,const char* ,VmCapi ); -ELS_API void vm_close(els_VmObj*); -ELS_API void vm_setGC(els_VmObj*,unsigned long ); -ELS_API els_VmObj* vm_newthread(els_VmObj*); -ELS_API void vm_endthread(els_VmObj*); -ELS_API unsigned long vm_getmem(els_VmObj*); - -ELS_API LosuObj* arg_get(els_VmObj*,int ); -ELS_API void arg_return(els_VmObj *,LosuObj ); -ELS_API int arg_num(els_VmObj*); - -ELS_API Number arg_getnum(els_VmObj*,int ); -ELS_API const char* arg_getstr(els_VmObj*,int ); -ELS_API const char* arg_getbyte(els_VmObj*,int); -ELS_API char* arg_getptr(els_VmObj*,int ); -ELS_API VmCapi arg_getfunc(els_VmObj*,int ); -ELS_API int arg_gettype(els_VmObj*,int); - -ELS_API void arg_returnnum(els_VmObj*,Number); -ELS_API void arg_returnstr(els_VmObj*,const char* ); -ELS_API void arg_returnfunc(els_VmObj*,VmCapi ); -ELS_API void arg_returnptr(els_VmObj*,char* ); -ELS_API void arg_returnnull(els_VmObj*); -ELS_API void arg_returnbyte(els_VmObj*,char* ,size_t); - - -ELS_API const char* obj_tostr(els_VmObj* ,LosuObj *); -ELS_API Number obj_tonum(els_VmObj* ,LosuObj* ); -ELS_API char* obj_toptr(els_VmObj*,LosuObj*); -ELS_API VmCapi obj_tofunction(els_VmObj*,LosuObj*); -ELS_API const char* obj_tobyte(els_VmObj *,LosuObj *); -ELS_API int obj_type(els_VmObj*,LosuObj*); - -ELS_API LosuObj obj_newstr(els_VmObj* ,char* ); -ELS_API LosuObj obj_newnum(els_VmObj* ,Number ); -ELS_API LosuObj obj_newfunction(els_VmObj*,els_C_API_function ); -ELS_API LosuObj obj_newnull(els_VmObj* ); -ELS_API LosuObj obj_newunit(els_VmObj* ); -ELS_API LosuObj obj_newptr(els_VmObj*,char* ); -ELS_API LosuObj obj_newbyte(els_VmObj*,char*,size_t ); - -ELS_API LosuObj* obj_indexunit(els_VmObj*,LosuObj ,LosuObj ); -ELS_API LosuObj* obj_indexunitbynum(els_VmObj*vm,LosuObj unit,Number i); -ELS_API LosuObj* obj_indexunitbystr(els_VmObj*vm,LosuObj unit,char* s); -ELS_API void obj_setunit(els_VmObj*,LosuObj ,LosuObj ,LosuObj ); -ELS_API void obj_setunitbynum(els_VmObj*,LosuObj unit,Number key ,LosuObj value); -ELS_API void obj_setunitbystr(els_VmObj*,LosuObj unit,char* key ,LosuObj value); - - -// 下面4个 API 仅在 Windows 内核中被启用,负责字符集的转换。 - // 洛书的内核全部为 utf-8编码,可以使用转换函数,将其转换为 GBK 后传递给 Windows API - // 手动转换函数,转换后的字符串被存放在堆区中,需要手动释放堆区 -ELS_API char* vm_win_togbk(const char * ); -ELS_API char* vm_win_toutf8(const char* ); - // 自动转换函数,转换后的字符串被存放在 Vm 的字符池中,会在下一个周期被 GC 自动回收 ( 如果GC 被 启动) -ELS_API char* obj_toUTF8(els_VmObj*,char*); -ELS_API char* obj_toGBK(els_VmObj*,char* ); - - -ELS_API const char *ELS_TYPESYSTEM[]; -ELS_API char els_buff_tmp[]; - -``` - -### 创建解释器 -+ 标准 API - -```C++ -els_VmObj *l=vm_create(1024); // 创建虚拟机 -els_lib_init(l); // 初始化内核 -vm_dostring(l,""); // 解释字符串 -vm_dofile(l,""); // 解释文件 - -``` - -+ 快速 API(测试中) -```C++ -int main(int argc,const char** argv){ - ElsNewApp(vm_dostring,"print('Hello')",1024 ,0 , argc,argv); // 创建一个 栈大小 1024B,GC上限 0B,解释字符串的 洛书应用(Losu APP) -} -``` \ No newline at end of file diff --git a/lpkg/Ubuntu/makefile b/lpkg/Ubuntu/makefile deleted file mode 100755 index 37cf31607c9573dd5229ea4bf9379860b93662f2..0000000000000000000000000000000000000000 --- a/lpkg/Ubuntu/makefile +++ /dev/null @@ -1,13 +0,0 @@ -OBJS = lpkg.o -CFLAGS= -O2 -Wall -std=c99 -DLOSU_LINUX -I ../buildenv -fPIC -CC=x86_64-linux-gnu-gcc -T=./ElsLib_lpkg.lsd - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -shared -lm -s - -clean: - rm -rf $T $(OBJS) core core.* \ No newline at end of file diff --git a/lpkg/Windows/makefile b/lpkg/Windows/makefile deleted file mode 100755 index dd16d7059abccc33aed3978ab3c88ab674c149cb..0000000000000000000000000000000000000000 --- a/lpkg/Windows/makefile +++ /dev/null @@ -1,13 +0,0 @@ -OBJS = lpkg.o -CFLAGS= -O2 -Wall -std=c99 -DLOSU_WINDOWS -I ../buildenv -fPIC -CC=x86_64-w64-mingw32-gcc -T=ElsLib_lpkg.lsd - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -L ../buildenv -l:libeasylosu.dll -lurlmon -luser32 -lkernel32 -lwininet -static -shared -s - -clean: - rm -f $T $(OBJS) core core.* \ No newline at end of file diff --git a/lpkg/info b/lpkg/info deleted file mode 100755 index b367531f10f576b3d80bf2ba85366b01be0d15a3..0000000000000000000000000000000000000000 --- a/lpkg/info +++ /dev/null @@ -1,25 +0,0 @@ -{ - info = { - name = "lpkg/模块开发者工具", - text = "Losu Package ,适合开发者的模块管理工具,支持提交、检出、校验与自动化构建", - version = "23.12.26", - }, - source = { - all = { - "lpkg.els", - "lpkg.h", - "lpkg.c", - }, - Ubuntu = { - "makefile" - }, - Windows = { - "makefile" - }, - - }, - target = { - Ubuntu = "make ; cp ElsLib_lpkg.lsd target/ElsLib_lpkg.lsd_Ubuntu ; make clean", - Windows = "make; cp ElsLib_lpkg.lsd target/ElsLib_lpkg.lsd_Windows ; make clean" - } -} \ No newline at end of file diff --git a/lpkg/lpkg.c b/lpkg/lpkg.c deleted file mode 100755 index 18afd80a236b5a6b82e022c9d80bcc4efd3eeb86..0000000000000000000000000000000000000000 --- a/lpkg/lpkg.c +++ /dev/null @@ -1 +0,0 @@ -#include "lpkg.h" diff --git a/lpkg/lpkg.els b/lpkg/lpkg.els deleted file mode 100755 index 1fcf61ede2fefba77d547b94766cf5a5b1221474..0000000000000000000000000000000000000000 --- a/lpkg/lpkg.els +++ /dev/null @@ -1,216 +0,0 @@ -#!script -import "stdlib" - -var Lpkg={ - cmd = { - cp = def():;, - mkdir = def():;, - rm = def():;, - }, - error = def():;, - init = def():;, - argv = { - show = def():;, - clean = def():;, - make = def():;, - md5sum = def():;, - md5check = def():;, - checkout = def():;, - commit = def():;, - }, - ThisPack = {} -} - -def Lpkg.cmd.cp(src,obj): - return sys.system("cp \""&src&"\" \""&obj&"\"") - pass - -def Lpkg.cmd.mkdir(dir): - return sys.system("mkdir -p \""&dir&"\"") - pass - -def Lpkg.cmd.rm(f): - return sys.system("rm -f \""&f&"\"") - pass - - -def Lpkg.error(s): - print("[ERROR/错误]:LPKG:\t",s) - exit(1) - pass - -def Lpkg.init(): - var fin = file.open("info","r") - var s = "" - if not fin : - Lpkg.error("当前目录下没有模块配置文件!") pass - with not fin.eof(): - s = s & fin.lineinput() & "\n" - pass - eval("Lpkg.ThisPack="&s) - fin.close() - pass - - -def Lpkg.argv.show(): - print("当前模块信息:") - print("包名:\t"&Lpkg.ThisPack.info.name) - print("介绍:\t"&Lpkg.ThisPack.info.text) - print("版本:\t"&Lpkg.ThisPack.info.version) - print("支持的分支:") - print("\tall:") - for i,f in Lpkg.ThisPack.source.all: - print("\t\t",f) - pass - for n,b in Lpkg.ThisPack.source : - if n != "all": - print("\t",n,':') - for i,f in b: - print("\t\t",f) pass - pass - pass - pass - -def Lpkg.argv.clean(): - var fin = file.open(".lpkg","r") - if not fin: - Lpkg.error("工作区尚未打开分支!") pass - var Arch = fin.input() - fin.close() - # 清空工作区 - for i,f in Lpkg.ThisPack.source[Arch]: - Lpkg.cmd.rm(f) pass - - Lpkg.cmd.rm(".lpkg") - pass - -def Lpkg.argv.make(): - var fin = file.open(".lpkg","r") - if fin : - Lpkg.error("工作区已经打开分支!") pass - sys.system("mkdir target") - for Arch,Script in Lpkg.ThisPack.target: - #print("CHECK",Arch) - Lpkg.argv.checkout(Arch) - sys.system(Script) - Lpkg.argv.clean() - pass - pass - -def Lpkg.argv.md5sum(): - sys.system("> .keygen") - sys.system("md5sum info >> .keygen") - for arch,obj in Lpkg.ThisPack.source: - for i,f in obj: - if arch == "all": - sys.system("md5sum "&f&" >> .keygen") - else - sys.system("md5sum "&arch&"/"&f&" >> .keygen") pass - pass - pass - pass - -def Lpkg.argv.md5check(): - if sys.system("md5sum -c .keygen") !=0 : - return 1 pass - return 0 pass - -def Lpkg.argv.checkout(Arch): - var CheckOut_files_exsist,CheckOut_files - def CheckOut_files_exsist(f): - var fin = file.open(f,"r") - if fin : Lpkg.error("检测到工作区已经存在文件\t"&f&"\t,请清理后重新进行检出") ; - pass - def CheckOut_files(f): - if Lpkg.cmd.cp(Arch&"/"&f,"./"&f) != 0: Lpkg.error("文件\t"&f&"\t检出失败") ; - pass - - if Arch=="all": - Lpkg.error("all 作为通用分支,不能被单独检出!") pass - if not Lpkg.ThisPack.source[Arch]: - Lpkg.error("正在尝试检出一个不存在的分支:\t"&Arch) pass - - for i,f in Lpkg.ThisPack.source[Arch] : - CheckOut_files_exsist(f) - pass - for i,f in Lpkg.ThisPack.source[Arch] : - CheckOut_files(f) - pass - - var fout = file.open(".lpkg","w") - if not fout : - Lpkg.error("检出失败,请检查 lpkg 权限!") pass - fout.print(Arch) - fout.close() - pass - -def Lpkg.argv.commit(Arch): - var CheckIn_files_exsist,CheckIn_files - def CheckIn_files_exsist(f): - var fin = file.open(f,"r") - if not fin : Lpkg.error("检测到工作区缺少文件\t"&f&"\t,请补齐后重新进行合并") ; - fin.close() - pass - def CheckIn_files(f): - return Lpkg.cmd.cp("./"&f,Arch&"/"&f) - pass - - if Arch =="all": - Lpkg.error("all 作为通用分支,不能被单独合并!") - pass - if not Lpkg.ThisPack.source[Arch]: - Lpkg.error("正在尝试合并一个不存在的分支:\t"&Arch) - pass - - for i,f in Lpkg.ThisPack.source[Arch] : - CheckIn_files_exsist(f) - pass - - Lpkg.cmd.mkdir(Arch) - - for i,f in Lpkg.ThisPack.source[Arch] : - CheckIn_files(f) - pass - - var fout = file.open(".lpkg","w") - if not fout : Lpkg.error("检出失败,请检查 lpkg 权限!") ; - fout.print(Arch) - fout.close() - - pass - - -def main(argc,argv): - if argc() == 1: - Lpkg.init() - if argv(1)=="show": - Lpkg.argv.show() - elif argv(1)=="clean": - Lpkg.argv.clean() - elif argv(1)=="make": - Lpkg.argv.make() - elif argv(1)=="md5sum": - Lpkg.argv.md5sum() - elif argv(1)=="md5check": - exit(Lpkg.argv.md5check()) - else - Lpkg.error("无效的命令行参数") pass - elif argc()==2: - Lpkg.init() - if argv(1)=="checkout": - Lpkg.argv.checkout(argv(2)) - elif argv(1)=="commit": - Lpkg.argv.commit(argv(2)) pass - else - print("LPKG for Losu v2.x -- An Powerful Tool for Losu Packages") - print("洛书模块开发工具 —— V2.0.0") - pass - - pass - -main(argc,argv) -# Lpkg.init() -# Lpkg.argv.checkout("Ubuntu") -# Lpkg.argv.clean() - -#!end diff --git a/lpkg/lpkg.h b/lpkg/lpkg.h deleted file mode 100755 index 58303ed840996e289987822ee5ff787d6aa31c78..0000000000000000000000000000000000000000 --- a/lpkg/lpkg.h +++ /dev/null @@ -1,224 +0,0 @@ -#include "els.h" -#ifdef ELS_CONF_TOKEN_EN -static const char LibScript[]={ -105,109,112,111,114,116,32,34,115,116,100,108,105,98,34,10, -10, -118,97,114,32,76,112,107,103,61,123,10, -32,32,32,32,99,109,100,32,61,32,123,10, -32,32,32,32,32,32,32,32,99,112,32,32,32,32,61,32,100,101,102,40,41,58,59,44,10, -32,32,32,32,32,32,32,32,109,107,100,105,114,32,61,32,100,101,102,40,41,58,59,44,10, -32,32,32,32,32,32,32,32,114,109,32,32,32,32,61,32,100,101,102,40,41,58,59,44,10, -32,32,32,32,125,44,10, -32,32,32,32,101,114,114,111,114,32,61,32,100,101,102,40,41,58,59,44,10, -32,32,32,32,105,110,105,116,32,61,32,100,101,102,40,41,58,59,44,10, -32,32,32,32,97,114,103,118,32,61,32,123,10, -32,32,32,32,32,32,32,32,115,104,111,119,32,32,32,32,32,61,32,100,101,102,40,41,58,59,44,10, -32,32,32,32,32,32,32,32,99,108,101,97,110,32,32,32,32,61,32,100,101,102,40,41,58,59,44,10, -32,32,32,32,32,32,32,32,109,97,107,101,32,32,32,32,32,61,32,100,101,102,40,41,58,59,44,10, -32,32,32,32,32,32,32,32,109,100,53,115,117,109,32,32,32,61,32,100,101,102,40,41,58,59,44,10, -32,32,32,32,32,32,32,32,109,100,53,99,104,101,99,107,32,61,32,100,101,102,40,41,58,59,44,10, -32,32,32,32,32,32,32,32,99,104,101,99,107,111,117,116,32,61,32,100,101,102,40,41,58,59,44,10, -32,32,32,32,32,32,32,32,99,111,109,109,105,116,32,32,32,61,32,100,101,102,40,41,58,59,44,10, -32,32,32,32,125,44,10, -32,32,32,32,84,104,105,115,80,97,99,107,32,61,32,123,125,10, -125,10, -10, -100,101,102,32,76,112,107,103,46,99,109,100,46,99,112,40,115,114,99,44,111,98,106,41,58,10, -32,32,32,32,114,101,116,117,114,110,32,115,121,115,46,115,121,115,116,101,109,40,34,99,112,32,92,34,34,38,115,114,99,38,34,92,34,32,92,34,34,38,111,98,106,38,34,92,34,34,41,32,10, -32,32,32,32,112,97,115,115,10, -10, -100,101,102,32,76,112,107,103,46,99,109,100,46,109,107,100,105,114,40,100,105,114,41,58,10, -32,32,32,32,114,101,116,117,114,110,32,115,121,115,46,115,121,115,116,101,109,40,34,109,107,100,105,114,32,45,112,32,92,34,34,38,100,105,114,38,34,92,34,34,41,10, -32,32,32,32,112,97,115,115,10, -10, -100,101,102,32,76,112,107,103,46,99,109,100,46,114,109,40,102,41,58,10, -32,32,32,32,114,101,116,117,114,110,32,115,121,115,46,115,121,115,116,101,109,40,34,114,109,32,45,102,32,92,34,34,38,102,38,34,92,34,34,41,32,10, -32,32,32,32,112,97,115,115,10, -10, -10, -100,101,102,32,76,112,107,103,46,101,114,114,111,114,40,115,41,58,10, -32,32,32,32,112,114,105,110,116,40,34,91,69,82,82,79,82,47,-23,-108,-103,-24,-81,-81,93,58,76,80,75,71,58,92,116,34,44,115,41,10, -32,32,32,32,101,120,105,116,40,49,41,10, -32,32,32,32,112,97,115,115,10, -10, -100,101,102,32,76,112,107,103,46,105,110,105,116,40,41,58,10, -32,32,32,32,118,97,114,32,102,105,110,32,61,32,102,105,108,101,46,111,112,101,110,40,34,105,110,102,111,34,44,34,114,34,41,10, -32,32,32,32,118,97,114,32,115,32,61,32,34,34,10, -32,32,32,32,105,102,32,110,111,116,32,102,105,110,32,58,10, -32,32,32,32,32,32,32,32,76,112,107,103,46,101,114,114,111,114,40,34,-27,-67,-109,-27,-119,-115,-25,-101,-82,-27,-67,-107,-28,-72,-117,-26,-78,-95,-26,-100,-119,-26,-88,-95,-27,-99,-105,-23,-123,-115,-25,-67,-82,-26,-106,-121,-28,-69,-74,33,34,41,32,112,97,115,115,32,32,32,32,10, -32,32,32,32,119,105,116,104,32,110,111,116,32,102,105,110,46,101,111,102,40,41,58,10, -32,32,32,32,32,32,32,32,115,32,61,32,115,32,38,32,102,105,110,46,108,105,110,101,105,110,112,117,116,40,41,32,38,32,34,92,110,34,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,101,118,97,108,40,34,76,112,107,103,46,84,104,105,115,80,97,99,107,61,34,38,115,41,10, -32,32,32,32,102,105,110,46,99,108,111,115,101,40,41,10, -32,32,32,32,112,97,115,115,10, -10, -10, -100,101,102,32,76,112,107,103,46,97,114,103,118,46,115,104,111,119,40,41,58,10, -32,32,32,32,112,114,105,110,116,40,34,-27,-67,-109,-27,-119,-115,-26,-88,-95,-27,-99,-105,-28,-65,-95,-26,-127,-81,58,34,41,10, -32,32,32,32,112,114,105,110,116,40,34,-27,-116,-123,-27,-112,-115,58,92,116,34,38,76,112,107,103,46,84,104,105,115,80,97,99,107,46,105,110,102,111,46,110,97,109,101,41,10, -32,32,32,32,112,114,105,110,116,40,34,-28,-69,-117,-25,-69,-115,58,92,116,34,38,76,112,107,103,46,84,104,105,115,80,97,99,107,46,105,110,102,111,46,116,101,120,116,41,10, -32,32,32,32,112,114,105,110,116,40,34,-25,-119,-120,-26,-100,-84,58,92,116,34,38,76,112,107,103,46,84,104,105,115,80,97,99,107,46,105,110,102,111,46,118,101,114,115,105,111,110,41,10, -32,32,32,32,112,114,105,110,116,40,34,-26,-108,-81,-26,-116,-127,-25,-102,-124,-27,-120,-122,-26,-108,-81,58,34,41,10, -32,32,32,32,112,114,105,110,116,40,34,92,116,97,108,108,58,34,41,10, -32,32,32,32,102,111,114,32,105,44,102,32,105,110,32,76,112,107,103,46,84,104,105,115,80,97,99,107,46,115,111,117,114,99,101,46,97,108,108,58,10, -32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,92,116,92,116,34,44,102,41,32,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,102,111,114,32,110,44,98,32,105,110,32,76,112,107,103,46,84,104,105,115,80,97,99,107,46,115,111,117,114,99,101,32,58,10, -32,32,32,32,32,32,32,32,105,102,32,110,32,33,61,32,34,97,108,108,34,58,32,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,92,116,34,44,110,44,39,58,39,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,102,111,114,32,105,44,102,32,105,110,32,98,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,92,116,92,116,34,44,102,41,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,112,97,115,115,10, -10, -100,101,102,32,76,112,107,103,46,97,114,103,118,46,99,108,101,97,110,40,41,58,10, -32,32,32,32,118,97,114,32,102,105,110,32,61,32,102,105,108,101,46,111,112,101,110,40,34,46,108,112,107,103,34,44,34,114,34,41,10, -32,32,32,32,105,102,32,110,111,116,32,102,105,110,58,32,10, -32,32,32,32,32,32,32,32,76,112,107,103,46,101,114,114,111,114,40,34,-27,-73,-91,-28,-67,-100,-27,-116,-70,-27,-80,-102,-26,-100,-86,-26,-119,-109,-27,-68,-128,-27,-120,-122,-26,-108,-81,33,34,41,32,112,97,115,115,10, -32,32,32,32,118,97,114,32,65,114,99,104,32,61,32,102,105,110,46,105,110,112,117,116,40,41,10, -32,32,32,32,102,105,110,46,99,108,111,115,101,40,41,10, -32,32,32,32,35,32,-26,-72,-123,-25,-87,-70,-27,-73,-91,-28,-67,-100,-27,-116,-70,10, -32,32,32,32,102,111,114,32,105,44,102,32,105,110,32,76,112,107,103,46,84,104,105,115,80,97,99,107,46,115,111,117,114,99,101,91,65,114,99,104,93,58,10, -32,32,32,32,32,32,32,32,76,112,107,103,46,99,109,100,46,114,109,40,102,41,32,112,97,115,115,10, -10, -32,32,32,32,76,112,107,103,46,99,109,100,46,114,109,40,34,46,108,112,107,103,34,41,10, -32,32,32,32,112,97,115,115,10, -10, -100,101,102,32,76,112,107,103,46,97,114,103,118,46,109,97,107,101,40,41,58,10, -32,32,32,32,118,97,114,32,102,105,110,32,61,32,102,105,108,101,46,111,112,101,110,40,34,46,108,112,107,103,34,44,34,114,34,41,10, -32,32,32,32,105,102,32,102,105,110,32,58,32,10, -32,32,32,32,32,32,32,32,76,112,107,103,46,101,114,114,111,114,40,34,-27,-73,-91,-28,-67,-100,-27,-116,-70,-27,-73,-78,-25,-69,-113,-26,-119,-109,-27,-68,-128,-27,-120,-122,-26,-108,-81,33,34,41,32,112,97,115,115,32,10, -32,32,32,32,115,121,115,46,115,121,115,116,101,109,40,34,109,107,100,105,114,32,116,97,114,103,101,116,34,41,10, -32,32,32,32,102,111,114,32,65,114,99,104,44,83,99,114,105,112,116,32,105,110,32,76,112,107,103,46,84,104,105,115,80,97,99,107,46,116,97,114,103,101,116,58,10, -32,32,32,32,32,32,32,32,35,112,114,105,110,116,40,34,67,72,69,67,75,34,44,65,114,99,104,41,10, -32,32,32,32,32,32,32,32,76,112,107,103,46,97,114,103,118,46,99,104,101,99,107,111,117,116,40,65,114,99,104,41,10, -32,32,32,32,32,32,32,32,115,121,115,46,115,121,115,116,101,109,40,83,99,114,105,112,116,41,10, -32,32,32,32,32,32,32,32,76,112,107,103,46,97,114,103,118,46,99,108,101,97,110,40,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,112,97,115,115,10, -10, -100,101,102,32,76,112,107,103,46,97,114,103,118,46,109,100,53,115,117,109,40,41,58,10, -32,32,32,32,115,121,115,46,115,121,115,116,101,109,40,34,62,32,46,107,101,121,103,101,110,34,41,10, -32,32,32,32,115,121,115,46,115,121,115,116,101,109,40,34,109,100,53,115,117,109,32,105,110,102,111,32,62,62,32,46,107,101,121,103,101,110,34,41,10, -32,32,32,32,102,111,114,32,97,114,99,104,44,111,98,106,32,105,110,32,76,112,107,103,46,84,104,105,115,80,97,99,107,46,115,111,117,114,99,101,58,10, -32,32,32,32,32,32,32,32,102,111,114,32,105,44,102,32,105,110,32,111,98,106,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,97,114,99,104,32,61,61,32,34,97,108,108,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,115,121,115,46,115,121,115,116,101,109,40,34,109,100,53,115,117,109,32,34,38,102,38,34,32,62,62,32,46,107,101,121,103,101,110,34,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,115,121,115,46,115,121,115,116,101,109,40,34,109,100,53,115,117,109,32,34,38,97,114,99,104,38,34,47,34,38,102,38,34,32,62,62,32,46,107,101,121,103,101,110,34,41,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,112,97,115,115,10, -10, -100,101,102,32,76,112,107,103,46,97,114,103,118,46,109,100,53,99,104,101,99,107,40,41,58,10, -32,32,32,32,105,102,32,115,121,115,46,115,121,115,116,101,109,40,34,109,100,53,115,117,109,32,45,99,32,46,107,101,121,103,101,110,34,41,32,33,61,48,32,58,32,10, -32,32,32,32,32,32,32,32,114,101,116,117,114,110,32,49,32,112,97,115,115,10, -32,32,32,32,114,101,116,117,114,110,32,48,32,112,97,115,115,10, -10, -100,101,102,32,76,112,107,103,46,97,114,103,118,46,99,104,101,99,107,111,117,116,40,65,114,99,104,41,58,10, -32,32,32,32,118,97,114,32,67,104,101,99,107,79,117,116,95,102,105,108,101,115,95,101,120,115,105,115,116,44,67,104,101,99,107,79,117,116,95,102,105,108,101,115,10, -32,32,32,32,100,101,102,32,67,104,101,99,107,79,117,116,95,102,105,108,101,115,95,101,120,115,105,115,116,40,102,41,58,10, -32,32,32,32,32,32,32,32,118,97,114,32,102,105,110,32,61,32,102,105,108,101,46,111,112,101,110,40,102,44,34,114,34,41,10, -32,32,32,32,32,32,32,32,105,102,32,102,105,110,32,58,32,32,32,32,76,112,107,103,46,101,114,114,111,114,40,34,-26,-93,-128,-26,-75,-117,-27,-120,-80,-27,-73,-91,-28,-67,-100,-27,-116,-70,-27,-73,-78,-25,-69,-113,-27,-83,-104,-27,-100,-88,-26,-106,-121,-28,-69,-74,92,116,34,38,102,38,34,92,116,44,-24,-81,-73,-26,-72,-123,-25,-112,-122,-27,-112,-114,-23,-121,-115,-26,-106,-80,-24,-65,-101,-24,-95,-116,-26,-93,-128,-27,-121,-70,34,41,32,59,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,100,101,102,32,67,104,101,99,107,79,117,116,95,102,105,108,101,115,40,102,41,58,10, -32,32,32,32,32,32,32,32,105,102,32,76,112,107,103,46,99,109,100,46,99,112,40,65,114,99,104,38,34,47,34,38,102,44,34,46,47,34,38,102,41,32,33,61,32,48,58,32,32,32,76,112,107,103,46,101,114,114,111,114,40,34,-26,-106,-121,-28,-69,-74,92,116,34,38,102,38,34,92,116,-26,-93,-128,-27,-121,-70,-27,-92,-79,-24,-76,-91,34,41,32,59,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -10, -32,32,32,32,105,102,32,65,114,99,104,61,61,34,97,108,108,34,58,32,10, -32,32,32,32,32,32,32,32,76,112,107,103,46,101,114,114,111,114,40,34,97,108,108,32,-28,-67,-100,-28,-72,-70,-23,-128,-102,-25,-108,-88,-27,-120,-122,-26,-108,-81,44,-28,-72,-115,-24,-125,-67,-24,-94,-85,-27,-115,-107,-25,-117,-84,-26,-93,-128,-27,-121,-70,33,34,41,32,112,97,115,115,10, -32,32,32,32,105,102,32,110,111,116,32,76,112,107,103,46,84,104,105,115,80,97,99,107,46,115,111,117,114,99,101,91,65,114,99,104,93,58,32,10, -32,32,32,32,32,32,32,32,76,112,107,103,46,101,114,114,111,114,40,34,-26,-83,-93,-27,-100,-88,-27,-80,-99,-24,-81,-107,-26,-93,-128,-27,-121,-70,-28,-72,-128,-28,-72,-86,-28,-72,-115,-27,-83,-104,-27,-100,-88,-25,-102,-124,-27,-120,-122,-26,-108,-81,58,92,116,34,38,65,114,99,104,41,32,112,97,115,115,10, -10, -32,32,32,32,102,111,114,32,105,44,102,32,105,110,32,76,112,107,103,46,84,104,105,115,80,97,99,107,46,115,111,117,114,99,101,91,65,114,99,104,93,32,58,10, -32,32,32,32,32,32,32,32,67,104,101,99,107,79,117,116,95,102,105,108,101,115,95,101,120,115,105,115,116,40,102,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,102,111,114,32,105,44,102,32,105,110,32,76,112,107,103,46,84,104,105,115,80,97,99,107,46,115,111,117,114,99,101,91,65,114,99,104,93,32,58,10, -32,32,32,32,32,32,32,32,67,104,101,99,107,79,117,116,95,102,105,108,101,115,40,102,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,10, -32,32,32,32,118,97,114,32,102,111,117,116,32,61,32,102,105,108,101,46,111,112,101,110,40,34,46,108,112,107,103,34,44,34,119,34,41,10, -32,32,32,32,105,102,32,110,111,116,32,102,111,117,116,32,58,32,10, -32,32,32,32,32,32,32,32,76,112,107,103,46,101,114,114,111,114,40,34,-26,-93,-128,-27,-121,-70,-27,-92,-79,-24,-76,-91,44,-24,-81,-73,-26,-93,-128,-26,-97,-91,32,108,112,107,103,32,-26,-99,-125,-23,-103,-112,33,34,41,32,112,97,115,115,10, -32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,65,114,99,104,41,10, -32,32,32,32,102,111,117,116,46,99,108,111,115,101,40,41,10, -32,32,32,32,112,97,115,115,10, -10, -100,101,102,32,76,112,107,103,46,97,114,103,118,46,99,111,109,109,105,116,40,65,114,99,104,41,58,10, -32,32,32,32,118,97,114,32,67,104,101,99,107,73,110,95,102,105,108,101,115,95,101,120,115,105,115,116,44,67,104,101,99,107,73,110,95,102,105,108,101,115,10, -32,32,32,32,100,101,102,32,67,104,101,99,107,73,110,95,102,105,108,101,115,95,101,120,115,105,115,116,40,102,41,58,10, -32,32,32,32,32,32,32,32,118,97,114,32,102,105,110,32,61,32,102,105,108,101,46,111,112,101,110,40,102,44,34,114,34,41,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,102,105,110,32,58,32,76,112,107,103,46,101,114,114,111,114,40,34,-26,-93,-128,-26,-75,-117,-27,-120,-80,-27,-73,-91,-28,-67,-100,-27,-116,-70,-25,-68,-70,-27,-80,-111,-26,-106,-121,-28,-69,-74,92,116,34,38,102,38,34,92,116,44,-24,-81,-73,-24,-95,-91,-23,-67,-112,-27,-112,-114,-23,-121,-115,-26,-106,-80,-24,-65,-101,-24,-95,-116,-27,-112,-120,-27,-71,-74,34,41,32,59,10, -32,32,32,32,32,32,32,32,102,105,110,46,99,108,111,115,101,40,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,100,101,102,32,67,104,101,99,107,73,110,95,102,105,108,101,115,40,102,41,58,10, -32,32,32,32,32,32,32,32,114,101,116,117,114,110,32,76,112,107,103,46,99,109,100,46,99,112,40,34,46,47,34,38,102,44,65,114,99,104,38,34,47,34,38,102,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -10, -32,32,32,32,105,102,32,65,114,99,104,32,61,61,34,97,108,108,34,58,32,10, -32,32,32,32,32,32,32,32,76,112,107,103,46,101,114,114,111,114,40,34,97,108,108,32,-28,-67,-100,-28,-72,-70,-23,-128,-102,-25,-108,-88,-27,-120,-122,-26,-108,-81,44,-28,-72,-115,-24,-125,-67,-24,-94,-85,-27,-115,-107,-25,-117,-84,-27,-112,-120,-27,-71,-74,33,34,41,32,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,105,102,32,110,111,116,32,76,112,107,103,46,84,104,105,115,80,97,99,107,46,115,111,117,114,99,101,91,65,114,99,104,93,58,32,10, -32,32,32,32,32,32,32,32,76,112,107,103,46,101,114,114,111,114,40,34,-26,-83,-93,-27,-100,-88,-27,-80,-99,-24,-81,-107,-27,-112,-120,-27,-71,-74,-28,-72,-128,-28,-72,-86,-28,-72,-115,-27,-83,-104,-27,-100,-88,-25,-102,-124,-27,-120,-122,-26,-108,-81,58,92,116,34,38,65,114,99,104,41,32,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,10, -32,32,32,32,102,111,114,32,105,44,102,32,105,110,32,76,112,107,103,46,84,104,105,115,80,97,99,107,46,115,111,117,114,99,101,91,65,114,99,104,93,32,58,10, -32,32,32,32,32,32,32,32,67,104,101,99,107,73,110,95,102,105,108,101,115,95,101,120,115,105,115,116,40,102,41,32,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -10, -32,32,32,32,76,112,107,103,46,99,109,100,46,109,107,100,105,114,40,65,114,99,104,41,10, -10, -32,32,32,32,102,111,114,32,105,44,102,32,105,110,32,76,112,107,103,46,84,104,105,115,80,97,99,107,46,115,111,117,114,99,101,91,65,114,99,104,93,32,58,10, -32,32,32,32,32,32,32,32,67,104,101,99,107,73,110,95,102,105,108,101,115,40,102,41,32,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,10, -32,32,32,32,118,97,114,32,102,111,117,116,32,61,32,102,105,108,101,46,111,112,101,110,40,34,46,108,112,107,103,34,44,34,119,34,41,10, -32,32,32,32,105,102,32,110,111,116,32,102,111,117,116,32,58,32,76,112,107,103,46,101,114,114,111,114,40,34,-26,-93,-128,-27,-121,-70,-27,-92,-79,-24,-76,-91,44,-24,-81,-73,-26,-93,-128,-26,-97,-91,32,108,112,107,103,32,-26,-99,-125,-23,-103,-112,33,34,41,32,59,10, -32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,65,114,99,104,41,10, -32,32,32,32,102,111,117,116,46,99,108,111,115,101,40,41,10, -32,32,32,32,10, -32,32,32,32,112,97,115,115,10, -10, -10, -100,101,102,32,109,97,105,110,40,97,114,103,99,44,97,114,103,118,41,58,10, -32,32,32,32,105,102,32,97,114,103,99,40,41,32,61,61,32,49,58,10, -32,32,32,32,32,32,32,32,76,112,107,103,46,105,110,105,116,40,41,10, -32,32,32,32,32,32,32,32,105,102,32,97,114,103,118,40,49,41,61,61,34,115,104,111,119,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,76,112,107,103,46,97,114,103,118,46,115,104,111,119,40,41,10, -32,32,32,32,32,32,32,32,101,108,105,102,32,97,114,103,118,40,49,41,61,61,34,99,108,101,97,110,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,76,112,107,103,46,97,114,103,118,46,99,108,101,97,110,40,41,10, -32,32,32,32,32,32,32,32,101,108,105,102,32,97,114,103,118,40,49,41,61,61,34,109,97,107,101,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,76,112,107,103,46,97,114,103,118,46,109,97,107,101,40,41,10, -32,32,32,32,32,32,32,32,101,108,105,102,32,97,114,103,118,40,49,41,61,61,34,109,100,53,115,117,109,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,76,112,107,103,46,97,114,103,118,46,109,100,53,115,117,109,40,41,10, -32,32,32,32,32,32,32,32,101,108,105,102,32,97,114,103,118,40,49,41,61,61,34,109,100,53,99,104,101,99,107,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,101,120,105,116,40,76,112,107,103,46,97,114,103,118,46,109,100,53,99,104,101,99,107,40,41,41,10, -32,32,32,32,32,32,32,32,101,108,115,101,10, -32,32,32,32,32,32,32,32,32,32,32,32,76,112,107,103,46,101,114,114,111,114,40,34,-26,-105,-96,-26,-107,-120,-25,-102,-124,-27,-111,-67,-28,-69,-92,-24,-95,-116,-27,-113,-126,-26,-107,-80,34,41,32,112,97,115,115,32,10, -32,32,32,32,101,108,105,102,32,97,114,103,99,40,41,61,61,50,58,10, -32,32,32,32,32,32,32,32,76,112,107,103,46,105,110,105,116,40,41,10, -32,32,32,32,32,32,32,32,105,102,32,97,114,103,118,40,49,41,61,61,34,99,104,101,99,107,111,117,116,34,58,32,10, -32,32,32,32,32,32,32,32,32,32,32,32,76,112,107,103,46,97,114,103,118,46,99,104,101,99,107,111,117,116,40,97,114,103,118,40,50,41,41,10, -32,32,32,32,32,32,32,32,101,108,105,102,32,97,114,103,118,40,49,41,61,61,34,99,111,109,109,105,116,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,76,112,107,103,46,97,114,103,118,46,99,111,109,109,105,116,40,97,114,103,118,40,50,41,41,32,112,97,115,115,10, -32,32,32,32,101,108,115,101,32,10, -32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,76,80,75,71,32,102,111,114,32,76,111,115,117,32,118,50,46,120,32,45,45,32,65,110,32,80,111,119,101,114,102,117,108,32,84,111,111,108,32,102,111,114,32,76,111,115,117,32,80,97,99,107,97,103,101,115,34,41,10, -32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,-26,-76,-101,-28,-71,-90,-26,-88,-95,-27,-99,-105,-27,-68,-128,-27,-113,-111,-27,-73,-91,-27,-123,-73,32,-30,-128,-108,-30,-128,-108,32,86,50,46,48,46,48,34,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,10, -32,32,32,32,112,97,115,115,10, -10, -109,97,105,110,40,97,114,103,99,44,97,114,103,118,41,10, -35,32,76,112,107,103,46,105,110,105,116,40,41,10, -35,32,76,112,107,103,46,97,114,103,118,46,99,104,101,99,107,111,117,116,40,34,85,98,117,110,116,117,34,41,10, -35,32,76,112,107,103,46,97,114,103,118,46,99,108,101,97,110,40,41,10, -10, -0}; -#endif -void ElsLib_lpkg_libinit(els_VmObj *vm){ - #ifdef ELS_CONF_TOKEN_EN - vm_dostring(vm,LibScript); - #endif -}; diff --git a/lpkg/readme.md b/lpkg/readme.md deleted file mode 100755 index f983d9f78ae40939274c5213e6200284e023a533..0000000000000000000000000000000000000000 --- a/lpkg/readme.md +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/owls.wiki.losu.tech -# lpkg 模块开发者工具 Wiki -## 简介 -Losu Package,是一款运行在 Linux 环境下的,适合开发者的模块管理工具,支持提交、检出、校验与自动化构建等多种功能。 -## 可用功能 -+ 运行方法 -``` -losu -r lpkg [参数列表] -``` -```sh -lpkg show # 显示模块的详细信息 - -lpkg checkout [分支] # 检出指定分支的源代码到工作区 -lpkg commit [分支] # 提交工作区代码到指定分支 -lpkg clean # 清理工作区 - -lpkg md5sum # 计算 md5 文件 -lpkg md5check # 校验 md5 ,判断文件是否被更改 - -lpkg make # 构建模块二进制 -``` -## 使用方法 -+ [视频教程]() diff --git a/lpt/Ubuntu/lpt.c b/lpt/Ubuntu/lpt.c deleted file mode 100755 index 0ddf6cd291526df6895c2957e089f5481a1a6b73..0000000000000000000000000000000000000000 --- a/lpt/Ubuntu/lpt.c +++ /dev/null @@ -1,42 +0,0 @@ -#include "lpt.h" -#include -#include -#include -int ELSAPI_lpt_mkdir(els_VmObj* vm) -{ -// 这里填写API函数的 C 实现 - char tmp[ELS_BUFF_TMP_SIZE]; - sprintf(tmp,"mkdir %s ",arg_getstr(vm,1)); - if(system(tmp)) - arg_returnnull(vm); - else - arg_returnnum(vm,0); - return 1; -} -int ELSAPI_lpt_wget(els_VmObj* vm) -{ -// 这里填写API函数的 C 实现 - char tmp[ELS_BUFF_TMP_SIZE]; - sprintf(tmp,"wget --no-check-certificate -q --show-progress \"%s\" -O \"%s\"",arg_getstr(vm,1),arg_getstr(vm,2)); - if(system(tmp)){ - sprintf(tmp,"rm -f %s",arg_getstr(vm,2)); - system(tmp); - arg_returnnull(vm); - return 0; - }else - arg_returnnum(vm,0); - sprintf(tmp,"chmod 777 %s",arg_getstr(vm,2)); - system(tmp); - return 1; -} -int ELSAPI_lpt_rmfile(els_VmObj* vm) -{ -// 这里填写API函数的 C 实现 - char tmp[ELS_BUFF_TMP_SIZE]; - sprintf(tmp,"rm -rf %s ",arg_getstr(vm,1)); - if(system(tmp)) - arg_returnnull(vm); - else - arg_returnnum(vm,0); - return 1; -} diff --git a/lpt/Ubuntu/makefile b/lpt/Ubuntu/makefile deleted file mode 100755 index 827e4a254002a49b3601831f11d87f1ef7d9014a..0000000000000000000000000000000000000000 --- a/lpt/Ubuntu/makefile +++ /dev/null @@ -1,13 +0,0 @@ -OBJS = lpt.o -CFLAGS= -O2 -Wall -std=c99 -DLOSU_LINUX -I ../buildenv -fPIC -CC=x86_64-linux-gnu-gcc -T=./ElsLib_lpt.lsd - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -shared -s - -clean: - rm -rf $T $(OBJS) core core.* \ No newline at end of file diff --git a/lpt/Windows/lpt.c b/lpt/Windows/lpt.c deleted file mode 100755 index 9ba17d1efe1920955cc96d6afa6afb65dc1a5342..0000000000000000000000000000000000000000 --- a/lpt/Windows/lpt.c +++ /dev/null @@ -1,45 +0,0 @@ -#include "lpt.h" -#include -#include -#include -#include -#include -#include -int ELSAPI_lpt_wget(els_VmObj* vm) // wget(url: str,file: str): bool '''从指定的url下载到文件file,成功返回真,失败返回null''' -{ - DeleteUrlCacheEntry(arg_getstr(vm,1)); - if(URLDownloadToFile(NULL,arg_getstr(vm,1),arg_getstr(vm,2),0,NULL)){ - arg_returnnull(vm); - return 1; - } - arg_returnnum(vm,0); - return 1; -} - -int ELSAPI_lpt_mkdir(els_VmObj* vm) // mkdir(dir: str): bool '''创建一个文件夹''' -{ - char tmp[ELS_BUFF_TMP_SIZE]; - sprintf(tmp,"mkdir %s ",arg_getstr(vm,1)); - char* _t=vm_win_togbk(tmp); - if(system(_t)) - arg_returnnull(vm); - else - arg_returnnum(vm,0); - free(_t); - return 1; -} - -int ELSAPI_lpt_rmfile(els_VmObj* vm) // rmfile(f: str): bool '''删除一个文件''' -{ - char tmp[ELS_BUFF_TMP_SIZE]; - sprintf(tmp,"del %s ",arg_getstr(vm,1)); - char* _t=vm_win_togbk(tmp); - for(int i =0;i\t",Lpt.pkgs.version) - - # 设置更新脚本 - var url,obj - if vm.branch() == "Windows Branch": - url = Lpt.SrcUrl & '.repo/upscript/lsupdate.bat' - obj = Lpt.root&"lsupdate.bat" - else - url = Lpt.SrcUrl & './.repo/upscript/lsupdate_'&Lpt.SrcArch - obj = "/bin/lsupdate" - pass - print("[TRY] 正在尝试下载更新脚本:\t",url) - if this.os.download(url,obj) : - print("[OK]") - else - this.error("更新脚本下载失败,无法修正这一错误,LPT拒绝进一步执行") - pass - this.error("更新脚本已下载,运行 lsupdate 命令可以完成版本修正,或更换软件源后再运行LPT") - pass - - # 加载本地列表 - var flocal = file.open(Lpt.root&"local.list","r") - if flocal: - flocal.close() - if eval(Lpt.root&"local.list","f")!=0: - this.error("本地模块列表出现格式错误,拒绝进一步的执行!") - pass - pass - - # 检测有无阶段更新 - if Lpt.pkgs.upversion : - # 提示 - print("[NOTICE/提示] LPT:\t 检测到可用的阶段性更新", - vm.version(),'\t——>\t',Lpt.pkgs.upversion - ) - - # 设置更新脚本 - var url,obj - if vm.branch() == "Windows Branch": - url = Lpt.SrcUrl & '.repo/upscript/period_lsupdate.bat' - obj = Lpt.root&"lsupdate.bat" - else - url = Lpt.SrcUrl & './.repo/upscript/period_lsupdate_'&Lpt.SrcArch - obj = "/bin/lsupdate" - pass - - print("[TRY] 正在尝试下载更新脚本:\t",url) - if this.os.download(url,obj) : - print("[OK]") - print("[OK/成功] 更新脚本已下载,运行 lsupdate 命令可以完成版本更新") - else - print("[ERROR/错误] 更新脚本下载失败") - pass - - - pass - - pass - -def Lpt.end(): - # 结束函数,更新本地列表 - var flocal = file.open(this.root&"local.list","w") - # 检测是否成功打开 - if not flocal: - this.error("没有足够的权限修改本地列表") - pass - - # 写入列表 - flocal.print("Lpt.pkgs.local={\n") - for pkname,version in Lpt.pkgs.local: - flocal.print("\t"&pkname&'="'&version&'",\n') - pass - flocal.print("}\n") - flocal.close() - pass - - - - -def Lpt.argv.help(): - # 帮助函数 - var s - var fhelp = file.open(Lpt.root&"help",'r') - if not fhelp: - Lpt.error("找不到帮助文档!") - pass - with not fhelp.eof(): - s = fhelp.lineinput() - print((s=="" and "" )or(s)) - pass - - fhelp.close() - pass - -def Lpt.argv.update(): - # 初始化 LPT 的工作环境 - Lpt.init() - var upnum,badnum = 0,0 # 可更新与损坏的数量 - - # 检测更新 - for pkname,version in Lpt.pkgs.local: - if Lpt.pkgs.remote[pkname]: - if version != Lpt.pkgs.remote[pkname].info.version: - upnum = upnum +1 - Lpt.pkgs.upable[pkname]=Lpt.pkgs.remote[pkname].info.version - pass - else - badnum = badnum + 1 - Lpt.pkgs.bad[pkname] = version - pass - pass - - # 显示可以更新的列表 - if upnum != 0: - var f = file.open(Lpt.root&"upable.list",'w') - if not f : Lpt.error("没有足够的权限创建可更新列表") ; - print("共有以下 ",upnum," 个模块可以升级") - f.print("Lpt.pkgs.upable={\n") - for n,v in Lpt.pkgs.upable: - print(n,"\t",Lpt.pkgs.local[n],'\t----更新到---->\t',v) - f.print("\t"&n&' = "",\n') - pass - f.print("}\n") - f.close() - f = null - pass - - - # 显示缺损的模块列表 - if badnum !=0 : - var f = file.open(Lpt.root&"bad.list",'w') - if not f : Lpt.error("没有足够的权限创建缺损列表") ; - print("共有以下 ",badnum," 个模块出现缺损") - f.print("Lpt.pkgs.bad={\n") - for n,v in Lpt.pkgs.bad: - print(n,"\t",Lpt.pkgs.local[n],'\t----缺损---->?.?.?') - f.print("\t"&n&' = "",\n') - pass - f.print("}\n") - f.close() - f = null - print("这些模块已经被安装,但是没有出现软件源中,可能是已经被废弃或更名") - pass - pass - -def Lpt.argv.upgrade(yes): - var e = {} - var enum = 0 - # 初始化工作环境 - Lpt.init() - - # 检测是否存在本地更新列表 - var f = file.open(Lpt.root&"upable.list",'r') - if not f : Lpt.error("没有可参考的更新列表,考虑执行 lpt update命令") ; - f.close() - - if eval(Lpt.root&"upable.list",'f') != 0: - Lpt.error("更新列表存在格式错误,拒绝进一步的执行!") - pass - - print("输入 y 进行更新>") - yes = yes or lineinput() - if yes != "y": - Lpt.error("已取消") - pass - - for pkname,version in Lpt.pkgs.upable: - var url = Lpt.SrcUrl&pkname&"/target/ElsLib_"&pkname&".lsd_"&Lpt.SrcArch - var obj = Lpt.root&"lib/ElsLib_"&pkname&".lsd" - - if Lpt.pkgs.remote[pkname].type and Lpt.pkgs.remote[pkname].type == "const": - print("[WARN/警告]\t",pkname,"\t是一个被锁定的模块,不能由用户进行修改") - e[pkname]="" - enum = enum + 1 - elif Lpt.pkgs.remote[pkname].type and Lpt.pkgs.remote[pkname].type == "pre": - print("[WARN/警告]\t",pkname,"\t是一个前瞻的版本,不能自动进行安装") - e[pkname]="" - enum = enum + 1 - else - print("[TRY/尝试]\t"&url) - if Lpt.os.download(url,obj): - print("[OK]") - Lpt.pkgs.local[pkname]=Lpt.pkgs.remote[pkname].info.version - else - e[pkname] = "" - enum = enum + 1 - print("[ERROR]") - pass - - pass - - pass - - print("以下 ",enum," 个模块未能成功升级") - for n,v in e: - print(n) - pass - - Lpt.end() - - # 删除更新列表缓存 - Lpt.os.rmfile(Lpt.root&"upable.list") - pass - -def Lpt.argv.list(): - # 初始化 环境 - Lpt.init() - print("正在列举 ...") - for pkname,version in Lpt.pkgs.local: - print(pkname,"/",version) - pass - print("完成") - pass - -def Lpt.argv.install(pkname,yes): - # 初始化LPT环境 - Lpt.init() - - # 查找模块 - if not Lpt.pkgs.remote[pkname]: - Lpt.error("找不到模块\t"&pkname) - pass - print("找到了以下结果") - print("名称:\t",Lpt.pkgs.remote[pkname].info.name) - print("介绍:\t",Lpt.pkgs.remote[pkname].info.text) - print("版本:\t",Lpt.pkgs.remote[pkname].info.version) - - # 检测是否为锁定模块 - if Lpt.pkgs.remote[pkname].type and Lpt.pkgs.remote[pkname].type=="const": - Lpt.error("模块 "&pkname&" 是一个锁定模块,不能由 LPT 进行安装") - pass - print("输入 y 进行安装>") - if Lpt.pkgs.remote[pkname].type and Lpt.pkgs.remote[pkname].type=="pre": - print("[WARN/警告]:\t模块 "&pkname&" 是一个前瞻的版本,请谨慎决定是否安装") - yes = lineinput() - else - yes = yes or lineinput() - pass - - if yes != "y": - Lpt.error("已取消") - pass - - # 开始下载 - var url = Lpt.SrcUrl&pkname&"/target/ElsLib_"&pkname&".lsd_"&Lpt.SrcArch - var obj = Lpt.root&"lib/ElsLib_"&pkname&".lsd" - print("[TRY/尝试]:\t"&url) - if Lpt.os.download(url,obj): - print("[OK]") - else - Lpt.error("[ERROR/错误]\n安装失败") - pass - - # 更新本地列表 - Lpt.pkgs.local[pkname] = Lpt.pkgs.remote[pkname].info.version - Lpt.end() - pass - -def Lpt.argv.remove(pkname,yes): - # 初始化工作环境 - Lpt.init() - - var obj = Lpt.root&'lib/ElsLib_'&pkname&'.lsd' - # 检测模块是否被安装 - if not Lpt.pkgs.local[pkname]: - Lpt.error("模块\t"&pkname&"\t没有被安装,所以不会被卸载") - pass - - # 检测模块是否是锁定模块 - if Lpt.pkgs.remote[pkname] and Lpt.pkgs.remote[pkname].type and Lpt.pkgs.remote[pkname].type=="const": - Lpt.error("模块 "&pkname&" 是一个锁定模块,不能由 LPT 进行卸载") - pass - - print("输入 y 进行卸载>") - yes = yes or lineinput() - if yes != "y": - Lpt.error("已取消") - pass - - # 开始删除 - print("[DEL/删除]\t",obj) - if not Lpt.os.rmfile(obj) : - Lpt.error("未成功删除文件") - pass - print("[OK]") - - # 更新本地列表 - Lpt.pkgs.local[pkname]=null - Lpt.end() - pass - -def Lpt.argv.search(index): - # 初始化环境 - Lpt.init() - - # 开始查找 - for pkname,pkobj in Lpt.pkgs.remote : - # 包含关键词 - if coutnum(pkname,index)>0: - print(pkname,"/",pkobj.info.version) ; - pass - - pass - -def Lpt.argv.wiki(pkname): - # 初始化环境 - Lpt.init() - - # 检测模块是否存在 - if not Lpt.pkgs.remote[pkname]: - Lpt.error("找不到模块 "&pkname) - pass - print("找到了以下结果") - print("名称:\t",Lpt.pkgs.remote[pkname].info.name) - print("介绍:\t",Lpt.pkgs.remote[pkname].info.text) - print("版本:\t",Lpt.pkgs.remote[pkname].info.version) - - var url = Lpt.SrcUrl &pkname &"/readme.md" - var obj = pkname & ".md" - - print("[TRY/尝试]\t",url) - if Lpt.os.download(url,obj): - print("[OK]") - else - print("[ERROR]") - Lpt.error("找不到模块的文档") - pass - pass - -def Lpt.argv.show(pkname): - # 初始化环境 - Lpt.init() - - # 检测模块是否存在 - if not Lpt.pkgs.remote[pkname]: - Lpt.error("找不到模块 "&pkname) - pass - print("模块 ",pkname," 的相信信息如下") - print("名称:\t",Lpt.pkgs.remote[pkname].info.name) - print("介绍:\t",Lpt.pkgs.remote[pkname].info.text) - print("版本:\t",Lpt.pkgs.remote[pkname].info.version) - print("模式:\t",Lpt.pkgs.remote[pkname].type or "normal") - print("二进制分发的分支:") - for Arch,s in Lpt.pkgs.remote[pkname].target : - print("\t",Arch) - pass - - print("源代码及支持的分支:") - for Arch,Files in Lpt.pkgs.remote[pkname].source : - print("\t",Arch,":") - for n,f in Files : - print("\t\t",f) - pass - pass - - pass - -def Lpt.argv.clone(pkname): - var e = null - - - # 初始化环境 - Lpt.init() - - # 判断模块是否存在 - if not Lpt.pkgs.remote[pkname]: - Lpt.error("找不到模块\t"&pkname) - pass - - # 显示模块信息 - print("找到了以下结果") - print("名称:\t",Lpt.pkgs.remote[pkname].info.name) - print("介绍:\t",Lpt.pkgs.remote[pkname].info.text) - print("版本:\t",Lpt.pkgs.remote[pkname].info.version) - - # 开始克隆 - # 创建文件夹 - Lpt.os.mkdir(pkname) - # 下载 info 文件 - print("[TRY]\tinfo") - if Lpt.os.download( Lpt.SrcUrl & pkname & "/info",pkname & "/info"): - print('[OK]') - else - print('[ERROR]') - e = 1 - pass - - # 克隆 all 分支 - for i,f in Lpt.pkgs.remote[pkname].source.all : - var url = Lpt.SrcUrl & pkname & "/" & f - var obj = pkname & '/' & f - - print("[TRY]\t",url) - if Lpt.os.download(url,obj): - print("[OK]") - else - print("[ERROR]") - e = 1 - pass - pass - - # 克隆其他分支 - for arch,obj in Lpt.pkgs.remote[pkname].source: - if arch != "all": - Lpt.os.mkdir(pkname&"/"&arch) - for i,f in Lpt.pkgs.remote[pkname].source[arch]: - var url = Lpt.SrcUrl & pkname & '/' & arch & "/" & f - var obj = pkname & '/' & arch & "/" & f - print("[TRY]\t",url) - if Lpt.os.download(url,obj): - print("[OK]") - else - print("[ERROR]") - e = 1 - pass - pass - pass - pass - - # 结果反馈 - if e : - Lpt.error("有部分文件缺失") - else - print("克隆完成") - pass - - pass - - - -def Lpt.argv.autoremove(yes): - Lpt.init() - var e,enum = 0,{} # 出错的个数与模块 - - # 检测是否存在缺损列表 - var f = file.open(Lpt.root&"bad.list",'r') - if not f : Lpt.error("没有可参考的缺损,考虑执行 lpt update命令") ; - f.close() - f = null - - # 加载列表 - if eval(Lpt.root&"bad.list",'f') != 0: - Lpt.error("缺损列表存在格式错误,拒绝进一步的执行!") - pass - - # 列举模块 - print("以下模块将被自动卸载:") - for n,v in Lpt.pkgs.bad: - printl(n,"\t") - pass - print("") - - # 选择 - print("输入 y 进行卸载>") - yes = yes or lineinput() - if yes != "y": - Lpt.error("已取消") - pass - - # 开始逐个删除 - for pkname,i in Lpt.pkgs.bad: - var obj = Lpt.root&'lib/ElsLib_'&pkname&'.lsd' - print("[DEL/删除]\t",obj) - Lpt.os.rmfile(obj) - Lpt.pkgs.local[pkname]=null # 删去本地记录 - print("[OK]") - pass - - - # 更新本地列表 - Lpt.os.rmfile(Lpt.root&"bad.list") - Lpt.end() - pass - -def Lpt.argv.source(pkname,arch): - var e = null - - # 初始化工作环境 - Lpt.init() - arch = arch or Lpt.SrcArch - - # 判断模块是否存在 - if not Lpt.pkgs.remote[pkname]: - Lpt.error("找不到模块\t"&pkname) - pass - - # 显示模块信息 - print("找到了以下结果") - print("名称:\t",Lpt.pkgs.remote[pkname].info.name) - print("介绍:\t",Lpt.pkgs.remote[pkname].info.text) - print("版本:\t",Lpt.pkgs.remote[pkname].info.version) - - # 如果是一个不存在的分支 - if not Lpt.pkgs.remote[pkname].source[arch] : - print("[WARN/警告]\t",arch," 不是一个受支持的分支,将只下载通用代码") - pass - - # 开始下载 - Lpt.os.mkdir(pkname) - if arch != "all": - for i,f in Lpt.pkgs.remote[pkname].source[arch] or {}: - var url = Lpt.SrcUrl & pkname & '/' & arch & "/" & f - var obj = pkname & '/' & f - - print("[TRY]\t",url) - if Lpt.os.download(url,obj): - print("[OK]") - else - print("[ERROR]") - e = 1 - pass - pass - pass - - for i,f in Lpt.pkgs.remote[pkname].source.all : - var url = Lpt.SrcUrl & pkname & "/" & f - var obj = pkname & '/' & f - - print("[TRY]\t",url) - if Lpt.os.download(url,obj): - print("[OK]") - else - print("[ERROR]") - e = 1 - pass - pass - - # 结果反馈 - if e : - Lpt.error("有部分文件缺失") - else - print("下载完成") - pass - - pass - - - - -def Lpt.conf.src(fn,pack): - print('config file '&fn&'......\t') - var Libs={} - var Spt = 0 - var Cspt = 0 - var fin = file.open(fn&'.els','r') - if not fin : - Lpt.error("找不到要配置的文件") - pass - var fout = file.open(fn & '.h','w') - if not fout : - Lpt.error("输出文件 " & fn & '.h' & " 打开失败") - pass - var s,tmp = "","" - var fout_print - def fout_print(a): - for i = 1, length(a): - fout.print(asc(a[i])&",") - pass - pass - - fout.print('#include "els.h"\n') - with !fin.eof(): - s = fin.lineinput() - if replace(s," ","") == "#!script" : - Spt = 1 - fout.print("#ifdef ELS_CONF_TOKEN_EN\n") - fout.print('static const char LibScript[]={\n') - with not fin.eof() : - tmp = fin.lineinput() - if replace(tmp," ","") == "#!end" : - break - pass - fout_print(tmp&'\n') - fout.print('\n') - pass - fout.print("0};\n") - fout.print("#endif\n") - pass - if replace(s," ","") == "#!script-cn" : - Cspt = 1 - fout.print("#ifdef ELS_CONF_TOKEN_CN\n") - fout.print('static const char LibScript_cn[]={\n') - with not fin.eof() : - tmp = fin.lineinput() - if replace(tmp," ","") == "#!end" : - break - pass - fout_print(tmp&'\n') - fout.print('\n') - pass - fout.print("0};\n") - fout.print("#endif\n") - pass - if replace(s," ","") == "#!declare" : - with not fin.eof(): - tmp = fin.lineinput() - if replace(tmp," ","") == "#!end" : - break - pass - for i = 1,length(tmp) : - if mid(tmp,i,1) == "#" : - fout.print("// "&tmp&'\n') - pass - if mid(tmp,i,1) == "(" : - fout.print("int ELSAPI_"&pack&"_") - fout.print(replace(mid(tmp,1,i-1)," ","")) - fout.print("(els_VmObj* vm); ") - fout.print("// "&tmp&'\n') - Libs[replace(mid(tmp,1,i-1)," ","")]= "ELSAPI_"&pack&"_"&replace(mid(tmp,1,i-1)," ","") - break - pass - pass - pass - pass - pass - - fout.print("void ElsLib_"&pack&"_libinit(els_VmObj *vm){\n") - for name,func in Libs : - fout.print("\tvm_register(vm,"&'"'&name&'",'&func&");\n") - pass - if Spt == 1 : - fout.print("\t#ifdef ELS_CONF_TOKEN_EN\n") - fout.print("\t\tvm_dostring(vm,LibScript);\n") - fout.print("\t#endif\n") - pass - if Cspt == 1 : - fout.print("\t#ifdef ELS_CONF_TOKEN_CN\n") - fout.print("\t\tvm_dostring(vm,LibScript_cn);\n") - fout.print("\t#endif\n") - pass - fout.print("};\n") - fin.close() - fout.close() - - # var fout = file.open(fn & '.c','r') - # if not fout : - # fout = file.open(fn & '.c','w') if !fout : throw("输出文件 " & fn & '.c' & " 打开失败") ; - # fout.print('#include "'&pack&'.h"\n') - # for name,func in Libs : - # fout.print("int "&func&"(els_VmObj* vm)\n{\n// 这里填写API函数的 C 实现\n}\n") - # pass - # fout.close() - # pass - - print('done') - pass - -def Lpt.conf.pro(fn): - if eval(fn,1)!=0: - Lpt.error("错误的工程模板") - pass - - var fout = file.open("els_libload.h","w") - if not fout : - Lpt.error("文件打开失败") - pass - - fout.print('#include "els.h"\n') - - for name,obj in project: - fout.print("extern void ElsLib_"&name&"_libinit(els_VmObj *vm);\n") - pass - - fout.print('struct{\nchar *name;\nvoid (*func)(els_VmObj *vm);\n}const els_libload_alllib[]={\n') - - for name,obj in project: - print("config "&name&'......\t') - fout.print('{"' &name& '",ElsLib_' & name & '_libinit},\n') - Lpt.conf.src(obj,name) - print('done') - pass - fout.print('};\n') - fout.close() - pass - - -def Lpt.os.download(url,obj): - return wget(url,obj) - pass - -def Lpt.os.mkdir(dir): - return mkdir(dir) - pass - -def Lpt.os.rmfile(fn): - return rmfile(fn) - pass - - -# 主函数 -def main(argc,argv): - if argc()==1: - if argv(1)=="update": - Lpt.argv.update() - elif argv(1)=="upgrade": - Lpt.argv.upgrade() - elif argv(1)=="autoremove": - Lpt.argv.autoremove() - elif argv(1)=="list": - Lpt.argv.list() - elif argv(1)=="help": - Lpt.argv.help() - pass - elif argc()==2: - if argv(1)=="upgrade": - Lpt.argv.upgrade(argv(2)) - elif argv(1)=="autoremove": - Lpt.argv.autoremove(argv(2)) - - elif argv(1)=="install": - Lpt.argv.install(argv(2)) - elif argv(1)=="remove": - Lpt.argv.remove(argv(2)) - - elif argv(1)=="search": - Lpt.argv.search(argv(2)) - elif argv(1)=="wiki": - Lpt.argv.wiki(argv(2)) - elif argv(1)=="show": - Lpt.argv.show(argv(2)) - elif argv(1)=="source": - Lpt.argv.source(argv(2)) - elif argv(1)=="clone": - Lpt.argv.clone(argv(2)) - elif argv(1)=="confsrc": - var Packname = "" - var _argv = replace(argv(2),"\\","/") - tmp = strtok(_argv,"/") - with 1: - Packname = tmp - tmp = strtok(null,"/") - if tmp == "": break ; - ; - Lpt.conf.src(argv(2),Packname) - elif argv(1)=="confpro": - Lpt.conf.pro(argv(2)) - pass - elif argc()==3: - if argv(1)=="install": - Lpt.argv.install(argv(2),argv(3)) - elif argv(1)=="remove": - Lpt.argv.remove(argv(2),argv(3)) - elif argv(1)=="source": - Lpt.argv.source(argv(2),argv(3)) - pass - else - print("Lpt -- Losu Packages Tool , 输入 help 参数查看使用帮助") - pass - pass - -main(argc,argv) - - -#!end diff --git a/lpt/lpt.h b/lpt/lpt.h deleted file mode 100755 index 9992e316876b4416837646b24d78348a339c31ac..0000000000000000000000000000000000000000 --- a/lpt/lpt.h +++ /dev/null @@ -1,844 +0,0 @@ -#include "els.h" -int ELSAPI_lpt_wget(els_VmObj* vm); // wget(url: str,file: str): bool '''从指定的url下载到文件file,成功返回真,失败返回null''' -int ELSAPI_lpt_mkdir(els_VmObj* vm); // mkdir(dir: str): bool '''创建一个文件夹''' -int ELSAPI_lpt_rmfile(els_VmObj* vm); // rmfile(f: str): bool '''删除一个文件''' -#ifdef ELS_CONF_TOKEN_EN -static const char LibScript[]={ -76,112,116,32,61,32,123,32,32,32,32,32,32,32,32,32,35,32,76,80,84,32,-26,-98,-74,-26,-98,-124,-28,-72,-128,-24,-89,-120,-27,-81,-71,-24,-79,-95,32,10, -32,32,32,32,101,114,114,111,114,32,61,32,100,101,102,40,41,58,59,32,44,32,32,32,35,32,-23,-108,-103,-24,-81,-81,-27,-92,-124,-25,-112,-122,-27,-121,-67,-26,-107,-80,10, -32,32,32,32,112,107,103,115,32,32,61,32,123,32,32,32,32,32,32,32,32,32,32,32,35,32,-26,-88,-95,-27,-99,-105,-27,-120,-105,-24,-95,-88,10, -32,32,32,32,32,32,32,32,114,101,109,111,116,101,32,32,32,61,32,123,125,44,32,32,32,32,32,32,32,32,35,32,-24,-65,-100,-25,-88,-117,-26,-88,-95,-27,-99,-105,-27,-120,-105,-24,-95,-88,10, -32,32,32,32,32,32,32,32,108,111,99,97,108,32,32,32,32,61,32,123,125,44,32,32,32,32,32,32,32,32,35,32,-26,-100,-84,-27,-100,-80,-26,-88,-95,-27,-99,-105,-27,-120,-105,-24,-95,-88,10, -32,32,32,32,32,32,32,32,117,112,97,98,108,101,32,32,32,61,32,123,125,44,32,32,32,32,32,32,32,32,35,32,-27,-113,-81,-27,-115,-121,-25,-70,-89,-25,-102,-124,-26,-88,-95,-27,-99,-105,-27,-120,-105,-24,-95,-88,10, -32,32,32,32,32,32,32,32,98,97,100,32,32,32,32,32,32,61,32,123,125,44,32,32,32,32,32,32,32,32,35,32,-26,-115,-97,-27,-99,-113,-29,-128,-127,-25,-68,-70,-27,-92,-79,-25,-102,-124,-26,-88,-95,-27,-99,-105,-27,-120,-105,-24,-95,-88,10, -32,32,32,32,32,32,32,32,118,101,114,115,105,111,110,32,32,61,32,34,34,44,32,32,32,32,32,32,32,32,35,32,-25,-119,-120,-26,-100,-84,-27,-113,-73,10, -32,32,32,32,32,32,32,32,117,112,115,116,114,101,97,109,32,61,32,123,125,44,32,32,32,32,32,32,32,32,35,32,-27,-115,-121,-25,-70,-89,-26,-114,-88,-23,-128,-127,-26,-72,-96,-23,-127,-109,10, -32,32,32,32,125,44,10, -32,32,32,32,97,114,103,118,32,61,32,123,32,32,32,32,32,32,32,32,32,32,32,32,35,32,-27,-111,-67,-28,-69,-92,-24,-95,-116,-27,-121,-67,-26,-107,-80,10, -32,32,32,32,32,32,32,32,117,112,100,97,116,101,32,32,61,32,100,101,102,40,41,58,59,32,44,32,32,35,32,-24,-114,-73,-27,-113,-106,-24,-65,-100,-25,-88,-117,-24,-67,-81,-28,-69,-74,-27,-120,-105,-24,-95,-88,-17,-68,-116,-26,-93,-128,-26,-97,-91,-26,-101,-76,-26,-106,-80,10, -32,32,32,32,32,32,32,32,117,112,103,114,97,100,101,32,61,32,100,101,102,40,41,58,59,32,44,32,32,35,32,-26,-101,-76,-26,-106,-80,-26,-119,-128,-26,-100,-119,-27,-113,-81,-26,-101,-76,-26,-106,-80,-25,-102,-124,-26,-88,-95,-27,-99,-105,10, -32,32,32,32,32,32,32,32,104,101,108,112,32,32,32,32,61,32,100,101,102,40,41,58,59,32,44,32,32,35,32,-26,-104,-66,-25,-92,-70,-27,-72,-82,-27,-118,-87,-28,-65,-95,-26,-127,-81,10, -32,32,32,32,32,32,32,32,108,105,115,116,32,32,32,32,61,32,100,101,102,40,41,58,59,32,44,32,32,35,32,-27,-120,-105,-28,-72,-66,-26,-100,-84,-27,-100,-80,-27,-120,-105,-24,-95,-88,10, -10, -32,32,32,32,32,32,32,32,105,110,115,116,97,108,108,32,61,32,100,101,102,40,41,58,59,32,44,32,32,35,32,-27,-82,-119,-24,-93,-123,-26,-116,-121,-27,-82,-102,-26,-88,-95,-27,-99,-105,10, -32,32,32,32,32,32,32,32,114,101,109,111,118,101,32,32,61,32,100,101,102,40,41,58,59,32,44,32,32,35,32,-27,-115,-72,-24,-67,-67,-28,-72,-128,-28,-72,-86,-26,-88,-95,-27,-99,-105,10, -32,32,32,32,32,32,32,32,115,101,97,114,99,104,32,32,61,32,100,101,102,40,41,58,59,32,44,32,32,35,32,-26,-112,-100,-25,-76,-94,-28,-72,-128,-28,-72,-86,-26,-88,-95,-27,-99,-105,10, -32,32,32,32,32,32,32,32,119,105,107,105,32,32,32,32,61,32,100,101,102,40,41,58,59,32,44,32,32,35,32,-24,-114,-73,-27,-113,-106,-26,-106,-121,-26,-95,-93,10, -32,32,32,32,32,32,32,32,115,104,111,119,32,32,32,32,61,32,100,101,102,40,41,58,59,32,44,32,32,35,32,-26,-104,-66,-25,-92,-70,-26,-88,-95,-27,-99,-105,-25,-102,-124,-24,-81,-90,-25,-69,-122,-28,-65,-95,-26,-127,-81,10, -32,32,32,32,32,32,32,32,99,108,111,110,101,32,32,32,61,32,100,101,102,40,41,58,59,32,44,32,32,35,32,-27,-123,-117,-23,-102,-122,-28,-72,-128,-28,-72,-86,-26,-88,-95,-27,-99,-105,-25,-102,-124,-27,-123,-88,-23,-125,-88,-27,-113,-81,-24,-114,-73,-27,-113,-106,-28,-69,-93,-25,-96,-127,10, -10, -32,32,32,32,32,32,32,32,115,111,117,114,99,101,32,32,61,32,100,101,102,40,41,58,59,32,44,32,32,35,32,-24,-114,-73,-27,-113,-106,-28,-72,-128,-28,-72,-86,-26,-88,-95,-27,-99,-105,-26,-116,-121,-27,-82,-102,-27,-120,-122,-26,-108,-81,-25,-102,-124,-26,-70,-112,-28,-69,-93,-25,-96,-127,10, -32,32,32,32,32,32,32,32,97,117,116,111,114,101,109,111,118,101,32,61,32,100,101,102,40,41,58,59,32,35,32,-24,-121,-86,-27,-118,-88,-25,-89,-69,-23,-103,-92,-26,-119,-128,-26,-100,-119,-25,-68,-70,-26,-115,-97,-26,-88,-95,-27,-99,-105,10, -32,32,32,32,125,44,10, -32,32,32,32,99,111,110,102,32,61,32,123,32,32,32,32,35,32,-26,-88,-95,-27,-99,-105,-23,-123,-115,-25,-67,-82,-17,-68,-116,-24,-125,-74,-26,-80,-76,-28,-69,-93,-25,-96,-127,-25,-102,-124,-25,-108,-97,-26,-120,-112,10, -32,32,32,32,32,32,32,32,115,114,99,32,61,32,100,101,102,40,41,58,59,32,44,32,35,32,-23,-123,-115,-25,-67,-82,-27,-115,-107,-25,-117,-84,-25,-102,-124,-24,-124,-102,-26,-100,-84,-26,-106,-121,-28,-69,-74,10, -32,32,32,32,32,32,32,32,112,114,111,32,61,32,100,101,102,40,41,58,59,32,44,32,35,32,-23,-123,-115,-25,-67,-82,-27,-92,-102,-26,-106,-121,-28,-69,-74,-26,-88,-95,-26,-99,-65,10, -32,32,32,32,125,44,10, -32,32,32,32,111,115,32,61,32,123,32,32,35,32,-25,-77,-69,-25,-69,-97,-25,-101,-72,-27,-123,-77,-27,-118,-97,-24,-125,-67,-27,-121,-67,-26,-107,-80,10, -32,32,32,32,32,32,32,32,100,111,119,110,108,111,97,100,32,61,32,100,101,102,40,41,58,59,32,44,32,32,32,32,35,32,-28,-72,-117,-24,-67,-67,10, -32,32,32,32,32,32,32,32,109,107,100,105,114,32,32,32,32,61,32,100,101,102,40,41,58,59,32,44,32,32,32,32,35,32,-27,-120,-101,-27,-69,-70,-26,-106,-121,-28,-69,-74,-27,-92,-71,10, -32,32,32,32,32,32,32,32,114,109,102,105,108,101,32,32,32,61,32,100,101,102,40,41,58,59,32,44,32,32,32,32,35,32,-27,-120,-96,-23,-103,-92,-26,-106,-121,-28,-69,-74,10, -32,32,32,32,125,44,10, -32,32,32,32,35,32,-26,-96,-71,-25,-101,-82,-27,-67,-107,10, -32,32,32,32,114,111,111,116,32,32,61,32,40,115,121,115,46,103,101,116,111,115,40,41,61,61,34,87,105,110,100,111,119,115,32,66,114,97,110,99,104,34,32,97,110,100,32,115,121,115,46,103,101,116,101,110,118,40,39,76,80,84,82,79,79,84,39,41,41,32,111,114,32,34,47,101,108,115,47,34,44,10, -32,32,32,32,35,32,105,110,105,116,32,38,32,101,110,100,10, -32,32,32,32,105,110,105,116,32,61,32,100,101,102,40,41,58,59,44,10, -32,32,32,32,101,110,100,32,32,61,32,100,101,102,40,41,58,59,44,10, -32,32,32,32,83,114,99,85,114,108,32,32,61,32,34,34,44,32,35,32,-24,-67,-81,-28,-69,-74,-26,-70,-112,-27,-100,-80,-27,-99,-128,10, -32,32,32,32,83,114,99,65,114,99,104,32,61,32,34,34,44,32,35,32,-27,-120,-122,-26,-108,-81,10, -125,10, -10, -100,101,102,32,76,112,116,46,101,114,114,111,114,40,105,110,102,111,41,58,10, -32,32,32,32,112,114,105,110,116,40,34,91,69,82,82,79,82,47,-23,-108,-103,-24,-81,-81,93,32,76,80,84,58,92,116,34,44,105,110,102,111,41,10, -32,32,32,32,101,120,105,116,40,49,41,10, -32,32,32,32,112,97,115,115,10, -10, -100,101,102,32,76,112,116,46,105,110,105,116,40,41,58,10, -32,32,32,32,35,32,-27,-120,-99,-27,-89,-117,-27,-116,-106,-27,-121,-67,-26,-107,-80,10, -32,32,32,32,10, -32,32,32,32,35,32,-27,-120,-99,-27,-89,-117,-27,-116,-106,-28,-69,-109,-27,-70,-109,-28,-72,-114,-27,-120,-122,-26,-108,-81,10, -32,32,32,32,118,97,114,32,102,108,112,116,32,61,32,102,105,108,101,46,111,112,101,110,40,76,112,116,46,114,111,111,116,38,34,108,112,116,46,99,111,110,102,34,44,34,114,34,41,10, -32,32,32,32,105,102,32,110,111,116,32,102,108,112,116,32,58,10, -32,32,32,32,32,32,32,32,116,104,105,115,46,101,114,114,111,114,40,34,-25,-68,-70,-27,-80,-111,-23,-123,-115,-25,-67,-82,-26,-106,-121,-28,-69,-74,92,116,34,38,76,112,116,46,114,111,111,116,38,34,108,112,116,46,99,111,110,102,34,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,76,112,116,46,83,114,99,85,114,108,32,32,61,32,102,108,112,116,46,105,110,112,117,116,40,41,10, -32,32,32,32,76,112,116,46,83,114,99,65,114,99,104,32,61,32,102,108,112,116,46,105,110,112,117,116,40,41,10, -32,32,32,32,102,108,112,116,46,99,108,111,115,101,40,41,10, -32,32,32,32,10, -10, -32,32,32,32,35,32,-27,-118,-96,-24,-67,-67,-24,-65,-100,-25,-88,-117,-24,-67,-81,-28,-69,-74,-27,-120,-105,-24,-95,-88,10, -32,32,32,32,35,32,-28,-72,-117,-24,-67,-67,-24,-65,-100,-25,-88,-117,-24,-67,-81,-28,-69,-74,-27,-120,-105,-24,-95,-88,10, -32,32,32,32,105,102,32,110,111,116,32,76,112,116,46,111,115,46,100,111,119,110,108,111,97,100,40,76,112,116,46,83,114,99,85,114,108,38,34,46,114,101,112,111,47,46,105,110,100,101,120,34,44,76,112,116,46,114,111,111,116,38,34,114,101,109,111,116,101,46,108,105,115,116,34,41,32,58,10, -32,32,32,32,32,32,32,32,116,104,105,115,46,101,114,114,111,114,40,34,-25,-76,-94,-27,-68,-107,-26,-106,-121,-28,-69,-74,-28,-72,-117,-24,-67,-67,-27,-92,-79,-24,-76,-91,33,34,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,35,32,-27,-80,-99,-24,-81,-107,-27,-118,-96,-24,-67,-67,-25,-76,-94,-27,-68,-107,-26,-106,-121,-28,-69,-74,10, -32,32,32,32,105,102,32,101,118,97,108,40,76,112,116,46,114,111,111,116,38,34,114,101,109,111,116,101,46,108,105,115,116,34,44,34,102,34,41,33,61,48,58,10, -32,32,32,32,32,32,32,32,116,104,105,115,46,101,114,114,111,114,40,34,-24,-65,-100,-25,-88,-117,-25,-76,-94,-27,-68,-107,-27,-120,-105,-24,-95,-88,-27,-121,-70,-25,-114,-80,-26,-96,-68,-27,-68,-113,-23,-108,-103,-24,-81,-81,44,-26,-117,-110,-25,-69,-99,-24,-65,-101,-28,-72,-128,-26,-83,-91,-25,-102,-124,-26,-119,-89,-24,-95,-116,33,34,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,35,32,-26,-93,-128,-26,-75,-117,-24,-67,-81,-28,-69,-74,-26,-70,-112,-25,-119,-120,-26,-100,-84,10, -32,32,32,32,105,102,32,40,32,110,111,116,32,76,112,116,46,112,107,103,115,46,118,101,114,115,105,111,110,32,41,32,111,114,32,40,32,76,112,116,46,112,107,103,115,46,118,101,114,115,105,111,110,32,33,61,32,118,109,46,118,101,114,115,105,111,110,40,41,32,41,58,10, -32,32,32,32,32,32,32,32,35,32,-27,-92,-124,-25,-112,-122,-25,-119,-120,-26,-100,-84,-23,-108,-103,-24,-81,-81,10, -32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,91,87,65,82,78,47,-24,-83,-90,-27,-111,-118,93,32,76,80,84,58,92,116,32,-27,-67,-109,-27,-119,-115,-27,-122,-123,-26,-96,-72,-25,-102,-124,-25,-119,-120,-26,-100,-84,-28,-72,-114,-24,-67,-81,-28,-69,-74,-26,-70,-112,-25,-119,-120,-26,-100,-84,-27,-83,-104,-27,-100,-88,-27,-73,-82,-27,-68,-126,58,34,41,10, -32,32,32,32,32,32,32,32,112,114,105,110,116,40,118,109,46,118,101,114,115,105,111,110,40,41,44,34,92,116,-30,-128,-108,-30,-128,-108,62,92,116,34,44,76,112,116,46,112,107,103,115,46,118,101,114,115,105,111,110,41,10, -32,32,32,32,32,32,32,32,10, -32,32,32,32,32,32,32,32,35,32,-24,-82,-66,-25,-67,-82,-26,-101,-76,-26,-106,-80,-24,-124,-102,-26,-100,-84,10, -32,32,32,32,32,32,32,32,118,97,114,32,117,114,108,44,111,98,106,10, -32,32,32,32,32,32,32,32,105,102,32,118,109,46,98,114,97,110,99,104,40,41,32,61,61,32,34,87,105,110,100,111,119,115,32,66,114,97,110,99,104,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,117,114,108,32,61,32,76,112,116,46,83,114,99,85,114,108,32,38,32,39,46,114,101,112,111,47,117,112,115,99,114,105,112,116,47,108,115,117,112,100,97,116,101,46,98,97,116,39,10, -32,32,32,32,32,32,32,32,32,32,32,32,111,98,106,32,61,32,76,112,116,46,114,111,111,116,38,34,108,115,117,112,100,97,116,101,46,98,97,116,34,10, -32,32,32,32,32,32,32,32,101,108,115,101,10, -32,32,32,32,32,32,32,32,32,32,32,32,117,114,108,32,61,32,76,112,116,46,83,114,99,85,114,108,32,38,32,39,46,47,46,114,101,112,111,47,117,112,115,99,114,105,112,116,47,108,115,117,112,100,97,116,101,95,39,38,76,112,116,46,83,114,99,65,114,99,104,10, -32,32,32,32,32,32,32,32,32,32,32,32,111,98,106,32,61,32,34,47,98,105,110,47,108,115,117,112,100,97,116,101,34,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,91,84,82,89,93,32,-26,-83,-93,-27,-100,-88,-27,-80,-99,-24,-81,-107,-28,-72,-117,-24,-67,-67,-26,-101,-76,-26,-106,-80,-24,-124,-102,-26,-100,-84,58,92,116,34,44,117,114,108,41,10, -32,32,32,32,32,32,32,32,105,102,32,116,104,105,115,46,111,115,46,100,111,119,110,108,111,97,100,40,117,114,108,44,111,98,106,41,32,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,91,79,75,93,34,41,10, -32,32,32,32,32,32,32,32,101,108,115,101,10, -32,32,32,32,32,32,32,32,32,32,32,32,116,104,105,115,46,101,114,114,111,114,40,34,-26,-101,-76,-26,-106,-80,-24,-124,-102,-26,-100,-84,-28,-72,-117,-24,-67,-67,-27,-92,-79,-24,-76,-91,44,-26,-105,-96,-26,-77,-107,-28,-65,-82,-26,-83,-93,-24,-65,-103,-28,-72,-128,-23,-108,-103,-24,-81,-81,44,76,80,84,-26,-117,-110,-25,-69,-99,-24,-65,-101,-28,-72,-128,-26,-83,-91,-26,-119,-89,-24,-95,-116,34,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,116,104,105,115,46,101,114,114,111,114,40,34,-26,-101,-76,-26,-106,-80,-24,-124,-102,-26,-100,-84,-27,-73,-78,-28,-72,-117,-24,-67,-67,44,-24,-65,-112,-24,-95,-116,32,108,115,117,112,100,97,116,101,32,-27,-111,-67,-28,-69,-92,-27,-113,-81,-28,-69,-91,-27,-82,-116,-26,-120,-112,-25,-119,-120,-26,-100,-84,-28,-65,-82,-26,-83,-93,44,-26,-120,-106,-26,-101,-76,-26,-115,-94,-24,-67,-81,-28,-69,-74,-26,-70,-112,-27,-112,-114,-27,-122,-115,-24,-65,-112,-24,-95,-116,76,80,84,34,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -10, -32,32,32,32,35,32,-27,-118,-96,-24,-67,-67,-26,-100,-84,-27,-100,-80,-27,-120,-105,-24,-95,-88,10, -32,32,32,32,118,97,114,32,102,108,111,99,97,108,32,61,32,102,105,108,101,46,111,112,101,110,40,76,112,116,46,114,111,111,116,38,34,108,111,99,97,108,46,108,105,115,116,34,44,34,114,34,41,10, -32,32,32,32,105,102,32,102,108,111,99,97,108,58,10, -32,32,32,32,32,32,32,32,102,108,111,99,97,108,46,99,108,111,115,101,40,41,10, -32,32,32,32,32,32,32,32,105,102,32,101,118,97,108,40,76,112,116,46,114,111,111,116,38,34,108,111,99,97,108,46,108,105,115,116,34,44,34,102,34,41,33,61,48,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,116,104,105,115,46,101,114,114,111,114,40,34,-26,-100,-84,-27,-100,-80,-26,-88,-95,-27,-99,-105,-27,-120,-105,-24,-95,-88,-27,-121,-70,-25,-114,-80,-26,-96,-68,-27,-68,-113,-23,-108,-103,-24,-81,-81,44,-26,-117,-110,-25,-69,-99,-24,-65,-101,-28,-72,-128,-26,-83,-91,-25,-102,-124,-26,-119,-89,-24,-95,-116,33,34,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -10, -32,32,32,32,35,32,-26,-93,-128,-26,-75,-117,-26,-100,-119,-26,-105,-96,-23,-104,-74,-26,-82,-75,-26,-101,-76,-26,-106,-80,10, -32,32,32,32,105,102,32,76,112,116,46,112,107,103,115,46,117,112,118,101,114,115,105,111,110,32,58,10, -32,32,32,32,32,32,32,32,35,32,-26,-113,-112,-25,-92,-70,10, -32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,91,78,79,84,73,67,69,47,-26,-113,-112,-25,-92,-70,93,32,76,80,84,58,92,116,32,-26,-93,-128,-26,-75,-117,-27,-120,-80,-27,-113,-81,-25,-108,-88,-25,-102,-124,-23,-104,-74,-26,-82,-75,-26,-128,-89,-26,-101,-76,-26,-106,-80,34,44,10, -32,32,32,32,32,32,32,32,32,32,32,32,118,109,46,118,101,114,115,105,111,110,40,41,44,39,92,116,-30,-128,-108,-30,-128,-108,62,92,116,39,44,76,112,116,46,112,107,103,115,46,117,112,118,101,114,115,105,111,110,10, -32,32,32,32,32,32,32,32,41,10, -10, -32,32,32,32,32,32,32,32,35,32,-24,-82,-66,-25,-67,-82,-26,-101,-76,-26,-106,-80,-24,-124,-102,-26,-100,-84,10, -32,32,32,32,32,32,32,32,118,97,114,32,117,114,108,44,111,98,106,32,10, -32,32,32,32,32,32,32,32,105,102,32,118,109,46,98,114,97,110,99,104,40,41,32,61,61,32,34,87,105,110,100,111,119,115,32,66,114,97,110,99,104,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,117,114,108,32,61,32,76,112,116,46,83,114,99,85,114,108,32,38,32,39,46,114,101,112,111,47,117,112,115,99,114,105,112,116,47,112,101,114,105,111,100,95,108,115,117,112,100,97,116,101,46,98,97,116,39,10, -32,32,32,32,32,32,32,32,32,32,32,32,111,98,106,32,61,32,76,112,116,46,114,111,111,116,38,34,108,115,117,112,100,97,116,101,46,98,97,116,34,10, -32,32,32,32,32,32,32,32,101,108,115,101,10, -32,32,32,32,32,32,32,32,32,32,32,32,117,114,108,32,61,32,76,112,116,46,83,114,99,85,114,108,32,38,32,39,46,47,46,114,101,112,111,47,117,112,115,99,114,105,112,116,47,112,101,114,105,111,100,95,108,115,117,112,100,97,116,101,95,39,38,76,112,116,46,83,114,99,65,114,99,104,10, -32,32,32,32,32,32,32,32,32,32,32,32,111,98,106,32,61,32,34,47,98,105,110,47,108,115,117,112,100,97,116,101,34,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -10, -32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,91,84,82,89,93,32,-26,-83,-93,-27,-100,-88,-27,-80,-99,-24,-81,-107,-28,-72,-117,-24,-67,-67,-26,-101,-76,-26,-106,-80,-24,-124,-102,-26,-100,-84,58,92,116,34,44,117,114,108,41,10, -32,32,32,32,32,32,32,32,105,102,32,116,104,105,115,46,111,115,46,100,111,119,110,108,111,97,100,40,117,114,108,44,111,98,106,41,32,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,91,79,75,93,34,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,91,79,75,47,-26,-120,-112,-27,-118,-97,93,32,-26,-101,-76,-26,-106,-80,-24,-124,-102,-26,-100,-84,-27,-73,-78,-28,-72,-117,-24,-67,-67,44,-24,-65,-112,-24,-95,-116,32,108,115,117,112,100,97,116,101,32,-27,-111,-67,-28,-69,-92,-27,-113,-81,-28,-69,-91,-27,-82,-116,-26,-120,-112,-25,-119,-120,-26,-100,-84,-26,-101,-76,-26,-106,-80,34,41,10, -32,32,32,32,32,32,32,32,101,108,115,101,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,91,69,82,82,79,82,47,-23,-108,-103,-24,-81,-81,93,32,-26,-101,-76,-26,-106,-80,-24,-124,-102,-26,-100,-84,-28,-72,-117,-24,-67,-67,-27,-92,-79,-24,-76,-91,34,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,10, -10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -10, -32,32,32,32,112,97,115,115,10, -10, -100,101,102,32,76,112,116,46,101,110,100,40,41,58,10, -32,32,32,32,35,32,-25,-69,-109,-26,-99,-97,-27,-121,-67,-26,-107,-80,44,-26,-101,-76,-26,-106,-80,-26,-100,-84,-27,-100,-80,-27,-120,-105,-24,-95,-88,10, -32,32,32,32,118,97,114,32,102,108,111,99,97,108,32,61,32,102,105,108,101,46,111,112,101,110,40,116,104,105,115,46,114,111,111,116,38,34,108,111,99,97,108,46,108,105,115,116,34,44,34,119,34,41,10, -32,32,32,32,35,32,-26,-93,-128,-26,-75,-117,-26,-104,-81,-27,-112,-90,-26,-120,-112,-27,-118,-97,-26,-119,-109,-27,-68,-128,10, -32,32,32,32,105,102,32,110,111,116,32,102,108,111,99,97,108,58,10, -32,32,32,32,32,32,32,32,116,104,105,115,46,101,114,114,111,114,40,34,-26,-78,-95,-26,-100,-119,-24,-74,-77,-27,-92,-97,-25,-102,-124,-26,-99,-125,-23,-103,-112,-28,-65,-82,-26,-108,-71,-26,-100,-84,-27,-100,-80,-27,-120,-105,-24,-95,-88,34,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,10, -32,32,32,32,35,32,-27,-122,-103,-27,-123,-91,-27,-120,-105,-24,-95,-88,10, -32,32,32,32,102,108,111,99,97,108,46,112,114,105,110,116,40,34,76,112,116,46,112,107,103,115,46,108,111,99,97,108,61,123,92,110,34,41,10, -32,32,32,32,102,111,114,32,112,107,110,97,109,101,44,118,101,114,115,105,111,110,32,105,110,32,76,112,116,46,112,107,103,115,46,108,111,99,97,108,58,10, -32,32,32,32,32,32,32,32,102,108,111,99,97,108,46,112,114,105,110,116,40,34,92,116,34,38,112,107,110,97,109,101,38,39,61,34,39,38,118,101,114,115,105,111,110,38,39,34,44,92,110,39,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,102,108,111,99,97,108,46,112,114,105,110,116,40,34,125,92,110,34,41,10, -32,32,32,32,102,108,111,99,97,108,46,99,108,111,115,101,40,41,10, -32,32,32,32,112,97,115,115,10, -10, -10, -10, -10, -100,101,102,32,76,112,116,46,97,114,103,118,46,104,101,108,112,40,41,58,10, -32,32,32,32,35,32,-27,-72,-82,-27,-118,-87,-27,-121,-67,-26,-107,-80,10, -32,32,32,32,118,97,114,32,115,10, -32,32,32,32,118,97,114,32,102,104,101,108,112,32,61,32,102,105,108,101,46,111,112,101,110,40,76,112,116,46,114,111,111,116,38,34,104,101,108,112,34,44,39,114,39,41,10, -32,32,32,32,105,102,32,110,111,116,32,102,104,101,108,112,58,10, -32,32,32,32,32,32,32,32,76,112,116,46,101,114,114,111,114,40,34,-26,-119,-66,-28,-72,-115,-27,-120,-80,-27,-72,-82,-27,-118,-87,-26,-106,-121,-26,-95,-93,33,34,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,119,105,116,104,32,110,111,116,32,102,104,101,108,112,46,101,111,102,40,41,58,10, -32,32,32,32,32,32,32,32,115,32,61,32,102,104,101,108,112,46,108,105,110,101,105,110,112,117,116,40,41,10, -32,32,32,32,32,32,32,32,112,114,105,110,116,40,40,115,61,61,34,34,32,97,110,100,32,34,34,32,41,111,114,40,115,41,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,10, -32,32,32,32,102,104,101,108,112,46,99,108,111,115,101,40,41,10, -32,32,32,32,112,97,115,115,10, -10, -100,101,102,32,76,112,116,46,97,114,103,118,46,117,112,100,97,116,101,40,41,58,10, -32,32,32,32,35,32,-27,-120,-99,-27,-89,-117,-27,-116,-106,32,76,80,84,32,-25,-102,-124,-27,-73,-91,-28,-67,-100,-25,-114,-81,-27,-94,-125,10, -32,32,32,32,76,112,116,46,105,110,105,116,40,41,32,32,32,32,10, -32,32,32,32,118,97,114,32,117,112,110,117,109,44,98,97,100,110,117,109,32,61,32,48,44,48,32,32,35,32,-27,-113,-81,-26,-101,-76,-26,-106,-80,-28,-72,-114,-26,-115,-97,-27,-99,-113,-25,-102,-124,-26,-107,-80,-23,-121,-113,10, -10, -32,32,32,32,35,32,-26,-93,-128,-26,-75,-117,-26,-101,-76,-26,-106,-80,10, -32,32,32,32,102,111,114,32,112,107,110,97,109,101,44,118,101,114,115,105,111,110,32,105,110,32,76,112,116,46,112,107,103,115,46,108,111,99,97,108,58,10, -32,32,32,32,32,32,32,32,105,102,32,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,118,101,114,115,105,111,110,32,33,61,32,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,105,110,102,111,46,118,101,114,115,105,111,110,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,117,112,110,117,109,32,61,32,117,112,110,117,109,32,43,49,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,76,112,116,46,112,107,103,115,46,117,112,97,98,108,101,91,112,107,110,97,109,101,93,61,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,105,110,102,111,46,118,101,114,115,105,111,110,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,101,108,115,101,10, -32,32,32,32,32,32,32,32,32,32,32,32,98,97,100,110,117,109,32,61,32,98,97,100,110,117,109,32,43,32,49,10, -32,32,32,32,32,32,32,32,32,32,32,32,76,112,116,46,112,107,103,115,46,98,97,100,91,112,107,110,97,109,101,93,32,61,32,118,101,114,115,105,111,110,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,10, -32,32,32,32,35,32,-26,-104,-66,-25,-92,-70,-27,-113,-81,-28,-69,-91,-26,-101,-76,-26,-106,-80,-25,-102,-124,-27,-120,-105,-24,-95,-88,10, -32,32,32,32,105,102,32,117,112,110,117,109,32,33,61,32,48,58,10, -32,32,32,32,32,32,32,32,118,97,114,32,102,32,61,32,102,105,108,101,46,111,112,101,110,40,76,112,116,46,114,111,111,116,38,34,117,112,97,98,108,101,46,108,105,115,116,34,44,39,119,39,41,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,102,32,58,32,76,112,116,46,101,114,114,111,114,40,34,-26,-78,-95,-26,-100,-119,-24,-74,-77,-27,-92,-97,-25,-102,-124,-26,-99,-125,-23,-103,-112,-27,-120,-101,-27,-69,-70,-27,-113,-81,-26,-101,-76,-26,-106,-80,-27,-120,-105,-24,-95,-88,34,41,32,59,10, -32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,-27,-123,-79,-26,-100,-119,-28,-69,-91,-28,-72,-117,32,34,44,117,112,110,117,109,44,34,32,-28,-72,-86,-26,-88,-95,-27,-99,-105,-27,-113,-81,-28,-69,-91,-27,-115,-121,-25,-70,-89,34,41,10, -32,32,32,32,32,32,32,32,102,46,112,114,105,110,116,40,34,76,112,116,46,112,107,103,115,46,117,112,97,98,108,101,61,123,92,110,34,41,10, -32,32,32,32,32,32,32,32,102,111,114,32,110,44,118,32,105,110,32,76,112,116,46,112,107,103,115,46,117,112,97,98,108,101,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,114,105,110,116,40,110,44,34,92,116,34,44,76,112,116,46,112,107,103,115,46,108,111,99,97,108,91,110,93,44,39,92,116,45,45,45,45,-26,-101,-76,-26,-106,-80,-27,-120,-80,45,45,45,45,62,92,116,39,44,118,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,102,46,112,114,105,110,116,40,34,92,116,34,38,110,38,39,32,61,32,34,34,44,92,110,39,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,102,46,112,114,105,110,116,40,34,125,92,110,34,41,10, -32,32,32,32,32,32,32,32,102,46,99,108,111,115,101,40,41,10, -32,32,32,32,32,32,32,32,102,32,61,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -10, -10, -32,32,32,32,35,32,-26,-104,-66,-25,-92,-70,-25,-68,-70,-26,-115,-97,-25,-102,-124,-26,-88,-95,-27,-99,-105,-27,-120,-105,-24,-95,-88,10, -32,32,32,32,105,102,32,98,97,100,110,117,109,32,33,61,48,32,58,10, -32,32,32,32,32,32,32,32,118,97,114,32,102,32,61,32,102,105,108,101,46,111,112,101,110,40,76,112,116,46,114,111,111,116,38,34,98,97,100,46,108,105,115,116,34,44,39,119,39,41,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,102,32,58,32,76,112,116,46,101,114,114,111,114,40,34,-26,-78,-95,-26,-100,-119,-24,-74,-77,-27,-92,-97,-25,-102,-124,-26,-99,-125,-23,-103,-112,-27,-120,-101,-27,-69,-70,-25,-68,-70,-26,-115,-97,-27,-120,-105,-24,-95,-88,34,41,32,59,10, -32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,-27,-123,-79,-26,-100,-119,-28,-69,-91,-28,-72,-117,32,34,44,98,97,100,110,117,109,44,34,32,-28,-72,-86,-26,-88,-95,-27,-99,-105,-27,-121,-70,-25,-114,-80,-25,-68,-70,-26,-115,-97,34,41,10, -32,32,32,32,32,32,32,32,102,46,112,114,105,110,116,40,34,76,112,116,46,112,107,103,115,46,98,97,100,61,123,92,110,34,41,10, -32,32,32,32,32,32,32,32,102,111,114,32,110,44,118,32,105,110,32,76,112,116,46,112,107,103,115,46,98,97,100,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,114,105,110,116,40,110,44,34,92,116,34,44,76,112,116,46,112,107,103,115,46,108,111,99,97,108,91,110,93,44,39,92,116,45,45,45,45,-25,-68,-70,-26,-115,-97,45,45,45,45,62,63,46,63,46,63,39,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,102,46,112,114,105,110,116,40,34,92,116,34,38,110,38,39,32,61,32,34,34,44,92,110,39,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,102,46,112,114,105,110,116,40,34,125,92,110,34,41,10, -32,32,32,32,32,32,32,32,102,46,99,108,111,115,101,40,41,10, -32,32,32,32,32,32,32,32,102,32,61,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,-24,-65,-103,-28,-70,-101,-26,-88,-95,-27,-99,-105,-27,-73,-78,-25,-69,-113,-24,-94,-85,-27,-82,-119,-24,-93,-123,44,-28,-67,-122,-26,-104,-81,-26,-78,-95,-26,-100,-119,-27,-121,-70,-25,-114,-80,-24,-67,-81,-28,-69,-74,-26,-70,-112,-28,-72,-83,44,-27,-113,-81,-24,-125,-67,-26,-104,-81,-27,-73,-78,-25,-69,-113,-24,-94,-85,-27,-70,-97,-27,-68,-125,-26,-120,-106,-26,-101,-76,-27,-112,-115,34,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,112,97,115,115,10, -10, -100,101,102,32,76,112,116,46,97,114,103,118,46,117,112,103,114,97,100,101,40,121,101,115,41,58,10, -32,32,32,32,118,97,114,32,101,32,61,32,123,125,10, -32,32,32,32,118,97,114,32,101,110,117,109,32,61,32,48,10, -32,32,32,32,35,32,-27,-120,-99,-27,-89,-117,-27,-116,-106,-27,-73,-91,-28,-67,-100,-25,-114,-81,-27,-94,-125,10, -32,32,32,32,76,112,116,46,105,110,105,116,40,41,10, -10, -32,32,32,32,35,32,-26,-93,-128,-26,-75,-117,-26,-104,-81,-27,-112,-90,-27,-83,-104,-27,-100,-88,-26,-100,-84,-27,-100,-80,-26,-101,-76,-26,-106,-80,-27,-120,-105,-24,-95,-88,10, -32,32,32,32,118,97,114,32,102,32,61,32,102,105,108,101,46,111,112,101,110,40,76,112,116,46,114,111,111,116,38,34,117,112,97,98,108,101,46,108,105,115,116,34,44,39,114,39,41,10, -32,32,32,32,105,102,32,110,111,116,32,102,32,58,32,76,112,116,46,101,114,114,111,114,40,34,-26,-78,-95,-26,-100,-119,-27,-113,-81,-27,-113,-126,-24,-128,-125,-25,-102,-124,-26,-101,-76,-26,-106,-80,-27,-120,-105,-24,-95,-88,44,-24,-128,-125,-24,-103,-111,-26,-119,-89,-24,-95,-116,32,108,112,116,32,117,112,100,97,116,101,-27,-111,-67,-28,-69,-92,34,41,32,59,10, -32,32,32,32,102,46,99,108,111,115,101,40,41,10, -10, -32,32,32,32,105,102,32,101,118,97,108,40,76,112,116,46,114,111,111,116,38,34,117,112,97,98,108,101,46,108,105,115,116,34,44,39,102,39,41,32,33,61,32,48,58,10, -32,32,32,32,32,32,32,32,76,112,116,46,101,114,114,111,114,40,34,-26,-101,-76,-26,-106,-80,-27,-120,-105,-24,-95,-88,-27,-83,-104,-27,-100,-88,-26,-96,-68,-27,-68,-113,-23,-108,-103,-24,-81,-81,-17,-68,-116,-26,-117,-110,-25,-69,-99,-24,-65,-101,-28,-72,-128,-26,-83,-91,-25,-102,-124,-26,-119,-89,-24,-95,-116,33,34,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,10, -32,32,32,32,112,114,105,110,116,40,34,-24,-66,-109,-27,-123,-91,32,121,32,-24,-65,-101,-24,-95,-116,-26,-101,-76,-26,-106,-80,62,34,41,10, -32,32,32,32,121,101,115,32,61,32,121,101,115,32,111,114,32,108,105,110,101,105,110,112,117,116,40,41,32,10, -32,32,32,32,105,102,32,121,101,115,32,33,61,32,34,121,34,58,10, -32,32,32,32,32,32,32,32,76,112,116,46,101,114,114,111,114,40,34,-27,-73,-78,-27,-113,-106,-26,-74,-120,34,41,32,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -10, -32,32,32,32,102,111,114,32,112,107,110,97,109,101,44,118,101,114,115,105,111,110,32,105,110,32,76,112,116,46,112,107,103,115,46,117,112,97,98,108,101,58,10, -32,32,32,32,32,32,32,32,118,97,114,32,117,114,108,32,61,32,76,112,116,46,83,114,99,85,114,108,38,112,107,110,97,109,101,38,34,47,116,97,114,103,101,116,47,69,108,115,76,105,98,95,34,38,112,107,110,97,109,101,38,34,46,108,115,100,95,34,38,76,112,116,46,83,114,99,65,114,99,104,10, -32,32,32,32,32,32,32,32,118,97,114,32,111,98,106,32,61,32,76,112,116,46,114,111,111,116,38,34,108,105,98,47,69,108,115,76,105,98,95,34,38,112,107,110,97,109,101,38,34,46,108,115,100,34,10, -10, -32,32,32,32,32,32,32,32,105,102,32,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,116,121,112,101,32,97,110,100,32,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,116,121,112,101,32,61,61,32,34,99,111,110,115,116,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,91,87,65,82,78,47,-24,-83,-90,-27,-111,-118,93,92,116,34,44,112,107,110,97,109,101,44,34,92,116,-26,-104,-81,-28,-72,-128,-28,-72,-86,-24,-94,-85,-23,-108,-127,-27,-82,-102,-25,-102,-124,-26,-88,-95,-27,-99,-105,44,-28,-72,-115,-24,-125,-67,-25,-108,-79,-25,-108,-88,-26,-120,-73,-24,-65,-101,-24,-95,-116,-28,-65,-82,-26,-108,-71,34,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,101,91,112,107,110,97,109,101,93,61,34,34,10, -32,32,32,32,32,32,32,32,32,32,32,32,101,110,117,109,32,61,32,101,110,117,109,32,43,32,49,10, -32,32,32,32,32,32,32,32,101,108,105,102,32,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,116,121,112,101,32,97,110,100,32,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,116,121,112,101,32,61,61,32,34,112,114,101,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,91,87,65,82,78,47,-24,-83,-90,-27,-111,-118,93,92,116,34,44,112,107,110,97,109,101,44,34,92,116,-26,-104,-81,-28,-72,-128,-28,-72,-86,-27,-119,-115,-25,-98,-69,-25,-102,-124,-25,-119,-120,-26,-100,-84,44,-28,-72,-115,-24,-125,-67,-24,-121,-86,-27,-118,-88,-24,-65,-101,-24,-95,-116,-27,-82,-119,-24,-93,-123,34,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,101,91,112,107,110,97,109,101,93,61,34,34,10, -32,32,32,32,32,32,32,32,32,32,32,32,101,110,117,109,32,61,32,101,110,117,109,32,43,32,49,10, -32,32,32,32,32,32,32,32,101,108,115,101,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,91,84,82,89,47,-27,-80,-99,-24,-81,-107,93,92,116,34,38,117,114,108,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,76,112,116,46,111,115,46,100,111,119,110,108,111,97,100,40,117,114,108,44,111,98,106,41,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,91,79,75,93,34,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,76,112,116,46,112,107,103,115,46,108,111,99,97,108,91,112,107,110,97,109,101,93,61,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,105,110,102,111,46,118,101,114,115,105,111,110,10, -32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,32,32,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,91,112,107,110,97,109,101,93,32,61,32,34,34,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,110,117,109,32,61,32,101,110,117,109,32,43,32,49,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,91,69,82,82,79,82,93,34,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,10, -32,32,32,32,112,114,105,110,116,40,34,-28,-69,-91,-28,-72,-117,32,34,44,101,110,117,109,44,34,32,-28,-72,-86,-26,-88,-95,-27,-99,-105,-26,-100,-86,-24,-125,-67,-26,-120,-112,-27,-118,-97,-27,-115,-121,-25,-70,-89,34,41,10, -32,32,32,32,102,111,114,32,110,44,118,32,105,110,32,101,58,10, -32,32,32,32,32,32,32,32,112,114,105,110,116,40,110,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -10, -32,32,32,32,76,112,116,46,101,110,100,40,41,10, -10, -32,32,32,32,35,32,-27,-120,-96,-23,-103,-92,-26,-101,-76,-26,-106,-80,-27,-120,-105,-24,-95,-88,-25,-68,-109,-27,-83,-104,10, -32,32,32,32,76,112,116,46,111,115,46,114,109,102,105,108,101,40,76,112,116,46,114,111,111,116,38,34,117,112,97,98,108,101,46,108,105,115,116,34,41,10, -32,32,32,32,112,97,115,115,10, -10, -100,101,102,32,76,112,116,46,97,114,103,118,46,108,105,115,116,40,41,58,10, -32,32,32,32,35,32,-27,-120,-99,-27,-89,-117,-27,-116,-106,32,-25,-114,-81,-27,-94,-125,10, -32,32,32,32,76,112,116,46,105,110,105,116,40,41,10, -32,32,32,32,112,114,105,110,116,40,34,-26,-83,-93,-27,-100,-88,-27,-120,-105,-28,-72,-66,32,46,46,46,34,41,10, -32,32,32,32,102,111,114,32,112,107,110,97,109,101,44,118,101,114,115,105,111,110,32,105,110,32,76,112,116,46,112,107,103,115,46,108,111,99,97,108,58,10, -32,32,32,32,32,32,32,32,112,114,105,110,116,40,112,107,110,97,109,101,44,34,47,34,44,118,101,114,115,105,111,110,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,112,114,105,110,116,40,34,-27,-82,-116,-26,-120,-112,34,41,10, -32,32,32,32,112,97,115,115,10, -10, -100,101,102,32,76,112,116,46,97,114,103,118,46,105,110,115,116,97,108,108,40,112,107,110,97,109,101,44,121,101,115,41,58,10, -32,32,32,32,35,32,-27,-120,-99,-27,-89,-117,-27,-116,-106,76,80,84,-25,-114,-81,-27,-94,-125,10, -32,32,32,32,76,112,116,46,105,110,105,116,40,41,10, -10, -32,32,32,32,35,32,-26,-97,-91,-26,-119,-66,-26,-88,-95,-27,-99,-105,10, -32,32,32,32,105,102,32,110,111,116,32,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,58,10, -32,32,32,32,32,32,32,32,76,112,116,46,101,114,114,111,114,40,34,-26,-119,-66,-28,-72,-115,-27,-120,-80,-26,-88,-95,-27,-99,-105,92,116,34,38,112,107,110,97,109,101,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,112,114,105,110,116,40,34,-26,-119,-66,-27,-120,-80,-28,-70,-122,-28,-69,-91,-28,-72,-117,-25,-69,-109,-26,-98,-100,34,41,10, -32,32,32,32,112,114,105,110,116,40,34,-27,-112,-115,-25,-89,-80,58,92,116,34,44,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,105,110,102,111,46,110,97,109,101,41,10, -32,32,32,32,112,114,105,110,116,40,34,-28,-69,-117,-25,-69,-115,58,92,116,34,44,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,105,110,102,111,46,116,101,120,116,41,10, -32,32,32,32,112,114,105,110,116,40,34,-25,-119,-120,-26,-100,-84,58,92,116,34,44,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,105,110,102,111,46,118,101,114,115,105,111,110,41,10, -10, -32,32,32,32,35,32,-26,-93,-128,-26,-75,-117,-26,-104,-81,-27,-112,-90,-28,-72,-70,-23,-108,-127,-27,-82,-102,-26,-88,-95,-27,-99,-105,10, -32,32,32,32,105,102,32,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,116,121,112,101,32,97,110,100,32,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,116,121,112,101,61,61,34,99,111,110,115,116,34,58,10, -32,32,32,32,32,32,32,32,76,112,116,46,101,114,114,111,114,40,34,-26,-88,-95,-27,-99,-105,32,34,38,112,107,110,97,109,101,38,34,32,-26,-104,-81,-28,-72,-128,-28,-72,-86,-23,-108,-127,-27,-82,-102,-26,-88,-95,-27,-99,-105,44,-28,-72,-115,-24,-125,-67,-25,-108,-79,32,76,80,84,32,-24,-65,-101,-24,-95,-116,-27,-82,-119,-24,-93,-123,34,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,112,114,105,110,116,40,34,-24,-66,-109,-27,-123,-91,32,121,32,-24,-65,-101,-24,-95,-116,-27,-82,-119,-24,-93,-123,62,34,41,10, -32,32,32,32,105,102,32,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,116,121,112,101,32,97,110,100,32,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,116,121,112,101,61,61,34,112,114,101,34,58,10, -32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,91,87,65,82,78,47,-24,-83,-90,-27,-111,-118,93,58,92,116,-26,-88,-95,-27,-99,-105,32,34,38,112,107,110,97,109,101,38,34,32,-26,-104,-81,-28,-72,-128,-28,-72,-86,-27,-119,-115,-25,-98,-69,-25,-102,-124,-25,-119,-120,-26,-100,-84,44,-24,-81,-73,-24,-80,-88,-26,-123,-114,-27,-122,-77,-27,-82,-102,-26,-104,-81,-27,-112,-90,-27,-82,-119,-24,-93,-123,34,41,10, -32,32,32,32,32,32,32,32,121,101,115,32,61,32,108,105,110,101,105,110,112,117,116,40,41,10, -32,32,32,32,101,108,115,101,10, -32,32,32,32,32,32,32,32,121,101,115,32,61,32,121,101,115,32,111,114,32,108,105,110,101,105,110,112,117,116,40,41,32,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,10, -32,32,32,32,105,102,32,121,101,115,32,33,61,32,34,121,34,58,10, -32,32,32,32,32,32,32,32,76,112,116,46,101,114,114,111,114,40,34,-27,-73,-78,-27,-113,-106,-26,-74,-120,34,41,32,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,10, -32,32,32,32,35,32,-27,-68,-128,-27,-89,-117,-28,-72,-117,-24,-67,-67,10, -32,32,32,32,118,97,114,32,117,114,108,32,61,32,76,112,116,46,83,114,99,85,114,108,38,112,107,110,97,109,101,38,34,47,116,97,114,103,101,116,47,69,108,115,76,105,98,95,34,38,112,107,110,97,109,101,38,34,46,108,115,100,95,34,38,76,112,116,46,83,114,99,65,114,99,104,10, -32,32,32,32,118,97,114,32,111,98,106,32,61,32,76,112,116,46,114,111,111,116,38,34,108,105,98,47,69,108,115,76,105,98,95,34,38,112,107,110,97,109,101,38,34,46,108,115,100,34,10, -32,32,32,32,112,114,105,110,116,40,34,91,84,82,89,47,-27,-80,-99,-24,-81,-107,93,58,92,116,34,38,117,114,108,41,10, -32,32,32,32,105,102,32,76,112,116,46,111,115,46,100,111,119,110,108,111,97,100,40,117,114,108,44,111,98,106,41,58,10, -32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,91,79,75,93,34,41,10, -32,32,32,32,101,108,115,101,10, -32,32,32,32,32,32,32,32,76,112,116,46,101,114,114,111,114,40,34,91,69,82,82,79,82,47,-23,-108,-103,-24,-81,-81,93,92,110,-27,-82,-119,-24,-93,-123,-27,-92,-79,-24,-76,-91,34,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,10, -32,32,32,32,35,32,-26,-101,-76,-26,-106,-80,-26,-100,-84,-27,-100,-80,-27,-120,-105,-24,-95,-88,10, -32,32,32,32,76,112,116,46,112,107,103,115,46,108,111,99,97,108,91,112,107,110,97,109,101,93,32,61,32,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,105,110,102,111,46,118,101,114,115,105,111,110,10, -32,32,32,32,76,112,116,46,101,110,100,40,41,10, -32,32,32,32,112,97,115,115,10, -10, -100,101,102,32,76,112,116,46,97,114,103,118,46,114,101,109,111,118,101,40,112,107,110,97,109,101,44,121,101,115,41,58,10, -32,32,32,32,35,32,-27,-120,-99,-27,-89,-117,-27,-116,-106,-27,-73,-91,-28,-67,-100,-25,-114,-81,-27,-94,-125,10, -32,32,32,32,76,112,116,46,105,110,105,116,40,41,10, -10, -32,32,32,32,118,97,114,32,111,98,106,32,61,32,76,112,116,46,114,111,111,116,38,39,108,105,98,47,69,108,115,76,105,98,95,39,38,112,107,110,97,109,101,38,39,46,108,115,100,39,10, -32,32,32,32,35,32,-26,-93,-128,-26,-75,-117,-26,-88,-95,-27,-99,-105,-26,-104,-81,-27,-112,-90,-24,-94,-85,-27,-82,-119,-24,-93,-123,10, -32,32,32,32,105,102,32,110,111,116,32,76,112,116,46,112,107,103,115,46,108,111,99,97,108,91,112,107,110,97,109,101,93,58,10, -32,32,32,32,32,32,32,32,76,112,116,46,101,114,114,111,114,40,34,-26,-88,-95,-27,-99,-105,92,116,34,38,112,107,110,97,109,101,38,34,92,116,-26,-78,-95,-26,-100,-119,-24,-94,-85,-27,-82,-119,-24,-93,-123,44,-26,-119,-128,-28,-69,-91,-28,-72,-115,-28,-68,-102,-24,-94,-85,-27,-115,-72,-24,-67,-67,34,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -10, -32,32,32,32,35,32,-26,-93,-128,-26,-75,-117,-26,-88,-95,-27,-99,-105,-26,-104,-81,-27,-112,-90,-26,-104,-81,-23,-108,-127,-27,-82,-102,-26,-88,-95,-27,-99,-105,10, -32,32,32,32,105,102,32,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,32,97,110,100,32,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,116,121,112,101,32,97,110,100,32,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,116,121,112,101,61,61,34,99,111,110,115,116,34,58,10, -32,32,32,32,32,32,32,32,76,112,116,46,101,114,114,111,114,40,34,-26,-88,-95,-27,-99,-105,32,34,38,112,107,110,97,109,101,38,34,32,-26,-104,-81,-28,-72,-128,-28,-72,-86,-23,-108,-127,-27,-82,-102,-26,-88,-95,-27,-99,-105,44,-28,-72,-115,-24,-125,-67,-25,-108,-79,32,76,80,84,32,-24,-65,-101,-24,-95,-116,-27,-115,-72,-24,-67,-67,34,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,10, -32,32,32,32,112,114,105,110,116,40,34,-24,-66,-109,-27,-123,-91,32,121,32,-24,-65,-101,-24,-95,-116,-27,-115,-72,-24,-67,-67,62,34,41,10, -32,32,32,32,121,101,115,32,61,32,121,101,115,32,111,114,32,108,105,110,101,105,110,112,117,116,40,41,32,10, -32,32,32,32,105,102,32,121,101,115,32,33,61,32,34,121,34,58,10, -32,32,32,32,32,32,32,32,76,112,116,46,101,114,114,111,114,40,34,-27,-73,-78,-27,-113,-106,-26,-74,-120,34,41,32,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -10, -32,32,32,32,35,32,-27,-68,-128,-27,-89,-117,-27,-120,-96,-23,-103,-92,10, -32,32,32,32,112,114,105,110,116,40,34,91,68,69,76,47,-27,-120,-96,-23,-103,-92,93,92,116,34,44,111,98,106,41,10, -32,32,32,32,105,102,32,110,111,116,32,76,112,116,46,111,115,46,114,109,102,105,108,101,40,111,98,106,41,32,58,10, -32,32,32,32,32,32,32,32,76,112,116,46,101,114,114,111,114,40,34,-26,-100,-86,-26,-120,-112,-27,-118,-97,-27,-120,-96,-23,-103,-92,-26,-106,-121,-28,-69,-74,34,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,112,114,105,110,116,40,34,91,79,75,93,34,41,10, -10, -32,32,32,32,35,32,-26,-101,-76,-26,-106,-80,-26,-100,-84,-27,-100,-80,-27,-120,-105,-24,-95,-88,10, -32,32,32,32,76,112,116,46,112,107,103,115,46,108,111,99,97,108,91,112,107,110,97,109,101,93,61,110,117,108,108,10, -32,32,32,32,76,112,116,46,101,110,100,40,41,10, -32,32,32,32,112,97,115,115,10, -10, -100,101,102,32,76,112,116,46,97,114,103,118,46,115,101,97,114,99,104,40,105,110,100,101,120,41,58,10, -32,32,32,32,35,32,-27,-120,-99,-27,-89,-117,-27,-116,-106,-25,-114,-81,-27,-94,-125,10, -32,32,32,32,76,112,116,46,105,110,105,116,40,41,10, -10, -32,32,32,32,35,32,-27,-68,-128,-27,-89,-117,-26,-97,-91,-26,-119,-66,10, -32,32,32,32,102,111,114,32,112,107,110,97,109,101,44,112,107,111,98,106,32,105,110,32,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,32,58,10, -32,32,32,32,32,32,32,32,35,32,-27,-116,-123,-27,-112,-85,-27,-123,-77,-23,-108,-82,-24,-81,-115,10, -32,32,32,32,32,32,32,32,105,102,32,99,111,117,116,110,117,109,40,112,107,110,97,109,101,44,105,110,100,101,120,41,62,48,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,114,105,110,116,40,112,107,110,97,109,101,44,34,47,34,44,112,107,111,98,106,46,105,110,102,111,46,118,101,114,115,105,111,110,41,32,59,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -10, -32,32,32,32,112,97,115,115,10, -10, -100,101,102,32,76,112,116,46,97,114,103,118,46,119,105,107,105,40,112,107,110,97,109,101,41,58,10, -32,32,32,32,35,32,-27,-120,-99,-27,-89,-117,-27,-116,-106,-25,-114,-81,-27,-94,-125,10, -32,32,32,32,76,112,116,46,105,110,105,116,40,41,10, -10, -32,32,32,32,35,32,-26,-93,-128,-26,-75,-117,-26,-88,-95,-27,-99,-105,-26,-104,-81,-27,-112,-90,-27,-83,-104,-27,-100,-88,10, -32,32,32,32,105,102,32,110,111,116,32,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,58,10, -32,32,32,32,32,32,32,32,76,112,116,46,101,114,114,111,114,40,34,-26,-119,-66,-28,-72,-115,-27,-120,-80,-26,-88,-95,-27,-99,-105,32,34,38,112,107,110,97,109,101,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,112,114,105,110,116,40,34,-26,-119,-66,-27,-120,-80,-28,-70,-122,-28,-69,-91,-28,-72,-117,-25,-69,-109,-26,-98,-100,34,41,10, -32,32,32,32,112,114,105,110,116,40,34,-27,-112,-115,-25,-89,-80,58,92,116,34,44,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,105,110,102,111,46,110,97,109,101,41,10, -32,32,32,32,112,114,105,110,116,40,34,-28,-69,-117,-25,-69,-115,58,92,116,34,44,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,105,110,102,111,46,116,101,120,116,41,10, -32,32,32,32,112,114,105,110,116,40,34,-25,-119,-120,-26,-100,-84,58,92,116,34,44,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,105,110,102,111,46,118,101,114,115,105,111,110,41,10, -10, -32,32,32,32,118,97,114,32,117,114,108,32,61,32,76,112,116,46,83,114,99,85,114,108,32,38,112,107,110,97,109,101,32,38,34,47,114,101,97,100,109,101,46,109,100,34,10, -32,32,32,32,118,97,114,32,111,98,106,32,61,32,112,107,110,97,109,101,32,38,32,34,46,109,100,34,10, -32,32,32,32,10, -32,32,32,32,112,114,105,110,116,40,34,91,84,82,89,47,-27,-80,-99,-24,-81,-107,93,92,116,34,44,117,114,108,41,10, -32,32,32,32,105,102,32,76,112,116,46,111,115,46,100,111,119,110,108,111,97,100,40,117,114,108,44,111,98,106,41,58,10, -32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,91,79,75,93,34,41,10, -32,32,32,32,101,108,115,101,10, -32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,91,69,82,82,79,82,93,34,41,10, -32,32,32,32,32,32,32,32,76,112,116,46,101,114,114,111,114,40,34,-26,-119,-66,-28,-72,-115,-27,-120,-80,-26,-88,-95,-27,-99,-105,-25,-102,-124,-26,-106,-121,-26,-95,-93,34,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,112,97,115,115,10, -10, -100,101,102,32,76,112,116,46,97,114,103,118,46,115,104,111,119,40,112,107,110,97,109,101,41,58,10, -32,32,32,32,35,32,-27,-120,-99,-27,-89,-117,-27,-116,-106,-25,-114,-81,-27,-94,-125,10, -32,32,32,32,76,112,116,46,105,110,105,116,40,41,10, -10, -32,32,32,32,35,32,-26,-93,-128,-26,-75,-117,-26,-88,-95,-27,-99,-105,-26,-104,-81,-27,-112,-90,-27,-83,-104,-27,-100,-88,10, -32,32,32,32,105,102,32,110,111,116,32,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,58,10, -32,32,32,32,32,32,32,32,76,112,116,46,101,114,114,111,114,40,34,-26,-119,-66,-28,-72,-115,-27,-120,-80,-26,-88,-95,-27,-99,-105,32,34,38,112,107,110,97,109,101,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,112,114,105,110,116,40,34,-26,-88,-95,-27,-99,-105,32,34,44,112,107,110,97,109,101,44,34,32,-25,-102,-124,-25,-101,-72,-28,-65,-95,-28,-65,-95,-26,-127,-81,-27,-90,-126,-28,-72,-117,34,41,10, -32,32,32,32,112,114,105,110,116,40,34,-27,-112,-115,-25,-89,-80,58,92,116,34,44,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,105,110,102,111,46,110,97,109,101,41,10, -32,32,32,32,112,114,105,110,116,40,34,-28,-69,-117,-25,-69,-115,58,92,116,34,44,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,105,110,102,111,46,116,101,120,116,41,10, -32,32,32,32,112,114,105,110,116,40,34,-25,-119,-120,-26,-100,-84,58,92,116,34,44,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,105,110,102,111,46,118,101,114,115,105,111,110,41,10, -32,32,32,32,112,114,105,110,116,40,34,-26,-88,-95,-27,-68,-113,58,92,116,34,44,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,116,121,112,101,32,111,114,32,34,110,111,114,109,97,108,34,41,10, -32,32,32,32,112,114,105,110,116,40,34,-28,-70,-116,-24,-65,-101,-27,-120,-74,-27,-120,-122,-27,-113,-111,-25,-102,-124,-27,-120,-122,-26,-108,-81,58,34,41,10, -32,32,32,32,102,111,114,32,65,114,99,104,44,115,32,105,110,32,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,116,97,114,103,101,116,32,58,10, -32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,92,116,34,44,65,114,99,104,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -10, -32,32,32,32,112,114,105,110,116,40,34,-26,-70,-112,-28,-69,-93,-25,-96,-127,-27,-113,-118,-26,-108,-81,-26,-116,-127,-25,-102,-124,-27,-120,-122,-26,-108,-81,58,34,41,10, -32,32,32,32,102,111,114,32,65,114,99,104,44,70,105,108,101,115,32,105,110,32,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,115,111,117,114,99,101,32,58,10, -32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,92,116,34,44,65,114,99,104,44,34,58,34,41,10, -32,32,32,32,32,32,32,32,102,111,114,32,110,44,102,32,105,110,32,70,105,108,101,115,32,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,92,116,92,116,34,44,102,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -10, -32,32,32,32,112,97,115,115,10, -32,32,32,32,10, -100,101,102,32,76,112,116,46,97,114,103,118,46,99,108,111,110,101,40,112,107,110,97,109,101,41,58,10, -32,32,32,32,118,97,114,32,101,32,61,32,110,117,108,108,10, -32,32,32,32,10, -32,32,32,32,10, -32,32,32,32,35,32,-27,-120,-99,-27,-89,-117,-27,-116,-106,-25,-114,-81,-27,-94,-125,10, -32,32,32,32,76,112,116,46,105,110,105,116,40,41,10, -32,32,32,32,10, -32,32,32,32,35,32,-27,-120,-92,-26,-106,-83,-26,-88,-95,-27,-99,-105,-26,-104,-81,-27,-112,-90,-27,-83,-104,-27,-100,-88,10, -32,32,32,32,105,102,32,110,111,116,32,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,58,10, -32,32,32,32,32,32,32,32,76,112,116,46,101,114,114,111,114,40,34,-26,-119,-66,-28,-72,-115,-27,-120,-80,-26,-88,-95,-27,-99,-105,92,116,34,38,112,107,110,97,109,101,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,10, -32,32,32,32,35,32,-26,-104,-66,-25,-92,-70,-26,-88,-95,-27,-99,-105,-28,-65,-95,-26,-127,-81,10, -32,32,32,32,112,114,105,110,116,40,34,-26,-119,-66,-27,-120,-80,-28,-70,-122,-28,-69,-91,-28,-72,-117,-25,-69,-109,-26,-98,-100,34,41,10, -32,32,32,32,112,114,105,110,116,40,34,-27,-112,-115,-25,-89,-80,58,92,116,34,44,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,105,110,102,111,46,110,97,109,101,41,10, -32,32,32,32,112,114,105,110,116,40,34,-28,-69,-117,-25,-69,-115,58,92,116,34,44,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,105,110,102,111,46,116,101,120,116,41,10, -32,32,32,32,112,114,105,110,116,40,34,-25,-119,-120,-26,-100,-84,58,92,116,34,44,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,105,110,102,111,46,118,101,114,115,105,111,110,41,10, -10, -32,32,32,32,35,32,-27,-68,-128,-27,-89,-117,-27,-123,-117,-23,-102,-122,10, -32,32,32,32,32,32,32,32,35,32,-27,-120,-101,-27,-69,-70,-26,-106,-121,-28,-69,-74,-27,-92,-71,10, -32,32,32,32,76,112,116,46,111,115,46,109,107,100,105,114,40,112,107,110,97,109,101,41,10, -32,32,32,32,32,32,32,32,35,32,-28,-72,-117,-24,-67,-67,32,105,110,102,111,32,-26,-106,-121,-28,-69,-74,10, -32,32,32,32,112,114,105,110,116,40,34,91,84,82,89,93,92,116,105,110,102,111,34,41,10, -32,32,32,32,105,102,32,76,112,116,46,111,115,46,100,111,119,110,108,111,97,100,40,32,76,112,116,46,83,114,99,85,114,108,32,38,32,112,107,110,97,109,101,32,38,32,34,47,105,110,102,111,34,44,112,107,110,97,109,101,32,38,32,34,47,105,110,102,111,34,41,58,10, -32,32,32,32,32,32,32,32,112,114,105,110,116,40,39,91,79,75,93,39,41,10, -32,32,32,32,101,108,115,101,10, -32,32,32,32,32,32,32,32,112,114,105,110,116,40,39,91,69,82,82,79,82,93,39,41,10, -32,32,32,32,32,32,32,32,101,32,61,32,49,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,10, -32,32,32,32,32,32,32,32,35,32,-27,-123,-117,-23,-102,-122,32,97,108,108,32,-27,-120,-122,-26,-108,-81,10, -32,32,32,32,102,111,114,32,105,44,102,32,105,110,32,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,115,111,117,114,99,101,46,97,108,108,32,58,10, -32,32,32,32,32,32,32,32,118,97,114,32,117,114,108,32,61,32,76,112,116,46,83,114,99,85,114,108,32,38,32,112,107,110,97,109,101,32,38,32,34,47,34,32,38,32,102,10, -32,32,32,32,32,32,32,32,118,97,114,32,111,98,106,32,61,32,112,107,110,97,109,101,32,38,32,39,47,39,32,38,32,102,10, -10, -32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,91,84,82,89,93,92,116,34,44,117,114,108,41,10, -32,32,32,32,32,32,32,32,105,102,32,76,112,116,46,111,115,46,100,111,119,110,108,111,97,100,40,117,114,108,44,111,98,106,41,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,91,79,75,93,34,41,10, -32,32,32,32,32,32,32,32,101,108,115,101,32,32,32,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,91,69,82,82,79,82,93,34,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,101,32,61,32,49,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -10, -32,32,32,32,32,32,32,32,35,32,-27,-123,-117,-23,-102,-122,-27,-123,-74,-28,-69,-106,-27,-120,-122,-26,-108,-81,10, -32,32,32,32,102,111,114,32,97,114,99,104,44,111,98,106,32,105,110,32,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,115,111,117,114,99,101,58,10, -32,32,32,32,32,32,32,32,105,102,32,97,114,99,104,32,33,61,32,34,97,108,108,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,76,112,116,46,111,115,46,109,107,100,105,114,40,112,107,110,97,109,101,38,34,47,34,38,97,114,99,104,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,102,111,114,32,105,44,102,32,105,110,32,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,115,111,117,114,99,101,91,97,114,99,104,93,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,118,97,114,32,117,114,108,32,61,32,76,112,116,46,83,114,99,85,114,108,32,38,32,112,107,110,97,109,101,32,38,32,39,47,39,32,38,32,97,114,99,104,32,38,32,34,47,34,32,38,32,102,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,118,97,114,32,111,98,106,32,61,32,112,107,110,97,109,101,32,38,32,39,47,39,32,38,32,97,114,99,104,32,38,32,34,47,34,32,38,32,102,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,91,84,82,89,93,92,116,34,44,117,114,108,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,76,112,116,46,111,115,46,100,111,119,110,108,111,97,100,40,117,114,108,44,111,98,106,41,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,91,79,75,93,34,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,32,32,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,91,69,82,82,79,82,93,34,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,32,61,32,49,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,10, -32,32,32,32,35,32,-25,-69,-109,-26,-98,-100,-27,-113,-115,-23,-90,-120,10, -32,32,32,32,105,102,32,101,32,58,10, -32,32,32,32,32,32,32,32,76,112,116,46,101,114,114,111,114,40,34,-26,-100,-119,-23,-125,-88,-27,-120,-122,-26,-106,-121,-28,-69,-74,-25,-68,-70,-27,-92,-79,34,41,10, -32,32,32,32,101,108,115,101,10, -32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,-27,-123,-117,-23,-102,-122,-27,-82,-116,-26,-120,-112,34,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,10, -32,32,32,32,112,97,115,115,10, -10, -10, -10, -100,101,102,32,76,112,116,46,97,114,103,118,46,97,117,116,111,114,101,109,111,118,101,40,121,101,115,41,58,10, -32,32,32,32,76,112,116,46,105,110,105,116,40,41,10, -32,32,32,32,118,97,114,32,101,44,101,110,117,109,32,61,32,48,44,123,125,32,35,32,-27,-121,-70,-23,-108,-103,-25,-102,-124,-28,-72,-86,-26,-107,-80,-28,-72,-114,-26,-88,-95,-27,-99,-105,10, -10, -32,32,32,32,35,32,-26,-93,-128,-26,-75,-117,-26,-104,-81,-27,-112,-90,-27,-83,-104,-27,-100,-88,-25,-68,-70,-26,-115,-97,-27,-120,-105,-24,-95,-88,10, -32,32,32,32,118,97,114,32,102,32,61,32,102,105,108,101,46,111,112,101,110,40,76,112,116,46,114,111,111,116,38,34,98,97,100,46,108,105,115,116,34,44,39,114,39,41,10, -32,32,32,32,105,102,32,110,111,116,32,102,32,58,32,76,112,116,46,101,114,114,111,114,40,34,-26,-78,-95,-26,-100,-119,-27,-113,-81,-27,-113,-126,-24,-128,-125,-25,-102,-124,-25,-68,-70,-26,-115,-97,44,-24,-128,-125,-24,-103,-111,-26,-119,-89,-24,-95,-116,32,108,112,116,32,117,112,100,97,116,101,-27,-111,-67,-28,-69,-92,34,41,32,59,10, -32,32,32,32,102,46,99,108,111,115,101,40,41,10, -32,32,32,32,102,32,61,32,110,117,108,108,10, -10, -32,32,32,32,35,32,-27,-118,-96,-24,-67,-67,-27,-120,-105,-24,-95,-88,10, -32,32,32,32,105,102,32,101,118,97,108,40,76,112,116,46,114,111,111,116,38,34,98,97,100,46,108,105,115,116,34,44,39,102,39,41,32,33,61,32,48,58,10, -32,32,32,32,32,32,32,32,76,112,116,46,101,114,114,111,114,40,34,-25,-68,-70,-26,-115,-97,-27,-120,-105,-24,-95,-88,-27,-83,-104,-27,-100,-88,-26,-96,-68,-27,-68,-113,-23,-108,-103,-24,-81,-81,-17,-68,-116,-26,-117,-110,-25,-69,-99,-24,-65,-101,-28,-72,-128,-26,-83,-91,-25,-102,-124,-26,-119,-89,-24,-95,-116,33,34,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,10, -32,32,32,32,35,32,-27,-120,-105,-28,-72,-66,-26,-88,-95,-27,-99,-105,10, -32,32,32,32,112,114,105,110,116,40,34,-28,-69,-91,-28,-72,-117,-26,-88,-95,-27,-99,-105,-27,-80,-122,-24,-94,-85,-24,-121,-86,-27,-118,-88,-27,-115,-72,-24,-67,-67,58,34,41,10, -32,32,32,32,102,111,114,32,110,44,118,32,105,110,32,76,112,116,46,112,107,103,115,46,98,97,100,58,10, -32,32,32,32,32,32,32,32,112,114,105,110,116,108,40,110,44,34,92,116,34,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,112,114,105,110,116,40,34,34,41,10, -10, -32,32,32,32,35,32,-23,-128,-119,-26,-117,-87,10, -32,32,32,32,112,114,105,110,116,40,34,-24,-66,-109,-27,-123,-91,32,121,32,-24,-65,-101,-24,-95,-116,-27,-115,-72,-24,-67,-67,62,34,41,10, -32,32,32,32,121,101,115,32,61,32,121,101,115,32,111,114,32,108,105,110,101,105,110,112,117,116,40,41,32,10, -32,32,32,32,105,102,32,121,101,115,32,33,61,32,34,121,34,58,10, -32,32,32,32,32,32,32,32,76,112,116,46,101,114,114,111,114,40,34,-27,-73,-78,-27,-113,-106,-26,-74,-120,34,41,32,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -10, -32,32,32,32,35,32,-27,-68,-128,-27,-89,-117,-23,-128,-112,-28,-72,-86,-27,-120,-96,-23,-103,-92,10, -32,32,32,32,102,111,114,32,112,107,110,97,109,101,44,105,32,105,110,32,76,112,116,46,112,107,103,115,46,98,97,100,58,10, -32,32,32,32,32,32,32,32,118,97,114,32,111,98,106,32,61,32,76,112,116,46,114,111,111,116,38,39,108,105,98,47,69,108,115,76,105,98,95,39,38,112,107,110,97,109,101,38,39,46,108,115,100,39,10, -32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,91,68,69,76,47,-27,-120,-96,-23,-103,-92,93,92,116,34,44,111,98,106,41,10, -32,32,32,32,32,32,32,32,76,112,116,46,111,115,46,114,109,102,105,108,101,40,111,98,106,41,32,10, -32,32,32,32,32,32,32,32,76,112,116,46,112,107,103,115,46,108,111,99,97,108,91,112,107,110,97,109,101,93,61,110,117,108,108,32,35,32,-27,-120,-96,-27,-114,-69,-26,-100,-84,-27,-100,-80,-24,-82,-80,-27,-67,-107,10, -32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,91,79,75,93,34,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,10, -10, -32,32,32,32,35,32,-26,-101,-76,-26,-106,-80,-26,-100,-84,-27,-100,-80,-27,-120,-105,-24,-95,-88,10, -32,32,32,32,76,112,116,46,111,115,46,114,109,102,105,108,101,40,76,112,116,46,114,111,111,116,38,34,98,97,100,46,108,105,115,116,34,41,10, -32,32,32,32,76,112,116,46,101,110,100,40,41,10, -32,32,32,32,112,97,115,115,10, -10, -100,101,102,32,76,112,116,46,97,114,103,118,46,115,111,117,114,99,101,40,112,107,110,97,109,101,44,97,114,99,104,41,58,10, -32,32,32,32,118,97,114,32,101,32,61,32,110,117,108,108,10, -10, -32,32,32,32,35,32,-27,-120,-99,-27,-89,-117,-27,-116,-106,-27,-73,-91,-28,-67,-100,-25,-114,-81,-27,-94,-125,10, -32,32,32,32,76,112,116,46,105,110,105,116,40,41,10, -32,32,32,32,97,114,99,104,32,61,32,97,114,99,104,32,111,114,32,76,112,116,46,83,114,99,65,114,99,104,10, -10, -32,32,32,32,35,32,-27,-120,-92,-26,-106,-83,-26,-88,-95,-27,-99,-105,-26,-104,-81,-27,-112,-90,-27,-83,-104,-27,-100,-88,10, -32,32,32,32,105,102,32,110,111,116,32,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,58,10, -32,32,32,32,32,32,32,32,76,112,116,46,101,114,114,111,114,40,34,-26,-119,-66,-28,-72,-115,-27,-120,-80,-26,-88,-95,-27,-99,-105,92,116,34,38,112,107,110,97,109,101,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,10, -32,32,32,32,35,32,-26,-104,-66,-25,-92,-70,-26,-88,-95,-27,-99,-105,-28,-65,-95,-26,-127,-81,10, -32,32,32,32,112,114,105,110,116,40,34,-26,-119,-66,-27,-120,-80,-28,-70,-122,-28,-69,-91,-28,-72,-117,-25,-69,-109,-26,-98,-100,34,41,10, -32,32,32,32,112,114,105,110,116,40,34,-27,-112,-115,-25,-89,-80,58,92,116,34,44,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,105,110,102,111,46,110,97,109,101,41,10, -32,32,32,32,112,114,105,110,116,40,34,-28,-69,-117,-25,-69,-115,58,92,116,34,44,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,105,110,102,111,46,116,101,120,116,41,10, -32,32,32,32,112,114,105,110,116,40,34,-25,-119,-120,-26,-100,-84,58,92,116,34,44,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,105,110,102,111,46,118,101,114,115,105,111,110,41,10, -10, -32,32,32,32,35,32,-27,-90,-126,-26,-98,-100,-26,-104,-81,-28,-72,-128,-28,-72,-86,-28,-72,-115,-27,-83,-104,-27,-100,-88,-25,-102,-124,-27,-120,-122,-26,-108,-81,10, -32,32,32,32,105,102,32,110,111,116,32,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,115,111,117,114,99,101,91,97,114,99,104,93,32,58,10, -32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,91,87,65,82,78,47,-24,-83,-90,-27,-111,-118,93,92,116,34,44,97,114,99,104,44,34,32,-28,-72,-115,-26,-104,-81,-28,-72,-128,-28,-72,-86,-27,-113,-105,-26,-108,-81,-26,-116,-127,-25,-102,-124,-27,-120,-122,-26,-108,-81,44,-27,-80,-122,-27,-113,-86,-28,-72,-117,-24,-67,-67,-23,-128,-102,-25,-108,-88,-28,-69,-93,-25,-96,-127,34,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -10, -32,32,32,32,35,32,-27,-68,-128,-27,-89,-117,-28,-72,-117,-24,-67,-67,10, -32,32,32,32,76,112,116,46,111,115,46,109,107,100,105,114,40,112,107,110,97,109,101,41,10, -32,32,32,32,105,102,32,97,114,99,104,32,33,61,32,34,97,108,108,34,58,10, -32,32,32,32,32,32,32,32,102,111,114,32,105,44,102,32,105,110,32,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,115,111,117,114,99,101,91,97,114,99,104,93,32,111,114,32,123,125,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,118,97,114,32,117,114,108,32,61,32,76,112,116,46,83,114,99,85,114,108,32,38,32,112,107,110,97,109,101,32,38,32,39,47,39,32,38,32,97,114,99,104,32,38,32,34,47,34,32,38,32,102,10, -32,32,32,32,32,32,32,32,32,32,32,32,118,97,114,32,111,98,106,32,61,32,112,107,110,97,109,101,32,38,32,39,47,39,32,38,32,102,10, -10, -32,32,32,32,32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,91,84,82,89,93,92,116,34,44,117,114,108,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,76,112,116,46,111,115,46,100,111,119,110,108,111,97,100,40,117,114,108,44,111,98,106,41,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,91,79,75,93,34,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,32,32,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,91,69,82,82,79,82,93,34,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,32,61,32,49,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,10, -32,32,32,32,102,111,114,32,105,44,102,32,105,110,32,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,91,112,107,110,97,109,101,93,46,115,111,117,114,99,101,46,97,108,108,32,58,10, -32,32,32,32,32,32,32,32,118,97,114,32,117,114,108,32,61,32,76,112,116,46,83,114,99,85,114,108,32,38,32,112,107,110,97,109,101,32,38,32,34,47,34,32,38,32,102,10, -32,32,32,32,32,32,32,32,118,97,114,32,111,98,106,32,61,32,112,107,110,97,109,101,32,38,32,39,47,39,32,38,32,102,10, -10, -32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,91,84,82,89,93,92,116,34,44,117,114,108,41,10, -32,32,32,32,32,32,32,32,105,102,32,76,112,116,46,111,115,46,100,111,119,110,108,111,97,100,40,117,114,108,44,111,98,106,41,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,91,79,75,93,34,41,10, -32,32,32,32,32,32,32,32,101,108,115,101,32,32,32,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,91,69,82,82,79,82,93,34,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,101,32,61,32,49,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,10, -32,32,32,32,35,32,-25,-69,-109,-26,-98,-100,-27,-113,-115,-23,-90,-120,10, -32,32,32,32,105,102,32,101,32,58,10, -32,32,32,32,32,32,32,32,76,112,116,46,101,114,114,111,114,40,34,-26,-100,-119,-23,-125,-88,-27,-120,-122,-26,-106,-121,-28,-69,-74,-25,-68,-70,-27,-92,-79,34,41,10, -32,32,32,32,101,108,115,101,10, -32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,-28,-72,-117,-24,-67,-67,-27,-82,-116,-26,-120,-112,34,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,10, -32,32,32,32,112,97,115,115,10, -10, -10, -10, -10, -100,101,102,32,76,112,116,46,99,111,110,102,46,115,114,99,40,102,110,44,112,97,99,107,41,58,10, -32,32,32,32,112,114,105,110,116,40,39,99,111,110,102,105,103,32,102,105,108,101,32,39,38,102,110,38,39,46,46,46,46,46,46,92,116,39,41,10, -32,32,32,32,118,97,114,32,76,105,98,115,61,123,125,10, -32,32,32,32,118,97,114,32,83,112,116,32,61,32,48,10, -32,32,32,32,118,97,114,32,67,115,112,116,32,61,32,48,10, -32,32,32,32,118,97,114,32,102,105,110,32,32,61,32,32,102,105,108,101,46,111,112,101,110,40,102,110,38,39,46,101,108,115,39,44,39,114,39,41,32,10, -32,32,32,32,105,102,32,110,111,116,32,102,105,110,32,32,58,32,10, -32,32,32,32,32,32,32,32,76,112,116,46,101,114,114,111,114,40,34,-26,-119,-66,-28,-72,-115,-27,-120,-80,-24,-90,-127,-23,-123,-115,-25,-67,-82,-25,-102,-124,-26,-106,-121,-28,-69,-74,34,41,32,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,118,97,114,32,102,111,117,116,32,61,32,32,102,105,108,101,46,111,112,101,110,40,102,110,32,38,32,39,46,104,39,44,39,119,39,41,32,32,32,10, -32,32,32,32,105,102,32,110,111,116,32,102,111,117,116,32,58,32,10, -32,32,32,32,32,32,32,32,76,112,116,46,101,114,114,111,114,40,34,-24,-66,-109,-27,-121,-70,-26,-106,-121,-28,-69,-74,32,34,32,38,32,32,102,110,32,32,38,32,39,46,104,39,32,38,32,34,32,-26,-119,-109,-27,-68,-128,-27,-92,-79,-24,-76,-91,34,41,32,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,118,97,114,32,115,44,116,109,112,32,61,32,34,34,44,34,34,10, -32,32,32,32,118,97,114,32,102,111,117,116,95,112,114,105,110,116,10, -32,32,32,32,100,101,102,32,102,111,117,116,95,112,114,105,110,116,40,97,41,58,10, -32,32,32,32,32,32,32,32,102,111,114,32,105,32,61,32,49,44,32,108,101,110,103,116,104,40,97,41,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,97,115,99,40,97,91,105,93,41,38,34,44,34,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -10, -32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,39,35,105,110,99,108,117,100,101,32,34,101,108,115,46,104,34,92,110,39,41,10, -32,32,32,32,119,105,116,104,32,33,102,105,110,46,101,111,102,40,41,58,10, -32,32,32,32,32,32,32,32,115,32,61,32,102,105,110,46,108,105,110,101,105,110,112,117,116,40,41,10, -32,32,32,32,32,32,32,32,105,102,32,114,101,112,108,97,99,101,40,115,44,34,32,34,44,34,34,41,32,61,61,32,34,35,33,115,99,114,105,112,116,34,32,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,83,112,116,32,61,32,49,10, -32,32,32,32,32,32,32,32,32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,34,35,105,102,100,101,102,32,69,76,83,95,67,79,78,70,95,84,79,75,69,78,95,69,78,92,110,34,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,39,115,116,97,116,105,99,32,99,111,110,115,116,32,99,104,97,114,32,76,105,98,83,99,114,105,112,116,91,93,61,123,92,110,39,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,119,105,116,104,32,110,111,116,32,102,105,110,46,101,111,102,40,41,32,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,116,109,112,32,61,32,102,105,110,46,108,105,110,101,105,110,112,117,116,40,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,114,101,112,108,97,99,101,40,116,109,112,44,34,32,34,44,34,34,41,32,61,61,32,34,35,33,101,110,100,34,32,58,32,32,32,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,98,114,101,97,107,32,32,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,102,111,117,116,95,112,114,105,110,116,40,116,109,112,38,39,92,110,39,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,39,92,110,39,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,34,48,125,59,92,110,34,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,34,35,101,110,100,105,102,92,110,34,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,105,102,32,114,101,112,108,97,99,101,40,115,44,34,32,34,44,34,34,41,32,61,61,32,34,35,33,115,99,114,105,112,116,45,99,110,34,32,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,67,115,112,116,32,61,32,49,10, -32,32,32,32,32,32,32,32,32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,34,35,105,102,100,101,102,32,69,76,83,95,67,79,78,70,95,84,79,75,69,78,95,67,78,92,110,34,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,39,115,116,97,116,105,99,32,99,111,110,115,116,32,99,104,97,114,32,76,105,98,83,99,114,105,112,116,95,99,110,91,93,61,123,92,110,39,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,119,105,116,104,32,110,111,116,32,102,105,110,46,101,111,102,40,41,32,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,116,109,112,32,61,32,102,105,110,46,108,105,110,101,105,110,112,117,116,40,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,114,101,112,108,97,99,101,40,116,109,112,44,34,32,34,44,34,34,41,32,61,61,32,34,35,33,101,110,100,34,32,58,32,32,32,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,98,114,101,97,107,32,32,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,102,111,117,116,95,112,114,105,110,116,40,116,109,112,38,39,92,110,39,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,39,92,110,39,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,34,48,125,59,92,110,34,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,34,35,101,110,100,105,102,92,110,34,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,105,102,32,114,101,112,108,97,99,101,40,115,44,34,32,34,44,34,34,41,32,61,61,32,34,35,33,100,101,99,108,97,114,101,34,32,58,32,32,32,10, -32,32,32,32,32,32,32,32,32,32,32,32,119,105,116,104,32,110,111,116,32,102,105,110,46,101,111,102,40,41,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,116,109,112,32,61,32,102,105,110,46,108,105,110,101,105,110,112,117,116,40,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,114,101,112,108,97,99,101,40,116,109,112,44,34,32,34,44,34,34,41,32,61,61,32,34,35,33,101,110,100,34,32,32,58,32,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,98,114,101,97,107,32,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,32,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,102,111,114,32,105,32,61,32,49,44,108,101,110,103,116,104,40,116,109,112,41,32,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,109,105,100,40,116,109,112,44,105,44,49,41,32,61,61,32,34,35,34,32,58,32,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,34,47,47,32,34,38,116,109,112,38,39,92,110,39,41,32,32,32,32,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,109,105,100,40,116,109,112,44,105,44,49,41,32,61,61,32,34,40,34,32,58,32,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,34,105,110,116,32,69,76,83,65,80,73,95,34,38,112,97,99,107,38,34,95,34,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,114,101,112,108,97,99,101,40,109,105,100,40,116,109,112,44,49,44,105,45,49,41,44,34,32,34,44,34,34,41,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,34,40,101,108,115,95,86,109,79,98,106,42,32,118,109,41,59,32,34,41,32,32,32,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,34,47,47,32,34,38,116,109,112,38,39,92,110,39,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,76,105,98,115,91,114,101,112,108,97,99,101,40,109,105,100,40,116,109,112,44,49,44,105,45,49,41,44,34,32,34,44,34,34,41,93,61,32,34,69,76,83,65,80,73,95,34,38,112,97,99,107,38,34,95,34,38,114,101,112,108,97,99,101,40,109,105,100,40,116,109,112,44,49,44,105,45,49,41,44,34,32,34,44,34,34,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,98,114,101,97,107,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -10, -32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,34,118,111,105,100,32,69,108,115,76,105,98,95,34,38,112,97,99,107,38,34,95,108,105,98,105,110,105,116,40,101,108,115,95,86,109,79,98,106,32,42,118,109,41,123,92,110,34,41,32,10, -32,32,32,32,102,111,114,32,110,97,109,101,44,102,117,110,99,32,105,110,32,76,105,98,115,32,58,10, -32,32,32,32,32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,34,92,116,118,109,95,114,101,103,105,115,116,101,114,40,118,109,44,34,38,39,34,39,38,110,97,109,101,38,39,34,44,39,38,102,117,110,99,38,34,41,59,92,110,34,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,105,102,32,83,112,116,32,61,61,32,49,32,58,32,10, -32,32,32,32,32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,34,92,116,35,105,102,100,101,102,32,69,76,83,95,67,79,78,70,95,84,79,75,69,78,95,69,78,92,110,34,41,10, -32,32,32,32,32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,34,92,116,92,116,118,109,95,100,111,115,116,114,105,110,103,40,118,109,44,76,105,98,83,99,114,105,112,116,41,59,92,110,34,41,32,32,32,10, -32,32,32,32,32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,34,92,116,35,101,110,100,105,102,92,110,34,41,32,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,105,102,32,67,115,112,116,32,61,61,32,49,32,58,32,10, -32,32,32,32,32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,34,92,116,35,105,102,100,101,102,32,69,76,83,95,67,79,78,70,95,84,79,75,69,78,95,67,78,92,110,34,41,10, -32,32,32,32,32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,34,92,116,92,116,118,109,95,100,111,115,116,114,105,110,103,40,118,109,44,76,105,98,83,99,114,105,112,116,95,99,110,41,59,92,110,34,41,32,32,32,32,10, -32,32,32,32,32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,34,92,116,35,101,110,100,105,102,92,110,34,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,34,125,59,92,110,34,41,10, -32,32,32,32,102,105,110,46,99,108,111,115,101,40,41,10, -32,32,32,32,102,111,117,116,46,99,108,111,115,101,40,41,10, -10, -32,32,32,32,35,32,118,97,114,32,102,111,117,116,32,61,32,102,105,108,101,46,111,112,101,110,40,102,110,32,38,32,39,46,99,39,44,39,114,39,41,10, -32,32,32,32,35,32,105,102,32,110,111,116,32,102,111,117,116,32,58,10, -32,32,32,32,35,32,32,32,32,32,102,111,117,116,32,61,32,102,105,108,101,46,111,112,101,110,40,102,110,32,38,32,39,46,99,39,44,39,119,39,41,32,105,102,32,33,102,111,117,116,32,58,32,116,104,114,111,119,40,34,-24,-66,-109,-27,-121,-70,-26,-106,-121,-28,-69,-74,32,34,32,38,32,32,102,110,32,32,38,32,39,46,99,39,32,38,32,34,32,-26,-119,-109,-27,-68,-128,-27,-92,-79,-24,-76,-91,34,41,32,59,10, -32,32,32,32,35,32,32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,39,35,105,110,99,108,117,100,101,32,34,39,38,112,97,99,107,38,39,46,104,34,92,110,39,41,10, -32,32,32,32,35,32,32,32,32,32,102,111,114,32,110,97,109,101,44,102,117,110,99,32,105,110,32,76,105,98,115,32,58,10, -32,32,32,32,35,32,32,32,32,32,32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,34,105,110,116,32,34,38,102,117,110,99,38,34,40,101,108,115,95,86,109,79,98,106,42,32,118,109,41,92,110,123,92,110,47,47,32,-24,-65,-103,-23,-121,-116,-27,-95,-85,-27,-122,-103,65,80,73,-27,-121,-67,-26,-107,-80,-25,-102,-124,32,67,32,-27,-82,-98,-25,-114,-80,92,110,125,92,110,34,41,10, -32,32,32,32,35,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,35,32,32,32,32,32,102,111,117,116,46,99,108,111,115,101,40,41,10, -32,32,32,32,35,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,10, -32,32,32,32,112,114,105,110,116,40,39,100,111,110,101,39,41,10, -32,32,32,32,112,97,115,115,10, -10, -100,101,102,32,76,112,116,46,99,111,110,102,46,112,114,111,40,102,110,41,58,10, -32,32,32,32,105,102,32,101,118,97,108,40,102,110,44,49,41,33,61,48,58,10, -32,32,32,32,32,32,32,32,76,112,116,46,101,114,114,111,114,40,34,-23,-108,-103,-24,-81,-81,-25,-102,-124,-27,-73,-91,-25,-88,-117,-26,-88,-95,-26,-99,-65,34,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -10, -32,32,32,32,118,97,114,32,102,111,117,116,32,61,32,102,105,108,101,46,111,112,101,110,40,34,101,108,115,95,108,105,98,108,111,97,100,46,104,34,44,34,119,34,41,32,10, -32,32,32,32,105,102,32,110,111,116,32,102,111,117,116,32,58,32,10, -32,32,32,32,32,32,32,32,76,112,116,46,101,114,114,111,114,40,34,-26,-106,-121,-28,-69,-74,-26,-119,-109,-27,-68,-128,-27,-92,-79,-24,-76,-91,34,41,32,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,10, -32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,39,35,105,110,99,108,117,100,101,32,34,101,108,115,46,104,34,92,110,39,41,10, -32,32,32,32,10, -32,32,32,32,102,111,114,32,110,97,109,101,44,111,98,106,32,105,110,32,112,114,111,106,101,99,116,58,10, -32,32,32,32,32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,34,101,120,116,101,114,110,32,118,111,105,100,32,69,108,115,76,105,98,95,34,38,110,97,109,101,38,34,95,108,105,98,105,110,105,116,40,101,108,115,95,86,109,79,98,106,32,42,118,109,41,59,92,110,34,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,10, -32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,39,115,116,114,117,99,116,123,92,110,99,104,97,114,32,42,110,97,109,101,59,92,110,118,111,105,100,32,40,42,102,117,110,99,41,40,101,108,115,95,86,109,79,98,106,32,42,118,109,41,59,92,110,125,99,111,110,115,116,32,101,108,115,95,108,105,98,108,111,97,100,95,97,108,108,108,105,98,91,93,61,123,92,110,39,41,10, -32,32,32,32,10, -32,32,32,32,102,111,114,32,110,97,109,101,44,111,98,106,32,105,110,32,112,114,111,106,101,99,116,58,10, -32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,99,111,110,102,105,103,32,34,38,110,97,109,101,38,39,46,46,46,46,46,46,92,116,39,41,10, -32,32,32,32,32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,39,123,34,39,32,38,110,97,109,101,38,32,39,34,44,69,108,115,76,105,98,95,39,32,32,38,32,110,97,109,101,32,38,32,39,95,108,105,98,105,110,105,116,125,44,92,110,39,41,10, -32,32,32,32,32,32,32,32,76,112,116,46,99,111,110,102,46,115,114,99,40,111,98,106,44,110,97,109,101,41,10, -32,32,32,32,32,32,32,32,112,114,105,110,116,40,39,100,111,110,101,39,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,39,125,59,92,110,39,41,10, -32,32,32,32,102,111,117,116,46,99,108,111,115,101,40,41,10, -32,32,32,32,112,97,115,115,10, -10, -10, -100,101,102,32,76,112,116,46,111,115,46,100,111,119,110,108,111,97,100,40,117,114,108,44,111,98,106,41,58,10, -32,32,32,32,114,101,116,117,114,110,32,119,103,101,116,40,117,114,108,44,111,98,106,41,10, -32,32,32,32,112,97,115,115,10, -10, -100,101,102,32,76,112,116,46,111,115,46,109,107,100,105,114,40,100,105,114,41,58,10, -32,32,32,32,114,101,116,117,114,110,32,109,107,100,105,114,40,100,105,114,41,10, -32,32,32,32,112,97,115,115,10, -10, -100,101,102,32,76,112,116,46,111,115,46,114,109,102,105,108,101,40,102,110,41,58,10, -32,32,32,32,114,101,116,117,114,110,32,114,109,102,105,108,101,40,102,110,41,10, -32,32,32,32,112,97,115,115,10, -10, -10, -35,32,-28,-72,-69,-27,-121,-67,-26,-107,-80,10, -100,101,102,32,109,97,105,110,40,97,114,103,99,44,97,114,103,118,41,58,10, -32,32,32,32,105,102,32,97,114,103,99,40,41,61,61,49,58,10, -32,32,32,32,32,32,32,32,105,102,32,97,114,103,118,40,49,41,61,61,34,117,112,100,97,116,101,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,76,112,116,46,97,114,103,118,46,117,112,100,97,116,101,40,41,10, -32,32,32,32,32,32,32,32,101,108,105,102,32,97,114,103,118,40,49,41,61,61,34,117,112,103,114,97,100,101,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,76,112,116,46,97,114,103,118,46,117,112,103,114,97,100,101,40,41,10, -32,32,32,32,32,32,32,32,101,108,105,102,32,97,114,103,118,40,49,41,61,61,34,97,117,116,111,114,101,109,111,118,101,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,76,112,116,46,97,114,103,118,46,97,117,116,111,114,101,109,111,118,101,40,41,10, -32,32,32,32,32,32,32,32,101,108,105,102,32,97,114,103,118,40,49,41,61,61,34,108,105,115,116,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,76,112,116,46,97,114,103,118,46,108,105,115,116,40,41,10, -32,32,32,32,32,32,32,32,101,108,105,102,32,97,114,103,118,40,49,41,61,61,34,104,101,108,112,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,76,112,116,46,97,114,103,118,46,104,101,108,112,40,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,101,108,105,102,32,97,114,103,99,40,41,61,61,50,58,10, -32,32,32,32,32,32,32,32,105,102,32,97,114,103,118,40,49,41,61,61,34,117,112,103,114,97,100,101,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,76,112,116,46,97,114,103,118,46,117,112,103,114,97,100,101,40,97,114,103,118,40,50,41,41,10, -32,32,32,32,32,32,32,32,101,108,105,102,32,97,114,103,118,40,49,41,61,61,34,97,117,116,111,114,101,109,111,118,101,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,76,112,116,46,97,114,103,118,46,97,117,116,111,114,101,109,111,118,101,40,97,114,103,118,40,50,41,41,10, -10, -32,32,32,32,32,32,32,32,101,108,105,102,32,97,114,103,118,40,49,41,61,61,34,105,110,115,116,97,108,108,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,76,112,116,46,97,114,103,118,46,105,110,115,116,97,108,108,40,97,114,103,118,40,50,41,41,10, -32,32,32,32,32,32,32,32,101,108,105,102,32,97,114,103,118,40,49,41,61,61,34,114,101,109,111,118,101,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,76,112,116,46,97,114,103,118,46,114,101,109,111,118,101,40,97,114,103,118,40,50,41,41,10, -32,32,32,32,32,32,32,32,10, -32,32,32,32,32,32,32,32,101,108,105,102,32,97,114,103,118,40,49,41,61,61,34,115,101,97,114,99,104,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,76,112,116,46,97,114,103,118,46,115,101,97,114,99,104,40,97,114,103,118,40,50,41,41,10, -32,32,32,32,32,32,32,32,101,108,105,102,32,97,114,103,118,40,49,41,61,61,34,119,105,107,105,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,76,112,116,46,97,114,103,118,46,119,105,107,105,40,97,114,103,118,40,50,41,41,10, -32,32,32,32,32,32,32,32,101,108,105,102,32,97,114,103,118,40,49,41,61,61,34,115,104,111,119,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,76,112,116,46,97,114,103,118,46,115,104,111,119,40,97,114,103,118,40,50,41,41,10, -32,32,32,32,32,32,32,32,101,108,105,102,32,97,114,103,118,40,49,41,61,61,34,115,111,117,114,99,101,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,76,112,116,46,97,114,103,118,46,115,111,117,114,99,101,40,97,114,103,118,40,50,41,41,10, -32,32,32,32,32,32,32,32,101,108,105,102,32,97,114,103,118,40,49,41,61,61,34,99,108,111,110,101,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,76,112,116,46,97,114,103,118,46,99,108,111,110,101,40,97,114,103,118,40,50,41,41,10, -32,32,32,32,32,32,32,32,101,108,105,102,32,97,114,103,118,40,49,41,61,61,34,99,111,110,102,115,114,99,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,118,97,114,32,80,97,99,107,110,97,109,101,32,61,32,34,34,10, -32,32,32,32,32,32,32,32,32,32,32,32,118,97,114,32,95,97,114,103,118,32,61,32,114,101,112,108,97,99,101,40,97,114,103,118,40,50,41,44,34,92,92,34,44,34,47,34,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,116,109,112,32,61,32,115,116,114,116,111,107,40,95,97,114,103,118,44,34,47,34,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,119,105,116,104,32,49,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,80,97,99,107,110,97,109,101,32,61,32,116,109,112,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,116,109,112,32,61,32,115,116,114,116,111,107,40,110,117,108,108,44,34,47,34,41,32,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,116,109,112,32,61,61,32,34,34,58,32,98,114,101,97,107,32,59,10, -32,32,32,32,32,32,32,32,32,32,32,32,59,10, -32,32,32,32,32,32,32,32,32,32,32,32,76,112,116,46,99,111,110,102,46,115,114,99,40,97,114,103,118,40,50,41,44,80,97,99,107,110,97,109,101,41,10, -32,32,32,32,32,32,32,32,101,108,105,102,32,97,114,103,118,40,49,41,61,61,34,99,111,110,102,112,114,111,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,76,112,116,46,99,111,110,102,46,112,114,111,40,97,114,103,118,40,50,41,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,101,108,105,102,32,97,114,103,99,40,41,61,61,51,58,10, -32,32,32,32,32,32,32,32,105,102,32,97,114,103,118,40,49,41,61,61,34,105,110,115,116,97,108,108,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,76,112,116,46,97,114,103,118,46,105,110,115,116,97,108,108,40,97,114,103,118,40,50,41,44,97,114,103,118,40,51,41,41,10, -32,32,32,32,32,32,32,32,101,108,105,102,32,97,114,103,118,40,49,41,61,61,34,114,101,109,111,118,101,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,76,112,116,46,97,114,103,118,46,114,101,109,111,118,101,40,97,114,103,118,40,50,41,44,97,114,103,118,40,51,41,41,10, -32,32,32,32,32,32,32,32,101,108,105,102,32,97,114,103,118,40,49,41,61,61,34,115,111,117,114,99,101,34,58,32,10, -32,32,32,32,32,32,32,32,32,32,32,32,76,112,116,46,97,114,103,118,46,115,111,117,114,99,101,40,97,114,103,118,40,50,41,44,97,114,103,118,40,51,41,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,101,108,115,101,10, -32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,76,112,116,32,45,45,32,76,111,115,117,32,80,97,99,107,97,103,101,115,32,84,111,111,108,32,44,32,-24,-66,-109,-27,-123,-91,32,104,101,108,112,32,-27,-113,-126,-26,-107,-80,-26,-97,-91,-25,-100,-117,-28,-67,-65,-25,-108,-88,-27,-72,-82,-27,-118,-87,34,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,112,97,115,115,10, -10, -109,97,105,110,40,97,114,103,99,44,97,114,103,118,41,10, -10, -10, -0}; -#endif -void ElsLib_lpt_libinit(els_VmObj *vm){ - vm_register(vm,"mkdir",ELSAPI_lpt_mkdir); - vm_register(vm,"wget",ELSAPI_lpt_wget); - vm_register(vm,"rmfile",ELSAPI_lpt_rmfile); - #ifdef ELS_CONF_TOKEN_EN - vm_dostring(vm,LibScript); - #endif -}; diff --git a/lpt/readme.md b/lpt/readme.md deleted file mode 100755 index aac24b511de64949d06a3ba0aed299e58250b5f3..0000000000000000000000000000000000000000 --- a/lpt/readme.md +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/owls.wiki.losu.tech -# lpt 模块管理工具 Wiki -## 简介 -Lpt (Losu Packages Tool),洛书模块管理工具,是一款轻量高效的跨平台模块管理器,支持模块的下载,安装,查找,升级,卸载,更新,接口胶水生成等多种功能 -## 可用功能 -+ 运行方法 -``` -losu -r lpt [参数列表] -``` -```sh -lpt help # 查看帮助文档 -lpt update # 下载远程列表,检测更新 -lpt upgrade # 自动化更新 -lpt list # 列举已安装的模块 - - -lpt install [模块名] # 安装模块 -lpt remove [模块名] # 卸载模块 -lpt autoremove # 卸载所有被废弃的模块 - -lpt search [关键字] # 查找并列举所有相关的模块 -lpt show [模块] # 显示模块的详细信息 -lpt wiki [模块] # 下载模块的readme文件 - -lpt source [模块] [可选/分支] # 拉取模块源代码 -lpt confsrc [文件] # 根据脚本文件生成 C/C++ 接口 -lpt confpro [文件] # 根据工程文件批量生成 C/C++ 接口 - -``` -## 使用方法 -+ [视频教程]() diff --git a/lsmath/Ubuntu/makefile b/lsmath/Ubuntu/makefile deleted file mode 100755 index ff95a655f5078cc904797e801c80d2c051791f2f..0000000000000000000000000000000000000000 --- a/lsmath/Ubuntu/makefile +++ /dev/null @@ -1,13 +0,0 @@ -OBJS = lsmath.o -CFLAGS= -O2 -Wall -std=c99 -DLOSU_LINUX -I ../buildenv -fPIC -CC=x86_64-linux-gnu-gcc -T=./ElsLib_lsmath.lsd - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -shared -lm -s - -clean: - rm -rf $T $(OBJS) core core.* \ No newline at end of file diff --git a/lsmath/Windows/makefile b/lsmath/Windows/makefile deleted file mode 100755 index ee272180ddbe257afe10df7935ea9ac37d2d8149..0000000000000000000000000000000000000000 --- a/lsmath/Windows/makefile +++ /dev/null @@ -1,13 +0,0 @@ -OBJS = lsmath.o -CFLAGS= -O2 -Wall -std=c99 -DLOSU_WINDOWS -I ../buildenv -fPIC -CC=x86_64-w64-mingw32-gcc -T=ElsLib_lsmath.lsd - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -L ../buildenv -l:libeasylosu.dll -lm -static -shared -s - -clean: - rm -rf lsmath.o \ No newline at end of file diff --git a/lsmath/info b/lsmath/info deleted file mode 100755 index b023320ab12fe32694c9677522b0db4100661396..0000000000000000000000000000000000000000 --- a/lsmath/info +++ /dev/null @@ -1,25 +0,0 @@ -{ - info = { - name = "lsmath/数学拓展库", - text = "stdmath的拓展模块", - version = "23.11.11" - }, - source = { - all = { - "lsmath.c", - "lsmath.h", - "lsmath.els", - "readme.md" - }, - Ubuntu = { - "makefile", - }, - Windows = { - "makefile", - } - }, - target = { - Ubuntu = "make ; cp ElsLib_lsmath.lsd target/ElsLib_lsmath.lsd_Ubuntu ; make clean", - Windows = "make ; cp ElsLib_lsmath.lsd target/ElsLib_lsmath.lsd_Windows ; make clean", - } -} \ No newline at end of file diff --git a/lsmath/lsmath.c b/lsmath/lsmath.c deleted file mode 100755 index d9415dc0756f3bb2f19c5de0356072e4dd1c9f42..0000000000000000000000000000000000000000 --- a/lsmath/lsmath.c +++ /dev/null @@ -1,444 +0,0 @@ -#include "lsmath.h" -#include - -#define PI 3.141592653589793 -#define E 2.718281828459045 -#define GAMMA 0.577215664901532 - -// # 常量定义 -int ELSAPI_lsmath_PI(els_VmObj* vm){ - /* - 返回π(圆周率)的值 - - # 参数 - 无参数 - - # 返回值 - 1.π - */ - arg_returnnum(vm, PI); - return 1; -} -int ELSAPI_lsmath_E(els_VmObj* vm){ - /* - 返回e(自然常数)的值 - - # 参数 - 无参数 - - # 返回值 - 1.e - */ - arg_returnnum(vm, E); - return 1; -} -int ELSAPI_lsmath_GAMMA(els_VmObj* vm){ - /* - 返回gamma(欧拉常数)的值 - - # 参数 - 无参数 - - # 返回值 - 1.gamma - */ - arg_returnnum(vm, GAMMA); - return 1; -} - -// #标准数学函数 -// #杂项函数 -int ELSAPI_lsmath_abs(els_VmObj *vm){ - arg_returnnum(vm,fabs(arg_getnum(vm,1))); - return 1; -} - -int ELSAPI_lsmath_mod(els_VmObj *vm){ - arg_returnnum(vm,((long int)arg_getnum(vm,1)%(long int)arg_getnum(vm,2))); - return 1; -} - -int ELSAPI_lsmath_sqrt(els_VmObj *vm){ - arg_returnnum(vm,sqrt(arg_getnum(vm,1))); - return 1; -} - -int ELSAPI_lsmath_anyroot(els_VmObj* vm){ - /* - 若要开num的i次方,即求num的(1 / i)次方 - 根据换底公式,num = exp(log(num)) - 则num ^ (1 /i) = exp(log(num)) ^ (1 / i) = exp((1 / i) * log(num)) - - # 参数 - 1. num: number 要被开方的数 - 2. i: int 要开的次方 - - # 返回值 - 1. output: float 一个近似根 - */ - if (arg_gettype(vm, 1)==ELS_API_TYPE_NUMBER && arg_gettype(vm, 2)==ELS_API_TYPE_NUMBER) - { - //类型检查合格的情况 - double num = arg_getnum(vm, 1); - double i = (int)arg_getnum(vm, 2); - double output = exp((1 / i) * log(num)); - - arg_returnnum(vm, output); - - } - else - arg_returnnull(vm); - return 1; -} - -int ELSAPI_lsmath_gcd(els_VmObj* vm) -{ - /* - gcd( a:int, b:int ): int 返回整数a和b的最大公约数 - - 根据辗转相除法,若f(a, b)表示整数a和b的最大公约数,则有 - f(a, b) = f(b, a mod b) - */ - if (arg_gettype(vm, 1) == ELS_API_TYPE_NUMBER && arg_gettype(vm, 2) == ELS_API_TYPE_NUMBER) - { - long long a = arg_getnum(vm, 1); - long long b = arg_getnum(vm, 2); - long long mid; - - while (b!=0) - { - mid = a; - a = b; - b = mid % b; - } - - arg_returnnum(vm, a); - } - else - arg_returnnull(vm); - return 1; -} -// #三角函数 -int ELSAPI_lsmath_acos(els_VmObj *vm){ - arg_returnnum(vm,acos(arg_getnum(vm,1))); - return 1; -} - -int ELSAPI_lsmath_asin(els_VmObj *vm){ - arg_returnnum(vm,asin(arg_getnum(vm,1))); - return 1; -} - -int ELSAPI_lsmath_atan(els_VmObj *vm){ - arg_returnnum(vm,atan(arg_getnum(vm,1))); - return 1; -} - -int ELSAPI_lsmath_cos(els_VmObj *vm){ - arg_returnnum(vm,cos(arg_getnum(vm,1))); - return 1; -} - -int ELSAPI_lsmath_sin(els_VmObj *vm){ - arg_returnnum(vm,sin(arg_getnum(vm,1))); - return 1; -} - -int ELSAPI_lsmath_tan(els_VmObj *vm){ - arg_returnnum(vm,tan(arg_getnum(vm,1))); - return 1; -} - -int ELSAPI_lsmath_exp(els_VmObj *vm){ - arg_returnnum(vm,exp(arg_getnum(vm,1))); - return 1; -} - -int ELSAPI_lsmath_log(els_VmObj *vm){ - /* - 返回以a为底N的对数 - 根据换底公式,若f(x)=ln(x),则logaN可表示为 - f(a) / f(N) - - # 参数 - 1.a 底数 - 2.N 真数 - - # 返回值 - 1.x 对数 - */ - double a = arg_getnum(vm, 1); - double N = arg_getnum(vm, 2); - arg_returnnum(vm, log(a) / log(N)); - return 1; -} - -int ELSAPI_lsmath_ln(els_VmObj *vm){ - arg_returnnum(vm,log(arg_getnum(vm,1))); - return 1; -} - -int ELSAPI_lsmath_lg(els_VmObj *vm){ - arg_returnnum(vm,log10(arg_getnum(vm,1))); - return 1; -} - -// #取整函数 -int ELSAPI_lsmath_ceil(els_VmObj *vm){ - arg_returnnum(vm,ceil(arg_getnum(vm,1))); - return 1; -} - -int ELSAPI_lsmath_floor(els_VmObj *vm){ - arg_returnnum(vm,floor(arg_getnum(vm,1))); - return 1; -} - -int ELSAPI_lsmath_round(els_VmObj *vm){ - /* - 调用math.h中的double round(double)函数,用于四舍五入 - 从洛书处接收要四舍五入的数 - */ - arg_returnnum(vm, (double)round(arg_getnum(vm, 1))); - return 1; -} - -int ELSAPI_lsmath_cut(els_VmObj *vm){ - /* - 截取小数点后若干位的函数 - - # 参数 - 从洛书处接受两个参数 - 1.num 被截取的数 - 2.x 要保留的位数 - */ - double num = arg_getnum(vm, 1); - int x = arg_getnum(vm, 2); - x = pow(10, x); - arg_returnnum(vm, (double)(long long)(num * x) / x); - return 1; -} - -// #位运算 -int ELSAPI_lsmath_move_left(els_VmObj* vm) -{ - /* - # 参数 - 1. num: int - 2. n: int - */ - if (arg_gettype(vm, 1)==ELS_API_TYPE_NUMBER && arg_gettype(vm, 2)==ELS_API_TYPE_NUMBER) - { - long long num = arg_getnum(vm, 1); - long long n = arg_getnum(vm, 2); - long long result = num << n; - arg_returnnum(vm, result); - } - else - arg_returnnull(vm); - return 1; -} -int ELSAPI_lsmath_move_right(els_VmObj* vm) -{ - /* - # 参数 - 1. num: int - 2. n: int - */ - if (arg_gettype(vm, 1)==ELS_API_TYPE_NUMBER && arg_gettype(vm, 2)==ELS_API_TYPE_NUMBER) - { - long long num = arg_getnum(vm, 1); - long long n = arg_getnum(vm, 2); - long long result = num >> n; - arg_returnnum(vm, result); - } - else - arg_returnnull(vm); - return 1; -} - -int ELSAPI_lsmath_bitwise_and(els_VmObj* vm) -{ - /* - # 参数 - 1. num: int - 2. n: int - */ - if (arg_gettype(vm, 1)==ELS_API_TYPE_NUMBER && arg_gettype(vm, 2)==ELS_API_TYPE_NUMBER) - { - long long num = arg_getnum(vm, 1); - long long n = arg_getnum(vm, 2); - long long result = num & n; - arg_returnnum(vm, result); - } - else - arg_returnnull(vm); - return 1; -} - -int ELSAPI_lsmath_bitwise_or(els_VmObj* vm) -{ - /* - # 参数 - 1. num: int - 2. n: int - */ - if (arg_gettype(vm, 1)==ELS_API_TYPE_NUMBER && arg_gettype(vm, 2)==ELS_API_TYPE_NUMBER) - { - long long num = arg_getnum(vm, 1); - long long n = arg_getnum(vm, 2); - long long result = num | n; - arg_returnnum(vm, result); - } - else - arg_returnnull(vm); - return 1; -} - -int ELSAPI_lsmath_bitwise_not(els_VmObj* vm) -{ - /* - # 参数 - 1. num: int - */ - if (arg_gettype(vm, 1)==ELS_API_TYPE_NUMBER && arg_gettype(vm, 2)==ELS_API_TYPE_NUMBER) - { - long long num = arg_getnum(vm, 1); - long long result = ~num; - arg_returnnum(vm, result); - } - else - arg_returnnull(vm); - return 1; -} - -int ELSAPI_lsmath_bitwise_xor(els_VmObj* vm) -{ - /* - # 参数 - 1. num: int - 2. n: int - */ - if (arg_gettype(vm, 1)==ELS_API_TYPE_NUMBER && arg_gettype(vm, 2)==ELS_API_TYPE_NUMBER) - { - long long num = arg_getnum(vm, 1); - long long n = arg_getnum(vm, 2); - long long result = num ^ n; - arg_returnnum(vm, result); - } - else - arg_returnnull(vm); - return 1; -} - -// #数组运算 -int ELSAPI_lsmath_sum(els_VmObj* vm) -{ - /* - 目前的实现是,从1开始遍历单元,直至索引到的值为空 - - # 参数 - 1. u unit - - #返回值 - 1. u中从1开始到索引为0时的所有数字之和 - */ - if (arg_gettype(vm, 1)==ELS_API_TYPE_UNIT) - { - LosuObj *unit = arg_get(vm, 1); - LosuObj key; - LosuObj *val; - double output = 0; - unsigned int index = 1; - - for (;;) - { - key = obj_newnum(vm, index); - val = obj_indexunit(vm, *unit, key); - - if (obj_type(vm, val)==ELS_API_TYPE_NULL) - break; - if (obj_type(vm, val)==ELS_API_TYPE_NUMBER) - output += obj_tonum(vm, val); - index++; - } - arg_returnnum(vm, output); - } - else - arg_returnnull(vm); - return 1; -} - -int ELSAPI_lsmath_even(els_VmObj* vm) -{ - if (arg_gettype(vm, 1)==ELS_API_TYPE_UNIT) - { - LosuObj *unit = arg_get(vm, 1); - LosuObj key; - LosuObj *val; - double output = 0; - unsigned int index = 0; - - for (;;) - { - key = obj_newnum(vm, index+1); - val = obj_indexunit(vm, *unit, key); - - if (obj_type(vm, val)==ELS_API_TYPE_NULL) - break; - if (obj_type(vm, val)==ELS_API_TYPE_NUMBER) - output += obj_tonum(vm, val); - index++; - } - - if (index==0) - arg_returnnum(vm, 0); - else - arg_returnnum(vm, output / (double)(index)); - } - else - arg_returnnull(vm); - return 1; -} - -int ELSAPI_lsmath_degree(els_VmObj* vm) -{ - /* - 将弧度制转化为角度制 - - # 参数 - 1. x 角度制的数 - - # 返回值 - 1. 转化为弧度制后 - */ - if (arg_gettype(vm, 1) == ELS_API_TYPE_NUMBER) - { - double x = arg_getnum(vm, 1); - arg_returnnum(vm, x * 180 / PI); - } - else - arg_returnnull(vm); - return 1; -} - -int ELSAPI_lsmath_radian(els_VmObj* vm) -{ - /* - 将角度制转化为弧度制 - - # 参数 - 1. x 弧度制的数 - - # 返回值 - 1. 转化为角度制后 - */ - if (arg_gettype(vm, 1) == ELS_API_TYPE_NUMBER) - { - double x = arg_getnum(vm, 1); - arg_returnnum(vm, x * PI / 180); - } - else - arg_returnnull(vm); - return 1; -} \ No newline at end of file diff --git a/lsmath/lsmath.els b/lsmath/lsmath.els deleted file mode 100755 index d8b2acd9b2466060520b0ec3f49061883362cbc5..0000000000000000000000000000000000000000 --- a/lsmath/lsmath.els +++ /dev/null @@ -1,73 +0,0 @@ -#!declare -# 常量定义 -PI(): float 返回π的值 -E(): float 返回e的值 -GAMMA(): float 返回γ(欧拉常数)的值 -#标准数学函数 - #杂项函数 -abs( num ) 返回数的绝对值 -mod( a, b ) 返回a mod b的结果 -sqrt( num:number ): float 返回num的平方根 -anyroot( num:number, n:int ): float 返回对num开n次方的一个近似根 -gcd( a:int, b:int ): int 返回整数a和b的最大公约数 - - #三角函数 -acos( x ) 返回以弧度表示的x的反余弦 -asin( x ) 返回以弧度表示的x的反正弦 -atan( x ) 返回以弧度表示的x的反正切 -cos( x ) 返回x的余弦值 -sin( x ) 返回x的正弦值 -tan( x ) 返回x的正切值 - - #对数函数 -exp( x ) 返回e的x次幂的值 -log( a, N ) 返回以a为第N的对数 -ln( N ) 返回以e为底,N的对数 -lg( N ) 返回以10为底,N的对数 - - #取整函数 -ceil( num:float ): float 对num向上取整 -floor( num:float ): float 对num向下取整 -round( num:float ): float 将小数四舍五入成整数 -cut( num:float, x:int): float 截取小数到若干位 - - #位运算 -move_left( num:int, n:int ): int 对num左移n位 -move_right( num:int, n:int ): int 对num右移n位 -bitwise_and( a:int, b:int ): int 返回对a进行b的按位与运算结果 -bitwise_or( a:int, b:int ): int 返回对a进行b的按位或运算结果 -bitwise_not( a:int ): int 返回对a按位取反运算结果 -bitwise_xor( a:int, b:int ): int 返回对a进行b的按位异或运算结果 - - #数组运算 -sum( a:unit ): number 返回a中所有数字的和 -even( a:unit ): number 返回a中所有数字的平均数 - - #角度运算 -degree( x:number ): number 将x从弧度制转化为角度制 -radian( x:number ): number 将x从角度制转化为弧度制 -#!end - -#!script -圆周率 = PI -自然常数 = E -欧拉常数 = GAMMA - -绝对值 = abs -取模 = mod -反余弦 = acos -反正弦 = asin -反正切 = atan -余弦 = cos -正弦 = sin -正切 = tan -对数 = log - #exp起名空缺 - #ln起名空缺 - #lg起名空缺 -开平方 = sqrt -向上取整 = ceil -向下取整 = floor -四舍五入 = round -保留位数 = cut -#!end \ No newline at end of file diff --git a/lsmath/lsmath.h b/lsmath/lsmath.h deleted file mode 100755 index 956253cab281ad2b494dce9ceba731460bf6c8e4..0000000000000000000000000000000000000000 --- a/lsmath/lsmath.h +++ /dev/null @@ -1,104 +0,0 @@ -#include "els.h" -// # 常量定义 -int ELSAPI_lsmath_PI(els_VmObj* vm); // PI(): float 返回π的值 -int ELSAPI_lsmath_E(els_VmObj* vm); // E(): float 返回e的值 -int ELSAPI_lsmath_GAMMA(els_VmObj* vm); // GAMMA(): float 返回γ(欧拉常数)的值 -// #标准数学函数 -// #杂项函数 -int ELSAPI_lsmath_abs(els_VmObj* vm); // abs( num ) 返回数的绝对值 -int ELSAPI_lsmath_mod(els_VmObj* vm); // mod( a, b ) 返回a mod b的结果 -int ELSAPI_lsmath_sqrt(els_VmObj* vm); // sqrt( num:number ): float 返回num的平方根 -int ELSAPI_lsmath_anyroot(els_VmObj* vm); // anyroot( num:number, n:int ): float 返回对num开n次方的一个近似根 -int ELSAPI_lsmath_gcd(els_VmObj* vm); // gcd( a:int, b:int ): int 返回整数a和b的最大公约数 -// #三角函数 -int ELSAPI_lsmath_acos(els_VmObj* vm); // acos( x ) 返回以弧度表示的x的反余弦 -int ELSAPI_lsmath_asin(els_VmObj* vm); // asin( x ) 返回以弧度表示的x的反正弦 -int ELSAPI_lsmath_atan(els_VmObj* vm); // atan( x ) 返回以弧度表示的x的反正切 -int ELSAPI_lsmath_cos(els_VmObj* vm); // cos( x ) 返回x的余弦值 -int ELSAPI_lsmath_sin(els_VmObj* vm); // sin( x ) 返回x的正弦值 -int ELSAPI_lsmath_tan(els_VmObj* vm); // tan( x ) 返回x的正切值 -// #对数函数 -int ELSAPI_lsmath_exp(els_VmObj* vm); // exp( x ) 返回e的x次幂的值 -int ELSAPI_lsmath_log(els_VmObj* vm); // log( a, N ) 返回以a为第N的对数 -int ELSAPI_lsmath_ln(els_VmObj* vm); // ln( N ) 返回以e为底,N的对数 -int ELSAPI_lsmath_lg(els_VmObj* vm); // lg( N ) 返回以10为底,N的对数 -// #取整函数 -int ELSAPI_lsmath_ceil(els_VmObj* vm); // ceil( num:float ): float 对num向上取整 -int ELSAPI_lsmath_floor(els_VmObj* vm); // floor( num:float ): float 对num向下取整 -int ELSAPI_lsmath_round(els_VmObj* vm); // round( num:float ): float 将小数四舍五入成整数 -int ELSAPI_lsmath_cut(els_VmObj* vm); // cut( num:float, x:int): float 截取小数到若干位 -// #位运算 -int ELSAPI_lsmath_move_left(els_VmObj* vm); // move_left( num:int, n:int ): int 对num左移n位 -int ELSAPI_lsmath_move_right(els_VmObj* vm); // move_right( num:int, n:int ): int 对num右移n位 -int ELSAPI_lsmath_bitwise_and(els_VmObj* vm); // bitwise_and( a:int, b:int ): int 返回对a进行b的按位与运算结果 -int ELSAPI_lsmath_bitwise_or(els_VmObj* vm); // bitwise_or( a:int, b:int ): int 返回对a进行b的按位或运算结果 -int ELSAPI_lsmath_bitwise_not(els_VmObj* vm); // bitwise_not( a:int ): int 返回对a按位取反运算结果 -int ELSAPI_lsmath_bitwise_xor(els_VmObj* vm); // bitwise_xor( a:int, b:int ): int 返回对a进行b的按位异或运算结果 -// #数组运算 -int ELSAPI_lsmath_sum(els_VmObj* vm); // sum( a:unit ): number 返回a中所有数字的和 -int ELSAPI_lsmath_even(els_VmObj* vm); // even( a:unit ): number 返回a中所有数字的平均数 -// #角度运算 -int ELSAPI_lsmath_degree(els_VmObj* vm); // degree( x:number ): number 将x从弧度制转化为角度制 -int ELSAPI_lsmath_radian(els_VmObj* vm); // radian( x:number ): number 将x从角度制转化为弧度制 -#ifdef ELS_CONF_TOKEN_EN -static const char LibScript[]={ --27,-100,-122,-27,-111,-88,-25,-114,-121,32,61,32,80,73,10, --24,-121,-86,-25,-124,-74,-27,-72,-72,-26,-107,-80,32,61,32,69,10, --26,-84,-89,-26,-117,-119,-27,-72,-72,-26,-107,-80,32,61,32,71,65,77,77,65,10, -10, --25,-69,-99,-27,-81,-71,-27,-128,-68,32,61,32,97,98,115,10, --27,-113,-106,-26,-88,-95,32,61,32,109,111,100,10, --27,-113,-115,-28,-67,-103,-27,-68,-90,32,61,32,97,99,111,115,10, --27,-113,-115,-26,-83,-93,-27,-68,-90,32,61,32,97,115,105,110,10, --27,-113,-115,-26,-83,-93,-27,-120,-121,32,61,32,97,116,97,110,10, --28,-67,-103,-27,-68,-90,32,61,32,99,111,115,10, --26,-83,-93,-27,-68,-90,32,61,32,115,105,110,10, --26,-83,-93,-27,-120,-121,32,61,32,116,97,110,10, --27,-81,-71,-26,-107,-80,32,61,32,108,111,103,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,35,101,120,112,-24,-75,-73,-27,-112,-115,-25,-87,-70,-25,-68,-70,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,35,108,110,-24,-75,-73,-27,-112,-115,-25,-87,-70,-25,-68,-70,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,35,108,103,-24,-75,-73,-27,-112,-115,-25,-87,-70,-25,-68,-70,10, --27,-68,-128,-27,-71,-77,-26,-106,-71,32,61,32,115,113,114,116,10, --27,-112,-111,-28,-72,-118,-27,-113,-106,-26,-107,-76,32,61,32,99,101,105,108,10, --27,-112,-111,-28,-72,-117,-27,-113,-106,-26,-107,-76,32,61,32,102,108,111,111,114,10, --27,-101,-101,-24,-120,-115,-28,-70,-108,-27,-123,-91,32,61,32,114,111,117,110,100,10, --28,-65,-99,-25,-107,-103,-28,-67,-115,-26,-107,-80,32,61,32,99,117,116,10, -0}; -#endif -void ElsLib_lsmath_libinit(els_VmObj *vm){ - vm_register(vm,"even",ELSAPI_lsmath_even); - vm_register(vm,"sqrt",ELSAPI_lsmath_sqrt); - vm_register(vm,"bitwise_or",ELSAPI_lsmath_bitwise_or); - vm_register(vm,"round",ELSAPI_lsmath_round); - vm_register(vm,"gcd",ELSAPI_lsmath_gcd); - vm_register(vm,"bitwise_not",ELSAPI_lsmath_bitwise_not); - vm_register(vm,"sum",ELSAPI_lsmath_sum); - vm_register(vm,"bitwise_xor",ELSAPI_lsmath_bitwise_xor); - vm_register(vm,"floor",ELSAPI_lsmath_floor); - vm_register(vm,"move_right",ELSAPI_lsmath_move_right); - vm_register(vm,"acos",ELSAPI_lsmath_acos); - vm_register(vm,"mod",ELSAPI_lsmath_mod); - vm_register(vm,"E",ELSAPI_lsmath_E); - vm_register(vm,"bitwise_and",ELSAPI_lsmath_bitwise_and); - vm_register(vm,"radian",ELSAPI_lsmath_radian); - vm_register(vm,"abs",ELSAPI_lsmath_abs); - vm_register(vm,"sin",ELSAPI_lsmath_sin); - vm_register(vm,"asin",ELSAPI_lsmath_asin); - vm_register(vm,"atan",ELSAPI_lsmath_atan); - vm_register(vm,"cut",ELSAPI_lsmath_cut); - vm_register(vm,"ceil",ELSAPI_lsmath_ceil); - vm_register(vm,"cos",ELSAPI_lsmath_cos); - vm_register(vm,"GAMMA",ELSAPI_lsmath_GAMMA); - vm_register(vm,"ln",ELSAPI_lsmath_ln); - vm_register(vm,"log",ELSAPI_lsmath_log); - vm_register(vm,"move_left",ELSAPI_lsmath_move_left); - vm_register(vm,"anyroot",ELSAPI_lsmath_anyroot); - vm_register(vm,"tan",ELSAPI_lsmath_tan); - vm_register(vm,"degree",ELSAPI_lsmath_degree); - vm_register(vm,"exp",ELSAPI_lsmath_exp); - vm_register(vm,"lg",ELSAPI_lsmath_lg); - vm_register(vm,"PI",ELSAPI_lsmath_PI); - #ifdef ELS_CONF_TOKEN_EN - vm_dostring(vm,LibScript); - #endif -}; diff --git a/lsmath/readme.md b/lsmath/readme.md deleted file mode 100755 index e778967be3c5bac9d6f1efdccc684bfea34b8453..0000000000000000000000000000000000000000 --- a/lsmath/readme.md +++ /dev/null @@ -1,132 +0,0 @@ -#!/bin/owls.wiki.losu.tech -# wiki for lsmath -## 简介 -+ lsmath是对洛书stdmath的拓展 - -## 包含的函数 - -### PI() :float -+ 中文版本名为“圆周率” -+ 返回π的值 -### E() :float -+ 中文版本名为“自然常数” -+ 返回e的值 -### GAMMA() :float -+ 中文版本名为“欧拉常数” -+ 返回γ(欧拉常数)的值 -### abs( x:number ) :number -+ 中文版本名为“绝对值” -+ 返回x的绝对值。当x大于等于0时,返回其本身,否则返回其相反数。 -### mod( a:int, b:int ): int -+ 中文版本名为“取模” -+ 返回a取模b的结果。即a除以b的余数。 -### sqrt( num:number ): number -+ 中文版本名为“开平方” -+ 返回num的平方根 -### anyroot( num:number, n:int ): number -+ 无中文版本 -+ 参数 - 1. num:number 被开方数 - 2. n:int 要开方的级数 -+ 返回值 - 1. 返回num的n次方根的一个近似值 - 2. 当类型不合法时,返回null -+ 注意 - 1. num和n的类型必须为number型 -### gcd( a:int, b:int ): int -+ 无中文版本 -+ 参数 - 1. a:int 一个任意的整数 - 2. b:int 一个任意的整数 -+ 返回值 - 1. 返回a和b的最大公约数 - 2. 当类型不合法时返回null -+ 注意 - 1. a和b的类型必须为number - 2. a和b会被转化为long long类型,即只取整数部分,抛去小数部分 -### acos( x ) -+ 中文版本名为“反余弦” -+ 返回以弧度表示的x的反余弦 -### asin( x ) -+ 中文版本名为“反正弦” -+ 返回以弧度表示的x的反正弦 -### atan( x ) -+ 中文版本名为“反正切” -+ 返回以弧度表示的x的反正切 -### cos( x ) -+ 中文版本名为“余弦” -+ 返回x的余弦值 -### sin( x ) -+ 中文版本名为“正弦” -+ 返回x的正弦值 -### tan( x ) -+ 中文版本名为“正切” -+ 返回x的正切值 -### log( a, N ) -+ 中文版本名为“对数” -+ 返回以a为底N的对数 -### exp( x ) -+ 暂无中文版本 -+ 返回e的x次幂的值 -### ln( N ) -+ 暂无中文版本 -+ 返回以e为底,N的对数 -### lg( N ) -+ 暂无中文版本 -+ 返回以10为底,N的对数 -### ceil( num ) -+ 中文版本名为“向上取整” -+ 对num向上取整 -### floor( num ) -+ 中文版本名为“向下取整” -+ 对num向下取整 -### round( num ) -+ 中文版本名为“四舍五入” -+ 将num四舍五入成整数 -### cut( num, x ) -+ 中文版本名为“保留位数” -+ 截取num到第x位小数 -### move_left( num:int, n:int ): int -+ 参数 - 1. num:int 被左移数 - 2. n:int 要左移的位数 -+ 返回值 - 1. 左移之后的结果 - 2. 如果类型检查不合格则返回null -+ 注意 - 1. num和n的类型必须为number型 - 2. num和n会被转化为long long型 - 3. 请自行防止溢出,本函数不做类似检查 -### move_right( num:int, n:int ): int -+ 参数 - 1. num:int 被右移数 - 2. n:int 要右移的位数 -+ 返回值 - 1. 右移之后的结果 - 2. 如果类型检查不合格则返回null -+ 注意 - 1. num和n的类型必须为number型 - 2. num和n会被转化为long long型 - 3. 请自行防止溢出,本函数不做类似检查 -### bitwise_and( a:int, b:int ): int -+ 返回对a进行b的按位与运算结果 -### bitwise_or( a:int, b:int ): int -+ 返回对a进行b的按位或运算结果 -### bitwise_not( a:int ): int -+ 返回对a按位取反运算结果 -### bitwise_xor( a:int, b:int ): int -+ 返回对a进行b的按位异或运算结果 -### sum( a:unit ): number -+ 返回a中所有数字的和 -### even( a:unit ): number -+ 返回a中所有数字的平均数 -### degree( x:number ): number -+ 参数 - 1. x:number 弧度制下的数字 -+ 返回值 - 1. 转化为角度制后的数据 -### radian( x:number ): number -+ 参数 - 1. x:number 角度制制下的数字 -+ 返回值 - 1. 转化为弧度制后的数据 \ No newline at end of file diff --git a/lsnput/ELS_lsnput.c b/lsnput/ELS_lsnput.c deleted file mode 100644 index db8c1189390361ee7f5db58b36fb5892050b5673..0000000000000000000000000000000000000000 --- a/lsnput/ELS_lsnput.c +++ /dev/null @@ -1,78 +0,0 @@ -#include "ELS_lsnput.h" -#include "clsnput.h" - -#include - -int ELSAPI_lsnput_GetMousePosition(els_VmObj* vm) -{ - LosuObj output = obj_newunit(vm); - MousePosition p; - - //获取鼠标位置 - GetMousePosition(&p); - obj_setunit(vm, output, obj_newstr(vm, "x"), obj_newnum(vm, p.x)); - obj_setunit(vm, output, obj_newstr(vm, "y"), obj_newnum(vm, p.y)); - - arg_return(vm, output); - return 1; -} - -int ELSAPI_lsnput_SetMousePosition(els_VmObj* vm) -{ - MousePosition p; - - //获取要设置的坐标 - p.x = arg_getnum(vm, 2); - p.y = arg_getnum(vm, 3); - - //设置鼠标位置 - if (SetMousePosition(&p)) - arg_returnnum(vm, 1); - else - arg_returnnull(vm); - - return 1; -} - -int ELSAPI_lsnput_MouseAct(els_VmObj* vm) -{ - MouseEvent e; - - e.type = (uint32_t)arg_getnum(vm, 2) | (uint32_t)arg_getnum(vm, 3); //获取鼠标事件的类型 - e.slide = arg_getnum(vm, 4); //获取滑轮滚动的距离 - - if (MouseAct(&e)) - arg_returnnum(vm, 1); - else - arg_returnnull(vm); - - return 1; -} - -int ELSAPI_lsnput_click(els_VmObj *vm) -{ - MousePosition p; - uint8_t type = arg_getnum(vm, 2); - - GetMousePosition(&p); - if (MouseClick(&p, type)) - arg_returnnum(vm, 1); - else - arg_returnnull(vm); - return 1; -} - -int ELSAPI_lsnput_lsnput_init(els_VmObj *vm) -{ - LosuObj lib = obj_newunit(vm); - - vm_setval(vm, "lsnput", lib); - - obj_setunit(vm, lib, obj_newstr(vm, "get_mouse_position"), obj_newfunction(vm, ELSAPI_lsnput_GetMousePosition)); - obj_setunit(vm, lib, obj_newstr(vm, "set_mouse_position"), obj_newfunction(vm, ELSAPI_lsnput_SetMousePosition)); - obj_setunit(vm, lib, obj_newstr(vm, "mouse_act"), obj_newfunction(vm, ELSAPI_lsnput_MouseAct)); - obj_setunit(vm, lib, obj_newstr(vm, "click"), obj_newfunction(vm, ELSAPI_lsnput_click)); - //obj_setunit(vm, lib, obj_newstr(vm, ""), obj_newfunction(vm, ELSAPI_lsnput_)); - - return 0; -} diff --git a/lsnput/ELS_lsnput.h b/lsnput/ELS_lsnput.h deleted file mode 100644 index fdb48369b07d18a7965faf30a4ec7e3283a647e5..0000000000000000000000000000000000000000 --- a/lsnput/ELS_lsnput.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef ELS_LSINPUT_H_ -#define ELS_LSINPUT_H_ - -#include "els.h" - -int ELSAPI_lsnput_GetMousePosition(els_VmObj* vm); -int ELSAPI_lsnput_SetMousePosition(els_VmObj* vm); -int ELSAPI_lsnput_MouseAct(els_VmObj* vm); -int ELSAPI_lsnput_click(els_VmObj *vm); - -#endif diff --git a/lsnput/Ubuntu/makefile b/lsnput/Ubuntu/makefile deleted file mode 100644 index f6a74478e274b2407b76debdd08a9ef8a5c06265..0000000000000000000000000000000000000000 --- a/lsnput/Ubuntu/makefile +++ /dev/null @@ -1,14 +0,0 @@ -OBJ = ElsLib_lsnput.lsd -CFLAGS= -O3 -std=c99 -Wall -DLOSU_LINUX -I ../buildenv -fPIC -CC=gcc -T=./ElsLib_lsnput.lsd - - -all: $T - -$T: - gcc ./*.c -c $(CFLAGS) - $(CC) -o $(OBJ) ./*.o -shared -lm -s -lc -O3 - -clean: - rm -rf $T ./*.o ./*.lsd \ No newline at end of file diff --git a/lsnput/WIKI/c.md b/lsnput/WIKI/c.md deleted file mode 100644 index 77d031359da3e8b2c6c5d14efb1aab074b9dd9d8..0000000000000000000000000000000000000000 --- a/lsnput/WIKI/c.md +++ /dev/null @@ -1,114 +0,0 @@ -# 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 deleted file mode 100644 index be8d8e8a6458cf7e2515c6632d3819ff732e3e7f..0000000000000000000000000000000000000000 --- a/lsnput/WIKI/script.md +++ /dev/null @@ -1,53 +0,0 @@ -# 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/1.17.0.1" "b/lsnput/WIKI/\345\216\206\345\217\262/1.17.0.1" deleted file mode 100644 index d8a8008ce1e3431ccf51e6b884dcb30eed3b4521..0000000000000000000000000000000000000000 --- "a/lsnput/WIKI/\345\216\206\345\217\262/1.17.0.1" +++ /dev/null @@ -1 +0,0 @@ -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" deleted file mode 100644 index 4e7886e7a4508a6f5a98b09b4f8a21ca371a1078..0000000000000000000000000000000000000000 --- "a/lsnput/WIKI/\345\216\206\345\217\262/1.7.0.0.md" +++ /dev/null @@ -1,6 +0,0 @@ -# 1.7.0.0 版本文档 - -这是lsnput的第一个发行版,只完成了Windows平台下的鼠标位置获取与设置、鼠标事件的设置。鼠标事件的监听和键盘系列的实现还在酝酿。 - -本模块在设计时的受众主要是Windows平台下的普通用户,并非开发者。但是C层代码为开发者精心设置了接口。这样lsnput的脚本层和C层都可以是一个跨平台的鼠标键盘处理模块,成为编程人员的好帮手。 - diff --git a/lsnput/Windows/makefile b/lsnput/Windows/makefile deleted file mode 100644 index 9f69ea7b72aa5b9a63c68a2f5bbcc96bf9e71025..0000000000000000000000000000000000000000 --- a/lsnput/Windows/makefile +++ /dev/null @@ -1,11 +0,0 @@ -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) ./*.o -c $(CFLAGE) - $(CC) -o $(OBJ) $(BASE) $(CFLAGE) - -clean: - rm -rf $T ./*.o ./*.lsd diff --git a/lsnput/clsnput.c b/lsnput/clsnput.c deleted file mode 100644 index 4c56e29a0c534478e4b355e5f7b6be018d2172ca..0000000000000000000000000000000000000000 --- a/lsnput/clsnput.c +++ /dev/null @@ -1,171 +0,0 @@ -#include "clsnput.h" - -/* - Windows系统实现 -*/ -#ifdef LOSU_WINDOWS - -#include - -inline bool GetMousePosition(MousePosition *position) -{ - /* - BOOL GetCursorPos( - [out] LPPOINT lpPoint - ); - - 检索鼠标光标的位置(以屏幕坐标为单位)。 - - 参数 - [out] lpPoint - 类型: LPPOINT - 指向接收光标屏幕坐标的 POINT 结构的指针。 - - 返回值 - 类型: BOOL - 如果成功,则返回非零值,否则返回零。 要获得更多的错误信息,请调用 GetLastError。 - - 注解 - 光标位置始终在屏幕坐标中指定,不受包含光标的窗口的映射模式的影响。 - 调用进程必须具有对窗口工作站 WINSTA_READATTRIBUTES 访问权限。 - 调用 GetCursorPos 时,输入桌面必须是当前桌面。 调用 OpenInputDesktop 以确定当前桌面是否为输入桌面。 - 如果不是,请使用 OpenInputDesktop 返回的 HDESK 调用 SetThreadDesktop 以切换到该桌面。 - */ - - bool output; - POINT pt; - - output = GetCursorPos(&pt); - position->x = pt.x; - position->y = pt.y; - - return output; -} - -inline bool SetMousePosition(MousePosition *position) -{ - /* - BOOL SetCursorPos( - [in] int X, - [in] int Y - ); - - 将光标移动到指定的屏幕坐标。 如果新坐标不在由最近的 ClipCursor 函数调用设置的屏幕矩形内,则系统会自动调整坐标,使光标停留在矩形内。 - - 参数 - [in] X - 类型: int - 光标的新 x 坐标(以屏幕坐标为单位)。 - - [in] Y - 类型: int - 光标的新 y 坐标(以屏幕坐标为单位)。 - - 返回值 - 类型: BOOL - 如果成功,则返回非零值,否则返回零。 要获得更多的错误信息,请调用 GetLastError。 - - 注解 - 游标是共享资源。 仅当光标位于窗口工作区时,窗口才应移动光标。 - 调用进程必须具有对窗口工作站 WINSTA_WRITEATTRIBUTES 访问权限。 - 调用 SetCursorPos 时,输入桌面必须是当前桌面。 调用 OpenInputDesktop 以确定当前桌面是否为输入桌面。 - 如果不是,请使用 OpenInputDesktop 返回的 HDESK 调用 SetThreadDesktop 以切换到该桌面。 - */ - return SetCursorPos(position->x, position->y); -} - -bool MouseAct(MouseEvent *event) -{ - /* - void mouse_event( - [in] DWORD dwFlags, - [in] DWORD dx, - [in] DWORD dy, - [in] DWORD dwData, - [in] ULONG_PTR dwExtraInfo - ); - - mouse_event 函数合成鼠标运动和按钮单击。 - - - */ - DWORD dwFlags, dwData; - - dwData = 0; - - switch (event->type) - { - case LSNPUT_MOUSE_LEFT | LSNPUT_MOUSE_DOWN: - //左键向下 - dwFlags = MOUSEEVENTF_LEFTDOWN; - break; - case LSNPUT_MOUSE_LEFT | LSNPUT_MOUSE_UP: - //左键向上 - dwFlags = MOUSEEVENTF_LEFTUP; - break; - case LSNPUT_MOUSE_RIGHT | LSNPUT_MOUSE_DOWN: - //右键向下 - dwFlags = MOUSEEVENTF_RIGHTDOWN; - break; - case LSNPUT_MOUSE_RIGHT | LSNPUT_MOUSE_UP: - //右键向上 - dwFlags = MOUSEEVENTF_RIGHTUP; - break; - case LSNPUT_MOUSE_MID | LSNPUT_MOUSE_DOWN: - //中键向下 - if (event->slide == 0) - //纯向下 - dwFlags = MOUSEEVENTF_MIDDLEDOWN; - else - { - //滚轮滑动 - dwFlags = MOUSEEVENTF_WHEEL; - dwData = event->slide; - } - break; - case LSNPUT_MOUSE_MID | LSNPUT_MOUSE_UP: - //中键向上 - dwFlags = MOUSEEVENTF_MIDDLEUP; - break; - default: - return false; - } - - mouse_event(dwFlags, 0, 0, dwData, 0); - - return true; -} - -#endif - -/* - Linux系统实现 -*/ - -#ifdef LOSU_LINUX - -#endif - - -/* - 通用操作系统实现 -*/ - -bool MouseClick(MousePosition *p, uint64_t type) -{ - MouseEvent e; - - e.slide = 0; - SetMousePosition(p); - - if (type & 0b00000111) - { - e.type = type | LSNPUT_MOUSE_DOWN; - MouseAct(&e); - e.type = type | LSNPUT_MOUSE_UP; - MouseAct(&e); - return true; - } - return false; -} - diff --git a/lsnput/clsnput.h b/lsnput/clsnput.h deleted file mode 100644 index 916bab81fc272d6a6bc01bec1be0ecb300d4d0c1..0000000000000000000000000000000000000000 --- a/lsnput/clsnput.h +++ /dev/null @@ -1,36 +0,0 @@ -#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/info b/lsnput/info deleted file mode 100755 index cc2cea2181ada68e8f202a7d53a1a442d5244140..0000000000000000000000000000000000000000 --- a/lsnput/info +++ /dev/null @@ -1,30 +0,0 @@ -{ - type = "pre", - info = { - name = "lsnput/键盘鼠标库", - text = "为洛书而编写的键盘鼠标控制库", - version = "24.2.9" - }, - source = { - all = { - "lsnput.h", - "lsnput.c", - "lsnput.els", - "readme.md", - "ELS_lsnput.h", - "ELS_lsnput.c", - "lsnput_script.h" - }, - # Ubuntu = { - # "makefile", - # }, - Windows = { - "makefile", - } - }, - target = { - #Ubuntu = "make ; cp ElsLib_lsnput.lsd target/ElsLib_lsnput.lsd_Ubuntu ; make clean", - Windows = "make ; cp ElsLib_lsnput.lsd target/ElsLib_lsnput.lsd_Windows ; make clean", - } -} - diff --git a/lsnput/lsnput.c b/lsnput/lsnput.c deleted file mode 100644 index e5b60a1682c37f89a914bd18f5b0bc18941a10fd..0000000000000000000000000000000000000000 --- a/lsnput/lsnput.c +++ /dev/null @@ -1 +0,0 @@ -#include "lsnput.h" \ No newline at end of file diff --git a/lsnput/lsnput.els b/lsnput/lsnput.els deleted file mode 100644 index 970555ea8b8c3ce176fe12eea9c94267de5333b7..0000000000000000000000000000000000000000 --- a/lsnput/lsnput.els +++ /dev/null @@ -1,100 +0,0 @@ -#!declare -lsnput_init() -#!end - -#!script - -import "stdlib" - -lsnput_init() - -lsnput.Mouse = {} - -lsnput.Mouse.LEFT = 1 -lsnput.Mouse.RIGHT = 2 -lsnput.Mouse.MID = 4 -lsnput.Mouse.UP = 8 -lsnput.Mouse.DOWN = 16 - -def lsnput.Mouse.class(): - """ - 鼠标类的构造函数 - """ - var this = {} - - this.where = lsnput.get_mouse_position #查询鼠标位置 - this.set = lsnput.set_mouse_position #设置鼠标位置 - - this.click = def(this, mode, t): #点击鼠标 - var type - var c = 0 - t = t or 1 - - if mode == 'left': - type = lsnput.Mouse.LEFT - elif mode == 'right': - type = lsnput.Mouse.RIGHT - elif mode == 'mid': - type = lsnput.Mouse.MID - else - type = lsnput.Mouse.LEFT - ; - - with 1: - c = c + 1 - - if c > t: - break - ; - - lsnput.click(type) - ; - - ; - - rt this -; - -令 键鼠事件 = {} - -键鼠事件.鼠标 = {} - -方法 键鼠事件.鼠标.class(): - """ - 鼠标类的构造函数 - """ - var this = {} - - this.位置 = lsnput.get_mouse_position #查询鼠标位置 - this.设置 = lsnput.set_mouse_position #设置鼠标位置 - - this.点击 = def(this, mode, t): #点击鼠标 - var type - var c = 0 - t = t or 1 - - if mode == 'left': - type = lsnput.Mouse.LEFT - elif mode == 'right': - type = lsnput.Mouse.RIGHT - elif mode == 'mid': - type = lsnput.Mouse.MID - else - type = lsnput.Mouse.LEFT - ; - - with 1: - c = c + 1 - - if c > t: - break - ; - - lsnput.click(type) - ; - - ; - - rt this -; -#!end \ No newline at end of file diff --git a/lsnput/lsnput.h b/lsnput/lsnput.h deleted file mode 100644 index f5efe3fabe84686fab5085aca5e40fe93a6dfe6f..0000000000000000000000000000000000000000 --- a/lsnput/lsnput.h +++ /dev/null @@ -1,106 +0,0 @@ -#include "els.h" -int ELSAPI_lsnput_lsnput_init(els_VmObj* vm); // lsnput_init() -#ifdef ELS_CONF_TOKEN_EN -static const char LibScript[]={ -10, -105,109,112,111,114,116,32,34,115,116,100,108,105,98,34,10, -10, -108,115,110,112,117,116,95,105,110,105,116,40,41,10, -10, -108,115,110,112,117,116,46,77,111,117,115,101,32,61,32,123,125,10, -10, -108,115,110,112,117,116,46,77,111,117,115,101,46,76,69,70,84,32,61,32,49,10, -108,115,110,112,117,116,46,77,111,117,115,101,46,82,73,71,72,84,32,61,32,50,10, -108,115,110,112,117,116,46,77,111,117,115,101,46,77,73,68,32,61,32,52,10, -108,115,110,112,117,116,46,77,111,117,115,101,46,85,80,32,61,32,56,10, -108,115,110,112,117,116,46,77,111,117,115,101,46,68,79,87,78,32,61,32,49,54,10, -10, -100,101,102,32,108,115,110,112,117,116,46,77,111,117,115,101,46,99,108,97,115,115,40,41,58,10, -32,32,32,32,34,34,34,10, -32,32,32,32,32,32,32,32,-23,-68,-96,-26,-96,-121,-25,-79,-69,-25,-102,-124,-26,-98,-124,-23,-128,-96,-27,-121,-67,-26,-107,-80,10, -32,32,32,32,34,34,34,10, -32,32,32,32,118,97,114,32,116,104,105,115,32,61,32,123,125,10, -10, -32,32,32,32,116,104,105,115,46,119,104,101,114,101,32,61,32,108,115,110,112,117,116,46,103,101,116,95,109,111,117,115,101,95,112,111,115,105,116,105,111,110,32,32,35,-26,-97,-91,-24,-81,-94,-23,-68,-96,-26,-96,-121,-28,-67,-115,-25,-67,-82,10, -32,32,32,32,116,104,105,115,46,115,101,116,32,61,32,108,115,110,112,117,116,46,115,101,116,95,109,111,117,115,101,95,112,111,115,105,116,105,111,110,32,32,32,32,35,-24,-82,-66,-25,-67,-82,-23,-68,-96,-26,-96,-121,-28,-67,-115,-25,-67,-82,10, -10, -32,32,32,32,116,104,105,115,46,99,108,105,99,107,32,61,32,100,101,102,40,116,104,105,115,44,32,109,111,100,101,44,32,116,41,58,32,32,32,32,32,32,32,32,32,32,32,32,32,32,35,-25,-126,-71,-27,-121,-69,-23,-68,-96,-26,-96,-121,10, -32,32,32,32,32,32,32,32,118,97,114,32,116,121,112,101,10, -32,32,32,32,32,32,32,32,118,97,114,32,99,32,61,32,48,10, -32,32,32,32,32,32,32,32,116,32,61,32,116,32,111,114,32,49,10, -10, -32,32,32,32,32,32,32,32,105,102,32,109,111,100,101,32,61,61,32,39,108,101,102,116,39,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,116,121,112,101,32,61,32,108,115,110,112,117,116,46,77,111,117,115,101,46,76,69,70,84,10, -32,32,32,32,32,32,32,32,101,108,105,102,32,109,111,100,101,32,61,61,32,39,114,105,103,104,116,39,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,116,121,112,101,32,61,32,108,115,110,112,117,116,46,77,111,117,115,101,46,82,73,71,72,84,10, -32,32,32,32,32,32,32,32,101,108,105,102,32,109,111,100,101,32,61,61,32,39,109,105,100,39,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,116,121,112,101,32,61,32,108,115,110,112,117,116,46,77,111,117,115,101,46,77,73,68,10, -32,32,32,32,32,32,32,32,101,108,115,101,10, -32,32,32,32,32,32,32,32,32,32,32,32,116,121,112,101,32,61,32,108,115,110,112,117,116,46,77,111,117,115,101,46,76,69,70,84,10, -32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,32,32,32,32,119,105,116,104,32,49,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,99,32,61,32,99,32,43,32,49,10, -32,32,32,32,32,32,32,32,32,32,32,32,10, -32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,99,32,62,32,116,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,98,114,101,97,107,10, -32,32,32,32,32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,32,32,32,32,32,32,32,32,108,115,110,112,117,116,46,99,108,105,99,107,40,116,121,112,101,41,10, -32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,59,10, -10, -32,32,32,32,114,116,32,116,104,105,115,10, -59,10, -10, --28,-69,-92,32,-23,-108,-82,-23,-68,-96,-28,-70,-117,-28,-69,-74,32,61,32,123,125,10, -10, --23,-108,-82,-23,-68,-96,-28,-70,-117,-28,-69,-74,46,-23,-68,-96,-26,-96,-121,32,61,32,123,125,10, -10, --26,-106,-71,-26,-77,-107,32,-23,-108,-82,-23,-68,-96,-28,-70,-117,-28,-69,-74,46,-23,-68,-96,-26,-96,-121,46,99,108,97,115,115,40,41,58,10, -32,32,32,32,34,34,34,10, -32,32,32,32,32,32,32,32,-23,-68,-96,-26,-96,-121,-25,-79,-69,-25,-102,-124,-26,-98,-124,-23,-128,-96,-27,-121,-67,-26,-107,-80,10, -32,32,32,32,34,34,34,10, -32,32,32,32,118,97,114,32,116,104,105,115,32,61,32,123,125,10, -10, -32,32,32,32,116,104,105,115,46,-28,-67,-115,-25,-67,-82,32,61,32,108,115,110,112,117,116,46,103,101,116,95,109,111,117,115,101,95,112,111,115,105,116,105,111,110,32,32,35,-26,-97,-91,-24,-81,-94,-23,-68,-96,-26,-96,-121,-28,-67,-115,-25,-67,-82,10, -32,32,32,32,116,104,105,115,46,-24,-82,-66,-25,-67,-82,32,61,32,108,115,110,112,117,116,46,115,101,116,95,109,111,117,115,101,95,112,111,115,105,116,105,111,110,32,32,32,32,35,-24,-82,-66,-25,-67,-82,-23,-68,-96,-26,-96,-121,-28,-67,-115,-25,-67,-82,10, -10, -32,32,32,32,116,104,105,115,46,-25,-126,-71,-27,-121,-69,32,61,32,100,101,102,40,116,104,105,115,44,32,109,111,100,101,44,32,116,41,58,32,32,32,32,32,32,32,32,32,32,32,32,32,32,35,-25,-126,-71,-27,-121,-69,-23,-68,-96,-26,-96,-121,10, -32,32,32,32,32,32,32,32,118,97,114,32,116,121,112,101,10, -32,32,32,32,32,32,32,32,118,97,114,32,99,32,61,32,48,10, -32,32,32,32,32,32,32,32,116,32,61,32,116,32,111,114,32,49,10, -10, -32,32,32,32,32,32,32,32,105,102,32,109,111,100,101,32,61,61,32,39,108,101,102,116,39,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,116,121,112,101,32,61,32,108,115,110,112,117,116,46,77,111,117,115,101,46,76,69,70,84,10, -32,32,32,32,32,32,32,32,101,108,105,102,32,109,111,100,101,32,61,61,32,39,114,105,103,104,116,39,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,116,121,112,101,32,61,32,108,115,110,112,117,116,46,77,111,117,115,101,46,82,73,71,72,84,10, -32,32,32,32,32,32,32,32,101,108,105,102,32,109,111,100,101,32,61,61,32,39,109,105,100,39,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,116,121,112,101,32,61,32,108,115,110,112,117,116,46,77,111,117,115,101,46,77,73,68,10, -32,32,32,32,32,32,32,32,101,108,115,101,10, -32,32,32,32,32,32,32,32,32,32,32,32,116,121,112,101,32,61,32,108,115,110,112,117,116,46,77,111,117,115,101,46,76,69,70,84,10, -32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,32,32,32,32,119,105,116,104,32,49,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,99,32,61,32,99,32,43,32,49,10, -32,32,32,32,32,32,32,32,32,32,32,32,10, -32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,99,32,62,32,116,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,98,114,101,97,107,10, -32,32,32,32,32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,32,32,32,32,32,32,32,32,108,115,110,112,117,116,46,99,108,105,99,107,40,116,121,112,101,41,10, -32,32,32,32,32,32,32,32,59,10, -10, -32,32,32,32,59,10, -10, -32,32,32,32,114,116,32,116,104,105,115,10, -59,10, -0}; -#endif -void ElsLib_lsnput_libinit(els_VmObj *vm){ - vm_register(vm,"lsnput_init",ELSAPI_lsnput_lsnput_init); - #ifdef ELS_CONF_TOKEN_EN - vm_dostring(vm,LibScript); - #endif -}; diff --git a/lsnput/readme.md b/lsnput/readme.md deleted file mode 100644 index be8d8e8a6458cf7e2515c6632d3819ff732e3e7f..0000000000000000000000000000000000000000 --- a/lsnput/readme.md +++ /dev/null @@ -1,53 +0,0 @@ -# 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/lsrepo/Ubuntu/makefile b/lsrepo/Ubuntu/makefile deleted file mode 100755 index da863863bbf7860e86e3094093fd0f7452a8a842..0000000000000000000000000000000000000000 --- a/lsrepo/Ubuntu/makefile +++ /dev/null @@ -1,13 +0,0 @@ -OBJS = lsrepo.o -CFLAGS= -O2 -Wall -std=c99 -DLOSU_LINUX -I ../buildenv -fPIC -CC=x86_64-linux-gnu-gcc -T=./ElsLib_lsrepo.lsd - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -shared -s - -clean: - rm -rf $T $(OBJS) core core.* \ No newline at end of file diff --git a/lsrepo/info b/lsrepo/info deleted file mode 100755 index 5737f5590d692ecd335e636003c71da5fd37357d..0000000000000000000000000000000000000000 --- a/lsrepo/info +++ /dev/null @@ -1,20 +0,0 @@ -{ - info = { - name = "lsrepo/洛书持续交付工具", - text = "洛书持续交付工具,实现远程软件源的持续部署与交付", - version = "24.1.28", - }, - source = { - all = { - "lsrepo.els", - "lsrepo.h", - "lsrepo.c", - }, - Ubuntu = { - "makefile", - } - }, - target = { - Ubuntu = "make ; cp ElsLib_lsrepo.lsd target/ElsLib_lsrepo.lsd_Ubuntu ; make clean", - } -} \ No newline at end of file diff --git a/lsrepo/lsrepo.c b/lsrepo/lsrepo.c deleted file mode 100755 index 5f248ffaa4a1d9d98fea34c900ade6b3b9b6cee8..0000000000000000000000000000000000000000 --- a/lsrepo/lsrepo.c +++ /dev/null @@ -1 +0,0 @@ -#include "lsrepo.h" \ No newline at end of file diff --git a/lsrepo/lsrepo.els b/lsrepo/lsrepo.els deleted file mode 100755 index 1528af8a9ae1b1cac9140214010465efaa7c305c..0000000000000000000000000000000000000000 --- a/lsrepo/lsrepo.els +++ /dev/null @@ -1,189 +0,0 @@ -#!script -import "stdlib" - -lsrepo = { - error = def():; , - init = def():; , # 初始化工作环境 - add = def():; , # 添加模块 - rm = def():; , # 删除模块 - make = def():; , # 构建模块(增量构建) - check = def():; , # 检测模块是否更改 - list = def():; , # 列举已经安装的模块 - thispack = {} , # 模块列表 -} - -def lsrepo.error(i): - print("[ERROR/错误]: LPKG:\t",i) - pass - -def lsrepo.init(): - var s,fin - fin = file.open(".repo/.repo",'r') - if not fin : - lsrepo.error("当前目录下找不到仓库配置网站!") - pass - - with not fin.eof(): - s = fin.input() - if s!="": - lsrepo.thispack[s]=s - pass - pass - fin.close() - fin = null - - fin = file.open(".repo/.nosafe",'r') - if not fin: - return - pass - with not fin.eof(): - s = fin.input() - if s!="": - if lsrepo.thispack[s]: - lsrepo.thispack[s]='--xx--' - pass - pass - pass - pass - -def lsrepo.add(pack): - # 初始化工作环境 - lsrepo.init() - - lsrepo.thispack[pack]=pack - var fout = file.open(".repo/.repo","w") - if not fout: - lsrepo.error("权限不足,无法打开仓库配置文件!") - pass - for name,obj in lsrepo.thispack: - fout.print(name&"\n") - pass - fout.close() - pass - -def lsrepo.rm(pack): - # 初始化工作环境 - lsrepo.init() - - if not lsrepo.thispack[pack]: - lsrepo.error("仓库中没有模块 "&pack) - pass - lsrepo.thispack[pack] = null - var fout = file.open(".repo/.repo",'w') - if not fout : - lsrepo.error("权限不足,无法打开仓库配置文件!") - pass - for name,obj in lsrepo.thispack: - fout.print(name&"\n") - pass - fout.close() - pass - -def lsrepo.check(pack): - return sys.system("./.repo/.check "&pack) - pass - -def lsrepo.make(argv_version,upversion): - # 初始化环境 - var version - lsrepo.init() - - var f = file.open(".repo/.index",'w') - if not f : - lsrepo.error("无法创建 .index 索引文件") - pass - f.print("Lpt = Lpt or { pkgs = { version='',remote = {}}}\n") - - - # 获取应有的版本号 - version = (argv_version and ('"'&argv_version&'"')) - or - ('"' & (time.year()-2000) & '.' & time.mon() & '.' & int(time.day()/7) & '"') - - - # 写入 els_version.h - var fout = file.open("losu_core/els_version.h",'w') - if fout: - fout.print('#define ELS_CORE_VERSION '&version) - fout.close() - pass - fout = null - - f.print('Lpt.pkgs.version = '&version&'\n') - if upversion: - f.print('Lpt.pkgs.upversion = "'&upversion&'"\n') - pass - - # var fin = file.open(".repo/.version",'r') - # if not fin: - # lsrepo.error("找不到版本配置文件 .version") - # pass - # f.print('Lpt.pkgs.version = "'&fin.lineinput()&'"\n') - # fin.close() - # fin = null - - if sys.system("./.repo/.update")!=0: - lsrepo.error("更新脚本存在错误!") - pass - for pack,name in lsrepo.thispack: - if name != '--xx--' and lsrepo.check(pack)!=0 : - sys.system("./.repo/.build "&pack) - pass - # 生成 remote.list - f.print("Lpt.pkgs.remote."&pack&"= ") - fin = file.open(pack&"/info",'r') - if not fin: - lsrepo.error("找不到模块配置文件 info") - pass - with not fin.eof(): - f.print(fin.lineinput()&"\n") - pass - fin.close() - fin = null - pass - pass - -def lsrepo.list(): - lsrepo.init() - for pack,name in lsrepo.thispack: - print(pack) - pass - pass - - - - - - - -def main(argc,argv): - if argc()==1 : - if argv(1) == "make": - lsrepo.make() - elif argv(1)=="list": - lsrepo.list() - pass - - elif argc()==2: - if argv(1)=="add": - lsrepo.add(argv(2)) - elif argv(1)=="rm": - lsrepo.rm(argv(2)) - elif argv(1)=="check": - lsrepo.check(argv(2)) - elif argv(1)=="make": - lsrepo.make(argv(2)) - pass - elif argc()==3: - if argv(1)=="make": - lsrepo.make(argv(2),argv(3)) - pass - else - print("LsRepo Tool -- An Powerful Tool for Losu Packages' Server AutoBuild!") - pass - - pass - -main(argc,argv) - -#!end diff --git a/lsrepo/lsrepo.h b/lsrepo/lsrepo.h deleted file mode 100755 index 2c0bc7be1b3fa3c3628d6966a05b01983844f03a..0000000000000000000000000000000000000000 --- a/lsrepo/lsrepo.h +++ /dev/null @@ -1,197 +0,0 @@ -#include "els.h" -#ifdef ELS_CONF_TOKEN_EN -static const char LibScript[]={ -105,109,112,111,114,116,32,34,115,116,100,108,105,98,34,10, -10, -108,115,114,101,112,111,32,61,32,123,10, -32,32,32,32,101,114,114,111,114,32,61,32,100,101,102,40,41,58,59,32,44,10, -32,32,32,32,105,110,105,116,32,32,61,32,100,101,102,40,41,58,59,32,44,32,32,32,35,32,-27,-120,-99,-27,-89,-117,-27,-116,-106,-27,-73,-91,-28,-67,-100,-25,-114,-81,-27,-94,-125,10, -32,32,32,32,97,100,100,32,32,32,61,32,100,101,102,40,41,58,59,32,44,32,32,32,35,32,-26,-73,-69,-27,-118,-96,-26,-88,-95,-27,-99,-105,10, -32,32,32,32,114,109,32,32,32,32,61,32,100,101,102,40,41,58,59,32,44,32,32,32,35,32,-27,-120,-96,-23,-103,-92,-26,-88,-95,-27,-99,-105,10, -32,32,32,32,109,97,107,101,32,32,61,32,100,101,102,40,41,58,59,32,44,32,32,32,35,32,-26,-98,-124,-27,-69,-70,-26,-88,-95,-27,-99,-105,-17,-68,-120,-27,-94,-98,-23,-121,-113,-26,-98,-124,-27,-69,-70,-17,-68,-119,10, -32,32,32,32,99,104,101,99,107,32,61,32,100,101,102,40,41,58,59,32,44,32,32,32,35,32,-26,-93,-128,-26,-75,-117,-26,-88,-95,-27,-99,-105,-26,-104,-81,-27,-112,-90,-26,-101,-76,-26,-108,-71,10, -32,32,32,32,108,105,115,116,32,32,61,32,100,101,102,40,41,58,59,32,44,32,32,32,35,32,-27,-120,-105,-28,-72,-66,-27,-73,-78,-25,-69,-113,-27,-82,-119,-24,-93,-123,-25,-102,-124,-26,-88,-95,-27,-99,-105,10, -32,32,32,32,116,104,105,115,112,97,99,107,32,61,32,123,125,32,32,32,44,32,32,32,35,32,-26,-88,-95,-27,-99,-105,-27,-120,-105,-24,-95,-88,10, -125,10, -10, -100,101,102,32,108,115,114,101,112,111,46,101,114,114,111,114,40,105,41,58,10, -32,32,32,32,112,114,105,110,116,40,34,91,69,82,82,79,82,47,-23,-108,-103,-24,-81,-81,93,58,32,76,80,75,71,58,92,116,34,44,105,41,10, -32,32,32,32,112,97,115,115,10, -10, -100,101,102,32,108,115,114,101,112,111,46,105,110,105,116,40,41,58,10, -32,32,32,32,118,97,114,32,115,44,102,105,110,10, -32,32,32,32,102,105,110,32,61,32,102,105,108,101,46,111,112,101,110,40,34,46,114,101,112,111,47,46,114,101,112,111,34,44,39,114,39,41,10, -32,32,32,32,105,102,32,110,111,116,32,102,105,110,32,58,10, -32,32,32,32,32,32,32,32,108,115,114,101,112,111,46,101,114,114,111,114,40,34,-27,-67,-109,-27,-119,-115,-25,-101,-82,-27,-67,-107,-28,-72,-117,-26,-119,-66,-28,-72,-115,-27,-120,-80,-28,-69,-109,-27,-70,-109,-23,-123,-115,-25,-67,-82,-25,-67,-111,-25,-85,-103,33,34,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,10, -32,32,32,32,119,105,116,104,32,110,111,116,32,102,105,110,46,101,111,102,40,41,58,10, -32,32,32,32,32,32,32,32,115,32,61,32,102,105,110,46,105,110,112,117,116,40,41,10, -32,32,32,32,32,32,32,32,105,102,32,115,33,61,34,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,108,115,114,101,112,111,46,116,104,105,115,112,97,99,107,91,115,93,61,115,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,102,105,110,46,99,108,111,115,101,40,41,32,10, -32,32,32,32,102,105,110,32,61,32,110,117,108,108,10, -10, -32,32,32,32,102,105,110,32,61,32,102,105,108,101,46,111,112,101,110,40,34,46,114,101,112,111,47,46,110,111,115,97,102,101,34,44,39,114,39,41,10, -32,32,32,32,105,102,32,110,111,116,32,102,105,110,58,10, -32,32,32,32,32,32,32,32,114,101,116,117,114,110,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,119,105,116,104,32,110,111,116,32,102,105,110,46,101,111,102,40,41,58,10, -32,32,32,32,32,32,32,32,115,32,61,32,102,105,110,46,105,110,112,117,116,40,41,10, -32,32,32,32,32,32,32,32,105,102,32,115,33,61,34,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,108,115,114,101,112,111,46,116,104,105,115,112,97,99,107,91,115,93,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,115,114,101,112,111,46,116,104,105,115,112,97,99,107,91,115,93,61,39,45,45,120,120,45,45,39,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,112,97,115,115,32,10, -32,32,32,32,112,97,115,115,10, -10, -100,101,102,32,108,115,114,101,112,111,46,97,100,100,40,112,97,99,107,41,58,10, -32,32,32,32,35,32,-27,-120,-99,-27,-89,-117,-27,-116,-106,-27,-73,-91,-28,-67,-100,-25,-114,-81,-27,-94,-125,10, -32,32,32,32,108,115,114,101,112,111,46,105,110,105,116,40,41,10, -10, -32,32,32,32,108,115,114,101,112,111,46,116,104,105,115,112,97,99,107,91,112,97,99,107,93,61,112,97,99,107,10, -32,32,32,32,118,97,114,32,102,111,117,116,32,61,32,102,105,108,101,46,111,112,101,110,40,34,46,114,101,112,111,47,46,114,101,112,111,34,44,34,119,34,41,10, -32,32,32,32,105,102,32,110,111,116,32,102,111,117,116,58,10, -32,32,32,32,32,32,32,32,108,115,114,101,112,111,46,101,114,114,111,114,40,34,-26,-99,-125,-23,-103,-112,-28,-72,-115,-24,-74,-77,44,-26,-105,-96,-26,-77,-107,-26,-119,-109,-27,-68,-128,-28,-69,-109,-27,-70,-109,-23,-123,-115,-25,-67,-82,-26,-106,-121,-28,-69,-74,33,34,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,102,111,114,32,110,97,109,101,44,111,98,106,32,105,110,32,108,115,114,101,112,111,46,116,104,105,115,112,97,99,107,58,10, -32,32,32,32,32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,110,97,109,101,38,34,92,110,34,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,102,111,117,116,46,99,108,111,115,101,40,41,10, -32,32,32,32,112,97,115,115,10, -10, -100,101,102,32,108,115,114,101,112,111,46,114,109,40,112,97,99,107,41,58,10, -32,32,32,32,35,32,-27,-120,-99,-27,-89,-117,-27,-116,-106,-27,-73,-91,-28,-67,-100,-25,-114,-81,-27,-94,-125,10, -32,32,32,32,108,115,114,101,112,111,46,105,110,105,116,40,41,10, -10, -32,32,32,32,105,102,32,110,111,116,32,108,115,114,101,112,111,46,116,104,105,115,112,97,99,107,91,112,97,99,107,93,58,10, -32,32,32,32,32,32,32,32,108,115,114,101,112,111,46,101,114,114,111,114,40,34,-28,-69,-109,-27,-70,-109,-28,-72,-83,-26,-78,-95,-26,-100,-119,-26,-88,-95,-27,-99,-105,32,34,38,112,97,99,107,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,108,115,114,101,112,111,46,116,104,105,115,112,97,99,107,91,112,97,99,107,93,32,61,32,110,117,108,108,10, -32,32,32,32,118,97,114,32,102,111,117,116,32,61,32,102,105,108,101,46,111,112,101,110,40,34,46,114,101,112,111,47,46,114,101,112,111,34,44,39,119,39,41,10, -32,32,32,32,105,102,32,110,111,116,32,102,111,117,116,32,58,10, -32,32,32,32,32,32,32,32,108,115,114,101,112,111,46,101,114,114,111,114,40,34,-26,-99,-125,-23,-103,-112,-28,-72,-115,-24,-74,-77,44,-26,-105,-96,-26,-77,-107,-26,-119,-109,-27,-68,-128,-28,-69,-109,-27,-70,-109,-23,-123,-115,-25,-67,-82,-26,-106,-121,-28,-69,-74,33,34,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,102,111,114,32,110,97,109,101,44,111,98,106,32,105,110,32,108,115,114,101,112,111,46,116,104,105,115,112,97,99,107,58,10, -32,32,32,32,32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,110,97,109,101,38,34,92,110,34,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,102,111,117,116,46,99,108,111,115,101,40,41,10, -32,32,32,32,112,97,115,115,10, -10, -100,101,102,32,108,115,114,101,112,111,46,99,104,101,99,107,40,112,97,99,107,41,58,10, -32,32,32,32,114,101,116,117,114,110,32,115,121,115,46,115,121,115,116,101,109,40,34,46,47,46,114,101,112,111,47,46,99,104,101,99,107,32,32,34,38,112,97,99,107,41,10, -32,32,32,32,112,97,115,115,10, -10, -100,101,102,32,108,115,114,101,112,111,46,109,97,107,101,40,97,114,103,118,95,118,101,114,115,105,111,110,44,117,112,118,101,114,115,105,111,110,41,58,10, -32,32,32,32,35,32,-27,-120,-99,-27,-89,-117,-27,-116,-106,-25,-114,-81,-27,-94,-125,10, -32,32,32,32,118,97,114,32,118,101,114,115,105,111,110,10, -32,32,32,32,108,115,114,101,112,111,46,105,110,105,116,40,41,10, -10, -32,32,32,32,118,97,114,32,102,32,61,32,102,105,108,101,46,111,112,101,110,40,34,46,114,101,112,111,47,46,105,110,100,101,120,34,44,39,119,39,41,10, -32,32,32,32,105,102,32,110,111,116,32,102,32,58,10, -32,32,32,32,32,32,32,32,108,115,114,101,112,111,46,101,114,114,111,114,40,34,-26,-105,-96,-26,-77,-107,-27,-120,-101,-27,-69,-70,32,46,105,110,100,101,120,32,-25,-76,-94,-27,-68,-107,-26,-106,-121,-28,-69,-74,34,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,102,46,112,114,105,110,116,40,34,76,112,116,32,61,32,76,112,116,32,111,114,32,123,32,112,107,103,115,32,61,32,123,32,118,101,114,115,105,111,110,61,39,39,44,114,101,109,111,116,101,32,61,32,123,125,125,125,92,110,34,41,10, -10, -10, -32,32,32,32,35,32,-24,-114,-73,-27,-113,-106,-27,-70,-108,-26,-100,-119,-25,-102,-124,-25,-119,-120,-26,-100,-84,-27,-113,-73,10, -32,32,32,32,118,101,114,115,105,111,110,32,61,32,40,97,114,103,118,95,118,101,114,115,105,111,110,32,97,110,100,32,40,39,34,39,38,97,114,103,118,95,118,101,114,115,105,111,110,38,39,34,39,41,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,111,114,32,32,32,32,32,32,32,32,32,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,40,39,34,39,32,38,32,40,116,105,109,101,46,121,101,97,114,40,41,45,50,48,48,48,41,32,38,32,39,46,39,32,38,32,116,105,109,101,46,109,111,110,40,41,32,38,32,39,46,39,32,38,32,105,110,116,40,116,105,109,101,46,100,97,121,40,41,47,55,41,32,38,32,39,34,39,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,10, -32,32,32,32,35,32,-27,-122,-103,-27,-123,-91,32,101,108,115,95,118,101,114,115,105,111,110,46,104,10, -32,32,32,32,118,97,114,32,102,111,117,116,32,61,32,102,105,108,101,46,111,112,101,110,40,34,108,111,115,117,95,99,111,114,101,47,101,108,115,95,118,101,114,115,105,111,110,46,104,34,44,39,119,39,41,10, -32,32,32,32,105,102,32,102,111,117,116,58,10, -32,32,32,32,32,32,32,32,102,111,117,116,46,112,114,105,110,116,40,39,35,100,101,102,105,110,101,32,69,76,83,95,67,79,82,69,95,86,69,82,83,73,79,78,32,39,38,118,101,114,115,105,111,110,41,10, -32,32,32,32,32,32,32,32,102,111,117,116,46,99,108,111,115,101,40,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,102,111,117,116,32,61,32,110,117,108,108,10, -10, -32,32,32,32,102,46,112,114,105,110,116,40,39,76,112,116,46,112,107,103,115,46,118,101,114,115,105,111,110,32,61,32,39,38,118,101,114,115,105,111,110,38,39,92,110,39,41,10, -32,32,32,32,105,102,32,117,112,118,101,114,115,105,111,110,58,10, -32,32,32,32,32,32,32,32,102,46,112,114,105,110,116,40,39,76,112,116,46,112,107,103,115,46,117,112,118,101,114,115,105,111,110,32,61,32,34,39,38,117,112,118,101,114,115,105,111,110,38,39,34,92,110,39,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -10, -32,32,32,32,35,32,118,97,114,32,102,105,110,32,61,32,102,105,108,101,46,111,112,101,110,40,34,46,114,101,112,111,47,46,118,101,114,115,105,111,110,34,44,39,114,39,41,10, -32,32,32,32,35,32,105,102,32,110,111,116,32,102,105,110,58,10, -32,32,32,32,35,32,32,32,32,32,108,115,114,101,112,111,46,101,114,114,111,114,40,34,-26,-119,-66,-28,-72,-115,-27,-120,-80,-25,-119,-120,-26,-100,-84,-23,-123,-115,-25,-67,-82,-26,-106,-121,-28,-69,-74,32,46,118,101,114,115,105,111,110,34,41,10, -32,32,32,32,35,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,35,32,102,46,112,114,105,110,116,40,39,76,112,116,46,112,107,103,115,46,118,101,114,115,105,111,110,32,61,32,34,39,38,102,105,110,46,108,105,110,101,105,110,112,117,116,40,41,38,39,34,92,110,39,41,10, -32,32,32,32,35,32,102,105,110,46,99,108,111,115,101,40,41,10, -32,32,32,32,35,32,102,105,110,32,61,32,110,117,108,108,10, -10, -32,32,32,32,105,102,32,115,121,115,46,115,121,115,116,101,109,40,34,46,47,46,114,101,112,111,47,46,117,112,100,97,116,101,34,41,33,61,48,58,10, -32,32,32,32,32,32,32,32,108,115,114,101,112,111,46,101,114,114,111,114,40,34,-26,-101,-76,-26,-106,-80,-24,-124,-102,-26,-100,-84,-27,-83,-104,-27,-100,-88,-23,-108,-103,-24,-81,-81,33,34,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,102,111,114,32,112,97,99,107,44,110,97,109,101,32,105,110,32,108,115,114,101,112,111,46,116,104,105,115,112,97,99,107,58,10, -32,32,32,32,32,32,32,32,105,102,32,32,110,97,109,101,32,33,61,32,39,45,45,120,120,45,45,39,32,97,110,100,32,108,115,114,101,112,111,46,99,104,101,99,107,40,112,97,99,107,41,33,61,48,32,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,115,121,115,46,115,121,115,116,101,109,40,34,46,47,46,114,101,112,111,47,46,98,117,105,108,100,32,34,38,112,97,99,107,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,35,32,-25,-108,-97,-26,-120,-112,32,114,101,109,111,116,101,46,108,105,115,116,10, -32,32,32,32,32,32,32,32,102,46,112,114,105,110,116,40,34,76,112,116,46,112,107,103,115,46,114,101,109,111,116,101,46,34,38,112,97,99,107,38,34,61,32,34,41,10, -32,32,32,32,32,32,32,32,102,105,110,32,61,32,102,105,108,101,46,111,112,101,110,40,112,97,99,107,38,34,47,105,110,102,111,34,44,39,114,39,41,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,102,105,110,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,108,115,114,101,112,111,46,101,114,114,111,114,40,34,-26,-119,-66,-28,-72,-115,-27,-120,-80,-26,-88,-95,-27,-99,-105,-23,-123,-115,-25,-67,-82,-26,-106,-121,-28,-69,-74,32,105,110,102,111,34,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,119,105,116,104,32,110,111,116,32,102,105,110,46,101,111,102,40,41,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,102,46,112,114,105,110,116,40,102,105,110,46,108,105,110,101,105,110,112,117,116,40,41,38,34,92,110,34,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,32,32,32,32,102,105,110,46,99,108,111,115,101,40,41,10, -32,32,32,32,32,32,32,32,102,105,110,32,61,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,112,97,115,115,10, -10, -100,101,102,32,108,115,114,101,112,111,46,108,105,115,116,40,41,58,10, -32,32,32,32,108,115,114,101,112,111,46,105,110,105,116,40,41,10, -32,32,32,32,102,111,114,32,112,97,99,107,44,110,97,109,101,32,105,110,32,108,115,114,101,112,111,46,116,104,105,115,112,97,99,107,58,10, -32,32,32,32,32,32,32,32,112,114,105,110,116,40,112,97,99,107,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,112,97,115,115,10, -10, -10, -10, -10, -10, -10, -10, -100,101,102,32,109,97,105,110,40,97,114,103,99,44,97,114,103,118,41,58,10, -32,32,32,32,105,102,32,32,32,97,114,103,99,40,41,61,61,49,32,58,10, -32,32,32,32,32,32,32,32,105,102,32,97,114,103,118,40,49,41,32,61,61,32,34,109,97,107,101,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,108,115,114,101,112,111,46,109,97,107,101,40,41,10, -32,32,32,32,32,32,32,32,101,108,105,102,32,97,114,103,118,40,49,41,61,61,34,108,105,115,116,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,108,115,114,101,112,111,46,108,105,115,116,40,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -10, -32,32,32,32,101,108,105,102,32,97,114,103,99,40,41,61,61,50,58,10, -32,32,32,32,32,32,32,32,105,102,32,97,114,103,118,40,49,41,61,61,34,97,100,100,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,108,115,114,101,112,111,46,97,100,100,40,97,114,103,118,40,50,41,41,10, -32,32,32,32,32,32,32,32,101,108,105,102,32,97,114,103,118,40,49,41,61,61,34,114,109,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,108,115,114,101,112,111,46,114,109,40,97,114,103,118,40,50,41,41,10, -32,32,32,32,32,32,32,32,101,108,105,102,32,97,114,103,118,40,49,41,61,61,34,99,104,101,99,107,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,108,115,114,101,112,111,46,99,104,101,99,107,40,97,114,103,118,40,50,41,41,10, -32,32,32,32,32,32,32,32,101,108,105,102,32,97,114,103,118,40,49,41,61,61,34,109,97,107,101,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,108,115,114,101,112,111,46,109,97,107,101,40,97,114,103,118,40,50,41,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,101,108,105,102,32,97,114,103,99,40,41,61,61,51,58,10, -32,32,32,32,32,32,32,32,105,102,32,97,114,103,118,40,49,41,61,61,34,109,97,107,101,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,108,115,114,101,112,111,46,109,97,107,101,40,97,114,103,118,40,50,41,44,97,114,103,118,40,51,41,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,97,115,115,10, -32,32,32,32,101,108,115,101,10, -32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,76,115,82,101,112,111,32,84,111,111,108,32,45,45,32,65,110,32,80,111,119,101,114,102,117,108,32,84,111,111,108,32,102,111,114,32,76,111,115,117,32,80,97,99,107,97,103,101,115,39,32,83,101,114,118,101,114,32,65,117,116,111,66,117,105,108,100,33,34,41,10, -32,32,32,32,32,32,32,32,112,97,115,115,10, -10, -32,32,32,32,112,97,115,115,10, -10, -109,97,105,110,40,97,114,103,99,44,97,114,103,118,41,10, -10, -0}; -#endif -void ElsLib_lsrepo_libinit(els_VmObj *vm){ - #ifdef ELS_CONF_TOKEN_EN - vm_dostring(vm,LibScript); - #endif -}; diff --git a/lsrepo/readme.md b/lsrepo/readme.md deleted file mode 100755 index a90d0c89dfcdc3f07044e252788cc4e1538bd79d..0000000000000000000000000000000000000000 --- a/lsrepo/readme.md +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/owls.wiki.losu.tech -# lsrepo 洛书持续部署 wiki -## 简介 -lsrepo (Losu Repo ),洛书持续部署工具,是一款运行在 Linux 平台下的 CI 工具,支持多种 版本管理工具与构建环境,支持导入第三方源 -## 可用功能 -+ 运行方法 -``` -losu -r lsrepo [参数列表] -``` -```sh -lsrepo add [name] # 添加 追踪 -lsrepo rm [name] # 删除 追踪 -lsrepo list # 列出所有追踪信息 -lsrepo check [name] # 检测是否发生更改 -lsrepo make # 执行更新 - -``` -## 使用方法 -+ [视频教程]() \ No newline at end of file diff --git a/lssys/Ubuntu/linux_lssys.c b/lssys/Ubuntu/linux_lssys.c deleted file mode 100755 index c230ab929b9f2a8d7aec7996949e783f66e89d5a..0000000000000000000000000000000000000000 --- a/lssys/Ubuntu/linux_lssys.c +++ /dev/null @@ -1,260 +0,0 @@ -#include "linux_lssys.h" - -#ifdef LOSU_LINUX - -const char *Lssys_getos() -{ - return ELS_BRANCH; -} - -const char *Lssys_getenv(const char *name, char *buffer, int length) -{ - /* - char *getenv(const char *varname); - 返回指向环境变量的指针。操作该指针并不安全, - 故建议加const - 失败时返回NULL - */ - char *tmp = getenv(name); - if (tmp) - { - for (int i=0; i=0 - n = (n>0 && n - */ - if (getcwd(buffer, length)==NULL) - return false; - return true; -} - -bool Lssys_exsists(const char *path) -{ - /* - int access(const char *pathname, int mode); - - 成功返回0 - - mode: - R_OK 只判断是否有读权限 - W_OK 只判断是否有写权限 - X_OK 判断是否有执行权限 - F_OK 只判断是否存在 - */ - return access(path, F_OK)==0 ? true : false; -} - -bool Lssys_mkdir(const char* path) -{ - /* - int mkdir(const char *pathname, mode_t mode); - 参数: - 1:创建目录路径 - 2:创建文件的模式 - - 创建成功则返回0 - - mode: - S_IRWXU 00700权限,代表该文件所有者拥有读,写和执行操作的权限 - S_IRUSR(S_IREAD) 00400权限,代表该文件所有者拥有可读的权限 - S_IWUSR(S_IWRITE) 00200权限,代表该文件所有者拥有可写的权限 - S_IXUSR(S_IEXEC) 00100权限,代表该文件所有者拥有执行的权限 - S_IRWXG 00070权限,代表该文件用户组拥有读,写和执行操作的权限 - S_IRGRP 00040权限,代表该文件用户组拥有可读的权限 - S_IWGRP 00020权限,代表该文件用户组拥有可写的权限 - S_IXGRP 00010权限,代表该文件用户组拥有执行的权限 - S_IRWXO 00007权限,代表其他用户拥有读,写和执行操作的权限 - S_IROTH 00004权限,代表其他用户拥有可读的权限 - S_IWOTH 00002权限,代表其他用户拥有可写的权限 - S_IXOTH 00001权限,代表其他用户拥有执行的权限 - */ - return mkdir(path, S_IRWXU)==0 ? true : false; -} - -bool Lssys_rmdir(const char* path) -{ - /* - int rmdir(const char *pathname); - 成功时返回0 - - */ - return rmdir(path)==0 ? true:false; -} - -bool Lssys_rename(const char *oldn, const char *newn) -{ - /* - int rename(const char *oldname, const char *newname); - 成功时返回0 - */ - return rename(oldn, newn)==0 ? true : false; -} - -bool Lssys_remove(const char* path) -{ - /* - int remove(char * filename); - 成功时返回0 - */ - return remove(path); -} - -uint64_t Lssys_getpid() -{ - return getpid(); -} - -bool Lssys_join(const char *a, const char *b, char *result, int len) -{ - strcat(result, a); - strcat(result, LOSU_LINUX_LSSYS_PATH_ALTSEP); - strcat(result, b); - return true; -} - -bool Lssys_chdir(const char* path) -{ - /* - chdir(const char *path); - 成功返回0,失败返回-1 - */ - if (chdir(path)==0) - return true; - return false; -} - -bool Lssys_killp(uint64_t pid) -{ - if (kill(pid, SIGKILL) == 0) - return true; - return false; -} - -uint64_t Lssys_lpcount() -{ - return get_nprocs(); -} - -int Lssys_architecture() -{ - /* - struct utsname { - char sysname[]; / Operating system name (e.g., "Linux") / - char nodename[]; / Name within "some implementation-defined - network" / - char release[]; / Operating system release (e.g., "2.6.28") / - char version[]; / Operating system version / - char machine[]; / Hardware identifier / - #ifdef _GNU_SOURCE - char domainname[]; / NIS or YP domain name / - #endif - }; - - int uname(struct utsname *buf); - - */ - struct utsname info; - uname(&info); - - if (strcmp(info.machine, "x86_64") == 0) - return LSSYS_ARCH_X86; - else if (strcmp(info.machine, "amd64") == 0) - return LSSYS_ARCH_X86; - else if (strcmp(info.machine, "ARM") == 0) - return LSSYS_ARCH_ARM; - else - return LSSYS_ARCH_UNKNOW; -} - -/* - Linux 内存信息储存在 /proc/meminfo 文件中 -*/ - -uint64_t Lssys_memtotal() -{ - FILE *fp = fopen("/proc/meminfo", "r"); - uint64_t size; - - if (fp == NULL) - return -1; - - if (fscanf(fp, "MemTotal: %ld kB", &size)) - return size * 1024; - return -1; -} - -uint64_t Lssys_memfreep() -{ - FILE *fp = fopen("/proc/meminfo", "r"); - uint64_t size; - - if (fp == NULL) - return -1; - - for (int i = 0; i<2; i++) - for (;;) - { - char ch = fgetc(fp); - if (ch == '\n') - break; - } - - if (fscanf(fp, "MemAvailable: %ld kB",&size) == 1) - return size * 1024; - return -1; -} - -#endif \ No newline at end of file diff --git a/lssys/Ubuntu/linux_lssys.h b/lssys/Ubuntu/linux_lssys.h deleted file mode 100755 index d25d0809b47cee7a6580f20956d2869ce9df208b..0000000000000000000000000000000000000000 --- a/lssys/Ubuntu/linux_lssys.h +++ /dev/null @@ -1,77 +0,0 @@ -#ifndef LOSU_LINUX_LSSYS_H__ -#define LOSU_LINUX_LSSYS_H__ - -#ifndef LOSU_LINUX -#warning "该文件用于Linux系统,如需使用,请包含LOSU_LINUX宏" -#endif - -/* - popen等函数基于GNU拓展,但洛书标准库规定基于c99标准 - 如果在第一次包含之前没有定义宏_GNU_SOURCE的话,编译器会报warning - 虽然最后都可以正常链接 - 这里是为了消除warning,避免不知道的开发者误会 -*/ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#include -#undef _GNU_SOURCE -#else -#include -#endif - -#include //access -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "els.h" - -#ifdef LOSU_LINUX - -//Windows操作系统的规范化分隔符是反斜杠“\” -#ifndef LOSU_LINUX_LSSYS_PATH_ALTSEP -#define LOSU_LINUX_LSSYS_PATH_ALTSEP "/" -#endif - -#define LSSYS_ARCH_UNKNOW -1 -#define LSSYS_ARCH_ARM 1 -#define LSSYS_ARCH_X86 4 - - -//stdsys已经实现的 -const char *Lssys_getos(); -const char *Lssys_getenv(const char *, char *, int); -int Lssys_system(const char *); -void *Lssys_popen(const char *, const char *); -int Lssys_pwrite(void *, const char *); -int Lssys_pread(void *, int, char *); -int Lssys_pclose(void *); - -//lssys要实现的 -bool Lssys_getcwd(char *, int); -bool Lssys_exsists(const char *); -bool Lssys_mkdir(const char*); -bool Lssys_rmdir(const char*); -bool Lssys_rename(const char *, const char *); -bool Lssys_remove(const char*); -uint64_t Lssys_getpid(); -bool Lssys_join(const char *, const char *, char *, int); -bool Lssys_chdir(const char*); -bool Lssys_killp(uint64_t); -uint64_t Lssys_lpcount(); -int Lssys_architecture(); - - -uint64_t Lssys_memtotal(); -uint64_t Lssys_memfreep(); -#endif - -#endif \ No newline at end of file diff --git a/lssys/Ubuntu/makefile b/lssys/Ubuntu/makefile deleted file mode 100755 index 8c9d48095ce0d2e28e27a7cb476ae877330e20a8..0000000000000000000000000000000000000000 --- a/lssys/Ubuntu/makefile +++ /dev/null @@ -1,13 +0,0 @@ -OBJS = lssys.o linux_lssys.o -CFLAGS= -O2 -std=c99 -Wall -DLOSU_LINUX -I ../buildenv -fPIC -lc -CC=x86_64-linux-gnu-gcc -T=./ElsLib_lssys.lsd - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -shared -lm -s -lc - -clean: - rm -rf $T $(OBJS) core core.* \ No newline at end of file diff --git a/lssys/Windows/makefile b/lssys/Windows/makefile deleted file mode 100755 index 611f2062cf51f4a67e0cb963bdbffc0a3282e187..0000000000000000000000000000000000000000 --- a/lssys/Windows/makefile +++ /dev/null @@ -1,17 +0,0 @@ -WIN = win_lssys.o -MAIN = lssys.o -OBJS = $(WIN) $(MAIN) -CFLAGS= -O3 -std=c99 -Wall -DLOSU_WINDOWS -I ../buildenv -fPIC -CC=x86_64-w64-mingw32-gcc -T=ElsLib_lssys.lsd - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -L ../buildenv -l:libeasylosu.dll -lm -static -shared -s - -clean: - rm -rf $T - rm -rf $(WIN) - rm -rf $(MAIN) \ No newline at end of file diff --git a/lssys/Windows/win_lssys.c b/lssys/Windows/win_lssys.c deleted file mode 100755 index c970faf0023d5dec5f6fc5a0b9a221189503a27e..0000000000000000000000000000000000000000 --- a/lssys/Windows/win_lssys.c +++ /dev/null @@ -1,236 +0,0 @@ -#include "win_lssys.h" - -const char *Lssys_getos() -{ - return ELS_BRANCH; -} - -const char *Lssys_getenv(const char *name, char *buffer, int length) -{ - /* - char *getenv(const char *varname); - 返回指向环境变量的指针。操作该指针并不安全, - 故建议加const - 失败时返回NULL - */ - char *tmp = getenv(name); - char *_t = NULL; - if (tmp) - { - _t = vm_win_togbk(tmp); - for (int i=0; i=0 - n = (n>0 && n - 成功时返回指向buffer的指针 - 失败时返回NULL - */ - char *output = _getcwd(buffer, length); - return output==NULL ? false:true; -} - -bool Lssys_exsists(const char * path) -{ - /* - 看不懂原型 - 反正GetFileAttributes()的唯一参数是const char * - 找不到时返回INVALID_FILE_ATTRIBUTES - */ - int output; - - if (path==NULL) - return false; - - output = GetFileAttributes(path); - if (output==INVALID_FILE_ATTRIBUTES) - return false; - return true; -} - -bool Lssys_mkdir(const char* path) -{ - /* - int _mkdir(const char *dirname); - 成功创建时返回0 - */ - int output = _mkdir(path); - return output==0 ? true:false; -} - -bool Lssys_rmdir(const char* path) -{ - /* - int _rmdir(const char *dirname); - 成功删除时返回0 - */ - int output = _rmdir(path); - return output==0 ? true:false; -} - -bool Lssys_rename(const char *oldn, const char *newn) -{ - /* - int rename(const char *oldname, const char *newname); - 成功时返回0 - */ - int output = rename(oldn, newn); - return output==0 ? true:false; -} - -bool Lssys_remove(const char* filepath) -{ - /* - int remove(const char *filename); - 成功时返回0 - */ - int output = remove(filepath); - return output==0 ? true:false; -} - -uint64_t Lssys_getpid() -{ - /* - DWORD GetCurrentProcessId(); - 返回值是调用进程的进程标识符。在进程终止之前,进程标识符会在整个系统中唯一标识进程。 - */ - return GetCurrentProcessId(); -} - -bool Lssys_join(const char *a, const char *b, char *result, int len) -{ - /* - 将字符串a和b以系统标准路径分隔符连接 - */ - strcat(result, a); - strcat(result, LOSU_WIN_LSSYS_PATH_ALTSEP); - strcat(result, b); - return true; -} - -bool Lssys_chdir(const char*path) -{ - /* - BOOL SetCurrentDirectory( - [in] LPCTSTR lpPathName - ); - 当成功时,函数返回非0值 - */ - if (SetCurrentDirectory(path) != 0) - return true; - return false; -} - -bool Lssys_killp(uint64_t pid) -{ - HANDLE h = OpenProcess(PROCESS_TERMINATE, FALSE, pid); - if (h == NULL) - return false; - if (!TerminateProcess(h,0)) - return false; - return true; -} - -uint64_t Lssys_lpcount() -{ - /* - BOOL GetLogicalProcessorInformation( - [out] PSYSTEM_LOGICAL_PROCESSOR_INFORMATION Buffer, - [in, out] PDWORD ReturnedLength - ); - */ - SYSTEM_INFO info; - GetSystemInfo(&info); - return info.dwNumberOfProcessors; -} - -int Lssys_architecture() -{ - SYSTEM_INFO info; - GetSystemInfo(&info); - switch (info.wProcessorArchitecture) - { - case PROCESSOR_ARCHITECTURE_AMD64: - case PROCESSOR_ARCHITECTURE_INTEL: - return LSSYS_ARCH_X86; - case PROCESSOR_ARCHITECTURE_ARM: - case PROCESSOR_ARCHITECTURE_ARM64: - return LSSYS_ARCH_ARM; - default: - return LSSYS_ARCH_UNKNOW; - } -} - -uint64_t Lssys_memtotal() -{ - MEMORYSTATUSEX result; - result.dwLength = sizeof(result); //调用GlobalMemoryStatuEx之前要在dwLength成员中储存整个结构的大小 - GlobalMemoryStatusEx(&result); - return result.ullTotalPhys; -} - -uint64_t Lssys_memfreep() -{ - MEMORYSTATUSEX result; - result.dwLength = sizeof(result); //调用GlobalMemoryStatuEx之前要在dwLength成员中储存整个结构的大小 - GlobalMemoryStatusEx(&result); - return result.ullAvailPhys; -} \ No newline at end of file diff --git a/lssys/Windows/win_lssys.h b/lssys/Windows/win_lssys.h deleted file mode 100755 index 1a16bbffdab114adcf60230724c360e6c6fcd191..0000000000000000000000000000000000000000 --- a/lssys/Windows/win_lssys.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef LOSU_WIN_LSSYS_H__ -#define LOSU_WIN_LSSYS_H__ - -#ifndef LOSU_WINDOWS -#warning "注意,这是用于Windows平台的代码!!!如需包含代码,请定义宏LOSU_WINDOWS" -#endif - -#ifdef LOSU_WINDOWS - -#include "els.h" - -#include -#include -#include -#include -#include -#include -#include - -//Windows操作系统的规范化分隔符是反斜杠“\” -#ifndef LOSU_WIN_LSSYS_PATH_ALTSEP -#define LOSU_WIN_LSSYS_PATH_ALTSEP "\\" -#endif - -#define LSSYS_ARCH_UNKNOW -1 -#define LSSYS_ARCH_ARM 1 -#define LSSYS_ARCH_X86 4 - -//stdsys已经实现的 -const char *Lssys_getos(); -const char *Lssys_getenv(const char *, char *, int); -int Lssys_system(const char *); -void *Lssys_popen(const char *, const char *); -int Lssys_pwrite(void *, const char *); -int Lssys_pread(void *, int, char *); -int Lssys_pclose(void *); - -//lssys要实现的 -bool Lssys_getcwd(char *, int); -bool Lssys_exsists(const char *); -bool Lssys_mkdir(const char*); -bool Lssys_rmdir(const char*); -bool Lssys_rename(const char *, const char *); -bool Lssys_remove(const char*); -uint64_t Lssys_getpid(); -bool Lssys_join(const char *, const char *, char *, int); -bool Lssys_chdir(const char*); -bool Lssys_killp(uint64_t); -uint64_t Lssys_lpcount(); -int Lssys_architecture(); -uint64_t Lssys_memtotal(); -uint64_t Lssys_memfreep(); -#endif - -#endif \ No newline at end of file diff --git a/lssys/info b/lssys/info deleted file mode 100755 index 6cb35be57ebdce649b37e03539043f01760a316d..0000000000000000000000000000000000000000 --- a/lssys/info +++ /dev/null @@ -1,29 +0,0 @@ -{ - info = { - name = "lssys/系统拓展库", - text = "stdsys的拓展模块", - version = "23.10.10" - }, - source = { - all = { - "lssys.c", - "lssys.h", - "lssys.els", - "readme.md" - }, - Ubuntu = { - "makefile", - "linux_lssys.h", - "linux_lssys.c" - }, - Windows = { - "makefile", - "win_lssys.h", - "win_lssys.c" - } - }, - target={ - Ubuntu = "make ; cp ElsLib_lssys.lsd target/ElsLib_lssys.lsd_Ubuntu ; make clean", - Windows = "make ; cp ElsLib_lssys.lsd target/ElsLib_lssys.lsd_Windows ; make clean", - } -} \ No newline at end of file diff --git a/lssys/lssys.c b/lssys/lssys.c deleted file mode 100755 index d8c37a7d87da9b995469c469a7662040ffc443e4..0000000000000000000000000000000000000000 --- a/lssys/lssys.c +++ /dev/null @@ -1,546 +0,0 @@ -#include "lssys.h" - -#include - -#ifdef LOSU_WINDOWS -#include "win_lssys.h" -#endif - -#ifdef LOSU_LINUX -#include "linux_lssys.h" -#endif - -/* - 本文件的注释,第一行是用到的底层函数的原型 - 下面的参数和返回值都是指的脚本层的接口函数的 -*/ - -int ELSAPI_lssys_lssys_getos(els_VmObj* vm) -{ - /* - const char *Lssys_getos() - - # 参数 - 无 - - # 返回值 - Windows Branch / Linux Branch - */ - arg_returnstr(vm, Lssys_getos()); - return 1; -} - -int ELSAPI_lssys_lssys_getenv(els_VmObj* vm) -{ - /* - const char *Lssys_getenv(const char* name, char *buffer, int length) - - # 参数 - 1.name 要获取的环境变量的名称 - - # 返回值 - 1. 当name的类型为string或number时,返回包含环境变量信息的字符串 - 2. 当name的类型非法时,返回null - */ - if (arg_gettype(vm, 1) == ELS_API_TYPE_STRING) - { - const char *name = arg_getstr(vm, 1); - char buffer[ELS_BUFF_TMP_SIZE]; - arg_returnstr(vm, Lssys_getenv(name, buffer, ELS_BUFF_TMP_SIZE)); - } - else - arg_returnnull(vm); - return 1; -} - -int ELSAPI_lssys_lssys_system(els_VmObj* vm) -{ - /* - int Lssys_system(const char *cmd); - - # 参数 - 1.cmd 要执行的命令 - - # 返回值 - 1. 当cmd的类型为string时, 返回命令执行完后的状态码 - 2. 当cmd的类型非法时,返回null - */ - if (arg_gettype(vm, 1) == ELS_API_TYPE_STRING) - { - const char *cmd = arg_getstr(vm, 1); - arg_returnnum(vm, Lssys_system(cmd)); - } - else - arg_returnnull(vm); - - return 1; -} - -int ELSAPI_lssys_lssys_popen(els_VmObj* vm) -{ - /* - FILE *Lssys_popen(const char *cmd, const char *mod); - - # 参数 - 1. cmd 要执行的命令 - 2. mod 要执行的模式 - - # 返回值 - 1. fp 当cmd的类型为string时,返回管道的文件指针 - 2. 当存在非法类型时,返回null - */ - if (arg_gettype(vm, 1) == ELS_API_TYPE_STRING && arg_gettype(vm, 2)==ELS_API_TYPE_STRING) - { - const char *cmd = arg_getstr(vm, 1); - const char *mod = arg_getstr(vm, 2); - - FILE *fp = Lssys_popen(cmd, mod); - arg_returnptr(vm, (void*)fp); - } - else - arg_returnnull(vm); - - return 1; -} - -int ELSAPI_lssys_lssys_pwrite(els_VmObj* vm) -{ - /* - int Lssys_pwrite(void *p, const char *s); - - # 参数 - 1. p 管道的文件指针 - 2. s 要写入的字符串 - # 返回值 - 未知 - */ - //p的类型只能为ptr - //s的类型可以为string或number - if (arg_gettype(vm, 1)==ELS_API_TYPE_PTR && (arg_gettype(vm, 2) == ELS_API_TYPE_STRING || arg_gettype(vm, 2) == ELS_API_TYPE_NUMBER)) - { - void *p = arg_getptr(vm, 1); - const char *s = arg_getstr(vm, 2); - int output = Lssys_pwrite(p, s); - arg_returnnum(vm, output); - } - else - arg_returnnull(vm); - - - return 1; -} - -int ELSAPI_lssys_lssys_pread(els_VmObj* vm) -{ - /* - int Lssys_pread(void *p, int n, char *buffer); - - # 参数 - 1. p 管道的文件指针 - 2. n 要读取的字符数量 - - # 返回值 - 1. 成功读取时返回读取到的内容 - 2. 失败时返回null - 3. 参数类型必须都为string,否则也返回null - */ - //p的类型必须为ptr而且n的类型必须为number - if (arg_gettype(vm, 1) == ELS_API_TYPE_PTR && arg_gettype(vm, 2) == ELS_API_TYPE_NUMBER) - { - void *p = arg_getptr(vm, 1); - int n = arg_getnum(vm, 2); - char *buffer = NULL; - - //n必须>0 - if (n>0) - { - buffer = malloc(sizeof(char)*(n+1)); - if (Lssys_pread(p, n, buffer)) - arg_returnstr(vm, buffer); - else - arg_returnnull(vm); - free(buffer); - return 1; - } - arg_returnnull(vm); - } - else - arg_returnnull(vm); - - - return 1; -} - -int ELSAPI_lssys_lssys_pclose(els_VmObj* vm) -{ - /* - int Lssys_pclose(void *p); - - # 参数 - 1. p 管道的文件指针 - - # 返回值 - 未知 - */ - //p的类型必须为ptr - if (arg_gettype(vm, 1) == ELS_API_TYPE_PTR) - { - - void *p = arg_getptr(vm, 1); - arg_returnnum(vm, Lssys_pclose(p)); - } - else - arg_returnnull(vm); - - return 1; -} - -int ELSAPI_lssys_lssys_getcwd(els_VmObj* vm) -{ - /* - bool Lssys_getcwd(char *buffer, int maxlen); - - # 参数 - 无 - - # 返回值 - 1. 返回当前工作目录的字符串 - */ - //工作目录的缓冲区大小为1024 - //大概不会溢出 - char buffer[1024]; - if (Lssys_getcwd(buffer, 1024)) - arg_returnstr(vm, buffer); - else - arg_returnnull(vm); - return 1; -} - -int ELSAPI_lssys_lssys_exsists(els_VmObj* vm) -{ - /* - bool Lssys_exist(const char *path); - - # 参数 - 1. path 路径 - - # 返回值 - 1. 在path类型为string且路径存在时返回1 - 2. 不存在时返回null - */ - if (arg_gettype(vm, 1) == ELS_API_TYPE_STRING) - { - const char *path = arg_getstr(vm, 1); - if (Lssys_exsists(path)) - arg_returnnum(vm, 1); - else - arg_returnnull(vm); - } - else - arg_returnnull(vm); - return 1; -} - -int ELSAPI_lssys_lssys_mkdir(els_VmObj* vm) -{ - /* - bool Lssys_mkdir(const char *path); - - # 参数 - 1. path 路径 - - # 返回值 - 1. 在path类型为string且成功时返回1 - 2. 失败时返回null - */ - if (arg_gettype(vm, 1) == ELS_API_TYPE_STRING) - { - const char *path = arg_getstr(vm, 1); - if (Lssys_mkdir(path)) - arg_returnnum(vm, 1); - else - arg_returnnull(vm); - } - else - arg_returnnull(vm); - - return 1; -} -int ELSAPI_lssys_lssys_rmdir(els_VmObj* vm) -{ - /* - bool Lssys_rmdir(const char *path); - - # 参数 - 1. path 路径 - - # 返回值 - 1. 在path类型为string且成功时返回1 - 2. 在path类型非法或失败时返回null - */ - if (arg_gettype(vm, 1) == ELS_API_TYPE_STRING) - { - const char *path = arg_getstr(vm, 1); - if (Lssys_rmdir(path)) - arg_returnnum(vm, 1); - else - arg_returnnull(vm); - } - else - arg_returnnull(vm); - - return 1; -} - -int ELSAPI_lssys_lssys_rename(els_VmObj* vm) -{ - /* - bool Lssys_rename(const char *oldname, const char *newname); - - # 参数 - 1. oldname 旧的文件名 - 2. newname 新的文件名 - - # 返回值 - 1. 在oldname和newname类型均为string并且成功时返回1 - 2. 在有非法类型或失败时返回null - */ - //oldname和newname的类型都应该为string - if (arg_gettype(vm, 1) == ELS_API_TYPE_STRING && arg_gettype(vm, 2) == ELS_API_TYPE_STRING) - { - const char *oldname = arg_getstr(vm, 1); - const char *newname = arg_getstr(vm, 2); - if (Lssys_rename(oldname, newname)) - arg_returnnum(vm, 1); - else - arg_returnnull(vm); - } - else - arg_returnnull(vm); - return 1; -} - -int ELSAPI_lssys_lssys_remove(els_VmObj* vm) -{ - /* - bool Lssys_remove(const char *filepath); - - # 参数 - 1. path 文件路径 - - # 返回值 - 1. path的类型为sting并且成功时返回1 - 2. path的类型非法并且失败时返回null - */ - if (arg_gettype(vm, 1) == ELS_API_TYPE_STRING) - { - - const char *path = arg_getstr(vm, 1); - - //当成功删除时,Lssys_remove会返回真值 - if (Lssys_remove(path)) - arg_returnnum(vm, 1); - else - arg_returnnull(vm); - } - else - arg_returnnull(vm); - - return 1; -} - -int ELSAPI_lssys_lssys_getpid(els_VmObj* vm) -{ - /* - uint64_t Lssys_getpid(); - - # 参数 - 无 - - # 返回值 - 1. id 当前进程的id - */ - arg_returnnum(vm, Lssys_getpid()); //Lssys_getid已经封装了获取当前进程id的功能 - return 1; -} - - -int ELSAPI_lssys_lssys_join(els_VmObj* vm) -{ - /* - bool Lssys_join(const char* a, const char * b, char * result, int len); - - # 参数 - 1. a:str 前面的字符串 - 2. b:str 后面的字符串 - - # 返回值 - 1. 用系统规范路径分隔符连接的a和b - 2. 当类型非法时,返回null - */ - if (arg_gettype(vm, 1) == ELS_API_TYPE_STRING && arg_gettype(vm, 2) == ELS_API_TYPE_STRING) - { - const char *a = arg_getstr(vm, 1); - const char *b = arg_getstr(vm, 2); - char *result; - int len; - - //计算预计缓冲区大小 - len = (strlen(a) + strlen(b) + 2) * sizeof(char); - - //分配缓冲区 - result = malloc(len); - memset(result, 0, len); - - //得到结果 - if (Lssys_join(a, b, result, len)) - arg_returnstr(vm, result); - else - arg_returnnull(vm); - free(result); - } - else - arg_returnnull(vm); - return 1; -} - -int ELSAPI_lssys_lssys_chdir(els_VmObj* vm) -{ - /* - bool Lssys_chdir(const char *path); - - # 参数 - 1. path:str 目标路径 - - # 返回值 - 1. 当成功改变当前工作路径时返回1 - 2. 当改变工作路径失败时返回null - 3. 当类型不合法时返回null - */ - if (arg_gettype(vm, 1) == ELS_API_TYPE_STRING) - { - const char *path = arg_getstr(vm, 1); - - if (Lssys_chdir(path)) - arg_returnnum(vm, 1); - else - arg_returnnull(vm); - } - else - arg_returnnull(vm); - return 1; -} - -int ELSAPI_lssys_lssys_killp(els_VmObj* vm) -{ - /* - bool Lssys_killp(uint64_t pid); - - # 参数 - 1. pid:int 要杀死的进程的id - - # 返回值 - 1. 成功杀死时返回1 - 2. 未成功杀死时返回null - 3. 当类型不合法时返回null - */ - if (arg_gettype(vm, 1) == ELS_API_TYPE_NUMBER) - { - uint64_t pid = arg_getnum(vm, 1); - if (Lssys_killp(pid)) - arg_returnnum(vm, 1); - else - arg_returnnull(vm); - } - else - arg_returnnull(vm); - return 1; -} - -int ELSAPI_lssys_lssys_lpcount(els_VmObj* vm) -{ - /* - uint32_t Lssys_lpcount(); - - # 参数 - 无 - - # 返回值 - 1. 当前计算机的逻辑处理器个数 - */ - int result = Lssys_lpcount(); - if (result == -1) - arg_returnnull(vm); - else - arg_returnnum(vm, result); - return 1; -} - - -int ELSAPI_lssys_lssys_architecture(els_VmObj* vm) -{ - /* - int Lssys_architecture(); - - 可能的返回值有 - LSSYS_ARCH_ARM - LSSYS_ARCH_X86 - LSSYS_ARCH_UNKNOW - - # 参数 - 无 - - # 返回值 - 1. 当前CPU的架构 - 2. 当架构未知时,返回null - */ - const char *output; - - switch (Lssys_architecture()) - { - case LSSYS_ARCH_ARM: - output = "ARM"; - break; - case LSSYS_ARCH_X86: - output = "X86"; - break; - default: - output = NULL; - } - - if (output!=NULL) - arg_returnstr(vm, output); - else - arg_returnnull(vm); - return 1; -} - -int ELSAPI_lssys_lssys_memtotal(els_VmObj* vm) -{ - /* - uint64_t Lssys_memtotal(); - - # 参数 - 无 - - # 返回值 - 1. 操作系统的总内存量 - */ - arg_returnnum(vm, Lssys_memtotal()); - return 1; -} - -int ELSAPI_lssys_lssys_memfreep(els_VmObj* vm) -{ - /* - uint64_t Lssys_memfreep(); - - # 参数 - 无 - - # 返回值 - 1. 当前线程的可用内存量 - */ - arg_returnnum(vm, Lssys_memfreep()); - return 1; -} \ No newline at end of file diff --git a/lssys/lssys.els b/lssys/lssys.els deleted file mode 100755 index c335bbd1da5590d3d03f9109abf1f3a75bd56810..0000000000000000000000000000000000000000 --- a/lssys/lssys.els +++ /dev/null @@ -1,265 +0,0 @@ -#!declare - -stdsys的函数 -lssys_getos(): str '从内核中获取所在操作系统信息,一般为 Windwos/Linux' -lssys_getenv(n: str) '获取名称为n的环境变量' -lssys_system(cmd: str): int '调用一个命令' -lssys_popen(cmd: str, mod:str): ptr '创建一个管道,mod可取为 r,w' -lssys_pwrite(p: ptr,s: str): int '向指定管道 p 写入 s' -lssys_pread(p: ptr, n: int): int '从指定管道 p 读取 n 个字符' -lssys_pclose(p: ptr): int '关闭一个管道' - -lssys新增的 -lssys_getcwd(): str #获取当前工作目录 -lssys_exsists(path:str): [int/null] #判断路径是否存在 -lssys_mkdir(path:str): [int/null] #创建一个新目录 -lssys_rmdir(path:str): [int/null] #删除一个目录 -lssys_rename(oldname:str, newname:str) #将文件重命名 -lssys_remove(filename:str) #删除文件 -lssys_getpid(): int #获取当前进程的id -lssys_join( a:string, b:string ): string #将a和b以操作系统文件路径分隔符连接 -lssys_chdir( path:s ): [int/null] #改变当前进程的工作目录 -lssys_killp( pid:int, sig:unknow ): [int/null] #将sig作为信号发送给进程id为pid的进程 -lssys_lpcount(): int #返回当前的计算机的逻辑处理器数 -lssys_architecture(): str #返回当前CPU的架构 - -//待完成 -lssys_memtotal(): int #返回操作系统的总物理内存数,单位为字节 -lssys_memfreep(): int #返回该线程还可用的最大内存,单位为字节 -#!end - -#!script -if not sys: - sys={} -; - -def sys.popen(cmd,mod): - var this = {} - - this.P = lssys_popen(cmd, mod or 'r') - - if !this.P : return null ; - - def this.write(s): - if not ths.P: - rt null - ; - return lssys_pwrite(this.P,s) - ; - def this.read(i): - if not ths.P: - rt null - ; - return lssys_pread(this.P,i) - ; - def this.close(): - if not ths.P: - rt null - ; - var result = lssys_pclose(this.P) - this.P = null - rt result - ; - - return this -; - -block - """ - 在洛书运行时,操作系统就已经确定 - """ - var _ = lssys_getos() - def sys.getos(): - rt _ - ; -; - -def sys.getenv(name): - rt lssys_getenv(name) -; - -def sys.system(cmd): - rt lssys_system(cmd) -; - -def sys.getcwd(): - rt lssys_getcwd() -; - -def sys.exsists(path): - rt lssys_exsists(path) -; - -def sys.mkdir(path): - rt lssys_mkdir(path) -; - -def sys.rmdir(path): - rt lssys_rmdir(path) -; - -def sys.rename(old, new): - rt lssys_rename(old, new) -; - -def sys.remove(path): - rt lssys_remove(path) -; - -def sys.getpid(): - rt lssys_getpid() -; - -def sys.join(a, b): - rt lssys_join(a, b) -; - -def sys.chdir(path): - rt lssys_chdir(path) -; - -def sys.killp(pid): - rt lssys_killp(pid) -; - -block - """ - 闭包 - 在洛书运行时,逻辑处理器的个数就已经确定 - """ - var _ = lssys_lpcount() - def sys.lpcount(): - rt _ - ; -; - -block - """ - 闭包 - 在洛书运行时,处理器的架构就已经确定 - """ - var _ = lssys_architecture() - def sys.architecture(): - rt _ - ; -; - -def sys.memtotal(): - 回 lssys_memtotal() -; - -def sys.memfreep(): - 回 lssys_memfreep() -; - -if not 系统: - 系统={} -; - -def 系统.新进程(cmd,mod): - var this = {} - - this.P = lssys_popen(cmd, mod or 'r') - - if !this.P : return null ; - - def this.写(s): - if not this.P: - rt null - ; - return lssys_pwrite(this.P,s) - ; - def this.读(i): - if not this.P: - rt null - ; - return lssys_pread(this.P,i) - ; - def this.关闭(): - if not this.P: - rt null - ; - var result = lssys_pclose(this.P) - this.P = null - rt result - ; - - return this -; - -代码块 - 令 _ = lssys_getos() - 方法 系统.操作系统(): - 回 _ - ; -; - -方法 系统.环境变量(名称): - 回 lssys_getenv(名称) -; - -方法 系统.调用(命令): - 回 lssys_system(命令) -; - -方法 系统.工作目录(): - 回 lssys_getcwd() -; - -方法 系统.存在(路径): - 回 lssys_exsists(路径) -; - -方法 系统.创建目录(路径): - 回 lssys_mkdir(路径) -; - -方法 系统.删除目录(路径): - 回 lssys_rmdir(路径) -; - -方法 系统.重命名(旧名, 新名): - 回 lssys_rename(旧名, 新名) -; - -方法 系统.删除(路径): - 回 lssys_remove(路径) -; - -方法 系统.获取进程id(): - 回 lssys_getpid() -; - -方法 系统.拼接路径(甲, 乙): - 回 lssys_join(甲, 乙) -; - -方法 系统.改变工作目录(路径): - 回 lssys_chdir(路径) -; - -方法 系统.杀死进程(进程id): - 回 lssys_killp(进程id) -; - -代码块 - 令 _ = lssys_lpcount() - 方法 系统.逻辑处理器数(): - 回 _ - ; -; - -代码块 - 令 _ = lssys_architecture() - 方法 系统.处理器架构(): - 回 _ - ; -; - -方法 系统.总内存(): - 回 lssys_memtotal() -; - -方法 系统.线程可用内存(): - 回 lssys_memfreep() -; diff --git a/lssys/lssys.h b/lssys/lssys.h deleted file mode 100755 index 77cef457882cf5ab006fbad3258e959a192a8063..0000000000000000000000000000000000000000 --- a/lssys/lssys.h +++ /dev/null @@ -1,287 +0,0 @@ -#include "els.h" -int ELSAPI_lssys_lssys_getos(els_VmObj* vm); // lssys_getos(): str '从内核中获取所在操作系统信息,一般为 Windwos/Linux' -int ELSAPI_lssys_lssys_getenv(els_VmObj* vm); // lssys_getenv(n: str) '获取名称为n的环境变量' -int ELSAPI_lssys_lssys_system(els_VmObj* vm); // lssys_system(cmd: str): int '调用一个命令' -int ELSAPI_lssys_lssys_popen(els_VmObj* vm); // lssys_popen(cmd: str, mod:str): ptr '创建一个管道,mod可取为 r,w' -int ELSAPI_lssys_lssys_pwrite(els_VmObj* vm); // lssys_pwrite(p: ptr,s: str): int '向指定管道 p 写入 s' -int ELSAPI_lssys_lssys_pread(els_VmObj* vm); // lssys_pread(p: ptr, n: int): int '从指定管道 p 读取 n 个字符' -int ELSAPI_lssys_lssys_pclose(els_VmObj* vm); // lssys_pclose(p: ptr): int '关闭一个管道' -int ELSAPI_lssys_lssys_getcwd(els_VmObj* vm); // lssys_getcwd(): str #获取当前工作目录 -int ELSAPI_lssys_lssys_exsists(els_VmObj* vm); // lssys_exsists(path:str): [int/null] #判断路径是否存在 -int ELSAPI_lssys_lssys_mkdir(els_VmObj* vm); // lssys_mkdir(path:str): [int/null] #创建一个新目录 -int ELSAPI_lssys_lssys_rmdir(els_VmObj* vm); // lssys_rmdir(path:str): [int/null] #删除一个目录 -int ELSAPI_lssys_lssys_rename(els_VmObj* vm); // lssys_rename(oldname:str, newname:str) #将文件重命名 -int ELSAPI_lssys_lssys_remove(els_VmObj* vm); // lssys_remove(filename:str) #删除文件 -int ELSAPI_lssys_lssys_getpid(els_VmObj* vm); // lssys_getpid(): int #获取当前进程的id -int ELSAPI_lssys_lssys_join(els_VmObj* vm); // lssys_join( a:string, b:string ): string #将a和b以操作系统文件路径分隔符连接 -int ELSAPI_lssys_lssys_chdir(els_VmObj* vm); // lssys_chdir( path:s ): [int/null] #改变当前进程的工作目录 -int ELSAPI_lssys_lssys_killp(els_VmObj* vm); // lssys_killp( pid:int, sig:unknow ): [int/null] #将sig作为信号发送给进程id为pid的进程 -int ELSAPI_lssys_lssys_lpcount(els_VmObj* vm); // lssys_lpcount(): int #返回当前的计算机的逻辑处理器数 -int ELSAPI_lssys_lssys_architecture(els_VmObj* vm); // lssys_architecture(): str #返回当前CPU的架构 -int ELSAPI_lssys_lssys_memtotal(els_VmObj* vm); // lssys_memtotal(): int #返回操作系统的总物理内存数,单位为字节 -int ELSAPI_lssys_lssys_memfreep(els_VmObj* vm); // lssys_memfreep(): int #返回该线程还可用的最大内存,单位为字节 -#ifdef ELS_CONF_TOKEN_EN -static const char LibScript[]={ -105,102,32,110,111,116,32,115,121,115,58,10, -32,32,32,32,115,121,115,61,123,125,10, -59,10, -10, -100,101,102,32,115,121,115,46,112,111,112,101,110,40,99,109,100,44,109,111,100,41,58,10, -32,32,32,32,118,97,114,32,116,104,105,115,32,61,32,123,125,10, -10, -32,32,32,32,116,104,105,115,46,80,32,61,32,108,115,115,121,115,95,112,111,112,101,110,40,99,109,100,44,32,109,111,100,32,111,114,32,39,114,39,41,10, -10, -32,32,32,32,105,102,32,33,116,104,105,115,46,80,32,58,32,114,101,116,117,114,110,32,110,117,108,108,32,59,10, -10, -32,32,32,32,100,101,102,32,116,104,105,115,46,119,114,105,116,101,40,115,41,58,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,116,104,115,46,80,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -32,32,32,32,32,32,32,32,114,101,116,117,114,110,32,108,115,115,121,115,95,112,119,114,105,116,101,40,116,104,105,115,46,80,44,115,41,10, -32,32,32,32,59,32,32,10, -32,32,32,32,100,101,102,32,116,104,105,115,46,114,101,97,100,40,105,41,58,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,116,104,115,46,80,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -32,32,32,32,32,32,32,32,114,101,116,117,114,110,32,108,115,115,121,115,95,112,114,101,97,100,40,116,104,105,115,46,80,44,105,41,10, -32,32,32,32,59,10, -32,32,32,32,100,101,102,32,116,104,105,115,46,99,108,111,115,101,40,41,58,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,116,104,115,46,80,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -32,32,32,32,32,32,32,32,118,97,114,32,114,101,115,117,108,116,32,61,32,108,115,115,121,115,95,112,99,108,111,115,101,40,116,104,105,115,46,80,41,10, -32,32,32,32,32,32,32,32,116,104,105,115,46,80,32,61,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,114,116,32,114,101,115,117,108,116,10, -32,32,32,32,59,10, -10, -32,32,32,32,114,101,116,117,114,110,32,116,104,105,115,10, -59,32,10, -10, -98,108,111,99,107,10, -32,32,32,32,34,34,34,10, -32,32,32,32,32,32,32,32,-27,-100,-88,-26,-76,-101,-28,-71,-90,-24,-65,-112,-24,-95,-116,-26,-105,-74,-17,-68,-116,-26,-109,-115,-28,-67,-100,-25,-77,-69,-25,-69,-97,-27,-80,-79,-27,-73,-78,-25,-69,-113,-25,-95,-82,-27,-82,-102,10, -32,32,32,32,34,34,34,10, -32,32,32,32,118,97,114,32,95,32,61,32,108,115,115,121,115,95,103,101,116,111,115,40,41,10, -32,32,32,32,100,101,102,32,115,121,115,46,103,101,116,111,115,40,41,58,10, -32,32,32,32,32,32,32,32,114,116,32,95,10, -32,32,32,32,59,10, -59,10, -10, -100,101,102,32,115,121,115,46,103,101,116,101,110,118,40,110,97,109,101,41,58,10, -32,32,32,32,114,116,32,108,115,115,121,115,95,103,101,116,101,110,118,40,110,97,109,101,41,10, -59,10, -10, -100,101,102,32,115,121,115,46,115,121,115,116,101,109,40,99,109,100,41,58,10, -32,32,32,32,114,116,32,108,115,115,121,115,95,115,121,115,116,101,109,40,99,109,100,41,10, -59,10, -10, -100,101,102,32,115,121,115,46,103,101,116,99,119,100,40,41,58,10, -32,32,32,32,114,116,32,108,115,115,121,115,95,103,101,116,99,119,100,40,41,10, -59,10, -10, -100,101,102,32,115,121,115,46,101,120,115,105,115,116,115,40,112,97,116,104,41,58,10, -32,32,32,32,114,116,32,108,115,115,121,115,95,101,120,115,105,115,116,115,40,112,97,116,104,41,10, -59,10, -10, -100,101,102,32,115,121,115,46,109,107,100,105,114,40,112,97,116,104,41,58,10, -32,32,32,32,114,116,32,108,115,115,121,115,95,109,107,100,105,114,40,112,97,116,104,41,10, -59,10, -10, -100,101,102,32,115,121,115,46,114,109,100,105,114,40,112,97,116,104,41,58,10, -32,32,32,32,114,116,32,108,115,115,121,115,95,114,109,100,105,114,40,112,97,116,104,41,10, -59,10, -10, -100,101,102,32,115,121,115,46,114,101,110,97,109,101,40,111,108,100,44,32,110,101,119,41,58,10, -32,32,32,32,114,116,32,108,115,115,121,115,95,114,101,110,97,109,101,40,111,108,100,44,32,110,101,119,41,10, -59,10, -10, -100,101,102,32,115,121,115,46,114,101,109,111,118,101,40,112,97,116,104,41,58,10, -32,32,32,32,114,116,32,108,115,115,121,115,95,114,101,109,111,118,101,40,112,97,116,104,41,10, -59,10, -10, -100,101,102,32,115,121,115,46,103,101,116,112,105,100,40,41,58,10, -32,32,32,32,114,116,32,108,115,115,121,115,95,103,101,116,112,105,100,40,41,10, -59,10, -10, -100,101,102,32,115,121,115,46,106,111,105,110,40,97,44,32,98,41,58,10, -32,32,32,32,114,116,32,108,115,115,121,115,95,106,111,105,110,40,97,44,32,98,41,10, -59,10, -10, -100,101,102,32,115,121,115,46,99,104,100,105,114,40,112,97,116,104,41,58,10, -32,32,32,32,114,116,32,108,115,115,121,115,95,99,104,100,105,114,40,112,97,116,104,41,10, -59,10, -10, -100,101,102,32,115,121,115,46,107,105,108,108,112,40,112,105,100,41,58,10, -32,32,32,32,114,116,32,108,115,115,121,115,95,107,105,108,108,112,40,112,105,100,41,10, -59,10, -10, -98,108,111,99,107,10, -32,32,32,32,34,34,34,10, -32,32,32,32,32,32,32,32,-23,-105,-83,-27,-116,-123,10, -32,32,32,32,32,32,32,32,-27,-100,-88,-26,-76,-101,-28,-71,-90,-24,-65,-112,-24,-95,-116,-26,-105,-74,-17,-68,-116,-23,-128,-69,-24,-66,-111,-27,-92,-124,-25,-112,-122,-27,-103,-88,-25,-102,-124,-28,-72,-86,-26,-107,-80,-27,-80,-79,-27,-73,-78,-25,-69,-113,-25,-95,-82,-27,-82,-102,10, -32,32,32,32,34,34,34,10, -32,32,32,32,118,97,114,32,95,32,61,32,108,115,115,121,115,95,108,112,99,111,117,110,116,40,41,10, -32,32,32,32,100,101,102,32,115,121,115,46,108,112,99,111,117,110,116,40,41,58,10, -32,32,32,32,32,32,32,32,114,116,32,95,10, -32,32,32,32,59,10, -59,10, -10, -98,108,111,99,107,10, -32,32,32,32,34,34,34,10, -32,32,32,32,32,32,32,32,-23,-105,-83,-27,-116,-123,10, -32,32,32,32,32,32,32,32,-27,-100,-88,-26,-76,-101,-28,-71,-90,-24,-65,-112,-24,-95,-116,-26,-105,-74,-17,-68,-116,-27,-92,-124,-25,-112,-122,-27,-103,-88,-25,-102,-124,-26,-98,-74,-26,-98,-124,-27,-80,-79,-27,-73,-78,-25,-69,-113,-25,-95,-82,-27,-82,-102,10, -32,32,32,32,34,34,34,10, -32,32,32,32,118,97,114,32,95,32,61,32,108,115,115,121,115,95,97,114,99,104,105,116,101,99,116,117,114,101,40,41,10, -32,32,32,32,100,101,102,32,115,121,115,46,97,114,99,104,105,116,101,99,116,117,114,101,40,41,58,10, -32,32,32,32,32,32,32,32,114,116,32,95,10, -32,32,32,32,59,10, -59,10, -10, -100,101,102,32,115,121,115,46,109,101,109,116,111,116,97,108,40,41,58,10, -32,32,32,32,-27,-101,-98,32,108,115,115,121,115,95,109,101,109,116,111,116,97,108,40,41,10, -59,10, -10, -100,101,102,32,115,121,115,46,109,101,109,102,114,101,101,112,40,41,58,10, -32,32,32,32,-27,-101,-98,32,108,115,115,121,115,95,109,101,109,102,114,101,101,112,40,41,10, -59,10, -10, -105,102,32,110,111,116,32,-25,-77,-69,-25,-69,-97,58,10, -32,-25,-77,-69,-25,-69,-97,61,123,125,10, -59,10, -10, -100,101,102,32,-25,-77,-69,-25,-69,-97,46,-26,-106,-80,-24,-65,-101,-25,-88,-117,40,99,109,100,44,109,111,100,41,58,10, -32,32,32,32,118,97,114,32,116,104,105,115,32,61,32,123,125,10, -10, -32,32,32,32,116,104,105,115,46,80,32,61,32,108,115,115,121,115,95,112,111,112,101,110,40,99,109,100,44,32,109,111,100,32,111,114,32,39,114,39,41,10, -10, -32,32,32,32,105,102,32,33,116,104,105,115,46,80,32,58,32,114,101,116,117,114,110,32,110,117,108,108,32,59,10, -10, -32,32,32,32,100,101,102,32,116,104,105,115,46,-27,-122,-103,40,115,41,58,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,116,104,105,115,46,80,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -32,32,32,32,32,32,32,32,114,101,116,117,114,110,32,108,115,115,121,115,95,112,119,114,105,116,101,40,116,104,105,115,46,80,44,115,41,10, -32,32,32,32,59,32,32,10, -32,32,32,32,100,101,102,32,116,104,105,115,46,-24,-81,-69,40,105,41,58,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,116,104,105,115,46,80,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -32,32,32,32,32,32,32,32,114,101,116,117,114,110,32,108,115,115,121,115,95,112,114,101,97,100,40,116,104,105,115,46,80,44,105,41,10, -32,32,32,32,59,10, -32,32,32,32,100,101,102,32,116,104,105,115,46,-27,-123,-77,-23,-105,-83,40,41,58,10, -32,32,32,32,32,32,32,32,105,102,32,110,111,116,32,116,104,105,115,46,80,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,59,10, -32,32,32,32,32,32,32,32,118,97,114,32,114,101,115,117,108,116,32,61,32,108,115,115,121,115,95,112,99,108,111,115,101,40,116,104,105,115,46,80,41,10, -32,32,32,32,32,32,32,32,116,104,105,115,46,80,32,61,32,110,117,108,108,10, -32,32,32,32,32,32,32,32,114,116,32,114,101,115,117,108,116,10, -32,32,32,32,59,10, -10, -32,32,32,32,114,101,116,117,114,110,32,116,104,105,115,10, -59,32,10, -10, --28,-69,-93,-25,-96,-127,-27,-99,-105,10, -32,32,32,32,-28,-69,-92,32,95,32,61,32,108,115,115,121,115,95,103,101,116,111,115,40,41,10, -32,32,32,32,-26,-106,-71,-26,-77,-107,32,-25,-77,-69,-25,-69,-97,46,-26,-109,-115,-28,-67,-100,-25,-77,-69,-25,-69,-97,40,41,58,10, -32,32,32,32,32,32,32,32,-27,-101,-98,32,95,10, -32,32,32,32,59,10, -59,10, -10, --26,-106,-71,-26,-77,-107,32,-25,-77,-69,-25,-69,-97,46,-25,-114,-81,-27,-94,-125,-27,-113,-104,-23,-121,-113,40,-27,-112,-115,-25,-89,-80,41,58,10, -32,32,32,32,-27,-101,-98,32,108,115,115,121,115,95,103,101,116,101,110,118,40,-27,-112,-115,-25,-89,-80,41,10, -59,10, -10, --26,-106,-71,-26,-77,-107,32,-25,-77,-69,-25,-69,-97,46,-24,-80,-125,-25,-108,-88,40,-27,-111,-67,-28,-69,-92,41,58,10, -32,32,32,32,-27,-101,-98,32,108,115,115,121,115,95,115,121,115,116,101,109,40,-27,-111,-67,-28,-69,-92,41,10, -59,10, -10, --26,-106,-71,-26,-77,-107,32,-25,-77,-69,-25,-69,-97,46,-27,-73,-91,-28,-67,-100,-25,-101,-82,-27,-67,-107,40,41,58,10, -32,32,32,32,-27,-101,-98,32,108,115,115,121,115,95,103,101,116,99,119,100,40,41,10, -59,10, -10, --26,-106,-71,-26,-77,-107,32,-25,-77,-69,-25,-69,-97,46,-27,-83,-104,-27,-100,-88,40,-24,-73,-81,-27,-66,-124,41,58,10, -32,32,32,32,-27,-101,-98,32,108,115,115,121,115,95,101,120,115,105,115,116,115,40,-24,-73,-81,-27,-66,-124,41,10, -59,10, -10, --26,-106,-71,-26,-77,-107,32,-25,-77,-69,-25,-69,-97,46,-27,-120,-101,-27,-69,-70,-25,-101,-82,-27,-67,-107,40,-24,-73,-81,-27,-66,-124,41,58,10, -32,32,32,32,-27,-101,-98,32,108,115,115,121,115,95,109,107,100,105,114,40,-24,-73,-81,-27,-66,-124,41,10, -59,10, -10, --26,-106,-71,-26,-77,-107,32,-25,-77,-69,-25,-69,-97,46,-27,-120,-96,-23,-103,-92,-25,-101,-82,-27,-67,-107,40,-24,-73,-81,-27,-66,-124,41,58,10, -32,32,32,32,-27,-101,-98,32,108,115,115,121,115,95,114,109,100,105,114,40,-24,-73,-81,-27,-66,-124,41,10, -59,10, -10, --26,-106,-71,-26,-77,-107,32,-25,-77,-69,-25,-69,-97,46,-23,-121,-115,-27,-111,-67,-27,-112,-115,40,-26,-105,-89,-27,-112,-115,44,32,-26,-106,-80,-27,-112,-115,41,58,10, -32,32,32,32,-27,-101,-98,32,108,115,115,121,115,95,114,101,110,97,109,101,40,-26,-105,-89,-27,-112,-115,44,32,-26,-106,-80,-27,-112,-115,41,10, -59,10, -10, --26,-106,-71,-26,-77,-107,32,-25,-77,-69,-25,-69,-97,46,-27,-120,-96,-23,-103,-92,40,-24,-73,-81,-27,-66,-124,41,58,10, -32,32,32,32,-27,-101,-98,32,108,115,115,121,115,95,114,101,109,111,118,101,40,-24,-73,-81,-27,-66,-124,41,10, -59,10, -10, --26,-106,-71,-26,-77,-107,32,-25,-77,-69,-25,-69,-97,46,-24,-114,-73,-27,-113,-106,-24,-65,-101,-25,-88,-117,105,100,40,41,58,10, -32,32,32,32,-27,-101,-98,32,108,115,115,121,115,95,103,101,116,112,105,100,40,41,10, -59,10, -10, --26,-106,-71,-26,-77,-107,32,-25,-77,-69,-25,-69,-97,46,-26,-117,-68,-26,-114,-91,-24,-73,-81,-27,-66,-124,40,-25,-108,-78,44,32,-28,-71,-103,41,58,10, -32,32,32,32,-27,-101,-98,32,108,115,115,121,115,95,106,111,105,110,40,-25,-108,-78,44,32,-28,-71,-103,41,10, -59,10, -10, --26,-106,-71,-26,-77,-107,32,-25,-77,-69,-25,-69,-97,46,-26,-108,-71,-27,-113,-104,-27,-73,-91,-28,-67,-100,-25,-101,-82,-27,-67,-107,40,-24,-73,-81,-27,-66,-124,41,58,10, -32,32,32,32,-27,-101,-98,32,108,115,115,121,115,95,99,104,100,105,114,40,-24,-73,-81,-27,-66,-124,41,10, -59,10, -10, --26,-106,-71,-26,-77,-107,32,-25,-77,-69,-25,-69,-97,46,-26,-99,-128,-26,-83,-69,-24,-65,-101,-25,-88,-117,40,-24,-65,-101,-25,-88,-117,105,100,41,58,10, -32,32,32,32,-27,-101,-98,32,108,115,115,121,115,95,107,105,108,108,112,40,-24,-65,-101,-25,-88,-117,105,100,41,10, -59,10, -10, --28,-69,-93,-25,-96,-127,-27,-99,-105,10, -32,32,32,32,-28,-69,-92,32,95,32,61,32,108,115,115,121,115,95,108,112,99,111,117,110,116,40,41,10, -32,32,32,32,-26,-106,-71,-26,-77,-107,32,-25,-77,-69,-25,-69,-97,46,-23,-128,-69,-24,-66,-111,-27,-92,-124,-25,-112,-122,-27,-103,-88,-26,-107,-80,40,41,58,10, -32,32,32,32,32,32,32,32,-27,-101,-98,32,95,10, -32,32,32,32,59,10, -59,10, -10, --28,-69,-93,-25,-96,-127,-27,-99,-105,10, -32,32,32,32,-28,-69,-92,32,95,32,61,32,108,115,115,121,115,95,97,114,99,104,105,116,101,99,116,117,114,101,40,41,10, -32,32,32,32,-26,-106,-71,-26,-77,-107,32,-25,-77,-69,-25,-69,-97,46,-27,-92,-124,-25,-112,-122,-27,-103,-88,-26,-98,-74,-26,-98,-124,40,41,58,10, -32,32,32,32,32,32,32,32,-27,-101,-98,32,95,10, -32,32,32,32,59,10, -59,10, -10, --26,-106,-71,-26,-77,-107,32,-25,-77,-69,-25,-69,-97,46,-26,-128,-69,-27,-122,-123,-27,-83,-104,40,41,58,10, -32,32,32,32,-27,-101,-98,32,108,115,115,121,115,95,109,101,109,116,111,116,97,108,40,41,10, -59,10, -10, --26,-106,-71,-26,-77,-107,32,-25,-77,-69,-25,-69,-97,46,-25,-70,-65,-25,-88,-117,-27,-113,-81,-25,-108,-88,-27,-122,-123,-27,-83,-104,40,41,58,10, -32,32,32,32,-27,-101,-98,32,108,115,115,121,115,95,109,101,109,102,114,101,101,112,40,41,10, -59,10, -10, -0}; -#endif -void ElsLib_lssys_libinit(els_VmObj *vm){ - vm_register(vm,"lssys_killp",ELSAPI_lssys_lssys_killp); - vm_register(vm,"lssys_architecture",ELSAPI_lssys_lssys_architecture); - vm_register(vm,"lssys_rename",ELSAPI_lssys_lssys_rename); - vm_register(vm,"lssys_remove",ELSAPI_lssys_lssys_remove); - vm_register(vm,"lssys_rmdir",ELSAPI_lssys_lssys_rmdir); - vm_register(vm,"lssys_getpid",ELSAPI_lssys_lssys_getpid); - vm_register(vm,"lssys_system",ELSAPI_lssys_lssys_system); - vm_register(vm,"lssys_getenv",ELSAPI_lssys_lssys_getenv); - vm_register(vm,"lssys_getcwd",ELSAPI_lssys_lssys_getcwd); - vm_register(vm,"lssys_join",ELSAPI_lssys_lssys_join); - vm_register(vm,"lssys_pwrite",ELSAPI_lssys_lssys_pwrite); - vm_register(vm,"lssys_chdir",ELSAPI_lssys_lssys_chdir); - vm_register(vm,"lssys_memfreep",ELSAPI_lssys_lssys_memfreep); - vm_register(vm,"lssys_pread",ELSAPI_lssys_lssys_pread); - vm_register(vm,"lssys_memtotal",ELSAPI_lssys_lssys_memtotal); - vm_register(vm,"lssys_lpcount",ELSAPI_lssys_lssys_lpcount); - vm_register(vm,"lssys_popen",ELSAPI_lssys_lssys_popen); - vm_register(vm,"lssys_exsists",ELSAPI_lssys_lssys_exsists); - vm_register(vm,"lssys_mkdir",ELSAPI_lssys_lssys_mkdir); - vm_register(vm,"lssys_getos",ELSAPI_lssys_lssys_getos); - vm_register(vm,"lssys_pclose",ELSAPI_lssys_lssys_pclose); - #ifdef ELS_CONF_TOKEN_EN - vm_dostring(vm,LibScript); - #endif -}; diff --git a/lssys/readme.md b/lssys/readme.md deleted file mode 100755 index 82b6b60c6f89d07e73328a6f5eeb07831ff5dd2c..0000000000000000000000000000000000000000 --- a/lssys/readme.md +++ /dev/null @@ -1,106 +0,0 @@ -#!/bin/owls.wiki.losu.tech -# wiki for lssys - -## 简介 -lssys是洛书stdsys的扩展,加强了其功能。 - -## 函数 -### sys.getos(): str / 系统.操作系统(): 字符串 -+ 参数 - 无 -+ 返回值 - 1. 返回当前操作系统版本,值为"Windows Branch"或"Linux Branch" - -### sys.getenv(name:str): str / 系统.环境变量(名称:字符串): 字符串 -+ 参数 - 1. name 要获取的环境变量的名称 - -+ 返回值 - 1. 对应环境变量的值的字符串 - -### sys.popen(cmd:str, mod:str): unit / 系统.新进程(命令:字符串, 模式:字符串): 单元 -+ 参数 - 1. cmd 要执行的命令 - 2. mod 执行的模式 - -+ 返回值 - 1. 返回创建的管道文件的类,详情见下文 - -### sys.system(cmd:str): int / 系统.调用(命令:字符串): 数字 -+ 参数 - 1. cmd 要执行的命令 - -+ 返回值 - 1. 命令执行后的状态码 - -### sys.getcwd(): str / 系统.工作目录(): 字符串 -+ 参数 - 无 - -+ 返回值 - 1. 当前工作目录的路径的字符串 - -### sys.exsists(path:str): [int/null] / 系统.存在(路径:字符串): [数字/空] -+ 参数 - 1. path 要检查的文件路径 - -+ 返回值 - 1. 路径存在时返回1 - 2. 路径不存在时返回null - -### sys.mkdir(path:str): [int/null] / 系统.创建目录(路径:字符串): [数字/空] -+ 参数 - 1. path 要创建的目录路径 - -+ 返回值 - 1. 创建成功时返回1 - 2. 创建失败时返回null - -### sys.rename(oldname:str, newname:str): [int/null] / 系统.重命名(旧名:字符串, 新名:字符串): [数字/空] -+ 参数 - 1. oldname 要重命名的文件名 - 2. newname 新文件名 - -+ 返回值 - 1. 重命名成功时返回1 - 2. 重命名失败时返回null - -### sys.remove(name:str): [int/null] / 系统.删除(路径:字符串): [数字/空] -+ 参数 - 1. name 要删除的文件路径 - -+ 返回值 - 1. 删除成功时返回1 - 2. 删除失败时返回null - -### sys.getpid(): int / 系统.获取进程id(): 整数 -+ 参数 - 1. 无 - -+ 返回值 - 1. 返回当前进程的id - -### sys.lpcount(): int / 系统.逻辑处理器数(): 整数 -+ 参数 - 无 -+ 返回值 - 1. 当前处理器的逻辑处理器个数 - -### sys.architecture(): str / 系统.处理器架构() -+ 参数 - 无 -+ 返回值 - 1. 当前处理器的架构。会是“X86”、“ARM”的其中一个 - 2. 当架构未知时,返回null - -### sys.memtotal(): int / 系统.总内存(): 整数 -+ 参数 - 无 -+ 返回值 - 1. 当前操作系统的总物理内存 - -### sys.memfreep(): int / 系统.线程可用内存(): 整数 -+ 参数 - 无 -+ 返回值 - 1. 当前线程可用的最大内存 \ No newline at end of file diff --git a/makefile b/makefile new file mode 100755 index 0000000000000000000000000000000000000000..35dd150efa7b188a4d0bf7e108ae9c14005e5b06 --- /dev/null +++ b/makefile @@ -0,0 +1,41 @@ +# root makefile +# export LosuSDK_Root +export losu= LosuSDK is OK! - V$(LosuSDK_Version) +export LosuSDK_Root= $(shell pwd) +export LosuSDK_Pkgs=$(LosuSDK_Root)/pkgs +export LosuSDK_Rule=$(LosuSDK_Root)/rule +export LosuSDK_Tool=$(LosuSDK_Root)/tools +export LosuSDK_Include=$(LosuSDK_Root)/include +export LosuSDK_Build= $(LosuSDK_Root)/build +export LosuSDK_Path=$(LosuSDK_Build)/bin +export LosuSDK_Lib=$(LosuSDK_Build)/lib +export LosuSDK_Obj=$(LosuSDK_Build)/obj +export LosuSDK_Version=2.0.0 + + +# all will make sdk ,and exec a shell +# all: liblosu.a losu losuc losuh + +sdk:\ + $(LosuSDK_Build)/.keep \ + $(LosuSDK_Path)/losuc \ + $(LosuSDK_Path)/losuh \ + $(LosuSDK_Path)/lpkg \ + $(LosuSDK_Build)/target/.keep\ + $(LosuSDK_Build)/target/pkgs/.keep\ + + @sh losu-sdk.sh + @echo "exit Losu-SDK" + +clean: + rm -rf $(LosuSDK_Build) + +cloc: + @cloc ./ --force-lang=python,lsh --force-lang=python,els --force-lang=c,inc --force-lang=python,config + + +include $(LosuSDK_Rule)/keep.mk +include $(LosuSDK_Rule)/liblosu.mk +include $(LosuSDK_Rule)/losuc.mk +include $(LosuSDK_Rule)/losuh.mk +include $(LosuSDK_Rule)/lpkg.mk diff --git a/owls/Ubuntu/makefile b/owls/Ubuntu/makefile deleted file mode 100755 index de02b15a5e9238253881155f84bfe0e4dad82098..0000000000000000000000000000000000000000 --- a/owls/Ubuntu/makefile +++ /dev/null @@ -1,13 +0,0 @@ -OBJS = owls.o -CFLAGS= -O2 -Wall -std=c99 -DLOSU_LINUX -I ../buildenv -fPIC -CC=x86_64-linux-gnu-gcc -T=./ElsLib_owls.lsd - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -shared -s - -clean: - rm -rf $T $(OBJS) core core.* \ No newline at end of file diff --git a/owls/Windows/makefile b/owls/Windows/makefile deleted file mode 100755 index c367400246f4ac47fdddf788b21b281102e7e100..0000000000000000000000000000000000000000 --- a/owls/Windows/makefile +++ /dev/null @@ -1,13 +0,0 @@ -OBJS = owls.o -CFLAGS= -O2 -Wall -std=c99 -DLOSU_WINDOWS -I ../buildenv -fPIC -CC=x86_64-w64-mingw32-gcc -T=ElsLib_owls.lsd - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -L ../buildenv -l:libeasylosu.dll -lm -static -shared -s - -clean: - rm -rf $T $(OBJS) core core.* \ No newline at end of file diff --git a/owls/info b/owls/info deleted file mode 100755 index eaa296877eda9ce56c7b2d76a44ab3d02c0cb915..0000000000000000000000000000000000000000 --- a/owls/info +++ /dev/null @@ -1,20 +0,0 @@ -{ - info = { - name = "owls/轻量级wiki建站工具", - text = "owls · 基于洛书的wiki建站工具", - version = "23.7.3", - }, - source={ - all={ - "owls.els", - "owls.h", - "owls.c", - }, - Ubuntu = {"makefile"}, - Windows = {"makefile"}, - }, - target = { - Ubuntu = "make ; cp ElsLib_owls.lsd target/ElsLib_owls.lsd_Ubuntu ; make clean", - Windows = "make ; cp ElsLib_owls.lsd target/ElsLib_owls.lsd_Windows ; make clean", - } -} \ No newline at end of file diff --git a/owls/owls.c b/owls/owls.c deleted file mode 100755 index b4a822b1b3eaca61850bb2862303d276e643f917..0000000000000000000000000000000000000000 --- a/owls/owls.c +++ /dev/null @@ -1,19 +0,0 @@ -#include"owls.h" -#include - -extern int els_argc; -extern char** els_argv; -extern int els_getargv (els_VmObj *l); -extern int els_getargc (els_VmObj *l); - -int main(int argc,char** argv){ - els_argc = (int)(argc+1); - els_argv = (char**)((argv)-1); - els_VmObj* vm = vm_create(10240); - vm_register(vm,"argv", els_getargv); - vm_register(vm,"argc", els_getargc); - els_lib_init(vm); - ElsLib_owls_libinit(vm); - vm_close(vm); - return 0; -} \ No newline at end of file diff --git a/owls/owls.els b/owls/owls.els deleted file mode 100755 index 19642e5f7c3388b3571768489463ddd78bc303dd..0000000000000000000000000000000000000000 --- a/owls/owls.els +++ /dev/null @@ -1,54 +0,0 @@ -#!script -import('stdlib') -owls = {} -def owls.throw(s): - print("[OWLS-ERROR]\t"&s) - exit(0) -; - - - -# 主函数 Server -def owls.Server(project,wiki,path): - var wwwroot = project.wwwroot - var f = file.open(wwwroot&"owls_theme/owls.html",'r') - var fin = file.open(wiki,'r') - if !fin: owls.throw("找不到文件!") ; - if !f : owls.throw("错误的样式模板!") ; - var s = "" - print("content-type:text/html;charset=utf-8\n\n") - with !f.eof(): - s = f.lineinput() - if replace(s," ","") == "###OWLS_WIKI_MENU###": - owls.List( project.wiki or {},path or'/') - elif replace(s," ","") == "###OWLS_WIKI_TEXT###": - fin.lineinput() - with !fin.eof(): - print(fin.lineinput()) - ; - else - print(s&'\n') - ; - ; - f.close() - fin.close() - -; -# List -def owls.List(obj,path): - for dir,next in obj : - if type(next)=='string': - print("") - else - print("
"& dir &"") - owls.List(next,path&dir&'/') - print("
") - ; - ; -; - - -def owls.start(project,wiki,path): - owls.Server(project,wiki,path) -; -#!end diff --git a/owls/owls.h b/owls/owls.h deleted file mode 100755 index 3ae866c2241f8580e980024aa25569d330246c9e..0000000000000000000000000000000000000000 --- a/owls/owls.h +++ /dev/null @@ -1,62 +0,0 @@ -#include "els.h" -#ifdef ELS_CONF_TOKEN_EN -static const char LibScript[]={ -105,109,112,111,114,116,40,39,115,116,100,108,105,98,39,41,10, -111,119,108,115,32,61,32,123,125,10, -100,101,102,32,111,119,108,115,46,116,104,114,111,119,40,115,41,58,10, -32,32,32,32,112,114,105,110,116,40,34,91,79,87,76,83,45,69,82,82,79,82,93,92,116,34,38,115,41,10, -32,32,32,32,101,120,105,116,40,48,41,10, -59,10, -10, -10, -10, -35,32,-28,-72,-69,-27,-121,-67,-26,-107,-80,32,83,101,114,118,101,114,10, -100,101,102,32,111,119,108,115,46,83,101,114,118,101,114,40,112,114,111,106,101,99,116,44,119,105,107,105,44,112,97,116,104,41,58,10, -32,32,32,32,118,97,114,32,119,119,119,114,111,111,116,32,61,32,112,114,111,106,101,99,116,46,119,119,119,114,111,111,116,10, -32,32,32,32,118,97,114,32,102,32,61,32,102,105,108,101,46,111,112,101,110,40,119,119,119,114,111,111,116,38,34,111,119,108,115,95,116,104,101,109,101,47,111,119,108,115,46,104,116,109,108,34,44,39,114,39,41,10, -32,32,32,32,118,97,114,32,102,105,110,32,61,32,102,105,108,101,46,111,112,101,110,40,119,105,107,105,44,39,114,39,41,10, -32,32,32,32,105,102,32,33,102,105,110,58,32,111,119,108,115,46,116,104,114,111,119,40,34,-26,-119,-66,-28,-72,-115,-27,-120,-80,-26,-106,-121,-28,-69,-74,33,34,41,32,59,10, -32,32,32,32,105,102,32,33,102,32,58,32,111,119,108,115,46,116,104,114,111,119,40,34,-23,-108,-103,-24,-81,-81,-25,-102,-124,-26,-96,-73,-27,-68,-113,-26,-88,-95,-26,-99,-65,33,34,41,32,59,10, -32,32,32,32,118,97,114,32,115,32,61,32,34,34,10, -32,32,32,32,112,114,105,110,116,40,34,99,111,110,116,101,110,116,45,116,121,112,101,58,116,101,120,116,47,104,116,109,108,59,99,104,97,114,115,101,116,61,117,116,102,45,56,92,110,92,110,34,41,10, -32,32,32,32,119,105,116,104,32,33,102,46,101,111,102,40,41,58,10, -32,32,32,32,32,32,32,32,115,32,61,32,102,46,108,105,110,101,105,110,112,117,116,40,41,10, -32,32,32,32,32,32,32,32,105,102,32,114,101,112,108,97,99,101,40,115,44,34,32,34,44,34,34,41,32,61,61,32,34,35,35,35,79,87,76,83,95,87,73,75,73,95,77,69,78,85,35,35,35,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,111,119,108,115,46,76,105,115,116,40,32,112,114,111,106,101,99,116,46,119,105,107,105,32,111,114,32,123,125,44,112,97,116,104,32,111,114,39,47,39,41,32,10, -32,32,32,32,32,32,32,32,101,108,105,102,32,114,101,112,108,97,99,101,40,115,44,34,32,34,44,34,34,41,32,61,61,32,34,35,35,35,79,87,76,83,95,87,73,75,73,95,84,69,88,84,35,35,35,34,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,102,105,110,46,108,105,110,101,105,110,112,117,116,40,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,119,105,116,104,32,33,102,105,110,46,101,111,102,40,41,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,112,114,105,110,116,40,102,105,110,46,108,105,110,101,105,110,112,117,116,40,41,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,59,10, -32,32,32,32,32,32,32,32,101,108,115,101,32,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,114,105,110,116,40,115,38,39,92,110,39,41,10, -32,32,32,32,32,32,32,32,59,10, -32,32,32,32,59,10, -32,32,32,32,102,46,99,108,111,115,101,40,41,10, -32,32,32,32,102,105,110,46,99,108,111,115,101,40,41,10, -10, -59,10, -35,32,76,105,115,116,32,10, -100,101,102,32,111,119,108,115,46,76,105,115,116,40,111,98,106,44,112,97,116,104,41,58,10, -32,32,32,32,102,111,114,32,100,105,114,44,110,101,120,116,32,105,110,32,111,98,106,32,58,32,10, -32,32,32,32,32,32,32,32,105,102,32,116,121,112,101,40,110,101,120,116,41,61,61,39,115,116,114,105,110,103,39,58,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,60,100,105,118,32,99,108,97,115,115,61,39,79,87,76,83,95,87,73,75,73,95,77,69,78,85,95,70,73,76,69,39,62,60,97,32,104,114,101,102,61,39,34,38,112,97,116,104,38,32,110,101,120,116,32,38,34,39,62,34,38,110,101,120,116,38,34,60,47,97,62,60,47,100,105,118,62,34,41,10, -32,32,32,32,32,32,32,32,101,108,115,101,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,60,100,101,116,97,105,108,115,62,60,115,117,109,109,97,114,121,62,34,38,32,100,105,114,32,38,34,60,47,115,117,109,109,97,114,121,62,34,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,111,119,108,115,46,76,105,115,116,40,110,101,120,116,44,112,97,116,104,38,100,105,114,38,39,47,39,41,10, -32,32,32,32,32,32,32,32,32,32,32,32,112,114,105,110,116,40,34,60,47,100,101,116,97,105,108,115,62,34,41,32,10, -32,32,32,32,32,32,32,32,59,10, -32,32,32,32,59,10, -59,10, -10, -10, -100,101,102,32,111,119,108,115,46,115,116,97,114,116,40,112,114,111,106,101,99,116,44,119,105,107,105,44,112,97,116,104,41,58,10, -32,32,32,32,111,119,108,115,46,83,101,114,118,101,114,40,112,114,111,106,101,99,116,44,119,105,107,105,44,112,97,116,104,41,10, -59,10, -0}; -#endif -void ElsLib_owls_libinit(els_VmObj *vm){ - #ifdef ELS_CONF_TOKEN_EN - vm_dostring(vm,LibScript); - #endif -}; diff --git a/owls/readme.md b/owls/readme.md deleted file mode 100755 index b2d6c55ee406a7d6b9a0d975d0c4a3a136a8992c..0000000000000000000000000000000000000000 --- a/owls/readme.md +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/owls.wiki.losu.tech -# owls · wiki服务黑魔法 -## OWLS可以做什么? -+ OWLS是一个基于洛书实现的wiki建站服务工具,可以让您利用markdown文档生成精美的web网页 -## OWLS有哪些特色? -+ 更轻量、快速的选择 - - 基于高效的 losu script,完全由其标准库书写,仅需数十KB的资源需求 - - 支持多种markdown引擎 - - 通过洛书模块工具一键部署 -+ 满足个性化需求 - - 原生html模块支持 - - 支持工程自定义模板 -+ 无中间文件 - - 无html输出生成 - - 适合git版本管理机制 - - 保持源码整洁度 -## 如何使用? -## 安装与初始化 -1. 安装 洛书 v1.6.8+ 版本 -2. ```losu -r lpt install owls``` - - -## 编写工程文档 -```python -#!/bin/losu -import('owls') - -# 创建一个名为 web_losu 的工程,其根目录为 /var/www/losu -web_losu = { - wwwroot = "/var/www/losu/", - wiki = { - # 这里是绑定所有出现在侧边栏的文件 - [1] = "readme.md", - ["test"] = { # 这是指 test 目录下的 readm.md 文件,/var/www/losu/test/readme.md - [1] = "readme.md", - }, - } -} - -# 可以创建多个工程 - -owls.start(web_losu,argv(1)) - -``` - -## 编写主题 -+ 以 losu 工程为例,其主题目录为 wwwroot/owls_theme -+ 你可以访问[洛书官网](https://losu.tech)下载主题样例 - -## 编写文档 -+ 您可以遵循markdown格式自由的编写 -+ 创建链接,将 工程文档 链接到 /bin/owls_losu, -+ 在文档开头写一行声明```#!/bin/owls_losu```,这将另其可以被渲染 - -## 配置服务器 -+ 将所.md的文件配置为可执行的cgi程序,__注意__ ,不要将md文件所在目录配置为cgi-bin,这样会引起图片等多媒体资源的不可访问 -+ 检查,修改文件权限为 555 -+ 启动服务器,访问 xxx.md,观察效果 - diff --git a/lsnput/WIKI/.keep b/pkgs/.keep old mode 100644 new mode 100755 similarity index 100% rename from lsnput/WIKI/.keep rename to pkgs/.keep diff --git a/pkgs/cstring/config b/pkgs/cstring/config new file mode 100755 index 0000000000000000000000000000000000000000..72b102f5f5f89510e634d1fa724ef2c0729c132b --- /dev/null +++ b/pkgs/cstring/config @@ -0,0 +1,9 @@ +pkgs = { + name: "string", + version: "2.0.0", + description: "", + target:{ + "x86_64-linux-gnu", + "x86_64-w64-mingw32", + }, +} \ No newline at end of file diff --git a/pkgs/cstring/cstring.lsh b/pkgs/cstring/cstring.lsh new file mode 100755 index 0000000000000000000000000000000000000000..41bb004da6e853b46fe18910e2e5bd9f03e6f669 --- /dev/null +++ b/pkgs/cstring/cstring.lsh @@ -0,0 +1,40 @@ +# 类 C 的字符串函数库,该类函数都是以 C 风格处理字符串,字符串以 '\0' 结尾,第一个字符的位置为 0, +module cstring + sub cstring + def strlen(s:str ): + "@fn strlen(s:str) -> int" + "@brief 返回字符串的 C 风格长度" + def strstr(fs:str, ss:str): + "@fn strstr(fs:str, ss:str) -> str" + "@brief 返回在 fs 中以 ss 开头的字符串" + def strtok(s:str, sep:str): + "@fn strtok(s:str, sep:str) -> str" + "@brief 返回在 s 中以 sep 分隔的字符串" + def strmid(s:str, start:int, end:int): + "@fn strmid(s:str, start:int, end:int) -> str" + "@brief 返回 s 中从 start 到 end 的子字符串" + def strrev(s:str): + "@fn strrev(s:str) -> str" + "@brief 返回 s 的反转字符串" + def strupper(s:str): + "@fn strupper(s:str) -> str" + "@brief 返回 s 的大写字符串" + def strlower(s:str): + "@fn strlower(s:str) -> str" + "@brief 返回 s 的小写字符串" + def strcpy(...:str ): + "@fn strcpy(...:str ) -> str" + "@brief 返回连接所有参数的字符串" + # def strreplace(s:str, old:str, new:str): + # "@fn strreplace(s:str, old:str, new:str) -> str" + # "@brief 返回 s 中 old 字符串被 new 替换后的字符串" + def strcount(s:str, ss:str ): + "@fn strcount(s:str, ss:str) -> int" + "@brief 返回 s 中 ss 字符串出现的次数" + def strcmp(s1:str, s2:str, len:int ): + "@fn strcmp(s1:str, s2:str, len:int) -> int" + "@brief 返回 s1 和 s2 的比较结果, 不指定 len 则比较整个字符串" + def strnew(s:str, n:int): + "@fn strnew(s:str, n:int) -> str" + "@brief 将 n 个 s 连接起来" + \ No newline at end of file diff --git a/pkgs/cstring/cstring.lsh.c b/pkgs/cstring/cstring.lsh.c new file mode 100755 index 0000000000000000000000000000000000000000..e89c117dcaf87952a926998bad729ec7a4928e53 --- /dev/null +++ b/pkgs/cstring/cstring.lsh.c @@ -0,0 +1,121 @@ + +/* + This file was generated by losuh - Losu Header Generator, which is part of + the Losu SDK. + + Losu is an open source programming language from China with excellent + performance (comparable to lua), ultra-lightweight resource footprint (only + 4KB RAM) and easy-to-learn syntax (similar to Python) for IoT development. + + This file follows the following MIT LICENSE by default + ------------------------------------ + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + +*/ + +#include "cstring.lsh.h" +static int32_t __losuh__submod_cstring_cstring(LosuVm *vm); + + +static LosuModule __losuh__MODULELIST[] = { +{"cstring",__losuh__submod_cstring_cstring}, +{NULL,NULL}, +}; +LosuModule *__losuh__LOADMODULE_cstring() { +return &__losuh__MODULELIST[0]; +} + + +static int32_t __losuh__submod_cstring_cstring(LosuVm *vm) { +// constructors of number in cstring + +// constructors of string in cstring + +// constructors of function in cstring +/** +* @fn strlen(s:str) -> int +* @brief 返回字符串的 C 风格长度 +*/ +__losuhAPI_regFunc(vm,"strlen",__losuh__func_strlen_cstring_cstring); +/** +* @fn strstr(fs:str, ss:str) -> str +* @brief 返回在 fs 中以 ss 开头的字符串 +*/ +__losuhAPI_regFunc(vm,"strstr",__losuh__func_strstr_cstring_cstring); +/** +* @fn strtok(s:str, sep:str) -> str +* @brief 返回在 s 中以 sep 分隔的字符串 +*/ +__losuhAPI_regFunc(vm,"strtok",__losuh__func_strtok_cstring_cstring); +/** +* @fn strmid(s:str, start:int, end:int) -> str +* @brief 返回 s 中从 start 到 end 的子字符串 +*/ +__losuhAPI_regFunc(vm,"strmid",__losuh__func_strmid_cstring_cstring); +/** +* @fn strrev(s:str) -> str +* @brief 返回 s 的反转字符串 +*/ +__losuhAPI_regFunc(vm,"strrev",__losuh__func_strrev_cstring_cstring); +/** +* @fn strupper(s:str) -> str +* @brief 返回 s 的大写字符串 +*/ +__losuhAPI_regFunc(vm,"strupper",__losuh__func_strupper_cstring_cstring); +/** +* @fn strlower(s:str) -> str +* @brief 返回 s 的小写字符串 +*/ +__losuhAPI_regFunc(vm,"strlower",__losuh__func_strlower_cstring_cstring); +/** +* @fn strcpy(...:str ) -> str +* @brief 返回连接所有参数的字符串 +*/ +__losuhAPI_regFunc(vm,"strcpy",__losuh__func_strcpy_cstring_cstring); +/** +* @fn strcount(s:str, ss:str) -> int +* @brief 返回 s 中 ss 字符串出现的次数 +*/ +__losuhAPI_regFunc(vm,"strcount",__losuh__func_strcount_cstring_cstring); +/** +* @fn strcmp(s1:str, s2:str, len:int) -> int +* @brief 返回 s1 和 s2 的比较结果, 不指定 len 则比较整个字符串 +*/ +__losuhAPI_regFunc(vm,"strcmp",__losuh__func_strcmp_cstring_cstring); +/** +* @fn strnew(s:str, n:int) -> str +* @brief 将 n 个 s 连接起来 +*/ +__losuhAPI_regFunc(vm,"strnew",__losuh__func_strnew_cstring_cstring); + +// constructors of script in cstring + +// constructors of object in cstring + +// constructors of class in cstring + + +return 0; +} + + + + diff --git a/pkgs/cstring/cstring.lsh.h b/pkgs/cstring/cstring.lsh.h new file mode 100755 index 0000000000000000000000000000000000000000..1a3a2ebc68c8b412d31d4cc40b8288e57f79be95 --- /dev/null +++ b/pkgs/cstring/cstring.lsh.h @@ -0,0 +1,91 @@ + +/* + This file was generated by losuh - Losu Header Generator, which is part of + the Losu SDK. + + Losu is an open source programming language from China with excellent + performance (comparable to lua), ultra-lightweight resource footprint (only + 4KB RAM) and easy-to-learn syntax (similar to Python) for IoT development. + + This file follows the following MIT LICENSE by default + ------------------------------------ + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + +*/ + +#include "losu.h" +#include "losuh.h" +LosuModule *__losuh__LOADMODULE_cstring (); +/** + * @fn strlen(s:str) -> int + * @brief 返回字符串的 C 风格长度 + */ +int32_t __losuh__func_strlen_cstring_cstring (LosuVm *vm); +/** + * @fn strstr(fs:str, ss:str) -> str + * @brief 返回在 fs 中以 ss 开头的字符串 + */ +int32_t __losuh__func_strstr_cstring_cstring (LosuVm *vm); +/** + * @fn strtok(s:str, sep:str) -> str + * @brief 返回在 s 中以 sep 分隔的字符串 + */ +int32_t __losuh__func_strtok_cstring_cstring (LosuVm *vm); +/** + * @fn strmid(s:str, start:int, end:int) -> str + * @brief 返回 s 中从 start 到 end 的子字符串 + */ +int32_t __losuh__func_strmid_cstring_cstring (LosuVm *vm); +/** + * @fn strrev(s:str) -> str + * @brief 返回 s 的反转字符串 + */ +int32_t __losuh__func_strrev_cstring_cstring (LosuVm *vm); +/** + * @fn strupper(s:str) -> str + * @brief 返回 s 的大写字符串 + */ +int32_t __losuh__func_strupper_cstring_cstring (LosuVm *vm); +/** + * @fn strlower(s:str) -> str + * @brief 返回 s 的小写字符串 + */ +int32_t __losuh__func_strlower_cstring_cstring (LosuVm *vm); +/** + * @fn strcpy(...:str ) -> str + * @brief 返回连接所有参数的字符串 + */ +int32_t __losuh__func_strcpy_cstring_cstring (LosuVm *vm); +/** + * @fn strcount(s:str, ss:str) -> int + * @brief 返回 s 中 ss 字符串出现的次数 + */ +int32_t __losuh__func_strcount_cstring_cstring (LosuVm *vm); +/** + * @fn strcmp(s1:str, s2:str, len:int) -> int + * @brief 返回 s1 和 s2 的比较结果, 不指定 len 则比较整个字符串 + */ +int32_t __losuh__func_strcmp_cstring_cstring (LosuVm *vm); +/** + * @fn strnew(s:str, n:int) -> str + * @brief 将 n 个 s 连接起来 + */ +int32_t __losuh__func_strnew_cstring_cstring (LosuVm *vm); diff --git a/pkgs/cstring/libcstring.c b/pkgs/cstring/libcstring.c new file mode 100755 index 0000000000000000000000000000000000000000..6d72c0fdc5a112a30dc9db452d3628330a5e28ef --- /dev/null +++ b/pkgs/cstring/libcstring.c @@ -0,0 +1,347 @@ +/* + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +/* + This file was generated by losuh - Losu Header Generator, which is part of + the Losu SDK. + + Losu is an open source programming language from China with excellent + performance (comparable to lua), ultra-lightweight resource footprint (only + 4KB RAM) and easy-to-learn syntax (similar to Python) for IoT development. + + This file follows the following MIT LICENSE by default + ------------------------------------ + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + +*/ + +#include "cstring.lsh.h" +#include "losu_malloc.h" +#include + +static uint8_t __utf8CheckLen (uint8_t c); + +/** + * @fn strlen(s:str) -> int + * @brief 返回字符串的 C 风格长度 + */ +int32_t +__losuh__func_strlen_cstring_cstring (LosuVm *vm) +{ + const char *s = arg_getstr (vm, 1); + arg_returnnum (vm, (_l_number)strlen (s)); + return 1; +} +/** + * @fn strstr(fs:str, ss:str) -> str + * @brief 返回在 fs 中以 ss 开头的字符串 + */ +int32_t +__losuh__func_strstr_cstring_cstring (LosuVm *vm) +{ + const char *fs = arg_getstr (vm, 1); + const char *ss = arg_getstr (vm, 2); + arg_returnstr (vm, strstr (fs, ss)); + return 1; +} +/** + * @fn strtok(s:str, sep:str) -> str + * @brief 返回在 s 中以 sep 分隔的字符串 + */ +int32_t +__losuh__func_strtok_cstring_cstring (LosuVm *vm) +{ + LosuObj *s = arg_get (vm, 1); + LosuObj *sep = arg_get (vm, 2); + const char *r = NULL; + if (obj_type (vm, s) == LosuTypeDefine_null) + r = strtok (NULL, obj_tostr (vm, sep)); + else + r = strtok ((char *)obj_tostr (vm, s), obj_tostr (vm, sep)); + if (r == NULL) + return 0; + arg_returnstr (vm, r); + return 1; +} +/** + * @fn strmid(s:str, start:int, end:int) -> str + * @brief 返回 s 中从 start 到 end 的子字符串 + */ +int32_t +__losuh__func_strmid_cstring_cstring (LosuVm *vm) +{ + const char *s = arg_getstr (vm, 1); + int32_t start = arg_getnum (vm, 2); + int32_t end = arg_getnum (vm, 3); + LosuObj o = obj_newstrlen (vm, (char *)s + start, end - start + 1); + arg_return (vm, o); + return 1; +} +/** + * @fn strrev(s:str) -> str + * @brief 返回 s 的反转字符串 + */ +int32_t +__losuh__func_strrev_cstring_cstring (LosuVm *vm) +{ + const char *s = arg_getstr (vm, 1); + size_t len = strlen (s); + size_t count = len - 1; + char *r = __losu_mem_malloc (vm, len + 1); + memset (r, 0, len + 1); + + for (size_t i = 0; i < len;) + { + uint8_t clen = __utf8CheckLen (s[i]); + switch (clen) + { + case 1: + r[count] = s[i]; + break; + case 2: + r[count - 1] = s[i]; + r[count] = s[i + 1]; + break; + case 3: + r[count - 2] = s[i]; + r[count - 1] = s[i + 1]; + r[count] = s[i + 2]; + break; + case 4: + r[count - 3] = s[i]; + r[count - 2] = s[i + 1]; + r[count - 1] = s[i + 2]; + r[count] = s[i + 3]; + break; + default: + break; + } + i += clen; + count -= clen; + } + arg_returnstr (vm, r); + __losu_mem_free (vm, r); + return 1; +} +/** + * @fn strupper(s:str) -> str + * @brief 返回 s 的大写字符串 + */ +int32_t +__losuh__func_strupper_cstring_cstring (LosuVm *vm) +{ + const char *s = arg_getstr (vm, 1); + size_t len = strlen (s); + char *r = __losu_mem_malloc (vm, len + 1); + memset (r, 0, len + 1); + for (size_t i = 0; i < len; i++) + { + if (s[i] >= 'a' && s[i] <= 'z') + r[i] = s[i] - 32; + else + r[i] = s[i]; + } + arg_returnstr (vm, r); + __losu_mem_free (vm, r); + return 1; +} +/** + * @fn strlower(s:str) -> str + * @brief 返回 s 的小写字符串 + */ +int32_t +__losuh__func_strlower_cstring_cstring (LosuVm *vm) +{ + const char *s = arg_getstr (vm, 1); + size_t len = strlen (s); + char *r = __losu_mem_malloc (vm, len + 1); + memset (r, 0, len + 1); + for (size_t i = 0; i < len; i++) + { + if (s[i] >= 'A' && s[i] <= 'Z') + r[i] = s[i] + 32; + else + r[i] = s[i]; + } + arg_returnstr (vm, r); + __losu_mem_free (vm, r); + return 1; +} +/** + * @fn strcpy(...:str ) -> str + * @brief 返回连接所有参数的字符串 + */ +int32_t +__losuh__func_strcpy_cstring_cstring (LosuVm *vm) +{ + int32_t args = arg_num (vm); + size_t len = 0; + const char **slist = __losu_mem_malloc (vm, args * sizeof (char *)); + for (int32_t i = 1; i <= args; i++) + { + slist[i - 1] = arg_getstr (vm, i); + len += strlen (slist[i - 1]); + } + char *r = __losu_mem_malloc (vm, len + 1); + memset (r, 0, len + 1); + for (int32_t i = 0; i < args; i++) + strcat (r, slist[i]); + arg_returnstr (vm, r); + __losu_mem_free (vm, r); + return 1; +} + +/** + * @fn strcount(s:str, ss:str) -> int + * @brief 返回 s 中 ss 字符串出现的次数 + */ +int32_t +__losuh__func_strcount_cstring_cstring (LosuVm *vm) +{ + const char *s1 = arg_getstr (vm, 1); + const char *s2 = arg_getstr (vm, 2); + size_t len1 = strlen (s1); + size_t len2 = strlen (s2); + int32_t count = 0; + int32_t ans = 0; + + for (int32_t i = 0; i < len1; i++) + { + if (s1[i] == s2[0]) + { + count = 0; + for (int32_t j = i; j < i + len2; j++) + { + if (s1[j] != s2[j - i]) + break; + else + count++; + if (count == len2) + ans++; + } + } + } + arg_returnnum (vm, ans); + return 1; +} +/** + * @fn strcmp(s1:str, s2:str, len:int) -> int + * @brief 返回 s1 和 s2 的比较结果, 不指定 len 则比较整个字符串 + */ +int32_t +__losuh__func_strcmp_cstring_cstring (LosuVm *vm) +{ + const char *s1 = arg_getstr (vm, 1); + const char *s2 = arg_getstr (vm, 2); + LosuObj *lenobj = arg_get (vm, 3); + int32_t r = 0; + if (obj_type (vm, lenobj) == LosuTypeDefine_null) + r = strcmp (s1, s2); + else + r = strncmp (s1, s2, (size_t)obj_tonum (vm, lenobj)); + r = r < 0 ? -1 : (r > 0 ? 1 : 0); + arg_returnnum (vm, r); + return 1; +} +/** + * @fn strnew(s:str, n:int) -> str + * @brief 将 n 个 s 连接起来 + */ +int32_t +__losuh__func_strnew_cstring_cstring (LosuVm *vm) +{ + const char *s = arg_getstr (vm, 1); + int32_t n = arg_getnum (vm, 2); + size_t len = strlen (s); + char *r = __losu_mem_malloc (vm, len * n + 1); + memset (r, 0, len * n + 1); + for (int32_t i = 0; i < n; i++) + strcat (r, s); + arg_returnstr (vm, r); + __losu_mem_free (vm, r); + return 1; +} + +static uint8_t +__utf8CheckLen (uint8_t c) +{ + /** 单字节序列的 leader byte 总是在(0-127)范围内。 + * 两字节序列的 leader byte 在(194-223)范围内。 + * 三字节序列的 leader byte 在(224-239)范围内。 + * 四字节序列的 leader byte 在(240-247)范围内。 + * */ + uint8_t len = 0; + if (c < 0x80) + { /* then UTF-8 单字节 */ + len = 1; + } + else if (c >= 0xC2 && c <= 0xDF) + { /* then 首字节 UTF-8 占用2个字节 */ + len = 2; + } + else if (c >= 0xE0 && c <= 0xEF) + { /* then 首字节 UTF-8 占用3个字节 */ + len = 3; + } + else if (c >= 0xF0 && c <= 0xF7) + { /* then 首字节 UTF-8 占用4个字节 */ + len = 4; + } + + return len; +} \ No newline at end of file diff --git a/pkgs/cstring/target/x86_64-linux-gnu.mk b/pkgs/cstring/target/x86_64-linux-gnu.mk new file mode 100755 index 0000000000000000000000000000000000000000..043c3032f4645cee5b1cf045e367fd740721754c --- /dev/null +++ b/pkgs/cstring/target/x86_64-linux-gnu.mk @@ -0,0 +1,30 @@ +PkgTarget=$(LosuSDK_Build)/target/pkgs +PkgObj=$(LosuSDK_Build)/obj/target/pkgs/cstring + +cc=x86_64-linux-gnu-gcc + +CIncFile=$(shell ls $(LosuSDK_Include)/*.h) cstring.lsh.h + +cWarning= -Wall +cStd= -std=gnu99 +cOpt= -O2 +cInclude= -I$(LosuSDK_Include) + +cFlags= $(cWarning) $(cStd) $(cOpt) $(cInclude) + +$(PkgTarget)/liblpkgcstring.a:\ + $(PkgObj)/.keep\ + $(PkgObj)/cstring.lsh.o\ + $(PkgObj)/libcstring.o\ + + ar crs $@ $^ + +$(PkgObj)/.keep: + mkdir -p $(PkgObj) + touch $@ + +$(PkgObj)/cstring.lsh.o: cstring.lsh.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ + +$(PkgObj)/libcstring.o: libcstring.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ \ No newline at end of file diff --git a/pkgs/cstring/target/x86_64-w64-mingw32.mk b/pkgs/cstring/target/x86_64-w64-mingw32.mk new file mode 100755 index 0000000000000000000000000000000000000000..b3101d28e029f0067613ab9ddb1938d415343de5 --- /dev/null +++ b/pkgs/cstring/target/x86_64-w64-mingw32.mk @@ -0,0 +1,30 @@ +PkgTarget=$(LosuSDK_Build)/target/pkgs +PkgObj=$(LosuSDK_Build)/obj/target/pkgs/cstring + +cc=x86_64-w64-mingw32-gcc + +CIncFile=$(shell ls $(LosuSDK_Include)/*.h) cstring.lsh.h + +cWarning= -Wall +cStd= -std=gnu99 +cOpt= -O2 +cInclude= -I$(LosuSDK_Include) + +cFlags= $(cWarning) $(cStd) $(cOpt) $(cInclude) + +$(PkgTarget)/liblpkgcstring.a:\ + $(PkgObj)/.keep\ + $(PkgObj)/cstring.lsh.o\ + $(PkgObj)/libcstring.o\ + + ar crs $@ $^ + +$(PkgObj)/.keep: + mkdir -p $(PkgObj) + touch $@ + +$(PkgObj)/cstring.lsh.o: cstring.lsh.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ + +$(PkgObj)/libcstring.o: libcstring.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ \ No newline at end of file diff --git a/pkgs/file/config b/pkgs/file/config new file mode 100755 index 0000000000000000000000000000000000000000..d0ae3234bf4763f670a2999d37c806c33d986d7c --- /dev/null +++ b/pkgs/file/config @@ -0,0 +1,9 @@ +pkgs = { + name: "file", + version: "2.0.0", + description: "", + target:{ + "x86_64-linux-gnu", + "x86_64-w64-mingw32", + }, +} \ No newline at end of file diff --git a/pkgs/file/file.lsh b/pkgs/file/file.lsh new file mode 100755 index 0000000000000000000000000000000000000000..dc4302ae04a97f960571d2c939e0385050fb125a --- /dev/null +++ b/pkgs/file/file.lsh @@ -0,0 +1,54 @@ +module file + sub fileclass + class file(fn:str ,mode:str ='r'): + "@class file(self,fn:str ,mode:str ='r')" + "@brief 创建一个 file 对象, 并打开文件" + "@param fn 文件名" + "@param mode 打开文件的模式, 与 C 语言的 fopen 函数相同" + "@return file 对象, 失败返回 null" + def close(self): + "@fn file.close(self) ->bool" + "@brief 关闭文件" + "@return null 表示失败, 1 表示成功" + def putc(self,c:str): + "@fn file.putc(self,c:str) ->bool" + "@brief 向文件中写入一个字符" + "@param c 要写入的字符" + "@return null 表示失败, 1 表示成功" + def print(self,s:str): + "@fn file.print(self,s:str) ->bool" + "@brief 向文件中写入一个字符串" + "@param s 要写入的字符串" + "@return null 表示失败, 1 表示成功" + def read(self,n:int): + "@fn file.read(self,n:int) ->str" + "@brief 从文件中读取 n 个字符" + "@param n 要读取的字符数" + "@return 读取到的字符串, 失败返回 null" + def readline(self): + "@fn file.readline(self) ->str" + "@brief 从文件中读取一行" + "@return 读取到的字符串, 失败返回 null" + def getc(self): + "@fn file.getc(self) ->str" + "@brief 从文件中读取一个字符" + "@return 读取到的字符, 失败返回 null" + def eof(self): + "@fn file.eof(self) ->bool" + "@brief 判断文件是否已经读到末尾" + "@return 1 表示已经读到末尾, null 表示还没有到末尾" + def seek(self,offset:int,whence:int): + "@fn file.seek(self,offset:int,whence:int) ->bool" + "@brief 移动文件指针" + "@param offset 偏移量" + "@param whence 从哪里开始偏移, 0 表示文件开头, 1 表示当前位置, 2 表示文件末尾" + "@return null 表示失败, 1 表示成功" + def tell(self): + "@fn file.tell(self) ->int" + "@brief 获取文件指针当前位置, 从文件开头算起" + "@return 文件指针当前位置, 失败返回 -1" + def rewind(self): + "@fn file.rewind(self) ->bool" + "@brief 将文件指针移动到文件开头" + "@return null 表示失败, 1 表示成功" + \ No newline at end of file diff --git a/pkgs/file/file.lsh.c b/pkgs/file/file.lsh.c new file mode 100755 index 0000000000000000000000000000000000000000..59cba4b950b6b7ce79c90ad05d16a3be210a2c39 --- /dev/null +++ b/pkgs/file/file.lsh.c @@ -0,0 +1,153 @@ + +/* + This file was generated by losuh - Losu Header Generator, which is part of + the Losu SDK. + + Losu is an open source programming language from China with excellent + performance (comparable to lua), ultra-lightweight resource footprint (only + 4KB RAM) and easy-to-learn syntax (similar to Python) for IoT development. + + This file follows the following MIT LICENSE by default + ------------------------------------ + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + +*/ + +#include "file.lsh.h" +static int32_t __losuh__submod_fileclass_file(LosuVm *vm); +static LosuObj __losuh__class_file_fileclass_file(LosuVm *vm); + + +static LosuModule __losuh__MODULELIST[] = { +{"fileclass",__losuh__submod_fileclass_file}, +{NULL,NULL}, +}; +LosuModule *__losuh__LOADMODULE_file() { +return &__losuh__MODULELIST[0]; +} + + +static int32_t __losuh__submod_fileclass_file(LosuVm *vm) { +// constructors of number in fileclass + +// constructors of string in fileclass + +// constructors of function in fileclass + +// constructors of script in fileclass + +// constructors of object in fileclass + +// constructors of class in fileclass + +__losuhAPI_regClass(vm,"file",__losuh__class_file_fileclass_file(vm)); + + +return 0; +} + + + +static LosuObj __losuh__class_file_fileclass_file(LosuVm *vm){ +LosuObj newObj = obj_newunit(vm); +// constructor of number in file@fileclass_file + +// constructor of string in file@fileclass_file + +// constructor of function in file@fileclass_file +/** +* @fn file.close(self) ->bool +* @brief 关闭文件 +* @return null 表示失败, 1 表示成功 +*/ +__losuhAPI_regObjFunc(vm,newObj,"close",__losuh__func_close_file_fileclass_file); +/** +* @fn file.putc(self,c:str) ->bool +* @brief 向文件中写入一个字符 +* @param c 要写入的字符 +* @return null 表示失败, 1 表示成功 +*/ +__losuhAPI_regObjFunc(vm,newObj,"putc",__losuh__func_putc_file_fileclass_file); +/** +* @fn file.print(self,s:str) ->bool +* @brief 向文件中写入一个字符串 +* @param s 要写入的字符串 +* @return null 表示失败, 1 表示成功 +*/ +__losuhAPI_regObjFunc(vm,newObj,"print",__losuh__func_print_file_fileclass_file); +/** +* @fn file.read(self,n:int) ->str +* @brief 从文件中读取 n 个字符 +* @param n 要读取的字符数 +* @return 读取到的字符串, 失败返回 null +*/ +__losuhAPI_regObjFunc(vm,newObj,"read",__losuh__func_read_file_fileclass_file); +/** +* @fn file.readline(self) ->str +* @brief 从文件中读取一行 +* @return 读取到的字符串, 失败返回 null +*/ +__losuhAPI_regObjFunc(vm,newObj,"readline",__losuh__func_readline_file_fileclass_file); +/** +* @fn file.getc(self) ->str +* @brief 从文件中读取一个字符 +* @return 读取到的字符, 失败返回 null +*/ +__losuhAPI_regObjFunc(vm,newObj,"getc",__losuh__func_getc_file_fileclass_file); +/** +* @fn file.eof(self) ->bool +* @brief 判断文件是否已经读到末尾 +* @return 1 表示已经读到末尾, null 表示还没有到末尾 +*/ +__losuhAPI_regObjFunc(vm,newObj,"eof",__losuh__func_eof_file_fileclass_file); +/** +* @fn file.seek(self,offset:int,whence:int) ->bool +* @brief 移动文件指针 +* @param offset 偏移量 +* @param whence 从哪里开始偏移, 0 表示文件开头, 1 表示当前位置, 2 表示文件末尾 +* @return null 表示失败, 1 表示成功 +*/ +__losuhAPI_regObjFunc(vm,newObj,"seek",__losuh__func_seek_file_fileclass_file); +/** +* @fn file.tell(self) ->int +* @brief 获取文件指针当前位置, 从文件开头算起 +* @return 文件指针当前位置, 失败返回 -1 +*/ +__losuhAPI_regObjFunc(vm,newObj,"tell",__losuh__func_tell_file_fileclass_file); +/** +* @fn file.rewind(self) ->bool +* @brief 将文件指针移动到文件开头 +* @return null 表示失败, 1 表示成功 +*/ +__losuhAPI_regObjFunc(vm,newObj,"rewind",__losuh__func_rewind_file_fileclass_file); +/** +* @class file(self,fn:str ,mode:str ='r') +* @brief 创建一个 file 对象, 并打开文件 +* @param fn 文件名 +* @param mode 打开文件的模式, 与 C 语言的 fopen 函数相同 +* @return file 对象, 失败返回 null +*/ +__losuhAPI_regObjFunc(vm,newObj,"__init__",__losuh__func___init___file_fileclass_file); + +return newObj; +} + + diff --git a/pkgs/file/file.lsh.h b/pkgs/file/file.lsh.h new file mode 100755 index 0000000000000000000000000000000000000000..c0e8f77cc333e2ffb466e633c56cfaedc2d1f1fc --- /dev/null +++ b/pkgs/file/file.lsh.h @@ -0,0 +1,110 @@ + +/* + This file was generated by losuh - Losu Header Generator, which is part of + the Losu SDK. + + Losu is an open source programming language from China with excellent + performance (comparable to lua), ultra-lightweight resource footprint (only + 4KB RAM) and easy-to-learn syntax (similar to Python) for IoT development. + + This file follows the following MIT LICENSE by default + ------------------------------------ + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + +*/ + +#include "losu.h" +#include "losuh.h" +LosuModule *__losuh__LOADMODULE_file(); +/** +* @fn file.close(self) ->bool +* @brief 关闭文件 +* @return null 表示失败, 1 表示成功 +*/ +int32_t __losuh__func_close_file_fileclass_file(LosuVm *vm); +/** +* @fn file.putc(self,c:str) ->bool +* @brief 向文件中写入一个字符 +* @param c 要写入的字符 +* @return null 表示失败, 1 表示成功 +*/ +int32_t __losuh__func_putc_file_fileclass_file(LosuVm *vm); +/** +* @fn file.print(self,s:str) ->bool +* @brief 向文件中写入一个字符串 +* @param s 要写入的字符串 +* @return null 表示失败, 1 表示成功 +*/ +int32_t __losuh__func_print_file_fileclass_file(LosuVm *vm); +/** +* @fn file.read(self,n:int) ->str +* @brief 从文件中读取 n 个字符 +* @param n 要读取的字符数 +* @return 读取到的字符串, 失败返回 null +*/ +int32_t __losuh__func_read_file_fileclass_file(LosuVm *vm); +/** +* @fn file.readline(self) ->str +* @brief 从文件中读取一行 +* @return 读取到的字符串, 失败返回 null +*/ +int32_t __losuh__func_readline_file_fileclass_file(LosuVm *vm); +/** +* @fn file.getc(self) ->str +* @brief 从文件中读取一个字符 +* @return 读取到的字符, 失败返回 null +*/ +int32_t __losuh__func_getc_file_fileclass_file(LosuVm *vm); +/** +* @fn file.eof(self) ->bool +* @brief 判断文件是否已经读到末尾 +* @return 1 表示已经读到末尾, null 表示还没有到末尾 +*/ +int32_t __losuh__func_eof_file_fileclass_file(LosuVm *vm); +/** +* @fn file.seek(self,offset:int,whence:int) ->bool +* @brief 移动文件指针 +* @param offset 偏移量 +* @param whence 从哪里开始偏移, 0 表示文件开头, 1 表示当前位置, 2 表示文件末尾 +* @return null 表示失败, 1 表示成功 +*/ +int32_t __losuh__func_seek_file_fileclass_file(LosuVm *vm); +/** +* @fn file.tell(self) ->int +* @brief 获取文件指针当前位置, 从文件开头算起 +* @return 文件指针当前位置, 失败返回 -1 +*/ +int32_t __losuh__func_tell_file_fileclass_file(LosuVm *vm); +/** +* @fn file.rewind(self) ->bool +* @brief 将文件指针移动到文件开头 +* @return null 表示失败, 1 表示成功 +*/ +int32_t __losuh__func_rewind_file_fileclass_file(LosuVm *vm); +/** +* @class file(self,fn:str ,mode:str ='r') +* @brief 创建一个 file 对象, 并打开文件 +* @param fn 文件名 +* @param mode 打开文件的模式, 与 C 语言的 fopen 函数相同 +* @return file 对象, 失败返回 null +*/ +int32_t __losuh__func___init___file_fileclass_file(LosuVm *vm); + diff --git a/pkgs/file/libfile.c b/pkgs/file/libfile.c new file mode 100755 index 0000000000000000000000000000000000000000..90f7df48e60c024536ab1e1183d85f8ac563767f --- /dev/null +++ b/pkgs/file/libfile.c @@ -0,0 +1,182 @@ +/* + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#include "file.lsh.h" +#include +#include +#include + +/* + This file was generated by losuh - Losu Header Generator, which is part of + the Losu SDK. + + Losu is an open source programming language from China with excellent + performance (comparable to lua), ultra-lightweight resource footprint (only + 4KB RAM) and easy-to-learn syntax (similar to Python) for IoT development. + + This file follows the following MIT LICENSE by default + ------------------------------------ + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + +*/ + +/** + * #include "losu.h" + * #include "losuh.h" + * LosuModule *__losuh__LOADMODULE_file(); + */ + +#ifdef __config_losucore_encode_nativeUTF8 + +#ifdef __config_losucore_encode_winGBK +#error "Invalid encode config" +#endif + +#define toSys(vm, s) (s) +#define toLosu(vm, s) (s) + +#endif + +#ifdef __config_losucore_encode_winGBK + +#ifdef __config_losucore_encode_nativeUTF8 +#error "Invalid encode config" +#endif + +#define toSys(vm, s) (charset_newObj_toSys (vm, s)) +#define toLosu(vm, s) (charset_newObj_toLosu (vm, s)) + +#endif + +/** + * @class file(self,fn:str ,mode:str ='r') + * @brief 创建一个 file 对象, 并打开文件 + * @param fn 文件名 + * @param mode 打开文件的模式, 与 C 语言的 fopen 函数相同 + * @return file 对象, 失败返回 null + */ +int32_t +__losuh__func___init___file_fileclass_file (LosuVm *vm) +{ + LosuObj * this = arg_get(vm,1); +} +/** + * @fn file.close(self) ->bool + * @brief 关闭文件 + * @return null 表示失败, 1 表示成功 + */ +int32_t __losuh__func_close_file_fileclass_file (LosuVm *vm); +/** + * @fn file.putc(self,c:str) ->bool + * @brief 向文件中写入一个字符 + * @param c 要写入的字符 + * @return null 表示失败, 1 表示成功 + */ +int32_t __losuh__func_putc_file_fileclass_file (LosuVm *vm); +/** + * @fn file.print(self,s:str) ->bool + * @brief 向文件中写入一个字符串 + * @param s 要写入的字符串 + * @return null 表示失败, 1 表示成功 + */ +int32_t __losuh__func_print_file_fileclass_file (LosuVm *vm); +/** + * @fn file.read(self,n:int) ->str + * @brief 从文件中读取 n 个字符 + * @param n 要读取的字符数 + * @return 读取到的字符串, 失败返回 null + */ +int32_t __losuh__func_read_file_fileclass_file (LosuVm *vm); +/** + * @fn file.readline(self) ->str + * @brief 从文件中读取一行 + * @return 读取到的字符串, 失败返回 null + */ +int32_t __losuh__func_readline_file_fileclass_file (LosuVm *vm); +/** + * @fn file.getc(self) ->str + * @brief 从文件中读取一个字符 + * @return 读取到的字符, 失败返回 null + */ +int32_t __losuh__func_getc_file_fileclass_file (LosuVm *vm); +/** + * @fn file.eof(self) ->bool + * @brief 判断文件是否已经读到末尾 + * @return 1 表示已经读到末尾, null 表示还没有到末尾 + */ +int32_t __losuh__func_eof_file_fileclass_file (LosuVm *vm); +/** + * @fn file.seek(self,offset:int,whence:int) ->bool + * @brief 移动文件指针 + * @param offset 偏移量 + * @param whence 从哪里开始偏移, 0 表示文件开头, 1 表示当前位置, 2 表示文件末尾 + * @return null 表示失败, 1 表示成功 + */ +int32_t __losuh__func_seek_file_fileclass_file (LosuVm *vm); +/** + * @fn file.tell(self) ->int + * @brief 获取文件指针当前位置, 从文件开头算起 + * @return 文件指针当前位置, 失败返回 -1 + */ +int32_t __losuh__func_tell_file_fileclass_file (LosuVm *vm); +/** + * @fn file.rewind(self) ->bool + * @brief 将文件指针移动到文件开头 + * @return null 表示失败, 1 表示成功 + */ +int32_t __losuh__func_rewind_file_fileclass_file (LosuVm *vm); diff --git a/.repo/.nosafe b/pkgs/file/target/x86_64-linux-gnu.mk similarity index 100% rename from .repo/.nosafe rename to pkgs/file/target/x86_64-linux-gnu.mk diff --git a/.repo/upscript/.period b/pkgs/file/target/x86_64-w64-mingw32.mk old mode 100644 new mode 100755 similarity index 100% rename from .repo/upscript/.period rename to pkgs/file/target/x86_64-w64-mingw32.mk diff --git a/pkgs/helloworld/config b/pkgs/helloworld/config new file mode 100755 index 0000000000000000000000000000000000000000..a5747f7b63443494f34b3f1e867b34ebba33901a --- /dev/null +++ b/pkgs/helloworld/config @@ -0,0 +1,9 @@ +pkgs={ + name: "helloworld", + version: "1.0.0", + description: "A simple Hello World package", + target:{ + "x86_64-linux-gnu", + "x86_64-w64-mingw32", + }, +} \ No newline at end of file diff --git a/pkgs/helloworld/helloworld.lsh b/pkgs/helloworld/helloworld.lsh new file mode 100755 index 0000000000000000000000000000000000000000..5a442a8f00ef0292fc860dd20db3a01830f4e827 --- /dev/null +++ b/pkgs/helloworld/helloworld.lsh @@ -0,0 +1,8 @@ +# This is a Demo-Package for Losu +# module name: helloworld +module helloworld + # submod: main + sub main + # function hello() + def hello(): + # print "Hello World!" \ No newline at end of file diff --git a/pkgs/helloworld/helloworld.lsh.c b/pkgs/helloworld/helloworld.lsh.c new file mode 100755 index 0000000000000000000000000000000000000000..12ae2f953c4095c1bcd16126c85c965d283bbe48 --- /dev/null +++ b/pkgs/helloworld/helloworld.lsh.c @@ -0,0 +1,75 @@ + +/* + This file was generated by losuh - Losu Header Generator, which is part of + the Losu SDK. + + Losu is an open source programming language from China with excellent + performance (comparable to lua), ultra-lightweight resource footprint (only + 4KB RAM) and easy-to-learn syntax (similar to Python) for IoT development. + + This file follows the following MIT LICENSE by default + ------------------------------------ + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + +*/ + +#include "helloworld.lsh.h" +#include + +static int32_t __losuh__submod_main_helloworld (LosuVm *vm); + +static LosuModule __losuh__MODULELIST[] = { + { "main", __losuh__submod_main_helloworld }, + { NULL, NULL }, +}; +LosuModule * +__losuh__LOADMODULE_helloworld () +{ + return &__losuh__MODULELIST[0]; +} + +static int32_t +__losuh__submod_main_helloworld (LosuVm *vm) +{ + // constructors of number in main + + // constructors of string in main + + // constructors of function in main + /** + */ + __losuhAPI_regFunc (vm, "hello", __losuh__func_hello_main_helloworld); + + // constructors of script in main + + // constructors of object in main + + // constructors of class in main + + return 0; +} + +int32_t +__losuh__func_hello_main_helloworld (LosuVm *vm) +{ + printf ("Hello,world!\n"); + return 0; +} diff --git a/pkgs/helloworld/helloworld.lsh.h b/pkgs/helloworld/helloworld.lsh.h new file mode 100755 index 0000000000000000000000000000000000000000..31364e22519b99b06ac7d71a3de8e7f96ad23cfc --- /dev/null +++ b/pkgs/helloworld/helloworld.lsh.h @@ -0,0 +1,40 @@ + +/* + This file was generated by losuh - Losu Header Generator, which is part of + the Losu SDK. + + Losu is an open source programming language from China with excellent + performance (comparable to lua), ultra-lightweight resource footprint (only + 4KB RAM) and easy-to-learn syntax (similar to Python) for IoT development. + + This file follows the following MIT LICENSE by default + ------------------------------------ + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + +*/ + +#include "losu.h" +#include "losuh.h" +LosuModule *__losuh__LOADMODULE_helloworld(); +/** +*/ +int32_t __losuh__func_hello_main_helloworld(LosuVm *vm); + diff --git a/pkgs/helloworld/target/x86_64-linux-gnu.mk b/pkgs/helloworld/target/x86_64-linux-gnu.mk new file mode 100755 index 0000000000000000000000000000000000000000..0ce04c7cd66041333dbe0a3e5e66f7aab496e787 --- /dev/null +++ b/pkgs/helloworld/target/x86_64-linux-gnu.mk @@ -0,0 +1,26 @@ +PkgTarget=$(LosuSDK_Build)/target/pkgs +PkgObj=$(LosuSDK_Build)/obj/target/pkgs/helloworld + +cc=x86_64-linux-gnu-gcc + +CIncFile=$(shell ls $(LosuSDK_Include)/*.h) helloworld.lsh.h + +cWarning= -Wall +cStd= -std=c99 +cOpt= -O2 +cInclude= -I$(LosuSDK_Include) + +cFlags= $(cWarning) $(cStd) $(cOpt) $(cInclude) + +$(PkgTarget)/liblpkghelloworld.a:\ + $(PkgObj)/.keep\ + $(PkgObj)/helloworld.lsh.o\ + + ar crs $@ $^ + +$(PkgObj)/.keep: + mkdir -p $(PkgObj) + touch $@ + +$(PkgObj)/helloworld.lsh.o: helloworld.lsh.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ \ No newline at end of file diff --git a/pkgs/helloworld/target/x86_64-w64-mingw32.mk b/pkgs/helloworld/target/x86_64-w64-mingw32.mk new file mode 100755 index 0000000000000000000000000000000000000000..b0f1163178b476f81ae179f4c66a2478317c3372 --- /dev/null +++ b/pkgs/helloworld/target/x86_64-w64-mingw32.mk @@ -0,0 +1,26 @@ +PkgTarget=$(LosuSDK_Build)/target/pkgs +PkgObj=$(LosuSDK_Build)/obj/target/pkgs/helloworld + +cc=x86_64-w64-mingw32-gcc + +CIncFile=$(shell ls $(LosuSDK_Include)/*.h) helloworld.lsh.h + +cWarning= -Wall +cStd= -std=c99 +cOpt= -O2 +cInclude= -I$(LosuSDK_Include) + +cFlags= $(cWarning) $(cStd) $(cOpt) $(cInclude) + +$(PkgTarget)/liblpkghelloworld.a:\ + $(PkgObj)/.keep\ + $(PkgObj)/helloworld.lsh.o\ + + ar crs $@ $^ + +$(PkgObj)/.keep: + mkdir -p $(PkgObj) + touch $@ + +$(PkgObj)/helloworld.lsh.o: helloworld.lsh.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ \ No newline at end of file diff --git a/pkgs/math/config b/pkgs/math/config new file mode 100755 index 0000000000000000000000000000000000000000..3ef21f6b8914b6f366dd7fc21ad7b8094ed58bdc --- /dev/null +++ b/pkgs/math/config @@ -0,0 +1,9 @@ +pkgs = { + name: "math", + version: "2.0.0", + description: "A simple math package for Losu, depends on libm", + target:{ + "x86_64-linux-gnu", + "x86_64-w64-mingw32", + }, +} \ No newline at end of file diff --git a/pkgs/math/libmath.c b/pkgs/math/libmath.c new file mode 100755 index 0000000000000000000000000000000000000000..469e149d4a070d9d13f6e0995ee9452f8076c0f4 --- /dev/null +++ b/pkgs/math/libmath.c @@ -0,0 +1,434 @@ +/* + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#include "math.lsh.h" +#include + +#define PI 3.141592653589793 +#define E 2.718281828459045 +#define GAMMA 0.577215664901532 + +/** + * @fn abs(x:float) -> float + * @brief 返回 x 的绝对值 + */ +int32_t +__losuh__func_abs_base_math (LosuVm *vm) +{ + arg_returnnum (vm, (_l_number)fabs (arg_getnum (vm, 1))); + return 1; +} +/** + * @fn mod(a:float, b:float) -> float + * @brief 返回 a 除以 b 的余数 + */ +int32_t +__losuh__func_mod_base_math (LosuVm *vm) +{ + arg_returnnum (vm, (_l_number)fmod (arg_getnum (vm, 1), arg_getnum (vm, 2))); + return 1; +} +/** + * @fn pow(x:float, y:float) -> float + * @brief 返回 x 的 y 次幂 + */ +int32_t +__losuh__func_pow_base_math (LosuVm *vm) +{ + arg_returnnum (vm, (_l_number)pow (arg_getnum (vm, 1), arg_getnum (vm, 2))); + return 1; +} +/** + * @fn sqrt(x:float) -> float + * @brief 返回 x 的平方根 + */ +int32_t +__losuh__func_sqrt_base_math (LosuVm *vm) +{ + arg_returnnum (vm, (_l_number)sqrt (arg_getnum (vm, 1))); + return 1; +} +/** + * @fn anyroot(x:float, n:float) -> float + * @brief 返回 x 的 n 次方根(近似根) + */ +int32_t +__losuh__func_anyroot_base_math (LosuVm *vm) +{ + double x, n; + x = arg_getnum (vm, 1); + n = arg_getnum (vm, 2); + arg_returnnum (vm, exp (1 / n) * log (x)); + return 1; +} +/** + * @fn gcd(a:int, b:int) -> int + * @brief 返回 a 和 b 的最大公约数 + */ +int32_t +__losuh__func_gcd_base_math (LosuVm *vm) +{ + int64_t a, b, mid = 0; + a = arg_getnum (vm, 1); + b = arg_getnum (vm, 2); + while (b != 0) + { + mid = a; + a = b; + b = mid % b; + } + arg_returnnum (vm, a); + return 1; +} +/** + * @fn acos(x:float) -> float + * @brief 返回 x 的反余弦值 + */ +int32_t +__losuh__func_acos_trigonometric_math (LosuVm *vm) +{ + arg_returnnum (vm, (_l_number)acos (arg_getnum (vm, 1))); + return 1; +} +/** + * @fn asin(x:float) -> float + * @brief 返回 x 的反正弦值 + */ +int32_t +__losuh__func_asin_trigonometric_math (LosuVm *vm) +{ + arg_returnnum (vm, (_l_number)asin (arg_getnum (vm, 1))); + return 1; +} +/** + * @fn atan(x:float) -> float + * @brief 返回 x 的反正切值 + */ +int32_t +__losuh__func_atan_trigonometric_math (LosuVm *vm) +{ + arg_returnnum (vm, (_l_number)atan (arg_getnum (vm, 1))); + return 1; +} +/** + * @fn cos(x:float) -> float + * @brief 返回 x 的余弦值 + */ +int32_t +__losuh__func_cos_trigonometric_math (LosuVm *vm) +{ + arg_returnnum (vm, (_l_number)cos (arg_getnum (vm, 1))); + return 1; +} +/** + * @fn sin(x:float) -> float + * @brief 返回 x 的正弦值 + */ +int32_t +__losuh__func_sin_trigonometric_math (LosuVm *vm) +{ + arg_returnnum (vm, (_l_number)sin (arg_getnum (vm, 1))); + return 1; +} +/** + * @fn tan(x:float) -> float + * @brief 返回 x 的正切值 + */ +int32_t +__losuh__func_tan_trigonometric_math (LosuVm *vm) +{ + arg_returnnum (vm, (_l_number)tan (arg_getnum (vm, 1))); + return 1; +} +/** + * @fn log(x:float, base:float) -> float + * @brief 返回 x 的以 base 为底的对数 + */ +int32_t +__losuh__func_log_logarithmic_math (LosuVm *vm) +{ + arg_returnnum (vm, (_l_number)log (arg_getnum (vm, 1)) + / log (arg_getnum (vm, 2))); + return 1; +} +/** + * @fn ln(x:float) -> float + * @brief 返回 x 的自然对数 + */ +int32_t +__losuh__func_ln_logarithmic_math (LosuVm *vm) +{ + arg_returnnum (vm, (_l_number)log (arg_getnum (vm, 1))); + return 1; +} +/** + * @fn log10(x:float) -> float + * @brief 返回 x 的以 10 为底的对数 + */ +int32_t +__losuh__func_log10_logarithmic_math (LosuVm *vm) +{ + arg_returnnum (vm, (_l_number)log10 (arg_getnum (vm, 1))); + return 1; +} +/** + * @fn exp(x:float) -> float + * @brief 返回 e 的 x 次幂 + */ +int32_t +__losuh__func_exp_logarithmic_math (LosuVm *vm) +{ + arg_returnnum (vm, (_l_number)exp (arg_getnum (vm, 1))); + return 1; +} +/** + * @fn ceil(x:float) -> float + * @brief 返回大于或等于 x 的最小整数 + */ +int32_t +__losuh__func_ceil_rounding_math (LosuVm *vm) +{ + arg_returnnum (vm, (_l_number)ceil (arg_getnum (vm, 1))); + return 1; +} +/** + * @fn floor(x:float) -> float + * @brief 返回小于或等于 x 的最大整数 + */ +int32_t +__losuh__func_floor_rounding_math (LosuVm *vm) +{ + arg_returnnum (vm, (_l_number)floor (arg_getnum (vm, 1))); + return 1; +} +/** + * @fn round(x:float) -> float + * @brief 返回最接近 x 的整数(四舍五入) + */ +int32_t +__losuh__func_round_rounding_math (LosuVm *vm) +{ + arg_returnnum (vm, (_l_number)round (arg_getnum (vm, 1))); + return 1; +} +/** + * @fn cut(x:float, n:int) -> float + * @brief 截断 x ,保留 n 位小数 + */ +int32_t +__losuh__func_cut_rounding_math (LosuVm *vm) +{ + _l_number num = arg_getnum (vm, 1); + int64_t x = arg_getnum (vm, 2); + x = pow (10, x); + arg_returnnum (vm, (_l_number)((int64_t)(num * x)) / x); + return 1; +} +/** + * @fn movl(x:int, y:int) -> int + * @brief 返回将 x 左移 y 位的结果 + */ +int32_t +__losuh__func_movl_bitwise_math (LosuVm *vm) +{ + uint32_t x = arg_getnum (vm, 1); + uint32_t y = arg_getnum (vm, 2); + uint32_t z = x << y; + arg_returnnum (vm, (_l_number)z); + return 1; +} +/** + * @fn movr(x:int, y:int) -> int + * @brief 返回将 x 右移 y 位的结果 + */ +int32_t +__losuh__func_movr_bitwise_math (LosuVm *vm) +{ + uint32_t x = arg_getnum (vm, 1); + uint32_t y = arg_getnum (vm, 2); + uint32_t z = x >> y; + arg_returnnum (vm, (_l_number)z); + return 1; +} +/** + * @fn bitand(x:int, y:int) -> int + * @brief 返回 x 和 y 的按位与结果 + */ +int32_t +__losuh__func_bitand_bitwise_math (LosuVm *vm) +{ + uint32_t x = arg_getnum (vm, 1); + uint32_t y = arg_getnum (vm, 2); + uint32_t z = x & y; + arg_returnnum (vm, (_l_number)z); + return 1; +} +/** + * @fn bitor(x:int, y:int) -> int + * @brief 返回 x 和 y 的按位或结果 + */ +int32_t +__losuh__func_bitor_bitwise_math (LosuVm *vm) +{ + uint32_t x = arg_getnum (vm, 1); + uint32_t y = arg_getnum (vm, 2); + uint32_t z = x | y; + arg_returnnum (vm, (_l_number)z); + return 1; +} +/** + * @fn bitxor(x:int, y:int) -> int + * @brief 返回 x 和 y 的按位异或结果 + */ +int32_t +__losuh__func_bitxor_bitwise_math (LosuVm *vm) +{ + uint32_t x = arg_getnum (vm, 1); + uint32_t y = arg_getnum (vm, 2); + uint32_t z = x ^ y; + arg_returnnum (vm, (_l_number)z); + return 1; +} +/** + * @fn bitnot(x:int) -> int + * @brief 返回 x 的按位取反结果 + */ +int32_t +__losuh__func_bitnot_bitwise_math (LosuVm *vm) +{ + uint32_t x = arg_getnum (vm, 1); + uint32_t z = ~x; + arg_returnnum (vm, (_l_number)z); + return 1; +} +/** + * @fn sum(a:list) -> float + * @brief 返回数组 a 的元素之和 + */ +int32_t +__losuh__func_sum_array_math (LosuVm *vm) +{ + LosuObj *list = arg_get (vm, 1); + _l_number sum = 0; + LosuObj *val = NULL; + int32_t n = 1; + while (1) + { + val = obj_indexunitbynum (vm, *list, n); + if (obj_type (vm, val) == LosuTypeDefine_null) + break; + sum += obj_tonum (vm, val); + n++; + } + arg_returnnum (vm, sum); + return 1; +} +/** + * @fn prod(a:list) -> float + * @brief 返回数组 a 的元素之积 + */ +int32_t +__losuh__func_prod_array_math (LosuVm *vm) +{ + LosuObj *list = arg_get (vm, 1); + _l_number prod = 1; + LosuObj *val = NULL; + int32_t n = 1; + while (1) + { + val = obj_indexunitbynum (vm, *list, n); + if (obj_type (vm, val) == LosuTypeDefine_null) + break; + prod *= obj_tonum (vm, val); + n++; + } + arg_returnnum (vm, prod); + return 1; +} +/** + * @fn mean(a:list) -> float + * @brief 返回数组 a 的元素的平均值 + */ +int32_t +__losuh__func_mean_array_math (LosuVm *vm) +{ + LosuObj *unit = arg_get (vm, 1); + LosuObj *val; + _l_number output = 0; + unsigned int index = 0; + while (1) + { + val = obj_indexunitbynum (vm, *unit, index + 1); + if (obj_type (vm, val) == LosuTypeDefine_null) + break; + output += obj_tonum (vm, val); + index++; + } + + if (index == 0) + arg_returnnum (vm, 0); + else + arg_returnnum (vm, output / index); + return 1; +} +/** + * @fn rad2deg(x:float) -> float + * @brief 将弧度转换为角度 + */ +int32_t +__losuh__func_rad2deg_angle_math (LosuVm *vm) +{ + double x = arg_getnum (vm, 1); + double z = x * 180 / PI; + arg_returnnum (vm, (_l_number)z); + return 1; +} +/** + * @fn deg2rad(x:float) -> float + * @brief 将角度转换为弧度 + */ +int32_t +__losuh__func_deg2rad_angle_math (LosuVm *vm) +{ + double x = arg_getnum (vm, 1); + double z = x * PI / 180; + arg_returnnum (vm, (_l_number)z); + return 1; +} diff --git a/pkgs/math/math.lsh b/pkgs/math/math.lsh new file mode 100755 index 0000000000000000000000000000000000000000..f16ff23eeb2e9d093971dcf8be5fcfd8dfe56061 --- /dev/null +++ b/pkgs/math/math.lsh @@ -0,0 +1,115 @@ +module math + # 数学常量 + sub constant + object math + number PI "3.141592653589793" + number E "2.718281828459045" + number GAMMA "0.577215664901532" + # 基本数学函数 + sub base + def abs(x:float): + "@fn abs(x:float) -> float" + "@brief 返回 x 的绝对值" + def mod(a:float, b:float): + "@fn mod(a:float, b:float) -> float" + "@brief 返回 a 除以 b 的余数" + def pow(x:float, y:float): + "@fn pow(x:float, y:float) -> float" + "@brief 返回 x 的 y 次幂" + def sqrt(x:float): + "@fn sqrt(x:float) -> float" + "@brief 返回 x 的平方根" + def anyroot(x:float, n:float): + "@fn anyroot(x:float, n:float) -> float" + "@brief 返回 x 的 n 次方根(近似根)" + def gcd(a:int, b:int): + "@fn gcd(a:int, b:int) -> int" + "@brief 返回 a 和 b 的最大公约数" + # 三角函数 + sub trigonometric + def acos(x:float): + "@fn acos(x:float) -> float" + "@brief 返回 x 的反余弦值" + def asin(x:float): + "@fn asin(x:float) -> float" + "@brief 返回 x 的反正弦值" + def atan(x:float): + "@fn atan(x:float) -> float" + "@brief 返回 x 的反正切值" + def cos(x:float): + "@fn cos(x:float) -> float" + "@brief 返回 x 的余弦值" + def sin(x:float): + "@fn sin(x:float) -> float" + "@brief 返回 x 的正弦值" + def tan(x:float): + "@fn tan(x:float) -> float" + "@brief 返回 x 的正切值" + # 对数函数 + sub logarithmic + def log(x:float, base:float): + "@fn log(x:float, base:float) -> float" + "@brief 返回 x 的以 base 为底的对数" + def ln(x:float): + "@fn ln(x:float) -> float" + "@brief 返回 x 的自然对数" + def log10(x:float): + "@fn log10(x:float) -> float" + "@brief 返回 x 的以 10 为底的对数" + def exp(x:float): + "@fn exp(x:float) -> float" + "@brief 返回 e 的 x 次幂" + # 取整函数 + sub rounding + def ceil(x:float): + "@fn ceil(x:float) -> float" + "@brief 返回大于或等于 x 的最小整数" + def floor(x:float): + "@fn floor(x:float) -> float" + "@brief 返回小于或等于 x 的最大整数" + def round(x:float): + "@fn round(x:float) -> float" + "@brief 返回最接近 x 的整数(四舍五入)" + def cut(x:float, n:int): + "@fn cut(x:float, n:int) -> float" + "@brief 截断 x ,保留 n 位小数" + # 位运算(uint32_t) + sub bitwise + def movl(x:int, y:int): + "@fn movl(x:int, y:int) -> int" + "@brief 返回将 x 左移 y 位的结果" + def movr(x:int, y:int): + "@fn movr(x:int, y:int) -> int" + "@brief 返回将 x 右移 y 位的结果" + def bitand(x:int, y:int): + "@fn bitand(x:int, y:int) -> int" + "@brief 返回 x 和 y 的按位与结果" + def bitor(x:int, y:int): + "@fn bitor(x:int, y:int) -> int" + "@brief 返回 x 和 y 的按位或结果" + def bitxor(x:int, y:int): + "@fn bitxor(x:int, y:int) -> int" + "@brief 返回 x 和 y 的按位异或结果" + def bitnot(x:int): + "@fn bitnot(x:int) -> int" + "@brief 返回 x 的按位取反结果" + # 数组运算(从 a[1] 到第一个空位置) + sub array + def sum(a:list): + "@fn sum(a:list) -> float" + "@brief 返回数组 a 的元素之和" + def prod(a:list): + "@fn prod(a:list) -> float" + "@brief 返回数组 a 的元素之积" + def mean(a:list): + "@fn mean(a:list) -> float" + "@brief 返回数组 a 的元素的平均值" + # 角度转换 + sub angle + def rad2deg(x:float): + "@fn rad2deg(x:float) -> float" + "@brief 将弧度转换为角度" + def deg2rad(x:float): + "@fn deg2rad(x:float) -> float" + "@brief 将角度转换为弧度" + \ No newline at end of file diff --git a/pkgs/math/math.lsh.c b/pkgs/math/math.lsh.c new file mode 100755 index 0000000000000000000000000000000000000000..81415661e009026dab372e8b16a8912c9d12f86b --- /dev/null +++ b/pkgs/math/math.lsh.c @@ -0,0 +1,384 @@ + +/* + This file was generated by losuh - Losu Header Generator, which is part of + the Losu SDK. + + Losu is an open source programming language from China with excellent + performance (comparable to lua), ultra-lightweight resource footprint (only + 4KB RAM) and easy-to-learn syntax (similar to Python) for IoT development. + + This file follows the following MIT LICENSE by default + ------------------------------------ + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + +*/ + +#include "math.lsh.h" +static int32_t __losuh__submod_constant_math (LosuVm *vm); +static LosuObj __losuh__obj_math_constant_math (LosuVm *vm); +static int32_t __losuh__submod_base_math (LosuVm *vm); +static int32_t __losuh__submod_trigonometric_math (LosuVm *vm); +static int32_t __losuh__submod_logarithmic_math (LosuVm *vm); +static int32_t __losuh__submod_rounding_math (LosuVm *vm); +static int32_t __losuh__submod_bitwise_math (LosuVm *vm); +static int32_t __losuh__submod_array_math (LosuVm *vm); +static int32_t __losuh__submod_angle_math (LosuVm *vm); + +static LosuModule __losuh__MODULELIST[] = { + { "constant", __losuh__submod_constant_math }, + { "base", __losuh__submod_base_math }, + { "trigonometric", __losuh__submod_trigonometric_math }, + { "logarithmic", __losuh__submod_logarithmic_math }, + { "rounding", __losuh__submod_rounding_math }, + { "bitwise", __losuh__submod_bitwise_math }, + { "array", __losuh__submod_array_math }, + { "angle", __losuh__submod_angle_math }, + { NULL, NULL }, +}; +LosuModule * +__losuh__LOADMODULE_math () +{ + return &__losuh__MODULELIST[0]; +} + +static int32_t +__losuh__submod_constant_math (LosuVm *vm) +{ + // constructors of number in constant + + // constructors of string in constant + + // constructors of function in constant + + // constructors of script in constant + + // constructors of object in constant + + __losuhAPI_regObject (vm, "math", __losuh__obj_math_constant_math (vm)); + + // constructors of class in constant + + return 0; +} + +static int32_t +__losuh__submod_base_math (LosuVm *vm) +{ + // constructors of number in base + + // constructors of string in base + + // constructors of function in base + /** + * @fn abs(x:float) -> float + * @brief 返回 x 的绝对值 + */ + __losuhAPI_regFunc (vm, "abs", __losuh__func_abs_base_math); + /** + * @fn mod(a:float, b:float) -> float + * @brief 返回 a 除以 b 的余数 + */ + __losuhAPI_regFunc (vm, "mod", __losuh__func_mod_base_math); + /** + * @fn pow(x:float, y:float) -> float + * @brief 返回 x 的 y 次幂 + */ + __losuhAPI_regFunc (vm, "pow", __losuh__func_pow_base_math); + /** + * @fn sqrt(x:float) -> float + * @brief 返回 x 的平方根 + */ + __losuhAPI_regFunc (vm, "sqrt", __losuh__func_sqrt_base_math); + /** + * @fn anyroot(x:float, n:float) -> float + * @brief 返回 x 的 n 次方根(近似根) + */ + __losuhAPI_regFunc (vm, "anyroot", __losuh__func_anyroot_base_math); + /** + * @fn gcd(a:int, b:int) -> int + * @brief 返回 a 和 b 的最大公约数 + */ + __losuhAPI_regFunc (vm, "gcd", __losuh__func_gcd_base_math); + + // constructors of script in base + + // constructors of object in base + + // constructors of class in base + + return 0; +} + +static int32_t +__losuh__submod_trigonometric_math (LosuVm *vm) +{ + // constructors of number in trigonometric + + // constructors of string in trigonometric + + // constructors of function in trigonometric + /** + * @fn acos(x:float) -> float + * @brief 返回 x 的反余弦值 + */ + __losuhAPI_regFunc (vm, "acos", __losuh__func_acos_trigonometric_math); + /** + * @fn asin(x:float) -> float + * @brief 返回 x 的反正弦值 + */ + __losuhAPI_regFunc (vm, "asin", __losuh__func_asin_trigonometric_math); + /** + * @fn atan(x:float) -> float + * @brief 返回 x 的反正切值 + */ + __losuhAPI_regFunc (vm, "atan", __losuh__func_atan_trigonometric_math); + /** + * @fn cos(x:float) -> float + * @brief 返回 x 的余弦值 + */ + __losuhAPI_regFunc (vm, "cos", __losuh__func_cos_trigonometric_math); + /** + * @fn sin(x:float) -> float + * @brief 返回 x 的正弦值 + */ + __losuhAPI_regFunc (vm, "sin", __losuh__func_sin_trigonometric_math); + /** + * @fn tan(x:float) -> float + * @brief 返回 x 的正切值 + */ + __losuhAPI_regFunc (vm, "tan", __losuh__func_tan_trigonometric_math); + + // constructors of script in trigonometric + + // constructors of object in trigonometric + + // constructors of class in trigonometric + + return 0; +} + +static int32_t +__losuh__submod_logarithmic_math (LosuVm *vm) +{ + // constructors of number in logarithmic + + // constructors of string in logarithmic + + // constructors of function in logarithmic + /** + * @fn log(x:float, base:float) -> float + * @brief 返回 x 的以 base 为底的对数 + */ + __losuhAPI_regFunc (vm, "log", __losuh__func_log_logarithmic_math); + /** + * @fn ln(x:float) -> float + * @brief 返回 x 的自然对数 + */ + __losuhAPI_regFunc (vm, "ln", __losuh__func_ln_logarithmic_math); + /** + * @fn log10(x:float) -> float + * @brief 返回 x 的以 10 为底的对数 + */ + __losuhAPI_regFunc (vm, "log10", __losuh__func_log10_logarithmic_math); + /** + * @fn exp(x:float) -> float + * @brief 返回 e 的 x 次幂 + */ + __losuhAPI_regFunc (vm, "exp", __losuh__func_exp_logarithmic_math); + + // constructors of script in logarithmic + + // constructors of object in logarithmic + + // constructors of class in logarithmic + + return 0; +} + +static int32_t +__losuh__submod_rounding_math (LosuVm *vm) +{ + // constructors of number in rounding + + // constructors of string in rounding + + // constructors of function in rounding + /** + * @fn ceil(x:float) -> float + * @brief 返回大于或等于 x 的最小整数 + */ + __losuhAPI_regFunc (vm, "ceil", __losuh__func_ceil_rounding_math); + /** + * @fn floor(x:float) -> float + * @brief 返回小于或等于 x 的最大整数 + */ + __losuhAPI_regFunc (vm, "floor", __losuh__func_floor_rounding_math); + /** + * @fn round(x:float) -> float + * @brief 返回最接近 x 的整数(四舍五入) + */ + __losuhAPI_regFunc (vm, "round", __losuh__func_round_rounding_math); + /** + * @fn cut(x:float, n:int) -> float + * @brief 截断 x ,保留 n 位小数 + */ + __losuhAPI_regFunc (vm, "cut", __losuh__func_cut_rounding_math); + + // constructors of script in rounding + + // constructors of object in rounding + + // constructors of class in rounding + + return 0; +} + +static int32_t +__losuh__submod_bitwise_math (LosuVm *vm) +{ + // constructors of number in bitwise + + // constructors of string in bitwise + + // constructors of function in bitwise + /** + * @fn movl(x:int, y:int) -> int + * @brief 返回将 x 左移 y 位的结果 + */ + __losuhAPI_regFunc (vm, "movl", __losuh__func_movl_bitwise_math); + /** + * @fn movr(x:int, y:int) -> int + * @brief 返回将 x 右移 y 位的结果 + */ + __losuhAPI_regFunc (vm, "movr", __losuh__func_movr_bitwise_math); + /** + * @fn bitand(x:int, y:int) -> int + * @brief 返回 x 和 y 的按位与结果 + */ + __losuhAPI_regFunc (vm, "bitand", __losuh__func_bitand_bitwise_math); + /** + * @fn bitor(x:int, y:int) -> int + * @brief 返回 x 和 y 的按位或结果 + */ + __losuhAPI_regFunc (vm, "bitor", __losuh__func_bitor_bitwise_math); + /** + * @fn bitxor(x:int, y:int) -> int + * @brief 返回 x 和 y 的按位异或结果 + */ + __losuhAPI_regFunc (vm, "bitxor", __losuh__func_bitxor_bitwise_math); + /** + * @fn bitnot(x:int) -> int + * @brief 返回 x 的按位取反结果 + */ + __losuhAPI_regFunc (vm, "bitnot", __losuh__func_bitnot_bitwise_math); + + // constructors of script in bitwise + + // constructors of object in bitwise + + // constructors of class in bitwise + + return 0; +} + +static int32_t +__losuh__submod_array_math (LosuVm *vm) +{ + // constructors of number in array + + // constructors of string in array + + // constructors of function in array + /** + * @fn sum(a:list) -> float + * @brief 返回数组 a 的元素之和 + */ + __losuhAPI_regFunc (vm, "sum", __losuh__func_sum_array_math); + /** + * @fn prod(a:list) -> float + * @brief 返回数组 a 的元素之积 + */ + __losuhAPI_regFunc (vm, "prod", __losuh__func_prod_array_math); + /** + * @fn mean(a:list) -> float + * @brief 返回数组 a 的元素的平均值 + */ + __losuhAPI_regFunc (vm, "mean", __losuh__func_mean_array_math); + + // constructors of script in array + + // constructors of object in array + + // constructors of class in array + + return 0; +} + +static int32_t +__losuh__submod_angle_math (LosuVm *vm) +{ + // constructors of number in angle + + // constructors of string in angle + + // constructors of function in angle + /** + * @fn rad2deg(x:float) -> float + * @brief 将弧度转换为角度 + */ + __losuhAPI_regFunc (vm, "rad2deg", __losuh__func_rad2deg_angle_math); + /** + * @fn deg2rad(x:float) -> float + * @brief 将角度转换为弧度 + */ + __losuhAPI_regFunc (vm, "deg2rad", __losuh__func_deg2rad_angle_math); + + // constructors of script in angle + + // constructors of object in angle + + // constructors of class in angle + + return 0; +} + +static LosuObj +__losuh__obj_math_constant_math (LosuVm *vm) +{ + LosuObj newObj = obj_newunit (vm); + // constructor of number in math@constant_math + + __losuhAPI_regObjNumber (vm, newObj, "PI", 3.141592653589793); + + __losuhAPI_regObjNumber (vm, newObj, "E", 2.718281828459045); + + __losuhAPI_regObjNumber (vm, newObj, "GAMMA", 0.577215664901532); + + // constructor of string in math@constant_math + + // constructor of object in math@constant_math + + // constructor of class in math@constant_math + + // constructor of function in math@constant_math + + return newObj; +} diff --git a/pkgs/math/math.lsh.h b/pkgs/math/math.lsh.h new file mode 100755 index 0000000000000000000000000000000000000000..baaa0d7ea5ebc2b2fecf981338e31c7a8b5647a0 --- /dev/null +++ b/pkgs/math/math.lsh.h @@ -0,0 +1,191 @@ + +/* + This file was generated by losuh - Losu Header Generator, which is part of + the Losu SDK. + + Losu is an open source programming language from China with excellent + performance (comparable to lua), ultra-lightweight resource footprint (only + 4KB RAM) and easy-to-learn syntax (similar to Python) for IoT development. + + This file follows the following MIT LICENSE by default + ------------------------------------ + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + +*/ + +#include "losu.h" +#include "losuh.h" +LosuModule *__losuh__LOADMODULE_math (); +/** + * @fn abs(x:float) -> float + * @brief 返回 x 的绝对值 + */ +int32_t __losuh__func_abs_base_math (LosuVm *vm); +/** + * @fn mod(a:float, b:float) -> float + * @brief 返回 a 除以 b 的余数 + */ +int32_t __losuh__func_mod_base_math (LosuVm *vm); +/** + * @fn pow(x:float, y:float) -> float + * @brief 返回 x 的 y 次幂 + */ +int32_t __losuh__func_pow_base_math (LosuVm *vm); +/** + * @fn sqrt(x:float) -> float + * @brief 返回 x 的平方根 + */ +int32_t __losuh__func_sqrt_base_math (LosuVm *vm); +/** + * @fn anyroot(x:float, n:float) -> float + * @brief 返回 x 的 n 次方根(近似根) + */ +int32_t __losuh__func_anyroot_base_math (LosuVm *vm); +/** + * @fn gcd(a:int, b:int) -> int + * @brief 返回 a 和 b 的最大公约数 + */ +int32_t __losuh__func_gcd_base_math (LosuVm *vm); +/** + * @fn acos(x:float) -> float + * @brief 返回 x 的反余弦值 + */ +int32_t __losuh__func_acos_trigonometric_math (LosuVm *vm); +/** + * @fn asin(x:float) -> float + * @brief 返回 x 的反正弦值 + */ +int32_t __losuh__func_asin_trigonometric_math (LosuVm *vm); +/** + * @fn atan(x:float) -> float + * @brief 返回 x 的反正切值 + */ +int32_t __losuh__func_atan_trigonometric_math (LosuVm *vm); +/** + * @fn cos(x:float) -> float + * @brief 返回 x 的余弦值 + */ +int32_t __losuh__func_cos_trigonometric_math (LosuVm *vm); +/** + * @fn sin(x:float) -> float + * @brief 返回 x 的正弦值 + */ +int32_t __losuh__func_sin_trigonometric_math (LosuVm *vm); +/** + * @fn tan(x:float) -> float + * @brief 返回 x 的正切值 + */ +int32_t __losuh__func_tan_trigonometric_math (LosuVm *vm); +/** + * @fn log(x:float, base:float) -> float + * @brief 返回 x 的以 base 为底的对数 + */ +int32_t __losuh__func_log_logarithmic_math (LosuVm *vm); +/** + * @fn ln(x:float) -> float + * @brief 返回 x 的自然对数 + */ +int32_t __losuh__func_ln_logarithmic_math (LosuVm *vm); +/** + * @fn log10(x:float) -> float + * @brief 返回 x 的以 10 为底的对数 + */ +int32_t __losuh__func_log10_logarithmic_math (LosuVm *vm); +/** + * @fn exp(x:float) -> float + * @brief 返回 e 的 x 次幂 + */ +int32_t __losuh__func_exp_logarithmic_math (LosuVm *vm); +/** + * @fn ceil(x:float) -> float + * @brief 返回大于或等于 x 的最小整数 + */ +int32_t __losuh__func_ceil_rounding_math (LosuVm *vm); +/** + * @fn floor(x:float) -> float + * @brief 返回小于或等于 x 的最大整数 + */ +int32_t __losuh__func_floor_rounding_math (LosuVm *vm); +/** + * @fn round(x:float) -> float + * @brief 返回最接近 x 的整数(四舍五入) + */ +int32_t __losuh__func_round_rounding_math (LosuVm *vm); +/** + * @fn cut(x:float, n:int) -> float + * @brief 截断 x ,保留 n 位小数 + */ +int32_t __losuh__func_cut_rounding_math (LosuVm *vm); +/** + * @fn movl(x:int, y:int) -> int + * @brief 返回将 x 左移 y 位的结果 + */ +int32_t __losuh__func_movl_bitwise_math (LosuVm *vm); +/** + * @fn movr(x:int, y:int) -> int + * @brief 返回将 x 右移 y 位的结果 + */ +int32_t __losuh__func_movr_bitwise_math (LosuVm *vm); +/** + * @fn bitand(x:int, y:int) -> int + * @brief 返回 x 和 y 的按位与结果 + */ +int32_t __losuh__func_bitand_bitwise_math (LosuVm *vm); +/** + * @fn bitor(x:int, y:int) -> int + * @brief 返回 x 和 y 的按位或结果 + */ +int32_t __losuh__func_bitor_bitwise_math (LosuVm *vm); +/** + * @fn bitxor(x:int, y:int) -> int + * @brief 返回 x 和 y 的按位异或结果 + */ +int32_t __losuh__func_bitxor_bitwise_math (LosuVm *vm); +/** + * @fn bitnot(x:int) -> int + * @brief 返回 x 的按位取反结果 + */ +int32_t __losuh__func_bitnot_bitwise_math (LosuVm *vm); +/** + * @fn sum(a:list) -> float + * @brief 返回数组 a 的元素之和 + */ +int32_t __losuh__func_sum_array_math (LosuVm *vm); +/** + * @fn prod(a:list) -> float + * @brief 返回数组 a 的元素之积 + */ +int32_t __losuh__func_prod_array_math (LosuVm *vm); +/** + * @fn mean(a:list) -> float + * @brief 返回数组 a 的元素的平均值 + */ +int32_t __losuh__func_mean_array_math (LosuVm *vm); +/** + * @fn rad2deg(x:float) -> float + * @brief 将弧度转换为角度 + */ +int32_t __losuh__func_rad2deg_angle_math (LosuVm *vm); +/** + * @fn deg2rad(x:float) -> float + * @brief 将角度转换为弧度 + */ +int32_t __losuh__func_deg2rad_angle_math (LosuVm *vm); diff --git a/pkgs/math/target/x86_64-linux-gnu.mk b/pkgs/math/target/x86_64-linux-gnu.mk new file mode 100755 index 0000000000000000000000000000000000000000..c1ab957922e421691428ecec4f269fc7e0bbdb30 --- /dev/null +++ b/pkgs/math/target/x86_64-linux-gnu.mk @@ -0,0 +1,30 @@ +PkgTarget=$(LosuSDK_Build)/target/pkgs +PkgObj=$(LosuSDK_Build)/obj/target/pkgs/math + +cc=x86_64-linux-gnu-gcc + +CIncFile=$(shell ls $(LosuSDK_Include)/*.h) math.lsh.h + +cWarning= -Wall +cStd= -std=gnu99 +cOpt= -O2 +cInclude= -I$(LosuSDK_Include) + +cFlags= $(cWarning) $(cStd) $(cOpt) $(cInclude) + +$(PkgTarget)/liblpkgmath.a:\ + $(PkgObj)/.keep\ + $(PkgObj)/math.lsh.o\ + $(PkgObj)/libmath.o\ + + ar crs $@ $^ + +$(PkgObj)/.keep: + mkdir -p $(PkgObj) + touch $@ + +$(PkgObj)/math.lsh.o: math.lsh.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ + +$(PkgObj)/libmath.o: libmath.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ \ No newline at end of file diff --git a/pkgs/math/target/x86_64-w64-mingw32.mk b/pkgs/math/target/x86_64-w64-mingw32.mk new file mode 100755 index 0000000000000000000000000000000000000000..a986ff309d2ebb29b8ecd0a61d907f5e402f8a81 --- /dev/null +++ b/pkgs/math/target/x86_64-w64-mingw32.mk @@ -0,0 +1,31 @@ +PkgTarget=$(LosuSDK_Build)/target/pkgs +PkgObj=$(LosuSDK_Build)/obj/target/pkgs/math + +cc=x86_64-w64-mingw32-gcc + +CIncFile=$(shell ls $(LosuSDK_Include)/*.h) math.lsh.h + +cWarning= -Wall +cStd= -std=gnu99 +cOpt= -O2 +cInclude= -I$(LosuSDK_Include) + +cFlags= $(cWarning) $(cStd) $(cOpt) $(cInclude) + +$(PkgTarget)/liblpkgmath.a:\ + $(PkgObj)/.keep\ + $(PkgObj)/math.lsh.o\ + $(PkgObj)/libmath.o\ + + ar crs $@ $^ + +$(PkgObj)/.keep: + mkdir -p $(PkgObj) + touch $@ + +$(PkgObj)/math.lsh.o: math.lsh.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ + +$(PkgObj)/libmath.o: libmath.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ + diff --git a/pkgs/random/config b/pkgs/random/config new file mode 100755 index 0000000000000000000000000000000000000000..9d6b5802aad69273bb761b5493b26ae70442661c --- /dev/null +++ b/pkgs/random/config @@ -0,0 +1,9 @@ +pkgs = { + name: "random", + version: "2.0.0", + description: "", + target:{ + "x86_64-linux-gnu", + "x86_64-w64-mingw32", + }, +} \ No newline at end of file diff --git a/pkgs/random/random.lsh b/pkgs/random/random.lsh new file mode 100755 index 0000000000000000000000000000000000000000..2dc210d336787f30d1b71dbb3b5240e4c493c249 --- /dev/null +++ b/pkgs/random/random.lsh @@ -0,0 +1,26 @@ +# random是一个高性能的随机模块,模块分为 种子、数字、字符串三个部分,可以按需求进行裁剪与导入。 +module random + sub rand + def srand(seed:float ): + "@fn srand(seed:float )" + "@brief 设置随机数种子, 如果 seed 为空,则使用默认种子" + sub randn + object randn + def int(a:int, b:int): + "@fn randn.int(a:int, b:int) -> int" + "@brief 生成一个 [a,b) 之间的随机整数" + def num(a:int, b:int): + "@fn randn.num(a:int, b:int) -> float" + "@brief 生成一个 [a,b) 之间的随机数" + def bool(rate:float =0): + "@fn randn.bool(rate:float =0) -> bool" + "@brief 根据概率生成随机真伪值" + sub rands + object rands + def str(len:int): + "@fn rands.str(len:int) -> str" + "@brief 生成一个长度为 len 的随机字符串" + def bits(len:int): + "@fn rands.bits(len:int) -> str" + "@brief 生成一个长度为 len 的随机二进制字符串" + \ No newline at end of file diff --git a/pkgs/random/random.lsh.c b/pkgs/random/random.lsh.c new file mode 100755 index 0000000000000000000000000000000000000000..f8af695e8db820bf40fb3a2e4e81a853c2676d91 --- /dev/null +++ b/pkgs/random/random.lsh.c @@ -0,0 +1,222 @@ + +/* + This file was generated by losuh - Losu Header Generator, which is part of + the Losu SDK. + + Losu is an open source programming language from China with excellent + performance (comparable to lua), ultra-lightweight resource footprint (only + 4KB RAM) and easy-to-learn syntax (similar to Python) for IoT development. + + This file follows the following MIT LICENSE by default + ------------------------------------ + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + +*/ + +#include "random.lsh.h" +static int32_t __losuh__submod_rand_random (LosuVm *vm); +static LosuObj __losuh__obj_rand_rand_random (LosuVm *vm); +static int32_t __losuh__submod_randn_random (LosuVm *vm); +static LosuObj __losuh__obj_randn_randn_random (LosuVm *vm); +static int32_t __losuh__submod_rands_random (LosuVm *vm); +static LosuObj __losuh__obj_rands_rands_random (LosuVm *vm); + +static LosuModule __losuh__MODULELIST[] = { + { "rand", __losuh__submod_rand_random }, + { "randn", __losuh__submod_randn_random }, + { "rands", __losuh__submod_rands_random }, + { NULL, NULL }, +}; +LosuModule * +__losuh__LOADMODULE_random () +{ + return &__losuh__MODULELIST[0]; +} + +static int32_t +__losuh__submod_rand_random (LosuVm *vm) +{ + // constructors of number in rand + + // constructors of string in rand + + // constructors of function in rand + /** + * @fn srand(seed:float ) + * @brief 设置随机数种子, 如果 seed 为空,则使用默认种子 + */ + __losuhAPI_regFunc (vm, "srand", __losuh__func_srand_rand_random); + + // constructors of script in rand + + // constructors of object in rand + + __losuhAPI_regObject (vm, "rand", __losuh__obj_rand_rand_random (vm)); + + // constructors of class in rand + + return 0; +} + +static int32_t +__losuh__submod_randn_random (LosuVm *vm) +{ + // constructors of number in randn + + // constructors of string in randn + + // constructors of function in randn + + // constructors of script in randn + + // constructors of object in randn + + __losuhAPI_regObject (vm, "randn", __losuh__obj_randn_randn_random (vm)); + + // constructors of class in randn + + return 0; +} + +static int32_t +__losuh__submod_rands_random (LosuVm *vm) +{ + // constructors of number in rands + + // constructors of string in rands + + // constructors of function in rands + + // constructors of script in rands + + // constructors of object in rands + + __losuhAPI_regObject (vm, "rands", __losuh__obj_rands_rands_random (vm)); + + // constructors of class in rands + + return 0; +} + +static LosuObj +__losuh__obj_rand_rand_random (LosuVm *vm) +{ + LosuObj newObj = obj_newunit (vm); + // constructor of number in rand@rand_random + + // constructor of string in rand@rand_random + + // constructor of object in rand@rand_random + + // constructor of class in rand@rand_random + + // constructor of function in rand@rand_random + /** + * @fn rand.srand(seed:float ) + * @brief 设置随机数种子, 如果 seed 为空,则使用默认种子 + */ + __losuhAPI_regObjFunc (vm, newObj, "srand", + __losuh__func_srand_rand_rand_random); + /** + * @fn rand.random() -> float + * @brief 生成一个 [0,1) 之间的随机浮点数 + */ + __losuhAPI_regObjFunc (vm, newObj, "random", + __losuh__func_random_rand_rand_random); + /** + * @fn rand.randint(a:int, b:int) -> int + * @brief 生成一个 [a,b) 之间的随机整数 + */ + __losuhAPI_regObjFunc (vm, newObj, "randint", + __losuh__func_randint_rand_rand_random); + /** + * @fn rand.randnum(a:int, b:int) -> float + * @brief 生成一个 [a,b) 之间的随机数 + */ + __losuhAPI_regObjFunc (vm, newObj, "randnum", + __losuh__func_randnum_rand_rand_random); + + return newObj; +} + +static LosuObj +__losuh__obj_randn_randn_random (LosuVm *vm) +{ + LosuObj newObj = obj_newunit (vm); + // constructor of number in randn@randn_random + + // constructor of string in randn@randn_random + + // constructor of object in randn@randn_random + + // constructor of class in randn@randn_random + + // constructor of function in randn@randn_random + /** + * @fn randn.int(a:int, b:int) -> int + * @brief 生成一个 [a,b) 之间的随机整数 + */ + __losuhAPI_regObjFunc (vm, newObj, "int", + __losuh__func_int_randn_randn_random); + /** + * @fn randn.num(a:int, b:int) -> float + * @brief 生成一个 [a,b) 之间的随机数 + */ + __losuhAPI_regObjFunc (vm, newObj, "num", + __losuh__func_num_randn_randn_random); + /** + * @fn randn.bool(rate:float =0) -> bool + * @brief 根据概率生成随机真伪值 + */ + __losuhAPI_regObjFunc (vm, newObj, "bool", + __losuh__func_bool_randn_randn_random); + + return newObj; +} + +static LosuObj +__losuh__obj_rands_rands_random (LosuVm *vm) +{ + LosuObj newObj = obj_newunit (vm); + // constructor of number in rands@rands_random + + // constructor of string in rands@rands_random + + // constructor of object in rands@rands_random + + // constructor of class in rands@rands_random + + // constructor of function in rands@rands_random + /** + * @fn rands.str(len:int) -> str + * @brief 生成一个长度为 len 的随机字符串 + */ + __losuhAPI_regObjFunc (vm, newObj, "str", + __losuh__func_str_rands_rands_random); + /** + * @fn rands.bits(len:int) -> str + * @brief 生成一个长度为 len 的随机二进制字符串 + */ + __losuhAPI_regObjFunc (vm, newObj, "bits", + __losuh__func_bits_rands_rands_random); + + return newObj; +} diff --git a/pkgs/random/random.lsh.h b/pkgs/random/random.lsh.h new file mode 100755 index 0000000000000000000000000000000000000000..843ea8393a362ee3531dee7065e1d60e37156088 --- /dev/null +++ b/pkgs/random/random.lsh.h @@ -0,0 +1,86 @@ + +/* + This file was generated by losuh - Losu Header Generator, which is part of + the Losu SDK. + + Losu is an open source programming language from China with excellent + performance (comparable to lua), ultra-lightweight resource footprint (only + 4KB RAM) and easy-to-learn syntax (similar to Python) for IoT development. + + This file follows the following MIT LICENSE by default + ------------------------------------ + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + +*/ + +#include "losu.h" +#include "losuh.h" +LosuModule *__losuh__LOADMODULE_random (); +/** + * @fn rand.srand(seed:float ) + * @brief 设置随机数种子, 如果 seed 为空,则使用默认种子 + */ +int32_t __losuh__func_srand_rand_rand_random (LosuVm *vm); +/** + * @fn rand.random() -> float + * @brief 生成一个 [0,1) 之间的随机浮点数 + */ +int32_t __losuh__func_random_rand_rand_random (LosuVm *vm); +/** + * @fn rand.randint(a:int, b:int) -> int + * @brief 生成一个 [a,b) 之间的随机整数 + */ +int32_t __losuh__func_randint_rand_rand_random (LosuVm *vm); +/** + * @fn rand.randnum(a:int, b:int) -> float + * @brief 生成一个 [a,b) 之间的随机数 + */ +int32_t __losuh__func_randnum_rand_rand_random (LosuVm *vm); +/** + * @fn srand(seed:float ) + * @brief 设置随机数种子, 如果 seed 为空,则使用默认种子 + */ +int32_t __losuh__func_srand_rand_random (LosuVm *vm); +/** + * @fn randn.int(a:int, b:int) -> int + * @brief 生成一个 [a,b) 之间的随机整数 + */ +int32_t __losuh__func_int_randn_randn_random (LosuVm *vm); +/** + * @fn randn.num(a:int, b:int) -> float + * @brief 生成一个 [a,b) 之间的随机数 + */ +int32_t __losuh__func_num_randn_randn_random (LosuVm *vm); +/** + * @fn randn.bool(rate:float =0) -> bool + * @brief 根据概率生成随机真伪值 + */ +int32_t __losuh__func_bool_randn_randn_random (LosuVm *vm); +/** + * @fn rands.str(len:int) -> str + * @brief 生成一个长度为 len 的随机字符串 + */ +int32_t __losuh__func_str_rands_rands_random (LosuVm *vm); +/** + * @fn rands.bits(len:int) -> str + * @brief 生成一个长度为 len 的随机二进制字符串 + */ +int32_t __losuh__func_bits_rands_rands_random (LosuVm *vm); diff --git "a/document/5-2-2-3-\350\264\241\347\214\256\345\206\205\346\240\270.md" b/pkgs/random/target/x86_64-linux-gnu.mk similarity index 100% rename from "document/5-2-2-3-\350\264\241\347\214\256\345\206\205\346\240\270.md" rename to pkgs/random/target/x86_64-linux-gnu.mk diff --git a/losu/losu.h b/pkgs/random/target/x86_64-w64-mingw32.mk similarity index 100% rename from losu/losu.h rename to pkgs/random/target/x86_64-w64-mingw32.mk diff --git a/pkgs/stdlib/config b/pkgs/stdlib/config new file mode 100755 index 0000000000000000000000000000000000000000..3030f5ee5a709e0cd52145fc55438b006bfbbcef --- /dev/null +++ b/pkgs/stdlib/config @@ -0,0 +1,9 @@ +pkgs={ + name: "stdlib", + version: "2.0.0", + description: "Losu Stdlib - Miniimal Standard Library Package", + target:{ + "x86_64-linux-gnu", + "x86_64-w64-mingw32", + }, +} \ No newline at end of file diff --git a/pkgs/stdlib/libstdlib.c b/pkgs/stdlib/libstdlib.c new file mode 100755 index 0000000000000000000000000000000000000000..092f4ad716bcc5232f88d36920aae0055809e5f4 --- /dev/null +++ b/pkgs/stdlib/libstdlib.c @@ -0,0 +1,420 @@ +/* + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#include "stdlib.lsh.h" +#include +#include +#include + +#ifdef __config_losucore_encode_nativeUTF8 + +#ifdef __config_losucore_encode_winGBK +#error "Invalid encode config" +#endif + +#define toSys(vm, s) (s) +#define toLosu(vm, s) (s) + +#endif + +#ifdef __config_losucore_encode_winGBK + +#ifdef __config_losucore_encode_nativeUTF8 +#error "Invalid encode config" +#endif + +#define toSys(vm, s) (charset_newObj_toSys (vm, s)) +#define toLosu(vm, s) (charset_newObj_toLosu (vm, s)) + +#endif + +#if 10 <= __config_losucore_platform_template \ + && __config_losucore_platform_template < 20 /* linux-all */ +#include +#define __config_losupkg_stdlib_platform_sleep(ms) (usleep (ms * 1000)) +#endif + +#if 20 <= __config_losucore_platform_template \ + && __config_losucore_platform_template < 30 /* windows-all */ +#include +#define __config_losupkg_stdlib_platform_sleep(ms) (Sleep (ms)) +#endif + +#define __config_losupkg_stdlib_buffszie 1024 + +/** + * @fn print( ...:str ) + * @brief 打印一行信息, 行末换行 + */ +int32_t +__losuh__func_print_io_stdlib (LosuVm *vm) +{ + for (int32_t i = 0; i < arg_num (vm); i++) + printf ("%s", toSys (vm, arg_getstr (vm, i + 1))); + printf ("\n"); + return 0; +} +/** + * @fn input( text:str = '' ,isline:bool = null ) + * @brief 输入数据, 如果 isline 非空, 输入一行 + * @param text 输入提示 + * @return str 输入的数据 + */ +int32_t +__losuh__func_input_io_stdlib (LosuVm *vm) +{ + char text[__config_losupkg_stdlib_buffszie] = { 0 }; + _l_bool isline = (arg_gettype (vm, 2) != LosuTypeDefine_null); + printf ("%s", toSys (vm, arg_getstr (vm, 1))); + + if (isline) + { + if (fgets (text, __config_losupkg_stdlib_buffszie, stdin) == NULL) + vm_error (vm, LosuErrorCode_Runtime, "Input overflow"); + } + else + { + if (scanf ("%s", text) != 1) + vm_error (vm, LosuErrorCode_Runtime, "Input failed"); + } + /* fmt */ + for (int32_t i = 0; text[i]; i++) + if (text[i] == '\n' || text[i] == '\r') + { + text[i] = 0; + break; + } + arg_returnstr (vm, toLosu (vm, text)); + return 1; +} +/** + * @fn sleep( ms:int ) + * @brief 睡眠 ms 毫秒 + */ +int32_t +__losuh__func_sleep_io_stdlib (LosuVm *vm) +{ + __config_losupkg_stdlib_platform_sleep (((int32_t)arg_getnum (vm, 1))); + return 0; +} +/** + * @fn exit( code:int = 0 ) + * @brief 退出程序 code 为退出码 + */ +int32_t +__losuh__func_exit_io_stdlib (LosuVm *vm) +{ + exit ((int32_t)arg_getnum (vm, 1)); + return 0; +} +/** + * @fn system( cmd:str ) + * @brief 执行系统命令,返回值 + */ +int32_t +__losuh__func_system_io_stdlib (LosuVm *vm) +{ + int32_t i = system (toSys (vm, arg_getstr (vm, 1))); + arg_returnnum (vm, i); + return 1; +} +/** + * @fn type( obj:any ) + * @brief 返回 obj 的类型 + * @return type obj的类型 + */ +int32_t +__losuh__func_type_type_stdlib (LosuVm *vm) +{ + arg_returnstr (vm, arg_gettypeStr (vm, 1)); + return 1; +} +/** + * @fn val( obj:any ) + * @brief 将 obj 数值化, 进行 ::->num 转换 + * @return val:float obj的值 + */ +int32_t +__losuh__func_val_type_stdlib (LosuVm *vm) +{ + arg_returnnum (vm, arg_getnum (vm, 1)); + return 1; +} +/** + * @fn int( obj:any ) + * @brief 将 obj 转换为整数, 先进行 ::->num 转换, 然后进行 num->int 转换 + * @return val:int obj的值 + */ +int32_t +__losuh__func_int_type_stdlib (LosuVm *vm) +{ + arg_returnnum (vm, (int32_t)arg_getnum (vm, 1)); + return 1; +} +/** + * @fn str( obj:any ) + * @brief 将 obj 转换为字符串, 进行 ::->str 转换 + * @return val:str obj的值 + */ +int32_t +__losuh__func_str_type_stdlib (LosuVm *vm) +{ + arg_returnstr (vm, arg_getstr (vm, 1)); + return 1; +} +/** + * @fn char( asc:int ) + * @brief 将 asc 转换为字符 + * @return val:str asc 对应的字符 + */ +int32_t +__losuh__func_char_type_stdlib (LosuVm *vm) +{ + char c[2] = { 0 }; + c[0] = (char)arg_getnum (vm, 1); + arg_returnstr (vm, c); + return 1; +} +/** + * @fn asc( char:str ) + * @brief 将 char 转换为 ascii 码 + * @return val:int char 对应的 ascii 码 + */ +int32_t +__losuh__func_asc_type_stdlib (LosuVm *vm) +{ + uint8_t asc = arg_getstr (vm, 1)[0]; + arg_returnnum (vm, (_l_number)((int32_t)(asc))); + return 1; +} +/** + * @fn vm.version( fmt:bool = null ) + * @brief 返回当前 vm 的版本号 + * @return version:str/int vm的版本号, 如果 fmt 为 null, 返回字符串, + * 否则返回整数 + */ +/** + * @fn len( s:str ) + * @brief 返回字符串 s 的长度 + * @return val:int 字符串 s 的长度 + */ +int32_t +__losuh__func_len_type_stdlib (LosuVm *vm) +{ + arg_returnnum (vm, obj_getstrlen (vm, arg_get (vm, 1))); + return 1; +} +/** + * @fn vm.version( fmt:bool = null ) + * @brief 返回当前 vm 的版本号 + * @return version:str/int vm的版本号, 如果 fmt 为 null, 返回字符串, + * 否则返回整数 + */ +int32_t +__losuh__func_version_vm_vm_stdlib (LosuVm *vm) +{ + _l_bool n = arg_gettype (vm, 2) != LosuTypeDefine_null; + if (n) + arg_returnnum (vm, LosuVersionNum); + else + arg_returnstr (vm, LosuVersion); + return 1; +} +/** + * @fn vm.build() + * @brief 返回当前 vm 的构建信息 + * @return build:str vm的构建信息 + */ +int32_t +__losuh__func_build_vm_vm_stdlib (LosuVm *vm) +{ + arg_returnstr (vm, LosuBuild); + return 1; +} +/** + * @fn vm.copyright() + * @brief 返回当前 vm 的版权信息 + * @return copyright:str vm的版权信息 + */ +int32_t +__losuh__func_copyright_vm_vm_stdlib (LosuVm *vm) +{ + arg_returnstr (vm, LosuCopyright); + return 1; +} +/** + * @fn eval( spt:str ,name:str = 'unknown' ) + * @brief 解释执行 spt 字符串 + * @return ... 一到多个脚本返回值 + */ +int32_t +__losuh__func_eval_vm_stdlib (LosuVm *vm) +{ + const char *s = arg_getstr (vm, 1); + const char *name = arg_getstr (vm, 2); + LosuObj *oldtop = vm->top; + if (name[0] == '\0') + name = "unknown"; + if (!s) /* s == NULL */ + return 0; + int32_t sta = vm_loadstring (vm, s, name); + if (sta) /* error */ + return 0; + stack_call (vm, 0, -1); + return vm->top - oldtop; +} +/** + * @fn exec( fn:str ) + * @breif 执行 fn 文件 (源代码或预编译的二进制) + * @return ... 一到多个脚本返回值 + */ +int32_t +__losuh__func_exec_vm_stdlib (LosuVm *vm) +{ + const char *fn = arg_getstr (vm, 1); + LosuObj *oldtop = vm->top; + if (fn[0] == '\0') + return 0; + int32_t sta = vm_loadfile (vm, toSys (vm, fn)); + if (sta) /* error */ + return 0; + stack_call (vm, 0, -1); + return vm->top - oldtop; +} +/** + * @fn error( msg:str = '' ) + * @brief 抛出异常 msg 为运行时异常信息 + */ +int32_t +__losuh__func_error_vm_stdlib (LosuVm *vm) +{ + vm_error (vm, LosuErrorCode_Runtime, arg_getstr (vm, 1)); + return 0; +} +/** + * @fn warning( msg:str = '' ) + * @brief 抛出警告 msg 为运行时警告信息 + */ +int32_t +__losuh__func_warning_vm_stdlib (LosuVm *vm) +{ + vm_warning (vm, arg_getstr (vm, 1)); + return 0; +} +/** + * @fn mem.nowuse( self, p:str = 'B' ) + * @brief 返回当前内存使用量 + * @return size:int 当前内存使用量,单位为 p(B,KB,M) + */ +int32_t +__losuh__func_nowuse_mem_mem_stdlib (LosuVm *vm) +{ + uint8_t p = arg_getstr (vm, 2)[0]; + int32_t e = 1; + switch (p) + { + case 'K': + e = 1024; + break; + case 'M': + e = 1024 * 1024; + default: + break; + } + arg_returnnum (vm, (_l_number)((_l_number)gc_getmemNow (vm) / (_l_number)e)); + return 1; +} +/** + * @fn mem.maxuse( self, p:str = 'B' ) + * @brief 返回最大内存使用量 + * @return size:int 最大内存使用量,单位为 p(B,KB,M) + */ +int32_t +__losuh__func_maxuse_mem_mem_stdlib (LosuVm *vm) +{ + uint8_t p = arg_getstr (vm, 2)[0]; + int32_t e = 1; + switch (p) + { + case 'K': + e = 1024; + break; + case 'M': + e = 1024 * 1024; + default: + break; + } + arg_returnnum (vm, (_l_number)((_l_number)gc_getmemMax (vm) / (_l_number)e)); + return 1; +} +/** + * @fn mem.setgc( self, size:int ,p:str = 'B' ) + * @brief 设置垃圾回收阈值, 单位为 p(B,KB,M) + */ +int32_t +__losuh__func_setgc_mem_mem_stdlib (LosuVm *vm) +{ + uint8_t p = arg_getstr (vm, 3)[0]; + int32_t e = 1; + switch (p) + { + case 'K': + e = 1024; + break; + case 'M': + e = 1024 * 1024; + default: + break; + } + + gc_setmax (vm, (_l_gcint)(arg_getnum (vm, 2) * e)); + return 0; +} +/** + * @fn mem.gc() + * @brief 手动触发垃圾回收 + * @return b:int 0-未进行垃圾回收, 1-进行了垃圾回收 + */ +int32_t +__losuh__func_gc_mem_mem_stdlib (LosuVm *vm) +{ + arg_returnnum (vm, gc_collect (vm)); + return 1; +} \ No newline at end of file diff --git a/pkgs/stdlib/stdlib.lsh b/pkgs/stdlib/stdlib.lsh new file mode 100755 index 0000000000000000000000000000000000000000..c1f1c81645163f0bf2ca935933f887be76af0d42 --- /dev/null +++ b/pkgs/stdlib/stdlib.lsh @@ -0,0 +1,96 @@ +# Package: stdlib { io, type, vm , mem} +module stdlib + # 洛书内置函数 from import new class + sub io + def print( ...:str ): + "@fn print( ...:str )" + "@brief 打印一行信息, 行末换行" + def input( text:str = '' ,isline:bool = null): + "@fn input( text:str = '' ,isline:bool = null )" + "@brief 输入数据, 如果 isline 非空, 输入一行" + "@param text 输入提示" + "@return str 输入的数据" + def sleep( ms:int ): + "@fn sleep( ms:int )" + "@brief 睡眠 ms 毫秒" + def exit( code:int = 0 ): + "@fn exit( code:int = 0 )" + "@brief 退出程序 code 为退出码" + def system(cmd:str): + "@fn system( cmd:str )" + "@brief 执行系统命令,返回值" + sub type + def type( obj:any ): + "@fn type( obj:any )" + "@brief 返回 obj 的类型" + "@return type obj的类型" + def val( obj:any ): + "@fn val( obj:any )" + "@brief 将 obj 数值化, 进行 ::->num 转换" + "@return val:float obj的值" + def int( obj:any ): + "@fn int( obj:any )" + "@brief 将 obj 转换为整数, 先进行 ::->num 转换, 然后进行 num->int 转换" + "@return val:int obj的值" + def str( obj:any ): + "@fn str( obj:any )" + "@brief 将 obj 转换为字符串, 进行 ::->str 转换" + "@return val:str obj的值" + def char( asc:int ): + "@fn char( asc:int )" + "@brief 将 asc 转换为字符" + "@return val:str asc 对应的字符" + def asc( char:str ): + "@fn asc( char:str )" + "@brief 将 char 转换为 ascii 码" + "@return val:int char 对应的 ascii 码" + def len( s:str ): + "@fn len( s:str )" + "@brief 返回字符串 s 的长度" + "@return val:int 字符串 s 的长度" + sub vm + def eval( spt:str ,name:str = 'unknown' ): + "@fn eval( spt:str ,name:str = 'unknown' )" + "@brief 解释执行 spt 字符串" + "@return ... 一到多个脚本返回值" + def exec( fn:str ): + "@fn exec( fn:str )" + "@breif 执行 fn 文件 (源代码或预编译的二进制)" + "@return ... 一到多个脚本返回值" + def error( msg:str = '' ): + "@fn error( msg:str = '' )" + "@brief 抛出异常 msg 为运行时异常信息" + def warning( msg:str = '' ): + "@fn warning( msg:str = '' )" + "@brief 抛出警告 msg 为运行时警告信息" + object vm + def version( self ,fmt:bool = null ): + "@fn vm.version( fmt:bool = null )" + "@brief 返回当前 vm 的版本号" + "@return version:str/int vm的版本号, 如果 fmt 为 null, 返回字符串, 否则返回整数" + def build(): + "@fn vm.build()" + "@brief 返回当前 vm 的构建信息" + "@return build:str vm的构建信息" + def copyright(): + "@fn vm.copyright()" + "@brief 返回当前 vm 的版权信息" + "@return copyright:str vm的版权信息" + sub mem + object mem + def nowuse( self , p:str = 'B'): + "@fn mem.nowuse( self, p:str = 'B' )" + "@brief 返回当前内存使用量" + "@return size:int 当前内存使用量,单位为 p(B,KB,M)" + def maxuse( self , p:str = 'B'): + "@fn mem.maxuse( self, p:str = 'B' )" + "@brief 返回最大内存使用量" + "@return size:int 最大内存使用量,单位为 p(B,KB,M)" + def setgc( self ,size:int ,p:str = 'B' ): + "@fn mem.setgc( self, size:int ,p:str = 'B' )" + "@brief 设置垃圾回收阈值, 单位为 p(B,KB,M)" + def gc(): + "@fn mem.gc()" + "@brief 手动触发垃圾回收" + "@return b:int 0-未进行垃圾回收, 1-进行了垃圾回收" + \ No newline at end of file diff --git a/pkgs/stdlib/stdlib.lsh.c b/pkgs/stdlib/stdlib.lsh.c new file mode 100755 index 0000000000000000000000000000000000000000..ad72419add7886b60a0a946b13f704dd22d2b88e --- /dev/null +++ b/pkgs/stdlib/stdlib.lsh.c @@ -0,0 +1,291 @@ + +/* + This file was generated by losuh - Losu Header Generator, which is part of + the Losu SDK. + + Losu is an open source programming language from China with excellent + performance (comparable to lua), ultra-lightweight resource footprint (only + 4KB RAM) and easy-to-learn syntax (similar to Python) for IoT development. + + This file follows the following MIT LICENSE by default + ------------------------------------ + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + +*/ + +#include "stdlib.lsh.h" +static int32_t __losuh__submod_io_stdlib(LosuVm *vm); +static int32_t __losuh__submod_type_stdlib(LosuVm *vm); +static int32_t __losuh__submod_vm_stdlib(LosuVm *vm); +static LosuObj __losuh__obj_vm_vm_stdlib(LosuVm *vm); +static int32_t __losuh__submod_mem_stdlib(LosuVm *vm); +static LosuObj __losuh__obj_mem_mem_stdlib(LosuVm *vm); + + +static LosuModule __losuh__MODULELIST[] = { +{"io",__losuh__submod_io_stdlib}, +{"type",__losuh__submod_type_stdlib}, +{"vm",__losuh__submod_vm_stdlib}, +{"mem",__losuh__submod_mem_stdlib}, +{NULL,NULL}, +}; +LosuModule *__losuh__LOADMODULE_stdlib() { +return &__losuh__MODULELIST[0]; +} + + +static int32_t __losuh__submod_io_stdlib(LosuVm *vm) { +// constructors of number in io + +// constructors of string in io + +// constructors of function in io +/** +* @fn print( ...:str ) +* @brief 打印一行信息, 行末换行 +*/ +__losuhAPI_regFunc(vm,"print",__losuh__func_print_io_stdlib); +/** +* @fn input( text:str = '' ,isline:bool = null ) +* @brief 输入数据, 如果 isline 非空, 输入一行 +* @param text 输入提示 +* @return str 输入的数据 +*/ +__losuhAPI_regFunc(vm,"input",__losuh__func_input_io_stdlib); +/** +* @fn sleep( ms:int ) +* @brief 睡眠 ms 毫秒 +*/ +__losuhAPI_regFunc(vm,"sleep",__losuh__func_sleep_io_stdlib); +/** +* @fn exit( code:int = 0 ) +* @brief 退出程序 code 为退出码 +*/ +__losuhAPI_regFunc(vm,"exit",__losuh__func_exit_io_stdlib); +/** +* @fn system( cmd:str ) +* @brief 执行系统命令,返回值 +*/ +__losuhAPI_regFunc(vm,"system",__losuh__func_system_io_stdlib); + +// constructors of script in io + +// constructors of object in io + +// constructors of class in io + + +return 0; +} + +static int32_t __losuh__submod_type_stdlib(LosuVm *vm) { +// constructors of number in type + +// constructors of string in type + +// constructors of function in type +/** +* @fn type( obj:any ) +* @brief 返回 obj 的类型 +* @return type obj的类型 +*/ +__losuhAPI_regFunc(vm,"type",__losuh__func_type_type_stdlib); +/** +* @fn val( obj:any ) +* @brief 将 obj 数值化, 进行 ::->num 转换 +* @return val:float obj的值 +*/ +__losuhAPI_regFunc(vm,"val",__losuh__func_val_type_stdlib); +/** +* @fn int( obj:any ) +* @brief 将 obj 转换为整数, 先进行 ::->num 转换, 然后进行 num->int 转换 +* @return val:int obj的值 +*/ +__losuhAPI_regFunc(vm,"int",__losuh__func_int_type_stdlib); +/** +* @fn str( obj:any ) +* @brief 将 obj 转换为字符串, 进行 ::->str 转换 +* @return val:str obj的值 +*/ +__losuhAPI_regFunc(vm,"str",__losuh__func_str_type_stdlib); +/** +* @fn char( asc:int ) +* @brief 将 asc 转换为字符 +* @return val:str asc 对应的字符 +*/ +__losuhAPI_regFunc(vm,"char",__losuh__func_char_type_stdlib); +/** +* @fn asc( char:str ) +* @brief 将 char 转换为 ascii 码 +* @return val:int char 对应的 ascii 码 +*/ +__losuhAPI_regFunc(vm,"asc",__losuh__func_asc_type_stdlib); +/** +* @fn len( s:str ) +* @brief 返回字符串 s 的长度 +* @return val:int 字符串 s 的长度 +*/ +__losuhAPI_regFunc(vm,"len",__losuh__func_len_type_stdlib); + +// constructors of script in type + +// constructors of object in type + +// constructors of class in type + + +return 0; +} + +static int32_t __losuh__submod_vm_stdlib(LosuVm *vm) { +// constructors of number in vm + +// constructors of string in vm + +// constructors of function in vm +/** +* @fn eval( spt:str ,name:str = 'unknown' ) +* @brief 解释执行 spt 字符串 +* @return ... 一到多个脚本返回值 +*/ +__losuhAPI_regFunc(vm,"eval",__losuh__func_eval_vm_stdlib); +/** +* @fn exec( fn:str ) +* @breif 执行 fn 文件 (源代码或预编译的二进制) +* @return ... 一到多个脚本返回值 +*/ +__losuhAPI_regFunc(vm,"exec",__losuh__func_exec_vm_stdlib); +/** +* @fn error( msg:str = '' ) +* @brief 抛出异常 msg 为运行时异常信息 +*/ +__losuhAPI_regFunc(vm,"error",__losuh__func_error_vm_stdlib); +/** +* @fn warning( msg:str = '' ) +* @brief 抛出警告 msg 为运行时警告信息 +*/ +__losuhAPI_regFunc(vm,"warning",__losuh__func_warning_vm_stdlib); + +// constructors of script in vm + +// constructors of object in vm + +__losuhAPI_regObject(vm,"vm",__losuh__obj_vm_vm_stdlib(vm)); + +// constructors of class in vm + + +return 0; +} + +static int32_t __losuh__submod_mem_stdlib(LosuVm *vm) { +// constructors of number in mem + +// constructors of string in mem + +// constructors of function in mem + +// constructors of script in mem + +// constructors of object in mem + +__losuhAPI_regObject(vm,"mem",__losuh__obj_mem_mem_stdlib(vm)); + +// constructors of class in mem + + +return 0; +} + + +static LosuObj __losuh__obj_vm_vm_stdlib(LosuVm *vm){ +LosuObj newObj = obj_newunit(vm); +// constructor of number in vm@vm_stdlib + +// constructor of string in vm@vm_stdlib + +// constructor of object in vm@vm_stdlib + +// constructor of class in vm@vm_stdlib + +// constructor of function in vm@vm_stdlib +/** +* @fn vm.version( fmt:bool = null ) +* @brief 返回当前 vm 的版本号 +* @return version:str/int vm的版本号, 如果 fmt 为 null, 返回字符串, 否则返回整数 +*/ +__losuhAPI_regObjFunc(vm,newObj,"version",__losuh__func_version_vm_vm_stdlib); +/** +* @fn vm.build() +* @brief 返回当前 vm 的构建信息 +* @return build:str vm的构建信息 +*/ +__losuhAPI_regObjFunc(vm,newObj,"build",__losuh__func_build_vm_vm_stdlib); +/** +* @fn vm.copyright() +* @brief 返回当前 vm 的版权信息 +* @return copyright:str vm的版权信息 +*/ +__losuhAPI_regObjFunc(vm,newObj,"copyright",__losuh__func_copyright_vm_vm_stdlib); + +return newObj; +} + +static LosuObj __losuh__obj_mem_mem_stdlib(LosuVm *vm){ +LosuObj newObj = obj_newunit(vm); +// constructor of number in mem@mem_stdlib + +// constructor of string in mem@mem_stdlib + +// constructor of object in mem@mem_stdlib + +// constructor of class in mem@mem_stdlib + +// constructor of function in mem@mem_stdlib +/** +* @fn mem.nowuse( self, p:str = 'B' ) +* @brief 返回当前内存使用量 +* @return size:int 当前内存使用量,单位为 p(B,KB,M) +*/ +__losuhAPI_regObjFunc(vm,newObj,"nowuse",__losuh__func_nowuse_mem_mem_stdlib); +/** +* @fn mem.maxuse( self, p:str = 'B' ) +* @brief 返回最大内存使用量 +* @return size:int 最大内存使用量,单位为 p(B,KB,M) +*/ +__losuhAPI_regObjFunc(vm,newObj,"maxuse",__losuh__func_maxuse_mem_mem_stdlib); +/** +* @fn mem.setgc( self, size:int ,p:str = 'B' ) +* @brief 设置垃圾回收阈值, 单位为 p(B,KB,M) +*/ +__losuhAPI_regObjFunc(vm,newObj,"setgc",__losuh__func_setgc_mem_mem_stdlib); +/** +* @fn mem.gc() +* @brief 手动触发垃圾回收 +* @return b:int 0-未进行垃圾回收, 1-进行了垃圾回收 +*/ +__losuhAPI_regObjFunc(vm,newObj,"gc",__losuh__func_gc_mem_mem_stdlib); + +return newObj; +} + + + diff --git a/pkgs/stdlib/stdlib.lsh.h b/pkgs/stdlib/stdlib.lsh.h new file mode 100755 index 0000000000000000000000000000000000000000..b66ff5b809fb62cc328cea25f40340f05bb8a986 --- /dev/null +++ b/pkgs/stdlib/stdlib.lsh.h @@ -0,0 +1,169 @@ + +/* + This file was generated by losuh - Losu Header Generator, which is part of + the Losu SDK. + + Losu is an open source programming language from China with excellent + performance (comparable to lua), ultra-lightweight resource footprint (only + 4KB RAM) and easy-to-learn syntax (similar to Python) for IoT development. + + This file follows the following MIT LICENSE by default + ------------------------------------ + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + +*/ + +#include "losu.h" +#include "losuh.h" +LosuModule *__losuh__LOADMODULE_stdlib(); +/** +* @fn print( ...:str ) +* @brief 打印一行信息, 行末换行 +*/ +int32_t __losuh__func_print_io_stdlib(LosuVm *vm); +/** +* @fn input( text:str = '' ,isline:bool = null ) +* @brief 输入数据, 如果 isline 非空, 输入一行 +* @param text 输入提示 +* @return str 输入的数据 +*/ +int32_t __losuh__func_input_io_stdlib(LosuVm *vm); +/** +* @fn sleep( ms:int ) +* @brief 睡眠 ms 毫秒 +*/ +int32_t __losuh__func_sleep_io_stdlib(LosuVm *vm); +/** +* @fn exit( code:int = 0 ) +* @brief 退出程序 code 为退出码 +*/ +int32_t __losuh__func_exit_io_stdlib(LosuVm *vm); +/** +* @fn system( cmd:str ) +* @brief 执行系统命令,返回值 +*/ +int32_t __losuh__func_system_io_stdlib(LosuVm *vm); +/** +* @fn type( obj:any ) +* @brief 返回 obj 的类型 +* @return type obj的类型 +*/ +int32_t __losuh__func_type_type_stdlib(LosuVm *vm); +/** +* @fn val( obj:any ) +* @brief 将 obj 数值化, 进行 ::->num 转换 +* @return val:float obj的值 +*/ +int32_t __losuh__func_val_type_stdlib(LosuVm *vm); +/** +* @fn int( obj:any ) +* @brief 将 obj 转换为整数, 先进行 ::->num 转换, 然后进行 num->int 转换 +* @return val:int obj的值 +*/ +int32_t __losuh__func_int_type_stdlib(LosuVm *vm); +/** +* @fn str( obj:any ) +* @brief 将 obj 转换为字符串, 进行 ::->str 转换 +* @return val:str obj的值 +*/ +int32_t __losuh__func_str_type_stdlib(LosuVm *vm); +/** +* @fn char( asc:int ) +* @brief 将 asc 转换为字符 +* @return val:str asc 对应的字符 +*/ +int32_t __losuh__func_char_type_stdlib(LosuVm *vm); +/** +* @fn asc( char:str ) +* @brief 将 char 转换为 ascii 码 +* @return val:int char 对应的 ascii 码 +*/ +int32_t __losuh__func_asc_type_stdlib(LosuVm *vm); +/** +* @fn len( s:str ) +* @brief 返回字符串 s 的长度 +* @return val:int 字符串 s 的长度 +*/ +int32_t __losuh__func_len_type_stdlib(LosuVm *vm); +/** +* @fn vm.version( fmt:bool = null ) +* @brief 返回当前 vm 的版本号 +* @return version:str/int vm的版本号, 如果 fmt 为 null, 返回字符串, 否则返回整数 +*/ +int32_t __losuh__func_version_vm_vm_stdlib(LosuVm *vm); +/** +* @fn vm.build() +* @brief 返回当前 vm 的构建信息 +* @return build:str vm的构建信息 +*/ +int32_t __losuh__func_build_vm_vm_stdlib(LosuVm *vm); +/** +* @fn vm.copyright() +* @brief 返回当前 vm 的版权信息 +* @return copyright:str vm的版权信息 +*/ +int32_t __losuh__func_copyright_vm_vm_stdlib(LosuVm *vm); +/** +* @fn eval( spt:str ,name:str = 'unknown' ) +* @brief 解释执行 spt 字符串 +* @return ... 一到多个脚本返回值 +*/ +int32_t __losuh__func_eval_vm_stdlib(LosuVm *vm); +/** +* @fn exec( fn:str ) +* @breif 执行 fn 文件 (源代码或预编译的二进制) +* @return ... 一到多个脚本返回值 +*/ +int32_t __losuh__func_exec_vm_stdlib(LosuVm *vm); +/** +* @fn error( msg:str = '' ) +* @brief 抛出异常 msg 为运行时异常信息 +*/ +int32_t __losuh__func_error_vm_stdlib(LosuVm *vm); +/** +* @fn warning( msg:str = '' ) +* @brief 抛出警告 msg 为运行时警告信息 +*/ +int32_t __losuh__func_warning_vm_stdlib(LosuVm *vm); +/** +* @fn mem.nowuse( self, p:str = 'B' ) +* @brief 返回当前内存使用量 +* @return size:int 当前内存使用量,单位为 p(B,KB,M) +*/ +int32_t __losuh__func_nowuse_mem_mem_stdlib(LosuVm *vm); +/** +* @fn mem.maxuse( self, p:str = 'B' ) +* @brief 返回最大内存使用量 +* @return size:int 最大内存使用量,单位为 p(B,KB,M) +*/ +int32_t __losuh__func_maxuse_mem_mem_stdlib(LosuVm *vm); +/** +* @fn mem.setgc( self, size:int ,p:str = 'B' ) +* @brief 设置垃圾回收阈值, 单位为 p(B,KB,M) +*/ +int32_t __losuh__func_setgc_mem_mem_stdlib(LosuVm *vm); +/** +* @fn mem.gc() +* @brief 手动触发垃圾回收 +* @return b:int 0-未进行垃圾回收, 1-进行了垃圾回收 +*/ +int32_t __losuh__func_gc_mem_mem_stdlib(LosuVm *vm); + diff --git a/pkgs/stdlib/target/x86_64-linux-gnu.mk b/pkgs/stdlib/target/x86_64-linux-gnu.mk new file mode 100755 index 0000000000000000000000000000000000000000..979ed6e2dc231f8dc1f16ef75b89db9c2ff3d8a5 --- /dev/null +++ b/pkgs/stdlib/target/x86_64-linux-gnu.mk @@ -0,0 +1,30 @@ +PkgTarget=$(LosuSDK_Build)/target/pkgs +PkgObj=$(LosuSDK_Build)/obj/target/pkgs/stdlib + +cc=x86_64-linux-gnu-gcc + +CIncFile=$(shell ls $(LosuSDK_Include)/*.h) stdlib.lsh.h + +cWarning= -Wall +cStd= -std=gnu99 +cOpt= -O2 +cInclude= -I$(LosuSDK_Include) + +cFlags= $(cWarning) $(cStd) $(cOpt) $(cInclude) + +$(PkgTarget)/liblpkgstdlib.a:\ + $(PkgObj)/.keep\ + $(PkgObj)/stdlib.lsh.o\ + $(PkgObj)/libstdlib.o\ + + ar crs $@ $^ + +$(PkgObj)/.keep: + mkdir -p $(PkgObj) + touch $@ + +$(PkgObj)/stdlib.lsh.o: stdlib.lsh.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ + +$(PkgObj)/libstdlib.o: libstdlib.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ \ No newline at end of file diff --git a/pkgs/stdlib/target/x86_64-w64-mingw32.mk b/pkgs/stdlib/target/x86_64-w64-mingw32.mk new file mode 100755 index 0000000000000000000000000000000000000000..2fd6154481fe75b128cc7dd2efd0a147da6c2290 --- /dev/null +++ b/pkgs/stdlib/target/x86_64-w64-mingw32.mk @@ -0,0 +1,30 @@ +PkgTarget=$(LosuSDK_Build)/target/pkgs +PkgObj=$(LosuSDK_Build)/obj/target/pkgs/stdlib + +cc=x86_64-w64-mingw32-gcc + +CIncFile=$(shell ls $(LosuSDK_Include)/*.h) stdlib.lsh.h + +cWarning= -Wall +cStd= -std=gnu99 +cOpt= -O2 +cInclude= -I$(LosuSDK_Include) + +cFlags= $(cWarning) $(cStd) $(cOpt) $(cInclude) + +$(PkgTarget)/liblpkgstdlib.a:\ + $(PkgObj)/.keep\ + $(PkgObj)/stdlib.lsh.o\ + $(PkgObj)/libstdlib.o\ + + ar crs $@ $^ + +$(PkgObj)/.keep: + mkdir -p $(PkgObj) + touch $@ + +$(PkgObj)/stdlib.lsh.o: stdlib.lsh.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ + +$(PkgObj)/libstdlib.o: libstdlib.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ \ No newline at end of file diff --git a/pkgs/time/config b/pkgs/time/config new file mode 100755 index 0000000000000000000000000000000000000000..002d1942dace2fe1dc2eaa201d4b2df988dceb80 --- /dev/null +++ b/pkgs/time/config @@ -0,0 +1,9 @@ +pkgs = { + name: "time", + version: "2.0.0", + description: "Time Package for Losu, with basic time functions", + target:{ + "x86_64-linux-gnu", + "x86_64-w64-mingw32", + }, +} \ No newline at end of file diff --git a/pkgs/time/libtime.c b/pkgs/time/libtime.c new file mode 100755 index 0000000000000000000000000000000000000000..4a55795a692d15a028eb858ad5c41a0258ec53a7 --- /dev/null +++ b/pkgs/time/libtime.c @@ -0,0 +1,168 @@ +/* + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#include "time.lsh.h" +#include +#include + +/** + * @fn time.year() -> int + * @brief 返回当前年份 + * @return y:int 当前年份 + */ +int32_t +__losuh__func_year_time_time_time (LosuVm *vm) +{ + time_t t; + time (&t); + arg_returnnum (vm, (localtime (&t)->tm_year) + 1900); + return 1; +} +/** + * @fn time.month() -> int + * @brief 返回当前月份 + * @return m:int 当前月份 + */ +int32_t +__losuh__func_month_time_time_time (LosuVm *vm) +{ + time_t t; + time (&t); + arg_returnnum (vm, (localtime (&t)->tm_mon) + 1); + return 1; +} +/** + * @fn time.day() -> int + * @brief 返回当前日期 + * @return d:int 当前日期 + */ +int32_t +__losuh__func_day_time_time_time (LosuVm *vm) +{ + time_t t; + time (&t); + arg_returnnum (vm, (localtime (&t)->tm_mday)); + return 1; +} +/** + * @fn time.hour() -> int + * @brief 返回当前小时 + * @return h:int 当前小时 + */ +int32_t +__losuh__func_hour_time_time_time (LosuVm *vm) +{ + time_t t; + time (&t); + arg_returnnum (vm, (localtime (&t)->tm_hour)); + return 1; +} +/** + * @fn time.minute() -> int + * @brief 返回当前分钟 + * @return m:int 当前分钟 + */ +int32_t +__losuh__func_minute_time_time_time (LosuVm *vm) +{ + time_t t; + time (&t); + arg_returnnum (vm, (localtime (&t)->tm_min)); + return 1; +} +/** + * @fn time.second() -> int + * @brief 返回当前秒数 + * @return s:int 当前秒数 + */ +int32_t +__losuh__func_second_time_time_time (LosuVm *vm) +{ + time_t t; + time (&t); + arg_returnnum (vm, (localtime (&t)->tm_sec)); + return 1; +} +/** + * @fn time.date(self, fmt: str) -> int/str + * @brief 返回当前日期(周几) + * @return d:int/str 当前日期,如果 fmt 为 'en' 返回英文,'cn' + * 返回中文,为空返回数字 + */ +int32_t +__losuh__func_date_time_time_time (LosuVm *vm) +{ + LosuObj *fmt = arg_get (vm, 2); + time_t t; + int32_t wdate; + const char *_wdateCn[] = { + "周日", "周一", "周二", "周三", "周四", "周五", "周六", + }; + const char *_wdateEn[] = { + "Sunday", "Monday", "Tuesday", "Wednesday", + "Thursday", "Friday", "Saturday", + }; + + time (&t); + wdate = localtime (&t)->tm_wday; + if (obj_type (vm, fmt) == LosuTypeDefine_null) + arg_returnnum (vm, wdate); + else + { + if (strcmp (obj_tostr (vm, fmt), "cn") == 0) + arg_returnstr (vm, _wdateCn[wdate]); + else if (strcmp (obj_tostr (vm, fmt), "en") == 0) + arg_returnstr (vm, _wdateEn[wdate]); + else + arg_returnnum (vm, wdate); + } + return 1; +} +/** + * @fn time.time() -> int + * @brief 返回当前时间戳 + * @return t:int 当前时间戳 + */ +int32_t +__losuh__func_time_time_time_time (LosuVm *vm) +{ + arg_returnnum (vm, (_l_number)(clock ()) / CLOCKS_PER_SEC); + return 1; +} \ No newline at end of file diff --git a/pkgs/time/target/x86_64-linux-gnu.mk b/pkgs/time/target/x86_64-linux-gnu.mk new file mode 100755 index 0000000000000000000000000000000000000000..59bfb222ba6462271ba635eaa067a1683226c2ae --- /dev/null +++ b/pkgs/time/target/x86_64-linux-gnu.mk @@ -0,0 +1,30 @@ +PkgTarget=$(LosuSDK_Build)/target/pkgs +PkgObj=$(LosuSDK_Build)/obj/target/pkgs/time + +cc=x86_64-linux-gnu-gcc + +CIncFile=$(shell ls $(LosuSDK_Include)/*.h) time.lsh.h + +cWarning= -Wall +cStd= -std=gnu99 +cOpt= -O2 +cInclude= -I$(LosuSDK_Include) + +cFlags= $(cWarning) $(cStd) $(cOpt) $(cInclude) + +$(PkgTarget)/liblpkgtime.a:\ + $(PkgObj)/.keep\ + $(PkgObj)/time.lsh.o\ + $(PkgObj)/libtime.o\ + + ar crs $@ $^ + +$(PkgObj)/.keep: + mkdir -p $(PkgObj) + touch $@ + +$(PkgObj)/time.lsh.o: time.lsh.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ + +$(PkgObj)/libtime.o: libtime.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ \ No newline at end of file diff --git a/pkgs/time/target/x86_64-w64-mingw32.mk b/pkgs/time/target/x86_64-w64-mingw32.mk new file mode 100755 index 0000000000000000000000000000000000000000..34d14f8e7927b90d3fba8ebc09ea97ce57812abf --- /dev/null +++ b/pkgs/time/target/x86_64-w64-mingw32.mk @@ -0,0 +1,30 @@ +PkgTarget=$(LosuSDK_Build)/target/pkgs +PkgObj=$(LosuSDK_Build)/obj/target/pkgs/time + +cc=x86_64-w64-mingw32-gcc + +CIncFile=$(shell ls $(LosuSDK_Include)/*.h) time.lsh.h + +cWarning= -Wall +cStd= -std=gnu99 +cOpt= -O2 +cInclude= -I$(LosuSDK_Include) + +cFlags= $(cWarning) $(cStd) $(cOpt) $(cInclude) + +$(PkgTarget)/liblpkgtime.a:\ + $(PkgObj)/.keep\ + $(PkgObj)/time.lsh.o\ + $(PkgObj)/libtime.o\ + + ar crs $@ $^ + +$(PkgObj)/.keep: + mkdir -p $(PkgObj) + touch $@ + +$(PkgObj)/time.lsh.o: time.lsh.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ + +$(PkgObj)/libtime.o: libtime.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ \ No newline at end of file diff --git a/pkgs/time/time.lsh b/pkgs/time/time.lsh new file mode 100755 index 0000000000000000000000000000000000000000..b04b7632862d4d5a9ad9dd341c8c7e56843d5483 --- /dev/null +++ b/pkgs/time/time.lsh @@ -0,0 +1,35 @@ +module time + sub time + object time + def year(): + "@fn time.year() -> int" + "@brief 返回当前年份" + "@return y:int 当前年份" + def month(): + "@fn time.month() -> int" + "@brief 返回当前月份" + "@return m:int 当前月份" + def day(): + "@fn time.day() -> int" + "@brief 返回当前日期" + "@return d:int 当前日期" + def hour(): + "@fn time.hour() -> int" + "@brief 返回当前小时" + "@return h:int 当前小时" + def minute(): + "@fn time.minute() -> int" + "@brief 返回当前分钟" + "@return m:int 当前分钟" + def second(): + "@fn time.second() -> int" + "@brief 返回当前秒数" + "@return s:int 当前秒数" + def date( fmt:str{'en','cn'} = null ): + "@fn time.date() -> int/str" + "@brief 返回当前日期(周几)" + "@return d:int/str 当前日期,如果 fmt 为 'en' 返回英文,'cn' 返回中文,为空返回数字" + def time(): + "@fn time.time() -> int" + "@brief 返回当前时间戳" + "@return t:int 当前时间戳" \ No newline at end of file diff --git a/pkgs/time/time.lsh.c b/pkgs/time/time.lsh.c new file mode 100755 index 0000000000000000000000000000000000000000..da9d51cf6347bb2aaff3acf49638bf8a093f04f9 --- /dev/null +++ b/pkgs/time/time.lsh.c @@ -0,0 +1,132 @@ + +/* + This file was generated by losuh - Losu Header Generator, which is part of + the Losu SDK. + + Losu is an open source programming language from China with excellent + performance (comparable to lua), ultra-lightweight resource footprint (only + 4KB RAM) and easy-to-learn syntax (similar to Python) for IoT development. + + This file follows the following MIT LICENSE by default + ------------------------------------ + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + +*/ + +#include "time.lsh.h" +static int32_t __losuh__submod_time_time(LosuVm *vm); +static LosuObj __losuh__obj_time_time_time(LosuVm *vm); + + +static LosuModule __losuh__MODULELIST[] = { +{"time",__losuh__submod_time_time}, +{NULL,NULL}, +}; +LosuModule *__losuh__LOADMODULE_time() { +return &__losuh__MODULELIST[0]; +} + + +static int32_t __losuh__submod_time_time(LosuVm *vm) { +// constructors of number in time + +// constructors of string in time + +// constructors of function in time + +// constructors of script in time + +// constructors of object in time + +__losuhAPI_regObject(vm,"time",__losuh__obj_time_time_time(vm)); + +// constructors of class in time + + +return 0; +} + + +static LosuObj __losuh__obj_time_time_time(LosuVm *vm){ +LosuObj newObj = obj_newunit(vm); +// constructor of number in time@time_time + +// constructor of string in time@time_time + +// constructor of object in time@time_time + +// constructor of class in time@time_time + +// constructor of function in time@time_time +/** +* @fn time.year() -> int +* @brief 返回当前年份 +* @return y:int 当前年份 +*/ +__losuhAPI_regObjFunc(vm,newObj,"year",__losuh__func_year_time_time_time); +/** +* @fn time.month() -> int +* @brief 返回当前月份 +* @return m:int 当前月份 +*/ +__losuhAPI_regObjFunc(vm,newObj,"month",__losuh__func_month_time_time_time); +/** +* @fn time.day() -> int +* @brief 返回当前日期 +* @return d:int 当前日期 +*/ +__losuhAPI_regObjFunc(vm,newObj,"day",__losuh__func_day_time_time_time); +/** +* @fn time.hour() -> int +* @brief 返回当前小时 +* @return h:int 当前小时 +*/ +__losuhAPI_regObjFunc(vm,newObj,"hour",__losuh__func_hour_time_time_time); +/** +* @fn time.minute() -> int +* @brief 返回当前分钟 +* @return m:int 当前分钟 +*/ +__losuhAPI_regObjFunc(vm,newObj,"minute",__losuh__func_minute_time_time_time); +/** +* @fn time.second() -> int +* @brief 返回当前秒数 +* @return s:int 当前秒数 +*/ +__losuhAPI_regObjFunc(vm,newObj,"second",__losuh__func_second_time_time_time); +/** +* @fn time.date() -> int/str +* @brief 返回当前日期(周几) +* @return d:int/str 当前日期,如果 fmt 为 'en' 返回英文,'cn' 返回中文,为空返回数字 +*/ +__losuhAPI_regObjFunc(vm,newObj,"date",__losuh__func_date_time_time_time); +/** +* @fn time.time() -> int +* @brief 返回当前时间戳 +* @return t:int 当前时间戳 +*/ +__losuhAPI_regObjFunc(vm,newObj,"time",__losuh__func_time_time_time_time); + +return newObj; +} + + + diff --git a/pkgs/time/time.lsh.h b/pkgs/time/time.lsh.h new file mode 100755 index 0000000000000000000000000000000000000000..40ad22e2fda4b0f9e511378f263788daee44414e --- /dev/null +++ b/pkgs/time/time.lsh.h @@ -0,0 +1,85 @@ + +/* + This file was generated by losuh - Losu Header Generator, which is part of + the Losu SDK. + + Losu is an open source programming language from China with excellent + performance (comparable to lua), ultra-lightweight resource footprint (only + 4KB RAM) and easy-to-learn syntax (similar to Python) for IoT development. + + This file follows the following MIT LICENSE by default + ------------------------------------ + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + +*/ + +#include "losu.h" +#include "losuh.h" +LosuModule *__losuh__LOADMODULE_time (); +/** + * @fn time.year() -> int + * @brief 返回当前年份 + * @return y:int 当前年份 + */ +int32_t __losuh__func_year_time_time_time (LosuVm *vm); +/** + * @fn time.month() -> int + * @brief 返回当前月份 + * @return m:int 当前月份 + */ +int32_t __losuh__func_month_time_time_time (LosuVm *vm); +/** + * @fn time.day() -> int + * @brief 返回当前日期 + * @return d:int 当前日期 + */ +int32_t __losuh__func_day_time_time_time (LosuVm *vm); +/** + * @fn time.hour() -> int + * @brief 返回当前小时 + * @return h:int 当前小时 + */ +int32_t __losuh__func_hour_time_time_time (LosuVm *vm); +/** + * @fn time.minute() -> int + * @brief 返回当前分钟 + * @return m:int 当前分钟 + */ +int32_t __losuh__func_minute_time_time_time (LosuVm *vm); +/** + * @fn time.second() -> int + * @brief 返回当前秒数 + * @return s:int 当前秒数 + */ +int32_t __losuh__func_second_time_time_time (LosuVm *vm); +/** + * @fn time.date() -> int/str + * @brief 返回当前日期(周几) + * @return d:int/str 当前日期,如果 fmt 为 'en' 返回英文,'cn' + * 返回中文,为空返回数字 + */ +int32_t __losuh__func_date_time_time_time (LosuVm *vm); +/** + * @fn time.time() -> int + * @brief 返回当前时间戳 + * @return t:int 当前时间戳 + */ +int32_t __losuh__func_time_time_time_time (LosuVm *vm); diff --git a/preversion b/preversion deleted file mode 160000 index 873134edec6bacb1b5fdd75a954caf0af7a3cef1..0000000000000000000000000000000000000000 --- a/preversion +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 873134edec6bacb1b5fdd75a954caf0af7a3cef1 diff --git a/random/ELS_random.c b/random/ELS_random.c deleted file mode 100755 index 732c905734c031b2fd915ffad7ed98e487b73a7f..0000000000000000000000000000000000000000 --- a/random/ELS_random.c +++ /dev/null @@ -1,100 +0,0 @@ -#include "ELS_random.h" -#include "crandom.h" - -#include - -int ELSAPI_random_randseed(els_VmObj *vm) -{ - arg_returnnum(vm, randseed()); - return 1; -} - -int ELSAPI_random_random(els_VmObj *vm) -{ - arg_returnnum(vm, random()); - return 1; -} - -int ELSAPI_random_randint(els_VmObj *vm) -{ - uint64_t start, end; - start = arg_getnum(vm, 2); - end = arg_getnum(vm, 3); - arg_returnnum(vm, randint(start, end)); - return 1; -} - -int ELSAPI_random_randfloat(els_VmObj *vm) -{ - double start, end; - start = arg_getnum(vm, 2); - end = arg_getnum(vm, 3); - arg_returnnum(vm, randfloat(start, end)); - return 1; -} - -int ELSAPI_random_normal(els_VmObj *vm) -{ - double nu, sigma; - nu = arg_getnum(vm, 2); - sigma = arg_getnum(vm, 3); - arg_returnnum(vm, normal(nu, sigma)); - return 1; -} - -int ELSAPI_random_srand(els_VmObj *vm) -{ - uint64_t seed = arg_getnum(vm, 2); - lc_srand(seed); - return 1; -} - -int ELSAPI_random_randstr(els_VmObj *vm) -{ - size_t len = arg_getnum(vm, 2); - char *result = malloc(len + 1); - randstr(result, len); - result[len + 1] = '\0'; - arg_returnstr(vm, result); - free(result); - return 1; -} - -int ELSAPI_random_randbytes(els_VmObj *vm) -{ - size_t len = arg_getnum(vm, 2); - uint8_t *result = malloc(len + 1); - randbytes(result, len); - result[len + 1] = '\0'; - arg_returnstr(vm, (void*)result); - free(result); - return 1; -} - -int ELSAPI_random_percent(els_VmObj *vm) -{ - double rate = arg_getnum(vm, 2); - if (percent(rate)) - arg_returnnum(vm, 1); - else - arg_returnnull(vm); - return 1; -} - -int ELSAPI_random_random_init(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); - return 0; -} diff --git a/random/ELS_random.h b/random/ELS_random.h deleted file mode 100755 index 96e082e48afac7022babc1c36e395763276cb2bc..0000000000000000000000000000000000000000 --- a/random/ELS_random.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef ELS_RANOM_H_ -#define ELS_RANOM_H_ - -#include "els.h" -#include "crandom.h" -#include "lc.h" - -#include - -int ELSAPI_random_randseed(els_VmObj *vm); -int ELSAPI_random_random(els_VmObj *vm); -int ELSAPI_random_randint(els_VmObj *vm); -int ELSAPI_random_randfloat(els_VmObj *vm); -int ELSAPI_random_normal(els_VmObj *vm); -int ELSAPI_random_srand(els_VmObj *vm); -int ELSAPI_random_randstr(els_VmObj *vm); -int ELSAPI_random_randbytes(els_VmObj *vm); -int ELSAPI_random_percent(els_VmObj *vm); - -#endif \ No newline at end of file diff --git a/random/Ubuntu/makefile b/random/Ubuntu/makefile deleted file mode 100755 index 253dd6aa3aa7f56e30aca013ded19f84358e2e26..0000000000000000000000000000000000000000 --- a/random/Ubuntu/makefile +++ /dev/null @@ -1,13 +0,0 @@ -OBJS = random.o randtext.o lc.o mt.o crandom.o ELS_random.o -CFLAGS= -O3 -std=c99 -Wall -DLOSU_LINUX -I ../buildenv -fPIC -CC=x86_64-linux-gnu-gcc -T=./ElsLib_random.lsd - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -shared -lm -s -lstdc++ - -clean: - rm -rf $T $(OBJS) core core.* \ No newline at end of file diff --git a/random/Windows/makefile b/random/Windows/makefile deleted file mode 100755 index b6803bb78b9634ba390017f8ec93642cc17c638a..0000000000000000000000000000000000000000 --- a/random/Windows/makefile +++ /dev/null @@ -1,12 +0,0 @@ -OBJS = random.o crandom.o lc.o mt.o randtext.o ELS_random.o -CFLAGS= -O3 -std=c99 -Wall -DLOSU_WINDOWS -I ../buildenv -fPIC -CC=x86_64-w64-mingw32-gcc -T=ElsLib_random.lsd - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -L ../buildenv -l:libeasylosu.dll -lm -static -shared -s - -clean: - rm -rf $T $(OBJS) core core.* \ No newline at end of file diff --git a/random/crandom.c b/random/crandom.c deleted file mode 100755 index 21b8c17b2ac717479b65275aa1186d9d55cd3578..0000000000000000000000000000000000000000 --- a/random/crandom.c +++ /dev/null @@ -1,53 +0,0 @@ -#include "lc.h" -#include "mt.h" -#include "crandom.h" - -#include -#include -#include -#include - -#define PI 3.141592653589793 -#define E 2.718281828459045 - -uint64_t randseed() -{ - return time(NULL); -} - -uint64_t _randint(uint64_t seed, uint64_t start, uint64_t end) -{ - return (_random(seed) * (end - start)) + start; -} - -double _randfloat(uint64_t seed, double start, double end) -{ - return (_random(seed) * ((double)end - (double)start)) + start; -} - -double _normal(uint64_t seed, double mu, double sigma) -{ - double output = cos(2*PI*_random(seed)); - output *= sqrt(-2*log(_random(_rand48(seed)))); - return output * sigma + mu; -} - -uint64_t randint(uint64_t start, uint64_t end) -{ - return _randint(rand48(), start, end); -} - -double randfloat(double start, double end) -{ - return _randfloat(rand48(), start, end); -} - -double normal(double mu, double sigma) -{ - return _normal(rand48(), mu, sigma); -} - -bool percent(double rate) -{ - return randint(0, 10000000000) < rate * 10000000000 ? true : false; -} diff --git a/random/crandom.h b/random/crandom.h deleted file mode 100755 index d0d2fc64f6c7938b6bd70d0fe553e320797d01f1..0000000000000000000000000000000000000000 --- a/random/crandom.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef RANDOM_H_ -#define RANDOM_H_ - -/* -随机数模块 -作者:Matriller -创建时间:2023-9-28 -维护者:暂无 -*/ - -#include "lc.h" //线性同余 -#include "mt.h" //梅森旋转 -#include "randtext.h" //随机文本和字节 - -#include -#include - -/* - 返回8字节的随机种子 -*/ -uint64_t randseed(); - -/* - 底层randint - seed是随机种子,一般是由rand48或_rand48生成 -*/ -uint64_t _randint(uint64_t seed, uint64_t start, uint64_t end); - -/* - 底层randfloat -*/ -double _randfloat(uint64_t seed, double start, double end); - -/* - 底层normal -*/ -double _normal(uint64_t seed, double mu, double sigma); - -/* - 生成[start, end)的随机整数 -*/ -uint64_t randint(uint64_t start, uint64_t end); - -/* - 生成[start, end)的随机实数 -*/ -double randfloat(double start, double end); - -/* - 生成方差为sigma,数学期望为mu的生态分布随机数 -*/ -double normal(double mu, double sigma); - -/* - 以rate的几率返回true -*/ -bool percent(double rate); - -#endif diff --git a/random/info b/random/info deleted file mode 100755 index 37bd46d1eabbc275d0b25e7a396a02f67ff4b3c2..0000000000000000000000000000000000000000 --- a/random/info +++ /dev/null @@ -1,32 +0,0 @@ -{ - type = "pre", - info = { - name = "random/随机数模块", - text = "随机数模块", - version = "24.2.9" - }, - source = { - all = { - "crandom.c", - "crandom.h", - "ELS_random.c", - "ELS_random.h", - "lc.c", - "lc.h", - "mt.c", - "mt.h", - "random.c", - "random.els", - "random.h", - "randtext.c", - "randtext.h", - "readme.md" - }, - Ubuntu = {"makefile"}, - Windows = {"makefile"} - }, - target = { - 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", - } -} diff --git a/random/lc.c b/random/lc.c deleted file mode 100755 index 5745b2aa2acfad801baf0d3b89351f990201a0af..0000000000000000000000000000000000000000 --- a/random/lc.c +++ /dev/null @@ -1,39 +0,0 @@ -#include "lc.h" - -#define MUT 134775813 -#define ADD 1 -#define MOD 4294967296 -#define RAND_MAX_ MOD - -uint64_t lcseed = 33; - -inline uint64_t _rand48(uint64_t seed) -{ - /* - 线性同余算法 - 符合均匀分布 - 模数取2^48 - */ - return ((seed * MUT + ADD) % MOD); -} - - -inline double _random(uint64_t seed) -{ - return (double)_rand48(seed) / (double)RAND_MAX_; -} - -void lc_srand(uint64_t seed) -{ - lcseed = seed; -} - -inline uint64_t rand48() -{ - return (lcseed = _rand48(lcseed)); -} - -inline double random() -{ - return _random(rand48()); -} diff --git a/random/lc.h b/random/lc.h deleted file mode 100755 index 36e102ba3406da7f008bf460e7f3815f8b57cfd1..0000000000000000000000000000000000000000 --- a/random/lc.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef LC_H_ -#define LC_H_ - -#include -#include -/* - 底层的rand接口 -*/ -uint64_t _rand48(uint64_t seed); -double _random(uint64_t seed); -void lc_srand(uint64_t seed); -uint64_t rand48(); -double random(); - -#endif \ No newline at end of file diff --git a/random/mt.c b/random/mt.c deleted file mode 100755 index 6fc43ffbbeb37584c9d2ad8afabf9ccacab76268..0000000000000000000000000000000000000000 --- a/random/mt.c +++ /dev/null @@ -1 +0,0 @@ -#include "mt.h" \ No newline at end of file diff --git a/random/mt.h b/random/mt.h deleted file mode 100755 index 498374affef2286b7f00d8dcdd8fbbb3b05c1305..0000000000000000000000000000000000000000 --- a/random/mt.h +++ /dev/null @@ -1,3 +0,0 @@ -#ifndef MT_H_ -#define MT_H_ -#endif \ No newline at end of file diff --git a/random/random.c b/random/random.c deleted file mode 100644 index 703e4874d23efa710d8ec5cea44f8570e6b28e83..0000000000000000000000000000000000000000 --- a/random/random.c +++ /dev/null @@ -1 +0,0 @@ -#include "random.h" \ No newline at end of file diff --git a/random/random.els b/random/random.els deleted file mode 100755 index f5ab186ff80f63c88ecde274970dce951e2a6661..0000000000000000000000000000000000000000 --- a/random/random.els +++ /dev/null @@ -1,24 +0,0 @@ -#!declare - -random_init() - -#!end - -#!script -import "stdlib" - -random_init() -random.srand(time.clock()) - -随机 = {} - -随机.获取随机种子 = random.randseed -随机.改种子 = random.srand -随机.随机数 = random.random -随机.随机整数 = random.randint -随机.随机实数 = random.randfloat -随机.随机字符串 = random.randstr -随机.随机字节 = random.randbytes -随机.百分之 = random.percent - -#!end \ No newline at end of file diff --git a/random/random.h b/random/random.h deleted file mode 100644 index 40558192b54d543e69877f41a51bca0d2f1cb128..0000000000000000000000000000000000000000 --- a/random/random.h +++ /dev/null @@ -1,28 +0,0 @@ -#include "els.h" -int ELSAPI_random_random_init(els_VmObj* vm); // random_init() -#ifdef ELS_CONF_TOKEN_EN -static const char LibScript[]={ -105,109,112,111,114,116,32,34,115,116,100,108,105,98,34,10, -10, -114,97,110,100,111,109,95,105,110,105,116,40,41,10, -114,97,110,100,111,109,46,115,114,97,110,100,40,116,105,109,101,46,99,108,111,99,107,40,41,41,10, -10, --23,-102,-113,-26,-100,-70,32,61,32,123,125,10, -10, --23,-102,-113,-26,-100,-70,46,-24,-114,-73,-27,-113,-106,-23,-102,-113,-26,-100,-70,-25,-89,-115,-27,-83,-112,32,61,32,114,97,110,100,111,109,46,114,97,110,100,115,101,101,100,10, --23,-102,-113,-26,-100,-70,46,-26,-108,-71,-25,-89,-115,-27,-83,-112,32,61,32,114,97,110,100,111,109,46,115,114,97,110,100,10, --23,-102,-113,-26,-100,-70,46,-23,-102,-113,-26,-100,-70,-26,-107,-80,32,61,32,114,97,110,100,111,109,46,114,97,110,100,111,109,10, --23,-102,-113,-26,-100,-70,46,-23,-102,-113,-26,-100,-70,-26,-107,-76,-26,-107,-80,32,61,32,114,97,110,100,111,109,46,114,97,110,100,105,110,116,10, --23,-102,-113,-26,-100,-70,46,-23,-102,-113,-26,-100,-70,-27,-82,-98,-26,-107,-80,32,61,32,114,97,110,100,111,109,46,114,97,110,100,102,108,111,97,116,10, --23,-102,-113,-26,-100,-70,46,-23,-102,-113,-26,-100,-70,-27,-83,-105,-25,-84,-90,-28,-72,-78,32,61,32,114,97,110,100,111,109,46,114,97,110,100,115,116,114,10, --23,-102,-113,-26,-100,-70,46,-23,-102,-113,-26,-100,-70,-27,-83,-105,-24,-118,-126,32,61,32,114,97,110,100,111,109,46,114,97,110,100,98,121,116,101,115,10, --23,-102,-113,-26,-100,-70,46,-25,-103,-66,-27,-120,-122,-28,-71,-117,32,61,32,114,97,110,100,111,109,46,112,101,114,99,101,110,116,10, -10, -0}; -#endif -void ElsLib_random_libinit(els_VmObj *vm){ - vm_register(vm,"random_init",ELSAPI_random_random_init); - #ifdef ELS_CONF_TOKEN_EN - vm_dostring(vm,LibScript); - #endif -}; diff --git a/random/randtext.c b/random/randtext.c deleted file mode 100755 index bc7b48b2719dcfa8ecf1d46b39acb5904056239e..0000000000000000000000000000000000000000 --- a/random/randtext.c +++ /dev/null @@ -1,16 +0,0 @@ -#include "randtext.h" -#include "crandom.h" - -extern uint64_t randint(uint64_t, uint64_t); - -void randstr(char *result, size_t len) -{ - for (size_t i = 0; i < len; i++) - result[i] = LOSU_RANDOM_RANDSTR_DEFAULT_STRING[randint(0, 95)]; -} - -void randbytes(uint8_t *result, size_t len) -{ - for (size_t i = 0; i < len; i++) - result[i] = rand48() % 0xFF; -} diff --git a/random/randtext.h b/random/randtext.h deleted file mode 100755 index 5025034b4a23061bef0c411ed237996c812b71b8..0000000000000000000000000000000000000000 --- a/random/randtext.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef RANDOMTEXT_H_ -#define RANDOMTEXT_H_ - -#include "lc.h" - -#define LOSU_RANDOM_RANDSTR_DEFAULT_STRING "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" -#define LOSU_RANDOM_RANDSTR_DEFAULT_STRING_LENGTH 95 - -void randstr(char *result, size_t len); -void randbytes(uint8_t *result, size_t len); - -#endif \ No newline at end of file diff --git a/random/readme.md b/random/readme.md deleted file mode 100755 index 8379cd2d37073b461e21c276187d2268a2277db9..0000000000000000000000000000000000000000 --- a/random/readme.md +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/owls.wiki.losu.tech -# random脚本层维基 - -random是一个高性能的随机数模块。整个模块分为脚本层、C层和文档三部分。每个部分都是相对独立的整体。 - -若要移植C层到其他模块,请参阅C.md。如果需要获取历史更改信息,请参阅WIKI目录下的“历史”目录。 - -下面介绍脚本层函数。 - -## random.randseed() -返回一个随机种子 -+ 中文名:随机.获取随机种子 -+ 返回值:C层uint64_t类型的一个随机种子 - -## random.srand(seed) -将修改储存在动态库中的种子 -+ 中文名:随机.改种子 -+ 参数 seed:要使用的随机种子 - -## random.random() -+ 中文名:随机.随机数 -+ 返回值:返回介于[0, 1)的实数 - -## random.randint(start, end) -+ 中文名:随机.随机整数 -+ 参数 start: 随机区间的开始 -+ 参数 end: 随机区间的结束 -+ 返回值:返回位于[start, end)的随机整数 - -## random.randfloat(start, end) -+ 中文名:随机.随机实数 -+ 参数 start: 随机区间的开始 -+ 参数 end: 随机区间的结束 -+ 返回值:返回位于[start, end)的随机实数 - -## random.randstr(len) -生成指定长度的英文字符串 -+ 中文名:随机.随机字符串 -+ 参数 len:要生成的字符串的长度 -+ 返回值:生成的字符串 - -## random.randbytes(len) -生成指定长度的随机字节 -注意,目前以字符串形式返回 -+ 中文名:随机.随机字节 -+ 参数 len:要生成的字节数 -+ 返回值:生成的字节 - -## random.percent(rate) -以指定概率返回真值 -+ 中文名:随机.百分之 -+ 参数 rate:指定的概率 -+ 返回值:当为真时,返回1,否则返回null \ No newline at end of file diff --git a/re/Ubuntu/makefile b/re/Ubuntu/makefile deleted file mode 100644 index 4acf5cf1c43b3f57c8997c0d76c58fb6c6263800..0000000000000000000000000000000000000000 --- a/re/Ubuntu/makefile +++ /dev/null @@ -1,10 +0,0 @@ -CFLAGS = -O2 -std=c99 -DELS_CONF_OS_LINUX -I ../buildenv -L ../buildenv -fPIC -s -l:libeasylosu.so -CPPFLAGS = -O2 -std=c++11 -DELS_CONF_OS_LINUX -I ../buildenv -L ../buildenv -l:libeasylosu.so - -re: - gcc cre.c -c $(CFLAGS) - g++ re.cpp -c $(CPPFLAGS) - gcc -o ElsLib_re.lsd *.o -shared $(CFLAGS) -lstdc++ - -clean: - rm ./*.o diff --git a/re/Windows/makefile b/re/Windows/makefile deleted file mode 100644 index b89d02c5a9f22761f8dcfa7d6ad1bdb87179bae6..0000000000000000000000000000000000000000 --- a/re/Windows/makefile +++ /dev/null @@ -1,10 +0,0 @@ -CFLAGS = -O2 -std=c99 -DELS_CONF_OS_WINDOWS -I ../buildenv -L ../buildenv -fPIC -s -l:libeasylosu.dll -CPPFLAGS = -O2 -std=c++11 -DELS_CONF_OS_WINDOWS -I ../buildenv -L ../buildenv -l:libeasylosu.dll - -re: - gcc cre.c -c $(CFLAGS) - g++ re.cpp -c $(CPPFLAGS) - gcc -o ElsLib_re.lsd *.o -shared $(CFLAGS) -lstdc++ - -clean: - rm ./*.o diff --git a/re/cre.c b/re/cre.c deleted file mode 100644 index 500510d597813a0315c2c6882240658c52568113..0000000000000000000000000000000000000000 --- a/re/cre.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "cre.h" -#include "re.h" - -int ELSAPI_re_re_match(els_VmObj *vm) -{ - const char *target = arg_getstr(vm, unit_arg(1)); - const char *p = arg_getstr(vm, unit_arg(2)); - int output = re_match(target, p); - if (output == 1) - arg_returntrue(vm); - else - arg_returnfalse(vm); - return 1; -} - -int ELSAPI_re_re_search(els_VmObj *vm) -{ - const char *target = arg_getstr(vm, unit_arg(1)); - const char *p = arg_getstr(vm, unit_arg(2)); - arg_return(vm, re_search(target, p, vm)); - return 1; -} - -int ELSAPI_re_re_replace(els_VmObj *vm) -{ - const char *target = arg_getstr(vm, unit_arg(1)); - const char *p = arg_getstr(vm, unit_arg(2)); - const char *r = arg_getstr(vm, unit_arg(3)); - LsString output = re_replace(target, p, r, vm); - arg_return(vm, output); - return 1; -} diff --git a/re/cre.h b/re/cre.h deleted file mode 100644 index d36572c3f7c4d75759cb8875500673aa7d014279..0000000000000000000000000000000000000000 --- a/re/cre.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef __XKIT_RE_H__ -#define __XKIT_RE_H__ - -#include "cxkit.h" - -XKIT_API int re_match(const char *targert, const char *p); -XKIT_API LsUnit re_search(const char *targert, const char *p, els_VmObj *vm); -XKIT_API LsString re_replace(const char *targert, const char *p, const char *replace_string, els_VmObj *vm); - -#endif \ No newline at end of file diff --git a/re/cxkit.h b/re/cxkit.h deleted file mode 100644 index c25334eba91c98a440ab2ffdf9e127c4a7c9753a..0000000000000000000000000000000000000000 --- a/re/cxkit.h +++ /dev/null @@ -1,71 +0,0 @@ -#ifndef __xkit_cxkit_h__ -#define __xkit_cxkit_h__ - -#include -#include - -//包含els.h -#ifdef __cplusplus -extern "C" { - #include "els.h" -} -#else -#include "els.h" -#endif - -//用于unit内函数的处理宏 -#define unit_arg(x) x+1 -#define unit_argtype(vm, x) arg_gettype(vm, x+1) -#define unit_argisnum(vm, x) arg_gettype(vm, x+1) == ELS_API_TYPE_NUMBER -#define unit_argisstr(vm, x) arg_gettype(vm, x+1) == ELS_API_TYPE_STRING -#define unit_argisunit(vm, x) arg_gettype(vm, x+1) == ELS_API_TYPE_UNIT -#define unit_argisptr(vm, x) arg_gettype(vm, x+1) == ELS_API_TYPE_ptr -#define unit_argisbyte(vm, x) arg_gettype(vm, x+1) == ELS_API_TYPE_byte -#define unit_argisfunc(vm, x) arg_gettype(vm, x+1) == ELS_API_TYPE_function - -//unit操作宏 -#define unit_getval(vm, u, s) obj_indexunitbystr(vm, u, (char*)s) -#define unit_addfunc(vm, u, s, f) obj_setunitbystr(vm, u, s, obj_newfunction(vm, (els_C_API_function)f)) - -//API接口标识 -#ifdef __cplusplus -#define XKIT_API extern "C" -#else -#define XKIT_API extern -#endif - -//LosuObj的别称 -typedef LosuObj LsUnit; -typedef LosuObj LsNumber; -typedef LosuObj LsString; -typedef LosuObj LsByte; -typedef LosuObj LsPoiter; -typedef LosuObj LsFunction; - -//返回值的bool处理 -#define arg_returntrue(vm) arg_return(vm, obj_newnum(vm, 1)) -#define arg_returnfalse(vm) arg_returnnull(vm) - -//关于gbk和utf8编码的输入输出宏 -#ifdef _WIN32 -#define outstr(vm, x) (char*)obj_toGBK(vm, (char*)x) -#define instr(vm, x) (char*)obj_toUTF8(vm, (char*)x) -#endif -#ifdef __linux__ -#define outstr(vm, x) (char*)x -#define instr(vm, x) (char*)x -#endif - -//操作系统宏开关 -#ifdef __linux__ -#ifndef ELS_CONF_OS_LINUX -#define ELS_CONF_OS_LINUX -#endif -#endif -#ifdef _WIN32 -#ifndef ELS_CONF_OS_WINDOWS -#define ELS_CONF_OS_WINDOWS -#endif -#endif - -#endif diff --git a/re/info b/re/info deleted file mode 100644 index 7d31bd25c845d73ab3311270fdb4edbec12564e4..0000000000000000000000000000000000000000 --- a/re/info +++ /dev/null @@ -1,28 +0,0 @@ -{ - type = "pre", - info = { - name = "re", - text = "正则表达式模块", - version = "24.3.10" - }, - source = { - all = { - "cre.c", - "cre.h", - "cxkit.h", - "re.cpp", - "re.els", - "re.h", - }, - Ubuntu = { - "makefile" - }, - Windows = { - "makefile" - } - }, - target = { - Ubuntu = "make ; cp ElsLib_re.lsd target/ElsLib_re.lsd_Ubuntu ; make clean", - Windows = "make ; cp ElsLib_re.lsd target/ElsLib_re.lsd_Windows ; make clean", - } -} diff --git a/re/re.cpp b/re/re.cpp deleted file mode 100644 index 44a4ddbe4727cd54b7eb263847919424dc9cf48f..0000000000000000000000000000000000000000 --- a/re/re.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include -#include - -#include "cre.h" - -using namespace std; -using namespace __cxx11; - -XKIT_API int re_match(const char *targert, const char *p) -{ - smatch results; - string _t = targert; - string _p = p; - return regex_match(_t, results, regex(_p)); -} - -XKIT_API LsUnit re_search(const char *targert, const char *p, els_VmObj *vm) -{ - smatch results; - string _t = targert; - regex pattern(p); - LsUnit output = obj_newunit(vm); - string::const_iterator iter = _t.begin(); - string::const_iterator iterEnd = _t.end(); - - for (uint64_t i = 0; regex_search(iter, iterEnd, results, pattern);) - { - string tmp = results[0]; - i ++; - obj_setunitbynum(vm, output, i, obj_newstr(vm, (char*)tmp.c_str())); - iter = results[0].second; - } - - return output; -} - -XKIT_API LsString re_replace(const char *targert, const char *p, const char *replace_string, els_VmObj *vm) -{ - smatch results; - string _t = targert; - string _p = p; - string _r = replace_string; - string output = regex_replace(_t, regex(_p), _r); - return obj_newstr(vm, (char*)output.c_str()); -} diff --git a/re/re.els b/re/re.els deleted file mode 100644 index ed1cbe24fa7a7a2b841356b399b046e2f960001b..0000000000000000000000000000000000000000 --- a/re/re.els +++ /dev/null @@ -1,15 +0,0 @@ -#!declare -re_match() -re_search() -re_replace() -#!end - -#!script - -var re = { - match = re_match, - search = re_search, - replace = re_replace -} - -#!end \ No newline at end of file diff --git a/re/re.h b/re/re.h deleted file mode 100644 index 34ebdc8aecdebc2bccb275478d31993fcfa64d62..0000000000000000000000000000000000000000 --- a/re/re.h +++ /dev/null @@ -1,23 +0,0 @@ -#include "els.h" -int ELSAPI_re_re_match(els_VmObj* vm); // re_match() -int ELSAPI_re_re_search(els_VmObj* vm); // re_search() -int ELSAPI_re_re_replace(els_VmObj* vm); // re_replace() -#ifdef ELS_CONF_TOKEN_EN -static const char LibScript[]={ -10, -118,97,114,32,114,101,32,61,32,123,10, -32,32,32,32,109,97,116,99,104,32,61,32,114,101,95,109,97,116,99,104,44,10, -32,32,32,32,115,101,97,114,99,104,32,61,32,114,101,95,115,101,97,114,99,104,44,10, -32,32,32,32,114,101,112,108,97,99,101,32,61,32,114,101,95,114,101,112,108,97,99,101,10, -125,10, -10, -0}; -#endif -void ElsLib_re_libinit(els_VmObj *vm){ - vm_register(vm,"re_match",ELSAPI_re_re_match); - vm_register(vm,"re_search",ELSAPI_re_re_search); - vm_register(vm,"re_replace",ELSAPI_re_re_replace); - #ifdef ELS_CONF_TOKEN_EN - vm_dostring(vm,LibScript); - #endif -}; diff --git a/re/readme.md b/re/readme.md deleted file mode 100644 index c181fec81e2e1a8db1b53ea32a3b37f3cadfce24..0000000000000000000000000000000000000000 --- a/re/readme.md +++ /dev/null @@ -1,24 +0,0 @@ -# re中文文档 - -re是一个正则表达式模块。该模块基于C++的regex模块。 - -# 例程 - -```lua -var s = "aabbccaa" -var res = re.replace(s, "aa", "yyy") -print(res) -``` - -# 函数 - -## re.match(s:str, pattern:str) -检查字符串s是否符合pattern指定的模式。是则返回1,否则返回null。 - -## re.search(s:str, pattern:str) -搜索字符串s中所有符合pattern的子字符串,并储存在一个unit中返回。 - -返回值的索引从1开始,如果没有找到任何子字符串,则返回空unit。 - -## re.repalce(a:str, pattern:str, b:str) -将字符串a中所有符合pattern的子字符串都替换为b。返回替换后的字符串。 diff --git a/readme.md b/readme.md deleted file mode 100755 index 762bb052b429fd585c0431a70ed6b2d0d64940c6..0000000000000000000000000000000000000000 --- a/readme.md +++ /dev/null @@ -1,73 +0,0 @@ -#!/bin/owls.wiki.losu.tech - -# 洛 书 · L O S U -## 嵌入式中文脚本语言 -## 开源 · 高效 · 强大 - - -star -fork - - - -# 简介 -+ [官网](https://losu.tech) -+ [在线运行](https://losu.tech/playground)—— 在线体验 · 免安装 · 免配置 · 点开即玩 - -洛书(Losu) 编程语言,全称 Language Of Systemd Units ,超轻量、跨平台、易扩展、支持中文代码、拥有中文文档和视频资料,致力于打造一门开源、高效、强大的编程语言。 - -![架构图](.img/framework.png) - -+ 洛书是一款: - + __图灵完备__ 的编程语言,支持面向过程、面向对象与部分元编程的特性 - + __全平台可用__,支持Windows、Linux、RTOS等多种操作系统,解释器可以由 __任何__ 遵循 __c99__ 标准的编译器编译通过并运行于任何拥有 __libc__ 的平台之上 - + __高性能__、__低开销__、__零依赖__,可以在低资源设备上运行 __完整__ 的内核,具备裸机运行能力。 - -# 快速开始? -+ 我们为您编译了常见平台的安装包,包括 Windows、Linux、Rt-thread等操作系统,x86、Arm、RISC-V、C-SKY、龙芯等CPU -+ 您可以访问洛书的 [官网](https://losu.tech) 以获取最新的二进制包,同时您可以参考 [文档中心](https://losu.tech/wiki/readme.md)中的 -文档进行上手 -+ 通过 [洛书在线运行平台](https://losu.tech/playground),您可以不进行本地安装的情况下,对洛书进行体验。 - - - - -# 最新资讯 -+ [洛书 2023 项目总结](https://mp.weixin.qq.com/s?__biz=MzkwNDY1ODk1NA==&mid=2247483665&idx=1&sn=0086aeae935a868a23e386d773a13479&chksm=c082e874f7f561623bd36018027103835a61a5b5946a3e500f9e834796934adfef78c658a9db&mpshare=1&scene=23&srcid=030100VSb6GExKmqxRwfed6u&sharer_shareinfo=3ebad755459b9dfe3cbeded9c667be35&sharer_shareinfo_first=3ebad755459b9dfe3cbeded9c667be35#rd) -+ [更稳定、更便捷、更 AI 的编程语言 — 洛书 24.1.4 阶段版本发布](https://www.oschina.net/news/278754/luoshu-24-1-4-released) -+ [聚沙成塔:洛书开源一周年版本 v1.6.8-alpha发布](https://www.oschina.net/news/252430) -+ [洛书 1.6.5 发布——十余项重要更新,第一个生产级标志性版本](https://www.oschina.net/news/245204) -+ [洛书 1.6.4 发布——全新SDK开发模式,统一的跨平台开发支持](https://gitee.com/chen-chaochen/lpk/releases/tag/v1.6.4) - - -# 文档手册 - -+ 我们为您准备了周期性的,随版本更新的文档 -+ 前往[文档中心](https://losu.tech/wiki/readme.md) - -# 贡献、交流与技术支持 -## 贡献您的代码 -+ 我们真诚地感谢您的每一份贡献,您可以参考[贡献文档](https://losu.tech/wiki/readme.md#contribute)中的流程参与代码贡献 -+ 您可以贡献 demo,package,kernel,也可以帮助我们纠正完善文档 -+ 您的贡献在通过审核后,将被合并入项目仓库。 -## 不是只有代码才能参与贡献 -+ 您可以在你的工作、个人项目、比赛中使用我们的产品 -+ 您可以协助我们对作品进行宣传推广 -+ 您可以给我们点个star -+ 请作者喝[生椰拿铁](https://afdian.net/a/cthreechen) -+ 体验、反馈、支持我们的产品 - -## 交流与支持 -+ 通过创建 [issue](https://gitee.com/chen-chaochen/lpk/issues/new/) 向我们反馈,等待开发者的回复 -+ 通过[邮箱](mailto:cthree2004@163.com)联系开发者 -+ 加入官方QQ群,一起讨论,反馈,吹水,获得保姆级服务 - -![](.img/Q.jpg) - - - - -# 感谢所有帮助过我们的热心人 diff --git a/rule/keep.mk b/rule/keep.mk new file mode 100755 index 0000000000000000000000000000000000000000..a60002cfcea42f52f3c30578bb1034add57b56a9 --- /dev/null +++ b/rule/keep.mk @@ -0,0 +1,38 @@ +$(LosuSDK_Build)/.keep: + mkdir -p $(LosuSDK_Build) + touch $@ + +$(LosuSDK_Path)/.keep: + mkdir -p $(LosuSDK_Path) + touch $@ + +$(LosuSDK_Lib)/.keep: + mkdir -p $(LosuSDK_Lib) + touch $@ + +$(LosuSDK_Obj)/.keep: + mkdir -p $(LosuSDK_Obj) + touch $@ + +$(LosuSDK_Build)/target/.keep: $(LosuSDK_Build)/.keep + mkdir -p $(LosuSDK_Build)/target + touch $@ + +$(LosuSDK_Build)/target/pkgs/.keep: $(LosuSDK_Build)/target/.keep + mkdir -p $(LosuSDK_Build)/target/pkgs + touch $@ + +$(LosuSDK_Obj)/sdk/losuh/.keep: $(LosuSDK_Obj)/.keep + mkdir -p $(LosuSDK_Obj)/sdk/losuh + touch $@ + +$(LosuSDK_Obj)/sdk/losuc/.keep: $(LosuSDK_Obj)/.keep + mkdir -p $(LosuSDK_Obj)/sdk/losuc + touch $@ +$(LosuSDK_Obj)/sdk/lpkg/.keep: $(LosuSDK_Obj)/.keep + mkdir -p $(LosuSDK_Obj)/sdk/lpkg + touch $@ + +$(LosuSDK_Obj)/sdk/liblosu/.keep: $(LosuSDK_Obj)/.keep + mkdir -p $(LosuSDK_Obj)/sdk/liblosu + touch $@ \ No newline at end of file diff --git a/rule/liblosu.mk b/rule/liblosu.mk new file mode 100755 index 0000000000000000000000000000000000000000..eb294bd8f78e823cb4f890d7937ab3e5a73d91ab --- /dev/null +++ b/rule/liblosu.mk @@ -0,0 +1,7 @@ +$(LosuSDK_Lib)/liblosu.a:\ + $(LosuSDK_Lib)/.keep\ + $(LosuSDK_Obj)/sdk/liblosu/.keep\ + + @echo "---- Make losuc (PreCompiler of Losu) ----" + cd $(LosuSDK_Root)/core;make; + @echo "---- Done losuc (PreCompiler of Losu) ----" diff --git a/rule/losuc.mk b/rule/losuc.mk new file mode 100755 index 0000000000000000000000000000000000000000..bee171529eaef3980818c5b6963512648c6a8453 --- /dev/null +++ b/rule/losuc.mk @@ -0,0 +1,8 @@ +$(LosuSDK_Path)/losuc:\ + $(LosuSDK_Path)/.keep\ + $(LosuSDK_Obj)/sdk/losuc/.keep\ + $(LosuSDK_Lib)/liblosu.a\ + + @echo "---- Make losuc (PreCompiler of Losu) ----" + cd $(LosuSDK_Tool)/losuc;make; + @echo "---- Done losuc (PreCompiler of Losu) ----" diff --git a/rule/losuh.mk b/rule/losuh.mk new file mode 100755 index 0000000000000000000000000000000000000000..4a5d2efd54b96ceeed94752bf7bbfd73d9f179de --- /dev/null +++ b/rule/losuh.mk @@ -0,0 +1,7 @@ +$(LosuSDK_Path)/losuh:\ + $(LosuSDK_Path)/.keep \ + $(LosuSDK_Obj)/sdk/losuh/.keep \ + + @echo "---- Make losuh (Losu Header Generator) ----" + cd $(LosuSDK_Tool)/losuh;make; + @echo "---- Done losuh (Losu Header Generator) ----" diff --git a/rule/lpkg.mk b/rule/lpkg.mk new file mode 100755 index 0000000000000000000000000000000000000000..1f80be49a2ede8199f8e8ce38546d7c1abc133f3 --- /dev/null +++ b/rule/lpkg.mk @@ -0,0 +1,8 @@ +$(LosuSDK_Path)/lpkg:\ + $(LosuSDK_Path)/.keep\ + $(LosuSDK_Obj)/sdk/lpkg/.keep\ + $(LosuSDK_Path)/losuc\ + + @echo "-------- Building lpkg (Losu Package) --------" + cd $(LosuSDK_Tool)/lpkg;make + @echo "-------- Build success --------" diff --git a/sharedlib/Windows/makefile b/sharedlib/Windows/makefile deleted file mode 100644 index e704ae4728fa13f5a4ef62a4f3f125e2ee43d66c..0000000000000000000000000000000000000000 --- a/sharedlib/Windows/makefile +++ /dev/null @@ -1,11 +0,0 @@ -T = ElsLib_sharedlib.lsd -CFLAGS = -O2 -std=c99 -DELS_CONF_OS_WINDOWS -I ../buildenv -L ../buildenv -fPIC -s -l:libeasylosu.dll -CPPFLAGS = -O3 -std=c++11 -DELS_CONF_OS_WINDOWS -I ./include -I ../buildenv - -all: $T - -$T: - gcc sharedlib.c -o $(T) -shared $(CFLAGS) - -clean: - rm *.o diff --git a/sharedlib/info b/sharedlib/info deleted file mode 100644 index 8403d622eebd04b2a1d20c84779007732178e600..0000000000000000000000000000000000000000 --- a/sharedlib/info +++ /dev/null @@ -1,21 +0,0 @@ -{ - type = "normal", - info = { - name = "sharedlib", - text = "动态库操作模块", - version = "24.3.24" - }, - source = { - all = { - "info", - "sharedlib.c", - "sharedlib.h", - "sharedlib.els", - "readme.md", - }, - Windows ={"makefile"}, - }, - target={ - Windows = "make ; cp ElsLib_sharedlib.lsd target/ElsLib_sharedlib.lsd_Windows ; make clean", - } -} diff --git a/sharedlib/readme.md b/sharedlib/readme.md deleted file mode 100644 index 35827225d5f54fb3b296e10992b23831260397e8..0000000000000000000000000000000000000000 --- a/sharedlib/readme.md +++ /dev/null @@ -1,27 +0,0 @@ -# sharedlib文档 - -## 概述 - -sharedlib是一个动态库操作模块,提供了动态库的加载、卸载和指针地址获取功能。 - -## 函数列表 - -### sharedlib.load - -sharedlib.load(...:str) -> ptr / unit - -接受str类型的参数作为动态库路径。当参数个数为1时,返回加载的动态库的指针。当参数个数大于1时,将指针装在unit中返回。 - -单个参数,当加载失败时,返回null。多个参数,当加载失败时,对应的索引,其值为null。 - -### sharedlib.unload - -sharedlib.unload(...:ptr) - -卸载对应的指针的动态库。该函数始终返回null。 - -### sharedlib.sys - -sharedlib.sys(libp:ptr, sys:str) - -在libp中查找sys标准,当查找到时,返回对应的指针,否则返回null。 diff --git a/sharedlib/sharedlib.c b/sharedlib/sharedlib.c deleted file mode 100644 index 0159c602c95eb9be45202bca6171fda446650374..0000000000000000000000000000000000000000 --- a/sharedlib/sharedlib.c +++ /dev/null @@ -1,176 +0,0 @@ -#include "els.h" -#include "sharedlib.h" - -/* - xkit的动态库操作接口 -*/ - -#include -#include -#include -#include -#include - -#ifdef __linux__ - -#include -#include - -#endif - -#ifdef _WIN32 - -#include - -#endif - -#define unit_arg(x) x+1 -#define unit_arg_gettype(vm, x) arg_gettype(vm, x+1) - -int ELSAPI_sharedlib_sharedlib_load(els_VmObj *vm) -{ - int argnum = arg_num(vm); - - if (argnum == unit_arg(0)) //当参数个数(除this指针外) == 0 - { - arg_returnnull(vm); - return 1; - } - else if (argnum == unit_arg(1)) //当参数个数(除this指针外) == 1 - { - const char *name = arg_getstr(vm, unit_arg(1)); - if (name[0] == '\0') - { - arg_returnnull(vm); - return 1; - } - #ifdef __linux__ - void *p = dlopen(name, RTLD_LAZY); - #endif - - #ifdef _WIN32 - void *p = LoadLibrary(name); - #endif - - if (p == NULL) - { - arg_returnnull(vm); - return 1; - } - - arg_returnptr(vm, p); - return 1; - } - - //当参数个数(除this指针外)>=2时会运行到这里 - LosuObj unit = obj_newunit(vm); - for (int i = 1; i <= argnum - 1; i++) - { - const char *s = arg_getstr(vm, unit_arg(i)); - - #ifdef __linux__ - void *p = dlopen(s, RTLD_LAZY); //Linux下的动态库打开方式 - #endif - - #ifdef _WIN32 - void *p = LoadLibrary(s); - #endif - - if (p != NULL) - obj_setunitbynum(vm, unit, i, obj_newptr(vm, p)); - else - obj_setunitbynum(vm, unit, i, obj_newnull(vm)); - } - arg_return(vm, unit); - - return 1; -} - -int ELSAPI_sharedlib_sharedlib_unload(els_VmObj *vm) -{ - int argnum = arg_num(vm); - - if (argnum == unit_arg(0)) //当参数个数(除this指针外) == 0 - { - arg_returnnull(vm); - return 1; - } - else if (argnum == unit_arg(1)) //当参数个数(除this指针外) == 1 - { - void *p = arg_getptr(vm, unit_arg(1)); - - if (p == NULL) - { - arg_returnnull(vm); - return 1; - } - - #ifdef __linux__ - dlclose(p); - #endif - - #ifdef _WIN32 - FreeLibrary(p); - #endif - - arg_returnnull(vm); - return 1; - } - - //当参数个数(除this指针外)>=2时会运行到这里 - for (int i = 1; i <= argnum - 1; i++) - { - void *p = arg_getptr(vm, unit_arg(i)); - - if (p == NULL) - { - continue; - } - - #ifdef __linux__ - dlclose(p); - #endif - - #ifdef _WIN32 - FreeLibrary(p); - #endif - } - - return 1; -} - -int ELSAPI_sharedlib_sharedlib_sys(els_VmObj *vm) -{ - if (unit_arg_gettype(vm, 1) == ELS_API_TYPE_PTR && unit_arg_gettype(vm, 2) == ELS_API_TYPE_STRING) - { - void *p = arg_getptr(vm, unit_arg(1)); - const char *s = arg_getstr(vm, unit_arg(2)); - - if (p == NULL || s[0] == '\0') - { - arg_returnnull(vm); - return 1; - } - - #ifdef __linux__ - void *proc = dlsym(p, s); - #endif - - #ifdef _WIN32 - void *proc = GetProcAddress(p, s); - #endif - - if (proc == NULL) - arg_returnnull(vm); - else - arg_returnptr(vm, proc); - - return 1; - } - else - { - arg_returnnull(vm); - } - - return 1; -} diff --git a/sharedlib/sharedlib.els b/sharedlib/sharedlib.els deleted file mode 100644 index 3fe2e168883ddc88e166c35839f56c8dd02e92ea..0000000000000000000000000000000000000000 --- a/sharedlib/sharedlib.els +++ /dev/null @@ -1,19 +0,0 @@ -#!declare - -sharedlib_load() -sharedlib_unload() -sharedlib_sys() - -#!end - - -#!script - -var sharedlib = { - load = sharedlib_load, - unload = sharedlib_unload, - sys = sharedlib_sys -} - -#!end - diff --git a/sharedlib/sharedlib.h b/sharedlib/sharedlib.h deleted file mode 100644 index 620a9a6f2e9517e8c4d4459cb859a92f84cb7633..0000000000000000000000000000000000000000 --- a/sharedlib/sharedlib.h +++ /dev/null @@ -1,23 +0,0 @@ -#include "els.h" -int ELSAPI_sharedlib_sharedlib_load(els_VmObj* vm); // sharedlib_load() -int ELSAPI_sharedlib_sharedlib_unload(els_VmObj* vm); // sharedlib_unload() -int ELSAPI_sharedlib_sharedlib_sys(els_VmObj* vm); // sharedlib_sys() -#ifdef ELS_CONF_TOKEN_EN -static const char LibScript[]={ -10, -118,97,114,32,115,104,97,114,101,100,108,105,98,32,61,32,123,10, -32,32,32,32,108,111,97,100,32,61,32,115,104,97,114,101,100,108,105,98,95,108,111,97,100,44,10, -32,32,32,32,117,110,108,111,97,100,32,61,32,115,104,97,114,101,100,108,105,98,95,117,110,108,111,97,100,44,10, -32,32,32,32,115,121,115,32,61,32,115,104,97,114,101,100,108,105,98,95,115,121,115,10, -125,10, -10, -0}; -#endif -void ElsLib_sharedlib_libinit(els_VmObj *vm){ - vm_register(vm,"sharedlib_unload",ELSAPI_sharedlib_sharedlib_unload); - vm_register(vm,"sharedlib_load",ELSAPI_sharedlib_sharedlib_load); - vm_register(vm,"sharedlib_sys",ELSAPI_sharedlib_sharedlib_sys); - #ifdef ELS_CONF_TOKEN_EN - vm_dostring(vm,LibScript); - #endif -}; diff --git a/socket/Ubuntu/linux_sock.c b/socket/Ubuntu/linux_sock.c deleted file mode 100755 index 8ce07747b3116c1eeda3a8e43332be4fe794369d..0000000000000000000000000000000000000000 --- a/socket/Ubuntu/linux_sock.c +++ /dev/null @@ -1,126 +0,0 @@ -#include "linux_sock.h" - -#ifdef __linux__ - -//辅助函数 -gethostbyname_t *LosuSock_gethostbyname(const char *name) -{ - return gethostbyname(name); -} - -bool LosuSock_sendtimeout(socket_t *sock, double sec) -{ - int _sec; - int usec; - usec = modf(sec, (void*)&_sec) * 1000000; - - struct timeval timeout; // - timeout.tv_sec = _sec; - timeout.tv_usec = usec; - - if (setsockopt(sock->sockfd, SOL_SOCKET, SO_SNDTIMEO, (void *)&timeout, sizeof(timeout)) == 0) - return true; - return false; -} - -bool LosuSock_recvtimeout(socket_t *sock, double sec) -{ - int _sec; - int usec; - usec = modf(sec, (void*)&_sec) * 1000000; - - struct timeval timeout; - timeout.tv_sec = _sec; - timeout.tv_usec = usec; - - if (setsockopt(sock->sockfd, SOL_SOCKET, SO_RCVTIMEO, (void *)&timeout, sizeof(timeout)) == 0) - return true; - return false; -} - - -//socket操作函数 -socket_t *LosuSock_socket(int family, int type, int protocol) -{ - socket_t *sock = malloc(sizeof(socket_t)); - sock->sockfd = socket(family, type, protocol); - sock->family = family; - sock->type = type; - sock->protocol = protocol; - sock->addr.sin_family = family; - return sock; -} - -bool LosuSock_bind(socket_t *sock, const char *ip, int port) -{ - sock->addr.sin_port = htons(port); - - if (ip==NULL) - sock->addr.sin_addr.s_addr = INADDR_ANY; - else - sock->addr.sin_addr.s_addr = inet_addr(ip); - - if (bind(sock->sockfd, (void*)&sock->addr, sizeof(sock->addr)) == 0) - return true; - return false; -}; - -bool LosuSock_listen(socket_t *sock, int amount) -{ - if (listen(sock->sockfd, amount) == 0) - return true; - return false; -} - -socket_t *LosuSock_accept(socket_t *sock) -{ - socket_t *client = malloc(sizeof(socket_t)); - int length = sizeof(client->addr); - - client->family = sock->family; - client->type = sock->type; - client->protocol = sock->protocol; - client->addr.sin_family = sock->family; - - client->sockfd = accept(sock->sockfd, (void*)&client->addr, (void*)&length); - return client; -} - -bool LosuSock_connect(socket_t *sock, const char *ip, int port) -{ - sock->addr.sin_port = htons(port); - sock->addr.sin_addr.s_addr = inet_addr(ip); - - if (connect(sock->sockfd, (struct sockaddr*)&sock->addr, sizeof(sock->addr)) == 0) - return true; - return false; -} - -bool LosuSock_send(socket_t *sock, const char *data, int length, int x) -{ - if (send(sock->sockfd, data, length, x) != -1); - return true; - return false; -} - -bool LosuSock_recv(socket_t *sock, char *buffer, int length, int x) -{ - if (recv(sock->sockfd, buffer, length, x) >= 0) - return true; - return false; -} - -bool LosuSock_close(socket_t *sock) -{ - if (close(sock->sockfd) != -1) - { - free(sock); - return true; - } - free(sock); - return false; -} - - - -#endif \ No newline at end of file diff --git a/socket/Ubuntu/linux_sock.h b/socket/Ubuntu/linux_sock.h deleted file mode 100755 index 13625686c19b0bd3b4f199c3bce136139035e793..0000000000000000000000000000000000000000 --- a/socket/Ubuntu/linux_sock.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef LOSU_LINUX_SOCK_H__ -#define LOSU_LINUX_SOCK_H__ - -#ifndef __linux__ -#warning "该文件用于Linux系统" -#endif - -#ifdef __linux__ - -#include -#include //struct timeval -#include -#include -#include -#include //gethostbyname - -#include -#include -#include -#include -#include - -typedef struct sockaddr_in sock_addr_t; - -typedef struct -{ - int sockfd; - int family; - int type; - int protocol; - sock_addr_t addr; -} socket_t; - -typedef struct hostent gethostbyname_t; - -//辅助函数 -gethostbyname_t *LosuSock_gethostbyname(const char *name); -bool LosuSock_sendtimeout(socket_t *sock, double sec); -bool LosuSock_recvtimeout(socket_t *sock, double sec); - -//socket操作函数 -socket_t *LosuSock_socket(int family, int type, int protocol); -bool LosuSock_bind(socket_t *sock, const char *ip, int port); -bool LosuSock_listen(socket_t *sock, int amount); -socket_t *LosuSock_accept(socket_t *sock); -bool LosuSock_connect(socket_t *sock, const char *ip, int port); -bool LosuSock_send(socket_t *sock, const char *data, int length, int x); -bool LosuSock_recv(socket_t *sock, char *buffer, int length, int x); -bool LosuSock_close(socket_t *sock); - -#endif - -#endif \ No newline at end of file diff --git a/socket/Ubuntu/makefile b/socket/Ubuntu/makefile deleted file mode 100755 index c692681ae5526a0eb1878550c4f75bd19b7c503d..0000000000000000000000000000000000000000 --- a/socket/Ubuntu/makefile +++ /dev/null @@ -1,13 +0,0 @@ -OBJS = socket.o linux_sock.o -CFLAGS= -O2 -std=c99 -Wall -DLOSU_LINUX -I ../buildenv -fPIC -CC=x86_64-linux-gnu-gcc -T=./ElsLib_socket.lsd - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -shared -lm -s - -clean: - rm -rf $T $(OBJS) core core.* \ No newline at end of file diff --git a/socket/Windows/.keep b/socket/Windows/.keep deleted file mode 100755 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/socket/Windows/makefile b/socket/Windows/makefile deleted file mode 100755 index 8d2d99f94847da54d9a8ce8d950bbead49b048df..0000000000000000000000000000000000000000 --- a/socket/Windows/makefile +++ /dev/null @@ -1,13 +0,0 @@ -OBJS = socket.o win_sock.o -CFLAGS= -O2 -std=c99 -Wall -DLOSU_WINDOWS -I ../buildenv -fPIC -CC=x86_64-w64-mingw32-gcc -T=ElsLib_socket.lsd - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -L ../buildenv -l:libeasylosu.dll -lws2_32 -lm -static -shared -s - -clean: - rm -rf $T $(OBJS) core core.* \ No newline at end of file diff --git a/socket/Windows/win_sock.c b/socket/Windows/win_sock.c deleted file mode 100755 index 1988387407a38feb42c73146082012940019bb20..0000000000000000000000000000000000000000 --- a/socket/Windows/win_sock.c +++ /dev/null @@ -1,162 +0,0 @@ -#include "win_sock.h" - -#ifdef _WIN32 - -int WinSockInited = 0; //保存初始化信息,已初始化则为1,否则为0 - -//辅助函数 -bool LosuSock_init() -{ - /* - winsock库需要特殊的初始化 - */ - WORD sockVersion = MAKEWORD(2, 2); - WSADATA wsdata; - - if (WSAStartup(sockVersion, &wsdata) == 0) - return true; - return false; -} - -gethostbyname_t *LosuSock_gethostbyname(const char *name) -{ - if (!WinSockInited) - WinSockInited = LosuSock_init(); - gethostbyname_t *output; - output = gethostbyname(name); - return output; -} - -bool LosuSock_sendtimeout(socket_t *sock, double sec) -{ - int _sec; - int usec; - usec = modf(sec, (void*)&_sec) * 1000000; - - struct timeval timeout; - timeout.tv_sec = _sec; - timeout.tv_usec = usec; - - if (setsockopt(sock->sockfd, SOL_SOCKET, SO_SNDTIMEO, (void *)&timeout, sizeof(timeout)) == 0) - return true; - return false; -} - -bool LosuSock_recvtimeout(socket_t *sock, double sec) -{ - int _sec; - int usec; - usec = modf(sec, (void*)&_sec) * 1000000; - - struct timeval timeout; - timeout.tv_sec = _sec; - timeout.tv_usec = usec; - - if (setsockopt(sock->sockfd, SOL_SOCKET, SO_RCVTIMEO, (void *)&timeout, sizeof(timeout)) == 0) - return true; - return false; -} - -//socket操作 - -socket_t *LosuSock_socket(int family, int type, int protocol) -{ - /* - 创建一个套接字 - */ - if (!WinSockInited) - LosuSock_init(); - - socket_t *sock = malloc(sizeof(socket_t)); - sock->sockfd = socket(family, type, protocol); - sock->family = family; - sock->type = type; - sock->protocol = protocol; - sock->addr.sin_family = family; - - return sock; -} - -bool LosuSock_bind(socket_t *sock, const char *ip, int port) -{ - /* - 将套接字和对应的ip和端口相绑定 - */ - sock->addr.sin_port = htons(port); - - if (ip == NULL) - //ip缺省时的情况 - sock->addr.sin_addr.S_un.S_addr = INADDR_ANY; - else - sock->addr.sin_addr.S_un.S_addr = inet_addr(ip); - - if (bind(sock->sockfd, (void*)&sock->addr, sizeof(sock->addr)) != SOCKET_ERROR) - return true; - return false; -} - -bool LosuSock_listen(socket_t *sock, int amount) -{ - /* - 监听 - */ - if (listen(sock->sockfd, amount) != SOCKET_ERROR) - return true; - return false; -} - -bool LosuSock_connect(socket_t *sock, const char *ip, int port) -{ - /* - 连接 - */ - sock->addr.sin_port = htons(port); - sock->addr.sin_addr.S_un.S_addr = inet_addr(ip); - int length = sizeof(sock->addr); - - if (connect(sock->sockfd, (void*)&sock->addr, length) == SOCKET_ERROR) - return false; - return true; -} - -socket_t *LosuSock_accept(socket_t * sock) -{ - socket_t *client = malloc(sizeof(socket_t)); - int length = sizeof(client->addr); - client->sockfd = accept(sock->sockfd, (void*)&client->addr, &length); - client->family = sock->family; - client->type = sock->type; - client->protocol = sock->protocol; - return client; -} - -bool LosuSock_send(socket_t *sock, const char *msg, int length, int x) -{ - if (send(sock->sockfd, msg, length, x) != SOCKET_ERROR) - { - return true; - } - return false; -} - -bool LosuSock_recv(socket_t *sock, char *buffer, int length, int x) -{ - recv(sock->sockfd, buffer, length, x); - return true; -} - -bool LosuSock_close(socket_t *sock) -{ - /* - 关闭 - */ - if (closesocket(sock->sockfd) == 0) - { - free(sock); - return true; - } - free(sock); - return false; -} - -#endif diff --git a/socket/Windows/win_sock.h b/socket/Windows/win_sock.h deleted file mode 100755 index e6fd6992bad9fbf79eda2087756f7df7cc750ae5..0000000000000000000000000000000000000000 --- a/socket/Windows/win_sock.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef LOSU_WIN_SOCK_H__ -#define LOSU_WIN_SOCK_H__ - -#ifndef _WIN32 - #warning "该文件用于Windows系统" -#endif - - -#ifdef _WIN32 - -#include "els.h" - -#include -#include //包含inet_ntop - -#include -#include -#include -#include -#include - -typedef struct sockaddr_in sock_addr_t; - -typedef struct -{ - int sockfd; - int family; - int type; - int protocol; - sock_addr_t addr; -} socket_t; - -typedef struct hostent gethostbyname_t; - -//辅助函数 -bool LosuSock_init(); -gethostbyname_t *LosuSock_gethostbyname(const char *name); -bool LosuSock_sendtimeout(socket_t *sock, double sec); -bool LosuSock_recvtimeout(socket_t *sock, double sec); - -//socket操作 -socket_t *LosuSock_socket(int family, int type, int prototol); -bool LosuSock_bind(socket_t *sock, const char *ip, int port); -bool LosuSock_listen(socket_t *sock, int amount); -socket_t *LosuSock_accept(socket_t *sock); -bool LosuSock_connect(socket_t *sock, const char *ip, int port); -bool LosuSock_send(socket_t *sock, const char *msg, int length, int x); -bool LosuSock_recv(socket_t *sock, char *buffer, int length, int x); -bool LosuSock_close(socket_t *sock); -#endif - -#endif \ No newline at end of file diff --git a/socket/info b/socket/info deleted file mode 100755 index c6ee955fcd8aef3a7253cf69db43c73430b83283..0000000000000000000000000000000000000000 --- a/socket/info +++ /dev/null @@ -1,29 +0,0 @@ -{ - info = { - name = "socket/套接字模块", - text = "网络套接字模块", - version = "24.4.11" - }, - source = { - all = { - "socket.c", - "socket.h", - "socket.els", - "readme.md" - }, - Ubuntu = { - "makefile", - "linux_sock.h", - "linux_sock.c", - }, - Windows = { - "makefile", - "win_sock.h", - "win_sock.c" - } - }, - target = { - Ubuntu = "make ; cp ElsLib_socket.lsd target/ElsLib_socket.lsd_Ubuntu ; make clean", - Windows = "make ; cp ElsLib_socket.lsd target/ElsLib_socket.lsd_Windows ; make clean", - } -} \ No newline at end of file diff --git a/socket/readme.md b/socket/readme.md deleted file mode 100755 index b07884138cea9179d44f63399e27e7b6e412c501..0000000000000000000000000000000000000000 --- a/socket/readme.md +++ /dev/null @@ -1,104 +0,0 @@ -#!/bin/owls.wiki.losu.tech -# wiki for socket - -# 简介 -socket是一个跨平台的网络编程模块,用于向洛书提供套接字服务。 - -# 常量 -## socket.AF_INET -AF_INET指的是IPv4地址族 - -## socket.SOCK_STREAM -SOCK_STREAM指的是流式套接字 - -# 函数 -## socket.gethostbyname(name:str): str -### 参数 -1. name 要解析的主机名 -### 返回值 -1. 一个单元,结构如下 -```python -{ - name:str, #查询的主机的正式名称 - aliases:unit, #查询的主机的别称,是一个都是字符串的单元,索引从0开始 - addrtype:int, #对应ip的地址族 - length:int, #对应ip的长度 - addr_list:unit #对应的ip,是一个都是字符串的单元,索引从0开始 -} -``` -### 注意事项 -1. 该函数在错误输入除字符串外的一切数据时不会出错,但在输入某些错误字符串时会造成未知原因的程序无响应,请确保输入的字符串大致符合主机名的格式 - -## socket.class(family, type, protocol) -### 参数 -1. family指要创建的套接字的地址族,目前可选的有socket.AF_INET -2. type指要创建的套接字的类型,目前可选的有socket.SOCK_STREAM -3. protocol指要创建的套接字的协议,目前只能留空 -### 返回值 -返回一个套接字类 - -# 类 -## socket -### 创建方式 -+ 使用new(socket.Socket, ...)创建 -### 成员变量 -#### sockfd -+ 保存一个指向socket_t的指针 -+ 此变量不应被非开发者访问 - -### 成员函数 - -#### sendtimeout(sec:int) -设置发送的超时时间 - -#### recvtimeout(sec:int) -设置接收的超时时间 - -#### bind(ip:string, port:int): [int/null] -将套接字绑定到指定ip和端口 -##### 参数 -1. ip 要绑定的ip地址,默认为本机地址 -2. port要绑定的端口,默认为80 - -___ - -#### listen(amount:int): [int/null] -开始监听 -##### 参数 -1. amount 设置最大连接数 - -___ - -#### accept(): socket -接受客户端套接字 -##### 返回值 -1. 返回连接到的客户端套接字的socket类 - -___ - -#### connect(ip:string, port:int): [int/null] -连接到指定ip和端口 -##### 参数 -1. ip 要连接的服务端的ip -2. port 要连接的服务端的端口 -##### 返回值 -连接成功时返回1,失败时返回null - -___ - -#### send(data:string): [int/null] -向套接字另一端发送数据 -##### 参数 -1. data 要发送的数据 - -___ - -#### recv(amount:int): string -从套接字另一端接受数据 -##### 参数 -1. amount 预计接受的字符数,应大于0而小于1024 - -___ - -#### close(): null -关闭套接字 \ No newline at end of file diff --git a/socket/socket.c b/socket/socket.c deleted file mode 100755 index 7a2e6f6161ddcc7cf43c9a7a40a9237f750db601..0000000000000000000000000000000000000000 --- a/socket/socket.c +++ /dev/null @@ -1,381 +0,0 @@ -#include "socket.h" - -#ifdef _WIN32 - #include "win_sock.h" - #include - #include -#endif - -#ifdef __linux__ - #include "linux_sock.h" -#endif - -/* - 各结构应有原型 - typedef struct sockaddr_in sock_addr_t; - - typedef struct - { - int sockfd; #网络套接字的描述符 - int family; #该套接字的地址族 - int type; #该套接字的类型 - int protocol; #该套接字的协议 - sock_addr_t addr; #该套接字的地址或是对面套接字的地址 - } socket_t; - - typedef struct{ - char *h_name; #标准主机名 - char **h_aliases; #主机的别名 - int h_addrtype; #主机ip地址的类型,只会是AF_INET - int h_length; #主机地址的长度 - char **h_addr_list; #主机的ip地址,是网络字节序,需要通过inet_ntop函数转换 - } gethostbyname_t; - - 各函数应有原型 - //辅助函数 - gethostbyname_t *LosuSock_gethostbyname(const char *name); - bool LosuSock_sendtimeout(socket_t *sock, double sec); - bool LosuSock_recvtimeout(socket_t *sock, double sec); - - //socket操作 - socket_t *LosuSock_socket(int family, int type, int protocol); - int LosuSock_bind(socket_t *sock, const char *ip, int port); - int LosuSock_listen(socket_t *sock, int amount); - int LosuSock_connect(socket_t *sock, const char *ip, int port); - socket_t *LosuSock_accept(socket_t *sock); - int LosuSock_send(socket_t *sock, const char *msg, int length, int x); - int LosuSock_recv(socket_t *sock, char *buffer, int length, int x); - int LosuSock_close(socket_t *sock); -*/ - -int ELSAPI_socket_c_AF_INET(els_VmObj* vm) -{ - arg_returnnum(vm, AF_INET); - return 1; -} - -int ELSAPI_socket_c_SOCK_STREAM(els_VmObj* vm) -{ - arg_returnnum(vm, SOCK_STREAM); - return 1; -} - -#define PUTN(s, n) vm_setval(vm, s, obj_newnum(vm, n)) - -int ELSAPI_socket_c_constinit(els_VmObj* vm) // c_constinit() -{ - /* - 用于将一些常量,如AF_INET放入全局作用域中 - */ - //地址系列常量 - PUTN("AF_UNSPEC", AF_UNSPEC); - PUTN("AF_INET", AF_INET); - PUTN("AF_IPX", AF_IPX); - PUTN("AF_APPLETALK", AF_APPLETALK); - PUTN("AF_NETBIOS", AF_NETBIOS); - PUTN("AF_INET6", AF_INET6); - PUTN("AF_IRDA", AF_IRDA); - PUTN("AF_BTH", AF_BTH); - - //套接字类型系列常量 - PUTN("SOCK_STREAM", SOCK_STREAM); - PUTN("SOCK_DGRAM", SOCK_DGRAM); - PUTN("SOCK_RAW", SOCK_RAW); - PUTN("SOCK_RDM", SOCK_RDM); - PUTN("SOCK_SEQPACKET", SOCK_SEQPACKET); - - //套接字协议系列常量 - PUTN("IPPROTO_ICMP", IPPROTO_ICMP); - PUTN("IPPROTO_IGMP", IPPROTO_IGMP); - PUTN("IPPROTO_TCP", IPPROTO_TCP); - PUTN("IPPROTO_UDP", IPPROTO_UDP); - PUTN("IPPROTO_ICMPV6", IPPROTO_ICMPV6); - PUTN("IPPROTO_RM", IPPROTO_RM); - - return 0; -} - -int ELSAPI_socket_c_gethostbyname(els_VmObj *vm) -{ - /* - # 参数 - 1. name 要获取的主机名称 - - #返回值 - 1. hosts 获取的结果 - */ - - const char *name; - gethostbyname_t *result = NULL; - int index = 0; - char buffer[128]; - - //将结果以单元的形式返回 - LosuObj unit_obj = obj_newunit(vm); - LosuObj aliases = obj_newunit(vm); //存放别称的单元 - LosuObj addr_list = obj_newunit(vm); - - /* - void obj_setunit(els_VmObj*vm,LosuObj unit,LosuObj key,LosuObj value); - 设定一个对象指定下标的值 - */ - - - - if (arg_gettype(vm, 1)!=ELS_API_TYPE_STRING || strlen((name=arg_getstr(vm, 1)))==0 || (result = LosuSock_gethostbyname(name))==NULL) - { - //如果获取失败,则返回 - //此时 - arg_returnnull(vm); - return 1; - } - - obj_setunit( - //将存放别称的单元放入aliases键中 - vm, unit_obj, - obj_newstr(vm, "aliases"), aliases - ); - - obj_setunit( - //先将addr_list放入单元 - vm, unit_obj, - obj_newstr(vm, "addr_list"), addr_list - ); - - obj_setunit( - //放入标准主机名 - vm, unit_obj, - obj_newstr(vm, "name"), obj_newstr(vm, result->h_name) - ); - - for (char **name=result->h_aliases; ; name++) - { - if (*name==NULL) - break; - - //将别称放入unit.aliases中 - obj_setunit( - vm, aliases, - obj_newnum(vm, index), obj_newstr(vm, *name) - ); - - index++; - } - - obj_setunit( - //将主机地址的类型放入addrtype中 - vm, unit_obj, - obj_newstr(vm, "addrtype"), obj_newnum(vm, result->h_addrtype) - ); - - obj_setunit( - //将主机地址的长度放入length中 - vm, unit_obj, - obj_newstr(vm, "length"), obj_newnum(vm, result->h_length) - ); - - index = 0; - for (char **ip=result->h_addr_list; ;ip++) - { - //将ip转化后放入unit.addr_list - if (*ip==NULL) - break; - - inet_ntop(result->h_addrtype, *ip, buffer, sizeof(buffer)); - - obj_setunit( - vm, addr_list, - obj_newnum(vm, index), obj_newstr(vm, buffer) - ); - - index++; - } - - arg_return(vm, unit_obj); - return 1; -} - -int ELSAPI_socket_c_sendtimeout(els_VmObj *vm) -{ - /* - # 参数 - 1.sock - 2.sec 要设置的时间,单位为秒 - */ - socket_t *sock = (void*)arg_getptr(vm, 1); - double sec = arg_getnum(vm, 2); - - if (LosuSock_sendtimeout(sock, sec)) - arg_returnnum(vm, 1); - else - arg_returnnull(vm); - return 1; -} -int ELSAPI_socket_c_recvtimeout(els_VmObj *vm) -{ - /* - # 参数 - 1.sock - 2.sec 要设置的时间,单位为秒 - */ - socket_t *sock = (void*)arg_getptr(vm, 1); - double sec = arg_getnum(vm, 2); - - if (LosuSock_recvtimeout(sock, sec)) - arg_returnnum(vm, 1); - else - arg_returnnull(vm); - return 1; -} - -int ELSAPI_socket_c_socket(els_VmObj* vm) -{ - /* - - # 参数 - 1.family - 2.type - 3.protocol - - # 返回值 - 1.sockfd - */ - int family = arg_getnum(vm, 1); - int type = arg_getnum(vm, 2); - int protocol = arg_getnum(vm, 3); - - socket_t *sockfd = LosuSock_socket(family, type, protocol); - arg_returnptr(vm, (void*)sockfd); - - return 1; -} - -int ELSAPI_socket_c_bind(els_VmObj* vm) -{ - /* - # 参数 - 1.sock - 2.ip - 3.port - - # 返回值 - 成功时返回1 - 失败时返回null - */ - socket_t *sock = (void*)arg_getptr(vm, 1); - const char *ip = arg_getstr(vm, 2); - int port = arg_getnum(vm, 3); - - if (LosuSock_bind(sock, ip, port)) - arg_returnnum(vm, 1); - else - arg_returnnull(vm); - - return 1; -} - -int ELSAPI_socket_c_listen(els_VmObj* vm) -{ - /* - # 参数 - 1.sock - 2.amount - - # 返回值 - 成功时返回1 - 失败时返回null - */ - socket_t * sock = (void*)arg_getptr(vm, 1); - int amount = arg_getnum(vm, 2); - - if (LosuSock_listen(sock, amount)) - arg_returnnum(vm, 1); - else - arg_returnnull(vm); - - return 1; -} - -int ELSAPI_socket_c_accept(els_VmObj* vm) -{ - /* - # 参数 - 1.sock - - # 返回值 - 1.client - */ - socket_t *sock = (void*)arg_getptr(vm, 1); - - arg_returnptr(vm, (void*)LosuSock_accept(sock)); - return 1; -} - -int ELSAPI_socket_c_connect(els_VmObj* vm) -{ - /* - 参数: - 1.sock - 2.ip - 3.port - - 返回值: - 成功时返回1 - 失败时返回null - */ - socket_t *sock = (void*)arg_getptr(vm, 1); - const char *ip = arg_getstr(vm, 2); - int port = arg_getnum(vm, 3); - - if (LosuSock_connect(sock, ip, port)) - arg_returnnum(vm, 1); - else - arg_returnnull(vm); - - return 1; -} - -int ELSAPI_socket_c_send(els_VmObj* vm) -{ - /* - 参数: - 1.sock - 2.data - */ - socket_t *sock = (void*)arg_getptr(vm, 1); - const char *data = ""; - - if (arg_gettype(vm, 2) == ELS_API_TYPE_STRING) - data = arg_getstr(vm, 2); - - LosuSock_send(sock, data, strlen(data), 0); - return 1; -} - -int ELSAPI_socket_c_recv(els_VmObj* vm) -{ - /* - 参数: - 1.sockfd - 2.amount - */ - socket_t *sock = (void*)arg_getptr(vm, 1); - int amount = arg_getnum(vm, 2); - char *tmp = calloc(sizeof(char), amount + 1); - - LosuSock_recv(sock, tmp, amount, 0); - arg_returnstr(vm, tmp); - free(tmp); - return 1; -} - -int ELSAPI_socket_c_close(els_VmObj* vm) -{ - /* - 参数: - 1.sockfd - */ - socket_t *sock = (void*)arg_getptr(vm, 1); - LosuSock_close(sock); - return 1; -} diff --git a/socket/socket.els b/socket/socket.els deleted file mode 100755 index ab31eabc695f1d062c53cc3b48f8522a68e89e38..0000000000000000000000000000000000000000 --- a/socket/socket.els +++ /dev/null @@ -1,163 +0,0 @@ -#!declare -c_constinit() - -c_AF_INET() -c_SOCK_STREAM() - -c_gethostbyname() -c_sendtimeout() -c_recvtimeout() - -c_socket() -c_bind() -c_listen() -c_accept() -c_connect() -c_send() -c_recv() -c_close() -#!end - -#!script - -c_constinit() #加载常量到全局作用域 - -socket = { - #地址系列常量 - AF_UNSPEC = AF_UNSPEC, - AF_INET = AF_INET, - AF_IPX = AF_IPX, - AF_APPLETALK = AF_APPLETALK, - AF_NETBIOS = AF_NETBIOS, - AF_INET6 = AF_INET6, - AF_IRDA = AF_IRDA, - AF_BTH = AF_BTH, - - #套接字类型系列常量 - SOCK_STREAM = SOCK_STREAM, - SOCK_DGRAM = SOCK_DGRAM, - SOCK_RAW = SOCK_RAW, - SOCK_RDM = SOCK_RDM, - SOCK_SEQPACKET = SOCK_SEQPACKET, - - #套接字协议系列常量 - IPPROTO_ICMP = IPPROTO_ICMP, - IPPROTO_IGMP = IPPROTO_IGMP, - IPPROTO_TCP = IPPROTO_TCP, - IPPROTO_UDP = IPPROTO_UDP, - IPPROTO_ICMPV6 = IPPROTO_ICMPV6, - IPPROTO_RM = IPPROTO_RM, - - #类 - Socket = {} -} - -def socket.gethostbyname(name): - rt c_gethostbyname(name) -; - -def socket.Socket.class(family, type, protocol): - var this = { - - } - - #成员变量 - this.family = family or socket.AF_INET - this.type = type or socket.SOCK_STREAM - this.protocol = protocol or 0 - this.sock = c_socket(this.family, this.type, this.protocol) - - #成员函数 - this.sendtimeout = socket.sendtimeout - this.recvtimeout = sock.recvtimeout - this.bind = socket.bind - this.listen = socket.listen - this.accept = socket.accept - this.connect = socket.connect - this.send = socket.send - this.recv = socket.recv - this.close = socket.close - - rt this -; - -def socket.sendtimeout(sec): - if not sec or not this.sock: - rt null - ; - rt c_sendtimeout(this.sock, sec) -; - -def socket.recvtimeout(sec): - if not sec or not this.sock: - rt null - ; - rt c_recvtimeout(this.sock, sec) -; - -def socket.bind(ip, port): - if not this.sock: - rt null - ; - - this.ip = ip or 0 - this.port = port or 80 - rt c_bind(this.sock, this.ip, this.port) -; - -def socket.listen(amount): - if not this.sock: - rt null - ; - - this.amount = amount or 5 - rt c_listen(this.sock, this.amount) -; - -def socket.accept(): - if not this.sock: - rt null - ; - - var client = new(socket.Socket, this.family, this.type, this.protocol) - client.sock = c_accept(this.sock) - rt client -; - -def socket.connect(ip, port): - if not ip or not this.sock: - rt null - ; - this.ip = ip - this.port = port or 80 - c_connect(this.sock, this.ip, this.port) -; - -def socket.send(data): - if not data or not this.sock: - rt null - ; - - c_send(this.sock, data) -; - -def socket.recv(amount): - if not this.sock: - rt null - ; - - amount = amount or 1024 - - rt c_recv(this.sock, amount) -; - -def socket.close(): - if not this.sock: - rt null - ; - - c_close(this.sock) - this.sock = null -; - -#!end diff --git a/socket/socket.h b/socket/socket.h deleted file mode 100755 index b32e384387bb0bc0873fe55b5cfe3cac0373f190..0000000000000000000000000000000000000000 --- a/socket/socket.h +++ /dev/null @@ -1,179 +0,0 @@ -#include "els.h" -int ELSAPI_socket_c_constinit(els_VmObj* vm); // c_constinit() -int ELSAPI_socket_c_AF_INET(els_VmObj* vm); // c_AF_INET() -int ELSAPI_socket_c_SOCK_STREAM(els_VmObj* vm); // c_SOCK_STREAM() -int ELSAPI_socket_c_gethostbyname(els_VmObj* vm); // c_gethostbyname() -int ELSAPI_socket_c_sendtimeout(els_VmObj* vm); // c_sendtimeout() -int ELSAPI_socket_c_recvtimeout(els_VmObj* vm); // c_recvtimeout() -int ELSAPI_socket_c_socket(els_VmObj* vm); // c_socket() -int ELSAPI_socket_c_bind(els_VmObj* vm); // c_bind() -int ELSAPI_socket_c_listen(els_VmObj* vm); // c_listen() -int ELSAPI_socket_c_accept(els_VmObj* vm); // c_accept() -int ELSAPI_socket_c_connect(els_VmObj* vm); // c_connect() -int ELSAPI_socket_c_send(els_VmObj* vm); // c_send() -int ELSAPI_socket_c_recv(els_VmObj* vm); // c_recv() -int ELSAPI_socket_c_close(els_VmObj* vm); // c_close() -#ifdef ELS_CONF_TOKEN_EN -static const char LibScript[]={ -10, -99,95,99,111,110,115,116,105,110,105,116,40,41,32,35,-27,-118,-96,-24,-67,-67,-27,-72,-72,-23,-121,-113,-27,-120,-80,-27,-123,-88,-27,-79,-128,-28,-67,-100,-25,-108,-88,-27,-97,-97,10, -10, -115,111,99,107,101,116,32,61,32,123,10, -32,32,32,32,35,-27,-100,-80,-27,-99,-128,-25,-77,-69,-27,-120,-105,-27,-72,-72,-23,-121,-113,10, -32,32,32,32,65,70,95,85,78,83,80,69,67,32,61,32,65,70,95,85,78,83,80,69,67,44,10, -32,32,32,32,65,70,95,73,78,69,84,32,61,32,65,70,95,73,78,69,84,44,10, -32,32,32,32,65,70,95,73,80,88,32,61,32,65,70,95,73,80,88,44,10, -32,32,32,32,65,70,95,65,80,80,76,69,84,65,76,75,32,61,32,65,70,95,65,80,80,76,69,84,65,76,75,44,10, -32,32,32,32,65,70,95,78,69,84,66,73,79,83,32,61,32,65,70,95,78,69,84,66,73,79,83,44,10, -32,32,32,32,65,70,95,73,78,69,84,54,32,61,32,65,70,95,73,78,69,84,54,44,10, -32,32,32,32,65,70,95,73,82,68,65,32,61,32,65,70,95,73,82,68,65,44,10, -32,32,32,32,65,70,95,66,84,72,32,61,32,65,70,95,66,84,72,44,10, -10, -32,32,32,32,35,-27,-91,-105,-26,-114,-91,-27,-83,-105,-25,-79,-69,-27,-98,-117,-25,-77,-69,-27,-120,-105,-27,-72,-72,-23,-121,-113,10, -32,32,32,32,83,79,67,75,95,83,84,82,69,65,77,32,61,32,83,79,67,75,95,83,84,82,69,65,77,44,10, -32,32,32,32,83,79,67,75,95,68,71,82,65,77,32,61,32,83,79,67,75,95,68,71,82,65,77,44,10, -32,32,32,32,83,79,67,75,95,82,65,87,32,61,32,83,79,67,75,95,82,65,87,44,10, -32,32,32,32,83,79,67,75,95,82,68,77,32,61,32,83,79,67,75,95,82,68,77,44,10, -32,32,32,32,83,79,67,75,95,83,69,81,80,65,67,75,69,84,32,61,32,83,79,67,75,95,83,69,81,80,65,67,75,69,84,44,10, -10, -32,32,32,32,35,-27,-91,-105,-26,-114,-91,-27,-83,-105,-27,-115,-113,-24,-82,-82,-25,-77,-69,-27,-120,-105,-27,-72,-72,-23,-121,-113,10, -32,32,32,32,73,80,80,82,79,84,79,95,73,67,77,80,32,61,32,73,80,80,82,79,84,79,95,73,67,77,80,44,10, -32,32,32,32,73,80,80,82,79,84,79,95,73,71,77,80,32,61,32,73,80,80,82,79,84,79,95,73,71,77,80,44,10, -32,32,32,32,73,80,80,82,79,84,79,95,84,67,80,32,61,32,73,80,80,82,79,84,79,95,84,67,80,44,10, -32,32,32,32,73,80,80,82,79,84,79,95,85,68,80,32,61,32,73,80,80,82,79,84,79,95,85,68,80,44,10, -32,32,32,32,73,80,80,82,79,84,79,95,73,67,77,80,86,54,32,61,32,73,80,80,82,79,84,79,95,73,67,77,80,86,54,44,10, -32,32,32,32,73,80,80,82,79,84,79,95,82,77,32,61,32,73,80,80,82,79,84,79,95,82,77,44,10, -10, -32,32,32,32,35,-25,-79,-69,10, -32,32,32,32,83,111,99,107,101,116,32,61,32,123,125,10, -125,10, -10, -100,101,102,32,115,111,99,107,101,116,46,103,101,116,104,111,115,116,98,121,110,97,109,101,40,110,97,109,101,41,58,10, -32,32,32,32,114,116,32,99,95,103,101,116,104,111,115,116,98,121,110,97,109,101,40,110,97,109,101,41,10, -59,10, -10, -100,101,102,32,115,111,99,107,101,116,46,83,111,99,107,101,116,46,99,108,97,115,115,40,102,97,109,105,108,121,44,32,116,121,112,101,44,32,112,114,111,116,111,99,111,108,41,58,10, -32,32,32,32,118,97,114,32,116,104,105,115,32,61,32,123,10, -10, -32,32,32,32,125,10, -10, -32,32,32,32,35,-26,-120,-112,-27,-111,-104,-27,-113,-104,-23,-121,-113,10, -32,32,32,32,116,104,105,115,46,102,97,109,105,108,121,32,61,32,102,97,109,105,108,121,32,111,114,32,115,111,99,107,101,116,46,65,70,95,73,78,69,84,10, -32,32,32,32,116,104,105,115,46,116,121,112,101,32,61,32,116,121,112,101,32,111,114,32,115,111,99,107,101,116,46,83,79,67,75,95,83,84,82,69,65,77,10, -32,32,32,32,116,104,105,115,46,112,114,111,116,111,99,111,108,32,61,32,112,114,111,116,111,99,111,108,32,111,114,32,48,10, -32,32,32,32,116,104,105,115,46,115,111,99,107,32,61,32,99,95,115,111,99,107,101,116,40,116,104,105,115,46,102,97,109,105,108,121,44,32,116,104,105,115,46,116,121,112,101,44,32,116,104,105,115,46,112,114,111,116,111,99,111,108,41,10, -10, -32,32,32,32,35,-26,-120,-112,-27,-111,-104,-27,-121,-67,-26,-107,-80,10, -32,32,32,32,116,104,105,115,46,115,101,110,100,116,105,109,101,111,117,116,32,61,32,115,111,99,107,101,116,46,115,101,110,100,116,105,109,101,111,117,116,10, -32,32,32,32,116,104,105,115,46,114,101,99,118,116,105,109,101,111,117,116,32,61,32,115,111,99,107,46,114,101,99,118,116,105,109,101,111,117,116,10, -32,32,32,32,116,104,105,115,46,98,105,110,100,32,61,32,115,111,99,107,101,116,46,98,105,110,100,10, -32,32,32,32,116,104,105,115,46,108,105,115,116,101,110,32,61,32,115,111,99,107,101,116,46,108,105,115,116,101,110,10, -32,32,32,32,116,104,105,115,46,97,99,99,101,112,116,32,61,32,115,111,99,107,101,116,46,97,99,99,101,112,116,10, -32,32,32,32,116,104,105,115,46,99,111,110,110,101,99,116,32,61,32,115,111,99,107,101,116,46,99,111,110,110,101,99,116,10, -32,32,32,32,116,104,105,115,46,115,101,110,100,32,61,32,115,111,99,107,101,116,46,115,101,110,100,10, -32,32,32,32,116,104,105,115,46,114,101,99,118,32,61,32,115,111,99,107,101,116,46,114,101,99,118,10, -32,32,32,32,116,104,105,115,46,99,108,111,115,101,32,61,32,115,111,99,107,101,116,46,99,108,111,115,101,10, -10, -32,32,32,32,114,116,32,116,104,105,115,10, -59,10, -10, -100,101,102,32,115,111,99,107,101,116,46,115,101,110,100,116,105,109,101,111,117,116,40,115,101,99,41,58,10, -32,32,32,32,105,102,32,110,111,116,32,115,101,99,32,111,114,32,110,111,116,32,116,104,105,115,46,115,111,99,107,58,10, -32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,59,10, -32,32,32,32,114,116,32,99,95,115,101,110,100,116,105,109,101,111,117,116,40,116,104,105,115,46,115,111,99,107,44,32,115,101,99,41,10, -59,10, -10, -100,101,102,32,115,111,99,107,101,116,46,114,101,99,118,116,105,109,101,111,117,116,40,115,101,99,41,58,10, -32,32,32,32,105,102,32,110,111,116,32,115,101,99,32,111,114,32,110,111,116,32,116,104,105,115,46,115,111,99,107,58,10, -32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,59,10, -32,32,32,32,114,116,32,99,95,114,101,99,118,116,105,109,101,111,117,116,40,116,104,105,115,46,115,111,99,107,44,32,115,101,99,41,10, -59,10, -10, -100,101,102,32,115,111,99,107,101,116,46,98,105,110,100,40,105,112,44,32,112,111,114,116,41,58,10, -32,32,32,32,105,102,32,110,111,116,32,116,104,105,115,46,115,111,99,107,58,10, -32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,59,10, -10, -32,32,32,32,116,104,105,115,46,105,112,32,61,32,105,112,32,111,114,32,48,10, -32,32,32,32,116,104,105,115,46,112,111,114,116,32,61,32,112,111,114,116,32,111,114,32,56,48,10, -32,32,32,32,114,116,32,99,95,98,105,110,100,40,116,104,105,115,46,115,111,99,107,44,32,116,104,105,115,46,105,112,44,32,116,104,105,115,46,112,111,114,116,41,10, -59,10, -10, -100,101,102,32,115,111,99,107,101,116,46,108,105,115,116,101,110,40,97,109,111,117,110,116,41,58,10, -32,32,32,32,105,102,32,110,111,116,32,116,104,105,115,46,115,111,99,107,58,10, -32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,59,10, -10, -32,32,32,32,116,104,105,115,46,97,109,111,117,110,116,32,61,32,97,109,111,117,110,116,32,111,114,32,53,10, -32,32,32,32,114,116,32,99,95,108,105,115,116,101,110,40,116,104,105,115,46,115,111,99,107,44,32,116,104,105,115,46,97,109,111,117,110,116,41,10, -59,10, -10, -100,101,102,32,115,111,99,107,101,116,46,97,99,99,101,112,116,40,41,58,10, -32,32,32,32,105,102,32,110,111,116,32,116,104,105,115,46,115,111,99,107,58,10, -32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,59,10, -10, -32,32,32,32,118,97,114,32,99,108,105,101,110,116,32,61,32,110,101,119,40,115,111,99,107,101,116,46,83,111,99,107,101,116,44,32,116,104,105,115,46,102,97,109,105,108,121,44,32,116,104,105,115,46,116,121,112,101,44,32,116,104,105,115,46,112,114,111,116,111,99,111,108,41,10, -32,32,32,32,99,108,105,101,110,116,46,115,111,99,107,32,61,32,99,95,97,99,99,101,112,116,40,116,104,105,115,46,115,111,99,107,41,10, -32,32,32,32,114,116,32,99,108,105,101,110,116,10, -59,10, -10, -100,101,102,32,115,111,99,107,101,116,46,99,111,110,110,101,99,116,40,105,112,44,32,112,111,114,116,41,58,10, -32,32,32,32,105,102,32,110,111,116,32,105,112,32,111,114,32,110,111,116,32,116,104,105,115,46,115,111,99,107,58,10, -32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,59,10, -32,32,32,32,116,104,105,115,46,105,112,32,61,32,105,112,10, -32,32,32,32,116,104,105,115,46,112,111,114,116,32,61,32,112,111,114,116,32,111,114,32,56,48,10, -32,32,32,32,99,95,99,111,110,110,101,99,116,40,116,104,105,115,46,115,111,99,107,44,32,116,104,105,115,46,105,112,44,32,116,104,105,115,46,112,111,114,116,41,10, -59,10, -10, -100,101,102,32,115,111,99,107,101,116,46,115,101,110,100,40,100,97,116,97,41,58,10, -32,32,32,32,105,102,32,110,111,116,32,100,97,116,97,32,111,114,32,110,111,116,32,116,104,105,115,46,115,111,99,107,58,10, -32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,59,10, -10, -32,32,32,32,99,95,115,101,110,100,40,116,104,105,115,46,115,111,99,107,44,32,100,97,116,97,41,10, -59,10, -10, -100,101,102,32,115,111,99,107,101,116,46,114,101,99,118,40,97,109,111,117,110,116,41,58,10, -32,32,32,32,105,102,32,110,111,116,32,116,104,105,115,46,115,111,99,107,58,10, -32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,59,10, -10, -32,32,32,32,97,109,111,117,110,116,32,61,32,97,109,111,117,110,116,32,111,114,32,49,48,50,52,10, -10, -32,32,32,32,114,116,32,99,95,114,101,99,118,40,116,104,105,115,46,115,111,99,107,44,32,97,109,111,117,110,116,41,10, -59,10, -10, -100,101,102,32,115,111,99,107,101,116,46,99,108,111,115,101,40,41,58,10, -32,32,32,32,105,102,32,110,111,116,32,116,104,105,115,46,115,111,99,107,58,10, -32,32,32,32,32,32,32,32,114,116,32,110,117,108,108,10, -32,32,32,32,59,10, -10, -32,32,32,32,99,95,99,108,111,115,101,40,116,104,105,115,46,115,111,99,107,41,10, -32,32,32,32,116,104,105,115,46,115,111,99,107,32,61,32,110,117,108,108,10, -59,10, -10, -0}; -#endif -void ElsLib_socket_libinit(els_VmObj *vm){ - vm_register(vm,"c_gethostbyname",ELSAPI_socket_c_gethostbyname); - vm_register(vm,"c_socket",ELSAPI_socket_c_socket); - vm_register(vm,"c_recvtimeout",ELSAPI_socket_c_recvtimeout); - vm_register(vm,"c_close",ELSAPI_socket_c_close); - vm_register(vm,"c_SOCK_STREAM",ELSAPI_socket_c_SOCK_STREAM); - vm_register(vm,"c_bind",ELSAPI_socket_c_bind); - vm_register(vm,"c_recv",ELSAPI_socket_c_recv); - vm_register(vm,"c_sendtimeout",ELSAPI_socket_c_sendtimeout); - vm_register(vm,"c_send",ELSAPI_socket_c_send); - vm_register(vm,"c_accept",ELSAPI_socket_c_accept); - vm_register(vm,"c_connect",ELSAPI_socket_c_connect); - vm_register(vm,"c_AF_INET",ELSAPI_socket_c_AF_INET); - vm_register(vm,"c_listen",ELSAPI_socket_c_listen); - vm_register(vm,"c_constinit",ELSAPI_socket_c_constinit); - #ifdef ELS_CONF_TOKEN_EN - vm_dostring(vm,LibScript); - #endif -}; diff --git a/std/Ubuntu/makefile b/std/Ubuntu/makefile deleted file mode 100755 index de08f132a3431ac51217e2035ee6895c46ba9b2c..0000000000000000000000000000000000000000 --- a/std/Ubuntu/makefile +++ /dev/null @@ -1,13 +0,0 @@ -OBJS = std.o -CFLAGS= -O2 -Wall -std=gnu99 -DELS_CONF_OS_LINUX -I ../buildenv -fPIC -CC=x86_64-linux-gnu-gcc -T=./ElsLib_std.lsd - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -shared -s - -clean: - rm -rf $T $(OBJS) core core.* \ No newline at end of file diff --git a/std/Ubuntu/std.c b/std/Ubuntu/std.c deleted file mode 100755 index 794ee56bf344b804f3747059ffcee7c52e4452a2..0000000000000000000000000000000000000000 --- a/std/Ubuntu/std.c +++ /dev/null @@ -1,113 +0,0 @@ - -#include "std.h" -#include -#include -#include -#include - -//void usleep ( int micro_seconds); - -int ELSAPI_std_getversion(els_VmObj* vm) // getversion(): int '获取版本信息' -{ - arg_returnstr(vm,ELS_VERSION); - return 1; -} -int ELSAPI_std_print(els_VmObj* vm) -{ - // print( s:str , ... ) : null '打印并换行' - - for(int i=0;i -#include -#include -#include - - -int ELSAPI_std_getversion(els_VmObj* vm) // getversion(): int '获取版本信息' -{ - arg_returnstr(vm,ELS_VERSION); - return 1; -} -int ELSAPI_std_print(els_VmObj* vm) -{ // print( s:str , ... ) : null '打印并换行' - - char* tmp; - for(int i=0;i -#include -#include - - -int ELSAPI_stdbyte_stdbyte_newbyte_str(els_VmObj* vm) // stdbyte_newbyte_str(o: object,b: str): byte '生成一个新的二进制变量-从字符串' -{ - arg_returnbyte(vm,(char*)arg_getstr(vm,2),arg_get(vm,2)->value.ts->len); - return 1; -} -int ELSAPI_stdbyte_stdbyte_newbyte_num(els_VmObj* vm) // stdbyte_newbyte_num(o: object,b: num): byte '生成一个新的二进制变量-从数字' -{ - char tmp[sizeof(Number)]={0}; - Number i = arg_getnum(vm,2); - char * _i = (char*)(&i); - for(int j=0;j -#include - -int ELSAPI_stdfile_fopen(els_VmObj* vm) // fopen(fname: str,mod: str): ptr '以指定模式打开一个文件,mod对应C语言,失败返回null' -{ - FILE* f = fopen(arg_getstr(vm,1),arg_getstr(vm,2)); - - if(f) arg_returnptr(vm,(char*)(f)); - else arg_returnnull(vm); - - return 1; -} -int ELSAPI_stdfile_fclose(els_VmObj* vm) // fclose(fp: ptr): int '关闭一个文件,成功返回0,失败返回null' -{ - int i = fclose((FILE*)(arg_getptr(vm,1))); - - if(i!=EOF) arg_returnnum(vm,i); - else arg_returnnull(vm); - - return 1; -} -int ELSAPI_stdfile_fputc(els_VmObj* vm) // fputc(fp: ptr,c: [int]): int 'c 的字符值写入到 fp 所指向的输出流中。如果写入成功,它会返回写入的字符,如果发生错误,则会返回 null' -{ - int i = fputc(arg_getnum(vm,2),(FILE*)(arg_getptr(vm,1))); - - if(i!=EOF) arg_returnnum(vm,i); - else arg_returnnull(vm); - - return 1; -} -int ELSAPI_stdfile_fputs(els_VmObj* vm) // fputs(fp: ptr,s: str): int 's 写入到 fp 所指向的输出流中。如果写入成功,它会返回一个非负值,如果发生错误,则会返回 null' -{ - int i = fputs(arg_getstr(vm,2),(FILE*)(arg_getptr(vm,1))); - if(i!=EOF) arg_returnnum(vm,i); - else arg_returnnull(vm); - - return 1; -} - -int ELSAPI_stdfile_fgetc(els_VmObj* vm) // fgetc(fp: ptr): int '函数从 fp 所指向的输入文件中读取一个字符。返回值是读取的字符,如果发生错误则返回 null' -{ - arg_returnnum(vm,(Number)(fgetc((FILE*)(arg_getptr(vm,1))))); - return 1; -} - -int ELSAPI_stdfile_finput(els_VmObj* vm) // finput(fp:ptr): str '从 fp 所指向文件中读取一个字段,遇到空格等结束' -{ - char tmp[ELS_BUFF_TMP_SIZE]; - memset(tmp,'\0',ELS_BUFF_TMP_SIZE); - if(feof((FILE*)(arg_getptr(vm,1)))) arg_returnnull(vm); - else{ - fscanf((FILE*)(arg_getptr(vm,1)),"%s",tmp); - arg_returnstr(vm,tmp); - } - return 1; -} - -int ELSAPI_stdfile_fgets(els_VmObj* vm) // fgets(fp: ptr, int n): str '从 fp 所指向的输入流中读取 n-1 个字符"如果n为null,则读取为内核最大字符缓冲区"如果这个函数在读取最后一个字符之前就遇到一个换行符或文件的末尾 null,则只会返回读取到的字符,包括换行符' -{ - char tmp[ELS_BUFF_TMP_SIZE]; - memset(tmp,'\0',ELS_BUFF_TMP_SIZE); - - if(feof((FILE*)(arg_getptr(vm,1)))) { - arg_returnnull(vm); - return 1; - } - if(arg_gettype(vm,2)==ELS_API_TYPE_NULL){ - fgets(tmp,ELS_BUFF_TMP_SIZE,(FILE*)(arg_getptr(vm,1))); - }else{ - fgets(tmp,(int)arg_getnum(vm,2),(FILE*)(arg_getptr(vm,1))); - } - char a = tmp[strlen(tmp)-1]; - tmp[strlen(tmp)-1]=(a=='\n')?'\0':a; - a = tmp[strlen(tmp)-1]; - tmp[strlen(tmp)-1]=(a=='\r')?'\0':a; - arg_returnstr(vm,tmp); - return 1; -} - -int ELSAPI_stdfile_feof(els_VmObj* vm) // feof(fp: ptr): int 'fp 是否到达结尾,否返回 null' -{ - int i = feof((FILE*)(arg_getptr(vm,1))); - - if(i) arg_returnnum(vm,i); - else arg_returnnull(vm); - - return 1; -} - -int ELSAPI_stdfile_fseek(els_VmObj* vm) // fseek(fp: ptr,i: int,sp: int):int '设置流 fp 的文件位置为给定的偏移 i,参数i 意味着从给定的 sp 位置查找的字节数' -{ - int i = fseek((FILE*)(arg_getptr(vm,1)),(int)(arg_getnum(vm,2)),(int)(arg_getnum(vm,3))); - if(i) arg_returnnum(vm,i); - else arg_returnnull(vm); - - return 1; -} -int ELSAPI_stdfile_ftell(els_VmObj* vm) // ftell(fp: ptr): int '返回文件当前位置,以文件头为相对位置' -{ - arg_returnnum(vm,(Number)(ftell((FILE*)(arg_getptr(vm,1))))); - return 1; -} -int ELSAPI_stdfile_rewind(els_VmObj* vm) // rewind(fp: prt): null '返回文件头' -{ - rewind((FILE*)(arg_getptr(vm,1))); - arg_returnnull(vm); - return 1; -} - - diff --git a/stdfile/Windows/makefile b/stdfile/Windows/makefile deleted file mode 100755 index 7f4dfca6125a97f812a5d8aae481d75276620a61..0000000000000000000000000000000000000000 --- a/stdfile/Windows/makefile +++ /dev/null @@ -1,12 +0,0 @@ -OBJS = stdfile.o -CFLAGS= -O2 -Wall -std=c99 -DLOSU_WINDOWS -I ../buildenv -fPIC -CC=x86_64-w64-mingw32-gcc -T=ElsLib_stdfile.lsd - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -L ../buildenv -l:libeasylosu.dll -shared -s -static -#-lUrlmon -lUser32 -lkernel32 -lWininet -clean: - rm -rf $T $(OBJS) core core.* diff --git a/stdfile/Windows/stdfile.c b/stdfile/Windows/stdfile.c deleted file mode 100755 index ebb478c4d085b6e923f597cbb0c74704ef7248d0..0000000000000000000000000000000000000000 --- a/stdfile/Windows/stdfile.c +++ /dev/null @@ -1,111 +0,0 @@ -#include "stdfile.h" -#include -#include -#include - -int ELSAPI_stdfile_fopen(els_VmObj* vm) // fopen(fname: str,mod: str): ptr '以指定模式打开一个文件,mod对应C语言,失败返回null' -{ - char * tmp = vm_win_togbk(arg_getstr(vm,1)); - FILE* f = fopen(tmp,arg_getstr(vm,2)); - free(tmp); - - if(f) arg_returnptr(vm,(char*)(f)); - else arg_returnnull(vm); - - return 1; -} -int ELSAPI_stdfile_fclose(els_VmObj* vm) // fclose(fp: ptr): int '关闭一个文件,成功返回0,失败返回null' -{ - int i = fclose((FILE*)(arg_getptr(vm,1))); - - if(i!=EOF) arg_returnnum(vm,i); - else arg_returnnull(vm); - - return 1; -} -int ELSAPI_stdfile_fputc(els_VmObj* vm) // fputc(fp: ptr,c: [int]): int 'c 的字符值写入到 fp 所指向的输出流中。如果写入成功,它会返回写入的字符,如果发生错误,则会返回 null' -{ - int i = fputc(arg_getnum(vm,2),(FILE*)(arg_getptr(vm,1))); - - if(i!=EOF) arg_returnnum(vm,i); - else arg_returnnull(vm); - - return 1; -} -int ELSAPI_stdfile_fputs(els_VmObj* vm) // fputs(fp: ptr,s: str): int 's 写入到 fp 所指向的输出流中。如果写入成功,它会返回一个非负值,如果发生错误,则会返回 null' -{ - int i = fputs(arg_getstr(vm,2),(FILE*)(arg_getptr(vm,1))); - if(i!=EOF) arg_returnnum(vm,i); - else arg_returnnull(vm); - - return 1; -} - -int ELSAPI_stdfile_fgetc(els_VmObj* vm) // fgetc(fp: ptr): int '函数从 fp 所指向的输入文件中读取一个字符。返回值是读取的字符,如果发生错误则返回 null' -{ - arg_returnnum(vm,(Number)(fgetc((FILE*)(arg_getptr(vm,1))))); - return 1; -} - -int ELSAPI_stdfile_finput(els_VmObj* vm) // finput(fp:ptr): str '从 fp 所指向文件中读取一个字段,遇到空格等结束' -{ - char tmp[ELS_BUFF_TMP_SIZE]; - memset(tmp,'\0',ELS_BUFF_TMP_SIZE); - if(feof((FILE*)(arg_getptr(vm,1)))) arg_returnnull(vm); - else{ - fscanf((FILE*)(arg_getptr(vm,1)),"%s",tmp); - arg_returnstr(vm,tmp); - } - return 1; -} - -int ELSAPI_stdfile_fgets(els_VmObj* vm) // fgets(fp: ptr, int n): str '从 fp 所指向的输入流中读取 n-1 个字符"如果n为null,则读取为内核最大字符缓冲区"如果这个函数在读取最后一个字符之前就遇到一个换行符或文件的末尾 null,则只会返回读取到的字符,包括换行符' -{ - char tmp[ELS_BUFF_TMP_SIZE]; - memset(tmp,'\0',ELS_BUFF_TMP_SIZE); - - if(feof((FILE*)(arg_getptr(vm,1)))) { - arg_returnnull(vm); - return 1; - } - if(arg_gettype(vm,2)==ELS_API_TYPE_NULL){ - fgets(tmp,ELS_BUFF_TMP_SIZE,(FILE*)(arg_getptr(vm,1))); - }else{ - fgets(tmp,(int)arg_getnum(vm,2),(FILE*)(arg_getptr(vm,1))); - } - char a = tmp[strlen(tmp)-1]; - tmp[strlen(tmp)-1]=(a=='\n')?'\0':a;arg_returnstr(vm,tmp); - return 1; -} - -int ELSAPI_stdfile_feof(els_VmObj* vm) // feof(fp: ptr): int 'fp 是否到达结尾,否返回 null' -{ - int i = feof((FILE*)(arg_getptr(vm,1))); - - if(i) arg_returnnum(vm,i); - else arg_returnnull(vm); - - return 1; -} - -int ELSAPI_stdfile_fseek(els_VmObj* vm) // fseek(fp: ptr,i: int,sp: int):int '设置流 fp 的文件位置为给定的偏移 i,参数i 意味着从给定的 sp 位置查找的字节数' -{ - int i = fseek((FILE*)(arg_getptr(vm,1)),(int)(arg_getnum(vm,2)),(int)(arg_getnum(vm,3))); - if(i) arg_returnnum(vm,i); - else arg_returnnull(vm); - - return 1; -} -int ELSAPI_stdfile_ftell(els_VmObj* vm) // ftell(fp: ptr): int '返回文件当前位置,以文件头为相对位置' -{ - arg_returnnum(vm,(Number)(ftell((FILE*)(arg_getptr(vm,1))))); - return 1; -} -int ELSAPI_stdfile_rewind(els_VmObj* vm) // rewind(fp: prt): null '返回文件头' -{ - rewind((FILE*)(arg_getptr(vm,1))); - arg_returnnull(vm); - return 1; -} - - diff --git a/stdfile/info b/stdfile/info deleted file mode 100755 index b2de4fe8f6a82331e1c520d66bd5036dc856eb07..0000000000000000000000000000000000000000 --- a/stdfile/info +++ /dev/null @@ -1,24 +0,0 @@ -{ - type = "const", - info = { - name = "stdfile/标准库(文件)", - text = "stdlib中的文件函数部分", - version = "23.12.1" - }, - source = { - all = { - "stdfile.els", - "stdfile.h" - }, - Ubuntu = { - "stdfile.c","makefile" - }, - Windows = { - "stdfile.c","makefile" - }, - }, - target = { - Ubuntu = "make ; cp ElsLib_stdfile.lsd target/ElsLib_stdfile.lsd_Ubuntu ; make clean", - Windows = "make ; cp ElsLib_stdfile.lsd target/ElsLib_stdfile.lsd_Windows ; make clean", - } -} \ No newline at end of file diff --git a/stdfile/readme.md b/stdfile/readme.md deleted file mode 100755 index 259fd471150246f54eaef33aa1b655a6d287c64c..0000000000000000000000000000000000000000 --- a/stdfile/readme.md +++ /dev/null @@ -1,125 +0,0 @@ -#!/bin/owls.wiki.losu.tech -# stdlib (stdfile) - -```python -#!declare -fopen(fname: str,mod: str): ptr '以指定模式打开一个文件,mod对应C语言,失败返回null' -fclose(fp: ptr): int '关闭一个文件,成功返回0,失败返回null' -fputc(fp: ptr,c: [int]): int 'c 的字符值写入到 fp 所指向的输出流中。如果写入成功,它会返回写入的字符,如果发生错误,则会返回 null' -fputs(fp: ptr,s: str): int 's 写入到 fp 所指向的输出流中。如果写入成功,它会返回一个非负值,如果发生错误,则会返回 null' -fgetc(fp: ptr): int '函数从 fp 所指向的输入文件中读取一个字符。返回值是读取的字符,如果发生错误则返回 null' -finput(fp:ptr): str '从 fp 所指向文件中读取一个字段,遇到空格等结束' -fgets(fp: ptr, int n): str '从 fp 所指向的输入流中读取 n-1 个字符"如果n为null,则读取为内核最大字符缓冲区"如果这个函数在读取最后一个字符之前就遇到一个换行符或文件的末尾 null,则只会返回读取到的字符,包括换行符' -feof(fp: ptr): int 'fp 是否到达结尾,否返回 null' -fseek(fp: ptr,i: int,sp: int):int '设置流 fp 的文件位置为给定的偏移 i,参数i 意味着从给定的 sp 位置查找的字节数' -ftell(fp: ptr): int '返回文件当前位置,以文件头为相对位置' -rewind(fp: prt): null '返回文件头' -#!end -#!script -file = {} -def file.open(fn,mod): - ''' - fn是文件名,mod 是打开模式 - mod 是与C函数fopen的第二个参数相同的模式参数,具体如下 - 模式 描述 - "r" 打开一个用于读取的文件。该文件必须存在。 - "w" 创建一个用于写入的空文件。如果文件名称与已存在的文件相同,则会删除已有文件的内容,文件被视为一个新的空文件。 - "a" 追加到一个文件。写操作向文件末尾追加数据。如果文件不存在,则创建文件。 - "r+" 打开一个用于更新的文件,可读取也可写入。该文件必须存在。 - "w+" 创建一个用于读写的空文件。 - "a+" 打开一个用于读取和追加的文件。 - - ''' - - var this = {} - - this.FILE = fopen(fn,mod) - if this.FILE == null : return null ; - - this.filename = fn - this.mod = mod - - def this.close(): - return fclose(this.FILE) - ; - def this.putc(i): - return fputc(this.FILE,i) - ; - def this.print(s): - return fputs(this.FILE,s) - ; - - def this.gets(i): # 读取i个字符,与fgets不一样 - return fgets(this.FILE,i) - ; - def this.getc(): - return fgetc(this.FILE) - ; - def this.input(): - return finput(this.FILE) - ; - def this.lineinput(): - return fgets(this.FILE) - ; - def this.eof(): - return feof(this.FILE) - ; - def this.seek(i,sp): - return fseek(this.FILE,i,sp) - ; - def this.tell(): - return ftell(this.FILE) - ; - - return this -; -#!end -#!script-cn -文件 = {} -def 文件.打开(fn,mod): - - var this = {} - - this.FILE = fopen(fn,mod) - if this.FILE == null : return null ; - - this.文件名 = fn - this.模式 = mod - - def this.关闭(): - return fclose(this.FILE) - ; - def this.写字节(i): - return fputc(this.FILE,i) - ; - def this.打印(s): - return fputs(this.FILE,s) - ; - - def this.读取(i): - return fgets(this.FILE,i) - ; - def this.读字节(): - return fgetc(this.FILE) - ; - def this.输入(): - return finput(this.FILE) - ; - def this.输入一行(): - return fgets(this.FILE) - ; - def this.文件尾(): - return feof(this.FILE) - ; - def this.定位(i,sp): - return fseek(this.FILE,i,sp) - ; - def this.当前位置(): - return ftell(this.FILE) - ; - - return this -; -#!end - -``` \ No newline at end of file diff --git a/stdfile/stdfile.els b/stdfile/stdfile.els deleted file mode 100755 index c7aa9b5493194b9a4edb4487844b6b5e899393c8..0000000000000000000000000000000000000000 --- a/stdfile/stdfile.els +++ /dev/null @@ -1,119 +0,0 @@ -#!declare -fopen(fname: str,mod: str): ptr '以指定模式打开一个文件,mod对应C语言,失败返回null' -fclose(fp: ptr): int '关闭一个文件,成功返回0,失败返回null' -fputc(fp: ptr,c: [int]): int 'c 的字符值写入到 fp 所指向的输出流中。如果写入成功,它会返回写入的字符,如果发生错误,则会返回 null' -fputs(fp: ptr,s: str): int 's 写入到 fp 所指向的输出流中。如果写入成功,它会返回一个非负值,如果发生错误,则会返回 null' -fgetc(fp: ptr): int '函数从 fp 所指向的输入文件中读取一个字符。返回值是读取的字符,如果发生错误则返回 null' -finput(fp:ptr): str '从 fp 所指向文件中读取一个字段,遇到空格等结束' -fgets(fp: ptr, int n): str '从 fp 所指向的输入流中读取 n-1 个字符"如果n为null,则读取为内核最大字符缓冲区"如果这个函数在读取最后一个字符之前就遇到一个换行符或文件的末尾 null,则只会返回读取到的字符,包括换行符' -feof(fp: ptr): int 'fp 是否到达结尾,否返回 null' -fseek(fp: ptr,i: int,sp: int):int '设置流 fp 的文件位置为给定的偏移 i,参数i 意味着从给定的 sp 位置查找的字节数' -ftell(fp: ptr): int '返回文件当前位置,以文件头为相对位置' -rewind(fp: prt): null '返回文件头' -#!end -#!script -file = {} -def file.open(fn,mod): - ''' - fn是文件名,mod 是打开模式 - mod 是与C函数fopen的第二个参数相同的模式参数,具体如下 - 模式 描述 - "r" 打开一个用于读取的文件。该文件必须存在。 - "w" 创建一个用于写入的空文件。如果文件名称与已存在的文件相同,则会删除已有文件的内容,文件被视为一个新的空文件。 - "a" 追加到一个文件。写操作向文件末尾追加数据。如果文件不存在,则创建文件。 - "r+" 打开一个用于更新的文件,可读取也可写入。该文件必须存在。 - "w+" 创建一个用于读写的空文件。 - "a+" 打开一个用于读取和追加的文件。 - - ''' - - var this = {} - - this.FILE = fopen(fn,mod) - if this.FILE == null : return null ; - - this.filename = fn - this.mod = mod - - def this.close(): - return fclose(this.FILE) - ; - def this.putc(i): - return fputc(this.FILE,i) - ; - def this.print(s): - return fputs(this.FILE,s) - ; - - def this.gets(i): # 读取i个字符,与fgets不一样 - return fgets(this.FILE,i) - ; - def this.getc(): - return fgetc(this.FILE) - ; - def this.input(): - return finput(this.FILE) - ; - def this.lineinput(): - return fgets(this.FILE) - ; - def this.eof(): - return feof(this.FILE) - ; - def this.seek(i,sp): - return fseek(this.FILE,i,sp) - ; - def this.tell(): - return ftell(this.FILE) - ; - - return this -; -#!end -#!script-cn -文件 = {} -def 文件.打开(fn,mod): - - var this = {} - - this.FILE = fopen(fn,mod) - if this.FILE == null : return null ; - - this.文件名 = fn - this.模式 = mod - - def this.关闭(): - return fclose(this.FILE) - ; - def this.写字节(i): - return fputc(this.FILE,i) - ; - def this.打印(s): - return fputs(this.FILE,s) - ; - - def this.读取(i): - return fgets(this.FILE,i) - ; - def this.读字节(): - return fgetc(this.FILE) - ; - def this.输入(): - return finput(this.FILE) - ; - def this.输入一行(): - return fgets(this.FILE) - ; - def this.文件尾(): - return feof(this.FILE) - ; - def this.定位(i,sp): - return fseek(this.FILE,i,sp) - ; - def this.当前位置(): - return ftell(this.FILE) - ; - - return this -; -#!end diff --git a/stdfile/stdfile.h b/stdfile/stdfile.h deleted file mode 100755 index 3b4dfed15a6437009057082492c2f09f3affe66b..0000000000000000000000000000000000000000 --- a/stdfile/stdfile.h +++ /dev/null @@ -1,141 +0,0 @@ -#include "els.h" -int ELSAPI_stdfile_fopen(els_VmObj* vm); // fopen(fname: str,mod: str): ptr '以指定模式打开一个文件,mod对应C语言,失败返回null' -int ELSAPI_stdfile_fclose(els_VmObj* vm); // fclose(fp: ptr): int '关闭一个文件,成功返回0,失败返回null' -int ELSAPI_stdfile_fputc(els_VmObj* vm); // fputc(fp: ptr,c: [int]): int 'c 的字符值写入到 fp 所指向的输出流中。如果写入成功,它会返回写入的字符,如果发生错误,则会返回 null' -int ELSAPI_stdfile_fputs(els_VmObj* vm); // fputs(fp: ptr,s: str): int 's 写入到 fp 所指向的输出流中。如果写入成功,它会返回一个非负值,如果发生错误,则会返回 null' -int ELSAPI_stdfile_fgetc(els_VmObj* vm); // fgetc(fp: ptr): int '函数从 fp 所指向的输入文件中读取一个字符。返回值是读取的字符,如果发生错误则返回 null' -int ELSAPI_stdfile_finput(els_VmObj* vm); // finput(fp:ptr): str '从 fp 所指向文件中读取一个字段,遇到空格等结束' -int ELSAPI_stdfile_fgets(els_VmObj* vm); // fgets(fp: ptr, int n): str '从 fp 所指向的输入流中读取 n-1 个字符"如果n为null,则读取为内核最大字符缓冲区"如果这个函数在读取最后一个字符之前就遇到一个换行符或文件的末尾 null,则只会返回读取到的字符,包括换行符' -int ELSAPI_stdfile_feof(els_VmObj* vm); // feof(fp: ptr): int 'fp 是否到达结尾,否返回 null' -int ELSAPI_stdfile_fseek(els_VmObj* vm); // fseek(fp: ptr,i: int,sp: int):int '设置流 fp 的文件位置为给定的偏移 i,参数i 意味着从给定的 sp 位置查找的字节数' -int ELSAPI_stdfile_ftell(els_VmObj* vm); // ftell(fp: ptr): int '返回文件当前位置,以文件头为相对位置' -int ELSAPI_stdfile_rewind(els_VmObj* vm); // rewind(fp: prt): null '返回文件头' -#ifdef ELS_CONF_TOKEN_EN -static const char LibScript[]={ -102,105,108,101,32,61,32,123,125,10, -100,101,102,32,102,105,108,101,46,111,112,101,110,40,102,110,44,109,111,100,41,58,10, -32,32,32,32,39,39,39,10, -32,32,32,32,32,32,32,32,102,110,-26,-104,-81,-26,-106,-121,-28,-69,-74,-27,-112,-115,44,109,111,100,32,-26,-104,-81,-26,-119,-109,-27,-68,-128,-26,-88,-95,-27,-68,-113,10, -32,32,32,32,32,32,32,32,109,111,100,32,-26,-104,-81,-28,-72,-114,67,-27,-121,-67,-26,-107,-80,102,111,112,101,110,-25,-102,-124,-25,-84,-84,-28,-70,-116,-28,-72,-86,-27,-113,-126,-26,-107,-80,-25,-101,-72,-27,-112,-116,-25,-102,-124,-26,-88,-95,-27,-68,-113,-27,-113,-126,-26,-107,-80,44,-27,-123,-73,-28,-67,-109,-27,-90,-126,-28,-72,-117,10, -32,32,32,32,32,32,32,32,-26,-88,-95,-27,-68,-113,32,32,32,32,32,-26,-113,-113,-24,-65,-80,10, -32,32,32,32,32,32,32,32,34,114,34,32,32,32,32,32,-26,-119,-109,-27,-68,-128,-28,-72,-128,-28,-72,-86,-25,-108,-88,-28,-70,-114,-24,-81,-69,-27,-113,-106,-25,-102,-124,-26,-106,-121,-28,-69,-74,-29,-128,-126,-24,-81,-91,-26,-106,-121,-28,-69,-74,-27,-65,-123,-23,-95,-69,-27,-83,-104,-27,-100,-88,-29,-128,-126,10, -32,32,32,32,32,32,32,32,34,119,34,9,32,32,32,32,-27,-120,-101,-27,-69,-70,-28,-72,-128,-28,-72,-86,-25,-108,-88,-28,-70,-114,-27,-122,-103,-27,-123,-91,-25,-102,-124,-25,-87,-70,-26,-106,-121,-28,-69,-74,-29,-128,-126,-27,-90,-126,-26,-98,-100,-26,-106,-121,-28,-69,-74,-27,-112,-115,-25,-89,-80,-28,-72,-114,-27,-73,-78,-27,-83,-104,-27,-100,-88,-25,-102,-124,-26,-106,-121,-28,-69,-74,-25,-101,-72,-27,-112,-116,-17,-68,-116,-27,-120,-103,-28,-68,-102,-27,-120,-96,-23,-103,-92,-27,-73,-78,-26,-100,-119,-26,-106,-121,-28,-69,-74,-25,-102,-124,-27,-122,-123,-27,-82,-71,-17,-68,-116,-26,-106,-121,-28,-69,-74,-24,-94,-85,-24,-89,-122,-28,-72,-70,-28,-72,-128,-28,-72,-86,-26,-106,-80,-25,-102,-124,-25,-87,-70,-26,-106,-121,-28,-69,-74,-29,-128,-126,10, -32,32,32,32,32,32,32,32,34,97,34,9,32,32,32,32,-24,-65,-67,-27,-118,-96,-27,-120,-80,-28,-72,-128,-28,-72,-86,-26,-106,-121,-28,-69,-74,-29,-128,-126,-27,-122,-103,-26,-109,-115,-28,-67,-100,-27,-112,-111,-26,-106,-121,-28,-69,-74,-26,-100,-85,-27,-80,-66,-24,-65,-67,-27,-118,-96,-26,-107,-80,-26,-115,-82,-29,-128,-126,-27,-90,-126,-26,-98,-100,-26,-106,-121,-28,-69,-74,-28,-72,-115,-27,-83,-104,-27,-100,-88,-17,-68,-116,-27,-120,-103,-27,-120,-101,-27,-69,-70,-26,-106,-121,-28,-69,-74,-29,-128,-126,10, -32,32,32,32,32,32,32,32,34,114,43,34,9,-26,-119,-109,-27,-68,-128,-28,-72,-128,-28,-72,-86,-25,-108,-88,-28,-70,-114,-26,-101,-76,-26,-106,-80,-25,-102,-124,-26,-106,-121,-28,-69,-74,-17,-68,-116,-27,-113,-81,-24,-81,-69,-27,-113,-106,-28,-71,-97,-27,-113,-81,-27,-122,-103,-27,-123,-91,-29,-128,-126,-24,-81,-91,-26,-106,-121,-28,-69,-74,-27,-65,-123,-23,-95,-69,-27,-83,-104,-27,-100,-88,-29,-128,-126,10, -32,32,32,32,32,32,32,32,34,119,43,34,9,-27,-120,-101,-27,-69,-70,-28,-72,-128,-28,-72,-86,-25,-108,-88,-28,-70,-114,-24,-81,-69,-27,-122,-103,-25,-102,-124,-25,-87,-70,-26,-106,-121,-28,-69,-74,-29,-128,-126,10, -32,32,32,32,32,32,32,32,34,97,43,34,9,-26,-119,-109,-27,-68,-128,-28,-72,-128,-28,-72,-86,-25,-108,-88,-28,-70,-114,-24,-81,-69,-27,-113,-106,-27,-110,-116,-24,-65,-67,-27,-118,-96,-25,-102,-124,-26,-106,-121,-28,-69,-74,-29,-128,-126,10, -10, -32,32,32,32,39,39,39,10, -10, -32,32,32,32,118,97,114,32,116,104,105,115,32,61,32,123,125,10, -32,32,32,32,10, -32,32,32,32,116,104,105,115,46,70,73,76,69,32,61,32,102,111,112,101,110,40,102,110,44,109,111,100,41,10, -32,32,32,32,105,102,32,116,104,105,115,46,70,73,76,69,32,61,61,32,110,117,108,108,32,58,32,114,101,116,117,114,110,32,110,117,108,108,32,59,10, -32,32,32,32,10, -32,32,32,32,116,104,105,115,46,102,105,108,101,110,97,109,101,32,61,32,102,110,10, -32,32,32,32,116,104,105,115,46,109,111,100,32,61,32,109,111,100,10, -32,32,32,32,10, -32,32,32,32,100,101,102,32,116,104,105,115,46,99,108,111,115,101,40,41,58,10, -32,32,32,32,32,32,32,32,114,101,116,117,114,110,32,102,99,108,111,115,101,40,116,104,105,115,46,70,73,76,69,41,10, -32,32,32,32,59,10, -32,32,32,32,100,101,102,32,116,104,105,115,46,112,117,116,99,40,105,41,58,10, -32,32,32,32,32,32,32,32,114,101,116,117,114,110,32,102,112,117,116,99,40,116,104,105,115,46,70,73,76,69,44,105,41,10, -32,32,32,32,59,10, -32,32,32,32,100,101,102,32,116,104,105,115,46,112,114,105,110,116,40,115,41,58,10, -32,32,32,32,32,32,32,32,114,101,116,117,114,110,32,102,112,117,116,115,40,116,104,105,115,46,70,73,76,69,44,115,41,10, -32,32,32,32,59,10, -10, -32,32,32,32,100,101,102,32,116,104,105,115,46,103,101,116,115,40,105,41,58,32,35,32,-24,-81,-69,-27,-113,-106,105,-28,-72,-86,-27,-83,-105,-25,-84,-90,-17,-68,-116,-28,-72,-114,102,103,101,116,115,-28,-72,-115,-28,-72,-128,-26,-96,-73,10, -32,32,32,32,32,32,32,32,114,101,116,117,114,110,32,102,103,101,116,115,40,116,104,105,115,46,70,73,76,69,44,105,41,10, -32,32,32,32,59,10, -32,32,32,32,100,101,102,32,116,104,105,115,46,103,101,116,99,40,41,58,10, -32,32,32,32,32,32,32,32,114,101,116,117,114,110,32,102,103,101,116,99,40,116,104,105,115,46,70,73,76,69,41,32,32,32,32,10, -32,32,32,32,59,10, -32,32,32,32,100,101,102,32,116,104,105,115,46,105,110,112,117,116,40,41,58,10, -32,32,32,32,32,32,32,32,114,101,116,117,114,110,32,102,105,110,112,117,116,40,116,104,105,115,46,70,73,76,69,41,10, -32,32,32,32,59,10, -32,32,32,32,100,101,102,32,116,104,105,115,46,108,105,110,101,105,110,112,117,116,40,41,58,10, -32,32,32,32,32,32,32,32,114,101,116,117,114,110,32,102,103,101,116,115,40,116,104,105,115,46,70,73,76,69,41,10, -32,32,32,32,59,10, -32,32,32,32,100,101,102,32,116,104,105,115,46,101,111,102,40,41,58,10, -32,32,32,32,32,32,32,32,114,101,116,117,114,110,32,102,101,111,102,40,116,104,105,115,46,70,73,76,69,41,10, -32,32,32,32,59,10, -32,32,32,32,100,101,102,32,116,104,105,115,46,115,101,101,107,40,105,44,115,112,41,58,10, -32,32,32,32,32,32,32,32,114,101,116,117,114,110,32,102,115,101,101,107,40,116,104,105,115,46,70,73,76,69,44,105,44,115,112,41,10, -32,32,32,32,59,10, -32,32,32,32,100,101,102,32,116,104,105,115,46,116,101,108,108,40,41,58,10, -32,32,32,32,32,32,32,32,114,101,116,117,114,110,32,102,116,101,108,108,40,116,104,105,115,46,70,73,76,69,41,32,32,32,32,10, -32,32,32,32,59,10, -10, -32,32,32,32,114,101,116,117,114,110,32,116,104,105,115,10, -59,10, -0}; -#endif -#ifdef ELS_CONF_TOKEN_CN -static const char LibScript_cn[]={ --26,-106,-121,-28,-69,-74,32,61,32,123,125,10, -100,101,102,32,-26,-106,-121,-28,-69,-74,46,-26,-119,-109,-27,-68,-128,40,102,110,44,109,111,100,41,58,10, -32,32,32,32,10, -32,32,32,32,118,97,114,32,116,104,105,115,32,61,32,123,125,10, -32,32,32,32,10, -32,32,32,32,116,104,105,115,46,70,73,76,69,32,61,32,102,111,112,101,110,40,102,110,44,109,111,100,41,10, -32,32,32,32,105,102,32,116,104,105,115,46,70,73,76,69,32,61,61,32,110,117,108,108,32,58,32,114,101,116,117,114,110,32,110,117,108,108,32,59,10, -32,32,32,32,10, -32,32,32,32,116,104,105,115,46,-26,-106,-121,-28,-69,-74,-27,-112,-115,32,61,32,102,110,10, -32,32,32,32,116,104,105,115,46,-26,-88,-95,-27,-68,-113,32,61,32,109,111,100,10, -32,32,32,32,10, -32,32,32,32,100,101,102,32,116,104,105,115,46,-27,-123,-77,-23,-105,-83,40,41,58,10, -32,32,32,32,32,32,32,32,114,101,116,117,114,110,32,102,99,108,111,115,101,40,116,104,105,115,46,70,73,76,69,41,10, -32,32,32,32,59,10, -32,32,32,32,100,101,102,32,116,104,105,115,46,-27,-122,-103,-27,-83,-105,-24,-118,-126,40,105,41,58,10, -32,32,32,32,32,32,32,32,114,101,116,117,114,110,32,102,112,117,116,99,40,116,104,105,115,46,70,73,76,69,44,105,41,10, -32,32,32,32,59,10, -32,32,32,32,100,101,102,32,116,104,105,115,46,-26,-119,-109,-27,-115,-80,40,115,41,58,10, -32,32,32,32,32,32,32,32,114,101,116,117,114,110,32,102,112,117,116,115,40,116,104,105,115,46,70,73,76,69,44,115,41,10, -32,32,32,32,59,10, -10, -32,32,32,32,100,101,102,32,116,104,105,115,46,-24,-81,-69,-27,-113,-106,40,105,41,58,10, -32,32,32,32,32,32,32,32,114,101,116,117,114,110,32,102,103,101,116,115,40,116,104,105,115,46,70,73,76,69,44,105,41,10, -32,32,32,32,59,10, -32,32,32,32,100,101,102,32,116,104,105,115,46,-24,-81,-69,-27,-83,-105,-24,-118,-126,40,41,58,10, -32,32,32,32,32,32,32,32,114,101,116,117,114,110,32,102,103,101,116,99,40,116,104,105,115,46,70,73,76,69,41,32,32,32,32,10, -32,32,32,32,59,10, -32,32,32,32,100,101,102,32,116,104,105,115,46,-24,-66,-109,-27,-123,-91,40,41,58,10, -32,32,32,32,32,32,32,32,114,101,116,117,114,110,32,102,105,110,112,117,116,40,116,104,105,115,46,70,73,76,69,41,10, -32,32,32,32,59,10, -32,32,32,32,100,101,102,32,116,104,105,115,46,-24,-66,-109,-27,-123,-91,-28,-72,-128,-24,-95,-116,40,41,58,10, -32,32,32,32,32,32,32,32,114,101,116,117,114,110,32,102,103,101,116,115,40,116,104,105,115,46,70,73,76,69,41,10, -32,32,32,32,59,10, -32,32,32,32,100,101,102,32,116,104,105,115,46,-26,-106,-121,-28,-69,-74,-27,-80,-66,40,41,58,10, -32,32,32,32,32,32,32,32,114,101,116,117,114,110,32,102,101,111,102,40,116,104,105,115,46,70,73,76,69,41,10, -32,32,32,32,59,10, -32,32,32,32,100,101,102,32,116,104,105,115,46,-27,-82,-102,-28,-67,-115,40,105,44,115,112,41,58,10, -32,32,32,32,32,32,32,32,114,101,116,117,114,110,32,102,115,101,101,107,40,116,104,105,115,46,70,73,76,69,44,105,44,115,112,41,10, -32,32,32,32,59,10, -32,32,32,32,100,101,102,32,116,104,105,115,46,-27,-67,-109,-27,-119,-115,-28,-67,-115,-25,-67,-82,40,41,58,10, -32,32,32,32,32,32,32,32,114,101,116,117,114,110,32,102,116,101,108,108,40,116,104,105,115,46,70,73,76,69,41,32,32,32,32,10, -32,32,32,32,59,10, -10, -32,32,32,32,114,101,116,117,114,110,32,116,104,105,115,32,32,32,32,10, -59,10, -0}; -#endif -void ElsLib_stdfile_libinit(els_VmObj *vm){ - vm_register(vm,"fputc",ELSAPI_stdfile_fputc); - vm_register(vm,"ftell",ELSAPI_stdfile_ftell); - vm_register(vm,"rewind",ELSAPI_stdfile_rewind); - vm_register(vm,"feof",ELSAPI_stdfile_feof); - vm_register(vm,"finput",ELSAPI_stdfile_finput); - vm_register(vm,"fgets",ELSAPI_stdfile_fgets); - vm_register(vm,"fputs",ELSAPI_stdfile_fputs); - vm_register(vm,"fopen",ELSAPI_stdfile_fopen); - vm_register(vm,"fclose",ELSAPI_stdfile_fclose); - vm_register(vm,"fseek",ELSAPI_stdfile_fseek); - vm_register(vm,"fgetc",ELSAPI_stdfile_fgetc); - #ifdef ELS_CONF_TOKEN_EN - vm_dostring(vm,LibScript); - #endif - #ifdef ELS_CONF_TOKEN_CN - vm_dostring(vm,LibScript_cn); - #endif -}; diff --git a/stdlib/Ubuntu/makefile b/stdlib/Ubuntu/makefile deleted file mode 100755 index 5648a97b8d664e54f5620b862cad2a56cec49e41..0000000000000000000000000000000000000000 --- a/stdlib/Ubuntu/makefile +++ /dev/null @@ -1,13 +0,0 @@ -OBJS = stdlib.o -CFLAGS= -O2 -Wall -std=c99 -DELS_CONF_OS_LINUX -I ../buildenv -fPIC -CC=x86_64-linux-gnu-gcc -T=./ElsLib_stdlib.lsd - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -shared -s - -clean: - rm -rf $T $(OBJS) core core.* \ No newline at end of file diff --git a/stdlib/Windows/makefile b/stdlib/Windows/makefile deleted file mode 100755 index f72c0185622b21e760b44f1732d26964a5f81a72..0000000000000000000000000000000000000000 --- a/stdlib/Windows/makefile +++ /dev/null @@ -1,13 +0,0 @@ -OBJS = stdlib.o -CFLAGS= -O2 -Wall -std=c99 -DELS_CONF_OS_WINDOWS -I ../buildenv -fPIC -CC=x86_64-w64-mingw32-gcc -T=./ElsLib_stdlib.lsd - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -shared -s -L ../buildenv -l:libeasylosu.dll -static - -clean: - rm -rf $T $(OBJS) core core.* \ No newline at end of file diff --git a/stdlib/info b/stdlib/info deleted file mode 100755 index 1adc977ee9216d51991bdeb72734b420069276de..0000000000000000000000000000000000000000 --- a/stdlib/info +++ /dev/null @@ -1,19 +0,0 @@ -{ - type = "const", - info = { - name = "stdlib/标准库", - text = "stdlib接口", - version = "23.11.26" - }, - source = { - all ={ - "stdlib.els","stdlib.h","stdlib.c" - }, - Ubuntu = {"makefile"}, - Windows = {"makefile"} - }, - target = { - Ubuntu = "make ; cp ElsLib_stdlib.lsd target/ElsLib_stdlib.lsd_Ubuntu ; make clean", - Windows = "make ; cp ElsLib_stdlib.lsd target/ElsLib_stdlib.lsd_Windows ; make clean", - } -} \ No newline at end of file diff --git a/stdlib/readme.md b/stdlib/readme.md deleted file mode 100755 index 292eb04caebe925bf51cb287c805149c112bd378..0000000000000000000000000000000000000000 --- a/stdlib/readme.md +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/owls.wiki.losu.tech -# stdlib -+ stdlib 是洛书的标准库,由 IO ,字节,文件,数学,字符串,系统,多线程,时间,虚拟机等多个模块组合而成 - -```python -import "stdlib" - -``` - -相当于 - -```python -import "std" -import "stdbyte" -import "stdfile" -import "stdmath" -import "stdstring" -import "stdsys" -import "stdthread" -import "stdtime" -import "stdvm" - -``` \ No newline at end of file diff --git a/stdlib/stdlib.c b/stdlib/stdlib.c deleted file mode 100755 index b52597557c2b673415c6eb1d09169b9998461801..0000000000000000000000000000000000000000 --- a/stdlib/stdlib.c +++ /dev/null @@ -1 +0,0 @@ -#include "stdlib.h" diff --git a/stdlib/stdlib.els b/stdlib/stdlib.els deleted file mode 100755 index 29adf6e70784d3e620168703ed56f288fbeb62d1..0000000000000000000000000000000000000000 --- a/stdlib/stdlib.els +++ /dev/null @@ -1,11 +0,0 @@ -#!script -import "std" -import "stdbyte" -import "stdfile" -import "stdmath" -import "stdstring" -import "stdsys" -import "stdthread" -import "stdtime" -import "stdvm" -#!end \ No newline at end of file diff --git a/stdlib/stdlib.h b/stdlib/stdlib.h deleted file mode 100755 index aa0a0d0604491ec227637d2b6d7fcf34caab2c8b..0000000000000000000000000000000000000000 --- a/stdlib/stdlib.h +++ /dev/null @@ -1,19 +0,0 @@ -#include "els.h" -#ifdef ELS_CONF_TOKEN_EN -static const char LibScript[]={ -105,109,112,111,114,116,32,34,115,116,100,34,10, -105,109,112,111,114,116,32,34,115,116,100,98,121,116,101,34,10, -105,109,112,111,114,116,32,34,115,116,100,102,105,108,101,34,10, -105,109,112,111,114,116,32,34,115,116,100,109,97,116,104,34,10, -105,109,112,111,114,116,32,34,115,116,100,115,116,114,105,110,103,34,10, -105,109,112,111,114,116,32,34,115,116,100,115,121,115,34,10, -105,109,112,111,114,116,32,34,115,116,100,116,104,114,101,97,100,34,10, -105,109,112,111,114,116,32,34,115,116,100,116,105,109,101,34,10, -105,109,112,111,114,116,32,34,115,116,100,118,109,34,10, -0}; -#endif -void ElsLib_stdlib_libinit(els_VmObj *vm){ - #ifdef ELS_CONF_TOKEN_EN - vm_dostring(vm,LibScript); - #endif -}; diff --git a/stdmath/Ubuntu/makefile b/stdmath/Ubuntu/makefile deleted file mode 100755 index c3d2515d9fd9e705ce52909190dffafcb2b43614..0000000000000000000000000000000000000000 --- a/stdmath/Ubuntu/makefile +++ /dev/null @@ -1,13 +0,0 @@ -OBJS = stdmath.o -CFLAGS= -O2 -Wall -std=gnu99 -DELS_CONF_OS_LINUX -I ../buildenv -fPIC -CC=x86_64-linux-gnu-gcc -T=./ElsLib_stdmath.lsd - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -shared -lm -s - -clean: - rm -rf $T $(OBJS) core core.* \ No newline at end of file diff --git a/stdmath/Windows/makefile b/stdmath/Windows/makefile deleted file mode 100755 index 0d6994519e986d6c241fbdf632d4e10d139b0e86..0000000000000000000000000000000000000000 --- a/stdmath/Windows/makefile +++ /dev/null @@ -1,13 +0,0 @@ -OBJS = stdmath.o -CFLAGS= -O2 -Wall -std=gnu99 -DELS_CONF_OS_WINDOWS -I ../buildenv -fPIC -CC=x86_64-w64-mingw32-gcc -T=./ElsLib_stdmath.lsd - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -shared -lm -s -L ../buildenv -l:libeasylosu.dll -static - -clean: - rm -rf $T $(OBJS) core core.* \ No newline at end of file diff --git a/stdmath/info b/stdmath/info deleted file mode 100755 index bdf603e3b653ec9e0f11cd30e7858eeeeab406e5..0000000000000000000000000000000000000000 --- a/stdmath/info +++ /dev/null @@ -1,17 +0,0 @@ -{ - type = "const", - info = { - name = "stdmath/标准库(数学)", - text = "stdlib中的数学函数部分", - version = "23.10.20" - }, - source = { - all = {"stdmath.els","stdmath.h","stdmath.c"}, - Ubuntu = {"makefile"}, - Windows ={"makefile"}, - }, - target={ - Ubuntu = "make ; cp ElsLib_stdmath.lsd target/ElsLib_stdmath.lsd_Ubuntu ; make clean", - Windows = "make ; cp ElsLib_stdmath.lsd target/ElsLib_stdmath.lsd_Windows ; make clean", - } -} \ No newline at end of file diff --git a/stdmath/readme.md b/stdmath/readme.md deleted file mode 100755 index e047dfd574e70bcbda1105e220e6d023200b79df..0000000000000000000000000000000000000000 --- a/stdmath/readme.md +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/owls.wiki.losu.tech -``` -# stdlib (stdmath) -#!declare -# 常量定义 -PI(): float #返回π的值 -E(): float #返回e的值 -GAMMA(): float #返回γ(欧拉常数)的值 -# 标准数学函数 -abs( num ) #返回数的绝对值 -mod( a, b ) #返回a mod b的结果 -acos( x ) #返回以弧度表示的x的反余弦 -asin( x ) #返回以弧度表示的x的反正弦 -atan( x ) #返回以弧度表示的x的反正切 -cos( x ) #返回x的余弦值 -sin( x ) #返回x的正弦值 -tan( x ) #返回x的正切值 -exp( x ) #返回e的x次幂的值 -log( a, N ) #返回以a为第N的对数 -ln( N ) #返回以e为底,N的对数 -lg( N ) #返回以10为底,N的对数 -sqrt( num:number ): float #返回num的平方根 -ceil( num:float ): float #对num向上取整 -floor( num:float ): float #对num向下取整 -round( num:float ): float #将小数四舍五入成整数 -cut( num:float, x:int): float #截取小数到若干位 -#!end - -#!script-cn - -圆周率 = PI -自然常数 = E -欧拉常数 = GAMMA - -绝对值 = abs -取模 = mod -反余弦 = acos -反正弦 = asin -反正切 = atan -余弦 = cos -正弦 = sin -正切 = tan -对数 = log - #exp起名空缺 - #ln起名空缺 - #lg起名空缺 -开平方 = sqrt -向上取整 = ceil -向下取整 = floor -四舍五入 = round -保留位数 = cut - -#!end -``` diff --git a/stdmath/stdmath.c b/stdmath/stdmath.c deleted file mode 100755 index e0ef39fc0be222917dca5b6f43bd41bf00d92bb0..0000000000000000000000000000000000000000 --- a/stdmath/stdmath.c +++ /dev/null @@ -1,143 +0,0 @@ -#include "stdmath.h" -#include - -#define PI 3.141592653589793 -#define E 2.718281828459045 -#define GAMMA 0.577215664901532 - -int ELSAPI_stdmath_PI(els_VmObj* vm){ - /* - 返回π(圆周率)的值 - - # 参数 - 无参数 - - # 返回值 - 1.π - */ - arg_returnnum(vm, PI); - return 1; -} -int ELSAPI_stdmath_E(els_VmObj* vm){ - /* - 返回e(自然常数)的值 - - # 参数 - 无参数 - - # 返回值 - 1.e - */ - arg_returnnum(vm, E); - return 1; -} -int ELSAPI_stdmath_GAMMA(els_VmObj* vm){ - /* - 返回gamma(欧拉常数)的值 - - # 参数 - 无参数 - - # 返回值 - 1.gamma - */ - arg_returnnum(vm, GAMMA); - return 1; -} -int ELSAPI_stdmath_abs(els_VmObj *vm){ - arg_returnnum(vm,fabs(arg_getnum(vm,1))); - return 1; -} -int ELSAPI_stdmath_mod(els_VmObj *vm){ - arg_returnnum(vm,((long int)arg_getnum(vm,1)%(long int)arg_getnum(vm,2))); - return 1; -} -int ELSAPI_stdmath_acos(els_VmObj *vm){ - arg_returnnum(vm,acos(arg_getnum(vm,1))); - return 1; -} -int ELSAPI_stdmath_asin(els_VmObj *vm){ - arg_returnnum(vm,asin(arg_getnum(vm,1))); - return 1; -} -int ELSAPI_stdmath_atan(els_VmObj *vm){ - arg_returnnum(vm,atan(arg_getnum(vm,1))); - return 1; -} -int ELSAPI_stdmath_cos(els_VmObj *vm){ - arg_returnnum(vm,cos(arg_getnum(vm,1))); - return 1; -} -int ELSAPI_stdmath_sin(els_VmObj *vm){ - arg_returnnum(vm,sin(arg_getnum(vm,1))); - return 1; -} -int ELSAPI_stdmath_tan(els_VmObj *vm){ - arg_returnnum(vm,tan(arg_getnum(vm,1))); - return 1; -} -int ELSAPI_stdmath_exp(els_VmObj *vm){ - arg_returnnum(vm,exp(arg_getnum(vm,1))); - return 1; -} -int ELSAPI_stdmath_log(els_VmObj *vm){ - /* - 返回以a为底N的对数 - 根据换底公式,若f(x)=ln(x),则logaN可表示为 - f(a) / f(N) - - # 参数 - 1.a 底数 - 2.N 真数 - - # 返回值 - 1.x 对数 - */ - double a = arg_getnum(vm, 1); - double N = arg_getnum(vm, 2); - arg_returnnum(vm, log(a) / log(N)); - return 1; -} -int ELSAPI_stdmath_ln(els_VmObj *vm){ - arg_returnnum(vm,log(arg_getnum(vm,1))); - return 1; -} -int ELSAPI_stdmath_lg(els_VmObj *vm){ - arg_returnnum(vm,log10(arg_getnum(vm,1))); - return 1; -} -int ELSAPI_stdmath_sqrt(els_VmObj *vm){ - arg_returnnum(vm,sqrt(arg_getnum(vm,1))); - return 1; -} -int ELSAPI_stdmath_ceil(els_VmObj *vm){ - arg_returnnum(vm,ceil(arg_getnum(vm,1))); - return 1; -} -int ELSAPI_stdmath_floor(els_VmObj *vm){ - arg_returnnum(vm,floor(arg_getnum(vm,1))); - return 1; -} -int ELSAPI_stdmath_round(els_VmObj *vm){ - /* - 调用math.h中的double round(double)函数,用于四舍五入 - 从洛书处接收要四舍五入的数 - */ - arg_returnnum(vm, (double)round(arg_getnum(vm, 1))); - return 1; -} -int ELSAPI_stdmath_cut(els_VmObj *vm){ - /* - 截取小数点后若干位的函数 - - # 参数 - 从洛书处接受两个参数 - 1.num 被截取的数 - 2.x 要保留的位数 - */ - double num = arg_getnum(vm, 1); - int x = arg_getnum(vm, 2); - x = pow(10, x); - arg_returnnum(vm, (double)(long long)(num * x) / x); - return 1; -} \ No newline at end of file diff --git a/stdmath/stdmath.els b/stdmath/stdmath.els deleted file mode 100755 index 56ca280bc31f8d512e30b6345db5b1aff19744df..0000000000000000000000000000000000000000 --- a/stdmath/stdmath.els +++ /dev/null @@ -1,50 +0,0 @@ -#!declare -# 常量定义 -PI(): float #返回π的值 -E(): float #返回e的值 -GAMMA(): float #返回γ(欧拉常数)的值 -# 标准数学函数 -abs( num ) #返回数的绝对值 -mod( a, b ) #返回a mod b的结果 -acos( x ) #返回以弧度表示的x的反余弦 -asin( x ) #返回以弧度表示的x的反正弦 -atan( x ) #返回以弧度表示的x的反正切 -cos( x ) #返回x的余弦值 -sin( x ) #返回x的正弦值 -tan( x ) #返回x的正切值 -exp( x ) #返回e的x次幂的值 -log( a, N ) #返回以a为第N的对数 -ln( N ) #返回以e为底,N的对数 -lg( N ) #返回以10为底,N的对数 -sqrt( num:number ): float #返回num的平方根 -ceil( num:float ): float #对num向上取整 -floor( num:float ): float #对num向下取整 -round( num:float ): float #将小数四舍五入成整数 -cut( num:float, x:int): float #截取小数到若干位 -#!end - -#!script-cn - -圆周率 = PI -自然常数 = E -欧拉常数 = GAMMA - -绝对值 = abs -取模 = mod -反余弦 = acos -反正弦 = asin -反正切 = atan -余弦 = cos -正弦 = sin -正切 = tan -对数 = log - #exp起名空缺 - #ln起名空缺 - #lg起名空缺 -开平方 = sqrt -向上取整 = ceil -向下取整 = floor -四舍五入 = round -保留位数 = cut - -#!end \ No newline at end of file diff --git a/stdmath/stdmath.h b/stdmath/stdmath.h deleted file mode 100755 index 8a7be1dd229c0cf4082ec035605698eec96525b5..0000000000000000000000000000000000000000 --- a/stdmath/stdmath.h +++ /dev/null @@ -1,75 +0,0 @@ -#include "els.h" -// # 常量定义 -int ELSAPI_stdmath_PI(els_VmObj* vm); // PI(): float #返回π的值 -int ELSAPI_stdmath_E(els_VmObj* vm); // E(): float #返回e的值 -int ELSAPI_stdmath_GAMMA(els_VmObj* vm); // GAMMA(): float #返回γ(欧拉常数)的值 -// # 标准数学函数 -int ELSAPI_stdmath_abs(els_VmObj* vm); // abs( num ) #返回数的绝对值 -int ELSAPI_stdmath_mod(els_VmObj* vm); // mod( a, b ) #返回a mod b的结果 -int ELSAPI_stdmath_acos(els_VmObj* vm); // acos( x ) #返回以弧度表示的x的反余弦 -int ELSAPI_stdmath_asin(els_VmObj* vm); // asin( x ) #返回以弧度表示的x的反正弦 -int ELSAPI_stdmath_atan(els_VmObj* vm); // atan( x ) #返回以弧度表示的x的反正切 -int ELSAPI_stdmath_cos(els_VmObj* vm); // cos( x ) #返回x的余弦值 -int ELSAPI_stdmath_sin(els_VmObj* vm); // sin( x ) #返回x的正弦值 -int ELSAPI_stdmath_tan(els_VmObj* vm); // tan( x ) #返回x的正切值 -int ELSAPI_stdmath_exp(els_VmObj* vm); // exp( x ) #返回e的x次幂的值 -int ELSAPI_stdmath_log(els_VmObj* vm); // log( a, N ) #返回以a为第N的对数 -int ELSAPI_stdmath_ln(els_VmObj* vm); // ln( N ) #返回以e为底,N的对数 -int ELSAPI_stdmath_lg(els_VmObj* vm); // lg( N ) #返回以10为底,N的对数 -int ELSAPI_stdmath_sqrt(els_VmObj* vm); // sqrt( num:number ): float #返回num的平方根 -int ELSAPI_stdmath_ceil(els_VmObj* vm); // ceil( num:float ): float #对num向上取整 -int ELSAPI_stdmath_floor(els_VmObj* vm); // floor( num:float ): float #对num向下取整 -int ELSAPI_stdmath_round(els_VmObj* vm); // round( num:float ): float #将小数四舍五入成整数 -int ELSAPI_stdmath_cut(els_VmObj* vm); // cut( num:float, x:int): float #截取小数到若干位 -#ifdef ELS_CONF_TOKEN_CN -static const char LibScript_cn[]={ -10, --27,-100,-122,-27,-111,-88,-25,-114,-121,32,61,32,80,73,10, --24,-121,-86,-25,-124,-74,-27,-72,-72,-26,-107,-80,32,61,32,69,10, --26,-84,-89,-26,-117,-119,-27,-72,-72,-26,-107,-80,32,61,32,71,65,77,77,65,10, -10, --25,-69,-99,-27,-81,-71,-27,-128,-68,32,61,32,97,98,115,10, --27,-113,-106,-26,-88,-95,32,61,32,109,111,100,10, --27,-113,-115,-28,-67,-103,-27,-68,-90,32,61,32,97,99,111,115,10, --27,-113,-115,-26,-83,-93,-27,-68,-90,32,61,32,97,115,105,110,10, --27,-113,-115,-26,-83,-93,-27,-120,-121,32,61,32,97,116,97,110,10, --28,-67,-103,-27,-68,-90,32,61,32,99,111,115,10, --26,-83,-93,-27,-68,-90,32,61,32,115,105,110,10, --26,-83,-93,-27,-120,-121,32,61,32,116,97,110,10, --27,-81,-71,-26,-107,-80,32,61,32,108,111,103,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,35,101,120,112,-24,-75,-73,-27,-112,-115,-25,-87,-70,-25,-68,-70,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,35,108,110,-24,-75,-73,-27,-112,-115,-25,-87,-70,-25,-68,-70,10, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,35,108,103,-24,-75,-73,-27,-112,-115,-25,-87,-70,-25,-68,-70,10, --27,-68,-128,-27,-71,-77,-26,-106,-71,32,61,32,115,113,114,116,10, --27,-112,-111,-28,-72,-118,-27,-113,-106,-26,-107,-76,32,61,32,99,101,105,108,10, --27,-112,-111,-28,-72,-117,-27,-113,-106,-26,-107,-76,32,61,32,102,108,111,111,114,10, --27,-101,-101,-24,-120,-115,-28,-70,-108,-27,-123,-91,32,61,32,114,111,117,110,100,10, --28,-65,-99,-25,-107,-103,-28,-67,-115,-26,-107,-80,32,61,32,99,117,116,10, -10, -0}; -#endif -void ElsLib_stdmath_libinit(els_VmObj *vm){ - vm_register(vm,"mod",ELSAPI_stdmath_mod); - vm_register(vm,"E",ELSAPI_stdmath_E); - vm_register(vm,"sqrt",ELSAPI_stdmath_sqrt); - vm_register(vm,"abs",ELSAPI_stdmath_abs); - vm_register(vm,"cut",ELSAPI_stdmath_cut); - vm_register(vm,"GAMMA",ELSAPI_stdmath_GAMMA); - vm_register(vm,"asin",ELSAPI_stdmath_asin); - vm_register(vm,"atan",ELSAPI_stdmath_atan); - vm_register(vm,"exp",ELSAPI_stdmath_exp); - vm_register(vm,"cos",ELSAPI_stdmath_cos); - vm_register(vm,"round",ELSAPI_stdmath_round); - vm_register(vm,"ln",ELSAPI_stdmath_ln); - vm_register(vm,"floor",ELSAPI_stdmath_floor); - vm_register(vm,"ceil",ELSAPI_stdmath_ceil); - vm_register(vm,"log",ELSAPI_stdmath_log); - vm_register(vm,"acos",ELSAPI_stdmath_acos); - vm_register(vm,"lg",ELSAPI_stdmath_lg); - vm_register(vm,"sin",ELSAPI_stdmath_sin); - vm_register(vm,"tan",ELSAPI_stdmath_tan); - vm_register(vm,"PI",ELSAPI_stdmath_PI); - #ifdef ELS_CONF_TOKEN_CN - vm_dostring(vm,LibScript_cn); - #endif -}; diff --git a/stdstring/Ubuntu/makefile b/stdstring/Ubuntu/makefile deleted file mode 100755 index 9caf91c5a12f7e7d2967173982f77b5b5ca6a7a8..0000000000000000000000000000000000000000 --- a/stdstring/Ubuntu/makefile +++ /dev/null @@ -1,13 +0,0 @@ -OBJS = stdstring.o -CFLAGS= -O2 -Wall -std=c99 -DELS_CONF_OS_LINUX -I ../buildenv -fPIC -CC=x86_64-linux-gnu-gcc -T=./ElsLib_stdstring.lsd - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -shared -s - -clean: - rm -rf $T $(OBJS) core core.* \ No newline at end of file diff --git a/stdstring/Windows/makefile b/stdstring/Windows/makefile deleted file mode 100755 index eea07a8cfca58f2cd460ba733c84fff397b3f32f..0000000000000000000000000000000000000000 --- a/stdstring/Windows/makefile +++ /dev/null @@ -1,13 +0,0 @@ -OBJS = stdstring.o -CFLAGS= -O2 -Wall -std=c99 -DELS_CONF_OS_WINDOWS -I ../buildenv -fPIC -CC=x86_64-w64-mingw32-gcc -T=./ElsLib_stdstring.lsd - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -shared -s -L ../buildenv -l:libeasylosu.dll -static - -clean: - rm -rf $T $(OBJS) core core.* \ No newline at end of file diff --git a/stdstring/info b/stdstring/info deleted file mode 100755 index 90a1ddb395bc591eb905e17cd1831f795e9f9776..0000000000000000000000000000000000000000 --- a/stdstring/info +++ /dev/null @@ -1,21 +0,0 @@ -{ - type = "const", - info = { - name = "stdstring/标准库(字符串)", - text = "stdlib中的字符串函数部分", - version = "23.11.10" - }, - source = { - all = { - "stdstring.els", - "stdstring.h", - "stdstring.c" - }, - Ubuntu = {"makefile"}, - Windows = {"makefile"}, - }, - target = { - Ubuntu = "make ; cp ElsLib_stdstring.lsd target/ElsLib_stdstring.lsd_Ubuntu ; make clean", - Windows = "make ; cp ElsLib_stdstring.lsd target/ElsLib_stdstring.lsd_Windows ; make clean", - } -} \ No newline at end of file diff --git a/stdstring/readme.md b/stdstring/readme.md deleted file mode 100755 index ff91816a28602daf7d55cf453c2555ea8d4aed99..0000000000000000000000000000000000000000 --- a/stdstring/readme.md +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/owls.wiki.losu.tech -# stdlib (stdstring) - -```python -#!declare -length(s: str ): int '返回 s 的长度' -strstr(fs: str,ss: str): str '返回在 fs 中 ss 出现为首的子字符串' -strtok(fs: str,t: str): str '以 s 为标志,在 fs 中分词' -replace(fs: str,ss: str, obj: str): str '将 fs 中 的 ss 替换成 obj' -mid(s: str,sp: int ,len: int): str '在 s 中 sp 位置 截取 len 长度的字符串' -reverse(s: str): str '倒置 s' -toupper(s: str): str '大写 s' -tolower(s: str): str '小写 s' -string(s: str,n: int): str '将 n 个 fs 拼接为一个长字符串' -coutnum(fs: str,ss: str): int '统计 fs 中 ss 出现次数' -#!end -#!script-cn -长度 = length -寻至 = strstr -分词 = strtok -替换 = replace -截取 = mid -倒置 = reverse -大写 = toupper -小写 = tolower -抄写 = string -统计 = coutnum -#!end -``` - diff --git a/stdstring/stdstring.c b/stdstring/stdstring.c deleted file mode 100755 index 6e478f28b11f4cd75776be7e7bd85eeb75a15b58..0000000000000000000000000000000000000000 --- a/stdstring/stdstring.c +++ /dev/null @@ -1,162 +0,0 @@ -#include "stdstring.h" -#include -#define els_string_rt tmp -int ELSAPI_stdstring_length(els_VmObj* vm) // length(s: str ): int '返回 s 的长度' -{ - arg_returnnum(vm,strlen(arg_getstr(vm,1))); - return 1; -} - -int ELSAPI_stdstring_strstr(els_VmObj* vm) // strstr(fs: str,ss: str): str '返回在 fs 中 ss 出现为首的子字符串' -{ - const char* tmp = strstr(arg_getstr(vm,1),arg_getstr(vm,2)); - if(tmp==NULL) arg_returnstr(vm,""); - else arg_returnstr(vm,tmp); - return 1; -} - -int ELSAPI_stdstring_strtok(els_VmObj* vm) // strtok(fs: str,t: str): str '以 s 为标志,在 fs 中分词' -{ - char *tmp; - if(arg_gettype(vm,1)==ELS_API_TYPE_NULL){ - tmp = strtok(NULL,arg_getstr(vm,2)); - if(tmp==NULL) arg_returnstr(vm,""); - else arg_returnstr(vm,tmp); - }else{ - tmp = strtok((char*)arg_getstr(vm,1),arg_getstr(vm,2)); - if(tmp==NULL) arg_returnstr(vm,""); - else arg_returnstr(vm,tmp); - } - return 1; -} - - -int ELSAPI_stdstring_replace(els_VmObj* l) // replace(fs: str,ss: str, obj: str): str '将 fs 中 的 ss 替换成 obj' -{ - char tmp[ELS_BUFF_TMP_SIZE]; - memset(tmp,'\0',ELS_BUFF_TMP_SIZE); - const char* s1 = arg_getstr(l,1); - const char* s2 = arg_getstr(l,2); - const char* s3 = arg_getstr(l,3); - int p =0; - for(int i=0; istrlen(s1)||sp<=0) arg_returnstr(l,""); - else arg_returnstr(l,els_string_rt); - return 1; -} -int ELSAPI_stdstring_reverse(els_VmObj* l) // reverse(s: str): str '倒置 s' -{ - char tmp[ELS_BUFF_TMP_SIZE]; - memset(els_string_rt,'\0',ELS_BUFF_TMP_SIZE); - const char* s1=arg_getstr(l,1); - int count=strlen(s1)-1; - int i; - for(i=0;i=(char)0xe2&&s1[i]<=(char)0xef){ - els_string_rt[count-2]=s1[i]; - els_string_rt[count-1]=s1[i+1]; - els_string_rt[count]=s1[i+2]; - i=i+2; - count-=3; - } - else if(s1[i]==(char)0xf0){ - els_string_rt[count-3] = s1[i]; - els_string_rt[count-2]=s1[i+1]; - els_string_rt[count-1]=s1[i+2]; - els_string_rt[count]=s1[i+3]; - i=i+3; - count-=4; - } - else{ - els_string_rt[count]=s1[i]; - count--; - } - } - els_string_rt[i]='\0'; - arg_returnstr(l,els_string_rt); - return 1; -} - -int ELSAPI_stdstring_toupper(els_VmObj* l) // toupper(s: str): str '大写 s' -{ - char tmp[ELS_BUFF_TMP_SIZE]; - memset(els_string_rt,'\0',ELS_BUFF_TMP_SIZE); - const char* s1=arg_getstr(l,1); - for(int i=0;i='a'&&s1[i]<='z') els_string_rt[i]=s1[i]-32; - else els_string_rt[i]=s1[i]; - } - arg_returnstr(l,els_string_rt); - return 1; -} -int ELSAPI_stdstring_tolower(els_VmObj* l) // tolower(s: str): str '小写 s' -{ - char tmp[ELS_BUFF_TMP_SIZE]; - memset(els_string_rt,'\0',ELS_BUFF_TMP_SIZE); - const char* s1=arg_getstr(l,1); - for(int i=0;i='A'&&s1[i]<='Z') els_string_rt[i]=s1[i]+32; - else els_string_rt[i]=s1[i]; - } - arg_returnstr(l,els_string_rt); - return 1; -} -int ELSAPI_stdstring_string(els_VmObj* l) // string(s: str,n: int): str '将 n 个 fs 拼接为一个长字符串' -{ - char tmp[ELS_BUFF_TMP_SIZE]; - memset(els_string_rt,'\0',ELS_BUFF_TMP_SIZE); - const char* s1=arg_getstr(l,1); - int len=arg_getnum(l,2); - for(int i=0;i -#include -#include -#include - -FILE *popen(const char *cmdstring, const char *type); - -int pclose(FILE *fp); - -int ELSAPI_stdsys_sys_getos(els_VmObj* vm) // sys_getos(): str '从内核中获取所在操作系统信息,一般为 Windwos/Linux Branch' -{ - arg_returnstr(vm,ELS_BRANCH); - return 1; -} -int ELSAPI_stdsys_sys_getenv(els_VmObj* vm) // sys_getenv(n: str) '获取名称为n的环境变量' -{ - char * tmp = getenv(arg_getstr(vm,1)); - if(tmp){ - arg_returnstr(vm,tmp); - return 1; - } - arg_returnnull(vm); - return 1; -} -int ELSAPI_stdsys_sys_system(els_VmObj* vm) // sys_system(cmd: str): int '调用一个命令' -{ - arg_returnnum(vm,(Number)(system(arg_getstr(vm,1)))); - return 1; -} -int ELSAPI_stdsys_sys_popen(els_VmObj* vm) // sys_popen(cmd: str, mod:str): ptr '创建一个管道,mod可取为 r,w' -{ - FILE *f = popen(arg_getstr(vm,1),arg_getstr(vm,2)); - if(f){ - arg_returnptr(vm,(char*)(f)); - return 1; - } - arg_returnnull(vm); - return 1; - -} -int ELSAPI_stdsys_sys_pwrite(els_VmObj* vm) // sys_pwrite(p: ptr,s: str): int '向指定管道 p 写入 s' -{ - arg_returnnum(vm,(Number)fwrite(arg_getstr(vm,2),1,strlen(arg_getstr(vm,2)),(FILE*)(arg_getptr(vm,1)))); - return 1; - -} -int ELSAPI_stdsys_sys_pread(els_VmObj* vm) // sys_pread(p: ptr, n: int): int '从指定管道 p 读取 n 个字符' -{ - char tmp[ELS_BUFF_TMP_SIZE]; - memset(tmp,'\0',ELS_BUFF_TMP_SIZE); - if(arg_gettype(vm,2)==ELS_API_TYPE_NULL) - fgets(tmp,ELS_BUFF_TMP_SIZE,(FILE*)(arg_getptr(vm,1))); - else - fgets(tmp,(int)arg_getnum(vm,2),(FILE*)(arg_getptr(vm,1))); - - arg_returnstr(vm,tmp); - return 1; -} -int ELSAPI_stdsys_sys_pclose(els_VmObj* vm) // sys_pclose(p: ptr): int '关闭一个管道' -{ - arg_returnnum(vm, (Number)pclose((FILE*)(arg_getptr(vm,1)))); - return 1; -} diff --git a/stdsys/Windows/makefile b/stdsys/Windows/makefile deleted file mode 100755 index ef8f5e1f186cfcdc5b12c6a4e0b69443707dae0f..0000000000000000000000000000000000000000 --- a/stdsys/Windows/makefile +++ /dev/null @@ -1,13 +0,0 @@ -OBJS = stdsys.o -CFLAGS= -O2 -Wall -std=c99 -DELS_CONF_OS_WINDOWS -I ../buildenv -fPIC -CC=x86_64-w64-mingw32-gcc -T=./ElsLib_stdsys.lsd - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -shared -s -L ../buildenv -l:libeasylosu.dll -static - -clean: - rm -rf $T $(OBJS) core core.* \ No newline at end of file diff --git a/stdsys/Windows/stdsys.c b/stdsys/Windows/stdsys.c deleted file mode 100755 index ca88a1035d169c6e2ee986c6335acb023a6e9d4f..0000000000000000000000000000000000000000 --- a/stdsys/Windows/stdsys.c +++ /dev/null @@ -1,71 +0,0 @@ -#include "stdsys.h" -#include -#include -#include -#include - -int ELSAPI_stdsys_sys_getos(els_VmObj* vm) // sys_getos(): str '从内核中获取所在操作系统信息,一般为 Windwos/Linux Branch' -{ - arg_returnstr(vm,ELS_BRANCH); - return 1; -} -int ELSAPI_stdsys_sys_getenv(els_VmObj* vm) // sys_getenv(n: str) '获取名称为n的环境变量' -{ - char * tmp = getenv(arg_getstr(vm,1)); - char* _t; - if(tmp){ - _t = vm_win_togbk(tmp); - arg_returnstr(vm,_t); - free(_t); - return 1; - } - arg_returnnull(vm); - return 1; -} -int ELSAPI_stdsys_sys_system(els_VmObj* vm) // sys_system(cmd: str): int '调用一个命令' -{ - char* tmp = vm_win_togbk(arg_getstr(vm,1)); - arg_returnnum(vm,(Number)(system(tmp))); - free(tmp); - return 1; -} -int ELSAPI_stdsys_sys_popen(els_VmObj* vm) // sys_popen(cmd: str, mod:str): ptr '创建一个管道,mod可取为 r,w' -{ - char* tmp = vm_win_togbk(arg_getstr(vm,1)); - FILE *f = popen(tmp,arg_getstr(vm,2));free(tmp); - if(f){ - arg_returnptr(vm,(char*)(f)); - return 1; - } - arg_returnnull(vm); - return 1; - -} -int ELSAPI_stdsys_sys_pwrite(els_VmObj* vm) // sys_pwrite(p: ptr,s: str): int '向指定管道 p 写入 s' -{ - char* tmp = vm_win_togbk(arg_getstr(vm,2)); - arg_returnnum(vm,(Number)fwrite(tmp,1,strlen(tmp),(FILE*)(arg_getptr(vm,1)))); - free(tmp); - return 1; - -} -int ELSAPI_stdsys_sys_pread(els_VmObj* vm) // sys_pread(p: ptr, n: int): int '从指定管道 p 读取 n 个字符' -{ - char tmp[ELS_BUFF_TMP_SIZE]; - char *_t; - memset(tmp,'\0',ELS_BUFF_TMP_SIZE); - if(arg_gettype(vm,2)==ELS_API_TYPE_NULL) - fgets(tmp,ELS_BUFF_TMP_SIZE,(FILE*)(arg_getptr(vm,1))); - else - fgets(tmp,(int)arg_getnum(vm,2),(FILE*)(arg_getptr(vm,1))); - - _t = vm_win_toutf8(tmp); - arg_returnstr(vm,_t); - free(_t); - return 1; -} -int ELSAPI_stdsys_sys_pclose(els_VmObj* vm) // sys_pclose(p: ptr): int '关闭一个管道' -{ - arg_returnnum(vm, (Number)pclose((FILE*)(arg_getptr(vm,1)))); - return 1; -} diff --git a/stdsys/info b/stdsys/info deleted file mode 100755 index f3973ccda586c20996a09edcdb34bcfac1db4085..0000000000000000000000000000000000000000 --- a/stdsys/info +++ /dev/null @@ -1,17 +0,0 @@ -{ - type = "const", - info = { - name = "stdsys/标准库(系统函数)", - text = "stdlib中的系统函数部分", - version = "23.10.28" - }, - source = { - all = {"stdsys.els","stdsys.h"}, - Ubuntu = {"makefile","stdsys.c"}, - Windows = {"makefile","stdsys.c"}, - }, - target = { - Ubuntu = "make ; cp ElsLib_stdsys.lsd target/ElsLib_stdsys.lsd_Ubuntu ; make clean", - Windows = "make ; cp ElsLib_stdsys.lsd target/ElsLib_stdsys.lsd_Windows ; make clean", - } -} \ No newline at end of file diff --git a/stdsys/readme.md b/stdsys/readme.md deleted file mode 100755 index caa3b1e40d6dca100e7a3b5eb56096e3386996a4..0000000000000000000000000000000000000000 --- a/stdsys/readme.md +++ /dev/null @@ -1,78 +0,0 @@ -#!/bin/owls.wiki.losu.tech -# stdlib (stdsys) - -```python -#!declare -sys_getos(): str '从内核中获取所在操作系统信息,一般为 Windwos/Linux' -sys_getenv(n: str) '获取名称为n的环境变量' -sys_system(cmd: str): int '调用一个命令' -sys_popen(cmd: str, mod:str): ptr '创建一个管道,mod可取为 r,w' -sys_pwrite(p: ptr,s: str): int '向指定管道 p 写入 s' -sys_pread(p: ptr, n: int): int '从指定管道 p 读取 n 个字符' -sys_pclose(p: ptr): int '关闭一个管道' -#!end -#!script -sys={} -sys.getos = sys_getos -def sys.getenv(name): - return sys_getenv(name) -; -def sys.popen(cmd,mod): - var this = {} - - this.P = sys_popen(cmd,mod) - - if !this.P : return null ; - - def this.write(s): - return sys_pwrite(this.P,s) - ; - def this.read(i): - return sys_pread(this.P,i) - ; - def this.close(): - return sys_pclose(this.P) - ; - - return this -; - -def sys.system(cmd): - return sys_system(cmd) -; -#!end - -#!script-cn -系统={} -系统.操作系统 = sys_getos -def 系统.环境变量(name): - return sys_getenv(name) -; -def 系统.新进程(cmd,mod): - var this = {} - - this.P = sys_popen(cmd,mod) - - if !this.P : return null ; - - def this.写(s): - return sys_pwrite(this.P,s) - ; - def this.读(i): - return sys_pread(this.P,i) - ; - def this.关闭(): - return sys_pclose(this.P) - ; - - return this -; - -def 系统.调用(cmd): - return sys_system(cmd) -; - - -#!end - -``` \ No newline at end of file diff --git a/stdsys/stdsys.els b/stdsys/stdsys.els deleted file mode 100755 index 68cc642da420af9a334ce5d889740c326b8da069..0000000000000000000000000000000000000000 --- a/stdsys/stdsys.els +++ /dev/null @@ -1,72 +0,0 @@ -#!declare -sys_getos(): str '从内核中获取所在操作系统信息,一般为 Windwos/Linux' -sys_getenv(n: str) '获取名称为n的环境变量' -sys_system(cmd: str): int '调用一个命令' -sys_popen(cmd: str, mod:str): ptr '创建一个管道,mod可取为 r,w' -sys_pwrite(p: ptr,s: str): int '向指定管道 p 写入 s' -sys_pread(p: ptr, n: int): int '从指定管道 p 读取 n 个字符' -sys_pclose(p: ptr): int '关闭一个管道' -#!end -#!script -sys={} -sys.getos = sys_getos -def sys.getenv(name): - return sys_getenv(name) -; -def sys.popen(cmd,mod): - var this = {} - - this.P = sys_popen(cmd,mod) - - if !this.P : return null ; - - def this.write(s): - return sys_pwrite(this.P,s) - ; - def this.read(i): - return sys_pread(this.P,i) - ; - def this.close(): - return sys_pclose(this.P) - ; - - return this -; - -def sys.system(cmd): - return sys_system(cmd) -; -#!end - -#!script-cn -系统={} -系统.操作系统 = sys_getos -def 系统.环境变量(name): - return sys_getenv(name) -; -def 系统.新进程(cmd,mod): - var this = {} - - this.P = sys_popen(cmd,mod) - - if !this.P : return null ; - - def this.写(s): - return sys_pwrite(this.P,s) - ; - def this.读(i): - return sys_pread(this.P,i) - ; - def this.关闭(): - return sys_pclose(this.P) - ; - - return this -; - -def 系统.调用(cmd): - return sys_system(cmd) -; - - -#!end diff --git a/stdsys/stdsys.h b/stdsys/stdsys.h deleted file mode 100755 index 7b0a12b19be6ed15c7ad7485bca959a7755179a3..0000000000000000000000000000000000000000 --- a/stdsys/stdsys.h +++ /dev/null @@ -1,89 +0,0 @@ -#include "els.h" -int ELSAPI_stdsys_sys_getos(els_VmObj* vm); // sys_getos(): str '从内核中获取所在操作系统信息,一般为 Windwos/Linux' -int ELSAPI_stdsys_sys_getenv(els_VmObj* vm); // sys_getenv(n: str) '获取名称为n的环境变量' -int ELSAPI_stdsys_sys_system(els_VmObj* vm); // sys_system(cmd: str): int '调用一个命令' -int ELSAPI_stdsys_sys_popen(els_VmObj* vm); // sys_popen(cmd: str, mod:str): ptr '创建一个管道,mod可取为 r,w' -int ELSAPI_stdsys_sys_pwrite(els_VmObj* vm); // sys_pwrite(p: ptr,s: str): int '向指定管道 p 写入 s' -int ELSAPI_stdsys_sys_pread(els_VmObj* vm); // sys_pread(p: ptr, n: int): int '从指定管道 p 读取 n 个字符' -int ELSAPI_stdsys_sys_pclose(els_VmObj* vm); // sys_pclose(p: ptr): int '关闭一个管道' -#ifdef ELS_CONF_TOKEN_EN -static const char LibScript[]={ -115,121,115,61,123,125,10, -115,121,115,46,103,101,116,111,115,32,32,61,32,115,121,115,95,103,101,116,111,115,10, -100,101,102,32,115,121,115,46,103,101,116,101,110,118,40,110,97,109,101,41,58,10, -32,32,32,32,114,101,116,117,114,110,32,115,121,115,95,103,101,116,101,110,118,40,110,97,109,101,41,10, -59,10, -100,101,102,32,115,121,115,46,112,111,112,101,110,40,99,109,100,44,109,111,100,41,58,10, -32,32,32,32,118,97,114,32,116,104,105,115,32,61,32,123,125,10, -10, -32,32,32,32,116,104,105,115,46,80,32,61,32,115,121,115,95,112,111,112,101,110,40,99,109,100,44,109,111,100,41,10, -10, -32,32,32,32,105,102,32,33,116,104,105,115,46,80,32,58,32,114,101,116,117,114,110,32,110,117,108,108,32,59,10, -10, -32,32,32,32,100,101,102,32,116,104,105,115,46,119,114,105,116,101,40,115,41,58,10, -32,32,32,32,32,32,32,32,114,101,116,117,114,110,32,115,121,115,95,112,119,114,105,116,101,40,116,104,105,115,46,80,44,115,41,10, -32,32,32,32,59,32,32,10, -32,32,32,32,100,101,102,32,116,104,105,115,46,114,101,97,100,40,105,41,58,10, -32,32,32,32,32,32,32,32,114,101,116,117,114,110,32,115,121,115,95,112,114,101,97,100,40,116,104,105,115,46,80,44,105,41,10, -32,32,32,32,59,10, -32,32,32,32,100,101,102,32,116,104,105,115,46,99,108,111,115,101,40,41,58,10, -32,32,32,32,32,32,32,32,114,101,116,117,114,110,32,115,121,115,95,112,99,108,111,115,101,40,116,104,105,115,46,80,41,10, -32,32,32,32,59,10, -10, -32,32,32,32,114,101,116,117,114,110,32,116,104,105,115,10, -59,32,10, -10, -100,101,102,32,115,121,115,46,115,121,115,116,101,109,40,99,109,100,41,58,10, -32,32,32,32,114,101,116,117,114,110,32,115,121,115,95,115,121,115,116,101,109,40,99,109,100,41,10, -59,10, -0}; -#endif -#ifdef ELS_CONF_TOKEN_CN -static const char LibScript_cn[]={ --25,-77,-69,-25,-69,-97,61,123,125,10, --25,-77,-69,-25,-69,-97,46,-26,-109,-115,-28,-67,-100,-25,-77,-69,-25,-69,-97,32,32,61,32,115,121,115,95,103,101,116,111,115,10, -100,101,102,32,-25,-77,-69,-25,-69,-97,46,-25,-114,-81,-27,-94,-125,-27,-113,-104,-23,-121,-113,40,110,97,109,101,41,58,10, -32,32,32,32,114,101,116,117,114,110,32,115,121,115,95,103,101,116,101,110,118,40,110,97,109,101,41,10, -59,10, -100,101,102,32,-25,-77,-69,-25,-69,-97,46,-26,-106,-80,-24,-65,-101,-25,-88,-117,40,99,109,100,44,109,111,100,41,58,10, -32,32,32,32,118,97,114,32,116,104,105,115,32,61,32,123,125,10, -10, -32,32,32,32,116,104,105,115,46,80,32,61,32,115,121,115,95,112,111,112,101,110,40,99,109,100,44,109,111,100,41,10, -10, -32,32,32,32,105,102,32,33,116,104,105,115,46,80,32,58,32,114,101,116,117,114,110,32,110,117,108,108,32,59,10, -10, -32,32,32,32,100,101,102,32,116,104,105,115,46,-27,-122,-103,40,115,41,58,10, -32,32,32,32,32,32,32,32,114,101,116,117,114,110,32,115,121,115,95,112,119,114,105,116,101,40,116,104,105,115,46,80,44,115,41,10, -32,32,32,32,59,32,32,10, -32,32,32,32,100,101,102,32,116,104,105,115,46,-24,-81,-69,40,105,41,58,10, -32,32,32,32,32,32,32,32,114,101,116,117,114,110,32,115,121,115,95,112,114,101,97,100,40,116,104,105,115,46,80,44,105,41,10, -32,32,32,32,59,10, -32,32,32,32,100,101,102,32,116,104,105,115,46,-27,-123,-77,-23,-105,-83,40,41,58,10, -32,32,32,32,32,32,32,32,114,101,116,117,114,110,32,115,121,115,95,112,99,108,111,115,101,40,116,104,105,115,46,80,41,10, -32,32,32,32,59,10, -10, -32,32,32,32,114,101,116,117,114,110,32,116,104,105,115,10, -59,32,10, -10, -100,101,102,32,-25,-77,-69,-25,-69,-97,46,-24,-80,-125,-25,-108,-88,40,99,109,100,41,58,10, -32,32,32,32,114,101,116,117,114,110,32,115,121,115,95,115,121,115,116,101,109,40,99,109,100,41,10, -59,10, -10, -10, -0}; -#endif -void ElsLib_stdsys_libinit(els_VmObj *vm){ - vm_register(vm,"sys_getos",ELSAPI_stdsys_sys_getos); - vm_register(vm,"sys_pclose",ELSAPI_stdsys_sys_pclose); - vm_register(vm,"sys_popen",ELSAPI_stdsys_sys_popen); - vm_register(vm,"sys_pwrite",ELSAPI_stdsys_sys_pwrite); - vm_register(vm,"sys_getenv",ELSAPI_stdsys_sys_getenv); - vm_register(vm,"sys_pread",ELSAPI_stdsys_sys_pread); - vm_register(vm,"sys_system",ELSAPI_stdsys_sys_system); - #ifdef ELS_CONF_TOKEN_EN - vm_dostring(vm,LibScript); - #endif - #ifdef ELS_CONF_TOKEN_CN - vm_dostring(vm,LibScript_cn); - #endif -}; diff --git a/stdthread/Ubuntu/makefile b/stdthread/Ubuntu/makefile deleted file mode 100755 index b2aa9e0890c9b00424cbe2d6bdefa45ba6aafec1..0000000000000000000000000000000000000000 --- a/stdthread/Ubuntu/makefile +++ /dev/null @@ -1,13 +0,0 @@ -OBJS = stdthread.o -CFLAGS= -O2 -Wall -std=c99 -DLOSU_LINUX -I ../buildenv -fPIC -CC=x86_64-linux-gnu-gcc -T=ElsLib_stdthread.lsd - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -shared -lpthread -s - -clean: - rm -rf $T $(OBJS) core core.* \ No newline at end of file diff --git a/stdthread/Ubuntu/stdthread.c b/stdthread/Ubuntu/stdthread.c deleted file mode 100755 index 96d22eb7adf66c73e8f66709c5c5933bb1a256d6..0000000000000000000000000000000000000000 --- a/stdthread/Ubuntu/stdthread.c +++ /dev/null @@ -1,71 +0,0 @@ -#include "stdthread.h" -#include "els_vmhost.h" -#include "els_heap.h" -#include -#include -#include - - -static void ElsLib_lsthread_newthread(els_VmObj *vm){ - els_Heap_call(vm,vm->stack,-1); - vm_close(vm); -} -int ELSAPI_stdthread_stdthread_exit(els_VmObj* vm) -{ -// 这里填写API函数的 C 实现 - pthread_exit(NULL); - return 0; -} -int ELSAPI_stdthread_stdthread_self(els_VmObj* vm) -{ -// 这里填写API函数的 C 实现 - arg_returnnum(vm,(Number)((unsigned int)(pthread_self()))); - return 1; -} -int ELSAPI_stdthread_stdthread_join(els_VmObj* vm) -{ -// 这里填写API函数的 C 实现 - pthread_t pt = (pthread_t)obj_tonum(vm,obj_indexunit(vm, *arg_get(vm,1) , obj_newstr(vm,"thread_t") )); - arg_returnnum(vm,pthread_join(pt,NULL)); - return 1; -} -int ELSAPI_stdthread_stdthread_create(els_VmObj* vm) -{ -// 这里填写API函数的 C 实现 - pthread_t _t; - pthread_t *t=&_t; - - obj_setunit(vm,*arg_get(vm,1),obj_newstr(vm,"thread_t"),obj_newptr(vm,(char*)(t))); - #ifdef ELS_CONF_TOKEN_EN - obj_setunit(vm,*arg_get(vm,1),obj_newstr(vm,"argn"),obj_newnum(vm,arg_num(vm)-2)); - #endif - - #ifdef ELS_CONF_TOKEN_CN - obj_setunit(vm,*arg_get(vm,1),obj_newstr(vm,"参数个数"),obj_newnum(vm,arg_num(vm)-2)); - #endif - els_VmObj* n = vm_fork(vm,1024); - *(n->stack) = *arg_get(vm,2); - if(obj_type(vm,arg_get(vm,2))!=ELS_API_TYPE_FUNCTION){ - printf("PThread Error : Not Function,create failed!\n"); - return 0; - } - for(int i=2;istack+ i-1) = *arg_get(vm,i+1); - n->top =n->stack + arg_num(vm) ; - arg_returnnum(vm,pthread_create(t,NULL,(void*)(*ElsLib_lsthread_newthread),n)); - return 1; -} -int ELSAPI_stdthread_stdthread_cancel(els_VmObj* vm) -{ -// 这里填写API函数的 C 实现 - pthread_t pt = (pthread_t)obj_tonum(vm,obj_indexunit(vm,*arg_get(vm,2),obj_newstr(vm,"thread_t") )); - arg_returnnum(vm,pthread_cancel(pt)); - return 1; -} -int ELSAPI_stdthread_stdthread_detach(els_VmObj* vm) -{ -// 这里填写API函数的 C 实现 - pthread_t pt = (pthread_t)obj_tonum(vm,obj_indexunit(vm,*arg_get(vm,1),obj_newstr(vm,"thread_t") )); - arg_returnnum(vm,pthread_detach(pt)); - return 1; -} diff --git a/stdthread/Windows/makefile b/stdthread/Windows/makefile deleted file mode 100755 index 28e41af387e9cd22e62e36327a4b70ef66d8d9c1..0000000000000000000000000000000000000000 --- a/stdthread/Windows/makefile +++ /dev/null @@ -1,13 +0,0 @@ -OBJS = stdthread.o -CFLAGS= -O2 -Wall -std=c99 -DLOSU_WINDOWS -I ../buildenv -fPIC -CC=x86_64-w64-mingw32-gcc -T=ElsLib_stdthread.lsd - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -shared -lpthread -s -L ../buildenv -l:libeasylosu.dll -static - -clean: - rm -rf $T $(OBJS) core core.* \ No newline at end of file diff --git a/stdthread/Windows/stdthread.c b/stdthread/Windows/stdthread.c deleted file mode 100755 index 96d22eb7adf66c73e8f66709c5c5933bb1a256d6..0000000000000000000000000000000000000000 --- a/stdthread/Windows/stdthread.c +++ /dev/null @@ -1,71 +0,0 @@ -#include "stdthread.h" -#include "els_vmhost.h" -#include "els_heap.h" -#include -#include -#include - - -static void ElsLib_lsthread_newthread(els_VmObj *vm){ - els_Heap_call(vm,vm->stack,-1); - vm_close(vm); -} -int ELSAPI_stdthread_stdthread_exit(els_VmObj* vm) -{ -// 这里填写API函数的 C 实现 - pthread_exit(NULL); - return 0; -} -int ELSAPI_stdthread_stdthread_self(els_VmObj* vm) -{ -// 这里填写API函数的 C 实现 - arg_returnnum(vm,(Number)((unsigned int)(pthread_self()))); - return 1; -} -int ELSAPI_stdthread_stdthread_join(els_VmObj* vm) -{ -// 这里填写API函数的 C 实现 - pthread_t pt = (pthread_t)obj_tonum(vm,obj_indexunit(vm, *arg_get(vm,1) , obj_newstr(vm,"thread_t") )); - arg_returnnum(vm,pthread_join(pt,NULL)); - return 1; -} -int ELSAPI_stdthread_stdthread_create(els_VmObj* vm) -{ -// 这里填写API函数的 C 实现 - pthread_t _t; - pthread_t *t=&_t; - - obj_setunit(vm,*arg_get(vm,1),obj_newstr(vm,"thread_t"),obj_newptr(vm,(char*)(t))); - #ifdef ELS_CONF_TOKEN_EN - obj_setunit(vm,*arg_get(vm,1),obj_newstr(vm,"argn"),obj_newnum(vm,arg_num(vm)-2)); - #endif - - #ifdef ELS_CONF_TOKEN_CN - obj_setunit(vm,*arg_get(vm,1),obj_newstr(vm,"参数个数"),obj_newnum(vm,arg_num(vm)-2)); - #endif - els_VmObj* n = vm_fork(vm,1024); - *(n->stack) = *arg_get(vm,2); - if(obj_type(vm,arg_get(vm,2))!=ELS_API_TYPE_FUNCTION){ - printf("PThread Error : Not Function,create failed!\n"); - return 0; - } - for(int i=2;istack+ i-1) = *arg_get(vm,i+1); - n->top =n->stack + arg_num(vm) ; - arg_returnnum(vm,pthread_create(t,NULL,(void*)(*ElsLib_lsthread_newthread),n)); - return 1; -} -int ELSAPI_stdthread_stdthread_cancel(els_VmObj* vm) -{ -// 这里填写API函数的 C 实现 - pthread_t pt = (pthread_t)obj_tonum(vm,obj_indexunit(vm,*arg_get(vm,2),obj_newstr(vm,"thread_t") )); - arg_returnnum(vm,pthread_cancel(pt)); - return 1; -} -int ELSAPI_stdthread_stdthread_detach(els_VmObj* vm) -{ -// 这里填写API函数的 C 实现 - pthread_t pt = (pthread_t)obj_tonum(vm,obj_indexunit(vm,*arg_get(vm,1),obj_newstr(vm,"thread_t") )); - arg_returnnum(vm,pthread_detach(pt)); - return 1; -} diff --git a/stdthread/info b/stdthread/info deleted file mode 100755 index f2b9bc9c7c6b3060fee13428f32a9f8f99ff699c..0000000000000000000000000000000000000000 --- a/stdthread/info +++ /dev/null @@ -1,17 +0,0 @@ -{ - type = "const", - info = { - name = "stdthread/标准库(线程)", - text = "stdlib中的线程函数部分", - version = "24.1.5" - }, - source = { - all = {"stdthread.els","stdthread.h",}, - Ubuntu = {"makefile","stdthread.c"}, - Windows = {"makefile","stdthread.c"}, - }, - target = { - Ubuntu = "make ; cp ElsLib_stdthread.lsd target/ElsLib_stdthread.lsd_Ubuntu ; make clean", - Windows = "make ; cp ElsLib_stdthread.lsd target/ElsLib_stdthread.lsd_Windows ; make clean", - } -} diff --git a/stdthread/readme.md b/stdthread/readme.md deleted file mode 100755 index 50060c72be296b3ded00e98b4206b5f84f820e7f..0000000000000000000000000000000000000000 --- a/stdthread/readme.md +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/owls.wiki.losu.tech -# stdlib (stdthread) -```python -#!declare -stdthread_create(obj: object,f: def,...): ptr '''创建一个新线程,调用脚本中的函数 f ,并传递参数''' -stdthread_exit(): int '''退出当前线程''' -stdthread_join(obj: object): int '''阻塞至线程结束''' -stdthread_detach(obj: object): int '''分离当前线程''' -stdthread_cancel(obj: object): int '''终止当前线程''' -stdthread_self(): pid '''返回当前的PID''' -#!end -#!script -thread={} -def thread.class(): - var this = {} - this.create = stdthread_create - this.join = stdthread_join - this.detach = stdthread_detach - this.exit = stdthread_exit - this.self = stdthread_self - return this -; -thread.cancel = stdthread_cancel -thread.exit = stdthread_exit -#!end - -#!script-cn -线程={} -def 线程.class(): - var this = {} - this.启动 = stdthread_create - this.等待 = stdthread_join - this.分离 = stdthread_detach - this.退出 = stdthread_exit - this.自身ID = stdthread_self - return this -; -线程.停止 = stdthread_cancel -线程.退出 = stdthread_exit -#!end - - -``` \ No newline at end of file diff --git a/stdthread/stdthread.els b/stdthread/stdthread.els deleted file mode 100755 index f29c16499b6ab33f92db65bb3c1b96ce6667e806..0000000000000000000000000000000000000000 --- a/stdthread/stdthread.els +++ /dev/null @@ -1,39 +0,0 @@ -#!declare -stdthread_create(obj: object,f: def,...): ptr '''创建一个新线程,调用脚本中的函数 f ,并传递参数''' -stdthread_exit(): int '''退出当前线程''' -stdthread_join(obj: object): int '''阻塞至线程结束''' -stdthread_detach(obj: object): int '''分离当前线程''' -stdthread_cancel(obj: object): int '''终止当前线程''' -stdthread_self(): pid '''返回当前的PID''' -#!end -#!script -thread={} -def thread.class(): - var this = {} - this.create = stdthread_create - this.join = stdthread_join - this.detach = stdthread_detach - this.exit = stdthread_exit - this.self = stdthread_self - return this -; -thread.cancel = stdthread_cancel -thread.exit = stdthread_exit -#!end - -#!script-cn -线程={} -def 线程.class(): - var this = {} - this.启动 = stdthread_create - this.等待 = stdthread_join - this.分离 = stdthread_detach - this.退出 = stdthread_exit - this.自身ID = stdthread_self - return this -; -线程.停止 = stdthread_cancel -线程.退出 = stdthread_exit -#!end - - diff --git a/stdthread/stdthread.h b/stdthread/stdthread.h deleted file mode 100755 index dc20892aa9a35161d72b63a8ac4d8b2c52024d9b..0000000000000000000000000000000000000000 --- a/stdthread/stdthread.h +++ /dev/null @@ -1,53 +0,0 @@ -#include "els.h" -int ELSAPI_stdthread_stdthread_create(els_VmObj* vm); // stdthread_create(obj: object,f: def,...): ptr '''创建一个新线程,调用脚本中的函数 f ,并传递参数''' -int ELSAPI_stdthread_stdthread_exit(els_VmObj* vm); // stdthread_exit(): int '''退出当前线程''' -int ELSAPI_stdthread_stdthread_join(els_VmObj* vm); // stdthread_join(obj: object): int '''阻塞至线程结束''' -int ELSAPI_stdthread_stdthread_detach(els_VmObj* vm); // stdthread_detach(obj: object): int '''分离当前线程''' -int ELSAPI_stdthread_stdthread_cancel(els_VmObj* vm); // stdthread_cancel(obj: object): int '''终止当前线程''' -int ELSAPI_stdthread_stdthread_self(els_VmObj* vm); // stdthread_self(): pid '''返回当前的PID''' -#ifdef ELS_CONF_TOKEN_EN -static const char LibScript[]={ -116,104,114,101,97,100,61,123,125,10, -100,101,102,32,116,104,114,101,97,100,46,99,108,97,115,115,40,41,58,32,10, -32,32,32,32,118,97,114,32,116,104,105,115,32,61,32,123,125,10, -32,32,32,32,116,104,105,115,46,99,114,101,97,116,101,32,61,32,115,116,100,116,104,114,101,97,100,95,99,114,101,97,116,101,10, -32,32,32,32,116,104,105,115,46,106,111,105,110,32,32,32,61,32,115,116,100,116,104,114,101,97,100,95,106,111,105,110,10, -32,32,32,32,116,104,105,115,46,100,101,116,97,99,104,32,61,32,115,116,100,116,104,114,101,97,100,95,100,101,116,97,99,104,10, -32,32,32,32,116,104,105,115,46,101,120,105,116,32,32,32,61,32,115,116,100,116,104,114,101,97,100,95,101,120,105,116,10, -32,32,32,32,116,104,105,115,46,115,101,108,102,32,32,32,61,32,115,116,100,116,104,114,101,97,100,95,115,101,108,102,32,32,32,10, -32,32,32,32,114,101,116,117,114,110,32,116,104,105,115,10, -59,10, -116,104,114,101,97,100,46,99,97,110,99,101,108,32,61,32,115,116,100,116,104,114,101,97,100,95,99,97,110,99,101,108,10, -116,104,114,101,97,100,46,101,120,105,116,32,32,32,61,32,115,116,100,116,104,114,101,97,100,95,101,120,105,116,10, -0}; -#endif -#ifdef ELS_CONF_TOKEN_CN -static const char LibScript_cn[]={ --25,-70,-65,-25,-88,-117,61,123,125,10, -100,101,102,32,-25,-70,-65,-25,-88,-117,46,99,108,97,115,115,40,41,58,10, -32,32,32,32,118,97,114,32,116,104,105,115,32,61,32,123,125,10, -32,32,32,32,116,104,105,115,46,-27,-112,-81,-27,-118,-88,32,32,32,61,32,115,116,100,116,104,114,101,97,100,95,99,114,101,97,116,101,10, -32,32,32,32,116,104,105,115,46,-25,-83,-119,-27,-66,-123,32,32,32,61,32,115,116,100,116,104,114,101,97,100,95,106,111,105,110,10, -32,32,32,32,116,104,105,115,46,-27,-120,-122,-25,-90,-69,32,32,32,61,32,115,116,100,116,104,114,101,97,100,95,100,101,116,97,99,104,10, -32,32,32,32,116,104,105,115,46,-23,-128,-128,-27,-121,-70,32,32,32,61,32,115,116,100,116,104,114,101,97,100,95,101,120,105,116,10, -32,32,32,32,116,104,105,115,46,-24,-121,-86,-24,-70,-85,73,68,32,61,32,115,116,100,116,104,114,101,97,100,95,115,101,108,102,10, -32,32,32,32,114,101,116,117,114,110,32,116,104,105,115,10, -59,10, --25,-70,-65,-25,-88,-117,46,-27,-127,-100,-26,-83,-94,32,61,32,115,116,100,116,104,114,101,97,100,95,99,97,110,99,101,108,10, --25,-70,-65,-25,-88,-117,46,-23,-128,-128,-27,-121,-70,32,61,32,115,116,100,116,104,114,101,97,100,95,101,120,105,116,10, -0}; -#endif -void ElsLib_stdthread_libinit(els_VmObj *vm){ - vm_register(vm,"stdthread_exit",ELSAPI_stdthread_stdthread_exit); - vm_register(vm,"stdthread_self",ELSAPI_stdthread_stdthread_self); - vm_register(vm,"stdthread_join",ELSAPI_stdthread_stdthread_join); - vm_register(vm,"stdthread_create",ELSAPI_stdthread_stdthread_create); - vm_register(vm,"stdthread_cancel",ELSAPI_stdthread_stdthread_cancel); - vm_register(vm,"stdthread_detach",ELSAPI_stdthread_stdthread_detach); - #ifdef ELS_CONF_TOKEN_EN - vm_dostring(vm,LibScript); - #endif - #ifdef ELS_CONF_TOKEN_CN - vm_dostring(vm,LibScript_cn); - #endif -}; diff --git a/stdtime/Ubuntu/makefile b/stdtime/Ubuntu/makefile deleted file mode 100755 index 68e27546b4578c5acbdb59c44cbea5b4f4d6f597..0000000000000000000000000000000000000000 --- a/stdtime/Ubuntu/makefile +++ /dev/null @@ -1,13 +0,0 @@ -OBJS = stdtime.o -CFLAGS= -O2 -Wall -std=c99 -DELS_CONF_OS_LINUX -I ../buildenv -fPIC -CC=x86_64-linux-gnu-gcc -T=./ElsLib_stdtime.lsd - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -shared -s - -clean: - rm -rf $T $(OBJS) core core.* \ No newline at end of file diff --git a/stdtime/Windows/makefile b/stdtime/Windows/makefile deleted file mode 100755 index 27796e98ef0a96f58d764970c9322462b4fa2f2c..0000000000000000000000000000000000000000 --- a/stdtime/Windows/makefile +++ /dev/null @@ -1,13 +0,0 @@ -OBJS = stdtime.o -CFLAGS= -O2 -Wall -std=c99 -DELS_CONF_OS_WINDOWS -I ../buildenv -fPIC -CC=x86_64-w64-mingw32-gcc -T=./ElsLib_stdtime.lsd - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -shared -s -L ../buildenv -l:libeasylosu.dll -static - -clean: - rm -rf $T $(OBJS) core core.* \ No newline at end of file diff --git a/stdtime/info b/stdtime/info deleted file mode 100755 index fadd1ba8a726f935cdb61a9cbc837ba3cab9c837..0000000000000000000000000000000000000000 --- a/stdtime/info +++ /dev/null @@ -1,17 +0,0 @@ -{ - type = "const", - info = { - name = "stdtime/标准库(时间)", - text = "stdlib中的时间函数部分", - version = "23.11.30" - }, - source = { - all = {"stdtime.els","stdtime.h","stdtime.c"}, - Ubuntu = {"makefile"}, - Windows = {"makefile"}, - }, - target = { - Ubuntu = "make ; cp ElsLib_stdtime.lsd target/ElsLib_stdtime.lsd_Ubuntu ; make clean", - Windows = "make ; cp ElsLib_stdtime.lsd target/ElsLib_stdtime.lsd_Windows ; make clean", - } -} \ No newline at end of file diff --git a/stdtime/readme.md b/stdtime/readme.md deleted file mode 100755 index ef3397b121e1d1d831faf3236353a8bcb4294d79..0000000000000000000000000000000000000000 --- a/stdtime/readme.md +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/owls.wiki.losu.tech -# stdlib (stdtime) - -```python -#!declare -stdtime_getyear():int '获取年' -stdtime_getmon():int '获取月' -stdtime_getday():int '获取日' -stdtime_gethour():int '获取时' -stdtime_getmin():int '获取分' -stdtime_getsec():int '获取秒' -stdtime_getdate():int '获取周几' -stdtime_clock():int '获取计时器程序从运行开始的毫秒计时' -#!end - -#!script - -# time 结构类 -time = { - year = stdtime_getyear, - mon = stdtime_getmon, - day = stdtime_getday, - hour = stdtime_gethour, - min = stdtime_getmin, - sec = stdtime_getsec, - date = stdtime_getdate, - clock = stdtime_clock, -} -#!end -#!script-cn -时间 = { - 年 = stdtime_getyear, - 月 = stdtime_getmon, - 日 = stdtime_getday, - 时 = stdtime_gethour, - 分 = stdtime_getmin, - 秒 = stdtime_getsec, - 周几 = stdtime_getdate, - 计时 = stdtime_clock, -} -#!end - -``` \ No newline at end of file diff --git a/stdtime/stdtime.c b/stdtime/stdtime.c deleted file mode 100755 index b2889941066e07883e1ad08b24f1d43c960c5802..0000000000000000000000000000000000000000 --- a/stdtime/stdtime.c +++ /dev/null @@ -1,64 +0,0 @@ -#include "stdtime.h" -#include -//#include "../buildenv/els.h" -int ELSAPI_stdtime_stdtime_getyear(els_VmObj* vm) // stdtime_getyear():int '获取年' -{ - time_t t; - time(&t); - arg_returnnum(vm,(localtime(&t) -> tm_year) +1900); - return 1; -} - -int ELSAPI_stdtime_stdtime_getmon(els_VmObj* vm) // stdtime_getmon():int '获取月' -{ - time_t t; - time(&t); - arg_returnnum(vm,localtime(&t) -> tm_mon+1); - return 1; -} - -int ELSAPI_stdtime_stdtime_getday(els_VmObj* vm) // stdtime_getday():int '获取日' -{ - time_t t; - time(&t); - arg_returnnum(vm,localtime(&t) -> tm_mday); - return 1; -} - -int ELSAPI_stdtime_stdtime_gethour(els_VmObj* vm) // stdtime_gethour():int '获取时' -{ - time_t t; - time(&t); - arg_returnnum(vm,localtime(&t) -> tm_hour); - return 1; -} - -int ELSAPI_stdtime_stdtime_getmin(els_VmObj* vm) // stdtime_getmin():int '获取分' -{ - time_t t; - time(&t); - arg_returnnum(vm,localtime(&t) -> tm_min); - return 1; -} - -int ELSAPI_stdtime_stdtime_getsec(els_VmObj* vm) // stdtime_getsec():int '获取秒' -{ - time_t t; - time(&t); - arg_returnnum(vm,localtime(&t) -> tm_sec); - return 1; -} - -int ELSAPI_stdtime_stdtime_getdate(els_VmObj* vm) // stdtime_getdate():int '获取周几' -{ - time_t t; - time(&t); - arg_returnnum(vm,localtime(&t) -> tm_wday); - return 1; -} - -int ELSAPI_stdtime_stdtime_clock(els_VmObj* vm) // stdtime_clock():int '获取计时器程序从运行开始的毫秒计时' -{ - arg_returnnum(vm,(Number)(clock())/CLOCKS_PER_SEC); - return 1; -} diff --git a/stdtime/stdtime.els b/stdtime/stdtime.els deleted file mode 100755 index e98b9b36629d0a79b2c8091a0263bd11fcae37dc..0000000000000000000000000000000000000000 --- a/stdtime/stdtime.els +++ /dev/null @@ -1,37 +0,0 @@ -#!declare -stdtime_getyear():int '获取年' -stdtime_getmon():int '获取月' -stdtime_getday():int '获取日' -stdtime_gethour():int '获取时' -stdtime_getmin():int '获取分' -stdtime_getsec():int '获取秒' -stdtime_getdate():int '获取周几' -stdtime_clock():int '获取计时器程序从运行开始的毫秒计时' -#!end - -#!script - -# time 结构类 -time = { - year = stdtime_getyear, - mon = stdtime_getmon, - day = stdtime_getday, - hour = stdtime_gethour, - min = stdtime_getmin, - sec = stdtime_getsec, - date = stdtime_getdate, - clock = stdtime_clock, -} -#!end -#!script-cn -时间 = { - 年 = stdtime_getyear, - 月 = stdtime_getmon, - 日 = stdtime_getday, - 时 = stdtime_gethour, - 分 = stdtime_getmin, - 秒 = stdtime_getsec, - 周几 = stdtime_getdate, - 计时 = stdtime_clock, -} -#!end \ No newline at end of file diff --git a/stdtime/stdtime.h b/stdtime/stdtime.h deleted file mode 100755 index 886e3e89d2ab0b17d23e8ebbcac1b6d1f0327cf7..0000000000000000000000000000000000000000 --- a/stdtime/stdtime.h +++ /dev/null @@ -1,55 +0,0 @@ -#include "els.h" -int ELSAPI_stdtime_stdtime_getyear(els_VmObj* vm); // stdtime_getyear():int '获取年' -int ELSAPI_stdtime_stdtime_getmon(els_VmObj* vm); // stdtime_getmon():int '获取月' -int ELSAPI_stdtime_stdtime_getday(els_VmObj* vm); // stdtime_getday():int '获取日' -int ELSAPI_stdtime_stdtime_gethour(els_VmObj* vm); // stdtime_gethour():int '获取时' -int ELSAPI_stdtime_stdtime_getmin(els_VmObj* vm); // stdtime_getmin():int '获取分' -int ELSAPI_stdtime_stdtime_getsec(els_VmObj* vm); // stdtime_getsec():int '获取秒' -int ELSAPI_stdtime_stdtime_getdate(els_VmObj* vm); // stdtime_getdate():int '获取周几' -int ELSAPI_stdtime_stdtime_clock(els_VmObj* vm); // stdtime_clock():int '获取计时器程序从运行开始的毫秒计时' -#ifdef ELS_CONF_TOKEN_EN -static const char LibScript[]={ -10, -35,32,116,105,109,101,32,-25,-69,-109,-26,-98,-124,-25,-79,-69,10, -116,105,109,101,32,61,32,123,10, -32,32,32,32,121,101,97,114,32,61,32,115,116,100,116,105,109,101,95,103,101,116,121,101,97,114,44,10, -32,32,32,32,109,111,110,32,32,61,32,115,116,100,116,105,109,101,95,103,101,116,109,111,110,44,10, -32,32,32,32,100,97,121,32,32,61,32,115,116,100,116,105,109,101,95,103,101,116,100,97,121,44,10, -32,32,32,32,104,111,117,114,32,61,32,115,116,100,116,105,109,101,95,103,101,116,104,111,117,114,44,10, -32,32,32,32,109,105,110,32,32,61,32,115,116,100,116,105,109,101,95,103,101,116,109,105,110,44,10, -32,32,32,32,115,101,99,32,32,61,32,115,116,100,116,105,109,101,95,103,101,116,115,101,99,44,10, -32,32,32,32,100,97,116,101,32,61,32,115,116,100,116,105,109,101,95,103,101,116,100,97,116,101,44,10, -32,32,32,32,99,108,111,99,107,32,32,32,61,32,115,116,100,116,105,109,101,95,99,108,111,99,107,44,10, -125,10, -0}; -#endif -#ifdef ELS_CONF_TOKEN_CN -static const char LibScript_cn[]={ --26,-105,-74,-23,-105,-76,32,61,32,123,10, -32,32,32,32,-27,-71,-76,32,32,32,61,32,115,116,100,116,105,109,101,95,103,101,116,121,101,97,114,44,10, -32,32,32,32,-26,-100,-120,32,32,32,61,32,115,116,100,116,105,109,101,95,103,101,116,109,111,110,44,10, -32,32,32,32,-26,-105,-91,32,32,32,61,32,115,116,100,116,105,109,101,95,103,101,116,100,97,121,44,10, -32,32,32,32,-26,-105,-74,32,32,32,61,32,115,116,100,116,105,109,101,95,103,101,116,104,111,117,114,44,10, -32,32,32,32,-27,-120,-122,32,32,32,61,32,115,116,100,116,105,109,101,95,103,101,116,109,105,110,44,10, -32,32,32,32,-25,-89,-110,32,32,32,61,32,115,116,100,116,105,109,101,95,103,101,116,115,101,99,44,10, -32,32,32,32,-27,-111,-88,-27,-121,-96,32,61,32,115,116,100,116,105,109,101,95,103,101,116,100,97,116,101,44,10, -32,32,32,32,-24,-82,-95,-26,-105,-74,32,61,32,115,116,100,116,105,109,101,95,99,108,111,99,107,44,10, -125,10, -0}; -#endif -void ElsLib_stdtime_libinit(els_VmObj *vm){ - vm_register(vm,"stdtime_getyear",ELSAPI_stdtime_stdtime_getyear); - vm_register(vm,"stdtime_clock",ELSAPI_stdtime_stdtime_clock); - vm_register(vm,"stdtime_getday",ELSAPI_stdtime_stdtime_getday); - vm_register(vm,"stdtime_getdate",ELSAPI_stdtime_stdtime_getdate); - vm_register(vm,"stdtime_gethour",ELSAPI_stdtime_stdtime_gethour); - vm_register(vm,"stdtime_getmin",ELSAPI_stdtime_stdtime_getmin); - vm_register(vm,"stdtime_getsec",ELSAPI_stdtime_stdtime_getsec); - vm_register(vm,"stdtime_getmon",ELSAPI_stdtime_stdtime_getmon); - #ifdef ELS_CONF_TOKEN_EN - vm_dostring(vm,LibScript); - #endif - #ifdef ELS_CONF_TOKEN_CN - vm_dostring(vm,LibScript_cn); - #endif -}; diff --git a/stdvm/Ubuntu/makefile b/stdvm/Ubuntu/makefile deleted file mode 100755 index a499a2cfab3b2de3104b480ef794eb7aa58cac9c..0000000000000000000000000000000000000000 --- a/stdvm/Ubuntu/makefile +++ /dev/null @@ -1,13 +0,0 @@ -OBJS = stdvm.o -CFLAGS= -O2 -Wall -std=c99 -DELS_CONF_OS_LINUX -I ../buildenv -fPIC -CC=x86_64-linux-gnu-gcc -T=./ElsLib_stdvm.lsd - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -shared -s - -clean: - rm -rf $T $(OBJS) core core.* \ No newline at end of file diff --git a/stdvm/Windows/makefile b/stdvm/Windows/makefile deleted file mode 100755 index d0a91c73ffcfd3682ae62b1ed1a70be96f4fcc30..0000000000000000000000000000000000000000 --- a/stdvm/Windows/makefile +++ /dev/null @@ -1,13 +0,0 @@ -OBJS = stdvm.o -CFLAGS= -O2 -Wall -std=c99 -DELS_CONF_OS_WINDOWS -I ../buildenv -fPIC -CC=x86_64-w64-mingw32-gcc -T=./ElsLib_stdvm.lsd - - -all: $T - -$T: $(OBJS) - $(CC) -o $@ $(OBJS) -shared -s -L ../buildenv -l:libeasylosu.dll -static - -clean: - rm -rf $T $(OBJS) core core.* \ No newline at end of file diff --git a/stdvm/info b/stdvm/info deleted file mode 100755 index 2734e7670286af82a57077c68ccd9b707284a287..0000000000000000000000000000000000000000 --- a/stdvm/info +++ /dev/null @@ -1,21 +0,0 @@ -{ - type = "const", - info = { - name = "stdvm/标准库(解释器)", - text = "stdlib中的解释器模块部分", - version = "23.12.20" - }, - source = { - all = { - "stdvm.els", - "stdvm.h", - "stdvm.c" - }, - Ubuntu = {"makefile"}, - Windows = {"makefile"}, - }, - target ={ - Ubuntu = "make ; cp ElsLib_stdvm.lsd target/ElsLib_stdvm.lsd_Ubuntu ; make clean", - Windows = "make ; cp ElsLib_stdvm.lsd target/ElsLib_stdvm.lsd_Windows ; make clean", - } -} \ No newline at end of file diff --git a/stdvm/readme.md b/stdvm/readme.md deleted file mode 100755 index f87c071c169e5439ba10bb374262fda66af1613b..0000000000000000000000000000000000000000 --- a/stdvm/readme.md +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/owls.wiki.losu.tech -# stdlib (stdvm) -```python -''' -V 1.7.0 + 版本开始支持的模块,主要用以获取与设定虚拟机的状态 -''' -#!declare -stdvm_get_version(): str '获取版本信息' -stdvm_get_build(): str '获取构建信息' -stdvm_get_copy(): str '获取版权信息' -stdvm_get_branch(): str '获取分支信息' -stdvm_set_gc(o:object,size: int,p:str): null '设置GC上限,p可以为 B,K(默认),M' -stdvm_get_mem(o: obj,p:str): int '获取内存占用大小,单位 B(默认),K,M' -stdvm_get_gc(o: obj,p:str): int '获取GC上限,单位 B(默认),K,M' -stdvm_gc() '立即进行GC' -#!end -#!script -vm = { - version = stdvm_get_version, - build = stdvm_get_build, - copy = stdvm_get_copy, - branch = stdvm_get_branch, - setgc = stdvm_set_gc, - getmem = stdvm_get_mem, - getgc = stdvm_get_gc, - gc = stdvm_gc, -} -#!end -#!script-cn -解释器 = { - 版本 = stdvm_get_version, - 构建 = stdvm_get_build, - 版权 = stdvm_get_copy, - 分支 = stdvm_get_branch, - 设定GC = stdvm_set_gc, - 获取内存 = stdvm_get_mem, - 获取GC = stdvm_get_gc, - 回收垃圾 = stdvm_gc, -} -#!end -``` \ No newline at end of file diff --git a/stdvm/stdvm.c b/stdvm/stdvm.c deleted file mode 100755 index 7d0bd860ab04e5ab551389b3d2b7aa3f201461c8..0000000000000000000000000000000000000000 --- a/stdvm/stdvm.c +++ /dev/null @@ -1,73 +0,0 @@ -#include "stdvm.h" -#include "els_vmhost.h" -#include -extern void els_Gc_checkGC(els_VmObj *L); - -int ELSAPI_stdvm_stdvm_get_version(els_VmObj* vm){ - arg_returnstr(vm,ELS_VERSION); - return 1; -} // stdvm_get_version(): str '获取版本信息' - -int ELSAPI_stdvm_stdvm_get_build(els_VmObj* vm){ - arg_returnstr(vm,ELS_BUILD); - return 1; -} // stdvm_get_build(): str '获取构建信息' - -int ELSAPI_stdvm_stdvm_get_copy(els_VmObj* vm){ - arg_returnstr(vm,ELS_COPYRIGHT); - return 1; -} // stdvm_get_copy(): str '获取版权信息' - -int ELSAPI_stdvm_stdvm_get_branch(els_VmObj* vm){ - arg_returnstr(vm,ELS_BRANCH); - return 1; -} // stdvm_get_branch(): str '获取分支信息' - -int ELSAPI_stdvm_stdvm_set_gc(els_VmObj* vm){ - int i = 0; - switch (arg_getstr(vm,3)[0]) - { - case 'B': case 'b' : i = 1; break; - case 'K': case 'k' : i = 1024; break; - case 'M': case 'm' : i = 1024*1024; break; - default : i = 1024;break; - } - vm_setGC(vm,(unsigned long)((unsigned long)(i) * (unsigned long)(arg_getnum(vm,2)) )); - return 0; - -} // stdvm_set_gc(o:object,size: int,p:str): null '设置GC上限,p可以为 B,KB(默认),M' - -int ELSAPI_stdvm_stdvm_get_mem(els_VmObj* vm){ - int i = 0; - switch (arg_getstr(vm,2)[0]) - { - case 'B': case 'b' : i = 1; break; - case 'K': case 'k' : i = 1024; break; - case 'M': case 'm' : i = 1024*1024; break; - default : i = 1;break; - } - double n = vm->nblocks / i; - arg_returnnum(vm,n); - return 1; -} // stdvm_get_mem(o: obj,p:str): int '获取内存占用大小,单位 B(默认),K,M' -int ELSAPI_stdvm_stdvm_get_gc(els_VmObj* vm){ - int i = 0; - switch (arg_getstr(vm,2)[0]) - { - case 'B': case 'b' : i = 1; break; - case 'K': case 'k' : i = 1024; break; - case 'M': case 'm' : i = 1024*1024; break; - default : i = 1;break; - } - if(vm->GCnowmax>vm->GCMAX) - vm->GCnowmax=vm->GCMAX; - double n = vm->GCnowmax / i; - arg_returnnum(vm,n); - return 1; -} // stdvm_get_gc(o: obj,p:str): int '获取GC上限,单位 B(默认),K,M' - -int ELSAPI_stdvm_stdvm_gc(els_VmObj* vm){ - vm->GCnowmax=vm->nblocks; - els_Gc_checkGC(vm); - return 0; -} // stdvm_gc() '立即进行GC' \ No newline at end of file diff --git a/stdvm/stdvm.els b/stdvm/stdvm.els deleted file mode 100755 index baa68703f3b6eed4774467eb73c78006331d4250..0000000000000000000000000000000000000000 --- a/stdvm/stdvm.els +++ /dev/null @@ -1,37 +0,0 @@ -''' -V 1.7.0 + 版本开始支持的模块,主要用以获取与设定虚拟机的状态 -''' -#!declare -stdvm_get_version(): str '获取版本信息' -stdvm_get_build(): str '获取构建信息' -stdvm_get_copy(): str '获取版权信息' -stdvm_get_branch(): str '获取分支信息' -stdvm_set_gc(o:object,size: int,p:str): null '设置GC上限,p可以为 B,K(默认),M' -stdvm_get_mem(o: obj,p:str): int '获取内存占用大小,单位 B(默认),K,M' -stdvm_get_gc(o: obj,p:str): int '获取GC上限,单位 B(默认),K,M' -stdvm_gc() '立即进行GC' -#!end -#!script -vm = { - version = stdvm_get_version, - build = stdvm_get_build, - copy = stdvm_get_copy, - branch = stdvm_get_branch, - setgc = stdvm_set_gc, - getmem = stdvm_get_mem, - getgc = stdvm_get_gc, - gc = stdvm_gc, -} -#!end -#!script-cn -解释器 = { - 版本 = stdvm_get_version, - 构建 = stdvm_get_build, - 版权 = stdvm_get_copy, - 分支 = stdvm_get_branch, - 设定GC = stdvm_set_gc, - 获取内存 = stdvm_get_mem, - 获取GC = stdvm_get_gc, - 回收垃圾 = stdvm_gc, -} -#!end \ No newline at end of file diff --git a/stdvm/stdvm.h b/stdvm/stdvm.h deleted file mode 100755 index cd51f6833089fd7983734f3453bad614c33f3a20..0000000000000000000000000000000000000000 --- a/stdvm/stdvm.h +++ /dev/null @@ -1,53 +0,0 @@ -#include "els.h" -int ELSAPI_stdvm_stdvm_get_version(els_VmObj* vm); // stdvm_get_version(): str '获取版本信息' -int ELSAPI_stdvm_stdvm_get_build(els_VmObj* vm); // stdvm_get_build(): str '获取构建信息' -int ELSAPI_stdvm_stdvm_get_copy(els_VmObj* vm); // stdvm_get_copy(): str '获取版权信息' -int ELSAPI_stdvm_stdvm_get_branch(els_VmObj* vm); // stdvm_get_branch(): str '获取分支信息' -int ELSAPI_stdvm_stdvm_set_gc(els_VmObj* vm); // stdvm_set_gc(o:object,size: int,p:str): null '设置GC上限,p可以为 B,K(默认),M' -int ELSAPI_stdvm_stdvm_get_mem(els_VmObj* vm); // stdvm_get_mem(o: obj,p:str): int '获取内存占用大小,单位 B(默认),K,M' -int ELSAPI_stdvm_stdvm_get_gc(els_VmObj* vm); // stdvm_get_gc(o: obj,p:str): int '获取GC上限,单位 B(默认),K,M' -int ELSAPI_stdvm_stdvm_gc(els_VmObj* vm); // stdvm_gc() '立即进行GC' -#ifdef ELS_CONF_TOKEN_EN -static const char LibScript[]={ -118,109,32,61,32,123,10, -32,32,32,32,118,101,114,115,105,111,110,32,61,32,115,116,100,118,109,95,103,101,116,95,118,101,114,115,105,111,110,44,10, -32,32,32,32,98,117,105,108,100,32,32,32,61,32,115,116,100,118,109,95,103,101,116,95,98,117,105,108,100,44,10, -32,32,32,32,99,111,112,121,32,32,32,32,61,32,115,116,100,118,109,95,103,101,116,95,99,111,112,121,44,10, -32,32,32,32,98,114,97,110,99,104,32,32,61,32,115,116,100,118,109,95,103,101,116,95,98,114,97,110,99,104,44,10, -32,32,32,32,115,101,116,103,99,32,32,32,61,32,115,116,100,118,109,95,115,101,116,95,103,99,44,10, -32,32,32,32,103,101,116,109,101,109,32,32,61,32,115,116,100,118,109,95,103,101,116,95,109,101,109,44,10, -32,32,32,32,103,101,116,103,99,32,32,32,61,32,115,116,100,118,109,95,103,101,116,95,103,99,44,10, -32,32,32,32,103,99,32,32,32,32,32,32,61,32,115,116,100,118,109,95,103,99,44,10, -125,10, -0}; -#endif -#ifdef ELS_CONF_TOKEN_CN -static const char LibScript_cn[]={ --24,-89,-93,-23,-121,-118,-27,-103,-88,32,61,32,123,10, -32,32,32,32,-25,-119,-120,-26,-100,-84,32,61,32,115,116,100,118,109,95,103,101,116,95,118,101,114,115,105,111,110,44,10, -32,32,32,32,-26,-98,-124,-27,-69,-70,32,32,32,61,32,115,116,100,118,109,95,103,101,116,95,98,117,105,108,100,44,10, -32,32,32,32,-25,-119,-120,-26,-99,-125,32,32,32,32,61,32,115,116,100,118,109,95,103,101,116,95,99,111,112,121,44,10, -32,32,32,32,-27,-120,-122,-26,-108,-81,32,32,61,32,115,116,100,118,109,95,103,101,116,95,98,114,97,110,99,104,44,10, -32,32,32,32,-24,-82,-66,-27,-82,-102,71,67,32,32,32,61,32,115,116,100,118,109,95,115,101,116,95,103,99,44,10, -32,32,32,32,-24,-114,-73,-27,-113,-106,-27,-122,-123,-27,-83,-104,32,32,61,32,115,116,100,118,109,95,103,101,116,95,109,101,109,44,10, -32,32,32,32,-24,-114,-73,-27,-113,-106,71,67,32,32,32,61,32,115,116,100,118,109,95,103,101,116,95,103,99,44,10, -32,32,32,32,-27,-101,-98,-26,-108,-74,-27,-98,-125,-27,-100,-66,32,61,32,115,116,100,118,109,95,103,99,44,10, -125,10, -0}; -#endif -void ElsLib_stdvm_libinit(els_VmObj *vm){ - vm_register(vm,"stdvm_get_version",ELSAPI_stdvm_stdvm_get_version); - vm_register(vm,"stdvm_get_build",ELSAPI_stdvm_stdvm_get_build); - vm_register(vm,"stdvm_gc",ELSAPI_stdvm_stdvm_gc); - vm_register(vm,"stdvm_get_branch",ELSAPI_stdvm_stdvm_get_branch); - vm_register(vm,"stdvm_get_gc",ELSAPI_stdvm_stdvm_get_gc); - vm_register(vm,"stdvm_get_mem",ELSAPI_stdvm_stdvm_get_mem); - vm_register(vm,"stdvm_get_copy",ELSAPI_stdvm_stdvm_get_copy); - vm_register(vm,"stdvm_set_gc",ELSAPI_stdvm_stdvm_set_gc); - #ifdef ELS_CONF_TOKEN_EN - vm_dostring(vm,LibScript); - #endif - #ifdef ELS_CONF_TOKEN_CN - vm_dostring(vm,LibScript_cn); - #endif -}; diff --git "a/lsnput/WIKI/\345\216\206\345\217\262/.keep" b/template/.keep old mode 100644 new mode 100755 similarity index 100% rename from "lsnput/WIKI/\345\216\206\345\217\262/.keep" rename to template/.keep diff --git a/template/package/config b/template/package/config new file mode 100755 index 0000000000000000000000000000000000000000..364b8ec72e5e50df91b8781138ec8b7d2bafaa6f --- /dev/null +++ b/template/package/config @@ -0,0 +1,9 @@ +pkgs = { + name: "template", + version: "1.0.0", + description: "", + target:{ + "x86_64-linux-gnu", + "x86_64-w64-mingw32", + }, +} \ No newline at end of file diff --git a/lsnput/Windows/.keep b/template/package/target/x86_64-linux-gnu.mk old mode 100644 new mode 100755 similarity index 100% rename from lsnput/Windows/.keep rename to template/package/target/x86_64-linux-gnu.mk diff --git a/socket/Ubuntu/.keep b/template/package/target/x86_64-w64-mingw32.mk similarity index 100% rename from socket/Ubuntu/.keep rename to template/package/target/x86_64-w64-mingw32.mk diff --git a/test/config b/test/config new file mode 100755 index 0000000000000000000000000000000000000000..fe54cffe48f02e83809cbeee65521eb685ebd6fa --- /dev/null +++ b/test/config @@ -0,0 +1,12 @@ +main = { + name: "test", + target: "x86_64-linux-gnu.mk", + # target: "x86_64-w64-mingw32.mk", + pkgs : { + "helloworld", + "stdlib", + "time", + "math", + "cstring", + }, +} diff --git a/test/main.c b/test/main.c new file mode 100755 index 0000000000000000000000000000000000000000..55ba2a12375cdf77e31a4c95a4eea6b238962e8a --- /dev/null +++ b/test/main.c @@ -0,0 +1,29 @@ +#include "losu.h" +#include +#include + +/* need config */ +#include "pkgs.inc" + +/* need losuc -c main.els */ +static const char __main__[] = +#include "main.els.inc" + ; + +/* main */ +int32_t +main (int32_t argc, const char **argv) +{ + int32_t i = 0; + LosuVm *vm = vm_create (1024); + if (vm) + { + LosuPackages = &_inlinePkgs[0]; + vm_init (vm, argc, argv); + i = vm_dobyte (vm,__main__,sizeof(__main__),"main.els"); + } + else + i = -1; + vm_close(vm); + return i; +} \ No newline at end of file diff --git a/test/main.els b/test/main.els new file mode 100755 index 0000000000000000000000000000000000000000..b572e6efef6da82069f13f71edfabce40c7ebd97 --- /dev/null +++ b/test/main.els @@ -0,0 +1,3 @@ +import "stdlib" +print("Hello, world!") +print("test") \ No newline at end of file diff --git a/test/main.els.hex b/test/main.els.hex new file mode 100644 index 0000000000000000000000000000000000000000..872aa77ba47175243621d2d087ea246eaf6c9da9 Binary files /dev/null and b/test/main.els.hex differ diff --git a/test/main.els.inc b/test/main.els.inc new file mode 100755 index 0000000000000000000000000000000000000000..301d3f54fd82b8477d9deb581325c1e660d0551e --- /dev/null +++ b/test/main.els.inc @@ -0,0 +1,21 @@ +{ + 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x09, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x65, 0x6c, + 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x03, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x7f, + 0x05, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x69, + 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x73, 0x74, 0x64, 0x6c, 0x69, 0x62, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x00, 0x0e, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x77, 0x6f, + 0x72, 0x6c, 0x64, 0x21, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x74, 0x65, 0x73, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0a, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x8b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc5, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x8b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; diff --git a/test/pkgs.inc b/test/pkgs.inc new file mode 100755 index 0000000000000000000000000000000000000000..dabfa00032a48602ea6225a77ac1db3e484e7517 --- /dev/null +++ b/test/pkgs.inc @@ -0,0 +1,13 @@ +LosuExtern LosuModule *__losuh__LOADMODULE_helloworld(); +LosuExtern LosuModule *__losuh__LOADMODULE_stdlib(); +LosuExtern LosuModule *__losuh__LOADMODULE_time(); +LosuExtern LosuModule *__losuh__LOADMODULE_math(); +LosuExtern LosuModule *__losuh__LOADMODULE_cstring(); +static LosuPackage_t _inlinePkgs[]={ +{"helloworld",__losuh__LOADMODULE_helloworld}, +{"stdlib",__losuh__LOADMODULE_stdlib}, +{"time",__losuh__LOADMODULE_time}, +{"math",__losuh__LOADMODULE_math}, +{"cstring",__losuh__LOADMODULE_cstring}, +{NULL,NULL}, +}; diff --git a/test/target/x86_64-linux-gnu.mk b/test/target/x86_64-linux-gnu.mk new file mode 100755 index 0000000000000000000000000000000000000000..5f904e2f7ab43af43d08964e3ee45dd4d4534a23 --- /dev/null +++ b/test/target/x86_64-linux-gnu.mk @@ -0,0 +1,12 @@ +cc=x86_64-linux-gnu-gcc + +cWarning= -Wall +cStd= -std=c99 +cOpt= -O2 +cInclude= -I$(LosuSDK_Include) +cFlags= $(cWarning) $(cStd) $(cOpt) $(cInclude) +cLink= -L $(LosuSDK_Build)/target -llosucore -lm + +$(main.out): main.els $(LosuSDK_Build)/target/liblosucore.a + losuc -c main.els + $(cc) -o $@ $(cFlags) main.c $(cLink) diff --git a/test/target/x86_64-w64-mingw32.mk b/test/target/x86_64-w64-mingw32.mk new file mode 100755 index 0000000000000000000000000000000000000000..ac4e68d412f5c106e48c06d36bf52d15d4a234a1 --- /dev/null +++ b/test/target/x86_64-w64-mingw32.mk @@ -0,0 +1,14 @@ +cc=x86_64-w64-mingw32-gcc + +cWarning= -Wall +cStd= -std=c99 +cOpt= -Os +cInclude= -I$(LosuSDK_Include) +cFlags= $(cWarning) $(cStd) $(cOpt) $(cInclude) +cLink= -static -L $(LosuSDK_Build)/target -llosucore -lm + +$(main.out): main.els + losuc -c main.els + + $(cc) -o $@ $(cFlags) main.c $(cLink) + \ No newline at end of file diff --git a/test/test b/test/test new file mode 100755 index 0000000000000000000000000000000000000000..3f226b514c0f0485356909eb504aca76eba134dd Binary files /dev/null and b/test/test differ diff --git a/tools/losuc/LICENSE b/tools/losuc/LICENSE new file mode 100755 index 0000000000000000000000000000000000000000..58c54142a03cfb878e765a9da91f0d352945c752 --- /dev/null +++ b/tools/losuc/LICENSE @@ -0,0 +1,8 @@ +The MIT License (MIT) +Copyright © 2024 Dongqiao Huang + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/tools/losuc/include/losuc.h b/tools/losuc/include/losuc.h new file mode 100755 index 0000000000000000000000000000000000000000..0f8c43991be22f52a87cb6dcc796ee753fae9145 --- /dev/null +++ b/tools/losuc/include/losuc.h @@ -0,0 +1,100 @@ +/* + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +/* + This document is part of the Losu Community OSPP - 2024 subject results + contributed by Dongqiao Huang @ NEUQ, following MIT LICENSE Contributed to + the Losu Community. + + The MIT LICENSE is as follows + -------------------- + Copyright 2024 Dongqiao Huang + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +/* Byte Code Head Struct + -------------------- + |magic: 0| + |Endianness: 1 = little,0 = big| + |Version: | + |Vm-bitsize: 32/64| + |Chuck| +*/ + +#ifndef __LOSUC_H__ +#define __LOSUC_H__ + +#include "losu.h" +#include +#include + +/* Encode functions */ +LosuExtern void __losu_bytecode_encode (_inlineScode *main, FILE *f, + _l_bool isC); + +#define __losuc_help__ \ +"\ +------------------------------------------------\n\ +| losuc: Compiler in Losu-SDK |\n\ +| filename make file to .bin |\n\ +| -a filename make file for both |\n\ +| -c filename make file to C .inc |\n\ +| -h filename make file by 'losuh' |\n\ +------------------------------------------------\n\ +" + +#endif \ No newline at end of file diff --git a/tools/losuc/makefile b/tools/losuc/makefile new file mode 100755 index 0000000000000000000000000000000000000000..868fd39cc1e9b705b399f98fd9bf307ba9a0be7f --- /dev/null +++ b/tools/losuc/makefile @@ -0,0 +1,31 @@ +PkgObj=$(LosuSDK_Obj)/sdk/losuc + +cc=cc + +CIncFile=$(shell ls include/*.h) $(shell ls $(LosuSDK_Include)/*.h) + +cWarning= -Wall +cStd= -std=c99 +cOpt= -O2 +cInclude= -I$(LosuSDK_Include) -Iinclude +cLink= -lm -L$(LosuSDK_Lib) -l:liblosu.a +cFlags= $(cWarning) $(cStd) $(cOpt) $(cInclude) + + + + +$(LosuSDK_Path)/losuc:\ + $(PkgObj)/losuc.o\ + $(PkgObj)/main.o\ + $(LosuSDK_Lib)/liblosu.a\ + + $(cc) -o $@ $^ $(cLink) + + +$(PkgObj)/losuc.o: src/losuc.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ + +$(PkgObj)/main.o: src/main.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ + + diff --git a/tools/losuc/readme.md b/tools/losuc/readme.md new file mode 100755 index 0000000000000000000000000000000000000000..b7f1592fab0000bc484750a73cb178fe185cb2cf --- /dev/null +++ b/tools/losuc/readme.md @@ -0,0 +1,61 @@ +# losuc · Losu Compiler + +## 简介 +Losuc,全称 Losu Compiler,是 Losu SDK 包含的工具之一,用于编译 Losu 编写的源代码文件到二进制文件。 + +## 使用方法 + +1. 在 Losu SDK 环境下,使用以下命令编译源代码文件,生成 .hex 后缀的二进制文件: + +```sh +losuc filename +``` + +2. 在 Losu SDK 环境下,使用以下命令编译源代码文件,生成 .inc 后缀的 C语言 数组文件: + +```sh +losuc -c filename +``` + +3. 在 Losu SDK 环境下,使用以下命令编译源代码文件,同时生成 .hex 后缀的二进制文件和 .inc 后缀的 C语言 数组文件: + +```sh +losuc -a filename +``` + +4. 在 Losu SDK 环境下,使用以下命令调用 losuh 工具,编译 .lsh 到 C语言 接口文件。(关于 losuh 命令,可以参考 `SDK/tools/losuh/readme.md` ) + +```sh +losuc -h filename +``` + +# losuc · Losu Compiler + +## Introduction +Losuc, known as Losu Compiler, is one of the tools included in the Losu SDK for compiling source code files written by Losu into binary files. + +## Usage + +1. In the Losu SDK environment, use the following command to compile the source code file to generate a binary file with the .hex suffix: + +```sh +losuc filename +``` + +2. In the Losu SDK environment, use the following command to compile the source code file to generate a C language array file with the .inc suffix: + +```sh +losuc -c filename +``` + +3. In the Losu SDK environment, use the following command to compile the source code file and generate both a binary file with the .hex suffix and a C language array file with the .inc suffix: + +```sh +losuc -a filename +``` + +4. In the Losu SDK environment, use the following command to call the losuh tool to compile .lsh to a C language interface file. (For more information about the losuh command, refer to `SDK/tools/losuh/readme.md`) + +```sh +losuc -h filename +``` diff --git a/tools/losuc/src/losuc.c b/tools/losuc/src/losuc.c new file mode 100755 index 0000000000000000000000000000000000000000..a98b2ce627f4790566639b9b16145da423e71c93 --- /dev/null +++ b/tools/losuc/src/losuc.c @@ -0,0 +1,253 @@ +/* + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +/* + This document is part of the Losu Community OSPP - 2024 subject results + contributed by Dongqiao Huang @ NEUQ, following MIT LICENSE Contributed to + the Losu Community. + + The MIT LICENSE is as follows + -------------------- + Copyright 2024 Dongqiao Huang + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +/* include headfile */ +#include "losuc.h" + +/* static segment */ + +/* function for object */ +static void __losuIrEncodeHead (FILE *f, _l_bool isC); +static void __losuIrEncodeFunc (_inlineScode *fs, FILE *f, _l_bool isC); +static void __losuIrEncodeConst (_inlineScode *fs, FILE *f, _l_bool isC); +static void __losuIrEncodeLine (_inlineScode *fs, FILE *f, _l_bool isC); +static void __losuIrEncodeLcvar (_inlineScode *fs, FILE *f, _l_bool isC); +static void __losuIrEncodeIns (_inlineScode *fs, FILE *f, _l_bool isC); +static void __losuIrEncodeString (_inlineString *s, FILE *f, _l_bool isC); +static void __losuIrEncodeSizet (_l_size_t n, FILE *f, _l_bool isC); +static void __losuIrEncodeInt32 (int32_t n, FILE *f, _l_bool isC); + +/* IO function */ +static void __losuIrEncodeByte (uint8_t c, FILE *f, _l_bool isC); +static void __losuIrEncodeBlock (void *p, size_t len, FILE *f, _l_bool isC); +static void __losuIrEncodeVector (void *p, size_t n, size_t s, FILE *f, + _l_bool isC); + +/* function segment */ +/* Encode functions */ +LosuExtern void +__losu_bytecode_encode (_inlineScode *main, FILE *f, _l_bool isC) +{ + if (isC) + { + fputc ('{', f); + fputc ('\n', f); + fputc (' ', f); + fputc (' ', f); + } + __losuIrEncodeHead (f, isC); + __losuIrEncodeFunc (main, f, isC); + if (isC) + { + fputc ('\n', f); + fputc ('}', f); + fputc (';', f); + fputc ('\n', f); + } +} + +static void +__losuIrEncodeHead (FILE *f, _l_bool isC) +{ + int32_t i = 1; + /* magic */ + __losuIrEncodeByte (0, f, isC); + /* Endianness */ + __losuIrEncodeByte ((*(uint8_t *)(&i)), f, isC); + /* Version */ + __losuIrEncodeSizet (LosuVersionNum, f, isC); + /* Vm-bitsize */ + __losuIrEncodeByte (sizeof (vmInstruction), f, isC); +} + +static void +__losuIrEncodeFunc (_inlineScode *fs, FILE *f, _l_bool isC) +{ + __losuIrEncodeString (fs->src, f, isC); + __losuIrEncodeInt32 (fs->defedline, f, isC); + __losuIrEncodeInt32 (fs->narg, f, isC); + __losuIrEncodeByte (fs->isVarg, f, isC); + __losuIrEncodeInt32 (fs->maxstacksize, f, isC); + + __losuIrEncodeLcvar (fs, f, isC); + __losuIrEncodeLine (fs, f, isC); + __losuIrEncodeConst (fs, f, isC); + + __losuIrEncodeIns (fs, f, isC); +} + +static void +__losuIrEncodeConst (_inlineScode *fs, FILE *f, _l_bool isC) +{ + /* encode lcstr */ + __losuIrEncodeInt32 (fs->nlcstr, f, isC); + for (int32_t i = 0; i < fs->nlcstr; i++) + __losuIrEncodeString (fs->lcstr[i], f, isC); + + /* encode lcnum */ + __losuIrEncodeInt32 (fs->nlcnum, f, isC); + __losuIrEncodeVector (fs->lcnum, fs->nlcnum, sizeof (*fs->lcnum), f, isC); + + /* encode lcscode */ + __losuIrEncodeInt32 (fs->nlcscode, f, isC); + for (int32_t i = 0; i < fs->nlcscode; i++) + __losuIrEncodeFunc (fs->lcscode[i], f, isC); +} + +static void +__losuIrEncodeLine (_inlineScode *fs, FILE *f, _l_bool isC) +{ + __losuIrEncodeInt32 (fs->nlineinfo, f, isC); + __losuIrEncodeVector (fs->lineinfo, fs->nlineinfo, sizeof (*fs->lineinfo), f, + isC); +} + +static void +__losuIrEncodeLcvar (_inlineScode *fs, FILE *f, _l_bool isC) +{ + __losuIrEncodeInt32 (fs->nlocalvar, f, isC); + for (int32_t i = 0; i < fs->nlocalvar; i++) + { + __losuIrEncodeString (fs->localvar[i].name, f, isC); + __losuIrEncodeInt32 (fs->localvar[i].startpc, f, isC); + __losuIrEncodeInt32 (fs->localvar[i].endpc, f, isC); + } +} + +static void +__losuIrEncodeIns (_inlineScode *fs, FILE *f, _l_bool isC) +{ + __losuIrEncodeInt32 (fs->ncode, f, isC); + __losuIrEncodeVector (fs->code, fs->ncode, sizeof (*fs->code), f, isC); +} + +static void +__losuIrEncodeString (_inlineString *s, FILE *f, _l_bool isC) +{ + if (s == NULL) + __losuIrEncodeSizet (0, f, isC); + else + { + size_t len = s->len + 1; + __losuIrEncodeSizet (len, f, isC); + __losuIrEncodeBlock (s->str, len, f, isC); + } +} +static void +__losuIrEncodeSizet (_l_size_t n, FILE *f, _l_bool isC) +{ + __losuIrEncodeBlock (&n, sizeof (_l_size_t), f, isC); +} +static void +__losuIrEncodeInt32 (int32_t n, FILE *f, _l_bool isC) +{ + __losuIrEncodeBlock (&n, sizeof (n), f, isC); +} + +static void +__losuIrEncodeByte (uint8_t c, FILE *f, _l_bool isC) +{ + static int8_t i = 0; + if (isC) + { + fprintf (f, "0x%.2x, ", (int32_t)c); + i++; + if (i == 13) + { + fputc ('\n', f); + fputc (' ', f); + fputc (' ', f); + + i = 0; + } + } + else + fputc (c, f); +} +static void +__losuIrEncodeBlock (void *p, size_t len, FILE *f, _l_bool isC) +{ + if (isC) + { + for (size_t i = 0; i < len; i++) + __losuIrEncodeByte (((uint8_t *)p)[i], f, isC); + } + else + fwrite (p, len, 1, f); +} +static void +__losuIrEncodeVector (void *p, size_t n, size_t s, FILE *f, _l_bool isC) +{ + if (isC) + { + for (size_t i = 0; i < n; i++) + __losuIrEncodeBlock (((uint8_t *)p) + i * s, s, f, isC); + } + else + fwrite (p, n, s, f); +} diff --git a/tools/losuc/src/main.c b/tools/losuc/src/main.c new file mode 100755 index 0000000000000000000000000000000000000000..2b16c258c38711cfd2e5a62c792e886c2705803a --- /dev/null +++ b/tools/losuc/src/main.c @@ -0,0 +1,160 @@ +/* + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +/* + This document is part of the Losu Community OSPP - 2024 subject results + contributed by Dongqiao Huang @ NEUQ, following MIT LICENSE Contributed to + the Losu Community. + + The MIT LICENSE is as follows + -------------------- + Copyright 2024 Dongqiao Huang + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +#include "losu_object.h" +#include "losuc.h" +#include +#include +#include + +static void +error (const char *msg, ...) +{ + char buf[256] = { 0 }; + va_list ap; + va_start (ap, msg); + vsnprintf (buf, sizeof (buf), msg, ap); + fprintf (stderr, "[Error@losuc]: %s .\n", buf); + va_end (ap); + exit (-1); +} + +static int32_t +doFile (LosuVm *vm, const char *ifn, const char *exn, _l_bool isC) +{ + int32_t r = 0; + r = vm_loadfile (vm, ifn); + if (r == LosuErrorCode_File) /* input error */ + error ("Failed to open input file '%s'", ifn); + if (r == 0) /* load ok */ + { + size_t fn_len = strlen (ifn) + strlen (exn) + 1; + char *fn = malloc (fn_len); + memset (fn, 0, fn_len); + snprintf (fn, fn_len, "%s%s", ifn, exn); + FILE *fp = fopen (fn, "wb"); + if (fp == NULL) + error ("Failed to open output file '%s'", fn); + __losu_bytecode_encode (ovfunc (vm->stack)->func.sdef, fp, isC); + fclose (fp); + free (fn); + } + return r; +} + +int32_t +main (int32_t argc, const char *argv[]) +{ + int32_t r = 0; /* return value */ + LosuVm *vm = vm_create (1024); + if (vm == NULL) + error ("Faliled to create LosuVm"); + /* argc */ + switch (argc) + { + case 1: /* no arg,print help info */ + { + printf ("%s\n", __losuc_help__); + break; + } + case 2: /* losuc file */ + { + r = doFile (vm, argv[1], ".hex", 0); + break; + } + case 3: /* -x filename */ + { + if (strcmp (argv[1], "-a") == 0) + { + r = doFile (vm, argv[2], ".hex", 0); + if (r == 0) + r = doFile (vm, argv[2], ".inc", 1); + break; + } + else if (strcmp (argv[1], "-c") == 0) + { + r = doFile (vm, argv[2], ".inc", 1); + break; + } + else if (strcmp (argv[1], "-h") == 0) + { + char s[1024] = { 0 }; + snprintf (s, 1024, "losuh %s", argv[2]); + r = system (s); + break; + } + else + error ("Invalid args '%s'", argv[1]); + break; + } + default: + error ("Invalid args number"); + } + vm_close (vm); + return r; +} diff --git a/tools/losuh/LICENSE b/tools/losuh/LICENSE new file mode 100755 index 0000000000000000000000000000000000000000..58c54142a03cfb878e765a9da91f0d352945c752 --- /dev/null +++ b/tools/losuh/LICENSE @@ -0,0 +1,8 @@ +The MIT License (MIT) +Copyright © 2024 Dongqiao Huang + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/tools/losuh/include/hCodegen.hh b/tools/losuh/include/hCodegen.hh new file mode 100755 index 0000000000000000000000000000000000000000..b6ad2c1e9e0b9da0e5907688fa9286b797190845 --- /dev/null +++ b/tools/losuh/include/hCodegen.hh @@ -0,0 +1,225 @@ +/* + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +/* + This document is part of the Losu Community OSPP - 2024 subject results + contributed by Dongqiao Huang @ NEUQ, following MIT LICENSE Contributed to + the Losu Community. + + The MIT LICENSE is as follows + -------------------- + Copyright 2024 Dongqiao Huang + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +#ifndef HCODEGEN_HH +#define HCODEGEN_HH + +#include +#include +#include + +namespace LosuPreCompiler +{ +namespace CodeGen +{ + +typedef struct cgOutput cgOutput; +typedef struct cgType_module cgType_module; +typedef struct cgType_submod cgType_submod; +typedef struct cgType_class cgType_class; +typedef struct cgType_object cgType_object; +typedef struct cgType_func cgType_func; +typedef struct cgType_script cgType_script; +typedef struct cgType_number cgType_number; +typedef struct cgType_string cgType_string; + +typedef struct cgOutput +{ + struct headFile + { + std::string headcmt; // head comment + std::string declare; // head declare + } headFile; + struct srcFile + { + std::string headcmt; // head comment + std::string declare; // head declare (include and ...) + std::string module; // module constructor + std::string submod; // sub module constructor + std::string object; // object constructor + std::string classs; // class constructor + std::string func; // function constructor + } srcFile; + + struct mdFile + { + std::string headcmt; // head comment + std::string menu; // head declare + std::string text; + } mdFile; + +} cgOutput; + +typedef struct cgType_func +{ + std::string comment; // comment + std::string name; // function name +} cgType_func; + +typedef struct cgType_script +{ + std::string comment; // comment + std::string name; // script name + std::string file; // script file +} cgType_script; + +typedef struct cgType_number +{ + std::string comment; // comment + std::string name; // number name + std::string value; // number value +} cgType_number; + +typedef struct cgType_string +{ + std::string comment; // comment + std::string name; // string name + std::string value; // string value +} cgType_string; + +typedef struct cgType_object +{ + std::string comment; // comment + std::string name; // class name + std::vector subObj; // sub object + std::vector subFunc; // sub function + std::vector subNum; // sub number + std::vector subStr; // sub string + std::vector subCls; // sub class +} cgType_object; + +typedef struct cgType_class +{ + std::string comment; // comment + std::string name; // class name + std::vector subFunc; // sub function + std::vector subNum; // sub number + std::vector subStr; // sub string +} cgType_class; + +typedef struct cgType_submod +{ + std::string comment; // comment + std::string name; // sub module name + std::vector subCls; // sub class + std::vector subObj; // sub object + std::vector subFunc; // sub function + std::vector subScript; // sub script + std::vector subNum; // sub number + std::vector subStr; // sub string +} cgType_submod; + +typedef struct cgType_module +{ + std::string comment; // comment + std::string name; // module name + std::vector subMod; // sub modules +} cgType_module; + +class hCodegen +{ +public: + hCodegen (std::string fname); // constructor + void addModule (cgType_module module, std::int32_t line); // add module + void addSubmod (cgType_submod submod, std::vector *root, + std::int32_t line); // add sub module + void addClass (cgType_class cls, std::vector *root, + std::int32_t line); // add class + void addObject (cgType_object obj, std::vector *root, + std::int32_t line); // add object + void addFunc (cgType_func func, std::vector *root, + std::int32_t line); // add function + void addScript (cgType_script script, std::vector *root, + std::int32_t line); // add script + void addNumber (cgType_number num, std::vector *root, + std::int32_t line); // add number + void addString (cgType_string str, std::vector *root, + std::int32_t line); // add string + cgOutput genCode (); // generate code + +private: + void p_genModule (cgType_module module); // generate module + void p_genSmod (cgType_submod submod, + std::string pname); // generate submod + void p_genClass (cgType_class cls, std::string pname); // generate class + void p_genObject (cgType_object obj, std::string pname); // generate object + void p_genFunc (cgType_func func, std::string pname); // generate function + void p_genSpt (cgType_script spt, std::string pname); // generate script + std::string p_getPname (std::string cls, std::string obj, + std::string pname); // get parent name + +protected: + cgOutput output; // output + cgType_module mainModule; // module main + std::string fname; // file name +}; + +} +} + +#endif diff --git a/tools/losuh/include/hError.hh b/tools/losuh/include/hError.hh new file mode 100755 index 0000000000000000000000000000000000000000..324f672695437249418a62da6872aba74ba56ffa --- /dev/null +++ b/tools/losuh/include/hError.hh @@ -0,0 +1,111 @@ +/* + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +/* + This document is part of the Losu Community OSPP - 2024 subject results + contributed by Dongqiao Huang @ NEUQ, following MIT LICENSE Contributed to + the Losu Community. + + The MIT LICENSE is as follows + -------------------- + Copyright 2024 Dongqiao Huang + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +#ifndef HERROR_HH +#define HERROR_HH +#include +#include +#include + +namespace LosuPreCompiler +{ +namespace Error +{ +class hError_t : public std::exception +{ +public: + hError_t (std::string err, std::int32_t line, std::int32_t ecode); + std::string getErr (); + std::int32_t getLine (); + std::int32_t getEcode (); + +private: + std::string errmsg; + std::int32_t line; + std::int32_t ecode; +}; + +class hError +{ +public: + hError (std::string caller, std::string file, std::int32_t line, + std::int32_t ecode, std::string message); + + enum errCode + { + eCode_OK = 0, + eCode_Lexer, + eCode_Parser, + eCode_Codegen, + eCode_Unknown, + } errCode; +}; +} +} + +#endif \ No newline at end of file diff --git a/tools/losuh/include/hLexer.hh b/tools/losuh/include/hLexer.hh new file mode 100755 index 0000000000000000000000000000000000000000..f903648ec4d928a0eb4b6867a76568b7eccede15 --- /dev/null +++ b/tools/losuh/include/hLexer.hh @@ -0,0 +1,156 @@ +/* + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +/* + This document is part of the Losu Community OSPP - 2024 subject results + contributed by Dongqiao Huang @ NEUQ, following MIT LICENSE Contributed to + the Losu Community. + + The MIT LICENSE is as follows + -------------------- + Copyright 2024 Dongqiao Huang + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +#ifndef HLEXER_HH +#define HLEXER_HH + +#include +#include +#include + +namespace LosuPreCompiler +{ +namespace Lexer +{ + +class hLexer +{ +public: + hLexer (std::string source, std::string filename); // constructor. + void nextToken (); // Move to the next token. + std::int32_t getLine (); // Get the current line number. + std::int32_t getTkType (); // Get the type of the current token. + std::string getTkValue (); // Get the value of the current token. + + // declare segment + enum synTktype + { + // tkType is int16_t, more than ASCII + TK_EOZ = 256, + TK_MODULE, + TK_IMPORT, + TK_SUB, + TK_DEF, + TK_OBJECT, + TK_CLASS, + TK_KSTR, + TK_STRING, + TK_NUMBER, + TK_SCRIPT, + TK_POINT, + TK_NAME, + TK_END, + } synTktype; + struct synTklist_t + { + std::int32_t tkType; + const char *tkValue; + std::int8_t isKey; + } synTklist[TK_END - 255] = { + { TK_EOZ, "EOZ", 0 }, { TK_MODULE, "module", 2 }, + { TK_IMPORT, "import", 1 }, { TK_SUB, "sub", 2 }, + { TK_DEF, "def", 2 }, { TK_OBJECT, "object", 2 }, + { TK_CLASS, "class", 2 }, { TK_STRING, "string", 0 }, + { TK_KSTR, "string", 1 }, { TK_NUMBER, "number", 1 }, + { TK_SCRIPT, "script", 1 }, { TK_POINT, "pointer", 1 }, + { TK_NAME, "name", 0 }, { TK_END, "end", 0 }, + }; + +private: + std::int32_t CurChar (); // Get the current character. + void NextChar (); // Move to the next character. + void PushIndent (); // Push indent. + void PopIndent (); // Pop indent. + std::string ReadName (); // Read Name. + std::string ReadString (std::int32_t c, std::int32_t line); // Read String. + +protected: + // syntax segment + std::stringstream source; // Source code stream. + std::string fName; // File name. + std::string sSrc; // Source code. + std::size_t sPos; // Position. + std::size_t sLen; // Length. + std::int32_t sLine; // Line number. + std::int32_t sEOZ; // End of the source code. + + // data segment + std::int32_t tkType; // Token type. + std::string tkValue; // Token value. + struct synIdt // Indent structure. + { + std::int32_t nowIdt; // Now indent (should be). + std::int32_t curIdt; // Current indent. + std::int32_t size; // Indent size. 2/4/8 + std::int32_t idtNum; // Indent number. + } synIdt; +}; + +} +} +#endif diff --git a/tools/losuh/include/hParser.hh b/tools/losuh/include/hParser.hh new file mode 100755 index 0000000000000000000000000000000000000000..badeb0574f7adf24ef8c254c97fac1e379eada8a --- /dev/null +++ b/tools/losuh/include/hParser.hh @@ -0,0 +1,111 @@ +/* + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +/* + This document is part of the Losu Community OSPP - 2024 subject results + contributed by Dongqiao Huang @ NEUQ, following MIT LICENSE Contributed to + the Losu Community. + + The MIT LICENSE is as follows + -------------------- + Copyright 2024 Dongqiao Huang + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +#ifndef HPARSER_HH +#define HPARSER_HH + +#include "hCodegen.hh" +#include "hLexer.hh" + +namespace LosuPreCompiler +{ + +namespace Parser +{ + +class hParser +{ +public: + hParser (std::string source, std::string fname); // constructor + ~hParser (); // destructor + CodeGen::cgOutput doParse (); // parse the source code +private: + CodeGen::cgType_module p_parModule (); // parse the module + CodeGen::cgType_submod p_parSubmod (); // parse the sub module + CodeGen::cgType_func p_parFunc (); // parse the function + CodeGen::cgType_number p_parNumber (); // parse the number + CodeGen::cgType_string p_parString (); // parse the string + CodeGen::cgType_script p_parScript (); // parse the script + CodeGen::cgType_object p_parObject (); // parse the object + CodeGen::cgType_class p_parClass (); // parse the class +protected: + Lexer::hLexer *lex; // lexer + CodeGen::hCodegen *cgen; // code generator + CodeGen::cgType_module module; // module + std::string fname; // file name + std::string expString; // export string + void CheckMatch (std::int32_t needed, std::int32_t pre, + std::int32_t line); // check the match + void ParseExp (); +}; + +} // namespace Parser + +} // namespace LosuPreCompiler + +#endif \ No newline at end of file diff --git a/tools/losuh/main.cc b/tools/losuh/main.cc new file mode 100755 index 0000000000000000000000000000000000000000..535d8dc713b54363c602a87e57532322787ceae4 --- /dev/null +++ b/tools/losuh/main.cc @@ -0,0 +1,193 @@ +/* + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +/* + This document is part of the Losu Community OSPP - 2024 subject results + contributed by Dongqiao Huang @ NEUQ, following MIT LICENSE Contributed to + the Losu Community. + + The MIT LICENSE is as follows + -------------------- + Copyright 2024 Dongqiao Huang + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +// info +#define __losuh_info__ \ + "\ +------------------------------------\n\ +| losuh - Losu Header Generator |\n\ +| file make file to C-API |\n\ +------------------------------------\n\ +" + +// copy (c) +#define __losuh_copy__ \ + "\ +/*\n\ + This file was generated by losuh - Losu Header Generator, which is part of\n\ + the Losu SDK.\n\ +\n\ + Losu is an open source programming language from China with excellent\n\ + performance (comparable to lua), ultra-lightweight resource footprint (only\n\ + 4KB RAM) and easy-to-learn syntax (similar to Python) for IoT development.\n\ +\n\ + This file follows the following MIT LICENSE by default\n\ + ------------------------------------\n\ + Copyright 2020 - now chen-chaochen\n\ +\n\ + Permission is hereby granted, free of charge, to any person obtaining a\n\ + copy of this software and associated documentation files (the “Software”), to\n\ + deal in the Software without restriction, including without limitation the\n\ + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n\ + sell copies of the Software, and to permit persons to whom the Software is\n\ + furnished to do so, subject to the following conditions:\n\ +\n\ + The above copyright notice and this permission notice shall be included in\n\ + all copies or substantial portions of the Software.\n\ +\n\ + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n\ + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n\ + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n\ + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n\ + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n\ + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n\ + SOFTWARE.\n\ +\n\ +*/\n\ +" + +#include "hError.hh" +#include "hParser.hh" +#include +#include +#include + +using namespace LosuPreCompiler; +using namespace Error; +using namespace Parser; + +std::int32_t +main (std::int32_t argc, char *argv[]) +{ + // init + std::vector _argv; + for (std::int32_t i = 0; i < argc; i++) + _argv.push_back (std::string (argv[i])); + std::string sFname; // source file name + std::string sSrc; // source string + try + { + // check argc + switch (argc) + { + case 1: // no args + { + std::cout << __losuh_info__ << std::endl; + break; + } + case 2: // one arg + { + std::string tmp; + sFname = _argv[1]; + // Do parse + // 1. input src + std::ifstream ifs (sFname); + if (!ifs.is_open ()) // file not exist + throw hError_t ("file '" + sFname + "' not exist", 0, + hError::errCode::eCode_Unknown); + while (std::getline (ifs, tmp)) + sSrc += tmp + "\n"; + ifs.close (); + // 2. parse + hParser p (sSrc, sFname); + CodeGen::cgOutput out_t = p.doParse (); + // 3. output + std::ofstream ofhs (sFname + ".h"); + std::ofstream ofcs (sFname + ".c"); + if (!ofhs.is_open () || !ofcs.is_open ()) + throw hError_t ("output files open failed", 0, + hError::errCode::eCode_Unknown); + ofhs << out_t.headFile.headcmt << std::endl + << __losuh_copy__ << std::endl + << "#include \"losu.h\"" << std::endl + << "#include \"losuh.h\"" << std::endl + << out_t.headFile.declare << std::endl; + ofcs << out_t.srcFile.headcmt << std::endl + << __losuh_copy__ << std::endl + << "#include \"" << sFname << ".h\"" << std::endl + << out_t.srcFile.declare << std::endl + << out_t.srcFile.module << std::endl + << out_t.srcFile.submod << std::endl + << out_t.srcFile.object << std::endl + << out_t.srcFile.classs << std::endl + << out_t.srcFile.func << std::endl; + ofhs.close (); + ofcs.close (); + break; + } + default: // more than one arg + throw hError_t ("too many args", 0, hError::errCode::eCode_Unknown); + } + } + catch (hError_t &e) + { + std::cerr << "[Error@losuh]:" << e.getErr () << std::endl; + exit (e.getEcode ()); + } + return 0; +} \ No newline at end of file diff --git a/tools/losuh/makefile b/tools/losuh/makefile new file mode 100755 index 0000000000000000000000000000000000000000..d521e87515ba924974fb640610a3fd450cabbd91 --- /dev/null +++ b/tools/losuh/makefile @@ -0,0 +1,45 @@ +# pkg obj +PkgObj=$(LosuSDK_Obj)/sdk/losuh +# compiler +cxx=c++ + +# files +cxxFile=$(shell ls src/*.cc) +cxxIncFile=$(shell ls include/*.hh) + +# flags +cxxWarning=-Wall +cxxStd= -std=c++14 +cxxOpt= -O2 +cxxInclude= -Iinclude -I$(LosuSDK_Include) +cxxFlags= $(cxxWarning) $(cxxStd) $(cxxOpt) $(cxxInclude) + +#target +$(LosuSDK_Path)/losuh:\ + $(PkgObj)/hCodegen.o \ + $(PkgObj)/hError.o \ + $(PkgObj)/hLexer.o \ + $(PkgObj)/hParser.o \ + $(PkgObj)/main.o \ + + $(cxx) -o $@ $^ + + + +$(PkgObj)/hCodegen.o: src/hCodegen.cc $(cxxIncFile) + $(cxx) $(cxxFlags) -c $< -o $@ + +$(PkgObj)/hError.o: src/hError.cc $(cxxIncFile) + $(cxx) $(cxxFlags) -c $< -o $@ + + +$(PkgObj)/hLexer.o: src/hLexer.cc $(cxxIncFile) + $(cxx) $(cxxFlags) -c $< -o $@ + + +$(PkgObj)/hParser.o: src/hParser.cc $(cxxIncFile) + $(cxx) $(cxxFlags) -c $< -o $@ + +$(PkgObj)/main.o: main.cc $(cxxIncFile) + $(cxx) $(cxxFlags) -c $< -o $@ + \ No newline at end of file diff --git a/tools/losuh/readme.md b/tools/losuh/readme.md new file mode 100755 index 0000000000000000000000000000000000000000..4198490afe616abea953927afd8736656a05311a --- /dev/null +++ b/tools/losuh/readme.md @@ -0,0 +1,27 @@ +# losuh · Losu Header Generator +## 简介 +losuh,全称 Losu Header Generator,是 Losu SDK 包含的工具之一,用于生成 Losu 头文件,它可以帮助开发者快速生成符合 Losu API 的 C语言 接口文件,主要用于 Losu Package 的开发。它可以将 .lsh 后缀的 Losu Package 声明文件(类似于 pyi 文件)编译到 C语言 接口文件中,自动化地生成子模块、函数声明、变量绑定、类与对象等接口代码 + +losuh 生成的代码需要 liblosuh 中的接口函数。因此需要引入头文件 `$(SDK)/include/losuh.h` ,并链接 `$(SDK)/lib/liblosuh` 库 + +## 使用方法 + +在 Losu SDK 环境下,使用以下命令编译源代码文件,生成 相应的 C 接口文件 `.c .h`: + +```sh +losuh filename +``` + +# losuh · Losu Header Generator +## Introduction +losuh, full name Losu Header Generator, is one of the tools included in the Losu SDK, used to generate Losu header files. It can help developers quickly generate C language interface files that conform to the Losu API, mainly used for the development of Losu Package. It can compile the Losu Package declaration file (similar to pyi file) with the .lsh suffix into C language interface files, automatically generating sub-modules, function declarations, variable bindings, classes and objects, etc. interface code + +losuh generated code needs to use the interface functions in liblosuh. Therefore, the header file `$(SDK)/include/losuh.h` needs to be included, and the library `$(SDK)/lib/liblosuh` needs to be linked + +## Usage + +In the Losu SDK environment, use the following command to compile the source code file to generate the corresponding C interface file `.c .h`: + +```sh +losuh filename +``` diff --git a/tools/losuh/src/hCodegen.cc b/tools/losuh/src/hCodegen.cc new file mode 100755 index 0000000000000000000000000000000000000000..53f2c766ade046f4d2406bef30fcadf6b476d720 --- /dev/null +++ b/tools/losuh/src/hCodegen.cc @@ -0,0 +1,809 @@ +/* + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +/* + This document is part of the Losu Community OSPP - 2024 subject results + contributed by Dongqiao Huang @ NEUQ, following MIT LICENSE Contributed to + the Losu Community. + + The MIT LICENSE is as follows + -------------------- + Copyright 2024 Dongqiao Huang + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +#include "hCodegen.hh" + +#include + +#include "hError.hh" + +namespace LosuPreCompiler +{ +using namespace Error; +namespace CodeGen +{ + +hCodegen::hCodegen (std::string fname) +{ + cgOutput *o = &this->output; + // init the output + // head file + o->headFile.headcmt = ""; + o->headFile.declare = ""; + // source file + o->srcFile.headcmt = ""; + o->srcFile.declare = ""; + o->srcFile.module = ""; + o->srcFile.submod = ""; + o->srcFile.classs = ""; + o->srcFile.object = ""; + o->srcFile.func = ""; + // markdown + o->mdFile.headcmt = ""; + o->mdFile.menu = ""; + o->mdFile.text = ""; + + this->fname = fname; +} + +/** + * @brief add a module to the codegen + * @param module the module to add + */ +void +hCodegen::addModule (cgType_module module, std::int32_t line) +{ + this->mainModule = module; + return; +} + +/** + * @brief add a submod to the codegen, at the root node + * @param submod the submod to add + * @param root the root node + * @param line the line number + */ +void +hCodegen::addSubmod (cgType_submod submod, std::vector *root, + std::int32_t line) +{ + for (std::size_t i = 0; i < root->size (); i++) + if (root->at (i).name == submod.name) + throw hError_t ( + std::string ("submod name conflict: '" + submod.name + "'."), line, + hError::errCode::eCode_Codegen); + root->push_back (submod); + return; +} + +/** + * @brief add a class to the codegen, at the root node + * @param cls the class to add + * @param root the root node + * @param line the line number + */ +void +hCodegen::addClass (cgType_class cls, std::vector *root, + std::int32_t line) +{ + for (std::size_t i = 0; i < root->size (); i++) + if (root->at (i).name == cls.name) + throw hError_t (std::string ("class name conflict: '" + cls.name + "'."), + line, hError::errCode::eCode_Codegen); + root->push_back (cls); + return; +} + +/** + * @brief add an object to the codegen, at the root node + * @param obj the object to add + * @param root the root node + * @param line the line number + */ +void +hCodegen::addObject (cgType_object obj, std::vector *root, + std::int32_t line) +{ + for (std::size_t i = 0; i < root->size (); i++) + if (root->at (i).name == obj.name) + throw hError_t ( + std::string ("object name conflict: '" + obj.name + "'."), line, + hError::errCode::eCode_Codegen); + root->push_back (obj); + return; +} + +/** + * @brief add a function to the codegen, at the root node + * @param func the function to add + * @param root the root node + * @param line the line number + */ +void +hCodegen::addFunc (cgType_func func, std::vector *root, + std::int32_t line) +{ + for (std::size_t i = 0; i < root->size (); i++) + if (root->at (i).name == func.name) + throw hError_t ( + std::string ("function name conflict: '" + func.name + "'."), line, + hError::errCode::eCode_Codegen); + root->push_back (func); + return; +} + +/** + * @brief add a script to the codegen, at the root node + * @param script the script to add + * @param root the root node + * @param line the line number + */ +void +hCodegen::addScript (cgType_script script, std::vector *root, + std::int32_t line) +{ + for (std::size_t i = 0; i < root->size (); i++) + if (root->at (i).name == script.name) + throw hError_t ( + std::string ("script name conflict: '" + script.name + "'."), line, + hError::errCode::eCode_Codegen); + root->push_back (script); + return; +} + +/** + * @brief add a number to the codegen, at the root node + * @param num the number to add + * @param root the root node + * @param line the line number + */ +void +hCodegen::addNumber (cgType_number num, std::vector *root, + std::int32_t line) +{ + for (std::size_t i = 0; i < root->size (); i++) + if (root->at (i).name == num.name) + throw hError_t ( + std::string ("number name conflict: '" + num.name + "'."), line, + hError::errCode::eCode_Codegen); + root->push_back (num); +} + +/** + * @brief add a string to the codegen, at the root node + * @param str the string to add + * @param root the root node + * @param line the line number + */ +void +hCodegen::addString (cgType_string str, std::vector *root, + std::int32_t line) +{ + for (std::size_t i = 0; i < root->size (); i++) + if (root->at (i).name == str.name) + throw hError_t ( + std::string ("string name conflict: '" + str.name + "'."), line, + hError::errCode::eCode_Codegen); + root->push_back (str); + return; +} + +/** + * @brief generate code + */ +cgOutput +hCodegen::genCode () +{ + try + { + this->p_genModule (this->mainModule); + return this->output; + } + catch (hError_t &err) + { + // hError ("Syntax-Codegen", this->fname, err.getLine (), err.getEcode + // (), + // err.getErr ()); + std::cout << "P1" << std::endl; + exit (1); + } +} + +/** + * @brief generate code for a module + * @param mod the module to generate code for + */ +void +hCodegen::p_genModule (cgType_module mod) +{ +#define outC this->output.srcFile.module +#define outH this->output.headFile.declare + + // declare + outH += "LosuModule *__losuh__LOADMODULE_" + mod.name + "();\n"; + // module list + outC += mod.comment + "\n"; + outC += "static LosuModule __losuh__MODULELIST[] = {\n"; + for (std::size_t i = 0; i < mod.subMod.size (); i++) + outC += "{\"" + mod.subMod[i].name + "\"," + "__losuh__submod_" + + mod.subMod[i].name + "_" + mod.name + "},\n"; + outC += "{NULL,NULL},\n};\n"; + + // module loader + outC += "LosuModule *__losuh__LOADMODULE_" + mod.name + + "() {\nreturn &__losuh__MODULELIST[0];\n}\n"; + + // codgen member: + // submod + for (std::size_t i = 0; i < mod.subMod.size (); i++) + this->p_genSmod (mod.subMod[i], mod.name); + +#undef outC +#undef outH +} + +/** + * @brief generate code for a sub-module + * @param submod the sub-module to generate code for + * @param pname the parent module name + */ +void // pname = mod.name +hCodegen::p_genSmod (cgType_submod submod, std::string pname) +{ +#define outC this->output.srcFile.submod +#define outH this->output.srcFile.declare + + // declare submod + outH += "static int32_t __losuh__submod_" + submod.name + "_" + pname + + "(LosuVm *vm);\n"; + + // submod loader + // comment + outC += submod.comment + "\n"; + outC += "static int32_t __losuh__submod_" + submod.name + "_" + pname + + "(LosuVm *vm) {\n"; + // codegen member + // number + { + outC += "// constructors of number in " + submod.name + "\n"; + for (std::size_t i = 0; i < submod.subNum.size (); i++) + { + outC += submod.subNum[i].comment + "\n"; + outC += "__losuhAPI_regNumber(vm,\"" + submod.subNum[i].name + "\"," + + submod.subNum[i].value + ");\n"; + } + outC += "\n"; + } + // string + { + outC += "// constructors of string in " + submod.name + "\n"; + for (std::size_t i = 0; i < submod.subStr.size (); i++) + { + outC += submod.subStr[i].comment + "\n"; + outC += "__losuhAPI_regString(vm,\"" + submod.subStr[i].name + "\"," + + submod.subStr[i].value + ");\n"; + } + outC += "\n"; + } + // function + { + outC += "// constructors of function in " + submod.name + "\n"; + for (std::size_t i = 0; i < submod.subFunc.size (); i++) + { + outC += submod.subFunc[i].comment + "\n"; + outC += "__losuhAPI_regFunc(vm,\"" + submod.subFunc[i].name + "\"," + + /* inline func name */ + ("__losuh__func_" + submod.subFunc[i].name + "_" + submod.name + + "_" + pname) + + ");\n"; + } + outC += "\n"; + } + // script + { + outC += "// constructors of script in " + submod.name + "\n"; + for (std::size_t i = 0; i < submod.subScript.size (); i++) + { + std::string ilineName = "__losuh__script_" + submod.subScript[i].name + + "_" + submod.name + "_" + pname; + outC += submod.subScript[i].comment + "\n"; + outC += "__losuhAPI_regScript(vm,\"" + submod.subScript[i].name + "\"," + + ilineName + ",sizeof(" + ilineName + "));\n"; + } + outC += "\n"; + } + // object + { + outC += "// constructors of object in " + submod.name + "\n"; + for (std::size_t i = 0; i < submod.subObj.size (); i++) + { + outC += submod.subObj[i].comment + "\n"; + outC += "__losuhAPI_regObject(vm,\"" + submod.subObj[i].name + "\"," + + /* inline object name */ + ("__losuh__obj_" + submod.subObj[i].name + "_" + submod.name + + "_" + pname) + + "(vm));\n"; + } + outC += "\n"; + } + // class + { + outC += "// constructors of class in " + submod.name + "\n"; + for (std::size_t i = 0; i < submod.subCls.size (); i++) + { + outC += submod.subCls[i].comment + "\n"; + outC += "__losuhAPI_regClass(vm,\"" + submod.subCls[i].name + "\"," + + /* inline class name */ + ("__losuh__class_" + submod.subCls[i].name + "_" + submod.name + + "_" + pname) + + "(vm));\n"; + } + outC += "\n"; + } + // tail + { + outC += "\nreturn 0;\n}\n"; + } + // call member constructor + { + // object + for (std::size_t i = 0; i < submod.subObj.size (); i++) + this->p_genObject (submod.subObj[i], submod.name + "_" + pname); + // class + for (std::size_t i = 0; i < submod.subCls.size (); i++) + this->p_genClass (submod.subCls[i], submod.name + "_" + pname); + // script + for (std::size_t i = 0; i < submod.subScript.size (); i++) + this->p_genSpt (submod.subScript[i], submod.name + "_" + pname); + // func + for (std::size_t i = 0; i < submod.subFunc.size (); i++) + this->p_genFunc (submod.subFunc[i], submod.name + "_" + pname); + } + +#undef outC +#undef outH +} + +/** + * @brief generate object + * @param object object to generate code for + * @param pname the parent name of the object + */ +void // pname = xxx_xxx +hCodegen::p_genObject (cgType_object object, std::string pname) +{ +#define outC this->output.srcFile.object +#define outH this->output.srcFile.declare + + // declare + outH += "static LosuObj __losuh__obj_" + object.name + "_" + pname + + "(LosuVm *vm);\n"; + + // constructor of object + // comment + outC += object.comment + "\n"; + // loader + outC += "static LosuObj __losuh__obj_" + object.name + "_" + pname + + "(LosuVm *vm){\nLosuObj newObj = obj_newunit(vm);\n"; + + // bind member + // number + { + outC += "// constructor of number in " + object.name + "@" + pname + "\n"; + for (std::size_t i = 0; i < object.subNum.size (); i++) + { + cgType_number sNum = object.subNum[i]; + outC += sNum.comment + "\n"; + outC += "__losuhAPI_regObjNumber(vm,newObj,\"" + sNum.name + "\"," + + sNum.value + ");\n"; + } + outC += "\n"; + } + // string + { + outC += "// constructor of string in " + object.name + "@" + pname + "\n"; + for (std::size_t i = 0; i < object.subStr.size (); i++) + { + cgType_string sStr = object.subStr[i]; + outC += sStr.comment + "\n"; + outC += "__losuhAPI_regObjString(vm,newObj,\"" + sStr.name + "\",\"" + + sStr.value + "\");\n"; + } + outC += "\n"; + } + // object + { + outC += "// constructor of object in " + object.name + "@" + pname + "\n"; + for (std::size_t i = 0; i < object.subObj.size (); i++) + { + cgType_object sObj = object.subObj[i]; + outC += sObj.comment + "\n"; + outC += "__losuhAPI_regObjObject(vm,newObj,\"" + sObj.name + "\"," + + "__losuh__obj_" + sObj.name + "_" + object.name + "_" + pname + + "(vm));\n"; + } + outC += "\n"; + } + // class + { + outC += "// constructor of class in " + object.name + "@" + pname + "\n"; + for (std::size_t i = 0; i < object.subCls.size (); i++) + { + cgType_class sCls = object.subCls[i]; + outC += sCls.comment + "\n"; + outC += "__losuhAPI_regObjClass(vm,newObj,\"" + sCls.name + "\",\"" + + this->p_getPname (sCls.name, object.name, pname) + "\"," + + "__losuh__class_" + sCls.name + "_" + object.name + "_" + + pname + "(vm));\n"; + } + outC += "\n"; + } + // function + { + outC + += "// constructor of function in " + object.name + "@" + pname + "\n"; + for (std::size_t i = 0; i < object.subFunc.size (); i++) + { + cgType_func sFun = object.subFunc[i]; + outC += sFun.comment + "\n"; + outC += "__losuhAPI_regObjFunc(vm,newObj,\"" + sFun.name + + "\"," + /* Inline func name */ + + "__losuh__func_" + sFun.name + "_" + object.name + "_" + + pname + ");\n"; + } + outC += "\n"; + } + // tail + { + outC += "return newObj;\n}\n"; + } + // call member constructor + { + for (std::size_t i = 0; i < object.subObj.size (); i++) + this->p_genObject (object.subObj[i], object.name + "_" + pname); + for (std::size_t i = 0; i < object.subCls.size (); i++) + this->p_genClass (object.subCls[i], object.name + "_" + pname); + for (std::size_t i = 0; i < object.subFunc.size (); i++) + this->p_genFunc (object.subFunc[i], object.name + "_" + pname); + } + +#undef outC +#undef outH +} + +/** + * @brief Generate Class + * @param cls class to generate + * @param pname parent name + */ +void // pname = xxx_xxx +hCodegen::p_genClass (cgType_class cls, std::string pname) +{ +#define outC this->output.srcFile.classs +#define outH this->output.srcFile.declare + + // declare + outH += "static LosuObj __losuh__class_" + cls.name + "_" + pname + + "(LosuVm *vm);\n"; + + // constructor of class + // comment + outC += cls.comment + "\n"; + // loader + outC += "static LosuObj __losuh__class_" + cls.name + "_" + pname + + "(LosuVm *vm){\nLosuObj newObj = obj_newunit(vm);\n"; + // codegen member + // number + { + outC += "// constructor of number in " + cls.name + "@" + pname + "\n"; + for (std::size_t i = 0; i < cls.subNum.size (); i++) + { + cgType_number sNum = cls.subNum[i]; + outC += sNum.comment + "\n"; + outC += "__losuhAPI_regObjNumber(vm,newObj,\"" + sNum.name + "\"," + + sNum.value + ");\n"; + } + outC += "\n"; + } + // string + { + outC += "// constructor of string in " + cls.name + "@" + pname + "\n"; + for (std::size_t i = 0; i < cls.subStr.size (); i++) + { + cgType_string sStr = cls.subStr[i]; + outC += sStr.comment + "\n"; + outC += "__losuhAPI_regObjString(vm,newObj,\"" + sStr.name + "\",\"" + + sStr.value + "\");\n"; + } + outC += "\n"; + } + // function + { + outC += "// constructor of function in " + cls.name + "@" + pname + "\n"; + for (std::size_t i = 0; i < cls.subFunc.size (); i++) + { + cgType_func sFun = cls.subFunc[i]; + outC += sFun.comment + "\n"; + outC += "__losuhAPI_regObjFunc(vm,newObj,\"" + sFun.name + + "\"," + /* Inline func name */ + + "__losuh__func_" + sFun.name + "_" + cls.name + "_" + pname + + ");\n"; + } + outC += "\n"; + } + // tail + { + outC += "return newObj;\n}\n"; + } + // call member constructor + { + for (std::size_t i = 0; i < cls.subFunc.size (); i++) + this->p_genFunc (cls.subFunc[i], cls.name + "_" + pname); + } + +#undef outC +#undef outH +} + +/** + * @brief Generate function + * @param func function to generate + * @param pname parent name + */ +void // pname = xxx_xxx +hCodegen::p_genFunc (cgType_func func, std::string pname) +{ +#define outC this->output.srcFile.func +#define outH this->output.headFile.declare + + // declare + outH += func.comment + "\n"; + outH += "int32_t __losuh__func_" + func.name + "_" + pname + + "(LosuVm *vm);\n"; + // constructor of function + // comment + // outC += func.comment + "\n"; + // loader + // outC += "int32_t __losuh__func_" + func.name + "_" + pname + // + "(LosuVm *vm){\nreturn 0;\n}\n"; + // outC += "int32_t __losuh__func_" + func.name + "_" + pname + // + "(LosuVm *vm);\n"; +#undef outC +#undef outH +} + +void // pname = xxx_xxx +hCodegen::p_genSpt (cgType_script spt, std::string pname) +{ +#define outH this->output.srcFile.declare + + outH += "static const char __losuh__script_" + spt.name + "_" + pname + + "[] = \n#include \"" + spt.file + ".inc\"\n;\n"; + outH += "\n"; +#undef outH +} + +std::string +hCodegen::p_getPname (std::string cls, std::string obj, std::string pname) +{ + std::string ret = ""; + std::vector vec; + ret += obj + "." + cls; + // token pname + const char *str = new char[pname.length () + 1]; + std::memcpy ((void *)str, pname.c_str (), pname.length () + 1); + + const char *token = std::strtok ((char *)str, "_"); + while (token != NULL) + { + vec.push_back (std::string (token)); + token = std::strtok (NULL, "_"); + } + if (vec.size () > 2) + { + for (std::size_t i = 0; i < vec.size () - 2; i++) + ret = vec[i] + "." + ret; + } + return ret; +} + +} // namespace CodeGen +} // namespace LosuPreCompiler + +// #define HCODEGENCC_MAIN +#ifdef HCODEGENCC_MAIN + +#include +#include + +using namespace LosuPreCompiler; +using namespace CodeGen; +using namespace Error; + +int +main () +{ + std::ofstream ofile; + cgType_module mod_stdlib = { + .name = "stdlib", + }; + hCodegen cGen ("demo.els.c"); + + try + { + cgType_submod smod_stdaux, smod_stdio, smod_stdfile; + cgType_class cls_file; + cgType_object obj_time, obj_date_time; + cgType_number num_PI, num_year0; + cgType_string str_version; + cgType_func Fprint, Fclock, Fday, Fread; + + /** + * module stdlib + * sub stdio + * def print() + * sub stdaux + * number PI 3.14 + * string version "1.0" + * object time + * number year0 "1900" + * def clock() + * object data + * def day() + * script demo "demo.els" + * sub stdfile + * class file(): + * read() + */ + { + smod_stdio = (cgType_submod){ + .name = "stdio", + }; + smod_stdaux = (cgType_submod){ + .name = "stdaux", + }; + smod_stdfile = (cgType_submod){ + .name = "stdfile", + }; + cls_file = (cgType_class){ + .name = "file", + }; + obj_time = (cgType_object){ + .name = "time", + + }; + obj_date_time = (cgType_object){ + .name = "date", + }; + num_PI = (cgType_number){ + .name = "PI", + .value = "3.14", + }; + num_year0 = (cgType_number){ + .name = "year0", + .value = "1900", + }; + str_version = (cgType_string){ + .name = "version", + .value = "1.0", + }; + Fprint = (cgType_func){ + .name = "print", + }; + Fclock = (cgType_func){ + .name = "clock", + }; + Fday = (cgType_func){ + .name = "day", + }; + Fread = (cgType_func){ + .name = "read", + }; + } + { + cGen.addFunc (Fprint, &smod_stdio.subFunc, 1); + cGen.addSubmod (smod_stdio, &mod_stdlib.subMod, 1); + + cGen.addFunc (Fday, &obj_date_time.subFunc, 1); + cGen.addObject (obj_date_time, &obj_time.subObj, 1); + cGen.addNumber (num_year0, &obj_time.subNum, 1); + cGen.addFunc (Fclock, &obj_time.subFunc, 1); + cGen.addObject (obj_time, &smod_stdaux.subObj, 1); + cGen.addNumber (num_PI, &smod_stdaux.subNum, 1); + cGen.addString (str_version, &smod_stdaux.subStr, 1); + cGen.addScript ( + (cgType_script){ + .name = "demoInline", + .file = "demoInline.inc", + }, + &smod_stdaux.subScript, 1); + cGen.addSubmod (smod_stdaux, &mod_stdlib.subMod, 1); + + cGen.addFunc (Fread, &cls_file.subFunc, 1); + cGen.addClass (cls_file, &smod_stdfile.subCls, 1); + cGen.addSubmod (smod_stdfile, &mod_stdlib.subMod, 1); + + cGen.addModule (mod_stdlib, 1); + } + { + cgOutput out = cGen.genCode (); + std::ofstream ofile ("test/demo.els.c"); + std::ofstream hfile ("test/demo.els.h"); + hfile << out.headFile.headcmt << std::endl + << out.headFile.declare << std::endl; + ofile << out.srcFile.headcmt << std::endl + << out.srcFile.declare << std::endl + << out.srcFile.module << std::endl + << out.srcFile.submod << std::endl + << out.srcFile.object << std::endl + << out.srcFile.classs << std::endl + << out.srcFile.func << std::endl; + hfile.close (); + ofile.close (); + } + } + catch (hError_t &err) + { + hError ("Syntax-Codegen", "demo.els", err.getLine (), err.getEcode (), + err.getErr ()); + } +} + +#endif \ No newline at end of file diff --git a/tools/losuh/src/hError.cc b/tools/losuh/src/hError.cc new file mode 100755 index 0000000000000000000000000000000000000000..b011dd800073271804217e9c6a9feb7f924facce --- /dev/null +++ b/tools/losuh/src/hError.cc @@ -0,0 +1,120 @@ +/* + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +/* + This document is part of the Losu Community OSPP - 2024 subject results + contributed by Dongqiao Huang @ NEUQ, following MIT LICENSE Contributed to + the Losu Community. + + The MIT LICENSE is as follows + -------------------- + Copyright 2024 Dongqiao Huang + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +#include "hError.hh" + +#include + +namespace LosuPreCompiler +{ +namespace Error +{ +/** + * @fn hError + * @brief This function is used to create an error object + * @param caller - the name of the function that called this function + * @param file - the name of the file that called this function + * @param line - the line number in the file that called this function + * @param ecode - the error code + * @param message - the error message + */ +hError::hError (std::string caller, std::string file, std::int32_t line, + std::int32_t ecode, std::string message) +{ + std::cerr << "Error@" << caller << "['" << file << "'-line:" << line + << "]:\t" << message << std::endl; + std::exit (ecode); // exit the program +} + +hError_t::hError_t (std::string errmsg, std::int32_t line, std::int32_t ecode) +{ + this->errmsg = errmsg; + this->line = line; + this->ecode = ecode; +} + +std::string +hError_t::getErr () +{ + return this->errmsg; +} + +std::int32_t +hError_t::getLine () +{ + return this->line; +} + +std::int32_t +hError_t::getEcode () +{ + return this->ecode; +} + +} // namespace Error +} // namespace LosuPreCompiler \ No newline at end of file diff --git a/tools/losuh/src/hLexer.cc b/tools/losuh/src/hLexer.cc new file mode 100755 index 0000000000000000000000000000000000000000..2e4e7d12b261929f586178057b8cf2fb056017a0 --- /dev/null +++ b/tools/losuh/src/hLexer.cc @@ -0,0 +1,408 @@ +/* + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +/* + This document is part of the Losu Community OSPP - 2024 subject results + contributed by Dongqiao Huang @ NEUQ, following MIT LICENSE Contributed to + the Losu Community. + + The MIT LICENSE is as follows + -------------------- + Copyright 2024 Dongqiao Huang + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +#include "hLexer.hh" + +#include +#include +#include + +#include "hError.hh" + +namespace LosuPreCompiler +{ +namespace Lexer +{ +/** + * @fn hLexer::hLexer(std::string source) + * @brief Constructor, initializes the lexer with the source code + * @param source The source code to be lexed + * @param filename The filename of the source code + */ +hLexer::hLexer (std::string source, std::string filename) +{ + this->source = std::stringstream (source); + this->fName = filename; + this->sSrc = ""; + this->sPos = 0; + this->sLen = 0; + this->sLine = 1; + this->sEOZ = 0; + this->tkType = -1; // -1 means no token has been read yet + this->tkValue = ""; + this->synIdt.nowIdt = 0; + this->synIdt.curIdt = 0; + this->synIdt.size = 4; + this->synIdt.idtNum = 0; + this->nextToken (); +} + +void +hLexer::nextToken () +{ +#define _return(tk, tkv) \ + { \ + this->tkType = tk, this->tkValue = tkv; \ + return; \ + } + + try + { + while (1) + { + switch (this->CurChar ()) + { + case '#': + { + while (this->CurChar () != '\n') + this->NextChar (); + break; + } + case synTktype::TK_EOZ: + { + _return (synTktype::TK_EOZ, "EOZ"); + break; + } + case '\0': + case ' ': + case '\t': + { + this->NextChar (); + break; + } + case synTktype::TK_END: + { + this->NextChar (); + _return (synTktype::TK_END, "end"); + break; + } + case '\n': + { + this->NextChar (); + this->sLine++; + break; + } + case '"': + case '\'': + { + _return (synTktype::TK_STRING, + this->ReadString (this->CurChar (), this->sLine)); + break; + } + default: + { + if (!std::isalpha (this->CurChar ()) && this->CurChar () != '_' + && this->CurChar () < 0x80) + { + int32_t c = this->CurChar (); + this->NextChar (); + // _return (synTktype::TK_NAME, c); + _return (c, c); + } + std::string sName = this->ReadName (); + + // is keyword ? + for (int32_t i = 0; + i < (int32_t)(sizeof (synTklist) / sizeof (synTklist[0])); + i++) + { + if (sName == std::string (synTklist[i].tkValue) + && synTklist[i].isKey) + { + if (synTklist[i].isKey > 1) + this->PushIndent (); + _return (synTklist[i].tkType, + (std::string (synTklist[i].tkValue))); + } + } + _return (synTktype::TK_NAME, sName); + break; + } + } + } + } + catch (std::string e) + { + LosuPreCompiler::Error::hError ( + std::string ("Syntax-Lexer"), this->fName, this->sLine, + LosuPreCompiler::Error::hError::errCode::eCode_Lexer, e); + } + +#undef _return +} + +std::int32_t +hLexer::getLine () +{ + return this->sLine; +} + +std::int32_t +hLexer::getTkType () +{ + return this->tkType; +} + +std::string +hLexer::getTkValue () +{ + return this->tkValue; +} + +std::int32_t +hLexer::CurChar () +{ + // if exsist Idt ? + if (this->synIdt.idtNum) + return synTktype::TK_END; + // if EOF ? + if (this->sEOZ) + return synTktype::TK_EOZ; + // return sSrc[sPos]; + return this->sSrc[this->sPos]; +} + +void +hLexer::NextChar () +{ + // if exsist Idt ? + if (synIdt.idtNum) + { + this->PopIndent (); + this->synIdt.idtNum--; + return; + } + + // if EOF ? + if (this->sEOZ) + return; + + // Is at this line + if (this->sPos < this->sLen) + this->sPos++; + else // get next line + { + if (std::getline (this->source, this->sSrc)) // read new line + { + this->sSrc += "\n"; + this->sLen = this->sSrc.length (); + this->sPos = 0; + this->synIdt.curIdt = 0; // reset idt + + // set idt + while (1) + { + switch (this->sSrc[this->sPos]) + { + case '\n': + { + break; + } + case ' ': + { + this->synIdt.curIdt++; + this->sPos++; + continue; + } + case '\t': + { + this->synIdt.curIdt += this->synIdt.size; + this->sPos++; + continue; + } + default: + { + // if curIdt > nowIdt, throw error + if (this->synIdt.curIdt > this->synIdt.nowIdt) + throw (std::string ( + "Invalid indentation, need less than '" + + std::to_string (this->synIdt.nowIdt) + "', but '" + + std::to_string (this->synIdt.curIdt) + "'.")); + + // if curIdt < nowIdt + if (this->synIdt.curIdt < this->synIdt.nowIdt) + { + // check if idt is Invalid, if curIdt % size != 0, + // throw error + if (this->synIdt.curIdt % this->synIdt.size) + throw ( + "Invalid indentation, need Multiples of '" + + std::to_string (this->synIdt.size) + "', but '" + + std::to_string (this->synIdt.curIdt) + "'."); + + // if valid,set Idt + this->synIdt.idtNum + = (this->synIdt.nowIdt - this->synIdt.curIdt) + / this->synIdt.size; + } + break; + } + } + break; + } + // reset sPos + this->sPos = 0; + } + else // EOF + { + this->sSrc = ""; + this->sLen = 0; + this->sPos = 0; + this->sEOZ = 1; + // if valid,set Idt + this->synIdt.idtNum = this->synIdt.nowIdt / this->synIdt.size; + } + } +} + +void +hLexer::PushIndent () +{ + this->synIdt.nowIdt += this->synIdt.size; +} + +void +hLexer::PopIndent () +{ + this->synIdt.nowIdt -= this->synIdt.size; +} + +std::string +hLexer::ReadName () +{ + std::string sRet = ""; + while (1) + { + int32_t c = this->CurChar (); + if (!(std::isalnum (c) || c == '_')) + break; + sRet += (char)c; + this->NextChar (); + } + return sRet; +} + +std::string +hLexer::ReadString (std::int32_t c, std::int32_t line) +{ + std::string sRet = ""; + this->NextChar (); + while (this->CurChar () != c) + { + if (this->CurChar () == synTktype::TK_EOZ || this->CurChar () == '\n') + throw (std::string ("String not closed (line '" + std::to_string (line) + + "')")); + sRet += (char)this->CurChar (); + this->NextChar (); + } + this->NextChar (); + return sRet; +} + +} // namespace Lexer +} // namespace LosuPreCompiler + +#ifdef HLEXERCC_MAIN + +#include +int +main () +{ + std::ifstream fin; + fin.open ("test.els", std::ios::in); + std::string s, t; + while (std::getline (fin, t)) + s += t + "\n"; + fin.close (); + LosuPreCompiler::Lexer::hLexer lex (s, "test.els"); + while (lex.getTkType () != lex.synTktype::TK_EOZ) + { + std::cout + << lex.synTklist[lex.getTkType () - lex.synTktype::TK_EOZ].tkValue + << "\t" << lex.getTkValue () << std::endl; + lex.nextToken (); + } + + /* + LscLexer l1 (s); + cout<< "| TK | TK_VAL |VAL|LINE|\n|---|---|---|---|\n"; + while (l1.current.type != TK_EOZ) + { + l1.next (); + cout<< "|"; + cout << l1.current.type << "|" + << lscTokenList[l1.current.type].tokenValue << "|" + << l1.current.value << "|" + << l1.linenum<<"|"<fname = fname; + this->expString = ""; + this->lex = new hLexer (source, this->fname); + this->cgen = new hCodegen (this->fname); +} + +hParser::~hParser () +{ + delete this->lex; + delete this->cgen; +} + +void +hParser::CheckMatch (std::int32_t needed, std::int32_t pre, std::int32_t line) +{ + if (this->lex->getTkType () != needed) + { + std::string nstr = "", pstr = ""; + if (needed < hLexer::synTktype::TK_EOZ) + nstr += needed; + else + nstr += this->lex->synTklist[needed - hLexer::synTktype::TK_EOZ] + .tkValue; + if (pre < hLexer::synTktype::TK_EOZ) + pstr += pre; + else + pstr += this->lex->synTklist[pre - hLexer::synTktype::TK_EOZ].tkValue; + throw hError_t ("need [" + nstr + "] after '" + pstr + "'", line, + hError::errCode::eCode_Parser); + } +} + +void +hParser::ParseExp () +{ + hLexer *const lex = this->lex; + std::int32_t n0 = 0, n1 = 0, n2 = 0; // n0 = ( n1 = [ n2 { + while (1) + { + switch (lex->getTkType ()) + { + case '(': + n0++; + break; + case ')': + n0--; + break; + case '[': + n1++; + break; + case ']': + n1--; + break; + case '{': + n2++; + break; + case '}': + n2--; + break; + case hLexer::synTktype::TK_EOZ: + { + throw hError_t ("unexpected end of file", lex->getLine (), + hError::errCode::eCode_Parser); + break; + } + default: + break; + } + lex->nextToken (); + if (0 == n0) + break; + } + if (0 != n1 || 0 != n2) + throw hError_t ("Unbalanced expressions", lex->getLine (), + hError::errCode::eCode_Parser); +} + +CodeGen::cgOutput +hParser::doParse () +{ + try + { + hLexer *const lex = this->lex; + hCodegen *const cgen = this->cgen; + while (1) + { + switch (lex->getTkType ()) + { + case hLexer::synTktype::TK_IMPORT: + { + lex->nextToken (); + // check name after import + this->CheckMatch (hLexer::synTktype::TK_NAME, + hLexer::synTktype::TK_IMPORT, + lex->getLine ()); + break; + } + case hLexer::synTktype::TK_MODULE: + { + lex->nextToken (); + std::int32_t l = lex->getLine (); + // check name after module + this->CheckMatch (hLexer::synTktype::TK_NAME, + hLexer::synTktype::TK_MODULE, l); + cgen->addModule (this->p_parModule (), l); + break; + } + case hLexer::synTktype::TK_EOZ: + { + return cgen->genCode (); + } + default: + { + throw hError_t ("invalid experssion", lex->getLine (), + hError::errCode::eCode_Parser); + } + } + lex->nextToken (); // next token + } + } + catch (hError_t &err) + { + hError ("Syntax-Parser", this->fname, err.getLine (), err.getEcode (), + err.getErr ()); + } + return cgen->genCode (); +} + +cgType_module +hParser::p_parModule () +{ + hLexer *const lex = this->lex; + hCodegen *const cgen = this->cgen; + + cgType_module modObj; + // set name; + modObj.name = lex->getTkValue (); + + // until end + while (1) + { + lex->nextToken (); + switch (lex->getTkType ()) + { + case hLexer::synTktype::TK_END: // return module, tk = END; + { + return modObj; + break; + } + case hLexer::synTktype::TK_SUB: + { + lex->nextToken (); + std::int32_t l = lex->getLine (); + // check name after sub + this->CheckMatch (hLexer::synTktype::TK_NAME, + hLexer::synTktype::TK_SUB, l); + cgen->addSubmod (this->p_parSubmod (), &modObj.subMod, l); + break; + } + default: + { + throw hError_t ("invalid experssion", lex->getLine (), + hError::errCode::eCode_Parser); + } + } + } +} + +cgType_submod +hParser::p_parSubmod () +{ + hLexer *const lex = this->lex; + hCodegen *const cgen = this->cgen; + + cgType_submod smodObj; + // set name; + smodObj.name = lex->getTkValue (); + + // until end + while (1) + { + lex->nextToken (); + switch (lex->getTkType ()) + { + case hLexer::synTktype::TK_END: // return module, tk = END; + { + return smodObj; + break; + } + case hLexer::synTktype::TK_POINT: // variable, back tk = NAME; + { + lex->nextToken (); + std::int32_t l = lex->getLine (); + + // check name after point + this->CheckMatch (hLexer::synTktype::TK_NAME, + hLexer::synTktype::TK_POINT, l); + + break; + } + case hLexer::synTktype::TK_DEF: // function, back tk = END; + { + lex->nextToken (); + std::int32_t l = lex->getLine (); + + // check name after def + this->CheckMatch (hLexer::synTktype::TK_NAME, + hLexer::synTktype::TK_DEF, l); + + // gen func + cgen->addFunc (this->p_parFunc (), &smodObj.subFunc, l); + break; + } + case hLexer::synTktype::TK_NUMBER: // variable, back tk = STRING; + { + lex->nextToken (); + std::int32_t l = lex->getLine (); + + // check name after number + this->CheckMatch (hLexer::synTktype::TK_NAME, + hLexer::synTktype::TK_NUMBER, l); + + // gen number + cgen->addNumber (this->p_parNumber (), &smodObj.subNum, l); + break; + } + case hLexer::synTktype::TK_KSTR: // variable, back tk = STRING; + { + lex->nextToken (); + std::int32_t l = lex->getLine (); + + // check name after string + this->CheckMatch (hLexer::synTktype::TK_NAME, + hLexer::synTktype::TK_KSTR, l); + + // gen string + cgen->addString (this->p_parString (), &smodObj.subStr, l); + break; + } + case hLexer::synTktype::TK_SCRIPT: // variable, back tk = STRING; + { + lex->nextToken (); + std::int32_t l = lex->getLine (); + + // check name after script + this->CheckMatch (hLexer::synTktype::TK_NAME, + hLexer::synTktype::TK_SCRIPT, l); + + // gen script + cgen->addScript (this->p_parScript (), &smodObj.subScript, l); + break; + } + case hLexer::synTktype::TK_OBJECT: // variable, back tk = END; + { + lex->nextToken (); + std::int32_t l = lex->getLine (); + + // check name after object + this->CheckMatch (hLexer::synTktype::TK_NAME, + hLexer::synTktype::TK_OBJECT, l); + + // gen object + cgen->addObject (this->p_parObject (), &smodObj.subObj, l); + break; + } + case hLexer::synTktype::TK_CLASS: // variable, back tk = END; + { + lex->nextToken (); + std::int32_t l = lex->getLine (); + + // check name after class + this->CheckMatch (hLexer::synTktype::TK_NAME, + hLexer::synTktype::TK_CLASS, l); + + // gen class + cgen->addClass (this->p_parClass (), &smodObj.subCls, l); + break; + } + default: + { + throw hError_t ("invalid experssion", lex->getLine (), + hError::errCode::eCode_Parser); + } + } + } +} + +cgType_func // parse func, back-tk = END; +hParser::p_parFunc () +{ + hLexer *const lex = this->lex; + + cgType_func funcObj; + // set name + funcObj.name = lex->getTkValue (); + funcObj.comment = "/**\n"; + + // until end + while (1) + { + lex->nextToken (); + switch (lex->getTkType ()) + { + case hLexer::synTktype::TK_END: // end of func + { + funcObj.comment += "*/"; + return funcObj; + break; + } + case '(': // parse params + { + this->ParseExp (); // back tk = ':' + this->CheckMatch (':', hLexer::synTktype::TK_DEF, lex->getLine ()); + break; + } + case hLexer::synTktype::TK_STRING: // string is Token Body + { + funcObj.comment += "* " + lex->getTkValue () + "\n"; + break; + } + default: + { + throw hError_t ("invalid experssion", lex->getLine (), + hError::errCode::eCode_Parser); + } + } + } +} + +cgType_number // parse number, back-tk = STRING; +hParser::p_parNumber () +{ + hLexer *const lex = this->lex; + + cgType_number numObj; + // set name + numObj.name = lex->getTkValue (); + + lex->nextToken (); + this->CheckMatch (hLexer::synTktype::TK_STRING, hLexer::synTktype::TK_NUMBER, + lex->getLine ()); + numObj.value = lex->getTkValue (); + return numObj; +} + +cgType_string // parse string, back-tk = STRING; +hParser::p_parString () +{ + hLexer *const lex = this->lex; + + cgType_string strObj; + // set name + strObj.name = lex->getTkValue (); + + lex->nextToken (); + this->CheckMatch (hLexer::synTktype::TK_STRING, hLexer::synTktype::TK_STRING, + lex->getLine ()); + strObj.value = "\"" + lex->getTkValue () + "\""; + return strObj; +} + +cgType_script // parse script, back-tk = STRING; +hParser::p_parScript () +{ + hLexer *const lex = this->lex; + + cgType_script scrObj; + // set name + scrObj.name = lex->getTkValue (); + + lex->nextToken (); + this->CheckMatch (hLexer::synTktype::TK_STRING, hLexer::synTktype::TK_SCRIPT, + lex->getLine ()); + scrObj.file = lex->getTkValue (); + return scrObj; +} + +cgType_object // parse object, back-tk = END; +hParser::p_parObject () +{ + hLexer *const lex = this->lex; + hCodegen *const cgen = this->cgen; + + cgType_object objObj; + // set name + objObj.name = lex->getTkValue (); + + // until end + while (1) + { + lex->nextToken (); + switch (lex->getTkType ()) + { + case hLexer::synTktype::TK_END: // end of object + { + return objObj; + break; + } + case hLexer::synTktype::TK_POINT: // variable, back tk = NAME; + { + lex->nextToken (); + + // check name after point + this->CheckMatch (hLexer::synTktype::TK_NAME, + hLexer::synTktype::TK_POINT, lex->getLine ()); + + break; + } + case hLexer::synTktype::TK_DEF: // variable, back tk = END; + { + lex->nextToken (); + std::int32_t l = lex->getLine (); + + // check name after def + this->CheckMatch (hLexer::synTktype::TK_NAME, + hLexer::synTktype::TK_DEF, l); + + // gen func + cgen->addFunc (this->p_parFunc (), &objObj.subFunc, l); + break; + } + case hLexer::synTktype::TK_NUMBER: // number, back tk = STRING; + { + lex->nextToken (); + std::int32_t l = lex->getLine (); + + // check name after number + this->CheckMatch (hLexer::synTktype::TK_NAME, + hLexer::synTktype::TK_NUMBER, l); + + // gen number + cgen->addNumber (this->p_parNumber (), &objObj.subNum, l); + break; + } + case hLexer::synTktype::TK_KSTR: // string, back tk = STRING; + { + lex->nextToken (); + std::int32_t l = lex->getLine (); + + // check name after number + this->CheckMatch (hLexer::synTktype::TK_NAME, + hLexer::synTktype::TK_KSTR, l); + + // gen number + cgen->addString (this->p_parString (), &objObj.subStr, l); + break; + } + case hLexer::synTktype::TK_OBJECT: // variable, back tk = END; + { + lex->nextToken (); + std::int32_t l = lex->getLine (); + + // check name after object + this->CheckMatch (hLexer::synTktype::TK_NAME, + hLexer::synTktype::TK_OBJECT, l); + + // gen object + cgen->addObject (this->p_parObject (), &objObj.subObj, l); + break; + } + case hLexer::synTktype::TK_CLASS: // variable, back tk = END; + { + lex->nextToken (); + std::int32_t l = lex->getLine (); + + // check name after class + this->CheckMatch (hLexer::synTktype::TK_NAME, + hLexer::synTktype::TK_CLASS, l); + + // gen class + cgen->addClass (this->p_parClass (), &objObj.subCls, l); + break; + } + default: + { + throw hError_t ("invalid experssion", lex->getLine (), + hError::errCode::eCode_Parser); + } + } + } +} + +cgType_class // parse class, back tk = END; +hParser::p_parClass () +{ + hLexer *const lex = this->lex; + hCodegen *const cgen = this->cgen; + + cgType_class clsObj; + clsObj.name = lex->getTkValue (); + + cgType_func initFunc; + initFunc.name = "__init__"; + initFunc.comment = "/**\n"; + + // check parameters + lex->nextToken (); + this->CheckMatch ('(', hLexer::synTktype::TK_CLASS, lex->getLine ()); + this->ParseExp (); + this->CheckMatch (':', hLexer::synTktype::TK_CLASS, lex->getLine ()); + + // until END + while (1) + { + lex->nextToken (); + switch (lex->getTkType ()) + { + case hLexer::synTktype::TK_END: + { + initFunc.comment += "*/"; + cgen->addFunc (initFunc, &clsObj.subFunc, lex->getLine ()); + return clsObj; + break; + } + case hLexer::synTktype::TK_POINT: // variable, back tk = NAME; + { + lex->nextToken (); + + // check name after point + this->CheckMatch (hLexer::synTktype::TK_NAME, + hLexer::synTktype::TK_POINT, lex->getLine ()); + + break; + } + case hLexer::synTktype::TK_DEF: // variable, back tk = END; + { + lex->nextToken (); + std::int32_t l = lex->getLine (); + + // check name after def + this->CheckMatch (hLexer::synTktype::TK_NAME, + hLexer::synTktype::TK_DEF, l); + + // gen func + cgen->addFunc (this->p_parFunc (), &clsObj.subFunc, l); + break; + } + case hLexer::synTktype::TK_NUMBER: // number, back tk = STRING; + { + lex->nextToken (); + std::int32_t l = lex->getLine (); + + // check name after number + this->CheckMatch (hLexer::synTktype::TK_NAME, + hLexer::synTktype::TK_NUMBER, l); + + // gen number + cgen->addNumber (this->p_parNumber (), &clsObj.subNum, l); + break; + } + case hLexer::synTktype::TK_KSTR: // key-string, back tk = STRING; + { + lex->nextToken (); + std::int32_t l = lex->getLine (); + + // check name after number + this->CheckMatch (hLexer::synTktype::TK_NAME, + hLexer::synTktype::TK_KSTR, l); + + // gen number + cgen->addString (this->p_parString (), &clsObj.subStr, l); + break; + } + case hLexer::synTktype::TK_STRING: // string, back tk = STRING; + { + initFunc.comment += "* " + lex->getTkValue () + '\n'; + break; + } + default: + { + throw hError_t ("invalid experssion", lex->getLine (), + hError::errCode::eCode_Parser); + } + } + } +} + +} // namespace Parser + +} // namespace LosuPreCompiler + + +#ifdef HPARSERCC_MAIN + +#include +#include +using namespace LosuPreCompiler; +using namespace Parser; + +int +main () +{ + std::ifstream fin ("test/demo.els", std::ios::in); + std::string sSrc, tmp; + while (std::getline (fin, tmp)) + sSrc += tmp + '\n'; + fin.close (); + + hParser p (sSrc, "demo.els"); + CodeGen::cgOutput out = p.doParse (); + std::ofstream ofile ("test/demo.els.c"); + std::ofstream hfile ("test/demo.els.h"); + hfile << out.headFile.headcmt << std::endl + << out.headFile.declare << std::endl; + ofile << out.srcFile.headcmt << std::endl + << out.srcFile.declare << std::endl + << out.srcFile.module << std::endl + << out.srcFile.submod << std::endl + << out.srcFile.object << std::endl + << out.srcFile.classs << std::endl + << out.srcFile.func << std::endl; + hfile.close (); + ofile.close (); + + return 0; +} + +#endif \ No newline at end of file diff --git a/tools/lpkg/LICENSE b/tools/lpkg/LICENSE new file mode 100755 index 0000000000000000000000000000000000000000..5f03f99cd682fe24599fb52bfe57bca0deeeb967 --- /dev/null +++ b/tools/lpkg/LICENSE @@ -0,0 +1,8 @@ +The MIT License (MIT) +Copyright © 2024 chen-chaochen & Dongqiao Huang + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/tools/lpkg/lib/lpkg.lsh b/tools/lpkg/lib/lpkg.lsh new file mode 100755 index 0000000000000000000000000000000000000000..eb9f3bcc170e7534ec6cdb0228c1b5ff4e4c5db7 --- /dev/null +++ b/tools/lpkg/lib/lpkg.lsh @@ -0,0 +1,16 @@ +module lpkg + sub main + object lpkg + def system(self: this, cmd: str): + # run system command + "@fn lpkg.system()" + def error(self: this, msg: str): + # print error message + "@fn lpkg.error()" + def export(self: this, pkg: str, fn: str): + # export package to file fn + "@fn lpkg.export()" + def print(self: this, info: str): + # print info to console + "@fn lpkg.print" + \ No newline at end of file diff --git a/tools/lpkg/lib/lpkg.lsh.c b/tools/lpkg/lib/lpkg.lsh.c new file mode 100755 index 0000000000000000000000000000000000000000..e17caa0e2fc7da3667826a0d59311a88e8f14d7e --- /dev/null +++ b/tools/lpkg/lib/lpkg.lsh.c @@ -0,0 +1,155 @@ + +/* + This file was generated by losuh - Losu Header Generator, which is part of + the Losu SDK. + + Losu is an open source programming language from China with excellent + performance (comparable to lua), ultra-lightweight resource footprint (only + 4KB RAM) and easy-to-learn syntax (similar to Python) for IoT development. + + This file follows the following MIT LICENSE by default + ------------------------------------ + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + +*/ + +#include "lpkg.lsh.h" +#include +#include +#include + +static int32_t __losuh__submod_main_lpkg (LosuVm *vm); +static LosuObj __losuh__obj_lpkg_main_lpkg (LosuVm *vm); +static int32_t __losuh__func_system_lpkg_main_lpkg (LosuVm *vm); +static int32_t __losuh__func_error_lpkg_main_lpkg (LosuVm *vm); +static int32_t __losuh__func_export_lpkg_main_lpkg (LosuVm *vm); +static int32_t __losuh__func_print_lpkg_main_lpkg (LosuVm *vm); + +LosuModule __losuh__MODULELIST[] = { + { "main", __losuh__submod_main_lpkg }, + { NULL, NULL }, +}; +LosuModule * +__losuh__LOADMODULE_lpkg () +{ + return &__losuh__MODULELIST[0]; +} + +static int32_t +__losuh__submod_main_lpkg (LosuVm *vm) +{ + // constructors of number in main + + // constructors of string in main + + // constructors of function in main + + // constructors of script in main + + // constructors of object in main + + __losuhAPI_regObject (vm, "lpkg", __losuh__obj_lpkg_main_lpkg (vm)); + + // constructors of class in main + + return 0; +} + +static LosuObj +__losuh__obj_lpkg_main_lpkg (LosuVm *vm) +{ + LosuObj newObj = obj_newunit (vm); + // constructor of number in lpkg@main_lpkg + + // constructor of string in lpkg@main_lpkg + + // constructor of object in lpkg@main_lpkg + + // constructor of class in lpkg@main_lpkg + + // constructor of function in lpkg@main_lpkg + /** + * @fn lpkg.system() + */ + __losuhAPI_regObjFunc (vm, newObj, "system", + __losuh__func_system_lpkg_main_lpkg); + /** + * @fn lpkg.error() + */ + __losuhAPI_regObjFunc (vm, newObj, "error", + __losuh__func_error_lpkg_main_lpkg); + /** + * @fn lpkg.export() + */ + __losuhAPI_regObjFunc (vm, newObj, "export", + __losuh__func_export_lpkg_main_lpkg); + /** + * @fn lpkg.print + */ + __losuhAPI_regObjFunc (vm, newObj, "print", + __losuh__func_print_lpkg_main_lpkg); + + return newObj; +} + +/** + * @fn lpkg.system() + */ +int32_t +__losuh__func_system_lpkg_main_lpkg (LosuVm *vm) +{ + int32_t i = system (arg_getstr (vm, 2)); + arg_returnnum (vm, (_l_number)i); + return 1; +} +/** + * @fn lpkg.error() + */ +int32_t +__losuh__func_error_lpkg_main_lpkg (LosuVm *vm) +{ + vm_error (vm, LosuErrorCode_Runtime, arg_getstr (vm, 2)); + return 0; +} +/** + * @fn lpkg.export() + */ +int32_t +__losuh__func_export_lpkg_main_lpkg (LosuVm *vm) +{ + const char *fn = arg_getstr (vm, 3); + FILE *f = fopen (fn, "w"); + if (f == NULL) + vm_error (vm, LosuErrorCode_Runtime, "Can't open output file '%s'", fn); + const char *s = arg_getstr (vm, 2); + fwrite (s, sizeof (char ), strlen (s), f); + fclose (f); + return 0; +} +/** + * @fn lpkg.print + */ +int32_t +__losuh__func_print_lpkg_main_lpkg (LosuVm *vm) +{ + printf ("%s\n", arg_getstr (vm, 2)); + return 0; +} diff --git a/tools/lpkg/lib/lpkg.lsh.h b/tools/lpkg/lib/lpkg.lsh.h new file mode 100755 index 0000000000000000000000000000000000000000..a706f3ce23e2db9a6522845d8a573a8ed8108595 --- /dev/null +++ b/tools/lpkg/lib/lpkg.lsh.h @@ -0,0 +1,37 @@ + +/* + This file was generated by losuh - Losu Header Generator, which is part of + the Losu SDK. + + Losu is an open source programming language from China with excellent + performance (comparable to lua), ultra-lightweight resource footprint (only + 4KB RAM) and easy-to-learn syntax (similar to Python) for IoT development. + + This file follows the following MIT LICENSE by default + ------------------------------------ + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + +*/ + +#include "losu.h" +#include "losuh.h" +LosuModule *__losuh__LOADMODULE_lpkg(); + diff --git a/tools/lpkg/main.c b/tools/lpkg/main.c new file mode 100755 index 0000000000000000000000000000000000000000..0481ae2300f233a656667b9542f3fdb0beb1e9f9 --- /dev/null +++ b/tools/lpkg/main.c @@ -0,0 +1,101 @@ +/* + Losu Copyright Notice + -------------------- + Losu is an open source programming language project under the MIT license + that can be used for both academic and commercial purposes. There are no + fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies + as open source software. However, Losu is not public property, and founder + 'chen-chaochen' retains its copyright. + + Losu has been registered with the National Copyright Administration of the + People's Republic of China, and adopts the MIT license as the copyright + licensing contract under which the right holder conditionally licenses its + reproduction, distribution, and modification rights to an unspecified public. + + If you use Losu, please follow the public MIT agreement or choose to enter + into a dedicated license agreement with us. + + The MIT LICENSE is as follows + -------------------- + Copyright 2020 - now chen-chaochen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +/* + This document is part of the Losu Community OSPP - 2024 subject results + contributed by Dongqiao Huang @ NEUQ, following MIT LICENSE Contributed to + the Losu Community. + + The MIT LICENSE is as follows + -------------------- + Copyright 2024 Dongqiao Huang + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the “Software”), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +#include "lpkg.lsh.h" +#include +#include +#include + +const char __this_script[] = +#include "lpkg.els.inc" + ; +; + +LosuPackage_t __this_pkgs[] = { + { "lpkg", __losuh__LOADMODULE_lpkg }, + { NULL, NULL }, +}; + +int32_t +main (int32_t argc, const char *argv[]) +{ + int32_t i = 0; + LosuPackages = &__this_pkgs[0]; + LosuVm *vm = vm_create (1024); + vm_init (vm, argc, argv); + + /* load config */ + i = vm_dofile (vm, "./config"); + /* do script */ + /* if (i == LosuErrorCode_File) + fprintf (stderr, "[lpkg] Error: config file not found\n"); + if (i == 0) */ + i += abs (vm_dobyte (vm, __this_script, sizeof (__this_script), "lpkg.els")); + vm_close (vm); + return i; +} diff --git a/tools/lpkg/makefile b/tools/lpkg/makefile new file mode 100755 index 0000000000000000000000000000000000000000..9b97635302a55fd1c17d58b7abc6b63045af3636 --- /dev/null +++ b/tools/lpkg/makefile @@ -0,0 +1,31 @@ +PkgObj=$(LosuSDK_Obj)/sdk/lpkg + +cc=cc + +CIncFile=\ + $(shell ls lib/*.h)\ + $(shell ls $(LosuSDK_Include)/*.h)\ + + +cWarning= -Wall +cStd= -std=c99 +cOpt= -O2 +cInclude= -Ilib -Iscript -I$(LosuSDK_Include) +cLink= -lm -L$(LosuSDK_Lib) -l:liblosu.a +cFlags= $(cWarning) $(cStd) $(cOpt) $(cInclude) + +$(LosuSDK_Path)/lpkg:\ + $(LosuSDK_Obj)/sdk/lpkg/main.o\ + $(LosuSDK_Obj)/sdk/lpkg/lpkg.lsh.o\ + $(LosuSDK_Lib)/liblosu.a\ + + $(cc) -o $@ $^ $(cLink) + +$(LosuSDK_Obj)/sdk/lpkg/main.o: main.c $(CIncFile) script/lpkg.els.inc + $(cc) $(cFlags) -c $< -o $@ + +$(LosuSDK_Obj)/sdk/lpkg/lpkg.lsh.o: lib/lpkg.lsh.c $(CIncFile) + $(cc) $(cFlags) -c $< -o $@ + +script/lpkg.els.inc: script/lpkg.els + $(LosuSDK_Path)/losuc -c $< \ No newline at end of file diff --git a/tools/lpkg/readme.md b/tools/lpkg/readme.md new file mode 100755 index 0000000000000000000000000000000000000000..f9b679c03c2d4c130025d12bbddd8ff58a74d491 --- /dev/null +++ b/tools/lpkg/readme.md @@ -0,0 +1,43 @@ +# Lpkg · Losu Package +## 简介 +Lpkg(全称 Losu Package),可以根据 `config` 文件配置、构建 Losu SDK。 +## 配置 ++ 在工程目录下运行 `lpkg config` 进行配置 + - 如果当前工程是 `main` 工程,Lpkg 会: + - 配置主文件 `main.els` (由 `.main` 成员指定) + - 配置所有依赖的 `pkgs` 工程(由 `.pkgs` 成员指定) + - 生成 `pkgs` 列表 + - 如果当前工程是 `pkgs` 工程,Lpkg 会: + - 配置所有依赖的脚本文件(基于 `losuc`) + +## 构建 ++ lpkg 可以根据内置规则对 `main` 工程进行构建 ++ 在已经完成配置的工程目录下运行 `lpkg make` 进行构建,Lpkg 会: + - 构建洛书内核 + - 构建所有依赖的 pkgs 工程 + - 构建可执行二进制 + +## 清理 ++ 使用 `lpkg clean` 清理工程 + +# Lpkg · Losu Package +## Introduction +Lpkg (Losu Package), can build Losu SDK according to `config` file. +## Configuration ++ Run `lpkg config` in the project directory to configure + - If the current project is the `main` project, Lpkg will: + - Configure the main file `main.els` (specified by the `.main` member) + - Configure all dependent `pkgs` projects (specified by the `.pkgs` member) + - Generate `pkgs` list + - If the current project is a `pkgs` project, Lpkg will: + - Configure all dependent script files (based on `losuc`) + +## Build ++ Lpkg can build the `main` project according to the built-in rules ++ Run `lpkg make` in the project directory that has been configured, Lpkg will: + - Build the Losu kernel + - Build all dependent pkgs projects + - Build the executable binary + +## Clean ++ Run `lpkg clean` in the project directory that has been made to clean \ No newline at end of file diff --git a/tools/lpkg/script/lpkg.els b/tools/lpkg/script/lpkg.els new file mode 100755 index 0000000000000000000000000000000000000000..6ff951d3723c7fc730de68c3f2b927b1a79b79cb --- /dev/null +++ b/tools/lpkg/script/lpkg.els @@ -0,0 +1,213 @@ +# Losu Copyright Notice +# -------------------- +# Losu is an open source programming language project under the MIT license +# that can be used for both academic and commercial purposes. There are no +# fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies +# as open source software. However, Losu is not public property, and founder +# 'chen-chaochen' retains its copyright. + +# Losu has been registered with the National Copyright Administration of the +# People's Republic of China, and adopts the MIT license as the copyright +# licensing contract under which the right holder conditionally licenses its +# reproduction, distribution, and modification rights to an unspecified public. + +# If you use Losu, please follow the public MIT agreement or choose to enter +# into a dedicated license agreement with us. + +# The MIT LICENSE is as follows +# -------------------- +# Copyright 2020 - now chen-chaochen + +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the “Software”), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + + +# This document is part of the Losu Community OSPP - 2024 subject results +# contributed by Dongqiao Huang @ NEUQ, following MIT LICENSE Contributed to +# the Losu Community. + +# The MIT LICENSE is as follows +# -------------------- +# Copyright 2024 Dongqiao Huang + +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the “Software”), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +import "lpkg" + + +var lpkg = lpkg or {} + + +def lpkg.config(): + # config the losu package in `./`, with file `config` + # 1. load the config file, this step will be done in C-file + # 2. set the config value to the lpkg + if main: # 2.1 - if pkg is `main` + lpkg.configMain() + elif pkgs: # 2.2 - if pkg is `pkgs` + lpkg.configPkgs() + else: # 2.3 - error type + lpkg.error("invalid type, must be `main` or `pkgs`") + +def lpkg.configMain(): + # config Main type pkgs + for n,pkgs in main.pkgs or {}: + # system to config pkgs + var t = ( + lpkg.system( + "cd $LosuSDK_Pkgs/" + & pkgs + & "&& lpkg config" + ) ==0 and 1 + ) or lpkg.error( + "failed to config pkg '" + & pkgs + & "'" + ) + # export the pkgs.inc + var out_t = { + dec: "", + list: "", + } + local: # init list head + out_t.list = "static LosuPackage_t _inlinePkgs[]={\n" + for n,pkgs in main.pkgs or {}: + # concat declare + out_t.dec = ( + out_t.dec + & "LosuExtern LosuModule *__losuh__LOADMODULE_" & pkgs + & "();\n" + ) + # concat list body + out_t.list = ( + out_t.list + & "{\"" & pkgs & "\"," + & "__losuh__LOADMODULE_" & pkgs + & "},\n" + ) + local: # init list tail + out_t.list = out_t.list & "{NULL,NULL},\n" + out_t.list = out_t.list & "};\n" + # write the pkgs.inc + lpkg.export(out_t.dec & out_t.list, "pkgs.inc") + +def lpkg.configPkgs(): + # config Pkgs type pkgs + for n,srcf in pkgs.src or {}: + # system to config pkgs + var t = ( + lpkg.system("losuc -c "& srcf) ==0 and 1 + ) or lpkg.error( + "failed to config pkg '" + & (pkgs.name or "unknown") & "'" + & " ,file '" & srcf & "'" + ) + +def lpkg.make(): + # make the losu package in `./`, with file `config` + # 1. load the config file, this step will be done in C-file + # 2. set the config value to the lpkg + if main: # 2.1 - if pkg is `main` + lpkg.makeMain() + else: # 2.3 - error type + lpkg.error("invalid type, must be `main`") + +def lpkg.makeMain(): + # make Main type pkgs + # 1. check the config file + var target = main.target or lpkg.error("no target specified") + # var pkgs = main.pkgs or {} + # var msrc = main.main or "main.els" + + # 2. make `liblosu.a` + var liblosu = ( + lpkg.system( + "cd $LosuSDK_Root/core; make -f target/" + & target + ) == 0 and 1 + ) or lpkg.error("failed to make `liblosu.a`") + + # 3. make the pkgs + for n,pkgs in main.pkgs or {}: + # system to make pkgs + var t = ( + lpkg.system( + "cd $LosuSDK_Pkgs/" & pkgs + & "&& make -f target/" & target + ) ==0 and 1 + ) or lpkg.error("failed to make pkg '" & pkgs & "'") + + # 4. make `liblosupkgs.a` + var liblosupkgs = ( + lpkg.system( + "cd $LosuSDK_Build/target&&" + &"ar crsT liblosucore.a liblosu.a ./pkgs/*.a" + ) == 0 and 1 + ) or lpkg.error("failed to make `liblosupkgs.a`") + + # 5. make 'main.out' + var mainout = ( + lpkg.system( + "make main.out=\"" & (main.name or "main.out") + &"\" -f target/" & target + ) == 0 and 1 + ) or lpkg.error("failed to make `main.out`") + +def lpkg.clean(): + lpkg.system("rm -rf $LosuSDK_Build/target/*.a") + lpkg.system("rm -rf $LosuSDK_Build/target/pkgs/*") + lpkg.system("rm -rf $LosuSDK_Obj/target/*") + lpkg.print("clean project done") + + +# main +# check args.n +if args.n == 1: # if n == 1, print help info + lpkg.print("--------- Lpkg - Losu Package ---------") + lpkg.print("| lpkg config config project |") + lpkg.print("| lpkg make make project |") + lpkg.print("| lpkg clean clean project |") + lpkg.print("---------------------------------------") +elif args.n == 2: # if n == 2, check config or make + if args[2] == "config": + lpkg.config() + elif args[2] == "clean": + lpkg.clean() + elif args[2] == "make": + lpkg.make() + else + lpkg.error("unknown args '" & args[2]& "'") +else + lpkg.error("too much args") + diff --git a/tools/lpkg/script/lpkg.els.inc b/tools/lpkg/script/lpkg.els.inc new file mode 100755 index 0000000000000000000000000000000000000000..578b23e9f62973a82b1a2bc7111f2caab759cfdb --- /dev/null +++ b/tools/lpkg/script/lpkg.els.inc @@ -0,0 +1,528 @@ +{ + 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x2f, + 0x6c, 0x70, 0x6b, 0x67, 0x2e, 0x65, 0x6c, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x27, 0x00, 0x00, 0x00, 0xbf, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xfe, + 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0x07, 0x00, + 0x00, 0x00, 0xf6, 0xff, 0xff, 0xff, 0x09, 0x00, 0x00, 0x00, 0xd7, 0xff, 0xff, + 0xff, 0x0d, 0x00, 0x00, 0x00, 0xf5, 0xff, 0xff, 0xff, 0x11, 0x00, 0x00, 0x00, + 0xf8, 0xff, 0xff, 0xff, 0x15, 0x00, 0x00, 0x00, 0xd8, 0xff, 0xff, 0xff, 0x19, + 0x00, 0x00, 0x00, 0xfa, 0xff, 0xff, 0xff, 0x1d, 0x00, 0x00, 0x00, 0xff, 0xff, + 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, + 0x00, 0x2c, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, + 0x38, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x43, 0x00, 0x00, 0x00, 0x46, + 0x00, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x4f, 0x00, 0x00, 0x00, 0x55, 0x00, + 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, 0x59, 0x00, 0x00, 0x00, 0x63, 0x00, 0x00, + 0x00, 0x64, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x68, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xff, 0x7f, 0x18, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x00, 0x05, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x70, 0x6b, 0x67, 0x00, 0x07, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x00, 0x0b, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, + 0x4d, 0x61, 0x69, 0x6e, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x6c, 0x70, 0x6b, 0x67, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x50, 0x6b, 0x67, 0x73, 0x00, 0x05, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x70, 0x6b, 0x67, 0x00, 0x05, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x6b, 0x65, 0x00, 0x09, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x6b, 0x65, 0x4d, 0x61, 0x69, + 0x6e, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x70, 0x6b, + 0x67, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x6c, 0x65, + 0x61, 0x6e, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x61, 0x72, + 0x67, 0x73, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6e, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x70, 0x6b, 0x67, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x72, 0x69, 0x6e, 0x74, + 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2d, 0x2d, 0x2d, 0x2d, + 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x20, 0x4c, 0x70, 0x6b, 0x67, 0x20, 0x2d, 0x20, + 0x4c, 0x6f, 0x73, 0x75, 0x20, 0x50, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x20, + 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x00, 0x28, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x20, 0x20, 0x6c, 0x70, 0x6b, 0x67, 0x20, + 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x20, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, + 0x74, 0x20, 0x20, 0x20, 0x7c, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x7c, 0x20, 0x20, 0x6c, 0x70, 0x6b, 0x67, 0x20, 0x6d, 0x61, 0x6b, 0x65, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6d, 0x61, 0x6b, 0x65, + 0x20, 0x20, 0x20, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x20, 0x20, + 0x7c, 0x00, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x20, 0x20, + 0x6c, 0x70, 0x6b, 0x67, 0x20, 0x63, 0x6c, 0x65, 0x61, 0x6e, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x63, 0x6c, 0x65, 0x61, 0x6e, 0x20, 0x20, 0x20, + 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x20, 0x20, 0x7c, 0x00, 0x28, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, + 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, + 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, + 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x00, 0x0f, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x75, 0x6e, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x20, 0x61, + 0x72, 0x67, 0x73, 0x20, 0x27, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x27, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0x6f, + 0x6f, 0x20, 0x6d, 0x75, 0x63, 0x68, 0x20, 0x61, 0x72, 0x67, 0x73, 0x00, 0x06, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x06, + 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, 0x63, + 0x72, 0x69, 0x70, 0x74, 0x2f, 0x6c, 0x70, 0x6b, 0x67, 0x2e, 0x65, 0x6c, 0x73, + 0x00, 0x48, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, + 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x73, 0x65, 0x6c, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, + 0x0a, 0x00, 0x00, 0x00, 0xb5, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x02, + 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x0b, 0x00, + 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, + 0x00, 0xff, 0xff, 0xff, 0x7f, 0x07, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x6c, 0x70, 0x6b, 0x67, 0x00, 0x0b, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x4d, 0x61, 0x69, + 0x6e, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x6b, 0x67, + 0x73, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x6f, 0x6e, + 0x66, 0x69, 0x67, 0x50, 0x6b, 0x67, 0x73, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x00, 0x27, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x69, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x20, 0x74, + 0x79, 0x70, 0x65, 0x2c, 0x20, 0x6d, 0x75, 0x73, 0x74, 0x20, 0x62, 0x65, 0x20, + 0x60, 0x6d, 0x61, 0x69, 0x6e, 0x60, 0x20, 0x6f, 0x72, 0x20, 0x60, 0x70, 0x6b, + 0x67, 0x73, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, + 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe2, 0x00, + 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x4b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x89, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x65, 0x02, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0xcb, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe2, 0x00, 0x00, 0x00, 0x20, 0x00, + 0x00, 0x00, 0x4b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xe5, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x4b, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x49, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x2f, 0x6c, 0x70, + 0x6b, 0x67, 0x2e, 0x65, 0x6c, 0x73, 0x00, 0x53, 0x00, 0x00, 0x00, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x05, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, 0x65, 0x6c, 0x66, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x67, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x5f, 0x5f, 0x54, 0x48, 0x49, 0x53, 0x5f, 0x5f, 0x00, 0x06, 0x00, 0x00, + 0x00, 0x1c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x6e, 0x00, 0x06, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x6b, 0x67, 0x73, 0x00, 0x06, 0x00, 0x00, + 0x00, 0x1c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x74, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x6f, 0x75, 0x74, 0x5f, 0x74, 0x00, 0x22, 0x00, + 0x00, 0x00, 0x67, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x5f, 0x5f, 0x54, 0x48, 0x49, 0x53, 0x5f, 0x5f, 0x00, 0x2c, 0x00, 0x00, + 0x00, 0x4b, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x6e, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x4b, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x6b, 0x67, 0x73, 0x00, 0x2c, 0x00, 0x00, + 0x00, 0x4b, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0xac, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0x06, 0x00, 0x00, 0x00, 0xfe, + 0xff, 0xff, 0xff, 0x09, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x11, 0x00, + 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0x15, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, + 0x00, 0xff, 0xff, 0xff, 0xff, 0x1c, 0x00, 0x00, 0x00, 0x1d, 0x00, 0x00, 0x00, + 0x1f, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0x22, 0x00, 0x00, 0x00, 0x26, + 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x2c, 0x00, 0x00, 0x00, 0x2e, 0x00, + 0x00, 0x00, 0x2f, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x37, 0x00, 0x00, + 0x00, 0xff, 0xff, 0xff, 0xff, 0x38, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x00, + 0x3b, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00, 0x49, + 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x4b, 0x00, 0x00, 0x00, 0x53, 0x00, + 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x5b, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, + 0xff, 0x66, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x7f, 0x17, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x6b, 0x67, 0x73, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x70, 0x6b, 0x67, 0x00, + 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, 0x79, 0x73, 0x74, 0x65, + 0x6d, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x64, 0x20, + 0x24, 0x4c, 0x6f, 0x73, 0x75, 0x53, 0x44, 0x4b, 0x5f, 0x50, 0x6b, 0x67, 0x73, + 0x2f, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0x26, 0x20, + 0x6c, 0x70, 0x6b, 0x67, 0x20, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x00, 0x06, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x00, + 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x61, 0x69, 0x6c, 0x65, + 0x64, 0x20, 0x74, 0x6f, 0x20, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x20, 0x70, + 0x6b, 0x67, 0x20, 0x27, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x27, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x65, 0x63, + 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x69, 0x73, 0x74, 0x00, 0x26, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, 0x20, 0x4c, + 0x6f, 0x73, 0x75, 0x50, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x5f, 0x74, 0x20, + 0x5f, 0x69, 0x6e, 0x6c, 0x69, 0x6e, 0x65, 0x50, 0x6b, 0x67, 0x73, 0x5b, 0x5d, + 0x3d, 0x7b, 0x0a, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4c, + 0x6f, 0x73, 0x75, 0x45, 0x78, 0x74, 0x65, 0x72, 0x6e, 0x20, 0x4c, 0x6f, 0x73, + 0x75, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x20, 0x2a, 0x5f, 0x5f, 0x6c, 0x6f, + 0x73, 0x75, 0x68, 0x5f, 0x5f, 0x4c, 0x4f, 0x41, 0x44, 0x4d, 0x4f, 0x44, 0x55, + 0x4c, 0x45, 0x5f, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, + 0x29, 0x3b, 0x0a, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7b, + 0x22, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x2c, 0x00, + 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5f, 0x5f, 0x6c, 0x6f, 0x73, + 0x75, 0x68, 0x5f, 0x5f, 0x4c, 0x4f, 0x41, 0x44, 0x4d, 0x4f, 0x44, 0x55, 0x4c, + 0x45, 0x5f, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7d, 0x2c, + 0x0a, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7b, 0x4e, 0x55, + 0x4c, 0x4c, 0x2c, 0x4e, 0x55, 0x4c, 0x4c, 0x7d, 0x2c, 0x0a, 0x00, 0x04, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7d, 0x3b, 0x0a, 0x00, 0x07, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x00, 0x09, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x6b, 0x67, 0x73, 0x2e, 0x69, + 0x6e, 0x63, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00, + 0x00, 0x67, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x0e, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x69, 0x05, 0x00, 0x00, 0x20, 0x00, 0x00, + 0x00, 0x8b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc9, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x05, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xca, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, 0x00, 0x20, + 0x00, 0x00, 0x00, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe3, 0x01, + 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x8b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x89, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc5, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xca, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x6a, 0xfa, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x8e, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x45, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc5, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x85, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x92, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc5, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xcf, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x20, + 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa9, 0x07, + 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x45, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x45, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x0a, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0x03, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xcf, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc5, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x4a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc5, 0x02, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc5, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x05, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0x04, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x85, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xcf, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2a, + 0xf8, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xc5, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xc5, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc5, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcf, 0xc0, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xc5, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xc5, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x05, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcf, 0xc0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x8b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x49, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x45, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xc5, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x85, + 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x80, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x2f, 0x6c, + 0x70, 0x6b, 0x67, 0x2e, 0x65, 0x6c, 0x73, 0x00, 0x7d, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x05, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, 0x65, 0x6c, 0x66, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x5f, 0x5f, 0x54, 0x48, 0x49, 0x53, 0x5f, 0x5f, 0x00, 0x06, 0x00, + 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x6e, 0x00, 0x06, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x05, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, 0x72, 0x63, 0x66, 0x00, 0x06, 0x00, + 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x74, 0x00, 0x22, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x0c, 0x00, + 0x00, 0x00, 0x82, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, + 0xff, 0x06, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, + 0x13, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0xff, + 0xff, 0xff, 0xff, 0x24, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x7f, 0x0b, 0x00, + 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x6b, 0x67, + 0x73, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, 0x72, 0x63, + 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x70, 0x6b, 0x67, + 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, 0x79, 0x73, 0x74, + 0x65, 0x6d, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x6f, + 0x73, 0x75, 0x63, 0x20, 0x2d, 0x63, 0x20, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x00, 0x17, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x66, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x20, 0x74, 0x6f, + 0x20, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x20, 0x70, 0x6b, 0x67, 0x20, 0x27, + 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6e, 0x61, 0x6d, 0x65, + 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x75, 0x6e, 0x6b, 0x6e, + 0x6f, 0x77, 0x6e, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x27, + 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x2c, 0x66, 0x69, + 0x6c, 0x65, 0x20, 0x27, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, + 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x69, 0x07, 0x00, 0x00, 0x20, + 0x00, 0x00, 0x00, 0x8b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc9, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xca, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, 0x00, 0x20, 0x00, + 0x00, 0x00, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x04, 0x00, + 0x00, 0x20, 0x00, 0x00, 0x00, 0x8b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x49, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc5, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x23, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x05, 0x02, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x45, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x85, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xca, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x45, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x6a, 0xf8, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, + 0x63, 0x72, 0x69, 0x70, 0x74, 0x2f, 0x6c, 0x70, 0x6b, 0x67, 0x2e, 0x65, 0x6c, + 0x73, 0x00, 0x89, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, + 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x73, 0x65, 0x6c, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, + 0x00, 0x08, 0x00, 0x00, 0x00, 0x74, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xff, + 0xff, 0xff, 0xff, 0x0a, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x7f, 0x05, 0x00, + 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, + 0x6e, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x70, 0x6b, + 0x67, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x6b, + 0x65, 0x4d, 0x61, 0x69, 0x6e, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x00, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x69, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x20, 0x74, 0x79, 0x70, + 0x65, 0x2c, 0x20, 0x6d, 0x75, 0x73, 0x74, 0x20, 0x62, 0x65, 0x20, 0x60, 0x6d, + 0x61, 0x69, 0x6e, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0b, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe2, + 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x4b, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x89, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xe5, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x4b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc9, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x05, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x40, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, 0x63, 0x72, 0x69, + 0x70, 0x74, 0x2f, 0x6c, 0x70, 0x6b, 0x67, 0x2e, 0x65, 0x6c, 0x73, 0x00, 0x92, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x09, + 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, 0x65, + 0x6c, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x59, 0x00, 0x00, 0x00, 0x07, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x59, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x6c, 0x69, 0x62, 0x6c, 0x6f, 0x73, 0x75, 0x00, 0x16, 0x00, + 0x00, 0x00, 0x59, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x5f, 0x5f, 0x54, 0x48, 0x49, 0x53, 0x5f, 0x5f, 0x00, 0x1c, 0x00, 0x00, + 0x00, 0x34, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x6e, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x6b, 0x67, 0x73, 0x00, 0x1c, 0x00, 0x00, + 0x00, 0x34, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x74, 0x00, 0x32, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x69, 0x62, 0x6c, 0x6f, 0x73, 0x75, 0x70, + 0x6b, 0x67, 0x73, 0x00, 0x42, 0x00, 0x00, 0x00, 0x59, 0x00, 0x00, 0x00, 0x08, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x6f, 0x75, + 0x74, 0x00, 0x58, 0x00, 0x00, 0x00, 0x59, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, + 0x00, 0x6c, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xfb, 0xff, 0xff, 0xff, + 0x08, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x0b, 0x00, 0x00, 0x00, 0x0d, + 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0x16, 0x00, + 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0x1c, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, + 0xff, 0x1f, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, + 0xfd, 0xff, 0xff, 0xff, 0x34, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x37, + 0x00, 0x00, 0x00, 0x39, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x00, 0x00, 0xfd, 0xff, + 0xff, 0xff, 0x42, 0x00, 0x00, 0x00, 0x45, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x00, + 0x00, 0x4f, 0x00, 0x00, 0x00, 0x53, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, + 0x58, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x7f, 0x15, 0x00, 0x00, 0x00, 0x05, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x07, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, + 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x70, 0x6b, 0x67, + 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x72, 0x72, 0x6f, + 0x72, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6e, 0x6f, 0x20, + 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x20, 0x73, 0x70, 0x65, 0x63, 0x69, 0x66, + 0x69, 0x65, 0x64, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, + 0x79, 0x73, 0x74, 0x65, 0x6d, 0x00, 0x27, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x63, 0x64, 0x20, 0x24, 0x4c, 0x6f, 0x73, 0x75, 0x53, 0x44, 0x4b, 0x5f, + 0x52, 0x6f, 0x6f, 0x74, 0x2f, 0x63, 0x6f, 0x72, 0x65, 0x3b, 0x20, 0x6d, 0x61, + 0x6b, 0x65, 0x20, 0x2d, 0x66, 0x20, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x2f, + 0x00, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x61, 0x69, 0x6c, + 0x65, 0x64, 0x20, 0x74, 0x6f, 0x20, 0x6d, 0x61, 0x6b, 0x65, 0x20, 0x60, 0x6c, + 0x69, 0x62, 0x6c, 0x6f, 0x73, 0x75, 0x2e, 0x61, 0x60, 0x00, 0x05, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x6b, 0x67, 0x73, 0x00, 0x12, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x64, 0x20, 0x24, 0x4c, 0x6f, 0x73, 0x75, + 0x53, 0x44, 0x4b, 0x5f, 0x50, 0x6b, 0x67, 0x73, 0x2f, 0x00, 0x13, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0x26, 0x20, 0x6d, 0x61, 0x6b, 0x65, 0x20, + 0x2d, 0x66, 0x20, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x2f, 0x00, 0x15, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x20, + 0x74, 0x6f, 0x20, 0x6d, 0x61, 0x6b, 0x65, 0x20, 0x70, 0x6b, 0x67, 0x20, 0x27, + 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x27, 0x00, 0x1b, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x64, 0x20, 0x24, 0x4c, 0x6f, 0x73, + 0x75, 0x53, 0x44, 0x4b, 0x5f, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x2f, 0x74, 0x61, + 0x72, 0x67, 0x65, 0x74, 0x26, 0x26, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x61, 0x72, 0x20, 0x63, 0x72, 0x73, 0x54, 0x20, 0x6c, 0x69, 0x62, + 0x6c, 0x6f, 0x73, 0x75, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x20, 0x6c, 0x69, + 0x62, 0x6c, 0x6f, 0x73, 0x75, 0x2e, 0x61, 0x20, 0x2e, 0x2f, 0x70, 0x6b, 0x67, + 0x73, 0x2f, 0x2a, 0x2e, 0x61, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x66, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x20, 0x74, 0x6f, 0x20, 0x6d, 0x61, + 0x6b, 0x65, 0x20, 0x60, 0x6c, 0x69, 0x62, 0x6c, 0x6f, 0x73, 0x75, 0x70, 0x6b, + 0x67, 0x73, 0x2e, 0x61, 0x60, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x6d, 0x61, 0x6b, 0x65, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x6f, 0x75, + 0x74, 0x3d, 0x22, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6e, + 0x61, 0x6d, 0x65, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6d, + 0x61, 0x69, 0x6e, 0x2e, 0x6f, 0x75, 0x74, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x22, 0x20, 0x2d, 0x66, 0x20, 0x74, 0x61, 0x72, 0x67, 0x65, + 0x74, 0x2f, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x61, + 0x69, 0x6c, 0x65, 0x64, 0x20, 0x74, 0x6f, 0x20, 0x6d, 0x61, 0x6b, 0x65, 0x20, + 0x60, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x6f, 0x75, 0x74, 0x60, 0x00, 0x08, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, + 0x3f, 0x00, 0x00, 0x00, 0x00, 0x59, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe3, 0x00, 0x00, 0x00, 0x20, 0x00, + 0x00, 0x00, 0x8b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc9, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x42, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8b, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x49, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x80, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5b, + 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xe3, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x8b, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xc9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xc5, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x80, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x23, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xe9, 0x05, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x8b, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x45, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x4a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe3, + 0x01, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x8b, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xc9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc5, 0x02, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x05, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x80, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xea, 0xf9, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x8b, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x49, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0xc0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x5b, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x46, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xe3, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x8b, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xc5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0xc0, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x8b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x04, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0x04, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x23, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x85, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xc5, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, 0x00, 0x20, 0x00, + 0x00, 0x00, 0xc6, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe3, 0x00, 0x00, + 0x00, 0x20, 0x00, 0x00, 0x00, 0x8b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xc9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x05, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x42, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x2f, 0x6c, 0x70, 0x6b, 0x67, 0x2e, + 0x65, 0x6c, 0x73, 0x00, 0xbb, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x73, 0x65, 0x6c, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, + 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x45, 0xff, 0xff, 0xff, 0x00, 0x00, + 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, + 0x00, 0xfe, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x7f, + 0x07, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, + 0x70, 0x6b, 0x67, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, + 0x79, 0x73, 0x74, 0x65, 0x6d, 0x00, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x72, 0x6d, 0x20, 0x2d, 0x72, 0x66, 0x20, 0x24, 0x4c, 0x6f, 0x73, 0x75, + 0x53, 0x44, 0x4b, 0x5f, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x2f, 0x74, 0x61, 0x72, + 0x67, 0x65, 0x74, 0x2f, 0x2a, 0x2e, 0x61, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x72, 0x6d, 0x20, 0x2d, 0x72, 0x66, 0x20, 0x24, 0x4c, 0x6f, + 0x73, 0x75, 0x53, 0x44, 0x4b, 0x5f, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x2f, 0x74, + 0x61, 0x72, 0x67, 0x65, 0x74, 0x2f, 0x70, 0x6b, 0x67, 0x73, 0x2f, 0x2a, 0x00, + 0x1d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x72, 0x6d, 0x20, 0x2d, 0x72, + 0x66, 0x20, 0x24, 0x4c, 0x6f, 0x73, 0x75, 0x53, 0x44, 0x4b, 0x5f, 0x4f, 0x62, + 0x6a, 0x2f, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x2f, 0x2a, 0x00, 0x06, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x00, 0x13, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x6c, 0x65, 0x61, 0x6e, 0x20, + 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x64, 0x6f, 0x6e, 0x65, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x0b, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x85, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc5, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x05, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x69, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4b, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x4d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x4b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcf, 0xc0, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xc5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x40, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xcf, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x08, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcf, 0xc0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x8b, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xc5, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0xc0, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xcf, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4b, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x08, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcf, 0xc0, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x4b, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x85, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x40, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xcf, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcb, 0x02, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x1b, 0x05, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x4b, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x89, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xc5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x4b, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x89, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x04, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4b, 0x03, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x89, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x45, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x4b, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x89, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4b, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x89, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc5, + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xa5, 0x0b, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0xcb, 0x02, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x5b, 0x09, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0xcb, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xdb, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x4b, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x89, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x25, 0x08, 0x00, + 0x00, 0x20, 0x00, 0x00, 0x00, 0xcb, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x85, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdb, 0x00, + 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x4b, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x89, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xe5, 0x05, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0xcb, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc5, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xdb, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x4b, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc9, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa5, 0x03, + 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x4b, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0x05, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xcb, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x85, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe5, 0x00, 0x00, 0x00, 0x20, + 0x00, 0x00, 0x00, 0x4b, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x05, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc5, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, +};