version 0.7.0

This commit is contained in:
Andreas Rumpf
2008-11-16 22:08:15 +01:00
parent 972c510861
commit 8b2a9401a1
185 changed files with 21451 additions and 24296 deletions

View File

@@ -148,8 +148,7 @@ proc main() =
# Create long-lived array, filling half of it
echo(" Creating a long-lived array of " & $kArraySize & " doubles")
myarray = []
setlength(myarray, kArraySize)
newSeq(myarray, kArraySize)
for i in 0..kArraySize div 2 -1:
myarray[i] = 1.0 / toFloat(i)

View File

@@ -38,13 +38,13 @@ proc newCaseNode(data: string): PCaseNode =
result.data = data
else:
result.kind = nkWhole
result.unused = ["", "abc", "abdc"]
result.unused = @["", "abc", "abdc"]
flip = 1 - flip
proc newCaseNode(a, b: PCaseNode): PCaseNode =
new(result)
result.kind = nkList
result.sons = [a, b]
result.sons = @[a, b]
proc caseTree(lvl: int = 0): PCaseNode =
if lvl == 3: result = newCaseNode("data item")
@@ -53,6 +53,7 @@ proc caseTree(lvl: int = 0): PCaseNode =
proc finalizeBNode(n: TBNode) = writeln(stdout, n.data)
proc finalizeNode(n: PNode) =
assert(n != nil)
write(stdout, "finalizing: ")
if isNil(n.data): writeln(stdout, "nil!")
else: writeln(stdout, n.data)
@@ -101,17 +102,17 @@ proc unsureNew(result: var PNode) =
new(result, finalizeNode)
result.data = $id
new(result.le, finalizeNode)
result.le.data = $id & ".1"
result.le.data = $id & ".a"
new(result.ri, finalizeNode)
result.ri.data = $id & ".2"
result.ri.data = $id & ".b"
inc(id)
proc setSons(n: var TBNode) =
n.sons = [] # free memory of the sons
n.t.data = []
n.sons = @[] # free memory of the sons
n.t.data = @[]
var
m: seq[string]
m = []
m = @[]
setLen(m, len(n.t.data) * 2)
for i in 0..high(m):
m[i] = "..."
@@ -120,16 +121,17 @@ proc setSons(n: var TBNode) =
proc buildBTree(father: var TBNode) =
father.data = "father"
father.other = nil
father.sons = []
father.sons = @[]
for i in 1..10:
write(stdout, "next iteration!\n")
var n: TBNode
n.other = returnTree()
n.data = "B node: " & $i
if i mod 1 == 0: n.sons = [] # nil and [] need to be handled correctly!
if i mod 2 == 0: n.sons = @[] # nil and [] need to be handled correctly!
add father.sons, n
father.t.counter = 0
father.t.max = 3
father.t.data = ["ha", "lets", "stress", "it"]
father.t.data = @["ha", "lets", "stress", "it"]
setSons(father)
proc main() =
@@ -148,7 +150,7 @@ proc main() =
t2 = buildTree()
printTree(t2)
write(stdout, "now test sequences of strings:")
var s: seq[string] = []
var s: seq[string] = @[]
for i in 1..100:
add s, "hohoho" # test reallocation
writeln(stdout, s[89])
@@ -157,15 +159,22 @@ proc main() =
#main()
#GC_disable()
writeln(stdout, repr(caseTree()))
var
father: TBNode
buildBTree(father)
write(stdout, repr(father))
s: string
s = ""
s = ""
writeln(stdout, repr(caseTree()))
father.t.data = @["ha", "lets", "stress", "it"]
father.t.data = @["ha", "lets", "stress", "it"]
var t = buildTree()
write(stdout, repr(t^))
buildBTree(father)
write(stdout, repr(father))
write(stdout, "starting main...\n")
main()
write(stdout, "finished\n")
GC_fullCollect()
GC_fullCollect()
write(stdout, GC_getStatistics())

View File

@@ -2,6 +2,7 @@ import mambsym2 # import TExport
type
TExport* = enum x, y, z
TOtherEnum* = enum mDec, mInc, mAssign
proc ha() =
var

View File

@@ -1,2 +1,3 @@
type
TExport* = enum x, y, z # exactly the same type!
TExport* = enum a, b, c

View File

