One .md file holds the prose and the program. midad type-checks it, runs it in an interpreter, or compiles it to a native binary through your C compiler, or through a built-in Cranelift backend.ملف .md واحد يجمع الشرح والبرنامج. تفحص midad الأنواع، وتشغّله بمفسِّر، أو تحوّله إلى برنامج تنفيذي أصلي عبر مترجم C لديك، أو عبر واجهة Cranelift المدمجة إن لم يوجد مترجم C.
cc -O2) or Craneliftواجهة C (cc -O2) أو CraneliftThe prose is the documentation and the fenced blocks are the code, so there is no second file to keep in sync. Conditions must be booleans, and a number never mixes with a float implicitly: both are errors before anything runs.الشرح هو التوثيق، والكتل المسوَّرة هي الكود، فلا ملف ثانٍ يجب مزامنته. يجب أن تكون الشروط قيماً منطقية، ولا يُخلط عدد صحيح بعدد عشري ضمناً: كلاهما خطأ قبل أن يعمل أي شيء.
On every example on this site, the interpreter, the C backend and the Cranelift backend print the same output.في كل مثال على هذا الموقع، يعطي المفسِّر وواجهة C وواجهة Cranelift المخرجات نفسها.
---
midad: "0.1"
module: report
---
# Order report
Totals are a function. The program is the `exec` block.
```fn
function total(prices: list): number {
let sum = 0;
for p in prices {
sum = sum + int(p);
}
return sum;
}
function average(prices: list): float {
return float(total(prices)) / float(len(prices));
}
```
```exec
let prices = [120, 45, 300, 16];
print("orders: " + str(len(prices)));
print("total: " + str(total(prices)));
print("average: " + str(average(prices)));
let units = idiv(total(prices), len(prices));
print("whole units per order: " + str(units));
```$ midad run report.md
orders: 4
total: 481
average: 120.25
whole units per order: 120
$ midad build report.md --native-all -o report
built: 17 KB (C backend) / 1.2 MB (Cranelift)| workload | interp | cranelift | C | Go |
|---|---|---|---|---|
| heavy | not run | 3666 | 1568 | 2616 |
| json | 15.8 | 9.9 | 1.3 | 39.0 |
| strcat | 6.8 | 1.4 | 0.5 | 6.2 |
| fib(27) | 141.3 | 1.8 | 1.4 | 2.0 |
| lists | 17.8 | 1.0 | 0.8 | 1.3 |
| splitjoin | 8.9 | 2.7 | 2.2 | 2.1 |
| loops | 452.8 | 18.3 | 8.8 | 7.2 |
| maps | 18.8 | 6.8 | 9.4 | 4.0 |
anyالقوائم والخرائط بلا أنواع: العنصر anyThe full list is docs/limits, rendered from docs/LIMITS.md at build time.القائمة الكاملة في docs/limits، مولَّدة من docs/LIMITS.md وقت البناء.
cargo install midad from crates.ioمن crates.iobrew install mdexec/tap/midad.sha256أرشيفات Linux (x86-64 وarm64) وmacOS (Apple silicon وIntel) على إصدار v0.2.0، ومع كل أرشيف .sha256git clone https://github.com/mdexec/midad && cd midad && cargo build --releaseأو من المصدر: git clone https://github.com/mdexec/midad && cd midad && cargo build --releasecc; the interpreter needs nothingواجهة C تحتاج cc؛ والمفسِّر لا يحتاج شيئاًlibmidad_rt.a. The 0.2.0 archives and cargo install carry the binary without it: build one with cargo build -p midad-rt --release and point MIDAD_RT_A at itتربط واجهة Cranelift الملف libmidad_rt.a. ولا يأتي هذا الملف مع أرشيفات الإصدار 0.2.0 ولا مع cargo install: ابنِه بالأمر cargo build -p midad-rt --release ثم اضبط MIDAD_RT_A على مساره