From 310761873209eb2aa2fea69bc5719aa8668f33bc Mon Sep 17 00:00:00 2001 From: joe-conigliaro Date: Tue, 26 Nov 2019 17:23:11 +1100 Subject: [PATCH] vweb: remove no longer needed special case & fix tmpl --- vlib/compiler/comptime.v | 2 -- vlib/compiler/fn.v | 8 ++------ vlib/compiler/parser.v | 5 ++--- vlib/vweb/tmpl/tmpl.v | 3 +-- 4 files changed, 5 insertions(+), 13 deletions(-) diff --git a/vlib/compiler/comptime.v b/vlib/compiler/comptime.v index 2ed22c5533..042b86e5dc 100644 --- a/vlib/compiler/comptime.v +++ b/vlib/compiler/comptime.v @@ -169,9 +169,7 @@ fn (p mut Parser) comp_time() { } p.import_table.register_used_import('strings') p.genln('/////////////////// tmpl start') - p.is_vweb = true p.statements_from_text(v_code, false) - p.is_vweb = false p.genln('/////////////////// tmpl end') receiver := p.cur_fn.args[0] dot := if receiver.is_mut || receiver.ptr { '->' } else { '.' } diff --git a/vlib/compiler/fn.v b/vlib/compiler/fn.v index 33fd18c377..46a69ebcce 100644 --- a/vlib/compiler/fn.v +++ b/vlib/compiler/fn.v @@ -402,9 +402,7 @@ fn (p mut Parser) fn_decl() { } } dll_export_linkage := p.get_linkage_prefix() - if !p.is_vweb { - p.set_current_fn( f ) - } + p.set_current_fn( f ) // Generate `User_register()` instead of `register()` // Internally it's still stored as "register" in type User mut fn_name_cgen := p.table.fn_gen_name(f) @@ -517,10 +515,8 @@ fn (p mut Parser) fn_decl() { p.genln(p.print_prof_counters()) } // Counting or not, always need to add defer before the end - if !p.is_vweb { - if f.defer_text.len > f.scope_level { + if f.defer_text.len > f.scope_level { p.genln(f.defer_text[f.scope_level]) - } } if typ != 'void' && !p.returns { p.error_with_token_index('$f.name must return "$typ"', f.fn_name_token_idx) diff --git a/vlib/compiler/parser.v b/vlib/compiler/parser.v index b4040d4dfe..dd140f1196 100644 --- a/vlib/compiler/parser.v +++ b/vlib/compiler/parser.v @@ -68,7 +68,6 @@ mut: is_const_literal bool // `1`, `2.0` etc, so that `u64_var == 0` works in_dispatch bool // dispatching generic instance? is_vgen bool - is_vweb bool is_sql bool is_js bool sql_i int // $1 $2 $3 @@ -1172,7 +1171,7 @@ fn (p mut Parser) gen(s string) { // Generate V header from V source fn (p mut Parser) statement(add_semi bool) string { p.expected_type = '' - if p.returns && !p.is_vweb { + if p.returns { p.error('unreachable code') } // if !p.in_dispatch { @@ -2833,7 +2832,7 @@ fn (p mut Parser) return_st() { } else { // Don't allow `return val` in functions that don't return anything - if !p.is_vweb && (p.tok == .name || p.tok == .number || p.tok == .str) { + if p.tok == .name || p.tok == .number || p.tok == .str { p.error_with_token_index('function `$p.cur_fn.name` should not return a value', p.cur_fn.fn_name_token_idx) } diff --git a/vlib/vweb/tmpl/tmpl.v b/vlib/vweb/tmpl/tmpl.v index aed5e84040..cd797c2a97 100644 --- a/vlib/vweb/tmpl/tmpl.v +++ b/vlib/vweb/tmpl/tmpl.v @@ -79,8 +79,7 @@ _ = header } } s.writeln(STR_END) - s.writeln('tmpl_res := sb.str() ') - s.writeln('return tmpl_res }') + s.writeln('tmpl_res := sb.str() }') return s.str() }