Skip to content
العربية

Coming from Zig

Meem is closer to Zig than to any teaching language: an allocator is a value that is passed around, خاتمه corresponds to defer, and !نوع corresponds to !T. Zig was not installed on the analysis machine, so what is said here about Zig comes from its documentation and is not tried.

In Zig In Meem
passing a std.mem.Allocator the allocator as the last argument, which may be left out, and then الافتراضي is passed
ArenaAllocator ساحة(الاصل) and اعد
FixedBufferAllocator مخزن_ثابت
GeneralPurposeAllocator in debugging the detector, on by default in meem برنامج.م and with --debug in meem build; --debug-mem adds the leak report
defer / errdefer خاتمه / خاتمه_عند_خطأ
!T, try, catch !نوع, جرّب, والا
error{...} an اخطاء: (errors) block, and an optional error set in the signature: !{غير_موجود, ممنوع} نص (since 0.11.0)
?T ن؟ (since 0.11.0), with والا (else) for a fallback
fn max(comptime T: type, ...) داله اكبر[ن](ا ن, ب ن) ن:, inferred from the arguments (since 0.15.0)
Debug / ReleaseFast a direct run with the detector / meem build or --release without it. Bounds and overflow are checked in both modes, and بلا_فحص inside خطر switches that off locally
خاتمه, like defer
داله عالج(ن عدد64) نص:
اطبع("فتح المورد ", ن)
خاتمه اطبع("إغلاق المورد ", ن)
خاتمه اطبع("تنظيف أول")
اذا ن < 0:
ارجع "سالب"
اطبع("عمل على ", ن)
ارجع "تم"
اطبع(عالج(5))
اطبع("---")
اطبع(عالج(-1))
Output recorded from the compilermeem ذاكرة_خاتمه.م · meem 0.17.3+434e13f
فتح المورد 5عمل على 5تنظيف أولإغلاق المورد 5تم---فتح المورد -1تنظيف أولإغلاق المورد -1سالب
خاتمه_عند_خطأ, like errdefer
اخطاء:
ملف_تالف
داله حمّل(صالح منطقي) !عدد64:
اطبع("فتح")
خاتمه اطبع("إغلاق")
خاتمه_عند_خطأ اطبع("تراجع عن نصف العمل")
اذا !صالح:
ارجع خطأ.ملف_تالف
ارجع 42
اطبع(حمّل(صواب) والا -1)
اطبع("---")
اطبع(حمّل(خطاء) والا -1)
Output recorded from the compilermeem اخطاء_عند_خطأ.م · meem 0.17.3+434e13f
فتحإغلاق42---فتحتراجع عن نصف العملإغلاق-1

Where Meem departs from Zig’s model (0.17.1)

Section titled “Where Meem departs from Zig’s model (0.17.1)”
  • «No hidden allocation» is the rule since 0.10.0, with one exception: growing with ن += ذيل leaves the old buffer behind (a bounded leak of about twice the final length). In 0.9.1, operations on a «view» allocated copies that were never given back.
  • Slices and strings: a string is {pointer, length, owner}, and a view is a string on the bytes of another string, living as long as it does.
  • No comptime: generics use type parameters copied for each combination, and a constraint is a trait (سمة and يحقق, since 0.17.0), not code run at compile time.
  • No user-written allocators, and no resize or alignment.
  • The detector works at run time, not compile time, it does not see C memory, and حرر does not follow what is inside a container (no deep deinit).
  • No full error trace: «نشأ في» (originated in) with the line of the first ارجع that returned it, and a «ثم» (then) line for each جرّب it passed through in a direct run (since 0.11.0); Zig has a full error return trace in debug builds.

Memory in Meem · Dealing with errors · Meem compared with C and Zig