mirror of
https://github.com/Mercantec-GHC/h4-projekt-gruppe-0-sm.git
synced 2025-04-28 00:34:06 +02:00
add void ptr
This commit is contained in:
parent
827e26577a
commit
da6aae12b1
@ -11,7 +11,7 @@ out: entry.o out.o lib.o
|
|||||||
nasm -f elf64 $< -o $@
|
nasm -f elf64 $< -o $@
|
||||||
|
|
||||||
out.nasm: program.sbl
|
out.nasm: program.sbl
|
||||||
deno run --allow-read --allow-write --check main.ts $<
|
deno run --allow-read --allow-write --check main.ts $< $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf out.asm out.o lib.o entry.o out
|
rm -rf out.asm out.o lib.o entry.o out
|
||||||
|
@ -83,6 +83,7 @@ export type Ty = {
|
|||||||
|
|
||||||
export type TyKind =
|
export type TyKind =
|
||||||
| { tag: "error" }
|
| { tag: "error" }
|
||||||
|
| { tag: "void" }
|
||||||
| { tag: "ident"; ident: string }
|
| { tag: "ident"; ident: string }
|
||||||
| { tag: "ptr"; ty: Ty };
|
| { tag: "ptr"; ty: Ty };
|
||||||
|
|
||||||
|
13
sbc/front.ts
13
sbc/front.ts
@ -188,6 +188,8 @@ export class Checker {
|
|||||||
switch (k.tag) {
|
switch (k.tag) {
|
||||||
case "error":
|
case "error":
|
||||||
return { tag: "error" };
|
return { tag: "error" };
|
||||||
|
case "void":
|
||||||
|
return { tag: "void" };
|
||||||
case "ident": {
|
case "ident": {
|
||||||
switch (k.ident) {
|
switch (k.ident) {
|
||||||
case "int":
|
case "int":
|
||||||
@ -232,6 +234,8 @@ export class Checker {
|
|||||||
|
|
||||||
if (a.tag === "error" || b.tag === "error") {
|
if (a.tag === "error" || b.tag === "error") {
|
||||||
return ok(a);
|
return ok(a);
|
||||||
|
} else if (both("void")) {
|
||||||
|
return ok(a);
|
||||||
} else if (both("int")) {
|
} else if (both("int")) {
|
||||||
return ok(a);
|
return ok(a);
|
||||||
} else if (both("str")) {
|
} else if (both("str")) {
|
||||||
@ -912,7 +916,14 @@ export class Parser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private parseTy(): AstTy {
|
private parseTy(): AstTy {
|
||||||
if (this.eat("ident")) {
|
if (this.eat("(")) {
|
||||||
|
if (this.eat(")")) {
|
||||||
|
return this.ty({ tag: "void" }, this.eaten!.line);
|
||||||
|
} else {
|
||||||
|
this.report("expected ')'");
|
||||||
|
return this.ty({ tag: "error" }, this.last!.line);
|
||||||
|
}
|
||||||
|
} else if (this.eat("ident")) {
|
||||||
return this.ty(
|
return this.ty(
|
||||||
{ tag: "ident", ident: this.eaten!.identVal! },
|
{ tag: "ident", ident: this.eaten!.identVal! },
|
||||||
this.eaten!.line,
|
this.eaten!.line,
|
||||||
|
10
sbc/main.ts
10
sbc/main.ts
@ -8,7 +8,13 @@ import { AsmGen } from "./asm_gen.ts";
|
|||||||
import { optimizeLir } from "./lir_optimize.ts";
|
import { optimizeLir } from "./lir_optimize.ts";
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const text = await Deno.readTextFile(Deno.args[0]);
|
const inputFile = Deno.args[0];
|
||||||
|
const outputFile = Deno.args[1];
|
||||||
|
if (!inputFile || !outputFile) {
|
||||||
|
throw new Error("incorrect arguments");
|
||||||
|
}
|
||||||
|
|
||||||
|
const text = await Deno.readTextFile(inputFile);
|
||||||
|
|
||||||
const ast = new Parser(text).parse();
|
const ast = new Parser(text).parse();
|
||||||
// console.log("=== AST ===");
|
// console.log("=== AST ===");
|
||||||
@ -44,7 +50,7 @@ async function main() {
|
|||||||
// console.log("=== ASM ===");
|
// console.log("=== ASM ===");
|
||||||
// console.log(asm);
|
// console.log(asm);
|
||||||
|
|
||||||
await Deno.writeTextFile("out.nasm", asm);
|
await Deno.writeTextFile(outputFile, asm);
|
||||||
}
|
}
|
||||||
|
|
||||||
main();
|
main();
|
||||||
|
@ -11,6 +11,10 @@ fn factorial(v: int) -> int {
|
|||||||
return v * factorial(v - 1);
|
return v * factorial(v - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn return_void_ptr(ptr: *()) -> *() {
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
#[c_export("sbc_main")]
|
#[c_export("sbc_main")]
|
||||||
fn main() -> int {
|
fn main() -> int {
|
||||||
let i = 0;
|
let i = 0;
|
||||||
|
@ -3,6 +3,7 @@ import * as ast from "./ast.ts";
|
|||||||
export type Ty =
|
export type Ty =
|
||||||
| { tag: "error" }
|
| { tag: "error" }
|
||||||
| { tag: "unknown" }
|
| { tag: "unknown" }
|
||||||
|
| { tag: "void" }
|
||||||
| { tag: "int" }
|
| { tag: "int" }
|
||||||
| { tag: "str" }
|
| { tag: "str" }
|
||||||
| { tag: "ptr"; ty: Ty }
|
| { tag: "ptr"; ty: Ty }
|
||||||
@ -14,6 +15,8 @@ export function tyToString(ty: Ty): string {
|
|||||||
return `<error>`;
|
return `<error>`;
|
||||||
case "unknown":
|
case "unknown":
|
||||||
return `<unknown>`;
|
return `<unknown>`;
|
||||||
|
case "void":
|
||||||
|
return `()`;
|
||||||
case "int":
|
case "int":
|
||||||
return `int`;
|
return `int`;
|
||||||
case "str":
|
case "str":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user