Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mikea committed Jun 11, 2024
1 parent 4540c15 commit 2d612b2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

See also:

- [Rbuik's 2x2 Cube](examples/rubik-2x2.md)
- [Rubik's 2x2 Cube](examples/rubik-2x2.md)

## Advanced Calculator

Expand Down
33 changes: 20 additions & 13 deletions src/words.c++
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#include "print.h"
#include "words.h"

// common utilities
#pragma region support

#pragma region ffi1_support

void global_dict_add_ffi1(str n, const ffi1_table& ffi) {
global_dict_add_new({string(n), array::create(T_FFI, ffi.size(), ffi.begin())});
Expand Down Expand Up @@ -84,6 +86,17 @@ struct fn_1_1_registrar {
}
};

#define REG_FN_1_1(name, y_t, fn) \
ttX struct name##_k { \
using Y = y_t; \
ALWAYS_INLINE Y::t apply(X::t x) { return fn(x); } \
}; \
fn_1_1_registrar<name##_k, c8_t, i64_t, f64_t> name##_registrar(#name);

#pragma endregion ffi1_support

#pragma region ffi2_support

void global_dict_add_ffi2(str n, const ffi2_table& ffi) {
global_dict_add_new({string(n), array::create(T_FFI, ffi.size() * ffi.size(), ffi.begin())});
}
Expand All @@ -96,6 +109,10 @@ struct ffi2_registrar {
}
};

#pragma endregion ffi2_support

#pragma endregion support

#pragma region stack

DEF_WORD("dup", dup) { DUP; }
Expand Down Expand Up @@ -172,18 +189,8 @@ DEF_WORD("2over", _2over) {

#pragma region bool

#define REG_FN_1_1(name, y_t, fn) \
ttX struct name##_k { \
using Y = y_t; \
ALWAYS_INLINE Y::t apply(X::t x) { return fn(x); } \
}; \
fn_1_1_registrar<name##_k, i64_t, f64_t> name##_registrar(#name);

ttX struct not_impl {
using Y = i64_t;
inline static Y::t apply(X::t x) { return !x; }
};
fn_1_1_registrar<not_impl, c8_t, i64_t, f64_t> not_registrar("not");
ttX X not_impl(X x) { return !x; }
REG_FN_1_1(not, i64_t, not_impl);

#pragma endregion bool

Expand Down

0 comments on commit 2d612b2

Please sign in to comment.