flipjump 1.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. flipjump-1.2.0/LICENSE +25 -0
  2. flipjump-1.2.0/PKG-INFO +275 -0
  3. flipjump-1.2.0/README.md +238 -0
  4. flipjump-1.2.0/flipjump/README.md +95 -0
  5. flipjump-1.2.0/flipjump/__init__.py +23 -0
  6. flipjump-1.2.0/flipjump/assembler/__init__.py +0 -0
  7. flipjump-1.2.0/flipjump/assembler/assembler.py +241 -0
  8. flipjump-1.2.0/flipjump/assembler/fj_parser.py +728 -0
  9. flipjump-1.2.0/flipjump/assembler/inner_classes/__init__.py +0 -0
  10. flipjump-1.2.0/flipjump/assembler/inner_classes/expr.py +129 -0
  11. flipjump-1.2.0/flipjump/assembler/inner_classes/ops.py +369 -0
  12. flipjump-1.2.0/flipjump/assembler/preprocessor.py +292 -0
  13. flipjump-1.2.0/flipjump/fjm/__init__.py +0 -0
  14. flipjump-1.2.0/flipjump/fjm/fjm_consts.py +66 -0
  15. flipjump-1.2.0/flipjump/fjm/fjm_reader.py +187 -0
  16. flipjump-1.2.0/flipjump/fjm/fjm_writer.py +189 -0
  17. flipjump-1.2.0/flipjump/flipjump_cli.py +345 -0
  18. flipjump-1.2.0/flipjump/flipjump_quickstart.py +342 -0
  19. flipjump-1.2.0/flipjump/interpretter/__init__.py +0 -0
  20. flipjump-1.2.0/flipjump/interpretter/debugging/__init__.py +0 -0
  21. flipjump-1.2.0/flipjump/interpretter/debugging/breakpoints.py +234 -0
  22. flipjump-1.2.0/flipjump/interpretter/debugging/macro_usage_graph.py +98 -0
  23. flipjump-1.2.0/flipjump/interpretter/fjm_run.py +183 -0
  24. flipjump-1.2.0/flipjump/interpretter/io_devices/BrokenIO.py +15 -0
  25. flipjump-1.2.0/flipjump/interpretter/io_devices/FixedIO.py +51 -0
  26. flipjump-1.2.0/flipjump/interpretter/io_devices/IODevice.py +16 -0
  27. flipjump-1.2.0/flipjump/interpretter/io_devices/StandardIO.py +57 -0
  28. flipjump-1.2.0/flipjump/interpretter/io_devices/__init__.py +0 -0
  29. flipjump-1.2.0/flipjump/stl/README.md +146 -0
  30. flipjump-1.2.0/flipjump/stl/bit/casting.fj +168 -0
  31. flipjump-1.2.0/flipjump/stl/bit/cond_jumps.fj +97 -0
  32. flipjump-1.2.0/flipjump/stl/bit/input.fj +29 -0
  33. flipjump-1.2.0/flipjump/stl/bit/logics.fj +128 -0
  34. flipjump-1.2.0/flipjump/stl/bit/math.fj +85 -0
  35. flipjump-1.2.0/flipjump/stl/bit/memory.fj +113 -0
  36. flipjump-1.2.0/flipjump/stl/bit/output.fj +221 -0
  37. flipjump-1.2.0/flipjump/stl/bit/pointers.fj +181 -0
  38. flipjump-1.2.0/flipjump/stl/bit/shifts.fj +57 -0
  39. flipjump-1.2.0/flipjump/stl/casting.fj +52 -0
  40. flipjump-1.2.0/flipjump/stl/conf.json +31 -0
  41. flipjump-1.2.0/flipjump/stl/hex/advanced_pointers.fj +153 -0
  42. flipjump-1.2.0/flipjump/stl/hex/cond_jumps.fj +162 -0
  43. flipjump-1.2.0/flipjump/stl/hex/input.fj +87 -0
  44. flipjump-1.2.0/flipjump/stl/hex/logics.fj +257 -0
  45. flipjump-1.2.0/flipjump/stl/hex/math.fj +281 -0
  46. flipjump-1.2.0/flipjump/stl/hex/math_basic.fj +207 -0
  47. flipjump-1.2.0/flipjump/stl/hex/memory.fj +122 -0
  48. flipjump-1.2.0/flipjump/stl/hex/output.fj +214 -0
  49. flipjump-1.2.0/flipjump/stl/hex/pointers.fj +227 -0
  50. flipjump-1.2.0/flipjump/stl/hex/shifts.fj +83 -0
  51. flipjump-1.2.0/flipjump/stl/hex/tables_init.fj +78 -0
  52. flipjump-1.2.0/flipjump/stl/mathlib.fj +516 -0
  53. flipjump-1.2.0/flipjump/stl/ptrlib.fj +87 -0
  54. flipjump-1.2.0/flipjump/stl/runlib.fj +163 -0
  55. flipjump-1.2.0/flipjump/utils/__init__.py +0 -0
  56. flipjump-1.2.0/flipjump/utils/classes.py +94 -0
  57. flipjump-1.2.0/flipjump/utils/constants.py +17 -0
  58. flipjump-1.2.0/flipjump/utils/exceptions.py +54 -0
  59. flipjump-1.2.0/flipjump/utils/functions.py +74 -0
  60. flipjump-1.2.0/pyproject.toml +52 -0
