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/midadThe 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 waymidad run file.md <command>does. A native binary used to refuse any program with a command; nowmain(argc, argv)matchesargv[1]against the commands, bindsargsto the words after it as a list of strings, runs that command alone (execdoes not run), and printsunknown command `name`to stderr with exit 2 for a name it does not have.commands_dispatch_like_the_interpretercompares 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 takingargs, the generated C main dispatches onargv[1]to it, andmidad_rt_args_fromturns 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.mdhas 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 (
concatcopies 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.mdhas 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 thestateblock 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 droppersist:. 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
whiledoes. All three paths render the same bytes, checked byfour_paths.rswith no refusal allowed, on a loop with a nestedif/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" }}orif 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
iffor a jump, aforover 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 byfour_paths.rson a template with a loop, a nestedif/elseand 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})rendersother; a native build reads the variable named after the hole, so it would have renderedname. 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 pairIter/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, anddocs/SPRINTS.mdrecords the shape the backends will emit. - A
beforeblock's state reaches a route answered by a handler. What abeforeblock declares is the request's state, but a handler only receives the request, so the two could not meet: the state is now copied intoreq["ctx"]after everybeforeblock runs, andctxexists as an empty map even with no middleware.lib/midad-webgainsrequest.ctx(req, name),ctx_textandctx_idto read it. - An HTML form can post to a route. A non-empty body was always parsed as JSON, so
<form method="post">(which sendsapplication/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 samereq["body"]map JSON bodies produce, sorequest.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-webgainsrequest.query(req, name)for query-string values. html:NAMEtemplates takefor name in list: a linefor x in itemswith its children indented under it, rendered once per element, withif/elsenesting 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 isany, the same asfor x in xsin the language. The iterable must be a list: a number is refused at render time with a message naming what it got. Likeif, 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:NAMEtemplates takeif/else: a lineif condwith its children indented under it, and an optional siblingelseat the same indentation. Only a boolean is a condition; anything else is refused with a message showing the shape to write (if x > 1, notif 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> --watchre-runs the program when a.mdfile next to it (ormidad.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 fmttakes a directory now:midad fmt .formats every.mdfile under it (the entry file, its imports, vendored libraries), skips.git,targetandnode_modules, and prints how many of how many changed.--checkreports each file that would change and exits 1;--stdoutstays 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 theelse;else if (…) { … }chains work the same way. A one-linewhileis unchanged.midad fmtkeeps 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-webvalidate.check_intaccepted no JSON integer: it comparedtype_of(x)with"number", a nametype_ofnever returns (it says"int"or"float"). It now checks"int", so a JSON3passes and3.5is rejected as not a whole number.type_ofkeeps naming the two kinds apart;numberstays the annotation word for the integer type. Fixed in the library and in both example apps' copies.- The
ffi_calls_libmtest named Linux shared objects only; it now pickslibSystem.B.dylibon macOS, so the foreign-call path is tested there too. Not run on a Mac from here.