Skip to content

Commit ccdfc36

Browse files
authored
Merge pull request #739 from edwinb/refcount-c
Experimental C backend with reference counting
2 parents de58c66 + 77ba750 commit ccdfc36

28 files changed

+3634
-5
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Compiler changes:
1919

2020
* Added primitives to the parsing library used in the compiler to get more precise
2121
boundaries to the AST nodes `FC`.
22+
* New experimental ``refc`` code generator, which generates C with reference
23+
counting.
2224

2325
REPL/IDE mode changes:
2426

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,11 @@ test:
8787

8888
support:
8989
@${MAKE} -C support/c
90+
@${MAKE} -C support/refc
9091

9192
support-clean:
9293
@${MAKE} -C support/c clean
94+
@${MAKE} -C support/refc clean
9395

9496
clean-libs:
9597
${MAKE} -C libs/prelude clean
@@ -129,6 +131,7 @@ install-support:
129131
install support/gambit/* ${PREFIX}/idris2-${IDRIS2_VERSION}/support/gambit
130132
install support/js/* ${PREFIX}/idris2-${IDRIS2_VERSION}/support/js
131133
@${MAKE} -C support/c install
134+
@${MAKE} -C support/refc install
132135

133136
install-libs:
134137
${MAKE} -C libs/prelude install IDRIS2=../../${TARGET} IDRIS2_PATH=${IDRIS2_BOOT_PATH}

Release/mkdist.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ git checkout tags/v$1
1717
rm -rf .git
1818
rm -rf .github
1919
rm .git*
20-
rm .travis*
20+
rm -f .travis*
2121
rm -rf Release
2222
find . -type f -name '.gitignore' -exec rm -f {} \;
2323

docs/source/backends/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,5 @@ or via the `IDRIS2_CG` environment variable.
6161
racket
6262
gambit
6363
javascript
64+
refc
6465
custom

docs/source/backends/refc.rst

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
*************************
2+
C with Reference Counting
3+
*************************
4+
5+
There is an experimental code generator which compiles to an executable via C,
6+
using a reference counting garbage collector. This is intended as a lightweight
7+
(i.e. minimal dependencies) code generator that can be ported to multiple
8+
platforms, especially those with memory constraints.
9+
10+
Performance is not as good as the Scheme based code generators, partly because
11+
the reference counting has not yet had any optimisation, and partly because of
12+
the limitations of C. However, the main goal is portability: the generated
13+
code should run on any platform that supports a C compiler.
14+
15+
This code generator can be accessed via the REPL command:
16+
17+
::
18+
19+
Main> :set cg refc
20+
21+
Alternatively, you can set it via the ``IDRIS2_CG`` environment variable:
22+
23+
::
24+
25+
$ export IDRIS2_CG=refc
26+
27+
The C compiler it invokes is determined by either the ``IDRIS2_CC`` or ``CC``
28+
environment variables. If neither is set, it uses ``cc``.
29+
30+
This code generator does not yet support `:exec`, just `:c`.
31+
32+
Also note that, if you link with any dynamic libraries for interfacing with
33+
C, you will need to arrange for them to be accessible via ``LD_LIBRARY_PATH``
34+
when running the executable. The default Idris 2 support libraries are
35+
statically linked.

idris2api.ipkg

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ modules =
2121
Compiler.ES.RemoveUnused,
2222
Compiler.ES.TailRec,
2323

24+
Compiler.RefC.RefC,
25+
2426
Compiler.Scheme.Chez,
2527
Compiler.Scheme.Racket,
2628
Compiler.Scheme.Gambit,

0 commit comments

Comments
 (0)