Skip to content

Commit

Permalink
Merge pull request #22 from X-FRI/main
Browse files Browse the repository at this point in the history
G-Machine implementation
  • Loading branch information
muqiuhan authored Apr 18, 2024
2 parents 4067bd4 + be24b94 commit d075efb
Show file tree
Hide file tree
Showing 44 changed files with 3,396 additions and 1,871 deletions.
41 changes: 31 additions & 10 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Language: Cpp
BasedOnStyle: LLVM
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: true
AfterEnum: true
AfterFunction: true
Expand All @@ -22,17 +22,38 @@ BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: true
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
ColumnLimit: 120
ColumnLimit: 80
LambdaBodyIndentation: OuterScope
RemoveBracesLLVM: true
SeparateDefinitionBlocks: Always
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 2
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveDeclarations:
Enabled: true
AcrossEmptyLines: true
AcrossComments: true
AlignCompound: true
PadOperators: true
AlignConsecutiveMacros:
Enabled: true
AcrossEmptyLines: true
AcrossComments: true
AlignCompound: true
PadOperators: true
AlignEscapedNewlines: Right
AlignOperands: Align
AlignTrailingComments: true
AllowShortEnumsOnASingleLine: false
AllowShortBlocksOnASingleLine: Never
Cpp11BracedListStyle: true
DerivePointerAlignment: true
DisableFormat: false
ExperimentalAutoDetectBinPacking: true
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IncludeCategories:
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|isl|json)/)'
Expand All @@ -47,11 +68,11 @@ MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
PenaltyBreakComment: 120
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 120
PenaltyExcessCharacter: 120
PenaltyReturnTypeOnItsOwnLine: 120
PenaltyBreakComment: 80
PenaltyBreakFirstLessLess: 80
PenaltyBreakString: 80
PenaltyExcessCharacter: 80
PenaltyReturnTypeOnItsOwnLine: 80
PointerAlignment: Middle
ReflowComments: true
SortIncludes: "Never"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ data Bool = [ True, False ]
data List = [ Nil, Cons Int List ]
let main(argv) = {
Match argv with {
match argv with {
| True => { 0 }
| Nil => { 1 }
}
Expand All @@ -62,7 +62,7 @@ let main(argv) = {
data List = [ Nil, Cons Int List ]
let main(argv) = {
Match argv with {
match argv with {
| Nil => { 0 }
| Cons x xs => { 0 }
}
Expand Down
1 change: 0 additions & 1 deletion after_build.sh

This file was deleted.

27 changes: 23 additions & 4 deletions compiler/ast/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@ namespace swallow::compiler::type
{
void TypeCheck(const std::vector<ast::Definition::Ptr> &program) noexcept
{
Manager typeManager;
Manager typeManager;
Environment typeEnvironment;

auto intType = Type::Ptr(new Base("Int"));
auto binopType = Type::Ptr(new Arrow(intType, Type::Ptr(new type::Arrow(intType, intType))));
auto intType = Type::Ptr(new Base("Int"));
auto binopType = Type::Ptr(
new Arrow(intType, Type::Ptr(new type::Arrow(intType, intType))));

typeEnvironment.Bind("+", binopType);
typeEnvironment.Bind("-", binopType);
Expand All @@ -97,4 +98,22 @@ namespace swallow::compiler::type
for (const auto &definition : program)
definition->Resolve(typeManager);
}
} // namespace swallow::compiler::type
} // namespace swallow::compiler::type

namespace swallow::compiler::gmachine
{
void Compile(const std::vector<ast::Definition::Ptr> &program) noexcept
{
for (const auto &definition : program)
{
definition->Compile();
const auto *fn = dynamic_cast<Fn *>(definition.get());

if (nullptr == fn)
continue;

for (const auto &instruction : fn->Instructions)
instruction->Dump(0, std::cout);
}
}
} // namespace swallow::compiler::gmachine
Loading

0 comments on commit d075efb

Please sign in to comment.