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