From 979ee5245348c4dff3b5f18e1eda13272f1f5d3f Mon Sep 17 00:00:00 2001 From: subkey <2822448396@qq.com> Date: Fri, 19 Apr 2024 09:16:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20linux=E6=94=AF=E6=8C=81,=20readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .cargo/config.toml | 3 +++ .gitignore | 2 ++ Cargo.toml | 3 +++ readme.md | 17 +++++++++++++++++ samples/helloworld.ks | 5 ++--- src/c.rs | 32 ++++++++++++++++++++++++-------- src/main.rs | 2 -- 7 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 .cargo/config.toml create mode 100644 readme.md diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..c477d2e --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,3 @@ +[target.x86_64-unknown-linux-musl] +linker = "rust-lld" +rustflags = ["-C", "linker-flavor=ld.lld"] \ No newline at end of file diff --git a/.gitignore b/.gitignore index ea8c4bf..fd55b43 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /target +/spec +/samples diff --git a/Cargo.toml b/Cargo.toml index 2871c85..2ef3b29 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,3 +4,6 @@ version = "0.1.6" edition = "2021" description = "To be the prettiest and simpliest script" license = "MPL-2.0" +repository = "https://github.com/bylx666/key-native" +homepage = "https://docs.subkey.top" +documentation = "https://docs.subkey.top/native" diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..bae0fdf --- /dev/null +++ b/readme.md @@ -0,0 +1,17 @@ +# Key Lang + +轻快, 省心, 做最精致的编程语言. + +1. 消去了引用的存在, 初学者也能轻松上手 +2. 更短的循环, `for!`代替`while(true)` +3. 更方便的迭代器, `for i:20`即可循环20次 +4. 更强大的`match`, 原生支持数字范围匹配 +5. 有趣的`extern`, 用key代码直接操作动态链接库! +6. 区分整数和浮点数, 再也不用`floor`遍地跑 +7. 原生类型支持, 动态类型检查, 大量减少判断量 +8. 像`js`一样用`{}`字面量创建哈希表 +9. 原生类型`Buf`让你轻松操作内存 + +更多特性请见[Key语言官网](https://docs.subkey.top). + +在我17岁时, 就在只有标准库的情况下完成了整个工程, 并独自创建了[Key语言官网](https://docs.subkey.top)和[在线尝试Key语言](https://play.subkey.top/)两个网站. 这一切, 或许都只是我的成人礼罢了. diff --git a/samples/helloworld.ks b/samples/helloworld.ks index ed9cb91..c2db320 100644 --- a/samples/helloworld.ks +++ b/samples/helloworld.ks @@ -1,6 +1,5 @@ //mod D:\code\rs\tst\target\debug\tstlib.dll> m; -let s = 99; - -log(0b10101010) \ No newline at end of file +let a = 5; +log(`a的值是:{a+5}`); \ No newline at end of file diff --git a/src/c.rs b/src/c.rs index ab9d430..29ab5c5 100644 --- a/src/c.rs +++ b/src/c.rs @@ -2,18 +2,34 @@ use std::ptr::NonNull; -extern { - fn LoadLibraryA(src:*const u8)-> *const (); - fn GetProcAddress(lib:*const (), src:*const u8)-> *const (); +#[cfg(windows)] +mod dl { + extern { + fn LoadLibraryA(src:*const u8)-> *const (); + fn GetProcAddress(lib:*const (), src:*const u8)-> *const (); + } + pub unsafe fn dlopen(src:*const u8)-> *const () { + unsafe {LoadLibraryA(src)} + } + + pub unsafe fn dlsym(lib:*const (), src:*const u8)-> *const () { + unsafe {GetProcAddress(lib, src)} + } } -pub unsafe fn dlopen(src:*const u8)-> *const () { - unsafe {LoadLibraryA(src)} +#[cfg(target_os = "linux")] +mod dl { + extern { + #[link_name = "dlopen"] + fn dlopen_(src:*const u8, m:i32)-> *const (); + pub fn dlsym(lib:*const (), src:*const u8)-> *const (); + } + pub unsafe fn dlopen(src:*const u8)-> *const () { + unsafe {dlopen_(src, 0)} + } } -pub unsafe fn dlsym(lib:*const (), src:*const u8)-> *const () { - unsafe {GetProcAddress(lib, src)} -} +pub use dl::*; pub struct Clib (*const ()); diff --git a/src/main.rs b/src/main.rs index b840923..57f1457 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,8 +38,6 @@ static VERSION:usize = 100006; static DISTRIBUTION:&str = "Subkey"; fn main()-> ExitCode { - // pub use pub mod - // 科学计数法0x 0b // linux macos支持 // 脚本打包exe