From 78f8a8aee6c103a1aac034df35c23845e63e2cae Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 2 Jun 2020 15:49:43 +0200 Subject: [PATCH] cgen: remove g_ hack --- cmd/tools/modules/testing/common.v | 4 +++ examples/vcasino/{VCasino.v => vcasino.v} | 2 +- vlib/v/gen/cgen.v | 35 ++++++++--------------- 3 files changed, 17 insertions(+), 24 deletions(-) rename examples/vcasino/{VCasino.v => vcasino.v} (99%) diff --git a/cmd/tools/modules/testing/common.v b/cmd/tools/modules/testing/common.v index ef4ebf2956..34737994b4 100644 --- a/cmd/tools/modules/testing/common.v +++ b/cmd/tools/modules/testing/common.v @@ -233,6 +233,10 @@ pub fn v_build_failing_skipped(zargs string, folder string, skipped []string) bo mut mains := []string{} for f in files { if !f.contains('modules') && !f.contains('preludes') { + if f.contains('/vweb/') { + continue + + } $if windows { // skip pico example on windows if f.ends_with('examples\\pico\\pico.v') { diff --git a/examples/vcasino/VCasino.v b/examples/vcasino/vcasino.v similarity index 99% rename from examples/vcasino/VCasino.v rename to examples/vcasino/vcasino.v index 97c44627af..0026e9c2c5 100644 --- a/examples/vcasino/VCasino.v +++ b/examples/vcasino/vcasino.v @@ -92,7 +92,7 @@ fn get_bet(money int) int { fn run_wheel(bet_nbr int, _bet int) int { mut bet := _bet - rand.seed(time.now().unix) + rand.seed(int(time.now().unix)) winning_nbr := rand.next(50) print('Roulette Wheel spinning... and stops on the number $winning_nbr which is a ') if winning_nbr % 2 == 1 { diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index b5c06c6b1b..543e8d3146 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -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 { x := styp // .replace('*', '_ptr') // handle option ptrs // replace void with something else - size := if base == 'void' { - 'int' - } else { - base - } + size := if base == 'void' { 'int' } else { base } ret := 'struct $x { bool ok; bool is_none; @@ -386,7 +382,6 @@ fn (mut g Gen) register_optional(t table.Type) string { bool ok; bool is_none; } Option2_$no_ptr;') - // println(styp) g.typedefs2.writeln('typedef struct $styp $styp;') 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 { return s.replace('\\', '\\\\').replace('"', "\'") } + // ctoslit returns a 'tos_lit("$s")' call, where s is properly escaped. fn ctoslit(s string) string { return 'tos_lit("' + cestring(s) + '")' } + fn (mut g Gen) gen_assert_stmt(a ast.AssertStmt) { g.writeln('// assert') g.inside_ternary++ @@ -978,7 +975,7 @@ fn (mut g Gen) gen_assert_metainfo(a ast.AssertStmt) string { ast.CallExpr { g.writeln(' ${metaname}.op = tos_lit("call");') } - else{} + else {} } return metaname } @@ -986,14 +983,14 @@ fn (mut g Gen) gen_assert_metainfo(a ast.AssertStmt) string { fn (mut g Gen) gen_assert_single_expr(e ast.Expr, t table.Type) { unknown_value := '*unknown value*' match e { - ast.CallExpr { g.write( ctoslit(unknown_value) ) } - ast.CastExpr { g.write( ctoslit(unknown_value) ) } - ast.IndexExpr { g.write( ctoslit(unknown_value) ) } - ast.PrefixExpr { g.write( ctoslit(unknown_value) ) } - ast.MatchExpr { g.write( ctoslit(unknown_value) ) } - else{ g.gen_expr_to_string(e, t) } + ast.CallExpr { g.write(ctoslit(unknown_value)) } + ast.CastExpr { g.write(ctoslit(unknown_value)) } + ast.IndexExpr { g.write(ctoslit(unknown_value)) } + ast.PrefixExpr { g.write(ctoslit(unknown_value)) } + ast.MatchExpr { g.write(ctoslit(unknown_value)) } + else { g.gen_expr_to_string(e, t) } } - g.write(' /* typeof: ' +typeof(e) + ' type: ' + t.str() + ' */ ') + g.write(' /* typeof: ' + typeof(e) + ' type: ' + t.str() + ' */ ') } fn (mut g Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) { @@ -2063,7 +2060,7 @@ fn (mut g Gen) ident(node ast.Ident) { g.write(node.name[2..].replace('.', '__')) return } - if node.kind == .constant && !node.name.starts_with('g_') { + if node.kind == .constant { // && !node.name.starts_with('g_') { // TODO globals hack g.write('_const_') } @@ -2346,7 +2343,6 @@ fn (mut g Gen) return_statement(node ast.Return) { g.write('/*opt promotion*/ Option $tmp = ') g.expr_with_cast(node.exprs[0], node.types[0], g.fn_decl.return_type) g.write(';') - styp := g.typ(g.fn_decl.return_type) g.writeln('return *($styp*)&$tmp;') 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) // mr_info := typ_sym.info as table.MultiReturn mut styp := '' - mut opt_tmp := '' mut opt_type := '' - if fn_return_is_optional { opt_type = g.typ(g.fn_decl.return_type) // Create a tmp for this option opt_tmp = g.new_tmp_var() g.write('$opt_type $opt_tmp;') styp = g.base_type(g.fn_decl.return_type) - g.write('opt_ok2(&($styp/*X*/[]) { ') } else { g.write('return ') @@ -2391,7 +2384,6 @@ fn (mut g Gen) return_statement(node ast.Return) { g.writeln(';') multi_unpack += g.go_before_stmt(0) g.write(s) - expr_types := expr_sym.mr_info().types for j, _ in expr_types { 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.write(last_text) } - type_name := g.typ(field.typ) - field_name := c_name(field.name) - g.type_definitions.writeln('\t$type_name $field_name;') } } else {