idk, i refactored some stuff ig
This commit is contained in:
+28
-33
@@ -1,34 +1,29 @@
|
||||
++++++++++++++++++++++++++++++++++++++++++++ c1v44 : ASCII code of comma
|
||||
>++++++++++++++++++++++++++++++++ c2v32 : ASCII code of space
|
||||
>++++++++++++++++ c3v11 : quantity of numbers to be calculated
|
||||
> c4v0 : zeroth Fibonacci number (will not be printed)
|
||||
>+ c5v1 : first Fibonacci number
|
||||
<< c3 : loop counter
|
||||
[ block : loop to print (i)th number and calculate next one
|
||||
>> c5 : the number to be printed
|
||||
|
||||
block : divide c5 by 10 (preserve c5)
|
||||
> c6v0 : service zero
|
||||
>++++++++++ c7v10 : divisor
|
||||
<< c5 : back to dividend
|
||||
[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<] c5v0 : divmod algo; results in 0 n d_n%d n%d n/d
|
||||
>[<+>-] c5 : move dividend back to c5 and clear c6
|
||||
>[-] c7v0 : clear c7
|
||||
|
||||
>> block : c9 can have two digits; divide it by ten again
|
||||
>++++++++++ c10v10: divisor
|
||||
< c9 : back to dividend
|
||||
[->-[>+>>]>[+[-<+>]>+>>]<<<<<] c9v0 : another divmod algo; results in 0 d_n%d n%d n/d
|
||||
>[-] c10v0 : clear c10
|
||||
>>[++++++++++++++++++++++++++++++++++++++++++++++++.[-]]c12v0 : print nonzero n/d (first digit) and clear c12
|
||||
<[++++++++++++++++++++++++++++++++++++++++++++++++.[-]] c11v0 : print nonzero n%d (second digit) and clear c11
|
||||
|
||||
<<<++++++++++++++++++++++++++++++++++++++++++++++++.[-] c8v0 : print any n%d (last digit) and clear c8
|
||||
<<<<<<<.>. c1c2 : print comma and space
|
||||
block : actually calculate next Fibonacci in c6
|
||||
>>[>>+<<-] c4v0 : move c4 to c6 (don't need to preserve it)
|
||||
>[>+<<+>-] c5v0 : move c5 to c6 and c4 (need to preserve it)
|
||||
>[<+>-] c6v0 : move c6 with sum to c5
|
||||
<<<- c3 : decrement loop counter
|
||||
++++++++++++++++++++++++++++++++++++++++++++
|
||||
>++++++++++++++++++++++++++++++++
|
||||
>++++++++++++++++
|
||||
>
|
||||
>+
|
||||
<<
|
||||
[
|
||||
>>
|
||||
>
|
||||
>++++++++++
|
||||
<<
|
||||
[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]
|
||||
>[<+>-]
|
||||
>[-]
|
||||
>>
|
||||
>++++++++++
|
||||
<
|
||||
[->-[>+>>]>[+[-<+>]>+>>]<<<<<]
|
||||
>[-]
|
||||
>>[++++++++++++++++++++++++++++++++++++++++++++++++.[-]]
|
||||
<[++++++++++++++++++++++++++++++++++++++++++++++++.[-]]
|
||||
<<<++++++++++++++++++++++++++++++++++++++++++++++++.[-]
|
||||
<<<<<<<.>.
|
||||
>>[>>+<<-]
|
||||
>[>+<<+>-]
|
||||
>[<+>-]
|
||||
<<<-
|
||||
]
|
||||
<<++... c1 : output three dots
|
||||
<<++...
|
||||
|
||||
@@ -12,7 +12,7 @@ pub fn lexer(mut program: String, module: u64) -> Result<Vec<Token>, AssembleErr
|
||||
let mut literal = String::new();
|
||||
|
||||
for line in lines {
|
||||
for token in line.split_whitespace() {
|
||||
for (i, token) in line.split_whitespace().enumerate() {
|
||||
if token.starts_with("//") {
|
||||
break;
|
||||
}
|
||||
@@ -23,7 +23,9 @@ pub fn lexer(mut program: String, module: u64) -> Result<Vec<Token>, AssembleErr
|
||||
|
||||
if !literal.is_empty() {
|
||||
if !token.starts_with('"') {
|
||||
literal.push(' ');
|
||||
if i > 0 {
|
||||
literal.push(' ');
|
||||
}
|
||||
literal.push_str(token);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,11 +13,13 @@
|
||||
)]
|
||||
|
||||
pub mod assembler;
|
||||
pub mod brainf;
|
||||
pub mod image_builder;
|
||||
pub mod tooling;
|
||||
mod util;
|
||||
|
||||
pub mod prelude {
|
||||
pub use crate::assembler::CompilerEngine;
|
||||
pub use crate::image_builder;
|
||||
pub use crate::tooling::brainf;
|
||||
pub use crate::tooling::project;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
use assembler::{brainf, prelude::*};
|
||||
use assembler::{
|
||||
prelude::*,
|
||||
tooling::{brainf, project},
|
||||
};
|
||||
use std::{fs, io::Write, path::PathBuf};
|
||||
|
||||
fn main() {
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
pub mod brainf;
|
||||
pub mod project;
|
||||
|
||||
Reference in New Issue
Block a user