Urgent.News

600+ sources. One page. See who else covered it.

Editions

Tech

Designing a Stack-Based VM in Rust: 44 Instructions, Dual Backends, and Zero-Cost Security Types

Designing a Stack-Based VM in Rust: 44 Instructions, Dual Backends, and Zero-Cost Security Types A deep dive into the architecture of Metalogos — how 30,500 lines of Rust implement a language where XSS and SQL injection are compile-time errors, and why two execution backends crosscheck every program. Introduction Most programming languages treat security as an external concern — linters, SAST…

Designing a Stack-Based VM in Rust: 44 Instructions, Dual Backends, and Zero-Cost Security Types is a deep dive into the architecture of Metalogos. The language enforces security constraints through its type system, eliminating issues like XSS and SQL injection at compile-time. This article explores the Rust implementation behind this idea, focusing on architectural decisions that can be reused beyond Metalogos.

The codebase consists of approximately 30,500 lines of Rust, 91 Architecture Decision Records (ADRs), and two execution backends that must agree on every program's output. It is not a toy, a DSL, or a compiler; it is a full-fledged compiler, bytecode VM, HTTP server, semantic memory engine, and a security audit tool, all in one workspace.

The grammatical structure of Metalogos is defined using Pest 2.7 PEG, a declarative and powerful parser generator. This grammar consists of 384 lines and 180 rules, and it remains stable while the language evolves. The grammar serves as the specification for the entire language, and every change in syntax is reflected in the grammar rules. This ensures that the Abstract Syntax Tree (AST) is consistent and eliminates parser drift bugs.

Metalogos has two execution backends that implement identical semantics: a tree-walking interpreter and a bytecode VM. Both backends are generated concurrently and run with identical inputs. If the outputs differ, the test fails, providing a structural guarantee that both implementations implement the same semantics. This approach ensures that any semantic bugs introduced during the compilation process are caught early in the development process.

The bytecode VM in Metalogos consists of 44 instructions and operates on a stack-based model. The instruction set is intentionally minimal, with one opcode per action. Constants, variables, calls, arithmetic and comparison operations, struct and list manipulations, control flow, and Metalogos-specific instructions like fluid type resolution, memorization, and adaptation are all represented by specific opcodes.

The compilation process for Metalogos is two-pass. The first pass collects global variables, assigns slot indices, and resolves imports recursively. The second pass generates instructions based on the AST. Expression compilation is context-aware, meaning that pattern parameters are loaded onto the stack as local variables, while global variables are accessed using LoadGlobal instructions.

Flow declarations, such as control structures, are compiled into a single FlowPipeline macro instruction, which is resolved at runtime but validated at compile time.

To ensure zero-cost security, Metalogos includes five opaque types: Html, Secret, Encrypted, Hash, and SqlQuery. These types are enforced at compile-time through semantic analysis and are erased during code generation. By making these types compile-time constraints, Metalogos eliminates the risk of security vulnerabilities like XSS and SQL injection at runtime.

In summary, the Metalogos language is a highly secure, performant, and flexible programming language built using Rust. Its architecture, which includes a grammar defined using Pest, a robust AST, dual execution backends, a minimalist bytecode VM, and zero-cost security types, makes it a powerful tool for developers seeking a secure and efficient programming language.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Container Image Signing & SLSA Provenance Verification with Sigstore Cosign

Container Image Signing & SLSA Provenance Verification with Sigstore Cosign Supply chain security guide on signing OCI container images keylessly and verifying SLSA build provenance using Sigstore…

  • Sigstore Cosign signs container images in CI/CD pipelines without managing private keys.
  • Cosign records signed images in public Rekor transparency log for immutable provenance verification.
  • Kyverno policies enforce use of signed images in Kubernetes clusters for supply chain security.

Why We Parse Industrial Code Instead of Embedding It

Most of the industrial AI you have seen is a retrieval pipeline with a chat box on it. Chunk the manuals, embed them, stuff the top matches into a context window, let the model talk. It demos well.

  • Nexus system prioritizes language model as core component
  • Parses ladder logic, structured text, AOIs, UDTs, tag databases, device configs
  • Benchmarks show zero errors with independent controls engineers

What I Learned Stealing Ideas from Matt Pocock’s `.agents` Directory

What I Learned Stealing Ideas from Matt Pocock’s .agents Directory If you’ve spent more than ten minutes on TypeScript Twitter, you know Matt Pocock.

  • Matt Pocock's .agents directory teaches importance of context and guardrails for AI agents
  • Explicit "do not" lists prevent unwanted changes and break team conventions
  • Repository structure includes role definitions, explicit rules, and context injection patterns

Robots That Walk and Talk Are Coming To Car Factories

An anonymous reader quotes a report from The New York Times: At a BMW factory in South Carolina, a human-shaped robot with a screen for a face recently stepped from a charging station toward a stack…

  • BMW unveils humanoid robot at Spartanburg factory
  • Robot demonstrates sluggish, human-like movements
  • Humanoid robots aim to revolutionize U.S. manufacturing