Compare commits
6 Commits
c405c19168
...
3afb88c4e8
Author | SHA1 | Date |
---|---|---|
Jef Roosens | 3afb88c4e8 | |
yuyi | 798873fe44 | |
playX | a17d744e8b | |
StunxFS | 3f87f8f4b4 | |
Delyan Angelov | 01e97d75a5 | |
Delyan Angelov | a3279a1c2b |
|
@ -217,7 +217,7 @@ jobs:
|
|||
cd gitly
|
||||
../v .
|
||||
# ./gitly -ci_run
|
||||
../v -autofree .
|
||||
# ../v -autofree .
|
||||
../v -o x tests/first_run.v
|
||||
./x
|
||||
cd ..
|
||||
|
|
|
@ -30,7 +30,7 @@ pipeline:
|
|||
- export "COMMIT_HASH=$(git rev-parse --short HEAD)"
|
||||
- export "COMMIT_MSG=$(git log -1 --oneline --pretty='%s' HEAD)"
|
||||
- rm -rf vc
|
||||
- git clone --depth=1 'git@git.rustybever.be:Chewing_Bever/vc.git'
|
||||
- git clone --depth=1 'git@git.rustybever.be:vieter/vc.git'
|
||||
- rm -rf vc/v.c vc/v_win.c
|
||||
- ./v -o vc/v.c -os cross cmd/v
|
||||
- ./v -o vc/v_win.c -os windows -cc msvc cmd/v
|
||||
|
|
|
@ -5,7 +5,7 @@ TMPDIR ?= /tmp
|
|||
VROOT ?= .
|
||||
VC ?= ./vc
|
||||
V ?= ./v
|
||||
VCREPO ?= https://git.rustybever.be/Chewing_Bever/vc
|
||||
VCREPO ?= https://git.rustybever.be/vieter/vc
|
||||
TCCREPO ?= https://github.com/vlang/tccbin
|
||||
|
||||
VCFILE := v.c
|
||||
|
|
2
Makefile
2
Makefile
|
@ -7,7 +7,7 @@ LDFLAGS ?=
|
|||
|
||||
all:
|
||||
rm -rf vc/
|
||||
git clone --depth 1 --quiet https://git.rustybever.be/Chewing_Bever/vc
|
||||
git clone --depth 1 --quiet https://git.rustybever.be/vieter/vc
|
||||
$(CC) $(CFLAGS) -std=gnu11 -w -o v1 vc/v.c -lm -lexecinfo -lpthread $(LDFLAGS)
|
||||
./v1 -no-parallel -o v2 $(VFLAGS) cmd/v
|
||||
./v2 -o v $(VFLAGS) cmd/v
|
||||
|
|
|
@ -1,17 +1,11 @@
|
|||
builtin/js
|
||||
builtin/bare
|
||||
builtin/linux_bare
|
||||
builtin/wasm_bare
|
||||
dl/example
|
||||
oldgg/
|
||||
os/bare
|
||||
os2/
|
||||
net/websocket/examples
|
||||
uiold/
|
||||
v/tests/
|
||||
v/checker/tests/
|
||||
v/gen/js/tests/
|
||||
v/gen/x64/tests/
|
||||
v/gen/native/tests/
|
||||
v/gen/tests/
|
||||
v/preludes_js/
|
||||
vweb/tests
|
||||
|
|
|
@ -13,6 +13,9 @@ pub fn (mut c Checker) check_types(got ast.Type, expected ast.Type) bool {
|
|||
got_is_ptr := got.is_ptr()
|
||||
exp_is_ptr := expected.is_ptr()
|
||||
if c.pref.translated {
|
||||
if expected.is_int() && got.is_int() {
|
||||
return true
|
||||
}
|
||||
if expected == ast.byteptr_type {
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -935,6 +935,12 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
|
|||
if arg_typ == ast.int_type && param_typ_sym.kind == .enum_ {
|
||||
continue
|
||||
}
|
||||
|
||||
if (arg_typ == ast.bool_type && param.typ.is_int())
|
||||
|| (arg_typ.is_int() && param.typ == ast.bool_type) {
|
||||
continue
|
||||
}
|
||||
|
||||
// In C unsafe number casts are used all the time (e.g. `char*` where
|
||||
// `int*` is expected etc), so just allow them all.
|
||||
mut param_is_number := param.typ.is_number()
|
||||
|
@ -953,8 +959,10 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
|
|||
continue
|
||||
}
|
||||
// Allow `[32]i8` as `&i8` etc
|
||||
if (arg_typ_sym.kind == .array_fixed && param_is_number)
|
||||
|| (param_typ_sym.kind == .array_fixed && typ_is_number) {
|
||||
if (arg_typ_sym.kind == .array_fixed && (param_is_number
|
||||
|| param.typ.is_any_kind_of_pointer()))
|
||||
|| (param_typ_sym.kind == .array_fixed && (typ_is_number
|
||||
|| arg_typ.is_any_kind_of_pointer())) {
|
||||
continue
|
||||
}
|
||||
// Allow `int` as `&i8`
|
||||
|
@ -1061,13 +1069,6 @@ pub fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
|
|||
left_type := c.expr(node.left)
|
||||
c.expected_type = left_type
|
||||
mut is_generic := left_type.has_flag(.generic)
|
||||
// x is Bar<T>, x.foo() -> x.foo<T>()
|
||||
if is_generic && node.concrete_types.len == 0 {
|
||||
rec_sym := c.table.sym(left_type)
|
||||
if rec_sym.info is ast.Struct {
|
||||
node.concrete_types = rec_sym.info.generic_types
|
||||
}
|
||||
}
|
||||
node.left_type = left_type
|
||||
// Set default values for .return_type & .receiver_type too,
|
||||
// or there will be hard tRo diagnose 0 type panics in cgen.
|
||||
|
@ -1105,19 +1106,6 @@ pub fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
|
|||
// c.error('`void` type has no methods', node.left.pos())
|
||||
return ast.void_type
|
||||
}
|
||||
mut concrete_types := []ast.Type{}
|
||||
for concrete_type in node.concrete_types {
|
||||
if concrete_type.has_flag(.generic) {
|
||||
concrete_types << c.unwrap_generic(concrete_type)
|
||||
} else {
|
||||
concrete_types << concrete_type
|
||||
}
|
||||
}
|
||||
if concrete_types.len > 0 {
|
||||
if c.table.register_fn_concrete_types(node.fkey(), concrete_types) {
|
||||
c.need_recheck_generic_fns = true
|
||||
}
|
||||
}
|
||||
// TODO: remove this for actual methods, use only for compiler magic
|
||||
// FIXME: Argument count != 1 will break these
|
||||
if left_sym.kind == .array && method_name in array_builtin_methods {
|
||||
|
@ -1231,6 +1219,33 @@ pub fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
|
|||
}
|
||||
}
|
||||
if has_method {
|
||||
// x is Bar<T>, x.foo() -> x.foo<T>()
|
||||
rec_sym := c.table.sym(node.left_type)
|
||||
rec_is_generic := left_type.has_flag(.generic)
|
||||
if rec_sym.info is ast.Struct {
|
||||
if rec_is_generic && node.concrete_types.len == 0 {
|
||||
node.concrete_types = rec_sym.info.generic_types
|
||||
} else if !rec_is_generic && rec_sym.info.concrete_types.len > 0
|
||||
&& node.concrete_types.len > 0
|
||||
&& rec_sym.info.concrete_types.len + node.concrete_types.len == method.generic_names.len {
|
||||
t_concrete_types := node.concrete_types.clone()
|
||||
node.concrete_types = rec_sym.info.concrete_types
|
||||
node.concrete_types << t_concrete_types
|
||||
}
|
||||
}
|
||||
mut concrete_types := []ast.Type{}
|
||||
for concrete_type in node.concrete_types {
|
||||
if concrete_type.has_flag(.generic) {
|
||||
concrete_types << c.unwrap_generic(concrete_type)
|
||||
} else {
|
||||
concrete_types << concrete_type
|
||||
}
|
||||
}
|
||||
if concrete_types.len > 0 {
|
||||
if c.table.register_fn_concrete_types(node.fkey(), concrete_types) {
|
||||
c.need_recheck_generic_fns = true
|
||||
}
|
||||
}
|
||||
node.is_noreturn = method.is_noreturn
|
||||
node.is_ctor_new = method.is_ctor_new
|
||||
if !method.is_pub && !c.pref.is_test && method.mod != c.mod {
|
||||
|
|
|
@ -48,6 +48,7 @@ pub mut:
|
|||
inside_const bool
|
||||
is_mbranch_expr bool // match a { x...y { } }
|
||||
fn_scope &ast.Scope = voidptr(0)
|
||||
wsinfix_depth int
|
||||
}
|
||||
|
||||
pub fn fmt(file ast.File, table &ast.Table, pref &pref.Preferences, is_debug bool) string {
|
||||
|
@ -2075,7 +2076,13 @@ fn split_up_infix(infix_str string, ignore_paren bool, is_cond_infix bool) ([]st
|
|||
return conditions, penalties
|
||||
}
|
||||
|
||||
const wsinfix_depth_max = 10
|
||||
|
||||
fn (mut f Fmt) write_splitted_infix(conditions []string, penalties []int, ignore_paren bool, is_cond bool) {
|
||||
f.wsinfix_depth++
|
||||
defer {
|
||||
f.wsinfix_depth--
|
||||
}
|
||||
for i, cnd in conditions {
|
||||
c := cnd.trim_space()
|
||||
if f.line_len + c.len < fmt.max_len[penalties[i]] {
|
||||
|
@ -2086,6 +2093,11 @@ fn (mut f Fmt) write_splitted_infix(conditions []string, penalties []int, ignore
|
|||
} else {
|
||||
is_paren_expr := (c[0] == `(` || (c.len > 5 && c[3] == `(`)) && c.ends_with(')')
|
||||
final_len := ((f.indent + 1) * 4) + c.len
|
||||
if f.wsinfix_depth > fmt.wsinfix_depth_max {
|
||||
// limit indefinite recursion, by just giving up splitting:
|
||||
f.write(c)
|
||||
continue
|
||||
}
|
||||
if final_len > fmt.max_len.last() && is_paren_expr {
|
||||
conds, pens := split_up_infix(c, true, is_cond)
|
||||
f.write_splitted_infix(conds, pens, true, is_cond)
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
module main
|
||||
|
||||
struct Abc {
|
||||
pub mut:
|
||||
x int
|
||||
y int
|
||||
angle int
|
||||
}
|
||||
|
||||
fn s_adjustsoundparams(listener &Abc, source &Abc, vol &int, sep &int) int {
|
||||
approx_dist := 0
|
||||
adx := 0
|
||||
ady := 0
|
||||
angle := 0
|
||||
adx = C.abs(listener.x - source.x)
|
||||
ady = C.abs(listener.y - source.y)
|
||||
approx_dist = adx + ady - ((if adx < ady { adx } else { ady }) >> 1)
|
||||
if gamemap != 8 && approx_dist > (1200 * (1 << 16)) {
|
||||
return 0
|
||||
}
|
||||
angle = r_pointtoangle2(listener.x, listener.y, source.x, source.y)
|
||||
if angle > listener.angle {
|
||||
angle = angle - listener.angle
|
||||
} else {
|
||||
angle = angle + (4294967295 - listener.angle)
|
||||
}
|
||||
angle >>= 19
|
||||
*sep = 128 - (fixedmul((96 * (1 << 16)), finesine[angle]) >> 16)
|
||||
if approx_dist < (200 * (1 << 16)) {
|
||||
*vol = snd_SfxVolume
|
||||
} else if gamemap == 8 {
|
||||
if approx_dist > (1200 * (1 << 16)) {
|
||||
approx_dist = (1200 * (1 << 16))
|
||||
}
|
||||
*vol = 15 +((snd_SfxVolume - 15) * (((1200 * (1 << 16)) - approx_dist) >> 16)) / (((1200 * (1 << 16)) - (200 * (1 << 16))) >> 16)
|
||||
} else {
|
||||
*vol = (snd_SfxVolume * (((1200 * (1 << 16)) - approx_dist) >> 16)) / (((1200 * (1 << 16)) - (200 * (1 << 16))) >> 16)
|
||||
}
|
||||
return *vol > 0
|
||||
}
|
|
@ -352,8 +352,9 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
|
|||
if is_method && rec.typ.has_flag(.generic) {
|
||||
sym := p.table.sym(rec.typ)
|
||||
if sym.info is ast.Struct {
|
||||
rec_generic_names := sym.info.generic_types.map(p.table.sym(it).name)
|
||||
for gname in rec_generic_names {
|
||||
fn_generic_names := generic_names.clone()
|
||||
generic_names = sym.info.generic_types.map(p.table.sym(it).name)
|
||||
for gname in fn_generic_names {
|
||||
if gname !in generic_names {
|
||||
generic_names << gname
|
||||
}
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
struct Outer<T> {
|
||||
mut:
|
||||
inner Inner<T>
|
||||
}
|
||||
|
||||
struct Inner<T> {
|
||||
val T
|
||||
}
|
||||
|
||||
fn (mut i Inner<T>) next<S>(input S) f64 {
|
||||
$if S is f32 {
|
||||
return 32
|
||||
} $else {
|
||||
panic('"$S.name" is not supported')
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
fn test_generics_method_on_nested_struct() {
|
||||
mut outer := Outer<f64>{
|
||||
inner: Inner<f64>{
|
||||
val: 1.1
|
||||
}
|
||||
}
|
||||
r1 := outer.inner.next<f32>(99.0)
|
||||
println(r1)
|
||||
assert r1 == 32.0
|
||||
|
||||
r2 := outer.inner.next<f64, f32>(99.0)
|
||||
println(r2)
|
||||
assert r2 == 32.0
|
||||
|
||||
r3 := outer.inner.next(f32(99.0))
|
||||
println(r3)
|
||||
assert r3 == 32.0
|
||||
}
|
Loading…
Reference in New Issue