diff --git a/src/lexer.rs b/src/lexer.rs index 80091bf..b285f37 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -11,15 +11,19 @@ pub fn lex(input: String, filename: String) -> Words { fn read_block(str_words: &[String], isfn: bool, origin: &FrameInfo) -> (Option, Words, usize) { let mut rem = None; - if str_words[0] == "{" && isfn { - let mut r = 0_u32; - while str_words[r as usize + 1] != "|" { - r += 1; - } - rem = Some(r); - } let mut words = Vec::new(); let mut i = 0; + if str_words[0] == "{" { + if isfn { + let mut r = 0_u32; + while str_words[r as usize + 1] != "|" { + r += 1; + } + i += r as usize + 1; + rem = Some(r); + } + i += 1; + } while i < str_words.len() { let word = str_words[i].to_owned(); match word.as_str() { @@ -118,6 +122,9 @@ fn read_block(str_words: &[String], isfn: bool, origin: &FrameInfo) -> (Option { break; } + x if x.starts_with("\"") => { + words.push(Word::Const(Constant::Str(x[1..].to_owned()))); + } mut x => { let mut ra = 0; while x.starts_with("&") { @@ -158,17 +165,15 @@ fn parse_line(line: &str) -> Vec { if escaping { if c == '\\' { s += "\\"; - continue; } if c == 'n' { s += "\n"; - continue; } if c == 'r' { s += "\r"; - continue; } escaping = false; + continue; } else if c == '"' { in_string = false; escaping = false; @@ -176,9 +181,11 @@ fn parse_line(line: &str) -> Vec { } if c == '\\' { escaping = true; + continue; } } else { if c == '"' { + s += "\""; in_string = true; continue; } @@ -193,5 +200,8 @@ fn parse_line(line: &str) -> Vec { } s += String::from(c).as_str(); } + if s != "" { + words.push(s); + } words } diff --git a/src/main.rs b/src/main.rs index 05e87a9..f449d7e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use spl::runtime::*; +use spl::{lexer::lex, runtime::*}; use std::{ io::{stdout, Write}, @@ -49,5 +49,6 @@ fn main() { ], } .exec(&mut stack); + lex("func println { | print \"\\n\" print } def helloworld \"Hello, World\" =helloworld helloworld println".to_owned(), "TEST".to_owned()).exec(&mut stack); Runtime::reset(); } diff --git a/src/runtime.rs b/src/runtime.rs index c31e3a9..9b08665 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -35,6 +35,8 @@ impl Runtime { rt.make_type("int".to_owned(), |t| t); rt.make_type("long".to_owned(), |t| t); rt.make_type("mega".to_owned(), |t| t); + rt.make_type("float".to_owned(), |t| t); + rt.make_type("double".to_owned(), |t| t); rt.make_type("func".to_owned(), |t| t); rt.make_type("array".to_owned(), |t| t); rt.make_type("str".to_owned(), |t| t); @@ -260,7 +262,7 @@ impl Stack { } } -#[derive(Clone)] +#[derive(Clone, Debug)] pub enum Keyword { /// /// @@ -316,11 +318,13 @@ pub enum Constant { Int(i32), Long(i64), Mega(i128), + Float(f32), + Double(f64), Func(AFunc), Str(String), } -#[derive(Clone)] +#[derive(Clone, Debug)] pub enum Word { Key(Keyword), Const(Constant), @@ -328,7 +332,7 @@ pub enum Word { ObjCall(String, bool, u32), } -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct Words { pub words: Vec, } @@ -433,6 +437,8 @@ impl Object { Constant::Int(x) => x > &0, Constant::Long(x) => x > &0, Constant::Mega(x) => x > &0, + Constant::Float(_) => true, + Constant::Double(_) => true, Constant::Func(_) => true, Constant::Str(x) => x == "", } @@ -450,9 +456,11 @@ impl From for Object { Constant::Int(_) => x.get_type_by_id(1), Constant::Long(_) => x.get_type_by_id(2), Constant::Mega(_) => x.get_type_by_id(3), - Constant::Func(_) => x.get_type_by_id(4), - // array is 5 - Constant::Str(_) => x.get_type_by_id(6), + Constant::Float(_) => x.get_type_by_id(4), + Constant::Double(_) => x.get_type_by_id(5), + Constant::Func(_) => x.get_type_by_id(6), + // array is 7 + Constant::Str(_) => x.get_type_by_id(8), } .expect("runtime uninitialized: default types not set.") }),