Coming from C
Like C, Meem compiles to machine code (through LLVM), and its memory is manual. But it always checks arithmetic and indexing, and it writes errors as values in the signature.
What corresponds to what
Section titled “What corresponds to what”| In C | In Meem |
|---|---|
int8_t .. int64_t, uint8_t .. uint64_t, float, double, bool |
عدد8 .. عدد64, طبيعي8 .. طبيعي64, كسر32, كسر64, منطقي; widening is implicit and narrowing is explicit and checked (عدد8(ن)) |
zero-terminated char * |
نص: UTF-8 with its length, and طول counts characters, not bytes |
struct |
هيكل (struct): passed by value; several return values with a tuple: (خارج عدد64, باقي عدد64) |
a tagged union |
an تعداد (enum) with a payload: دائرة(نق كسر64), unpacked with حالات (since 0.15.0) |
| fixed array / growable array | مصفوفة[نوع, حجم] (copied on assignment) / قائمة[نوع] |
malloc / free |
allocation from an allocator (usually implicit) / حرر(س) |
T * and NULL |
مؤشر[نوع] with جديد and محتوى, and لاشيء; no pointer arithmetic |
void * from a library |
مؤشر_خام, readable only inside خطر |
a return code and errno |
!نوع and خطأ.اسم, and handling them is mandatory |
goto cleanup |
خاتمه and خاتمه_عند_خطأ |
#include |
استورد |
printf |
اطبع with commas, and رياضيات.نسق and نسق_عدد for formatting |
| undefined overflow | a runtime error with code 3; wrapping is explicit: جمع_ملتف (wrapping add) and its siblings for one operation, --fast for the whole program |
| calling a C library | خارجي with explicit C types |
خارجي "m" داله جذر_c(س كسر64) كسر64 باسم "sqrt"خارجي داله طول_c(ن نص) طبيعي64 باسم "strlen"اطبع(جذر_c(2.0))اطبع("ميم بالبايتات: ", طول_c("ميم"), "، وبالأحرف: ", طول("ميم"))كبير = 9223372036854775807اطبع(كبير)اطبع(كبير + 1)Exit code: 3
In the error catalog: E0341
What will surprise you (from writing real programs with 0.9.1, reviewed on 0.17.1)
Section titled “What will surprise you (from writing real programs with 0.9.1, reviewed on 0.17.1)”- Two modes, as in Zig:
meem برنامج.مruns the program with a memory detector that catches use after free and double free, naming both lines, whilemeem buildbuilds without the detector, and in that file use after free through another name is undefined behaviour, as in C. Build with--debugto keep the detector. حررdoes not follow: freeing a list of lists leaves the inner lists, likefreeon an array of pointers.- Characters before bytes:
طولandجزءwork in characters; byte operations have explicit names (طول_بايت,جزء_بايت,بايتات_نص, since 0.14.0). - Generics by copying:
داله اكبر[ن](...)andهيكل زوج[ا, ب]:are copied for each combination of types, and a constraint is a trait ([ن يحقق قابل_للمقارنة], since 0.17.0); there is no dynamic polymorphism. - A
هيكل_سيmust be defined before the declaration that uses it. - An error is a value with a small context (since 0.11.0): a name, a message and a cause, and «نشأ في» (originated in) with the line of the first
ارجعthat returned it; there is no full stack trace. - No
printfand no variadic functions, and no structs by value to C. - The static build (musl) is slower than
--dynamicin allocation-heavy programs.
And what you will like
Section titled “And what you will like”- Bounds and overflow are checked by default, with a message giving the line and the ID.
خاتمهandخاتمه_عند_خطأrun in the right order across functions.- A static executable of tens of kilobytes, built in about a second.
- Algorithmic code performs on a par with C (Dijkstra and a search tree).
خارجيis one line per function, and the symbol is checked at compile time.
See also
Section titled “See also”Memory in Meem · What is خطر? · Meem compared with C and Zig · Calling C