@@ -4,3 +4,5 @@ import mambsym1, mambsym2
var
v: TExport #ERROR_MSG ambigious identifier
v = y

View File

@@ -7,14 +7,14 @@ type
proc sum(a: TMyarray): int =
result = 0
var i = 0
while i < length(a):
while i < len(a):
inc(result, a[i])
inc(i)
proc sum(a: openarray[int]): int =
result = 0
var i = 0
while i < length(a):
while i < len(a):
inc(result, a[i])
inc(i)

View File

@@ -6,8 +6,8 @@ proc putEnv(key, val: string) =
# documentation)
var
env: ptr array[0..500000, char]
env = alloc(length(key) + length(val) + 2)
for i in 0..length(key)-1: env[i] = key[i]
env[length(key)] = '='
for i in 0..length(val)-1:
env[length(key)+1+i] = val[i]
env = cast[ptr array[0..500000, char]](alloc(len(key) + len(val) + 2))
for i in 0..len(key)-1: env[i] = key[i]
env[len(key)] = '='
for i in 0..len(val)-1:
env[len(key)+1+i] = val[i]

View File

@@ -14,14 +14,14 @@ proc test() =
a.x = 1
a.y = 2
a.s = "Hallo!"
a.seq = ["abc", "def", "ghi", "jkl"]
a.arr = []
a.seq = @["abc", "def", "ghi", "jkl"]
a.arr = @[]
setLen(a.arr, 4)
a.arr[0] = []
a.arr[1] = []
a.arr[0] = @[]
a.arr[1] = @[]
b = a # perform a deep copy here!
b.seq = ["xyz", "huch", "was", "soll"]
b.seq = @["xyz", "huch", "was", "soll"]
writeln(stdout, len(a.seq))
writeln(stdout, a.seq[3])
writeln(stdout, len(b.seq))

View File

@@ -3,9 +3,8 @@
proc main =
block endLess:
break endLess
write(stdout, "Muaahh!\N")
break endLess
break ha #ERROR

View File

@@ -5,23 +5,19 @@ type
s: string,
x, y: int,
z: float,
chars: set[Char]
]
chars: set[Char]]
proc testSem =
var
things: array [0..1, TComplexRecord] = [
(chars: {'a', 'b', 'c'}, s: "hi", x: 69, y: 45, z: 0.0),
(chars: {'a', 'b', 'c'}, s: "hi", x: 69, y: 45, z: 1.0)
]
(s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}),
(s: "hi", x: 69, y: 45, z: 1.0, chars: {'a', 'b', 'c'})]
write(stdout, things[0].x)
const
things: array [0..] of TComplexRecord = [
(chars: {'a', 'b', 'c'}, s: "hi", x: 69, y: 45, z: 0.0),
(chars: {'a', 'b', 'c'}, s: "hi", x: 69, y: 45) #ERROR
]
things: array [0..1, TComplexRecord] = [
(s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}),
(s: "hi", x: 69, y: 45, z: 1.0)] #ERROR
otherThings = [ # the same
(chars: {'a', 'b', 'c'}, s: "hi", x: 69, y: 45, z: 0.0),
(chars: {'a', 'b', 'c'}, s: "hi", x: 69, y: 45)
]
(s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}),
(s: "hi", x: 69, y: 45, z: 1.0, chars: {'a'})]

View File

@@ -5,16 +5,15 @@ type
s: string,
x, y: int,
z: float,
chars: set[char],
]
chars: set[char]]
const
things: array [0.., TComplexRecord] = [
(chars: {'a', 'b', 'c'}, s: "hi", x: 69, y: 45, z: 0.0),
(chars: {'a', 'b', 'c'}, s: "hi", x: 69, z: 0.3, y: 45)]
things: array [0..1, TComplexRecord] = [
(s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}),
(s: "hi", x: 69, y: 45, z: 1.0, chars: {})]
otherThings = [ # the same
(chars: {'a', 'b', 'c'}, s: "hi", x: 69, y: 45, z: 0.0),
(z: 0.0, chars: {'a', 'b', 'c'}, s: "hi", x: 69, y: 45)]
(s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}),
(s: "hi", x: 69, y: 45, z: 1.0, chars: {'a'})]
write(stdout, things[0].x)
#OUT 69

View File

