pforth  0943e5e71114f286dbb2474d55aabf91df02d104
words.h
Go to the documentation of this file.
1 #include "pforth.h"
2 #pragma once
3 
8 #ifdef EMBED_BUILD
9 #define _PRE_DEC
10 #define _POST_DEC __attribute__((naked))
11 #else
12 #define _PRE_DEC
13 #define _POST_DEC
14 #endif
15 #define _EMBED_DECORATE(FUNC) _PRE_DEC FUNC _POST_DEC
16 
18 
19 void _push(void* data, size_t size);
20 
21 #define _PRECOMPILED_WORDS
22 
23 _EMBED_DECORATE(void _push(void* data, size_t size));
24 
25 _EMBED_DECORATE(void _drop(size_t size));
26 
27 #define POP_WORD(TYPE) \
28  _EMBED_DECORATE(TYPE pop_ ## TYPE());
29 
30 #define PUSH_WORD(TYPE) \
31  _EMBED_DECORATE(void push_ ## TYPE(TYPE value));
32 
33 #define _MATH_OP(TYPE, NAME, OP) \
34  _EMBED_DECORATE(void M_CONC(_, M_CONC(NAME, M_CONC(_, TYPE))) ());
35 
36 #define _FIVE_MATH_OPS(TYPE) \
37  _MATH_OP(TYPE, add, +) \
38  _MATH_OP(TYPE, sub, -) \
39  _MATH_OP(TYPE, mul, *) \
40  _MATH_OP(TYPE, div, /) \
41  _MATH_OP(TYPE, mod, %)
42 
43 #define _COMPARE_OP(TYPE, NAME, OP) \
44  _EMBED_DECORATE(void M_CONC(_, M_CONC(NAME, M_CONC(_, TYPE))) ());
45 
46 #define _COMPARISON_OPS(TYPE) \
47  _COMPARE_OP(TYPE, gt, >) \
48  _COMPARE_OP(TYPE, lt, <) \
49  _COMPARE_OP(TYPE, ge, >=) \
50  _COMPARE_OP(TYPE, le, <=) \
51  _COMPARE_OP(TYPE, eq, ==) \
52  _COMPARE_OP(TYPE, neq, !=)
53 
54 #define _TRUE_OP(TYPE) \
55  _EMBED_DECORATE(int M_CONC(_, M_CONC(true, M_CONC(_, TYPE))) ());
56 
57 #define PUSH_POP_WORD(TYPE) PUSH_WORD(TYPE) POP_WORD(TYPE)
58 #define PUSH_POP_WORDS(...) PUSH_POP_WORD(__VA_ARGS__)
59 
60 #define EVAL0(...) __VA_ARGS__
61 #define EVAL1(...) EVAL0(EVAL0(EVAL0(__VA_ARGS__)))
62 #define EVAL2(...) EVAL1(EVAL1(EVAL1(__VA_ARGS__)))
63 #define EVAL3(...) EVAL2(EVAL2(EVAL2(__VA_ARGS__)))
64 #define EVAL4(...) EVAL3(EVAL3(EVAL3(__VA_ARGS__)))
65 #define EVAL(...) EVAL4(EVAL4(EVAL4(__VA_ARGS__)))
66 #define MAP_END(...)
67 #define MAP_OUT
68 #define MAP_GET_END() 0, MAP_END
69 #define MAP_NEXT0(test, next, ...) next MAP_OUT
70 #define MAP_NEXT1(test, next) MAP_NEXT0(test, next, 0)
71 #define MAP_NEXT(test, next) MAP_NEXT1(MAP_GET_END test, next)
72 #define MAP0(f, x, peek, ...) f(x) MAP_NEXT(peek, MAP1) (f, peek, __VA_ARGS__)
73 #define MAP1(f, x, peek, ...) f(x) MAP_NEXT(peek, MAP0) (f, peek, __VA_ARGS__)
74 #define MAP(f, ...) EVAL(MAP1(f, __VA_ARGS__, (), 0))
75 
76 #define M_CONC(A, B) M_CONC_(A, B)
77 #define M_CONC_(A, B) A ## B
78 
79 #define _TYPED_GENERIC_WORD(TYPE, NAME) \
80  _EMBED_DECORATE(void M_CONC(_, M_CONC(NAME, M_CONC(_, TYPE))) ());
81 
82 #define _GENERIC_WORD(NAME) _TYPED_GENERIC_WORD(FORTH_TYPE, NAME)
83 
84 #define POP M_CONC(pop_, FORTH_TYPE) ();
85 
86 _GENERIC_WORD(emit)
87 
88 _GENERIC_WORD(dot)
89 
90 _GENERIC_WORD(dup)
91 
92 _GENERIC_WORD(swap)
93 
94 _GENERIC_WORD(rot)
95 
96 _GENERIC_WORD(over)
97 
98 _GENERIC_WORD(dot)
99 
100 _GENERIC_WORD(depth)
101 
102 _GENERIC_WORD(times_divide)
103 
104 _GENERIC_WORD(times_divide_mod)
105 
106 _GENERIC_WORD(key)
107 
108 _GENERIC_WORD(max)
109 
110 _GENERIC_WORD(min)
111 
112 _GENERIC_WORD(pick)
113 
114 #include "generators_run.h"
115 
116 void register_precompiled();
117 
118 pforth_word_ptr create_variable(const char* name);
119 
120 /* Variable management */
void register_precompiled()
Definition: words.c:314
void _drop(size_t size)
Definition: words.c:40
#define FORTH_TYPE
Definition: pforth.h:38
int size
Definition: pforth.h:105
void _push(void *data, size_t size)
Definition: words.c:18
#define _GENERIC_WORD(NAME)
Definition: words.h:82
pforth_word_ptr create_variable(const char *name)
Definition: words.c:340
FORTH_TYPE _depth()
Definition: words.c:29
#define _EMBED_DECORATE(FUNC)
Definition: words.h:15
Definition: pforth.h:58