72 lines
2.5 KiB
C
72 lines
2.5 KiB
C
#ifndef WITH99_H
|
|
#define WITH99_H
|
|
|
|
#include <metalang99.h>
|
|
#include <metalang99/tuple.h>
|
|
#include <metalang99/util.h>
|
|
#include <metalang99/lang.h>
|
|
#include <metalang99/bool.h>
|
|
|
|
#if !ML99_VERSION_COMPATIBLE(1, 13, 2)
|
|
#error Your Metalang99 is a bit mouldy, update to v1.13.2 or later.
|
|
#endif
|
|
|
|
#define WITH99_VERSION 2
|
|
|
|
#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_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)\
|
|
ML99_appl(ML99_reify(v(ML99_CHAIN_EXPR_STMT)),\
|
|
ML99_call(v(WITH99_priv_init_resource),\
|
|
ML99_untuple(v(tResNameArgs))\
|
|
)\
|
|
)
|
|
|
|
#define WITH99_PRIV_IF_ERROR(code)\
|
|
if (!code)
|
|
|
|
#define WITH99_priv_throw_match_1_IMPL(tResNameArgs)\
|
|
ML99_appl(ML99_reify(v(WITH99_PRIV_IF_ERROR)),\
|
|
ML99_call(v(WITH99_priv_init_resource),\
|
|
ML99_untuple(v(tResNameArgs))\
|
|
)\
|
|
)
|
|
|
|
#define WITH99_priv_create_stmt_IMPL(tResNameArgs)\
|
|
ML99_appl(ML99_reify(v(ML99_INTRODUCE_VAR_TO_STMT)),\
|
|
ML99_call(v(WITH99_priv_declare_resource),\
|
|
ML99_untuple(v(tResNameArgs))\
|
|
)\
|
|
),\
|
|
ML99_boolMatchWithArgs(\
|
|
ML99_call(\
|
|
v(WITH99_priv_throws_resource),\
|
|
ML99_untuple(v(tResNameArgs))\
|
|
),\
|
|
v(WITH99_priv_throw_match_),\
|
|
v(tResNameArgs)\
|
|
),\
|
|
ML99_appl(ML99_reify(v(ML99_CHAIN_EXPR_STMT_AFTER)),\
|
|
ML99_call(v(WITH99_priv_free_resource),\
|
|
ML99_untuple(v(tResNameArgs))\
|
|
)\
|
|
)
|
|
|
|
|
|
#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__))
|
|
|
|
#endif
|