~jojo/Carth

f86719ee54c644be12ea4f2c37143c99c582d06f — JoJo 1 year, 3 months ago b29388e
Make GC_malloc take NatSize instead of IntSize

I mean, how the heck do you allocate a negative amount of memory, right?
4 files changed, 4 insertions(+), 4 deletions(-)

M carth.cabal
M src/Infer.hs
M src/Inferred.hs
M std/array.carth
M carth.cabal => carth.cabal +1 -1
@@ 101,7 101,7 @@ test-suite carth-test
      SystemSpec
  hs-source-dirs:
      test
  ghc-options: -threaded -rtsopts -with-rtsopts=-N -Weverything -Werror -Wno-safe -Wno-unsafe -Wno-missing-import-lists -Wno-missing-exported-signatures -Wno-missing-export-lists -Wno-missing-local-signatures -Wno-missing-signatures -Wno-monomorphism-restriction -Wno-implicit-prelude -Wno-name-shadowing -Wno-orphans -Wno-missed-specialisations -Wno-all-missed-specialisations -Wno-unticked-promoted-constructors -Wno-missing-deriving-strategies -Wno-missing-export-lists
  ghc-options: -threaded -rtsopts -with-rtsopts=-N -Weverything -Werror -Wno-safe -Wno-unsafe -Wno-missing-import-lists -Wno-missing-exported-signatures -Wno-missing-local-signatures -Wno-monomorphism-restriction -Wno-implicit-prelude -Wno-name-shadowing -Wno-orphans -Wno-missed-specialisations -Wno-all-missed-specialisations -Wno-unticked-promoted-constructors -Wno-missing-deriving-strategies -Wno-missing-export-lists
  build-depends:
      QuickCheck
    , base

M src/Infer.hs => src/Infer.hs +1 -1
@@ 217,7 217,7 @@ infer (WithPos pos e) = fmap (second (WithPos pos)) $ case e of
        pure (tbody, App f matchee' tbody)
    Parsed.FunMatch cases -> fmap (second FunMatch) (inferFunMatch cases)
    Parsed.Ctor c -> inferExprConstructor c
    Parsed.Sizeof t -> fmap ((TPrim TIntSize, ) . Sizeof) (checkType pos t)
    Parsed.Sizeof t -> fmap ((TPrim TNatSize, ) . Sizeof) (checkType pos t)

inferFunMatch :: [(Parsed.Pat, Parsed.Expr)] -> Infer (Type, FunMatch)
inferFunMatch cases = do

M src/Inferred.hs => src/Inferred.hs +1 -1
@@ 135,7 135,7 @@ ftv = \case
builtinExterns :: Map String (Type, SrcPos)
builtinExterns = Map.fromList $ map
    (second (, SrcPos "<builtin>" 0 0))
    [("GC_malloc", tfun (TPrim TIntSize) (TBox tByte))]
    [("GC_malloc", tfun (TPrim TNatSize) (TBox tByte))]

builtinVirtuals :: Map String Scheme
builtinVirtuals =

M std/array.carth => std/array.carth +1 -1
@@ 8,7 8,7 @@

(define: (array/collect xs) (forall (a) (Fun (Iter a) (Array a)))
  (let ((n (iter/length xs))
        (ptr (: (transmute (id@"GC_malloc" (* (sizeof a) n))) (Box a))))
        (ptr (: (transmute (id@"GC_malloc" (* (sizeof a) (cast n)))) (Box a))))
    (foldl (fun (v (Pair i x)) (array/insert i x v))
           (Array ptr (cast n))
           (enumerate xs))))