2022-05-28

VLANG-VIM-GDB

VLANG is a new programming language rather similar to GO, it can create executables for Linux/Mac/Windows and Android with ease from a unique source code.

On Windows, I have compiled VLANG with the msys2/mingw64-w GCC compiler as follows:

   git clone https://github.com/vlang/v
   cd v
   make.bat -gcc

which produces the command-line compiler and REPL v.exe inside the repository's root folder.

A present VLANG limitation is the lack of a dedicated debugger, however, it's possible to get some help from the GDB debugger. I wrote the following simple VLANG program to use as an example:

    import rand

    fn main() {
    mut heads := 0
    mut tails := 0
        for _ in 0 .. 10 {
            coin := rand.intn(1000)?
            if  coin%2 !=0 {
                println("head")
                heads++
            }
            else {
                println("tail")
                tails++
            }
        } 
        println('heads: ${heads}\t tails: ${tails}')
    }


    

It can be transpiled to C code with:

   v.exe -o coinflip.c coinflip.v
   

I can then compile the C code and include the debugging symbols as follows:

   gcc coinflip.c -g -Wl,-subsystem,windows -municode

NeoDebug

NeoDebug provides a GDB front-end in VIM. As shown in the video below, I can set a breakpoint to the wmain function, step into the function main_main and observe the value of variables as they change throughout the program.