[HN Gopher] Astmaker - A DSL in Rust for programming language de...
___________________________________________________________________
Astmaker - A DSL in Rust for programming language designers
Author : linkdd
Score : 75 points
Date : 2023-05-17 17:30 UTC (5 hours ago)
(HTM) web link (david-delassus.medium.com)
(TXT) w3m dump (david-delassus.medium.com)
| hardwaregeek wrote:
| One question I always ask myself when I see a crate that uses
| macros is "how much will this crate disrupt my IDE experience?"
| If it breaks rename and goto definition, then I'm not sure it's
| worth it. Especially with AST definitions where I will be going
| back to my AST definition a lot.
|
| Also, I find the whole visitor pattern abstraction a little
| pointless in Rust. I can't help but feel that applying a visitor
| pattern is taking an idiosyncrasy of object oriented programming
| and forcing it into Rust. Basically abstraction for abstraction's
| sake. I'd much rather write a bunch of `visit_expr`, `visit_stmt`
| (really `type_check_expr`, `type_check_stmt`) functions that
| pattern match on the data. It's much more searchable, and
| condenses the information at the pass level and not the data
| structure level. I care much more about having all of my type
| checking methods in one place, than I care about having all of
| the transformations of `Expr` in one place. I suppose if you're
| doing a lot of passes over the same representation and you need
| to schedule them in an efficient way, a visitor pattern could
| work. But how often are you doing that? Maybe if you're writing
| an optimizer but more often than not I'm doing a transformation
| pass from one IR to another.
|
| With that said I can sympathize with ASTs being a lot of
| boilerplate. It took a lot of typing to thread location data
| through my AST.
| nindalf wrote:
| Rust seems to be good for language designers thanks to a
| combination of features - enums that can contain data (aka tagged
| unions) and exhaustive matching on all variants of that enum with
| the match statement. This makes it easy to model all the token
| types of the language. Good performance helps as well.
|
| I reckon other languages could replicate this combination, it's
| not very hard. Dart added this feature recently. I just don't
| know why it's taken so long for tagged unions + exhaustive match
| to become widely adopted.
| vmchale wrote:
| I prefer having a GC, makes things easier. Also a copying GC
| can be better for some of the stuff you do in a compiler
| (immutable data structures).
| smaddox wrote:
| Easier for quick prototypes, for sure (although I switched to
| Rust from Haskell due to even worse compile times in Haskell
| and my disdain for monad transformers). Also, Rust can't
| currently do nested pattern matching through Boxes, which can
| be annoying, coming from Haskell.
|
| But for a high performance compiler, manually managed arena
| allocation will beat out a generational GC.
| discardable_dan wrote:
| Chez Scheme would disagree.
| Jeff_Brown wrote:
| Exhaustive pattern matching and tagged unions (sum types) are
| both great. Haskell's had them since its inception.
| JoelMcCracken wrote:
| well, sadly, you have to turn on an option to get
| exhaustivity checking. Which annoys me, because sometimes I
| _forget_ to turn it on for a small project /script.
|
| I need to come up with a haskell "new project" template thing
| carterschonwald wrote:
| Wall!it's great.
| nfiegbfjrd wrote:
| [dead]
| vmchale wrote:
| You can define a tree-walking interpreter in an ML just by
| recursion and pattern matching.
| tantaman wrote:
| Is it just me or is this paywalled?
| mdaniel wrote:
| https://david-delassus.scribe.rip/astmaker-a-dsl-in-rust-for...
| will help that problem, and strip a bazillion tons of JS out
| while it's at it
| linkdd wrote:
| HN removes the friend tag in the URL so I can't share the "no-
| paywall" link unfortunately.
|
| Though, this is fine by me. I don't mind people bypassing the
| paywall, but it's a source of (rather small) income for me :)
| digitalsanctum wrote:
| Same here, unfortunately.
| classified wrote:
| Medium sucks, I don't like reading stuff there.
| mdaniel wrote:
| https://david-delassus.scribe.rip/astmaker-a-dsl-in-rust-for...
|
| _courtesy of a Show HN project from a while ago_
___________________________________________________________________
(page generated 2023-05-17 23:01 UTC)