flipjump-1.2.0/LICENSE ADDED
@@ -0,0 +1,25 @@
1
+ BSD 2-Clause License
2
+
3
+ Copyright (c) 2023, Tom Herman
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,275 @@
1
+ Metadata-Version: 2.1
2
+ Name: flipjump
3
+ Version: 1.2.0
4
+ Summary: The single instruction language - Flip a bit, then Jump
5
+ Home-page: https://esolangs.org/wiki/FlipJump
6
+ License: BSD-2-Clause-Simplified
7
+ Keywords: esolang,oisc,assembly
8
+ Author: Tom Herman
9
+ Author-email: flipjumpproject@gmail.com
10
+ Requires-Python: >=3.7,<4.0
11
+ Classifier: License :: Other/Proprietary License
12
+ Classifier: Programming Language :: Other
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.7
15
+ Classifier: Programming Language :: Python :: 3.8
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Topic :: Education
20
+ Classifier: Topic :: Software Development :: Assemblers
21
+ Classifier: Topic :: Software Development :: Compilers
22
+ Classifier: Topic :: Software Development :: Debuggers
23
+ Classifier: Topic :: Software Development :: Interpreters
24
+ Classifier: Topic :: Software Development :: Libraries
25
+ Provides-Extra: stats
26
+ Provides-Extra: tests
27
+ Requires-Dist: easygui (>=0.98.3,<0.99.0)
28
+ Requires-Dist: plotly (>=5.16.1,<6.0.0) ; extra == "stats"
29
+ Requires-Dist: pytest (>=7.4.0,<8.0.0) ; extra == "tests"
30
+ Requires-Dist: pytest-ordering (>=0.6,<0.7) ; extra == "tests"
31
+ Requires-Dist: pytest-xdist (>=3.3.1,<4.0.0) ; extra == "tests"
32
+ Requires-Dist: sly (>=0.4,<0.5)
33
+ Project-URL: Documentation, https://github.com/tomhea/flip-jump/wiki
34
+ Project-URL: Repository, https://github.com/tomhea/flip-jump
35
+ Description-Content-Type: text/markdown
36
+
37
+ # FlipJump
38
+
39
+ [![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/tomhea/flip-jump)](https://github.com/tomhea/flip-jump#project-structure)
40
+ [![GitHub release (latest by date)](https://img.shields.io/github/v/release/tomhea/flip-jump)](https://github.com/tomhea/flip-jump/releases/latest)
41
+ [![GitHub Discussions](https://img.shields.io/github/discussions/tomhea/flip-jump)](https://github.com/tomhea/flip-jump/discussions)
42
+ [![GitHub](https://img.shields.io/github/license/tomhea/flip-jump)](LICENSE)
43
+ [![Website](https://img.shields.io/website?down_color=red&down_message=down&up_message=up&url=https%3A%2F%2Fesolangs.org%2Fwiki%2FFlipJump)](https://esolangs.org/wiki/FlipJump)
44
+ [![PyPI - Version](https://img.shields.io/pypi/v/flipjump)](https://pypi.org/project/flipjump/)
45
+
46
+ FlipJump is the simplest programing language.
47
+ Yet, it can do **any modern computation**.
48
+
49
+ It's an Esoteric language ([FlipJump esolangs page](https://esolangs.org/wiki/FlipJump)), with just 1 operation `a;b`:
50
+ - `not *a; jump b`
51
+
52
+ Which means - **Flip** a bit, then **Jump**.
53
+
54
+ The operation takes 2 memory addresses - it flips (inverts) the bit the first address points to, and jumps to (continue execution from) the second address. The next opcode is the two memory-addresses found right where you jumped to. You flip and jump again, and so on...
55
+
56
+
57
+ This project includes a **Macro Assembler**, an **Interpreter**, and a **Thoroughly Tested Standard Library** for the FlipJump language.
58
+ Additionally, it provides a **Python Library** that makes it easy to work with those components.
59
+
60
+ This calculator was built with only FlipJump ([source](programs/calc.fj)):
61
+ ![Calculations using only FlipJump](res/calc.gif)
62
+
63
+ ## Hello, World!
64
+
65
+ <details>
66
+ <summary>A simple hello-world flipjump program, not using the standard library:</summary>
67
+ (jump to the source code)
68
+
69
+ ```c
70
+ // define macros that will be used later
71
+
72
+ // this macro exports the "IO" label to be a global label
73
+ def startup @ code_start > IO {
74
+ ;code_start
75
+ IO:
76
+ ;0 // the second op is reserved for Input/Output.
77
+ code_start:
78
+ }
79
+
80
+ // this macro gets one parameter "bit", and uses the global label "IO".
81
+ def output_bit bit < IO {
82
+ IO + bit; // flipping IO+0 outputs 0; flipping IO+1 outputs 1.
83
+ }
84
+ def output_char ascii {
85
+ // the next line will be unwinded into 8 output_bit macro-uses, each with a different parameter
86
+ rep(8, i) output_bit ((ascii>>i)&1)
87
+ }
88
+
89
+ def end_loop @ loop_label {
90
+ loop_label:
91
+ ;loop_label // a flipjump program finishes on a self loop
92
+ }
93
+
94
+
95
+ // The first lines of actual code:
96
+
97
+ startup
98
+
99
+ output_char 'H'
100
+ output_char 'e'
101
+ output_char 'l'
102
+ output_char 'l'
103
+ output_char 'o'
104
+ output_char ','
105
+ output_char ' '
106
+
107
+ output_char 'W'
108
+ output_char 'o'
109
+ output_char 'r'
110
+ output_char 'l'
111
+ output_char 'd'
112
+ output_char '!'
113
+
114
+ end_loop
115
+
116
+ ```
117
+
118
+ The source code can be found here: [hello_no-stl.fj](programs/print_tests/hello_no-stl.fj).
119
+
120
+ The FlipJump assembly supports a ```"Hello, World!"``` syntax for initializing a variable with a string value.
121
+ Look at the [hello_world.fj](programs/print_tests/hello_world.fj) program for more info.
122
+
123
+ Note that all of these macros are already implemented in the standard library (all in [runlib.fj](flipjump/stl/runlib.fj)):
124
+ - startup
125
+ - end_loop (loop)
126
+ - output_char
127
+ - output (for printing string consts, e.g. output "Hello, World!")
128
+ </details>
129
+
130
+
131
+ # How to install?
132
+
133
+ ```shell
134
+ pip install flipjump
135
+ ```
136
+
137
+ You can also install it with its extras:
138
+ - flipjump[**stats**]: support for viewing macro usage in an interactive graph.
139
+ - flipjump[**tests**]: all the testing libraries needed.
140
+ ```shell
141
+ pip install flipjump[stats,tests]
142
+ ```
143
+
144
+
145
+ Pycharm Extensions:
146
+ - Add <span style="color:orange">syntax highlighting</span> support for *.fj files - just import the [PycharmHighlighting.zip](ide-extensions/pycharm/PycharmHighlighting.zip) settings.
147
+ - Add a ctrl+shift+click (find fj-macro definition) functionality by using the [AutoHotKey script](ide-extensions/pycharm/fj-pycharm-def-finder.ahk).
148
+
149
+ # How to run?
150
+
151
+ Use the `fj` utility:
152
+ ```shell
153
+ fj hello_world.fj
154
+ ```
155
+
156
+ ![Hello World in FlipJump](res/hello.gif)
157
+
158
+ - The --no-stl flag tells the assembler not to include the standard library. for example: `fj programs/print_tests/hello_no-stl.fj --no-stl`.
159
+ - the -w [WIDTH] flag allows compiling the .fj files to a WIDTH-bits memory width. WIDTH is 64 by default.
160
+ - You can use the -o flag to save the assembled file for later use too.
161
+ - you can find all the different flags with `fj -h`.
162
+
163
+ You can also **[Test the project](tests/README.md)** with the project's tests, and with your tests.
164
+
165
+ You can also assemble and run separately:
166
+
167
+ ```bash
168
+ fj --asm hello.fj -o hello_world.fjm
169
+ fj --run hello_world.fjm
170
+ ```
171
+
172
+ - The first line will assemble your code.
173
+ - The second line will run your code.
174
+
175
+ You can also use the faster [cpp-based interpreter](https://github.com/tomhea/fji-cpp):
176
+
177
+ ```bash
178
+ >>> fji hello.fjm -s
179
+ Hello, World!
180
+ ```
181
+
182
+ ### How to Debug?
183
+ Programs won't work on their first run. They just can't. That's why we support the next debugging flags.
184
+
185
+ - No debugging flags at all: Shows the last 10 executed addresses of tests that failed their run (i.e. finished not by looping).
186
+ - `-d [PATH]`: Save debug information: Adds [very extensive label names](tests/README.md#example-label-name-youll-get-with-using---debuginfo-len), Which are like a "**macro-stack**" for each of the last executed address. (can be used with `--debug-ops-list LEN`)
187
+ - `--debug-ops-list LEN`: Shows the last _LEN_ executed addresses (instead of 10). (can be used with `-d`)
188
+ - `-b NAME [NAME ...]`: Places breakpoints at every specified label NAMEs (note that label names are long: [more information about labels](flipjump/README.md#generated-label-names)). (requires `-b`)
189
+ - `-B NAME [NAME ...]`: Places breakpoints at every label that contains one of the given NAMEs. (requires `-b`)
190
+
191
+
192
+ # Get Started with FlipJump
193
+ - Install flipjump: `pip install flipjump`
194
+ - Write your flipjump program (use the [stl - standard library](flipjump/stl/README.md) macros).
195
+ - For example: [print_dec.fj](programs/print_tests/print_dec.fj).
196
+ - assemble+run your program: `fj print_dec.fj`
197
+
198
+ ### Example usage of the flipjump python library
199
+ ```python
200
+ from pathlib import Path
201
+ from flipjump import assemble_and_run # assemble, run_test_output, ...
202
+
203
+ fj_file_paths = [Path('path/to/main.fj'), Path('path/to/consts.fj')]
204
+ termination_statistics = assemble_and_run(fj_file_paths)
205
+ ```
206
+
207
+ _You can also use the `flipjump.assemble_run_according_to_cmd_line_args(cmd_line_args=[...])`._
208
+
209
+
210
+ # Project Structure
211
+
212
+ **[flipjump](flipjump/README.md)** (assembler + interpreter source files):
213
+ - [flipjump_cli.py](flipjump/flipjump_cli.py) - Main CLI script fot the FlipJump Assembler & Interpreter.
214
+ - [fjm/](flipjump/fjm) - Tools for reading/writing .fjm (flip-jump-memory) files.
215
+ - [interpreter/fjm_run.py](flipjump/interpretter/fjm_run.py) - Interpreter + debugger for assembled fj files.
216
+ - [assembler/](flipjump/assembler) - Components for assembling FlipJump code.
217
+ - [fj_parser.py](flipjump/assembler/fj_parser.py) - Pythonic lex/yacc parser.
218
+ - [preprocessor.py](flipjump/assembler/preprocessor.py) - Unwinds all macros and reps (repetitions).
219
+ - [assembler.py](flipjump/assembler/assembler.py) - Assembles macro-less fj files.
220
+ - [more...](flipjump/README.md) - Additional project files and documentation.
221
+
222
+ **[flipjump/stl](flipjump/stl/README.md)** (standard library files - macros. The [stl readme](flipjump/stl/README.md#the-files) contains the list of all macros):
223
+ - runlib.fj - Constants and initialization macros. Output constant strings.
224
+ - [bit/](flipjump/stl/README.md#bit) - Directory of stl files. Macros for io/manipulating binary variables and vectors (i.e. numbers): math, logic, conditional jumps, pointers, casting, IO, ...
225
+ - [hex/](flipjump/stl/README.md#hex) - Directory of stl files. Macros for io/manipulating hexadecimal variables and vectors (i.e. numbers): math, logic, conditional jumps, pointers, casting, IO, ...
226
+ - mathlib.fj - Advanced math macros (mul/div).
227
+ - casting.fj - Macros for casting between bit/hex.
228
+ - ptrlib.fj - Macros for working with pointers, stacks, and functions.
229
+ - conf.json - The list of the standard library files.
230
+
231
+ **[programs](programs)** (flipjump programs, used by the tests), for example:
232
+ - [hello_world.fj](programs/print_tests/hello_world.fj) - Prints "hello world :)"
233
+ - [calc.fj](programs/calc.fj) - A command-line calculator for 2 hex/dec numbers: ```a [+-*/%] b```.
234
+ - [func_tests/](programs/func_tests) - Programs for testing function calls and stack operations.
235
+ - [hexlib_tests/](programs/hexlib_tests) - Tests for all the hex macros, except the hex.pointers.
236
+ - [quine16.fj](programs/quine16.fj) - A 16-bits quine by [lestrozi](https://github.com/lestrozi); when assembled with `-w16 -v0` - prints itself.
237
+ - [pair_ns.fj](programs/concept_checks/pair_ns.fj) - Simulates the concept of a Class, by using a namespace.
238
+ - [print_dec.fj](programs/print_tests/print_dec.fj) - Prints binary variables as decimals.
239
+ - [multi_comp/](programs/multi_comp) - Simulates a big project (compilation of multiple files).
240
+
241
+ **[tests](tests/README.md)** (tests compiling+running the programs with the stl), for example:
242
+ - compiled/ - The designated directory for the assembled tests files.
243
+ - inout/ - Contains the .in and .out files for each test.
244
+ - conftest.py - The pytest configuration file. The tests are being generated here.
245
+ - test_fj.py - The base test functions for compilation and running ([how to run](tests/README.md#run-the-tests)).
246
+ - test_compile_*.csv - Arguments for the compile tests ([compile test arguments format](tests/README.md#compile-csvs-format)).
247
+ - test_run_*.csv - Arguments for the run tests ([run test arguments format](tests/README.md#run-csvs-format)).
248
+ - conf.json - The tests groups+order lists.
249
+ - xfail_*.csv - [xfail](https://docs.pytest.org/en/7.1.x/how-to/skipping.html#xfail-mark-test-functions-as-expected-to-fail) these tests.
250
+
251
+
252
+ # Read More - Extra Documentation
253
+
254
+ Take a look at the other READMEs:
255
+ * Read more about the [assembler/interpreter source files](flipjump/README.md).
256
+ * Read more about [how to run the tests](tests/README.md).
257
+ * Read more about the [standard library](flipjump/stl/README.md).
258
+
259
+ A very extensive explanation can be found on the [GitHub wiki page](https://github.com/tomhea/flip-jump/wiki/Learn-FlipJump).
260
+
261
+ More detailed explanation and the **specifications of the FlipJump assembly** can be found on the [FlipJump esolangs page](https://esolangs.org/wiki/FlipJump).
262
+
263
+ If you are new to FlipJump and you want to learn how modern computation can be executed using FlipJump, and you want to jump onto your first flipjump code - Start by reading the [bit.xor](flipjump/stl/bit/logics.fj) and [bit.if](flipjump/stl/bit/cond_jumps.fj) macros. That's where the FlipJump magic begins.
264
+ If you want to understand how the deep optimized hex macros work, understand how the next macros are implemented: [hex.exact_xor](flipjump/stl/hex/logics.fj), [hex.output](flipjump/stl/hex/output.fj), [hex.inc1](flipjump/stl/hex/math_basic.fj), and [hex.add](flipjump/stl/hex/math.fj) (understand the concept of the [lookup tables](https://esolangs.org/wiki/FlipJump#Lookup_Tables).
265
+
266
+ You can also write and run programs for yourself! It is just [that](README.md#how-to-run) easy :)
267
+
268
+
269
+ # Contribute
270
+
271
+ If you want to contribute to this project, read the [CONTRIBUTING.md](CONTRIBUTING.md) file, and take a look at the [I-Want-To-Contribute Thread](https://github.com/tomhea/flip-jump/discussions/148).
272
+
273
+ Actually, just writing your own flipjump programs and sharing them with the world is a great contribution to the community :)
274
+ Take a look at what the [standard library](flipjump/stl/README.md) offers, and see some [example programs](programs) to get you inspired!
275
+
@@ -0,0 +1,238 @@
1
+ # FlipJump
2
+
3
+ [![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/tomhea/flip-jump)](https://github.com/tomhea/flip-jump#project-structure)
4
+ [![GitHub release (latest by date)](https://img.shields.io/github/v/release/tomhea/flip-jump)](https://github.com/tomhea/flip-jump/releases/latest)
5
+ [![GitHub Discussions](https://img.shields.io/github/discussions/tomhea/flip-jump)](https://github.com/tomhea/flip-jump/discussions)
6
+ [![GitHub](https://img.shields.io/github/license/tomhea/flip-jump)](LICENSE)
7
+ [![Website](https://img.shields.io/website?down_color=red&down_message=down&up_message=up&url=https%3A%2F%2Fesolangs.org%2Fwiki%2FFlipJump)](https://esolangs.org/wiki/FlipJump)
8
+ [![PyPI - Version](https://img.shields.io/pypi/v/flipjump)](https://pypi.org/project/flipjump/)
9
+
10
+ FlipJump is the simplest programing language.
11
+ Yet, it can do **any modern computation**.
12
+
13
+ It's an Esoteric language ([FlipJump esolangs page](https://esolangs.org/wiki/FlipJump)), with just 1 operation `a;b`:
14
+ - `not *a; jump b`
15
+
16
+ Which means - **Flip** a bit, then **Jump**.
17
+
18
+ The operation takes 2 memory addresses - it flips (inverts) the bit the first address points to, and jumps to (continue execution from) the second address. The next opcode is the two memory-addresses found right where you jumped to. You flip and jump again, and so on...
19
+
20
+
21
+ This project includes a **Macro Assembler**, an **Interpreter**, and a **Thoroughly Tested Standard Library** for the FlipJump language.
22
+ Additionally, it provides a **Python Library** that makes it easy to work with those components.
23
+
24
+ This calculator was built with only FlipJump ([source](programs/calc.fj)):
25
+ ![Calculations using only FlipJump](res/calc.gif)
26
+
27
+ ## Hello, World!
28
+
29
+ <details>
30
+ <summary>A simple hello-world flipjump program, not using the standard library:</summary>
31
+ (jump to the source code)
32
+
33
+ ```c
34
+ // define macros that will be used later
35
+
36
+ // this macro exports the "IO" label to be a global label
37
+ def startup @ code_start > IO {
38
+ ;code_start
39
+ IO:
40
+ ;0 // the second op is reserved for Input/Output.
41
+ code_start:
42
+ }
43
+
44
+ // this macro gets one parameter "bit", and uses the global label "IO".
45
+ def output_bit bit < IO {
46
+ IO + bit; // flipping IO+0 outputs 0; flipping IO+1 outputs 1.
47
+ }
48
+ def output_char ascii {
49
+ // the next line will be unwinded into 8 output_bit macro-uses, each with a different parameter
50
+ rep(8, i) output_bit ((ascii>>i)&1)
51
+ }
52
+
53
+ def end_loop @ loop_label {
54
+ loop_label:
55
+ ;loop_label // a flipjump program finishes on a self loop
56
+ }
57
+
58
+
59
+ // The first lines of actual code:
60
+
61
+ startup
62
+
63
+ output_char 'H'
64
+ output_char 'e'
65
+ output_char 'l'
66
+ output_char 'l'
67
+ output_char 'o'
68
+ output_char ','
69
+ output_char ' '
70
+
71
+ output_char 'W'
72
+ output_char 'o'
73
+ output_char 'r'
74
+ output_char 'l'
75
+ output_char 'd'
76
+ output_char '!'
77
+
78
+ end_loop
79
+
80
+ ```
81
+
82
+ The source code can be found here: [hello_no-stl.fj](programs/print_tests/hello_no-stl.fj).
83
+
84
+ The FlipJump assembly supports a ```"Hello, World!"``` syntax for initializing a variable with a string value.
85
+ Look at the [hello_world.fj](programs/print_tests/hello_world.fj) program for more info.
86
+
87
+ Note that all of these macros are already implemented in the standard library (all in [runlib.fj](flipjump/stl/runlib.fj)):
88
+ - startup
89
+ - end_loop (loop)
90
+ - output_char
91
+ - output (for printing string consts, e.g. output "Hello, World!")
92
+ </details>
93
+
94
+
95
+ # How to install?
96
+
97
+ ```shell
98
+ pip install flipjump
99
+ ```
100
+
101
+ You can also install it with its extras:
102
+ - flipjump[**stats**]: support for viewing macro usage in an interactive graph.
103
+ - flipjump[**tests**]: all the testing libraries needed.
104
+ ```shell
105
+ pip install flipjump[stats,tests]
106
+ ```
107
+
108
+
109
+ Pycharm Extensions:
110
+ - Add <span style="color:orange">syntax highlighting</span> support for *.fj files - just import the [PycharmHighlighting.zip](ide-extensions/pycharm/PycharmHighlighting.zip) settings.
111
+ - Add a ctrl+shift+click (find fj-macro definition) functionality by using the [AutoHotKey script](ide-extensions/pycharm/fj-pycharm-def-finder.ahk).
112
+
113
+ # How to run?
114
+
115
+ Use the `fj` utility:
116
+ ```shell
117
+ fj hello_world.fj
118
+ ```
119
+
120
+ ![Hello World in FlipJump](res/hello.gif)
121
+
122
+ - The --no-stl flag tells the assembler not to include the standard library. for example: `fj programs/print_tests/hello_no-stl.fj --no-stl`.
123
+ - the -w [WIDTH] flag allows compiling the .fj files to a WIDTH-bits memory width. WIDTH is 64 by default.
124
+ - You can use the -o flag to save the assembled file for later use too.
125
+ - you can find all the different flags with `fj -h`.
126
+
127
+ You can also **[Test the project](tests/README.md)** with the project's tests, and with your tests.
128
+
129
+ You can also assemble and run separately:
130
+
131
+ ```bash
132
+ fj --asm hello.fj -o hello_world.fjm
133
+ fj --run hello_world.fjm
134
+ ```
135
+
136
+ - The first line will assemble your code.
137
+ - The second line will run your code.
138
+
139
+ You can also use the faster [cpp-based interpreter](https://github.com/tomhea/fji-cpp):
140
+
141
+ ```bash
142
+ >>> fji hello.fjm -s
143
+ Hello, World!
144
+ ```
145
+
146
+ ### How to Debug?
147
+ Programs won't work on their first run. They just can't. That's why we support the next debugging flags.
148
+
149
+ - No debugging flags at all: Shows the last 10 executed addresses of tests that failed their run (i.e. finished not by looping).
150
+ - `-d [PATH]`: Save debug information: Adds [very extensive label names](tests/README.md#example-label-name-youll-get-with-using---debuginfo-len), Which are like a "**macro-stack**" for each of the last executed address. (can be used with `--debug-ops-list LEN`)
151
+ - `--debug-ops-list LEN`: Shows the last _LEN_ executed addresses (instead of 10). (can be used with `-d`)
152
+ - `-b NAME [NAME ...]`: Places breakpoints at every specified label NAMEs (note that label names are long: [more information about labels](flipjump/README.md#generated-label-names)). (requires `-b`)
153
+ - `-B NAME [NAME ...]`: Places breakpoints at every label that contains one of the given NAMEs. (requires `-b`)
154
+
155
+
156
+ # Get Started with FlipJump
157
+ - Install flipjump: `pip install flipjump`
158
+ - Write your flipjump program (use the [stl - standard library](flipjump/stl/README.md) macros).
159
+ - For example: [print_dec.fj](programs/print_tests/print_dec.fj).
160
+ - assemble+run your program: `fj print_dec.fj`
161
+
162
+ ### Example usage of the flipjump python library
163
+ ```python
164
+ from pathlib import Path
165
+ from flipjump import assemble_and_run # assemble, run_test_output, ...
166
+
167
+ fj_file_paths = [Path('path/to/main.fj'), Path('path/to/consts.fj')]
168
+ termination_statistics = assemble_and_run(fj_file_paths)
169
+ ```
170
+
171
+ _You can also use the `flipjump.assemble_run_according_to_cmd_line_args(cmd_line_args=[...])`._
172
+
173
+
174
+ # Project Structure
175
+
176
+ **[flipjump](flipjump/README.md)** (assembler + interpreter source files):
177
+ - [flipjump_cli.py](flipjump/flipjump_cli.py) - Main CLI script fot the FlipJump Assembler & Interpreter.
178
+ - [fjm/](flipjump/fjm) - Tools for reading/writing .fjm (flip-jump-memory) files.
179
+ - [interpreter/fjm_run.py](flipjump/interpretter/fjm_run.py) - Interpreter + debugger for assembled fj files.
180
+ - [assembler/](flipjump/assembler) - Components for assembling FlipJump code.
181
+ - [fj_parser.py](flipjump/assembler/fj_parser.py) - Pythonic lex/yacc parser.
182
+ - [preprocessor.py](flipjump/assembler/preprocessor.py) - Unwinds all macros and reps (repetitions).
183
+ - [assembler.py](flipjump/assembler/assembler.py) - Assembles macro-less fj files.
184
+ - [more...](flipjump/README.md) - Additional project files and documentation.
185
+
186
+ **[flipjump/stl](flipjump/stl/README.md)** (standard library files - macros. The [stl readme](flipjump/stl/README.md#the-files) contains the list of all macros):
187
+ - runlib.fj - Constants and initialization macros. Output constant strings.
188
+ - [bit/](flipjump/stl/README.md#bit) - Directory of stl files. Macros for io/manipulating binary variables and vectors (i.e. numbers): math, logic, conditional jumps, pointers, casting, IO, ...
189
+ - [hex/](flipjump/stl/README.md#hex) - Directory of stl files. Macros for io/manipulating hexadecimal variables and vectors (i.e. numbers): math, logic, conditional jumps, pointers, casting, IO, ...
190
+ - mathlib.fj - Advanced math macros (mul/div).
191
+ - casting.fj - Macros for casting between bit/hex.
192
+ - ptrlib.fj - Macros for working with pointers, stacks, and functions.
193
+ - conf.json - The list of the standard library files.
194
+
195
+ **[programs](programs)** (flipjump programs, used by the tests), for example:
196
+ - [hello_world.fj](programs/print_tests/hello_world.fj) - Prints "hello world :)"
197
+ - [calc.fj](programs/calc.fj) - A command-line calculator for 2 hex/dec numbers: ```a [+-*/%] b```.
198
+ - [func_tests/](programs/func_tests) - Programs for testing function calls and stack operations.
199
+ - [hexlib_tests/](programs/hexlib_tests) - Tests for all the hex macros, except the hex.pointers.
200
+ - [quine16.fj](programs/quine16.fj) - A 16-bits quine by [lestrozi](https://github.com/lestrozi); when assembled with `-w16 -v0` - prints itself.
201
+ - [pair_ns.fj](programs/concept_checks/pair_ns.fj) - Simulates the concept of a Class, by using a namespace.
202
+ - [print_dec.fj](programs/print_tests/print_dec.fj) - Prints binary variables as decimals.
203
+ - [multi_comp/](programs/multi_comp) - Simulates a big project (compilation of multiple files).
204
+
205
+ **[tests](tests/README.md)** (tests compiling+running the programs with the stl), for example:
206
+ - compiled/ - The designated directory for the assembled tests files.
207
+ - inout/ - Contains the .in and .out files for each test.
208
+ - conftest.py - The pytest configuration file. The tests are being generated here.
209
+ - test_fj.py - The base test functions for compilation and running ([how to run](tests/README.md#run-the-tests)).
210
+ - test_compile_*.csv - Arguments for the compile tests ([compile test arguments format](tests/README.md#compile-csvs-format)).
211
+ - test_run_*.csv - Arguments for the run tests ([run test arguments format](tests/README.md#run-csvs-format)).
212
+ - conf.json - The tests groups+order lists.
213
+ - xfail_*.csv - [xfail](https://docs.pytest.org/en/7.1.x/how-to/skipping.html#xfail-mark-test-functions-as-expected-to-fail) these tests.
214
+
215
+
216
+ # Read More - Extra Documentation
217
+
218
+ Take a look at the other READMEs:
219
+ * Read more about the [assembler/interpreter source files](flipjump/README.md).
220
+ * Read more about [how to run the tests](tests/README.md).
221
+ * Read more about the [standard library](flipjump/stl/README.md).
222
+
223
+ A very extensive explanation can be found on the [GitHub wiki page](https://github.com/tomhea/flip-jump/wiki/Learn-FlipJump).
224
+
225
+ More detailed explanation and the **specifications of the FlipJump assembly** can be found on the [FlipJump esolangs page](https://esolangs.org/wiki/FlipJump).
226
+
227
+ If you are new to FlipJump and you want to learn how modern computation can be executed using FlipJump, and you want to jump onto your first flipjump code - Start by reading the [bit.xor](flipjump/stl/bit/logics.fj) and [bit.if](flipjump/stl/bit/cond_jumps.fj) macros. That's where the FlipJump magic begins.
228
+ If you want to understand how the deep optimized hex macros work, understand how the next macros are implemented: [hex.exact_xor](flipjump/stl/hex/logics.fj), [hex.output](flipjump/stl/hex/output.fj), [hex.inc1](flipjump/stl/hex/math_basic.fj), and [hex.add](flipjump/stl/hex/math.fj) (understand the concept of the [lookup tables](https://esolangs.org/wiki/FlipJump#Lookup_Tables).
229
+
230
+ You can also write and run programs for yourself! It is just [that](README.md#how-to-run) easy :)
231
+
232
+
233
+ # Contribute
234
+
235
+ If you want to contribute to this project, read the [CONTRIBUTING.md](CONTRIBUTING.md) file, and take a look at the [I-Want-To-Contribute Thread](https://github.com/tomhea/flip-jump/discussions/148).
236
+
237
+ Actually, just writing your own flipjump programs and sharing them with the world is a great contribution to the community :)
238
+ Take a look at what the [standard library](flipjump/stl/README.md) offers, and see some [example programs](programs) to get you inspired!
@@ -0,0 +1,95 @@
1
+ # FlipJump Source Code
2
+
3
+ In this documentation file you could find information about every python source file in the flipjump module.
4
+
5
+ ## The FlipJump Macro-Assembler
6
+
7
+ The assembler has 4 steps:
8
+ - parsing the .fj text files into a dictionary of macros and their ops ([fj_parser.py](assembler/fj_parser.py)).
9
+ - resolving (unwinding) the macros (and reps) to get a straight stream of ops ([preprocessor.py](assembler/preprocessor.py)).
10
+ - resolving the label values and getting the ops binary data ([assembler.py](assembler/assembler.py)).
11
+ - writing the binary data into the executable ([fjm_writer.py](fjm/fjm_writer.py)).
12
+
13
+ The whole process is executed within the [assemble()](assembler/assembler.py) function.
14
+ ![Assembly of calc.fj](../res/calc__asm.jpg)
15
+
16
+ - The [ops.py](assembler/inner_classes/ops.py) file contains the classes of the different assembly ops.
17
+ - The [expr.py](assembler/inner_classes/expr.py) file contains the expression class (Expr), which is the code's representation of the assembly mathematical expressions. The expressions are based on numbers and labels.
18
+
19
+ ## The FlipJump Interpreter
20
+
21
+ The Interpreter ([fjm_run.py](interpretter/fjm_run.py)) stores the entire memory in a dictionary {address: value}, and supports unaligned-word access.
22
+
23
+ The whole interpretation is done within the [run()](interpretter/fjm_run.py) function (also uses the [fjm_reader.py](fjm/fjm_reader.py) to read the fjm file - i.e. to get the flipjump program memory from the compiled fjm file).
24
+ More about [how to run](../README.md#how-to-run).
25
+ ![Running the compiled calculator](../res/calc__run.jpg)
26
+
27
+ The Interpreter has a built-in debugger, and it's activated by specifying breakpoints when called (via the [breakpoints.py](interpretter/debugging/breakpoints.py)'s `BreakpointHandler`).
28
+ The debugger can stop on the next breakpoint, or on a fixed number of executed ops after the current breakpoint.
29
+ In order to call the debugger with the right labels, get familiar with the [generating label names](README.md#Generated-Label-Names) (and see the debugger-image there), and use the `-d`/`-b`/`-B` cli options.
30
+ More about [how to debug](../README.md#how-to-debug).
31
+
32
+ The [macro_usage_graph.py](interpretter/debugging/macro_usage_graph.py) file exports a feature to present the macro-usage (which are the most used macros, and what % do they take from the overall flipjump ops) in a graph.
33
+ In order to view it, run the assembler with `--stats` (requires plotly to be installed (installed automatically with `pip install flipjump[stats]`)).
34
+ For example:
35
+ ![The macro-usage statistics of calc.fj](../res/calc_stats.png)
36
+
37
+ ## The Using-FlipJump Files
38
+
39
+ - The [flipjump_cli.py](flipjump_cli.py) file is the main FlipJump cli-script. run with --help to see its capabilities. The `fj` utility runs the main() of this file.
40
+ - The [flipjump_quickstart.py](flipjump_quickstart.py) file contains the fundamental assemble/run functions that are exposed to the users. They are wrappers to the inner api. These are the functions that will be exported when you `import flipjump`.
41
+
42
+ ### FJM versions
43
+
44
+ The .fjm file currently has 4 versions:
45
+
46
+ - Version 0: The basic version
47
+ - Version 1: The normal version (more configurable than the basic version)
48
+ - Version 2: The relative-jumps version (good for further compression)
49
+ - Version 3: The compressed version
50
+
51
+ You can specify the version you want with the `-v VERSION` flag.
52
+ The assembler chooses **by default** version **3** if the `--outfile` is specified, and version **1** if it isn't.
53
+
54
+ ### Generated Label Names
55
+
56
+ The generated label string is a concatenation of the macro call tree, each separated by '---', and finish with the label local-name.
57
+
58
+ Each macro call string is as follows:\
59
+ short_file_name **:** line **:** macro_called
60
+
61
+ So if a->bit.b->hex.c->my_label: (a, bit.b called from file f2 lines 3,5; hex.c from file s1, line 72), the label's name will be:\
62
+ f2:3:a---f2:5:bit.b---s1:72:hex.c---my_label
63
+
64
+ On a rep-call (on index==i), the macro call string is:\
65
+ short_file_name : line : rep{i} : macro_called\
66
+ for example: f1:32:rep6:hex.print---f2:17:print_bit---print_label
67
+
68
+ the short_file_name is (by default) s1,s2,s3,... for the standard library files (in the order of [stl/conf.json - all](stl/conf.json)),
69
+ and f1,f2,f3,... for the compiled .fj files, in the order they are mentioned to the compiler (or appear in the test-line).
70
+
71
+ You can place breakpoints to stop on specific labels using the `-d`, followed by a `-b` and a label name (or `-B` and a part of a label name). For example:
72
+ ![Debugging Demo](../res/breakpoint.jpg)
73
+
74
+ ## More Files
75
+
76
+ - The [fjm_consts.py](fjm/fjm_consts.py) contains the constants needed for interacting with the fjm format (used by the [fjm_reader.py](fjm/fjm_reader.py) + [fjm_writer.py](fjm/fjm_writer.py)).
77
+ - The [utils/](utils) folder contains common utilities used and shared by the entire project:
78
+ - [utils/classes.py](utils/classes.py) - contains the common classes used in the entire project
79
+ - [utils/functions.py](utils/functions.py) - contains the common utility functions used in the entire project
80
+ - [utils/constants.py](utils/constants.py) - contains the project's constants and definitions.
81
+ - [utils/exceptions.py](utils/exceptions.py) - contains all the project's exceptions.
82
+ - The [interpreter/io_devices/](interpretter/io_devices) folder contains modules for different Input/Output-handling classes (can be passed as a parameter to the interpreter).
83
+ - The standard one is [StandardIO.py](interpretter/io_devices/StandardIO.py), which takes its input from the standard input, and write its output to the standard output.
84
+ - The tests use the [FixedIO.py](interpretter/io_devices/FixedIO.py), which takes a defined input and remembers its output.
85
+ - If you want to assert that your program takes no input and generates no output, use the [BrokenIO.py](interpretter/io_devices/BrokenIO.py), which raises exception on every input/output.
86
+ - Finally, the pure abstract IO handler class - [IODevice.py](interpretter/io_devices/IODevice.py).
87
+
88
+ # Read More
89
+
90
+ The FlipJump source is built in a way that allows simple addition of new features.
91
+
92
+ Every addition should be supported from the parsing level, up to the phase that is disappears (and probably is replaced with some flipjump ops). See the `assemble()` function in [assembler](assembler/assembler.py) to better understand the assembler 'pipeline'.
93
+
94
+ For example, if you want to add a new operation `a@b` that calculates _a^2+b^2_ or `a!` for _factorial(a)_, it is simple as adding a parsing rule in [fj_parser.py](assembler/fj_parser.py), and then adding the function to the op_string_to_function() in [expr.py](assembler/inner_classes/expr.py). That's it.
95
+
@@ -0,0 +1,23 @@
1
+ from flipjump.flipjump_cli import assemble_run_according_to_cmd_line_args
2
+ from flipjump.flipjump_quickstart import (assemble, run, debug, run_test_output,
3
+ assemble_and_run, assemble_and_debug, assemble_and_run_test_output,
4
+ FJMVersion, TerminationCause, TerminationStatistics,
5
+ FixedIO, IODevice, StandardIO)
6
+ from flipjump.utils.exceptions import IODeviceException, FlipJumpException
7
+ from flipjump.interpretter.io_devices.BrokenIO import BrokenIO
8
+
9
+
10
+ __all__ = [
11
+ 'assemble_run_according_to_cmd_line_args',
12
+ 'assemble',
13
+ 'run',
14
+ 'debug',
15
+ 'run_test_output',
16
+ 'assemble_and_run',
17
+ 'assemble_and_debug',
18
+ 'assemble_and_run_test_output',
19
+ 'FJMVersion',
20
+ 'TerminationCause',
21
+ 'TerminationStatistics',
22
+ 'FlipJumpException',
23
+ ]
File without changes