-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
221 additions
and
56 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,9 +1,4 @@ | ||
|
||
// mod D:\code\rs\key-native\target\debug\key_native.dll> m | ||
mod D:\code\rs\key-native\target\debug\key_native.dll> m | ||
|
||
let a=0 | ||
for(a<5) { | ||
a+=1; | ||
log(a) | ||
if a>3 break | ||
} | ||
log(Sym::iter_end()) |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Symbol | ||
|
||
Sym类型是为了Key解释器添加新功能所留下的退路, 是基本类型. 目前Sym只有一种:let sym = Sym::iter_end(), 用来在.@next()定义中告知迭代结束. |
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
Empty file.
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use std::cell::UnsafeCell; | ||
|
||
use crate::scan::literal::Litr; | ||
|
||
|
||
pub struct LitrIterator<'a> { | ||
pub v: &'a Litr, | ||
pub n: usize | ||
} | ||
impl<'a> LitrIterator<'a> { | ||
pub fn new(v:&'a Litr)-> Self { | ||
LitrIterator { v, n: 0 } | ||
} | ||
} | ||
|
||
impl Iterator for LitrIterator<'_> { | ||
type Item = Litr; | ||
fn next(&mut self) -> Option<Self::Item> { | ||
match self.v { | ||
Litr::Str(s)=>unsafe{s.get_unchecked(self.n..).chars().next().map(|c|{ | ||
let s = String::from(c); | ||
self.n += s.len(); | ||
Litr::Str(s)} | ||
)} | ||
Litr::Buffer(v)=> { | ||
let v = v.get(self.n).map(|n|Litr::Uint((*n) as usize)); | ||
self.n += 1; | ||
v | ||
} | ||
Litr::Uint(n)=> if self.n < *n { | ||
let v = Some(Litr::Uint(self.n)); | ||
self.n += 1; | ||
v | ||
}else {None} | ||
Litr::Int(n)=> if (self.n as isize) < *n { | ||
let v = Some(Litr::Int(self.n as isize)); | ||
self.n += 1; | ||
v | ||
}else {None} | ||
Litr::List(v)=> { | ||
let v = v.get(self.n).cloned(); | ||
self.n += 1; | ||
v | ||
} | ||
Litr::Bool(_)=> panic!("Bool无法迭代"), | ||
Litr::Float(_)=> panic!("Float无法迭代"), | ||
Litr::Func(_)=> panic!("Func无法迭代"), | ||
Litr::Inst(_)=> panic!("Inst?"), | ||
Litr::Ninst(_)=> panic!("Native Inst?"), | ||
Litr::Uninit=> panic!("uninit作为迭代器要判死刑的"), | ||
Litr::Obj(_)=> panic!("Obj是无序的,难以迭代"), | ||
Litr::Sym(_)=> panic!("Sym无法迭代") | ||
} | ||
} | ||
} | ||
|
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use crate::{ | ||
runtime::calc::CalcRef, | ||
scan::literal::Litr, | ||
intern::{Interned, intern}, | ||
native::NativeFn | ||
}; | ||
|
||
#[derive(Debug, Clone)] | ||
pub enum Symbol { | ||
IterEnd | ||
} | ||
|
||
|
||
pub fn statics()-> Vec<(Interned, NativeFn)> { | ||
vec![ | ||
(intern(b"iter_end"), s_iter_end) | ||
] | ||
} | ||
|
||
fn s_iter_end(_:Vec<CalcRef>)-> Litr { | ||
Litr::Sym(Symbol::IterEnd) | ||
} |
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