Initial commit.
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
#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 1
|
||||
|
||||
#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_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_throw_match_0_IMPL(tResNameArgs)\
|
||||
ML99_appl(ML99_reify(v(ML99_CHAIN_EXPR_STMT)),\
|
||||
ML99_appl(ML99_reify(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_appl(ML99_reify(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_appl(ML99_reify(v(WITH99_PRIV_DECLARE_RESOURCE)),\
|
||||
ML99_untuple(v(tResNameArgs))\
|
||||
)\
|
||||
),\
|
||||
ML99_boolMatchWithArgs(\
|
||||
ML99_appl(\
|
||||
ML99_reify(\
|
||||
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_appl(ML99_reify(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_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
|
||||
Reference in New Issue
Block a user