native: rename cgen to code_gen to avoid confusion with cgen

pull/11089/head^2
Alexander Medvednikov 2021-09-10 03:17:53 +03:00
parent 0370d4f268
commit afeb1525a1
3 changed files with 8 additions and 9 deletions

View File

@ -9,8 +9,7 @@ fn main() {
library_file_path := os.join_path(os.getwd(), dl.get_libname('library')) library_file_path := os.join_path(os.getwd(), dl.get_libname('library'))
handle := dl.open_opt(library_file_path, dl.rtld_lazy) ? handle := dl.open_opt(library_file_path, dl.rtld_lazy) ?
eprintln('handle: ${ptr_str(handle)}') eprintln('handle: ${ptr_str(handle)}')
mut f := FNAdder(0) f := FNAdder(dl.sym_opt(handle, 'add_1') ?)
f = dl.sym_opt(handle, 'add_1') ?
eprintln('f: ${ptr_str(f)}') eprintln('f: ${ptr_str(f)}')
res := f(1, 2) res := f(1, 2)
eprintln('res: $res') eprintln('res: $res')

View File

@ -26,7 +26,7 @@ pub struct Gen {
out_name string out_name string
pref &pref.Preferences // Preferences shared from V struct pref &pref.Preferences // Preferences shared from V struct
mut: mut:
cgen CodeGen code_gen CodeGen
table &ast.Table table &ast.Table
buf []byte buf []byte
sect_header_name_pos int sect_header_name_pos int
@ -79,12 +79,12 @@ pub fn gen(files []&ast.File, table &ast.Table, out_name string, pref &pref.Pref
out_name: out_name out_name: out_name
pref: pref pref: pref
// TODO: workaround, needs to support recursive init // TODO: workaround, needs to support recursive init
cgen: get_backend(pref.arch) or { code_gen: get_backend(pref.arch) or {
eprintln('No available backend for this configuration. Use `-a arm64` or `-a amd64`.') eprintln('No available backend for this configuration. Use `-a arm64` or `-a amd64`.')
exit(1) exit(1)
} }
} }
g.cgen.g = g g.code_gen.g = g
g.generate_header() g.generate_header()
for file in files { for file in files {
if file.warnings.len > 0 { if file.warnings.len > 0 {
@ -404,8 +404,8 @@ fn (mut g Gen) for_in_stmt(node ast.ForInStmt) {
} }
pub fn (mut g Gen) gen_exit(node ast.Expr) { pub fn (mut g Gen) gen_exit(node ast.Expr) {
// check node type and then call the cgen method // check node type and then call the code_gen method
g.cgen.gen_exit(mut g, node) g.code_gen.gen_exit(mut g, node)
} }
fn (mut g Gen) stmt(node ast.Stmt) { fn (mut g Gen) stmt(node ast.Stmt) {
@ -543,7 +543,7 @@ fn (mut g Gen) expr(node ast.Expr) {
/* /*
fn (mut g Gen) allocate_var(name string, size int, initial_val int) { fn (mut g Gen) allocate_var(name string, size int, initial_val int) {
g.cgen.allocate_var(name, size, initial_val) g.code_gen.allocate_var(name, size, initial_val)
} }
*/ */

View File

@ -9,7 +9,7 @@ fn test_macho() {
pref: &pref.Preferences{} pref: &pref.Preferences{}
out_name: 'test.bin' out_name: 'test.bin'
table: ast.new_table() table: ast.new_table()
cgen: native.Amd64{ code_gen: native.Amd64{
g: 0 g: 0
} }
} }