-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
linear types are now storable in variables
- Loading branch information
1 parent
2ac5a06
commit 89fec60
Showing
11 changed files
with
273 additions
and
259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import * as colors from "https://deno.land/[email protected]/fmt/colors.ts"; | ||
|
||
import type * as Syntax from "~/bnf/syntax.d.ts"; | ||
import Structure from "~/compiler/structure.ts"; | ||
import { IsContainerType, LinearType, SolidType, OperandType } from "~/compiler/codegen/expression/type.ts"; | ||
import { Panic, LatentOffset } from "~/helper.ts"; | ||
import { IntrinsicValue } from "~/compiler/intrinsic.ts"; | ||
import { CompileExpr } from "~/compiler/codegen/expression/index.ts"; | ||
import { Instruction } from "~/wasm/index.ts"; | ||
import { Context } from "~/compiler/codegen/context.ts"; | ||
import { Store } from "~/compiler/codegen/expression/helper.ts"; | ||
import { SourceView } from "~/parser.ts"; | ||
|
||
export function StructBuilder(ctx: Context, syntax: Syntax.Term_Container, expect?: SolidType): OperandType { | ||
if (!(expect instanceof Structure)) Panic( | ||
`${colors.red("Error")}: Unable to infer struct type\n`, { | ||
path: ctx.file.path, name: ctx.file.name, ref: syntax.ref | ||
}); | ||
if (expect instanceof Structure) expect.link(); | ||
|
||
const alloc = ctx.scope.stack.allocate(expect.size, expect.align); | ||
const linear = LinearType.make(expect, alloc, ctx.file.owner.project.stackBase); | ||
|
||
function* iterator() { | ||
const base = syntax.value[0].value[0]; | ||
if (!base) return; | ||
|
||
yield base.value[0]; // first | ||
for (const next of base.value[1].value) yield next.value[0]; // comma chained | ||
|
||
return; | ||
} | ||
|
||
for (const item of iterator()) { | ||
const elm = item.value[0]; | ||
if (elm.type === "container_value") { | ||
console.error( | ||
`${colors.red("Error")}: Unexpected array value as struct member\n` | ||
+ SourceView(ctx.file.path, ctx.file.name, elm.ref) | ||
); | ||
ctx.file.markFailure(); | ||
continue; | ||
} | ||
|
||
const name = elm.value[0].value[0].value; | ||
const attr = expect.get(name); | ||
if (!attr) Panic( | ||
`${colors.red("Error")}: Unknown attribute ${name} in struct ${expect.name}\n`, { | ||
path: ctx.file.path, name: ctx.file.name, ref: elm.ref | ||
}); | ||
|
||
ctx.block.push(Instruction.const.i32(0)); | ||
const expr = CompileExpr(ctx, elm.value[1], attr.type); | ||
if (expr instanceof IntrinsicValue) { | ||
Store(ctx, expr.type, new LatentOffset(alloc.getOffset(), attr.offset)); | ||
} else Panic( | ||
`${colors.red("Error")}: Only intrinsics are currently supported\n`, { | ||
path: ctx.file.path, name: ctx.file.name, ref: elm.ref | ||
}); | ||
} | ||
|
||
return linear; | ||
} | ||
|
||
export function ArrayBuilder(ctx: Context, syntax: Syntax.Term_Container, expect?: SolidType): OperandType { | ||
if (!expect) Panic( | ||
`${colors.red("Error")}: Unsupported untyped container creation\n`, { | ||
path: ctx.file.path, name: ctx.file.name, ref: syntax.ref | ||
}); | ||
|
||
Panic(`${colors.red("Error")}: Arrays are currently unsupported\n`, | ||
{ path: ctx.file.path, name: ctx.file.name, ref: syntax.ref } | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.