DEV Community

Cover image for I Built a Programming Language with Inline Assembly in 5 Hours (On a $150 Phone). Here’s How H-Code Works.
Harun - solo dev for HYNAWEB

Posted on Edited on

I Built a Programming Language with Inline Assembly in 5 Hours (On a $150 Phone). Here’s How H-Code Works.

Honest limitations and real memory leaks included

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:

  1. Lexical Analysis: A DFA-driven lexer that tokenizes the source. It explicitly tracks INDENT and DEDENT tokens, giving us Python-like block scoping without the curly braces.
  2. Syntax Analysis: A recursive descent parser with lookahead (peek()). It enforces a strict grammar hierarchy (Statements -> Expressions -> Terms -> Factors).
  3. AST Generation: The parser builds a polymorphic tree of nodes (IfNode, VectorOpNode, RAMStoreNode).
  4. 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 via calloc, 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 ListInt struct using realloc to 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/throw semantics implemented using C's setjmp and longjmp for 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" 
    }
}
Enter fullscreen mode Exit fullscreen mode

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.

  1. Network is blocking: net.get(url) currently shells out to curl via popen. It works, but it's synchronous and I need to implement strict URL sanitization to prevent OS command injection. Next step: native POSIX sockets or libcurl.
  2. Memory Leaks on Throw: Because C lacks RAII, if you malloc inside a try block and then throw, the longjmp will bypass your cleanup code.
  3. 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
Enter fullscreen mode Exit fullscreen mode

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 (12)

Collapse
 
pengeszikra profile image
Peter Vivo •

Great concept

Collapse
 
koda2026 profile image
Harun - solo dev HYNAWEB •

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! 🐯☁️

Collapse
 
aheadkit profile image
AheadKit •

Five hours on a $150 phone is the kind of constraint that forces honest decisions, and building a language with inline assembly under it is the opposite of a demo. Our own experiment rig runs a 1.5B model on a 2-core box at about 3 tokens a second, and the small box is what keeps the measurements honest, because nothing there can hide behind scale. What did the phone force you to cut that the laptop version would have kept, and did any of those cuts turn out to be the better design?

Collapse
 
koda2026 profile image
Harun - solo dev HYNAWEB •

AheadKit — running a 1.5B model on a 2-core box is exactly the kind of constraint I respect. Nothing hides behind scale there.

To answer your question: the phone forced me to cut a complex multi-file watch mode and a heavy local language server. I couldn't keep a background daemon running in Termux without draining the battery and choking the RAM. So I made the compiler strictly single-pass with inline preprocessing.

Did it turn out to be a better design? Yes. It eliminated dependency resolution hell. You just get a single, flat C file that Clang compiles instantly. Sometimes constraints don't just limit you; they force you to simplify the architecture. Keep pushing that 2-core box! 🐯☁️

Collapse
 
zarb450 profile image
Ameer Hamza •

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?🤧

Collapse
 
koda2026 profile image
Harun - solo dev HYNAWEB •

Ameer — great questions! Let me break them down:

  1. What you can build: Right now, it's best for CLI tools, data processing scripts, and basic 2D games (using the SDL2 wrapper). It's not ready for web backends yet, but it's great for systems-level logic.
  2. The plans: I'm actually planning to add H-code as the 13th supported runtime on my cloud platform, HYNA-Stage. Imagine writing H-code and deploying it to an isolated MicroVM in 7 seconds.
  3. Long-term: Definitely long-term. This isn't a weekend throwaway; it's a core part of the HYNAWEB ecosystem.
  4. How I did it: I used a recursive descent parser to build an Abstract Syntax Tree (AST), and then wrote a tree-walking transpiler that converts that AST into standard C99 code. Then I just let GCC/Clang do the heavy lifting to make it a native binary. All of it written entirely on my phone.

Let me know if you try building something with it! 🐯☁️

Collapse
 
zarb450 profile image
Ameer Hamza •

All of this without AI?

Thread Thread
 
koda2026 profile image
Harun - solo dev HYNAWEB •

WHO SAID WITHOUT AI?

Collapse
 
amintacccp profile image
tamina •

The honest limitations section is the strongest part of this — net.get shelling out to curl via popen, and the longjmp leak on throw, are exactly the things most 5-hour builds would quietly skip. Transpiling to C to get Clang/GCC optimizations for free was the right shortcut for a build like this. Curious what the package manager plan looks like — is the inline-import preprocessing going to get a real resolver, or is that deliberately out of scope for now?

Collapse
 
koda2026 profile image
Harun - solo dev HYNAWEB •

tamina — glad you caught the popen and longjmp notes. I figured if I didn't call them out, someone would find them the hard way, and I'd rather be honest upfront.

For the package manager: a real resolver is deliberately out of scope for v1.2.0. Right now, the inline preprocessing keeps the compiler dependency-free and fast. Building a proper resolver means handling versioning, caching, and network fetches, which is essentially building a second tool from scratch. I want to stabilize the core transpiler and the standard library first. Once the language syntax is rock solid, hpm (H-code Package Manager) will be the next major build. 🐯☁️

Collapse
 
koda2026 profile image
Harun - solo dev HYNAWEB •

@effessdev bro Gem back

Collapse
 
effessdev profile image
EffessDev •

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...)