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
8 changes: 8 additions & 0 deletions src/codegen/infrastructure/type-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@ export function createFloatType(): ResolvedType {
return createResolvedType("number", { numericKind: "float" });
}

export function fieldTypeToLlvmPrimitive(fieldType: string): string | null {
if (fieldType === "string") return "i8*";
if (fieldType === "number") return "double";
if (fieldType === "boolean") return "double";
if (fieldType.startsWith("'") || fieldType.startsWith('"')) return "i8*";
return null;
}

export function tsTypeToLlvm(tsType: string): string {
return canonicalTypeToLlvm(tsType, "default", false, false, "");
}
Expand Down
11 changes: 2 additions & 9 deletions src/codegen/statements/control-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
classifyArray,
ArrayKind_None,
arrayKindToLlvm,
fieldTypeToLlvmPrimitive,
} from "../infrastructure/type-system.js";
import { setWantsI1 } from "../expressions/condition-generator.js";
import { tryOptimizeWhileLoopMap } from "./loop-idiom.js";
Expand Down Expand Up @@ -863,16 +864,8 @@ export class ControlFlowGenerator {
return type;
}

private fieldTypeToLlvmPrimitive(fieldType: string): string | null {
if (fieldType === "string") return "i8*";
if (fieldType === "number") return "double";
if (fieldType === "boolean") return "double";
if (fieldType.startsWith("'") || fieldType.startsWith('"')) return "i8*";
return null;
}

private fieldTypeToLlvm(fieldType: string): string {
const prim = this.fieldTypeToLlvmPrimitive(fieldType);
const prim = fieldTypeToLlvmPrimitive(fieldType);
if (prim) return prim;
const ak = classifyArray(fieldType);
if (ak !== ArrayKind_None) return arrayKindToLlvm(ak);
Expand Down
11 changes: 2 additions & 9 deletions src/codegen/types/objects/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
classifyArray,
arrayKindToLlvm,
ArrayKind_None,
fieldTypeToLlvmPrimitive,
} from "../../infrastructure/type-system.js";
import type { FieldInfo } from "../../infrastructure/type-resolver/types.js";
import { emitZext, emitSitofp, emitPtrtoint } from "../../infrastructure/ir-builders.js";
Expand Down Expand Up @@ -1724,16 +1725,8 @@ export class ClassGenerator {
this.ctx.defineVariable(paramName, allocaReg, llvmType, SymbolKind_Object, "local");
}

private fieldTypeToLlvmPrimitive(fieldType: string): string | null {
if (fieldType === "string") return "i8*";
if (fieldType === "number") return "double";
if (fieldType === "boolean") return "double";
if (fieldType.startsWith("'") || fieldType.startsWith('"')) return "i8*";
return null;
}

private fieldTypeToLlvm(fieldType: string): string {
const prim = this.fieldTypeToLlvmPrimitive(fieldType);
const prim = fieldTypeToLlvmPrimitive(fieldType);
if (prim) return prim;
const ak = classifyArray(fieldType);
if (ak !== ArrayKind_None) return arrayKindToLlvm(ak);
Expand Down
Loading