diff --git a/compiler/checker.ts b/compiler/checker.ts index 12110c8..1eb4df3 100644 --- a/compiler/checker.ts +++ b/compiler/checker.ts @@ -121,7 +121,13 @@ export class Checker { } const { returnType } = stmt.kind.vtype!; 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); + this.fnReturnStack.pop(); if (!vtypesEqual(returnType, body)) { this.report( diff --git a/compiler/main.ts b/compiler/main.ts index 1b7af94..0884103 100644 --- a/compiler/main.ts +++ b/compiler/main.ts @@ -15,9 +15,8 @@ const lexer = new Lexer(text, reporter); const parser = new Parser(lexer, reporter); const ast = parser.parseStmts(); -console.log(JSON.stringify(ast, null, 4)); +// console.log(JSON.stringify(ast, null, 4)); -/* new Resolver(reporter).resolve(ast); new Checker(reporter).check(ast); @@ -34,4 +33,3 @@ const program = lowerer.finish(); console.log(JSON.stringify(program)); await Deno.writeTextFile("out.slgbc", JSON.stringify(program)); -*/ diff --git a/examples/annos.slg b/examples/annos.slg index cf182cf..0225358 100644 --- a/examples/annos.slg +++ b/examples/annos.slg @@ -1,4 +1,6 @@ -fn print(msg: string) #[builtin(print)] {} +fn print(msg: string) #[builtin(print)] { + + "hello" 0 +} fn main() { print("hello world!");