1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

v.js: fix for ..

This commit is contained in:
Alexander Medvednikov 2019-09-17 22:16:16 +03:00
parent 32ad33558d
commit ecffa8e1d9
3 changed files with 12 additions and 5 deletions

View File

@ -235,6 +235,11 @@ fn (p mut Parser) gen_for_str_header(i, tmp, var_typ, val string) {
p.genln('$var_typ $val = (($var_typ *) bytes_$tmp . data)[$i];') p.genln('$var_typ $val = (($var_typ *) bytes_$tmp . data)[$i];')
} }
fn (p mut Parser) gen_for_range_header(i, range_end, tmp, var_type, val string) {
p.genln(';\nfor (int $i = $tmp; $i < $range_end; $i++) {')
p.genln('$var_type $val = $i;')
}
fn (p mut Parser) gen_for_map_header(i, tmp, var_typ, val, typ string) { fn (p mut Parser) gen_for_map_header(i, tmp, var_typ, val, typ string) {
def := type_default(typ) def := type_default(typ)
p.genln('array_string keys_$tmp = map_keys(& $tmp ); ') p.genln('array_string keys_$tmp = map_keys(& $tmp ); ')

View File

@ -34,7 +34,6 @@ fn (p mut Parser) gen_fn_decl(f Fn, typ, _str_args string) {
} }
fn types_to_c(types []Type, table &Table) string { fn types_to_c(types []Type, table &Table) string {
println('js typ to code ')
mut sb := strings.new_builder(10) mut sb := strings.new_builder(10)
for t in types { for t in types {
if t.cat != .union_ && t.cat != .struct_ { if t.cat != .union_ && t.cat != .struct_ {
@ -96,6 +95,11 @@ fn (p mut Parser) gen_for_header(i, tmp, var_typ, val string) {
p.genln('var $val = $tmp [$i];') p.genln('var $val = $tmp [$i];')
} }
fn (p mut Parser) gen_for_range_header(i, range_end, tmp, var_type, val string) {
p.genln(';\nfor (var $i = $tmp; $i < $range_end; $i++) {')
p.genln('var /*$var_type*/ $val = $i;')
}
fn (p mut Parser) gen_for_str_header(i, tmp, var_typ, val string) { fn (p mut Parser) gen_for_str_header(i, tmp, var_typ, val string) {
p.genln('for (var $i = 0; $i < $tmp .length; $i ++) {') p.genln('for (var $i = 0; $i < $tmp .length; $i ++) {')
p.genln('var $val = $tmp[$i];') p.genln('var $val = $tmp[$i];')

View File

@ -2983,7 +2983,6 @@ fn (p mut Parser) for_st() {
next_tok := p.peek() next_tok := p.peek()
//debug := p.scanner.file_path.contains('r_draw') //debug := p.scanner.file_path.contains('r_draw')
p.open_scope() p.open_scope()
i_type := if p.is_js { 'var' } else { 'int' }
if p.tok == .lcbr { if p.tok == .lcbr {
// Infinite loop // Infinite loop
p.gen('while (1) {') p.gen('while (1) {')
@ -3147,9 +3146,8 @@ fn (p mut Parser) for_st() {
else if is_str { else if is_str {
p.gen_for_str_header(i, tmp, var_type, val) p.gen_for_str_header(i, tmp, var_type, val)
} }
else if is_range && !p.is_js { else if is_range {
p.genln(';\nfor ($i_type $i = $tmp; $i < $range_end; $i++) {') p.gen_for_range_header(i, range_end, tmp, var_type, val)
p.genln('$var_type $val = $i;')
} }
} else { } else {
// `for a < b {` // `for a < b {`