diff --git a/include/with99.h b/include/with99.h index cab44fc..defbad9 100644 --- a/include/with99.h +++ b/include/with99.h @@ -11,21 +11,21 @@ #error Your Metalang99 is a bit mouldy, update to v1.13.2 or later. #endif -#define WITH99_VERSION 1 +#define WITH99_VERSION 2 -#define WITH99_PRIV_RESTYPE(res, ...) WITH99_RESOURCE_TYPE_ ## res (__VA_ARGS__) -#define WITH99_PRIV_RESINIT(res, ...) WITH99_RESOURCE_INIT_ ## res (__VA_ARGS__) -#define WITH99_PRIV_RESFREE(res, ...) WITH99_RESOURCE_FREE_ ## res (__VA_ARGS__) -#define WITH99_PRIV_RESTHROWS(res, ...) WITH99_RESOURCE_THROWS_ ## res (__VA_ARGS__) +#define WITH99_priv_restype_IMPL(res, ...) ML99_call(ML99_cat(v(WITH99_resource_type_ ), v(res)), v(__VA_ARGS__)) +#define WITH99_priv_resinit_IMPL(res, ...) ML99_call(ML99_cat(v(WITH99_resource_init_ ), v(res)), v(__VA_ARGS__)) +#define WITH99_priv_resfree_IMPL(res, ...) ML99_call(ML99_cat(v(WITH99_resource_free_ ), v(res)), v(__VA_ARGS__)) +#define WITH99_priv_resthrows_IMPL(res, ...) ML99_call(ML99_cat(v(WITH99_resource_throws_), v(res)), v(__VA_ARGS__)) -#define WITH99_PRIV_DECLARE_RESOURCE(res, name, ...) WITH99_PRIV_RESTYPE(res, __VA_ARGS__) name -#define WITH99_PRIV_INIT_RESOURCE(res, name, ...) WITH99_PRIV_RESINIT(res, &name, __VA_ARGS__) -#define WITH99_PRIV_FREE_RESOURCE(res, name, ...) WITH99_PRIV_RESFREE(res, &name, __VA_ARGS__) -#define WITH99_PRIV_THROWS_RESOURCE(res, name, ...) WITH99_PRIV_RESTHROWS(res, __VA_ARGS__) +#define WITH99_priv_declare_resource_IMPL(res, name, ...) ML99_TERMS(ML99_call(v(WITH99_priv_restype), v(res), v(__VA_ARGS__)), v(name)) +#define WITH99_priv_init_resource_IMPL(res, name, ...) ML99_call(v(WITH99_priv_resinit), v(res), v(&name), v(__VA_ARGS__)) +#define WITH99_priv_free_resource_IMPL(res, name, ...) ML99_call(v(WITH99_priv_resfree), v(res), v(&name), v(__VA_ARGS__)) +#define WITH99_priv_throws_resource_IMPL(res, name, ...) ML99_call(v(WITH99_priv_resthrows), v(res), v(__VA_ARGS__)) -#define WITH99_PRIV_throw_match_0_IMPL(tResNameArgs)\ +#define WITH99_priv_throw_match_0_IMPL(tResNameArgs)\ ML99_appl(ML99_reify(v(ML99_CHAIN_EXPR_STMT)),\ - ML99_appl(ML99_reify(v(WITH99_PRIV_INIT_RESOURCE)),\ + ML99_call(v(WITH99_priv_init_resource),\ ML99_untuple(v(tResNameArgs))\ )\ ) @@ -33,43 +33,39 @@ #define WITH99_PRIV_IF_ERROR(code)\ if (!code) -#define WITH99_PRIV_throw_match_1_IMPL(tResNameArgs)\ +#define WITH99_priv_throw_match_1_IMPL(tResNameArgs)\ ML99_appl(ML99_reify(v(WITH99_PRIV_IF_ERROR)),\ - ML99_appl(ML99_reify(v(WITH99_PRIV_INIT_RESOURCE)),\ + ML99_call(v(WITH99_priv_init_resource),\ ML99_untuple(v(tResNameArgs))\ )\ ) -#define WITH99_PRIV_create_stmt_IMPL(tResNameArgs)\ +#define WITH99_priv_create_stmt_IMPL(tResNameArgs)\ ML99_appl(ML99_reify(v(ML99_INTRODUCE_VAR_TO_STMT)),\ - ML99_appl(ML99_reify(v(WITH99_PRIV_DECLARE_RESOURCE)),\ + ML99_call(v(WITH99_priv_declare_resource),\ ML99_untuple(v(tResNameArgs))\ )\ ),\ ML99_boolMatchWithArgs(\ - ML99_appl(\ - ML99_reify(\ - v(WITH99_PRIV_THROWS_RESOURCE)\ - ),\ + ML99_call(\ + v(WITH99_priv_throws_resource),\ ML99_untuple(v(tResNameArgs))\ ),\ - v(WITH99_PRIV_throw_match_),\ + v(WITH99_priv_throw_match_),\ v(tResNameArgs)\ ),\ ML99_appl(ML99_reify(v(ML99_CHAIN_EXPR_STMT_AFTER)),\ - ML99_appl(ML99_reify(v(WITH99_PRIV_FREE_RESOURCE)),\ + ML99_call(v(WITH99_priv_free_resource),\ ML99_untuple(v(tResNameArgs))\ )\ ) -//#define WITH99_PRIV_create_stmt_IMPL(a) ML99_untuple(v(a)) - -#define WITH99_PRIV_create_stmt_ARITY 1 +#define WITH99_priv_create_stmt_ARITY 1 #define WITH99_With(...) ML99_EVAL(WITH99_with(__VA_ARGS__)) #define WITH99_with(...) ML99_call(WITH99_with, v(__VA_ARGS__)) -#define WITH99_with_IMPL(...) ML99_variadicsForEach(v(WITH99_PRIV_create_stmt), v(__VA_ARGS__)) +#define WITH99_with_IMPL(...) ML99_variadicsForEach(v(WITH99_priv_create_stmt), v(__VA_ARGS__)) #endif