midad 0.1.0

generated from midad spec --json at build time; not edited by hand

Install 0.1.0

Download the archive for your machine from this release, check it, and put the binary on your path:

$ curl -LO https://github.com/mdexec/midad/releases/download/v0.1.0/midad-x86_64-unknown-linux-gnu.tar.gz
$ curl -LO https://github.com/mdexec/midad/releases/download/v0.1.0/midad-x86_64-unknown-linux-gnu.tar.gz.sha256
$ sha256sum -c midad-x86_64-unknown-linux-gnu.tar.gz.sha256
$ tar xzf midad-x86_64-unknown-linux-gnu.tar.gz
$ install -m 0755 midad ~/.local/bin/midad

The two macOS archives are in the same release, midad-aarch64-apple-darwin.tar.gz and midad-x86_64-apple-darwin.tar.gz. With cargo, cargo install midad --locked builds the latest published crate; add --version 0.1.0 to pin this one. Every install path is on the install page.

What changed

Summary: The first release of the language, in which a while loop whose bound is not a literal runs the number of times it should instead of zero.

Fixed: a while loop whose bound was not a literal ran zero times

A top-level loop like

let n = 3;
let i = 0;
while (i < n) {
  i = i + 1;
}
print(str(i));      // printed 0

printed 0 and exited with status 0. No diagnostic, no error, just a wrong answer. The compiled path (crates/midad-core/src/vm.rs) recorded the jump slot before emitting the loop condition, so patching the jump overwrote the condition's first instruction. The loop then tested a value that was never pushed, the value stack was empty, and the executor's unwrap_or(false) read that emptiness as "condition is false" and left the loop.

What was affected: any while in a block the bytecode compiler accepted whose condition was not variable <op> literal. while (i < 3) worked because it takes the fused compare, and while (i < len(xs)) worked because a call made the block fall back to the tree walker. Loops inside functions were unaffected for the same reason: a return made the compiler decline the block. That is why the benchmark suite, which loops inside functions over literal bounds, never saw it.

What to do: nothing, if you are on this commit or later. If you are on an earlier one, upgrade; do not paper over it by rewriting the bound as a literal.

Two changes: the jump slot is now taken after the condition is emitted, and the compiled path refuses an empty value stack with an internal error instead of inventing false, because an invented value is what made a compiler bug look like an answer. Six tests in crates/midad-core/tests/runtime.rs pin the bound shapes (literal, variable, const, call, float, <=, !=, decrementing, nested, and the same loop inside a function), plus the sibling conditions that share the code path (if, &&, ||).

get(map, key) on a missing key returns None

get returned a null value for a key that was not there. It now returns an empty option, which is what docs/LLM-BRIEF.md documented and what the C backend already did, so the interpreter was the odd one out.

Why it matters: the obvious way to read an optional field failed.

unwrap_or(get(get(req, "headers"), "x-user"), "anonymous")

gave null instead of "anonymous", and the next + on it failed with operator cannot combine string and null.

What to do:

  • Reading a key you know is there needs no change: get still returns the value itself, not Some(value).
  • Reading a key that may be absent: unwrap_or(get(m, "k"), default), is_none(get(m, "k")), or if let Some(v) = ....
  • is_null(get(m, "k")) no longer holds; is_null still exists for the runtime's internal missing-value cases.

unwrap_or's own semantics are unchanged: it replaces an empty option, not a null.

html("NAME", {"k": v}) binds a template's holes

A template used to render in the caller's scope, so it could only be used where its data happened to be named the same. The second argument binds names for the holes, and the checker binds the map's literal keys so a misspelled hole is E0241 at check time. Old calls without a map still work.

before blocks: middleware and per-request state

A before block runs on every matched request, in the same scope its route then runs in, so what it declares is the request's state and a return respond(...) in it answers the request. A before block in an imported file is refused (E0319); a before block with no routes is E0255.

A route can mount a handler: route:GET /items api.list

A library could not offer a route, because routes belong to the file that serves them. It still does not decide what is served, but it can supply the code: the fence names a function, the body is empty, and the function takes one map and returns a map. E0257 if the signature is wrong, E0256 if there is no such function, E0173 if a route has both a handler and a body. A before block still runs first.

Imports carry namespaces

An imported file's declarations are reached through its module: name (money.total(...), store.count, html("view.page")), or an as alias. A bare name that two files declare is an error, not a silent choice.

The name

First version with a name. Before this the language was called mdx; the frontmatter key mdx: "0.1" is still accepted.

On this page