Skip to content

Commit

Permalink
BinFuck v0.0.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Takym committed Apr 16, 2024
1 parent 75ece71 commit d6dc0f6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
37 changes: 26 additions & 11 deletions BinFuck/BinFuck.csx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#r "System.Console"
using static System.Console;

string version = "0.0.0.3";
string version = "0.0.0.4";

if (Args.Count == 0) {
ShowUsage();
Expand Down Expand Up @@ -112,6 +112,7 @@ public class Runner
private int _index;
private int _stack_point;
private bool _do_subtract;
private bool _rw_int;

public Runner(List<string> sources, Encoding? enc = null, int memorySize = 2048)
{
Expand All @@ -121,6 +122,7 @@ public class Runner
_memory = new long[memorySize];
_stack_point = 0;
_do_subtract = false;
_rw_int = false;
}

public void RunAll()
Expand Down Expand Up @@ -195,14 +197,28 @@ public class Runner
case 'a': // Set do subtract flag to false
_do_subtract = false;
break;
case 'w': // Write a character
this.TryWriteChar(0);
case 'i': // Set read/write integer flag to true
_rw_int = true;
break;
case 'c': // Set read/write integer flag to false
_rw_int = false;
break;
case 'w': // Write a character or an integer
if (_rw_int) {
Write("{0:D}", _memory[_stack_point]);
} else {
this.TryWriteChar(0);
}
break;
case 'W': // Write a string
for (int j = 0; this.TryWriteChar(j); ++j) ;
break;
case 'r': // Read a character
_memory[_stack_point] = Read();
if (_rw_int) {
_memory[_stack_point] = long.TryParse(ReadLine(), out long result) ? result : 0;
} else {
_memory[_stack_point] = Read();
}
break;
case 'R': // Read a string
byte[] input1 = _enc.GetBytes(ReadLine() ?? string.Empty);
Expand All @@ -217,11 +233,12 @@ public class Runner
}
break;
case 'D': // Dump the runner information
WriteLine("Encoding: {0}", _enc.EncodingName);
WriteLine("Encoding : {0}", _enc.EncodingName);
WriteLine("Memory Size: {0}", _memory.Length);
WriteLine("Memory Type: {0}", _memory[0].GetType());
WriteLine("Stack Point: {0}", _stack_point);
WriteLine("Do Subtract: {0}", _do_subtract);
WriteLine("R/W Integer: {0}", _rw_int);
WriteLine("Use the \'d\' instruction to dump the memory.");
WriteLine("Use the \'_\' instruction to dump the list of functions.");
break;
Expand Down Expand Up @@ -290,18 +307,16 @@ public class Runner
break;
case '[': // Loop start
if (_memory[_stack_point] == 0) {
++i;
while (i < s.Length && s[i] != ']') {
do {
++i;
}
} while (i < s.Length && s[i] != ']');
}
break;
case ']': // Loop end
if (_memory[_stack_point] != 0) {
--i;
while (i >= 0 && s[i] != '[') {
do {
--i;
}
} while (i >= 0 && s[i] != '[');
}
break;
// default: /* ignore */ break;
Expand Down
12 changes: 10 additions & 2 deletions BinFuck/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Copyright (C) 2020-2024 Takym.
BinFuck is an esoteric programming language.
I developed by drawing on [Brainfuck](https://en.wikipedia.org/wiki/Brainfuck).
The naming origin is a programming language like machine language (binary).
Try `1[>rw<]` in REPL mode!
Try `1[>rw<]` or `irw>.99998cw<iw` in REPL mode!
Use `Dd_` to dump data.

## How to use
Expand All @@ -17,6 +17,10 @@ Use `Dd_` to dump data.
> bfk repl
> 999999999992=3>=>7=>=>3<<<<W
hello
> ir>r[-<+>]<w
1
2
3
```

### Run a script file
Expand All @@ -39,7 +43,7 @@ This interpreter is distributed under the [MIT License](LICENSE.md).
BinFuck は難解プログラミング言語です。
[Brainfuck](https://ja.wikipedia.org/wiki/Brainfuck) を参考に開発しました。
機械語(binary)の様なプログラミング言語であるというのが名称の由来です。
REPL モードで `1[>rw<]` を試してみてください。
REPL モードで `1[>rw<]` または `irw>.99998cw<iw` を試してみてください。
内部データを表示するには `Dd_` と入力してください。

## 使い方
Expand All @@ -49,6 +53,10 @@ REPL モードで `1[>rw<]` を試してみてください。
> bfk repl
> 999999999992=3>=>7=>=>3<<<<W
hello
> ir>r[-<+>]<w
1
2
3
```

### スクリプトファイルを実行する
Expand Down
4 changes: 2 additions & 2 deletions BinFuck/sample.bfk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# The BinFuck Interpreter #
# Copyright (C) 2020-2023 Takym. #
# Copyright (C) 2020-2024 Takym. #
# distributed under the MIT License. #

(.a999999999992=3>=>7=>=>3>.9+<<<<<W)@
(.ac999999999992=3>=>7=>=>3>.9+<<<<<W)@

0 comments on commit d6dc0f6

Please sign in to comment.