[Yhc] Adding new calling conventions for use in YHC.Core

Jeremy Shaw jeremy at n-heptane.com
Wed Aug 22 03:24:43 EDT 2007


Hello,

My ycr->swf backend is far enough along that I am ready to figure out
how to properly import foreign functions.

There are three types of ActionScript 'functions' that I want to import:

 1. actionscript primitives, such as ActionSubtract, ActionStringAdd, etc
 2. actionscript functions (mostly old functions that predate flash 5.0)
 3. actionscript method calls (for flash 5.0 and higher, which has an object system)

These each require a slightly different calling convention. So, I
think I want to be able to import them by adding lines like this:

foreign import primitive "ActionSubtract" actionSubtractInt :: Int -> Int -> Int
foreign import ascall "someFunction" someFunction :: Int -> IO Int
foreign import asmethod "someMethod" someMethod :: SomeObject -> Int -> IO Int

However, to do this requires modifying the yhc frontend to accept
these additional calling conventions.

In YHC.Core, the calling convention is just a String, so there is no
problem representing my new calling conventions in Core. But, the YHC
frontend only wants to accept a limited set of predefined calling
conventions.

Perhaps when the --core flag is present, the frontend should just
treat the calling convention as String? Basically, I would extend the
Style from:

data Style   = Ordinary | CCast | Address | FunAddress | Dynamic | Wrapper
             deriving Eq

to:

data Style   = Ordinary | CCast | Address | FunAddress | Dynamic | Wrapper | Other String
             deriving Eq

And then modify the rest of the code so that when yhc is compiled with
the --core flag, the calling convention is not parsed, but simply
stuck inside the Other constructor? (Or perhaps, if it parses, the
normal constructor is used, but if it fails to parse, then it is just
dumped in Other ?)

Or, perhaps I am taking completely the wrong approach ?

j.


More information about the Yhc mailing list