IGCC is a small hack pretending to be a real-eval-print loop (REPL) simulator for C/C++ programmers. It allows you to type C++ commands which are immediately compiled and executed. Underneath it uses the normal GCC exe for compiling. http://www.artificialworlds.net/wiki/IGCC
Find a file
Timo Tijhof b57a6c6bb0 Add support for Python 3
* Run `2to3 -w ./libigcc/*.py` on Python 3.13.3, which fixes
  "print" syntax errors [1] and most other issues.

* Change IGCCQuitException to inherit Exception, to fix [2].

* Change Popen() calls to set text=True, because otherwise they
  use binary for input/output. [2] The input from get_full_source()
  could be converted to binary using str.encode('utf-8'), but
  while that would avoid a crash, it would still return stdout/stderr
  as binary which, then makes for a confusing REPL where output
  is formatted as `b''`.

* Remove unwanted `end=' '` from print() in Runner.do_run.
  These were added by 2to3. Restores automatic newlines as before,
  to provide a clean g++ prompt after each submitted line.

* Fix sorted() call in test to use named `key` parameter. [3]

[1]:

```
$ python3 ./igcc
Traceback (most recent call last):
  File "/igcc/igcc"
  File "/igcc/libigcc/run.py", line 62
    print line
SyntaxError: Missing parentheses in call to 'print'.
```

[2]:

```
$ python3 ./igcc
g++> int a = 42;
Traceback (most recent call last):
  File "/igcc/libigcc/run.py", line 189, in do_run
    self.compile_error = run_compile( subs_compiler_command,
  File "/igcc/libigcc/run.py", line 102, in run_compile
    stdoutdata, stderrdata = compile_process.communicate(
  File "/usr/lib/python3.9/subprocess.py"
    input_view = memoryview(self._input)
TypeError: memoryview: a bytes-like object is required, not 'str'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/igcc/igcc"
    libigcc.run.run()
  File "/igcc/libigcc/run.py", line 288, in run
    except dot_commands.IGCCQuitException:
TypeError: catching classes that do not inherit from BaseException is not allowed
```

[3]:

```
Traceback (most recent call last):
  File "/igcc/./test-igcc", …
  File "/igcc/./test-igcc", line 249, in test_help_message
    run_program_regex_output( commands, expected_output_re )
  File "/igcc/./test-igcc", line 76, in run_program_regex_output
    libigcc.run.run( outputfile, stdinfile, False )
  File "/igcc/libigcc/run.py", line 287, in run
    Runner( options, inputfile, exefilename ).do_run()
  File "/igcc/libigcc/run.py", line 177, in do_run
    dot_commands.process( inp, self ) )
  File "/igcc/libigcc/dot_commands.py", line 90, in process
    return dot_h( runner )
  File "/igcc/libigcc/dot_commands.py", line 84, in dot_h
    for cmd in sorted( list(dot_commands.keys()), case_insensitive_string_compare ):
TypeError: sorted expected 1 argument, got 2
```
2025-08-14 00:59:34 +01:00
libigcc Add support for Python 3 2025-08-14 00:59:34 +01:00
test Allow specifying lib directories and libs to link against on the command line. 2009-08-21 02:31:51 +01:00
.gitignore Added a Makefile that knows how to make a source tarball. 2009-08-26 15:45:40 +01:00
COPYING.txt Added license and warranty information. 2009-08-21 02:45:32 +01:00
igcc Add support for Python 3 2025-08-14 00:59:34 +01:00
Makefile Add support for Python 3 2025-08-14 00:59:34 +01:00
README.txt Correct untar instructions. Fixes #2 2024-06-04 08:23:56 +01:00
test-igcc Add support for Python 3 2025-08-14 00:59:34 +01:00
test-igcc-slow Allow specifying lib directories and libs to link against on the command line. 2009-08-21 02:31:51 +01:00

Interactive GCC
===============

Interactive GCC (igcc) is a small hack pretending to be a real-eval-print loop
(REPL) for C/C++ programmers.

It can be used like this:

 $ ./igcc 
 g++> int a = 5;
 g++> a += 2;
 g++> cout << a << endl;
 7
 g++> --a;
 g++> cout << a << endl;
 6
 g++> 

It is possible to include header files you need like this:

 $ ./igcc 
 g++> #include <vector>
 g++> vector<int> myvec;
 g++> myvec.push_back( 17 );
 g++> printf( "%d\n", myvec.size() );
 1
 g++> myvec.push_back( 21 );
 g++> printf( "%d\n", myvec.size() );
 2
 g++> 

Compile errors can be tolerated until the code works:

 $ ./igcc
 g++> #include <map>
 g++> map<string,int> hits;
 g++> hits["foo"] = 12;
 g++> hits["bar"] = 15;
 g++> for( map<string,int>::iterator it = hits.begin(); it != hits.end(); ++it )
 [Compile error - type .e to see it.]
 g++> {
 [Compile error - type .e to see it.]
 g++> 	cout << it->first << " " << it->second << endl;
 [Compile error - type .e to see it.]
 g++> }
 bar 15
 foo 12
 g++> 

Extra include directories can be supplied:

 $ ./igcc -Itest/cpp -Itest/cpp2
 g++> #include "hello.h"
 g++> hello();
 Hello, 
 g++> #include "world.h"
 g++> world();
 world!
 g++> 

Libs can be linked:

 $ ./igcc -lm
 g++> #include "math.h"
 g++> cout << pow( 3, 3 ) << endl; // Actually a bad example since libm.a is already linked in C++
 27
 g++> 

Your own libs can be linked too:

 $ ./igcc -Itest/cpp -Ltest/cpp -lmylib
 g++> #include "mylib.h"
 g++> defined_in_cpp();
 defined_in_cpp saying hello.
 g++> 

The cstdio, iostream and string headers are automatically included, and the std
namespace is automatically in scope.

Downloading and using
---------------------

Download the IGCC tarball from the download area:

https://codeberg.org/andybalaam/igcc/releases

Untar it like so:

 tar -xf igcc-*.tar.gz

And then start the program like this:

 cd igcc-*/
 ./igcc

Then type the C++ code you want to execute. It will be compiled with GCC and the
results (if any) will be displayed.

Type .h to see some (minimal) help.

Links
-----

IGCC home page:
http://www.artificialworlds.net/wiki/IGCC/IGCC

IGCC project page:
https://codeberg.org/andybalaam/igcc

Andy Balaam's home page:
http://www.artificialworlds.net

Andy Balaam's blog:
http://www.artificialworlds.net/blog

Copyright
---------

IGCC is Copyright (C) 2009 Andy Balaam

IGCC is Free Software released under the terms of the GNU General Public License version 2 or later.

IGCC comes with NO WARRANTY.

See the file COPYING for more information.