2019-11-17 00:58:09 +03:00
|
|
|
// Copyright (c) 2019 Alexander Medvednikov. All rights reserved.
|
|
|
|
// Use of this source code is governed by an MIT license
|
|
|
|
// that can be found in the LICENSE file.
|
|
|
|
module compiler
|
|
|
|
|
|
|
|
fn (p mut Parser) inline_asm() {
|
|
|
|
if !p.inside_unsafe {
|
2019-11-19 09:43:02 +03:00
|
|
|
p.error('asm() needs to be run inside `unsafe {}`')
|
2019-12-20 00:29:37 +03:00
|
|
|
}
|
2019-11-17 00:58:09 +03:00
|
|
|
p.next()
|
2019-11-18 04:53:46 +03:00
|
|
|
p.check(.lcbr)
|
2019-11-17 00:58:09 +03:00
|
|
|
s := p.check_string()
|
|
|
|
p.genln('asm("$s"')
|
|
|
|
for p.tok == .str {
|
|
|
|
p.genln('"$p.lit"')
|
|
|
|
p.next()
|
2019-12-20 00:29:37 +03:00
|
|
|
}
|
2019-11-17 00:58:09 +03:00
|
|
|
for p.tok == .colon {
|
|
|
|
p.next()
|
|
|
|
arg := p.check_string()
|
|
|
|
p.gen(': "$arg"')
|
|
|
|
if p.tok == .lpar {
|
|
|
|
p.next()
|
|
|
|
var_name := p.check_name()
|
|
|
|
if !p.known_var(var_name) {
|
|
|
|
p.error('unknown variable `$var_name`')
|
2019-12-20 00:29:37 +03:00
|
|
|
}
|
2019-11-17 00:58:09 +03:00
|
|
|
p.check(.rpar)
|
|
|
|
p.genln('($var_name)')
|
2019-12-20 00:29:37 +03:00
|
|
|
}
|
|
|
|
}
|
2019-11-17 00:58:09 +03:00
|
|
|
p.genln(');')
|
2019-11-18 04:53:46 +03:00
|
|
|
p.check(.rcbr)
|
2019-12-20 00:29:37 +03:00
|
|
|
}
|
|
|
|
|