emit if and true/false/nil constants

This commit is contained in:
Nathan Braswell
2020-04-13 22:55:25 -04:00
parent 05c77e3ad9
commit 4b44277d30
2 changed files with 14 additions and 3 deletions

4
bf.kp
View File

@@ -49,5 +49,7 @@
(println (bf { ,>+++[<.>-] } [1337]))
;(def! main (fn* [argv] 2))
(def! main (fn* [] (let* (a 13 b 12 c 11) b)))
;(def! main (fn* [] (let* (a 13 b 12 c 11) b)))
;(def! main (fn* [] (do 13 12 11)))
(def! main (fn* [] (if false 1 2)))
;(def! main (fn* [] (+ 13 1)))

View File

@@ -1449,6 +1449,15 @@ fun compile_value(defs: *str, env: *Env, ast: MalValue): str {
MalValue::Int(i) {
return to_string(i<<3)
}
MalValue::Nil() {
return str("0x2F")
}
MalValue::True() {
return str("0x9F")
}
MalValue::False() {
return str("0x1F")
}
}
/*return MalResult::Ok(ast)*/
error("could not compile value: " + pr_str(ast, true))
@@ -1519,11 +1528,11 @@ fun compile(defs: *str, env: *Env, ast: MalValue): str {
}
var cond = compile(defs, env, l[1])
var tmp_name = new_tmp()
*defs += "size_t " + tmp_name + "; if (" + cond + ") {\n"
*defs += "size_t " + tmp_name + "; if (" + cond + " != 0x1F) {\n"
var then = compile(defs, env, l[2])
*defs += tmp_name + " = " + then + ";\n} else {\n"
var else_ = compile(defs, env, l[3])
*defs += tmp_name + " = " + else_ + ";\n}"
*defs += tmp_name + " = " + else_ + ";\n}\n"
return tmp_name
} else if (is_symbol(l[0], "fn*")) {
error("compile fn* unimplemented")