Web Analytics

igcc

⭐ 209 stars Traditional Chinese by alexandru-dinu

🌐 語言

互動式 GCC

tests contrib Code style: black

[!注意]
Andy Balaam 的原始倉庫在這裡:https://codeberg.org/andybalaam/igcc。

在這個分支中,我進行了一些重構,並嘗試讓它更容易使用。

[!WARNING]
這個專案是一個為了在某些情況下縮短 C/C++ 開發時回饋迴圈的嘗試,明顯並不適用於任何嚴肅用途。

互動式 GCC(igcc)是一個 C/C++ 的讀取-求值-輸出迴圈(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

類似專案

致謝

--- Tranlated By Open Ai Tx | Last indexed: 2025-12-11 ---