mindustry logic execution, map- and schematic- parsing and rendering
-rw-r--r--lemu/src/lib.rs1
-rw-r--r--lemu/src/memory.rs4
-rw-r--r--lemu/src/primes.mlog21
3 files changed, 24 insertions, 2 deletions
diff --git a/lemu/src/lib.rs b/lemu/src/lib.rs
index 47ae3f0..8a46264 100644
--- a/lemu/src/lib.rs
+++ b/lemu/src/lib.rs
@@ -174,6 +174,7 @@ mod test {
}
test!(run fib.mlog; output = b"12586269025");
+ test!(run primes.mlog; output = b"2 | 3 | 5 | 7 | 11 | 13 | 17 | 19 | 23 | 29 | 31 | 37 | 41 | 43 | 47 | 53 | 59 | 61 | 67 | 71 | 73 | 79 | 83 | 89 | 97 | 101 | 103 | 107 | 109 | 113 | 127 | 131 | 137 | 139 | 149 | 151 | 157 | 163 | 167 | 173 | 179 | 181 | 191 | 193 | 197 | 199 | 211 | 223 | 227 | 229 | 233 | 239 | 241 | 251 | 257 | 263 | 269 | 271 | 277 | 281 | 283 | 293 | 307 | 311 | 313 | 317 | 331 | 337 | 347 | 349 | 353 | 359 | 367 | 373 | 379 | 383 | 389 | 397 | 401 | 409 | 419 | 421 | 431 | 433 | 439 | 443 | 449 | 457 | 461 | 463 | 467 | 479 | 487 | 491 | 499 | 503 | 509 | ");
test!(run numbers.mlog; output = b"121212");
test!(run celliterate.mlog 500 times; cell[0][0] = 500.0);
test!(run hello.mlog; output = b"hello world");
diff --git a/lemu/src/memory.rs b/lemu/src/memory.rs
index 561569c..63d5db9 100644
--- a/lemu/src/memory.rs
+++ b/lemu/src/memory.rs
@@ -49,8 +49,8 @@ pub struct Priv {
impl std::fmt::Debug for LAddress<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
- Self::Const(c) => write!(f, "LAddress {c}"),
- Self::Address(n, ..) => write!(f, "LAddress {n:x}"),
+ Self::Const(c) => write!(f, "{c}"),
+ Self::Address(n, ..) => write!(f, "0x{n:x}"),
}
}
}
diff --git a/lemu/src/primes.mlog b/lemu/src/primes.mlog
new file mode 100644
index 0000000..67defe2
--- /dev/null
+++ b/lemu/src/primes.mlog
@@ -0,0 +1,21 @@
+set truth 0
+set:
+ op add truth truth 1
+ write true bank1 truth
+ jump set lessThanEq truth 512
+set prime 1
+loop:
+ op add prime prime 1
+ jump end greaterThanEq prime 512
+ read primality bank1 prime
+ jump loop notEqual primality true
+ print prime
+ print " | "
+ op mul multiple prime prime
+ inner:
+ write false bank1 multiple
+ op add multiple multiple prime
+ jump inner lessThanEq multiple 512
+ jump loop always
+end:
+ stop