Language request: Vala

I’ve found Vala to be a rather pleasant language to work with and would love to have it added for use in codingame challenges. It transpiles into C as part of compilation, although valac itself is capable of invoking C compiler.

Proposed compilation options:

--target-glib=auto --pkg gio-2.0 --pkg gee-0.8

Justification:

  • --target-glib=auto - we don’t care about resulting binary to be ABI-compatible with anything but build machine, so might as well reduce meaningless warnings from C compiler.
  • --pkg gee-0.8 - a large library of collections. While it’s not directly a part of vala or glib, it’s still a de-facto standard one (valadoc even lists it as a core library alongside glib and similar fundamental libraries).

Possible additional flags:

  • --Xcc=-O2 - Vala relies very heavily on C compiler to do optimizations, so I’d suggest enabling what is considered a “reasonable” optimization level by most distros out there. Although, given that it’s not default, and CodinGame’s history with lack of optimization options I’m not overly hopeful here…
  • --pkg gio-2.0 - allows to use async methods. Their usefulness is somewhat debatable in context of challenges, but they can be handy regardless.

Template codegen can be borrowed from C with minor changes:

  • Drop includes
  • Use stdin.scanf()/stdin.getc() for input
  • Use print() for output, it works just like printf in raw C

I’m unfamiliar with inner workings of language assistant CodinGame uses, but it’s worth noting that there exists vala-language-server project that works rather well.

4 Likes

Up !
can you add vala to the list of languages or add the includes glib-2.0 and gobject-2.0 for the C language?

valac can use the same template as C

an exemple with the actual event exemple code in C:

void main()
{
    int player_idx;
    stdin.scanf("%d", out player_idx);
    int nb_games;
    stdin.scanf("%d", out nb_games); stdin.getc();

    // game loop
    while (true) {
        for (int i = 0; i < 3; i++) {
            char score_info[65];
            stdin.scanf("%[^\n]", score_info); stdin.getc();
        }
        for (int i = 0; i < nb_games; i++) {
            char gpu[65];
            int reg_0;
            int reg_1;
            int reg_2;
            int reg_3;
            int reg_4;
            int reg_5;
            int reg_6;
            stdin.scanf("%s%d%d%d%d%d%d%d", gpu, out reg_0, out reg_1, out reg_2, out reg_3, out reg_4, out reg_5, out reg_6); stdin.getc();
        }

        // Write an action using printf(). DON'T FORGET THE TRAILING \n
        // To debug: fprintf(stderr, "Debug messages...\n");

        stdout.printf("LEFT\n");
    }
}

juste remove all #include and replace ‘&’ by ‘out’

valac is like gcc/clang valac file.vala -o out

1 Like