-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 移除litr的sym, 将其设定为原生模块, 类型名为Symbol
- Loading branch information
Showing
10 changed files
with
55 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
mod D:\code\rs\tst\target\debug\tstlib.dll> m; | ||
|
||
// 直接调用模块上的公共函数 | ||
let a = m-.new(); | ||
a.test(); // 打印: | ||
let s = "芙 | ||
卡 | ||
洛 | ||
斯"; | ||
for c: s.lines() { | ||
log(c) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,34 @@ | ||
use crate::{ | ||
runtime::{calc::CalcRef, Scope}, | ||
primitive::litr::Litr, | ||
intern::{Interned, intern}, | ||
native::NativeFn | ||
intern::{intern, Interned}, native::{NativeClassDef, NativeFn, NativeInstance}, primitive::litr::Litr, runtime::{calc::CalcRef, Scope} | ||
}; | ||
|
||
#[derive(Debug, Clone, PartialEq, PartialOrd)] | ||
pub enum Symbol { | ||
IterEnd, | ||
Reserved | ||
} | ||
pub const ITER_END:usize = 1; | ||
|
||
static mut SYMBOL_CLASS: *mut NativeClassDef = std::ptr::null_mut(); | ||
|
||
pub fn statics()-> Vec<(Interned, NativeFn)> { | ||
vec![ | ||
(intern(b"iter_end"), s_iter_end) | ||
] | ||
pub fn init()-> (Interned, *mut NativeClassDef) { | ||
unsafe { | ||
let s = super::new_static_class(b"Sym", | ||
vec![ | ||
(intern(b"iter_end"), |_,_|iter_end()) | ||
] | ||
); | ||
SYMBOL_CLASS = s.1; | ||
s | ||
} | ||
} | ||
|
||
fn s_iter_end(_:Vec<CalcRef>, _cx:Scope)-> Litr { | ||
Litr::Sym(Symbol::IterEnd) | ||
pub fn is_sym(v:&NativeInstance)-> bool { | ||
unsafe {v.cls == SYMBOL_CLASS} | ||
} | ||
pub fn iter_end()-> Litr { | ||
unsafe{Litr::Ninst(NativeInstance {v: 1, w:0, cls: SYMBOL_CLASS})} | ||
} | ||
|
||
pub fn to_str(s:&Symbol)-> String { | ||
let t = match s { | ||
Symbol::IterEnd=> "迭代结束", | ||
Symbol::Reserved=> "未使用" | ||
pub fn to_str(s:&NativeInstance)-> String { | ||
let t = match s.v { | ||
ITER_END=> "迭代结束", | ||
_=> "未知" | ||
}; | ||
format!("Sym {{ {} }}", t) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters