What does HackerNews think of virgil?

A fast and lightweight native programming language

Language: Shell

#31 in Compiler
#16 in Python
This paper is the first time I seen mention of the Virgil programming language, from the same author:

https://github.com/titzer/virgil

Yes! The difference is on Linux a shared library is not actually required for kernel system calls. The binary interface is stable and will not change.

https://github.com/torvalds/linux/blob/master/Documentation/...

On Windows and other operating systems, things such as system call numbers can and do change. There's no way to interface with the kernel without linking to vendor libraries.

So on Linux you can ditch libc and write your own code. A Rust liblinux is definitely possible, I tested it. You can even have a compiler generate the system calls for you! It just needs to support the simple calling convention. No libraries necessary. I've seen a project that does just that:

https://github.com/titzer/virgil

This is a deep hole for language design.

I thought about this very, very carefully when designing Virgil[1]'s numerical tower, which has both fixed-size signed and unsigned integers, as well as floating point. Like other new language designs, Virgil doesn't have any implicit narrowing conversions (even between float and int). Also, any conversions between numbers include range/representability checks that will throw if out-of-range or rounding occurs. If you want to reinterpret the bits, then there's an operator to view the bits. But conversions that have to do with "numbers" then all make sense in that numbers then exist on a single number line and have different representations in different types. Conversion between always preserve numbers and where they lie on the number line, whereas "view" is a bit-level operation, which generally compiles to a no-op. Unfortunately, the implications of this for floating point is that -0 is not actually an integer, so you can't cast it to an int. You must round it. But that's fine, because you always want to round floats to int, never cast them.

[1] https://github.com/titzer/virgil

I thought very hard about this problem as I've developed Virgil [https://github.com/titzer/virgil] over the years. Bootstrapping any system, not the least of which a new programming language is a hard problem.

Virgil has an (almost) hermetic build. The compiler binaries for a stable version are checked into the repository. At any given revision, that stable compiler can compile the source code in the repo to produce a new compiler binary, for any of the supported platforms. That stable binary is therefore a cross-compiler. There are stable binaries for each of the supported stable platforms (x86-darwin, x86-linux, JVM), and there are more platforms that are in the works (x86-64-linux, wasm), but don't have stable binaries.

What do you need to run one of the stable binaries?

1. JVM: any Java 5 compliant JVM

2. x86-linux: a 32-bit Linux kernel

3. x86-darwin: a 32-bit Darwin kernel*

[*] sadly, no longer supported past Mavericks, thanks Apple

The (native) compiler binaries are statically-linked, so they don't need any runtime libraries, DLLs, .so, etc.

Also, nothing depends on having a compiler for any other language, or even much of a shell. There is test code in C, but no runtime system or other services. The entire system is self-hosted.

I think this is a decent solution, but it has limitations. For one, since stable executables absolutely need to be checked in, it's not good to rev stable too often, since it will bloat the git repo. Also, checking in binaries that are all cross-compilers for every platform grows like O(n^2). It would be better to check in just one binary per platform, that contains an interpreter capable of running the compiler from source to bootstrap itself. I guess I'll get to that at platform #4.

> It finally possible to make Linux binaries in a high level language not involving anything written in C at build-time or run-time!!!

Virgil has been doing this for years.

https://github.com/titzer/virgil/

They look a lot nicer in ML and Haskell, IMO.

Of course I implemented them in Virgil, too. (shameless plug: https://github.com/titzer/virgil)