V: tetris.v doesn't compile

Created on 22 Jun 2019  路  18Comments  路  Source: vlang/v

check()
next token = `INT`
pass=1 fn=``
panic: tetris.v:58
expected `,` but got `(`
exit():

Most helpful comment

I get another error:

pass=1 fn=``
panic: gl_lin.v:5
redefinition of `gl.init_glad`
exit():

All 18 comments

I get another error:

pass=1 fn=``
panic: gl_lin.v:5
redefinition of `gl.init_glad`
exit():

did a git pull and now i get

(char code=0) pos=4428 len=4651
panic: array.v:224
invalid character ``
exit():

EDIT: this was caused by CRLF, made seperate issue for that, still get first error.

I succeeded to compile it.
Screenshot from 2019-06-23 05-43-40

I had to fix the program, v compiler and manually install dependencies.
I can help you to compile it if needed. but I think the compiler and demo include bugs.

@musou1500 Could you share a patch?

@dloss
here is a patch. but it is a temporary fix so terrible....

additionally,

  • install glad.h
  • install stb
  • put RobotoMono-Regular.ttf to /var/tmp

If you are using v.c to compile Tetris, you need to fix v.c same as parser.v.

diff --git a/builtin/array.v b/builtin/array.v
index 8a23647..21d8aea 100644
--- a/builtin/array.v
+++ b/builtin/array.v
@@ -3,8 +3,8 @@ module builtin
 struct array {
    // Using a void pointer allows to implement arrays without generics and without generating
    // extra code for every type.
-   data         voidptr
 pub:
+   data         voidptr
    len          int
    cap          int
    element_size int
diff --git a/builtin/string.v b/builtin/string.v
index 9a8ebe4..f458b28 100644
--- a/builtin/string.v
+++ b/builtin/string.v
@@ -2,8 +2,8 @@ module builtin

 // V strings are not null-terminated.
 struct string {
-   str byteptr
 pub:
+   str byteptr
    len int
 }

diff --git a/compiler/parser.v b/compiler/parser.v
index 9e698b8..5e95ad2 100644
--- a/compiler/parser.v
+++ b/compiler/parser.v
@@ -2352,7 +2352,7 @@ fn (p mut Parser) array_init() string {
    // }
    mut new_arr := '/*$new_arr_ph*/ new_array_from_c_array'
    if no_copy {
-       new_arr += '_no_copy'
+       new_arr += ''
    }
    p.gen(' })')
    // p.gen('$new_arr($vals.len, $vals.len, sizeof($typ), ($typ[]) $c_arr );')
diff --git a/gg/gg.v b/gg/gg.v
index cd43b8d..08c64a6 100644
--- a/gg/gg.v
+++ b/gg/gg.v
@@ -10,7 +10,7 @@ import gl
 #flag linux -I.
 #include "ft2build.h"
 #include FT_FREETYPE_H
-#include "glad.h"
+#include "glad/glad.h"
 struct Vec2 {
    x int
    y int
diff --git a/gl/gl.v b/gl/gl.v
index d9f4116..81436c5 100644
--- a/gl/gl.v
+++ b/gl/gl.v
@@ -9,7 +9,7 @@ import const (
    GL_DEPTH_TEST
 )

-#include "glad.h"
+#include "glad/glad.h"
 #include "glad.c"
 fn init_glad() {
    ok := C.gladLoadGL()
diff --git a/gl/gl_lin.v b/gl/gl_lin.v
deleted file mode 100644
index 696c1ee..0000000
--- a/gl/gl_lin.v
+++ /dev/null
@@ -1,14 +0,0 @@
-module gl
-
-#include "glad.h"
-#include "glad.c"
-fn init_glad() {
-   println('init_glad() win')
-   // # ok= gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
-   ok := C.gladLoadGL()
-   if !ok {
-       os.exit('Failed to initialize glad OpenGL context')
-   }
-   // C.printf("initglad test: glClear ADDR=%p\n', glClear);
-}
-
diff --git a/glm/glm.v b/glm/glm.v
index 4560829..73ec253 100644
--- a/glm/glm.v
+++ b/glm/glm.v
@@ -126,10 +126,14 @@ fn rotate(m Mat4, angle float, vec Vec3) Mat4 {
 }
 */
 // fn translate(vec Vec3) *float {
+fn float_calloc(n int) *float {
+  return *float(malloc(sizeof(float) * n))
+}
+
 fn translate(m Mat4, v Vec3) Mat4 {
    // # return glm__mat4(myglm_translate(vec.x,vec.y,vec.z)  );
    a := m.data
-   mut out := float_calloc(16)
+  mut out := float_calloc(16)
    x := v.x
    y := v.y
    z := v.z
@@ -157,7 +161,7 @@ fn ortho(left, right, bottom, top float) Mat4 {
    println('glm ortho($left, $right, $bottom, $top)')
    // mat<4, 4, T, defaultp> Result(static_cast<T>(1));
    n := 16
-   mut res := float_calloc(n)
+  mut res := float_calloc(n)
    # res[0] = 2 / (right - left) ;
    # res[5] = 2.0 / (top - bottom);
    # res[10] =  (1);
@@ -170,7 +174,7 @@ fn ortho(left, right, bottom, top float) Mat4 {
 // fn scale(a *float, v Vec3) *float {
 fn scale(m Mat4, v Vec3) Mat4 {
    a := m.data
-   mut out := float_calloc(16)
+  mut out := float_calloc(16)
    x := v.x
    y := v.y
    z := v.z
@@ -196,7 +200,7 @@ fn scale(m Mat4, v Vec3) Mat4 {
 // fn rotate_z(a *float, rad float) *float {
 fn rotate_z(m Mat4, rad float) Mat4 {
    a := m.data
-   mut out := float_calloc(16)
+  mut out := float_calloc(16)
    s := math.sin(rad)
    c := math.cos(rad)
    a00 := a[0]
@@ -233,7 +237,7 @@ fn identity() Mat4 {
    // 0 0 1 0
    // 0 0 0 1
    n := 16
-   mut res := float_calloc(sizeof(float) * n)
+  mut res := float_calloc(sizeof(float) * n)
    res[0] = 1
    res[5] = 1
    res[10] = 1
diff --git a/stbi/stbi.v b/stbi/stbi.v
index 3f3e605..8ab463d 100644
--- a/stbi/stbi.v
+++ b/stbi/stbi.v
@@ -1,6 +1,6 @@
 module stbi

-#include "glad.h"
+#include "glad/glad.h"
 import gl

 #define STB_IMAGE_IMPLEMENTATION

Thanks!

I think the following fix is needed to close this issue.

  • publish string.str andarray.data (or fix to avoid using private fields)
  • add doc for dependencies

    • glad

    • stb

  • add unimplemented functions

    • new_array_from_c_array_no_copy

    • float_calloc

  • remove gl/gl_lin.v
  • add RobotoMono-Regular.ttf to example/tetris

still doesnt fix

check()
next token = `INT`
pass=1 fn=``
panic: tetris.v:58
expected `,` but got `(`
exit():

@Cynosphere can you post tetris.v?

@musou1500 ive made no modifications to mine at all from example/tetris.v

@Cynosphere are you using latest compiler? please try to confirm commit log.

yeah i just had to build an updated compiler and then hack it together again to work on windows, compiled fine now

I created some Pull-Requets.

remaining tasks are these.

  • add doc for dependencies

    • glad

    • stb

    • freetype2

  • add unimplemented functions new_array_from_c_array_no_copy
  • add RobotoMono-Regular.ttf to example/tetris

to simplify the problem, split it up to multiple issues may be good.

freetype2 needs to be added in dependency list

@Cynosphere thank you! I updated my comment.

tetris seems works.
it can be closed now.

Works for me as well. :+1:

It should now work as commit c619243 fixed it. Feel free to reopen if it's still not working. :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PavelVozenilek picture PavelVozenilek  路  3Comments

taojy123 picture taojy123  路  3Comments

markgraydev picture markgraydev  路  3Comments

XVilka picture XVilka  路  3Comments

ArcDrake picture ArcDrake  路  3Comments