diff --git a/runtime/src/juvix/object/print.c b/runtime/src/juvix/object/print.c index b7de59fe7..8d8e9517e 100644 --- a/runtime/src/juvix/object/print.c +++ b/runtime/src/juvix/object/print.c @@ -207,6 +207,7 @@ size_t print_to_buf(char *buf, size_t n, word_t x) { return k; } +// The returned pointer should be freed with `free_strbuf` char *print(word_t x) { // TODO: replace this with malloc when we have it for all APIs char *buf = palloc(1); diff --git a/src/Juvix/Compiler/Asm/Transformation/Prealloc.hs b/src/Juvix/Compiler/Asm/Transformation/Prealloc.hs index 5d3a14f84..79479aa05 100644 --- a/src/Juvix/Compiler/Asm/Transformation/Prealloc.hs +++ b/src/Juvix/Compiler/Asm/Transformation/Prealloc.hs @@ -38,6 +38,14 @@ computeCodePrealloc tab code = prealloc <$> foldS sig code (0, []) TailCall {} -> return (0, cmd : prealloc acc) CallClosures {} -> return (0, cmd : prealloc acc) TailCallClosures {} -> return (0, cmd : prealloc acc) + Binop StrConcat -> do + opts <- ask + let size = opts ^. optLimits . limitsMaxStringSize + return (k + size, cmd : c) + ValShow -> do + opts <- ask + let size = opts ^. optLimits . limitsMaxStringSize + return (k + size, cmd : c) _ -> return (k, cmd : c) where cmd = Instr instr @@ -108,6 +116,14 @@ checkCodePrealloc tab code = do opts <- ask let size = opts ^. optLimits . limitsMaxClosureSize return $ \k -> cont (k - size) + Binop StrConcat -> do + opts <- ask + let size = opts ^. optLimits . limitsMaxStringSize + return $ \k -> cont (k - size) + ValShow -> do + opts <- ask + let size = opts ^. optLimits . limitsMaxStringSize + return $ \k -> cont (k - size) _ -> return id goBranch :: CmdBranch -> (Int -> Int) -> (Int -> Int) -> (Int -> Int) -> Sem r (Int -> Int) diff --git a/src/Juvix/Compiler/Backend.hs b/src/Juvix/Compiler/Backend.hs index 723246031..dd965cc79 100644 --- a/src/Juvix/Compiler/Backend.hs +++ b/src/Juvix/Compiler/Backend.hs @@ -12,6 +12,7 @@ data Limits = Limits _limitsMaxLocalVars :: Int, _limitsMaxClosureSize :: Int, _limitsClosureHeadSize :: Int, + _limitsMaxStringSize :: Int, _limitsMaxStackDelta :: Int, _limitsMaxFunctionAlloc :: Int, _limitsDispatchStackSize :: Int, @@ -32,6 +33,7 @@ getLimits tgt debug = case tgt of _limitsMaxLocalVars = 2048, _limitsMaxClosureSize = 253 + 3, _limitsClosureHeadSize = if debug then 3 else 2, + _limitsMaxStringSize = 255 + 1, _limitsMaxStackDelta = 16368, _limitsMaxFunctionAlloc = 16368, _limitsDispatchStackSize = 4, @@ -45,6 +47,7 @@ getLimits tgt debug = case tgt of _limitsMaxLocalVars = 1024, _limitsMaxClosureSize = 253 + 3, _limitsClosureHeadSize = if debug then 3 else 2, + _limitsMaxStringSize = 255 + 1, _limitsMaxStackDelta = 8184, _limitsMaxFunctionAlloc = 8184, _limitsDispatchStackSize = 4, diff --git a/test/Asm/Compile/Base.hs b/test/Asm/Compile/Base.hs index 90351be43..31a6db722 100644 --- a/test/Asm/Compile/Base.hs +++ b/test/Asm/Compile/Base.hs @@ -26,6 +26,10 @@ asmCompileAssertion' tab mainFile expectedFile stdinText step = do Runtime.clangAssertion cFile expectedFile stdinText step ) where + -- TODO: In the future, the target supplied here might need to correspond to + -- the actual target, and C code will then need to be re-generated for each + -- target separately. Now this works only because those limits that + -- Prealloc.hs uses are the same for the Native64 and Wasm32 targets. asmOpts :: Options asmOpts = makeOptions Backend.TargetCNative64 True