@@ -265,7 +265,9 @@ fn byt(n i32, s i32) u8 {
265265fn (mut g Gen) get_var_from_ident (ident ast.Ident) IdentVar {
266266 mut obj := ident.obj
267267 if obj ! in [ast.Var, ast.ConstField, ast.GlobalField, ast.AsmRegister] {
268- obj = ident.scope.find (ident.name) or { g.n_error ('unknown variable ${ident .name }' ) }
268+ obj = ident.scope.find (ident.name) or {
269+ g.n_error ('${@LOCATION } unknown variable ${ident .name }' )
270+ }
269271 }
270272 match obj {
271273 ast.Var {
@@ -277,7 +279,7 @@ fn (mut g Gen) get_var_from_ident(ident ast.Ident) IdentVar {
277279 }
278280 }
279281 else {
280- g.n_error ('unsupported variable type type:${obj } name:${ident .name }' )
282+ g.n_error ('${@ LOCATION } unsupported variable type type:${obj } name:${ident .name }' )
281283 }
282284 }
283285}
@@ -291,7 +293,7 @@ fn (mut g Gen) get_type_from_var(var Var) ast.Type {
291293 return var.typ
292294 }
293295 GlobalVar {
294- g.n_error ('cannot get type from GlobalVar yet' )
296+ g.n_error ('${@ LOCATION } cannot get type from GlobalVar yet' )
295297 }
296298 }
297299}
@@ -452,7 +454,7 @@ pub fn (mut g Gen) generate_header() {
452454 }
453455 }
454456 else {
455- g.n_error ('only `raw`, `linux`, `windows` and `macos` are supported for -os in -native' )
457+ g.n_error ('${@ LOCATION } only `raw`, `linux`, `windows` and `macos` are supported for -os in -native' )
456458 }
457459 }
458460}
@@ -517,7 +519,7 @@ pub fn (mut g Gen) link(obj_name string) {
517519 // TODO: implement linking for macos!
518520 }
519521 else {
520- g.n_error ('native linking is not implemented for ${g .pref .os }' )
522+ g.n_error ('${@ LOCATION } native linking is not implemented for ${g .pref .os }' )
521523 }
522524 }
523525}
@@ -681,15 +683,17 @@ fn (mut g Gen) try_var_offset(var_name string) i32 {
681683fn (mut g Gen) get_var_offset (var_name string ) i32 {
682684 r := g.try_var_offset (var_name)
683685 if r == - 1 {
684- g.n_error ('unknown variable `${var_name }`' )
686+ g.n_error ('${@ LOCATION } unknown variable `${var_name }`' )
685687 }
686688 return r
687689}
688690
689691fn (mut g Gen) get_field_offset (in_type ast.Type, name string ) i32 {
690692 typ := g.unwrap (in_type)
691693 ts := g.table.sym (typ)
692- field := ts.find_field (name) or { g.n_error ('Could not find field `${name }` on init' ) }
694+ field := ts.find_field (name) or {
695+ g.n_error ('${@LOCATION } Could not find field `${name }` on init' )
696+ }
693697 return g.structs[typ.idx ()].offsets[field.i]
694698}
695699
@@ -724,7 +728,7 @@ fn (mut g Gen) get_type_size(raw_type ast.Type) i32 {
724728 ast.float_literal_type_idx { 8 }
725729 ast.char_type_idx { 1 }
726730 ast.rune_type_idx { 4 }
727- else { g.n_error ('unknown type size ${typ }' ) }
731+ else { g.n_error ('${@ LOCATION } unknown type size ${typ }' ) }
728732 }
729733 }
730734 if typ.is_bool () {
@@ -835,7 +839,7 @@ fn (mut g Gen) get_sizeof_ident(ident ast.Ident) i32 {
835839 return g.get_type_size (typ)
836840 }
837841 size := g.var_alloc_size[ident.name] or {
838- g.n_error ('unknown variable `${ident }`' )
842+ g.n_error ('${@ LOCATION } unknown variable `${ident }`' )
839843 return 0
840844 }
841845 return size
@@ -911,7 +915,7 @@ fn (mut g Gen) eval_escape_codes(str string) string {
911915 `u` {
912916 i++
913917 utf8 := strconv.parse_int (str[i..i + 4 ], 16 , 16 ) or {
914- g.n_error ('invalid \\ u escape code (${str [i ..i + 4 ]})' )
918+ g.n_error ('${@ LOCATION } invalid \\ u escape code (${str [i ..i + 4 ]})' )
915919 0
916920 }
917921 i + = 4
@@ -925,22 +929,22 @@ fn (mut g Gen) eval_escape_codes(str string) string {
925929 `x` {
926930 i++
927931 c := strconv.parse_int (str[i..i + 2 ], 16 , 8 ) or {
928- g.n_error ('invalid \\ x escape code (${str [i ..i + 2 ]})' )
932+ g.n_error ('${@ LOCATION } invalid \\ x escape code (${str [i ..i + 2 ]})' )
929933 0
930934 }
931935 i + = 2
932936 buffer << u8 (c)
933937 }
934938 `0` ...`7` {
935939 c := strconv.parse_int (str[i..i + 3 ], 8 , 8 ) or {
936- g.n_error ('invalid escape code \\ ${str [i ..i + 3 ]}' )
940+ g.n_error ('${@ LOCATION } invalid escape code \\ ${str [i ..i + 3 ]}' )
937941 0
938942 }
939943 i + = 3
940944 buffer << u8 (c)
941945 }
942946 else {
943- g.n_error ('invalid escape code \\ ${str [i ]}' )
947+ g.n_error ('${@ LOCATION } invalid escape code \\ ${str [i ]}' )
944948 }
945949 }
946950 }
@@ -973,7 +977,7 @@ fn (mut g Gen) gen_to_string(reg Register, typ ast.Type) {
973977 g.code_gen.mov_reg (g.code_gen.main_reg (), reg)
974978 }
975979 } else {
976- g.n_error ('int-to-string conversion not implemented for type ${typ }' )
980+ g.n_error ('${@ LOCATION } int-to-string conversion not implemented for type ${typ }' )
977981 }
978982 g.println ('; to_string }' )
979983}
@@ -986,7 +990,7 @@ fn (mut g Gen) gen_var_to_string(reg Register, expr ast.Expr, var Var, config Va
986990 g.code_gen.convert_rune_to_string (reg, buffer, var, config)
987991 } else if typ.is_int () {
988992 if typ.is_unsigned () {
989- g.n_error ('Unsigned integer print is not supported' )
993+ g.n_error ('${@ LOCATION } Unsigned integer print is not supported' )
990994 } else {
991995 buffer := g.allocate_array ('itoa-buffer' , 1 , 32 ) // 32 characters should be enough
992996 end_of_buffer := buffer + 4 + 32 - 1 // 4 bytes for the size and 32 for the chars, -1 to not go out of array
@@ -1001,7 +1005,7 @@ fn (mut g Gen) gen_var_to_string(reg Register, expr ast.Expr, var Var, config Va
10011005 } else if typ.is_string () {
10021006 g.code_gen.mov_var_to_reg (reg, var, config)
10031007 } else {
1004- g.n_error ('int-to-string conversion not implemented for type ${typ }' )
1008+ g.n_error ('${@ LOCATION } int-to-string conversion not implemented for type ${typ }' )
10051009 }
10061010 g.println ('; var_to_string }' )
10071011}
@@ -1019,7 +1023,7 @@ fn (mut g Gen) patch_calls() {
10191023 for c in g.callpatches {
10201024 addr := g.fn_addr[c.name]
10211025 if addr == 0 {
1022- g.n_error ('fn addr of `${c .name }` = 0' )
1026+ g.n_error ('${@ LOCATION } fn addr of `${c .name }` = 0' )
10231027 return
10241028 }
10251029 last := i32 (g.buf.len)
@@ -1038,7 +1042,7 @@ fn (mut g Gen) patch_labels() {
10381042 for label in g.labels.patches {
10391043 addr := g.labels.addrs[label.id]
10401044 if addr == 0 {
1041- g.n_error ('label addr = 0' )
1045+ g.n_error ('${@ LOCATION } label addr = 0' )
10421046 return
10431047 }
10441048
0 commit comments