Claude builtin implementation
This commit is contained in:
parent
3a054bc211
commit
e76287b9a4
|
|
@ -1,9 +1,11 @@
|
|||
[package]
|
||||
name = "sls"
|
||||
version = "0.1.0"
|
||||
version = "0.0.1-alpha"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
bitflags = "2.4"
|
||||
rand = "0.8"
|
||||
|
||||
[build-dependencies]
|
||||
rustc_version = "0.4"
|
||||
|
|
|
|||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
|
|
@ -21,7 +21,7 @@ pub fn exec_file(interpreter: &mut InterpreterState, filename: &str) -> bool {
|
|||
match result {
|
||||
LexResult::Ok(tokens) => {
|
||||
for token in tokens {
|
||||
if !interpreter.execute(token) {
|
||||
if !interpreter.execute(&token) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ pub enum StackValue {
|
|||
|
||||
TokenString(TokenString),
|
||||
|
||||
Callable(FunctionItem),
|
||||
Callable(TokenString),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
@ -54,31 +54,31 @@ impl InterpreterState {
|
|||
load_builtins(self)
|
||||
}
|
||||
|
||||
pub fn push_token(&mut self, token: Token) -> bool {
|
||||
pub fn push_token(&mut self, token: &Token) -> bool {
|
||||
let value = match token {
|
||||
Token::Eof => return true,
|
||||
|
||||
Token::Identifier(id) => {
|
||||
StackValue::Identifier(id)
|
||||
StackValue::Identifier(id.clone())
|
||||
}
|
||||
|
||||
Token::I64(v) => StackValue::I64(v),
|
||||
Token::I32(v) => StackValue::I32(v),
|
||||
Token::I16(v) => StackValue::I16(v),
|
||||
Token::I8(v) => StackValue::I8(v),
|
||||
Token::I64(v) => StackValue::I64(*v),
|
||||
Token::I32(v) => StackValue::I32(*v),
|
||||
Token::I16(v) => StackValue::I16(*v),
|
||||
Token::I8(v) => StackValue::I8(*v),
|
||||
|
||||
Token::U64(v) => StackValue::U64(v),
|
||||
Token::U32(v) => StackValue::U32(v),
|
||||
Token::U16(v) => StackValue::U16(v),
|
||||
Token::U8(v) => StackValue::U8(v),
|
||||
Token::U64(v) => StackValue::U64(*v),
|
||||
Token::U32(v) => StackValue::U32(*v),
|
||||
Token::U16(v) => StackValue::U16(*v),
|
||||
Token::U8(v) => StackValue::U8(*v),
|
||||
|
||||
Token::Float(v) => StackValue::F32(v),
|
||||
Token::Double(v) => StackValue::F64(v),
|
||||
Token::Float(v) => StackValue::F32(*v),
|
||||
Token::Double(v) => StackValue::F64(*v),
|
||||
|
||||
Token::Character(c) => StackValue::Character(c),
|
||||
Token::Boolean(b) => StackValue::Boolean(b),
|
||||
Token::Character(c) => StackValue::Character(*c),
|
||||
Token::Boolean(b) => StackValue::Boolean(*b),
|
||||
|
||||
Token::TokenString(ts) => StackValue::TokenString(ts),
|
||||
Token::TokenString(ts) => StackValue::TokenString(ts.clone()),
|
||||
|
||||
Token::StringLiteral(_) |
|
||||
Token::Array(_) |
|
||||
|
|
@ -97,12 +97,12 @@ impl InterpreterState {
|
|||
|
||||
match item {
|
||||
FunctionItem::Builtin(f) => f(self),
|
||||
FunctionItem::TokenString(ts) => self.execute_token_string(ts),
|
||||
FunctionItem::TokenString(ts) => self.execute_token_string(&ts),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn execute_token_string(&mut self, ts: TokenString) -> bool {
|
||||
for token in ts.tokens {
|
||||
pub fn execute_token_string(&mut self, ts: &TokenString) -> bool {
|
||||
for token in &ts.tokens {
|
||||
if let Token::Identifier(id) = &token {
|
||||
if !id.is_literal {
|
||||
if !self.execute_func(&id.name) {
|
||||
|
|
@ -112,14 +112,14 @@ impl InterpreterState {
|
|||
}
|
||||
}
|
||||
|
||||
if !self.push_token(token) {
|
||||
if !self.push_token(&token) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
pub fn execute(&mut self, token: Token) -> bool {
|
||||
pub fn execute(&mut self, token: &Token) -> bool {
|
||||
match token {
|
||||
Token::Identifier(id) if !id.is_literal => {
|
||||
self.execute_func(&id.name)
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ pub fn repl() -> i32 {
|
|||
match result {
|
||||
LexResult::Ok(tokens) => {
|
||||
for token in tokens {
|
||||
if !interpreter.execute(token) {
|
||||
if !interpreter.execute(&token) {
|
||||
println!("A runtime error occured!");
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue