table: register rune type

pull/6221/head
Alexander Medvednikov 2020-08-25 18:15:19 +02:00
parent 45505a8423
commit a55bea44da
4 changed files with 35 additions and 13 deletions

View File

@ -3,6 +3,7 @@
- make `-autofree` the default - make `-autofree` the default
- coroutines - coroutines
+ channels
- lock{} - lock{}
- thread safe arrays/maps - thread safe arrays/maps
- C2V translator - C2V translator

View File

@ -280,12 +280,19 @@ pub fn (mut g JsGen) typ(t table.Type) string {
.interface_ { .interface_ {
styp = g.js_name(sym.name) styp = g.js_name(sym.name)
} }
.rune {
styp = 'any'
}
} }
/* else { /*
else {
println('jsgen.typ: Unhandled type $t') println('jsgen.typ: Unhandled type $t')
styp = sym.name styp = sym.name
} */ }
if styp.starts_with('JS.') { return styp[3..] } */
if styp.starts_with('JS.') {
return styp[3..]
}
return styp return styp
} }
@ -1108,7 +1115,7 @@ fn (mut g JsGen) gen_array_init_expr(it ast.ArrayInit) {
// 2) Give the code unnecessary complexity // 2) Give the code unnecessary complexity
// 3) Have several limitations like missing most `Array.prototype` methods // 3) Have several limitations like missing most `Array.prototype` methods
// 4) Modern engines can optimize regular arrays into typed arrays anyways, // 4) Modern engines can optimize regular arrays into typed arrays anyways,
// offering similar performance // offering similar performance
if it.has_len { if it.has_len {
t1 := g.new_tmp_var() t1 := g.new_tmp_var()
t2 := g.new_tmp_var() t2 := g.new_tmp_var()
@ -1259,17 +1266,21 @@ fn (mut g JsGen) gen_if_expr(node ast.IfExpr) {
g.expr(branch.cond) g.expr(branch.cond)
g.writeln(') {') g.writeln(') {')
} else if i == node.branches.len - 1 && node.has_else { } else if i == node.branches.len - 1 && node.has_else {
/* if is_guard { /*
if is_guard {
//g.writeln('} if (!$guard_ok) { /* else */') //g.writeln('} if (!$guard_ok) { /* else */')
} else { */ } else {
*/
g.writeln('} else {') g.writeln('} else {')
// } // }
} }
g.stmts(branch.stmts) g.stmts(branch.stmts)
} }
/* if is_guard { /*
if is_guard {
g.write('}') g.write('}')
} */ }
*/
g.writeln('}') g.writeln('}')
g.writeln('') g.writeln('')
} }
@ -1334,7 +1345,8 @@ fn (mut g JsGen) gen_infix_expr(it ast.InfixExpr) {
g.write('.push(') g.write('.push(')
if r_sym.kind == .array { if r_sym.kind == .array {
g.write('...') g.write('...')
} // arr << [1, 2] }
// arr << [1, 2]
g.expr(it.right) g.expr(it.right)
g.write(')') g.write(')')
} else if r_sym.kind in [.array, .map, .string] && it.op in [.key_in, .not_in] { } else if r_sym.kind in [.array, .map, .string] && it.op in [.key_in, .not_in] {

View File

@ -15,8 +15,8 @@ import strings
pub type Type int pub type Type int
pub type TypeInfo = Alias | Array | ArrayFixed | Chan | Enum | FnType | GenericStructInst | Interface | pub type TypeInfo = Alias | Array | ArrayFixed | Chan | Enum | FnType | GenericStructInst |
Map | MultiReturn | Struct | SumType Interface | Map | MultiReturn | Struct | SumType
pub enum Language { pub enum Language {
v v
@ -305,7 +305,7 @@ pub const (
pub const ( pub const (
builtin_type_names = ['void', 'voidptr', 'charptr', 'byteptr', 'i8', 'i16', 'int', 'i64', 'u16', builtin_type_names = ['void', 'voidptr', 'charptr', 'byteptr', 'i8', 'i16', 'int', 'i64', 'u16',
'u32', 'u64', 'any_int', 'f32', 'f64', 'any_float', 'string', 'ustring', 'char', 'byte', 'bool', 'u32', 'u64', 'any_int', 'f32', 'f64', 'any_float', 'string', 'ustring', 'char', 'byte', 'bool',
'none', 'array', 'array_fixed', 'map', 'chan', 'any', 'struct', 'mapnode', 'size_t'] 'none', 'array', 'array_fixed', 'map', 'chan', 'any', 'struct', 'mapnode', 'size_t', 'rune']
) )
pub struct MultiReturn { pub struct MultiReturn {
@ -338,6 +338,7 @@ pub enum Kind {
f64 f64
char char
size_t size_t
rune
bool bool
none_ none_
string string
@ -593,6 +594,12 @@ pub fn (mut t Table) register_builtin_type_symbols() {
source_name: 'size_t' source_name: 'size_t'
mod: 'builtin' mod: 'builtin'
}) })
t.register_type_symbol({
kind: .size_t
name: 'rune'
source_name: 'rune'
mod: 'builtin'
})
// TODO: remove. for v1 map compatibility // TODO: remove. for v1 map compatibility
map_string_string_idx := t.find_or_register_map(string_type, string_type) map_string_string_idx := t.find_or_register_map(string_type, string_type)
map_string_int_idx := t.find_or_register_map(string_type, int_type) map_string_int_idx := t.find_or_register_map(string_type, int_type)
@ -671,6 +678,7 @@ pub fn (k Kind) str() string {
.interface_ { 'interface' } .interface_ { 'interface' }
.ustring { 'ustring' } .ustring { 'ustring' }
.generic_struct_inst { 'generic_struct_inst' } .generic_struct_inst { 'generic_struct_inst' }
.rune { 'rune' }
} }
return k_str return k_str
} }
@ -756,7 +764,7 @@ pub mut:
pub struct Chan { pub struct Chan {
pub mut: pub mut:
elem_type Type elem_type Type
} }
pub struct Map { pub struct Map {

View File

@ -7,6 +7,7 @@ pub struct FilterVTestConfig {
fix_slashes bool = true fix_slashes bool = true
} }
// if VTEST_ONLY env var is set, returns tests that match the query
pub fn filter_vtest_only(paths []string, config FilterVTestConfig) []string { pub fn filter_vtest_only(paths []string, config FilterVTestConfig) []string {
mut res := []string{} mut res := []string{}
patterns := os.getenv('VTEST_ONLY').split(',') patterns := os.getenv('VTEST_ONLY').split(',')