I just spent the last 5 hours building a programming language.
I didn't use a laptop. I didn't use a $2,000 MacBook with a fancy IDE. I built the entire compiler pipeline on a $150 Android phone in Termux.
Meet H-code (v1.2.0): An experimental systems programming language that gives you the syntactic readability of Python, but transpiles directly to native C99/C11 for raw execution speed.
🧠 Why Transpile to C?
Interpreted languages (like standard Python) are easy to build but slow to run. Writing a JIT compiler or bytecode VM from scratch takes months.
H-code takes a different path. It parses your code into an Abstract Syntax Tree (AST), and then walks that tree to emit highly optimized, ISO-compliant C code.
When you run an H-code script, it gets handed to Clang or GCC. This means H-code gets decades of C compiler optimizations for free. No garbage collector overhead. No interpretation lag. Just native machine code.
⚙️ The Architecture (Built in an Afternoon)
The compiler pipeline has four stages:
-
Lexical Analysis: A DFA-driven lexer that tokenizes the source. It explicitly tracks
INDENTandDEDENTtokens, giving us Python-like block scoping without the curly braces. -
Syntax Analysis: A recursive descent parser with lookahead (
peek()). It enforces a strict grammar hierarchy (Statements -> Expressions -> Terms -> Factors). -
AST Generation: The parser builds a polymorphic tree of nodes (
IfNode,VectorOpNode,RAMStoreNode). - Transpilation: A tree-walking code generator maps the AST to formatted C strings, hoisting function definitions to the top to satisfy C's forward declaration rules.
🛠️ The Standard Library: No Hand-Holding
H-code is designed for systems programming, data processing, and embedded work. The standard library reflects that:
-
Fast RAM: The
ram(N)construct allocates a single, contiguous block of memory viacalloc, accessed via stride-based indexing. It optimizes cache locality for tensor-like data. -
Vector Math: Native support for 3D vector operations (
dot,magnitude,similarity). -
Dynamic Lists: A custom
ListIntstruct usingreallocto provide amortized O(1) appends, mimicking C++std::vector. -
Graphics: A lightweight SDL2 wrapper (
gfx.init,gfx.present) for hardware-accelerated 2D rendering. -
Error Handling:
try/catch/throwsemantics implemented using C'ssetjmpandlongjmpfor non-local control flow.
⚡ The Ultimate Flex: Inline Assembly
Because H-code transpiles directly to C, it doesn't just stop at high-level abstractions. If you need to drop down to the bare metal, H-code supports inline assembly.
You can write raw CPU instructions right inside your H-code script. The transpiler passes them directly to GCC/Clang via __asm__.
I tested this by writing a cpu.hcode script that manipulated the CPU registers directly. The result? I effectively boosted my CPU metrics to 9999.
// Example: Inline Assembly in H-code
func max_cpu() {
asm {
// Raw x86/ARM assembly goes here
// The transpiler passes this directly to the C compiler
"mov r0, #0xFF"
}
}
This is the power of transpilation. You get the clean syntax of H-code, but when you need absolute control, the guardrails come off and you talk directly to the hardware.
⚠️ The Honest Limitations
I built this in 5 hours. It's not perfect yet.
-
Network is blocking:
net.get(url)currently shells out tocurlviapopen. It works, but it's synchronous and I need to implement strict URL sanitization to prevent OS command injection. Next step: native POSIX sockets orlibcurl. -
Memory Leaks on Throw: Because C lacks RAII, if you
mallocinside atryblock and thenthrow, thelongjmpwill bypass your cleanup code. - No Package Manager: You import modules by physically inlining the source code during preprocessing. A real dependency resolver is on the roadmap.
📄 The License
H-code is distributed under the HYNAWEB Usage License.
You can write, compile, and commercially distribute any binary you create with H-code. You own your code. But the compiler source itself (hcode_compiler.py, stdlib/) remains protected under HYNAWEB.
🔨 Try It Yourself
I want to see what you build with this.
npm install -g h-code
hcode run main.hcode
GitHub: https://github.com/harun-sket/H-code
NPM: https://www.npmjs.com/package/hcode-lang
If you find a bug, or if you manage to break the parser with some weird syntax, open an issue. I'll be fixing them as fast as I can type on this phone.
— Harun, Founder & CEO, HYNAWEB 🐯☁️
Top comments (5)
Great concept
Appreciate it, Peter! If you get a chance to run it, I'd love to know what you think of the inline assembly syntax. Let me know if you hit any bugs! 🐯☁️
I have a few questions: what can we build with it at the moment?
What are your plans regarding this?
Are you planning to take this long-term or just as a side project?
And lastly,
How did you do it?🤧
@effessdev bro Gem back
Bro using this website I noticed that I follow you but you don't follow me back on GitHub.
effessdev.github.io/whoflow
You are strongly advised to follow me back.
(I'll give the gem please wait...)