1
2
Fork
You've already forked ynova
0
Nova interpreter
  • D 100%
2025年06月11日 10:06:44 +01:00
examples support passing multiple files to the interpreter + STD lib 2025年06月11日 10:06:44 +01:00
source support passing multiple files to the interpreter + STD lib 2025年06月11日 10:06:44 +01:00
.gitignore initial 2025年05月23日 20:07:08 +01:00
dub.json add REPL 2025年05月29日 13:50:03 +01:00
dub.selections.json fix pushing order 2025年05月23日 22:25:38 +01:00
LICENSE initial 2025年05月23日 20:07:08 +01:00
README.md add reading files 2025年05月31日 13:07:38 +01:00
std.nv support passing multiple files to the interpreter + STD lib 2025年06月11日 10:06:44 +01:00

ynova

Toy nova interpreter

Build

dub build

Module: core

Imported by default

|:: print $x|

Prints $x to stdout

|:: import $mod|

Imports module $mod

(Variable arity) @shell

Runs and prints the given tuple as a shell command

|:: exit|

Exits the program

|:: write $str|

Prints $str without a new line

|:: read $file to $stack|

Pushes the characters from the file $file in reverse to $stack

Module: math

Imported by default

|:@math: +|

Pops 2 integers from the @math stack, adds them, and pushes the result

|:@math: -|

Pops 2 integers from the @math stack, subtracts them, and pushes the result

|:@math: *|

Pops 2 integers from the @math stack, multiplies them, and pushes the result

|:@math: /|

Pops 2 integers from the @math stack, divides them, and pushes the result

|:@math: %|

Pops 2 integers from the @math stack, divies them and calculates the remainder, and pushes the result

Module: build

|:: compile source $src to $obj|

Gets all source files using the wildcard $src and iterates through them. First, it pushes the tuple finalise to the @build stack. Then, it pushes this tuple to the @build stack:

$src to $obj

Where:

  • $src is one of the source files found using the wildcard from the rule
  • $obj is the $obj from the rule, but with the * replaced with the current source file with the extension removed

Example to compile a C project:

|:@build: $src to $obj|
	:@shell: gcc $src -o $obj -c
|:@build: finalise|
	:@shell: gcc bin/*.o -o main
||
	:: import build
	:: compile source source/*.c to bin/*.o
	:@shell: mkdir -p bin

|:--: compile source $src to $obj|

The same as the rule above, except it uses multithreading. A task pool is used with as many threads as available CPU cores. The interpreter creates a copy of itself for every source file, and in each copy a version of the :@build: $src to $obj tuple is pushed. These interpreter copies run until their version of the program exits.

Module: graphics

|:: create $w x $h window named $title|

|:: close window|

|:: use colour $r $g $b|

|:: clear window|

|:: render window|

|:: fetch events|

Pushes :@events: quit if the window is closing

|:: draw rect at $x $y with size $w x $h