Live data from Hacker News

A MOS6502 assembler impleme​nted as a Rust macro

play.rust-lang.org

21–30 of 59 posts

Re: A MOS6502 assembler impleme​nted as a Rust macro

#21
post #14

That ... is ... f *ing ... ugly to look at.

If your macros aren't ugly, you're doing it wrong.

Macros should never be ugly. There are multiple ways of using compile-time metaprogramming in a nice and clean way.

Maybe even in Rust, although I have not tried it yet.

Re: A MOS6502 assembler impleme​nted as a Rust macro

#22

Reminds me of this sweet paper http://research.microsoft.com/en-us/um/people/nick/coqasm.pd...

That's the exact one I thought of. On top of it, there's typed assembler:

https://www.cs.cornell.edu/talc/

And Vx86 used in Microsoft hypervisor:

http://swt.informatik.uni-freiburg.de/staff/maus/dissemain.p...

Note: Microsoft also used a TAL, though can't recall if same as Cornell, in their VerveOS that was verified down to assembler. Combined with SLAM, it's safe to say their researchers are kicking serious behind on practical, cutting-edge verification. I wouldn't have believed it 10+ years ago if someone told me haha.

Re: A MOS6502 assembler impleme​nted as a Rust macro

#23
post #5

Earlier quoted context omitted.

Well, a creative abuse of the language. Programmer humor.

Being a developer myself, I'm well aware of this. Still, it's ugly.

When I see this, I understand why the Go crowd didn't put generics or macros in Go. It's so easy to write useful but awful things with them, and they're really hard to fix and debug.

This is getting to be a big problem with Rust. The language, or maybe its community, encourages cutesy stuff like this. Remember "Diesel", the Rust compiler for SQL, from a few days ago? Just because you can doesn't mean you should. Too much fancy template stuff is being baked into the low level libraries. This may not end well.

C++ went down this road. The template system turned out to be more powerful than intended. Then people started writing cool stuff as fancy templates. Then the C++ committee added features to support the fancy templates better. Overly elaborate templates damaged C++; nobody could figure out what was going on. Use of C++ for new work declined.

All of this comes from smart people with good intentions. But when there's too much of this stuff, the mental load required to keep up with all of it becomes excessive. Especially if it changes a lot.

Re: A MOS6502 assembler impleme​nted as a Rust macro

#24
post #23

Earlier quoted context omitted.

Being a developer myself, I'm well aware of this. Still, it's ugly.

When I see this, I understand why the Go crowd didn't put generics or macros in Go. It's so easy to write useful but awful things with them, and they're really hard to fix and debug. This is getting to be a big problem with Rust. The language, or maybe its community, encourages cutesy stuff like this. Remember "Diesel", the Rust compiler for SQL, from a few days ago? Just because you can doesn't mean you should. Too…

This is silly. Rust could not achieve its performance and safety goals without macros and generics. Generics may have been optional for Go (I don't agree, but let's go with it), but there is no way to achieve zero-cost memory safety without generics (while supporting first-class references and dynamic allocation).

Rust generics are deliberately less expressive than C++ templates, in that they're strongly typed. That's why we get so many complaints from C++ and D developers that you can't do certain things. But Rust sticks with its strongly-typed generics, because Rust has always tried hard to strike a balance between code expressivity and maintainability.

This is a terrible example if you want to prove that point, anyway. This 6502 assembler is obviously a total abuse of the system, and nobody will deploy it to production. It's a neat hack, and that's all. Nobody would use an obfuscated quine written in Go to argue that Go is unreadable. This is exactly analogous.

Finally, Diesel is just an ORM. It uses exactly enough features to be an ORM; the only "problem" with it is that it's an ORM.

Re: A MOS6502 assembler impleme​nted as a Rust macro

#25
post #20
post #7

It doesn't support explicit accumulator addressing mode (ASL A, LSR A, ROL A, ROR A), but otherwise quite neat. (from a quick look at it) (also, 0x syntax is quite unusual, but I assume $ couldn't have been implemented for some reason)

The accumulator is the only register those work with. It was very common to not specify it.at all. I actually never have in all the 6502 assembly code I've ever written. Wasn't required.

I don't think that's true.

http://www.downloads.reactivemicro.com/Public/Users/David_Cr...

Code is straight from the Red Book listings. Search for ROR - accumulator (shown explicitly), indexed, you name it. 4 modes each.

Re: A MOS6502 assembler impleme​nted as a Rust macro

#26
post #23

Earlier quoted context omitted.

When I see this, I understand why the Go crowd didn't put generics or macros in Go. It's so easy to write useful but awful things with them, and they're really hard to fix and debug. This is getting to be a big problem with Rust. The language, or maybe its community, encourages cutesy stuff like this. Remember "Diesel", the Rust compiler for SQL, from a few days ago? Just because you can doesn't mean you should. Too…

This is silly. Rust could not achieve its performance and safety goals without macros and generics. Generics may have been optional for Go (I don't agree, but let's go with it), but there is no way to achieve zero-cost memory safety without generics (while supporting first-class references and dynamic allocation). Rust generics are deliberately less expressive than C++ templates, in that they're strongly typed. That'…

Animats had a very important point. While magic is so attractive and perhaps even useful in moderation, it causes so much damage in a large code base.

In C++, you get this damage from for example operator overload abuse (ok for math, not many other defensible uses), template abuse (ok in moderation), ninja exceptions and inheritance (especially multiple inheritance, ugh).

Anyways, if Rust proves to be a feasible workhorse building medium/large systems with bigger teams, it does sound interesting to me. Especially catching concurrency issues at compile time.

I just hope it won't ever become another C++.

Re: A MOS6502 assembler impleme​nted as a Rust macro

#28

That ... is ... f *ing ... ugly to look at.

You know that optical illusion where you can't tell whether you're looking at a cube from the top or the bottom, so your brain keeps flipping back and forth between them? This code is like that for me, but flipping between Perl and C.

Re: A MOS6502 assembler impleme​nted as a Rust macro

#29
post #23

Earlier quoted context omitted.

Being a developer myself, I'm well aware of this. Still, it's ugly.

When I see this, I understand why the Go crowd didn't put generics or macros in Go. It's so easy to write useful but awful things with them, and they're really hard to fix and debug. This is getting to be a big problem with Rust. The language, or maybe its community, encourages cutesy stuff like this. Remember "Diesel", the Rust compiler for SQL, from a few days ago? Just because you can doesn't mean you should. Too…

> It's so easy to write useful but awful things with them, and they're really hard to fix and debug.

And it is even easier to write useful, beautiful things with macros, which are really easy to fix and debug.

Re: A MOS6502 assembler impleme​nted as a Rust macro

#30
post #16
post #7

It doesn't support explicit accumulator addressing mode (ASL A, LSR A, ROL A, ROR A), but otherwise quite neat. (from a quick look at it) (also, 0x syntax is quite unusual, but I assume $ couldn't have been implemented for some reason)

Isn't A the only register those ops can use anyways? Although it's been a while, 25 years...

You can't ASL X or Y, but you can ASL $0 or ASL $0, X. (Using either a zero-page address or an absolute address.)
Post reply on HN