@@ -3,28 +3,20 @@
{.push dynlib: "SDL.dll", callconv: cdecl.}
when defined(windows):
type
PSDL_semaphore = ptr TSDL_semaphore
TSDL_semaphore {.final.} = object
id: uint32
count: UInt32
elif defined(linux):
type
PSDL_semaphore = ptr TSDL_semaphore
TSDL_semaphore {.final.} = object
sem: Pointer #PSem_t;
when not defined(USE_NAMED_SEMAPHORES):
sem_data: int
when defined(BROKEN_SEMGETVALUE):
# This is a little hack for MacOS X -
# It's not thread-safe, but it's better than nothing
sem_value: cint
type
PSDL_semaphore = ptr TSDL_semaphore
TSDL_semaphore {.final.} = object
sem: Pointer #PSem_t;
when not defined(USE_NAMED_SEMAPHORES):
sem_data: int
when defined(BROKEN_SEMGETVALUE):
# This is a little hack for MacOS X -
# It's not thread-safe, but it's better than nothing
sem_value: cint
type
PSDL_Sem = ptr TSDL_Sem
TSDL_Sem = TSDL_Semaphore
proc SDL_CreateSemaphore(initial_value: UInt32): PSDL_Sem
{.import: "SDL_CreateSemaphore".}
proc SDL_CreateSemaphore(initial_value: Int32): PSDL_Sem {.
importc: "SDL_CreateSemaphore".}

View File

@@ -42,7 +42,7 @@ var `name` = readLine(stdin)
echo("Hi " & thallo.name & "!\n")
debug(name)
var testseq: seq[string] = [ "a", "b", "c", "d"]
var testseq: seq[string] = @[ "a", "b", "c", "d", "e"]
echo(repr(testseq))
var dummy = "hallo"

View File

@@ -5,8 +5,6 @@ type
x: int
kids: seq[TLegal]
TIllegal {.final.} = object
TIllegal {.final.} = object #ERROR_MSG illegal recursion in type 'TIllegal'
y: Int
x: array[0..3, TIllegal]
#ERROR_MSG illegal recursion in type 'TIllegal'

View File

@@ -1,8 +1,8 @@
# This was parsed even though it should not!
proc chdir(path: CString): cint {.import: "chdir", header: "dirHeader".}
proc chdir(path: CString): cint {.importc: "chdir", header: "dirHeader".}
proc getcwd(buf: CString, buflen: cint): CString
when defined(unix): {.import: "getcwd", header: "<unistd.h>".} #ERROR
elif defined(windows): {.import: "getcwd", header: "<direct.h>"}
when defined(unix): {.importc: "getcwd", header: "<unistd.h>".} #ERROR_MSG invalid indentation
elif defined(windows): {.importc: "getcwd", header: "<direct.h>"}
else: {.error: "os library not ported to your OS. Please help!".}

View File

@@ -1,15 +1,13 @@
# Test the new iterators
iterator xrange(fromm, to: int, step = 1): (a: int) =
a = fromm
iterator xrange(fromm, to: int, step = 1): int =
var a = fromm
while a <= to:
yield a
inc(a, step)
iterator interval[T](a, b: T): (x: T)
iterator interval[T](a, b: T): (x: T) =
x = a
iterator interval[T](a, b: T): T =
var x = a
while x <= b:
yield x
inc(x)

View File

@@ -1,16 +1,18 @@
# test the new LastModificationTime() proc
import
os, times
os, times, strutils
proc main() =
var
a, b: TTime
a = getLastModificationTime(ParamStr(1))
b = getLastModificationTime(ParamStr(2))
writeln(stdout, $a)
writeln(stdout, $b)
if a < b:
Write(stdout, "b is newer than a\n")
Write(stdout, "$2 is newer than $1\n" % [ParamStr(1), ParamStr(2)])
else:
Write(stdout, "a is newer than b\n")
Write(stdout, "$1 is newer than $2\n" % [ParamStr(1), ParamStr(2)])
main()

View File

@@ -1,6 +1,6 @@
# tests for the interpreter
proc loops(a: out int) =
proc loops(a: var int) =
nil
#var
# b: int
@@ -81,9 +81,5 @@ proc main() =
of "Rumpf": write(stdout, "Du bist in der Familie meines Meisters!\n")
else: write(stdout, "ich kenne dich nicht!\n")
write(stdout, "Du heisst " & s & "\n")
# [[
proc main2() =
main()
main()
#]]

