diff --git a/SLS_Rust/sls/src/builtin.rs b/SLS_Rust/sls/src/builtin.rs index e69de29..5a2fed6 100644 --- a/SLS_Rust/sls/src/builtin.rs +++ b/SLS_Rust/sls/src/builtin.rs @@ -0,0 +1,5 @@ +use crate::interpreter::InterpreterState; + +pub fn load_builtins(_state: &mut InterpreterState) -> bool { + false +} diff --git a/SLS_Rust/sls/src/file.rs b/SLS_Rust/sls/src/file.rs index 0d306eb..4b016fd 100644 --- a/SLS_Rust/sls/src/file.rs +++ b/SLS_Rust/sls/src/file.rs @@ -14,7 +14,7 @@ pub fn exec_file(interpreter: &mut InterpreterState, filename: &str) -> bool { } }; - let mut lexer_info = LexerInfo::new(filename.clone(), source.clone()); + let mut lexer_info = LexerInfo::new(filename, source.clone()); let result = lexical_analysis(&mut lexer_info); @@ -40,6 +40,9 @@ pub fn run_file(filename: &str) -> i32 { println!("Executing file: {}", filename); let mut interpreter = InterpreterState::new(); + if !interpreter.init() { + return 1; + } if exec_file(&mut interpreter, filename) { 0 diff --git a/SLS_Rust/sls/src/interpreter.rs b/SLS_Rust/sls/src/interpreter.rs index bdafc86..ae4ee2d 100644 --- a/SLS_Rust/sls/src/interpreter.rs +++ b/SLS_Rust/sls/src/interpreter.rs @@ -1,6 +1,7 @@ use std::collections::HashMap; use crate::lexer::*; // Identifier, Token, TokenString, etc. +use crate::builtin::load_builtins; pub type BuiltinFn = fn(&mut InterpreterState) -> bool; @@ -49,6 +50,10 @@ impl InterpreterState { } } + pub fn init(&mut self) -> bool { + load_builtins(self) + } + pub fn push_token(&mut self, token: Token) -> bool { let value = match token { Token::Eof => return true, @@ -127,15 +132,3 @@ impl InterpreterState { self.stack.get(self.stack.len() - 1) } } - -pub fn interpreter_create(load_builtins: fn(&mut InterpreterState) -> bool) - -> Option -{ - let mut state = InterpreterState::new(); - - if !load_builtins(&mut state) { - return None; - } - - Some(state) -} diff --git a/SLS_Rust/sls/src/lexer.rs b/SLS_Rust/sls/src/lexer.rs index 0e0ae86..8b6df6f 100644 --- a/SLS_Rust/sls/src/lexer.rs +++ b/SLS_Rust/sls/src/lexer.rs @@ -68,29 +68,29 @@ pub struct Identifier { #[derive(Debug, Clone)] pub enum ArrayLiteral { - Identifiers(Vec), - I64(Vec), - I32(Vec), - I16(Vec), - I8(Vec), - U64(Vec), - U32(Vec), - U16(Vec), - U8(Vec), - Float(Vec), - Double(Vec), - Character(Vec), - Strings(Vec), - Boolean(Vec), - TokenStrings(Vec), - TypeTuples(Vec), - StructInline(StructInline), + _Identifiers(Vec), + _I64(Vec), + _I32(Vec), + _I16(Vec), + _I8(Vec), + _U64(Vec), + _U32(Vec), + _U16(Vec), + _U8(Vec), + _Float(Vec), + _Double(Vec), + _Character(Vec), + _Strings(Vec), + _Boolean(Vec), + _TokenStrings(Vec), + _TypeTuples(Vec), + _StructInline(StructInline), } #[derive(Debug, Clone)] pub struct ShapedArray { - pub array: ArrayLiteral, - pub shape: Vec, + pub _array: ArrayLiteral, + pub _shape: Vec, } #[derive(Debug, Clone)] @@ -100,25 +100,25 @@ pub struct TokenString { #[derive(Debug, Clone)] pub struct TypeTuple { - pub inputs: Vec, - pub outputs: Vec, + pub _inputs: Vec, + pub _outputs: Vec, } #[derive(Debug, Clone)] pub struct StructInline { - pub name: String, - pub values: Vec, + pub _name: String, + pub _values: Vec, } #[derive(Debug, Clone)] pub enum StructValue { - Integer(i64), - Float(f32), - Double(f64), - Boolean(bool), - Character(u8), - String(String), - Token(Token), + _Integer(i64), + _Float(f32), + _Double(f64), + _Boolean(bool), + _Character(u8), + _String(String), + _Token(Token), } #[derive(Debug, Clone)] @@ -190,7 +190,7 @@ impl LexerInfo { !c.is_ascii_digit() && self.is_identifier_continue(c) } - fn parse_identifiers_and_booleans(&mut self, start: usize, start_line: usize, start_col: usize) -> LexResult { + fn parse_identifiers_and_booleans(&mut self, _start: usize, start_line: usize, start_col: usize) -> LexResult { let mut c = self.peek(); let mut literal = false; @@ -259,7 +259,7 @@ impl LexerInfo { Ok(Token::Character(value)) } - fn parse_token_string(&mut self, start: usize, start_line: usize, start_col: usize) -> LexResult { + fn parse_token_string(&mut self, _start: usize, start_line: usize, start_col: usize) -> LexResult { let mut tokens = Vec::new(); self.advance(); // skip '{' @@ -399,7 +399,7 @@ impl LexerInfo { let mut is_float = false; let mut is_unsigned = false; - let mut bit_size = 64; // default + let bit_size: u32; if c == 'f' { is_float = true; diff --git a/SLS_Rust/sls/src/main.rs b/SLS_Rust/sls/src/main.rs index 8f942ce..f7a871a 100644 --- a/SLS_Rust/sls/src/main.rs +++ b/SLS_Rust/sls/src/main.rs @@ -14,11 +14,6 @@ use repl::repl; const SLS_NAME: &str = "SLS_RUST"; const SLS_VER: &str = "a.0.0"; -// Environment variables set via build.rs for commit hash / compiler. -const GIT_COMMIT_HASH: &str = env!("GIT_COMMIT_HASH", "UNKNOWN"); -const COMPILER_NAME: &str = env!("COMPILER_NAME", "Unknown"); -const COMPILER_VER: &str = env!("COMPILER_VER", "0"); - pub fn print_version() { let git_hash = option_env!("GIT_COMMIT_HASH").unwrap_or("unknown"); let compiler = option_env!("COMPILER_NAME").unwrap_or("rustc"); @@ -26,7 +21,7 @@ pub fn print_version() { let build_date = std::env::var("BUILD_DATE").unwrap_or_else(|_| "unknown".into()); let build_time = std::env::var("BUILD_TIME").unwrap_or_else(|_| "unknown".into()); - println!("YREA SLS (SLS_RUST) a.0.0 ({git_hash})"); + println!("YREA SLS ({SLS_NAME}) {SLS_VER} ({git_hash})"); println!("Compiled with {compiler} {compiler_ver} at {build_date} {build_time}"); } diff --git a/SLS_Rust/sls/src/repl.rs b/SLS_Rust/sls/src/repl.rs index dd0718a..c78b658 100644 --- a/SLS_Rust/sls/src/repl.rs +++ b/SLS_Rust/sls/src/repl.rs @@ -44,6 +44,9 @@ pub fn repl() -> i32 { io::stdout().flush().unwrap(); let mut interpreter = InterpreterState::new(); + if !interpreter.init() { + return 1; + } let stdin = io::stdin(); let mut buf = String::new();