インタラクティブGCC
[!NOTE]
Andy Balaamによるオリジナルリポジトリはこちらです: https://codeberg.org/andybalaam/igcc.
このフォークでは、リファクタリングを行い、使いやすくなるように工夫しました。
[!WARNING]
このプロジェクトは、C/C++での開発時にフィードバックループを短縮することを目的としたハッキーな試みであり、明らかに本格的な用途を想定したものではありません。
インタラクティブGCC(igcc)は、C/C++用のread-eval-printループ(REPL)です。これは、ユーザーコマンドでベースとなるソースファイルを操作し、各変更後にソースをコンパイルし、生成されたバイナリを実行してそのstdoutとstderrを収集することで動作します。
複数行(ブロック)入力もサポートされており、一度に複数行を追加してコンパイラを一度だけ呼び出すことができます(下記の例を参照)。
様々なヘッダファイルをインクルードできます。利便性のため、デフォルトでboilerplate.hがインクルードされています。また、using namespace std;はデフォルトでは有効になっていませんが、明示的に追加することができます(下記の例参照)。
igccの様々な設定項目は、config.yamlで変更できます。
はじめに
最も簡単な始め方は、pipxを使うことです。pipx install git+https://github.com/alexandru-dinu/igcc.git
または、uv を使うこともできます。
uv tool run git+https://github.com/alexandru-dinu/igcc
開発者向けには:
git clone https://github.com/alexandru-dinu/igcc.git
cd igcc
uv sync使用可能な引数:
usage: igcc [-h] [-I INCLUDE [INCLUDE ...]] [-L LIBDIR [LIBDIR ...]]
[-l LIB [LIB ...]]options:
-h, --help show this help message and exit
-I INCLUDE [INCLUDE ...]
Add INCLUDE to the list of directories to be searched
for header files.
-L LIBDIR [LIBDIR ...]
Add LIBDIR to the list of directories to be searched
for library files.
-l LIB [LIB ...] Search the library LIB when linking.
コードはGCC(g++)でコンパイルされ、結果(あれば)が表示されます。
ヘルプを表示するには .h と入力してください。
$ igcc
[1]> .h
.h Show this help message
.e Show the last compile errors/warnings
.l List the code you have entered
.L List the whole program as given to the compiler
.r Redo undone command
.u Undo previous command
.q Quit例
$ igcc
[1]> int a = 5;
[2]> a += 2;
[3]> using namespace std;
[4]> cout << a << endl;
7[5]> int b = 17;
[6]> a *= b;
[7]> cout << a << ", " << b << endl;
119, 17
[8]> .L
#include "boilerplate.h"
using namespace std;
int main(void) {
int a = 5;
a += 2;
cout << a << endl;
int b = 17;
a *= b;
cout << a << ", " << b << endl;
return 0;
}
複数行入力がサポートされています(設定のmultiline_markerを確認してください)。利点は複数回のコンパイラ呼び出しを回避できることです。
$ igcc
[1]> .m
... for (int i = 0; i < 10; i++) {
... std::cout << i << " ";
... }
... std::cout << "\n";
... .m
0 1 2 3 4 5 6 7 8 9ヘッダーを含めることができます:
$ igcc
[1]> #include
[2]> std::vector xs{1,2,3};
[3]> xs.push_back(17);
[4]> .m
... for (auto x : xs) {
... std::cout << x << " ";
... }
... .m
1 2 3 17
ライブラリはリンク可能です:$ igcc -lpthread
[ 1]> #include
[ 2]> pthread_t thr;
[ 3]> const char* msg = "Hello, World!";
[ 4]> // assuming print_msg is defined somewhere
[ 5]> int ret = pthread_create(&thr, NULL, print_msg, (void*) msg); pthread_join(thr, NULL);
Hello, World! コマンドを元に戻すこともできます:
$ igcc
[1]> int x = 2
Compile error - type .e to see it[2]> .e
: In function ‘int main()’:
:7:5: error: expected ‘,’ or ‘;’ before ‘return’
:5:9: warning: unused variable ‘x’ [-Wunused-variable]
[2]> .u
Undone int x = 2
[1]> int x = 2;
[2]> .L
#include "boilerplate.h"
int main(void) {
int x = 2;
return 0;
}
... または以前に取り消したコマンドをやり直す:
$ igcc
[1]> int x = 2;
[2]> std::cout << x;
2
[3]> .u
Undone std::cout << x;
[2]> .L
#include "boilerplate.h"
int main(void) {
int x = 2;
return 0;
}
[2]> .r
Redone std::cout << x;
2
[3]> .L
#include "boilerplate.h"
int main(void) {
int x = 2;
std::cout << x;
return 0;
}
将来の作業
https://github.com/alexandru-dinu/igcc/issues を参照してください類似プロジェクト
- https://github.com/BenBrock/reple: コンパイル言語向けの「リプレイベース」REPL
- https://github.com/root-project/cling: cling C++インタープリタ
クレジット
- IGCC ホームページ
- IGCC Sourceforge ページ
- Andy Balaam のホームページ
- Andy Balaam のブログ
- Andy Balaam への連絡は axis3x3 at users dot sourceforge dot net で可能です
- IGCC は 2009 年 Andy Balaam に著作権があります
- IGCC は GNU 一般公衆利用許諾契約書バージョン3の条件の下でリリースされたフリーソフトウェアです
- IGCC は無保証で提供されます