[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Chicken-users] Compiling w/ syntax-case
From: |
Matt Gushee |
Subject: |
[Chicken-users] Compiling w/ syntax-case |
Date: |
Sun, 07 Dec 2008 20:52:08 -0700 |
User-agent: |
Thunderbird 2.0.0.16 (X11/20080726) |
Hello, all--
Let's see ... first of all, I'm sure I'm making some kind of very basic
error. I am fairly new to Chicken and Scheme in general. Not a total
beginner (and I have some other FP experience, mainly w/ OCaml), but I
have made previous attempts to master Scheme and not quite made it ...
kinda like a rocket failing to achieve escape velocity--maybe this time
I'll make it into orbit :-)
But anyway, I have previously worked through various tutorials and
developed a few simple programs w/ Chicken, and I'm now attempting to
create an extension library for the first time. Not my original work,
though--this is in fact a port from PLT Scheme of the 'scm-pdf' package,
which in turn was ported to PLT from the 'cl-pdf' Common Lisp package.
So, the project requires syntax-case, since it has both syntax-rules
macros and modules. I'm not sure the modules are necessary or desirable,
since PLT modules are significantly different from syntax-case modules,
but my plan was to make the minimum changes necessary to get the library
working under Chicken, then think about the structure.
But I don't seem to be able to compile the code correctly. There are two
main source code files:
pdf-util.scm [mainly containing definitions of drawing functions]
pdf.scm [the main library, which depends on pdf-util.scm]
And there is also
pdf-examples.scm [which depends on pdf.scm]
I can load either pdf.scm or pdf-examples.scm into the REPL. I have not
yet confirmed that the code actually works, but that is due to problems
with the module structure, which I think are a separate issue. Anyway, I
can load the code w/o fatal errors.
Not so when I try to compile a library.
My basic approach has been:
1. csc -c pdf-util.scm
2. csc -c pdf.scm
3. csc [various options] pdf-util.o pdf.o
I have tried different combinations of options in Step 3--mostly one or
more of '-shared', '-dynamic', and '-extension', and in some cases have
managed to compile a 'pdf.so' without error. But no matter what I do, I
cannot load the compiled library into the REPL. I have seen various
errors, but the most common is
undefined reference to `C_syntax_case_toplevel'
When I Google that string, the only answer I find is to install the
syntax-case egg. But I definitely have syntax-case installed, and in the
course of learning how to use it have written several macros that worked
as expected, at least when I loaded the source code into the REPL.
So it seems there is some problem with my compiler invocation or my
toplevel declarations, or both. Here are the beginnings of both files:
pdf-util.scm
============
;(declare ; These declarations
; (unit pdf-util) ; caused compiler errors
; (uses syntax-case format-modular))
;(require-extension syntax-case format-modular mathh)
(require-for-syntax 'syntax-case)
(require-extension format-modular mathh)
(define-constant pi 3.14159) ; Maybe use mathh egg?
; (module pdf-util mzscheme
;
(module pdf-util
( set-page-stream
;in-text-mode ; The commented-out items in this list
set-font ; are macros.
;define-pdf-op
[many symbols omitted for brevity]
star)
;; The following is all PLT stuff which I'll keep just until I know
;; that I have the module/unit interfaces right.
; (require (lib "math.ss")
; (lib "list.ss")
; (rename (lib "format.ss" "format") fmt slib:format))
; (provide (all-defined-except
; *page-stream*
; escape-table
; arc-to
; bezarc
; distance
; angle2
; angle-3points
; midpoint
; fillet))
pdf.scm
=======
;(declare
; (unit pdf)
; (uses syntax-case format-modular pdf-util))
;(require-extension syntax-case format-modular pdf-util)
;(require-for-syntax 'syntax-case)
;(require-extension format-modular pdf-util)
(require-extension format-modular)
(require-for-syntax 'syntax-case 'pdf-util)
; (module pdf mzscheme
(module pdf
;; There doesn't seem to be any way to do this w/ syntax-case
;; modules
; (provide (all-from "pdf-util.ss")
( ;; FROM pdf-util
set-page-stream
;in-text-mode
set-font
;define-pdf-op
[and many more symbols, most imported from pdf-util]
page-height)
(import pdf-util)
Some observations and questions about these:
* There are macros defined in each source file.
* The pdf module does not use any macros defined in pdf-util, though
most of the functions it imports from pdf-util are macro expansions.
* Is there a conflict between 'unit' and 'uses' declarations and
syntax-case modules? From the compiler errors I saw today, it
seems so.
* Do I need 'require-for-syntax' at all? And if so, is it supposed to
be used *instead of* or *in addition to* a simple 'require' or
'require-extension'? Conversely, is it harmful to use
'require-for-syntax' when it is not required (other than perhaps
degrading performance a bit)?
* How does the '-extension' command-line option relate to '-shared'
and '-dynamic'? Can I/should I use all three?
And finally: can someone show me the proper way to compile a project of
this sort? I've looked at the Egg Tutorial, but it seems to assume a
simple library which can be reasonably structured in a single
compilation unit. A PDF generator, as you no doubt know, is a rather
complex undertaking, and it seems wise to split it up into several
components. Note also that the code I am starting with has limited
functionality, but my goal is to build a full-featured and up-to-date
PDF library.
Thanks for any light you can shed on this!
Oh, I almost forgot. I am running Chicken 3.4.0 on Linux (Arch Linux,
about one month since my last full upgrade).
--
Matt Gushee
: Bantam - lightweight file manager : matt.gushee.net/software/bantam/ :
: RASCL's A Simple Configuration Language : matt.gushee.net/rascl/ :
- [Chicken-users] Compiling w/ syntax-case,
Matt Gushee <=