@@ -400,26 +400,51 @@ fn (mut c Amd64) inc_var(var Var, config VarConfig) {
400400 c.inc_var (var_object as GlobalVar , config)
401401 }
402402 Register {
403+ c.g.n_error ('Register incrementation is not supported yet' )
403404 // TODO
404405 // g.inc()
405406 }
406407 }
407408 }
408409 LocalVar {
409- // TODO: size
410- c.g. write8 ( 0x81 ) // 83 for 1 byte
410+ typ := c.g. unwrap (var.typ)
411+ mut size_str := 'UNKNOWN'
411412 offset := var.offset - config.offset
412413 is_far_var := offset > 0x80 || offset < - 0x7f
414+ match typ {
415+ ast.i64_ type_idx, ast.u64_ type_idx, ast.isize_type_idx, ast.usize_type_idx,
416+ ast.int_literal_type_idx {
417+ c.g.write16 (0xFF48 )
418+ size_str = 'QWORD'
419+ }
420+ ast.i32_ type_idx, ast.int_type_idx, ast.u32_ type_idx, ast.rune_type_idx {
421+ c.g.write8 (0xFF )
422+ size_str = 'DWORD'
423+ }
424+ ast.i16_ type_idx, ast.u16_ type_idx {
425+ c.g.write8 (0xFF )
426+ size_str = 'WORD'
427+ }
428+ ast.i8_ type_idx, ast.u8_ type_idx, ast.char_type_idx {
429+ c.g.write8 (0xFE )
430+ size_str = 'BYTE'
431+ }
432+ else {
433+ ts := c.g.table.sym (typ.idx_type ())
434+ c.g.n_error ('unsupported type for inc_var ${ts.info} ' )
435+ }
436+ }
437+
413438 c.g.write8 (if is_far_var { i32 (0x85 ) } else { i32 (0x45 ) })
414439 if is_far_var {
415440 c.g.write32 (i32 ((0xffffffff - i64 (offset) + 1 ) % 0x100000000 ))
416441 } else {
417442 c.g.write8 ((0xff - offset + 1 ) % 0x100 )
418443 }
419- c.g.write32 (1 )
420- c.g.println ('inc_var `${var.name} `' )
444+ c.g.println ('inc_var ${size_str} `${var.name} `' )
421445 }
422446 GlobalVar {
447+ c.g.n_error ('Global variables incrementation is not supported yet' )
423448 // TODO
424449 }
425450 }
@@ -643,7 +668,7 @@ fn (mut c Amd64) mov_reg_to_var(var Var, r Register, config VarConfig) {
643668 c.g.write16 (0x8948 + if is_extended_register { i32 (4 ) } else { i32 (0 ) })
644669 size_str = 'QWORD'
645670 }
646- ast.int_type_idx, ast.u32_ type_idx, ast.rune_type_idx {
671+ ast.i 32_ type_idx, ast. int_type_idx, ast.u32_ type_idx, ast.rune_type_idx {
647672 if is_extended_register {
648673 c.g.write8 (0x44 )
649674 }
@@ -694,7 +719,7 @@ fn (mut c Amd64) mov_reg_to_var(var Var, r Register, config VarConfig) {
694719 } else {
695720 c.g.write8 ((0xff - offset + 1 ) % 0x100 )
696721 }
697- c.g.println ('mov ${size_str} PTR [rbp-${int(offset).hex2()} ],${reg} ' )
722+ c.g.println ('mov ${size_str} PTR [rbp-${int(offset).hex2()} ],${reg} ; ` ${var.name} ` ' )
698723 }
699724 GlobalVar {
700725 // TODO
@@ -746,7 +771,7 @@ fn (mut c Amd64) mov_int_to_var(var Var, integer i32, config VarConfig) {
746771 c.g.write16 (u16 (integer))
747772 c.g.println ('mov WORD PTR[rbp-${int(offset).hex2()} ], ${integer} ' )
748773 }
749- ast.int_type_idx, ast.u32_ type_idx, ast.rune_type_idx {
774+ ast.i 32_ type_idx, ast. int_type_idx, ast.u32_ type_idx, ast.rune_type_idx {
750775 c.g.write8 (0xc7 )
751776 c.g.write8 (if is_far_var { i32 (0x85 ) } else { i32 (0x45 ) })
752777 if is_far_var {
@@ -832,7 +857,6 @@ fn (mut c Amd64) mov_var_to_reg(reg Register, var Var, config VarConfig) {
832857 typ := if config.typ == 0 { var.typ } else { config.typ }
833858 size := c.g.get_type_size (typ)
834859 is_signed := ! typ.is_any_kind_of_pointer () && typ.is_signed ()
835-
836860 instruction , size_str := match true {
837861 size == 4 && is_signed {
838862 // movsxd rax, DWORD PTR [rbp-0x8]
0 commit comments