From ee62bcd2df55ac3d7535a44c66931228fd06850c Mon Sep 17 00:00:00 2001 From: ludverse <62475903+ludverse@users.noreply.github.com> Date: Sat, 24 Feb 2024 17:32:51 +0100 Subject: [PATCH] added a shitty way of separating std and source file --- example.ox | 1 + fizzbuzz.ox | 35 +---------------------------------- src/main.rs | 33 +++++++++++++++++++++++++-------- std.ox | 27 +++++++++++++++------------ 4 files changed, 42 insertions(+), 54 deletions(-) diff --git a/example.ox b/example.ox index e69de29..3315156 100644 --- a/example.ox +++ b/example.ox @@ -0,0 +1 @@ +print(to_string(4)); diff --git a/fizzbuzz.ox b/fizzbuzz.ox index 9c721e9..2631ae0 100644 --- a/fizzbuzz.ox +++ b/fizzbuzz.ox @@ -1,34 +1 @@ -let char_pos_out = 0; -fn char_pos(c: String) { - if c == "0" { char_pos_out = 0; }; - if c == "1" { char_pos_out = 1; }; - if c == "2" { char_pos_out = 2; }; - if c == "3" { char_pos_out = 3; }; - if c == "4" { char_pos_out = 4; }; - if c == "5" { char_pos_out = 5; }; - if c == "6" { char_pos_out = 6; }; - if c == "7" { char_pos_out = 7; }; - if c == "8" { char_pos_out = 8; }; - if c == "9" { char_pos_out = 9; }; -} - -let mut cmp_out = true; -fn cmp(a: String, b: String) { - char_pos(a); - let a_pos = char_pos_out; - - char_pos(a); - let b_pos = char_pos_out; - - -} - -let mut sort_out = ""; -fn sort(inp: String, len: Number) { - for i in 0..len { - sort_out = index_out; - } -} - -sort("51823", 5); -print(sort_out); +let GG = "EYESS"; diff --git a/src/main.rs b/src/main.rs index 8cdeab9..a3fb1ae 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,20 +12,37 @@ fn main() -> ExitCode { let mut args = env::args(); let config = Config::new(&mut args); - let buf = fs::read_to_string(config.source_file).expect("failed to read source file"); + let std_buf = fs::read_to_string("std.ox") + .expect("failed to read std file"); + let std_buf = std_buf.trim(); + + let buf = fs::read_to_string(config.source_file.to_string()) + .expect("failed to read source file"); let buf = buf.trim(); + let std_tokens = tokenize(&String::from("std"), std_buf); let tokens = tokenize(&String::from("main"), buf); - dbg!(&tokens); - let collector = TokenCollector::new(&tokens); - let mut parser = Parser::new(collector); - let program = parser.generate_program(); + let files_tokens = vec![std_tokens, tokens]; + + let mut sim_memory = None; + let mut memory = None; + for tokens in files_tokens { + let collector = TokenCollector::new(&tokens); + + let mut parser = Parser::new(collector); + if let Some(sim_memory) = sim_memory { parser.sim_memory = sim_memory } + let program = parser.generate_program(); + + // dbg!(&program); - dbg!(&program); + let mut interpreter = Interpreter::new(program); + if let Some(memory) = memory { interpreter.memory = memory } + interpreter.run(); - let mut interpreter = Interpreter::new(program); - interpreter.run(); + sim_memory = Some(parser.sim_memory); + memory = Some(interpreter.memory); + } 0.into() } diff --git a/std.ox b/std.ox index e59626b..97a963b 100644 --- a/std.ox +++ b/std.ox @@ -1,8 +1,7 @@ let LOOK_LEN = 9; -let mut out = ""; fn to_string(x: Number) { - out = ""; + let mut res = ""; for i in 0..LOOK_LEN { let i = LOOK_LEN - 1 - i; @@ -18,15 +17,19 @@ fn to_string(x: Number) { let d_from_floor = num % 1; let floored = num - d_from_floor; - if floored == 0 { out += "0"; }; - if floored == 1 { out += "1"; }; - if floored == 2 { out += "2"; }; - if floored == 3 { out += "3"; }; - if floored == 4 { out += "4"; }; - if floored == 5 { out += "5"; }; - if floored == 6 { out += "6"; }; - if floored == 7 { out += "7"; }; - if floored == 8 { out += "8"; }; - if floored == 9 { out += "9"; }; + if floored == 0 { res += "0"; }; + if floored == 1 { res += "1"; }; + if floored == 2 { res += "2"; }; + if floored == 3 { res += "3"; }; + if floored == 4 { res += "4"; }; + if floored == 5 { res += "5"; }; + if floored == 6 { res += "6"; }; + if floored == 7 { res += "7"; }; + if floored == 8 { res += "8"; }; + if floored == 9 { res += "9"; }; } + + res; } + +print("hi");