View File

@@ -3,4 +3,4 @@
var
a: int
a() #ERROR
a() #ERROR_MSG expression cannot be called

View File

@@ -7,7 +7,7 @@ type
TPoint3d = object of TPoint2d
z: int # added a field
proc getPoint(var p: TPoint2d) =
proc getPoint( p: var TPoint2d) =
{.breakpoint.}
writeln(stdout, p.x)

View File

@@ -2,13 +2,14 @@ type
TBase = object
x, y: int
TSubclassKind = enum ka, kb, kc, kd, ke, kf
TSubclass = object of TBase
c: int
case c
of 0, 1, 2, 3:
case c: TSubclassKind
of ka, kb, kc, kd:
a, b: int
of 4:
of ke:
d, e, f: char
else: nil
n: bool
var
@@ -21,25 +22,21 @@ var
case i
of 500..999: write(stdout, "ha!\n")
of 1000..3000, 12: write(stdout, "ganz sch<EFBFBD>n gro<EFBFBD>\n")
of 1000..3000, 12: write(stdout, "ganz schön groß\n")
of 1, 2, 3: write(stdout, "1 2 oder 3\n")
else: write(stdout, "sollte nicht passieren\n")
case r
of 0.0, 0.125..0.4444: write(stdout, "kleiner als 0.5\n")
else: write(stdout, "wei<EFBFBD> nicht\n")
case readLine(stdin)
of "Rumpf": write(stdout, "Hallo Meister!\n")
of "Andreas": write(stdout, "Hallo Meister!\n")
else: write(stdout, "Nicht mein Meister!\n")
global = global + 1
write(stdout, "Hallo wie hei<EFBFBD>t du? \n")
write(stdout, "Hallo wie heißt du? \n")
s = readLine(stdin)
i = 0
while i < length(s):
while i < len(s):
if s[i] == 'c': write(stdout, "'c' in deinem Namen gefunden\n")
i = i + 1
write(stdout, "Du hei<EFBFBD>t " & s)
write(stdout, "Du heißt " & s)

View File

@@ -2,13 +2,6 @@
# Used command line arguments:
# -m -q -o bootstrap\options.mor options.pas
#
#
# The Morpork Compiler
# (c) Copyright 2004 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
type
# please make sure we have under 32 options (improves code efficiency!)
@@ -26,4 +19,4 @@ var
gOptions: TOptionset = {optRefcGC, optRangeCheck, optBoundsCheck,
optOverflowCheck, optAssert, optWarns, optHints, optLineDir, optStackTrace}
compilerArgs: int
gExitcode: uint8
gExitcode: int8

View File

@@ -1,7 +1,6 @@
# Test for overloading
type
TNone {.export: "_NONE", final.} = object
TNone {.exportc: "_NONE", final.} = object
proc
TNone(a, b: int) = nil #ERROR_MSG attempt to redefine 'TNone'
proc TNone(a, b: int) = nil #ERROR_MSG attempt to redefine 'TNone'

View File

@@ -1,6 +1,6 @@
# Test operator overloading
proc % (a, b: int): int =
proc `%` (a, b: int): int =
return a mod b
var x, y: int

View File

@@ -1,6 +1,6 @@
# Test the overloading resolution in connection with a qualifier
proc write(t: tTextFile, s: string) =
proc write(t: TFile, s: string) =
nil # a nop
system.write(stdout, "hallo")

View File

@@ -1,11 +1,11 @@
import
os, parsecfg, strutils
os, parsecfg, strutils, streams
var
p: TCfgParser
if open(p, paramStr(1)):
var f = newFileStream(paramStr(1), fmRead)
if f != nil:
var p: TCfgParser
open(p, f, paramStr(1))
while true:
var e = next(p)
case e.kind

View File

@@ -1,6 +1,6 @@
# Test a printf proc
proc printf(file: TTextFile, args: openarray[string]) =
proc printf(file: TFile, args: openarray[string]) =
var i = 0
while i < args.len:
write(file, args[i])

View File

