[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Chicken-users] Generating C
From: |
Norman Gray |
Subject: |
[Chicken-users] Generating C |
Date: |
Fri, 08 Jul 2016 19:46:15 +0100 |
Greetings
I'm trying (still) to generate C from Chicken code, with the intention
of compiling that on a machine without a Chicken install. This is, for
my purposes, the principal reason why I've been experimenting with
Chicken.
I must say, it's an uphill struggle. I've managed to get a toy program
to work, but not a non-trivial program with assorted dependencies.
I'm quite close to managing it, but can't compile one of my own modules.
I have a module db.scm which starts
% head -16 ../../db.scm
(module db
(with-connection-to
with-connection-to*
query/map
query/for-each
query/single)
(import scheme chicken)
(use posix
extras
(prefix sqlite3 sql:))
(use util) ; my module, in ../../util.scm
(define current-connection*
(make-parameter #f))
All the dependencies are, I think, assembled and compiled to .c and
.import.scm files, but...
% make
echo '((files "../../util.scm" "util.setup"))' >util.meta
echo '(standard-extension "util")' >util.setup
"/Data/tools/chicken-4.11.0/bin/csc" -t -unit util -optimize-level 3
-include-path ../.. -emit-all-import-libraries -output-file util.c
../../util.scm
"/Data/tools/chicken-4.11.0/bin/csc" -t -unit db -optimize-level 3
-include-path ../.. -emit-all-import-libraries -output-file db.c
../../db.scm
Warning: extension `sqlite3' is currently not installed
Warning: imported identifier doesn't exist in module chicken:
dynamic-wind
Warning: extension `util' is currently not installed
[panic] nursery is too small - try higher setting using the `-:s' option
- execution terminated
Error: shell command terminated with non-zero exit status 256:
'/Data/tools/chicken-4.11.0/bin/chicken' '../../db.scm' -output-file
'db.c' -unit db -optimize-level 3 -include-path ../..
-emit-all-import-libraries
make: *** [db.c] Error 1
I don't know what the problem is with dynamic-wind, but it doesn't seem
to matter. If I try
'/Data/tools/chicken-4.11.0/bin/chicken' -:s10000000 '../../db.scm'
-output-file 'db.c' -unit db -optimize-level 3 -include-path ../..
-emit-all-import-libraries
...I get a core dump; and if I try with -:s1000000 I get the same error
message. Given the error message, and runtime.c, it would appear that a
lack of stack size is not the real problem. This is somewhat similar to
the error described in <https://bugs.call-cc.org/ticket/1287>, which
went away when I created trivial extension files .meta/.setup. I have
generated util.meta and util.setup above.
The eggs and other dependencies of the code are at this stage compiled
to *.c and *.import.scm files.
I have no idea how to proceed from here. Can anyone shed any light?
----
The documentation at
<http://wiki.call-cc.org/man/4/Using%20the%20compiler> is perhaps a
trifle laconic, and saying 'This is naturally rather simplistic' doesn't
really fill in the blanks.
One useful thing to mention on that page would be that when compiling
modules, '-t -unit <modulename>' is necessary, otherwise we get
(intelligible in eventual retrospect) duplicate symbols when compiling.
Inspection of c-backend.scm solved that particular puzzle.
The build system, based on Makefile.* and *.make files, seems quite
narrowly targeted for the case of building Chicken itself. The
experiments I've tried suggest that it can be adapted to building an
assembly of .c files, when I get them, but it needs a bit of hacking for
that case, and feels a bit wild-west. Is that really the recommended
technique?
It would be seriously useful if chicken-install, for example, could work
out the recursive set of dependencies for a particular source file, and
print them in a reusable way. I wrote quite a lot of a tool to do this,
and to generate a Makefile which would assemble a kit and prepare to
build it. However it started to acquire more and more special cases,
and it became clear that it could never really work reliably, given the
freedom of action afforded to the contents of <egg>.setup. Given that
chicken-install already has to deal with this complication, would it be
reasonable for it to gain an option to emit the dependencies, ideally in
the form of a Makefile?
I still have the impression that the ability to generate distributable C
is a key feature of Chicken (is this true?), which makes it odd that
this is documented only in a few dozen lines at the bottom of the 'Using
the compiler' page, and odd that an apparently simple build -- I'm not
doing anything exotic -- is quite this difficult, and requires quite so
much use of the source (Luke). Have I (as happens so often) got the
wrong end of the stick?
Thanks for any advice.
Best wishes,
Norman
--
Norman Gray : https://nxg.me.uk
SUPA School of Physics and Astronomy, University of Glasgow, UK
- [Chicken-users] Generating C,
Norman Gray <=