chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] need idea for read-syntax


From: felix
Subject: Re: [Chicken-users] need idea for read-syntax
Date: Sat, 15 Nov 2003 15:30:47 +0100
User-agent: Opera7.11/Linux M2 build 406

On Sat, 15 Nov 2003 11:18:43 +0000, Category 5 <address@hidden> wrote:

Hmmn!  Interesting challenge.  I played with this for a while and the
most promising syntax I was able to come up with was:

statement:         #[ doSomeInitStuff(); ]#
typed expression:  #[[c-string] my_version_string]#

I think the significance of C embedding justifies the use of #[...] and
most other syntax overloads or overcomplicates.  From a parsing point of
view you always know that #[ starts some inline C and it's easy to then
check for the #[[ to tell a typed expression from a statement.  It's
also helpful for expression readability to see the type first.


This looks very good. Thanks for the feedback!

I'm a bit unclear on the statement case, though; what's the return value
of an inline C statement?  Do you intend to allow for just one statement
or a sequence of them?  If sequences of statements are allowed, this
seems pretty similar to #>...<#, apart from program context.


Statements inside #[ ... ]# always returns (void). The expansion will be something like this:

(foreign-code " ... ")

which in turn expands into (for the curious):

(begin
(declare (foreign-declare "static C_word <TMP>() { ... ; return C_SCHEME_UNDEFINED; }"))
 (##core#inline "<TMP>") )      ; generate an inline call

The typed expression expands into:

(foreign-code " ... " <TYPE>)

which ends up as:

(begin
 (define-foreign-variable <TMP> <TYPE> " ... ")
 <TMP>)

The difference between #[ ... ]# and #> ... <# is that the latter expands into a declaration at the start of the generated code and the former is put into a static function. Program context doesn't really exist, since everywhere #> ... <# may be used is also a suitable context for #[ ... ]# (but one expands into a declaration part and the other into a code sequence to be run at the current position, even (and especially) if it appears at toplevel), since in
Scheme there is no "declaration" section.


cheers,
felix





reply via email to

[Prev in Thread] Current Thread [Next in Thread]