@@ -31,7 +31,7 @@ proc searchInner(r: PRadixNode, a: int): PRadixNode =
case r.kind
of rnLinear:
var x = cast[ptr TRadixNodeLinear](r)
for i in 0..x.len-1:
for i in 0..ze(x.len)-1:
if ze(x.keys[i]) == a: return x.vals[i]
of rnFull:
var x = cast[ptr TRadixNodeFull](r)
@@ -59,7 +59,7 @@ proc searchLeaf(r: PRadixNode, a: int): bool =
return testBit(x.b[a /% BitsPerUnit], a)
of rnLeafLinear:
var x = cast[ptr TRadixNodeLeafLinear](r)
for i in 0..x.len-1:
for i in 0..ze(x.len)-1:
if ze(x.keys[i]) == a: return true
else: assert(false)
@@ -103,7 +103,7 @@ proc addLeaf(r: var PRadixNode, a: int): bool =
# a linear node:
var x = cast[ptr TRadixNodeLinear](alloc(sizeof(TRadixNodeLinear)))
x.kind = rnLeafLinear
x.len = 1
x.len = 1'i8
x.keys[0] = toU8(a)
r = x
return false # not already in set
@@ -123,7 +123,7 @@ proc addLeaf(r: var PRadixNode, a: int): bool =
# transform into a full node:
var y = cast[ptr TRadixNodeLeafBits](alloc0(sizeof(TRadixNodeLeafBits)))
y.kind = rnLeafBits
for i in 0..x.len-1:
for i in 0..ze(x.len)-1:
var u = ze(x.keys[i])
setBit(y.b[u /% BitsPerUnit], u)
setBit(y.b[a /% BitsPerUnit], a)
@@ -139,7 +139,7 @@ proc addInner(r: var PRadixNode, a: int, d: int): bool =
# a linear node:
var x = cast[ptr TRadixNodeLinear](alloc(sizeof(TRadixNodeLinear)))
x.kind = rnLinear
x.len = 1
x.len = 1'i8
x.keys[0] = toU8(k)
r = x
return addInner(x.vals[0], a, d-8)

View File

@@ -2,7 +2,7 @@
# Macintosh, Unix or Windows text format.
var
inp: tTextFile
inp: TFile
line: string
if openFile(inp, "readme.txt"):

View File

@@ -4,7 +4,7 @@
import
regexprs
if "Username" =~ "[A-Za-z]+":
if "Username".match("[A-Za-z]+"):
echo("Yes!")
else:
echo("Bug!")

View File

@@ -1,12 +1,13 @@
# test the new "repr" built-in proc
type
TEnum = enum
en1, en2, en3, en4, en5, en6
TPoint {.final.} = object
x, y, z: int
s: array [0..1, string]
TEnum = enum
en1, en2, en3, en4, en5, en6
e: TEnum
var
p: TPoint
@@ -18,14 +19,14 @@ p.y = 13
p.z = 45
p.s[0] = "abc"
p.s[1] = "xyz"
p.e = en6
new(q)
q^ = p
s = [q, q, q, q]
s = @[q, q, q, q]
writeln(stdout, repr(p))
writeln(stdout, repr(q))
writeln(stdout, repr(s))
writeln(stdout, repr(nil))
writeln(stdout, repr(en4))

View File

@@ -1,4 +1,7 @@
# Test the &= operator for sequences and strings
# Test the add proc for sequences and strings
const
nestedFixed = true
type
TRec {.final.} = object
@@ -8,36 +11,35 @@ type
TRecSeq = seq[TRec]
proc test() =
var seq, b: seq[string]
seq = []
add(seq, "Hi")
add(seq, "there, ")
add(seq, "what's your name?")
var s, b: seq[string]
s = @[]
add(s, "Hi")
add(s, "there, ")
add(s, "what's your name?")
b = seq # deep copying here!
b = s # deep copying here!
b[0][1] = 'a'
for i in 0 .. length(seq)-1:
write(stdout, seq[i])
for i in 0 .. length(b)-1:
for i in 0 .. len(s)-1:
write(stdout, s[i])
for i in 0 .. len(b)-1:
write(stdout, b[i])
when defined(nestedFixed):
when nestedFixed:
proc nested() =
var
seq: seq[seq[string]]
s: seq[seq[string]]
for i in 0..10_000: # test if the garbage collector
# now works with sequences
seq = [
["A", "B", "C", "D"],
["E", "F", "G", "H"],
["I", "J", "K", "L"],
["M", "N", "O", "P"]
]
s = @[
@["A", "B", "C", "D"],
@["E", "F", "G", "H"],
@["I", "J", "K", "L"],
@["M", "N", "O", "P"]]
test()
when defined(nestedFixed):
when nestedFixed:
nested()
#OUT Hithere, what's your name?Hathere, what's your name?

