new test, bugfix

This commit is contained in:
prod2 2022-02-05 03:24:30 +01:00
parent 9fdbb1dda6
commit 05887323c0
5 changed files with 79 additions and 0 deletions

1
bin/.placeholder Normal file
View File

@ -0,0 +1 @@
ignoreme

View File

@ -235,6 +235,7 @@ proc run*(chunk: Chunk): InterpretResult =
else:
let start = stack.getIndexNeg(listLen - 1).addr
var list = newListCopymem[NdValue](start, listLen)
stack.deleteTopN(listLen)
stack.push(list.fromList())
of opCreateTable:
let tblLen = readDU8()
@ -245,6 +246,7 @@ proc run*(chunk: Chunk): InterpretResult =
if tbl[].tableSet(key, val):
runtimeError("Attempt to redefine an existing value inside table declaration.")
break
stack.deleteTopN(tblLen * 2)
stack.push(tbl.fromTable())
of opLen:
let res = stack.peek().getLength()

32
tests/closures.nds_d Normal file
View File

@ -0,0 +1,32 @@
//_d so the test doesn't run yet
// capturing closures in lists:
var f = funct() {
var y = 5;
var x = @[
funct() print y,
funct() y = y + 1
];
:result = x;
};
//expect:5.0
f()[0]();
f()[1]();
//expect:6.0
f()[0]();
// capturing the result of a function:
var f2 = funct() {
var x = { @f2
:result = funct() {
print :f2;
};
};
x = 5;
};
//expect:5.0
f2()();

9
tests/collections.nds Normal file
View File

@ -0,0 +1,9 @@
// a test about collections, WIP
var returnlist = funct() {
:result = @[1, 2, 3, 4];
};
//expect:3.0
print returnlist()[2];

35
tests/precedence.nds Normal file
View File

@ -0,0 +1,35 @@
// test for testing the relative precedence of expressions
// groupings
//expect:15.0
print 5 * (1 + 2);
//expect:11.0
print (5 * 2) + 1;
//expect:-9.0
print -((3 + 2) * 2) + 1;
// calls
// calls and indexes
var returnlist = funct() {
:result = @[];
:result[0] = 4;
:result[1] = 6;
:result[2] = 5;
:result[3] = 7;
};
//expect:5.0
print returnlist()[2];
// priority over unary
var truesayer = funct() {
:result = true;
};
//expect:false
print !truesayer();