-
Notifications
You must be signed in to change notification settings - Fork 25
/
README
147 lines (103 loc) · 4.29 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
Vacietis is a C compiler for Common Lisp systems.
Vacietis works by loading C code into a Common Lisp runtime as though
it were Lisp code, where it can then be compiled or evaled. The loaded
C code has the same function calling convention as regular CL code and
uses the same numerical representations. C memory is backed by regular
Common Lisp arrays.
Vacietis comes with a libc implemented in portable Common Lisp.
* INSTALLING:
----------
You can obtain Vacietis from github:
git clone https://github.com/vsedach/Vacietis.git
All Vacietis dependencies are available via Quicklisp
(http://www.quicklisp.org/). If you put Vacietis in
quicklisp/local-projects/ you can just load it with
(ql:quickload "vacietis")
* USAGE:
-----
C code can be read in the same way as regular Lisp code by using
readtables:
(let ((*readtable* vacietis:c-readtable)
(vacietis:*compiler-state* (vacietis:make-compiler-state)))
(read <some stream>))
The Vacietis reader keeps track of type and preprocessor
macro declarations in a compiler state object bound by
*compiler-state*. This mechanism is exposed to make it possible to
create things like C REPLs.
To simplify loading C files, a convenience function is provided that
sets up the readtable, compiler state, and additional debugging
information before calling LOAD:
(vacietis:load-c-file "/foo/bar/file.c")
* COMPILER EXECUTABLE:
-------------------
The system vacietis.vcc produces a toy C compiler executable that can
take a single-file C program and produce an executable
program. Currently it needs CCL, CLISP, or SBCL to work. Sample run:
(ql:quickload "vacietis.vcc") will produce the executable vcc/vcc in
the Vacietis source directory.
$ ./vcc ../test/programs/hanly-83-scanf/main.c
Produces the file a.out in the current directory.
$ ./a.out
Enter 8 numbers separated by blanks or <return>s
>
* TECHNICAL DETAILS:
-----------------
Vacietis uses the memory model of Common Lisp as is, so sizeof of the
primitive data types (char, int, float etc.) is all 1. This shouldn't
be a problem for most C code, but some C programs claim to be portable
while making assumptions that things can be cast into an array of
chars to be manipulated. These programs won't work under Vacietis.
The basic idea for the Vacietis runtime and memory model comes from
Scott L. Burson's Zeta-C compiler for Lisp Machines:
http://www.bitsavers.org/bits/TI/Explorer/zeta-c/
The technique for representing pointers to arbitrary C lvalues as
closures was first demonstrated by Oleg Kiselyov:
http://okmij.org/ftp/Scheme/pointer-as-closure.txt
The idea for a combined single-pass preprocessor/tokenizer/parser
comes from Fabrice Bellard's TCC: http://bellard.org/tcc/
* OBTAINING CODE AND HELP:
-----------------------
The official Vacietis repository is at:
https://github.com/vsedach/vacietis
There is a Vacietis mailing list on the web:
http://groups.google.com/group/vacietis
Bug reports can be sent to the mailing list:
http://groups.google.com/group/vacietis
the github issue tracker:
https://github.com/vsedach/vacietis
or directly to the author:
vsedach@gmail.com
* UNIT TESTS:
----------
(ql:quickload "vacietis.test")
(vacietis.test:run-tests)
(eos:run! 'vacietis.test.reader::preprocessor-nested) ; individual test case
The Vacietis test suite includes a variety of code that tests the
compiler and libc.
* TODO:
----
- pointer scaling
- enums: assignment of arbitrary values to enum labels
- struct call by value
- pass arguments to main()
- implement overloading class scope correctly (see H&S p. 147)
- libc stdio: binary streams
- libc stddef: offsetof
- libc signal
- libc stdlib: div/ldiv, srand, exit cleanup, bsearch, qsort
- libc time
- libc setjmp
* THINGS THAT PROBABLY WON'T BE SUPPORTED:
---------------------------------------
- trying to cast arrays of chars to other types (mmap)
- any kind of GCC extension
* LICENSING INFORMATION
---------------------
Vacietis is authored by Vladimir Sedach <vsedach@gmail.com>; the
latest copyright year is 2012.
Vacietis is licensed under the LLGPL (see the file LICENSE included
with the distribution for details).
Portions of the Vacietis libc may be derived from Zeta-C (released
into the public domain by its author, Scott L. Burson) and Erik
Andersen's <andersen@codepoet.org> LGPL-licensed uClibc
(http://www.uclibc.org/)