midad 0.1.2

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

Install 0.1.2

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.2/midad-x86_64-unknown-linux-gnu.tar.gz
$ curl -LO https://github.com/mdexec/midad/releases/download/v0.1.2/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.2 to pin this one. Every install path is on the install page.

What changed

Summary: Templates gained if/else and for loops, a form can post without JavaScript in front of it, and both native backends build commands and branching templates instead of refusing them.

  • The C backend builds a program's command: blocks and dispatches them the way midad run file.md <command> does. A native binary used to refuse any program with a command; now main(argc, argv) matches argv[1] against the commands, binds args to the words after it as a list of strings, runs that command alone (exec does not run), and prints unknown command `name` to stderr with exit 2 for a name it does not have. commands_dispatch_like_the_interpreter compares the binary against the interpreter for a command with arguments, a command without, no command and an unknown name. The Cranelift backend builds them too: each command body compiles to a function taking args, the generated C main dispatches on argv[1] to it, and midad_rt_args_from turns the process arguments into the list of strings, so a command behaves the same on both native backends and interpreted.
  • Cranelift renders a template into one growable buffer too, and it is now the fastest path on the render benchmark: 93 ms against 406 ms before, where Go takes 149 ms. Its runtime has no growable string (a block is a refcount, a length and bytes, with no capacity), so it gained a render buffer of its own (midad_rt_buf_new, midad_rt_buf_put, midad_rt_buf_put_escaped, midad_rt_buf_done), the emitter carries it through the template's blocks, and the finished render becomes one block. Every template goes out as its instruction list now, flat or not, so the flat plan path is gone from this backend as it is from the C backend. BENCHMARKS.md has the row.
  • A render writes into one growable buffer instead of allocating per piece. The C backend's template path built a string per hole (escaping allocated) and copied the whole accumulated text on every append (concat copies both sides), so rendering a 50-row table 200,000 times took 302 ms against Go's 147 ms. The buffer is now pre-sized from the template's static text, literals are copied into it, holes are formatted or escaped straight into it, and the finished string takes the buffer's bytes, so a render allocates one string and nothing per piece: the same benchmark, rerun on a quiet box, is 131 ms against Go's 157 ms, where it was 302 ms against 147 ms. BENCHMARKS.md has the before and after, including the first run's 702 ms interpreter number, which was a concurrent build and not a regression. Cranelift still uses the old path (its runtime has no growable string), and the interpreter is unchanged on this row.
  • A native build refuses a program with persist:. The interpreter loads the state block from that file and writes it back after every run; nothing in the native runtime does, so a native binary built from such a program ran, printed the right output and silently lost the state (two runs both started from zero and no file was written). It is refused by name on both backends now, with a message saying to run it interpreted or drop persist:. Caught while measuring the render benchmark, not by a test; there is one now.
  • Cranelift renders a template that branches or loops. It emitted a template from the flat plan, so a native build refused one that branches or loops by name; it now emits the template's instruction list as blocks, with the output buffer as each block's parameter (the phi a jump target needs) and a loop that keeps its list, its index and the current item in locals the way the language's own while does. All three paths render the same bytes, checked by four_paths.rs with no refusal allowed, on a loop with a nested if/else, nested loops, a loop over numbers, a raw hole in a loop and a loop over an empty list. The one native limit is the element type: a native loop variable is a string, number or float, because the native subset has no dynamic values, so a loop over a list of lists is refused by name.
  • A string literal written inside a template expression builds on the C backend. It registered a template's literal text but not the string literals in its holes and conditions, so {{ "hi" }} or if x == "a" failed the build with "string literal missing from the table". Caught by a template loop over a list literal; fixed by collecting those literals too.
  • The C backend renders a template that branches or loops. A native build used to refuse such a template by name; it now emits the template's instruction list as C: one buffer per call, appended to as it goes, a real if for a jump, a for over the list's items for a loop with the loop variable assigned where the body starts (the back edge jumps there), and jump targets as C labels. The interpreter and the C backend render the same bytes, checked by four_paths.rs on a template with a loop, a nested if/else and a second call with an empty list. Cranelift still refuses one by name, which is a refusal, not a wrong answer.
  • A native build binds a template's holes by name, and now says so when the map disagrees. The interpreter reads a hole's value from the map you pass, so html("t", {"name": other}) renders other; a native build reads the variable named after the hole, so it would have rendered name. That is a silent wrong answer, so a native build refuses a map whose key does not name the variable of the same name. A map held in a variable, which the checker cannot read, gets the same refusal rather than a guess.
  • The template compiler is one instruction list now (Lit, Hole, JumpIfFalse, Jump, and a loop pair Iter/Next) that the interpreter runs, instead of a renderer that walked the nodes plus a separate flat plan built by re-rendering with marker characters. Nothing changes for a program: every template renders the same bytes, the flat plan the native backends read is that list without control flow, and docs/SPRINTS.md records the shape the backends will emit.
  • A before block's state reaches a route answered by a handler. What a before block declares is the request's state, but a handler only receives the request, so the two could not meet: the state is now copied into req["ctx"] after every before block runs, and ctx exists as an empty map even with no middleware. lib/midad-web gains request.ctx(req, name), ctx_text and ctx_id to read it.
  • An HTML form can post to a route. A non-empty body was always parsed as JSON, so <form method="post"> (which sends application/x-www-form-urlencoded) answered 400 "invalid JSON body" and forms needed JavaScript in front of them. A urlencoded body is now parsed into the same req["body"] map JSON bodies produce, so request.text(req, "title") reads either, and a body of another type is refused with a message naming the two types the server reads. lib/midad-web gains request.query(req, name) for query-string values.
  • html:NAME templates take for name in list: a line for x in items with its children indented under it, rendered once per element, with if/else nesting inside it and loops nesting inside elements, because indentation is the nesting. The variable is bound for the body only (a hole after the loop is an unknown name, E0241) and it is any, the same as for x in xs in the language. The iterable must be a list: a number is refused at render time with a message naming what it got. Like if, a loop is interpreter-only for now: the C and Cranelift backends render a template from a flat plan of text and hole positions, so a native build refuses a template that branches or loops rather than rendering something else.
  • html:NAME templates take if/else: a line if cond with its children indented under it, and an optional sibling else at the same indentation. Only a boolean is a condition; anything else is refused with a message showing the shape to write (if x > 1, not if x). Both branches are type-checked, not only the one that runs. The interpreter renders it; a native build refuses a template that branches, because the plan the C and Cranelift backends render from is still a flat sequence and cannot express a branch yet.
  • midad run <file.md> --watch re-runs the program when a .md file next to it (or midad.toml) changes. The program runs as a child process, so a program that exits or serves HTTP does not take the watcher with it, and a broken program keeps the watcher alive: the error is printed and the next edit re-runs it.
  • midad fmt takes a directory now: midad fmt . formats every .md file under it (the entry file, its imports, vendored libraries), skips .git, target and node_modules, and prints how many of how many changed. --check reports each file that would change and exits 1; --stdout stays one file. Formatting one file is unchanged.
  • A statement no longer ends at the end of its line: while a (, [ or { is still open, the next line continues it. So a list, a map or an argument list can be written one item per line, and a trailing comma before the closing bracket is allowed. let xs = [ … ]; used to be three parse errors; an unclosed bracket now says which bracket is open and what closes it (E0101) instead of "unexpected end of expression".
  • if (c) { a(); } else { b(); } on one line runs the else branch. It used to run the then-branch and then fail on the else; else if (…) { … } chains work the same way. A one-line while is unchanged.
  • midad fmt keeps a list, map or call written across lines where it was, indented one level deeper than the statement, and puts the closing bracket back at the statement's level. It used to pull every continuation line back to the left margin.
  • midad-web validate.check_int accepted no JSON integer: it compared type_of(x) with "number", a name type_of never returns (it says "int" or "float"). It now checks "int", so a JSON 3 passes and 3.5 is rejected as not a whole number. type_of keeps naming the two kinds apart; number stays the annotation word for the integer type. Fixed in the library and in both example apps' copies.
  • The ffi_calls_libm test named Linux shared objects only; it now picks libSystem.B.dylib on macOS, so the foreign-call path is tested there too. Not run on a Mac from here.
On this page