[Yhc] Compiling Prelude.hs

Thomas Shackell shackell at cs.york.ac.uk
Wed Jan 18 06:47:35 EST 2006


One thing to consider (that I forgot to mention) is that the compiler 
generates wrappers for primitives. Thus if you have Haskell code like:

aPrimitive primitive 1 :: Int -> Int

The code that is generated is a wrapper

FUN aPrimitive:
    PUSH_ARG 0
    EVAL
    POP 1
    PRIMITIVE [aPrimitive C code]
    RETURN_EVAL

It *is* possible to get away without the wrapper but it makes life quite 
hard, because you need to make sure that the arguments are evaluated 
before calling the primitive function.

You could of course do

FUN aPrimitive:
    PUSH_ARG 0
    EVAL
    MK_AP [aPrimitive C code] 1
    RETURN_EVAL

but this is both quite nasty and also less efficient.


Tom


Krasimir Angelov wrote:
> Ok. Then I will follow the same way used in the bytecode backend.
> 
> 2006/1/18, Thomas Shackell <shackell at cs.york.ac.uk>:
> 
>>Hi Krasimir,
>>
>>Great work with the .NET backend!
>>
>>It wouldn't be easy. Knowing whether a function internal to this module
>>is primitive is relatively easy. However knowing whether a function in
>>another module is primitive is harder because the program gets it's
>>information about external functions from the .hi file and the .hi file
>>doesn't store whether a function was primitive or not.
>>
>>It would be possible to add it, but messing about with the hi files
>>isn't fun (trust me ;-)).
>>
>>Hope that helps
>>
>>Tom
>>
>>Krasimir Angelov wrote:
>>
>>>Cool! Now I am able to compile the entire base package to IL code but
>>>there is still one problem. The byte code backend is using a special
>>>instruction for all primitives. I would like to try an another
>>>approach that will allow to call the primitives directly. For this
>>>purpose I need to now whether a given Id is an Id of a primitive. Is
>>>it currently possible? It is enough if there was any flag in the Info
>>>datatype. Any suggestions?
>>>
>>>Krasimir
>>>
>>>2006/1/17, Neil Mitchell <ndmitchell at gmail.com>:
>>>
>>>
>>>>>code. Is it possible to remove the duplicated instances as well?
>>>>
>>>>Yep, I removed them already - they were certainly a bug. It should be
>>>>in the repo already.
>>>>
>>>>The compiler detects duplicate class declarations (good), but
>>>>supresses rename errors with the -redefine flag (bad, fixed now), and
>>>>doesn't detect duplicate instance declarations (bad, unfixed).
>>>>
>>>>Thanks
>>>>
>>>>Neil
>>>>
>>>
>>>_______________________________________________
>>>Yhc mailing list
>>>Yhc at haskell.org
>>>http://haskell.org/mailman/listinfo/yhc
>>
>>



More information about the Yhc mailing list