-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge: pull request #5 from raklaptudirm/optimization
feat: more and better instruction optimization
- Loading branch information
Showing
7 changed files
with
240 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<h1> <samp>brainfuck</samp> Interpreter, Transpiler, Optimizer, and Toolkit </h1> | ||
|
||
<samp>brainfuck</samp> is a complete language toolkit for the | ||
[brainfuck](https://en.wikipedia.org/wiki/Brainfuck) esoteric | ||
programming language. | ||
|
||
> This project is a work is progress, so some of the functionality | ||
> is missing. | ||
<div align="center"> | ||
<img src="https://user-images.githubusercontent.com/68542775/175783619-bc3e723a-0540-4062-8e6b-cd96fd2b7525.PNG" alt="mandelbrot"> | ||
</div> | ||
|
||
|
||
### Installation | ||
|
||
``` | ||
git clone https://github.com/raklaptudirm/brainfuck.git | ||
cd brainfuck | ||
go build ./cmd/brainfuck | ||
``` | ||
|
||
### Usage | ||
|
||
``` | ||
brainfuck <file> | ||
``` | ||
|
||
### References | ||
|
||
- https://en.wikipedia.org/wiki/Brainfuck | ||
- http://calmerthanyouare.org/2015/01/07/optimizing-brainfuck.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright © 2022 Rak Laptudirm <[email protected]> | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"laptudirm.com/x/brainfuck/pkg/lexer" | ||
"laptudirm.com/x/brainfuck/pkg/parser" | ||
"laptudirm.com/x/brainfuck/pkg/targets/opcode" | ||
) | ||
|
||
func main() { | ||
if err := mainFunc(); err != nil { | ||
fmt.Fprintln(os.Stderr, err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func mainFunc() error { | ||
if len(os.Args) != 2 { | ||
return fmt.Errorf("usage: brainfuck <file>") | ||
} | ||
|
||
// extract filename | ||
filename := os.Args[1] | ||
|
||
// read source code | ||
source, err := os.ReadFile(filename) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// parse source code | ||
ins, err := parser.Parse(lexer.Lex(source)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// compile to opcode and run | ||
oc := opcode.Compile(ins) | ||
opcode.Run(oc) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.