Merge pull request #34 from Productive2/master

Fix #25 and test suite for longs
This commit is contained in:
Mattia 2021-01-16 14:28:26 +01:00 committed by GitHub
commit c45145b3b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 13555 additions and 2 deletions

1
.gitignore vendored
View File

@ -14,6 +14,7 @@ src/japl
src/compiler
tests/runtests
tests/maketest
tests/makelongtests
src/lexer
src/vm
tests/runtests

View File

@ -35,7 +35,7 @@ type
proc toStr*(obj: ptr Obj): string =
## Converts a JAPL string into a nim string
var strObj = cast[ptr String](obj)
for i in 0..strObj.str.len - 1:
for i in 0..strObj.len - 1:
result.add(strObj.str[i])
@ -43,7 +43,7 @@ proc hash*(self: ptr String): uint64 =
## Implements the FNV-1a hashing algorithm
## for strings
result = 2166136261u
for i in countup(0, self.len):
for i in countup(0, self.len-1):
result = result xor uint64(self.str[i])
result *= 16777619

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

124
tests/makelongtests.nim Normal file
View File

@ -0,0 +1,124 @@
# TO BE RUN FROM /tests
import random, os, strformat, tables
# simple: lots of globals assigned to random vals
# then they are read
let longTestsPath = "japl" / "longs"
let test1Path = longTestsPath / "globAssgnRead.jpl"
if not test1Path.fileExists():
const varcount = 1000
const readcount = 500
var test1: string
var vars: Table[string, int]
for i in countup(0,varcount):
let varname = "a" & $i
let value = rand(10000)
test1 &= &"var {varname} = {value};\n"
vars[varname] = value
for i in countup(1,readcount):
let which = "a" & $rand(varcount)
let value = vars[which]
test1 &= &"print({which});//output:{value}\n"
writeFile(test1Path, test1)
# locals
# same as above but for locals
let test2Path = longTestsPath / "locAssgnRead.jpl"
if not test2Path.fileExists():
const varcount = 1000
const readcount = 500
var test2: string = "{\n"
var vars: Table[string, int]
for i in countup(0,varcount):
let varname = "a" & $i
let value = rand(10000)
test2 &= &"var {varname} = {value};\n"
vars[varname] = value
for i in countup(1,readcount):
let which = "a" & $rand(varcount)
let value = vars[which]
test2 &= &"print({which});//output:{value}\n"
test2 &= "}"
writeFile(test2Path, test2)
let test3Path = longTestsPath / "globWithSets.jpl"
if not test3Path.fileExists():
const varcount = 1000
const readcount = 500
const setcount = 2500
var test3: string = ""
var vars: Table[string, int]
for i in countup(0,varcount):
let varname = "a" & $i
let value = rand(10000)
test3 &= &"var {varname} = {value};\n"
vars[varname] = value
for i in countup(1, setcount):
let which = "a" & $rand(varcount)
let newval = rand(4500)
# sometimes test the old
if rand(50) > 25:
test3 &= &"print({which});//output:{vars[which]}\n"
vars[which] = newval
test3 &= &"{which} = {newval};\n"
for i in countup(1,readcount):
let which = "a" & $rand(varcount)
let value = vars[which]
test3 &= &"print({which});//output:{value}\n"
writeFile(test3Path, test3)
let test4Path = longTestsPath / "locWithSets.jpl"
if not test4Path.fileExists():
const varcount = 1000
const readcount = 500
const setcount = 2500
var test4: string = "{\n"
var vars: Table[string, int]
for i in countup(0,varcount):
let varname = "a" & $i
let value = rand(10000)
test4 &= &"var {varname} = {value};\n"
vars[varname] = value
for i in countup(1, setcount):
let which = "a" & $rand(varcount)
let newval = rand(4500)
# sometimes test the old
if rand(50) > 25:
test4 &= &"print({which});//output:{vars[which]}\n"
vars[which] = newval
test4 &= &"{which} = {newval};\n"
for i in countup(1,readcount):
let which = "a" & $rand(varcount)
let value = vars[which]
test4 &= &"print({which});//output:{value}\n"
test4 &= "}"
writeFile(test4Path, test4)