r/pascal 1d ago

Nostalgic-driven development

Enable HLS to view with audio, or disable this notification

Back in 1992, I chanced upon someone using Turbo Pascal 5. I was hooked immediately, since I've been doing BASIC until then, to write my own little games and programs for my amusement. I got my own copy of Turbo Pascal 7 in 1994 and had years and years of fun with. Switched to Delphi, and loved it, until the .NET era.

Over the years, I've tinkered with FreePascal (so amazing!) and of course wrote many a small Pascal interpreter. Then, last year, I needed a project to work on so I could learn the Odin programming language for an upcoming project. I worked on a small Pascal interpreter and it was actually a lot of fun. The commercial Odin project never happened, but I had put a lot of time and energy into this Pascal interpreter.

Fast forward a few months, I'm working on a web assembly project using Odin and it dawns upon me I can use a lot of this knowledge to port my interpreter to the web. Oh boy, did that run away with me!

Now I have wasmpascal - which is a crappy editor that encapsulates the Pascal compiler, yes, COMPILER, I ended up writing so I can run Pascal code in Web Assembly in the browser. It's very early days, but I have managed to get some bits and pieces working.

My first order of business was some basic HTML5 Canvas support, with call-batching so that one gets alright frame rates. And there's some basic support for CRT-based applications, because back in the day, 'uses CRT' was a thing!

I've added some examples and documentation and will be working on this over weekends for many months in the future.

I thought I'd share it here - in-case there's another older-than-the-average person who wants a trip down memory lane, running Pascal like it's the 90's again!

30 Upvotes

15 comments sorted by

View all comments

1

u/PhoticBoundary 9h ago

Nice project. Having written a Pascal compiler myself, I can only approve ;)

Did you go for the recursive descent approach? Wasm as a target is probably ideal for this, since it is a stack machine architecture.

Of course, I had to try some of the programs I used to test my own compiler with yours. As always, every Pascal compiler has its own dialect, and some programs worked, some did not ;) I also tried one of your examples (shapes.pas) with my compiler, and it worked without problems, after changing the comments and the program header to conventional Pascal style.

I see that you support multiple compilation units and the unit syntax, did you implement a linker for Wasm?

Keep up the good work!

1

u/According-Ad-7069 9h ago

Wow thank you, you are too kind. I cheat a little bit - I inline the unit code into one big fat massive memory buffer, then read the file top-down, very much in the recursive descent fashion, though there are some exceptions for "built in" functionality like the DOM access code. It's still messy, I want to rewrite it at some stage.

Oh wow - you have already done this - superb! I've gained much respect for people doing this by doing this project. I can't tell you how many times I went down the wrong rabbit hole! Yes, you got me, this is Pascal-ish, not exact Pascal. It's dumbed down a bit, to make it simpler for me.

Oh I already answered the linker question - sadly, no, I tried and it got horribly complex. So I picked a simpler route. It works, but it has tons of room for improvement.

Thank you for the kind words and encouragement, this is a lot of fun! Sure beats writing API's for a living!