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

cgen: test module fns and consts

This commit is contained in:
Alexander Medvednikov 2020-03-01 22:06:36 +01:00
parent 38de6c98fc
commit f921ea2fb7
5 changed files with 24 additions and 8 deletions

View File

@ -1,6 +0,0 @@
module builder
import (
os
filepath
)

View File

@ -63,7 +63,8 @@ fn (g mut Gen) stmt(node ast.Stmt) {
ast.ConstDecl {
for i, field in it.fields {
field_type_sym := g.table.get_type_symbol(field.typ)
g.write('$field_type_sym.name $field.name = ')
name := field.name.replace('.', '__')
g.write('$field_type_sym.name $name = ')
g.expr(it.exprs[i])
g.writeln(';')
}
@ -310,7 +311,8 @@ fn (g mut Gen) expr(node ast.Expr) {
g.write(')')
}
ast.Ident {
g.write('$it.name')
name := it.name.replace('.', '__')
g.write(name)
}
ast.SelectorExpr {
g.expr(it.expr)

View File

@ -10,6 +10,7 @@ void println(string s);
void matches();
void end();
void localmod__pub_foo();
int localmod__get_int_10();
int pi = 3;
int pi2 = pi;
@ -35,6 +36,8 @@ int main() {
int mypi = pi;
Color color = Color_red;
localmod__pub_foo();
int ten = localmod__get_int_10();
println(localmod__pub_int_const);
return 0;
}
@ -144,6 +147,13 @@ void end() {
int e = 2 + 3 * 4;
}
int localmod__pub_int_const = 20;
void localmod__pub_foo() {
int a = 10;
}
int localmod__get_int_10() {
return 10;
}

View File

@ -42,6 +42,8 @@ fn main() {
mypi := pi
color := Color.red
localmod.pub_foo()
ten := localmod.get_int_10()
println(localmod.pub_int_const)
}
/*
user := User{}

View File

@ -1,5 +1,13 @@
module localmod
pub const (
pub_int_const = 20
)
pub fn pub_foo() {
a := 10
}
pub fn get_int_10() int {
return 10
}