View File

@@ -1,5 +1,5 @@
# no statement after return
proc main() =
return
nil #ERROR
echo("huch?") #ERROR_MSG statement not allowed after

View File

@@ -1,3 +1,3 @@
# Test 3
true #ERROR_MSG statement has no effect
1+4 #ERROR_MSG value returned by statement has to be discarded

View File

@@ -9,6 +9,6 @@ type
data: array [0..0, char] # for the '\0' character
var
emptyString {.export: "emptyString".}: TStringDesc
emptyString {.exportc: "emptyString".}: TStringDesc

View File

@@ -1,26 +1,26 @@
# compute the edit distance between two strings
proc editDistance(a, b: string): int =
var c: seq[int] = []
var
n = a.len
m = b.len
setLength(c, (n+1)*(m+1))
for i in 0..n:
c[i*n] = i # [i,0]
for j in 0..m:
c[j] = j # [0,j]
for i in 1..n:
for j in 1..m:
var x = c[(i-1)*n + j]+1
var y = c[i*n + j-1]+1
var z: int
if a[i-1] == b[j-1]:
z = c[(i-1)*n + j-1]
else:
z = c[(i-1)*n + j-1]+1
c[(i-1)*n + (j-1)] = min(x,min(y,z))
return c[n*m]
write(stdout, editDistance("abc", "abd"))
# compute the edit distance between two strings
proc editDistance(a, b: string): int =
var
c: seq[int]
n = a.len
m = b.len
newSeq(c, (n+1)*(m+1))
for i in 0..n:
c[i*n] = i # [i,0]
for j in 0..m:
c[j] = j # [0,j]
for i in 1..n:
for j in 1..m:
var x = c[(i-1)*n + j]+1
var y = c[i*n + j-1]+1
var z: int
if a[i-1] == b[j-1]:
z = c[(i-1)*n + j-1]
else:
z = c[(i-1)*n + j-1]+1
c[(i-1)*n + (j-1)] = min(x,min(y,z))
return c[n*m]
write(stdout, editDistance("abc", "abd"))

View File

@@ -2,7 +2,7 @@
type
TRadixNodeKind = enum rnLinear, rnFull, rnLeaf
PRadixNode = ptr TRadixNode
PRadixNode = ref TRadixNode
TRadixNode = object
kind: TRadixNodeKind
TRadixNodeLinear = object of TRadixNode
@@ -24,7 +24,7 @@ proc search(r: PRadixNode, s: string): PRadixNode =
case r.kind
of rnLinear:
var x = PRadixNodeLinear(r)
for j in 0..x.len-1:
for j in 0..ze(x.len)-1:
if x.keys[j] == s[i]:
if s[i] == '\0': return r
r = x.vals[j]
@@ -56,21 +56,19 @@ proc testOrincl*(r: var PRadixNode, s: string): bool =
proc incl*(r: var PRadixNode, s: string) = discard testOrIncl(r, s)
proc excl*(r: var PRadixNode, s: string) =
x = search(r, s)
var x = search(r, s)
if x == nil: return
case x.kind
of rnLeaf: PRadixNodeLeaf(x).s = ""
of rnFull: PRadixNodeFull(x).b['\0'] = nil
of rnLinear:
var x = PRadixNodeLinear(x)
for i in 0..x.len-1:
for i in 0..ze(x.len)-1:
if x.keys[i] == '\0':
swap(x.keys[i], x.keys[x.len-1])
swap(x.keys[i], x.keys[ze(x.len)-1])
dec(x.len)
break
var
root: PRadixNode

View File

@@ -11,6 +11,14 @@ proc main() =
for p in split("/home/a1:xyz:/usr/bin", {':'}):
write(stdout, p)
assert(editDistance("prefix__hallo_suffix", "prefix__hallo_suffix") == 0)
assert(editDistance("prefix__hallo_suffix", "prefix__hallo_suffi1") == 1)
assert(editDistance("prefix__hallo_suffix", "prefix__HALLO_suffix") == 5)
assert(editDistance("prefix__hallo_suffix", "prefix__ha_suffix") == 3)
assert(editDistance("prefix__hallo_suffix", "prefix") == 14)
assert(editDistance("prefix__hallo_suffix", "suffix") == 14)
assert(editDistance("prefix__hallo_suffix", "prefix__hao_suffix") == 2)
main()
#OUT ha/home/a1xyz/usr/bin

