From c4ca6a9113829a83310f0bffde69dc8ac3a6eb63 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Fri, 15 May 2020 18:55:29 +0200 Subject: [PATCH] sokol: make examples compile --- examples/sokol/fonts.v | 8 ++++---- vlib/sokol/gfx/gfx_structs.v | 2 ++ vlib/sokol/gfx/gfx_utils.v | 6 +++++- vlib/v/gen/cgen.v | 11 ++++++++++- vlib/v/gen/fn.v | 4 +++- 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/examples/sokol/fonts.v b/examples/sokol/fonts.v index b387f9f646..cb96f25a32 100644 --- a/examples/sokol/fonts.v +++ b/examples/sokol/fonts.v @@ -14,21 +14,21 @@ mut: } fn main() { - mut color_action := sg_color_attachment_action{ + mut color_action := C.sg_color_attachment_action{ action: C.SG_ACTION_CLEAR } color_action.val[0] = 0.3 color_action.val[1] = 0.3 color_action.val[2] = 0.32 color_action.val[3] = 1.0 - mut pass_action := sg_pass_action{} + mut pass_action := C.sg_pass_action{} pass_action.colors[0] = color_action state := &AppState{ pass_action: pass_action fons: &C.FONScontext(0) } title := 'V Metal/GL Text Rendering' - desc := sapp_desc{ + desc := C.sapp_desc{ user_data: state init_userdata_cb: init frame_userdata_cb: frame @@ -41,7 +41,7 @@ fn main() { fn init(user_data voidptr) { mut state := &AppState(user_data) // dont actually alocate this on the heap in real life - gfx.setup(&sg_desc{ + gfx.setup(&C.sg_desc{ mtl_device: sapp.metal_get_device() mtl_renderpass_descriptor_cb: sapp.metal_get_renderpass_descriptor mtl_drawable_cb: sapp.metal_get_drawable diff --git a/vlib/sokol/gfx/gfx_structs.v b/vlib/sokol/gfx/gfx_structs.v index fa6742fde3..04fdb790e8 100644 --- a/vlib/sokol/gfx/gfx_structs.v +++ b/vlib/sokol/gfx/gfx_structs.v @@ -415,12 +415,14 @@ pub mut: val [4]f32 } +/* pub fn (action mut C.sg_color_attachment_action) set_color_values(r, g, b, a f32) { action.val[0] = r action.val[1] = g action.val[2] = b action.val[3] = a } +*/ pub struct C.sg_depth_attachment_action { pub mut: diff --git a/vlib/sokol/gfx/gfx_utils.v b/vlib/sokol/gfx/gfx_utils.v index 4a5ad0ab9c..fefab67b97 100644 --- a/vlib/sokol/gfx/gfx_utils.v +++ b/vlib/sokol/gfx/gfx_utils.v @@ -4,7 +4,11 @@ pub fn create_clear_pass(r, g, b, a f32) C.sg_pass_action { mut color_action := C.sg_color_attachment_action { action: C.SG_ACTION_CLEAR } - color_action.set_color_values(r, g, b, a) + //color_action.set_color_values(r, g, b, a) +color_action.val[0] = r + color_action.val[1] = g + color_action.val[2] = b + color_action.val[3] = a mut pass_action := C.sg_pass_action{} pass_action.colors[0] = color_action diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index c5538a7f4e..c66b0857d2 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -654,7 +654,7 @@ fn (mut g Gen) stmt(node ast.Stmt) { g.includes.writeln('#$it.val') } if typ == 'define' { - g.definitions.writeln('#$it.val') + g.includes.writeln('#$it.val') } } ast.Import {} @@ -967,6 +967,12 @@ fn (mut g Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) { right_sym := g.table.get_type_symbol(assign_stmt.right_types[i]) mut is_fixed_array_init := false mut has_val := false + /* + if val is ast.ArrayInit { + is_fixed_array_init = val.is_fixed + has_val = val.has_val + } + */ match val { ast.ArrayInit { is_fixed_array_init = it.is_fixed @@ -2444,6 +2450,9 @@ fn (mut g Gen) write_types(types []table.TypeSymbol) { mut fixed := styp[12..] len := styp.after('_') fixed = fixed[..fixed.len - len.len - 1] + if fixed.starts_with('C__') { + fixed = fixed[3..] + } g.definitions.writeln('typedef $fixed $styp [$len];') // } } diff --git a/vlib/v/gen/fn.v b/vlib/v/gen/fn.v index 4ccd25b084..bde295a322 100644 --- a/vlib/v/gen/fn.v +++ b/vlib/v/gen/fn.v @@ -292,8 +292,10 @@ fn (mut g Gen) method_call(node ast.CallExpr) { if node.left_type == 0 { verror('method receiver type is 0, this means there are some uchecked exprs') } - mut receiver_type_name := g.cc_type(node.receiver_type) + // mut receiver_type_name := g.cc_type(node.receiver_type) + //mut receiver_type_name := g.typ(node.receiver_type) typ_sym := g.table.get_type_symbol(node.receiver_type) + mut receiver_type_name := typ_sym.name.replace('.', '__') if typ_sym.kind == .interface_ { // Speaker_name_table[s._interface_idx].speak(s._object) g.write('${c_name(receiver_type_name)}_name_table[')