midad 0.1.1
generated from midad spec --json at build time; not edited by hand
Install 0.1.1
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.1/midad-x86_64-unknown-linux-gnu.tar.gz
$ curl -LO https://github.com/mdexec/midad/releases/download/v0.1.1/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.1 to pin this
one. Every install path is on the install page.
What changed
Summary: / is real division with idiv for the floor, integer overflow is refused on every backend including Cranelift, and a compiled program reports a runtime error in the same one-line form and exit status as the interpreter.
Breaking changes (read before upgrading from 0.1.0)
/is real division.7 / 2is now 3.5, not 3, on every path. Integer division isidiv(a, b), which floors (idiv(-7, 2)is -4).midad checkwarns W008 at every/between two numbers.x /= 2on anumbervariable is now a type error. Details: "/is real division" below.- Integer overflow is refused on the Cranelift backend. It used to wrap
silently (
9223372036854775807 + 1printed a negative number). It now stops withinteger overflow, like the interpreter and the C backend. A tight arithmetic loop is slower for it (a 300-million-iteration add, multiply and remainder loop went from 217 ms to 327 ms;heavy+4%, measured in BENCHMARKS.md). - Runtime errors have one format. Compiled programs (C and Cranelift) now
print one line,
midad runtime error: <message>, and exit with status 1. The C backend usedmdx: <message>and status 70, and Cranelift could abort with a signal. The interpreter keeps its source-locatedR0001diagnostic and exit 1. Anything that matched the old text or the status 70 must change. - Mixing a number and a float is a compile error (E0230), as it was, and now
says how to convert:
float(a) == b. Nothing changed in behaviour; it is listed so no one expects an implicit conversion. - Exponent literals (
1e21) are refused with a clear message. They never parsed; only the message changed.
Also new: functions as arguments (fn parameters), for x in xs, and clearer
diagnostics for ?:, for x of, for (x in), for i in 0..3. Fixed: the four
execution paths disagreed on overflow, string order, float text, float negation,
chars and unwrap_or on an error in the C backend, and int() of a huge float
crashed Cranelift binaries.
Fixed: the four execution paths disagreed
A differential pass over arithmetic and printing found these; each now has a test that runs the same program on the interpreter, Cranelift and C and requires the same answer, or a refusal on all three.
- Cranelift wrapped on integer overflow (
9223372036854775807 + 1printed-9223372036854775808) where the interpreter and C refused. It now refuses on+,-,*, unary-, and the smallest number divided by -1. - The C backend compared strings wrongly (
"a" < "b"was false). It now compares in byte order, like the interpreter. - The C backend printed floats with 17 digits (
1 / 3as0.33333333333333331). It now prints the shortest text that reads back as the same number, like the interpreter. The same applies tomidad build --native FN. - The C backend returned 0 for the smallest number
%-1; it refuses withinteger overflow, like the interpreter. - The bytecode VM could not negate a float:
-3.9stopped with "operator cannot combine int and float" while both native backends printed it.
Cost, measured: the Cranelift overflow checks slow a tight add, multiply and remainder loop by about 50% (217 ms to 327 ms, median of 7 interleaved runs of 300 million iterations, one box). Cranelift numbers in BENCHMARKS.md were taken before the checks and are not re-measured.
Fixed in the C backend (found by the list, map, option and result diff cases)
chars(s) generated a call to a function that did not exist, so any program using it failed at link time; it now splits by Unicode character like the interpreter. unwrap_or(Err(..), d) returned 0 or an empty value instead of d on a string, number or float default; it now returns d. Both are covered by four_paths.rs. Backends may still decline a program at build time as unsupported (for example Cranelift for map len); the new tests allow that refusal but fail on a build that errors any other way.
One runtime-error scheme on every path
A refused operation now looks the same on the interpreter, the C backend and Cranelift: the message core is identical (integer overflow, division by zero, `int`: not an integer, `int`: out of range, ...), native binaries print one line midad runtime error: <message> and exit with status 1 (the C backend used mdx: ... and 70; Cranelift aborted with a signal on some traps). The interpreter keeps its source-located diagnostic (R0001) and exit 1. int() of an out-of-range float crashed Cranelift binaries with SIGILL; it now refuses. four_paths.rs asserts the status, the line shape and the message on all three.
Mixing number and float
1 == 1.0, 1 + 1.0 and 1 < 1.0 stay compile errors (E0230) on every path: midad has no implicit number-to-float conversion, and a silent one would be a rule to learn. The error now says to convert one side, for example float(a) == b.
Better diagnostics for constructs midad does not have
Exponent literals such as 1e21 now say exponent notation is not supported and to write the number out; before, the error was a vague "expected )".
c ? a : b now says midad has no ?: and shows the if form. for x of xs,
for (x in xs), for i in 0..3 and for x in 3 each name what to write. One
bad line no longer produces a second, unrelated error: a failed let does not
turn every later use into "unknown variable", a value that fails to type-check
still binds its name, and a bad statement in exec no longer also reports "no
entry point".
Functions as arguments
A parameter typed fn takes the name of a function: twice(double, 3). There
are no closures and no function values. Each distinct function passed gets one
ordinary, separately type-checked copy of the callee before checking, so all
four execution paths run plain code and agree. Permissions stay static. Not
supported: storing, returning, let-binding or computing a function name, and
captured variables. New codes E0341 to E0346 and warning W009 (a function with a
fn parameter that is never called is not checked). Example:
examples/function_refs.md. Nothing that ran before changes: fn was not a
valid type name.
Breaking: / is real division, and idiv(a, b) is integer division
7 / 2 used to print 3. It prints 3.5 now, on every path. Integer division is
idiv(a, b), which floors rather than truncating: idiv(-7, 2) is -4 and
idiv(7, -2) is -4, the same answers Python gives. A zero denominator is still
division by zero, and the one pair that cannot be divided, idiv of the
smallest number by -1, is integer overflow.
What to do: a / that meant an integer quotient becomes idiv(a, b). A /
that wanted a real quotient keeps /, and its result is a float. midad check
warns W008 at every / with two number operands, because that is exactly
where the old meaning was. x /= 2 means x = x / 2, so on a number variable
it is now a type error rather than a silent integer divide.
Two examples changed with it: examples/links-app/lib/store.md (base32 decode,
which wanted integers) and examples/inventory/report.md (tax in whole units).
This also fixes a command bug found on the way: midad run and midad build
refused to run whenever any diagnostic existed, warnings included, so the
snake_case lints could stop a program from running. Warnings are advice now, and
only errors stop a run or a build.
Added: for x in xs
A list is now walked without an index:
let total = 0;
for n in nums {
total = total + int(n);
}
x is one element of the list, so it is a list element like at(nums, i) and
needs the same cast before arithmetic or comparison. The loop is spelled out at
parse time as a while over a hidden index with at, which is why break and
continue work in it, why it runs on the interpreter, the bytecode VM, the C
backend and Cranelift, and why the index is advanced at the top of the body:
continue cannot skip it and spin forever. The list expression is evaluated
once, not once per iteration.
Nothing that parsed before parses differently.