JasonBock / IronBefunge

IronBefunge is an interpreter (written in .NET) for Befunge programs.
MIT License
3 stars 1 forks source link

Updating to .NET 7 Affects New Lines #46

Open JasonBock opened 1 year ago

JasonBock commented 1 year ago

I'm not sure why, but when I upgraded to .NET 7, doing 52*, - i.e. add a line feed - doesn't quite work anymore. I updated Collatz.b98 to use d,a, and that seems to work. This also seems to affect Gasket.b98 and 99Bottles.b98, but offhand I can't figure out how to modify them so they output correctly. @logiclrd if you have any ideas let me know :).

JasonBock commented 1 year ago

OK, I figured out Gasket.b98. Next up is 99Bottles.b98 :)

logiclrd commented 1 year ago

Huh, so, with .NET 7, what does outputting only an LF do? Does it change it from this on earlier versions:

foo
bar
qux

...to this?:

foo
   bar
      qux

?

That's an interesting change, making .NET handle CR and LF in way consistent with how DOS and Windows have traditionally interpreted them. UNIX systems have for ages used LF to imply a carriage return.

JasonBock commented 1 year ago

I believe so. It definitely gets funky with the current "push a 10 on a stack and output as ASCII". If Befunge had a "write line" command, then that would make this easier because I'd just do a Console.WriteLine() underneath the scenes, which would do the right thing with new lines based on your environment. But Befunge requires this to be hard coded.

Side note, there is a way to do "fingerprints" or something like that, which I believe lets you map a function to a specific character. So, that would allow me to potentially do something like "map W to a Console.WriteLine()". But that's a feature I've never implemented, so that won't happen for a while.

logiclrd commented 1 year ago

Hmm, what about handling it inside OutputInstructionHandler, so that if the character being requested is a 10, then it does a Console.WriteLine instead?

JasonBock commented 1 year ago

I thought of that. It feels a little hacky to do that :). I think the right approach is to do some kind of custom command with the fingerprint approach is the overall "right" solution. For now, doing d,a, should always work....I think :).

logiclrd commented 1 year ago

I dunno, it doesn't feel particularly hacky to me. The only possible theoretical structural improvement would be to make a translating stream class and slot that in between OutputInstructionHandler and the actual stdout stream. The bottom line is that Befunge has a definition for its output stream that doesn't entirely match what .NET 7 is providing. They aren't the same thing, so translation is required to be strictly correct -- to match up with what the code did on earlier .NET versions.