Skip to content

Commit

Permalink
added a shitty way of separating std and source file
Browse files Browse the repository at this point in the history
  • Loading branch information
ludverse committed Feb 24, 2024
1 parent 2187716 commit ee62bcd
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 54 deletions.
1 change: 1 addition & 0 deletions example.ox
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print(to_string(4));
35 changes: 1 addition & 34 deletions fizzbuzz.ox
Original file line number Diff line number Diff line change
@@ -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";
33 changes: 25 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
27 changes: 15 additions & 12 deletions std.ox
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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");

0 comments on commit ee62bcd

Please sign in to comment.