Giter VIP home page Giter VIP logo

gridpietgenerator's Introduction

GridPietGenerator

Automatic source-code generator of Piet, the esoteric programming language

Readme in English

README in English may be coming soon...

概要

難解プログラミング言語Pietの ソースコード画像自動生成ツール(C++)です。 テキストで記述された処理フローからPietソースコードを生成します。

Image

手順

  1. Pietに実行させる処理フローをテキストファイルに保存する。(処理フローは独自の言語で記述する。)
  2. PietInterpreterで処理フローが正しく動くか確認する。
  3. PietGeneratorで処理フローを画像に変換する。
  4. やったぜ。

使用例

「10の階乗を計算するプログラム」を例にあげます。

処理フローの記述

処理フローは以下のようになります。これを"fact.txt"として保存します。 記述方法はこちらを参照してください。

# calculate 10!=10x9x8x7x6x5x4x3x2x1=3,628,800
push1 push2 push5 mul
:loop
dup
push3 push1 roll
mul
push2 push1 roll
push1 sub
dup
if:loop:end
:end
pop outn end

処理フローの動作確認

GridPietInterpreterを使うと、テキストファイルの処理フローを直接実行します。

Pietソースコードを出力する前に動作確認ができます。 (もちろん、Pietソースコードを出力した後に、PietインタプリタでデバッグしてもOKです。)

./GridPietInterpreter fact.txt

実行例は以下の通りです。

=== Contents of Flow Description File (fact.txt) ===
push1 push2 push5 mul
:loop
 ... (中略:読み込まれたファイルがそのまま出力されます。) ...
:end
pop outn end

=== /Contents of Flow Description File (fact.txt) ===

===PietInterpreter - Commands [00000042DD8FF600]
0-1 | push1
0-2 | push2
0-3 | push5
0-4 | mul
1-1 | :loop
 ... (中略:読み込まれた命令が、以下の形式で順に出力されます。) ...
 ... ([テキスト中の行数]-[行内での順番] | [読み込んだ命令]) ...
9-1 | :end
10-1 | pop
10-2 | outn
10-3 | end


 ... (以下、インタプリタの各ステップにおける状態を出力します。) ...
===PietInterpreter [00000042DD8FF600]
cnt :1
pc  :1
cur : push1 @ l.0-1
next: push2 @ l.0-2
stack: [00000 :     1]
output:


===PietInterpreter [00000042DD8FF600]
cnt :2
pc  :2
cur : push2 @ l.0-2
next: push5 @ l.0-3
stack: [00000 :     1] [00001 :     2]
output:

 ... (出力形式は以下の通りです。) ...
===PietInterpreter [00000042DD8FF600]
cnt :18                                (プログラム開始時点からのステップ数)
pc  :5                                 (次ステップでのプログラムカウンタの値)
cur : :loop @ l.1-1                    (直前に実行した命令)
next: dup @ l.2-1                      (次ステップで実行する命令)
stack: [00000 :    10] [00001 :     9] (スタックの状態 [ボトムからの距離 : 値])
output:                                (現時点までの出力結果)
 ...  ...

===PietInterpreter [00000042DD8FF600]
cnt :137
pc  :20
cur : outn @ l.10-2
next: end @ l.10-3
stack:
output:
3628800

Pietソースコードの出力

GridPietGeneratorを使うと、テキストファイルからPietソースコード画像(バイナリppm形式)を生成できます。

  • 入力ファイル名をオプションなしで指定
  • 出力ファイル名を-oオプションで指定
./GridPietGenerator fact.txt -o pietSource.ppm

出力画像の例 Output Image

詳細な情報を出力するオプションもあります。

Usage : ./GridPietGenerator [inputFileName] ...
[Usage]:
 --csv -c [arg]
   output path for piet design information in CSV format
 --log -l [arg]
   output path for debug log
 --ascii -a [arg]
   output path for piet ascii file
 --output -o [arg]
   output path for piet source code
  • -a,--ascii : Pietソースコード画像の配置を表すファイルを出力
    • テキストファイル
    • PietEmbedderの入力に使うと、任意の画像にPietソースコード(上記ppmファイル)を埋め込めます。
  • -c, --csv : 詳細調査用csvファイルを出力(デバッグ用)
  • -l,--log : コンソール出力をファイルに出力(デバッグ用)
./GridPietGenerator fact.txt -o pietSource.ppm -a ascii.txt -c debug.csv -l console.log

特徴

  • 出力画像はほぼ正方形になるようにしています。
  • 黒ブロックの使用を極力控えています。
  • 画像端で処理フローの大部分を処理し、画像**には多くの余白ができます。
  • PietEmbedderと組み合わせると、任意の画像にPietソースコードを埋め込めます。

アルゴリズム

概要はこちら

ビルド

要件

C++のコンパイラのみ。特別なライブラリのインストールは不要。

手順

  • ライブラリ不要のため、srcファイル内のcppファイルを直接コンパイルすることもできます。
g++ -o GridPietGenerator GridPietGenerator.cpp
g++ -o GridPietInterpreter GridPietInterpreter.cpp
  • cmakeも使えます。
    • 要件:version >= 2.8
git clone https://github.com/Y-mos/GridPietGenerator.git
cd GridPietGenerator
mkdir build
cd build
cmake ..
make

ライセンス

BSD 3-Clause License (LISENCE)参照

問合せ / Contact

Y-mos

twitter:Y-mos

gridpietgenerator's People

Contributors

y-mos avatar

Stargazers

 avatar

Watchers

 avatar

gridpietgenerator's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.