change project structure

This commit is contained in:
prod2 2022-01-29 22:33:34 +01:00
parent 45e22d9fed
commit 13da52ad24
23 changed files with 37 additions and 82 deletions

3
.gitignore vendored
View File

@ -1,4 +1,5 @@
nds
*.txt
callgrind*
.vscode
.vscode
bin/nds

View File

@ -1,13 +0,0 @@
var a = 0;
var b = 1;
var i = 1;
while (i < 300) {
var c = a + b;
a = b;
b = c;
i = i + 1;
};
print b;

View File

@ -1,13 +0,0 @@
a = 0
b = 1
i = 1
while i < 300:
c = a + b
a = b
b = c
i = i + 1
print (b)

View File

@ -1,13 +0,0 @@
x=0
y=1
i=2
while [ $i -lt 300 ]
do
i=$(( $i + 1 ))
z=$(( $x + $y ))
x=$y
y=$z
done
echo "$y"

View File

@ -1,9 +0,0 @@
local function fib(n)
if n < 2 then
return 1.5
else
return fib(n-1) + fib(n-2)
end
end
print(fib(37.2))

View File

@ -1,7 +0,0 @@
def fib(n):
if n < 2:
return 1.5
else:
return fib(n-1) + fib(n-2)
print(fib(37.2))

View File

@ -1 +0,0 @@
nim c --gc:arc -d:danger --out:nds main

View File

@ -1 +0,0 @@
nim c --gc:arc -d:debug --out:nds main

25
nds.nimble Normal file
View File

@ -0,0 +1,25 @@
# Package
version = "0.1.0"
author = "prod2"
description = "A simple scripting language."
license = "Apache-2.0"
srcDir = "src"
skipDirs = @["tests", "examples"]
binDir = "bin"
installExt = @["nim"]
bin = @["nds"]
# Dependencies
requires "nim >= 1.6.2"
task test, "run tests":
exec "nim c --gc:arc -d:debug --skipProjCfg --skipParentCfg -r tests/test.nim"
exec "rm tests/test"
task debug, "build nds for debugging":
exec "nim c --gc:arc -d:debug --skipProjCfg --skipParentCfg --out:bin/nds src/nds.nim"
task profile, "build nds with internal profiler":
exec "nim c --gc:arc -d:danger -d:ndsprofile --out:bin/nds src/nds.nim"

View File

@ -1 +1 @@
# placeholder for IDEs
--gc:arc -d:danger

View File

@ -1,13 +1,10 @@
import vm
import compiler
import config
import ndspkg/vm
import ndspkg/compiler
import ndspkg/config
import os
import strformat
when compileTests:
import tests/hashtable
type Result = enum
rsOK, rsCompileError, rsRuntimeError
@ -41,13 +38,6 @@ proc runFile(path: string) =
of rsOK:
quit 0
proc runTests =
when compileTests:
testHashtables()
else:
echo "Nds was compiled without nim tests. Please change the flag and recompile, then tests will be available."
quit 1
proc printUsage =
echo """Usage:
- Start a repl: nds
@ -69,10 +59,6 @@ elif paramCount() == 1:
runFile(paramStr(1))
else:
case arg:
of "--test":
when defined(danger) or defined(release):
echo "WARNING: nds was compiled with -d:danger or -d:release, tests are only supported on -d:debug!"
runTests()
of "--help":
printUsage()
quit 0
@ -81,6 +67,7 @@ elif paramCount() == 1:
printUsage()
quit 1
else:
echo "Maximum param count is 1"
echo "Maximum param count is 1."
printUsage()
quit 1

View File

@ -11,11 +11,7 @@ const assertionsCompiler* = true # sanity checks in the compiler
# vm debug options (setting any to true will slow runtime down!)
const debugVM* = defined(debug)
const assertionsVM* = defined(debug) # sanity checks in the VM, such as the stack being empty at the end
const profileInstructions* = false # if true, the time spent on every opcode is measured
const compileTests* = defined(debug)
# if true, the nim part of the test suite will be compiled in main
# it will be possible to start it using ./nds --test
const profileInstructions* = defined(ndsprofile) # if true, the time spent on every opcode is measured
# choose a line editor for the repl
const lineEditor = leRdstdin

3
tests/test.nim Normal file
View File

@ -0,0 +1,3 @@
import hashtable
testHashtables()