new benchmark, constant reuse (to better fit in the constant limit)

This commit is contained in:
prod2 2022-02-05 05:52:45 +01:00
parent 05887323c0
commit af2f639ccc
6 changed files with 100041 additions and 4 deletions

4
.gitignore vendored
View File

@ -4,4 +4,6 @@ callgrind*
.vscode
bin/nds
*.lua
*.py
*.py
benchmarkgen
test

7
benchmarks/10m.nds Normal file
View File

@ -0,0 +1,7 @@
var x = 0;
while (x < 10000000)
x = x + 1
;
print x;

100002
benchmarks/assign_incr_100k.nds Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,13 @@
# generate some benchmarks
# generate assign_incr_100k
proc genAssignIncr100k =
let path = "assign_incr_100k.nds"
var src = "var x = 0;\n"
for i in countup(0, 99999):
src &= "x = x + 1;\n"
src &= "print x;\n"
path.writeFile(src)
genAssignIncr100k()

View File

@ -64,9 +64,22 @@ proc toInt*(du8: DoubleUint8): int =
proc DU8ptrToInt*(du8: ptr uint8): int =
cast[ptr uint16](du8)[].int
proc findConstant(ch: var Chunk, constant: NdValue): int =
if ch.constants.len() == 0:
return -1
for i in countup(0, ch.constants.high()):
let current = ch.constants[i]
if current == constant:
return i
return -1
proc addConstant*(ch: var Chunk, constant: NdValue): int =
ch.constants.add(constant)
ch.constants.high
let found = ch.findConstant(constant)
if found == -1:
ch.constants.add(constant)
ch.constants.high
else:
found
proc writeConstant*(ch: var Chunk, constant: NdValue, line: int): int =
result = ch.addConstant(constant)

View File

@ -49,7 +49,7 @@ type
Precedence = enum
pcNone, pcExprTop, pcAmpersand, pcAssignment, pcNonAssignTop, pcOr, pcAnd, pcEquality, pcComparison,
pcTerm, pcFactor, pcUnary, pcIndex, pcCall, pcPrimary
pcTerm, pcFactor, pcUnary, pcCall, pcIndex, pcPrimary
# pcUnary applies to all prefix operators regardless of this enum's value
# changing pcUnary's position can change the priority of all unary ops
#