[clean-list] htoclean "cycle in spine detected"

Diederik van Arkel dvanarkel@mac.com
Mon, 12 Apr 2004 17:12:52 +0200


On Apr 12, 2004, at 4:24 PM, Tobias Neukom wrote:

> Hi everyone
>
> I'm trying to make an SDL (Simple DirectMedia Layer) binding for 
> Clean. But it seems that i don't understand htoclean:
>
> events.h
> -----------
>
> void cleansdlPumpEvents();
> Clean(cleansdlPumpEvents :: *World -> *World)
>
> events.c
> ----------
>
> void cleansdlPumpEvents()
> {
> }
>
> window.icl
> -------------
>
> module window
>
> import events
> import StdEnv, StdFile, StdDebug
>
> Start :: *World -> *World
> Start w
>    #    (c,w) =    trace_n "Create Console" (stdio w)
>        w = trace_n "DO NOTHING" (cleansdlPumpEvents w)
>        (ok,w) = trace_n "Close Console" (fclose c w)
>    =     w
>
> Output:
>
> Close Console
> DO NOTHING
> Create Console
> Run Time Warning: cycle in spine detected
>
> What does this "cycle in spine detected" mean? And why does it happen?
>

'cycle in spine' normally means that the runtime system detected an 
infinite reduction,
that is a non-terminating evualation. In this case it is actually 
indicating that your
stack has been clobbered (there is no way for you to have known this). 
This is due to
the code that has been generated for your ccall in cleansdlPumpEvents 
which only has the
*World as parameter, this is a special type and in this case is not 
treated correctly by
the code generator. If you replace the generated code in events.icl by 
something like:

implementation module events

import StdEnv


cleansdlPumpEvents :: !*World -> *World
cleansdlPumpEvents w
	# o = cleansdlPumpEvents 42
	| o == o
		= w
where
	cleansdlPumpEvents :: !*Int -> *Int
	cleansdlPumpEvents a0 = code {
		ccall cleansdlPumpEvents ":V:I"
	}

then your code will work correctly. I'm sure John van Groningen, the 
Clean runtime and
code generation wizard can provide a more detailed explanation if you 
need it.

Regards,

Diederik van Arkel