View File

@@ -3,4 +3,4 @@
import
times
write(stdout, TimeToString(getTime()) )
write(stdout, $getTime())

View File

@@ -3,4 +3,7 @@
var
x = 0
s = "Hallo"
a, b: int = 0 #ERROR
a, b: int = 4
write(stdout, a)
write(stdout, b) #OUT 44

View File

@@ -6,7 +6,7 @@ import
type
TBuffer = array [0..10, int8]
proc toVarNum(x: int32, b: out TBuffer) =
proc toVarNum(x: int32, b: var TBuffer) =
# encoding: first bit indicates end of number (0 if at end)
# second bit of the first byte denotes the sign (1 --> negative)
var a = x
@@ -18,15 +18,15 @@ proc toVarNum(x: int32, b: out TBuffer) =
# anyway
a = abs(x)
# first 6 bits:
b[0] = toU8(ord(a >% 63) shl 7 or (ord(x < 0) shl 6) or (a and 63))
a = a shr 6 # skip first 6 bits
b[0] = toU8(ord(a >% 63'i32) shl 7 or (ord(x < 0'i32) shl 6) or (int(a) and 63))
a = a shr 6'i32 # skip first 6 bits
var i = 1
while a != 0:
b[i] = toU8(ord(a >% 127) shl 7 or (a and 127))
while a != 0'i32:
b[i] = toU8(ord(a >% 127'i32) shl 7 or (int(a) and 127))
inc(i)
a = a shr 7
a = a shr 7'i32
proc toVarNum64(x: int64, b: out TBuffer) =
proc toVarNum64(x: int64, b: var TBuffer) =
# encoding: first bit indicates end of number (0 if at end)
# second bit of the first byte denotes the sign (1 --> negative)
var a = x
@@ -38,20 +38,20 @@ proc toVarNum64(x: int64, b: out TBuffer) =
# anyway
a = abs(x)
# first 6 bits:
b[0] = toU8(ord(a >% 63) shl 7 or (ord(x < 0) shl 6) or int(a and 63))
b[0] = toU8(ord(a >% 63'i64) shl 7 or (ord(x < 0'i64) shl 6) or int(a and 63))
a = a shr 6 # skip first 6 bits
var i = 1
while a != 0:
b[i] = toU8(ord(a >% 127) shl 7 or int(a and 127))
while a != 0'i64:
b[i] = toU8(ord(a >% 127'i64) shl 7 or int(a and 127))
inc(i)
a = a shr 7
proc toNum64(b: TBuffer): int64 =
# treat first byte different:
result = ze(b[0]) and 63
result = ze64(b[0]) and 63
var
i = 0
Shift: int64 = 6
Shift = 6'i64
while (ze(b[i]) and 128) != 0:
inc(i)
result = result or ((ze64(b[i]) and 127) shl Shift)
@@ -69,17 +69,17 @@ proc toNum(b: TBuffer): int32 =
Shift = 6
while (ze(b[i]) and 128) != 0:
inc(i)
result = result or ((ze(b[i]) and 127) shl Shift)
result = result or int32((ze(b[i]) and 127) shl Shift)
inc(Shift, 7)
if (ze(b[0]) and (1 shl 6)) != 0: # sign bit set?
result = not result +% 1
result = not int(result) +% 1
# this is the same as ``- result``
# but gives no overflow error for low(int)
proc toBinary(x: int64): string =
result = newString(64)
for i in 0..63:
result[63-i] = chr((int32(x shr i) and 1) + ord('0'))
result[63-i] = chr((int(x shr i) and 1) + ord('0'))
proc t64(i: int64) =
var
@@ -133,4 +133,4 @@ tm(100_000)
tm(low(int32))
tm(high(int32))
writeln(stdout, "Success!")
writeln(stdout, "Success!") #OUT Success!

View File

@@ -1,2 +1,3 @@
type
Uint8 = Uint8
Uint8 = Uint8 #ERROR_MSG illegal recursion in type 'Uint8'