forked from rollbear/basicpp
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasic.hpp
More file actions
115 lines (103 loc) · 3.23 KB
/
Copy pathbasic.hpp
File metadata and controls
115 lines (103 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//
// Originally written by BjÃrn Fahller (bjorn@fahller.se)
//
// No rights claimed. The sources are released to the public domain
//
// For license information, please refer to <http://unlicense.org>
//
#include <setjmp.h>
#include <stdlib.h>
#include <iostream>
#include <ostream>
#include <forward_list>
namespace basic {
struct stack_frame { jmp_buf buf; };
std::forward_list<stack_frame> stack;
#define GOSUB \
if (!(setjmp((basic::stack.emplace_front(),basic::stack.front().buf)) \
&& (basic::stack.pop_front(),true))) \
goto
#define RETURN if (basic::stack.empty()) return 0; longjmp(basic::stack.front().buf, 1)
template <typename T, typename U>
struct separator
{
static char const *str() { return ""; }
};
template <typename T>
struct separator<T,T>
{
static char const *str() { return ","; }
};
template <typename T>
class printer_h
{
using str = char const *;
public:
printer_h<str> operator,(str s) {
std::cout << separator<T, str>::str() << s;
return printer_h<str>();
}
template <typename U>
printer_h<U> operator,(U const& u) const {
std::cout << separator<T,U>::str() << u;
return printer_h<U>();
}
};
class printer
{
using str = char const;
public:
printer_h<str> operator,(str s) {
std::cout << s;
return printer_h<str>();
}
template <typename T>
printer_h<T> operator,(T const& t) const {
std::cout << t;
return printer_h<T>();
}
~printer() { std::cout << std::endl; }
};
class input
{
public:
input& operator,(char const *s) {
std::cout << s << std::flush;
return *this;
}
template <typename T>
input& operator,(T& t) {
std::cin >> t;
return *this;
}
};
#define INPUT basic::input(),
#define PRINT basic::printer(),
#define IF if (
#define THEN )
#define LET double
#define GOTO goto
#define FOR { double& for_loop_variable =
#define TO ; \
{ \
jmp_buf for_loop_top; \
bool for_loop_exit = 0; \
while (!for_loop_exit) \
{ \
if (setjmp(for_loop_top) == 0) \
{ \
double for_loop_step=1; \
double const for_loop_endval=
#define STEP ; \
for_loop_step=
#define NEXT for_loop_variable+=for_loop_step; \
for_loop_exit=( ( for_loop_step > 0 \
&& for_loop_variable > for_loop_endval) \
||( for_loop_step < 0 \
&& for_loop_variable < for_loop_endval)); \
longjmp(for_loop_top, 1); \
} \
} \
} \
}
} // namespace basic