compiler: fix #3973 by dealing with name mangling problem

pull/4117/head
hazohelet 2020-03-26 16:54:33 +09:00 committed by GitHub
parent d54843275f
commit d8bcd13e86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 76 additions and 66 deletions

View File

@ -28,13 +28,13 @@ fn main() {
fn init(user_data voidptr) { fn init(user_data voidptr) {
desc := sg_desc{ desc := sg_desc{
mtl_device: C.sapp_metal_get_device() mtl_device: sapp.metal_get_device()
mtl_renderpass_descriptor_cb: sapp_metal_get_renderpass_descriptor mtl_renderpass_descriptor_cb: sapp.metal_get_renderpass_descriptor
mtl_drawable_cb: sapp_metal_get_drawable mtl_drawable_cb: sapp.metal_get_drawable
d3d11_device: sapp_d3d11_get_device() d3d11_device: sapp.d3d11_get_device()
d3d11_device_context: sapp_d3d11_get_device_context() d3d11_device_context: sapp.d3d11_get_device_context()
d3d11_render_target_view_cb: sapp_d3d11_get_render_target_view d3d11_render_target_view_cb: sapp.d3d11_get_render_target_view
d3d11_depth_stencil_view_cb: sapp_d3d11_get_depth_stencil_view d3d11_depth_stencil_view_cb: sapp.d3d11_get_depth_stencil_view
} }
gfx.setup(&desc) gfx.setup(&desc)
sgl_desc := sgl_desc_t{} sgl_desc := sgl_desc_t{}
@ -75,9 +75,9 @@ fn draw_hollow_rect(x, y, w, h f32) {
fn draw_filled_rect(x, y, w, h f32) { fn draw_filled_rect(x, y, w, h f32) {
sgl.begin_quads() sgl.begin_quads()
sgl_v2f(x, y) sgl.v2f(x, y)
sgl_v2f(x + w, y) sgl.v2f(x + w, y)
sgl_v2f(x + w, y + h) sgl.v2f(x + w, y + h)
sgl_v2f(x, y + h) sgl.v2f(x, y + h)
sgl.end() sgl.end()
} }

View File

@ -42,13 +42,13 @@ fn init(user_data voidptr) {
mut state := &AppState(user_data) mut state := &AppState(user_data)
// dont actually alocate this on the heap in real life // dont actually alocate this on the heap in real life
gfx.setup(&sg_desc{ gfx.setup(&sg_desc{
mtl_device: C.sapp_metal_get_device() mtl_device: sapp.metal_get_device()
mtl_renderpass_descriptor_cb: sapp_metal_get_renderpass_descriptor mtl_renderpass_descriptor_cb: sapp.metal_get_renderpass_descriptor
mtl_drawable_cb: sapp_metal_get_drawable mtl_drawable_cb: sapp.metal_get_drawable
d3d11_device: sapp_d3d11_get_device() d3d11_device: sapp.d3d11_get_device()
d3d11_device_context: sapp_d3d11_get_device_context() d3d11_device_context: sapp.d3d11_get_device_context()
d3d11_render_target_view_cb: sapp_d3d11_get_render_target_view d3d11_render_target_view_cb: sapp.d3d11_get_render_target_view
d3d11_depth_stencil_view_cb: sapp_d3d11_get_depth_stencil_view d3d11_depth_stencil_view_cb: sapp.d3d11_get_depth_stencil_view
}) })
s := &C.sgl_desc_t{} s := &C.sgl_desc_t{}
C.sgl_setup(s) C.sgl_setup(s)
@ -64,7 +64,7 @@ fn frame(user_data voidptr) {
t := time.ticks() t := time.ticks()
mut state := &AppState(user_data) mut state := &AppState(user_data)
state.render_font() state.render_font()
gfx.begin_default_pass(&state.pass_action, sapp_width(), sapp_height()) gfx.begin_default_pass(&state.pass_action, sapp.width(), sapp.height())
sgl.draw() sgl.draw()
gfx.end_pass() gfx.end_pass()
gfx.commit() gfx.commit()
@ -98,43 +98,43 @@ fn (state &AppState) render_font() {
dy += lh dy += lh
C.fonsSetColor(state.fons, white) C.fonsSetColor(state.fons, white)
dx = C.fonsDrawText(state.fons, dx, dy, c'The quick ', C.NULL) dx = C.fonsDrawText(state.fons, dx, dy, c'The quick ', C.NULL)
fonsSetFont(state.fons, state.font_normal) C.fonsSetFont(state.fons, state.font_normal)
fonsSetSize(state.fons, 48.0) C.fonsSetSize(state.fons, 48.0)
fonsSetColor(state.fons, brown) C.fonsSetColor(state.fons, brown)
dx = fonsDrawText(state.fons, dx, dy, c'brown ', C.NULL) dx = C.fonsDrawText(state.fons, dx, dy, c'brown ', C.NULL)
fonsSetFont(state.fons, state.font_normal) C.fonsSetFont(state.fons, state.font_normal)
fonsSetSize(state.fons, 24.0) C.fonsSetSize(state.fons, 24.0)
fonsSetColor(state.fons, white) C.fonsSetColor(state.fons, white)
dx = fonsDrawText(state.fons, dx, dy, c'fox ', C.NULL) dx = C.fonsDrawText(state.fons, dx, dy, c'fox ', C.NULL)
dx = sx dx = sx
dy += lh * 1.2 dy += lh * 1.2
fonsSetSize(state.fons, 20.0) C.fonsSetSize(state.fons, 20.0)
fonsSetFont(state.fons, state.font_normal) C.fonsSetFont(state.fons, state.font_normal)
fonsSetColor(state.fons, blue) C.fonsSetColor(state.fons, blue)
fonsDrawText(state.fons, dx, dy, c'Now is the time for all good men to come to the aid of the party.', C.NULL) C.fonsDrawText(state.fons, dx, dy, c'Now is the time for all good men to come to the aid of the party.', C.NULL)
dx = 300 dx = 300
dy = 350 dy = 350
fonsSetAlign(state.fons, C.FONS_ALIGN_LEFT | C.FONS_ALIGN_BASELINE) C.fonsSetAlign(state.fons, C.FONS_ALIGN_LEFT | C.FONS_ALIGN_BASELINE)
fonsSetSize(state.fons, 60.0) C.fonsSetSize(state.fons, 60.0)
fonsSetFont(state.fons, state.font_normal) C.fonsSetFont(state.fons, state.font_normal)
fonsSetColor(state.fons, white) C.fonsSetColor(state.fons, white)
fonsSetSpacing(state.fons, 5.0) C.fonsSetSpacing(state.fons, 5.0)
fonsSetBlur(state.fons, 6.0) C.fonsSetBlur(state.fons, 6.0)
fonsDrawText(state.fons, dx, dy, c'Blurry...', C.NULL) C.fonsDrawText(state.fons, dx, dy, c'Blurry...', C.NULL)
dx = 300 dx = 300
dy += 50.0 dy += 50.0
fonsSetSize(state.fons, 28.0) C.fonsSetSize(state.fons, 28.0)
fonsSetFont(state.fons, state.font_normal) C.fonsSetFont(state.fons, state.font_normal)
fonsSetColor(state.fons, white) C.fonsSetColor(state.fons, white)
fonsSetSpacing(state.fons, 0.0) C.fonsSetSpacing(state.fons, 0.0)
fonsSetBlur(state.fons, 3.0) C.fonsSetBlur(state.fons, 3.0)
fonsDrawText(state.fons, dx, dy + 2, c'DROP SHADOW', C.NULL) C.fonsDrawText(state.fons, dx, dy + 2, c'DROP SHADOW', C.NULL)
fonsSetColor(state.fons, black) C.fonsSetColor(state.fons, black)
fonsSetBlur(state.fons, 0) C.fonsSetBlur(state.fons, 0)
fonsDrawText(state.fons, dx, dy, c'DROP SHADOW', C.NULL) C.fonsDrawText(state.fons, dx, dy, c'DROP SHADOW', C.NULL)
fonsSetSize(state.fons, 18.0) C.fonsSetSize(state.fons, 18.0)
fonsSetFont(state.fons, state.font_normal) C.fonsSetFont(state.fons, state.font_normal)
fonsSetColor(state.fons, white) C.fonsSetColor(state.fons, white)
dx = 50 dx = 50
dy = 350 dy = 350
line(dx - 10, dy, dx + 250, dy) line(dx - 10, dy, dx + 250, dy)

View File

@ -366,7 +366,7 @@ fn (p mut Parser) name_expr() string {
} }
// Unknown name, try prepending the module name to it // Unknown name, try prepending the module name to it
// TODO perf // TODO perf
else if !p.table.known_type(name) && !p.table.known_fn(name) && !p.table.known_const(name) && !is_c { else if !p.table.known_type(name) && !p.known_fn_in_mod(name) && !p.table.known_const(name) && !is_c {
name = p.prepend_mod(name) name = p.prepend_mod(name)
} }
// re-check // re-check

View File

@ -384,6 +384,16 @@ fn (t &Table) known_fn(name string) bool {
return true return true
} }
fn (p &Parser) known_fn_in_mod(name string) bool {
existing_fn := p.table.find_fn(name) or {
return false
}
if (existing_fn.mod == p.mod || existing_fn.mod == 'builtin') {
return true
}
return false
}
fn (t &Table) known_const(name string) bool { fn (t &Table) known_const(name string) bool {
_ = t.find_const(name) or { _ = t.find_const(name) or {
return false return false

View File

@ -56,13 +56,13 @@ __global g_font_path string
fn init_sokol_window() { fn init_sokol_window() {
desc := sg_desc{ desc := sg_desc{
mtl_device: C.sapp_metal_get_device() mtl_device: sapp.metal_get_device()
mtl_renderpass_descriptor_cb: sapp_metal_get_renderpass_descriptor mtl_renderpass_descriptor_cb: sapp.metal_get_renderpass_descriptor
mtl_drawable_cb: sapp_metal_get_drawable mtl_drawable_cb: sapp.metal_get_drawable
d3d11_device: sapp_d3d11_get_device() d3d11_device: sapp.d3d11_get_device()
d3d11_device_context: sapp_d3d11_get_device_context() d3d11_device_context: sapp.d3d11_get_device_context()
d3d11_render_target_view_cb: sapp_d3d11_get_render_target_view d3d11_render_target_view_cb: sapp.d3d11_get_render_target_view
d3d11_depth_stencil_view_cb: sapp_d3d11_get_depth_stencil_view d3d11_depth_stencil_view_cb: sapp.d3d11_get_depth_stencil_view
} }
gfx.setup(&desc) gfx.setup(&desc)
sgl_desc := sgl_desc_t{} sgl_desc := sgl_desc_t{}
@ -138,20 +138,20 @@ pub fn (gg &GG) run() {
pub fn (ctx &GG) draw_rect(x, y, w, h f32, c gx.Color) { pub fn (ctx &GG) draw_rect(x, y, w, h f32, c gx.Color) {
sgl.c4b(c.r, c.g, c.b, 128) sgl.c4b(c.r, c.g, c.b, 128)
sgl.begin_quads() sgl.begin_quads()
sgl_v2f(x, y) sgl.v2f(x, y)
sgl_v2f(x + w, y) sgl.v2f(x + w, y)
sgl_v2f(x + w, y + h) sgl.v2f(x + w, y + h)
sgl_v2f(x, y + h) sgl.v2f(x, y + h)
sgl.end() sgl.end()
} }
pub fn draw_rect(x, y, w, h f32, c gx.Color) { pub fn draw_rect(x, y, w, h f32, c gx.Color) {
sgl.c4b(c.r, c.g, c.b, 128) sgl.c4b(c.r, c.g, c.b, 128)
sgl.begin_quads() sgl.begin_quads()
sgl_v2f(x, y) sgl.v2f(x, y)
sgl_v2f(x + w, y) sgl.v2f(x + w, y)
sgl_v2f(x + w, y + h) sgl.v2f(x + w, y + h)
sgl_v2f(x, y + h) sgl.v2f(x, y + h)
sgl.end() sgl.end()
} }