#ifndef WITH99_H #define WITH99_H #include #include #include #include #include #include #include #if !ML99_VERSION_COMPATIBLE(1, 13, 2) #error Your Metalang99 is a bit mouldy, update to v1.13.2 or later. #endif #define WITH99_MAJOR 1 #define WITH99_MINOR 0 #define WITH99_PATCH 0 #define WITH99_VERSION_COMPATIBLE(x, y, z) (WITH99_MAJOR == (x) && ((WITH99_MINOR == (y) && WITH99_PATCH >= (z)) || (WITH99_MINOR > (y)))) #define WITH99_VERSION_EQ(x, y, z) (WITH99_MAJOR == (x) && WITH99_MINOR == (y) && WITH99_PATCH == (z)) #define WITH99_PRIV_IF_ERROR(code)\ if (!(code)) #define WITH99_priv_res2stmt(f, maybe) ML99_call(v(WITH99_priv_res2stmt), f, maybe) #define WITH99_priv_res2stmt_IMPL(f, maybe)\ ML99_if(\ ML99_isJust(v(maybe)),\ ML99_appl(\ ML99_reify(v(f)),\ ML99_maybeUnwrap(v(maybe))\ ),\ v()\ ) #define WITH99_priv_res2stmts_IMPL(tDeclInitDeinit)\ ML99_TERMS(\ WITH99_priv_res2stmt(v(ML99_INTRODUCE_VAR_TO_STMT), ML99_tupleGet(0)(v(tDeclInitDeinit))),\ WITH99_priv_res2stmt(v(WITH99_PRIV_IF_ERROR), ML99_tupleGet(1)(v(tDeclInitDeinit))),\ WITH99_priv_res2stmt(v(ML99_CHAIN_EXPR_STMT_AFTER), ML99_tupleGet(2)(v(tDeclInitDeinit)))\ ) #define WITH99_priv_create_stmt_IMPL(tResNameArgs)\ ML99_call(\ WITH99_priv_res2stmts,\ ML99_call(\ ML99_cat(v(WITH99_resource_), ML99_tupleGet(0)(v(tResNameArgs))),\ ML99_tupleTail(v(tResNameArgs))\ )\ ) #define WITH99_priv_create_stmt_ARITY 1 #define WITH99_With(...) ML99_EVAL(WITH99_with(v(__VA_ARGS__))) #define WITH99_with(...) ML99_call(WITH99_with, __VA_ARGS__) #define WITH99_with_IMPL(...) ML99_variadicsForEach(v(WITH99_priv_create_stmt), v(__VA_ARGS__)) #endif