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.

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

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
 
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 •

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