wasmpascal: a Pascal compiler that runs entirely in your browser
wasmpascal compiles Pascal source to
WebAssembly entirely inside your browser, then runs the
freshly compiled wasm on the same page. There is no file system, no native
binary, and no server-side toolchain: the compiler itself is a WebAssembly
module, written in the Odin programming language and compiled to js_wasm32. Type Pascal in the editor above, press Run, and the compiled program executes right there — console output, canvas graphics, or a full game.
What you can do
- Compile in the browser — the editor, compiler, and runtime are all on this page; nothing is uploaded anywhere.
- Multi-file projects — a root program plus
usesunits, with a file dropdown, add/rename/remove, and autosave tolocalStorage. - Turbo-Pascal-style console I/O —
write,writeln,read,readln,GotoXY,ClrScr,TextColor, andTextBackgroundrender into a fixed character screen. - Object-oriented Pascal — value-type
objectwithconstructor,virtual+ VMT dispatch,object(Parent)inheritance +inherited/overrideandNew(p, Init); reference-typeclasswithCreate/Free,class(Parent)two-level inheritance and polymorphism (seeobjects_demo.pas/classes_demo.pas). - Heap allocation —
New/DisposeandGetMem/FreeMemback a bump allocator with a free list, so linked lists and dynamic records work. - Typed const aggregates —
Origin: TPoint = (x: 10; y: 20),array[0..2] of Integer = (1,2,3), ands + cwherec: Char(seetyped_const_demo.pas). - Canvas and game ABIs — programs can drive a pixel-buffer canvas (
basic_canvas), self-wire a canvas and event loop (pascaldom— reach it withuses WEB, which brings the whole DOM bridge in without a singleexternaldeclaration, callback id or dispatcher), or use the batched-canvas game bridge (batchiness) with Web Audio sound effects. - Editor themes — Default modern dark theme plus classic Turbo Pascal 7 (DOS blue), Borland Pascal (navy), and FreePascal (royal blue) with live hot-swapping.
- Download — the
Download…toolbar menu saves the compiled.wasmas a standalone module, the whole project (root + everyusesunit) as a.ziparchive, or a ready-to-host standalone web app — as a folder (.zip: runnerindex.html+ runtimejs+ bridges + compiledwasm, upload it to any static web server) or as a single self-contained.html(everything inlined; opens straight from disk). - Upload
.pasfiles — pick any number of files from your computer and rebuild a project from them; the file declaringprogrambecomes the root.
How it works
When you press Run, the page spawns a fresh compile Worker that loads the compiler WebAssembly module and feeds it your Pascal source through a shared memory buffer. The compiler runs the full Pascal to WebAssembly pipeline — preprocess, lex, parse, semantic analysis, code generation, and WebAssembly module emission — and returns compiled wasm bytes. Those bytes are instantiated on the main thread, and the host detects the program's ABI from its exports: console-only programs run in a Worker with an inline input line, while canvas and game programs boot straight into the page.
The compiler itself is the wasmpascal Pascal-to-wasm32 compiler, written in the Odin programming language and recompiled to js_wasm32 with its CLI driver replaced by a memory-buffer browser driver. It shares its lineage with zigbasic, which runs a QBASIC interpreter in the browser the same way. The whole toolchain is client-side — there is no build server.
Compile Pascal to WebAssembly in the browser — no server, no install
Most online Pascal compilers send your source to a server, compile it with Free Pascal there, and stream the output back. wasmpascal does the opposite: it compiles Pascal to WebAssembly entirely in your browser. Your source never leaves the tab — it is copied into the compiler's linear memory at wasmpascal_source_ptr(), compiled by wasmpascal_compile() running as WebAssembly, and the resulting .wasm bytes are instantiated right on the same page.
The compiler is a single WebAssembly module (about 500 KB) that implements the complete pipeline. It parses Turbo Pascal 7 syntax, resolves uses units from an in-memory store, type-checks with range and set checks, and emits MVP-only WebAssembly — no WASI, no Emscripten shims, no hidden JavaScript runtime. That compiled WebAssembly runs in any modern browser, and you can download it as a standalone .wasm file or bundle it into a standalone web app (.zip folder for any static host, or a single self-contained .html that even opens from file://).
Because the compiler is WebAssembly, privacy and speed are built in: offline after the first load, deterministic builds, and no account or server queue. It is an in-browser Pascal to Wasm compiler you can use to learn, prototype, or ship — the same way you would run fpc locally, but with zero install.
What Pascal you can write
wasmpascal targets a practical Turbo Pascal 7 dialect plus FreePascal and Delphi extensions — enough to write real console programs, data structures, and games that compile to WebAssembly.
- Types —
Integer,Cardinal,Byte,ShortInt,SmallInt,Word,Real/Single/Double,Boolean,Char,Pointer/^T, fixed stringsString[n]and dynamicString, static arrays (includingarray[1..3, 1..4] of Twitha[i,j]), records with variants,set ofbitmasks, enumerations and subranges, and typed const aggregates. - Object-oriented Pascal — value-type
objectand reference-typeclass, withconstructor/destructor,virtual+ VMT dispatch,override,inherited,object(Parent)/class(Parent)inheritance, and polymorphism viaNew(p, Init)orTAnimal.Create/Free. - Control flow —
if/case(withlo..hiranges),for to/downto,while,repeat until,break/continue/exit, Delphi-style ternaryif cond then a else b,with, andgoto/label. - Procedures and functions —
varparameters by address (including locals via a per-call frame), procedural parameters andexternalimports for host ABIs. - Builtins — string helpers (
Length,Copy,Pos,Concat,Val,Str), math (Sin,Cos,ArcTan,Ln,Exp,Power,Sqrt,Hypot…), memory (FillChar,Move,SizeOf),Random/Randomize,Inc/Dec,Ord/Chr/UpCase, and more — see the quick reference (?/F1). - Console and screen —
write/writeln/read/readlnwith field widths,GotoXY/ClrScr,TextColor/TextBackground(palette indices,RRGGBBAAhex, orTextColorRGB),Delay, andReadKey/KeyPressed. - Units and modules —
program/library/unitheaders,useswith depth-first transitive loading,interface/implementation, and three units built into the compiler that need no registration:Crt,ClassesandWEB(the DOM/canvas bridge).
Directives like {$mode fpc}, {$M 32M} (heap size), {$Screen 80 25}, and {$R+}/{$R-} range checks are supported; unknown {$...} directives are ignored. The Learn Pascal tutorial (Help → Lessons) walks through every feature above with runnable examples.
An online Pascal IDE — editor, projects, and hosting
wasmpascal is a full online Pascal IDE and Pascal playground: the editor, compiler, and runtime all live on this page. The editor is CodeMirror 6 with Pascal syntax highlighting, bracket matching, and four themes — Default dark plus authentic Turbo Pascal 7 (DOS blue), Borland Pascal, and FreePascal — hot-swapped without losing undo history.
Work in multi-file projects: a named set of .pas files with one root program and any number of uses units, a file dropdown to switch files, and Files… actions to add/rename/remove or promote a new root. Projects autosave to localStorage, and you can upload any number of .pas files from disk or export the whole project as a .zip. The ? quick reference and the Learn Pascal lessons are built in.
When your program compiles, Download… gives you the compiled .wasm, the project .zip, or a ready-to-host standalone web app: a .zip folder (index.html + runtime js + bridges + your .wasm) that runs on any static host, or a single self-contained .html with everything inlined that opens straight from disk. That is how you go from Pascal source to a WebAssembly app you can share.
Example programs
Load any of these from the Examples… dropdown in the toolbar:
hello.pas— the classic hello world.hello_write.pas— console output viawrite/writeln.colors.pas—TextColor/TextBackgroundplus a canvas gradient.fibonacci.pas— recursion and loops.guess.pas— a number-guessing game withreadln.objects_demo.pas—objectvalue types: static methods,virtual+ VMT,object(Parent)+inherited/override,New(p, Init)(new in 0.5.0).classes_demo.pas—classreference types:Create/Free,class(Parent)inheritance (two-levelTLabrador), polymorphism (new in 0.5.0).typed_const_demo.pas— aggregate typed consts,s + cwithCharvar,s[i]indexing (new in 0.5.0).web_dom.pas— the DOM from Pascal withuses WEB: a styled panel, an animating canvas and pointer handlers, with noexternalblock and no dispatcher.sweep.pas— a minesweeper game (pascaldom ABI viauses WEB, seven units).pascaloids.pas,pong.pas,breakout_graphics.pas,sparks.pas,growable.pas,floaty_car.pas— games using the batchiness canvas ABI.flightleader.pas— FLIGHT LEADER, an arcade space-combat-style game (batchiness ABI, six units).xonix.pas— Xonix (ported from odinix): draw lines across the water to claim land — the fill floods from the balls, so it can never cover one (batchiness ABI).dugster.pas— DUGSTER, a Digger-style dig-em-up: dig tunnels, collect emeralds, dodge the nobbin (batchiness ABI, five units).paint.pas— PAINT: a paint program whose whole interface (panel, toolbar, colour swatches, status line) is built from the DOM by Pascal (pascaldom ABI,uses WEB).musicbox.pas— MUSIC BOX: a chiptune player that synthesises its four tracks with Web Audio and visualises them with DOM elements only — a piano-roll grid, VU meters and a spinning record; no canvas, no pixel buffer (pascaldom ABI,uses WEB).basic_canvas.pas— pixel-buffer canvas rendering.
FAQ — Pascal to WebAssembly, online compiler, and hosting
Does my Pascal code leave my browser? No. wasmpascal is a true in-browser Pascal compiler — source is copied into the compiler's WebAssembly memory and compiled there. Nothing is uploaded, there is no account, and the page works offline after the first load.
What Pascal dialect does it support? A practical Turbo Pascal 7 dialect plus FreePascal/Delphi extensions: typed consts, set of, conformant arrays, Delphi-style ternary if cond then a else b, and object/class OOP with virtual dispatch. Unknown {$...} directives are silently ignored for compatibility.
Can I learn Pascal here? Yes. The Learn Pascal tutorial (Help → Lessons) teaches the language lesson by lesson with runnable examples you load into the editor. The ? quick reference is the lookup companion.
Can I build games that compile to WebAssembly? Yes. Use the canvas host ABIs: basic_canvas for raw pixel buffers, pascaldom for DOM/canvas (add uses WEB and the whole DOM bridge is in scope — see web_dom.pas), and batchiness for batched-canvas games with Web Audio SFX. Every game example on this page was written in Pascal and compiled to WebAssembly the same way your code is.
Where can I find more example programs? Beyond the built-in Examples… dropdown, the wasmpascal_examples repository on GitHub collects extra Pascal programs you can copy into the editor and run.
How do I host a program I compiled to WebAssembly? Click Download… → Standalone app. The .zip is a folder (index.html + runtime js + your .wasm) you upload to any static host. The single .html is self-contained — CSS, runtime, and your compiled WebAssembly are inlined as base64, so it opens from disk with no server.
How big is the Pascal to WebAssembly compiler? About 500 KB of WebAssembly. The same Odin source also builds the native wasmpascal CLI. In the browser it runs in a fresh Worker per Run (wasmpascal_compile resets global state) and emits MVP-only WebAssembly validated by wasm-validate.
About the developer
I'm Ewald Horn, a software developer: I build all kinds of things, not just compilers. wasmpascal is one example from a personal collection of small browser projects used to explore systems programming, WebAssembly, and simulation from first principles. I might be available for freelance development work.
Acknowledgements
wasmpascal is built with gratitude on the following open-source projects and tools:
- CodeMirror 6 (by Marijn Haverbeke and contributors, MIT License) — powers the in-browser code editor with virtualized DOM rendering, Pascal syntax stream parsing, bracket matching, code folding, active-line highlighting, and search & replace.
- Odin Programming Language — powers the core Pascal-to-WebAssembly compiler engine.