~jojo/Carth

b32b4f44811e5b5f95ea700f2d826378cd5360d0 — JoJo 1 year, 10 months ago aa164fc
Don't greedily mark every call as tail -- causes segfaults & stuff!

For now, don't mark any call as tail. Gotta learn how it really works
first. Seems like only calls that are actually in tail-position should
be marked as tail, or mayhem ensues.
2 files changed, 12 insertions(+), 11 deletions(-)

M examples/fizzbuzz.carth
M src/Codegen.hs
M examples/fizzbuzz.carth => examples/fizzbuzz.carth +4 -7
@@ 7,21 7,18 @@

(define (start _)
  (for (Cons "foo" (box (Cons "bar" (box (Cons "baz" (box Nil))))))
       display
       unit))
       display))

(define (display s)
  (display-inline (str-append s "\n")))

(define (for xs f _)
(define (for xs f)
  (match xs
    [Nil unit]
    [(Cons x xs')
     ;; TODO: This is broken
     ;; (seq (f x) (for (deref xs') f))
     (for (deref xs') f (f x))]))
     (seq (f x) (for (deref xs') f))]))

;; (define (seq a b) b)
(define (seq a b) b)

(define (str-append s1 s2) (-str-append (Pair s1 s2)))


M src/Codegen.hs => src/Codegen.hs +8 -4
@@ 455,7 455,11 @@ app closure a rt = do
  where
    call f as = WithRetType
        (Call
            { tailCallKind = Just Tail
            -- NOTE: Just marking all calls as "tail" did not work out
            --       well. Lotsa segfaults and stuff! Learn more about what
            --       exactly "tail" does first. Maybe it's only ok to mark calls
            --       that are actually in tail position as tail calls?
            { tailCallKind = Nothing
            , callingConvention = cfg_callConv
            , returnAttributes = []
            , function = Right f


@@ 793,7 797,7 @@ callExtern f rt as = WithRetType (callExtern'' f rt as) rt

callExtern'' :: String -> Type -> [Operand] -> Instruction
callExtern'' f rt as = Call
    { tailCallKind = Just Tail
    { tailCallKind = Nothing
    , callingConvention = cfg_callConv
    , returnAttributes = []
    , function = Right $ ConstantOperand $ LLConst.GlobalReference


@@ 978,7 982,7 @@ sizeof layout t = do
toFFIType :: Type -> EncodeAST FFIType
toFFIType = encodeM

-- TODO: Use "tailcc" - Tail callable calling convention. It looks like exactly
--       what I want!
-- TODO: Try out "tailcc" - Tail callable calling convention. It looks like
--       exactly what I want!
cfg_callConv :: LLCallConv.CallingConvention
cfg_callConv = LLCallConv.C