Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules
dist
dist
examples/*
!examples/*.gom
3 changes: 0 additions & 3 deletions examples/functions.gom

This file was deleted.

8 changes: 6 additions & 2 deletions examples/hello_world.ll
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ source_filename = "mod"
@.strliteral = private unnamed_addr constant [14 x i8] c"Hello, World!\00", align 1
@newline = private unnamed_addr constant [2 x i8] c"\0A\00", align 1

declare i32 @printf(i8*, ...)

declare i8* @malloc(i32)

declare i8* @realloc(i8*, i32)

define void @main() {
entry:
%calltmp0 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.strliteral, i32 0, i32 0))
%newline = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @newline, i32 0, i32 0))
ret void
}

declare i32 @printf(i8*, ...)
Binary file modified examples/list
Binary file not shown.
Binary file modified examples/loop
Binary file not shown.
2 changes: 2 additions & 0 deletions examples/loop.ll
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ declare i32 @printf(i8*, ...)

declare i8* @malloc(i32)

declare i8* @realloc(i8*, i32)

define void @main() {
entry:
%i = alloca i32, align 4
Expand Down
Binary file modified examples/readme
Binary file not shown.
Binary file modified examples/test_2
Binary file not shown.
Binary file modified examples/test_3
Binary file not shown.
9 changes: 4 additions & 5 deletions run.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env tsx
import { runCompile } from "./src/index";
import { execSync } from "node:child_process";
import { logGreen } from "./src/util/console";

const filePath = process.argv[2];
const target = (process.argv[3] || "c") as "c" | "llvm";
Expand All @@ -12,13 +13,11 @@ runCompile(filePath, target)
execSync(
`clang -o ${filePath.replace(".gom", "")} ${filePath.replace(
".gom",
".ll"
".ll",
)}`,
{ stdio: "inherit" }
);
console.log(
`✅ Executable generated at: ${filePath.replace(".gom", "")}`
{ stdio: "inherit" },
);
logGreen(`Executable generated at: ${filePath.replace(".gom", "")}`);
}
})
.catch((error) => {
Expand Down
6 changes: 3 additions & 3 deletions src/codegen/c.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import { writeFileSync } from "node:fs";
import { BaseCodeGenerator } from "./common";
import { GomPrimitiveTypeOrAlias } from "../semantics/type";
import { GomPrimitiveTypeOrAlias } from "../types";
import {
NodeAccess,
NodeAssignment,
Expand Down Expand Up @@ -135,7 +135,7 @@ export class CodeGenerator extends BaseCodeGenerator {
visitLetStatement(node: NodeLetStatement): void {
for (const decl of node.decls) {
const type = this.mapGomTypeToC(
decl.lhs.resultantType as GomPrimitiveTypeOrAlias
decl.lhs.gomType as GomPrimitiveTypeOrAlias,
);
const rhsValue = this.visitExpression(decl.rhs);

Expand Down Expand Up @@ -183,7 +183,7 @@ export class CodeGenerator extends BaseCodeGenerator {

visitForStatement(node: NodeForStatement): void {
if (node.initExpr && node.conditionExpr && node.updateExpr) {
const initValue = this.visitExpression(node.initExpr);
const initValue = this.visitExpression(node.initExpr as NodeExpr);
const conditionValue = this.visitExpression(node.conditionExpr);
const updateValue = this.visitExpression(node.updateExpr);

Expand Down
2 changes: 1 addition & 1 deletion src/codegen/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export abstract class BaseCodeGenerator extends SimpleVisitor<void> {
this.outputPath = outputPath;
this.errorManager = errorManager;
this.symbolTableReader = new SymbolTableReader(
scopeManager.getCurrentSymbolTableNode()
scopeManager.getCurrentSymbolTableNode(),
);
}

Expand Down
Loading