builtins ignore type check

This commit is contained in:
Theis Pieter Hollebeek 2024-12-11 13:16:34 +01:00
parent 4a9d501a71
commit a6da283b0a
3 changed files with 10 additions and 4 deletions

View File

@ -121,7 +121,13 @@ export class Checker {
} }
const { returnType } = stmt.kind.vtype!; const { returnType } = stmt.kind.vtype!;
this.fnReturnStack.push(returnType); this.fnReturnStack.push(returnType);
const isBuiltin = stmt.kind.anno && stmt.kind.anno.ident === "builtin";
if (isBuiltin) {
stmt.kind.body.kind = { type: "block", stmts: [] };
}
const body = this.checkExpr(stmt.kind.body); const body = this.checkExpr(stmt.kind.body);
this.fnReturnStack.pop(); this.fnReturnStack.pop();
if (!vtypesEqual(returnType, body)) { if (!vtypesEqual(returnType, body)) {
this.report( this.report(

View File

@ -15,9 +15,8 @@ const lexer = new Lexer(text, reporter);
const parser = new Parser(lexer, reporter); const parser = new Parser(lexer, reporter);
const ast = parser.parseStmts(); const ast = parser.parseStmts();
console.log(JSON.stringify(ast, null, 4)); // console.log(JSON.stringify(ast, null, 4));
/*
new Resolver(reporter).resolve(ast); new Resolver(reporter).resolve(ast);
new Checker(reporter).check(ast); new Checker(reporter).check(ast);
@ -34,4 +33,3 @@ const program = lowerer.finish();
console.log(JSON.stringify(program)); console.log(JSON.stringify(program));
await Deno.writeTextFile("out.slgbc", JSON.stringify(program)); await Deno.writeTextFile("out.slgbc", JSON.stringify(program));
*/

View File

@ -1,4 +1,6 @@
fn print(msg: string) #[builtin(print)] {} fn print(msg: string) #[builtin(print)] {
+ "hello" 0
}
fn main() { fn main() {
print("hello world!"); print("hello world!");