Opened 14 years ago

Closed 14 years ago

Last modified 12 years ago

#574 closed defect (fixed)

Define-constant cannot be used with the FFI

Reported by: sjamaan Owned by: felix winkelmann
Priority: minor Milestone: 4.9.0
Component: compiler Version: 4.6.x
Keywords: constants, ffi, foreign values Cc:
Estimated difficulty:

Description

I'm not 100% sure this is even a bug or just bad documentation/error messaging, but here goes:

If I compile the following "program", I get an error message:

(define-constant one (foreign-value "1" int))

The error says

Syntax error: cannot evaluate compiler-special-form

        (##core#define-foreign-variable code_0 int "1")

I can see why; in compiler.scm, line 1111 under ##core#define-constant it runs eval on the constant that's defined (unless it's a collapsible literal) but of course eval doesn't have access to compiler syntax, so it dies.

The question is - should this be an error or not? It might make sense to just put the foreign value as-is in each usage point.

PS: there's a small spelling error in there, the predicate collapsable-literal? should be collapsible-literal? with an "i" instead of an "a".

Change History (4)

comment:1 Changed 14 years ago by sjamaan

Oddly enough, the following does not give an error. When I run it, it cleanly prints the number 1 on stdout. (well, not that odd, as it's a collapsible literal symbol "x", I guess...)

What I really don't understand is why it doesn't say "error in constant evaluation of ~S for named constant ~S" when eval fails. Is the syntax-error-hook bound to some odd error handler which quits the compiler immediately? If so, any error in eval would cause this to happen, I think?

(define x (foreign-value "1" int))
(define-constant one x)
(print one)

comment:2 Changed 14 years ago by felix winkelmann

Milestone: 4.8.0
Priority: not urgent at allminor

The constant-value must be evaluatable at compile-time. I will document this. The example you give later actually is a bug - "x" is treated as a symbol, as you correctly point out. Yet it expands into a variable reference. I have to investigate this more.

comment:3 Changed 14 years ago by felix winkelmann

Resolution: fixed
Status: newclosed

The example you give in your later comment will now trigger an error. Yes, any error in the evaluation of the constant expression will abort the compilation.

comment:4 Changed 12 years ago by felix winkelmann

Milestone: 4.8.04.9.0

Milestone 4.8.0 deleted

Note: See TracTickets for help on using tickets.