Skip to content

Commit

Permalink
Merge pull request #216 from tomhea/dev
Browse files Browse the repository at this point in the history
Refactor stl, hex.pointers, more improvements
  • Loading branch information
tomhea authored Jun 23, 2023
2 parents 6beaeda + ad5b84e commit a956630
Show file tree
Hide file tree
Showing 146 changed files with 5,078 additions and 3,169 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 2-Clause License

Copyright (c) 2022, Tom Herman
Copyright (c) 2023, Tom Herman
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
39 changes: 28 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# FlipJump

[![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/tomhea/flip-jump)](https://github.com/tomhea/flip-jump#project-structure)
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/tomhea/flip-jump)](https://github.com/tomhea/flip-jump/releases/latest)
[![GitHub Discussions](https://img.shields.io/github/discussions/tomhea/flip-jump)](https://github.com/tomhea/flip-jump/discussions)
[![GitHub](https://img.shields.io/github/license/tomhea/flip-jump)](LICENSE)
[![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)

FlipJump is the simplest programing language.<br>
Yet, it can do **any modern computation**.

Expand Down Expand Up @@ -64,11 +70,11 @@ def end_loop @ loop_label {
The FlipJump assembly supports a ```"Hello, World!"``` syntax for initializing a variable with a string value.
Look at the [hello_world.fj](programs/print_tests/hello_world.fj) program for more info.

Note that all of these macros are already implemented in the standard library:
- startup in [runlib.fj](stl/runlib.fj)
- end_loop in [bitlib.fj](stl/bitlib.fj) (loop)
- output_char in [iolib.fj](stl/iolib.fj)
- output in [iolib.fj](stl/iolib.fj) (for printing string consts, e.g. output "Hello, World!")
Note that all of these macros are already implemented in the standard library (all in [runlib.fj](stl/runlib.fj)):
- startup
- end_loop (loop)
- output_char
- output (for printing string consts, e.g. output "Hello, World!")

# How to download?

Expand All @@ -79,7 +85,9 @@ Cloning into 'flip-jump'...
>>> pip install -r requirements.txt
```

You can add <span style="color:orange">syntax highlighting</span> support for *.fj files on Pycharm - just import the [PycharmHighlighting.zip](PycharmHighlighting.zip) settings.
Pycharm Extensions:
- Add <span style="color:orange">syntax highlighting</span> support for *.fj files - just import the [PycharmHighlighting.zip](ide-extensions/pycharm/PycharmHighlighting.zip) settings.
- Add a ctrl+shift+click (find fj-macro definition) functionality by using the [AutoHotKey script](ide-extensions/pycharm/fj-pycharm-def-finder.ahk).

# How to run?

Expand Down Expand Up @@ -114,6 +122,15 @@ You can also use the faster [cpp-based interpreter](https://github.com/tomhea/fj
Hello, World!
```

### How to Debug?
Programs won't work on their first run. They just can't. That's why we support the next debugging flags.

- No debugging flags at all: Shows the last 10 executed addresses of tests that failed their run (i.e. finished not by looping).
- `-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`)
- `--debug-ops-list LEN`: Shows the last _LEN_ executed addresses (instead of 10). (can be used with `-d`)
- `-b NAME [NAME ...]`: Places breakpoints at every specified label NAMEs (note that label names are long: [more information about labels](src/README.md#generated-label-names)). (requires `-b`)
- `-B NAME [NAME ...]`: Places breakpoints at every label that contains one of the given NAMEs. (requires `-b`)

# Project Structure

**[src](src/README.md)** (assembler + interpreter source files):
Expand All @@ -126,11 +143,11 @@ Hello, World!
- [more...](src/README.md)

**[stl](stl/README.md)** (standard library files - macros. [list of all macros](https://esolangs.org/wiki/FlipJump#The_Standard_Library)):
- runlib.fj - constants and initialization macros.
- bitlib.fj - macros for manipulating binary variables and vectors (i.e. numbers).
- runlib.fj - constants and initialization macros. output constant strings.
- [bit/](stl/README.md#bit) - macros for io/manipulating binary variables and vectors (i.e. numbers).
- mathlib.fj - advanced math macros (mul/div).
- hexlib.fj - macros for manipulating hexadecimal variables and vectors.
- iolib.fj - input/output macros, bit/hex/dec casting.
- [hex/](stl/README.md#hex) - macros for io/manipulating hexadecimal variables and vectors.
- casting.fj - casting between bit/hex.
- ptrlib.fj - pointers, stack and functions.
- conf.json - standard library list file.

Expand Down Expand Up @@ -164,7 +181,7 @@ Read more about the [flip-jump source files](src/README.md) and [how to run the

If you want to contribute to this project, read the [CONTRIBUTING.md](CONTRIBUTING.md) file, and take a look at the [Discussions](https://github.com/tomhea/flip-jump/discussions/148).

If you are new to FlipJump and you want to learn how modern computation can be executed using FlipJump, Start by reading the [bitlib.fj](stl/bitlib.fj) standard library file (start with `xor`, `if`). That's where the FlipJump magic begins.
If you are new to FlipJump and you want to learn how modern computation can be executed using FlipJump, Start by reading the [bit/math.fj](stl/bit/math.fj) standard library file (start with `xor`, `if`). That's where the FlipJump magic begins.

You can also write and run programs for yourself! It is just [that](README.md#how-to-run) easy :)

File renamed without changes.
38 changes: 38 additions & 0 deletions ide-extensions/pycharm/fj-pycharm-def-finder.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
; Double-click the script (with AutoHotKey v1 installed) to run now. Copy e script to "%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup" to still take effect after reboot.

; The script makes a Ctrl+Shift+Click Pycharm shortcut for flip-jump files (Find macro declaration), that resembles the Ctrl+Click shortcut for python (Find function declaration).

; Script summery: Replace Ctrl+Shift+Click with [ Click -> Copy the pointed word -> Ctrl+Shift+F (search in project) -> (search) "def " + copied word ].


^+Lbutton::
{
old_clipboard := clipboard

; Click
Send {Lbutton}

; Mark the pointed word
Send ^{Left}
Send ^+{Right}

; Copy the pointed word
Send ^c

; Unmark word
Send {Right}

; Open the "Find in files" window (shortcut in Pycharm)
Send ^+f
Sleep 100

; Search for "def COPIED_WORD"
Send {Home}
Send +{End}
Send def{Space}
Send ^v
Send {Space}

clipboard := old_clipboard
return
}
24 changes: 14 additions & 10 deletions programs/calc.fj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
startup
stl.startup


loop:
Expand Down Expand Up @@ -39,7 +39,7 @@ loop:

do_print:
print_int a
output '\n'
stl.output '\n'

bit.if should_finish, loop, finish

Expand All @@ -52,7 +52,7 @@ loop:
line_ended loop, finish, finish

finish:
loop
stl.loop



Expand All @@ -70,7 +70,9 @@ def remove_spaces @ main_loop, try2, next_ascii, end < space1, space2, ascii {



def insert_number x @ check1, set_minus, check2, before_hex, hex_loop, before_dec, dec_loop, minus_flag, end, after_minus < dec, hex_prefix1, hex_prefix2, t, hex, minus, ascii, error, hex_used {
def insert_number x @ \
check1, set_minus, check2, before_hex, hex_loop, before_dec, dec_loop, minus_flag, end, after_minus \
< dec, hex_prefix1, hex_prefix2, t, hex, minus, ascii, error, hex_used {
bit.zero w, x
bit.zero minus_flag
bit.cmp 8, ascii, minus, check1, set_minus, check1
Expand Down Expand Up @@ -105,7 +107,7 @@ def insert_number x @ check1, set_minus, check2, before_hex, hex_loop, before_de
;dec_loop

minus_flag:
bit
bit.bit
end:
bit.if0 minus_flag, after_minus
bit.neg w, x
Expand All @@ -115,7 +117,9 @@ def insert_number x @ check1, set_minus, check2, before_hex, hex_loop, before_de



def calc a, op, b @ try_add, try_sub, try_mul, try_mul_loop, try_div, try_mod, add, sub, mul, mul_loop, div_mod, div, mod, bad, div_mod_flag, r, q, end < minus, asterisk, error, percentage, roof, slash, plus {
def calc a, op, b @ try_add, try_sub, try_mul, try_mul_loop, try_div, try_mod, \
add, sub, mul, mul_loop, div_mod, div, mod, bad, div_mod_flag, r, q, end \
< minus, asterisk, error, percentage, roof, slash, plus {
bit.zero error

try_add:
Expand Down Expand Up @@ -159,7 +163,7 @@ def calc a, op, b @ try_add, try_sub, try_mul, try_mul_loop, try_div, try_mod, a
;end

div_mod_flag:
bit
bit.bit
r:
bit.vec w
q:
Expand Down Expand Up @@ -206,11 +210,11 @@ def print_int x @ print_hex, end < hex_used {

op: bit.vec 8, 0
ascii: bit.vec 8, 0
error: bit 0
error: bit.bit 0
hex: bit.vec 4, 0
dec: bit.vec 4, 0
should_finish: bit 0
hex_used: bit 0
should_finish: bit.bit 0
hex_used: bit.bit 0

a: bit.vec w, 0
b: bit.vec w, 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
startup
stl.startup

test0:
bit.ptr_flip p0
bit.if d0, d00, d01
d00:
output '0'
stl.output '0'
;test1
d01:
output '1'
stl.output '1'
;test1

test1:
bit.ptr_jump p1
jump_to6:
output '6'
stl.output '6'
;test2
jump_to7:
output '7'
stl.output '7'
;test2

test2:
Expand All @@ -27,31 +27,29 @@ test2:
;p20
;p21
p20:
output 'N'
stl.output 'N'
;test3
p21:
output 'Y'
stl.output 'Y'
;test3

test3:
bit.zero d3_var
bit.xor_from_ptr d3_var, p3
bit.if d3_var, d30, d31
d30:
output 'F'
loop
stl.output 'F'
stl.loop
d31:
output 'T'
loop
stl.output 'T'
stl.loop



bit.ptr_init

p0:
bit.vec w, d0+dbit
d0:
bit 0 // 0 => 1, 1 => 0
bit.bit 0 // 0 => 1, 1 => 0

p1:
bit.vec w, d1
Expand All @@ -63,11 +61,14 @@ test3:
p2_jump:
bit.vec w, d2
d2:
bit 0 // 0 => N, 1 => Y
bit.bit 0 // 0 => N, 1 => Y

p3:
bit.vec w, d3
d3:
bit 1 // 0 => F, 1 => T
bit.bit 1 // 0 => F, 1 => T
d3_var:
bit 0
bit.bit 0


bit.pointers.ptr_init
32 changes: 16 additions & 16 deletions programs/concept_checks/casting.fj
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
startup
stl.startup

bit2hex h, b0
stl.bit2hex h, b0
hex.print_as_digit h, 0
bit2hex h, b1
stl.bit2hex h, b1
hex.print_as_digit h, 0
output '\n'
stl.output '\n'

bit2hex 12, hex, bits
stl.bit2hex 12, hex, bits
hex.print_as_digit 3, hex, 0
output '\n'
output '\n'
stl.output '\n'
stl.output '\n'

hex2bit 10, bits2, hex2
stl.hex2bit 10, bits2, hex2
hex.print_as_digit 10, hex2, 0
output '\n'
bit2hex 40, hex2, bits2
stl.output '\n'
stl.bit2hex 40, hex2, bits2
bit.print_hex_uint 40, bits2, 0
output '\n'
stl.output '\n'
bit.print_as_digit 40, bits2
output '\n'
stl.output '\n'

loop
stl.loop


b0: bit 0
b1: bit 1
h: hex
b0: bit.bit 0
b1: bit.bit 1
h: hex.hex
bits: bit.vec 12, 0x123
hex: hex.vec 3

Expand Down
Loading

0 comments on commit a956630

Please sign in to comment.