From bcde155da77dfe4fccf4549406f7a42fabd1eb17 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Mon, 16 Dec 2019 18:58:56 +0300 Subject: [PATCH] test the recent type alias string; print vweb templates in verbose mode --- vlib/compiler/comptime.v | 6 ++++++ vlib/compiler/table.v | 10 ++++++++++ vlib/compiler/tests/type_test.v | 19 +++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 vlib/compiler/tests/type_test.v diff --git a/vlib/compiler/comptime.v b/vlib/compiler/comptime.v index 8639664fd1..88f2349ef1 100644 --- a/vlib/compiler/comptime.v +++ b/vlib/compiler/comptime.v @@ -171,12 +171,18 @@ fn (p mut Parser) comp_time() { p.check(.lpar) p.check(.rpar) v_code := tmpl.compile_template(path) + if p.pref.is_verbose { + println('vweb template:') + println(v_code) + } is_strings_imorted := p.import_table.known_import('strings') if !is_strings_imorted { p.register_import('strings', 0) // used by v_code } p.import_table.register_used_import('strings') p.genln('/////////////////// tmpl start') + p.scanner.file_path = path + p.scanner.line_nr = 0 p.statements_from_text(v_code, false) p.genln('/////////////////// tmpl end') receiver := p.cur_fn.args[0] diff --git a/vlib/compiler/table.v b/vlib/compiler/table.v index 6ac4a53735..bf57554cf1 100644 --- a/vlib/compiler/table.v +++ b/vlib/compiler/table.v @@ -18,6 +18,7 @@ pub mut: fn_cnt int //atomic obfuscate bool varg_access []VargAccess + //enum_vals map[string][]string //names []Name } @@ -230,9 +231,18 @@ fn is_primitive_type(typ string) bool { return is_number_type(typ) || typ == 'string' } +/* +fn (t mut Table) register_enum_val(typ, val string) { + if t.enum_vals.len == 0 { + t.enum_vals = [val] + } +} +*/ + fn new_table(obfuscate bool) &Table { mut t := &Table { obfuscate: obfuscate + //enum_vals: map[string][]string } t.register_builtin('int') t.register_builtin('size_t') diff --git a/vlib/compiler/tests/type_test.v b/vlib/compiler/tests/type_test.v new file mode 100644 index 0000000000..688bd0669d --- /dev/null +++ b/vlib/compiler/tests/type_test.v @@ -0,0 +1,19 @@ +struct Human { name string } + +pub fn (h Human) str() string { return 'Human: $h.name' } + +type Person Human + +fn test_type_print() { + p := Person{'Bilbo'} + println(p) + assert p.str() == 'Human: Bilbo' +} + +pub fn (h Person) str() string { return 'Person: $h.name' } + +fn test_person_str() { + p := Person{'Bilbo'} + println(p) + assert p.str() == 'Person: Bilbo' +}