Skip to content

Commit

Permalink
Revert foreign export to use a plain calling convention
Browse files Browse the repository at this point in the history
  • Loading branch information
norm2782 committed Nov 9, 2011
1 parent 7859ad5 commit 1b869d3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 68 deletions.
67 changes: 2 additions & 65 deletions EHC/src/ehc/Core/ToJScript.cag
Original file line number Diff line number Diff line change
Expand Up @@ -677,61 +677,6 @@ tyNumArgs _ = 0
%%]


%%[(90 jscript) hs
-- TODO: Get rid of this; revert back to the old export
-- | construct the ffe call
ffeJScriptMkCall
:: ForeignExtraction
-> EHCOpts
-> Ty
-> [HsName]
-> Seq.Seq JBind
-> Seq.Seq J.Stat
-> Maybe J.Expr
-> ( [J.Expr -> J.Expr] -- additional unwrapping for each argument
, J.Expr -> J.Expr -- and result
, [J.Expr] -> J.Expr -- and primitive call itself
)
ffeJScriptMkCall
ent opts ty jsArgL jbinds jstats mjsLamBody
= javalikeMkFFICall
( const tyDefault
, \_ _ -> bx
, \_ -> bx
, \_ _ impExtract
-> case impExtract of
ForeignExtraction_Plain {forextractEnt = impEntNm}
-> jsVar $ mkHNm impEntNm
ForeignExtraction_Wrapper
-> panic "ffeJScriptMkCall.mkPrimFun: wrapper not implemented"
ForeignExtraction_Dynamic
-> panic "ffeJScriptMkCall.mkPrimFun: dynamic not implemented"
, \_ _ -> mk
, panic "ffeJScriptMkCall: wrapper not implemented"
, panic "ffeJScriptMkCall: dynamic not implemented"
, jsEvl, tyDefault
)
ent opts False [] Nothing
where bx = (id, tyDefault)
-- Notes:
-- jbinds defines the var binds in the function definition: function($__,$__63)
-- jstats defines the var binds in the function body: var $__64 = ....
-- mjsLamBody essentially provides the return keyword
-- TODO: Make sure it's a datatype, not some primitive thing. Done?
mkObj = case ty of -- TODO: Bah, this should be done during type checking!
(Ty_Con _) -> mkBdy $ Seq.map toPlain jstats
_ -> panic "Only datatype expression can be exported as a JavaScript object"
where toPlain (J.Stat_VarDecl nm (Just c@(J.Expr_Call {}))) = J.Stat_VarDecl nm (Just (jsCall "primToPlainObj" [c]))
toPlain stat = stat
mkVar _ = mkBdy jstats
mkBdy ss = J.Expr_Fun Nothing jsArgL
$ J.Stat_Block $ jsBody J.Stat_Ret jbinds ss mjsLamBody
pc = panic "ffeJScriptMkCall.foreignexprEval: not all foreign expressions are supported in foreign exports"
mk = foreignexprEval (pc, pc, pc, pc, mkObj, mkVar, pc) (forextractForeignExpr ent)
%%]



%%[(8 jscript)
SEM CBindAspect
| Bind loc . js = let str = if @lhs.evalCtx == EvalCtx_Eval then jsEvl else id
Expand All @@ -746,16 +691,8 @@ SEM CBindAspect
else str caf

%%[[90
| FFE loc . (mkArgsJS,mkResJS,mkFFI)
= ffeJScriptMkCall
@foreignEntInfo
@lhs.opts
@ty
@jsArgL
@expr.jbinds
@expr.jstats
(Just @expr.jsLamBody)
loc . js = @mkResJS $ @mkFFI []
| FFE loc . js = J.Expr_Fun Nothing @jsArgL
$ J.Stat_Block $ jsBody J.Stat_Ret @expr.jbinds @expr.jstats (Just @expr.jsLamBody)
%%]]
%%]

Expand Down
4 changes: 1 addition & 3 deletions EHC/src/ehc/Foreign/Parser.chs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ pForeignEnt dir way dfltNm
(_ ,FFIWay_CCall ) -> ForeignEnt_CCall <$> pCCall dfltNm
(_ ,FFIWay_Prim ) -> ForeignEnt_PrimCall <$> pPrimCall dfltNm
%%[[(90 jscript)
{- (ForeignDirection_Import,FFIWay_JScript) -> ForeignEnt_JScriptCall <$> pJScriptCall dfltNm-}
-- TODO: Verify that we really want to use the JScript calling convention for both imports and exports
(_ ,FFIWay_JScript) -> ForeignEnt_JScriptCall <$> pJScriptCall dfltNm
(ForeignDirection_Import,FFIWay_JScript) -> ForeignEnt_JScriptCall <$> pJScriptCall dfltNm
%%]]
_ -> ForeignEnt_PlainCall <$> pPlainCall dfltNm

Expand Down

0 comments on commit 1b869d3

Please sign in to comment.