mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
cgen,builtin: support for 64bit int 1
This commit is contained in:
parent
f6b60e4d9f
commit
16380c44a8
21 changed files with 152 additions and 183 deletions
|
@ -54,7 +54,7 @@ fn C.isdigit(c int) bool
|
|||
fn C.popen(c &char, t &char) voidptr
|
||||
|
||||
// <libproc.h>
|
||||
pub fn proc_pidpath(int, voidptr, int) int
|
||||
pub fn C.proc_pidpath(int, voidptr, int) int
|
||||
|
||||
fn C.realpath(const_path &char, resolved_path &char) &char
|
||||
|
||||
|
|
|
@ -42,8 +42,8 @@ pub const max_i16 = i16(32767)
|
|||
pub const min_i32 = i32(-2147483648)
|
||||
pub const max_i32 = i32(2147483647)
|
||||
|
||||
pub const min_int = int(-2147483648)
|
||||
pub const max_int = int(2147483647)
|
||||
pub const min_int = $if new_int ? { min_i64 } $else { min_i32 }
|
||||
pub const max_int = $if new_int ? { max_i64 } $else { max_i32 }
|
||||
|
||||
// -9223372036854775808 is wrong, because C compilers parse literal values
|
||||
// without sign first, and 9223372036854775808 overflows i64, hence the
|
||||
|
|
|
@ -2,6 +2,6 @@ module builtin
|
|||
|
||||
// str returns the value of the `int` as a `string`.
|
||||
// Example: assert int(-2020).str() == '-2020'
|
||||
pub fn int_str(n int) string {
|
||||
return i64(n).str()
|
||||
}
|
||||
// pub fn int_str(n int) string {
|
||||
// return i64(n).str()
|
||||
//}
|
||||
|
|
|
@ -31,10 +31,7 @@ pub fn maxof[T]() T {
|
|||
} $else $if T is f64 {
|
||||
return max_f64
|
||||
} $else $if T is int {
|
||||
$if new_int ? {
|
||||
return int(max_i64)
|
||||
}
|
||||
return int(max_i32)
|
||||
return max_int
|
||||
} $else {
|
||||
panic('A maximum value of the type `' + typeof[T]().name + '` is not defined.')
|
||||
}
|
||||
|
@ -68,10 +65,7 @@ pub fn minof[T]() T {
|
|||
} $else $if T is f64 {
|
||||
return -max_f64
|
||||
} $else $if T is int {
|
||||
$if new_int ? {
|
||||
return int(min_i64)
|
||||
}
|
||||
return int(min_i32)
|
||||
return min_int
|
||||
} $else {
|
||||
panic('A minimum value of the type `' + typeof[T]().name + '` is not defined.')
|
||||
}
|
||||
|
|
|
@ -24,13 +24,7 @@ pub const builtins = ['string', 'array', 'DenseArray', 'map', 'Error', 'IError',
|
|||
|
||||
pub type TypeDecl = AliasTypeDecl | FnTypeDecl | SumTypeDecl
|
||||
|
||||
// pub const int_type_name = $if amd64 || arm64 {
|
||||
pub const int_type_name = $if new_int ? {
|
||||
//'int'
|
||||
'i64'
|
||||
} $else {
|
||||
'int'
|
||||
}
|
||||
pub const int_type_name = $if new_int ? { '_vint_t' } $else { 'int' }
|
||||
|
||||
pub type Expr = NodeError
|
||||
| AnonFn
|
||||
|
|
|
@ -1233,7 +1233,7 @@ pub fn (t &Table) type_size(typ Type) (int, int) {
|
|||
}
|
||||
.int {
|
||||
$if new_int ? {
|
||||
$if arm64 || amd64 {
|
||||
$if arm64 || amd64 || rv64 || s390x || ppc64le || loongarch64 {
|
||||
size = 8
|
||||
align = 8
|
||||
} $else {
|
||||
|
|
|
@ -331,8 +331,16 @@ pub fn (mut e Eval) comptime_cond(cond ast.Expr) bool {
|
|||
right := e.comptime_cond(cond.right)
|
||||
return e.infix_expr(left, right, cond.op, ast.bool_type) as bool
|
||||
}
|
||||
ast.PostfixExpr {
|
||||
// unsupport
|
||||
return false
|
||||
}
|
||||
ast.NodeError {
|
||||
// unsupport
|
||||
return false
|
||||
}
|
||||
else {
|
||||
e.error('unsupported expression')
|
||||
e.error('unsupported expression ${cond}')
|
||||
}
|
||||
}
|
||||
return false
|
||||
|
|
|
@ -117,11 +117,11 @@ fn (mut g Gen) fixed_array_init(node ast.ArrayInit, array_type Type, var_name st
|
|||
g.writeln2(';', '{')
|
||||
g.indent++
|
||||
g.writeln('${elem_typ_str}* pelem = (${elem_typ_str}*)${past.tmp_var};')
|
||||
g.writeln('int _len = (int)sizeof(${past.tmp_var}) / sizeof(${elem_typ_str});')
|
||||
g.writeln('for (int index=0; index<_len; index++, pelem++) {')
|
||||
g.writeln('${ast.int_type_name} _len = (${ast.int_type_name})sizeof(${past.tmp_var}) / sizeof(${elem_typ_str});')
|
||||
g.writeln('for (${ast.int_type_name} index=0; index<_len; index++, pelem++) {')
|
||||
g.set_current_pos_as_last_stmt_pos()
|
||||
g.indent++
|
||||
g.writeln('int it = index;') // FIXME: Remove this line when it is fully forbidden
|
||||
g.writeln('${ast.int_type_name} it = index;') // FIXME: Remove this line when it is fully forbidden
|
||||
g.write('*pelem = ')
|
||||
g.expr_with_init(node)
|
||||
g.writeln(';')
|
||||
|
@ -354,10 +354,10 @@ fn (mut g Gen) array_init_with_fields(node ast.ArrayInit, elem_type Type, is_amp
|
|||
g.writeln2(';', '{')
|
||||
g.indent++
|
||||
g.writeln('${elem_typ}* pelem = (${elem_typ}*)${past.tmp_var}.data;')
|
||||
g.writeln('for (int index=0; index<${past.tmp_var}.len; index++, pelem++) {')
|
||||
g.writeln('for (${ast.int_type_name} index=0; index<${past.tmp_var}.len; index++, pelem++) {')
|
||||
g.set_current_pos_as_last_stmt_pos()
|
||||
g.indent++
|
||||
g.writeln('int it = index;') // FIXME: Remove this line when it is fully forbidden
|
||||
g.writeln('${ast.int_type_name} it = index;') // FIXME: Remove this line when it is fully forbidden
|
||||
if elem_type.unaliased_sym.kind != .array_fixed {
|
||||
g.write('*pelem = ')
|
||||
g.expr_with_init(node)
|
||||
|
@ -423,7 +423,7 @@ fn (mut g Gen) array_init_with_fields(node ast.ArrayInit, elem_type Type, is_amp
|
|||
g.expr(node.len_expr)
|
||||
g.writeln(') * sizeof(${elem_styp}));')
|
||||
ind := g.new_tmp_var()
|
||||
g.write('for (int ${ind}=0; ${ind}<')
|
||||
g.write('for (${ast.int_type_name} ${ind}=0; ${ind}<')
|
||||
g.expr(node.len_expr)
|
||||
g.writeln('; ${ind}++) {')
|
||||
g.write('\t${tmp}[${ind}] = ')
|
||||
|
@ -565,7 +565,7 @@ fn (mut g Gen) gen_array_map(node ast.CallExpr) {
|
|||
}
|
||||
|
||||
i := g.new_tmp_var()
|
||||
g.writeln('for (int ${i} = 0; ${i} < ${past.tmp_var}_len; ++${i}) {')
|
||||
g.writeln('for (${ast.int_type_name} ${i} = 0; ${i} < ${past.tmp_var}_len; ++${i}) {')
|
||||
g.indent++
|
||||
var_name := g.get_array_expr_param_name(mut expr)
|
||||
is_auto_heap := expr is ast.CastExpr && (expr.expr is ast.Ident && expr.expr.is_auto_heap())
|
||||
|
@ -948,7 +948,7 @@ fn (mut g Gen) gen_fixed_array_reverse_in_place(node ast.CallExpr) {
|
|||
i := g.new_tmp_var()
|
||||
left_var := g.expr_string(node.left)
|
||||
g.empty_line = true
|
||||
g.writeln('for (int ${i} = 0; ${i} < ${info.size}/2; ++${i}) {')
|
||||
g.writeln('for (${ast.int_type_name} ${i} = 0; ${i} < ${info.size}/2; ++${i}) {')
|
||||
g.writeln('\tmemcpy(&${tmp_var}, &${left_var}[${i}], sizeof(${elem_styp}));')
|
||||
g.writeln('\tmemcpy(&${left_var}[${i}], &${left_var}[${info.size}-${i}-1], sizeof(${elem_styp}));')
|
||||
g.writeln('\tmemcpy(&${left_var}[${info.size}-${i}-1], &${tmp_var}, sizeof(${elem_styp}));')
|
||||
|
@ -985,7 +985,7 @@ fn (mut g Gen) gen_array_filter(node ast.CallExpr) {
|
|||
}
|
||||
|
||||
i := g.new_tmp_var()
|
||||
g.writeln('for (int ${i} = 0; ${i} < ${past.tmp_var}_len; ++${i}) {')
|
||||
g.writeln('for (${ast.int_type_name} ${i} = 0; ${i} < ${past.tmp_var}_len; ++${i}) {')
|
||||
g.indent++
|
||||
g.write_prepared_var(var_name, info.elem_type, elem_type_str, past.tmp_var, i, true,
|
||||
false)
|
||||
|
@ -1123,10 +1123,6 @@ fn (mut g Gen) get_array_contains_method(typ ast.Type) string {
|
|||
|
||||
fn (mut g Gen) gen_array_contains_methods() {
|
||||
mut done := []ast.Type{}
|
||||
mut got_int_str := false
|
||||
$if new_int ? {
|
||||
println(g.array_contains_types)
|
||||
}
|
||||
for t in g.array_contains_types {
|
||||
left_final_sym := g.table.final_sym(t)
|
||||
if left_final_sym.idx in done || g.table.sym(t).has_method('contains') {
|
||||
|
@ -1137,20 +1133,6 @@ fn (mut g Gen) gen_array_contains_methods() {
|
|||
mut left_type_str := g.styp(t)
|
||||
fn_name := '${left_type_str}_contains'
|
||||
|
||||
$if new_int ? {
|
||||
if fn_name == 'Array_i64_contains' {
|
||||
if got_int_str {
|
||||
continue
|
||||
} else {
|
||||
got_int_str = true
|
||||
}
|
||||
}
|
||||
|
||||
// if t == ast.int_type_idx || t == ast.i64_type_idx {
|
||||
// continue
|
||||
//}
|
||||
}
|
||||
|
||||
if left_final_sym.kind == .array {
|
||||
elem_type := (left_final_sym.info as ast.Array).elem_type
|
||||
mut elem_type_str := g.styp(elem_type)
|
||||
|
@ -1162,7 +1144,7 @@ fn (mut g Gen) gen_array_contains_methods() {
|
|||
}
|
||||
g.type_definitions.writeln('${g.static_non_parallel}bool ${fn_name}(${left_type_str} a, ${elem_type_str} v);')
|
||||
fn_builder.writeln('${g.static_non_parallel}bool ${fn_name}(${left_type_str} a, ${elem_type_str} v) {')
|
||||
fn_builder.writeln('\tfor (int i = 0; i < a.len; ++i) {')
|
||||
fn_builder.writeln('\tfor (${ast.int_type_name} i = 0; i < a.len; ++i) {')
|
||||
if elem_kind == .string {
|
||||
fn_builder.writeln('\t\tif (fast_string_eq(((string*)a.data)[i], v)) {')
|
||||
} else if elem_kind in [.array, .array_fixed] && elem_is_not_ptr {
|
||||
|
@ -1204,7 +1186,7 @@ fn (mut g Gen) gen_array_contains_methods() {
|
|||
}
|
||||
g.type_definitions.writeln('${g.static_non_parallel}bool ${fn_name}(${left_type_str} a, ${elem_type_str} v);')
|
||||
fn_builder.writeln('${g.static_non_parallel}bool ${fn_name}(${left_type_str} a, ${elem_type_str} v) {')
|
||||
fn_builder.writeln('\tfor (int i = 0; i < ${size}; ++i) {')
|
||||
fn_builder.writeln('\tfor (${ast.int_type_name} i = 0; i < ${size}; ++i) {')
|
||||
if elem_kind == .string {
|
||||
fn_builder.writeln('\t\tif (fast_string_eq(a[i], v)) {')
|
||||
} else if elem_kind in [.array, .array_fixed] && elem_is_not_ptr {
|
||||
|
@ -1308,10 +1290,10 @@ fn (mut g Gen) gen_array_index_methods() {
|
|||
left_type_str = 'Array_voidptr'
|
||||
elem_type_str = 'voidptr'
|
||||
}
|
||||
g.type_definitions.writeln('${g.static_non_parallel}int ${fn_name}(${left_type_str} a, ${elem_type_str} v);')
|
||||
fn_builder.writeln('${g.static_non_parallel}int ${fn_name}(${left_type_str} a, ${elem_type_str} v) {')
|
||||
g.type_definitions.writeln('${g.static_non_parallel}${ast.int_type_name} ${fn_name}(${left_type_str} a, ${elem_type_str} v);')
|
||||
fn_builder.writeln('${g.static_non_parallel}${ast.int_type_name} ${fn_name}(${left_type_str} a, ${elem_type_str} v) {')
|
||||
fn_builder.writeln('\t${elem_type_str}* pelem = a.data;')
|
||||
fn_builder.writeln('\tfor (int i = 0; i < a.len; ++i, ++pelem) {')
|
||||
fn_builder.writeln('\tfor (${ast.int_type_name} i = 0; i < a.len; ++i, ++pelem) {')
|
||||
if elem_sym.kind == .string {
|
||||
fn_builder.writeln('\t\tif (fast_string_eq(*pelem, v)) {')
|
||||
} else if elem_sym.kind in [.array, .array_fixed] && !info.elem_type.is_ptr() {
|
||||
|
@ -1352,9 +1334,9 @@ fn (mut g Gen) gen_array_index_methods() {
|
|||
if elem_sym.kind == .function {
|
||||
elem_type_str = 'voidptr'
|
||||
}
|
||||
g.type_definitions.writeln('${g.static_non_parallel}int ${fn_name}(${left_type_str} a, ${elem_type_str} v);')
|
||||
fn_builder.writeln('${g.static_non_parallel}int ${fn_name}(${left_type_str} a, ${elem_type_str} v) {')
|
||||
fn_builder.writeln('\tfor (int i = 0; i < ${info.size}; ++i) {')
|
||||
g.type_definitions.writeln('${g.static_non_parallel}${ast.int_type_name} ${fn_name}(${left_type_str} a, ${elem_type_str} v);')
|
||||
fn_builder.writeln('${g.static_non_parallel}${ast.int_type_name} ${fn_name}(${left_type_str} a, ${elem_type_str} v) {')
|
||||
fn_builder.writeln('\tfor (${ast.int_type_name} i = 0; i < ${info.size}; ++i) {')
|
||||
if elem_sym.kind == .string {
|
||||
fn_builder.writeln('\t\tif (fast_string_eq(a[i], v)) {')
|
||||
} else if elem_sym.kind in [.array, .array_fixed] && !info.elem_type.is_ptr() {
|
||||
|
@ -1489,7 +1471,7 @@ fn (mut g Gen) gen_array_any(node ast.CallExpr) {
|
|||
}
|
||||
}
|
||||
i := g.new_tmp_var()
|
||||
g.writeln('for (int ${i} = 0; ${i} < ${past.tmp_var}_len; ++${i}) {')
|
||||
g.writeln('for (${ast.int_type_name} ${i} = 0; ${i} < ${past.tmp_var}_len; ++${i}) {')
|
||||
g.indent++
|
||||
|
||||
g.write_prepared_var(var_name, elem_type, elem_type_str, past.tmp_var, i, left_is_array,
|
||||
|
@ -1567,7 +1549,8 @@ fn (mut g Gen) gen_array_count(node ast.CallExpr) {
|
|||
(sym.info as ast.ArrayFixed).elem_type
|
||||
}
|
||||
elem_type_str := g.styp(elem_type)
|
||||
has_infix_left_var_name := g.write_prepared_tmp_value(past.tmp_var, node, 'int', '0')
|
||||
has_infix_left_var_name := g.write_prepared_tmp_value(past.tmp_var, node, ast.int_type_name,
|
||||
'0')
|
||||
|
||||
mut expr := node.args[0].expr
|
||||
var_name := g.get_array_expr_param_name(mut expr)
|
||||
|
@ -1580,7 +1563,7 @@ fn (mut g Gen) gen_array_count(node ast.CallExpr) {
|
|||
}
|
||||
}
|
||||
i := g.new_tmp_var()
|
||||
g.writeln('for (int ${i} = 0; ${i} < ${past.tmp_var}_len; ++${i}) {')
|
||||
g.writeln('for (${ast.int_type_name} ${i} = 0; ${i} < ${past.tmp_var}_len; ++${i}) {')
|
||||
g.indent++
|
||||
|
||||
g.write_prepared_var(var_name, elem_type, elem_type_str, past.tmp_var, i, left_is_array,
|
||||
|
@ -1674,7 +1657,7 @@ fn (mut g Gen) gen_array_all(node ast.CallExpr) {
|
|||
}
|
||||
}
|
||||
|
||||
g.writeln('for (int ${i} = 0; ${i} < ${past.tmp_var}_len; ++${i}) {')
|
||||
g.writeln('for (${ast.int_type_name} ${i} = 0; ${i} < ${past.tmp_var}_len; ++${i}) {')
|
||||
g.indent++
|
||||
g.write_prepared_var(var_name, elem_type, elem_type_str, past.tmp_var, i, left_is_array,
|
||||
false)
|
||||
|
@ -1764,7 +1747,7 @@ fn (mut g Gen) write_prepared_tmp_value(tmp string, node &ast.CallExpr, tmp_styp
|
|||
g.write('->val')
|
||||
}
|
||||
g.writeln(';')
|
||||
g.writeln('int ${tmp}_len = ${tmp}_orig.len;')
|
||||
g.writeln('${ast.int_type_name} ${tmp}_len = ${tmp}_orig.len;')
|
||||
} else if left_sym.kind == .array_fixed {
|
||||
left_info := left_sym.info as ast.ArrayFixed
|
||||
left_styp := g.styp(left_type)
|
||||
|
@ -1782,7 +1765,7 @@ fn (mut g Gen) write_prepared_tmp_value(tmp string, node &ast.CallExpr, tmp_styp
|
|||
}
|
||||
}
|
||||
g.writeln(', sizeof(${left_styp}));')
|
||||
g.writeln('int ${tmp}_len = ${left_info.size};')
|
||||
g.writeln('${ast.int_type_name} ${tmp}_len = ${left_info.size};')
|
||||
}
|
||||
return has_infix_left_var_name
|
||||
}
|
||||
|
|
|
@ -383,7 +383,7 @@ fn (mut g Gen) gen_array_equality_fn(left_type ast.Type) string {
|
|||
fn_builder.writeln('\tif (${left_len} != ${right_len}) {')
|
||||
fn_builder.writeln('\t\treturn false;')
|
||||
fn_builder.writeln('\t}')
|
||||
fn_builder.writeln('\tfor (int i = 0; i < ${left_len}; ++i) {')
|
||||
fn_builder.writeln('\tfor (${ast.int_type_name} i = 0; i < ${left_len}; ++i) {')
|
||||
// compare every pair of elements of the two arrays
|
||||
if elem.sym.kind == .string {
|
||||
fn_builder.writeln('\t\tif (!string__eq(*((${ptr_elem_styp}*)((byte*)${left_data}+(i*${left_elem}))), *((${ptr_elem_styp}*)((byte*)${right_data}+(i*${right_elem}))))) {')
|
||||
|
@ -472,7 +472,7 @@ fn (mut g Gen) gen_fixed_array_equality_fn(left_type ast.Type) string {
|
|||
fn_builder.writeln('\t\treturn true;')
|
||||
fn_builder.writeln('\t}')
|
||||
}
|
||||
fn_builder.writeln('\tfor (int i = 0; i < ${size}; ++i) {')
|
||||
fn_builder.writeln('\tfor (${ast.int_type_name} i = 0; i < ${size}; ++i) {')
|
||||
// compare every pair of elements of the two fixed arrays
|
||||
if elem.sym.kind == .string {
|
||||
fn_builder.writeln('\t\tif (!string__eq(((string*)${left})[i], ((string*)${right})[i])) {')
|
||||
|
@ -537,7 +537,7 @@ fn (mut g Gen) gen_map_equality_fn(left_type ast.Type) string {
|
|||
fn_builder.writeln('\tif (${left_len} != ${right_len}) {')
|
||||
fn_builder.writeln('\t\treturn false;')
|
||||
fn_builder.writeln('\t}')
|
||||
fn_builder.writeln('\tfor (int i = 0; i < ${key_values}.len; ++i) {')
|
||||
fn_builder.writeln('\tfor (${ast.int_type_name} i = 0; i < ${key_values}.len; ++i) {')
|
||||
fn_builder.writeln('\t\tif (!DenseArray_has_index(&${key_values}, i)) continue;')
|
||||
fn_builder.writeln('\t\tvoidptr k = DenseArray_key(&${key_values}, i);')
|
||||
fn_builder.writeln('\t\tif (!map_exists(${b}, k)) return false;')
|
||||
|
|
|
@ -185,7 +185,7 @@ fn (mut g Gen) gen_free_for_array(info ast.Array, styp string, fn_name string) {
|
|||
|
||||
sym := g.table.sym(g.unwrap_generic(info.elem_type))
|
||||
if sym.kind in [.string, .array, .map, .struct] {
|
||||
fn_builder.writeln('\tfor (int i = 0; i < it->len; i++) {')
|
||||
fn_builder.writeln('\tfor (${ast.int_type_name} i = 0; i < it->len; i++) {')
|
||||
|
||||
mut elem_styp := g.styp(info.elem_type).replace('*', '')
|
||||
elem_styp_fn_name := if sym.has_method('free') {
|
||||
|
|
|
@ -16,23 +16,9 @@ fn (mut g Gen) gen_str_default(sym ast.TypeSymbol, styp string, str_fn_name stri
|
|||
}
|
||||
mut convertor := ''
|
||||
mut typename_ := ''
|
||||
mut got_int_str := false
|
||||
if sym.parent_idx in ast.integer_type_idxs {
|
||||
convertor = 'int'
|
||||
typename_ = 'int'
|
||||
$if new_int ? {
|
||||
if str_fn_name == 'i64_str' {
|
||||
if got_int_str {
|
||||
return
|
||||
} else {
|
||||
got_int_str = true
|
||||
}
|
||||
}
|
||||
|
||||
// if sym.parent_idx == ast.int_type_idx {
|
||||
// return
|
||||
//}
|
||||
}
|
||||
} else if sym.parent_idx == ast.f32_type_idx {
|
||||
convertor = 'float'
|
||||
typename_ = 'f32'
|
||||
|
@ -199,8 +185,8 @@ fn (mut g Gen) gen_str_for_option(typ ast.Type, styp string, str_fn_name string)
|
|||
|
||||
g.definitions.writeln('string ${str_fn_name}(${styp} it);')
|
||||
g.auto_str_funcs.writeln('string ${str_fn_name}(${styp} it) { return indent_${str_fn_name}(it, 0); }')
|
||||
g.definitions.writeln('string indent_${str_fn_name}(${styp} it, int indent_count);')
|
||||
g.auto_str_funcs.writeln('string indent_${str_fn_name}(${styp} it, int indent_count) {')
|
||||
g.definitions.writeln('string indent_${str_fn_name}(${styp} it, ${ast.int_type_name} indent_count);')
|
||||
g.auto_str_funcs.writeln('string indent_${str_fn_name}(${styp} it, ${ast.int_type_name} indent_count) {')
|
||||
g.auto_str_funcs.writeln('\tstring res;')
|
||||
g.auto_str_funcs.writeln('\tif (it.state == 0) {')
|
||||
deref := if typ.is_ptr() && !typ.has_flag(.option_mut_param_t) {
|
||||
|
@ -252,8 +238,8 @@ fn (mut g Gen) gen_str_for_result(typ ast.Type, styp string, str_fn_name string)
|
|||
|
||||
g.definitions.writeln('string ${str_fn_name}(${styp} it);')
|
||||
g.auto_str_funcs.writeln('string ${str_fn_name}(${styp} it) { return indent_${str_fn_name}(it, 0); }')
|
||||
g.definitions.writeln('string indent_${str_fn_name}(${styp} it, int indent_count);')
|
||||
g.auto_str_funcs.writeln('string indent_${str_fn_name}(${styp} it, int indent_count) {')
|
||||
g.definitions.writeln('string indent_${str_fn_name}(${styp} it, ${ast.int_type_name} indent_count);')
|
||||
g.auto_str_funcs.writeln('string indent_${str_fn_name}(${styp} it, ${ast.int_type_name} indent_count) {')
|
||||
g.auto_str_funcs.writeln('\tstring res;')
|
||||
g.auto_str_funcs.writeln('\tif (!it.is_error) {')
|
||||
if sym.kind == .string {
|
||||
|
@ -289,8 +275,8 @@ fn (mut g Gen) gen_str_for_alias(info ast.Alias, styp string, str_fn_name string
|
|||
|
||||
g.definitions.writeln('${g.static_non_parallel}string ${str_fn_name}(${arg_def});')
|
||||
g.auto_str_funcs.writeln('${g.static_non_parallel}string ${str_fn_name}(${arg_def}) { return indent_${str_fn_name}(it, 0); }')
|
||||
g.definitions.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${arg_def}, int indent_count);')
|
||||
g.auto_str_funcs.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${arg_def}, int indent_count) {')
|
||||
g.definitions.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${arg_def}, ${ast.int_type_name} indent_count);')
|
||||
g.auto_str_funcs.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${arg_def}, ${ast.int_type_name} indent_count) {')
|
||||
old := g.reset_tmp_count()
|
||||
defer { g.tmp_count = old }
|
||||
g.auto_str_funcs.writeln('\tstring indents = string_repeat(_S(" "), indent_count);')
|
||||
|
@ -370,7 +356,7 @@ fn (mut g Gen) gen_str_for_enum(info ast.Enum, styp string, str_fn_name string)
|
|||
if info.is_flag {
|
||||
clean_name := util.strip_main_name(styp.replace('__', '.'))
|
||||
g.auto_str_funcs.writeln('\tstring ret = _S("${clean_name}{");')
|
||||
g.auto_str_funcs.writeln('\tint first = 1;')
|
||||
g.auto_str_funcs.writeln('\t${ast.int_type_name} first = 1;')
|
||||
g.auto_str_funcs.writeln('\tu64 zit = (u64)it;')
|
||||
for i, val in info.vals {
|
||||
mask := u64(1) << i
|
||||
|
@ -410,10 +396,10 @@ fn (mut g Gen) gen_str_for_interface(info ast.Interface, styp string, typ_str st
|
|||
// _str() functions should have a single argument, the indenting ones take 2:
|
||||
g.definitions.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} x);')
|
||||
g.auto_str_funcs.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} x) { return indent_${str_fn_name}(x, 0); }')
|
||||
g.definitions.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} x, int indent_count);')
|
||||
g.definitions.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} x, ${ast.int_type_name} indent_count);')
|
||||
mut fn_builder := strings.new_builder(512)
|
||||
clean_interface_v_type_name := util.strip_main_name(typ_str)
|
||||
fn_builder.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} x, int indent_count) { /* gen_str_for_interface */')
|
||||
fn_builder.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} x, ${ast.int_type_name} indent_count) { /* gen_str_for_interface */')
|
||||
for typ in info.types {
|
||||
sub_sym := g.table.sym(ast.mktyp(typ))
|
||||
if g.pref.skip_unused && sub_sym.idx !in g.table.used_features.used_syms {
|
||||
|
@ -470,9 +456,9 @@ fn (mut g Gen) gen_str_for_union_sum_type(info ast.SumType, styp string, typ_str
|
|||
// _str() functions should have a single argument, the indenting ones take 2:
|
||||
g.definitions.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} x);')
|
||||
g.auto_str_funcs.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} x) { return indent_${str_fn_name}(x, 0); }')
|
||||
g.definitions.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} x, int indent_count);')
|
||||
g.definitions.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} x, ${ast.int_type_name} indent_count);')
|
||||
mut fn_builder := strings.new_builder(512)
|
||||
fn_builder.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} x, int indent_count) {')
|
||||
fn_builder.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} x, ${ast.int_type_name} indent_count) {')
|
||||
mut clean_sum_type_v_type_name := ''
|
||||
if info.is_anon {
|
||||
variant_names := info.variants.map(util.strip_main_name(g.table.sym(it).name))
|
||||
|
@ -629,11 +615,11 @@ fn (mut g Gen) gen_str_for_array(info ast.Array, styp string, str_fn_name string
|
|||
|
||||
g.definitions.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} a);')
|
||||
g.auto_str_funcs.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} a) { return indent_${str_fn_name}(a, 0);}')
|
||||
g.definitions.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} a, int indent_count);')
|
||||
g.auto_str_funcs.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} a, int indent_count) {')
|
||||
g.definitions.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} a, ${ast.int_type_name} indent_count);')
|
||||
g.auto_str_funcs.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} a, ${ast.int_type_name} indent_count) {')
|
||||
g.auto_str_funcs.writeln('\tstrings__Builder sb = strings__new_builder(2 + a.len * 10);')
|
||||
g.auto_str_funcs.writeln('\tstrings__Builder_write_string(&sb, _S("["));')
|
||||
g.auto_str_funcs.writeln('\tfor (int i = 0; i < a.len; ++i) {')
|
||||
g.auto_str_funcs.writeln('\tfor (${ast.int_type_name} i = 0; i < a.len; ++i) {')
|
||||
if sym.kind == .function {
|
||||
g.auto_str_funcs.writeln('\t\tstring x = ${elem_str_fn_name}();')
|
||||
} else {
|
||||
|
@ -736,11 +722,11 @@ fn (mut g Gen) gen_str_for_array_fixed(info ast.ArrayFixed, styp string, str_fn_
|
|||
|
||||
g.definitions.writeln('${g.static_non_parallel}string ${str_fn_name}(${def_arg});')
|
||||
g.auto_str_funcs.writeln('${g.static_non_parallel}string ${str_fn_name}(${def_arg}) { return indent_${str_fn_name}(a, 0);}')
|
||||
g.definitions.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${def_arg}, int indent_count);')
|
||||
g.auto_str_funcs.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${def_arg}, int indent_count) {')
|
||||
g.definitions.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${def_arg}, ${ast.int_type_name} indent_count);')
|
||||
g.auto_str_funcs.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${def_arg}, ${ast.int_type_name} indent_count) {')
|
||||
g.auto_str_funcs.writeln('\tstrings__Builder sb = strings__new_builder(2 + ${info.size} * 10);')
|
||||
g.auto_str_funcs.writeln('\tstrings__Builder_write_string(&sb, _S("["));')
|
||||
g.auto_str_funcs.writeln('\tfor (int i = 0; i < ${info.size}; ++i) {')
|
||||
g.auto_str_funcs.writeln('\tfor (${ast.int_type_name} i = 0; i < ${info.size}; ++i) {')
|
||||
if sym.kind == .function {
|
||||
g.auto_str_funcs.writeln('\t\tstring x = ${elem_str_fn_name}();')
|
||||
g.auto_str_funcs.writeln('\t\tstrings__Builder_write_string(&sb, x);')
|
||||
|
@ -832,12 +818,12 @@ fn (mut g Gen) gen_str_for_map(info ast.Map, styp string, str_fn_name string) {
|
|||
|
||||
g.definitions.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} m);')
|
||||
g.auto_str_funcs.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} m) { return indent_${str_fn_name}(m, 0);}')
|
||||
g.definitions.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} m, int indent_count);')
|
||||
g.auto_str_funcs.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} m, int indent_count) { /* gen_str_for_map */')
|
||||
g.definitions.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} m, ${ast.int_type_name} indent_count);')
|
||||
g.auto_str_funcs.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} m, ${ast.int_type_name} indent_count) { /* gen_str_for_map */')
|
||||
g.auto_str_funcs.writeln('\tstrings__Builder sb = strings__new_builder(2 + m.key_values.len * 10);')
|
||||
g.auto_str_funcs.writeln('\tstrings__Builder_write_string(&sb, _S("{"));')
|
||||
g.auto_str_funcs.writeln('\tbool is_first = true;')
|
||||
g.auto_str_funcs.writeln('\tfor (int i = 0; i < m.key_values.len; ++i) {')
|
||||
g.auto_str_funcs.writeln('\tfor (${ast.int_type_name} i = 0; i < m.key_values.len; ++i) {')
|
||||
g.auto_str_funcs.writeln('\t\tif (!DenseArray_has_index(&m.key_values, i)) { continue; }')
|
||||
g.auto_str_funcs.writeln('\t\telse if (!is_first) { strings__Builder_write_string(&sb, _S(", ")); }')
|
||||
|
||||
|
@ -967,12 +953,12 @@ fn (mut g Gen) gen_str_for_struct(info ast.Struct, lang ast.Language, styp strin
|
|||
arg_def := if is_c_struct { '${styp}* it' } else { '${styp} it' }
|
||||
g.definitions.writeln('${g.static_non_parallel}string ${str_fn_name}(${arg_def});')
|
||||
g.auto_str_funcs.writeln('${g.static_non_parallel}string ${str_fn_name}(${arg_def}) { return indent_${str_fn_name}(it, 0);}')
|
||||
g.definitions.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${arg_def}, int indent_count);')
|
||||
g.definitions.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${arg_def}, ${ast.int_type_name} indent_count);')
|
||||
mut fn_builder := strings.new_builder(512)
|
||||
defer {
|
||||
g.auto_fn_definitions << fn_builder.str()
|
||||
}
|
||||
fn_builder.writeln('string indent_${str_fn_name}(${arg_def}, int indent_count) {')
|
||||
fn_builder.writeln('string indent_${str_fn_name}(${arg_def}, ${ast.int_type_name} indent_count) {')
|
||||
old := g.reset_tmp_count()
|
||||
defer { g.tmp_count = old }
|
||||
clean_struct_v_type_name := if info.is_anon { 'struct ' } else { util.strip_main_name(typ_str) }
|
||||
|
@ -1327,7 +1313,7 @@ fn (mut g Gen) gen_enum_static_from_string(fn_name string, mod_enum_name string,
|
|||
for field_val in enum_field_vals {
|
||||
fn_builder.writeln('\tarray_push((array*)&field_vals, _MOV((i64[]){ ${field_val} }));')
|
||||
}
|
||||
fn_builder.writeln('\tfor (int i = 0; i < ${enum_field_names.len}; ++i) {')
|
||||
fn_builder.writeln('\tfor (${ast.int_type_name} i = 0; i < ${enum_field_names.len}; ++i) {')
|
||||
fn_builder.writeln('\t\tif (fast_string_eq(name, (*(string*)array_get(field_names, i)))) {')
|
||||
fn_builder.writeln('\t\t\texists = true;')
|
||||
fn_builder.writeln('\t\t\tinx = i;')
|
||||
|
|
|
@ -1165,7 +1165,7 @@ pub fn (mut g Gen) write_typeof_functions() {
|
|||
g.writeln('\t}')
|
||||
}
|
||||
g.writeln2('}', '')
|
||||
g.writeln('${static_prefix}int v_typeof_sumtype_idx_${sym.cname}(int sidx) {')
|
||||
g.writeln('${static_prefix}${ast.int_type_name} v_typeof_sumtype_idx_${sym.cname}(int sidx) {')
|
||||
if g.pref.build_mode == .build_module {
|
||||
g.writeln('\t\tif( sidx == _v_type_idx_${sym.cname}() ) return ${int(ityp)};')
|
||||
for v in sum_info.variants {
|
||||
|
@ -1219,10 +1219,10 @@ pub fn (mut g Gen) write_typeof_functions() {
|
|||
g.writeln('\tif (sidx == _${sym.cname}_${sub_sym.cname}_index) return "${util.strip_main_name(sub_sym.name)}";')
|
||||
}
|
||||
g.writeln2('\treturn "unknown ${util.strip_main_name(sym.name)}";', '}')
|
||||
g.definitions.writeln('int v_typeof_interface_idx_${sym.cname}(int sidx);')
|
||||
g.writeln2('', 'int v_typeof_interface_idx_${sym.cname}(int sidx) {')
|
||||
g.definitions.writeln('${ast.int_type_name} v_typeof_interface_idx_${sym.cname}(int sidx);')
|
||||
g.writeln2('', '${ast.int_type_name} v_typeof_interface_idx_${sym.cname}(int sidx) {')
|
||||
if g.pref.parallel_cc {
|
||||
g.extern_out.writeln('extern int v_typeof_interface_idx_${sym.cname}(int sidx);')
|
||||
g.extern_out.writeln('extern ${ast.int_type_name} v_typeof_interface_idx_${sym.cname}(int sidx);')
|
||||
}
|
||||
for t in inter_info.types {
|
||||
sub_sym := g.table.sym(ast.mktyp(t))
|
||||
|
@ -1267,14 +1267,6 @@ fn (mut g Gen) base_type(_t ast.Type) string {
|
|||
return 'u64'
|
||||
}
|
||||
}
|
||||
/*
|
||||
// On 64 bit systems int is an i64
|
||||
$if amd64 || arm64 {
|
||||
if g.pref.use_64_int && t == ast.int_type {
|
||||
return 'i64'
|
||||
}
|
||||
}
|
||||
*/
|
||||
share := t.share()
|
||||
mut styp := if share == .atomic_t { t.atomic_typename() } else { g.cc_type(t, true) }
|
||||
if t.has_flag(.shared_f) {
|
||||
|
@ -1504,7 +1496,7 @@ fn (mut g Gen) write_shareds() {
|
|||
g.shared_types.writeln('\t${mtx_typ} mtx;')
|
||||
g.shared_types.writeln('\t${base} val;')
|
||||
g.shared_types.writeln('};')
|
||||
g.shared_functions.writeln('static inline voidptr __dup${sh_typ}(voidptr src, int sz) {')
|
||||
g.shared_functions.writeln('static inline voidptr __dup${sh_typ}(voidptr src, ${ast.int_type_name} sz) {')
|
||||
g.shared_functions.writeln('\t${sh_typ}* dest = memdup(src, sz);')
|
||||
g.shared_functions.writeln('\tsync__RwMutex_init(&dest->mtx);')
|
||||
g.shared_functions.writeln('\treturn dest;')
|
||||
|
@ -1553,7 +1545,7 @@ fn (mut g Gen) register_thread_array_wait_call(eltyp string) string {
|
|||
g.waiter_fn_definitions.writeln('void ${fn_name}(${thread_arr_typ} a);')
|
||||
g.gowrappers.writeln('
|
||||
void ${fn_name}(${thread_arr_typ} a) {
|
||||
for (int i = 0; i < a.len; ++i) {
|
||||
for (${ast.int_type_name} i = 0; i < a.len; ++i) {
|
||||
${thread_typ} t = ((${thread_typ}*)a.data)[i];
|
||||
if (t == 0) continue;
|
||||
__v_thread_wait(t);
|
||||
|
@ -1564,7 +1556,7 @@ void ${fn_name}(${thread_arr_typ} a) {
|
|||
g.gowrappers.writeln('
|
||||
${ret_typ} ${fn_name}(${thread_arr_typ} a) {
|
||||
${ret_typ} res = __new_array_with_default(a.len, a.len, sizeof(${eltyp}), 0);
|
||||
for (int i = 0; i < a.len; ++i) {
|
||||
for (${ast.int_type_name} i = 0; i < a.len; ++i) {
|
||||
${thread_typ} t = ((${thread_typ}*)a.data)[i];')
|
||||
if g.pref.os == .windows {
|
||||
g.gowrappers.writeln('\t\tif (t.handle == 0) continue;')
|
||||
|
@ -1601,7 +1593,7 @@ fn (mut g Gen) register_thread_fixed_array_wait_call(node ast.CallExpr, eltyp st
|
|||
g.waiter_fn_definitions.writeln('void ${fn_name}(${thread_arr_typ} a);')
|
||||
g.gowrappers.writeln('
|
||||
void ${fn_name}(${thread_arr_typ} a) {
|
||||
for (int i = 0; i < ${len}; ++i) {
|
||||
for (${ast.int_type_name} i = 0; i < ${len}; ++i) {
|
||||
${thread_typ} t = ((${thread_typ}*)a)[i];
|
||||
if (t == 0) continue;
|
||||
__v_thread_wait(t);
|
||||
|
@ -1612,7 +1604,7 @@ void ${fn_name}(${thread_arr_typ} a) {
|
|||
g.gowrappers.writeln('
|
||||
${ret_typ} ${fn_name}(${thread_arr_typ} a) {
|
||||
${ret_typ} res = __new_array_with_default(${len}, ${len}, sizeof(${eltyp}), 0);
|
||||
for (int i = 0; i < ${len}; ++i) {
|
||||
for (${ast.int_type_name} i = 0; i < ${len}; ++i) {
|
||||
${thread_typ} t = ((${thread_typ}*)a)[i];')
|
||||
if g.pref.os == .windows {
|
||||
g.gowrappers.writeln('\t\tif (t.handle == 0) continue;')
|
||||
|
@ -2152,7 +2144,7 @@ fn (mut g Gen) stmts_with_tmp_var(stmts []ast.Stmt, tmp_var string) bool {
|
|||
mut styp := g.base_type(stmt.typ)
|
||||
$if tinyc && x32 && windows {
|
||||
if stmt.typ == ast.int_literal_type {
|
||||
styp = 'int'
|
||||
styp = ast.int_type_name
|
||||
} else if stmt.typ == ast.float_literal_type {
|
||||
styp = 'f64'
|
||||
}
|
||||
|
@ -2210,7 +2202,7 @@ fn (mut g Gen) stmts_with_tmp_var(stmts []ast.Stmt, tmp_var string) bool {
|
|||
mut styp := g.base_type(stmt.typ)
|
||||
$if tinyc && x32 && windows {
|
||||
if stmt.typ == ast.int_literal_type {
|
||||
styp = 'int'
|
||||
styp = ast.int_type_name
|
||||
} else if stmt.typ == ast.float_literal_type {
|
||||
styp = 'f64'
|
||||
}
|
||||
|
@ -4953,7 +4945,8 @@ fn (mut g Gen) lock_expr(node ast.LockExpr) {
|
|||
} else {
|
||||
g.writeln('__sort_ptr(_arr_${mtxs}, _isrlck_${mtxs}, ${node.lockeds.len});')
|
||||
}
|
||||
g.writeln2('for (int ${mtxs}=0; ${mtxs}<${node.lockeds.len}; ${mtxs}++) {', '\tif (${mtxs} && _arr_${mtxs}[${mtxs}] == _arr_${mtxs}[${mtxs}-1]) continue;')
|
||||
g.writeln2('for (${ast.int_type_name} ${mtxs}=0; ${mtxs}<${node.lockeds.len}; ${mtxs}++) {',
|
||||
'\tif (${mtxs} && _arr_${mtxs}[${mtxs}] == _arr_${mtxs}[${mtxs}-1]) continue;')
|
||||
g.writeln2('\tif (_isrlck_${mtxs}[${mtxs}])', '\t\tsync__RwMutex_rlock((sync__RwMutex*)_arr_${mtxs}[${mtxs}]);')
|
||||
g.writeln2('\telse', '\t\tsync__RwMutex_lock((sync__RwMutex*)_arr_${mtxs}[${mtxs}]);')
|
||||
g.writeln('}')
|
||||
|
@ -4983,7 +4976,7 @@ fn (mut g Gen) unlock_locks() {
|
|||
g.expr(g.cur_lock.lockeds[0])
|
||||
g.write('->mtx);')
|
||||
} else {
|
||||
g.writeln('for (int ${g.mtxs}=${g.cur_lock.lockeds.len - 1}; ${g.mtxs}>=0; ${g.mtxs}--) {')
|
||||
g.writeln('for (${ast.int_type_name} ${g.mtxs}=${g.cur_lock.lockeds.len - 1}; ${g.mtxs}>=0; ${g.mtxs}--) {')
|
||||
g.writeln('\tif (${g.mtxs} && _arr_${g.mtxs}[${g.mtxs}] == _arr_${g.mtxs}[${g.mtxs}-1]) continue;')
|
||||
g.writeln('\tif (_isrlck_${g.mtxs}[${g.mtxs}])')
|
||||
g.writeln('\t\tsync__RwMutex_runlock((sync__RwMutex*)_arr_${g.mtxs}[${g.mtxs}]);')
|
||||
|
@ -8519,3 +8512,11 @@ fn (mut g Gen) check_noscan(elem_typ ast.Type) string {
|
|||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
// vint2int rename `_vint_t` to `int`
|
||||
fn vint2int(name string) string {
|
||||
if name == ast.int_type_name {
|
||||
return 'int'
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
module c
|
||||
|
||||
import v.ast
|
||||
|
||||
// Note: @@@ here serve as placeholders.
|
||||
// They will be replaced with correct strings
|
||||
// for each constant, during C code generation.
|
||||
|
@ -17,7 +19,7 @@ struct __shared_map {
|
|||
sync__RwMutex mtx;
|
||||
map val;
|
||||
};
|
||||
static inline voidptr __dup_shared_map(voidptr src, int sz) {
|
||||
static inline voidptr __dup_shared_map(voidptr src, ${ast.int_type_name} sz) {
|
||||
__shared_map* dest = memdup(src, sz);
|
||||
sync__RwMutex_init(&dest->mtx);
|
||||
return dest;
|
||||
|
@ -27,16 +29,16 @@ struct __shared_array {
|
|||
sync__RwMutex mtx;
|
||||
array val;
|
||||
};
|
||||
static inline voidptr __dup_shared_array(voidptr src, int sz) {
|
||||
static inline voidptr __dup_shared_array(voidptr src, ${ast.int_type_name} sz) {
|
||||
__shared_array* dest = memdup(src, sz);
|
||||
sync__RwMutex_init(&dest->mtx);
|
||||
return dest;
|
||||
}
|
||||
static inline void __sort_ptr(uintptr_t a[], bool b[], int l) {
|
||||
for (int i=1; i<l; i++) {
|
||||
static inline void __sort_ptr(uintptr_t a[], bool b[], ${ast.int_type_name} l) {
|
||||
for (${ast.int_type_name} i=1; i<l; i++) {
|
||||
uintptr_t ins = a[i];
|
||||
bool insb = b[i];
|
||||
int j = i;
|
||||
${ast.int_type_name} j = i;
|
||||
while(j>0 && a[j-1] > ins) {
|
||||
a[j] = a[j-1];
|
||||
b[j] = b[j-1];
|
||||
|
@ -476,9 +478,9 @@ void v_free(voidptr ptr);
|
|||
const c_builtin_types = '
|
||||
//================================== builtin types ================================*/
|
||||
#if defined(__x86_64__) || defined(_M_AMD64) || defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64) || (defined(__riscv_xlen) && __riscv_xlen == 64) || defined(__s390x__) || (defined(__powerpc64__) && defined(__LITTLE_ENDIAN__)) || defined(__loongarch64)
|
||||
typedef int64_t vint_t;
|
||||
typedef int64_t _vint_t;
|
||||
#else
|
||||
typedef int32_t vint_t;
|
||||
typedef int32_t _vint_t;
|
||||
#endif
|
||||
typedef int64_t i64;
|
||||
typedef int16_t i16;
|
||||
|
|
|
@ -292,7 +292,7 @@ fn (mut g Gen) const_decl_simple_define(mod string, name string, val string) {
|
|||
if g.pref.translated {
|
||||
g.global_const_defs[util.no_dots(name)] = GlobalConstDef{
|
||||
mod: mod
|
||||
def: 'const int ${x} = ${val};'
|
||||
def: 'const ${ast.int_type_name} ${x} = ${val};'
|
||||
order: -1
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -86,10 +86,10 @@ fn (mut g Gen) write_coverage_stats() {
|
|||
fmeta.writeln('}') or { continue }
|
||||
fmeta.close()
|
||||
}
|
||||
g.cov_declarations.writeln('\tlong int secs = 0;')
|
||||
g.cov_declarations.writeln('\tlong int nsecs = 0;')
|
||||
g.cov_declarations.writeln('\tint secs = 0;')
|
||||
g.cov_declarations.writeln('\tint nsecs = 0;')
|
||||
g.cov_declarations.writeln('\t#if defined(_WIN32)')
|
||||
g.cov_declarations.writeln('\tlong int ticks_passed = GetTickCount();')
|
||||
g.cov_declarations.writeln('\tint ticks_passed = GetTickCount();')
|
||||
g.cov_declarations.writeln('\nsecs = ticks_passed / 1000;')
|
||||
g.cov_declarations.writeln('\nnsecs = (ticks_passed % 1000) * 1000000;')
|
||||
g.cov_declarations.writeln('\t#endif')
|
||||
|
@ -109,7 +109,7 @@ fn (mut g Gen) write_coverage_stats() {
|
|||
for k, cov in g.coverage_files {
|
||||
nr_points := cov.points.len
|
||||
g.cov_declarations.writeln('\t{')
|
||||
g.cov_declarations.writeln('\t\tfor (int i = 0; i < ${nr_points}; ++i) {')
|
||||
g.cov_declarations.writeln('\t\tfor (${ast.int_type_name} i = 0; i < ${nr_points}; ++i) {')
|
||||
g.cov_declarations.writeln('\t\t\tif (_v_cov[_v_cov_file_offset_${k}+i]) {')
|
||||
g.cov_declarations.writeln("\t\t\t\tfprintf(fp, \"%s,%d,%ld\\n\", \"${cov.fhash}\", i, _v_cov[_v_cov_file_offset_${k}+i]);")
|
||||
g.cov_declarations.writeln('\t\t\t}')
|
||||
|
|
|
@ -177,14 +177,15 @@ fn (mut g Gen) dump_expr_definitions() {
|
|||
}
|
||||
dump_already_generated_fns[dump_fn_name] = true
|
||||
|
||||
dump_fn_defs.writeln('${str_dumparg_ret_type} ${dump_fn_name}(string fpath, int line, string sexpr, ${str_dumparg_type} dump_arg);')
|
||||
if g.writeln_fn_header('${str_dumparg_ret_type} ${dump_fn_name}(string fpath, int line, string sexpr, ${str_dumparg_type} dump_arg)', mut
|
||||
dump_fn_defs.writeln('${str_dumparg_ret_type} ${dump_fn_name}(string fpath, ${ast.int_type_name} line, string sexpr, ${str_dumparg_type} dump_arg);')
|
||||
if g.writeln_fn_header('${str_dumparg_ret_type} ${dump_fn_name}(string fpath, ${ast.int_type_name} line, string sexpr, ${str_dumparg_type} dump_arg)', mut
|
||||
dump_fns)
|
||||
{
|
||||
continue
|
||||
}
|
||||
mut surrounder := util.new_surrounder(3)
|
||||
surrounder.add('\tstring sline = int_str(line);', '\tstring_free(&sline);')
|
||||
int_str := g.get_str_fn(ast.int_type)
|
||||
surrounder.add('\tstring sline = ${int_str}(line);', '\tstring_free(&sline);')
|
||||
if dump_sym.kind == .function && !is_option {
|
||||
surrounder.add('\tstring value = ${to_string_fn_name}();', '\tstring_free(&value);')
|
||||
} else if dump_sym.kind == .none {
|
||||
|
|
|
@ -246,7 +246,7 @@ fn (mut g Gen) for_in_stmt(node_ ast.ForInStmt) {
|
|||
} else {
|
||||
'${cond_var}${op_field}len'
|
||||
}
|
||||
g.writeln('for (int ${i} = 0; ${i} < ${cond_expr}; ++${i}) {')
|
||||
g.writeln('for (${ast.int_type_name} ${i} = 0; ${i} < ${cond_expr}; ++${i}) {')
|
||||
if node.val_var != '_' {
|
||||
if mut val_sym.info is ast.FnType {
|
||||
g.write('\t')
|
||||
|
@ -308,7 +308,7 @@ fn (mut g Gen) for_in_stmt(node_ ast.ForInStmt) {
|
|||
idx := if node.key_var in ['', '_'] { g.new_tmp_var() } else { node.key_var }
|
||||
cond_sym := g.table.final_sym(node.cond_type)
|
||||
info := cond_sym.info as ast.ArrayFixed
|
||||
g.writeln('for (int ${idx} = 0; ${idx} != ${info.size}; ++${idx}) {')
|
||||
g.writeln('for (${ast.int_type_name} ${idx} = 0; ${idx} != ${info.size}; ++${idx}) {')
|
||||
if node.val_var != '_' {
|
||||
val_sym := g.table.sym(node.val_type)
|
||||
is_fixed_array := val_sym.kind == .array_fixed && !node.val_is_mut
|
||||
|
@ -357,12 +357,12 @@ fn (mut g Gen) for_in_stmt(node_ ast.ForInStmt) {
|
|||
idx := g.new_tmp_var()
|
||||
map_len := g.new_tmp_var()
|
||||
g.empty_line = true
|
||||
g.writeln('int ${map_len} = ${cond_var}${dot_or_ptr}key_values.len;')
|
||||
g.writeln('for (int ${idx} = 0; ${idx} < ${map_len}; ++${idx} ) {')
|
||||
g.writeln('${ast.int_type_name} ${map_len} = ${cond_var}${dot_or_ptr}key_values.len;')
|
||||
g.writeln('for (${ast.int_type_name} ${idx} = 0; ${idx} < ${map_len}; ++${idx} ) {')
|
||||
// TODO: don't have this check when the map has no deleted elements
|
||||
g.indent++
|
||||
diff := g.new_tmp_var()
|
||||
g.writeln('int ${diff} = ${cond_var}${dot_or_ptr}key_values.len - ${map_len};')
|
||||
g.writeln('${ast.int_type_name} ${diff} = ${cond_var}${dot_or_ptr}key_values.len - ${map_len};')
|
||||
g.writeln('${map_len} = ${cond_var}${dot_or_ptr}key_values.len;')
|
||||
// TODO: optimize this
|
||||
g.writeln('if (${diff} < 0) {')
|
||||
|
@ -413,7 +413,7 @@ fn (mut g Gen) for_in_stmt(node_ ast.ForInStmt) {
|
|||
}
|
||||
field_accessor := if node.cond_type.is_ptr() { '->' } else { '.' }
|
||||
i := if node.key_var in ['', '_'] { g.new_tmp_var() } else { node.key_var }
|
||||
g.write('for (int ${i} = 0; ${i} < ')
|
||||
g.write('for (${ast.int_type_name} ${i} = 0; ${i} < ')
|
||||
g.expr(cond)
|
||||
g.writeln('${field_accessor}len; ++${i}) {')
|
||||
if node.val_var != '_' {
|
||||
|
@ -519,7 +519,7 @@ fn (mut g Gen) for_in_stmt(node_ ast.ForInStmt) {
|
|||
|
||||
if node.kind == .map {
|
||||
// diff := g.new_tmp_var()
|
||||
// g.writeln('int $diff = $cond_var${arw_or_pt}key_values.len - $map_len;')
|
||||
// g.writeln('${ast.int_type_name} $diff = $cond_var${arw_or_pt}key_values.len - $map_len;')
|
||||
// g.writeln('if ($diff < 0) {')
|
||||
// g.writeln('\t$idx = -1;')
|
||||
// g.writeln('\t$map_len = $cond_var${arw_or_pt}key_values.len;')
|
||||
|
|
|
@ -87,12 +87,12 @@ ${dec_fn_dec} {
|
|||
if (!root) {
|
||||
const char *error_ptr = cJSON_GetErrorPtr();
|
||||
if (error_ptr != NULL) {
|
||||
const int error_pos = (int)cJSON_GetErrorPos();
|
||||
int maxcontext_chars = 30;
|
||||
const ${ast.int_type_name} error_pos = (${ast.int_type_name})cJSON_GetErrorPos();
|
||||
${ast.int_type_name} maxcontext_chars = 30;
|
||||
byte *buf = vcalloc_noscan(maxcontext_chars + 10);
|
||||
if (error_pos > 0) {
|
||||
int backlines = 1;
|
||||
int backchars = error_pos < maxcontext_chars-7 ? (int)error_pos : maxcontext_chars-7 ;
|
||||
${ast.int_type_name} backlines = 1;
|
||||
${ast.int_type_name} backchars = error_pos < maxcontext_chars-7 ? (${ast.int_type_name})error_pos : maxcontext_chars-7 ;
|
||||
char *prevline_ptr = (char*)error_ptr;
|
||||
while(backchars--){
|
||||
char prevc = *(prevline_ptr - 1);
|
||||
|
@ -107,7 +107,7 @@ ${dec_fn_dec} {
|
|||
break; // stop at `{` too
|
||||
}
|
||||
}
|
||||
int maxchars = vstrlen_char(prevline_ptr);
|
||||
${ast.int_type_name} maxchars = vstrlen_char(prevline_ptr);
|
||||
vmemcpy(buf, prevline_ptr, (maxchars < maxcontext_chars ? maxchars : maxcontext_chars));
|
||||
}
|
||||
string msg;
|
||||
|
@ -599,8 +599,8 @@ fn (mut g Gen) gen_sumtype_enc_dec(utyp ast.Type, sym ast.TypeSymbol, mut enc st
|
|||
dec.writeln('\t\t}')
|
||||
}
|
||||
|
||||
if var_t in ['i64', 'int', 'i8', 'u64', 'u32', 'u16', 'byte', 'u8', 'rune', 'f64',
|
||||
'f32'] {
|
||||
if var_t in ['i64', ast.int_type_name, 'int', 'i8', 'u64', 'u32', 'u16', 'byte',
|
||||
'u8', 'rune', 'f64', 'f32'] {
|
||||
if number_is_met {
|
||||
var_num := var_t.replace('__', '.')
|
||||
last_num := last_number_type.replace('__', '.')
|
||||
|
@ -690,7 +690,7 @@ fn (mut g Gen) gen_struct_enc_dec(utyp ast.Type, type_info ast.TypeInfo, styp st
|
|||
if is_skip {
|
||||
continue
|
||||
}
|
||||
field_type := g.styp(field.typ)
|
||||
field_type := vint2int(g.styp(field.typ))
|
||||
field_sym := g.table.sym(field.typ)
|
||||
op := if utyp.is_ptr() { '->' } else { '.' }
|
||||
embed_member := if embed_prefix.len > 0 { '.${embed_prefix}' } else { '' }
|
||||
|
@ -1018,6 +1018,7 @@ fn js_enc_name(typ string) string {
|
|||
if typ == 'i32' {
|
||||
suffix = typ.replace('i32', 'int')
|
||||
}
|
||||
suffix = vint2int(suffix)
|
||||
name := 'json__encode_${suffix}'
|
||||
return util.no_dots(name)
|
||||
}
|
||||
|
@ -1027,13 +1028,14 @@ fn js_dec_name(typ string) string {
|
|||
if typ == 'i32' {
|
||||
suffix = typ.replace('i32', 'int')
|
||||
}
|
||||
suffix = vint2int(suffix)
|
||||
name := 'json__decode_${suffix}'
|
||||
return util.no_dots(name)
|
||||
}
|
||||
|
||||
fn is_js_prim(typ string) bool {
|
||||
return typ in ['int', 'rune', 'string', 'bool', 'f32', 'f64', 'i8', 'i16', 'i32', 'i64', 'u8',
|
||||
'u16', 'u32', 'u64', 'byte']
|
||||
return typ in [ast.int_type_name, 'int', 'rune', 'string', 'bool', 'f32', 'f64', 'i8', 'i16',
|
||||
'i32', 'i64', 'u8', 'u16', 'u32', 'u64', 'byte']
|
||||
}
|
||||
|
||||
fn (mut g Gen) decode_array(utyp ast.Type, value_type ast.Type, fixed_array_size int, ret_styp string) string {
|
||||
|
@ -1049,7 +1051,7 @@ fn (mut g Gen) decode_array(utyp ast.Type, value_type ast.Type, fixed_array_size
|
|||
is_array_fixed_val := g.table.final_sym(value_type).kind == .array_fixed
|
||||
if utyp.has_flag(.option) {
|
||||
if fixed_array_size > -1 {
|
||||
fixed_array_idx += 'int fixed_array_idx = 0;'
|
||||
fixed_array_idx += '${ast.int_type_name} fixed_array_idx = 0;'
|
||||
array_element_assign += '((${styp}*)res.data)[fixed_array_idx] = val;'
|
||||
fixed_array_idx_increment += 'fixed_array_idx++; res.state = 0;'
|
||||
} else {
|
||||
|
@ -1059,11 +1061,11 @@ fn (mut g Gen) decode_array(utyp ast.Type, value_type ast.Type, fixed_array_size
|
|||
}
|
||||
} else {
|
||||
if is_array_fixed_val {
|
||||
fixed_array_idx += 'int fixed_array_idx = 0;'
|
||||
fixed_array_idx += '${ast.int_type_name} fixed_array_idx = 0;'
|
||||
array_element_assign += 'memcpy(res[fixed_array_idx], val, sizeof(${styp}));'
|
||||
fixed_array_idx_increment += 'fixed_array_idx++;'
|
||||
} else if fixed_array_size > -1 {
|
||||
fixed_array_idx += 'int fixed_array_idx = 0;'
|
||||
fixed_array_idx += '${ast.int_type_name} fixed_array_idx = 0;'
|
||||
array_element_assign += 'res[fixed_array_idx] = val;'
|
||||
fixed_array_idx_increment += 'fixed_array_idx++;'
|
||||
} else {
|
||||
|
@ -1137,7 +1139,7 @@ fn (mut g Gen) encode_array(utyp ast.Type, value_type ast.Type, fixed_array_size
|
|||
|
||||
return '
|
||||
o = cJSON_CreateArray();
|
||||
for (int i = 0; i < ${size_str}; i++){
|
||||
for (${ast.int_type_name} i = 0; i < ${size_str}; i++){
|
||||
cJSON_AddItemToArray(o, ${fn_name}( (${data_str})[i] ));
|
||||
}
|
||||
'
|
||||
|
@ -1212,7 +1214,7 @@ fn (mut g Gen) encode_map(utyp ast.Type, key_type ast.Type, value_type ast.Type)
|
|||
return '
|
||||
o = cJSON_CreateObject();
|
||||
Array_${styp} ${keys_tmp} = map_keys((map*)val.data);
|
||||
for (int i = 0; i < ${keys_tmp}.len; ++i) {
|
||||
for (${ast.int_type_name} i = 0; i < ${keys_tmp}.len; ++i) {
|
||||
${key}
|
||||
cJSON_AddItemToObject(o, (char*) key.str, ${fn_name_v} ( *(${styp_v}*) map_get((map*)val.data, &key, &(${styp_v}[]) { ${zero} } ) ) );
|
||||
}
|
||||
|
@ -1222,7 +1224,7 @@ fn (mut g Gen) encode_map(utyp ast.Type, key_type ast.Type, value_type ast.Type)
|
|||
return '
|
||||
o = cJSON_CreateObject();
|
||||
Array_${styp} ${keys_tmp} = map_keys(&val);
|
||||
for (int i = 0; i < ${keys_tmp}.len; ++i) {
|
||||
for (${ast.int_type_name} i = 0; i < ${keys_tmp}.len; ++i) {
|
||||
${key}
|
||||
cJSON_AddItemToObject(o, (char*) key.str, ${fn_name_v} ( *(${styp_v}*) map_get(&val, &key, &(${styp_v}[]) { ${zero} } ) ) );
|
||||
}
|
||||
|
|
|
@ -292,7 +292,7 @@ fn (mut g Gen) write_orm_update(node &ast.SqlStmtLine, table_name string, connec
|
|||
g.writeln('.kinds = __new_array_with_default_noscan(0, 0, sizeof(orm__OperationKind), 0),')
|
||||
g.writeln('.is_and = __new_array_with_default_noscan(0, 0, sizeof(bool), 0),')
|
||||
g.writeln('.types = __new_array_with_default_noscan(0, 0, sizeof(${ast.int_type_name}), 0),')
|
||||
g.writeln('.parentheses = __new_array_with_default_noscan(0, 0, sizeof(Array_int), 0),')
|
||||
g.writeln('.parentheses = __new_array_with_default_noscan(0, 0, sizeof(Array_${ast.int_type_name}), 0),')
|
||||
|
||||
if node.updated_columns.len > 0 {
|
||||
g.writeln('.fields = new_array_from_c_array(${node.updated_columns.len}, ${node.updated_columns.len}, sizeof(string),')
|
||||
|
@ -481,6 +481,7 @@ fn (mut g Gen) write_orm_insert_with_last_ids(node ast.SqlStmtLine, connection_v
|
|||
} else if sym.kind == .enum {
|
||||
typ = g.table.sym(final_field_typ).cname
|
||||
}
|
||||
typ = vint2int(typ)
|
||||
var := '${node.object_var}${member_access_type}${c_name(field.name)}'
|
||||
if final_field_typ.has_flag(.option) {
|
||||
g.writeln('${var}.state == 2? _const_orm__null_primitive : orm__${typ}_to_primitive(*(${ctyp}*)(${var}.data)),')
|
||||
|
@ -499,11 +500,11 @@ fn (mut g Gen) write_orm_insert_with_last_ids(node ast.SqlStmtLine, connection_v
|
|||
}
|
||||
g.indent--
|
||||
g.writeln('),')
|
||||
g.writeln('.types = __new_array_with_default_noscan(0, 0, sizeof(${ast.int_type_name}), 0),')
|
||||
g.writeln('.types = __new_array_with_default_noscan(0, 0, sizeof(int), 0),')
|
||||
if auto_fields.len > 0 {
|
||||
g.writeln('.auto_fields = new_array_from_c_array(${auto_fields.len}, ${auto_fields.len}, sizeof(${ast.int_type_name}),')
|
||||
g.indent++
|
||||
g.write('_MOV((int[${auto_fields.len}]){')
|
||||
g.write('_MOV((${ast.int_type_name}[${auto_fields.len}]){')
|
||||
for i in auto_fields {
|
||||
g.write(' ${i},')
|
||||
}
|
||||
|
@ -533,6 +534,7 @@ fn (mut g Gen) write_orm_insert_with_last_ids(node ast.SqlStmtLine, connection_v
|
|||
if typ == 'time__Time' {
|
||||
typ = 'time'
|
||||
}
|
||||
typ = vint2int(typ)
|
||||
g.writeln('orm__Primitive ${id_name} = orm__${typ}_to_primitive(${node.object_var}${member_access_type}${c_name(primary_field.name)});')
|
||||
}
|
||||
for i, mut arr in arrs {
|
||||
|
@ -540,9 +542,9 @@ fn (mut g Gen) write_orm_insert_with_last_ids(node ast.SqlStmtLine, connection_v
|
|||
ctyp := g.styp(arr.table_expr.typ)
|
||||
is_option := opt_fields.contains(i)
|
||||
if is_option {
|
||||
g.writeln('for (int ${idx} = 0; ${node.object_var}${member_access_type}${arr.object_var}.state != 2 && ${idx} < (*(Array_${ctyp}*)${node.object_var}${member_access_type}${arr.object_var}.data).len; ${idx}++) {')
|
||||
g.writeln('for (${ast.int_type_name} ${idx} = 0; ${node.object_var}${member_access_type}${arr.object_var}.state != 2 && ${idx} < (*(Array_${ctyp}*)${node.object_var}${member_access_type}${arr.object_var}.data).len; ${idx}++) {')
|
||||
} else {
|
||||
g.writeln('for (int ${idx} = 0; ${idx} < ${node.object_var}${member_access_type}${arr.object_var}.len; ${idx}++) {')
|
||||
g.writeln('for (${ast.int_type_name} ${idx} = 0; ${idx} < ${node.object_var}${member_access_type}${arr.object_var}.len; ${idx}++) {')
|
||||
}
|
||||
g.indent++
|
||||
last_ids := g.new_tmp_var()
|
||||
|
@ -680,6 +682,7 @@ fn (mut g Gen) write_orm_primitive(t ast.Type, expr ast.Expr) {
|
|||
} else if g.table.final_sym(t).kind == .array {
|
||||
typ = g.table.sym(g.table.final_type(t)).cname.to_lower()
|
||||
}
|
||||
typ = vint2int(typ)
|
||||
g.write('orm__${typ}_to_primitive(')
|
||||
if expr is ast.CallExpr {
|
||||
g.call_expr(expr)
|
||||
|
@ -741,10 +744,10 @@ fn (mut g Gen) write_orm_where(where_expr ast.Expr) {
|
|||
|
||||
g.write('.parentheses = ')
|
||||
if parentheses.len > 0 {
|
||||
g.write('new_array_from_c_array(${parentheses.len}, ${parentheses.len}, sizeof(Array_int), _MOV((Array_int[${parentheses.len}]){')
|
||||
g.write('new_array_from_c_array(${parentheses.len}, ${parentheses.len}, sizeof(Array_${ast.int_type_name}), _MOV((Array_${ast.int_type_name}[${parentheses.len}]){')
|
||||
for par in parentheses {
|
||||
if par.len > 0 {
|
||||
g.write('new_array_from_c_array(${par.len}, ${par.len}, sizeof(${ast.int_type_name}), _MOV((int[${par.len}]){')
|
||||
g.write('new_array_from_c_array(${par.len}, ${par.len}, sizeof(${ast.int_type_name}), _MOV((${ast.int_type_name}[${par.len}]){')
|
||||
for val in par {
|
||||
g.write('${val},')
|
||||
}
|
||||
|
@ -755,7 +758,7 @@ fn (mut g Gen) write_orm_where(where_expr ast.Expr) {
|
|||
}
|
||||
g.write('}))')
|
||||
} else {
|
||||
g.write('__new_array_with_default_noscan(0, 0, sizeof(Array_int), 0)')
|
||||
g.write('__new_array_with_default_noscan(0, 0, sizeof(Array_${ast.int_type_name}), 0)')
|
||||
}
|
||||
g.writeln(',')
|
||||
|
||||
|
@ -1006,7 +1009,7 @@ fn (mut g Gen) write_orm_select(node ast.SqlExpr, connection_var_name string, re
|
|||
g.indent++
|
||||
|
||||
if types.len > 0 {
|
||||
g.write('_MOV((int[${types.len}]){')
|
||||
g.write('_MOV((${ast.int_type_name}[${types.len}]){')
|
||||
for typ in types {
|
||||
g.write(' ${typ},')
|
||||
}
|
||||
|
@ -1032,7 +1035,7 @@ fn (mut g Gen) write_orm_select(node ast.SqlExpr, connection_var_name string, re
|
|||
g.writeln('.types = __new_array_with_default_noscan(0, 0, sizeof(${ast.int_type_name}), 0),')
|
||||
g.writeln('.kinds = __new_array_with_default_noscan(0, 0, sizeof(orm__OperationKind), 0),')
|
||||
g.writeln('.is_and = __new_array_with_default_noscan(0, 0, sizeof(bool), 0),')
|
||||
g.writeln('.parentheses = __new_array_with_default_noscan(0, 0, sizeof(Array_int), 0),')
|
||||
g.writeln('.parentheses = __new_array_with_default_noscan(0, 0, sizeof(Array_${ast.int_type_name}), 0),')
|
||||
if exprs.len > 0 {
|
||||
g.write('.data = new_array_from_c_array(${exprs.len}, ${exprs.len}, sizeof(orm__Primitive),')
|
||||
g.write(' _MOV((orm__Primitive[${exprs.len}]){')
|
||||
|
@ -1054,7 +1057,7 @@ fn (mut g Gen) write_orm_select(node ast.SqlExpr, connection_var_name string, re
|
|||
g.writeln('.types = __new_array_with_default_noscan(0, 0, sizeof(${ast.int_type_name}), 0),')
|
||||
g.writeln('.kinds = __new_array_with_default_noscan(0, 0, sizeof(orm__OperationKind), 0),')
|
||||
g.writeln('.is_and = __new_array_with_default_noscan(0, 0, sizeof(bool), 0),')
|
||||
g.writeln('.parentheses = __new_array_with_default_noscan(0, 0, sizeof(Array_int), 0),')
|
||||
g.writeln('.parentheses = __new_array_with_default_noscan(0, 0, sizeof(Array_${ast.int_type_name}), 0),')
|
||||
g.writeln('.data = __new_array_with_default_noscan(0, 0, sizeof(orm__Primitive), 0)')
|
||||
g.indent--
|
||||
g.writeln('}')
|
||||
|
@ -1077,11 +1080,11 @@ fn (mut g Gen) write_orm_select(node ast.SqlExpr, connection_var_name string, re
|
|||
g.writeln('Array_Array_orm__Primitive ${select_unwrapped_result_var_name} = (*(Array_Array_orm__Primitive*)${select_result_var_name}.data);')
|
||||
|
||||
if node.is_count {
|
||||
g.writeln('*(${unwrapped_c_typ}*) ${result_var}.data = *((*(orm__Primitive*) array_get((*(Array_orm__Primitive*)array_get(${select_unwrapped_result_var_name}, 0)), 0))._int);')
|
||||
g.writeln('*(${unwrapped_c_typ}*) ${result_var}.data = *((*(orm__Primitive*) array_get((*(Array_orm__Primitive*)array_get(${select_unwrapped_result_var_name}, 0)), 0))._${ast.int_type_name});')
|
||||
} else {
|
||||
tmp := g.new_tmp_var()
|
||||
idx := g.new_tmp_var()
|
||||
g.writeln('int ${idx} = 0;')
|
||||
g.writeln('${ast.int_type_name} ${idx} = 0;')
|
||||
mut typ_str := ''
|
||||
if node.is_array {
|
||||
info := g.table.sym(node.typ).array_info()
|
||||
|
|
|
@ -123,7 +123,7 @@ fn (g &Gen) gen_type_array(types []ast.Type) string {
|
|||
if types.len == 0 {
|
||||
return g.gen_empty_array(ast.int_type_name)
|
||||
}
|
||||
return 'new_array_from_c_array(${types.len},${types.len},sizeof(${ast.int_type_name}),_MOV((int[${types.len}]){${types.map(int(it).str()).join(',')}}))'
|
||||
return 'new_array_from_c_array(${types.len},${types.len},sizeof(int),_MOV((int[${types.len}]){${types.map(int(it).str()).join(',')}}))'
|
||||
}
|
||||
|
||||
// gen_string_array generates C code for []string
|
||||
|
|
|
@ -252,8 +252,6 @@ pub mut:
|
|||
warn_about_allocs bool // -warn-about-allocs warngs about every single allocation, e.g. 'hi $name'. Mostly for low level development where manual memory management is used.
|
||||
// game prototyping flags:
|
||||
div_by_zero_is_zero bool // -div-by-zero-is-zero makes so `x / 0 == 0`, i.e. eliminates the division by zero panics/segfaults
|
||||
// temp
|
||||
// use_64_int bool
|
||||
// forwards compatibility settings:
|
||||
relaxed_gcc14 bool = true // turn on the generated pragmas, that make gcc versions > 14 a lot less pedantic. The default is to have those pragmas in the generated C output, so that gcc-14 can be used on Arch etc.
|
||||
//
|
||||
|
@ -424,9 +422,6 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
|
|||
'-progress' {
|
||||
// processed by testing tools in cmd/tools/modules/testing/common.v
|
||||
}
|
||||
//'-i64' {
|
||||
// res.use_64_int = true
|
||||
//}
|
||||
'-Wimpure-v' {
|
||||
res.warn_impure_v = true
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue