Skip to content

Commit 9fef7ca

Browse files
authored
cgen: fix anon fn checking adding unresolved generic type on codegen (fix #25050) (#25055)
1 parent cd7e9a1 commit 9fef7ca

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

vlib/v/gen/c/fn.v

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ fn (mut g Gen) gen_fn_decl(node &ast.FnDecl, skip bool) {
218218
the_type := syms.map(it.name).join(', ')
219219
println('gen fn `${node.name}` for type `${the_type}`')
220220
}
221+
if concrete_types.any(it.has_flag(.generic)) {
222+
continue
223+
}
221224
g.cur_concrete_types = concrete_types
222225
g.gen_fn_decl(node, skip)
223226
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import arrays
2+
3+
pub fn Canvas.new(width int, height int) &Canvas {
4+
return &Canvas{
5+
layers: create_buffer(width, height)
6+
}
7+
}
8+
9+
pub fn (canvas Canvas) size() (int, int) {
10+
return canvas.layers[0].len, canvas.layers.len
11+
}
12+
13+
pub fn (canvas Canvas) string() string {
14+
output := buffer_to_braille(canvas.layers, dots_to_braille_rune_map)
15+
return arrays.join_to_string(output, '\n', |row| arrays.join_to_string(row, '', |character| '${character}'))
16+
}
17+
18+
pub fn (mut canvas Canvas) set(x int, y int) {
19+
canvas.layers[y][x] = true
20+
}
21+
22+
pub fn (mut canvas Canvas) unset(x int, y int) {
23+
canvas.layers[y][x] = false
24+
}
25+
26+
pub fn (mut canvas Canvas) clear() {
27+
width, height := canvas.size()
28+
canvas.layers = create_buffer(width, height)
29+
}
30+
31+
struct Canvas {
32+
mut:
33+
layers [][]bool
34+
}
35+
36+
const dots_to_braille = [u8(0), 3, 1, 4, 2, 5, 6, 7]
37+
const dots_to_braille_rune_map = memoize_dots_to_braille_rune()
38+
39+
fn dots_to_braille_rune(dots u8) rune {
40+
mut mask := 0
41+
for index in 0 .. 8 {
42+
if ((dots >> index) & 1) == 1 {
43+
mask |= 1 << dots_to_braille[index]
44+
}
45+
}
46+
47+
return rune(0x2800 + mask)
48+
}
49+
50+
fn memoize_dots_to_braille_rune() [256]rune {
51+
mut memo := [256]rune{}
52+
53+
for index in 0 .. 256 {
54+
memo[index] = dots_to_braille_rune(index)
55+
}
56+
57+
return memo
58+
}
59+
60+
fn buffer_to_braille(buffer [][]bool, braille_mapping [256]rune) [][]rune {
61+
out_rows := buffer.len / 4
62+
out_cols := buffer[0].len / 2
63+
mut output := [][]rune{len: out_rows, init: []rune{len: out_cols}}
64+
65+
for row := 0; row < out_rows; row += 1 {
66+
row_offset := row * 4
67+
for column := 0; column < out_cols; column += 1 {
68+
col_offset := column * 2
69+
70+
mut dots := u8(buffer[row_offset + 0][col_offset + 0])
71+
dots |= u8(buffer[row_offset + 0][col_offset + 1]) << 1
72+
dots |= u8(buffer[row_offset + 1][col_offset + 0]) << 2
73+
dots |= u8(buffer[row_offset + 1][col_offset + 1]) << 3
74+
dots |= u8(buffer[row_offset + 2][col_offset + 0]) << 4
75+
dots |= u8(buffer[row_offset + 2][col_offset + 1]) << 5
76+
dots |= u8(buffer[row_offset + 3][col_offset + 0]) << 6
77+
dots |= u8(buffer[row_offset + 3][col_offset + 1]) << 7
78+
79+
output[row][column] = dots_to_braille_rune(dots)
80+
}
81+
}
82+
83+
return output
84+
}
85+
86+
fn create_buffer(width int, height int) [][]bool {
87+
return [][]bool{len: height, init: []bool{len: width}}
88+
}
89+
90+
fn test_main() {
91+
braille_mapping := memoize_dots_to_braille_rune()
92+
width, height := 40, 48
93+
mut canvas := Canvas.new(width, height)
94+
mut buffer := [][]bool{len: height, init: []bool{len: width}}
95+
96+
minr := 16 * 16
97+
maxr := 20 * 20
98+
for y := 0; y < 48; y += 1 {
99+
for x := 0; x < width; x += 1 {
100+
cy := y - 24
101+
big_cx := x - 20
102+
small_cx := x - 16
103+
big := (big_cx * big_cx) + (cy * cy)
104+
small := (small_cx * small_cx) + (cy * cy)
105+
if small > minr && big < maxr {
106+
buffer[y][x] = true
107+
canvas.set(x, y)
108+
}
109+
}
110+
}
111+
112+
_ := buffer_to_braille(buffer, braille_mapping)
113+
}

0 commit comments

Comments
 (0)