1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

v.gen.native: support infinite loops for {} in amd64 and arm64 (#11254)

This commit is contained in:
pancake 2021-08-20 13:23:15 +02:00 committed by GitHub
parent 82b16453e4
commit 02d823fa6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1151,7 +1151,29 @@ fn (mut g Gen) if_expr(node ast.IfExpr) {
}
}
fn (mut g Gen) infloop() {
if g.pref.arch == .arm64 {
g.write32(byte(0x14))
} else {
g.write8(byte(0xeb))
g.write8(byte(0xfe))
}
g.println('jmp $$')
}
fn (mut g Gen) for_stmt(node ast.ForStmt) {
if node.is_inf {
if node.stmts.len == 0 {
g.infloop()
return
}
// infinite loop
start := g.pos()
g.stmts(node.stmts)
g.jmp(int(0xffffffff - (g.pos() + 5 - start) + 1))
g.println('jmp after infinite for')
return
}
infix_expr := node.cond as ast.InfixExpr
// g.mov(.eax, 0x77777777)
mut jump_addr := 0 // location of `jne *00 00 00 00*`