From fddedb782810837d1bd6a614468e405d8faa6d92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?b=CA=B0edoh=E2=82=82=20sw=C3=A9?= Date: Mon, 17 Jun 2024 04:14:13 +0500 Subject: [PATCH 1/9] Add #native --- Cargo.lock | 83 ++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/execute.rs | 6 ++- src/instructions/mod.rs | 1 + src/instructions/native.rs | 50 +++++++++++++++++++++++ test/native_test.lb | 4 ++ test/native_test.rs | 13 ++++++ 7 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 src/instructions/native.rs create mode 100644 test/native_test.lb create mode 100644 test/native_test.rs diff --git a/Cargo.lock b/Cargo.lock index 991b277..1484a35 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + [[package]] name = "fastrand" version = "2.0.1" @@ -13,11 +19,88 @@ name = "labast" version = "1.0.6" dependencies = [ "fastrand", + "libloading", "pico-args", ] +[[package]] +name = "libloading" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c571b676ddfc9a8c12f1f3d3085a7b163966a8fd8098a90640953ce5f6170161" +dependencies = [ + "cfg-if", + "windows-sys", +] + [[package]] name = "pico-args" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5be167a7af36ee22fe3115051bc51f6e6c7054c9348e28deb4f49bd6f705a315" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" diff --git a/Cargo.toml b/Cargo.toml index dce0edb..2eeb200 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,4 +18,5 @@ panic = "abort" [dependencies] fastrand = "2.0.1" +libloading = "0.8.1" pico-args = "0.5.0" diff --git a/src/execute.rs b/src/execute.rs index 8305b10..707f390 100644 --- a/src/execute.rs +++ b/src/execute.rs @@ -143,7 +143,11 @@ pub fn execute(stack: &mut Stack, mut origin_stack: Option<&mut Stack>, mod_name "exec" => { let arg = instruction.arg.clone(); instructions::modules::exec(stack, arg, mod_name.clone()) - } + }, + "native" => { + let arg = instruction.arg.clone(); + instructions::native::native(stack, arg) + }, // Self-modifying "insert" => { diff --git a/src/instructions/mod.rs b/src/instructions/mod.rs index a08c315..586aee4 100644 --- a/src/instructions/mod.rs +++ b/src/instructions/mod.rs @@ -9,3 +9,4 @@ pub mod self_modify; pub mod special; pub mod specific; pub mod stack_manage; +pub mod native; diff --git a/src/instructions/native.rs b/src/instructions/native.rs new file mode 100644 index 0000000..4bd4bbd --- /dev/null +++ b/src/instructions/native.rs @@ -0,0 +1,50 @@ +use crate::Stack; +use libloading::{Library, Symbol}; + +static mut STACKPTR: *mut Stack = 0 as *mut Stack; + +#[no_mangle] +extern fn stack_pop_callback() -> u16 { + return unsafe { + (*STACKPTR).memory.pop() + }; +} + +#[no_mangle] +extern fn stack_push_callback(data: u16) -> i32 { + unsafe { + (*STACKPTR).memory.push(data) + }; + return 0; +} + +#[no_mangle] +extern fn stack_len_callback() -> usize { + return unsafe{ + (*STACKPTR).memory.len() + }; +} + + +pub fn native(stack: &mut Stack, arg: String) { + unsafe { + STACKPTR = stack as *mut Stack; + } + #[cfg(not(target_family = "windows"))] + let libsuf: String = ".so".to_owned(); + + #[cfg(target_family = "windows")] + let libsuf: String = ".dll".to_owned(); + + let libpref: String = "./".to_owned(); + + unsafe { + let module = Library::new([libpref, arg, libsuf].join("")).unwrap(); + // C libraries should use + // int labashka(unsinged short (*pop)(), void (*push)(unsinged short), size_t (*len)(), size_t max_size ); + let func: Symbol u16, extern fn(u16) -> i32, extern fn () -> usize, usize) -> u32> = module.get(b"labashka").unwrap(); + func(stack_pop_callback,stack_push_callback,stack_len_callback, stack.memory.size()); + } +} + + diff --git a/test/native_test.lb b/test/native_test.lb new file mode 100644 index 0000000..1ec891a --- /dev/null +++ b/test/native_test.lb @@ -0,0 +1,4 @@ +@ 0 + push -1 + #native native_test + diff --git a/test/native_test.rs b/test/native_test.rs new file mode 100644 index 0000000..b6f7fc5 --- /dev/null +++ b/test/native_test.rs @@ -0,0 +1,13 @@ +// Build with +// rustc --crate-type cdylib native_test.rs -o native_test.so +// or +// rustc --crate-type cdylib native_test.rs -o native_test.dll + +#[no_mangle] +unsafe extern "C" fn labashka(pop: extern fn() -> u16, push: extern fn(u16) -> i32, len: extern fn () -> usize, max: usize) -> u32 { + println!("At {}, there's {}.", len(), pop()); + push(12); + println!("Maximum size is {}.", max); + return 0; +} + From 065df34eb1986c679ae1d7aa3c89d158c39888fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?b=CA=B0edoh=E2=82=82=20sw=C3=A9?= Date: Mon, 17 Jun 2024 17:48:53 +0500 Subject: [PATCH 2/9] Add "string" command --- src/execute.rs | 1 + src/instructions/stack_manage.rs | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/execute.rs b/src/execute.rs index 707f390..7564096 100644 --- a/src/execute.rs +++ b/src/execute.rs @@ -70,6 +70,7 @@ pub fn execute(stack: &mut Stack, mut origin_stack: Option<&mut Stack>, mod_name "dup" => instructions::stack_manage::dup(&mut stack.memory), "swap" => instructions::stack_manage::swap(&mut stack.memory), "pick" => instructions::stack_manage::pick(&mut stack.memory, instruction.data), + "string" => instructions::stack_manage::string(&mut stack.memory, instruction.arg.clone()), // Math operations "add" => instructions::math::add(&mut stack.memory), diff --git a/src/instructions/stack_manage.rs b/src/instructions/stack_manage.rs index a9201cf..6fce61b 100644 --- a/src/instructions/stack_manage.rs +++ b/src/instructions/stack_manage.rs @@ -34,3 +34,11 @@ pub fn pick(memory: &mut StackVec, data: u16) { .expect(&format!("{}", RunError::PickOutOfBounds)), ); } + +pub fn string(memory: &mut StackVec, arg: String) { + for i in arg.chars() { + memory.push(i as u16); + } + + memory.push(arg.len() as u16); +} From 906a72a19516ff6b83e3200f9b1c7b432258ed44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?b=CA=B0edoh=E2=82=82=20sw=C3=A9?= Date: Mon, 17 Jun 2024 21:06:49 +0500 Subject: [PATCH 3/9] Add "call" --- src/execute.rs | 4 ++++ src/instructions/modules.rs | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/execute.rs b/src/execute.rs index 7564096..ba5e3d2 100644 --- a/src/execute.rs +++ b/src/execute.rs @@ -145,6 +145,10 @@ pub fn execute(stack: &mut Stack, mut origin_stack: Option<&mut Stack>, mod_name let arg = instruction.arg.clone(); instructions::modules::exec(stack, arg, mod_name.clone()) }, + "call" => { + let arg = instruction.arg.clone(); + instructions::modules::call(stack, arg) + }, "native" => { let arg = instruction.arg.clone(); instructions::native::native(stack, arg) diff --git a/src/instructions/modules.rs b/src/instructions/modules.rs index e869135..3611d4c 100644 --- a/src/instructions/modules.rs +++ b/src/instructions/modules.rs @@ -34,3 +34,27 @@ pub fn exec(mut stack: &mut Stack, arg: String, mod_name: String) { stack.memory.push(*item); } } + +pub fn call(mut stack: &mut Stack, mod_name: String) { + let len: u16 = stack.memory.pop(); + let mut rev: String = String::new(); + for _i in 0..len { + rev.push(stack.memory.pop() as u8 as char); + } + let tocall: String = rev.chars().rev().collect::(); + + if mod_name == tocall { + eprintln!("{}", RunError::ExecuteItself(tocall.to_string())); + std::process::exit(2); + } + + let lines = fs::read_to_string(&tocall).expect(&format!("{}", RunError::FailToReadFile)); + let mut temp_stack = Stack::new(stack.memory.size()); + + parse(&mut temp_stack, &lines); + execute(&mut temp_stack, Some(&mut stack), tocall.clone()); + + for item in temp_stack.memory.iter() { + stack.memory.push(*item); + } +} From b42d582badd18a1992d370f2eae49365357c61c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?b=CA=B0edoh=E2=82=82=20sw=C3=A9?= Date: Tue, 18 Jun 2024 04:00:53 +0500 Subject: [PATCH 4/9] Fix a compatability issue. --- src/parse.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/parse.rs b/src/parse.rs index 075fff7..6617ce3 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -47,7 +47,9 @@ pub fn parse(stack: &mut Stack, file_content: &str) { } } - let inst = Instruction { name, arg, data }; - stack.program.push(inst); + if name != "" { + let inst = Instruction { name, arg, data }; + stack.program.push(inst); + } } } From e174f3a885a93aa6004eed79f9bff43b06b47994 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?b=CA=B0edoh=E2=82=82=20sw=C3=A9?= Date: Tue, 18 Jun 2024 16:46:45 +0500 Subject: [PATCH 5/9] Fix the function signature in #native --- src/instructions/native.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/instructions/native.rs b/src/instructions/native.rs index 4bd4bbd..4b25462 100644 --- a/src/instructions/native.rs +++ b/src/instructions/native.rs @@ -41,8 +41,8 @@ pub fn native(stack: &mut Stack, arg: String) { unsafe { let module = Library::new([libpref, arg, libsuf].join("")).unwrap(); // C libraries should use - // int labashka(unsinged short (*pop)(), void (*push)(unsinged short), size_t (*len)(), size_t max_size ); - let func: Symbol u16, extern fn(u16) -> i32, extern fn () -> usize, usize) -> u32> = module.get(b"labashka").unwrap(); + // void (*labashka)(unsigned short (*pop)(void), void (*push)(unsigned short), size_t (*len)(void), size_t max_size); + let func: Symbol u16, extern fn(u16) -> i32, extern fn () -> usize, usize)> = module.get(b"labashka").unwrap(); func(stack_pop_callback,stack_push_callback,stack_len_callback, stack.memory.size()); } } From 7223b995a3a362098ec58be4338bcd8819231a65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?b=CA=B0edoh=E2=82=82=20sw=C3=A9?= Date: Tue, 18 Jun 2024 23:19:53 +0500 Subject: [PATCH 6/9] Fix function signature in test/native_test.rs --- test/native_test.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/native_test.rs b/test/native_test.rs index b6f7fc5..ac41f88 100644 --- a/test/native_test.rs +++ b/test/native_test.rs @@ -4,10 +4,9 @@ // rustc --crate-type cdylib native_test.rs -o native_test.dll #[no_mangle] -unsafe extern "C" fn labashka(pop: extern fn() -> u16, push: extern fn(u16) -> i32, len: extern fn () -> usize, max: usize) -> u32 { +unsafe extern "C" fn labashka(pop: extern fn() -> u16, push: extern fn(u16) -> i32, len: extern fn () -> usize, max: usize) { println!("At {}, there's {}.", len(), pop()); push(12); println!("Maximum size is {}.", max); - return 0; } From 751971576e753c9d7b84c6252b39577ed3fa495c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?b=CA=B0edoh=E2=82=82=20sw=C3=A9?= Date: Wed, 19 Jun 2024 02:45:16 +0500 Subject: [PATCH 7/9] Fix function signature in #native... --- src/instructions/native.rs | 2 +- test/native_test.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/instructions/native.rs b/src/instructions/native.rs index 4b25462..20e7c11 100644 --- a/src/instructions/native.rs +++ b/src/instructions/native.rs @@ -42,7 +42,7 @@ pub fn native(stack: &mut Stack, arg: String) { let module = Library::new([libpref, arg, libsuf].join("")).unwrap(); // C libraries should use // void (*labashka)(unsigned short (*pop)(void), void (*push)(unsigned short), size_t (*len)(void), size_t max_size); - let func: Symbol u16, extern fn(u16) -> i32, extern fn () -> usize, usize)> = module.get(b"labashka").unwrap(); + let func: Symbol u16, extern fn(u16), extern fn() -> usize, usize)> = module.get(b"labashka").unwrap(); func(stack_pop_callback,stack_push_callback,stack_len_callback, stack.memory.size()); } } diff --git a/test/native_test.rs b/test/native_test.rs index ac41f88..a6061d6 100644 --- a/test/native_test.rs +++ b/test/native_test.rs @@ -4,7 +4,7 @@ // rustc --crate-type cdylib native_test.rs -o native_test.dll #[no_mangle] -unsafe extern "C" fn labashka(pop: extern fn() -> u16, push: extern fn(u16) -> i32, len: extern fn () -> usize, max: usize) { +unsafe extern "C" fn labashka(pop: extern fn() -> u16, push: extern fn(u16), len: extern fn () -> usize, max: usize) { println!("At {}, there's {}.", len(), pop()); push(12); println!("Maximum size is {}.", max); From fb1207bae5adc490bf045c325a6a6bcc2e4f8826 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?b=CA=B0edoh=E2=82=82=20sw=C3=A9?= Date: Wed, 19 Jun 2024 23:45:59 +0500 Subject: [PATCH 8/9] Fix a compatability issue and a compilation error --- src/execute.rs | 20 ++++++++++++++------ src/instructions/native.rs | 3 +-- src/instructions/self_modify.rs | 2 ++ src/parse.rs | 2 +- src/stack.rs | 2 ++ 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/execute.rs b/src/execute.rs index ba5e3d2..83c3345 100644 --- a/src/execute.rs +++ b/src/execute.rs @@ -1,6 +1,6 @@ use crate::{ instructions, - stack::{Instruction, Stack, StackVec}, + stack::{Instruction, Stack}, }; fn find_labels(stack: &mut Stack) { @@ -28,18 +28,17 @@ fn find_labels(stack: &mut Stack) { stack.program_counter = stack.labels[0].unwrap_or(0) as u16; } -fn find_prefix_operators(instruction: &mut Instruction, memory: &mut StackVec) { +fn find_prefix_operators(instruction: &mut Instruction) { match instruction.name.chars().nth(0) { Some('|') => { instruction.name = instruction.name.chars().skip(1).collect(); - instruction.data = memory.pop(); + instruction.ispiped = true; } Some('/') => { instruction.name = instruction.name.chars().skip(1).collect(); - memory.push(instruction.data); - instruction.data = 0; + instruction.isdrained = true; } _ => {} } @@ -51,7 +50,16 @@ pub fn execute(stack: &mut Stack, mut origin_stack: Option<&mut Stack>, mod_name while let Some(mut instruction) = stack.program.get_mut(stack.program_counter as usize) { stack.program_counter += 1; - find_prefix_operators(&mut instruction, &mut stack.memory); + find_prefix_operators(&mut instruction); + + if instruction.ispiped { + instruction.data = stack.memory.pop(); + } + + if instruction.isdrained { + stack.memory.push(instruction.data); + instruction.data = 0; + } if instruction.name.chars().nth(0) == Some('#') || instruction.name.chars().nth(0) == Some('$') diff --git a/src/instructions/native.rs b/src/instructions/native.rs index 20e7c11..f295a01 100644 --- a/src/instructions/native.rs +++ b/src/instructions/native.rs @@ -11,11 +11,10 @@ extern fn stack_pop_callback() -> u16 { } #[no_mangle] -extern fn stack_push_callback(data: u16) -> i32 { +extern fn stack_push_callback(data: u16){ unsafe { (*STACKPTR).memory.push(data) }; - return 0; } #[no_mangle] diff --git a/src/instructions/self_modify.rs b/src/instructions/self_modify.rs index ec75b49..be8c31d 100644 --- a/src/instructions/self_modify.rs +++ b/src/instructions/self_modify.rs @@ -22,5 +22,7 @@ pub fn insert(program: &mut Vec, arg: String, data: u16) { name: arg.to_string(), arg: "\n".to_string(), data, + ispiped: false, + isdrained: false }); } diff --git a/src/parse.rs b/src/parse.rs index 6617ce3..deae48a 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -48,7 +48,7 @@ pub fn parse(stack: &mut Stack, file_content: &str) { } if name != "" { - let inst = Instruction { name, arg, data }; + let inst = Instruction { name, arg, data, ispiped: false, isdrained: false }; stack.program.push(inst); } } diff --git a/src/stack.rs b/src/stack.rs index 601be6b..ae371b5 100644 --- a/src/stack.rs +++ b/src/stack.rs @@ -7,6 +7,8 @@ pub struct Instruction { pub name: String, pub arg: String, pub data: u16, + pub ispiped: bool, + pub isdrained: bool } pub struct Stack { From f69354ec3161724c4c3661dd34734d0fec309fee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?b=CA=B0edoh=E2=82=82=20sw=C3=A9?= Date: Fri, 21 Jun 2024 01:36:33 +0500 Subject: [PATCH 9/9] Fix skill issues --- src/execute.rs | 2 +- src/instructions/modules.rs | 18 ++---------------- src/instructions/native.rs | 38 +++++++++++++------------------------ src/parse.rs | 2 +- 4 files changed, 17 insertions(+), 43 deletions(-) diff --git a/src/execute.rs b/src/execute.rs index 83c3345..a94355d 100644 --- a/src/execute.rs +++ b/src/execute.rs @@ -159,7 +159,7 @@ pub fn execute(stack: &mut Stack, mut origin_stack: Option<&mut Stack>, mod_name }, "native" => { let arg = instruction.arg.clone(); - instructions::native::native(stack, arg) + unsafe {instructions::native::native(stack, arg)} }, // Self-modifying diff --git a/src/instructions/modules.rs b/src/instructions/modules.rs index 3611d4c..26a207b 100644 --- a/src/instructions/modules.rs +++ b/src/instructions/modules.rs @@ -35,26 +35,12 @@ pub fn exec(mut stack: &mut Stack, arg: String, mod_name: String) { } } -pub fn call(mut stack: &mut Stack, mod_name: String) { +pub fn call(stack: &mut Stack, mod_name: String) { let len: u16 = stack.memory.pop(); let mut rev: String = String::new(); for _i in 0..len { rev.push(stack.memory.pop() as u8 as char); } let tocall: String = rev.chars().rev().collect::(); - - if mod_name == tocall { - eprintln!("{}", RunError::ExecuteItself(tocall.to_string())); - std::process::exit(2); - } - - let lines = fs::read_to_string(&tocall).expect(&format!("{}", RunError::FailToReadFile)); - let mut temp_stack = Stack::new(stack.memory.size()); - - parse(&mut temp_stack, &lines); - execute(&mut temp_stack, Some(&mut stack), tocall.clone()); - - for item in temp_stack.memory.iter() { - stack.memory.push(*item); - } + exec(stack, tocall, mod_name); } diff --git a/src/instructions/native.rs b/src/instructions/native.rs index f295a01..fa17612 100644 --- a/src/instructions/native.rs +++ b/src/instructions/native.rs @@ -4,46 +4,34 @@ use libloading::{Library, Symbol}; static mut STACKPTR: *mut Stack = 0 as *mut Stack; #[no_mangle] -extern fn stack_pop_callback() -> u16 { - return unsafe { - (*STACKPTR).memory.pop() - }; +unsafe extern fn stack_pop_callback() -> u16 { + (*STACKPTR).memory.pop() } #[no_mangle] -extern fn stack_push_callback(data: u16){ - unsafe { - (*STACKPTR).memory.push(data) - }; +unsafe extern fn stack_push_callback(data: u16) { + (*STACKPTR).memory.push(data) } #[no_mangle] -extern fn stack_len_callback() -> usize { - return unsafe{ - (*STACKPTR).memory.len() - }; +unsafe extern fn stack_len_callback() -> usize { + (*STACKPTR).memory.len() } -pub fn native(stack: &mut Stack, arg: String) { - unsafe { - STACKPTR = stack as *mut Stack; - } +pub unsafe fn native(stack: &mut Stack, arg: String) { + STACKPTR = stack as *mut Stack; #[cfg(not(target_family = "windows"))] let libsuf: String = ".so".to_owned(); #[cfg(target_family = "windows")] let libsuf: String = ".dll".to_owned(); - let libpref: String = "./".to_owned(); - - unsafe { - let module = Library::new([libpref, arg, libsuf].join("")).unwrap(); - // C libraries should use - // void (*labashka)(unsigned short (*pop)(void), void (*push)(unsigned short), size_t (*len)(void), size_t max_size); - let func: Symbol u16, extern fn(u16), extern fn() -> usize, usize)> = module.get(b"labashka").unwrap(); - func(stack_pop_callback,stack_push_callback,stack_len_callback, stack.memory.size()); - } + let module = Library::new(format!("./{}{}", arg, libsuf)).unwrap(); + // C libraries should use + // void (*labashka)(unsigned short (*pop)(void), void (*push)(unsigned short), size_t (*len)(void), size_t max_size); + let func: Symbol u16, unsafe extern fn(u16), unsafe extern fn() -> usize, usize)> = module.get(b"labashka").unwrap(); + func(stack_pop_callback,stack_push_callback,stack_len_callback, stack.memory.size()); } diff --git a/src/parse.rs b/src/parse.rs index deae48a..27bf731 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -47,7 +47,7 @@ pub fn parse(stack: &mut Stack, file_content: &str) { } } - if name != "" { + if name.is_empty() { let inst = Instruction { name, arg, data, ispiped: false, isdrained: false }; stack.program.push(inst); }