1
1
mirror of https://github.com/anoma/juvix.git synced 2025-01-03 13:03:25 +03:00

Fix memory count for string operations (#1924)

* Closes #1919
This commit is contained in:
Łukasz Czajka 2023-03-23 20:47:51 +01:00 committed by GitHub
parent dbe9ff61d7
commit 6eae6c405c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 0 deletions

View File

@ -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);

View File

@ -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)

View File

@ -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,

View File

@ -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