vlang / msgpack

MIT License
19 stars 2 forks source link

vlang API change ? #3

Closed trollkarlen closed 11 months ago

trollkarlen commented 1 year ago
$ v version
V 0.3.3 d60ceb4

$ (v install msgpack && cd $HOME/.vmodules && v run ./msgpack/examples/basic.v)
msgpack/encode.v:63:26: error: only `$tmpl()`, `$env()`, `$embed_file()`, `$pkgconfig()`, `$vweb.html()`, `$compile_error()` and `$compile_warn()` comptime functions are supported right now
   61 |     } $else $if T.typ is []u8 {
   62 |         e.encode_string_bytes_raw(data)
   63 |     } $else $if T is $Array {
      |                             ^
   64 |         e.write_array_start(data.len)
   65 |         for value in data {

Same for git version:
$ (v install --git https://github.com/vlang/msgpack && cd $HOME/.vmodules && v run ./vlang/msgpack/examples/basic.v)
Updating module "vlang/msgpack" in "/Users/erobema/.vmodules/vlang/msgpack" ...
msgpack/encode.v:63:26: error: only `$tmpl()`, `$env()`, `$embed_file()`, `$pkgconfig()`, `$vweb.html()`, `$compile_error()` and `$compile_warn()` comptime functions are supported right now
   61 |     } $else $if T.typ is []u8 {
   62 |         e.encode_string_bytes_raw(data)
   63 |     } $else $if T is $Array {
      |                             ^
   64 |         e.write_array_start(data.len)
   65 |         for value in data {
felipensp commented 1 year ago

$Array, $Map, $Int, $Float, etc has been turned lowercased.

trollkarlen commented 1 year ago

Found very little information about these variables in the vlang documentation, where can i find more information about them ?

On Mon, Apr 3, 2023, 23:42 Felipe Pena @.***> wrote:

$Array, $Map, $Int, $Float, etc has been turn lowercased.

trollkarlen commented 1 year ago

With that change its still a lot of issues that goes beyond my vlang and template understanding.

$ (cd $HOME/.vmodules && v run ./msgpack/examples/basic.v)
msgpack/encode.v:32:19: error: cannot use `TestStructA` as `string` in argument 1 to `msgpack.Encoder.encode_string`
   30 | pub fn (mut e Encoder) encode[T](data T) []u8 {
   31 |     $if T.typ is string {
   32 |         e.encode_string(data)
      |                         ~~~~
   33 |     } $else $if T.typ is bool {
   34 |         e.encode_bool(data)
msgpack/encode.v:34:17: error: cannot use `TestStructA` as `bool` in argument 1 to `msgpack.Encoder.encode_bool`
   32 |         e.encode_string(data)
   33 |     } $else $if T.typ is bool {
   34 |         e.encode_bool(data)
      |                       ~~~~
   35 |     }
   36 |     // TODO: if int encode_int, if uint encode_uint
msgpack/encode.v:40:15: error: cannot use `TestStructA` as `i8` in argument 1 to `msgpack.Encoder.encode_i8`
   38 |     // then we will be using the smallest storage
   39 |     $else $if T.typ is i8 {
   40 |         e.encode_i8(data)
      |                     ~~~~
   41 |     } $else $if T.typ is i16 {
   42 |         e.encode_i16(data)
msgpack/encode.v:42:16: error: cannot use `TestStructA` as `i16` in argument 1 to `msgpack.Encoder.encode_i16`
   40 |         e.encode_i8(data)
   41 |     } $else $if T.typ is i16 {
   42 |         e.encode_i16(data)
      |                      ~~~~
   43 |     } $else $if T.typ is int {
   44 |         e.encode_i32(data)
msgpack/encode.v:44:16: error: cannot use `TestStructA` as `int` in argument 1 to `msgpack.Encoder.encode_i32`
   42 |         e.encode_i16(data)
   43 |     } $else $if T.typ is int {
   44 |         e.encode_i32(data)
      |                      ~~~~
   45 |     } $else $if T.typ is i64 {
   46 |         e.encode_i64(data)
msgpack/encode.v:46:16: error: cannot use `TestStructA` as `i64` in argument 1 to `msgpack.Encoder.encode_i64`
   44 |         e.encode_i32(data)
   45 |     } $else $if T.typ is i64 {
   46 |         e.encode_i64(data)
      |                      ~~~~
   47 |     } $else $if T.typ is u8 {
   48 |         e.encode_u8(data)
msgpack/encode.v:48:15: error: cannot use `TestStructA` as `u8` in argument 1 to `msgpack.Encoder.encode_u8`
   46 |         e.encode_i64(data)
   47 |     } $else $if T.typ is u8 {
   48 |         e.encode_u8(data)
      |                     ~~~~
   49 |     } $else $if T.typ is u16 {
   50 |         e.encode_u16(data)
msgpack/encode.v:50:16: error: cannot use `TestStructA` as `u16` in argument 1 to `msgpack.Encoder.encode_u16`
   48 |         e.encode_u8(data)
   49 |     } $else $if T.typ is u16 {
   50 |         e.encode_u16(data)
      |                      ~~~~
   51 |     } $else $if T.typ is u32 {
   52 |         e.encode_u32(data)
msgpack/encode.v:52:16: error: cannot use `TestStructA` as `u32` in argument 1 to `msgpack.Encoder.encode_u32`
   50 |         e.encode_u16(data)
   51 |     } $else $if T.typ is u32 {
   52 |         e.encode_u32(data)
      |                      ~~~~
   53 |     } $else $if T.typ is u64 {
   54 |         e.encode_u64(data)
msgpack/encode.v:54:16: error: cannot use `TestStructA` as `u64` in argument 1 to `msgpack.Encoder.encode_u64`
   52 |         e.encode_u32(data)
   53 |     } $else $if T.typ is u64 {
   54 |         e.encode_u64(data)
      |                      ~~~~
   55 |     } $else $if T.typ is f32 {
   56 |         e.encode_f32(data)
msgpack/encode.v:56:16: error: cannot use `TestStructA` as `f32` in argument 1 to `msgpack.Encoder.encode_f32`
   54 |         e.encode_u64(data)
   55 |     } $else $if T.typ is f32 {
   56 |         e.encode_f32(data)
      |                      ~~~~
   57 |     } $else $if T.typ is f64 {
   58 |         e.encode_f64(data)
msgpack/encode.v:58:16: error: cannot use `TestStructA` as `f64` in argument 1 to `msgpack.Encoder.encode_f64`
   56 |         e.encode_f32(data)
   57 |     } $else $if T.typ is f64 {
   58 |         e.encode_f64(data)
      |                      ~~~~
   59 |     } $else $if T.typ is time.Time {
   60 |         e.encode_time(data)
msgpack/encode.v:60:17: error: cannot use `TestStructA` as `time.Time` in argument 1 to `msgpack.Encoder.encode_time`
   58 |         e.encode_f64(data)
   59 |     } $else $if T.typ is time.Time {
   60 |         e.encode_time(data)
      |                       ~~~~
   61 |     } $else $if T.typ is []u8 {
   62 |         e.encode_string_bytes_raw(data)
msgpack/encode.v:62:29: error: cannot use `TestStructA` as `[]u8` in argument 1 to `msgpack.Encoder.encode_string_bytes_raw`
   60 |         e.encode_time(data)
   61 |     } $else $if T.typ is []u8 {
   62 |         e.encode_string_bytes_raw(data)
      |                                   ~~~~
   63 |     } $else $if T is $array {
   64 |         e.write_array_start(data.len)
msgpack/encode.v:100:13: error: cannot use `string` as `int` in argument 1 to `msgpack.Encoder.encode`
   98 |                 e.encode_string(field.name)
   99 |             }
  100 |             e.encode(data.$(field.name))
      |                      ~~~~~~~~~~~~~~~~~~
  101 |         }
  102 |     }
elimisteve commented 1 year ago

@trollkarlen Be sure to run the latest version of V!

trollkarlen commented 1 year ago

Im running the latest v and the same with this mornings version V 0.3.3 4a22d4a

medvednikov commented 1 year ago

We should probably add msgpack to vlang/v ci.

trollkarlen commented 1 year ago

Is this this a vlang issue or does msgpack need to be updated to reflect a change in vlang ?

medvednikov commented 1 year ago

msgpack needs to be updated

trollkarlen commented 1 year ago

How come the order of the $if and $else $if have meaning ? Is this by design or just a mishap ?

I found this when trying to figure out what happens here. I used this v test vlib/v/tests/option_compvar_val_test.v with small changes:

struct FixedStruct1 {
        a int
        b ?int
        c ?int = 4
}

// struct FixedStruct2 {
//     b ?int
// }

struct Encoder {}

struct Writer {}

fn write3(val string) {
        println(val)
}

fn write1[T](val T) {
        println(val)
}

fn (wr &Writer) write2[T](val T) {
        println(val)
}

fn encode_struct[T](val T) map[string][]string {
        wr := Writer{}
        mut out := map[string][]string{}
        $if T is $struct {
                $for field in T.fields {
                        value := val.$(field.name)
                        $if field.typ is ?int {
                                // work if comment lines 27 and 28
                                write1(value)
                                wr.write2(value)
                                out[field.name] << '${value:d}'
                        } $else {
                                write1(value)
                                wr.write2(value)
                                out[field.name] << value.str()
                        }
                        // This work well
                        $if field.is_option {
                                write1(value)
                                wr.write2(value)
                                out[field.name] << '${value:d}'
                        } $else {
                                write1(value)
                                wr.write2(value)
                                out[field.name] << value.str()
                        }
                }
        } $else $if T.typ is string {
                write1(val)
                wr.write2(val)
                write3(val)
                out["string"] << val
        }
        return out
}

fn test_main() {
        // cgen error: cannot convert 'struct _option_int' to 'int'
        mut out := encode_struct(FixedStruct1{})
        assert out['a'] == ['0', '0']
        assert out['b'] == ['0', '0']
        assert out['c'] == ['4', '4']
        out = encode_struct("hej")
        assert out['string'] == ['hej']
}
$ v run vlib/v/tests/option_compvar_val_test.v
0
0
0
0
0
0
0
0
4
4
4
4
hej
hej
hej
--- vlib/v/tests/option_compvar_val_test.v      2023-04-27 17:50:19.941276224 +0200
+++ vlib/v/tests/option_compvar_val_test2.v     2023-04-27 17:58:30.735544560 +0200
@@ -27,7 +27,13 @@
 fn encode_struct[T](val T) map[string][]string {
        wr := Writer{}
        mut out := map[string][]string{}
-       $if T is $struct {
+       println(val)
+       $if T.typ is string {
+               write1(val)
+               wr.write2(val)
+               write3(val)
+               out["string"] << val
+       } $else $if T is $struct {
                $for field in T.fields {
                        value := val.$(field.name)
                        $if field.typ is ?int {
@@ -51,11 +57,6 @@
                                out[field.name] << value.str()
                        }
                }
-       } $else $if T.typ is string {
-               write1(val)
-               wr.write2(val)
-               write3(val)
-               out["string"] << val
        }
        return out
 }
$ v run vlib/v/tests/option_compvar_val_test2.v
vlib/v/tests/option_compvar_val_test2.v:35:20: error: cannot append `T` to `[]string`
   33 |         wr.write2(val)
   34 |         write3(val)
   35 |         out["string"] << val
      |                          ~~~
   36 |     } $else $if T is $struct {
   37 |         $for field in T.fields {
--- vlib/v/tests/option_compvar_val_test2.v     2023-04-27 17:58:30.735544560 +0200
+++ vlib/v/tests/option_compvar_val_test3.v     2023-04-27 18:00:59.245350340 +0200
@@ -32,7 +32,7 @@
                write1(val)
                wr.write2(val)
                write3(val)
-               out["string"] << val
+               out["string"] << val.str()
        } $else $if T is $struct {
                $for field in T.fields {
                        value := val.$(field.name)
$ v run vlib/v/tests/option_compvar_val_test3.v

No output no error nothing and empty main :/

int main(int ___argc, char** ___argv){
    g_main_argc = ___argc; 
    g_main_argv = ___argv;
#if defined(_VGCBOEHM)
    GC_set_pages_executable(0);
    GC_INIT(); 
#endif
    _vinit(___argc, (voidptr)___argv);
    main__main();
    _vcleanup();
    return 0;
}
i582 commented 1 year ago

Found very little information about these variables in the vlang documentation, where can i find more information about them ?

See https://docs.vosca.dev/concepts/compile-time/reflection.html#type-checking

32ns commented 1 year ago

vlang seems to have features, but it seems like it cannot be used, which makes those who have been keeping an eye on it unable to see hope. With GPT being able to write code, does it still matter what syntax or language is used in the future? Does vlang still have its meaning if it continues to be delayed? Personally, I think vlang should focus on c2v and vtl, enriching vlang's library with c2v and training vlang's model with vtl to reverse itself. Half of 2023 has passed already! Nobody knows what GPT-5 will look like!

JalonSolov commented 11 months ago

If there is still a problem with the latest version of V and the most recent msgpack, please post example code that shows the problem.

spytheman commented 11 months ago

There is not a problem anymore, the msgpack code was updated, and it compiles cleanly with latest v.

spytheman commented 11 months ago

vlang seems to have features, but it seems like it cannot be used

I am using it every day.

32ns commented 11 months ago

vlang seems to have features, but it seems like it cannot be used

I am using it every day.

I also really like Vlang. However, it's currently not very mature. Just today, I wanted to use new_process to create a pseudo-terminal. However, when I called stdin_write, it gave me this error: image

Later, I tried to add a "pragma comment(linker,"")" in the program, but I couldn't achieve it. In the end, I could only add it to: image

I really love Vlang and would like to use it for all my projects. However, in practice, I find that most of the time, I'm not using Vlang but using it to call "C."

felipensp commented 11 months ago

vlang seems to have features, but it seems like it cannot be used

I am using it every day.

I also really like Vlang. However, it's currently not very mature. Just today, I wanted to use new_process to create a pseudo-terminal. However, when I called stdin_write, it gave me this error: image

Later, I tried to add a "pragma comment(linker,"")" in the program, but I couldn't achieve it. In the end, I could only add it to: image

I really love Vlang and would like to use it for all my projects. However, in practice, I find that most of the time, I'm not using Vlang but using it to call "C."

Your bug reports/patches are welcome. Your points can help us to bring it to the production state that you expects. Progress are done everyday. The robustness will came after heavy development.

32ns commented 11 months ago

vlang seems to have features, but it seems like it cannot be used

I am using it every day.

I also really like Vlang. However, it's currently not very mature. Just today, I wanted to use new_process to create a pseudo-terminal. However, when I called stdin_write, it gave me this error: image Later, I tried to add a "pragma comment(linker,"")" in the program, but I couldn't achieve it. In the end, I could only add it to: image I really love Vlang and would like to use it for all my projects. However, in practice, I find that most of the time, I'm not using Vlang but using it to call "C."

Your bug reports/patches are welcome. Your points can help us to bring it to the production state that you expects. Progress are done everyday. The robustness will came after heavy development.

There are too many mutilated documentation in vlang, and I haven't had time to read most of the code yet, but when I am familiar with it, I will also join in the code maintenance and make a little contribution to the community