There's a reason why people switch from C...
This commit is contained in:
parent
c9ade57580
commit
a513a5f50a
14
README.md
14
README.md
@ -6,20 +6,18 @@
|
|||||||
|
|
||||||
#include <with99.h>
|
#include <with99.h>
|
||||||
|
|
||||||
#define WITH99_RESOURCE_TYPE_intptr(...) int*
|
#define WITH99_resource_type_intptr_IMPL(...) v(int*)
|
||||||
#define WITH99_RESOURCE_INIT_intptr(res, ...) (printf("Allocated to %p\n", res), *res = malloc(sizeof(int)), 0)
|
#define WITH99_resource_init_intptr_IMPL(var, init, ...) v((printf("Allocated to %p\n", var), var = malloc(sizeof(int)), *var = init, 0))
|
||||||
#define WITH99_RESOURCE_FREE_intptr(res, ...) (printf("Freed %p at %p\n", res, *res), free(*res))
|
#define WITH99_resource_free_intptr_IMPL(var, ...) v((printf("Freed %p at %p\n", var, var), free(var)))
|
||||||
#define WITH99_RESOURCE_THROWS_intptr(res, ...) 0
|
#define WITH99_resource_throws_intptr_IMPL(...) ML99_false()
|
||||||
|
|
||||||
#define With WITH99_With
|
#define With WITH99_With
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
With(
|
With(
|
||||||
(intptr, a),
|
(intptr, a, 1),
|
||||||
(intptr, b)
|
(intptr, b, 3)
|
||||||
) {
|
) {
|
||||||
*a = 1;
|
|
||||||
*b = 2;
|
|
||||||
*a += *b;
|
*a += *b;
|
||||||
printf("%d\n", *a);
|
printf("%d\n", *a);
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <metalang99.h>
|
#include <metalang99.h>
|
||||||
#include <metalang99/tuple.h>
|
#include <metalang99/tuple.h>
|
||||||
|
#include <metalang99/variadics.h>
|
||||||
#include <metalang99/util.h>
|
#include <metalang99/util.h>
|
||||||
#include <metalang99/lang.h>
|
#include <metalang99/lang.h>
|
||||||
#include <metalang99/bool.h>
|
#include <metalang99/bool.h>
|
||||||
@ -11,22 +12,34 @@
|
|||||||
#error Your Metalang99 is a bit mouldy, update to v1.13.2 or later.
|
#error Your Metalang99 is a bit mouldy, update to v1.13.2 or later.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define WITH99_VERSION 2
|
#define WITH99_MAJOR 0
|
||||||
|
#define WITH99_MINOR 1
|
||||||
|
#define WITH99_PATCH 1
|
||||||
|
|
||||||
#define WITH99_priv_restype_IMPL(res, ...) ML99_call(ML99_cat(v(WITH99_resource_type_ ), v(res)), v(__VA_ARGS__))
|
#define WITH99_VERSION_COMPATIBLE(x, y, z) (WITH99_MAJOR == (x) && ((WITH99_MINOR == (y) && WITH99_PATCH >= (z)) || (WITH99_MINOR > (y))))
|
||||||
#define WITH99_priv_resinit_IMPL(res, ...) ML99_call(ML99_cat(v(WITH99_resource_init_ ), v(res)), v(__VA_ARGS__))
|
#define WITH99_VERSION_EQ(x, y, z) (WITH99_MAJOR == (x) && WITH99_MINOR == (y) && WITH99_PATCH == (z))
|
||||||
#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_restype_IMPL(tResNameArgs) ML99_call(ML99_cat(v(WITH99_resource_type_ ), ML99_tupleGet(0)(v(tResNameArgs))), ML99_tupleTail(v(tResNameArgs)))
|
||||||
#define WITH99_priv_init_resource_IMPL(res, name, ...) ML99_call(v(WITH99_priv_resinit), v(res), v(&name), v(__VA_ARGS__))
|
#define WITH99_priv_resinit_IMPL(tResNameArgs) ML99_call(ML99_cat(v(WITH99_resource_init_ ), ML99_tupleGet(0)(v(tResNameArgs))), ML99_tupleTail(v(tResNameArgs)))
|
||||||
#define WITH99_priv_free_resource_IMPL(res, name, ...) ML99_call(v(WITH99_priv_resfree), v(res), v(&name), v(__VA_ARGS__))
|
#define WITH99_priv_resfree_IMPL(tResNameArgs) ML99_call(ML99_cat(v(WITH99_resource_free_ ), ML99_tupleGet(0)(v(tResNameArgs))), ML99_tupleTail(v(tResNameArgs)))
|
||||||
#define WITH99_priv_throws_resource_IMPL(res, name, ...) ML99_call(v(WITH99_priv_resthrows), v(res), v(__VA_ARGS__))
|
#define WITH99_priv_resthrows_IMPL(tResNameArgs) ML99_call(ML99_cat(v(WITH99_resource_throws_), ML99_tupleGet(0)(v(tResNameArgs))), ML99_tupleTail(v(tResNameArgs)))
|
||||||
|
|
||||||
|
|
||||||
|
#define WITH99_priv_uncomma(...) ML99_call(v(WITH99_priv_uncomma), v(__VA_ARGS__))
|
||||||
|
|
||||||
|
// ASDIOJSAOIdmnlaskdjasoid;asjl
|
||||||
|
// ML99_uncomma breaks shit
|
||||||
|
#define WITH99_priv_uncomma_IMPL(...) ML99_abort(ML99_variadicsForEach(v(ML99_id), __VA_ARGS__))
|
||||||
|
|
||||||
|
#define WITH99_priv_declare_resource_IMPL(tResNameArgs) ML99_call(v(WITH99_priv_restype), v(tResNameArgs)), ML99_tupleGet(1)(v(tResNameArgs))
|
||||||
|
#define WITH99_priv_init_resource_IMPL(tResNameArgs) ML99_call(v(WITH99_priv_resinit), v(tResNameArgs))
|
||||||
|
#define WITH99_priv_free_resource_IMPL(tResNameArgs) ML99_call(v(WITH99_priv_resfree), v(tResNameArgs))
|
||||||
|
#define WITH99_priv_throws_resource_IMPL(tResNameArgs) ML99_call(v(WITH99_priv_resthrows), v(tResNameArgs))
|
||||||
|
|
||||||
#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(ML99_CHAIN_EXPR_STMT)),\
|
||||||
ML99_call(v(WITH99_priv_init_resource),\
|
ML99_call(v(WITH99_priv_init_resource),\
|
||||||
ML99_untuple(v(tResNameArgs))\
|
v(tResNameArgs)\
|
||||||
)\
|
)\
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -36,27 +49,29 @@
|
|||||||
#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_IF_ERROR)),\
|
||||||
ML99_call(v(WITH99_priv_init_resource),\
|
ML99_call(v(WITH99_priv_init_resource),\
|
||||||
ML99_untuple(v(tResNameArgs))\
|
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_TERMS(\
|
||||||
ML99_call(v(WITH99_priv_declare_resource),\
|
ML99_appl(ML99_reify(v(ML99_INTRODUCE_VAR_TO_STMT)),\
|
||||||
ML99_untuple(v(tResNameArgs))\
|
ML99_call(v(WITH99_priv_declare_resource),\
|
||||||
)\
|
v(tResNameArgs)\
|
||||||
),\
|
)\
|
||||||
ML99_boolMatchWithArgs(\
|
|
||||||
ML99_call(\
|
|
||||||
v(WITH99_priv_throws_resource),\
|
|
||||||
ML99_untuple(v(tResNameArgs))\
|
|
||||||
),\
|
),\
|
||||||
v(WITH99_priv_throw_match_),\
|
ML99_boolMatchWithArgs(\
|
||||||
v(tResNameArgs)\
|
ML99_call(\
|
||||||
),\
|
v(WITH99_priv_throws_resource),\
|
||||||
ML99_appl(ML99_reify(v(ML99_CHAIN_EXPR_STMT_AFTER)),\
|
v(tResNameArgs)\
|
||||||
ML99_call(v(WITH99_priv_free_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),\
|
||||||
|
v(tResNameArgs)\
|
||||||
|
)\
|
||||||
)\
|
)\
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user