Web Analytics

igcc

⭐ 209 stars Thai by alexandru-dinu

🌐 ภาษา

อินเทอร์แอคทีฟ GCC

tests contrib Code style: black

[!NOTE]
รีโปต้นฉบับจาก Andy Balaam อยู่ที่นี่: https://codeberg.org/andybalaam/igcc.
ใน fork นี้ ฉันได้ปรับปรุงโค้ดบางส่วนและพยายามทำให้ใช้งานง่ายขึ้น

[!WARNING]
โปรเจกต์นี้เป็นความพยายามแบบหยาบๆ เพื่อให้ได้ feedback loop ที่สั้นลงเมื่อทำงานกับ C/C++ ในบางกรณี และแน่นอนว่าไม่ได้ออกแบบมาสำหรับงานจริงจัง

Interactive GCC (igcc) คือ read-eval-print loop (REPL) สำหรับ C/C++ โดยทำงานโดยการแก้ไขไฟล์ source หลักตามคำสั่งของผู้ใช้ จากนั้นจะคอมไพล์ source หลังจากแต่ละครั้งที่มีการแก้ไข แล้วรัน binary ที่ได้ และรวบรวม stdout & stderr

รองรับการป้อนข้อมูลแบบหลายบรรทัด (block) ดังนั้นคุณสามารถเพิ่มหลายบรรทัดในครั้งเดียวและเรียกใช้งานคอมไพเลอร์เพียงครั้งเดียว (ตัวอย่างด้านล่าง)

คุณสามารถ include header files ต่างๆ ได้ เพื่อความสะดวก มี header เริ่มต้นที่ include ให้: 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 จาก config) ข้อดีคือช่วยหลีกเลี่ยงการเรียกคอมไพเลอร์หลายครั้ง

$ 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 ---