在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):cronokirby/haskell-in-haskell开源软件地址(OpenSource Url):https://github.com/cronokirby/haskell-in-haskell开源编程语言(OpenSource Language):Haskell 88.3%开源软件介绍(OpenSource Introduction):Haskell In HaskellThis is my attempt at writing an understandable implementation of a subset of Haskell, in Haskell itself. UsageThis project can be built with CompilingTo compile a Haskell file, just run:
The compiler only works with single Haskell files. To run the generated code,
you'll need to have a C compiler handy, and to make sure that
the
(Replacing The C generated should conform to the C99 standard. You can also
pass
StagesYou can also see the compiler's output after various stages, so: This will print the tokens after running the Lexer stage
This will print the parsed AST:
This will print the simplified AST:
This will print the AST after type-checking:
This will print the "STG" for your code, which is an intermediate functional IR:
Finally, this will print the "CMM", which is the last stage before generating C code:
FeaturesThe first big missing thing is In terms of features we have: Your standard top level definitions and bindings: x :: Int
x = 33
y :: String
y = 4
z :: Int -> Int
z 3 = 0
z _ = 4 We have let expressions: x =
let z = 3
y = 4
in z + y As well as where expressions: x = z + y
where
z = 3
y = 4 Your standard arithmetic operators: x = 1 + 3 / 45 * 6 - 34 Strings, and concatenation: x = "foo" ++ "bar" Booleans: true :: Bool
true = True
false :: Bool
false = False
z :: Bool
z = 3 > 4 If expressions: x = if 1 > 2 then 3 else 5 Case expressions: case z of
1 -> 3
x -> x
_ -> 4
case x of
"foo" -> "bar"
_ -> "baz" This extends to your standard multiple function heads: add 0 0 = 0
add n 0 = n
add n m = add n (m - 1) We have polymorphic functions: id :: a -> a
id x = x As well as your standard polymorphic ADTs: data List a = Cons a (List a) | Nil
length :: List a -> Int
length Nil = 0
length (Cons _ rest) = 1 + length rest Finally, we have type synonyms, which can't be polymorphic: type ListInt = List X
type X = Int Everything beyond that has not been implemented. I'd say this is a
respectable chunk of Haskell 98, but some glaring omissions include
Implementation FeaturesIn terms of the implementation, this is based of the 1992 ExamplesThe ContributingIf you want to help fix a bug, a first recommendation is to use the following compilation options for your C output:
This will enable This is the source of most bugs in the compiler. TestsThere are two forms of tests. Some stages have basic tests, which can be run with
but these mainly cover the frontend of the compiler. A more extensive suite of tests can be run with:
This script will go over all the Haskell files in For this to work, you need to have This suite is slower, but much more effective at finding problems. ResourcesI'm currently writing a series going through the implementation of this compiler in depth, so I'd recommend looking through that if you want to understand more. https://www.microsoft.com/en-us/research/wp-content/uploads/1992/04/spineless-tagless-gmachine.pdf https://homepages.inf.ed.ac.uk/wadler/papers/pattern/pattern.pdf http://moscova.inria.fr/~maranget/papers/ml05e-maranget.pdf |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论