-
Notifications
You must be signed in to change notification settings - Fork 0
/
fleaux_std_builtins.py
255 lines (168 loc) · 5.73 KB
/
fleaux_std_builtins.py
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
import itertools
import math
import typing
from typing import TypeVar
from rich.traceback import install
import sys
install(show_locals=True)
T = TypeVar('T')
def decompose_call(func: typing.Callable, tuple_args: tuple):
return func(*tuple_args)
class GetArgs:
def __init__(self):
pass
def __call__(self):
return tuple(sys.argv)
class Wrap:
def __init__(self):
pass
def __ror__(self, arg: T) -> tuple[T]:
return (arg, )
class Unwrap:
def __init__(self):
pass
def __ror__(self, tuple_arg: tuple[T]) -> tuple[T]:
return tuple_arg[0]
class ElementAt:
def __init__(self):
pass
def __ror__(self, tuple_args: tuple[tuple[T, ...], int]) -> T:
def extract(seq: tuple[typing.Any], idx: int):
return seq[idx]
return decompose_call(extract, tuple_args)
class ToNum:
def __init__(self):
pass
def __ror__(self, tuple_args: tuple[str]) -> float:
def parse_number(data: str) -> float:
num = float(data)
if num.is_integer():
return int(num)
return num
return decompose_call(parse_number, tuple_args)
class In:
def __init__(self):
pass
def __ror__(self, tuple_args: tuple[int]) -> tuple[str, ...] | tuple[str]:
def get_input(count: int):
if not count > 0:
raise ValueError(f"{count} is not a valid input for In operation")
if count == 1:
return tuple([input()])
return tuple([input() for _ in range(count)])
return decompose_call(get_input, tuple_args)
class Take:
def __init__(self):
pass
def __ror__(self, tuple_args: tuple[tuple[T, ...], int]) -> tuple[T, ...] | None:
def take(seq: tuple[T, ...], stop: int) -> tuple[T, ...] | None:
return seq[:stop]
return decompose_call(take, tuple_args)
class Drop:
def __init__(self):
pass
def __ror__(self, tuple_args: tuple[tuple[T, ...], int]) -> tuple[T, ...]:
def drop(seq: tuple[T, ...], start: int) -> tuple[T, ...]:
return seq[start:]
return decompose_call(drop, tuple_args)
class Length:
def __init__(self):
pass
def __ror__(self, tuple_args: tuple[typing.Any, ...]) -> float:
return len(tuple_args)
class Slice:
def __init__(self):
pass
def __ror__(self, tuple_args: tuple[tuple[T, ...], int] |
tuple[tuple[T, ...], int, int] |
tuple[tuple[T, ...], int, int, int]
) -> tuple[T, ...] | None:
if len(tuple_args) == 2:
def _slice_stop(iterable, stop):
return iterable[:stop]
return decompose_call(_slice_stop, tuple_args)
if len(tuple_args) == 3:
def _slice_start_stop(iterable, start, stop):
return iterable[start: stop:]
return decompose_call(_slice_start_stop, tuple_args)
if len(tuple_args) == 4:
def _slice_start_stop_step(iterable, start, stop, step):
return iterable[start: stop: step]
return decompose_call(_slice_start_stop_step, tuple_args)
class Pow:
def __init__(self):
pass
def __ror__(self, tuple_args: tuple[float, float]) -> float:
return decompose_call(math.pow, tuple_args)
class Subtract:
def __init__(self):
pass
def __ror__(self, tuple_args: tuple[float, float]) -> float:
def subtract(lhs, rhs):
return lhs - rhs
return decompose_call(subtract, tuple_args)
class Multiply:
def __init__(self):
pass
def __ror__(self, tuple_args: tuple[float, float]) -> float:
print (tuple_args)
def multiply(lhs, rhs):
return lhs * rhs
return decompose_call(multiply, tuple_args)
class Divide:
def __init__(self):
pass
def __ror__(self, tuple_args: tuple[float, float]) -> float:
def divide(lhs, rhs):
return lhs / rhs
return decompose_call(divide, tuple_args)
class Add:
def __init__(self):
pass
def __ror__(self, tuple_args: tuple[float, float]) -> float:
def add(lhs, rhs):
return rhs + lhs
return decompose_call(add, tuple_args)
class Sqrt:
def __init__(self):
pass
def __ror__(self, tuple_args: tuple[float]) -> float:
return decompose_call(math.sqrt, tuple_args)
class Println:
def __init__(self):
pass
def __ror__(self, tuple_args: tuple[T, ...]) -> tuple[T, ...] | T:
decompose_call(print, tuple_args)
if len(tuple_args) == 1:
return tuple_args[0]
return tuple_args
class Printf:
def __init__(self):
pass
def __ror__(self, tuple_args: tuple[str, typing.Any, ...]) -> tuple[str, typing.Any, ...]:
def printf(fmt_str: str, *args_inner):
print(fmt_str.format(args_inner))
return fmt_str, args_inner
return decompose_call(printf, tuple_args)
class Tan:
def __init__(self):
pass
def __ror__(self, tuple_args: tuple[float]) -> float:
return decompose_call(math.tan, tuple_args)
class Cos:
def __init__(self):
pass
def __ror__(self, tuple_args: tuple[float]) -> float:
return decompose_call(math.cos, tuple_args)
class Sin:
def __init__(self):
pass
def __ror__(self, tuple_args: tuple[float]) -> float:
return decompose_call(math.sin, tuple_args)
def make_node(func):
class Node:
def __init__(self):
self.func = func
def __ror__(self, tuple_args: tuple) -> typing.Any:
return decompose_call(self.func, tuple_args)
return Node