Skip to content

Commit

Permalink
Merge pull request #30 from Sellig6792/develop
Browse files Browse the repository at this point in the history
v2.1.0
  • Loading branch information
Sellig6792 authored Jan 5, 2023
2 parents b478187 + c390801 commit a391ed0
Show file tree
Hide file tree
Showing 12 changed files with 284 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/feature_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:

test:
name: Test
needs: [style]
if: always()
runs-on: ubuntu-latest

strategy:
Expand Down
80 changes: 43 additions & 37 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,29 @@ env:
CARGO_TERM_COLOR: always

jobs:
# style:
# name: Check Style
# runs-on: ubuntu-latest
# steps:
# - name: Checkout
# uses: actions/checkout@v1
#
# - name: Install rust
# uses: actions-rs/toolchain@v1
# with:
# toolchain: stable
# components: rustfmt
# profile: minimal
# override: true
#
# - name: cargo fmt -- --check
# uses: actions-rs/cargo@v1
# with:
# command: fmt
# args: --all -- --check
style:
name: Check Style
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Install rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt
profile: minimal
override: true
- name: cargo fmt -- --check
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check


test:
name: Test
# needs: [style]
if: always()
runs-on: ubuntu-latest

strategy:
Expand Down Expand Up @@ -82,21 +80,30 @@ jobs:
if: startsWith(github.ref, 'refs/tags/')
strategy:
matrix:
os: [ ubuntu-latest ] # Default os for build
target: [ aarch64-unknown-linux-gnu,
armv7-unknown-linux-gnueabihf,
i686-unknown-linux-gnu, i686-unknown-linux-musl,
mips-unknown-linux-gnu, mips64-unknown-linux-gnuabi64, mips64el-unknown-linux-gnuabi64, mipsel-unknown-linux-gnu,
powerpc-unknown-linux-gnu, powerpc64-unknown-linux-gnu, powerpc64le-unknown-linux-gnu,
arm-unknown-linux-gnueabi,
x86_64-unknown-linux-gnu, x86_64-unknown-linux-musl, x86_64-pc-windows-gnu ]
os: [ ubuntu-latest ]

include:
i686-pc-windows-gnu, x86_64-pc-windows-gnu,
i686-unknown-linux-gnu, x86_64-unknown-linux-gnu,
x86_64-apple-darwin ]
exclude: # Do not build for macOS on Linux
- target: x86_64-apple-darwin
os: ubuntu-latest
include: # List of all targets to build for and the name for common mortals
- target: aarch64-unknown-linux-gnu
name: arm64
- target: i686-pc-windows-gnu
name: win-i686
- target: x86_64-pc-windows-gnu
name: win-x86_64
- target: i686-unknown-linux-gnu
name: linux-i686
- target: x86_64-unknown-linux-gnu
name: linux-x86_64
- target: x86_64-apple-darwin
name: macos
os: macos-latest



# Runs on latest ubuntu by default except for windows targets
runs-on: ${{ matrix.os }}

Expand All @@ -119,17 +126,16 @@ jobs:
args: --release --target ${{ matrix.target }}

- name: Rename binary (Linux & macOS)
if: matrix.target != 'x86_64-pc-windows-gnu'
run: mv target/${{ matrix.target }}/release/fbf target/${{ matrix.target }}/release/fbf-${{ matrix.target }}
if: matrix.target != 'x86_64-pc-windows-gnu' && matrix.target != 'i686-pc-windows-gnu'
run: mv target/${{ matrix.target }}/release/fbf target/${{ matrix.target }}/release/fbf-${{ matrix.name }}

- name: Rename binary (Windows)
if: matrix.target == 'x86_64-pc-windows-gnu'
run: mv target/${{ matrix.target }}/release/fbf.exe target/${{ matrix.target }}/release/fbf-${{ matrix.target }}.exe
if: matrix.target == 'x86_64-pc-windows-gnu' || matrix.target == 'i686-pc-windows-gnu'
run: mv target/${{ matrix.target }}/release/fbf.exe target/${{ matrix.target }}/release/fbf-${{ matrix.name }}.exe


