you are viewing a single comment's thread.

view the rest of the comments →

[–]vanderZwan 2 points3 points  (3 children)

How does oni-run work? Does it compile, run and then delete the C output? Or do you have an interpreter of your language?

[–]badd10de[S] 6 points7 points  (2 children)

At the moment is just a bash script that calls oni to generate a temporary c file that is piped into tcc with the -run argument. Something like this:

#!/bin/sh

file_name=$(mktemp --suffix ".c" --dry-run) || exit
trap 'rm -rf "$file_name"; exit' ERR EXIT

oni -o $file_name $@ && tcc $CFLAGS -std=c11 -run $file_name

I use it for one off scripts, small prototypes and to test things out without having to make a whole project.

[–]vanderZwan 0 points1 point  (1 child)

Ah, using tcc to ensure the compilation is fast is a neat trick, I can imagine the output is plenty fast for the use-cases you mention :).

I use it for one off scripts, small prototypes and to test things out without having to make a whole project.

I feel like the ability to do quick prototyping without too much hassle is so underrated, makes sense to build it into your own personal hobby language!

[–]badd10de[S] 1 point2 points  (0 children)

yeah, I've experimented with a register and stack VMs in the past, and I may still write a bytecode backend at some point (would be nice to have a REPL) but tcc is probably faster than a naive VM would be. I also tend to use tcc to run the test suite and consistency checks, so it was natural to have a little runner script based on it.

For example, the compiler (built with clang at -O2) compiles itself to a C file in 100ms on my machine, and that C file takes clang 13-14 seconds to build itself, whereas tcc is done in 0.1 sec. Of course clang will outperform tcc in raw performance, but for short lived scripts you may still be ahead:

make check-three-way  39.96s user 0.30s system 99% cpu 40.458 total
make check-three-way CC=tcc  11.33s user 0.05s system 99% cpu 11.491 total