new test, bugfix
This commit is contained in:
parent
9fdbb1dda6
commit
05887323c0
|
@ -0,0 +1 @@
|
||||||
|
ignoreme
|
|
@ -235,6 +235,7 @@ proc run*(chunk: Chunk): InterpretResult =
|
||||||
else:
|
else:
|
||||||
let start = stack.getIndexNeg(listLen - 1).addr
|
let start = stack.getIndexNeg(listLen - 1).addr
|
||||||
var list = newListCopymem[NdValue](start, listLen)
|
var list = newListCopymem[NdValue](start, listLen)
|
||||||
|
stack.deleteTopN(listLen)
|
||||||
stack.push(list.fromList())
|
stack.push(list.fromList())
|
||||||
of opCreateTable:
|
of opCreateTable:
|
||||||
let tblLen = readDU8()
|
let tblLen = readDU8()
|
||||||
|
@ -245,6 +246,7 @@ proc run*(chunk: Chunk): InterpretResult =
|
||||||
if tbl[].tableSet(key, val):
|
if tbl[].tableSet(key, val):
|
||||||
runtimeError("Attempt to redefine an existing value inside table declaration.")
|
runtimeError("Attempt to redefine an existing value inside table declaration.")
|
||||||
break
|
break
|
||||||
|
stack.deleteTopN(tblLen * 2)
|
||||||
stack.push(tbl.fromTable())
|
stack.push(tbl.fromTable())
|
||||||
of opLen:
|
of opLen:
|
||||||
let res = stack.peek().getLength()
|
let res = stack.peek().getLength()
|
||||||
|
|
|
@ -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()();
|
|
@ -0,0 +1,9 @@
|
||||||
|
// a test about collections, WIP
|
||||||
|
|
||||||
|
var returnlist = funct() {
|
||||||
|
:result = @[1, 2, 3, 4];
|
||||||
|
};
|
||||||
|
|
||||||
|
//expect:3.0
|
||||||
|
print returnlist()[2];
|
||||||
|
|
|
@ -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();
|
Loading…
Reference in New Issue