uiold: make compile (fix vid); x64: mov rbp, rsp

pull/4539/head
Alexander Medvednikov 2020-04-21 10:48:52 +02:00
parent 071059e8f2
commit baf3bf6778
2 changed files with 22 additions and 5 deletions

View File

@ -6,7 +6,7 @@ module uiold
#include <Cocoa/Cocoa.h> #include <Cocoa/Cocoa.h>
#include <Carbon/Carbon.h> #include <Carbon/Carbon.h>
__global default_font *C.NSFont __global default_font &C.NSFont
fn focus_app(next, event, data voidptr) { fn focus_app(next, event, data voidptr) {

View File

@ -347,6 +347,24 @@ fn (mut g Gen) mov(reg Register, val int) {
g.write32(val) g.write32(val)
} }
/*
fn (mut g Gen) mov_reg(a, b Register) {
match a {
.rbp {
g.write8(0x48)
g.write8(0x89)
}
else {}
}
}
*/
// generates `mov rbp, rsp`
fn (mut g Gen) mov_rbp_rsp() {
g.write8(0x48)
g.write8(0x89)
g.write8(0xe5)
}
pub fn (mut g Gen) register_function_address(name string) { pub fn (mut g Gen) register_function_address(name string) {
addr := g.pos() addr := g.pos()
// println('reg fn addr $name $addr') // println('reg fn addr $name $addr')
@ -390,7 +408,6 @@ fn (mut g Gen) stmt(node ast.Stmt) {
g.ret() g.ret()
} }
ast.StructDecl {} ast.StructDecl {}
ast.Module {}
else { else {
println('x64.stmt(): bad node: ' + typeof(node)) println('x64.stmt(): bad node: ' + typeof(node))
} }
@ -443,8 +460,9 @@ fn (mut g Gen) fn_decl(it ast.FnDecl) {
g.save_main_fn_addr() g.save_main_fn_addr()
} else { } else {
g.register_function_address(it.name) g.register_function_address(it.name)
g.push(.rbp)
// g.write32(SEVENS) // g.write32(SEVENS)
g.push(.rbp)
g.mov_rbp_rsp()
// g.sub32(.rsp, 0x10) // g.sub32(.rsp, 0x10)
} }
for arg in it.args { for arg in it.args {
@ -458,8 +476,7 @@ fn (mut g Gen) fn_decl(it ast.FnDecl) {
// return // return
} }
if !is_main { if !is_main {
// g.leave() g.leave() // g.pop(.rbp)
g.pop(.rbp)
} }
g.ret() g.ret()
} }