Check type of main return

This commit is contained in:
Nathan Braswell
2020-04-14 23:59:52 -04:00
parent 3141ad1d1d
commit bed1871ad3
2 changed files with 9 additions and 2 deletions

7
bf.kp
View File

@@ -60,4 +60,9 @@
;(def! main (fn* [] (cond false 1 false 2 true 3 true 4 false 5)))
;(def! main (fn* [] ((fn* [] (+ (+ 1 2) 3)) 13 1 2)))
;(def! main (fn* [] (((fn* [] (fn* [] 1))))))
(def! main (fn* [] ((fn* [a b c] (- (+ a b) c)) 13 1 4)))
;(def! main (fn* [] ((fn* [a b c] (- (+ a b) c)) 13 1 4)))
(def! main (fn* [] (fn* [] 1)))
;(def! other (fn* [a b c] (- (+ a b) c)))
;(def! main (fn* [] (other 13 1 4)))

View File

@@ -1450,7 +1450,9 @@ fun main(argc: int, argv: **char): int {
top_defs += "closure _gte_closure = (closure){ _gte_impl, NULL};\n"
var main_s = str("int main(int argc, char** argv) {\n")
var inner_main = compile(&top_decs, &top_defs, &main_s, f.env, *f.body)
main_s += "return (" + inner_main + ")>>3;\n}\n"
main_s += "size_t main_to_ret = " + inner_main + ";\n"
main_s += "check_int(main_to_ret, \"main return\");\n"
main_s += "return (main_to_ret)>>3;\n}\n"
write_file(str(argv[1]) + ".c", top_decs + top_defs + main_s)
println("Finished compile")
return 0