cgen: remove g_ hack

pull/5174/head^2
Alexander Medvednikov 2020-06-02 15:49:43 +02:00
parent 1139d3b458
commit 78f8a8aee6
3 changed files with 17 additions and 24 deletions

View File

@ -233,6 +233,10 @@ pub fn v_build_failing_skipped(zargs string, folder string, skipped []string) bo
mut mains := []string{} mut mains := []string{}
for f in files { for f in files {
if !f.contains('modules') && !f.contains('preludes') { if !f.contains('modules') && !f.contains('preludes') {
if f.contains('/vweb/') {
continue
}
$if windows { $if windows {
// skip pico example on windows // skip pico example on windows
if f.ends_with('examples\\pico\\pico.v') { if f.ends_with('examples\\pico\\pico.v') {

View File

@ -92,7 +92,7 @@ fn get_bet(money int) int {
fn run_wheel(bet_nbr int, _bet int) int { fn run_wheel(bet_nbr int, _bet int) int {
mut bet := _bet mut bet := _bet
rand.seed(time.now().unix) rand.seed(int(time.now().unix))
winning_nbr := rand.next(50) winning_nbr := rand.next(50)
print('Roulette Wheel spinning... and stops on the number $winning_nbr which is a ') print('Roulette Wheel spinning... and stops on the number $winning_nbr which is a ')
if winning_nbr % 2 == 1 { if winning_nbr % 2 == 1 {

View File

@ -358,11 +358,7 @@ fn (g &Gen) optional_type_name(t table.Type) (string, string) {
fn (g &Gen) optional_type_text(styp, base string) string { fn (g &Gen) optional_type_text(styp, base string) string {
x := styp // .replace('*', '_ptr') // handle option ptrs x := styp // .replace('*', '_ptr') // handle option ptrs
// replace void with something else // replace void with something else
size := if base == 'void' { size := if base == 'void' { 'int' } else { base }
'int'
} else {
base
}
ret := 'struct $x { ret := 'struct $x {
bool ok; bool ok;
bool is_none; bool is_none;
@ -386,7 +382,6 @@ fn (mut g Gen) register_optional(t table.Type) string {
bool ok; bool ok;
bool is_none; bool is_none;
} Option2_$no_ptr;') } Option2_$no_ptr;')
// println(styp) // println(styp)
g.typedefs2.writeln('typedef struct $styp $styp;') g.typedefs2.writeln('typedef struct $styp $styp;')
g.options.write(g.optional_type_text(styp, base)) g.options.write(g.optional_type_text(styp, base))
@ -916,10 +911,12 @@ fn (mut g Gen) expr_with_cast(expr ast.Expr, got_type, expected_type table.Type)
fn cestring(s string) string { fn cestring(s string) string {
return s.replace('\\', '\\\\').replace('"', "\'") return s.replace('\\', '\\\\').replace('"', "\'")
} }
// ctoslit returns a 'tos_lit("$s")' call, where s is properly escaped. // ctoslit returns a 'tos_lit("$s")' call, where s is properly escaped.
fn ctoslit(s string) string { fn ctoslit(s string) string {
return 'tos_lit("' + cestring(s) + '")' return 'tos_lit("' + cestring(s) + '")'
} }
fn (mut g Gen) gen_assert_stmt(a ast.AssertStmt) { fn (mut g Gen) gen_assert_stmt(a ast.AssertStmt) {
g.writeln('// assert') g.writeln('// assert')
g.inside_ternary++ g.inside_ternary++
@ -2063,7 +2060,7 @@ fn (mut g Gen) ident(node ast.Ident) {
g.write(node.name[2..].replace('.', '__')) g.write(node.name[2..].replace('.', '__'))
return return
} }
if node.kind == .constant && !node.name.starts_with('g_') { if node.kind == .constant { // && !node.name.starts_with('g_') {
// TODO globals hack // TODO globals hack
g.write('_const_') g.write('_const_')
} }
@ -2346,7 +2343,6 @@ fn (mut g Gen) return_statement(node ast.Return) {
g.write('/*opt promotion*/ Option $tmp = ') g.write('/*opt promotion*/ Option $tmp = ')
g.expr_with_cast(node.exprs[0], node.types[0], g.fn_decl.return_type) g.expr_with_cast(node.exprs[0], node.types[0], g.fn_decl.return_type)
g.write(';') g.write(';')
styp := g.typ(g.fn_decl.return_type) styp := g.typ(g.fn_decl.return_type)
g.writeln('return *($styp*)&$tmp;') g.writeln('return *($styp*)&$tmp;')
return return
@ -2357,17 +2353,14 @@ fn (mut g Gen) return_statement(node ast.Return) {
// typ_sym := g.table.get_type_symbol(g.fn_decl.return_type) // typ_sym := g.table.get_type_symbol(g.fn_decl.return_type)
// mr_info := typ_sym.info as table.MultiReturn // mr_info := typ_sym.info as table.MultiReturn
mut styp := '' mut styp := ''
mut opt_tmp := '' mut opt_tmp := ''
mut opt_type := '' mut opt_type := ''
if fn_return_is_optional { if fn_return_is_optional {
opt_type = g.typ(g.fn_decl.return_type) opt_type = g.typ(g.fn_decl.return_type)
// Create a tmp for this option // Create a tmp for this option
opt_tmp = g.new_tmp_var() opt_tmp = g.new_tmp_var()
g.write('$opt_type $opt_tmp;') g.write('$opt_type $opt_tmp;')
styp = g.base_type(g.fn_decl.return_type) styp = g.base_type(g.fn_decl.return_type)
g.write('opt_ok2(&($styp/*X*/[]) { ') g.write('opt_ok2(&($styp/*X*/[]) { ')
} else { } else {
g.write('return ') g.write('return ')
@ -2391,7 +2384,6 @@ fn (mut g Gen) return_statement(node ast.Return) {
g.writeln(';') g.writeln(';')
multi_unpack += g.go_before_stmt(0) multi_unpack += g.go_before_stmt(0)
g.write(s) g.write(s)
expr_types := expr_sym.mr_info().types expr_types := expr_sym.mr_info().types
for j, _ in expr_types { for j, _ in expr_types {
g.write('.arg$arg_idx=${tmp}.arg$j') g.write('.arg$arg_idx=${tmp}.arg$j')
@ -2826,11 +2818,8 @@ fn (mut g Gen) write_types(types []table.TypeSymbol) {
g.type_definitions.writeln('${g.optional_type_text(styp, base)};') g.type_definitions.writeln('${g.optional_type_text(styp, base)};')
g.type_definitions.write(last_text) g.type_definitions.write(last_text)
} }
type_name := g.typ(field.typ) type_name := g.typ(field.typ)
field_name := c_name(field.name) field_name := c_name(field.name)
g.type_definitions.writeln('\t$type_name $field_name;') g.type_definitions.writeln('\t$type_name $field_name;')
} }
} else { } else {