On Thu, 2005-06-30 at 19:36 +0200, Leopold Toetsch wrote:
> Brian Wheeler wrote:
> > Its been a while since I tinkered with parrot so I thought I'd start
> > playing again...but I've hit a segfault.
> 
> Should of course not happen... But it seems that the codegen is mixing 
> old and new calling conventions.
> 
> The trace:
> 
> >   8233 set I0, 1        - I0=1,
> >   8236 set I1, 0        - I1=0,
> >   8239 set I2, 0        - I2=0,
> >   8242 set I3, 0        - I3=0,
> >   8245 set I4, 0        - I4=0,
> >   8248 set S1, ""       - S1="",
> >   8251 set P0, PMC_C[733]       - P0=Sub=PMC(0x8af24b8 pc:8023),
> >   8254 invokecc
> 
> clearly shows some wrong function call, like another one I found in the 
> pir source:
> 
> > .namespace ['main']
> 
> >     main()
> 
> This shorthand call syntax doesn't work together (yet) with the new 
> set_args/get_params ... opcodes.
> 


Ok, that seems reasonable, considering the newness of the new calling
conventions.


> So please verify that no function shortcut syntax is used in code 
> generation.
> 
> leo
> 

Thanks!

Not knowing Haskell (who said _perl_ looks like line noise?) this patch
to src/Pugs/CodeGen/PIR.hs gets it working to the point I can test an
optimizer I'm tinkering with:

@@ -320,6 +320,7 @@
 varInit ('&':_) = text $ "PerlScalar"
 varInit x       = error $ "invalid name: " ++ x

+
 {-| Compiles the current environment to PIR code. -}
 genPIR :: Eval Val
 genPIR = do
@@ -374,11 +375,17 @@
             -- XXX wrong, should be lexical
             , InsNew tempPMC PerlScalar
             , "store_global"    .- [lit "$_", tempPMC]
-            ]) ++ [ StmtRaw (text (name ++ "()")) | PSub
name@('_':'_':_) _ _ _ <- globPIL ] ++
-            [ StmtRaw (text "main()")
-            , StmtIns ("exit" .- [lit0])
-            ]
-        , DeclSub "main" [SubANON] [ StmtRaw $ emit mainPIR ]
+               ]  ++
+{- ) ++ [ StmtRaw (text (name ++ "()")) | PSub name@('_':'_':_) _ _ _
<- globPIL ] ++ -}
+           [ InsNew tempPMC PerlScalar
+           , tempPMC <-- "find_name" $ [lit "__main"]
+           , "set_args"        .- [lit "()"]
+           , InsNew tempPMC2 PerlScalar
+           , "get_results"     .-[lit "(0)", tempPMC2]
+           , "invokecc"        .-[tempPMC]
+           , "exit"            .-[lit0]
+       ])
+        , DeclSub "__main" {- [SubANON] -} [] [ StmtRaw $ emit
mainPIR ]
         ] ] ]
     where
     style = MkEvalStyle


Brian


Reply via email to