Skip to content

Commit eeaaff2

Browse files
committed
all: big batch4 fixes
1 parent 93e57bb commit eeaaff2

40 files changed

Lines changed: 538 additions & 163 deletions

‎cmd/tools/vcreate/vcreate_new_test.v‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// vtest retry: 3
12
import os
23
import v.vmod
34

‎cmd/tools/vtest-cleancode.v‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ const vet_folders = [
3232
'examples/term.ui',
3333
]
3434

35-
const verify_known_failing_exceptions = []string{}
35+
const verify_known_failing_exceptions = [
36+
'vlib/veb/tests/graceful_shutdown_test.v',
37+
]
3638

3739
const vfmt_verify_list = [
3840
'cmd/',
@@ -86,8 +88,10 @@ fn v_test_vetting(vargs string) ! {
8688
'${os.quoted_path(vexe)} fmt -inprocess -verify', 'fmt -inprocess -verify'
8789
}
8890
vfmt_list := util.find_all_v_files(vfmt_verify_list) or { return }
89-
exceptions := util.find_all_v_files(vfmt_known_failing_exceptions) or { return }
90-
verify_session := tsession(vargs, 'vfmt.v', fmt_cmd, fmt_args, vfmt_list, exceptions)
91+
exceptions := (util.find_all_v_files(vfmt_known_failing_exceptions) or { return }).map(os.abs_path)
92+
filtered_vfmt_list := vfmt_list.filter(os.abs_path(it) !in exceptions)
93+
verify_session := tsession(vargs, 'vfmt.v', fmt_cmd, fmt_args, filtered_vfmt_list,
94+
exceptions)
9195

9296
if vet_session.benchmark.nfail > 0 || verify_session.benchmark.nfail > 0 {
9397
eprintln('\n')

‎cmd/tools/vtest-fmt.v‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ fn v_files() []string {
3333
if tfile.starts_with('./vlib/v/cgen/tests') {
3434
continue
3535
}
36+
if tfile.ends_with('graceful_shutdown_test.v') {
37+
continue
38+
}
3639
files_that_can_be_formatted << tfile
3740
}
3841
return files_that_can_be_formatted

‎examples/wasm_codegen/add.v‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import wasm
2+
3+
fn main() {
4+
mut m := wasm.Module{}
5+
mut func := m.new_function('add', [.i32_t, .i32_t], [.i32_t])
6+
{
7+
func.local_get(0)
8+
func.local_get(1)
9+
func.add(.i32_t)
10+
}
11+
m.commit(func, true) // `export: true`
12+
print(m.compile().bytestr())
13+
}

‎examples/wasm_codegen/factorial.v‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import wasm
2+
3+
fn main() {
4+
mut m := wasm.Module{}
5+
mut fac := m.new_function('fac', [.i64_t], [.i64_t])
6+
{
7+
fac.local_get(0)
8+
fac.eqz(.i64_t)
9+
bif := fac.c_if([], [.i64_t])
10+
{
11+
fac.i64_const(1)
12+
}
13+
fac.c_else(bif)
14+
{
15+
{
16+
fac.local_get(0)
17+
}
18+
{
19+
fac.local_get(0)
20+
fac.i64_const(1)
21+
fac.sub(.i64_t)
22+
fac.call('fac')
23+
}
24+
fac.mul(.i64_t)
25+
}
26+
fac.c_end(bif)
27+
}
28+
m.commit(fac, true)
29+
print(m.compile().bytestr())
30+
31+
// v run factorial.v > a.wasm
32+
// wasmer a.wasm -i fac 5
33+
}

‎examples/wasm_codegen/functions.v‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import wasm
2+
3+
fn main() {
4+
mut m := wasm.Module{}
5+
mut pyth := m.new_function('pythagoras', [.f32_t, .f32_t], [
6+
.f32_t,
7+
])
8+
{
9+
pyth.local_get(0)
10+
pyth.local_get(0)
11+
pyth.mul(.f32_t)
12+
pyth.local_get(1)
13+
pyth.local_get(1)
14+
pyth.mul(.f32_t)
15+
pyth.add(.f32_t)
16+
pyth.sqrt(.f32_t)
17+
pyth.cast(.f32_t, true, .f64_t)
18+
}
19+
m.commit(pyth, true)
20+
mut test := m.new_function('test', [.f32_t], [.f64_t])
21+
{
22+
test.local_get(0)
23+
test.f32_const(10.0)
24+
test.call('pythagoras')
25+
test.cast(.f32_t, true, .f64_t)
26+
}
27+
m.commit(test, true)
28+
print(m.compile().bytestr())
29+
}
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
// Compiler runtime builtins needed for cross-compilation from macOS to Linux.
2+
// When cross-compiling with clang, 128-bit integer operations (e.g. in mbedtls bignum.c)
3+
// generate calls to __udivti3/__umodti3 which are normally provided by libgcc or compiler-rt.
4+
// Since the linuxroot sysroot doesn't include these libraries, we provide minimal
5+
// implementations here.
6+
7+
#ifdef __SIZEOF_INT128__
8+
9+
typedef unsigned __int128 tu_int;
10+
typedef unsigned long long du_int;
11+
12+
typedef union {
13+
tu_int all;
14+
struct {
15+
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
16+
du_int low;
17+
du_int high;
18+
#else
19+
du_int high;
20+
du_int low;
21+
#endif
22+
} s;
23+
} utwords;
24+
25+
static inline unsigned __clzdi2(du_int a) {
26+
unsigned n = 0;
27+
if (a == 0) return 64;
28+
if ((a & 0xFFFFFFFF00000000ULL) == 0) { n += 32; a <<= 32; }
29+
if ((a & 0xFFFF000000000000ULL) == 0) { n += 16; a <<= 16; }
30+
if ((a & 0xFF00000000000000ULL) == 0) { n += 8; a <<= 8; }
31+
if ((a & 0xF000000000000000ULL) == 0) { n += 4; a <<= 4; }
32+
if ((a & 0xC000000000000000ULL) == 0) { n += 2; a <<= 2; }
33+
if ((a & 0x8000000000000000ULL) == 0) { n += 1; }
34+
return n;
35+
}
36+
37+
tu_int __udivmodti4(tu_int a, tu_int b, tu_int *rem) {
38+
const unsigned n_udword_bits = sizeof(du_int) * 8;
39+
const unsigned n_utword_bits = sizeof(tu_int) * 8;
40+
utwords n, d, q, r;
41+
unsigned sr;
42+
n.all = a;
43+
d.all = b;
44+
45+
// Special cases
46+
if (n.s.high == 0) {
47+
if (d.s.high == 0) {
48+
if (rem) *rem = n.s.low % d.s.low;
49+
return n.s.low / d.s.low;
50+
}
51+
if (rem) *rem = n.s.low;
52+
return 0;
53+
}
54+
// n.s.high != 0
55+
if (d.s.low == 0) {
56+
if (d.s.high == 0) {
57+
// Division by zero (undefined behavior, just return 0)
58+
if (rem) *rem = 0;
59+
return 0;
60+
}
61+
if (n.s.low == 0) {
62+
if (rem) {
63+
r.s.high = n.s.high % d.s.high;
64+
r.s.low = 0;
65+
*rem = r.all;
66+
}
67+
return n.s.high / d.s.high;
68+
}
69+
// n.s.high != 0 && n.s.low != 0 && d.s.low == 0 && d.s.high != 0
70+
if ((d.s.high & (d.s.high - 1)) == 0) {
71+
// d is a power of 2
72+
if (rem) {
73+
r.s.low = n.s.low;
74+
r.s.high = n.s.high & (d.s.high - 1);
75+
*rem = r.all;
76+
}
77+
return n.s.high >> __clzdi2(d.s.high);
78+
}
79+
sr = __clzdi2(d.s.high) - __clzdi2(n.s.high);
80+
if (sr > n_udword_bits - 2) {
81+
if (rem) *rem = n.all;
82+
return 0;
83+
}
84+
++sr;
85+
// 1 <= sr <= n_udword_bits - 1
86+
q.s.low = 0;
87+
q.s.high = n.s.low << (n_udword_bits - sr);
88+
r.s.high = n.s.high >> sr;
89+
r.s.low = (n.s.high << (n_udword_bits - sr)) | (n.s.low >> sr);
90+
goto shift_loop;
91+
}
92+
// d.s.low != 0
93+
if (d.s.high == 0) {
94+
if ((d.s.low & (d.s.low - 1)) == 0) {
95+
if (rem) *rem = n.s.low & (d.s.low - 1);
96+
if (d.s.low == 1) return n.all;
97+
sr = __builtin_ctzll(d.s.low);
98+
q.s.high = n.s.high >> sr;
99+
q.s.low = (n.s.high << (n_udword_bits - sr)) | (n.s.low >> sr);
100+
return q.all;
101+
}
102+
sr = 1 + n_udword_bits + __clzdi2(d.s.low) - __clzdi2(n.s.high);
103+
if (sr == n_udword_bits) {
104+
q.s.low = 0;
105+
q.s.high = 0;
106+
r.s.high = 0;
107+
r.s.low = n.s.high;
108+
} else if (sr < n_udword_bits) {
109+
q.s.low = 0;
110+
q.s.high = n.s.low << (n_udword_bits - sr);
111+
r.s.high = n.s.high >> sr;
112+
r.s.low = (n.s.high << (n_udword_bits - sr)) | (n.s.low >> sr);
113+
} else {
114+
q.s.low = n.s.low << (n_utword_bits - sr);
115+
q.s.high = (n.s.high << (n_utword_bits - sr)) | (n.s.low >> (sr - n_udword_bits));
116+
r.s.high = 0;
117+
r.s.low = n.s.high >> (sr - n_udword_bits);
118+
}
119+
goto shift_loop;
120+
}
121+
// d.s.high != 0 && d.s.low != 0
122+
sr = __clzdi2(d.s.high) - __clzdi2(n.s.high);
123+
if (sr > n_udword_bits - 1) {
124+
if (rem) *rem = n.all;
125+
return 0;
126+
}
127+
++sr;
128+
q.s.low = 0;
129+
if (sr == n_udword_bits) {
130+
q.s.high = 0;
131+
r.s.high = 0;
132+
r.s.low = n.s.high;
133+
} else {
134+
r.s.high = n.s.high >> sr;
135+
r.s.low = (n.s.high << (n_udword_bits - sr)) | (n.s.low >> sr);
136+
q.s.high = n.s.low << (n_udword_bits - sr);
137+
}
138+
139+
shift_loop:
140+
// The main shift-and-subtract loop
141+
for (; sr > 0; --sr) {
142+
r.s.high = (r.s.high << 1) | (r.s.low >> (n_udword_bits - 1));
143+
r.s.low = (r.s.low << 1) | (q.s.high >> (n_udword_bits - 1));
144+
q.s.high = (q.s.high << 1) | (q.s.low >> (n_udword_bits - 1));
145+
q.s.low = (q.s.low << 1);
146+
// Compute (r - d) and conditionally subtract
147+
const long long s = (long long)(d.all - r.all - 1) >> (n_utword_bits - 1);
148+
q.s.low |= s & 1;
149+
r.all -= d.all & s;
150+
}
151+
if (rem) *rem = r.all;
152+
return q.all;
153+
}
154+
155+
tu_int __udivti3(tu_int a, tu_int b) {
156+
return __udivmodti4(a, b, 0);
157+
}
158+
159+
tu_int __umodti3(tu_int a, tu_int b) {
160+
tu_int r;
161+
__udivmodti4(a, b, &r);
162+
return r;
163+
}
164+
165+
#endif // __SIZEOF_INT128__

‎vlib/fasthttp/fasthttp.v‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,10 @@ pub fn (h ServerHandle) wait_till_running(params WaitTillRunningParams) !int {
114114
}
115115
$if windows {
116116
return error('fasthttp server lifecycle control is not supported on windows')
117+
} $else {
118+
mut server := unsafe { &Server(h.ptr) }
119+
return server.wait_till_running_impl(params)!
117120
}
118-
mut server := unsafe { &Server(h.ptr) }
119-
return server.wait_till_running_impl(params)!
120121
}
121122

122123
// shutdown gracefully stops accepting new requests and waits for active requests to finish.
@@ -126,9 +127,10 @@ pub fn (h ServerHandle) shutdown(params ShutdownParams) ! {
126127
}
127128
$if windows {
128129
return error('fasthttp server lifecycle control is not supported on windows')
130+
} $else {
131+
mut server := unsafe { &Server(h.ptr) }
132+
server.shutdown_impl(params)!
129133
}
130-
mut server := unsafe { &Server(h.ptr) }
131-
server.shutdown_impl(params)!
132134
}
133135

134136
$if !windows {

‎vlib/js/dom/dom.js.v‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ pub interface JS.WebGLRenderingContext {
631631
drawingBufferHeight JS.Number
632632
drawingBufferWidth JS.Number
633633
activeTexture(texture JS.Number)
634-
attachShader(program JS.WebGLProgram, shader JS.WebGLProgram)
634+
attachShader(program JS.WebGLProgram, shader JS.WebGLShader)
635635
linkProgram(program JS.WebGLProgram)
636636
bindAttribLocation(program JS.WebGLProgram, index JS.Number, name JS.String)
637637
bindBuffer(target JS.Number, buffer JS.WebGLBuffer)

‎vlib/json/tests/json_encode_json2_any_test.v‎

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)