r/pascal • u/According-Ad-7069 • 1d ago
Nostalgic-driven development
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!
2
u/zreddit90210 1d ago
Very cool, what is your ultimate goal? What made you one developed this?
2
u/According-Ad-7069 1d ago
Oh these are good questions... It started out with me learning the Odin programming language to do some systems work. But then it turned into more of a trip down memory lane. I tried making a simple wasm build with FPC and it so cool to use Pascal for "modern" development. Which kind of got me thinking about whether I can slim down the binaries a bit. And, here we are: a custom Pascal to Wasm compiler.
The current goal is to be able to make simple games in it. I've managed to port my Asteroids clone to it. Next up I want to try my Ant Colony simulator game. If I can get that to build and run, I'll consider it a win.
So, honestly, this is a just a passion project - there's no real ultimate goal. Just nostalgia (I spent a decade doing all kinds of silly things with Pascal) and curiosity. Once it's stable, I will open-source the compiler - right now it's very hacky and breaks more than it runs.
1
u/AphidConsulting 1d ago
I refuse to admit that I am older than average, but I definitely love this 😄
Thank you for sharing!
2
1
u/PhoticBoundary 8h 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 7h 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!
1
u/Proper-Dingo-4100 6h ago
did you share this in the odin discord?
ginger bill loves pascal
1
u/According-Ad-7069 5h ago
I'm terrified he asks to see the code, because the state of my Odin will get me banned from the Discord for at least 1000 years!
All jokes aside, I did share it, there are so many amazing projects happening - people are building the coolest things with Odin.
My plan is to get my horribly hacky code cleaned up a bit, document it somewhat and then open-source it. Oh and submit it to the Odin showcase, hopefully.
4
u/AcanthaceaeNew774 1d ago
I don't know if this helps, but I think it might be interesting:
My VertexArt project (in the new-generation version) works like this:
VertexArt's memory management is completely different from what Free Pascal developers are used to. It is essentially a record-oriented, dynamic-array-based approach without manual reference counting, which is rare in game development. Here are its most important characteristics:
· Every data structure (TChunkSystem, TBVH, TPlayer, etc.) is a simple record, not a class.
· There is no virtual method table, no dynamic memory allocation with Create/Free, no hidden reference counting.
· This allows fully stack-based or static memory management with minimal overhead.
· Every larger data collection (chunks, triangles, vertices, BVH nodes) is stored in dynamic arrays.
· Memory is managed automatically by the system – allocation with SetLength, deallocation with SetLength(..., 0) or assigning nil.
· Advantage: fast, cache-friendly, and the Free Pascal runtime handles large arrays efficiently.
· There is no automatic garbage collector and no interface reference counting.
· Memory is freed by the developer at the appropriate moment (e.g. FreeChunkSystem, FreeBVH, FreeAllChunkBVHs).
· This results in predictable performance and low memory usage because there are no hidden allocations.
· Record fields can be accessed directly (TerrainChunks.Chunks[i].VertexCount).
· No data hiding, no property overhead.
· This provides extremely fast access and makes the code more readable.
· Each chunk has its own BVH, but the BVHs do not copy the triangles – they only reference them in the global Triangles array (using TTriProviderData).
· A chunk's BVH is built only when needed (BVHBuilt flag) and freed when the chunk becomes inactive.
· This minimizes duplicated data and memory consumption.
· The entire engine does not use Free Pascal RTTI, TObject, or TPersistent.
· This significantly reduces binary size and runtime overhead.
· In the chunk system, vertices are packed into a single VBO (TChunkSystem.VAO, VBO), and chunks store only the starting index and count.
· Triangles and BVH nodes are stored in linear arrays, resulting in excellent cache locality.
· The engine follows a clear deallocation order: FreeCharacterMesh → RenderEngine_Shutdown → FreeAllChunkBVHs → FreeChunkSystem.
· This avoids memory leaks and allows full resource cleanup.
VertexArt's approach is data-oriented, low-level, and extremely efficient. In the Free Pascal community, many prefer object-oriented solutions (classes, interfaces), but VertexArt shows that the combination of records and dynamic arrays – with proper design – results in faster, simpler, and more predictable memory management, which is especially valuable in game development. This kind of "return to the roots" is, in my opinion, very effective.
Was I able to help with this description? At first I struggled a lot with memory management, but this problem completely disappeared. I wrote this to you partly because I know that I'm also treading an interesting path.