-
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
6 changed files
with
44 additions
and
11 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
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,10 +1,42 @@ | ||
use crate::{ | ||
intern::{intern, Interned}, | ||
native::NativeFn, | ||
runtime::calc::CalcRef, | ||
scan::literal::Litr | ||
runtime::{calc::CalcRef, err, Scope}, | ||
scan::{literal::{ArgDecl, Function, KsType, Litr, LocalFunc, LocalFuncRaw}, stmt::Statements} | ||
}; | ||
|
||
fn s_new(s:Vec<CalcRef>)-> Litr { | ||
Litr::Bool(false) | ||
pub fn statics()-> Vec<(Interned, NativeFn)> { | ||
vec![ | ||
(intern(b"new"), s_new) | ||
] | ||
} | ||
|
||
fn s_new(s:Vec<CalcRef>, cx:Scope)-> Litr { | ||
let mut itr = s.into_iter(); | ||
let arg1 = itr.next(); | ||
let stmts = match &arg1 { | ||
Some(arg)=> crate::scan::scan(match &**arg { | ||
Litr::Str(s)=> s.as_bytes(), | ||
Litr::Buf(b)=> b, | ||
_=> err!("Func::new第一个参数必须是Str或Buf, 用来被解析为函数体") | ||
}), | ||
None=> Statements(Vec::new()) | ||
}; | ||
|
||
let arg2 = itr.next(); | ||
let argdecl = match &arg2 { | ||
Some(arg)=> match &**arg { | ||
Litr::List(v)=> | ||
v.iter().map(|v|match v { | ||
Litr::Str(s)=> ArgDecl {default: Litr::Uninit, name: intern(s.as_bytes()), t:KsType::Any}, | ||
_=> ArgDecl {default: Litr::Uninit, name: intern(b"#ignored"), t:KsType::Any} | ||
}).collect(), | ||
_=> err!("Func::new第二个参数必须是Str组成的List, 用来定义该函数的参数名") | ||
}, | ||
None=> Vec::new() | ||
}; | ||
|
||
Litr::Func(Function::Local(LocalFunc::new(Box::into_raw(Box::new( | ||
LocalFuncRaw {argdecl, stmts} | ||
)),cx))) | ||
} |
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