- name: Upload release
uses: softprops/action-gh-release@v1
with:
files: target/${{ matrix.target }}/release/fbf-${{ matrix.target }}*
discussion_category_name: Q&A
files: target/${{ matrix.target }}/release/fbf-${{ matrix.name }}*
token: ${{ secrets.PAT_GITHUB }}
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fuckbrainfuck"
version = "0.1.0"
version = "2.1.0"
edition = "2021"
authors = ["Sellig6792 <sellig6792@gmail.com>"]
description = "The improved Brainfuck"
Expand Down
175 changes: 175 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
<div id="top"></div>

<!-- PROJECT SHIELDS -->
[![Contributors][contributors-shield]][contributors-url]
[![Forks][forks-shield]][forks-url]
[![Stargazers][stars-shield]][stars-url]
[![Issues][issues-shield]][issues-url]
[![MIT License][license-shield]][license-url]


<!-- PROJECT LOGO -->
<br />
<div align="center">
<a href="https://github.com/Sellig6792/FuckBrainfuck">
<img src="assets/logo.png" alt="Logo" width="80" height="auto">
</a>

### FuckBrainfuck
[Explore documentation][wiki] | [Report Bug][issues] | [Request Feature][issues]
</div>
<br/>


<!-- TABLE OF CONTENTS -->
1. [About the Project](#about-the-project)
2. [Installation](#installation)
- [Prebuilt Binaries](#1-prebuilt-binaries)
- [Building from Source](#2-building-from-source)
3. [Usage](#usage)
4. [Contributing](#contributing)
5. [License](#license)
6. [Contact](#contact)
7. [Acknowledgements](#acknowledgements)


<!-- ABOUT THE PROJECT -->
## About The Project

It all started on Graven's Discord server on June 26, 2022.
It was a joke that ended up on this shit...

So FuckBrainfuck was born. It is an improvement of the classic BrainFuck, with some new features and new commands.

Already implemented:

- [Functions][wiki-function]
- ["Safe" comments][wiki-comment]
- [Scopes for functions][wiki-scope]
- [Optimization][wiki-optimisation]

<p align="right">(<a href="#top">back to top</a>)</p>

### Built With
![Rust][rust-shield] ![Cargo][cargo-shield]

<p align="right">(<a href="#top">back to top</a>)</p>


## Installation

### 1. Prebuilt binaries

You can download the prebuilt binaries from the [releases page][release].
If your system is not supported, you can [build it yourself](#2-building-from-source).

### 2. Building from source

You need to have [Cargo](https://doc.rust-lang.org/cargo/getting-started/installation.html) installed.

```sh
git clone https://github.com/Sellig6792/FuckBrainfuck.git
cd FuckBrainfuck
cargo build --release
```

<p align="right">(<a href="#top">back to top</a>)</p>


<!-- USAGE EXAMPLES -->
## Usage
```
fbf [OPTIONS] <FILE>
```


### Options
`-O, --optimize` Optimize the code before executing it

`-V, --version` Prints version information

`-h, --help` Prints help information

<p align="right">(<a href="#top">back to top</a>)</p>


<!-- CONTRIBUTING -->
## Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create.
Any contributions you make are **greatly appreciated**.

If you have a suggestion that could make this better, please fork the repo and create a pull request.
You can also simply open an issue with the tag "enhancement".
Don't forget to give the project a star! Thanks again!

1. Fork the Project
2. Checkout the develop branch: `git checkout develop`
3. Create your Branch (feature or fix): `git checkout -b [feature/fix]/[name]`
4. Commit your Changes: `git commit -m 'Add some [...]`
5. Push to the Branch: `git push origin [feature/fix]/[name]`
6. Open a Pull Request to the develop branch and explain your changes

<p align="right">(<a href="#top">back to top</a>)</p>


<!-- LICENSE -->
## License

Distributed under the MIT License. See [the licence](LICENSE) for more information.

<p align="right">(<a href="#top">back to top</a>)</p>


<!-- CONTACT -->
## Contact

Sellig6792 - [@Sellig6792](https://twitter.com/Sellig6792) - sellig6792@gmail.com

<p align="right">(<a href="#top">back to top</a>)</p>


<!-- ACKNOWLEDGEMENTS -->
## Acknowledgements

* [Wikipedia - Brainfuck][wikipedia-brainfuck-url]
* [Astremy - Brainfuck Course (French)][astremy-brainfuck-pdf]

<p align="right">(<a href="#top">back to top</a>)</p>



<!-- MARKDOWN LINKS & IMAGES -->
[contributors-shield]: https://img.shields.io/github/contributors/Sellig6792/FuckBrainfuck.svg?style=for-the-badge
[contributors-url]: https://github.com/Sellig6792/FuckBrainfuck/graphs/contributors

[forks-shield]: https://img.shields.io/github/forks/Sellig6792/FuckBrainfuck.svg?style=for-the-badge
[forks-url]: https://github.com/Sellig6792/FuckBrainfuck/network/members

[stars-shield]: https://img.shields.io/github/stars/Sellig6792/FuckBrainfuck.svg?style=for-the-badge
[stars-url]: https://github.com/Sellig6792/FuckBrainfuck/stargazers

[issues-shield]: https://img.shields.io/github/issues/Sellig6792/FuckBrainfuck.svg?style=for-the-badge
[issues-url]: https://github.com/Sellig6792/FuckBrainfuck/issues

[license-shield]: https://img.shields.io/github/license/Sellig6792/FuckBrainfuck.svg?style=for-the-badge
[license-url]: https://github.com/Sellig6792/FuckBrainfuck/blob/main/LICENSE
[rust-shield]: https://img.shields.io/badge/-rust-black.svg?style=for-the-badge&logo=rust&colorB=555
[cargo-shield]: https://img.shields.io/badge/-cargo-black.svg?style=for-the-badge&logo=rust&colorB=555
[brainFuck-url]: https://en.wikipedia.org/wiki/Brainfuck
[brainFuck-shield]: https://img.shields.io/badge/-BrainFuck-black.svg?style=for-the-badge&logo=brainfuck&colorB=555

[graven-discord-url]: https://discord.gg/graven
[astremy-brainfuck-pdf]: https://cdn.discordapp.com/attachments/815331771197030441/824402769397940234/brainfuck.pdf
[wikipedia-brainfuck-url]: https://en.wikipedia.org/wiki/Brainfuck

[wiki]: https://github.com/Sellig6792/FuckBrainfuck/wiki

[wiki-function]: https://github.com/Sellig6792/FuckBrainfuck/wiki#functions
[wiki-optimisation]: https://github.com/Sellig6792/FuckBrainfuck/wiki#optimisation
[wiki-scope]: https://github.com/Sellig6792/FuckBrainfuck/wiki#scope
[wiki-comment]: https://github.com/Sellig6792/FuckBrainfuck/wiki#comments


[issues]: https://github.com/Sellig6792/FuckBrainfuck/issues
[release]: https://github.com/Sellig6792/FuckBrainfuck/releases
Binary file added assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 13 additions & 7 deletions src/ast/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,20 @@ pub struct Parser {

impl Parser {
pub fn new(program: String) -> Parser {
let program = program
.replace(' ', "")
.replace('\t', "")
.replace('\r', "")
.replace('\n', "");
let program = program.replace([' ', '\t', '\r', '\n'], "");

Parser { program }
}

pub fn parse(&mut self) -> Vec<Instruction> {
let (instructions, _) = self._parse(None, None);
return instructions;
instructions
}

fn _parse(&self, index: Option<usize>, stop_char: Option<char>) -> (Vec<Instruction>, usize) {
let mut index = index.unwrap_or(0);
let mut instructions = vec![];
let mut comment = false;

while index < self.program.len() {
let char = match self.program.chars().nth(index) {
Expand All @@ -33,6 +30,15 @@ impl Parser {
return (instructions, index);
}

if char == '#' {
comment = !comment;
}

if comment {
index += 1;
continue;
}

match char {
'+' => instructions.push(Instruction::new(InstructionType::Increment, None)),
'-' => instructions.push(Instruction::new(InstructionType::Decrement, None)),
Expand Down Expand Up @@ -89,6 +95,6 @@ impl Parser {
index += 1;
}

return (instructions, index);
(instructions, index)
}
}
2 changes: 1 addition & 1 deletion src/evaluation/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Cell {
pub fn sub<T: PrimInt>(&mut self, value: T) {
let sub: isize = self.value as isize - value.to_isize().unwrap();
self.value = if sub < 0 {
u8::MAX - (sub.abs() as u8 - 1)
u8::MAX - (sub.unsigned_abs() as u8 - 1)
} else {
sub as u8
};
Expand Down
Loading

0 comments on commit a391ed0

Please sign in to comment.