tool for me to use if i drop nixos
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

implement `Display` for `Expr` and builtins improvements

IamPyu 981bb10f 753f36f1

+508 -8
+353
Cargo.lock
··· 3 3 version = 4 4 4 5 5 [[package]] 6 + name = "anyhow" 7 + version = "1.0.102" 8 + source = "registry+https://github.com/rust-lang/crates.io-index" 9 + checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" 10 + 11 + [[package]] 12 + name = "bitflags" 13 + version = "2.11.0" 14 + source = "registry+https://github.com/rust-lang/crates.io-index" 15 + checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" 16 + 17 + [[package]] 18 + name = "cfg-if" 19 + version = "1.0.4" 20 + source = "registry+https://github.com/rust-lang/crates.io-index" 21 + checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" 22 + 23 + [[package]] 24 + name = "cfg_aliases" 25 + version = "0.2.1" 26 + source = "registry+https://github.com/rust-lang/crates.io-index" 27 + checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" 28 + 29 + [[package]] 30 + name = "clipboard-win" 31 + version = "5.4.1" 32 + source = "registry+https://github.com/rust-lang/crates.io-index" 33 + checksum = "bde03770d3df201d4fb868f2c9c59e66a3e4e2bd06692a0fe701e7103c7e84d4" 34 + dependencies = [ 35 + "error-code", 36 + ] 37 + 38 + [[package]] 6 39 name = "demeter" 7 40 version = "0.1.0" 8 41 ··· 10 43 name = "dmx" 11 44 version = "0.1.0" 12 45 dependencies = [ 46 + "anyhow", 13 47 "indexmap", 48 + "rustyline", 14 49 "serde", 15 50 "strum", 16 51 "thiserror", 17 52 ] 18 53 19 54 [[package]] 55 + name = "endian-type" 56 + version = "0.1.2" 57 + source = "registry+https://github.com/rust-lang/crates.io-index" 58 + checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" 59 + 60 + [[package]] 20 61 name = "equivalent" 21 62 version = "1.0.2" 22 63 source = "registry+https://github.com/rust-lang/crates.io-index" 23 64 checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" 24 65 25 66 [[package]] 67 + name = "errno" 68 + version = "0.3.14" 69 + source = "registry+https://github.com/rust-lang/crates.io-index" 70 + checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" 71 + dependencies = [ 72 + "libc", 73 + "windows-sys 0.61.2", 74 + ] 75 + 76 + [[package]] 77 + name = "error-code" 78 + version = "3.3.2" 79 + source = "registry+https://github.com/rust-lang/crates.io-index" 80 + checksum = "dea2df4cf52843e0452895c455a1a2cfbb842a1e7329671acf418fdc53ed4c59" 81 + 82 + [[package]] 83 + name = "fd-lock" 84 + version = "4.0.4" 85 + source = "registry+https://github.com/rust-lang/crates.io-index" 86 + checksum = "0ce92ff622d6dadf7349484f42c93271a0d49b7cc4d466a936405bacbe10aa78" 87 + dependencies = [ 88 + "cfg-if", 89 + "rustix", 90 + "windows-sys 0.59.0", 91 + ] 92 + 93 + [[package]] 26 94 name = "hashbrown" 27 95 version = "0.16.1" 28 96 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 35 103 checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" 36 104 37 105 [[package]] 106 + name = "home" 107 + version = "0.5.12" 108 + source = "registry+https://github.com/rust-lang/crates.io-index" 109 + checksum = "cc627f471c528ff0c4a49e1d5e60450c8f6461dd6d10ba9dcd3a61d3dff7728d" 110 + dependencies = [ 111 + "windows-sys 0.61.2", 112 + ] 113 + 114 + [[package]] 38 115 name = "indexmap" 39 116 version = "2.13.0" 40 117 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 47 124 ] 48 125 49 126 [[package]] 127 + name = "libc" 128 + version = "0.2.183" 129 + source = "registry+https://github.com/rust-lang/crates.io-index" 130 + checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d" 131 + 132 + [[package]] 133 + name = "linux-raw-sys" 134 + version = "0.12.1" 135 + source = "registry+https://github.com/rust-lang/crates.io-index" 136 + checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" 137 + 138 + [[package]] 139 + name = "log" 140 + version = "0.4.29" 141 + source = "registry+https://github.com/rust-lang/crates.io-index" 142 + checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" 143 + 144 + [[package]] 145 + name = "memchr" 146 + version = "2.8.0" 147 + source = "registry+https://github.com/rust-lang/crates.io-index" 148 + checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" 149 + 150 + [[package]] 151 + name = "nibble_vec" 152 + version = "0.1.0" 153 + source = "registry+https://github.com/rust-lang/crates.io-index" 154 + checksum = "77a5d83df9f36fe23f0c3648c6bbb8b0298bb5f1939c8f2704431371f4b84d43" 155 + dependencies = [ 156 + "smallvec", 157 + ] 158 + 159 + [[package]] 160 + name = "nix" 161 + version = "0.30.1" 162 + source = "registry+https://github.com/rust-lang/crates.io-index" 163 + checksum = "74523f3a35e05aba87a1d978330aef40f67b0304ac79c1c00b294c9830543db6" 164 + dependencies = [ 165 + "bitflags", 166 + "cfg-if", 167 + "cfg_aliases", 168 + "libc", 169 + ] 170 + 171 + [[package]] 50 172 name = "proc-macro2" 51 173 version = "1.0.106" 52 174 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 65 187 ] 66 188 67 189 [[package]] 190 + name = "radix_trie" 191 + version = "0.2.1" 192 + source = "registry+https://github.com/rust-lang/crates.io-index" 193 + checksum = "c069c179fcdc6a2fe24d8d18305cf085fdbd4f922c041943e203685d6a1c58fd" 194 + dependencies = [ 195 + "endian-type", 196 + "nibble_vec", 197 + ] 198 + 199 + [[package]] 200 + name = "rustix" 201 + version = "1.1.4" 202 + source = "registry+https://github.com/rust-lang/crates.io-index" 203 + checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" 204 + dependencies = [ 205 + "bitflags", 206 + "errno", 207 + "libc", 208 + "linux-raw-sys", 209 + "windows-sys 0.61.2", 210 + ] 211 + 212 + [[package]] 213 + name = "rustyline" 214 + version = "17.0.2" 215 + source = "registry+https://github.com/rust-lang/crates.io-index" 216 + checksum = "e902948a25149d50edc1a8e0141aad50f54e22ba83ff988cf8f7c9ef07f50564" 217 + dependencies = [ 218 + "bitflags", 219 + "cfg-if", 220 + "clipboard-win", 221 + "fd-lock", 222 + "home", 223 + "libc", 224 + "log", 225 + "memchr", 226 + "nix", 227 + "radix_trie", 228 + "unicode-segmentation", 229 + "unicode-width", 230 + "utf8parse", 231 + "windows-sys 0.60.2", 232 + ] 233 + 234 + [[package]] 68 235 name = "serde" 69 236 version = "1.0.228" 70 237 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 93 260 "quote", 94 261 "syn", 95 262 ] 263 + 264 + [[package]] 265 + name = "smallvec" 266 + version = "1.15.1" 267 + source = "registry+https://github.com/rust-lang/crates.io-index" 268 + checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" 96 269 97 270 [[package]] 98 271 name = "strum" ··· 151 324 version = "1.0.24" 152 325 source = "registry+https://github.com/rust-lang/crates.io-index" 153 326 checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" 327 + 328 + [[package]] 329 + name = "unicode-segmentation" 330 + version = "1.13.1" 331 + source = "registry+https://github.com/rust-lang/crates.io-index" 332 + checksum = "da36089a805484bcccfffe0739803392c8298778a2d2f09febf76fac5ad9025b" 333 + 334 + [[package]] 335 + name = "unicode-width" 336 + version = "0.2.2" 337 + source = "registry+https://github.com/rust-lang/crates.io-index" 338 + checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254" 339 + 340 + [[package]] 341 + name = "utf8parse" 342 + version = "0.2.2" 343 + source = "registry+https://github.com/rust-lang/crates.io-index" 344 + checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" 345 + 346 + [[package]] 347 + name = "windows-link" 348 + version = "0.2.1" 349 + source = "registry+https://github.com/rust-lang/crates.io-index" 350 + checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" 351 + 352 + [[package]] 353 + name = "windows-sys" 354 + version = "0.59.0" 355 + source = "registry+https://github.com/rust-lang/crates.io-index" 356 + checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" 357 + dependencies = [ 358 + "windows-targets 0.52.6", 359 + ] 360 + 361 + [[package]] 362 + name = "windows-sys" 363 + version = "0.60.2" 364 + source = "registry+https://github.com/rust-lang/crates.io-index" 365 + checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" 366 + dependencies = [ 367 + "windows-targets 0.53.5", 368 + ] 369 + 370 + [[package]] 371 + name = "windows-sys" 372 + version = "0.61.2" 373 + source = "registry+https://github.com/rust-lang/crates.io-index" 374 + checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" 375 + dependencies = [ 376 + "windows-link", 377 + ] 378 + 379 + [[package]] 380 + name = "windows-targets" 381 + version = "0.52.6" 382 + source = "registry+https://github.com/rust-lang/crates.io-index" 383 + checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" 384 + dependencies = [ 385 + "windows_aarch64_gnullvm 0.52.6", 386 + "windows_aarch64_msvc 0.52.6", 387 + "windows_i686_gnu 0.52.6", 388 + "windows_i686_gnullvm 0.52.6", 389 + "windows_i686_msvc 0.52.6", 390 + "windows_x86_64_gnu 0.52.6", 391 + "windows_x86_64_gnullvm 0.52.6", 392 + "windows_x86_64_msvc 0.52.6", 393 + ] 394 + 395 + [[package]] 396 + name = "windows-targets" 397 + version = "0.53.5" 398 + source = "registry+https://github.com/rust-lang/crates.io-index" 399 + checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" 400 + dependencies = [ 401 + "windows-link", 402 + "windows_aarch64_gnullvm 0.53.1", 403 + "windows_aarch64_msvc 0.53.1", 404 + "windows_i686_gnu 0.53.1", 405 + "windows_i686_gnullvm 0.53.1", 406 + "windows_i686_msvc 0.53.1", 407 + "windows_x86_64_gnu 0.53.1", 408 + "windows_x86_64_gnullvm 0.53.1", 409 + "windows_x86_64_msvc 0.53.1", 410 + ] 411 + 412 + [[package]] 413 + name = "windows_aarch64_gnullvm" 414 + version = "0.52.6" 415 + source = "registry+https://github.com/rust-lang/crates.io-index" 416 + checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" 417 + 418 + [[package]] 419 + name = "windows_aarch64_gnullvm" 420 + version = "0.53.1" 421 + source = "registry+https://github.com/rust-lang/crates.io-index" 422 + checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" 423 + 424 + [[package]] 425 + name = "windows_aarch64_msvc" 426 + version = "0.52.6" 427 + source = "registry+https://github.com/rust-lang/crates.io-index" 428 + checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" 429 + 430 + [[package]] 431 + name = "windows_aarch64_msvc" 432 + version = "0.53.1" 433 + source = "registry+https://github.com/rust-lang/crates.io-index" 434 + checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" 435 + 436 + [[package]] 437 + name = "windows_i686_gnu" 438 + version = "0.52.6" 439 + source = "registry+https://github.com/rust-lang/crates.io-index" 440 + checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" 441 + 442 + [[package]] 443 + name = "windows_i686_gnu" 444 + version = "0.53.1" 445 + source = "registry+https://github.com/rust-lang/crates.io-index" 446 + checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" 447 + 448 + [[package]] 449 + name = "windows_i686_gnullvm" 450 + version = "0.52.6" 451 + source = "registry+https://github.com/rust-lang/crates.io-index" 452 + checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" 453 + 454 + [[package]] 455 + name = "windows_i686_gnullvm" 456 + version = "0.53.1" 457 + source = "registry+https://github.com/rust-lang/crates.io-index" 458 + checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" 459 + 460 + [[package]] 461 + name = "windows_i686_msvc" 462 + version = "0.52.6" 463 + source = "registry+https://github.com/rust-lang/crates.io-index" 464 + checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" 465 + 466 + [[package]] 467 + name = "windows_i686_msvc" 468 + version = "0.53.1" 469 + source = "registry+https://github.com/rust-lang/crates.io-index" 470 + checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" 471 + 472 + [[package]] 473 + name = "windows_x86_64_gnu" 474 + version = "0.52.6" 475 + source = "registry+https://github.com/rust-lang/crates.io-index" 476 + checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" 477 + 478 + [[package]] 479 + name = "windows_x86_64_gnu" 480 + version = "0.53.1" 481 + source = "registry+https://github.com/rust-lang/crates.io-index" 482 + checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" 483 + 484 + [[package]] 485 + name = "windows_x86_64_gnullvm" 486 + version = "0.52.6" 487 + source = "registry+https://github.com/rust-lang/crates.io-index" 488 + checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" 489 + 490 + [[package]] 491 + name = "windows_x86_64_gnullvm" 492 + version = "0.53.1" 493 + source = "registry+https://github.com/rust-lang/crates.io-index" 494 + checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" 495 + 496 + [[package]] 497 + name = "windows_x86_64_msvc" 498 + version = "0.52.6" 499 + source = "registry+https://github.com/rust-lang/crates.io-index" 500 + checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" 501 + 502 + [[package]] 503 + name = "windows_x86_64_msvc" 504 + version = "0.53.1" 505 + source = "registry+https://github.com/rust-lang/crates.io-index" 506 + checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650"
+2
crates/dmx/Cargo.toml
··· 9 9 indexmap.workspace = true 10 10 strum.workspace = true 11 11 thiserror.workspace = true 12 + anyhow.workspace = true 13 + rustyline = "17.0.2" 12 14 13 15 [features] 14 16 default = []
+43
crates/dmx/src/bin/dmxi.rs
··· 1 + use dmx::{Chunk, Engine}; 2 + use rustyline::{Config, DefaultEditor, error::ReadlineError}; 3 + use std::io::{Write, stderr}; 4 + 5 + pub fn main() -> anyhow::Result<()> { 6 + let mut editor = DefaultEditor::with_config( 7 + Config::builder() 8 + .auto_add_history(true) 9 + .max_history_size(10000)? 10 + .build(), 11 + )?; 12 + 13 + let mut stderr = stderr().lock(); 14 + let engine = Engine::new(); 15 + 16 + writeln!(stderr, "CTRL-d to exit")?; 17 + stderr.flush()?; 18 + 19 + loop { 20 + let read = match editor.readline("λ> ") { 21 + Ok(s) => s, 22 + Err(ReadlineError::Eof | ReadlineError::Interrupted) => { 23 + break; 24 + } 25 + Err(e) => { 26 + eprintln!("readline error: {e}"); 27 + continue; 28 + } 29 + }; 30 + 31 + match Chunk::from_source(&read) { 32 + Ok(ref chunk) => match engine.eval_chunk(chunk) { 33 + Ok(v) => println!("-- {v}"), 34 + Err(e) => writeln!(stderr, "error: {e}")?, 35 + }, 36 + Err(e) => { 37 + writeln!(stderr, "error: {e}")?; 38 + } 39 + } 40 + } 41 + 42 + Ok(()) 43 + }
+57 -2
crates/dmx/src/builtins.rs
··· 10 10 ("nil", Expr::Nil), 11 11 ("true", Expr::Bool(true)), 12 12 ("false", Expr::Bool(false)), 13 - ("progn", Expr::Macro(crate::value::Macro(macro_progn))), 13 + ("progn!", Expr::Macro(crate::value::Macro(macro_progn))), 14 + ("set!", Expr::Macro(crate::value::Macro(macro_set))), 14 15 ("let", Expr::Macro(crate::value::Macro(macro_let))), 15 16 ("lambda", Expr::Macro(crate::value::Macro(macro_lambda))), 16 17 ("if", Expr::Macro(crate::value::Macro(macro_if))), ··· 18 19 ("debug", Expr::PrimOp(crate::value::PrimOp(func_debug))), 19 20 ("nth", Expr::PrimOp(crate::value::PrimOp(func_nth))), 20 21 ("map", Expr::PrimOp(crate::value::PrimOp(func_map))), 22 + ("not", Expr::PrimOp(crate::value::PrimOp(func_not))), 23 + ( 24 + "dump-scope", 25 + Expr::PrimOp(crate::value::PrimOp(func_dump_scope)), 26 + ), 21 27 ("+", Expr::PrimOp(crate::value::PrimOp(func_add))), 22 28 ("-", Expr::PrimOp(crate::value::PrimOp(func_sub))), 23 29 ("*", Expr::PrimOp(crate::value::PrimOp(func_mul))), ··· 35 41 scope.eval_ast(args) 36 42 } 37 43 44 + fn macro_set(scope: ScopeRef, args: ASTRef) -> Result<ExprRef, RuntimeError> { 45 + if args.len() != 1 { 46 + return Err(RuntimeError::InvalidArguments(format!( 47 + "expected 1 argument" 48 + ))); 49 + } 50 + 51 + let t = scope.eval(ExprRef::clone(&args[0]))?; 52 + match &*t { 53 + Expr::Map(m) => { 54 + for (k, v) in m { 55 + scope.parent().unwrap().set(k, ExprRef::clone(v)); 56 + } 57 + } 58 + _ => { 59 + return Err(RuntimeError::InvalidArguments(format!( 60 + "expected {:?} for argument #1", 61 + Type::Map 62 + ))); 63 + } 64 + } 65 + 66 + Ok(scope.value(Expr::Nil)) 67 + } 68 + 38 69 fn macro_let(scope: ScopeRef, args: ASTRef) -> Result<ExprRef, RuntimeError> { 39 70 if args.len() < 2 { 40 71 return Err(RuntimeError::InvalidArguments(format!( ··· 127 158 128 159 fn func_debug(scope: ScopeRef, args: &[ExprRef]) -> Result<ExprRef, RuntimeError> { 129 160 for a in args { 130 - println!("{a:?}"); 161 + eprintln!("{a}"); 131 162 } 132 163 133 164 Ok(scope.value(Expr::Nil)) ··· 185 216 "expected list for argument #1 and callable for argument #2" 186 217 ))), 187 218 } 219 + } 220 + 221 + fn func_not(scope: ScopeRef, args: &[ExprRef]) -> Result<ExprRef, RuntimeError> { 222 + if args.len() != 1 { 223 + return Err(RuntimeError::Exception(format!("expected 1 argument"))); 224 + } 225 + 226 + let [p, ..] = &args[..] else { unreachable!() }; 227 + 228 + Ok(scope.value(Expr::Bool(!p.is_truthy()))) 229 + } 230 + 231 + fn func_dump_scope(scope: ScopeRef, args: &[ExprRef]) -> Result<ExprRef, RuntimeError> { 232 + let locals = scope.locals.lock().unwrap(); 233 + 234 + for (k, v) in locals.iter().filter_map(|(k, v)| Some((k, v.upgrade()?))) { 235 + eprintln!("{k}: {v}"); 236 + } 237 + 238 + if let Some(s) = scope.parent() { 239 + func_dump_scope(s, args)?; 240 + } 241 + 242 + Ok(scope.value(Expr::Nil)) 188 243 } 189 244 190 245 macro_rules! arithmetic {
+1 -1
crates/dmx/src/lib.rs
··· 7 7 pub mod scope; 8 8 pub mod value; 9 9 10 - pub use engine::Engine; 10 + pub use engine::{Chunk, Engine}; 11 11 pub use scope::Scope; 12 12 pub use value::{Expr, Func, Macro, Map, PrimOp, Type}; 13 13
+4 -4
crates/dmx/src/scope.rs
··· 13 13 14 14 /// Scope, should only be accessed via when wrapped in an [Arc] 15 15 pub struct Scope { 16 - this: Weak<Self>, 17 - parent: Option<Weak<Self>>, 18 - locals: Mutex<HashMap<Symbol, Weak<Expr>>>, 19 - values: Mutex<Vec<Arc<Expr>>>, 16 + pub(crate) this: Weak<Self>, 17 + pub(crate) parent: Option<Weak<Self>>, 18 + pub(crate) locals: Mutex<HashMap<Symbol, Weak<Expr>>>, 19 + pub(crate) values: Mutex<Vec<Arc<Expr>>>, 20 20 } 21 21 22 22 impl Scope {
+1 -1
crates/dmx/src/tests/hello.dmx
··· 1 - ; vim:ft=scheme 1 + ; vim:syntax=scheme 2 2 3 3 (debug "hello") 4 4 (debug (let {
+47
crates/dmx/src/value.rs
··· 125 125 } 126 126 } 127 127 128 + impl std::fmt::Display for Expr { 129 + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 130 + match self { 131 + Self::Nil => write!(f, "nil"), 132 + Self::Bool(b) => { 133 + if *b { 134 + write!(f, "true") 135 + } else { 136 + write!(f, "false") 137 + } 138 + } 139 + Self::Int(n) => write!(f, "{n}"), 140 + Self::Float(n) => write!(f, "{n}"), 141 + Self::String(s) => write!(f, "{s}"), 142 + Self::Symbol(s) => write!(f, "'{s}"), 143 + Self::Quote(q) => write!(f, "`{q}"), 144 + Self::Function(_) => write!(f, "function<@{}>", (self as *const Expr).addr()), 145 + Self::PrimOp(_) => write!(f, "primop<@{}>", (self as *const Expr).addr()), 146 + Self::Macro(_) => write!(f, "macro<@{}>", (self as *const Expr).addr()), 147 + Self::List(l) => { 148 + write!(f, "(")?; 149 + let mut iter = l.iter().peekable(); 150 + while let Some(v) = iter.next() { 151 + if iter.peek().is_some() { 152 + write!(f, "{v} ") 153 + } else { 154 + write!(f, "{v}") 155 + }?; 156 + } 157 + write!(f, ")") 158 + } 159 + Self::Map(m) => { 160 + write!(f, "{{")?; 161 + let mut iter = m.iter().peekable(); 162 + while let Some((k, v)) = iter.next() { 163 + if iter.peek().is_some() { 164 + write!(f, "{k}:{v},") 165 + } else { 166 + write!(f, "{k}:{v}") 167 + }?; 168 + } 169 + write!(f, "}}") 170 + } 171 + } 172 + } 173 + } 174 + 128 175 #[derive(Debug, Clone, Copy, PartialEq, Eq)] 129 176 pub enum Type { 130 177 Nil,