summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2013-11-25 13:06:11 +0100
committerAraq <rumpf_a@web.de>2013-11-25 13:06:11 +0100
commit4855055bca7f5b2900ac15ce0e5cae90c22fa7fa (patch)
tree19794ccc8ae9367fa94e8808021f1b313e431d65
parent52d1a637b95f7cea95ad6e9591a941ef1be113cb (diff)
parentb893bd074f9e90f517c3f84037f92f89ab6fbad3 (diff)
downloadNim-4855055bca7f5b2900ac15ce0e5cae90c22fa7fa.tar.gz
Merge branch 'master' of https://github.com/Araq/Nimrod
-rw-r--r--compiler/ast.nim2
-rw-r--r--compiler/extccomp.nim2
-rw-r--r--compiler/msgs.nim55
-rw-r--r--compiler/parser.nim15
-rw-r--r--compiler/sem.nim3
-rw-r--r--compiler/semdata.nim4
-rw-r--r--compiler/semexprs.nim30
-rw-r--r--compiler/semstmts.nim39
-rw-r--r--compiler/semtypes.nim3
-rw-r--r--compiler/sigmatch.nim68
-rw-r--r--compiler/types.nim28
-rw-r--r--doc/gc.txt2
-rw-r--r--doc/intern.txt7
-rw-r--r--doc/lib.txt2
-rw-r--r--doc/manual.txt47
-rw-r--r--doc/tut1.txt8
-rw-r--r--lib/packages/docutils/rst.nim10
-rw-r--r--lib/posix/posix.nim47
-rw-r--r--lib/pure/asyncio.nim29
-rw-r--r--lib/pure/base64.nim242
-rw-r--r--lib/pure/collections/LockFreeHash.nim581
-rw-r--r--lib/pure/collections/baseutils.nim41
-rw-r--r--lib/pure/collections/sequtils.nim69
-rw-r--r--lib/pure/ftpclient.nim3
-rw-r--r--lib/pure/httpserver.nim14
-rw-r--r--lib/pure/irc.nim8
-rw-r--r--lib/pure/mersenne.nim39
-rw-r--r--lib/pure/oids.nim6
-rw-r--r--lib/pure/osproc.nim94
-rw-r--r--lib/pure/scgi.nim10
-rw-r--r--lib/pure/sockets.nim97
-rw-r--r--lib/pure/times.nim3
-rw-r--r--lib/pure/unicode.nim30
-rw-r--r--lib/system.nim4
-rw-r--r--lib/system/alloc.nim15
-rw-r--r--lib/system/atomics.nim239
-rw-r--r--lib/system/gc.nim21
-rw-r--r--lib/system/gc2.nim3
-rw-r--r--lib/system/mmdisp.nim1
-rw-r--r--lib/windows/winlean.nim57
-rw-r--r--lib/wrappers/opengl/glx.nim34
-rw-r--r--lib/wrappers/openssl.nim4
-rw-r--r--lib/wrappers/x11/keysym.nim3407
-rw-r--r--lib/wrappers/x11/xlib.nim317
-rw-r--r--lib/wrappers/x11/xutil.nim84
-rw-r--r--lib/wrappers/zip/zlib.nim1
-rw-r--r--readme.md10
-rw-r--r--readme.txt10
-rw-r--r--tests/run/temit.nim4
-rw-r--r--tests/run/tstaticparams.nim9
-rw-r--r--tests/run/tusertypeclasses.nim28
-rw-r--r--tools/niminst/buildsh.tmpl2
52 files changed, 3526 insertions, 2362 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim
index 2a7d8a551..5a5d87d06 100644
--- a/compiler/ast.nim
+++ b/compiler/ast.nim
@@ -712,7 +712,6 @@ type
                               # -1 means that the size is unkwown
     align*: int               # the type's alignment requirements
     loc*: TLoc
-    testeeName*: PIdent       # the test variable in user-defined type classes
 
   TPair*{.final.} = object 
     key*, val*: PObject
@@ -1088,7 +1087,6 @@ proc assignType(dest, src: PType) =
   dest.size = src.size
   dest.align = src.align
   dest.destructor = src.destructor
-  dest.testeeName = src.testeeName
   # this fixes 'type TLock = TSysLock':
   if src.sym != nil:
     if dest.sym != nil:
diff --git a/compiler/extccomp.nim b/compiler/extccomp.nim
index d7f3386e3..13eb972f6 100644
--- a/compiler/extccomp.nim
+++ b/compiler/extccomp.nim
@@ -583,7 +583,7 @@ proc CallCCompiler*(projectfile: string) =
       else:
         rawMessage(errGenerated, " execution of an external program failed; " &
                    "rerun with --parallelBuild:1 to see the error message")
-  if optNoLinking notin gGlobalOptions and cmds.len > 0:
+  if optNoLinking notin gGlobalOptions:
     # call the linker:
     var it = PStrEntry(toLink.head)
     var objfiles = ""
diff --git a/compiler/msgs.nim b/compiler/msgs.nim
index 5363442b4..895ba71f3 100644
--- a/compiler/msgs.nim
+++ b/compiler/msgs.nim
@@ -436,7 +436,14 @@ type
                                # only 8 bytes.
     line*, col*: int16
     fileIndex*: int32
-    
+  
+  TErrorOutput* = enum
+    eStdOut
+    eStdErr
+    eInMemory
+
+  TErrorOutputs* = set[TErrorOutput]
+
   ERecoverableError* = object of EInvalidValue
   ESuggestDone* = object of EBase
 
@@ -534,13 +541,27 @@ var
   gHintCounter*: int = 0
   gWarnCounter*: int = 0
   gErrorMax*: int = 1         # stop after gErrorMax errors
-  gSilence*: int              # == 0 if we produce any output at all 
 
 when useCaas:
   var stdoutSocket*: TSocket
 
+proc UnknownLineInfo*(): TLineInfo =
+  result.line = int16(-1)
+  result.col = int16(-1)
+  result.fileIndex = -1
+
+var 
+  msgContext: seq[TLineInfo] = @[]
+  lastError = UnknownLineInfo()
+  bufferedMsgs*: seq[string]
+
+  errorOutputs* = {eStdOut, eStdErr}
+
+proc clearBufferedMsgs* =
+  bufferedMsgs = nil
+
 proc SuggestWriteln*(s: string) =
-  if gSilence == 0:
+  if eStdOut in errorOutputs:
     when useCaas:
       if isNil(stdoutSocket): Writeln(stdout, s)
       else:
@@ -548,6 +569,9 @@ proc SuggestWriteln*(s: string) =
         stdoutSocket.send(s & "\c\L")
     else:
       Writeln(stdout, s)
+  
+  if eInMemory in errorOutputs:
+    bufferedMsgs.safeAdd(s)
 
 proc SuggestQuit*() =
   if not isServing:
@@ -570,14 +594,6 @@ const
   RawWarningFormat* = "Warning: $1"
   RawHintFormat* = "Hint: $1"
 
-proc UnknownLineInfo*(): TLineInfo = 
-  result.line = int16(-1)
-  result.col = int16(-1)
-  result.fileIndex = -1
-
-var 
-  msgContext: seq[TLineInfo] = @[]
-
 proc getInfoContextLen*(): int = return msgContext.len
 proc setInfoContextLen*(L: int) = setLen(msgContext, L)
 
@@ -642,14 +658,18 @@ proc addCheckpoint*(filename: string, line: int) =
 
 proc OutWriteln*(s: string) = 
   ## Writes to stdout. Always.
-  if gSilence == 0: Writeln(stdout, s)
+  if eStdOut in errorOutputs: Writeln(stdout, s)
  
 proc MsgWriteln*(s: string) = 
   ## Writes to stdout. If --stdout option is given, writes to stderr instead.
-  if gSilence == 0:
-    if gCmd == cmdIdeTools and optCDebug notin gGlobalOptions: return
-    if optStdout in gGlobalOptions: Writeln(stderr, s)
-    else: Writeln(stdout, s)
+  if gCmd == cmdIdeTools and optCDebug notin gGlobalOptions: return
+
+  if optStdout in gGlobalOptions:
+    if eStdErr in errorOutputs: Writeln(stderr, s)
+  else:
+    if eStdOut in errorOutputs: Writeln(stdout, s)
+  
+  if eInMemory in errorOutputs: bufferedMsgs.safeAdd(s)
 
 proc coordToStr(coord: int): string = 
   if coord == -1: result = "???"
@@ -736,9 +756,6 @@ proc rawMessage*(msg: TMsgKind, args: openarray[string]) =
 proc rawMessage*(msg: TMsgKind, arg: string) = 
   rawMessage(msg, [arg])
 
-var
-  lastError = UnknownLineInfo()
-
 proc writeSurroundingSrc(info: TLineInfo) =
   const indent = "  "
   MsgWriteln(indent & info.sourceLine.ropeToStr)
diff --git a/compiler/parser.nim b/compiler/parser.nim
index e8439466a..fd51b04ec 100644
--- a/compiler/parser.nim
+++ b/compiler/parser.nim
@@ -1624,10 +1624,23 @@ proc parseObject(p: var TParser): PNode =
     return
   addSon(result, parseObjectPart(p))
 
+proc parseTypeClassParam(p: var TParser): PNode =
+  if p.tok.tokType == tkVar:
+    getTok(p)
+    result = newNode(nkVarTy)
+    result.addSon(p.parseSymbol)
+  else:
+    result = p.parseSymbol
+
 proc parseTypeClass(p: var TParser): PNode =
   result = newNodeP(nkTypeClassTy, p)
   getTok(p)
-  addSon(result, p.parseSymbol)
+  var args = newNode(nkArgList)
+  addSon(result, args)
+  addSon(args, p.parseTypeClassParam)
+  while p.tok.TokType == tkComma:
+    getTok(p)
+    addSon(args, p.parseTypeClassParam)
   if p.tok.tokType == tkCurlyDotLe and p.validInd:
     addSon(result, parsePragma(p))
   else:
diff --git a/compiler/sem.nim b/compiler/sem.nim
index 71951dd3f..ea53afbeb 100644
--- a/compiler/sem.nim
+++ b/compiler/sem.nim
@@ -36,7 +36,8 @@ proc semParamList(c: PContext, n, genericParams: PNode, s: PSym)
 proc addParams(c: PContext, n: PNode, kind: TSymKind)
 proc maybeAddResult(c: PContext, s: PSym, n: PNode)
 proc instGenericContainer(c: PContext, n: PNode, header: PType): PType
-proc tryExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode
+proc tryExpr(c: PContext, n: PNode,
+             flags: TExprFlags = {}, bufferErrors = false): PNode
 proc fixImmediateParams(n: PNode): PNode
 proc activate(c: PContext, n: PNode)
 proc semQuoteAst(c: PContext, n: PNode): PNode
diff --git a/compiler/semdata.nim b/compiler/semdata.nim
index 121bf297d..d02359d4c 100644
--- a/compiler/semdata.nim
+++ b/compiler/semdata.nim
@@ -60,6 +60,7 @@ type
     threadEntries*: TSymSeq    # list of thread entries to check
     AmbiguousSymbols*: TIntSet # ids of all ambiguous symbols (cannot
                                # store this info in the syms themselves!)
+    InTypeClass*: int          # > 0 if we are in a user-defined type class
     InGenericContext*: int     # > 0 if we are in a generic type
     InUnrolledContext*: int    # > 0 if we are unrolling a loop
     InCompilesContext*: int    # > 0 if we are in a ``compiles`` magic
@@ -72,7 +73,8 @@ type
     libs*: TLinkedList         # all libs used by this module
     semConstExpr*: proc (c: PContext, n: PNode): PNode {.nimcall.} # for the pragmas
     semExpr*: proc (c: PContext, n: PNode, flags: TExprFlags = {}): PNode {.nimcall.}
-    semTryExpr*: proc (c: PContext, n: PNode, flags: TExprFlags = {}): PNode {.nimcall.}
+    semTryExpr*: proc (c: PContext, n: PNode,flags: TExprFlags = {},
+                       bufferErrors = false): PNode {.nimcall.}
     semOperand*: proc (c: PContext, n: PNode, flags: TExprFlags = {}): PNode {.nimcall.}
     semConstBoolExpr*: proc (c: PContext, n: PNode): PNode {.nimcall.} # XXX bite the bullet
     semOverloadedCall*: proc (c: PContext, n, nOrig: PNode,
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index 47e07d402..337224aef 100644
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -299,7 +299,7 @@ proc semOf(c: PContext, n: PNode): PNode =
   n.typ = getSysType(tyBool)
   result = n
 
-proc IsOpImpl(c: PContext, n: PNode): PNode =
+proc isOpImpl(c: PContext, n: PNode): PNode =
   InternalAssert n.sonsLen == 3 and
     n[1].kind == nkSym and n[1].sym.kind == skType and
     n[2].kind in {nkStrLit..nkTripleStrLit, nkType}
@@ -321,10 +321,19 @@ proc IsOpImpl(c: PContext, n: PNode): PNode =
   else:
     var match: bool
     let t2 = n[2].typ
-    if t2.kind == tyTypeClass:
+    case t2.kind
+    of tyTypeClass:
       var m: TCandidate
       InitCandidate(m, t2)
       match = matchUserTypeClass(c, m, emptyNode, t2, t1) != nil
+    of tyOrdinal:
+      var m: TCandidate
+      InitCandidate(m, t2)
+      match = isOrdinalType(t1)
+    of tySequence, tyArray, tySet:
+      var m: TCandidate
+      InitCandidate(m, t2)
+      match = typeRel(m, t2, t1) != isNone
     else:
       match = sameType(t1, t2)
  
@@ -353,7 +362,7 @@ proc semIs(c: PContext, n: PNode): PNode =
 
   let t1 = n[1].typ.sons[0]
   # BUGFIX: don't evaluate this too early: ``T is void``
-  if not containsGenericType(t1): result = IsOpImpl(c, n)
+  if not containsGenericType(t1): result = isOpImpl(c, n)
 
 proc semOpAux(c: PContext, n: PNode) =
   const flags = {efDetermineType}
@@ -763,7 +772,8 @@ proc afterCallActions(c: PContext; n, orig: PNode, flags: TExprFlags): PNode =
     analyseIfAddressTakenInCall(c, result)
     if callee.magic != mNone:
       result = magicsAfterOverloadResolution(c, result, flags)
-  result = evalAtCompileTime(c, result)
+  if c.InTypeClass == 0:
+    result = evalAtCompileTime(c, result)
 
 proc semDirectOp(c: PContext, n: PNode, flags: TExprFlags): PNode = 
   # this seems to be a hotspot in the compiler!
@@ -814,7 +824,7 @@ proc buildEchoStmt(c: PContext, n: PNode): PNode =
 
 proc semExprNoType(c: PContext, n: PNode): PNode =
   result = semExpr(c, n, {efWantStmt})
-  discardCheck(result)
+  discardCheck(c, result)
   
 proc isTypeExpr(n: PNode): bool = 
   case n.kind
@@ -1208,7 +1218,7 @@ proc semProcBody(c: PContext, n: PNode): PNode =
       a.sons[1] = result
       result = semAsgn(c, a)
   else:
-    discardCheck(result)
+    discardCheck(c, result)
   closeScope(c)
 
 proc SemYieldVarResult(c: PContext, n: PNode, restype: PType) =
@@ -1429,12 +1439,12 @@ proc semQuoteAst(c: PContext, n: PNode): PNode =
     newNode(nkCall, n.info, quotes)])
   result = semExpandToAst(c, result)
 
-proc tryExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
+proc tryExpr(c: PContext, n: PNode,
+             flags: TExprFlags = {}, bufferErrors = false): PNode =
   # watch out, hacks ahead:
   let oldErrorCount = msgs.gErrorCounter
   let oldErrorMax = msgs.gErrorMax
   inc c.InCompilesContext
-  inc msgs.gSilence
   # do not halt after first error:
   msgs.gErrorMax = high(int)
   
@@ -1443,6 +1453,8 @@ proc tryExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
   openScope(c)
   let oldOwnerLen = len(gOwners)
   let oldGenerics = c.generics
+  let oldErrorOutputs = errorOutputs
+  errorOutputs = if bufferErrors: {eInMemory} else: {}
   let oldContextLen = msgs.getInfoContextLen()
   
   let oldInGenericContext = c.InGenericContext
@@ -1465,7 +1477,7 @@ proc tryExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
   setlen(gOwners, oldOwnerLen)
   c.currentScope = oldScope
   dec c.InCompilesContext
-  dec msgs.gSilence
+  errorOutputs = oldErrorOutputs
   msgs.gErrorCounter = oldErrorCount
   msgs.gErrorMax = oldErrorMax
 
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index ed6787a16..da8ba50a8 100644
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -132,7 +132,7 @@ proc fixNilType(n: PNode) =
     for it in n: fixNilType(it)
   n.typ = nil
 
-proc discardCheck(result: PNode) =
+proc discardCheck(c: PContext, result: PNode) =
   if result.typ != nil and result.typ.kind notin {tyStmt, tyEmpty}:
     if result.kind == nkNilLit:
       result.typ = nil
@@ -142,6 +142,10 @@ proc discardCheck(result: PNode) =
       while n.kind in skipForDiscardable:
         n = n.lastSon
         n.typ = nil
+    elif c.InTypeClass > 0 and result.typ.kind == tyBool:
+      let verdict = semConstExpr(c, result)
+      if verdict.intVal == 0:
+        localError(result.info, "type class predicate failed.")
     elif result.typ.kind != tyError and gCmd != cmdInteractive:
       if result.typ.kind == tyNil:
         fixNilType(result)
@@ -169,7 +173,7 @@ proc semIf(c: PContext, n: PNode): PNode =
       typ = commonType(typ, it.sons[0].typ)
     else: illFormedAst(it)
   if isEmptyType(typ) or typ.kind == tyNil or not hasElse:
-    for it in n: discardCheck(it.lastSon)
+    for it in n: discardCheck(c, it.lastSon)
     result.kind = nkIfStmt
     # propagate any enforced VoidContext:
     if typ == EnforceVoidContext: result.typ = EnforceVoidContext
@@ -230,7 +234,7 @@ proc semCase(c: PContext, n: PNode): PNode =
       localError(n.info, errNotAllCasesCovered)
   closeScope(c)
   if isEmptyType(typ) or typ.kind == tyNil or not hasElse:
-    for i in 1..n.len-1: discardCheck(n.sons[i].lastSon)
+    for i in 1..n.len-1: discardCheck(c, n.sons[i].lastSon)
     # propagate any enforced VoidContext:
     if typ == EnforceVoidContext:
       result.typ = EnforceVoidContext
@@ -275,8 +279,8 @@ proc semTry(c: PContext, n: PNode): PNode =
     typ = commonType(typ, a.sons[length-1].typ)
   dec c.p.inTryStmt
   if isEmptyType(typ) or typ.kind == tyNil:
-    discardCheck(n.sons[0])
-    for i in 1..n.len-1: discardCheck(n.sons[i].lastSon)
+    discardCheck(c, n.sons[0])
+    for i in 1..n.len-1: discardCheck(c, n.sons[i].lastSon)
     if typ == EnforceVoidContext:
       result.typ = EnforceVoidContext
   else:
@@ -879,8 +883,9 @@ proc semLambda(c: PContext, n: PNode, flags: TExprFlags): PNode =
   openScope(c)
   if n.sons[genericParamsPos].kind != nkEmpty:
     illFormedAst(n)           # process parameters:
-  if n.sons[paramsPos].kind != nkEmpty: 
-    semParamList(c, n.sons[ParamsPos], nil, s)
+  if n.sons[paramsPos].kind != nkEmpty:
+    var gp = newNodeI(nkGenericParams, n.info)
+    semParamList(c, n.sons[ParamsPos], gp, s)
     ParamsTypeCheck(c, s.typ)
   else:
     s.typ = newTypeS(tyProc, c)
@@ -1104,24 +1109,24 @@ proc finishMethod(c: PContext, s: PSym) =
     methodDef(s, false)
 
 proc semMethod(c: PContext, n: PNode): PNode = 
-  if not isTopLevel(c): LocalError(n.info, errXOnlyAtModuleScope, "method")
+  if not isTopLevel(c): localError(n.info, errXOnlyAtModuleScope, "method")
   result = semProcAux(c, n, skMethod, methodPragmas)
   
   var s = result.sons[namePos].sym
-  if not isGenericRoutine(s):
+  if not isGenericRoutine(s) and result.sons[bodyPos].kind != nkEmpty:
     if hasObjParam(s):
-      methodDef(s, false)
+      methodDef(s, fromCache=false)
     else:
-      LocalError(n.info, errXNeedsParamObjectType, "method")
+      localError(n.info, errXNeedsParamObjectType, "method")
 
 proc semConverterDef(c: PContext, n: PNode): PNode = 
-  if not isTopLevel(c): LocalError(n.info, errXOnlyAtModuleScope, "converter")
+  if not isTopLevel(c): localError(n.info, errXOnlyAtModuleScope, "converter")
   checkSonsLen(n, bodyPos + 1)
   result = semProcAux(c, n, skConverter, converterPragmas)
   var s = result.sons[namePos].sym
   var t = s.typ
-  if t.sons[0] == nil: LocalError(n.info, errXNeedsReturnType, "converter")
-  if sonsLen(t) != 2: LocalError(n.info, errXRequiresOneArgument, "converter")
+  if t.sons[0] == nil: localError(n.info, errXNeedsReturnType, "converter")
+  if sonsLen(t) != 2: localError(n.info, errXRequiresOneArgument, "converter")
   addConverter(c, s)
 
 proc semMacroDef(c: PContext, n: PNode): PNode = 
@@ -1129,9 +1134,9 @@ proc semMacroDef(c: PContext, n: PNode): PNode =
   result = semProcAux(c, n, skMacro, macroPragmas)
   var s = result.sons[namePos].sym
   var t = s.typ
-  if t.sons[0] == nil: LocalError(n.info, errXNeedsReturnType, "macro")
+  if t.sons[0] == nil: localError(n.info, errXNeedsReturnType, "macro")
   if n.sons[bodyPos].kind == nkEmpty:
-    LocalError(n.info, errImplOfXexpected, s.name.s)
+    localError(n.info, errImplOfXexpected, s.name.s)
   
 proc evalInclude(c: PContext, n: PNode): PNode =
   result = newNodeI(nkStmtList, n.info)
@@ -1221,7 +1226,7 @@ proc semStmtList(c: PContext, n: PNode): PNode =
         voidContext = true
         n.typ = EnforceVoidContext
       if i != last or voidContext:
-        discardCheck(n.sons[i])
+        discardCheck(c, n.sons[i])
       else:
         n.typ = n.sons[i].typ
         if not isEmptyType(n.typ):
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim
index b9893d037..92f47f585 100644
--- a/compiler/semtypes.nim
+++ b/compiler/semtypes.nim
@@ -876,8 +876,7 @@ proc freshType(res, prev: PType): PType {.inline.} =
 proc semTypeClass(c: PContext, n: PNode, prev: PType): PType =
   # if n.sonsLen == 0: return newConstraint(c, tyTypeClass)
   result = newOrPrevType(tyTypeClass, prev, c)
-  result.testeeName = considerAcc(n[0])
-  result.n = n[3]
+  result.n = n
 
   let
     pragmas = n[1]
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim
index 318acc660..00f3b2b10 100644
--- a/compiler/sigmatch.nim
+++ b/compiler/sigmatch.nim
@@ -85,6 +85,7 @@ proc initCandidate*(c: var TCandidate, callee: PSym, binding: PNode,
   c.calleeSym = callee
   c.calleeScope = calleeScope
   initIdTable(c.bindings)
+  c.errors = nil
   if binding != nil and callee.kind in RoutineKinds:
     var typeParams = callee.ast[genericParamsPos]
     for i in 1..min(sonsLen(typeParams), sonsLen(binding)-1):
@@ -202,7 +203,7 @@ proc describeArgs*(c: PContext, n: PNode, startIdx = 1): string =
     add(result, argTypeToString(arg))
     if i != sonsLen(n) - 1: add(result, ", ")
 
-proc typeRel(c: var TCandidate, f, a: PType): TTypeRelation
+proc typeRel*(c: var TCandidate, f, a: PType): TTypeRelation
 proc concreteType(c: TCandidate, t: PType): PType = 
   case t.kind
   of tyArrayConstr: 
@@ -750,40 +751,55 @@ proc matchUserTypeClass*(c: PContext, m: var TCandidate,
 
   # pushInfoContext(arg.info)
   openScope(c)
+  inc c.InTypeClass
 
-  var testee = newSym(skParam, f.testeeName, f.sym, f.sym.info)
-  testee.typ = a
-  addDecl(c, testee)
+  finally:
+    dec c.InTypeClass
+    closeScope(c)
 
-  for stmt in f.n:
-    var e = c.semTryExpr(c, copyTree(stmt))
-    if e == nil:
-      let expStr = renderTree(stmt, {renderNoComments})
-      m.errors.safeAdd("can't compile " & expStr & "  for " & a.typeToString)
-      return nil
-    case e.kind
-    of nkReturnStmt:
-      nil
-    of nkTypeSection: nil
-    of nkConstDef: nil
+  for param in f.n[0]:
+    var
+      dummyName: PNode
+      dummyType: PType
+    
+    if param.kind == nkVarTy:
+      dummyName = param[0]
+      dummyType = makeVarType(c, a)
     else:
-      if e.typ.kind == tyBool:
-        let verdict = c.semConstExpr(c, e)
-        if verdict.intVal == 0:
-          let expStr = renderTree(stmt, {renderNoComments})
-          m.errors.safeAdd(expStr & " doesn't hold for " & a.typeToString)
-          return nil
+      dummyName = param
+      dummyType = a
+
+    InternalAssert dummyName.kind == nkIdent
+    var dummyParam = newSym(skType, dummyName.ident, f.sym, f.sym.info)
+    dummyParam.typ = dummyType
+    addDecl(c, dummyParam)
 
-  closeScope(c)
+  for stmt in f.n[3]:
+    var e = c.semTryExpr(c, copyTree(stmt), bufferErrors = false)
+    m.errors = bufferedMsgs
+    clearBufferedMsgs()
+    if e == nil: return nil
 
+    case e.kind
+    of nkReturnStmt: nil
+    of nkTypeSection: nil
+    of nkConstDef: nil
+    else: nil
+  
   result = arg
   put(m.bindings, f, a)
 
-proc ParamTypesMatchAux(c: PContext, m: var TCandidate, f, a: PType, 
+proc ParamTypesMatchAux(c: PContext, m: var TCandidate, f, argType: PType,
                         argSemantized, argOrig: PNode): PNode =
-  var arg = argSemantized
-  var r: TTypeRelation
-  let fMaybeExpr = f.skipTypes({tyDistinct})
+  var
+    r: TTypeRelation
+    arg = argSemantized
+
+  let
+    a = if c.InTypeClass > 0: argType.skipTypes({tyTypeDesc})
+        else: argType
+    fMaybeExpr = f.skipTypes({tyDistinct})
+
   case fMaybeExpr.kind
   of tyExpr:
     if fMaybeExpr.sonsLen == 0:
diff --git a/compiler/types.nim b/compiler/types.nim
index f9c40e201..4dec9ea2f 100644
--- a/compiler/types.nim
+++ b/compiler/types.nim
@@ -621,7 +621,7 @@ type
 proc initSameTypeClosure: TSameTypeClosure =
   # we do the initialization lazily for performance (avoids memory allocations)
   nil
-
+  
 proc containsOrIncl(c: var TSameTypeClosure, a, b: PType): bool =
   result = not IsNil(c.s) and c.s.contains((a.id, b.id))
   if not result:
@@ -750,9 +750,9 @@ template IfFastObjectTypeCheckFailed(a, b: PType, body: stmt) {.immediate.} =
 
 proc sameObjectTypes*(a, b: PType): bool =
   # specialized for efficiency (sigmatch uses it)
-  IfFastObjectTypeCheckFailed(a, b):
+  IfFastObjectTypeCheckFailed(a, b):     
     var c = initSameTypeClosure()
-    result = sameTypeAux(a, b, c)
+    result = sameTypeAux(a, b, c)    
 
 proc sameDistinctTypes*(a, b: PType): bool {.inline.} =
   result = sameObjectTypes(a, b)
@@ -808,11 +808,11 @@ proc SameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
       if containsOrIncl(c, a, b): return true
 
   proc sameFlags(a, b: PType): bool {.inline.} =
-    result = eqTypeFlags*a.flags == eqTypeFlags*b.flags
-    
+    result = eqTypeFlags*a.flags == eqTypeFlags*b.flags   
+
   if x == y: return true
   var a = skipTypes(x, {tyGenericInst})
-  var b = skipTypes(y, {tyGenericInst})
+  var b = skipTypes(y, {tyGenericInst})  
   assert(a != nil)
   assert(b != nil)
   if a.kind != b.kind:
@@ -824,7 +824,7 @@ proc SameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
       if a.kind != b.kind: return false
     of dcEqOrDistinctOf:
       while a.kind == tyDistinct: a = a.sons[0]
-      if a.kind != b.kind: return false
+      if a.kind != b.kind: return false  
   case a.Kind
   of tyEmpty, tyChar, tyBool, tyNil, tyPointer, tyString, tyCString,
      tyInt..tyBigNum, tyStmt:
@@ -837,15 +837,19 @@ proc SameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
       result = sameObjectStructures(a, b, c) and sameFlags(a, b)
   of tyDistinct:
     CycleCheck()
-    if c.cmp == dcEq: result = sameDistinctTypes(a, b) and sameFlags(a, b)
-    else: result = sameTypeAux(a.sons[0], b.sons[0], c) and sameFlags(a, b)
+    if c.cmp == dcEq:      
+      if sameFlags(a, b):
+        IfFastObjectTypeCheckFailed(a, b):
+          result = sameTypeAux(a.sons[0], b.sons[0], c)     
+    else: 
+      result = sameTypeAux(a.sons[0], b.sons[0], c) and sameFlags(a, b)
   of tyEnum, tyForward, tyProxy:
     # XXX generic enums do not make much sense, but require structural checking
     result = a.id == b.id and sameFlags(a, b)
   of tyTuple:
     CycleCheck()
     result = sameTuple(a, b, c) and sameFlags(a, b)
-  of tyGenericInst:
+  of tyGenericInst:    
     result = sameTypeAux(lastSon(a), lastSon(b), c)
   of tyTypeDesc:
     if c.cmp == dcEqIgnoreDistinct: result = false
@@ -858,7 +862,7 @@ proc SameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
      tyOpenArray, tySet, tyRef, tyPtr, tyVar, tyArrayConstr,
      tyArray, tyProc, tyConst, tyMutable, tyVarargs, tyIter,
      tyOrdinal, tyTypeClass:
-    CycleCheck()
+    CycleCheck()    
     result = sameChildrenAux(a, b, c) and sameFlags(a, b)
     if result and (a.kind == tyProc):
       result = a.callConv == b.callConv
@@ -867,7 +871,7 @@ proc SameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
     result = SameTypeOrNilAux(a.sons[0], b.sons[0], c) and
         SameValue(a.n.sons[0], b.n.sons[0]) and
         SameValue(a.n.sons[1], b.n.sons[1])
-  of tyNone: result = false
+  of tyNone: result = false  
 
 proc sameType*(x, y: PType): bool =
   var c = initSameTypeClosure()
diff --git a/doc/gc.txt b/doc/gc.txt
index 854f9ce2a..13498afaa 100644
--- a/doc/gc.txt
+++ b/doc/gc.txt
@@ -13,7 +13,7 @@ Introduction
 This document describes how the GC works and how to tune it for
 (soft) `realtime systems`:idx:.
 
-The basic algorithm is *Deferrent Reference Counting* with cycle detection.
+The basic algorithm is *Deferred Reference Counting* with cycle detection.
 References on the stack are not counted for better performance (and easier C
 code generation). The GC **never** scans the whole heap but it may scan the
 delta-subgraph of the heap that changed since its last run.
diff --git a/doc/intern.txt b/doc/intern.txt
index c84797251..9d9eb66cc 100644
--- a/doc/intern.txt
+++ b/doc/intern.txt
@@ -52,6 +52,11 @@ For a release version use::
   nimrod c koch.nim
   ./koch boot -d:release
 
+And for a debug version compatible with GDB::
+
+  nimrod c koch.nim
+  ./koch boot --debuginfo --linedir:on
+
 The ``koch`` program is Nimrod's maintenance script. It is a replacement for
 make and shell scripting with the advantage that it is much more portable.
 
@@ -64,7 +69,7 @@ Coding Guidelines
 * Max line length is 80 characters.
 * Provide spaces around binary operators if that enhances readability.
 * Use a space after a colon, but not before it.
-* Start types with a capital ``T``, unless they are pointers which start
+* Start types with a capital ``T``, unless they are pointers/references which start
   with ``P``. 
 
 
diff --git a/doc/lib.txt b/doc/lib.txt
index 1b004aa9d..92a4a7c83 100644
--- a/doc/lib.txt
+++ b/doc/lib.txt
@@ -64,6 +64,8 @@ Core
 Collections and algorithms
 --------------------------
 
+* `algorithm <algorithm.html>`_
+  Implements some common generic algorithms like sort or binary search.
 * `tables <tables.html>`_
   Nimrod hash table support. Contains tables, ordered tables and count tables.
 * `sets <sets.html>`_
diff --git a/doc/manual.txt b/doc/manual.txt
index 29b51321e..dabff3d69 100644
--- a/doc/manual.txt
+++ b/doc/manual.txt
@@ -893,11 +893,12 @@ integers from 0 to ``len(A)-1``. An array expression may be constructed by the
 array constructor ``[]``.
 
 `Sequences`:idx: are similar to arrays but of dynamic length which may change
-during runtime (like strings). A sequence ``S`` is always indexed by integers
-from 0 to ``len(S)-1`` and its bounds are checked. Sequences can be
-constructed by the array constructor ``[]`` in conjunction with the array to
-sequence operator ``@``. Another way to allocate space for a sequence is to
-call the built-in ``newSeq`` procedure.
+during runtime (like strings). Sequences are implemented as growable arrays, 
+allocating pieces of memory as items are added. A sequence ``S`` is always
+indexed by integers from 0 to ``len(S)-1`` and its bounds are checked. 
+Sequences can be constructed by the array constructor ``[]`` in conjunction
+with the array to sequence operator ``@``. Another way to allocate space for a
+sequence is to call the built-in ``newSeq`` procedure.
 
 A sequence may be passed to a parameter that is of type *open array*.
 
@@ -3288,27 +3289,36 @@ Declarative type classes are written in the following form:
       for value in c:
         type(value) is T
 
-
-The identifiers following the `generic` keyword are treated as variables of
-the matched type and the body of the type class consists of arbitrary code that
-must be valid under these circumstances.
-
-Specifically, the type class will be matched if:
+The type class will be matched if:
 
 a) all of the expressions within the body can be compiled for the tested type
 b) all statically evaluatable boolean expressions in the body must be true
 
-Please note that the ``is`` operator allows you to easily verify the precise type
-signatures of the required operations, but since type inference and default
-parameters are still applied in the provided block, it's also possible to encode
-usage protocols that doesn't reveal implementation details.
+The identifiers following the `generic` keyword represent instances of the
+currently matched type. These instances can act both as variables of the type,
+when used in contexts, where a value is expected, and as the type itself, when
+used in a contexts, where a type is expected.
+
+Please note that the ``is`` operator allows you to easily verify the precise
+type signatures of the required operations, but since type inference and
+default parameters are still applied in the provided block, it's also possible
+to encode usage protocols that doesn't reveal implementation details.
+
+As a special rule providing further convenience when writing type classes, any
+type value appearing in a callable expression will be treated as a variable of
+the designated type for overload resolution purposes, unless the type value was
+passed in its explicit ``typedesc[T]`` form:
+
+.. code-block:: nimrod
+  type
+    OutputStream = generic S
+      write(var S, string)
 
 Much like generics, the user defined type classes will be instantiated exactly
 once for each tested type and any static code included within them will also be
 executed once.
 
 
-
 Return Type Inference
 ---------------------
 
@@ -4673,9 +4683,10 @@ A proc can be marked with the `noStackFrame`:idx: pragma to tell the compiler
 it should not generate a stack frame for the proc. There are also no exit
 statements like ``return result;`` generated and the generated C function is
 declared as ``__declspec(naked)`` or ``__attribute__((naked))`` (depending on
-the used C compiler). This is useful for procs that only consist of an
-assembler statement.
+the used C compiler).
 
+**Note**: This pragma should only be used by procs which consist solely of assembler
+statements.
 
 error pragma
 ------------
diff --git a/doc/tut1.txt b/doc/tut1.txt
index 0cc9b05c1..5c1cdb52e 100644
--- a/doc/tut1.txt
+++ b/doc/tut1.txt
@@ -610,7 +610,7 @@ allow to silently throw away a return value:
   discard yes("May I ask a pointless question?")
 
 
-The return value can be ignored implicitely if the called proc/iterator has
+The return value can be ignored implicitly if the called proc/iterator has
 been declared with the ``discardable`` pragma: 
 
 .. code-block:: nimrod
@@ -1077,7 +1077,7 @@ can also be used to include elements (and ranges of elements):
     TCharSet = set[char]
   var
     x: TCharSet
-  x = {'a'..'z', '0'..'9'} # This constructs a set that conains the
+  x = {'a'..'z', '0'..'9'} # This constructs a set that contains the
                            # letters from 'a' to 'z' and the digits
                            # from '0' to '9'
 
@@ -1201,7 +1201,7 @@ to specify a range from zero to the specified index minus one:
 Sequences
 ---------
 `Sequences`:idx: are similar to arrays but of dynamic length which may change
-during runtime (like strings). Since sequences are resizeable they are always
+during runtime (like strings). Since sequences are resizable they are always
 allocated on the heap and garbage collected.
 
 Sequences are always indexed with an ``int`` starting at position 0.
@@ -1547,7 +1547,7 @@ exported symbols. An alternative that only imports listed symbols is the
 
 Include statement
 -----------------
-The `include`:idx: statement does something fundametally different than
+The `include`:idx: statement does something fundamentally different than
 importing a module: it merely includes the contents of a file. The ``include``
 statement is useful to split up a large module into several files:
 
diff --git a/lib/packages/docutils/rst.nim b/lib/packages/docutils/rst.nim
index 91664cd50..6dd407155 100644
--- a/lib/packages/docutils/rst.nim
+++ b/lib/packages/docutils/rst.nim
@@ -868,6 +868,12 @@ proc parseLine(p: var TRstParser, father: PRstNode) =
     case p.tok[p.idx].kind
     of tkWhite, tkWord, tkOther, tkPunct: parseInline(p, father)
     else: break 
+
+proc parseUntilNewline(p: var TRstParser, father: PRstNode) = 
+  while True: 
+    case p.tok[p.idx].kind
+    of tkWhite, tkWord, tkAdornment, tkOther, tkPunct: parseInline(p, father)
+    of tkEof, tkIndent: break
   
 proc parseSection(p: var TRstParser, result: PRstNode)
 proc parseField(p: var TRstParser): PRstNode = 
@@ -1078,7 +1084,7 @@ proc parseParagraph(p: var TRstParser, result: PRstNode) =
 
 proc parseHeadline(p: var TRstParser): PRstNode = 
   result = newRstNode(rnHeadline)
-  parseLine(p, result)
+  parseUntilNewLine(p, result)
   assert(p.tok[p.idx].kind == tkIndent)
   assert(p.tok[p.idx + 1].kind == tkAdornment)
   var c = p.tok[p.idx + 1].symbol[0]
@@ -1172,7 +1178,7 @@ proc parseOverline(p: var TRstParser): PRstNode =
   inc(p.idx, 2)
   result = newRstNode(rnOverline)
   while true: 
-    parseLine(p, result)
+    parseUntilNewline(p, result)
     if p.tok[p.idx].kind == tkIndent: 
       inc(p.idx)
       if p.tok[p.idx - 1].ival > currInd(p): 
diff --git a/lib/posix/posix.nim b/lib/posix/posix.nim
index cf260e9b7..806c255ee 100644
--- a/lib/posix/posix.nim
+++ b/lib/posix/posix.nim
@@ -81,6 +81,8 @@ else:
       ## A type representing a directory stream.   
   
 type
+  TSocketHandle* = distinct cint # The type used to represent socket descriptors
+
   Tdirent* {.importc: "struct dirent", 
              header: "<dirent.h>", final, pure.} = object ## dirent_t struct
     d_ino*: TIno  ## File serial number.
@@ -1791,7 +1793,7 @@ proc dlopen*(a1: cstring, a2: cint): pointer {.importc, header: "<dlfcn.h>".}
 proc dlsym*(a1: pointer, a2: cstring): pointer {.importc, header: "<dlfcn.h>".}
 
 proc creat*(a1: cstring, a2: Tmode): cint {.importc, header: "<fcntl.h>".}
-proc fcntl*(a1: cint, a2: cint): cint {.varargs, importc, header: "<fcntl.h>".}
+proc fcntl*(a1: cint | TSocketHandle, a2: cint): cint {.varargs, importc, header: "<fcntl.h>".}
 proc open*(a1: cstring, a2: cint): cint {.varargs, importc, header: "<fcntl.h>".}
 proc posix_fadvise*(a1: cint, a2, a3: Toff, a4: cint): cint {.
   importc, header: "<fcntl.h>".}
@@ -2068,7 +2070,7 @@ proc access*(a1: cstring, a2: cint): cint {.importc, header: "<unistd.h>".}
 proc alarm*(a1: cint): cint {.importc, header: "<unistd.h>".}
 proc chdir*(a1: cstring): cint {.importc, header: "<unistd.h>".}
 proc chown*(a1: cstring, a2: Tuid, a3: Tgid): cint {.importc, header: "<unistd.h>".}
-proc close*(a1: cint): cint {.importc, header: "<unistd.h>".}
+proc close*(a1: cint | TSocketHandle): cint {.importc, header: "<unistd.h>".}
 proc confstr*(a1: cint, a2: cstring, a3: int): int {.importc, header: "<unistd.h>".}
 proc crypt*(a1, a2: cstring): cstring {.importc, header: "<unistd.h>".}
 proc ctermid*(a1: cstring): cstring {.importc, header: "<unistd.h>".}
@@ -2346,9 +2348,9 @@ proc strerror*(errnum: cint): cstring {.importc, header: "<string.h>".}
 proc hstrerror*(herrnum: cint): cstring {.importc, header: "<netdb.h>".}
 
 proc FD_CLR*(a1: cint, a2: var Tfd_set) {.importc, header: "<sys/select.h>".}
-proc FD_ISSET*(a1: cint, a2: var Tfd_set): cint {.
+proc FD_ISSET*(a1: cint | TSocketHandle, a2: var Tfd_set): cint {.
   importc, header: "<sys/select.h>".}
-proc FD_SET*(a1: cint, a2: var Tfd_set) {.importc, header: "<sys/select.h>".}
+proc FD_SET*(a1: cint | TSocketHandle, a2: var Tfd_set) {.importc, header: "<sys/select.h>".}
 proc FD_ZERO*(a1: var Tfd_set) {.importc, header: "<sys/select.h>".}
 
 proc pselect*(a1: cint, a2, a3, a4: ptr Tfd_set, a5: ptr ttimespec,
@@ -2428,44 +2430,49 @@ proc CMSG_NXTHDR*(mhdr: ptr TMsgHdr, cmsg: ptr TCMsgHdr): ptr TCmsgHdr {.
 proc CMSG_FIRSTHDR*(mhdr: ptr TMsgHdr): ptr TCMsgHdr {.
   importc, header: "<sys/socket.h>".}
 
-proc accept*(a1: cint, a2: ptr Tsockaddr, a3: ptr Tsocklen): cint {.
+const
+  INVALID_SOCKET* = TSocketHandle(-1)
+
+proc `==`*(x, y: TSocketHandle): bool {.borrow.}
+
+proc accept*(a1: TSocketHandle, a2: ptr Tsockaddr, a3: ptr Tsocklen): TSocketHandle {.
   importc, header: "<sys/socket.h>".}
 
-proc bindSocket*(a1: cint, a2: ptr Tsockaddr, a3: Tsocklen): cint {.
+proc bindSocket*(a1: TSocketHandle, a2: ptr Tsockaddr, a3: Tsocklen): cint {.
   importc: "bind", header: "<sys/socket.h>".}
   ## is Posix's ``bind``, because ``bind`` is a reserved word
   
-proc connect*(a1: cint, a2: ptr Tsockaddr, a3: Tsocklen): cint {.
+proc connect*(a1: TSocketHandle, a2: ptr Tsockaddr, a3: Tsocklen): cint {.
   importc, header: "<sys/socket.h>".}
-proc getpeername*(a1: cint, a2: ptr Tsockaddr, a3: ptr Tsocklen): cint {.
+proc getpeername*(a1: TSocketHandle, a2: ptr Tsockaddr, a3: ptr Tsocklen): cint {.
   importc, header: "<sys/socket.h>".}
-proc getsockname*(a1: cint, a2: ptr Tsockaddr, a3: ptr Tsocklen): cint {.
+proc getsockname*(a1: TSocketHandle, a2: ptr Tsockaddr, a3: ptr Tsocklen): cint {.
   importc, header: "<sys/socket.h>".}
 
-proc getsockopt*(a1, a2, a3: cint, a4: pointer, a5: ptr Tsocklen): cint {.
+proc getsockopt*(a1: TSocketHandle, a2, a3: cint, a4: pointer, a5: ptr Tsocklen): cint {.
   importc, header: "<sys/socket.h>".}
 
-proc listen*(a1, a2: cint): cint {.
+proc listen*(a1: TSocketHandle, a2: cint): cint {.
   importc, header: "<sys/socket.h>".}
-proc recv*(a1: cint, a2: pointer, a3: int, a4: cint): int {.
+proc recv*(a1: TSocketHandle, a2: pointer, a3: int, a4: cint): int {.
   importc, header: "<sys/socket.h>".}
-proc recvfrom*(a1: cint, a2: pointer, a3: int, a4: cint,
+proc recvfrom*(a1: TSocketHandle, a2: pointer, a3: int, a4: cint,
         a5: ptr Tsockaddr, a6: ptr Tsocklen): int {.
   importc, header: "<sys/socket.h>".}
-proc recvmsg*(a1: cint, a2: ptr Tmsghdr, a3: cint): int {.
+proc recvmsg*(a1: TSocketHandle, a2: ptr Tmsghdr, a3: cint): int {.
   importc, header: "<sys/socket.h>".}
-proc send*(a1: cint, a2: pointer, a3: int, a4: cint): int {.
+proc send*(a1: TSocketHandle, a2: pointer, a3: int, a4: cint): int {.
   importc, header: "<sys/socket.h>".}
-proc sendmsg*(a1: cint, a2: ptr Tmsghdr, a3: cint): int {.
+proc sendmsg*(a1: TSocketHandle, a2: ptr Tmsghdr, a3: cint): int {.
   importc, header: "<sys/socket.h>".}
-proc sendto*(a1: cint, a2: pointer, a3: int, a4: cint, a5: ptr Tsockaddr,
+proc sendto*(a1: TSocketHandle, a2: pointer, a3: int, a4: cint, a5: ptr Tsockaddr,
              a6: Tsocklen): int {.
   importc, header: "<sys/socket.h>".}
-proc setsockopt*(a1, a2, a3: cint, a4: pointer, a5: Tsocklen): cint {.
+proc setsockopt*(a1: TSocketHandle, a2, a3: cint, a4: pointer, a5: Tsocklen): cint {.
   importc, header: "<sys/socket.h>".}
-proc shutdown*(a1, a2: cint): cint {.
+proc shutdown*(a1: TSocketHandle, a2: cint): cint {.
   importc, header: "<sys/socket.h>".}
-proc socket*(a1, a2, a3: cint): cint {.
+proc socket*(a1, a2, a3: cint): TSocketHandle {.
   importc, header: "<sys/socket.h>".}
 proc sockatmark*(a1: cint): cint {.
   importc, header: "<sys/socket.h>".}
diff --git a/lib/pure/asyncio.nim b/lib/pure/asyncio.nim
index 4ff6e0ced..c4a07d751 100644
--- a/lib/pure/asyncio.nim
+++ b/lib/pure/asyncio.nim
@@ -89,13 +89,13 @@ import sockets, os
 ##      getSocket(s).accept(client)
 
 when defined(windows):
-  from winlean import TTimeVal, TFdSet, FD_ZERO, FD_SET, FD_ISSET, select
+  from winlean import TTimeVal, TSocketHandle, TFdSet, FD_ZERO, FD_SET, FD_ISSET, select
 else:
-  from posix import TTimeVal, TFdSet, FD_ZERO, FD_SET, FD_ISSET, select
+  from posix import TTimeVal, TSocketHandle, TFdSet, FD_ZERO, FD_SET, FD_ISSET, select
 
 type
   TDelegate* = object
-    fd*: cint
+    fd*: TSocketHandle
     deleVal*: PObject
 
     handleRead*: proc (h: PObject) {.nimcall.}
@@ -213,6 +213,7 @@ proc asyncSockHandleRead(h: PObject) =
   else:
     PAsyncSocket(h).handleAccept(PAsyncSocket(h))
 
+proc close*(sock: PAsyncSocket)
 proc asyncSockHandleWrite(h: PObject) =
   when defined(ssl):
     if PAsyncSocket(h).socket.isSSL and not
@@ -230,15 +231,19 @@ proc asyncSockHandleWrite(h: PObject) =
   else:
     if PAsyncSocket(h).sendBuffer != "":
       let sock = PAsyncSocket(h)
-      let bytesSent = sock.socket.sendAsync(sock.sendBuffer)
-      assert bytesSent > 0
-      if bytesSent != sock.sendBuffer.len:
-        sock.sendBuffer = sock.sendBuffer[bytesSent .. -1]
-      elif bytesSent == sock.sendBuffer.len:
-        sock.sendBuffer = ""
-      
-      if PAsyncSocket(h).handleWrite != nil:
-        PAsyncSocket(h).handleWrite(PAsyncSocket(h))
+      try:
+        let bytesSent = sock.socket.sendAsync(sock.sendBuffer)
+        assert bytesSent > 0
+        if bytesSent != sock.sendBuffer.len:
+          sock.sendBuffer = sock.sendBuffer[bytesSent .. -1]
+        elif bytesSent == sock.sendBuffer.len:
+          sock.sendBuffer = ""
+        
+        if PAsyncSocket(h).handleWrite != nil:
+          PAsyncSocket(h).handleWrite(PAsyncSocket(h))
+      except EOS:
+        # Most likely the socket closed before the full buffer could be sent to it.
+        sock.close() # TODO: Provide a handleError for users?
     else:
       if PAsyncSocket(h).handleWrite != nil:
         PAsyncSocket(h).handleWrite(PAsyncSocket(h))
diff --git a/lib/pure/base64.nim b/lib/pure/base64.nim
index 685313551..4e59a6ca6 100644
--- a/lib/pure/base64.nim
+++ b/lib/pure/base64.nim
@@ -1,117 +1,127 @@
-#
-#
-#            Nimrod's Runtime Library
-#        (c) Copyright 2010 Andreas Rumpf
-#
-#    See the file "copying.txt", included in this
-#    distribution, for details about the copyright.
-#
-
-## This module implements a base64 encoder and decoder.
-
-const 
-  cb64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
-
-proc encode*(s: string, lineLen = 75, newLine="\13\10"): string = 
-  ## encodes `s` into base64 representation. After `lineLen` characters, a 
-  ## `newline` is added.
-  var total = ((len(s) + 2) div 3) * 4
-  var numLines = (total + lineLen - 1) div lineLen
+#

+#

+#            Nimrod's Runtime Library

+#        (c) Copyright 2010 Andreas Rumpf

+#

+#    See the file "copying.txt", included in this

+#    distribution, for details about the copyright.

+#

+

+## This module implements a base64 encoder and decoder.

+

+const 

+  cb64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"

+

+template encodeInternal(s: expr, lineLen: int, newLine: string): stmt {.immediate.} = 

+  ## encodes `s` into base64 representation. After `lineLen` characters, a 

+  ## `newline` is added.

+  var total = ((len(s) + 2) div 3) * 4

+  var numLines = (total + lineLen - 1) div lineLen

   if numLines > 0: inc(total, (numLines-1) * newLine.len)

-
-  result = newString(total)
-  var i = 0
-  var r = 0
-  var currLine = 0
-  while i < s.len - 2:
-    var a = ord(s[i])
-    var b = ord(s[i+1])
-    var c = ord(s[i+2])
-    result[r] = cb64[a shr 2]
-    result[r+1] = cb64[((a and 3) shl 4) or ((b and 0xF0) shr 4)]
-    result[r+2] = cb64[((b and 0x0F) shl 2) or ((c and 0xC0) shr 6)] 
-    result[r+3] = cb64[c and 0x3F] 
-    inc(r, 4)
-    inc(i, 3)
-    inc(currLine, 4)
-    if currLine >= lineLen and i != s.len-2: 
-      for x in items(newLine): 
-        result[r] = x
-        inc(r)
-      currLine = 0
-
-  if i < s.len-1:
-    var a = ord(s[i])
-    var b = ord(s[i+1])
-    result[r] = cb64[a shr 2]
-    result[r+1] = cb64[((a and 3) shl 4) or ((b and 0xF0) shr 4)]
-    result[r+2] = cb64[((b and 0x0F) shl 2)] 
-    result[r+3] = '='
-    if r+4 != result.len:
-      setLen(result, r+4)
-  elif i < s.len:
-    var a = ord(s[i])
-    result[r] = cb64[a shr 2]
-    result[r+1] = cb64[(a and 3) shl 4]
-    result[r+2] = '='
-    result[r+3] = '='
-    if r+4 != result.len:
-      setLen(result, r+4)
-  else:
-    assert(r == result.len)
-
-proc decodeByte(b: char): int {.inline.} = 
-  case b
-  of '+': result = ord('>')
-  of '0'..'9': result = ord(b) + 4
-  of 'A'..'Z': result = ord(b) - ord('A')
-  of 'a'..'z': result = ord(b) - 71
-  else: result = 63
-
-proc decode*(s: string): string = 
-  ## decodes a string in base64 representation back into its original form.
-  ## Whitespace is skipped.
-  const Whitespace = {' ', '\t', '\v', '\r', '\l', '\f'}
-  var total = ((len(s) + 3) div 4) * 3
-  # total is an upper bound, as we will skip arbitrary whitespace:
-  result = newString(total)
-
-  var i = 0
-  var r = 0
-  while true:
-    while s[i] in Whitespace: inc(i)
-    if i < s.len-3:
-      var a = s[i].decodeByte
-      var b = s[i+1].decodeByte
-      var c = s[i+2].decodeByte
-      var d = s[i+3].decodeByte
-      
-      result[r] = chr((a shl 2) and 0xff or ((b shr 4) and 0x03))
-      result[r+1] = chr((b shl 4) and 0xff or ((c shr 2) and 0x0F))
-      result[r+2] = chr((c shl 6) and 0xff or (d and 0x3F))
-      inc(r, 3)
-      inc(i, 4)
-    else: break
-  assert i == s.len
-  # adjust the length:
-  if i > 0 and s[i-1] == '=': 
-    dec(r)
-    if i > 1 and s[i-2] == '=': dec(r)
-  setLen(result, r)
-  
-when isMainModule:
-  assert encode("leasure.") == "bGVhc3VyZS4="
-  assert encode("easure.") == "ZWFzdXJlLg=="
-  assert encode("asure.") == "YXN1cmUu"
-  assert encode("sure.") == "c3VyZS4="
-  
-  const longText = """Man is distinguished, not only by his reason, but by this
-    singular passion from other animals, which is a lust of the mind, 
-    that by a perseverance of delight in the continued and indefatigable
-    generation of knowledge, exceeds the short vehemence of any carnal
-    pleasure."""
-  const tests = ["", "abc", "xyz", "man", "leasure.", "sure.", "easure.",
-                 "asure.", longText]
-  for t in items(tests):
-    assert decode(encode(t)) == t
-
+

+  result = newString(total)

+  var i = 0

+  var r = 0

+  var currLine = 0

+  while i < s.len - 2:

+    var a = ord(s[i])

+    var b = ord(s[i+1])

+    var c = ord(s[i+2])

+    result[r] = cb64[a shr 2]

+    result[r+1] = cb64[((a and 3) shl 4) or ((b and 0xF0) shr 4)]

+    result[r+2] = cb64[((b and 0x0F) shl 2) or ((c and 0xC0) shr 6)] 

+    result[r+3] = cb64[c and 0x3F] 

+    inc(r, 4)

+    inc(i, 3)

+    inc(currLine, 4)

+    if currLine >= lineLen and i != s.len-2: 

+      for x in items(newLine): 

+        result[r] = x

+        inc(r)

+      currLine = 0

+

+  if i < s.len-1:

+    var a = ord(s[i])

+    var b = ord(s[i+1])

+    result[r] = cb64[a shr 2]

+    result[r+1] = cb64[((a and 3) shl 4) or ((b and 0xF0) shr 4)]

+    result[r+2] = cb64[((b and 0x0F) shl 2)] 

+    result[r+3] = '='

+    if r+4 != result.len:

+      setLen(result, r+4)

+  elif i < s.len:

+    var a = ord(s[i])

+    result[r] = cb64[a shr 2]

+    result[r+1] = cb64[(a and 3) shl 4]

+    result[r+2] = '='

+    result[r+3] = '='

+    if r+4 != result.len:

+      setLen(result, r+4)

+  else:

+    assert(r == result.len)

+

+proc encode*[T:TInteger|char](s: openarray[T], lineLen = 75, newLine="\13\10"): string = 

+  ## encodes `s` into base64 representation. After `lineLen` characters, a 

+  ## `newline` is added.

+  encodeInternal(s, lineLen, newLine)

+    

+proc encode*(s: string, lineLen = 75, newLine="\13\10"): string = 

+  ## encodes `s` into base64 representation. After `lineLen` characters, a 

+  ## `newline` is added.

+  encodeInternal(s, lineLen, newLine)

+  

+proc decodeByte(b: char): int {.inline.} = 

+  case b

+  of '+': result = ord('>')

+  of '0'..'9': result = ord(b) + 4

+  of 'A'..'Z': result = ord(b) - ord('A')

+  of 'a'..'z': result = ord(b) - 71

+  else: result = 63

+

+proc decode*(s: string): string = 

+  ## decodes a string in base64 representation back into its original form.

+  ## Whitespace is skipped.

+  const Whitespace = {' ', '\t', '\v', '\r', '\l', '\f'}

+  var total = ((len(s) + 3) div 4) * 3

+  # total is an upper bound, as we will skip arbitrary whitespace:

+  result = newString(total)

+

+  var i = 0

+  var r = 0

+  while true:

+    while s[i] in Whitespace: inc(i)

+    if i < s.len-3:

+      var a = s[i].decodeByte

+      var b = s[i+1].decodeByte

+      var c = s[i+2].decodeByte

+      var d = s[i+3].decodeByte

+      

+      result[r] = chr((a shl 2) and 0xff or ((b shr 4) and 0x03))

+      result[r+1] = chr((b shl 4) and 0xff or ((c shr 2) and 0x0F))

+      result[r+2] = chr((c shl 6) and 0xff or (d and 0x3F))

+      inc(r, 3)

+      inc(i, 4)

+    else: break

+  assert i == s.len

+  # adjust the length:

+  if i > 0 and s[i-1] == '=': 

+    dec(r)

+    if i > 1 and s[i-2] == '=': dec(r)

+  setLen(result, r)

+  

+when isMainModule:

+  assert encode("leasure.") == "bGVhc3VyZS4="

+  assert encode("easure.") == "ZWFzdXJlLg=="

+  assert encode("asure.") == "YXN1cmUu"

+  assert encode("sure.") == "c3VyZS4="

+  

+  const longText = """Man is distinguished, not only by his reason, but by this

+    singular passion from other animals, which is a lust of the mind, 

+    that by a perseverance of delight in the continued and indefatigable

+    generation of knowledge, exceeds the short vehemence of any carnal

+    pleasure."""

+  const tests = ["", "abc", "xyz", "man", "leasure.", "sure.", "easure.",

+                 "asure.", longText]

+  for t in items(tests):

+    assert decode(encode(t)) == t

+

diff --git a/lib/pure/collections/LockFreeHash.nim b/lib/pure/collections/LockFreeHash.nim
new file mode 100644
index 000000000..d3a91763a
--- /dev/null
+++ b/lib/pure/collections/LockFreeHash.nim
@@ -0,0 +1,581 @@
+#nimrod c -t:-march=i686 --cpu:amd64 --threads:on -d:release lockfreehash.nim
+
+import baseutils, unsigned, math, hashes
+
+
+
+const
+  minTableSize = 8
+  reProbeLimit = 12
+  minCopyWork = 4096
+  intSize = sizeof(int)
+  
+
+
+when sizeof(int) == 4: # 32bit
+  type 
+    TRaw = range[0..1073741823]
+    ## The range of uint values that can be stored directly in a value slot
+    ## when on a 32 bit platform
+
+elif sizeof(int) == 8: # 64bit
+  type
+    TRaw = range[0..4611686018427387903]
+    ## The range of uint values that can be stored directly in a value slot
+    ## when on a 64 bit platform
+else: echo("unsupported platform")
+  
+type  
+  TEntry = tuple
+    key: int
+    value: int
+
+  TEntryArr = ptr array[0..10_000_000, TEntry]
+  
+  PConcTable[K,V] = ptr object {.pure.}
+    len: int
+    used: int
+    active: int
+    copyIdx: int
+    copyDone: int
+    next: PConcTable[K,V]    
+    data: TEntryArr
+
+
+proc setVal[K,V](table: var PConcTable[K,V], key: int, val: int,
+  expVal: int, match: bool): int 
+
+#------------------------------------------------------------------------------
+
+# Create a new table
+proc newLFTable*[K,V](size: int = minTableSize): PConcTable[K,V]  =
+  let 
+    dataLen = max(nextPowerOfTwo(size), minTableSize)   
+    dataSize = dataLen*sizeof(TEntry) 
+    dataMem = allocShared0(dataSize) 
+    tableSize = 7 * intSize
+    tableMem = allocShared0(tableSize)
+    table = cast[PConcTable[K,V]](tableMem) 
+  table.len = dataLen
+  table.used = 0
+  table.active = 0
+  table.copyIdx = 0
+  table.copyDone = 0
+  table.next = nil
+  table.data = cast[TEntryArr](dataMem)
+  result = table
+
+#------------------------------------------------------------------------------  
+
+# Delete a table
+proc deleteConcTable[K,V](tbl: PConcTable[K,V]) =
+  deallocShared(tbl.data) 
+  deallocShared(tbl)
+
+#------------------------------------------------------------------------------  
+
+proc `[]`[K,V](table: var PConcTable[K,V], i: int): var TEntry {.inline.} =
+  table.data[i]
+
+#------------------------------------------------------------------------------
+# State flags stored in ptr
+
+
+proc pack[T](x: T): int {.inline.} =
+  result = (cast[int](x) shl 2)
+  #echo("packKey ",cast[int](x) , " -> ", result)
+
+# Pop the flags off returning a 4 byte aligned ptr to our Key or Val 
+proc pop(x: int): int  {.inline.} =
+  result = x and 0xFFFFFFFC'i32
+
+# Pop the raw value off of our Key or Val 
+proc popRaw(x: int): int  {.inline.} =
+  result = x shr 2  
+
+# Pop the flags off returning a 4 byte aligned ptr to our Key or Val 
+proc popPtr[V](x: int): ptr V  {.inline.} =
+  result = cast[ptr V](pop(x))
+  #echo("popPtr " & $x & " -> " & $cast[int](result))
+
+# Ghost (sentinel)
+# K or V is no longer valid use new table
+const Ghost = 0xFFFFFFFC
+proc isGhost(x: int): bool {.inline.} =
+  result = x == 0xFFFFFFFC  
+
+# Tombstone 
+# applied to V = K is dead 
+proc isTomb(x: int): bool {.inline.} = 
+  result = (x and 0x00000002) != 0
+
+proc setTomb(x: int): int {.inline.} =
+  result = x or 0x00000002
+
+# Prime
+# K or V is in new table copied from old  
+proc isPrime(x: int): bool {.inline.} = 
+  result = (x and 0x00000001) != 0
+
+proc setPrime(x: int): int {.inline.} =
+  result = x or 0x00000001
+
+#------------------------------------------------------------------------------  
+
+##This is for i32 only need to override for i64
+proc hashInt(x: int):int {.inline.} = 
+  var h = uint32(x) #shr 2'u32  
+  h = h xor (h shr 16'u32)
+  h *= 0x85ebca6b'u32
+  h = h xor (h shr 13'u32)
+  h *= 0xc2b2ae35'u32
+  h = h xor (h shr 16'u32)  
+  result = int(h)
+
+#------------------------------------------------------------------------------
+
+proc resize[K,V](self: PConcTable[K,V]): PConcTable[K,V] =
+  var next = atomic_load_n(self.next.addr, ATOMIC_RELAXED)
+  #echo("next = " & $cast[int](next))
+  if next != nil:
+    #echo("A new table already exists, copy in progress")
+    return next
+  var
+    oldLen = atomic_load_n(self.len.addr, ATOMIC_RELAXED)     
+    newTable = newLFTable[K,V](oldLen*2)
+    success = atomic_compare_exchange_n(self.next.addr, next.addr, newTable,
+                  false, ATOMIC_RELAXED, ATOMIC_RELAXED)
+  if not success:
+    echo("someone beat us to it! delete table we just created and return his " & $cast[int](next))
+    deleteConcTable(newTable) 
+    return next     
+  else:
+    echo("Created New Table! " & $cast[int](newTable) & " Size = " & $newTable.len)
+    return newTable
+  
+
+#------------------------------------------------------------------------------
+#proc keyEQ[K](key1: ptr K, key2: ptr K): bool {.inline.} = 
+proc keyEQ[K](key1: int, key2: int): bool {.inline.} = 
+  result = false
+  when K is TRaw:
+    if key1 == key2: 
+      result = true
+  else:
+    var 
+      p1 = popPtr[K](key1)
+      p2 = popPtr[K](key2)
+    if p1 != nil and p2 != nil:  
+      if cast[int](p1) == cast[int](p2):
+        return true
+      if p1[] == p2[]:
+        return true
+
+#------------------------------------------------------------------------------
+
+#proc tableFull(self: var PConcTable[K,V]) : bool {.inline.} =
+
+
+#------------------------------------------------------------------------------
+
+proc copySlot[K,V](idx: int, oldTbl: var PConcTable[K,V], newTbl: var PConcTable[K,V]): bool =
+  #echo("Copy idx " & $idx)
+  var 
+    oldVal = 0
+    oldkey = 0   
+    ok = false
+  result = false
+  #Block the key so no other threads waste time here
+  while not ok:
+    ok = atomic_compare_exchange_n(oldTbl[idx].key.addr, oldKey.addr, 
+      setTomb(oldKey), false, ATOMIC_RELAXED, ATOMIC_RELAXED)
+  #echo("oldKey was = " & $oldKey & "  set it to tomb " & $setTomb(oldKey)) 
+  #Prevent new values from appearing in the old table by priming 
+  oldVal = atomic_load_n(oldTbl[idx].value.addr, ATOMIC_RELAXED)
+  while not isPrime(oldVal):
+    var box = if oldVal == NULL or isTomb(oldVal) : oldVal.setTomb.setPrime 
+      else: oldVal.setPrime 
+    if atomic_compare_exchange_n(oldTbl[idx].value.addr, oldVal.addr, 
+      box, false, ATOMIC_RELAXED, ATOMIC_RELAXED):
+      if isPrime(box) and isTomb(box):     
+        return true
+      oldVal = box
+      break
+  #echo("oldVal was = ", oldVal, "  set it to prime ", box)
+  if isPrime(oldVal) and isTomb(oldVal): 
+    #when not (K is TRaw):
+    #  deallocShared(popPtr[K](oldKey)) 
+    return false
+  if isTomb(oldVal): 
+    echo("oldVal is Tomb!!!, should not happen")
+  if pop(oldVal) != NULL:  
+    result = setVal(newTbl, pop(oldKey), pop(oldVal), NULL, true) == NULL
+  if result: 
+    #echo("Copied a Slot! idx= " & $idx & " key= " & $oldKey & " val= " & $oldVal)    
+  else: 
+    #echo("copy slot failed")    
+  # Our copy is done so we disable the old slot
+  while not ok:
+    ok = atomic_compare_exchange_n(oldTbl[idx].value.addr, oldVal.addr, 
+      oldVal.setTomb.setPrime , false, ATOMIC_RELAXED, ATOMIC_RELAXED)
+  #echo("disabled old slot") 
+  #echo"---------------------" 
+
+#------------------------------------------------------------------------------
+
+proc promote[K,V](table: var PConcTable[K,V]) =
+  var
+    newData = atomic_load_n(table.next.data.addr, ATOMIC_RELAXED)
+    newLen = atomic_load_n(table.next.len.addr, ATOMIC_RELAXED) 
+    newUsed = atomic_load_n(table.next.used.addr, ATOMIC_RELAXED)
+
+  deallocShared(table.data)
+  atomic_store_n(table.data.addr, newData, ATOMIC_RELAXED)
+  atomic_store_n(table.len.addr, newLen, ATOMIC_RELAXED)
+  atomic_store_n(table.used.addr, newUsed, ATOMIC_RELAXED)
+  atomic_store_n(table.copyIdx.addr, 0, ATOMIC_RELAXED)
+  atomic_store_n(table.copyDone.addr, 0, ATOMIC_RELAXED)
+  deallocShared(table.next)
+  atomic_store_n(table.next.addr, nil, ATOMIC_RELAXED) 
+  echo("new table swapped!")
+
+#------------------------------------------------------------------------------
+ 
+proc checkAndPromote[K,V](table: var PConcTable[K,V], workDone: int): bool =  
+  var 
+    oldLen = atomic_load_n(table.len.addr, ATOMIC_RELAXED)
+    copyDone = atomic_load_n(table.copyDone.addr, ATOMIC_RELAXED)
+    ok: bool
+  result = false  
+  if workDone > 0:
+    #echo("len to copy =" & $oldLen)
+    #echo("copyDone + workDone = " & $copyDone & " + " & $workDone) 
+    while not ok:
+      ok = atomic_compare_exchange_n(table.copyDone.addr, copyDone.addr, 
+        copyDone + workDone, false, ATOMIC_RELAXED, ATOMIC_RELAXED)
+    #if ok: echo("set copyDone")                 
+    # If the copy is done we can promote this table 
+    if copyDone + workDone >= oldLen:
+      # Swap new data
+      #echo("work is done!")        
+      table.promote
+      result = true
+    
+#------------------------------------------------------------------------------
+
+proc copySlotAndCheck[K,V](table: var PConcTable[K,V], idx: int):
+  PConcTable[K,V] =
+  var
+    newTable = cast[PConcTable[K,V]](atomic_load_n(table.next.addr, ATOMIC_RELAXED))
+  result = newTable  
+  if newTable != nil and copySlot(idx, table, newTable): 
+    #echo("copied a single slot, idx = " & $idx)   
+    if checkAndPromote(table, 1): return table
+  
+
+#------------------------------------------------------------------------------
+  
+proc helpCopy[K,V](table: var PConcTable[K,V]): PConcTable[K,V] =
+  var
+    newTable = cast[PConcTable[K,V]](atomic_load_n(table.next.addr, ATOMIC_RELAXED)) 
+  result = newTable   
+  if newTable != nil:     
+    var 
+      oldLen = atomic_load_n(table.len.addr, ATOMIC_RELAXED) 
+      copyDone = atomic_load_n(table.copyDone.addr, ATOMIC_RELAXED)
+      copyIdx = 0
+      work = min(oldLen, minCopyWork)
+      #panicStart = -1
+      workDone = 0
+    if copyDone < oldLen:
+      var ok: bool
+      while not ok:
+        ok = atomic_compare_exchange_n(table.copyIdx.addr, copyIdx.addr, 
+          copyIdx + work, false, ATOMIC_RELAXED, ATOMIC_RELAXED)
+      #echo("copy idx = ", copyIdx)  
+      for i in 0..work-1:
+        var idx = (copyIdx + i) and (oldLen - 1)        
+        if copySlot(idx, table, newTable):
+          workDone += 1
+      if workDone > 0:
+        #echo("did work ", workDone, " on thread ", cast[int](myThreadID[pointer]()))
+        if checkAndPromote(table, workDone): return table
+    # In case a thread finished all the work then got stalled before promotion 
+    if checkAndPromote(table, 0): return table
+    
+  
+
+#------------------------------------------------------------------------------
+
+proc setVal[K,V](table: var PConcTable[K,V], key: int, val: int,
+  expVal: int, match: bool): int =
+  #echo("-try set- in table ", " key = ", (popPtr[K](key)[]), " val = ", val)   
+  when K is TRaw: 
+    var idx = hashInt(key)    
+  else:
+    var idx = popPtr[K](key)[].hash                
+  var    
+    nextTable: PConcTable[K,V]   
+    probes = 1
+  # spin until we find a key slot or build and jump to next table    
+  while true:     
+    idx = idx and (table.len - 1) 
+    #echo("try set idx = " & $idx & "for" & $key)
+    var
+      probedKey = NULL     
+      openKey = atomic_compare_exchange_n(table[idx].key.addr, probedKey.addr, 
+        key, false, ATOMIC_RELAXED, ATOMIC_RELAXED) 
+    if openKey:
+      if val.isTomb:
+        #echo("val was tomb, bail, no reason to set an open slot to tomb")
+        return val
+      #increment used slots 
+      #echo("found an open slot, total used = " & 
+      #$atomic_add_fetch(table.used.addr, 1, ATOMIC_RELAXED))
+      discard atomic_add_fetch(table.used.addr, 1, ATOMIC_RELAXED)
+      break # We found an open slot 
+    #echo("set idx ", idx, " key = ", key, " probed = ", probedKey)       
+    if keyEQ[K](probedKey, key):
+      #echo("we found the matching slot")    
+      break # We found a matching slot      
+    if (not(expVal != NULL and match)) and (probes >= reProbeLimit or key.isTomb):
+      if key.isTomb: echo("Key is Tombstone")
+      #if probes >= reProbeLimit: echo("Too much probing " & $probes)
+      #echo("try to resize")
+      #create next bigger table
+      nextTable = resize(table)
+      #help do some copying
+      #echo("help copy old table to new")       
+      nextTable = helpCopy(table)      
+      #now setVal in the new table instead
+      #echo("jumping to next table to set val")       
+      return setVal(nextTable, key, val, expVal, match)      
+    else:
+      idx += 1
+      probes += 1
+  # Done spinning for a new slot
+  var oldVal = atomic_load_n(table[idx].value.addr, ATOMIC_RELAXED)     
+  if val == oldVal:
+    #echo("this val is alredy in the slot") 
+    return oldVal
+  nextTable = atomic_load_n(table.next.addr, ATOMIC_SEQ_CST)  
+  if nextTable == nil and 
+    ((oldVal == NULL and 
+    (probes >= reProbeLimit or table.used / table.len > 0.8)) or
+    (isPrime(oldVal))):
+    if table.used / table.len > 0.8: echo("resize because usage ratio = " &
+      $(table.used / table.len))
+    if isPrime(oldVal): echo("old val isPrime, should be a rare mem ordering event")
+    nextTable = resize(table)
+  if nextTable != nil:
+    #echo("tomb old slot then set in new table") 
+    nextTable = copySlotAndCheck(table,idx)
+    return setVal(nextTable, key, val, expVal, match)
+  # Finaly ready to add new val to table
+  while true:
+    if match and oldVal != expVal:
+      #echo("set failed, no match  oldVal= " & $oldVal & " expVal= " & $expVal)
+      return oldVal
+    if atomic_compare_exchange_n(table[idx].value.addr, oldVal.addr, 
+        val, false, ATOMIC_RELEASE, ATOMIC_RELAXED):
+      #echo("val set at table " & $cast[int](table))
+      if expVal != NULL:
+        if (oldVal == NULL or isTomb(oldVal)) and not isTomb(val):
+          discard atomic_add_fetch(table.active.addr, 1, ATOMIC_RELAXED)
+        elif not (oldVal == NULL or isTomb(oldVal)) and isTomb(val):
+          discard atomic_add_fetch(table.active.addr, -1, ATOMIC_RELAXED)
+      if oldVal == NULL and expVal != NULL:
+        return setTomb(oldVal)
+      else: return oldVal
+    if isPrime(oldVal):
+      nextTable = copySlotAndCheck(table, idx)
+      return setVal(nextTable, key, val, expVal, match)
+
+#------------------------------------------------------------------------------
+
+proc getVal[K,V](table: var PConcTable[K,V], key: int): int = 
+  #echo("-try get-  key = " & $key)
+  when K is TRaw: 
+    var idx = hashInt(key)
+  else:
+    var idx = popPtr[K](key)[].hash 
+    #echo("get idx ", idx)    
+  var    
+    probes = 0
+    val: int  
+  while true:
+    idx = idx and (table.len - 1)        
+    var 
+      newTable: PConcTable[K,V] # = atomic_load_n(table.next.addr, ATOMIC_ACQUIRE)
+      probedKey = atomic_load_n(table[idx].key.addr, ATOMIC_SEQ_CST)    
+    if keyEQ[K](probedKey, key):
+      #echo("found key after ", probes+1)
+      val = atomic_load_n(table[idx].value.addr, ATOMIC_ACQUIRE)
+      if not isPrime(val):
+        if isTomb(val):
+          #echo("val was tomb but not prime") 
+          return NULL
+        else:
+          #echo("-GotIt- idx = ", idx, " key = ", key, " val ", val ) 
+          return val
+      else:
+        newTable = copySlotAndCheck(table, idx)
+        return getVal(newTable, key) 
+    else:
+      #echo("probe ", probes, " idx = ", idx, " key = ", key, " found ", probedKey )    
+      if probes >= reProbeLimit*4 or key.isTomb:
+        if newTable == nil:
+          #echo("too many probes and no new table ", key, "  ", idx )
+          return NULL
+        else: 
+          newTable = helpCopy(table)
+          return getVal(newTable, key)
+      idx += 1
+      probes += 1
+
+#------------------------------------------------------------------------------
+   
+#proc set*(table: var PConcTable[TRaw,TRaw], key: TRaw, val: TRaw) =
+#  discard setVal(table, pack(key), pack(key), NULL, false)
+
+#proc set*[V](table: var PConcTable[TRaw,V], key: TRaw, val: ptr V) =
+#  discard setVal(table, pack(key), cast[int](val), NULL, false)
+
+proc set*[K,V](table: var PConcTable[K,V], key: var K, val: var V) =
+  when not (K is TRaw): 
+    var newKey = cast[int](copyShared(key))
+  else: 
+    var newKey = pack(key)
+  when not (V is TRaw): 
+    var newVal = cast[int](copyShared(val))
+  else: 
+    var newVal = pack(val)
+  var oldPtr = pop(setVal(table, newKey, newVal, NULL, false))
+    #echo("oldPtr = ", cast[int](oldPtr), " newPtr = ", cast[int](newPtr))
+  when not (V is TRaw): 
+    if newVal != oldPtr and oldPtr != NULL: 
+      deallocShared(cast[ptr V](oldPtr))
+  
+ 
+
+proc get*[K,V](table: var PConcTable[K,V], key: var K): V =
+  when not (V is TRaw):
+    when not (K is TRaw):
+      return popPtr[V](getVal(table, cast[int](key.addr)))[]
+    else: 
+      return popPtr[V](getVal(table, pack(key)))[]
+  else:
+    when not (K is TRaw):
+      return popRaw(getVal(table, cast[int](key.addr)))
+    else: 
+      return popRaw(getVal(table, pack(key)))   
+
+
+
+
+
+
+
+
+
+    
+
+#proc `[]`[K,V](table: var PConcTable[K,V], key: K): PEntry[K,V] {.inline.} =
+#  getVal(table, key)
+
+#proc `[]=`[K,V](table: var PConcTable[K,V], key: K, val: V): PEntry[K,V] {.inline.} =
+#  setVal(table, key, val)
+
+
+
+
+
+
+#Tests ----------------------------
+when isMainModule:
+  import locks, times, mersenne
+  
+  const 
+    numTests  = 100000
+    numThreads = 10
+
+
+    
+  type
+    TTestObj = tuple
+      thr: int      
+      f0: int
+      f1: int
+
+    TData = tuple[k: string,v: TTestObj]
+    PDataArr = array[0..numTests-1, TData]
+    Dict = PConcTable[string,TTestObj]
+    
+  var 
+    thr: array[0..numThreads-1, TThread[Dict]]
+    
+    table = newLFTable[string,TTestObj](8)        
+    rand = newMersenneTwister(2525)
+
+  proc createSampleData(len: int): PDataArr = 
+    #result = cast[PDataArr](allocShared0(sizeof(TData)*numTests))             
+    for i in 0..len-1:
+      result[i].k = "mark" & $(i+1)
+      #echo("mark" & $(i+1), " ", hash("mark" & $(i+1)))      
+      result[i].v.thr = 0
+      result[i].v.f0 = i+1 
+      result[i].v.f1 = 0       
+      #echo("key = " & $(i+1) & " Val ptr = " & $cast[int](result[i].v.addr))
+
+
+
+  proc threadProc(tp: Dict) {.thread.} = 
+    var t = cpuTime();     
+    for i in 1..numTests:
+      var key = "mark" & $(i)
+      var got = table.get(key)                         
+      got.thr = cast[int](myThreadID[pointer]())
+      got.f1 = got.f1 + 1                
+      table.set(key, got)
+    t = cpuTime() - t
+    echo t             
+  
+
+  var testData = createSampleData(numTests)
+
+  for i in 0..numTests-1:
+    table.set(testData[i].k, testData[i].v)
+    
+  var i = 0
+  while i < numThreads:
+    createThread(thr[i], threadProc, table)
+    i += 1
+
+  joinThreads(thr) 
+
+
+
+    
+
+  var fails = 0
+
+  for i in 0..numTests-1: 
+    var got = table.get(testData[i].k) 
+    if got.f0 != i+1 or got.f1 != numThreads:
+      fails += 1
+      echo(got)
+
+  echo("Failed read or write = ", fails)
+     
+
+  #for i in 1..numTests:
+  #  echo(i, " = ", hashInt(i) and 8191)
+
+  deleteConcTable(table)
+
+
+
+
+
+
+
diff --git a/lib/pure/collections/baseutils.nim b/lib/pure/collections/baseutils.nim
new file mode 100644
index 000000000..565a89ccb
--- /dev/null
+++ b/lib/pure/collections/baseutils.nim
@@ -0,0 +1,41 @@
+
+
+
+#------------------------------------------------------------------------------
+## Useful Constants
+const NULL* = 0
+
+
+#------------------------------------------------------------------------------
+## Memory Utility Functions
+
+proc newHeap*[T](): ptr T =
+  result = cast[ptr T](alloc0(sizeof(T))) 
+
+proc copyNew*[T](x: var T): ptr T =
+  var 
+    size = sizeof(T)    
+    mem = alloc(size)  
+  copyMem(mem, x.addr, size)  
+  return cast[ptr T](mem)
+
+proc copyTo*[T](val: var T, dest: int) = 
+  copyMem(pointer(dest), val.addr, sizeof(T))    
+
+proc allocType*[T](): pointer = alloc(sizeof(T)) 
+
+proc newShared*[T](): ptr T =
+  result = cast[ptr T](allocShared0(sizeof(T))) 
+
+proc copyShared*[T](x: var T): ptr T =
+  var 
+    size = sizeof(T)    
+    mem = allocShared(size)  
+  copyMem(mem, x.addr, size)  
+  return cast[ptr T](mem)
+
+#------------------------------------------------------------------------------
+## Pointer arithmetic 
+
+proc `+`*(p: pointer, i: int): pointer {.inline.} =
+  cast[pointer](cast[int](p) + i)
\ No newline at end of file
diff --git a/lib/pure/collections/sequtils.nim b/lib/pure/collections/sequtils.nim
index 705a97469..3a009a8cb 100644
--- a/lib/pure/collections/sequtils.nim
+++ b/lib/pure/collections/sequtils.nim
@@ -117,6 +117,57 @@ proc filter*[T](seq1: seq[T], pred: proc(item: T): bool {.closure.}): seq[T] =
   ##   assert f2 == @["yellow"]
   accumulateResult(filter(seq1, pred))
 
+proc delete*[T](s: var seq[T], first=0, last=0) =
+  ## Deletes in `s` the items at position `first` .. `last`. This modifies
+  ## `s` itself, it does not return a copy.
+  ##
+  ## Example:
+  ##
+  ##.. code-block:: nimrod
+  ##   let outcome = @[1,1,1,1,1,1,1,1]
+  ##   var dest = @[1,1,1,2,2,2,2,2,2,1,1,1,1,1]
+  ##   dest.delete(3, 8)
+  ##   assert outcome == dest
+  
+  var i = first
+  var j = last+1
+  var newLen = len(s)-j+i
+  while i < newLen:
+    s[i].shallowCopy(s[j])
+    inc(i)
+    inc(j)
+  setlen(s, newLen)
+
+proc insert*[T](dest: var seq[T], src: openArray[T], pos=0) =
+  ## Inserts items from `src` into `dest` at position `pos`. This modifies
+  ## `dest` itself, it does not return a copy.
+  ##
+  ## Example:
+  ##
+  ##.. code-block:: nimrod
+  ##   var dest = @[1,1,1,1,1,1,1,1]
+  ##   let 
+  ##     src = @[2,2,2,2,2,2]
+  ##     outcome = @[1,1,1,2,2,2,2,2,2,1,1,1,1,1]
+  ##   dest.insert(src, 3)
+  ##   assert dest == outcome
+  
+  var j = len(dest) - 1
+  var i = len(dest) + len(src) - 1
+  dest.setLen(i + 1)
+
+  # Move items after `pos` to the end of the sequence.
+  while j >= pos:
+    dest[i].shallowCopy(dest[j])
+    dec(i)
+    dec(j)
+  # Insert items from `dest` into `dest` at `pos`
+  inc(j)
+  for item in src:
+    dest[j] = item
+    inc(j)
+
+
 template filterIt*(seq1, pred: expr): expr {.immediate.} =
   ## Returns a new sequence with all the items that fulfilled the predicate.
   ##
@@ -312,4 +363,22 @@ when isMainModule:
     assert multiplication == 495, "Multiplication is (5*(9*(11)))"
     assert concatenation == "nimrodiscool"
 
+  block: # delete tests
+    let outcome = @[1,1,1,1,1,1,1,1]
+    var dest = @[1,1,1,2,2,2,2,2,2,1,1,1,1,1]
+    dest.delete(3, 8)
+    assert outcome == dest, """\
+    Deleting range 3-9 from [1,1,1,2,2,2,2,2,2,1,1,1,1,1] 
+    is [1,1,1,1,1,1,1,1]"""
+
+  block: # insert tests
+    var dest = @[1,1,1,1,1,1,1,1]
+    let 
+      src = @[2,2,2,2,2,2]
+      outcome = @[1,1,1,2,2,2,2,2,2,1,1,1,1,1]
+    dest.insert(src, 3)
+    assert dest == outcome, """\
+    Inserting [2,2,2,2,2,2] into [1,1,1,1,1,1,1,1]
+    at 3 is [1,1,1,2,2,2,2,2,2,1,1,1,1,1]"""
+
   echo "Finished doc tests"
diff --git a/lib/pure/ftpclient.nim b/lib/pure/ftpclient.nim
index 7893eafa0..b6127a9bc 100644
--- a/lib/pure/ftpclient.nim
+++ b/lib/pure/ftpclient.nim
@@ -129,7 +129,8 @@ proc expectReply(ftp: PFTPClient): TaintedString =
 proc send*(ftp: PFTPClient, m: string): TaintedString =
   ## Send a message to the server, and wait for a primary reply.
   ## ``\c\L`` is added for you.
-  ftp.getCSock().send(m & "\c\L")
+  blockingOperation(ftp.getCSock()):
+    ftp.getCSock().send(m & "\c\L")
   return ftp.expectReply()
 
 proc assertReply(received: TaintedString, expected: string) =
diff --git a/lib/pure/httpserver.nim b/lib/pure/httpserver.nim
index e24709451..901fdc779 100644
--- a/lib/pure/httpserver.nim
+++ b/lib/pure/httpserver.nim
@@ -224,11 +224,13 @@ type
   TAsyncHTTPServer = object of TServer
     asyncSocket: PAsyncSocket
   
-proc open*(s: var TServer, port = TPort(80)) =
+proc open*(s: var TServer, port = TPort(80), reuseAddr = false) =
   ## creates a new server at port `port`. If ``port == 0`` a free port is
   ## acquired that can be accessed later by the ``port`` proc.
   s.socket = socket(AF_INET)
   if s.socket == InvalidSocket: OSError(OSLastError())
+  if reuseAddr:
+    s.socket.setSockOpt(OptReuseAddr, True)
   bindAddr(s.socket, port)
   listen(s.socket)
 
@@ -399,8 +401,9 @@ proc nextAsync(s: PAsyncHTTPServer) =
       var value = ""
       i = header.parseUntil(key, ':')
       inc(i) # skip :
-      i += header.skipWhiteSpace(i)
-      i += header.parseUntil(value, {'\c', '\L'}, i)
+      if i < header.len:
+        i += header.skipWhiteSpace(i)
+        i += header.parseUntil(value, {'\c', '\L'}, i)
       s.headers[key] = value
     else:
       s.client.close()
@@ -475,7 +478,8 @@ proc nextAsync(s: PAsyncHTTPServer) =
 
 proc asyncHTTPServer*(handleRequest: proc (server: PAsyncHTTPServer, client: TSocket, 
                         path, query: string): bool {.closure.},
-                     port = TPort(80), address = ""): PAsyncHTTPServer =
+                     port = TPort(80), address = "",
+                     reuseAddr = false): PAsyncHTTPServer =
   ## Creates an Asynchronous HTTP server at ``port``.
   var capturedRet: PAsyncHTTPServer
   new(capturedRet)
@@ -486,6 +490,8 @@ proc asyncHTTPServer*(handleRequest: proc (server: PAsyncHTTPServer, client: TSo
       let quit = handleRequest(capturedRet, capturedRet.client, capturedRet.path,
                                capturedRet.query)
       if quit: capturedRet.asyncSocket.close()
+  if reuseAddr:
+    capturedRet.asyncSocket.setSockOpt(OptReuseAddr, True)
   
   capturedRet.asyncSocket.bindAddr(port, address)
   capturedRet.asyncSocket.listen()
diff --git a/lib/pure/irc.nim b/lib/pure/irc.nim
index 74ad7e26a..ee85d9c69 100644
--- a/lib/pure/irc.nim
+++ b/lib/pure/irc.nim
@@ -98,6 +98,7 @@ type
       params*: seq[string] ## Parameters of the IRC message
       origin*: string      ## The channel/user that this msg originated from
       raw*: string         ## Raw IRC message
+      timestamp*: TTime    ## UNIX epoch time the message was received
   
 proc send*(irc: PIRC, message: string, sendImmediately = false) =
   ## Sends ``message`` as a raw command. It adds ``\c\L`` for you.
@@ -160,9 +161,10 @@ proc isNumber(s: string): bool =
   result = i == s.len and s.len > 0
 
 proc parseMessage(msg: string): TIRCEvent =
-  result.typ = EvMsg
-  result.cmd = MUnknown
-  result.raw = msg
+  result.typ       = EvMsg
+  result.cmd       = MUnknown
+  result.raw       = msg
+  result.timestamp = times.getTime()
   var i = 0
   # Process the prefix
   if msg[i] == ':':
diff --git a/lib/pure/mersenne.nim b/lib/pure/mersenne.nim
new file mode 100644
index 000000000..2b12cce73
--- /dev/null
+++ b/lib/pure/mersenne.nim
@@ -0,0 +1,39 @@
+import unsigned
+
+type
+  TMersenneTwister* = object
+    mt: array[0..623, uint32]
+    index: int
+
+proc newMersenneTwister*(seed: int): TMersenneTwister =   
+  result.index = 0
+  result.mt[0]= uint32(seed)
+  for i in 1..623'u32:
+    result.mt[i]= (0x6c078965'u32 * (result.mt[i-1] xor (result.mt[i-1] shr 30'u32)) + i)
+
+proc generateNumbers(m: var TMersenneTwister) =
+  for i in 0..623:
+    var y = (m.mt[i] and 0x80000000'u32) + (m.mt[(i+1) mod 624] and 0x7fffffff'u32)
+    m.mt[i] = m.mt[(i+397) mod 624] xor uint32(y shr 1'u32)
+    if (y mod 2'u32) != 0:
+     m.mt[i] = m.mt[i] xor 0x9908b0df'u32
+
+proc getNum*(m: var TMersenneTwister): int =
+  if m.index == 0:
+    generateNumbers(m)
+  var y = m.mt[m.index]
+  y = y xor (y shr 11'u32)
+  y = y xor ((7'u32 shl y) and 0x9d2c5680'u32)
+  y = y xor ((15'u32 shl y) and 0xefc60000'u32)
+  y = y xor (y shr 18'u32)
+  m.index = (m.index+1) mod 624
+  return int(y)
+
+
+
+# Test
+when isMainModule:
+  var mt = newMersenneTwister(2525)
+
+  for i in 0..99:
+    echo mt.getNum
\ No newline at end of file
diff --git a/lib/pure/oids.nim b/lib/pure/oids.nim
index 0fd1d8cd2..fbe0dda95 100644
--- a/lib/pure/oids.nim
+++ b/lib/pure/oids.nim
@@ -1,7 +1,7 @@
 #
 #
 #            Nimrod's Runtime Library
-#        (c) Copyright 2012 Andreas Rumpf
+#        (c) Copyright 2013 Andreas Rumpf
 #
 #    See the file "copying.txt", included in this
 #    distribution, for details about the copyright.
@@ -52,6 +52,10 @@ proc oidToString*(oid: TOid, str: cstring) =
     inc(i)
   str[24] = '\0'
 
+proc `$`*(oid: TOid): string =
+  result = newString(25)
+  oidToString(oid, result)
+
 var
   incr: int 
   fuzz: int32
diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim
index b9bde73bc..754e34b85 100644
--- a/lib/pure/osproc.nim
+++ b/lib/pure/osproc.nim
@@ -24,10 +24,10 @@ type
   TProcess = object of TObject
     when defined(windows):
       FProcessHandle: Thandle
-      inputHandle, outputHandle, errorHandle: TFileHandle
+      inHandle, outHandle, errHandle: TFileHandle
       id: THandle
     else:
-      inputHandle, outputHandle, errorHandle: TFileHandle
+      inHandle, outHandle, errHandle: TFileHandle
       inStream, outStream, errStream: PStream
       id: TPid
     exitCode: cint
@@ -113,23 +113,47 @@ proc peekExitCode*(p: PProcess): int {.tags: [].}
   ## return -1 if the process is still running. Otherwise the process' exit code
 
 proc inputStream*(p: PProcess): PStream {.rtl, extern: "nosp$1", tags: [].}
-  ## returns ``p``'s input stream for writing to
+  ## returns ``p``'s input stream for writing to.
   ##
   ## **Warning**: The returned `PStream` should not be closed manually as it 
   ## is closed when closing the PProcess ``p``.
 
 proc outputStream*(p: PProcess): PStream {.rtl, extern: "nosp$1", tags: [].}
-  ## returns ``p``'s output stream for reading from
+  ## returns ``p``'s output stream for reading from.
   ##
   ## **Warning**: The returned `PStream` should not be closed manually as it 
   ## is closed when closing the PProcess ``p``.
 
 proc errorStream*(p: PProcess): PStream {.rtl, extern: "nosp$1", tags: [].}
-  ## returns ``p``'s output stream for reading from
+  ## returns ``p``'s error stream for reading from.
   ##
   ## **Warning**: The returned `PStream` should not be closed manually as it 
   ## is closed when closing the PProcess ``p``.
 
+proc inputHandle*(p: PProcess): TFileHandle {.rtl, extern: "nosp$1",
+  tags: [].} =
+  ## returns ``p``'s input file handle for writing to.
+  ##
+  ## **Warning**: The returned `TFileHandle` should not be closed manually as
+  ## it is closed when closing the PProcess ``p``.
+  result = p.inHandle
+
+proc outputHandle*(p: PProcess): TFileHandle {.rtl, extern: "nosp$1",
+  tags: [].} =
+  ## returns ``p``'s output file handle for reading from.
+  ##
+  ## **Warning**: The returned `TFileHandle` should not be closed manually as
+  ## it is closed when closing the PProcess ``p``.
+  result = p.outHandle
+
+proc errorHandle*(p: PProcess): TFileHandle {.rtl, extern: "nosp$1",
+  tags: [].} =
+  ## returns ``p``'s error file handle for reading from.
+  ##
+  ## **Warning**: The returned `TFileHandle` should not be closed manually as
+  ## it is closed when closing the PProcess ``p``.
+  result = p.errHandle
+
 when defined(macosx) or defined(bsd):
   const
     CTL_HW = 6
@@ -212,8 +236,8 @@ proc execProcesses*(cmds: openArray[string],
             inc(i)
             if i > high(cmds): break
     for j in 0..m-1:
-      if q[j] != nil: close(q[j])
       result = max(waitForExit(q[j]), result)
+      if q[j] != nil: close(q[j])
   else:
     for i in 0..high(cmds):
       var p = startCmd(cmds[i], options=options)
@@ -339,16 +363,16 @@ when defined(Windows) and not defined(useNimRtl):
         HE = HO
       else:
         CreatePipeHandles(HE, Si.hStdError)
-      result.inputHandle = TFileHandle(hi)
-      result.outputHandle = TFileHandle(ho)
-      result.errorHandle = TFileHandle(he)
+      result.inHandle = TFileHandle(hi)
+      result.outHandle = TFileHandle(ho)
+      result.errHandle = TFileHandle(he)
     else:
       SI.hStdError = GetStdHandle(STD_ERROR_HANDLE)
       SI.hStdInput = GetStdHandle(STD_INPUT_HANDLE)
       SI.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE)
-      result.inputHandle = TFileHandle(si.hStdInput)
-      result.outputHandle = TFileHandle(si.hStdOutput)
-      result.errorHandle = TFileHandle(si.hStdError)
+      result.inHandle = TFileHandle(si.hStdInput)
+      result.outHandle = TFileHandle(si.hStdOutput)
+      result.errHandle = TFileHandle(si.hStdError)
 
     var cmdl: cstring
     when false: # poUseShell in options:
@@ -389,9 +413,9 @@ when defined(Windows) and not defined(useNimRtl):
   proc close(p: PProcess) =
     when false:
       # somehow this does not work on Windows:
-      discard CloseHandle(p.inputHandle)
-      discard CloseHandle(p.outputHandle)
-      discard CloseHandle(p.errorHandle)
+      discard CloseHandle(p.inHandle)
+      discard CloseHandle(p.outHandle)
+      discard CloseHandle(p.errHandle)
       discard CloseHandle(p.FProcessHandle)
 
   proc suspend(p: PProcess) =
@@ -425,13 +449,13 @@ when defined(Windows) and not defined(useNimRtl):
       return res
 
   proc inputStream(p: PProcess): PStream =
-    result = newFileHandleStream(p.inputHandle)
+    result = newFileHandleStream(p.inHandle)
 
   proc outputStream(p: PProcess): PStream =
-    result = newFileHandleStream(p.outputHandle)
+    result = newFileHandleStream(p.outHandle)
 
   proc errorStream(p: PProcess): PStream =
-    result = newFileHandleStream(p.errorHandle)
+    result = newFileHandleStream(p.errHandle)
 
   proc execCmd(command: string): int =
     var
@@ -626,20 +650,20 @@ elif not defined(useNimRtl):
 
     if poParentStreams in options:
       # does not make much sense, but better than nothing:
-      result.inputHandle = 0
-      result.outputHandle = 1
+      result.inHandle = 0
+      result.outHandle = 1
       if poStdErrToStdOut in options:
-        result.errorHandle = result.outputHandle
+        result.errHandle = result.outHandle
       else:
-        result.errorHandle = 2
+        result.errHandle = 2
     else:
-      result.inputHandle = p_stdin[writeIdx]
-      result.outputHandle = p_stdout[readIdx]
+      result.inHandle = p_stdin[writeIdx]
+      result.outHandle = p_stdout[readIdx]
       if poStdErrToStdOut in options:
-        result.errorHandle = result.outputHandle
+        result.errHandle = result.outHandle
         discard close(p_stderr[readIdx])
       else:
-        result.errorHandle = p_stderr[readIdx]
+        result.errHandle = p_stderr[readIdx]
       discard close(p_stderr[writeIdx])
       discard close(p_stdin[readIdx])
       discard close(p_stdout[writeIdx])
@@ -648,9 +672,9 @@ elif not defined(useNimRtl):
     if p.inStream != nil: close(p.inStream)
     if p.outStream != nil: close(p.outStream)
     if p.errStream != nil: close(p.errStream)
-    discard close(p.inputHandle)
-    discard close(p.outputHandle)
-    discard close(p.errorHandle)
+    discard close(p.inHandle)
+    discard close(p.outHandle)
+    discard close(p.errHandle)
 
   proc suspend(p: PProcess) =
     if kill(-p.id, SIGSTOP) != 0'i32: OSError(OSLastError())
@@ -696,17 +720,17 @@ elif not defined(useNimRtl):
 
   proc inputStream(p: PProcess): PStream =
     if p.inStream == nil:
-      createStream(p.inStream, p.inputHandle, fmWrite)
+      createStream(p.inStream, p.inHandle, fmWrite)
     return p.inStream
 
   proc outputStream(p: PProcess): PStream =
     if p.outStream == nil:
-      createStream(p.outStream, p.outputHandle, fmRead)
+      createStream(p.outStream, p.outHandle, fmRead)
     return p.outStream
 
   proc errorStream(p: PProcess): PStream =
     if p.errStream == nil:
-      createStream(p.errStream, p.errorHandle, fmRead)
+      createStream(p.errStream, p.errHandle, fmRead)
     return p.errStream
 
   proc csystem(cmd: cstring): cint {.nodecl, importc: "system".}
@@ -717,14 +741,14 @@ elif not defined(useNimRtl):
   proc createFdSet(fd: var TFdSet, s: seq[PProcess], m: var int) = 
     FD_ZERO(fd)
     for i in items(s): 
-      m = max(m, int(i.outputHandle))
-      FD_SET(cint(i.outputHandle), fd)
+      m = max(m, int(i.outHandle))
+      FD_SET(cint(i.outHandle), fd)
      
   proc pruneProcessSet(s: var seq[PProcess], fd: var TFdSet) = 
     var i = 0
     var L = s.len
     while i < L:
-      if FD_ISSET(cint(s[i].outputHandle), fd) != 0'i32:
+      if FD_ISSET(cint(s[i].outHandle), fd) != 0'i32:
         s[i] = s[L-1]
         dec(L)
       else:
diff --git a/lib/pure/scgi.nim b/lib/pure/scgi.nim
index 8e45032c8..b18fe0094 100644
--- a/lib/pure/scgi.nim
+++ b/lib/pure/scgi.nim
@@ -95,7 +95,8 @@ proc recvBuffer(s: var TScgiState, L: int) =
     scgiError("could not read all data")
   setLen(s.input, L)
   
-proc open*(s: var TScgiState, port = TPort(4000), address = "127.0.0.1") = 
+proc open*(s: var TScgiState, port = TPort(4000), address = "127.0.0.1",
+  reuseAddr = False) = 
   ## opens a connection.
   s.bufLen = 4000
   s.input = newString(s.buflen) # will be reused
@@ -104,6 +105,8 @@ proc open*(s: var TScgiState, port = TPort(4000), address = "127.0.0.1") =
   new(s.client) # Initialise s.client for `next`
   if s.server == InvalidSocket: scgiError("could not open socket")
   #s.server.connect(connectionName, port)
+  if reuseAddr:
+    s.server.setSockOpt(OptReuseAddr, True)
   bindAddr(s.server, port, address)
   listen(s.server)
   
@@ -243,7 +246,8 @@ proc handleAccept(sock: PAsyncSocket, s: PAsyncScgiState) =
 
 proc open*(handleRequest: proc (client: PAsyncSocket, 
                                 input: string, headers: PStringTable) {.closure.},
-           port = TPort(4000), address = "127.0.0.1"): PAsyncScgiState =
+           port = TPort(4000), address = "127.0.0.1",
+           reuseAddr = false): PAsyncScgiState =
   ## Creates an ``PAsyncScgiState`` object which serves as a SCGI server.
   ##
   ## After the execution of ``handleRequest`` the client socket will be closed
@@ -252,6 +256,8 @@ proc open*(handleRequest: proc (client: PAsyncSocket,
   new(cres)
   cres.asyncServer = AsyncSocket()
   cres.asyncServer.handleAccept = proc (s: PAsyncSocket) = handleAccept(s, cres)
+  if reuseAddr:
+    cres.asyncServer.setSockOpt(OptReuseAddr, True)
   bindAddr(cres.asyncServer, port, address)
   listen(cres.asyncServer)
   cres.handleRequest = handleRequest
diff --git a/lib/pure/sockets.nim b/lib/pure/sockets.nim
index c8a4171ab..66bb1e6a9 100644
--- a/lib/pure/sockets.nim
+++ b/lib/pure/sockets.nim
@@ -31,6 +31,7 @@ when hostos == "solaris":
 
 import os, parseutils
 from times import epochTime
+import unsigned
 
 when defined(ssl):
   import openssl
@@ -62,7 +63,7 @@ const
 
 type
   TSocketImpl = object ## socket type
-    fd: cint
+    fd: TSocketHandle
     case isBuffered: bool # determines whether this socket is buffered.
     of true:
       buffer: array[0..BufferSize, char]
@@ -82,7 +83,7 @@ type
   
   TSocket* = ref TSocketImpl
   
-  TPort* = distinct int16  ## port type
+  TPort* = distinct uint16  ## port type
   
   TDomain* = enum   ## domain, which specifies the protocol family of the
                     ## created socket. Other domains than those that are listed
@@ -118,6 +119,10 @@ type
     length*: int
     addrList*: seq[string]
 
+  TSOBool* = enum ## Boolean socket options.
+    OptAcceptConn, OptBroadcast, OptDebug, OptDontRoute, OptKeepAlive,
+    OptOOBInline, OptReuseAddr
+
   TRecvLineResult* = enum ## result for recvLineAsync
     RecvFullLine, RecvPartialLine, RecvDisconnected, RecvFail
 
@@ -126,7 +131,19 @@ type
 
   ETimeout* = object of ESynch
 
-proc newTSocket(fd: int32, isBuff: bool): TSocket =
+let
+  InvalidSocket*: TSocket = nil ## invalid socket
+
+when defined(windows):
+  let
+    OSInvalidSocket = winlean.INVALID_SOCKET
+else:
+  let
+    OSInvalidSocket = posix.INVALID_SOCKET
+
+proc newTSocket(fd: TSocketHandle, isBuff: bool): TSocket =
+  if fd == OSInvalidSocket:
+    return nil
   new(result)
   result.fd = fd
   result.isBuffered = isBuff
@@ -134,15 +151,11 @@ proc newTSocket(fd: int32, isBuff: bool): TSocket =
     result.currPos = 0
   result.nonblocking = false
 
-let
-  InvalidSocket*: TSocket = nil ## invalid socket
-
 proc `==`*(a, b: TPort): bool {.borrow.}
   ## ``==`` for ports.
 
-proc `$`*(p: TPort): string = 
+proc `$`*(p: TPort): string {.borrow.}
   ## returns the port number as a string
-  result = $ze(int16(p))
 
 proc ntohl*(x: int32): int32 = 
   ## Converts 32-bit integers from network to host byte order.
@@ -211,7 +224,9 @@ else:
 
 proc socket*(domain: TDomain = AF_INET, typ: TType = SOCK_STREAM,
              protocol: TProtocol = IPPROTO_TCP, buffered = true): TSocket =
-  ## Creates a new socket; returns `InvalidSocket` if an error occurs.  
+  ## Creates a new socket; returns `InvalidSocket` if an error occurs.
+  
+  # TODO: Perhaps this should just raise EOS when an error occurs.
   when defined(Windows):
     result = newTSocket(winlean.socket(ord(domain), ord(typ), ord(protocol)), buffered)
   else:
@@ -456,7 +471,7 @@ template acceptAddrPlain(noClientRet, successRet: expr,
   var sock = accept(server.fd, cast[ptr TSockAddr](addr(sockAddress)),
                     addr(addrLen))
   
-  if sock < 0:
+  if sock == OSInvalidSocket:
     let err = OSLastError()
     when defined(windows):
       if err.int32 == WSAEINPROGRESS:
@@ -529,7 +544,7 @@ proc acceptAddr*(server: TSocket, client: var TSocket, address: var string) {.
               SSLError("Unknown error")
 
 proc setBlocking*(s: TSocket, blocking: bool) {.tags: [].}
-  ## sets blocking mode on socket
+  ## Sets blocking mode on socket
 
 when defined(ssl):
   proc acceptAddrSSL*(server: TSocket, client: var TSocket,
@@ -623,24 +638,32 @@ proc close*(socket: TSocket) =
       discard SSLShutdown(socket.sslHandle)
 
 proc getServByName*(name, proto: string): TServent {.tags: [FReadIO].} =
-  ## well-known getservbyname proc.
+  ## Searches the database from the beginning and finds the first entry for 
+  ## which the service name specified by ``name`` matches the s_name member
+  ## and the protocol name specified by ``proto`` matches the s_proto member.
+  ##
+  ## On posix this will search through the ``/etc/services`` file.
   when defined(Windows):
     var s = winlean.getservbyname(name, proto)
   else:
     var s = posix.getservbyname(name, proto)
-  if s == nil: OSError(OSLastError())
+  if s == nil: raise newException(EOS, "Service not found.")
   result.name = $s.s_name
   result.aliases = cstringArrayToSeq(s.s_aliases)
   result.port = TPort(s.s_port)
   result.proto = $s.s_proto
   
 proc getServByPort*(port: TPort, proto: string): TServent {.tags: [FReadIO].} = 
-  ## well-known getservbyport proc.
+  ## Searches the database from the beginning and finds the first entry for 
+  ## which the port specified by ``port`` matches the s_port member and the 
+  ## protocol name specified by ``proto`` matches the s_proto member.
+  ##
+  ## On posix this will search through the ``/etc/services`` file.
   when defined(Windows):
     var s = winlean.getservbyport(ze(int16(port)).cint, proto)
   else:
     var s = posix.getservbyport(ze(int16(port)).cint, proto)
-  if s == nil: OSError(OSLastError())
+  if s == nil: raise newException(EOS, "Service not found.")
   result.name = $s.s_name
   result.aliases = cstringArrayToSeq(s.s_aliases)
   result.port = TPort(s.s_port)
@@ -676,7 +699,7 @@ proc getHostByAddr*(ip: string): THostEnt {.tags: [FReadIO].} =
   result.length = int(s.h_length)
 
 proc getHostByName*(name: string): THostEnt {.tags: [FReadIO].} = 
-  ## well-known gethostbyname proc.
+  ## This function will lookup the IP address of a hostname.
   when defined(Windows):
     var s = winlean.gethostbyname(name)
   else:
@@ -714,6 +737,34 @@ proc setSockOptInt*(socket: TSocket, level, optname, optval: int) {.
                 sizeof(value).TSockLen) < 0'i32:
     OSError(OSLastError())
 
+proc toCInt(opt: TSOBool): cint =
+  case opt
+  of OptAcceptConn: SO_ACCEPTCONN
+  of OptBroadcast: SO_BROADCAST
+  of OptDebug: SO_DEBUG
+  of OptDontRoute: SO_DONTROUTE
+  of OptKeepAlive: SO_KEEPALIVE
+  of OptOOBInline: SO_OOBINLINE
+  of OptReuseAddr: SO_REUSEADDR
+
+proc getSockOpt*(socket: TSocket, opt: TSOBool, level = SOL_SOCKET): bool {.
+  tags: [FReadIO].} =
+  ## Retrieves option ``opt`` as a boolean value.
+  var res: cint
+  var size = sizeof(res).TSockLen
+  if getsockopt(socket.fd, cint(level), toCInt(opt), 
+                addr(res), addr(size)) < 0'i32:
+    OSError(OSLastError())
+  result = res != 0
+
+proc setSockOpt*(socket: TSocket, opt: TSOBool, value: bool, level = SOL_SOCKET) {.
+  tags: [FWriteIO].} =
+  ## Sets option ``opt`` to a boolean value specified by ``value``.
+  var valuei = cint(if value: 1 else: 0)
+  if setsockopt(socket.fd, cint(level), toCInt(opt), addr(valuei),  
+                sizeof(valuei).TSockLen) < 0'i32:
+    OSError(OSLastError())
+
 proc connect*(socket: TSocket, address: string, port = TPort(0), 
               af: TDomain = AF_INET) {.tags: [FReadIO].} =
   ## Connects socket to ``address``:``port``. ``Address`` can be an IP address or a
@@ -866,11 +917,6 @@ proc timeValFromMilliseconds(timeout = 500): TTimeVal =
     var seconds = timeout div 1000
     result.tv_sec = seconds.int32
     result.tv_usec = ((timeout - seconds * 1000) * 1000).int32
-#proc recvfrom*(s: TWinSocket, buf: cstring, len, flags: cint, 
-#               fromm: ptr TSockAddr, fromlen: ptr cint): cint 
-
-#proc sendto*(s: TWinSocket, buf: cstring, len, flags: cint,
-#             to: ptr TSockAddr, tolen: cint): cint
 
 proc createFdSet(fd: var TFdSet, s: seq[TSocket], m: var int) = 
   FD_ZERO(fd)
@@ -1608,14 +1654,14 @@ when defined(Windows):
     FIONBIO = IOC_IN.int32 or ((sizeof(int32) and IOCPARM_MASK) shl 16) or 
                              (102 shl 8) or 126
 
-  proc ioctlsocket(s: TWinSocket, cmd: clong, 
+  proc ioctlsocket(s: TSocketHandle, cmd: clong, 
                    argptr: ptr clong): cint {.
                    stdcall, importc:"ioctlsocket", dynlib: "ws2_32.dll".}
 
 proc setBlocking(s: TSocket, blocking: bool) =
   when defined(Windows):
     var mode = clong(ord(not blocking)) # 1 for non-blocking, 0 for blocking
-    if ioctlsocket(TWinSocket(s.fd), FIONBIO, addr(mode)) == -1:
+    if ioctlsocket(TSocketHandle(s.fd), FIONBIO, addr(mode)) == -1:
       OSError(OSLastError())
   else: # BSD sockets
     var x: int = fcntl(s.fd, F_GETFL, 0)
@@ -1656,9 +1702,12 @@ proc connect*(socket: TSocket, address: string, port = TPort(0), timeout: int,
 proc isSSL*(socket: TSocket): bool = return socket.isSSL
   ## Determines whether ``socket`` is a SSL socket.
 
-proc getFD*(socket: TSocket): cint = return socket.fd
+proc getFD*(socket: TSocket): TSocketHandle = return socket.fd
   ## Returns the socket's file descriptor
 
+proc isBlocking*(socket: TSocket): bool = not socket.nonblocking
+  ## Determines whether ``socket`` is blocking.
+
 when defined(Windows):
   var wsa: TWSADATA
   if WSAStartup(0x0101'i16, addr wsa) != 0: OSError(OSLastError())
diff --git a/lib/pure/times.nim b/lib/pure/times.nim
index 80a5ad8d3..e967ef683 100644
--- a/lib/pure/times.nim
+++ b/lib/pure/times.nim
@@ -246,7 +246,8 @@ proc toSeconds(a: TTimeInfo, interval: TTimeInterval): float =
     else:
       curMonth.inc()
   result += float(newinterv.days * 24 * 60 * 60)
-  result += float(newinterv.minutes * 60 * 60)
+  result += float(newinterv.hours * 60 * 60)
+  result += float(newinterv.minutes * 60)
   result += float(newinterv.seconds)
   result += newinterv.miliseconds / 1000
 
diff --git a/lib/pure/unicode.nim b/lib/pure/unicode.nim
index 142178a86..4aacb2f71 100644
--- a/lib/pure/unicode.nim
+++ b/lib/pure/unicode.nim
@@ -55,31 +55,31 @@ template fastRuneAt*(s: string, i: int, result: expr, doInc = true) =
     result = TRune(ord(s[i]))
     when doInc: inc(i)
   elif ord(s[i]) shr 5 == 0b110:
-    assert(ord(s[i+1]) shr 6 == 0b10)
+    # assert(ord(s[i+1]) shr 6 == 0b10)
     result = TRune((ord(s[i]) and (ones(5))) shl 6 or 
                    (ord(s[i+1]) and ones(6)))
     when doInc: inc(i, 2)
   elif ord(s[i]) shr 4 == 0b1110:
-    assert(ord(s[i+1]) shr 6 == 0b10)
-    assert(ord(s[i+2]) shr 6 == 0b10)
+    # assert(ord(s[i+1]) shr 6 == 0b10)
+    # assert(ord(s[i+2]) shr 6 == 0b10)
     result = TRune((ord(s[i]) and ones(4)) shl 12 or
              (ord(s[i+1]) and ones(6)) shl 6 or
              (ord(s[i+2]) and ones(6)))
     when doInc: inc(i, 3)
   elif ord(s[i]) shr 3 == 0b11110:
-    assert(ord(s[i+1]) shr 6 == 0b10)
-    assert(ord(s[i+2]) shr 6 == 0b10)
-    assert(ord(s[i+3]) shr 6 == 0b10)
+    # assert(ord(s[i+1]) shr 6 == 0b10)
+    # assert(ord(s[i+2]) shr 6 == 0b10)
+    # assert(ord(s[i+3]) shr 6 == 0b10)
     result = TRune((ord(s[i]) and ones(3)) shl 18 or
              (ord(s[i+1]) and ones(6)) shl 12 or
              (ord(s[i+2]) and ones(6)) shl 6 or
              (ord(s[i+3]) and ones(6)))
     when doInc: inc(i, 4)
   elif ord(s[i]) shr 2 == 0b111110: 
-    assert(ord(s[i+1]) shr 6 == 0b10)
-    assert(ord(s[i+2]) shr 6 == 0b10)
-    assert(ord(s[i+3]) shr 6 == 0b10)
-    assert(ord(s[i+4]) shr 6 == 0b10)
+    # assert(ord(s[i+1]) shr 6 == 0b10)
+    # assert(ord(s[i+2]) shr 6 == 0b10)
+    # assert(ord(s[i+3]) shr 6 == 0b10)
+    # assert(ord(s[i+4]) shr 6 == 0b10)
     result = TRune((ord(s[i]) and ones(2)) shl 24 or
              (ord(s[i+1]) and ones(6)) shl 18 or
              (ord(s[i+2]) and ones(6)) shl 12 or
@@ -87,11 +87,11 @@ template fastRuneAt*(s: string, i: int, result: expr, doInc = true) =
              (ord(s[i+4]) and ones(6)))
     when doInc: inc(i, 5)
   elif ord(s[i]) shr 1 == 0b1111110: 
-    assert(ord(s[i+1]) shr 6 == 0b10)
-    assert(ord(s[i+2]) shr 6 == 0b10)
-    assert(ord(s[i+3]) shr 6 == 0b10)
-    assert(ord(s[i+4]) shr 6 == 0b10)
-    assert(ord(s[i+5]) shr 6 == 0b10)
+    # assert(ord(s[i+1]) shr 6 == 0b10)
+    # assert(ord(s[i+2]) shr 6 == 0b10)
+    # assert(ord(s[i+3]) shr 6 == 0b10)
+    # assert(ord(s[i+4]) shr 6 == 0b10)
+    # assert(ord(s[i+5]) shr 6 == 0b10)
     result = TRune((ord(s[i]) and ones(1)) shl 30 or
              (ord(s[i+1]) and ones(6)) shl 24 or
              (ord(s[i+2]) and ones(6)) shl 18 or
diff --git a/lib/system.nim b/lib/system.nim
index 9beead0b7..34b67267f 100644
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -849,7 +849,7 @@ const
     ## a string that describes the application type. Possible values:
     ## "console", "gui", "lib".
   
-  seqShallowFlag = 1 shl (sizeof(int)*8-1)
+  seqShallowFlag = low(int)
   
 proc compileOption*(option: string): bool {.
   magic: "CompileOption", noSideEffect.}
@@ -1795,7 +1795,7 @@ when defined(JS):
 
 elif hostOS != "standalone":
   {.push stack_trace:off, profiler:off.}
-  proc add*(x: var string, y: cstring) {.noStackFrame.} =
+  proc add*(x: var string, y: cstring) =
     var i = 0
     while y[i] != '\0':
       add(x, y[i])
diff --git a/lib/system/alloc.nim b/lib/system/alloc.nim
index 744c26d36..2bab79212 100644
--- a/lib/system/alloc.nim
+++ b/lib/system/alloc.nim
@@ -520,11 +520,18 @@ proc allocInv(a: TMemRegion): bool =
   for s in low(a.freeSmallChunks)..high(a.freeSmallChunks):
     var c = a.freeSmallChunks[s]
     while c != nil:
-      if c.next == c: return false
-      if c.size != s * MemAlign: return false
+      if c.next == c: 
+        echo "[SYSASSERT] c.next == c"
+        return false
+      if c.size != s * MemAlign: 
+        echo "[SYSASSERT] c.size != s * MemAlign"
+        return false
       var it = c.freeList
       while it != nil:
-        if it.zeroField != 0: return false
+        if it.zeroField != 0: 
+          echo "[SYSASSERT] it.zeroField != 0"
+          cprintf("%ld %p\n", it.zeroField, it)
+          return false
         it = it.next
       c = c.next
   result = true
@@ -591,6 +598,7 @@ proc rawAlloc(a: var TMemRegion, requestedSize: int): pointer =
     add(a, a.root, cast[TAddress](result), cast[TAddress](result)+%size)
   sysAssert(isAccessible(a, result), "rawAlloc 14")
   sysAssert(allocInv(a), "rawAlloc: end")
+  when logAlloc: cprintf("rawAlloc: %ld %p\n", requestedSize, result)
 
 proc rawAlloc0(a: var TMemRegion, requestedSize: int): pointer =
   result = rawAlloc(a, requestedSize)
@@ -638,6 +646,7 @@ proc rawDealloc(a: var TMemRegion, p: pointer) =
     del(a, a.root, cast[int](addr(c.data)))
     freeBigChunk(a, c)
   sysAssert(allocInv(a), "rawDealloc: end")
+  when logAlloc: cprintf("rawDealloc: %p\n", p)
 
 proc isAllocatedPtr(a: TMemRegion, p: pointer): bool = 
   if isAccessible(a, p):
diff --git a/lib/system/atomics.nim b/lib/system/atomics.nim
index 623f8d0d2..36185e0a8 100644
--- a/lib/system/atomics.nim
+++ b/lib/system/atomics.nim
@@ -9,68 +9,207 @@
 
 # Atomic operations for Nimrod.
 
-when (defined(gcc) or defined(llvm_gcc)) and hasThreadSupport and 
-    not defined(windows):
-  proc sync_add_and_fetch(p: var int, val: int): int {.
-    importc: "__sync_add_and_fetch", nodecl.}
-  proc sync_sub_and_fetch(p: var int, val: int): int {.
-    importc: "__sync_sub_and_fetch", nodecl.}
+when (defined(gcc) or defined(llvm_gcc)) and hasThreadSupport: 
+  
+  type 
+    AtomMemModel* = enum
+      ATOMIC_RELAXED, 
+    ## No barriers or synchronization. 
+      ATOMIC_CONSUME, 
+    ## Data dependency only for both barrier and synchronization with another thread.
+      ATOMIC_ACQUIRE, 
+    ## Barrier to hoisting of code and synchronizes with release (or stronger) 
+    ## semantic stores from another thread.
+      ATOMIC_RELEASE,
+    ## Barrier to sinking of code and synchronizes with acquire (or stronger) 
+    ## semantic loads from another thread. 
+      ATOMIC_ACQ_REL,
+    ## Full barrier in both directions and synchronizes with acquire loads 
+    ## and release stores in another thread.
+      ATOMIC_SEQ_CST
+    ## Full barrier in both directions and synchronizes with acquire loads 
+    ## and release stores in all threads.
+
+    TAtomType* = TNumber|pointer|ptr|char
+    ## Type Class representing valid types for use with atomic procs
+
+  proc atomic_load_n*[T: TAtomType](p: ptr T, mem: AtomMemModel): T {.
+    importc: "__atomic_load_n", nodecl.}
+    ## This proc implements an atomic load operation. It returns the contents at p.
+    ## ATOMIC_RELAXED, ATOMIC_SEQ_CST, ATOMIC_ACQUIRE, ATOMIC_CONSUME.
+
+  proc atomic_load*[T: TAtomType](p: ptr T, ret: ptr T, mem: AtomMemModel) {.
+    importc: "__atomic_load", nodecl.}  
+    ## This is the generic version of an atomic load. It returns the contents at p in ret.
+
+  proc atomic_store_n*[T: TAtomType](p: ptr T, val: T, mem: AtomMemModel) {.
+    importc: "__atomic_store_n", nodecl.} 
+    ## This proc implements an atomic store operation. It writes val at p.
+    ## ATOMIC_RELAXED, ATOMIC_SEQ_CST, and ATOMIC_RELEASE.
+
+  proc atomic_store*[T: TAtomType](p: ptr T, val: ptr T, mem: AtomMemModel) {.
+    importc: "__atomic_store", nodecl.}
+    ## This is the generic version of an atomic store. It stores the value of val at p
+
+  proc atomic_exchange_n*[T: TAtomType](p: ptr T, val: T, mem: AtomMemModel): T {.
+    importc: "__atomic_exchange_n", nodecl.}
+    ## This proc implements an atomic exchange operation. It writes val at p, 
+    ## and returns the previous contents at p.
+    ## ATOMIC_RELAXED, ATOMIC_SEQ_CST, ATOMIC_ACQUIRE, ATOMIC_RELEASE, ATOMIC_ACQ_REL
+
+  proc atomic_exchange*[T: TAtomType](p: ptr T, val: ptr T, ret: ptr T, mem: AtomMemModel) {.
+    importc: "__atomic_exchange", nodecl.}
+    ## This is the generic version of an atomic exchange. It stores the contents at val at p. 
+    ## The original value at p is copied into ret.
+
+  proc atomic_compare_exchange_n*[T: TAtomType](p: ptr T, expected: ptr T, desired: T,
+    weak: bool, success_memmodel: AtomMemModel, failure_memmodel: AtomMemModel): bool {.
+    importc: "__atomic_compare_exchange_n ", nodecl.} 
+    ## This proc implements an atomic compare and exchange operation. This compares the
+    ## contents at p with the contents at expected and if equal, writes desired at p. 
+    ## If they are not equal, the current contents at p is written into expected. 
+    ## Weak is true for weak compare_exchange, and false for the strong variation. 
+    ## Many targets only offer the strong variation and ignore the parameter. 
+    ## When in doubt, use the strong variation.
+    ## True is returned if desired is written at p and the execution is considered 
+    ## to conform to the memory model specified by success_memmodel. There are no 
+    ## restrictions on what memory model can be used here. False is returned otherwise, 
+    ## and the execution is considered to conform to failure_memmodel. This memory model 
+    ## cannot be __ATOMIC_RELEASE nor __ATOMIC_ACQ_REL. It also cannot be a stronger model 
+    ## than that specified by success_memmodel.
+
+  proc atomic_compare_exchange*[T: TAtomType](p: ptr T, expected: ptr T, desired: ptr T,
+    weak: bool, success_memmodel: AtomMemModel, failure_memmodel: AtomMemModel): bool {.
+    importc: "__atomic_compare_exchange_n ", nodecl.}  
+    ## This proc implements the generic version of atomic_compare_exchange. 
+    ## The proc is virtually identical to atomic_compare_exchange_n, except the desired 
+    ## value is also a pointer. 
+
+  ## Perform the operation return the new value, all memory models are valid 
+  proc atomic_add_fetch*[T: TAtomType](p: ptr T, val: T, mem: AtomMemModel): T {.
+    importc: "__atomic_add_fetch", nodecl.}
+  proc atomic_sub_fetch*[T: TAtomType](p: ptr T, val: T, mem: AtomMemModel): T {.
+    importc: "__atomic_sub_fetch", nodecl.}
+  proc atomic_or_fetch*[T: TAtomType](p: ptr T, val: T, mem: AtomMemModel): T {.
+    importc: "__atomic_or_fetch ", nodecl.}
+  proc atomic_and_fetch*[T: TAtomType](p: ptr T, val: T, mem: AtomMemModel): T {.
+    importc: "__atomic_and_fetch", nodecl.}
+  proc atomic_xor_fetch*[T: TAtomType](p: ptr T, val: T, mem: AtomMemModel): T {.   
+    importc: "__atomic_xor_fetch", nodecl.}
+  proc atomic_nand_fetch*[T: TAtomType](p: ptr T, val: T, mem: AtomMemModel): T {.   
+    importc: "__atomic_nand_fetch ", nodecl.} 
+
+  ## Perform the operation return the old value, all memory models are valid 
+  proc atomic_fetch_add*[T: TAtomType](p: ptr T, val: T, mem: AtomMemModel): T {.
+    importc: "__atomic_fetch_add ", nodecl.}
+  proc atomic_fetch_sub*[T: TAtomType](p: ptr T, val: T, mem: AtomMemModel): T {.  
+    importc: "__atomic_fetch_sub ", nodecl.}
+  proc atomic_fetch_or*[T: TAtomType](p: ptr T, val: T, mem: AtomMemModel): T {.  
+    importc: "__atomic_fetch_or ", nodecl.}
+  proc atomic_fetch_and*[T: TAtomType](p: ptr T, val: T, mem: AtomMemModel): T {.   
+    importc: "__atomic_fetch_and ", nodecl.}
+  proc atomic_fetch_xor*[T: TAtomType](p: ptr T, val: T, mem: AtomMemModel): T {.  
+    importc: "__atomic_fetch_xor ", nodecl.}
+  proc atomic_fetch_nand*[T: TAtomType](p: ptr T, val: T, mem: AtomMemModel): T {.  
+    importc: "__atomic_fetch_nand", nodecl.} 
+
+  proc atomic_test_and_set*(p: pointer, mem: AtomMemModel): bool {.  
+    importc: "__atomic_test_and_set ", nodecl.} 
+    ## This built-in function performs an atomic test-and-set operation on the byte at p. 
+    ## The byte is set to some implementation defined nonzero “set” value and the return
+    ## value is true if and only if the previous contents were “set”.
+    ## All memory models are valid.
+
+  proc atomic_clear*(p: pointer, mem: AtomMemModel) {.  
+    importc: "__atomic_clear", nodecl.}
+    ## This built-in function performs an atomic clear operation at p. 
+    ## After the operation, at p contains 0.
+    ## ATOMIC_RELAXED, ATOMIC_SEQ_CST, ATOMIC_RELEASE
+
+  proc atomic_thread_fence*(mem: AtomMemModel) {.  
+    importc: "__atomic_thread_fence ", nodecl.}
+    ## This built-in function acts as a synchronization fence between threads based 
+    ## on the specified memory model. All memory orders are valid.
+
+  proc atomic_signal_fence*(mem: AtomMemModel) {.  
+    importc: "__atomic_signal_fence  ", nodecl.}
+    ## This built-in function acts as a synchronization fence between a thread and 
+    ## signal handlers based in the same thread. All memory orders are valid.
+
+  proc atomic_always_lock_free*(size: int, p: pointer): bool {.  
+    importc: "__atomic_always_lock_free   ", nodecl.}
+    ## This built-in function returns true if objects of size bytes always generate 
+    ## lock free atomic instructions for the target architecture. size must resolve 
+    ## to a compile-time constant and the result also resolves to a compile-time constant.
+    ## ptr is an optional pointer to the object that may be used to determine alignment. 
+    ## A value of 0 indicates typical alignment should be used. The compiler may also 
+    ## ignore this parameter.
+
+  proc atomic_is_lock_free*(size: int, p: pointer): bool {.  
+    importc: "__atomic_is_lock_free    ", nodecl.}
+    ## This built-in function returns true if objects of size bytes always generate 
+    ## lock free atomic instructions for the target architecture. If it is not known 
+    ## to be lock free a call is made to a runtime routine named __atomic_is_lock_free.
+    ## ptr is an optional pointer to the object that may be used to determine alignment. 
+    ## A value of 0 indicates typical alignment should be used. The compiler may also 
+    ## ignore this parameter.
+
+
+
 elif defined(vcc) and hasThreadSupport:
-  proc sync_add_and_fetch(p: var int, val: int): int {.
+  proc add_and_fetch*(p: ptr int, val: int): int {.
     importc: "NimXadd", nodecl.}
 else:
-  proc sync_add_and_fetch(p: var int, val: int): int {.inline.} =
-    inc(p, val)
-    result = p
+  proc add_and_fetch*(p: ptr int, val: int): int {.inline.} =
+    inc(p[], val)
+    result = p[]
+
+
+
+
+# atomic compare and swap (CAS) funcitons to implement lock-free algorithms  
+      
+#if defined(windows) and not defined(gcc) and hasThreadSupport:
+#    proc InterlockedCompareExchangePointer(mem: ptr pointer,
+#      newValue: pointer, comparand: pointer) : pointer {.nodecl, 
+#        importc: "InterlockedCompareExchangePointer", header:"windows.h".}
+
+#    proc compareAndSwap*[T](mem: ptr T, 
+#      expected: T, newValue: T): bool {.inline.}=
+#      ## Returns true if successfully set value at mem to newValue when value
+#      ## at mem == expected
+#      return InterlockedCompareExchangePointer(addr(mem), 
+#        addr(newValue), addr(expected))[] == expected
+    
+#elif not hasThreadSupport:
+#  proc compareAndSwap*[T](mem: ptr T, 
+#    expected: T, newValue: T): bool {.inline.} =
+#      ## Returns true if successfully set value at mem to newValue when value
+#      ## at mem == expected
+#      var oldval = mem[]
+#      if oldval == expected:
+#        mem[] = newValue
+#        return true
+#      return false
+
 
-proc atomicInc(memLoc: var int, x: int = 1): int =
-  when hasThreadSupport:
-    result = sync_add_and_fetch(memLoc, x)
+# Some convenient functions 
+proc atomicInc*(memLoc: var int, x: int = 1): int =
+  when defined(gcc) and hasThreadSupport:
+    result = atomic_add_fetch(memLoc.addr, x, ATOMIC_RELAXED)
   else:
     inc(memLoc, x)
     result = memLoc
   
-proc atomicDec(memLoc: var int, x: int = 1): int =
-  when hasThreadSupport:
-    when defined(sync_sub_and_fetch):
-      result = sync_sub_and_fetch(memLoc, x)
+proc atomicDec*(memLoc: var int, x: int = 1): int =
+  when defined(gcc) and hasThreadSupport:
+    when defined(atomic_sub_fetch):
+      result = atomic_sub_fetch(memLoc.addr, x, ATOMIC_RELAXED)
     else:
-      result = sync_add_and_fetch(memLoc, -x)
+      result = atomic_add_fetch(memLoc.addr, -x, ATOMIC_RELAXED)
   else:
     dec(memLoc, x)
     result = memLoc  
 
 
-# atomic compare and swap (CAS) funcitons to implement lock-free algorithms
-
-when (defined(gcc) or defined(llvm_gcc)) and hasThreadSupport:
-  proc compareAndSwap*[T: ptr|ref|pointer](mem: var T, expected: T, newValue: T): bool {.nodecl, 
-      importc: " __sync_bool_compare_and_swap".}
-    ## Returns true if successfully set value at mem to newValue when value
-    ## at mem == expected
-      
-elif defined(windows) and hasThreadSupport:
-    proc InterlockedCompareExchangePointer(mem: ptr pointer,
-      newValue: pointer, comparand: pointer) : pointer {.nodecl, 
-        importc: "InterlockedCompareExchangePointer", header:"windows.h".}
-
-
-    proc compareAndSwap*[T: ptr|ref|pointer](mem: var T, 
-      expected: T, newValue: T): bool {.inline.}=
-      ## Returns true if successfully set value at mem to newValue when value
-      ## at mem == expected
-      return InterlockedCompareExchangePointer(addr(mem), 
-        newValue, expected) == expected
-    
-elif not hasThreadSupport:
-  proc compareAndSwap*[T: ptr|ref|pointer](mem: var T, 
-    expected: T, newValue: T): bool {.inline.} =
-      ## Returns true if successfully set value at mem to newValue when value
-      ## at mem == expected
-      var oldval = mem
-      if oldval == expected:
-        mem = newValue
-        return true
-      return false
-
 
diff --git a/lib/system/gc.nim b/lib/system/gc.nim
index c5d4d2aa2..48705db96 100644
--- a/lib/system/gc.nim
+++ b/lib/system/gc.nim
@@ -9,7 +9,7 @@
 
 #            Garbage Collector
 #
-# The basic algorithm is *Deferrent Reference Counting* with cycle detection.
+# The basic algorithm is *Deferred Reference Counting* with cycle detection.
 # This is achieved by combining a Deutsch-Bobrow garbage collector
 # together with Christoper's partial mark-sweep garbage collector.
 #
@@ -407,12 +407,17 @@ proc addNewObjToZCT(res: PCell, gch: var TGcHeap) {.inline.} =
         return
     add(gch.zct, res)
 
+{.push stackTrace: off, profiler:off.}
+proc gcInvariant*(msg: string) =
+  sysAssert(allocInv(gch.region), msg)
+{.pop.}
+
 proc rawNewObj(typ: PNimType, size: int, gch: var TGcHeap): pointer =
   # generates a new object and sets its reference counter to 0
+  sysAssert(allocInv(gch.region), "rawNewObj begin")
   acquire(gch)
   gcAssert(typ.kind in {tyRef, tyString, tySequence}, "newObj: 1")
   collectCT(gch)
-  sysAssert(allocInv(gch.region), "rawNewObj begin")
   var res = cast[PCell](rawAlloc(gch.region, size + sizeof(TCell)))
   gcAssert((cast[TAddress](res) and (MemAlign-1)) == 0, "newObj: 2")
   # now it is buffered in the ZCT
@@ -517,7 +522,9 @@ proc growObj(old: pointer, newsize: int, gch: var TGcHeap): pointer =
     writeCell("growObj new cell", res)
   gcTrace(ol, csZctFreed)
   gcTrace(res, csAllocated)
-  when reallyDealloc: rawDealloc(gch.region, ol)
+  when reallyDealloc: 
+    sysAssert(allocInv(gch.region), "growObj before dealloc")
+    rawDealloc(gch.region, ol)
   else:
     sysAssert(ol.typ != nil, "growObj: 5")
     zeroMem(ol, sizeof(TCell))
@@ -537,7 +544,9 @@ proc freeCyclicCell(gch: var TGcHeap, c: PCell) =
   prepareDealloc(c)
   gcTrace(c, csCycFreed)
   when logGC: writeCell("cycle collector dealloc cell", c)
-  when reallyDealloc: rawDealloc(gch.region, c)
+  when reallyDealloc: 
+    sysAssert(allocInv(gch.region), "free cyclic cell")
+    rawDealloc(gch.region, c)
   else:
     gcAssert(c.typ != nil, "freeCyclicCell")
     zeroMem(c, sizeof(TCell))
@@ -910,7 +919,9 @@ proc collectZCT(gch: var TGcHeap): bool =
       # access invalid memory. This is done by prepareDealloc():
       prepareDealloc(c)
       forAllChildren(c, waZctDecRef)
-      when reallyDealloc: rawDealloc(gch.region, c)
+      when reallyDealloc: 
+        sysAssert(allocInv(gch.region), "collectZCT: rawDealloc")
+        rawDealloc(gch.region, c)
       else:
         sysAssert(c.typ != nil, "collectZCT 2")
         zeroMem(c, sizeof(TCell))
diff --git a/lib/system/gc2.nim b/lib/system/gc2.nim
index 05c291371..31c99a601 100644
--- a/lib/system/gc2.nim
+++ b/lib/system/gc2.nim
@@ -387,8 +387,7 @@ template `--`(rc: TRefCount): expr =
   rc <% rcIncrement
 
 template `--` (rc: TRefCount, heapType: THeapType): expr =
-  (when heapType == SharedHeap: atomicDec(rc, rcIncrement) <% rcIncrement
-   else: --rc)
+  (when heapType == SharedHeap: atomicDec(rc, rcIncrement) <% rcIncrement else: --rc)
 
 template doDecRef(cc: PCell,
                   heapType = LocalHeap,
diff --git a/lib/system/mmdisp.nim b/lib/system/mmdisp.nim
index c9801abad..118272ee3 100644
--- a/lib/system/mmdisp.nim
+++ b/lib/system/mmdisp.nim
@@ -28,6 +28,7 @@ const
   reallyOsDealloc = true
   coalescRight = true
   coalescLeft = true
+  logAlloc = false
 
 type
   PPointer = ptr pointer
diff --git a/lib/windows/winlean.nim b/lib/windows/winlean.nim
index d448d2b10..56d279db6 100644
--- a/lib/windows/winlean.nim
+++ b/lib/windows/winlean.nim
@@ -335,6 +335,9 @@ const
 proc WSAGetLastError*(): cint {.importc: "WSAGetLastError", dynlib: ws2dll.}
 
 type
+  TSocketHandle* = distinct int
+
+type
   TWSAData* {.pure, final, importc: "WSADATA", header: "Winsock2.h".} = object 
     wVersion, wHighVersion: int16
     szDescription: array[0..WSADESCRIPTION_LEN, char]
@@ -389,12 +392,10 @@ type
     h_addrtype*: int16
     h_length*: int16
     h_addr_list*: cstringArray
-    
-  TWinSocket* = cint
   
   TFdSet* {.pure, final.} = object
     fd_count*: cint # unsigned
-    fd_array*: array[0..FD_SETSIZE-1, TWinSocket]
+    fd_array*: array[0..FD_SETSIZE-1, TSocketHandle]
     
   TTimeval* {.pure, final.} = object
     tv_sec*, tv_usec*: int32
@@ -413,6 +414,22 @@ type
 
 var
   SOMAXCONN* {.importc, header: "Winsock2.h".}: cint
+  INVALID_SOCKET* {.importc, header: "Winsock2.h".}: TSocketHandle
+  SOL_SOCKET* {.importc, header: "Winsock2.h".}: cint
+  SO_DEBUG* {.importc, header: "Winsock2.h".}: cint ## turn on debugging info recording

+  SO_ACCEPTCONN* {.importc, header: "Winsock2.h".}: cint # socket has had listen()

+  SO_REUSEADDR* {.importc, header: "Winsock2.h".}: cint # allow local address reuse

+  SO_KEEPALIVE* {.importc, header: "Winsock2.h".}: cint # keep connections alive

+  SO_DONTROUTE* {.importc, header: "Winsock2.h".}: cint # just use interface addresses

+  SO_BROADCAST* {.importc, header: "Winsock2.h".}: cint # permit sending of broadcast msgs

+  SO_USELOOPBACK* {.importc, header: "Winsock2.h".}: cint # bypass hardware when possible

+  SO_LINGER* {.importc, header: "Winsock2.h".}: cint # linger on close if data present

+  SO_OOBINLINE* {.importc, header: "Winsock2.h".}: cint # leave received OOB data in line

+

+  SO_DONTLINGER* {.importc, header: "Winsock2.h".}: cint

+  SO_EXCLUSIVEADDRUSE* {.importc, header: "Winsock2.h".}: cint # disallow local address reuse
+
+proc `==`*(x, y: TSocketHandle): bool {.borrow.}
 
 proc getservbyname*(name, proto: cstring): ptr TServent {.
   stdcall, importc: "getservbyname", dynlib: ws2dll.}
@@ -426,45 +443,45 @@ proc gethostbyaddr*(ip: ptr TInAddr, len: cuint, theType: cint): ptr THostEnt {.
 proc gethostbyname*(name: cstring): ptr THostEnt {.
   stdcall, importc: "gethostbyname", dynlib: ws2dll.}
 
-proc socket*(af, typ, protocol: cint): TWinSocket {.
+proc socket*(af, typ, protocol: cint): TSocketHandle {.
   stdcall, importc: "socket", dynlib: ws2dll.}
 
-proc closesocket*(s: TWinSocket): cint {.
+proc closesocket*(s: TSocketHandle): cint {.
   stdcall, importc: "closesocket", dynlib: ws2dll.}
 
-proc accept*(s: TWinSocket, a: ptr TSockAddr, addrlen: ptr TSockLen): TWinSocket {.
+proc accept*(s: TSocketHandle, a: ptr TSockAddr, addrlen: ptr TSockLen): TSocketHandle {.
   stdcall, importc: "accept", dynlib: ws2dll.}
-proc bindSocket*(s: TWinSocket, name: ptr TSockAddr, namelen: TSockLen): cint {.
+proc bindSocket*(s: TSocketHandle, name: ptr TSockAddr, namelen: TSockLen): cint {.
   stdcall, importc: "bind", dynlib: ws2dll.}
-proc connect*(s: TWinSocket, name: ptr TSockAddr, namelen: TSockLen): cint {.
+proc connect*(s: TSocketHandle, name: ptr TSockAddr, namelen: TSockLen): cint {.
   stdcall, importc: "connect", dynlib: ws2dll.}
-proc getsockname*(s: TWinSocket, name: ptr TSockAddr, 
+proc getsockname*(s: TSocketHandle, name: ptr TSockAddr, 
                   namelen: ptr TSockLen): cint {.
   stdcall, importc: "getsockname", dynlib: ws2dll.}
-proc getsockopt*(s: TWinSocket, level, optname: cint, optval: pointer,
+proc getsockopt*(s: TSocketHandle, level, optname: cint, optval: pointer,
                  optlen: ptr TSockLen): cint {.
   stdcall, importc: "getsockopt", dynlib: ws2dll.}
-proc setsockopt*(s: TWinSocket, level, optname: cint, optval: pointer,
+proc setsockopt*(s: TSocketHandle, level, optname: cint, optval: pointer,
                  optlen: TSockLen): cint {.
   stdcall, importc: "setsockopt", dynlib: ws2dll.}
 
-proc listen*(s: TWinSocket, backlog: cint): cint {.
+proc listen*(s: TSocketHandle, backlog: cint): cint {.
   stdcall, importc: "listen", dynlib: ws2dll.}
-proc recv*(s: TWinSocket, buf: pointer, len, flags: cint): cint {.
+proc recv*(s: TSocketHandle, buf: pointer, len, flags: cint): cint {.
   stdcall, importc: "recv", dynlib: ws2dll.}
-proc recvfrom*(s: TWinSocket, buf: cstring, len, flags: cint, 
+proc recvfrom*(s: TSocketHandle, buf: cstring, len, flags: cint, 
                fromm: ptr TSockAddr, fromlen: ptr Tsocklen): cint {.
   stdcall, importc: "recvfrom", dynlib: ws2dll.}
 proc select*(nfds: cint, readfds, writefds, exceptfds: ptr TFdSet,
              timeout: ptr TTimeval): cint {.
   stdcall, importc: "select", dynlib: ws2dll.}
-proc send*(s: TWinSocket, buf: pointer, len, flags: cint): cint {.
+proc send*(s: TSocketHandle, buf: pointer, len, flags: cint): cint {.
   stdcall, importc: "send", dynlib: ws2dll.}
-proc sendto*(s: TWinSocket, buf: pointer, len, flags: cint,
+proc sendto*(s: TSocketHandle, buf: pointer, len, flags: cint,
              to: ptr TSockAddr, tolen: Tsocklen): cint {.
   stdcall, importc: "sendto", dynlib: ws2dll.}
 
-proc shutdown*(s: TWinSocket, how: cint): cint {.
+proc shutdown*(s: TSocketHandle, how: cint): cint {.
   stdcall, importc: "shutdown", dynlib: ws2dll.}
   
 proc getnameinfo*(a1: ptr Tsockaddr, a2: Tsocklen,
@@ -475,13 +492,13 @@ proc getnameinfo*(a1: ptr Tsockaddr, a2: Tsocklen,
 proc inet_addr*(cp: cstring): int32 {.
   stdcall, importc: "inet_addr", dynlib: ws2dll.} 
 
-proc WSAFDIsSet(s: TWinSocket, FDSet: var TFDSet): bool {.
+proc WSAFDIsSet(s: TSocketHandle, FDSet: var TFDSet): bool {.
   stdcall, importc: "__WSAFDIsSet", dynlib: ws2dll.}
 
-proc FD_ISSET*(Socket: TWinSocket, FDSet: var TFDSet): cint = 
+proc FD_ISSET*(Socket: TSocketHandle, FDSet: var TFDSet): cint = 
   result = if WSAFDIsSet(Socket, FDSet): 1'i32 else: 0'i32
 
-proc FD_SET*(Socket: TWinSocket, FDSet: var TFDSet) = 
+proc FD_SET*(Socket: TSocketHandle, FDSet: var TFDSet) = 
   if FDSet.fd_count < FD_SETSIZE:
     FDSet.fd_array[int(FDSet.fd_count)] = Socket
     inc(FDSet.fd_count)
diff --git a/lib/wrappers/opengl/glx.nim b/lib/wrappers/opengl/glx.nim
index 76c052d70..ae5ca75b5 100644
--- a/lib/wrappers/opengl/glx.nim
+++ b/lib/wrappers/opengl/glx.nim
@@ -36,23 +36,23 @@ else:
   const 
     dllname = "libGL.so"
 const 
-  GLX_USE_GL* = 1
-  GLX_BUFFER_SIZE* = 2
-  GLX_LEVEL* = 3
-  GLX_RGBA* = 4
-  GLX_DOUBLEBUFFER* = 5
-  GLX_STEREO* = 6
-  GLX_AUX_BUFFERS* = 7
-  GLX_RED_SIZE* = 8
-  GLX_GREEN_SIZE* = 9
-  GLX_BLUE_SIZE* = 10
-  GLX_ALPHA_SIZE* = 11
-  GLX_DEPTH_SIZE* = 12
-  GLX_STENCIL_SIZE* = 13
-  GLX_ACCUM_RED_SIZE* = 14
-  GLX_ACCUM_GREEN_SIZE* = 15
-  GLX_ACCUM_BLUE_SIZE* = 16
-  GLX_ACCUM_ALPHA_SIZE* = 17  # GLX_EXT_visual_info extension
+  GLX_USE_GL* = 1'i32
+  GLX_BUFFER_SIZE* = 2'i32
+  GLX_LEVEL* = 3'i32
+  GLX_RGBA* = 4'i32
+  GLX_DOUBLEBUFFER* = 5'i32
+  GLX_STEREO* = 6'i32
+  GLX_AUX_BUFFERS* = 7'i32
+  GLX_RED_SIZE* = 8'i32
+  GLX_GREEN_SIZE* = 9'i32
+  GLX_BLUE_SIZE* = 10'i32
+  GLX_ALPHA_SIZE* = 11'i32
+  GLX_DEPTH_SIZE* = 12'i32
+  GLX_STENCIL_SIZE* = 13'i32
+  GLX_ACCUM_RED_SIZE* = 14'i32
+  GLX_ACCUM_GREEN_SIZE* = 15'i32
+  GLX_ACCUM_BLUE_SIZE* = 16'i32
+  GLX_ACCUM_ALPHA_SIZE* = 17'i32  # GLX_EXT_visual_info extension
   GLX_X_VISUAL_TYPE_EXT* = 0x00000022
   GLX_TRANSPARENT_TYPE_EXT* = 0x00000023
   GLX_TRANSPARENT_INDEX_VALUE_EXT* = 0x00000024
diff --git a/lib/wrappers/openssl.nim b/lib/wrappers/openssl.nim
index f310c969b..af72d04eb 100644
--- a/lib/wrappers/openssl.nim
+++ b/lib/wrappers/openssl.nim
@@ -45,6 +45,7 @@ when defined(WINDOWS):
   const 
     DLLSSLName = "(ssleay32|libssl32).dll"
     DLLUtilName = "libeay32.dll"
+  from winlean import TSocketHandle
 else:
   const
     versions = "(|.1.0.0|.0.9.9|.0.9.8|.0.9.7|.0.9.6|.0.9.5|.0.9.4)"
@@ -56,6 +57,7 @@ else:
     const 
       DLLSSLName = "libssl.so" & versions
       DLLUtilName = "libcrypto.so" & versions
+  from posix import TSocketHandle
 
 type 
   SslStruct {.final, pure.} = object
@@ -225,7 +227,7 @@ proc SSL_CTX_use_PrivateKey_file*(ctx: PSSL_CTX,
 proc SSL_CTX_check_private_key*(ctx: PSSL_CTX): cInt{.cdecl, dynlib: DLLSSLName, 
     importc.}
 
-proc SSL_set_fd*(ssl: PSSL, fd: cint): cint{.cdecl, dynlib: DLLSSLName, importc.}
+proc SSL_set_fd*(ssl: PSSL, fd: TSocketHandle): cint{.cdecl, dynlib: DLLSSLName, importc.}
 
 proc SSL_shutdown*(ssl: PSSL): cInt{.cdecl, dynlib: DLLSSLName, importc.}
 proc SSL_connect*(ssl: PSSL): cint{.cdecl, dynlib: DLLSSLName, importc.}
diff --git a/lib/wrappers/x11/keysym.nim b/lib/wrappers/x11/keysym.nim
index b1fe13b80..c001ab622 100644
--- a/lib/wrappers/x11/keysym.nim
+++ b/lib/wrappers/x11/keysym.nim
@@ -11,9 +11,10 @@
 #
 
 #* default keysyms *
+import x
 
 const 
-  XK_VoidSymbol* = 0x00FFFFFF # void symbol 
+  XK_VoidSymbol*: TKeySym = 0x00FFFFFF # void symbol 
 
 when defined(XK_MISCELLANY) or true: 
   const
@@ -22,186 +23,186 @@ when defined(XK_MISCELLANY) or true:
     # * programming, but could have been arbitrary (at the cost of lookup
     # * tables in client code.
     # *
-    XK_BackSpace* = 0x0000FF08  # back space, back char 
-    XK_Tab* = 0x0000FF09
-    XK_Linefeed* = 0x0000FF0A   # Linefeed, LF 
-    XK_Clear* = 0x0000FF0B
-    XK_Return* = 0x0000FF0D     # Return, enter 
-    XK_Pause* = 0x0000FF13      # Pause, hold 
-    XK_Scroll_Lock* = 0x0000FF14
-    XK_Sys_Req* = 0x0000FF15
-    XK_Escape* = 0x0000FF1B
-    XK_Delete* = 0x0000FFFF     # Delete, rubout 
+    XK_BackSpace*: TKeySym = 0x0000FF08  # back space, back char 
+    XK_Tab*: TKeySym = 0x0000FF09
+    XK_Linefeed*: TKeySym = 0x0000FF0A   # Linefeed, LF 
+    XK_Clear*: TKeySym = 0x0000FF0B
+    XK_Return*: TKeySym = 0x0000FF0D     # Return, enter 
+    XK_Pause*: TKeySym = 0x0000FF13      # Pause, hold 
+    XK_Scroll_Lock*: TKeySym = 0x0000FF14
+    XK_Sys_Req*: TKeySym = 0x0000FF15
+    XK_Escape*: TKeySym = 0x0000FF1B
+    XK_Delete*: TKeySym = 0x0000FFFF     # Delete, rubout \
                                 # International & multi-key character composition 
-    XK_Multi_key* = 0x0000FF20  # Multi-key character compose 
-    XK_Codeinput* = 0x0000FF37
-    XK_SingleCandidate* = 0x0000FF3C
-    XK_MultipleCandidate* = 0x0000FF3D
-    XK_PreviousCandidate* = 0x0000FF3E # Japanese keyboard support 
-    XK_Kanji* = 0x0000FF21      # Kanji, Kanji convert 
-    XK_Muhenkan* = 0x0000FF22   # Cancel Conversion 
-    XK_Henkan_Mode* = 0x0000FF23 # Start/Stop Conversion 
-    XK_Henkan* = 0x0000FF23     # Alias for Henkan_Mode 
-    XK_Romaji* = 0x0000FF24     # to Romaji 
-    XK_Hiragana* = 0x0000FF25   # to Hiragana 
-    XK_Katakana* = 0x0000FF26   # to Katakana 
-    XK_Hiragana_Katakana* = 0x0000FF27 # Hiragana/Katakana toggle 
-    XK_Zenkaku* = 0x0000FF28    # to Zenkaku 
-    XK_Hankaku* = 0x0000FF29    # to Hankaku 
-    XK_Zenkaku_Hankaku* = 0x0000FF2A # Zenkaku/Hankaku toggle 
-    XK_Touroku* = 0x0000FF2B    # Add to Dictionary 
-    XK_Massyo* = 0x0000FF2C     # Delete from Dictionary 
-    XK_Kana_Lock* = 0x0000FF2D  # Kana Lock 
-    XK_Kana_Shift* = 0x0000FF2E # Kana Shift 
-    XK_Eisu_Shift* = 0x0000FF2F # Alphanumeric Shift 
-    XK_Eisu_toggle* = 0x0000FF30 # Alphanumeric toggle 
-    XK_Kanji_Bangou* = 0x0000FF37 # Codeinput 
-    XK_Zen_Koho* = 0x0000FF3D   # Multiple/All Candidate(s) 
-    XK_Mae_Koho* = 0x0000FF3E   # Previous Candidate 
+    XK_Multi_key*: TKeySym = 0x0000FF20  # Multi-key character compose 
+    XK_Codeinput*: TKeySym = 0x0000FF37
+    XK_SingleCandidate*: TKeySym = 0x0000FF3C
+    XK_MultipleCandidate*: TKeySym = 0x0000FF3D
+    XK_PreviousCandidate*: TKeySym = 0x0000FF3E # Japanese keyboard support 
+    XK_Kanji*: TKeySym = 0x0000FF21      # Kanji, Kanji convert 
+    XK_Muhenkan*: TKeySym = 0x0000FF22   # Cancel Conversion 
+    XK_Henkan_Mode*: TKeySym = 0x0000FF23 # Start/Stop Conversion 
+    XK_Henkan*: TKeySym = 0x0000FF23     # Alias for Henkan_Mode 
+    XK_Romaji*: TKeySym = 0x0000FF24     # to Romaji 
+    XK_Hiragana*: TKeySym = 0x0000FF25   # to Hiragana 
+    XK_Katakana*: TKeySym = 0x0000FF26   # to Katakana 
+    XK_Hiragana_Katakana*: TKeySym = 0x0000FF27 # Hiragana/Katakana toggle 
+    XK_Zenkaku*: TKeySym = 0x0000FF28    # to Zenkaku 
+    XK_Hankaku*: TKeySym = 0x0000FF29    # to Hankaku 
+    XK_Zenkaku_Hankaku*: TKeySym = 0x0000FF2A # Zenkaku/Hankaku toggle 
+    XK_Touroku*: TKeySym = 0x0000FF2B    # Add to Dictionary 
+    XK_Massyo*: TKeySym = 0x0000FF2C     # Delete from Dictionary 
+    XK_Kana_Lock*: TKeySym = 0x0000FF2D  # Kana Lock 
+    XK_Kana_Shift*: TKeySym = 0x0000FF2E # Kana Shift 
+    XK_Eisu_Shift*: TKeySym = 0x0000FF2F # Alphanumeric Shift 
+    XK_Eisu_toggle*: TKeySym = 0x0000FF30 # Alphanumeric toggle 
+    XK_Kanji_Bangou*: TKeySym = 0x0000FF37 # Codeinput 
+    XK_Zen_Koho*: TKeySym = 0x0000FF3D   # Multiple/All Candidate(s) 
+    XK_Mae_Koho*: TKeySym = 0x0000FF3E   # Previous Candidate \
                                 # = $FF31 thru = $FF3F are under XK_KOREAN 
                                 # Cursor control & motion 
-    XK_Home* = 0x0000FF50
-    XK_Left* = 0x0000FF51       # Move left, left arrow 
-    XK_Up* = 0x0000FF52         # Move up, up arrow 
-    XK_Right* = 0x0000FF53      # Move right, right arrow 
-    XK_Down* = 0x0000FF54       # Move down, down arrow 
-    XK_Prior* = 0x0000FF55      # Prior, previous 
-    XK_Page_Up* = 0x0000FF55
-    XK_Next* = 0x0000FF56       # Next 
-    XK_Page_Down* = 0x0000FF56
-    XK_End* = 0x0000FF57        # EOL 
-    XK_Begin* = 0x0000FF58      # BOL 
+    XK_Home*: TKeySym = 0x0000FF50
+    XK_Left*: TKeySym = 0x0000FF51       # Move left, left arrow 
+    XK_Up*: TKeySym = 0x0000FF52         # Move up, up arrow 
+    XK_Right*: TKeySym = 0x0000FF53      # Move right, right arrow 
+    XK_Down*: TKeySym = 0x0000FF54       # Move down, down arrow 
+    XK_Prior*: TKeySym = 0x0000FF55      # Prior, previous 
+    XK_Page_Up*: TKeySym = 0x0000FF55
+    XK_Next*: TKeySym = 0x0000FF56       # Next 
+    XK_Page_Down*: TKeySym = 0x0000FF56
+    XK_End*: TKeySym = 0x0000FF57        # EOL 
+    XK_Begin*: TKeySym = 0x0000FF58      # BOL \
                                 # Misc Functions 
-    XK_Select* = 0x0000FF60     # Select, mark 
-    XK_Print* = 0x0000FF61
-    XK_Execute* = 0x0000FF62    # Execute, run, do 
-    XK_Insert* = 0x0000FF63     # Insert, insert here 
-    XK_Undo* = 0x0000FF65       # Undo, oops 
-    XK_Redo* = 0x0000FF66       # redo, again 
-    XK_Menu* = 0x0000FF67
-    XK_Find* = 0x0000FF68       # Find, search 
-    XK_Cancel* = 0x0000FF69     # Cancel, stop, abort, exit 
-    XK_Help* = 0x0000FF6A       # Help 
-    XK_Break* = 0x0000FF6B
-    XK_Mode_switch* = 0x0000FF7E # Character set switch 
-    XK_script_switch* = 0x0000FF7E # Alias for mode_switch 
-    XK_Num_Lock* = 0x0000FF7F   # Keypad Functions, keypad numbers cleverly chosen to map to ascii 
-    XK_KP_Space* = 0x0000FF80   # space 
-    XK_KP_Tab* = 0x0000FF89
-    XK_KP_Enter* = 0x0000FF8D   # enter 
-    XK_KP_F1* = 0x0000FF91      # PF1, KP_A, ... 
-    XK_KP_F2* = 0x0000FF92
-    XK_KP_F3* = 0x0000FF93
-    XK_KP_F4* = 0x0000FF94
-    XK_KP_Home* = 0x0000FF95
-    XK_KP_Left* = 0x0000FF96
-    XK_KP_Up* = 0x0000FF97
-    XK_KP_Right* = 0x0000FF98
-    XK_KP_Down* = 0x0000FF99
-    XK_KP_Prior* = 0x0000FF9A
-    XK_KP_Page_Up* = 0x0000FF9A
-    XK_KP_Next* = 0x0000FF9B
-    XK_KP_Page_Down* = 0x0000FF9B
-    XK_KP_End* = 0x0000FF9C
-    XK_KP_Begin* = 0x0000FF9D
-    XK_KP_Insert* = 0x0000FF9E
-    XK_KP_Delete* = 0x0000FF9F
-    XK_KP_Equal* = 0x0000FFBD   # equals 
-    XK_KP_Multiply* = 0x0000FFAA
-    XK_KP_Add* = 0x0000FFAB
-    XK_KP_Separator* = 0x0000FFAC # separator, often comma 
-    XK_KP_Subtract* = 0x0000FFAD
-    XK_KP_Decimal* = 0x0000FFAE
-    XK_KP_Divide* = 0x0000FFAF
-    XK_KP_0* = 0x0000FFB0
-    XK_KP_1* = 0x0000FFB1
-    XK_KP_2* = 0x0000FFB2
-    XK_KP_3* = 0x0000FFB3
-    XK_KP_4* = 0x0000FFB4
-    XK_KP_5* = 0x0000FFB5
-    XK_KP_6* = 0x0000FFB6
-    XK_KP_7* = 0x0000FFB7
-    XK_KP_8* = 0x0000FFB8
-    XK_KP_9* = 0x0000FFB9 #*
+    XK_Select*: TKeySym = 0x0000FF60     # Select, mark 
+    XK_Print*: TKeySym = 0x0000FF61
+    XK_Execute*: TKeySym = 0x0000FF62    # Execute, run, do 
+    XK_Insert*: TKeySym = 0x0000FF63     # Insert, insert here 
+    XK_Undo*: TKeySym = 0x0000FF65       # Undo, oops 
+    XK_Redo*: TKeySym = 0x0000FF66       # redo, again 
+    XK_Menu*: TKeySym = 0x0000FF67
+    XK_Find*: TKeySym = 0x0000FF68       # Find, search 
+    XK_Cancel*: TKeySym = 0x0000FF69     # Cancel, stop, abort, exit 
+    XK_Help*: TKeySym = 0x0000FF6A       # Help 
+    XK_Break*: TKeySym = 0x0000FF6B
+    XK_Mode_switch*: TKeySym = 0x0000FF7E # Character set switch 
+    XK_script_switch*: TKeySym = 0x0000FF7E # Alias for mode_switch 
+    XK_Num_Lock*: TKeySym = 0x0000FF7F   # Keypad Functions, keypad numbers cleverly chosen to map to ascii 
+    XK_KP_Space*: TKeySym = 0x0000FF80   # space 
+    XK_KP_Tab*: TKeySym = 0x0000FF89
+    XK_KP_Enter*: TKeySym = 0x0000FF8D   # enter 
+    XK_KP_F1*: TKeySym = 0x0000FF91      # PF1, KP_A, ... 
+    XK_KP_F2*: TKeySym = 0x0000FF92
+    XK_KP_F3*: TKeySym = 0x0000FF93
+    XK_KP_F4*: TKeySym = 0x0000FF94
+    XK_KP_Home*: TKeySym = 0x0000FF95
+    XK_KP_Left*: TKeySym = 0x0000FF96
+    XK_KP_Up*: TKeySym = 0x0000FF97
+    XK_KP_Right*: TKeySym = 0x0000FF98
+    XK_KP_Down*: TKeySym = 0x0000FF99
+    XK_KP_Prior*: TKeySym = 0x0000FF9A
+    XK_KP_Page_Up*: TKeySym = 0x0000FF9A
+    XK_KP_Next*: TKeySym = 0x0000FF9B
+    XK_KP_Page_Down*: TKeySym = 0x0000FF9B
+    XK_KP_End*: TKeySym = 0x0000FF9C
+    XK_KP_Begin*: TKeySym = 0x0000FF9D
+    XK_KP_Insert*: TKeySym = 0x0000FF9E
+    XK_KP_Delete*: TKeySym = 0x0000FF9F
+    XK_KP_Equal*: TKeySym = 0x0000FFBD   # equals 
+    XK_KP_Multiply*: TKeySym = 0x0000FFAA
+    XK_KP_Add*: TKeySym = 0x0000FFAB
+    XK_KP_Separator*: TKeySym = 0x0000FFAC # separator, often comma 
+    XK_KP_Subtract*: TKeySym = 0x0000FFAD
+    XK_KP_Decimal*: TKeySym = 0x0000FFAE
+    XK_KP_Divide*: TKeySym = 0x0000FFAF
+    XK_KP_0*: TKeySym = 0x0000FFB0
+    XK_KP_1*: TKeySym = 0x0000FFB1
+    XK_KP_2*: TKeySym = 0x0000FFB2
+    XK_KP_3*: TKeySym = 0x0000FFB3
+    XK_KP_4*: TKeySym = 0x0000FFB4
+    XK_KP_5*: TKeySym = 0x0000FFB5
+    XK_KP_6*: TKeySym = 0x0000FFB6
+    XK_KP_7*: TKeySym = 0x0000FFB7
+    XK_KP_8*: TKeySym = 0x0000FFB8
+    XK_KP_9*: TKeySym = 0x0000FFB9 #*\
                           # * Auxilliary Functions; note the duplicate definitions for left and right
                           # * function keys;  Sun keyboards and a few other manufactures have such
                           # * function key groups on the left and/or right sides of the keyboard.
                           # * We've not found a keyboard with more than 35 function keys total.
                           # *
-    XK_F1* = 0x0000FFBE
-    XK_F2* = 0x0000FFBF
-    XK_F3* = 0x0000FFC0
-    XK_F4* = 0x0000FFC1
-    XK_F5* = 0x0000FFC2
-    XK_F6* = 0x0000FFC3
-    XK_F7* = 0x0000FFC4
-    XK_F8* = 0x0000FFC5
-    XK_F9* = 0x0000FFC6
-    XK_F10* = 0x0000FFC7
-    XK_F11* = 0x0000FFC8
-    XK_L1* = 0x0000FFC8
-    XK_F12* = 0x0000FFC9
-    XK_L2* = 0x0000FFC9
-    XK_F13* = 0x0000FFCA
-    XK_L3* = 0x0000FFCA
-    XK_F14* = 0x0000FFCB
-    XK_L4* = 0x0000FFCB
-    XK_F15* = 0x0000FFCC
-    XK_L5* = 0x0000FFCC
-    XK_F16* = 0x0000FFCD
-    XK_L6* = 0x0000FFCD
-    XK_F17* = 0x0000FFCE
-    XK_L7* = 0x0000FFCE
-    XK_F18* = 0x0000FFCF
-    XK_L8* = 0x0000FFCF
-    XK_F19* = 0x0000FFD0
-    XK_L9* = 0x0000FFD0
-    XK_F20* = 0x0000FFD1
-    XK_L10* = 0x0000FFD1
-    XK_F21* = 0x0000FFD2
-    XK_R1* = 0x0000FFD2
-    XK_F22* = 0x0000FFD3
-    XK_R2* = 0x0000FFD3
-    XK_F23* = 0x0000FFD4
-    XK_R3* = 0x0000FFD4
-    XK_F24* = 0x0000FFD5
-    XK_R4* = 0x0000FFD5
-    XK_F25* = 0x0000FFD6
-    XK_R5* = 0x0000FFD6
-    XK_F26* = 0x0000FFD7
-    XK_R6* = 0x0000FFD7
-    XK_F27* = 0x0000FFD8
-    XK_R7* = 0x0000FFD8
-    XK_F28* = 0x0000FFD9
-    XK_R8* = 0x0000FFD9
-    XK_F29* = 0x0000FFDA
-    XK_R9* = 0x0000FFDA
-    XK_F30* = 0x0000FFDB
-    XK_R10* = 0x0000FFDB
-    XK_F31* = 0x0000FFDC
-    XK_R11* = 0x0000FFDC
-    XK_F32* = 0x0000FFDD
-    XK_R12* = 0x0000FFDD
-    XK_F33* = 0x0000FFDE
-    XK_R13* = 0x0000FFDE
-    XK_F34* = 0x0000FFDF
-    XK_R14* = 0x0000FFDF
-    XK_F35* = 0x0000FFE0
-    XK_R15* = 0x0000FFE0        # Modifiers 
-    XK_Shift_L* = 0x0000FFE1    # Left shift 
-    XK_Shift_R* = 0x0000FFE2    # Right shift 
-    XK_Control_L* = 0x0000FFE3  # Left control 
-    XK_Control_R* = 0x0000FFE4  # Right control 
-    XK_Caps_Lock* = 0x0000FFE5  # Caps lock 
-    XK_Shift_Lock* = 0x0000FFE6 # Shift lock 
-    XK_Meta_L* = 0x0000FFE7     # Left meta 
-    XK_Meta_R* = 0x0000FFE8     # Right meta 
-    XK_Alt_L* = 0x0000FFE9      # Left alt 
-    XK_Alt_R* = 0x0000FFEA      # Right alt 
-    XK_Super_L* = 0x0000FFEB    # Left super 
-    XK_Super_R* = 0x0000FFEC    # Right super 
-    XK_Hyper_L* = 0x0000FFED    # Left hyper 
-    XK_Hyper_R* = 0x0000FFEE    # Right hyper 
+    XK_F1*: TKeySym = 0x0000FFBE
+    XK_F2*: TKeySym = 0x0000FFBF
+    XK_F3*: TKeySym = 0x0000FFC0
+    XK_F4*: TKeySym = 0x0000FFC1
+    XK_F5*: TKeySym = 0x0000FFC2
+    XK_F6*: TKeySym = 0x0000FFC3
+    XK_F7*: TKeySym = 0x0000FFC4
+    XK_F8*: TKeySym = 0x0000FFC5
+    XK_F9*: TKeySym = 0x0000FFC6
+    XK_F10*: TKeySym = 0x0000FFC7
+    XK_F11*: TKeySym = 0x0000FFC8
+    XK_L1*: TKeySym = 0x0000FFC8
+    XK_F12*: TKeySym = 0x0000FFC9
+    XK_L2*: TKeySym = 0x0000FFC9
+    XK_F13*: TKeySym = 0x0000FFCA
+    XK_L3*: TKeySym = 0x0000FFCA
+    XK_F14*: TKeySym = 0x0000FFCB
+    XK_L4*: TKeySym = 0x0000FFCB
+    XK_F15*: TKeySym = 0x0000FFCC
+    XK_L5*: TKeySym = 0x0000FFCC
+    XK_F16*: TKeySym = 0x0000FFCD
+    XK_L6*: TKeySym = 0x0000FFCD
+    XK_F17*: TKeySym = 0x0000FFCE
+    XK_L7*: TKeySym = 0x0000FFCE
+    XK_F18*: TKeySym = 0x0000FFCF
+    XK_L8*: TKeySym = 0x0000FFCF
+    XK_F19*: TKeySym = 0x0000FFD0
+    XK_L9*: TKeySym = 0x0000FFD0
+    XK_F20*: TKeySym = 0x0000FFD1
+    XK_L10*: TKeySym = 0x0000FFD1
+    XK_F21*: TKeySym = 0x0000FFD2
+    XK_R1*: TKeySym = 0x0000FFD2
+    XK_F22*: TKeySym = 0x0000FFD3
+    XK_R2*: TKeySym = 0x0000FFD3
+    XK_F23*: TKeySym = 0x0000FFD4
+    XK_R3*: TKeySym = 0x0000FFD4
+    XK_F24*: TKeySym = 0x0000FFD5
+    XK_R4*: TKeySym = 0x0000FFD5
+    XK_F25*: TKeySym = 0x0000FFD6
+    XK_R5*: TKeySym = 0x0000FFD6
+    XK_F26*: TKeySym = 0x0000FFD7
+    XK_R6*: TKeySym = 0x0000FFD7
+    XK_F27*: TKeySym = 0x0000FFD8
+    XK_R7*: TKeySym = 0x0000FFD8
+    XK_F28*: TKeySym = 0x0000FFD9
+    XK_R8*: TKeySym = 0x0000FFD9
+    XK_F29*: TKeySym = 0x0000FFDA
+    XK_R9*: TKeySym = 0x0000FFDA
+    XK_F30*: TKeySym = 0x0000FFDB
+    XK_R10*: TKeySym = 0x0000FFDB
+    XK_F31*: TKeySym = 0x0000FFDC
+    XK_R11*: TKeySym = 0x0000FFDC
+    XK_F32*: TKeySym = 0x0000FFDD
+    XK_R12*: TKeySym = 0x0000FFDD
+    XK_F33*: TKeySym = 0x0000FFDE
+    XK_R13*: TKeySym = 0x0000FFDE
+    XK_F34*: TKeySym = 0x0000FFDF
+    XK_R14*: TKeySym = 0x0000FFDF
+    XK_F35*: TKeySym = 0x0000FFE0
+    XK_R15*: TKeySym = 0x0000FFE0        # Modifiers 
+    XK_Shift_L*: TKeySym = 0x0000FFE1    # Left shift 
+    XK_Shift_R*: TKeySym = 0x0000FFE2    # Right shift 
+    XK_Control_L*: TKeySym = 0x0000FFE3  # Left control 
+    XK_Control_R*: TKeySym = 0x0000FFE4  # Right control 
+    XK_Caps_Lock*: TKeySym = 0x0000FFE5  # Caps lock 
+    XK_Shift_Lock*: TKeySym = 0x0000FFE6 # Shift lock 
+    XK_Meta_L*: TKeySym = 0x0000FFE7     # Left meta 
+    XK_Meta_R*: TKeySym = 0x0000FFE8     # Right meta 
+    XK_Alt_L*: TKeySym = 0x0000FFE9      # Left alt 
+    XK_Alt_R*: TKeySym = 0x0000FFEA      # Right alt 
+    XK_Super_L*: TKeySym = 0x0000FFEB    # Left super 
+    XK_Super_R*: TKeySym = 0x0000FFEC    # Right super 
+    XK_Hyper_L*: TKeySym = 0x0000FFED    # Left hyper 
+    XK_Hyper_R*: TKeySym = 0x0000FFEE    # Right hyper 
 # XK_MISCELLANY 
 #*
 # * ISO 9995 Function and Modifier Keys
@@ -210,108 +211,108 @@ when defined(XK_MISCELLANY) or true:
 
 when defined(XK_XKB_KEYS) or true: 
   const
-    XK_ISO_Lock* = 0x0000FE01
-    XK_ISO_Level2_Latch* = 0x0000FE02
-    XK_ISO_Level3_Shift* = 0x0000FE03
-    XK_ISO_Level3_Latch* = 0x0000FE04
-    XK_ISO_Level3_Lock* = 0x0000FE05
-    XK_ISO_Group_Shift* = 0x0000FF7E # Alias for mode_switch 
-    XK_ISO_Group_Latch* = 0x0000FE06
-    XK_ISO_Group_Lock* = 0x0000FE07
-    XK_ISO_Next_Group* = 0x0000FE08
-    XK_ISO_Next_Group_Lock* = 0x0000FE09
-    XK_ISO_Prev_Group* = 0x0000FE0A
-    XK_ISO_Prev_Group_Lock* = 0x0000FE0B
-    XK_ISO_First_Group* = 0x0000FE0C
-    XK_ISO_First_Group_Lock* = 0x0000FE0D
-    XK_ISO_Last_Group* = 0x0000FE0E
-    XK_ISO_Last_Group_Lock* = 0x0000FE0F
-    XK_ISO_Left_Tab* = 0x0000FE20
-    XK_ISO_Move_Line_Up* = 0x0000FE21
-    XK_ISO_Move_Line_Down* = 0x0000FE22
-    XK_ISO_Partial_Line_Up* = 0x0000FE23
-    XK_ISO_Partial_Line_Down* = 0x0000FE24
-    XK_ISO_Partial_Space_Left* = 0x0000FE25
-    XK_ISO_Partial_Space_Right* = 0x0000FE26
-    XK_ISO_Set_Margin_Left* = 0x0000FE27
-    XK_ISO_Set_Margin_Right* = 0x0000FE28
-    XK_ISO_Release_Margin_Left* = 0x0000FE29
-    XK_ISO_Release_Margin_Right* = 0x0000FE2A
-    XK_ISO_Release_Both_Margins* = 0x0000FE2B
-    XK_ISO_Fast_Cursor_Left* = 0x0000FE2C
-    XK_ISO_Fast_Cursor_Right* = 0x0000FE2D
-    XK_ISO_Fast_Cursor_Up* = 0x0000FE2E
-    XK_ISO_Fast_Cursor_Down* = 0x0000FE2F
-    XK_ISO_Continuous_Underline* = 0x0000FE30
-    XK_ISO_Discontinuous_Underline* = 0x0000FE31
-    XK_ISO_Emphasize* = 0x0000FE32
-    XK_ISO_Center_Object* = 0x0000FE33
-    XK_ISO_Enter* = 0x0000FE34
-    XK_dead_grave* = 0x0000FE50
-    XK_dead_acute* = 0x0000FE51
-    XK_dead_circumflex* = 0x0000FE52
-    XK_dead_tilde* = 0x0000FE53
-    XK_dead_macron* = 0x0000FE54
-    XK_dead_breve* = 0x0000FE55
-    XK_dead_abovedot* = 0x0000FE56
-    XK_dead_diaeresis* = 0x0000FE57
-    XK_dead_abovering* = 0x0000FE58
-    XK_dead_doubleacute* = 0x0000FE59
-    XK_dead_caron* = 0x0000FE5A
-    XK_dead_cedilla* = 0x0000FE5B
-    XK_dead_ogonek* = 0x0000FE5C
-    XK_dead_iota* = 0x0000FE5D
-    XK_dead_voiced_sound* = 0x0000FE5E
-    XK_dead_semivoiced_sound* = 0x0000FE5F
-    XK_dead_belowdot* = 0x0000FE60
-    XK_dead_hook* = 0x0000FE61
-    XK_dead_horn* = 0x0000FE62
-    XK_First_Virtual_Screen* = 0x0000FED0
-    XK_Prev_Virtual_Screen* = 0x0000FED1
-    XK_Next_Virtual_Screen* = 0x0000FED2
-    XK_Last_Virtual_Screen* = 0x0000FED4
-    XK_Terminate_Server* = 0x0000FED5
-    XK_AccessX_Enable* = 0x0000FE70
-    XK_AccessX_Feedback_Enable* = 0x0000FE71
-    XK_RepeatKeys_Enable* = 0x0000FE72
-    XK_SlowKeys_Enable* = 0x0000FE73
-    XK_BounceKeys_Enable* = 0x0000FE74
-    XK_StickyKeys_Enable* = 0x0000FE75
-    XK_MouseKeys_Enable* = 0x0000FE76
-    XK_MouseKeys_Accel_Enable* = 0x0000FE77
-    XK_Overlay1_Enable* = 0x0000FE78
-    XK_Overlay2_Enable* = 0x0000FE79
-    XK_AudibleBell_Enable* = 0x0000FE7A
-    XK_Pointer_Left* = 0x0000FEE0
-    XK_Pointer_Right* = 0x0000FEE1
-    XK_Pointer_Up* = 0x0000FEE2
-    XK_Pointer_Down* = 0x0000FEE3
-    XK_Pointer_UpLeft* = 0x0000FEE4
-    XK_Pointer_UpRight* = 0x0000FEE5
-    XK_Pointer_DownLeft* = 0x0000FEE6
-    XK_Pointer_DownRight* = 0x0000FEE7
-    XK_Pointer_Button_Dflt* = 0x0000FEE8
-    XK_Pointer_Button1* = 0x0000FEE9
-    XK_Pointer_Button2* = 0x0000FEEA
-    XK_Pointer_Button3* = 0x0000FEEB
-    XK_Pointer_Button4* = 0x0000FEEC
-    XK_Pointer_Button5* = 0x0000FEED
-    XK_Pointer_DblClick_Dflt* = 0x0000FEEE
-    XK_Pointer_DblClick1* = 0x0000FEEF
-    XK_Pointer_DblClick2* = 0x0000FEF0
-    XK_Pointer_DblClick3* = 0x0000FEF1
-    XK_Pointer_DblClick4* = 0x0000FEF2
-    XK_Pointer_DblClick5* = 0x0000FEF3
-    XK_Pointer_Drag_Dflt* = 0x0000FEF4
-    XK_Pointer_Drag1* = 0x0000FEF5
-    XK_Pointer_Drag2* = 0x0000FEF6
-    XK_Pointer_Drag3* = 0x0000FEF7
-    XK_Pointer_Drag4* = 0x0000FEF8
-    XK_Pointer_Drag5* = 0x0000FEFD
-    XK_Pointer_EnableKeys* = 0x0000FEF9
-    XK_Pointer_Accelerate* = 0x0000FEFA
-    XK_Pointer_DfltBtnNext* = 0x0000FEFB
-    XK_Pointer_DfltBtnPrev* = 0x0000FEFC
+    XK_ISO_Lock*: TKeySym = 0x0000FE01
+    XK_ISO_Level2_Latch*: TKeySym = 0x0000FE02
+    XK_ISO_Level3_Shift*: TKeySym = 0x0000FE03
+    XK_ISO_Level3_Latch*: TKeySym = 0x0000FE04
+    XK_ISO_Level3_Lock*: TKeySym = 0x0000FE05
+    XK_ISO_Group_Shift*: TKeySym = 0x0000FF7E # Alias for mode_switch 
+    XK_ISO_Group_Latch*: TKeySym = 0x0000FE06
+    XK_ISO_Group_Lock*: TKeySym = 0x0000FE07
+    XK_ISO_Next_Group*: TKeySym = 0x0000FE08
+    XK_ISO_Next_Group_Lock*: TKeySym = 0x0000FE09
+    XK_ISO_Prev_Group*: TKeySym = 0x0000FE0A
+    XK_ISO_Prev_Group_Lock*: TKeySym = 0x0000FE0B
+    XK_ISO_First_Group*: TKeySym = 0x0000FE0C
+    XK_ISO_First_Group_Lock*: TKeySym = 0x0000FE0D
+    XK_ISO_Last_Group*: TKeySym = 0x0000FE0E
+    XK_ISO_Last_Group_Lock*: TKeySym = 0x0000FE0F
+    XK_ISO_Left_Tab*: TKeySym = 0x0000FE20
+    XK_ISO_Move_Line_Up*: TKeySym = 0x0000FE21
+    XK_ISO_Move_Line_Down*: TKeySym = 0x0000FE22
+    XK_ISO_Partial_Line_Up*: TKeySym = 0x0000FE23
+    XK_ISO_Partial_Line_Down*: TKeySym = 0x0000FE24
+    XK_ISO_Partial_Space_Left*: TKeySym = 0x0000FE25
+    XK_ISO_Partial_Space_Right*: TKeySym = 0x0000FE26
+    XK_ISO_Set_Margin_Left*: TKeySym = 0x0000FE27
+    XK_ISO_Set_Margin_Right*: TKeySym = 0x0000FE28
+    XK_ISO_Release_Margin_Left*: TKeySym = 0x0000FE29
+    XK_ISO_Release_Margin_Right*: TKeySym = 0x0000FE2A
+    XK_ISO_Release_Both_Margins*: TKeySym = 0x0000FE2B
+    XK_ISO_Fast_Cursor_Left*: TKeySym = 0x0000FE2C
+    XK_ISO_Fast_Cursor_Right*: TKeySym = 0x0000FE2D
+    XK_ISO_Fast_Cursor_Up*: TKeySym = 0x0000FE2E
+    XK_ISO_Fast_Cursor_Down*: TKeySym = 0x0000FE2F
+    XK_ISO_Continuous_Underline*: TKeySym = 0x0000FE30
+    XK_ISO_Discontinuous_Underline*: TKeySym = 0x0000FE31
+    XK_ISO_Emphasize*: TKeySym = 0x0000FE32
+    XK_ISO_Center_Object*: TKeySym = 0x0000FE33
+    XK_ISO_Enter*: TKeySym = 0x0000FE34
+    XK_dead_grave*: TKeySym = 0x0000FE50
+    XK_dead_acute*: TKeySym = 0x0000FE51
+    XK_dead_circumflex*: TKeySym = 0x0000FE52
+    XK_dead_tilde*: TKeySym = 0x0000FE53
+    XK_dead_macron*: TKeySym = 0x0000FE54
+    XK_dead_breve*: TKeySym = 0x0000FE55
+    XK_dead_abovedot*: TKeySym = 0x0000FE56
+    XK_dead_diaeresis*: TKeySym = 0x0000FE57
+    XK_dead_abovering*: TKeySym = 0x0000FE58
+    XK_dead_doubleacute*: TKeySym = 0x0000FE59
+    XK_dead_caron*: TKeySym = 0x0000FE5A
+    XK_dead_cedilla*: TKeySym = 0x0000FE5B
+    XK_dead_ogonek*: TKeySym = 0x0000FE5C
+    XK_dead_iota*: TKeySym = 0x0000FE5D
+    XK_dead_voiced_sound*: TKeySym = 0x0000FE5E
+    XK_dead_semivoiced_sound*: TKeySym = 0x0000FE5F
+    XK_dead_belowdot*: TKeySym = 0x0000FE60
+    XK_dead_hook*: TKeySym = 0x0000FE61
+    XK_dead_horn*: TKeySym = 0x0000FE62
+    XK_First_Virtual_Screen*: TKeySym = 0x0000FED0
+    XK_Prev_Virtual_Screen*: TKeySym = 0x0000FED1
+    XK_Next_Virtual_Screen*: TKeySym = 0x0000FED2
+    XK_Last_Virtual_Screen*: TKeySym = 0x0000FED4
+    XK_Terminate_Server*: TKeySym = 0x0000FED5
+    XK_AccessX_Enable*: TKeySym = 0x0000FE70
+    XK_AccessX_Feedback_Enable*: TKeySym = 0x0000FE71
+    XK_RepeatKeys_Enable*: TKeySym = 0x0000FE72
+    XK_SlowKeys_Enable*: TKeySym = 0x0000FE73
+    XK_BounceKeys_Enable*: TKeySym = 0x0000FE74
+    XK_StickyKeys_Enable*: TKeySym = 0x0000FE75
+    XK_MouseKeys_Enable*: TKeySym = 0x0000FE76
+    XK_MouseKeys_Accel_Enable*: TKeySym = 0x0000FE77
+    XK_Overlay1_Enable*: TKeySym = 0x0000FE78
+    XK_Overlay2_Enable*: TKeySym = 0x0000FE79
+    XK_AudibleBell_Enable*: TKeySym = 0x0000FE7A
+    XK_Pointer_Left*: TKeySym = 0x0000FEE0
+    XK_Pointer_Right*: TKeySym = 0x0000FEE1
+    XK_Pointer_Up*: TKeySym = 0x0000FEE2
+    XK_Pointer_Down*: TKeySym = 0x0000FEE3
+    XK_Pointer_UpLeft*: TKeySym = 0x0000FEE4
+    XK_Pointer_UpRight*: TKeySym = 0x0000FEE5
+    XK_Pointer_DownLeft*: TKeySym = 0x0000FEE6
+    XK_Pointer_DownRight*: TKeySym = 0x0000FEE7
+    XK_Pointer_Button_Dflt*: TKeySym = 0x0000FEE8
+    XK_Pointer_Button1*: TKeySym = 0x0000FEE9
+    XK_Pointer_Button2*: TKeySym = 0x0000FEEA
+    XK_Pointer_Button3*: TKeySym = 0x0000FEEB
+    XK_Pointer_Button4*: TKeySym = 0x0000FEEC
+    XK_Pointer_Button5*: TKeySym = 0x0000FEED
+    XK_Pointer_DblClick_Dflt*: TKeySym = 0x0000FEEE
+    XK_Pointer_DblClick1*: TKeySym = 0x0000FEEF
+    XK_Pointer_DblClick2*: TKeySym = 0x0000FEF0
+    XK_Pointer_DblClick3*: TKeySym = 0x0000FEF1
+    XK_Pointer_DblClick4*: TKeySym = 0x0000FEF2
+    XK_Pointer_DblClick5*: TKeySym = 0x0000FEF3
+    XK_Pointer_Drag_Dflt*: TKeySym = 0x0000FEF4
+    XK_Pointer_Drag1*: TKeySym = 0x0000FEF5
+    XK_Pointer_Drag2*: TKeySym = 0x0000FEF6
+    XK_Pointer_Drag3*: TKeySym = 0x0000FEF7
+    XK_Pointer_Drag4*: TKeySym = 0x0000FEF8
+    XK_Pointer_Drag5*: TKeySym = 0x0000FEFD
+    XK_Pointer_EnableKeys*: TKeySym = 0x0000FEF9
+    XK_Pointer_Accelerate*: TKeySym = 0x0000FEFA
+    XK_Pointer_DfltBtnNext*: TKeySym = 0x0000FEFB
+    XK_Pointer_DfltBtnPrev*: TKeySym = 0x0000FEFC
   #*
   # * 3270 Terminal Keys
   # * Byte 3 = = $FD
@@ -319,36 +320,36 @@ when defined(XK_XKB_KEYS) or true:
 
 when defined(XK_3270) or true: 
   const
-    XK_3270_Duplicate* = 0x0000FD01
-    XK_3270_FieldMark* = 0x0000FD02
-    XK_3270_Right2* = 0x0000FD03
-    XK_3270_Left2* = 0x0000FD04
-    XK_3270_BackTab* = 0x0000FD05
-    XK_3270_EraseEOF* = 0x0000FD06
-    XK_3270_EraseInput* = 0x0000FD07
-    XK_3270_Reset* = 0x0000FD08
-    XK_3270_Quit* = 0x0000FD09
-    XK_3270_PA1* = 0x0000FD0A
-    XK_3270_PA2* = 0x0000FD0B
-    XK_3270_PA3* = 0x0000FD0C
-    XK_3270_Test* = 0x0000FD0D
-    XK_3270_Attn* = 0x0000FD0E
-    XK_3270_CursorBlink* = 0x0000FD0F
-    XK_3270_AltCursor* = 0x0000FD10
-    XK_3270_KeyClick* = 0x0000FD11
-    XK_3270_Jump* = 0x0000FD12
-    XK_3270_Ident* = 0x0000FD13
-    XK_3270_Rule* = 0x0000FD14
-    XK_3270_Copy* = 0x0000FD15
-    XK_3270_Play* = 0x0000FD16
-    XK_3270_Setup* = 0x0000FD17
-    XK_3270_Record* = 0x0000FD18
-    XK_3270_ChangeScreen* = 0x0000FD19
-    XK_3270_DeleteWord* = 0x0000FD1A
-    XK_3270_ExSelect* = 0x0000FD1B
-    XK_3270_CursorSelect* = 0x0000FD1C
-    XK_3270_PrintScreen* = 0x0000FD1D
-    XK_3270_Enter* = 0x0000FD1E
+    XK_3270_Duplicate*: TKeySym = 0x0000FD01
+    XK_3270_FieldMark*: TKeySym = 0x0000FD02
+    XK_3270_Right2*: TKeySym = 0x0000FD03
+    XK_3270_Left2*: TKeySym = 0x0000FD04
+    XK_3270_BackTab*: TKeySym = 0x0000FD05
+    XK_3270_EraseEOF*: TKeySym = 0x0000FD06
+    XK_3270_EraseInput*: TKeySym = 0x0000FD07
+    XK_3270_Reset*: TKeySym = 0x0000FD08
+    XK_3270_Quit*: TKeySym = 0x0000FD09
+    XK_3270_PA1*: TKeySym = 0x0000FD0A
+    XK_3270_PA2*: TKeySym = 0x0000FD0B
+    XK_3270_PA3*: TKeySym = 0x0000FD0C
+    XK_3270_Test*: TKeySym = 0x0000FD0D
+    XK_3270_Attn*: TKeySym = 0x0000FD0E
+    XK_3270_CursorBlink*: TKeySym = 0x0000FD0F
+    XK_3270_AltCursor*: TKeySym = 0x0000FD10
+    XK_3270_KeyClick*: TKeySym = 0x0000FD11
+    XK_3270_Jump*: TKeySym = 0x0000FD12
+    XK_3270_Ident*: TKeySym = 0x0000FD13
+    XK_3270_Rule*: TKeySym = 0x0000FD14
+    XK_3270_Copy*: TKeySym = 0x0000FD15
+    XK_3270_Play*: TKeySym = 0x0000FD16
+    XK_3270_Setup*: TKeySym = 0x0000FD17
+    XK_3270_Record*: TKeySym = 0x0000FD18
+    XK_3270_ChangeScreen*: TKeySym = 0x0000FD19
+    XK_3270_DeleteWord*: TKeySym = 0x0000FD1A
+    XK_3270_ExSelect*: TKeySym = 0x0000FD1B
+    XK_3270_CursorSelect*: TKeySym = 0x0000FD1C
+    XK_3270_PrintScreen*: TKeySym = 0x0000FD1D
+    XK_3270_Enter*: TKeySym = 0x0000FD1E
 #*
 # *  Latin 1
 # *  Byte 3 = 0
@@ -356,201 +357,201 @@ when defined(XK_3270) or true:
 
 when defined(XK_LATIN1) or true: 
   const
-    XK_space* = 0x00000020
-    XK_exclam* = 0x00000021
-    XK_quotedbl* = 0x00000022
-    XK_numbersign* = 0x00000023
-    XK_dollar* = 0x00000024
-    XK_percent* = 0x00000025
-    XK_ampersand* = 0x00000026
-    XK_apostrophe* = 0x00000027
-    XK_quoteright* = 0x00000027 # deprecated 
-    XK_parenleft* = 0x00000028
-    XK_parenright* = 0x00000029
-    XK_asterisk* = 0x0000002A
-    XK_plus* = 0x0000002B
-    XK_comma* = 0x0000002C
-    XK_minus* = 0x0000002D
-    XK_period* = 0x0000002E
-    XK_slash* = 0x0000002F
-    XK_0* = 0x00000030
-    XK_1* = 0x00000031
-    XK_2* = 0x00000032
-    XK_3* = 0x00000033
-    XK_4* = 0x00000034
-    XK_5* = 0x00000035
-    XK_6* = 0x00000036
-    XK_7* = 0x00000037
-    XK_8* = 0x00000038
-    XK_9* = 0x00000039
-    XK_colon* = 0x0000003A
-    XK_semicolon* = 0x0000003B
-    XK_less* = 0x0000003C
-    XK_equal* = 0x0000003D
-    XK_greater* = 0x0000003E
-    XK_question* = 0x0000003F
-    XK_at* = 0x00000040
-    XKc_A* = 0x00000041
-    XKc_B* = 0x00000042
-    XKc_C* = 0x00000043
-    XKc_D* = 0x00000044
-    XKc_E* = 0x00000045
-    XKc_F* = 0x00000046
-    XKc_G* = 0x00000047
-    XKc_H* = 0x00000048
-    XKc_I* = 0x00000049
-    XKc_J* = 0x0000004A
-    XKc_K* = 0x0000004B
-    XKc_L* = 0x0000004C
-    XKc_M* = 0x0000004D
-    XKc_N* = 0x0000004E
-    XKc_O* = 0x0000004F
-    XKc_P* = 0x00000050
-    XKc_Q* = 0x00000051
-    XKc_R* = 0x00000052
-    XKc_S* = 0x00000053
-    XKc_T* = 0x00000054
-    XKc_U* = 0x00000055
-    XKc_V* = 0x00000056
-    XKc_W* = 0x00000057
-    XKc_X* = 0x00000058
-    XKc_Y* = 0x00000059
-    XKc_Z* = 0x0000005A
-    XK_bracketleft* = 0x0000005B
-    XK_backslash* = 0x0000005C
-    XK_bracketright* = 0x0000005D
-    XK_asciicircum* = 0x0000005E
-    XK_underscore* = 0x0000005F
-    XK_grave* = 0x00000060
-    XK_quoteleft* = 0x00000060  # deprecated 
-    XK_a* = 0x00000061
-    XK_b* = 0x00000062
-    XK_c* = 0x00000063
-    XK_d* = 0x00000064
-    XK_e* = 0x00000065
-    XK_f* = 0x00000066
-    XK_g* = 0x00000067
-    XK_h* = 0x00000068
-    XK_i* = 0x00000069
-    XK_j* = 0x0000006A
-    XK_k* = 0x0000006B
-    XK_l* = 0x0000006C
-    XK_m* = 0x0000006D
-    XK_n* = 0x0000006E
-    XK_o* = 0x0000006F
-    XK_p* = 0x00000070
-    XK_q* = 0x00000071
-    XK_r* = 0x00000072
-    XK_s* = 0x00000073
-    XK_t* = 0x00000074
-    XK_u* = 0x00000075
-    XK_v* = 0x00000076
-    XK_w* = 0x00000077
-    XK_x* = 0x00000078
-    XK_y* = 0x00000079
-    XK_z* = 0x0000007A
-    XK_braceleft* = 0x0000007B
-    XK_bar* = 0x0000007C
-    XK_braceright* = 0x0000007D
-    XK_asciitilde* = 0x0000007E
-    XK_nobreakspace* = 0x000000A0
-    XK_exclamdown* = 0x000000A1
-    XK_cent* = 0x000000A2
-    XK_sterling* = 0x000000A3
-    XK_currency* = 0x000000A4
-    XK_yen* = 0x000000A5
-    XK_brokenbar* = 0x000000A6
-    XK_section* = 0x000000A7
-    XK_diaeresis* = 0x000000A8
-    XK_copyright* = 0x000000A9
-    XK_ordfeminine* = 0x000000AA
-    XK_guillemotleft* = 0x000000AB # left angle quotation mark 
-    XK_notsign* = 0x000000AC
-    XK_hyphen* = 0x000000AD
-    XK_registered* = 0x000000AE
-    XK_macron* = 0x000000AF
-    XK_degree* = 0x000000B0
-    XK_plusminus* = 0x000000B1
-    XK_twosuperior* = 0x000000B2
-    XK_threesuperior* = 0x000000B3
-    XK_acute* = 0x000000B4
-    XK_mu* = 0x000000B5
-    XK_paragraph* = 0x000000B6
-    XK_periodcentered* = 0x000000B7
-    XK_cedilla* = 0x000000B8
-    XK_onesuperior* = 0x000000B9
-    XK_masculine* = 0x000000BA
-    XK_guillemotright* = 0x000000BB # right angle quotation mark 
-    XK_onequarter* = 0x000000BC
-    XK_onehalf* = 0x000000BD
-    XK_threequarters* = 0x000000BE
-    XK_questiondown* = 0x000000BF
-    XKc_Agrave* = 0x000000C0
-    XKc_Aacute* = 0x000000C1
-    XKc_Acircumflex* = 0x000000C2
-    XKc_Atilde* = 0x000000C3
-    XKc_Adiaeresis* = 0x000000C4
-    XKc_Aring* = 0x000000C5
-    XKc_AE* = 0x000000C6
-    XKc_Ccedilla* = 0x000000C7
-    XKc_Egrave* = 0x000000C8
-    XKc_Eacute* = 0x000000C9
-    XKc_Ecircumflex* = 0x000000CA
-    XKc_Ediaeresis* = 0x000000CB
-    XKc_Igrave* = 0x000000CC
-    XKc_Iacute* = 0x000000CD
-    XKc_Icircumflex* = 0x000000CE
-    XKc_Idiaeresis* = 0x000000CF
-    XKc_ETH* = 0x000000D0
-    XKc_Ntilde* = 0x000000D1
-    XKc_Ograve* = 0x000000D2
-    XKc_Oacute* = 0x000000D3
-    XKc_Ocircumflex* = 0x000000D4
-    XKc_Otilde* = 0x000000D5
-    XKc_Odiaeresis* = 0x000000D6
-    XK_multiply* = 0x000000D7
-    XKc_Ooblique* = 0x000000D8
-    XKc_Oslash* = XKc_Ooblique
-    XKc_Ugrave* = 0x000000D9
-    XKc_Uacute* = 0x000000DA
-    XKc_Ucircumflex* = 0x000000DB
-    XKc_Udiaeresis* = 0x000000DC
-    XKc_Yacute* = 0x000000DD
-    XKc_THORN* = 0x000000DE
-    XK_ssharp* = 0x000000DF
-    XK_agrave* = 0x000000E0
-    XK_aacute* = 0x000000E1
-    XK_acircumflex* = 0x000000E2
-    XK_atilde* = 0x000000E3
-    XK_adiaeresis* = 0x000000E4
-    XK_aring* = 0x000000E5
-    XK_ae* = 0x000000E6
-    XK_ccedilla* = 0x000000E7
-    XK_egrave* = 0x000000E8
-    XK_eacute* = 0x000000E9
-    XK_ecircumflex* = 0x000000EA
-    XK_ediaeresis* = 0x000000EB
-    XK_igrave* = 0x000000EC
-    XK_iacute* = 0x000000ED
-    XK_icircumflex* = 0x000000EE
-    XK_idiaeresis* = 0x000000EF
-    XK_eth* = 0x000000F0
-    XK_ntilde* = 0x000000F1
-    XK_ograve* = 0x000000F2
-    XK_oacute* = 0x000000F3
-    XK_ocircumflex* = 0x000000F4
-    XK_otilde* = 0x000000F5
-    XK_odiaeresis* = 0x000000F6
-    XK_division* = 0x000000F7
-    XK_oslash* = 0x000000F8
-    XK_ooblique* = XK_oslash
-    XK_ugrave* = 0x000000F9
-    XK_uacute* = 0x000000FA
-    XK_ucircumflex* = 0x000000FB
-    XK_udiaeresis* = 0x000000FC
-    XK_yacute* = 0x000000FD
-    XK_thorn* = 0x000000FE
-    XK_ydiaeresis* = 0x000000FF
+    XK_space*: TKeySym = 0x00000020
+    XK_exclam*: TKeySym = 0x00000021
+    XK_quotedbl*: TKeySym = 0x00000022
+    XK_numbersign*: TKeySym = 0x00000023
+    XK_dollar*: TKeySym = 0x00000024
+    XK_percent*: TKeySym = 0x00000025
+    XK_ampersand*: TKeySym = 0x00000026
+    XK_apostrophe*: TKeySym = 0x00000027
+    XK_quoteright*: TKeySym = 0x00000027 # deprecated 
+    XK_parenleft*: TKeySym = 0x00000028
+    XK_parenright*: TKeySym = 0x00000029
+    XK_asterisk*: TKeySym = 0x0000002A
+    XK_plus*: TKeySym = 0x0000002B
+    XK_comma*: TKeySym = 0x0000002C
+    XK_minus*: TKeySym = 0x0000002D
+    XK_period*: TKeySym = 0x0000002E
+    XK_slash*: TKeySym = 0x0000002F
+    XK_0*: TKeySym = 0x00000030
+    XK_1*: TKeySym = 0x00000031
+    XK_2*: TKeySym = 0x00000032
+    XK_3*: TKeySym = 0x00000033
+    XK_4*: TKeySym = 0x00000034
+    XK_5*: TKeySym = 0x00000035
+    XK_6*: TKeySym = 0x00000036
+    XK_7*: TKeySym = 0x00000037
+    XK_8*: TKeySym = 0x00000038
+    XK_9*: TKeySym = 0x00000039
+    XK_colon*: TKeySym = 0x0000003A
+    XK_semicolon*: TKeySym = 0x0000003B
+    XK_less*: TKeySym = 0x0000003C
+    XK_equal*: TKeySym = 0x0000003D
+    XK_greater*: TKeySym = 0x0000003E
+    XK_question*: TKeySym = 0x0000003F
+    XK_at*: TKeySym = 0x00000040
+    XKc_A*: TKeySym = 0x00000041
+    XKc_B*: TKeySym = 0x00000042
+    XKc_C*: TKeySym = 0x00000043
+    XKc_D*: TKeySym = 0x00000044
+    XKc_E*: TKeySym = 0x00000045
+    XKc_F*: TKeySym = 0x00000046
+    XKc_G*: TKeySym = 0x00000047
+    XKc_H*: TKeySym = 0x00000048
+    XKc_I*: TKeySym = 0x00000049
+    XKc_J*: TKeySym = 0x0000004A
+    XKc_K*: TKeySym = 0x0000004B
+    XKc_L*: TKeySym = 0x0000004C
+    XKc_M*: TKeySym = 0x0000004D
+    XKc_N*: TKeySym = 0x0000004E
+    XKc_O*: TKeySym = 0x0000004F
+    XKc_P*: TKeySym = 0x00000050
+    XKc_Q*: TKeySym = 0x00000051
+    XKc_R*: TKeySym = 0x00000052
+    XKc_S*: TKeySym = 0x00000053
+    XKc_T*: TKeySym = 0x00000054
+    XKc_U*: TKeySym = 0x00000055
+    XKc_V*: TKeySym = 0x00000056
+    XKc_W*: TKeySym = 0x00000057
+    XKc_X*: TKeySym = 0x00000058
+    XKc_Y*: TKeySym = 0x00000059
+    XKc_Z*: TKeySym = 0x0000005A
+    XK_bracketleft*: TKeySym = 0x0000005B
+    XK_backslash*: TKeySym = 0x0000005C
+    XK_bracketright*: TKeySym = 0x0000005D
+    XK_asciicircum*: TKeySym = 0x0000005E
+    XK_underscore*: TKeySym = 0x0000005F
+    XK_grave*: TKeySym = 0x00000060
+    XK_quoteleft*: TKeySym = 0x00000060  # deprecated 
+    XK_a*: TKeySym = 0x00000061
+    XK_b*: TKeySym = 0x00000062
+    XK_c*: TKeySym = 0x00000063
+    XK_d*: TKeySym = 0x00000064
+    XK_e*: TKeySym = 0x00000065
+    XK_f*: TKeySym = 0x00000066
+    XK_g*: TKeySym = 0x00000067
+    XK_h*: TKeySym = 0x00000068
+    XK_i*: TKeySym = 0x00000069
+    XK_j*: TKeySym = 0x0000006A
+    XK_k*: TKeySym = 0x0000006B
+    XK_l*: TKeySym = 0x0000006C
+    XK_m*: TKeySym = 0x0000006D
+    XK_n*: TKeySym = 0x0000006E
+    XK_o*: TKeySym = 0x0000006F
+    XK_p*: TKeySym = 0x00000070
+    XK_q*: TKeySym = 0x00000071
+    XK_r*: TKeySym = 0x00000072
+    XK_s*: TKeySym = 0x00000073
+    XK_t*: TKeySym = 0x00000074
+    XK_u*: TKeySym = 0x00000075
+    XK_v*: TKeySym = 0x00000076
+    XK_w*: TKeySym = 0x00000077
+    XK_x*: TKeySym = 0x00000078
+    XK_y*: TKeySym = 0x00000079
+    XK_z*: TKeySym = 0x0000007A
+    XK_braceleft*: TKeySym = 0x0000007B
+    XK_bar*: TKeySym = 0x0000007C
+    XK_braceright*: TKeySym = 0x0000007D
+    XK_asciitilde*: TKeySym = 0x0000007E
+    XK_nobreakspace*: TKeySym = 0x000000A0
+    XK_exclamdown*: TKeySym = 0x000000A1
+    XK_cent*: TKeySym = 0x000000A2
+    XK_sterling*: TKeySym = 0x000000A3
+    XK_currency*: TKeySym = 0x000000A4
+    XK_yen*: TKeySym = 0x000000A5
+    XK_brokenbar*: TKeySym = 0x000000A6
+    XK_section*: TKeySym = 0x000000A7
+    XK_diaeresis*: TKeySym = 0x000000A8
+    XK_copyright*: TKeySym = 0x000000A9
+    XK_ordfeminine*: TKeySym = 0x000000AA
+    XK_guillemotleft*: TKeySym = 0x000000AB # left angle quotation mark 
+    XK_notsign*: TKeySym = 0x000000AC
+    XK_hyphen*: TKeySym = 0x000000AD
+    XK_registered*: TKeySym = 0x000000AE
+    XK_macron*: TKeySym = 0x000000AF
+    XK_degree*: TKeySym = 0x000000B0
+    XK_plusminus*: TKeySym = 0x000000B1
+    XK_twosuperior*: TKeySym = 0x000000B2
+    XK_threesuperior*: TKeySym = 0x000000B3
+    XK_acute*: TKeySym = 0x000000B4
+    XK_mu*: TKeySym = 0x000000B5
+    XK_paragraph*: TKeySym = 0x000000B6
+    XK_periodcentered*: TKeySym = 0x000000B7
+    XK_cedilla*: TKeySym = 0x000000B8
+    XK_onesuperior*: TKeySym = 0x000000B9
+    XK_masculine*: TKeySym = 0x000000BA
+    XK_guillemotright*: TKeySym = 0x000000BB # right angle quotation mark 
+    XK_onequarter*: TKeySym = 0x000000BC
+    XK_onehalf*: TKeySym = 0x000000BD
+    XK_threequarters*: TKeySym = 0x000000BE
+    XK_questiondown*: TKeySym = 0x000000BF
+    XKc_Agrave*: TKeySym = 0x000000C0
+    XKc_Aacute*: TKeySym = 0x000000C1
+    XKc_Acircumflex*: TKeySym = 0x000000C2
+    XKc_Atilde*: TKeySym = 0x000000C3
+    XKc_Adiaeresis*: TKeySym = 0x000000C4
+    XKc_Aring*: TKeySym = 0x000000C5
+    XKc_AE*: TKeySym = 0x000000C6
+    XKc_Ccedilla*: TKeySym = 0x000000C7
+    XKc_Egrave*: TKeySym = 0x000000C8
+    XKc_Eacute*: TKeySym = 0x000000C9
+    XKc_Ecircumflex*: TKeySym = 0x000000CA
+    XKc_Ediaeresis*: TKeySym = 0x000000CB
+    XKc_Igrave*: TKeySym = 0x000000CC
+    XKc_Iacute*: TKeySym = 0x000000CD
+    XKc_Icircumflex*: TKeySym = 0x000000CE
+    XKc_Idiaeresis*: TKeySym = 0x000000CF
+    XKc_ETH*: TKeySym = 0x000000D0
+    XKc_Ntilde*: TKeySym = 0x000000D1
+    XKc_Ograve*: TKeySym = 0x000000D2
+    XKc_Oacute*: TKeySym = 0x000000D3
+    XKc_Ocircumflex*: TKeySym = 0x000000D4
+    XKc_Otilde*: TKeySym = 0x000000D5
+    XKc_Odiaeresis*: TKeySym = 0x000000D6
+    XK_multiply*: TKeySym = 0x000000D7
+    XKc_Ooblique*: TKeySym = 0x000000D8
+    XKc_Oslash*: TKeySym = XKc_Ooblique
+    XKc_Ugrave*: TKeySym = 0x000000D9
+    XKc_Uacute*: TKeySym = 0x000000DA
+    XKc_Ucircumflex*: TKeySym = 0x000000DB
+    XKc_Udiaeresis*: TKeySym = 0x000000DC
+    XKc_Yacute*: TKeySym = 0x000000DD
+    XKc_THORN*: TKeySym = 0x000000DE
+    XK_ssharp*: TKeySym = 0x000000DF
+    XK_agrave*: TKeySym = 0x000000E0
+    XK_aacute*: TKeySym = 0x000000E1
+    XK_acircumflex*: TKeySym = 0x000000E2
+    XK_atilde*: TKeySym = 0x000000E3
+    XK_adiaeresis*: TKeySym = 0x000000E4
+    XK_aring*: TKeySym = 0x000000E5
+    XK_ae*: TKeySym = 0x000000E6
+    XK_ccedilla*: TKeySym = 0x000000E7
+    XK_egrave*: TKeySym = 0x000000E8
+    XK_eacute*: TKeySym = 0x000000E9
+    XK_ecircumflex*: TKeySym = 0x000000EA
+    XK_ediaeresis*: TKeySym = 0x000000EB
+    XK_igrave*: TKeySym = 0x000000EC
+    XK_iacute*: TKeySym = 0x000000ED
+    XK_icircumflex*: TKeySym = 0x000000EE
+    XK_idiaeresis*: TKeySym = 0x000000EF
+    XK_eth*: TKeySym = 0x000000F0
+    XK_ntilde*: TKeySym = 0x000000F1
+    XK_ograve*: TKeySym = 0x000000F2
+    XK_oacute*: TKeySym = 0x000000F3
+    XK_ocircumflex*: TKeySym = 0x000000F4
+    XK_otilde*: TKeySym = 0x000000F5
+    XK_odiaeresis*: TKeySym = 0x000000F6
+    XK_division*: TKeySym = 0x000000F7
+    XK_oslash*: TKeySym = 0x000000F8
+    XK_ooblique*: TKeySym = XK_oslash
+    XK_ugrave*: TKeySym = 0x000000F9
+    XK_uacute*: TKeySym = 0x000000FA
+    XK_ucircumflex*: TKeySym = 0x000000FB
+    XK_udiaeresis*: TKeySym = 0x000000FC
+    XK_yacute*: TKeySym = 0x000000FD
+    XK_thorn*: TKeySym = 0x000000FE
+    XK_ydiaeresis*: TKeySym = 0x000000FF
 # XK_LATIN1 
 #*
 # *   Latin 2
@@ -559,63 +560,63 @@ when defined(XK_LATIN1) or true:
 
 when defined(XK_LATIN2) or true: 
   const
-    XKc_Aogonek* = 0x000001A1
-    XK_breve* = 0x000001A2
-    XKc_Lstroke* = 0x000001A3
-    XKc_Lcaron* = 0x000001A5
-    XKc_Sacute* = 0x000001A6
-    XKc_Scaron* = 0x000001A9
-    XKc_Scedilla* = 0x000001AA
-    XKc_Tcaron* = 0x000001AB
-    XKc_Zacute* = 0x000001AC
-    XKc_Zcaron* = 0x000001AE
-    XKc_Zabovedot* = 0x000001AF
-    XK_aogonek* = 0x000001B1
-    XK_ogonek* = 0x000001B2
-    XK_lstroke* = 0x000001B3
-    XK_lcaron* = 0x000001B5
-    XK_sacute* = 0x000001B6
-    XK_caron* = 0x000001B7
-    XK_scaron* = 0x000001B9
-    XK_scedilla* = 0x000001BA
-    XK_tcaron* = 0x000001BB
-    XK_zacute* = 0x000001BC
-    XK_doubleacute* = 0x000001BD
-    XK_zcaron* = 0x000001BE
-    XK_zabovedot* = 0x000001BF
-    XKc_Racute* = 0x000001C0
-    XKc_Abreve* = 0x000001C3
-    XKc_Lacute* = 0x000001C5
-    XKc_Cacute* = 0x000001C6
-    XKc_Ccaron* = 0x000001C8
-    XKc_Eogonek* = 0x000001CA
-    XKc_Ecaron* = 0x000001CC
-    XKc_Dcaron* = 0x000001CF
-    XKc_Dstroke* = 0x000001D0
-    XKc_Nacute* = 0x000001D1
-    XKc_Ncaron* = 0x000001D2
-    XKc_Odoubleacute* = 0x000001D5
-    XKc_Rcaron* = 0x000001D8
-    XKc_Uring* = 0x000001D9
-    XKc_Udoubleacute* = 0x000001DB
-    XKc_Tcedilla* = 0x000001DE
-    XK_racute* = 0x000001E0
-    XK_abreve* = 0x000001E3
-    XK_lacute* = 0x000001E5
-    XK_cacute* = 0x000001E6
-    XK_ccaron* = 0x000001E8
-    XK_eogonek* = 0x000001EA
-    XK_ecaron* = 0x000001EC
-    XK_dcaron* = 0x000001EF
-    XK_dstroke* = 0x000001F0
-    XK_nacute* = 0x000001F1
-    XK_ncaron* = 0x000001F2
-    XK_odoubleacute* = 0x000001F5
-    XK_udoubleacute* = 0x000001FB
-    XK_rcaron* = 0x000001F8
-    XK_uring* = 0x000001F9
-    XK_tcedilla* = 0x000001FE
-    XK_abovedot* = 0x000001FF
+    XKc_Aogonek*: TKeySym = 0x000001A1
+    XK_breve*: TKeySym = 0x000001A2
+    XKc_Lstroke*: TKeySym = 0x000001A3
+    XKc_Lcaron*: TKeySym = 0x000001A5
+    XKc_Sacute*: TKeySym = 0x000001A6
+    XKc_Scaron*: TKeySym = 0x000001A9
+    XKc_Scedilla*: TKeySym = 0x000001AA
+    XKc_Tcaron*: TKeySym = 0x000001AB
+    XKc_Zacute*: TKeySym = 0x000001AC
+    XKc_Zcaron*: TKeySym = 0x000001AE
+    XKc_Zabovedot*: TKeySym = 0x000001AF
+    XK_aogonek*: TKeySym = 0x000001B1
+    XK_ogonek*: TKeySym = 0x000001B2
+    XK_lstroke*: TKeySym = 0x000001B3
+    XK_lcaron*: TKeySym = 0x000001B5
+    XK_sacute*: TKeySym = 0x000001B6
+    XK_caron*: TKeySym = 0x000001B7
+    XK_scaron*: TKeySym = 0x000001B9
+    XK_scedilla*: TKeySym = 0x000001BA
+    XK_tcaron*: TKeySym = 0x000001BB
+    XK_zacute*: TKeySym = 0x000001BC
+    XK_doubleacute*: TKeySym = 0x000001BD
+    XK_zcaron*: TKeySym = 0x000001BE
+    XK_zabovedot*: TKeySym = 0x000001BF
+    XKc_Racute*: TKeySym = 0x000001C0
+    XKc_Abreve*: TKeySym = 0x000001C3
+    XKc_Lacute*: TKeySym = 0x000001C5
+    XKc_Cacute*: TKeySym = 0x000001C6
+    XKc_Ccaron*: TKeySym = 0x000001C8
+    XKc_Eogonek*: TKeySym = 0x000001CA
+    XKc_Ecaron*: TKeySym = 0x000001CC
+    XKc_Dcaron*: TKeySym = 0x000001CF
+    XKc_Dstroke*: TKeySym = 0x000001D0
+    XKc_Nacute*: TKeySym = 0x000001D1
+    XKc_Ncaron*: TKeySym = 0x000001D2
+    XKc_Odoubleacute*: TKeySym = 0x000001D5
+    XKc_Rcaron*: TKeySym = 0x000001D8
+    XKc_Uring*: TKeySym = 0x000001D9
+    XKc_Udoubleacute*: TKeySym = 0x000001DB
+    XKc_Tcedilla*: TKeySym = 0x000001DE
+    XK_racute*: TKeySym = 0x000001E0
+    XK_abreve*: TKeySym = 0x000001E3
+    XK_lacute*: TKeySym = 0x000001E5
+    XK_cacute*: TKeySym = 0x000001E6
+    XK_ccaron*: TKeySym = 0x000001E8
+    XK_eogonek*: TKeySym = 0x000001EA
+    XK_ecaron*: TKeySym = 0x000001EC
+    XK_dcaron*: TKeySym = 0x000001EF
+    XK_dstroke*: TKeySym = 0x000001F0
+    XK_nacute*: TKeySym = 0x000001F1
+    XK_ncaron*: TKeySym = 0x000001F2
+    XK_odoubleacute*: TKeySym = 0x000001F5
+    XK_udoubleacute*: TKeySym = 0x000001FB
+    XK_rcaron*: TKeySym = 0x000001F8
+    XK_uring*: TKeySym = 0x000001F9
+    XK_tcedilla*: TKeySym = 0x000001FE
+    XK_abovedot*: TKeySym = 0x000001FF
 # XK_LATIN2 
 #*
 # *   Latin 3
@@ -624,28 +625,28 @@ when defined(XK_LATIN2) or true:
 
 when defined(XK_LATIN3) or true: 
   const
-    XKc_Hstroke* = 0x000002A1
-    XKc_Hcircumflex* = 0x000002A6
-    XKc_Iabovedot* = 0x000002A9
-    XKc_Gbreve* = 0x000002AB
-    XKc_Jcircumflex* = 0x000002AC
-    XK_hstroke* = 0x000002B1
-    XK_hcircumflex* = 0x000002B6
-    XK_idotless* = 0x000002B9
-    XK_gbreve* = 0x000002BB
-    XK_jcircumflex* = 0x000002BC
-    XKc_Cabovedot* = 0x000002C5
-    XKc_Ccircumflex* = 0x000002C6
-    XKc_Gabovedot* = 0x000002D5
-    XKc_Gcircumflex* = 0x000002D8
-    XKc_Ubreve* = 0x000002DD
-    XKc_Scircumflex* = 0x000002DE
-    XK_cabovedot* = 0x000002E5
-    XK_ccircumflex* = 0x000002E6
-    XK_gabovedot* = 0x000002F5
-    XK_gcircumflex* = 0x000002F8
-    XK_ubreve* = 0x000002FD
-    XK_scircumflex* = 0x000002FE
+    XKc_Hstroke*: TKeySym = 0x000002A1
+    XKc_Hcircumflex*: TKeySym = 0x000002A6
+    XKc_Iabovedot*: TKeySym = 0x000002A9
+    XKc_Gbreve*: TKeySym = 0x000002AB
+    XKc_Jcircumflex*: TKeySym = 0x000002AC
+    XK_hstroke*: TKeySym = 0x000002B1
+    XK_hcircumflex*: TKeySym = 0x000002B6
+    XK_idotless*: TKeySym = 0x000002B9
+    XK_gbreve*: TKeySym = 0x000002BB
+    XK_jcircumflex*: TKeySym = 0x000002BC
+    XKc_Cabovedot*: TKeySym = 0x000002C5
+    XKc_Ccircumflex*: TKeySym = 0x000002C6
+    XKc_Gabovedot*: TKeySym = 0x000002D5
+    XKc_Gcircumflex*: TKeySym = 0x000002D8
+    XKc_Ubreve*: TKeySym = 0x000002DD
+    XKc_Scircumflex*: TKeySym = 0x000002DE
+    XK_cabovedot*: TKeySym = 0x000002E5
+    XK_ccircumflex*: TKeySym = 0x000002E6
+    XK_gabovedot*: TKeySym = 0x000002F5
+    XK_gcircumflex*: TKeySym = 0x000002F8
+    XK_ubreve*: TKeySym = 0x000002FD
+    XK_scircumflex*: TKeySym = 0x000002FE
 # XK_LATIN3 
 #*
 # *   Latin 4
@@ -654,42 +655,42 @@ when defined(XK_LATIN3) or true:
 
 when defined(XK_LATIN4) or true: 
   const
-    XK_kra* = 0x000003A2
-    XK_kappa* = 0x000003A2      # deprecated 
-    XKc_Rcedilla* = 0x000003A3
-    XKc_Itilde* = 0x000003A5
-    XKc_Lcedilla* = 0x000003A6
-    XKc_Emacron* = 0x000003AA
-    XKc_Gcedilla* = 0x000003AB
-    XKc_Tslash* = 0x000003AC
-    XK_rcedilla* = 0x000003B3
-    XK_itilde* = 0x000003B5
-    XK_lcedilla* = 0x000003B6
-    XK_emacron* = 0x000003BA
-    XK_gcedilla* = 0x000003BB
-    XK_tslash* = 0x000003BC
-    XKc_ENG* = 0x000003BD
-    XK_eng* = 0x000003BF
-    XKc_Amacron* = 0x000003C0
-    XKc_Iogonek* = 0x000003C7
-    XKc_Eabovedot* = 0x000003CC
-    XKc_Imacron* = 0x000003CF
-    XKc_Ncedilla* = 0x000003D1
-    XKc_Omacron* = 0x000003D2
-    XKc_Kcedilla* = 0x000003D3
-    XKc_Uogonek* = 0x000003D9
-    XKc_Utilde* = 0x000003DD
-    XKc_Umacron* = 0x000003DE
-    XK_amacron* = 0x000003E0
-    XK_iogonek* = 0x000003E7
-    XK_eabovedot* = 0x000003EC
-    XK_imacron* = 0x000003EF
-    XK_ncedilla* = 0x000003F1
-    XK_omacron* = 0x000003F2
-    XK_kcedilla* = 0x000003F3
-    XK_uogonek* = 0x000003F9
-    XK_utilde* = 0x000003FD
-    XK_umacron* = 0x000003FE
+    XK_kra*: TKeySym = 0x000003A2
+    XK_kappa*: TKeySym = 0x000003A2      # deprecated 
+    XKc_Rcedilla*: TKeySym = 0x000003A3
+    XKc_Itilde*: TKeySym = 0x000003A5
+    XKc_Lcedilla*: TKeySym = 0x000003A6
+    XKc_Emacron*: TKeySym = 0x000003AA
+    XKc_Gcedilla*: TKeySym = 0x000003AB
+    XKc_Tslash*: TKeySym = 0x000003AC
+    XK_rcedilla*: TKeySym = 0x000003B3
+    XK_itilde*: TKeySym = 0x000003B5
+    XK_lcedilla*: TKeySym = 0x000003B6
+    XK_emacron*: TKeySym = 0x000003BA
+    XK_gcedilla*: TKeySym = 0x000003BB
+    XK_tslash*: TKeySym = 0x000003BC
+    XKc_ENG*: TKeySym = 0x000003BD
+    XK_eng*: TKeySym = 0x000003BF
+    XKc_Amacron*: TKeySym = 0x000003C0
+    XKc_Iogonek*: TKeySym = 0x000003C7
+    XKc_Eabovedot*: TKeySym = 0x000003CC
+    XKc_Imacron*: TKeySym = 0x000003CF
+    XKc_Ncedilla*: TKeySym = 0x000003D1
+    XKc_Omacron*: TKeySym = 0x000003D2
+    XKc_Kcedilla*: TKeySym = 0x000003D3
+    XKc_Uogonek*: TKeySym = 0x000003D9
+    XKc_Utilde*: TKeySym = 0x000003DD
+    XKc_Umacron*: TKeySym = 0x000003DE
+    XK_amacron*: TKeySym = 0x000003E0
+    XK_iogonek*: TKeySym = 0x000003E7
+    XK_eabovedot*: TKeySym = 0x000003EC
+    XK_imacron*: TKeySym = 0x000003EF
+    XK_ncedilla*: TKeySym = 0x000003F1
+    XK_omacron*: TKeySym = 0x000003F2
+    XK_kcedilla*: TKeySym = 0x000003F3
+    XK_uogonek*: TKeySym = 0x000003F9
+    XK_utilde*: TKeySym = 0x000003FD
+    XK_umacron*: TKeySym = 0x000003FE
 # XK_LATIN4 
 #*
 # * Latin-8
@@ -698,32 +699,32 @@ when defined(XK_LATIN4) or true:
 
 when defined(XK_LATIN8) or true: 
   const
-    XKc_Babovedot* = 0x000012A1
-    XK_babovedot* = 0x000012A2
-    XKc_Dabovedot* = 0x000012A6
-    XKc_Wgrave* = 0x000012A8
-    XKc_Wacute* = 0x000012AA
-    XK_dabovedot* = 0x000012AB
-    XKc_Ygrave* = 0x000012AC
-    XKc_Fabovedot* = 0x000012B0
-    XK_fabovedot* = 0x000012B1
-    XKc_Mabovedot* = 0x000012B4
-    XK_mabovedot* = 0x000012B5
-    XKc_Pabovedot* = 0x000012B7
-    XK_wgrave* = 0x000012B8
-    XK_pabovedot* = 0x000012B9
-    XK_wacute* = 0x000012BA
-    XKc_Sabovedot* = 0x000012BB
-    XK_ygrave* = 0x000012BC
-    XKc_Wdiaeresis* = 0x000012BD
-    XK_wdiaeresis* = 0x000012BE
-    XK_sabovedot* = 0x000012BF
-    XKc_Wcircumflex* = 0x000012D0
-    XKc_Tabovedot* = 0x000012D7
-    XKc_Ycircumflex* = 0x000012DE
-    XK_wcircumflex* = 0x000012F0
-    XK_tabovedot* = 0x000012F7
-    XK_ycircumflex* = 0x000012FE
+    XKc_Babovedot*: TKeySym = 0x000012A1
+    XK_babovedot*: TKeySym = 0x000012A2
+    XKc_Dabovedot*: TKeySym = 0x000012A6
+    XKc_Wgrave*: TKeySym = 0x000012A8
+    XKc_Wacute*: TKeySym = 0x000012AA
+    XK_dabovedot*: TKeySym = 0x000012AB
+    XKc_Ygrave*: TKeySym = 0x000012AC
+    XKc_Fabovedot*: TKeySym = 0x000012B0
+    XK_fabovedot*: TKeySym = 0x000012B1
+    XKc_Mabovedot*: TKeySym = 0x000012B4
+    XK_mabovedot*: TKeySym = 0x000012B5
+    XKc_Pabovedot*: TKeySym = 0x000012B7
+    XK_wgrave*: TKeySym = 0x000012B8
+    XK_pabovedot*: TKeySym = 0x000012B9
+    XK_wacute*: TKeySym = 0x000012BA
+    XKc_Sabovedot*: TKeySym = 0x000012BB
+    XK_ygrave*: TKeySym = 0x000012BC
+    XKc_Wdiaeresis*: TKeySym = 0x000012BD
+    XK_wdiaeresis*: TKeySym = 0x000012BE
+    XK_sabovedot*: TKeySym = 0x000012BF
+    XKc_Wcircumflex*: TKeySym = 0x000012D0
+    XKc_Tabovedot*: TKeySym = 0x000012D7
+    XKc_Ycircumflex*: TKeySym = 0x000012DE
+    XK_wcircumflex*: TKeySym = 0x000012F0
+    XK_tabovedot*: TKeySym = 0x000012F7
+    XK_ycircumflex*: TKeySym = 0x000012FE
 # XK_LATIN8 
 #*
 # * Latin-9 (a.k.a. Latin-0)
@@ -732,9 +733,9 @@ when defined(XK_LATIN8) or true:
 
 when defined(XK_LATIN9) or true: 
   const
-    XKc_OE* = 0x000013BC
-    XK_oe* = 0x000013BD
-    XKc_Ydiaeresis* = 0x000013BE
+    XKc_OE*: TKeySym = 0x000013BC
+    XK_oe*: TKeySym = 0x000013BD
+    XKc_Ydiaeresis*: TKeySym = 0x000013BE
 # XK_LATIN9 
 #*
 # * Katakana
@@ -743,76 +744,76 @@ when defined(XK_LATIN9) or true:
 
 when defined(XK_KATAKANA) or true: 
   const
-    XK_overline* = 0x0000047E
-    XK_kana_fullstop* = 0x000004A1
-    XK_kana_openingbracket* = 0x000004A2
-    XK_kana_closingbracket* = 0x000004A3
-    XK_kana_comma* = 0x000004A4
-    XK_kana_conjunctive* = 0x000004A5
-    XK_kana_middledot* = 0x000004A5 # deprecated 
-    XKc_kana_WO* = 0x000004A6
-    XK_kana_a* = 0x000004A7
-    XK_kana_i* = 0x000004A8
-    XK_kana_u* = 0x000004A9
-    XK_kana_e* = 0x000004AA
-    XK_kana_o* = 0x000004AB
-    XK_kana_ya* = 0x000004AC
-    XK_kana_yu* = 0x000004AD
-    XK_kana_yo* = 0x000004AE
-    XK_kana_tsu* = 0x000004AF
-    XK_kana_tu* = 0x000004AF    # deprecated 
-    XK_prolongedsound* = 0x000004B0
-    XKc_kana_A* = 0x000004B1
-    XKc_kana_I* = 0x000004B2
-    XKc_kana_U* = 0x000004B3
-    XKc_kana_E* = 0x000004B4
-    XKc_kana_O* = 0x000004B5
-    XKc_kana_KA* = 0x000004B6
-    XKc_kana_KI* = 0x000004B7
-    XKc_kana_KU* = 0x000004B8
-    XKc_kana_KE* = 0x000004B9
-    XKc_kana_KO* = 0x000004BA
-    XKc_kana_SA* = 0x000004BB
-    XKc_kana_SHI* = 0x000004BC
-    XKc_kana_SU* = 0x000004BD
-    XKc_kana_SE* = 0x000004BE
-    XKc_kana_SO* = 0x000004BF
-    XKc_kana_TA* = 0x000004C0
-    XKc_kana_CHI* = 0x000004C1
-    XKc_kana_TI* = 0x000004C1   # deprecated 
-    XKc_kana_TSU* = 0x000004C2
-    XKc_kana_TU* = 0x000004C2   # deprecated 
-    XKc_kana_TE* = 0x000004C3
-    XKc_kana_TO* = 0x000004C4
-    XKc_kana_NA* = 0x000004C5
-    XKc_kana_NI* = 0x000004C6
-    XKc_kana_NU* = 0x000004C7
-    XKc_kana_NE* = 0x000004C8
-    XKc_kana_NO* = 0x000004C9
-    XKc_kana_HA* = 0x000004CA
-    XKc_kana_HI* = 0x000004CB
-    XKc_kana_FU* = 0x000004CC
-    XKc_kana_HU* = 0x000004CC   # deprecated 
-    XKc_kana_HE* = 0x000004CD
-    XKc_kana_HO* = 0x000004CE
-    XKc_kana_MA* = 0x000004CF
-    XKc_kana_MI* = 0x000004D0
-    XKc_kana_MU* = 0x000004D1
-    XKc_kana_ME* = 0x000004D2
-    XKc_kana_MO* = 0x000004D3
-    XKc_kana_YA* = 0x000004D4
-    XKc_kana_YU* = 0x000004D5
-    XKc_kana_YO* = 0x000004D6
-    XKc_kana_RA* = 0x000004D7
-    XKc_kana_RI* = 0x000004D8
-    XKc_kana_RU* = 0x000004D9
-    XKc_kana_RE* = 0x000004DA
-    XKc_kana_RO* = 0x000004DB
-    XKc_kana_WA* = 0x000004DC
-    XKc_kana_N* = 0x000004DD
-    XK_voicedsound* = 0x000004DE
-    XK_semivoicedsound* = 0x000004DF
-    XK_kana_switch* = 0x0000FF7E # Alias for mode_switch 
+    XK_overline*: TKeySym = 0x0000047E
+    XK_kana_fullstop*: TKeySym = 0x000004A1
+    XK_kana_openingbracket*: TKeySym = 0x000004A2
+    XK_kana_closingbracket*: TKeySym = 0x000004A3
+    XK_kana_comma*: TKeySym = 0x000004A4
+    XK_kana_conjunctive*: TKeySym = 0x000004A5
+    XK_kana_middledot*: TKeySym = 0x000004A5 # deprecated 
+    XKc_kana_WO*: TKeySym = 0x000004A6
+    XK_kana_a*: TKeySym = 0x000004A7
+    XK_kana_i*: TKeySym = 0x000004A8
+    XK_kana_u*: TKeySym = 0x000004A9
+    XK_kana_e*: TKeySym = 0x000004AA
+    XK_kana_o*: TKeySym = 0x000004AB
+    XK_kana_ya*: TKeySym = 0x000004AC
+    XK_kana_yu*: TKeySym = 0x000004AD
+    XK_kana_yo*: TKeySym = 0x000004AE
+    XK_kana_tsu*: TKeySym = 0x000004AF
+    XK_kana_tu*: TKeySym = 0x000004AF    # deprecated 
+    XK_prolongedsound*: TKeySym = 0x000004B0
+    XKc_kana_A*: TKeySym = 0x000004B1
+    XKc_kana_I*: TKeySym = 0x000004B2
+    XKc_kana_U*: TKeySym = 0x000004B3
+    XKc_kana_E*: TKeySym = 0x000004B4
+    XKc_kana_O*: TKeySym = 0x000004B5
+    XKc_kana_KA*: TKeySym = 0x000004B6
+    XKc_kana_KI*: TKeySym = 0x000004B7
+    XKc_kana_KU*: TKeySym = 0x000004B8
+    XKc_kana_KE*: TKeySym = 0x000004B9
+    XKc_kana_KO*: TKeySym = 0x000004BA
+    XKc_kana_SA*: TKeySym = 0x000004BB
+    XKc_kana_SHI*: TKeySym = 0x000004BC
+    XKc_kana_SU*: TKeySym = 0x000004BD
+    XKc_kana_SE*: TKeySym = 0x000004BE
+    XKc_kana_SO*: TKeySym = 0x000004BF
+    XKc_kana_TA*: TKeySym = 0x000004C0
+    XKc_kana_CHI*: TKeySym = 0x000004C1
+    XKc_kana_TI*: TKeySym = 0x000004C1   # deprecated 
+    XKc_kana_TSU*: TKeySym = 0x000004C2
+    XKc_kana_TU*: TKeySym = 0x000004C2   # deprecated 
+    XKc_kana_TE*: TKeySym = 0x000004C3
+    XKc_kana_TO*: TKeySym = 0x000004C4
+    XKc_kana_NA*: TKeySym = 0x000004C5
+    XKc_kana_NI*: TKeySym = 0x000004C6
+    XKc_kana_NU*: TKeySym = 0x000004C7
+    XKc_kana_NE*: TKeySym = 0x000004C8
+    XKc_kana_NO*: TKeySym = 0x000004C9
+    XKc_kana_HA*: TKeySym = 0x000004CA
+    XKc_kana_HI*: TKeySym = 0x000004CB
+    XKc_kana_FU*: TKeySym = 0x000004CC
+    XKc_kana_HU*: TKeySym = 0x000004CC   # deprecated 
+    XKc_kana_HE*: TKeySym = 0x000004CD
+    XKc_kana_HO*: TKeySym = 0x000004CE
+    XKc_kana_MA*: TKeySym = 0x000004CF
+    XKc_kana_MI*: TKeySym = 0x000004D0
+    XKc_kana_MU*: TKeySym = 0x000004D1
+    XKc_kana_ME*: TKeySym = 0x000004D2
+    XKc_kana_MO*: TKeySym = 0x000004D3
+    XKc_kana_YA*: TKeySym = 0x000004D4
+    XKc_kana_YU*: TKeySym = 0x000004D5
+    XKc_kana_YO*: TKeySym = 0x000004D6
+    XKc_kana_RA*: TKeySym = 0x000004D7
+    XKc_kana_RI*: TKeySym = 0x000004D8
+    XKc_kana_RU*: TKeySym = 0x000004D9
+    XKc_kana_RE*: TKeySym = 0x000004DA
+    XKc_kana_RO*: TKeySym = 0x000004DB
+    XKc_kana_WA*: TKeySym = 0x000004DC
+    XKc_kana_N*: TKeySym = 0x000004DD
+    XK_voicedsound*: TKeySym = 0x000004DE
+    XK_semivoicedsound*: TKeySym = 0x000004DF
+    XK_kana_switch*: TKeySym = 0x0000FF7E # Alias for mode_switch 
 # XK_KATAKANA 
 #*
 # *  Arabic
@@ -821,97 +822,97 @@ when defined(XK_KATAKANA) or true:
 
 when defined(XK_ARABIC) or true: 
   const
-    XK_Farsi_0* = 0x00000590
-    XK_Farsi_1* = 0x00000591
-    XK_Farsi_2* = 0x00000592
-    XK_Farsi_3* = 0x00000593
-    XK_Farsi_4* = 0x00000594
-    XK_Farsi_5* = 0x00000595
-    XK_Farsi_6* = 0x00000596
-    XK_Farsi_7* = 0x00000597
-    XK_Farsi_8* = 0x00000598
-    XK_Farsi_9* = 0x00000599
-    XK_Arabic_percent* = 0x000005A5
-    XK_Arabic_superscript_alef* = 0x000005A6
-    XK_Arabic_tteh* = 0x000005A7
-    XK_Arabic_peh* = 0x000005A8
-    XK_Arabic_tcheh* = 0x000005A9
-    XK_Arabic_ddal* = 0x000005AA
-    XK_Arabic_rreh* = 0x000005AB
-    XK_Arabic_comma* = 0x000005AC
-    XK_Arabic_fullstop* = 0x000005AE
-    XK_Arabic_0* = 0x000005B0
-    XK_Arabic_1* = 0x000005B1
-    XK_Arabic_2* = 0x000005B2
-    XK_Arabic_3* = 0x000005B3
-    XK_Arabic_4* = 0x000005B4
-    XK_Arabic_5* = 0x000005B5
-    XK_Arabic_6* = 0x000005B6
-    XK_Arabic_7* = 0x000005B7
-    XK_Arabic_8* = 0x000005B8
-    XK_Arabic_9* = 0x000005B9
-    XK_Arabic_semicolon* = 0x000005BB
-    XK_Arabic_question_mark* = 0x000005BF
-    XK_Arabic_hamza* = 0x000005C1
-    XK_Arabic_maddaonalef* = 0x000005C2
-    XK_Arabic_hamzaonalef* = 0x000005C3
-    XK_Arabic_hamzaonwaw* = 0x000005C4
-    XK_Arabic_hamzaunderalef* = 0x000005C5
-    XK_Arabic_hamzaonyeh* = 0x000005C6
-    XK_Arabic_alef* = 0x000005C7
-    XK_Arabic_beh* = 0x000005C8
-    XK_Arabic_tehmarbuta* = 0x000005C9
-    XK_Arabic_teh* = 0x000005CA
-    XK_Arabic_theh* = 0x000005CB
-    XK_Arabic_jeem* = 0x000005CC
-    XK_Arabic_hah* = 0x000005CD
-    XK_Arabic_khah* = 0x000005CE
-    XK_Arabic_dal* = 0x000005CF
-    XK_Arabic_thal* = 0x000005D0
-    XK_Arabic_ra* = 0x000005D1
-    XK_Arabic_zain* = 0x000005D2
-    XK_Arabic_seen* = 0x000005D3
-    XK_Arabic_sheen* = 0x000005D4
-    XK_Arabic_sad* = 0x000005D5
-    XK_Arabic_dad* = 0x000005D6
-    XK_Arabic_tah* = 0x000005D7
-    XK_Arabic_zah* = 0x000005D8
-    XK_Arabic_ain* = 0x000005D9
-    XK_Arabic_ghain* = 0x000005DA
-    XK_Arabic_tatweel* = 0x000005E0
-    XK_Arabic_feh* = 0x000005E1
-    XK_Arabic_qaf* = 0x000005E2
-    XK_Arabic_kaf* = 0x000005E3
-    XK_Arabic_lam* = 0x000005E4
-    XK_Arabic_meem* = 0x000005E5
-    XK_Arabic_noon* = 0x000005E6
-    XK_Arabic_ha* = 0x000005E7
-    XK_Arabic_heh* = 0x000005E7 # deprecated 
-    XK_Arabic_waw* = 0x000005E8
-    XK_Arabic_alefmaksura* = 0x000005E9
-    XK_Arabic_yeh* = 0x000005EA
-    XK_Arabic_fathatan* = 0x000005EB
-    XK_Arabic_dammatan* = 0x000005EC
-    XK_Arabic_kasratan* = 0x000005ED
-    XK_Arabic_fatha* = 0x000005EE
-    XK_Arabic_damma* = 0x000005EF
-    XK_Arabic_kasra* = 0x000005F0
-    XK_Arabic_shadda* = 0x000005F1
-    XK_Arabic_sukun* = 0x000005F2
-    XK_Arabic_madda_above* = 0x000005F3
-    XK_Arabic_hamza_above* = 0x000005F4
-    XK_Arabic_hamza_below* = 0x000005F5
-    XK_Arabic_jeh* = 0x000005F6
-    XK_Arabic_veh* = 0x000005F7
-    XK_Arabic_keheh* = 0x000005F8
-    XK_Arabic_gaf* = 0x000005F9
-    XK_Arabic_noon_ghunna* = 0x000005FA
-    XK_Arabic_heh_doachashmee* = 0x000005FB
-    XK_Farsi_yeh* = 0x000005FC
-    XK_Arabic_farsi_yeh* = XK_Farsi_yeh
-    XK_Arabic_yeh_baree* = 0x000005FD
-    XK_Arabic_heh_goal* = 0x000005FE
-    XK_Arabic_switch* = 0x0000FF7E # Alias for mode_switch 
+    XK_Farsi_0*: TKeySym = 0x00000590
+    XK_Farsi_1*: TKeySym = 0x00000591
+    XK_Farsi_2*: TKeySym = 0x00000592
+    XK_Farsi_3*: TKeySym = 0x00000593
+    XK_Farsi_4*: TKeySym = 0x00000594
+    XK_Farsi_5*: TKeySym = 0x00000595
+    XK_Farsi_6*: TKeySym = 0x00000596
+    XK_Farsi_7*: TKeySym = 0x00000597
+    XK_Farsi_8*: TKeySym = 0x00000598
+    XK_Farsi_9*: TKeySym = 0x00000599
+    XK_Arabic_percent*: TKeySym = 0x000005A5
+    XK_Arabic_superscript_alef*: TKeySym = 0x000005A6
+    XK_Arabic_tteh*: TKeySym = 0x000005A7
+    XK_Arabic_peh*: TKeySym = 0x000005A8
+    XK_Arabic_tcheh*: TKeySym = 0x000005A9
+    XK_Arabic_ddal*: TKeySym = 0x000005AA
+    XK_Arabic_rreh*: TKeySym = 0x000005AB
+    XK_Arabic_comma*: TKeySym = 0x000005AC
+    XK_Arabic_fullstop*: TKeySym = 0x000005AE
+    XK_Arabic_0*: TKeySym = 0x000005B0
+    XK_Arabic_1*: TKeySym = 0x000005B1
+    XK_Arabic_2*: TKeySym = 0x000005B2
+    XK_Arabic_3*: TKeySym = 0x000005B3
+    XK_Arabic_4*: TKeySym = 0x000005B4
+    XK_Arabic_5*: TKeySym = 0x000005B5
+    XK_Arabic_6*: TKeySym = 0x000005B6
+    XK_Arabic_7*: TKeySym = 0x000005B7
+    XK_Arabic_8*: TKeySym = 0x000005B8
+    XK_Arabic_9*: TKeySym = 0x000005B9
+    XK_Arabic_semicolon*: TKeySym = 0x000005BB
+    XK_Arabic_question_mark*: TKeySym = 0x000005BF
+    XK_Arabic_hamza*: TKeySym = 0x000005C1
+    XK_Arabic_maddaonalef*: TKeySym = 0x000005C2
+    XK_Arabic_hamzaonalef*: TKeySym = 0x000005C3
+    XK_Arabic_hamzaonwaw*: TKeySym = 0x000005C4
+    XK_Arabic_hamzaunderalef*: TKeySym = 0x000005C5
+    XK_Arabic_hamzaonyeh*: TKeySym = 0x000005C6
+    XK_Arabic_alef*: TKeySym = 0x000005C7
+    XK_Arabic_beh*: TKeySym = 0x000005C8
+    XK_Arabic_tehmarbuta*: TKeySym = 0x000005C9
+    XK_Arabic_teh*: TKeySym = 0x000005CA
+    XK_Arabic_theh*: TKeySym = 0x000005CB
+    XK_Arabic_jeem*: TKeySym = 0x000005CC
+    XK_Arabic_hah*: TKeySym = 0x000005CD
+    XK_Arabic_khah*: TKeySym = 0x000005CE
+    XK_Arabic_dal*: TKeySym = 0x000005CF
+    XK_Arabic_thal*: TKeySym = 0x000005D0
+    XK_Arabic_ra*: TKeySym = 0x000005D1
+    XK_Arabic_zain*: TKeySym = 0x000005D2
+    XK_Arabic_seen*: TKeySym = 0x000005D3
+    XK_Arabic_sheen*: TKeySym = 0x000005D4
+    XK_Arabic_sad*: TKeySym = 0x000005D5
+    XK_Arabic_dad*: TKeySym = 0x000005D6
+    XK_Arabic_tah*: TKeySym = 0x000005D7
+    XK_Arabic_zah*: TKeySym = 0x000005D8
+    XK_Arabic_ain*: TKeySym = 0x000005D9
+    XK_Arabic_ghain*: TKeySym = 0x000005DA
+    XK_Arabic_tatweel*: TKeySym = 0x000005E0
+    XK_Arabic_feh*: TKeySym = 0x000005E1
+    XK_Arabic_qaf*: TKeySym = 0x000005E2
+    XK_Arabic_kaf*: TKeySym = 0x000005E3
+    XK_Arabic_lam*: TKeySym = 0x000005E4
+    XK_Arabic_meem*: TKeySym = 0x000005E5
+    XK_Arabic_noon*: TKeySym = 0x000005E6
+    XK_Arabic_ha*: TKeySym = 0x000005E7
+    XK_Arabic_heh*: TKeySym = 0x000005E7 # deprecated 
+    XK_Arabic_waw*: TKeySym = 0x000005E8
+    XK_Arabic_alefmaksura*: TKeySym = 0x000005E9
+    XK_Arabic_yeh*: TKeySym = 0x000005EA
+    XK_Arabic_fathatan*: TKeySym = 0x000005EB
+    XK_Arabic_dammatan*: TKeySym = 0x000005EC
+    XK_Arabic_kasratan*: TKeySym = 0x000005ED
+    XK_Arabic_fatha*: TKeySym = 0x000005EE
+    XK_Arabic_damma*: TKeySym = 0x000005EF
+    XK_Arabic_kasra*: TKeySym = 0x000005F0
+    XK_Arabic_shadda*: TKeySym = 0x000005F1
+    XK_Arabic_sukun*: TKeySym = 0x000005F2
+    XK_Arabic_madda_above*: TKeySym = 0x000005F3
+    XK_Arabic_hamza_above*: TKeySym = 0x000005F4
+    XK_Arabic_hamza_below*: TKeySym = 0x000005F5
+    XK_Arabic_jeh*: TKeySym = 0x000005F6
+    XK_Arabic_veh*: TKeySym = 0x000005F7
+    XK_Arabic_keheh*: TKeySym = 0x000005F8
+    XK_Arabic_gaf*: TKeySym = 0x000005F9
+    XK_Arabic_noon_ghunna*: TKeySym = 0x000005FA
+    XK_Arabic_heh_doachashmee*: TKeySym = 0x000005FB
+    XK_Farsi_yeh*: TKeySym = 0x000005FC
+    XK_Arabic_farsi_yeh*: TKeySym = XK_Farsi_yeh
+    XK_Arabic_yeh_baree*: TKeySym = 0x000005FD
+    XK_Arabic_heh_goal*: TKeySym = 0x000005FE
+    XK_Arabic_switch*: TKeySym = 0x0000FF7E # Alias for mode_switch 
 # XK_ARABIC 
 #*
 # * Cyrillic
@@ -920,145 +921,145 @@ when defined(XK_ARABIC) or true:
 
 when defined(XK_CYRILLIC) or true: 
   const
-    XKc_Cyrillic_GHE_bar* = 0x00000680
-    XK_Cyrillic_ghe_bar* = 0x00000690
-    XKc_Cyrillic_ZHE_descender* = 0x00000681
-    XK_Cyrillic_zhe_descender* = 0x00000691
-    XKc_Cyrillic_KA_descender* = 0x00000682
-    XK_Cyrillic_ka_descender* = 0x00000692
-    XKc_Cyrillic_KA_vertstroke* = 0x00000683
-    XK_Cyrillic_ka_vertstroke* = 0x00000693
-    XKc_Cyrillic_EN_descender* = 0x00000684
-    XK_Cyrillic_en_descender* = 0x00000694
-    XKc_Cyrillic_U_straight* = 0x00000685
-    XK_Cyrillic_u_straight* = 0x00000695
-    XKc_Cyrillic_U_straight_bar* = 0x00000686
-    XK_Cyrillic_u_straight_bar* = 0x00000696
-    XKc_Cyrillic_HA_descender* = 0x00000687
-    XK_Cyrillic_ha_descender* = 0x00000697
-    XKc_Cyrillic_CHE_descender* = 0x00000688
-    XK_Cyrillic_che_descender* = 0x00000698
-    XKc_Cyrillic_CHE_vertstroke* = 0x00000689
-    XK_Cyrillic_che_vertstroke* = 0x00000699
-    XKc_Cyrillic_SHHA* = 0x0000068A
-    XK_Cyrillic_shha* = 0x0000069A
-    XKc_Cyrillic_SCHWA* = 0x0000068C
-    XK_Cyrillic_schwa* = 0x0000069C
-    XKc_Cyrillic_I_macron* = 0x0000068D
-    XK_Cyrillic_i_macron* = 0x0000069D
-    XKc_Cyrillic_O_bar* = 0x0000068E
-    XK_Cyrillic_o_bar* = 0x0000069E
-    XKc_Cyrillic_U_macron* = 0x0000068F
-    XK_Cyrillic_u_macron* = 0x0000069F
-    XK_Serbian_dje* = 0x000006A1
-    XK_Macedonia_gje* = 0x000006A2
-    XK_Cyrillic_io* = 0x000006A3
-    XK_Ukrainian_ie* = 0x000006A4
-    XK_Ukranian_je* = 0x000006A4 # deprecated 
-    XK_Macedonia_dse* = 0x000006A5
-    XK_Ukrainian_i* = 0x000006A6
-    XK_Ukranian_i* = 0x000006A6 # deprecated 
-    XK_Ukrainian_yi* = 0x000006A7
-    XK_Ukranian_yi* = 0x000006A7 # deprecated 
-    XK_Cyrillic_je* = 0x000006A8
-    XK_Serbian_je* = 0x000006A8 # deprecated 
-    XK_Cyrillic_lje* = 0x000006A9
-    XK_Serbian_lje* = 0x000006A9 # deprecated 
-    XK_Cyrillic_nje* = 0x000006AA
-    XK_Serbian_nje* = 0x000006AA # deprecated 
-    XK_Serbian_tshe* = 0x000006AB
-    XK_Macedonia_kje* = 0x000006AC
-    XK_Ukrainian_ghe_with_upturn* = 0x000006AD
-    XK_Byelorussian_shortu* = 0x000006AE
-    XK_Cyrillic_dzhe* = 0x000006AF
-    XK_Serbian_dze* = 0x000006AF # deprecated 
-    XK_numerosign* = 0x000006B0
-    XKc_Serbian_DJE* = 0x000006B1
-    XKc_Macedonia_GJE* = 0x000006B2
-    XKc_Cyrillic_IO* = 0x000006B3
-    XKc_Ukrainian_IE* = 0x000006B4
-    XKc_Ukranian_JE* = 0x000006B4 # deprecated 
-    XKc_Macedonia_DSE* = 0x000006B5
-    XKc_Ukrainian_I* = 0x000006B6
-    XKc_Ukranian_I* = 0x000006B6 # deprecated 
-    XKc_Ukrainian_YI* = 0x000006B7
-    XKc_Ukranian_YI* = 0x000006B7 # deprecated 
-    XKc_Cyrillic_JE* = 0x000006B8
-    XKc_Serbian_JE* = 0x000006B8 # deprecated 
-    XKc_Cyrillic_LJE* = 0x000006B9
-    XKc_Serbian_LJE* = 0x000006B9 # deprecated 
-    XKc_Cyrillic_NJE* = 0x000006BA
-    XKc_Serbian_NJE* = 0x000006BA # deprecated 
-    XKc_Serbian_TSHE* = 0x000006BB
-    XKc_Macedonia_KJE* = 0x000006BC
-    XKc_Ukrainian_GHE_WITH_UPTURN* = 0x000006BD
-    XKc_Byelorussian_SHORTU* = 0x000006BE
-    XKc_Cyrillic_DZHE* = 0x000006BF
-    XKc_Serbian_DZE* = 0x000006BF # deprecated 
-    XK_Cyrillic_yu* = 0x000006C0
-    XK_Cyrillic_a* = 0x000006C1
-    XK_Cyrillic_be* = 0x000006C2
-    XK_Cyrillic_tse* = 0x000006C3
-    XK_Cyrillic_de* = 0x000006C4
-    XK_Cyrillic_ie* = 0x000006C5
-    XK_Cyrillic_ef* = 0x000006C6
-    XK_Cyrillic_ghe* = 0x000006C7
-    XK_Cyrillic_ha* = 0x000006C8
-    XK_Cyrillic_i* = 0x000006C9
-    XK_Cyrillic_shorti* = 0x000006CA
-    XK_Cyrillic_ka* = 0x000006CB
-    XK_Cyrillic_el* = 0x000006CC
-    XK_Cyrillic_em* = 0x000006CD
-    XK_Cyrillic_en* = 0x000006CE
-    XK_Cyrillic_o* = 0x000006CF
-    XK_Cyrillic_pe* = 0x000006D0
-    XK_Cyrillic_ya* = 0x000006D1
-    XK_Cyrillic_er* = 0x000006D2
-    XK_Cyrillic_es* = 0x000006D3
-    XK_Cyrillic_te* = 0x000006D4
-    XK_Cyrillic_u* = 0x000006D5
-    XK_Cyrillic_zhe* = 0x000006D6
-    XK_Cyrillic_ve* = 0x000006D7
-    XK_Cyrillic_softsign* = 0x000006D8
-    XK_Cyrillic_yeru* = 0x000006D9
-    XK_Cyrillic_ze* = 0x000006DA
-    XK_Cyrillic_sha* = 0x000006DB
-    XK_Cyrillic_e* = 0x000006DC
-    XK_Cyrillic_shcha* = 0x000006DD
-    XK_Cyrillic_che* = 0x000006DE
-    XK_Cyrillic_hardsign* = 0x000006DF
-    XKc_Cyrillic_YU* = 0x000006E0
-    XKc_Cyrillic_A* = 0x000006E1
-    XKc_Cyrillic_BE* = 0x000006E2
-    XKc_Cyrillic_TSE* = 0x000006E3
-    XKc_Cyrillic_DE* = 0x000006E4
-    XKc_Cyrillic_IE* = 0x000006E5
-    XKc_Cyrillic_EF* = 0x000006E6
-    XKc_Cyrillic_GHE* = 0x000006E7
-    XKc_Cyrillic_HA* = 0x000006E8
-    XKc_Cyrillic_I* = 0x000006E9
-    XKc_Cyrillic_SHORTI* = 0x000006EA
-    XKc_Cyrillic_KA* = 0x000006EB
-    XKc_Cyrillic_EL* = 0x000006EC
-    XKc_Cyrillic_EM* = 0x000006ED
-    XKc_Cyrillic_EN* = 0x000006EE
-    XKc_Cyrillic_O* = 0x000006EF
-    XKc_Cyrillic_PE* = 0x000006F0
-    XKc_Cyrillic_YA* = 0x000006F1
-    XKc_Cyrillic_ER* = 0x000006F2
-    XKc_Cyrillic_ES* = 0x000006F3
-    XKc_Cyrillic_TE* = 0x000006F4
-    XKc_Cyrillic_U* = 0x000006F5
-    XKc_Cyrillic_ZHE* = 0x000006F6
-    XKc_Cyrillic_VE* = 0x000006F7
-    XKc_Cyrillic_SOFTSIGN* = 0x000006F8
-    XKc_Cyrillic_YERU* = 0x000006F9
-    XKc_Cyrillic_ZE* = 0x000006FA
-    XKc_Cyrillic_SHA* = 0x000006FB
-    XKc_Cyrillic_E* = 0x000006FC
-    XKc_Cyrillic_SHCHA* = 0x000006FD
-    XKc_Cyrillic_CHE* = 0x000006FE
-    XKc_Cyrillic_HARDSIGN* = 0x000006FF
+    XKc_Cyrillic_GHE_bar*: TKeySym = 0x00000680
+    XK_Cyrillic_ghe_bar*: TKeySym = 0x00000690
+    XKc_Cyrillic_ZHE_descender*: TKeySym = 0x00000681
+    XK_Cyrillic_zhe_descender*: TKeySym = 0x00000691
+    XKc_Cyrillic_KA_descender*: TKeySym = 0x00000682
+    XK_Cyrillic_ka_descender*: TKeySym = 0x00000692
+    XKc_Cyrillic_KA_vertstroke*: TKeySym = 0x00000683
+    XK_Cyrillic_ka_vertstroke*: TKeySym = 0x00000693
+    XKc_Cyrillic_EN_descender*: TKeySym = 0x00000684
+    XK_Cyrillic_en_descender*: TKeySym = 0x00000694
+    XKc_Cyrillic_U_straight*: TKeySym = 0x00000685
+    XK_Cyrillic_u_straight*: TKeySym = 0x00000695
+    XKc_Cyrillic_U_straight_bar*: TKeySym = 0x00000686
+    XK_Cyrillic_u_straight_bar*: TKeySym = 0x00000696
+    XKc_Cyrillic_HA_descender*: TKeySym = 0x00000687
+    XK_Cyrillic_ha_descender*: TKeySym = 0x00000697
+    XKc_Cyrillic_CHE_descender*: TKeySym = 0x00000688
+    XK_Cyrillic_che_descender*: TKeySym = 0x00000698
+    XKc_Cyrillic_CHE_vertstroke*: TKeySym = 0x00000689
+    XK_Cyrillic_che_vertstroke*: TKeySym = 0x00000699
+    XKc_Cyrillic_SHHA*: TKeySym = 0x0000068A
+    XK_Cyrillic_shha*: TKeySym = 0x0000069A
+    XKc_Cyrillic_SCHWA*: TKeySym = 0x0000068C
+    XK_Cyrillic_schwa*: TKeySym = 0x0000069C
+    XKc_Cyrillic_I_macron*: TKeySym = 0x0000068D
+    XK_Cyrillic_i_macron*: TKeySym = 0x0000069D
+    XKc_Cyrillic_O_bar*: TKeySym = 0x0000068E
+    XK_Cyrillic_o_bar*: TKeySym = 0x0000069E
+    XKc_Cyrillic_U_macron*: TKeySym = 0x0000068F
+    XK_Cyrillic_u_macron*: TKeySym = 0x0000069F
+    XK_Serbian_dje*: TKeySym = 0x000006A1
+    XK_Macedonia_gje*: TKeySym = 0x000006A2
+    XK_Cyrillic_io*: TKeySym = 0x000006A3
+    XK_Ukrainian_ie*: TKeySym = 0x000006A4
+    XK_Ukranian_je*: TKeySym = 0x000006A4 # deprecated 
+    XK_Macedonia_dse*: TKeySym = 0x000006A5
+    XK_Ukrainian_i*: TKeySym = 0x000006A6
+    XK_Ukranian_i*: TKeySym = 0x000006A6 # deprecated 
+    XK_Ukrainian_yi*: TKeySym = 0x000006A7
+    XK_Ukranian_yi*: TKeySym = 0x000006A7 # deprecated 
+    XK_Cyrillic_je*: TKeySym = 0x000006A8
+    XK_Serbian_je*: TKeySym = 0x000006A8 # deprecated 
+    XK_Cyrillic_lje*: TKeySym = 0x000006A9
+    XK_Serbian_lje*: TKeySym = 0x000006A9 # deprecated 
+    XK_Cyrillic_nje*: TKeySym = 0x000006AA
+    XK_Serbian_nje*: TKeySym = 0x000006AA # deprecated 
+    XK_Serbian_tshe*: TKeySym = 0x000006AB
+    XK_Macedonia_kje*: TKeySym = 0x000006AC
+    XK_Ukrainian_ghe_with_upturn*: TKeySym = 0x000006AD
+    XK_Byelorussian_shortu*: TKeySym = 0x000006AE
+    XK_Cyrillic_dzhe*: TKeySym = 0x000006AF
+    XK_Serbian_dze*: TKeySym = 0x000006AF # deprecated 
+    XK_numerosign*: TKeySym = 0x000006B0
+    XKc_Serbian_DJE*: TKeySym = 0x000006B1
+    XKc_Macedonia_GJE*: TKeySym = 0x000006B2
+    XKc_Cyrillic_IO*: TKeySym = 0x000006B3
+    XKc_Ukrainian_IE*: TKeySym = 0x000006B4
+    XKc_Ukranian_JE*: TKeySym = 0x000006B4 # deprecated 
+    XKc_Macedonia_DSE*: TKeySym = 0x000006B5
+    XKc_Ukrainian_I*: TKeySym = 0x000006B6
+    XKc_Ukranian_I*: TKeySym = 0x000006B6 # deprecated 
+    XKc_Ukrainian_YI*: TKeySym = 0x000006B7
+    XKc_Ukranian_YI*: TKeySym = 0x000006B7 # deprecated 
+    XKc_Cyrillic_JE*: TKeySym = 0x000006B8
+    XKc_Serbian_JE*: TKeySym = 0x000006B8 # deprecated 
+    XKc_Cyrillic_LJE*: TKeySym = 0x000006B9
+    XKc_Serbian_LJE*: TKeySym = 0x000006B9 # deprecated 
+    XKc_Cyrillic_NJE*: TKeySym = 0x000006BA
+    XKc_Serbian_NJE*: TKeySym = 0x000006BA # deprecated 
+    XKc_Serbian_TSHE*: TKeySym = 0x000006BB
+    XKc_Macedonia_KJE*: TKeySym = 0x000006BC
+    XKc_Ukrainian_GHE_WITH_UPTURN*: TKeySym = 0x000006BD
+    XKc_Byelorussian_SHORTU*: TKeySym = 0x000006BE
+    XKc_Cyrillic_DZHE*: TKeySym = 0x000006BF
+    XKc_Serbian_DZE*: TKeySym = 0x000006BF # deprecated 
+    XK_Cyrillic_yu*: TKeySym = 0x000006C0
+    XK_Cyrillic_a*: TKeySym = 0x000006C1
+    XK_Cyrillic_be*: TKeySym = 0x000006C2
+    XK_Cyrillic_tse*: TKeySym = 0x000006C3
+    XK_Cyrillic_de*: TKeySym = 0x000006C4
+    XK_Cyrillic_ie*: TKeySym = 0x000006C5
+    XK_Cyrillic_ef*: TKeySym = 0x000006C6
+    XK_Cyrillic_ghe*: TKeySym = 0x000006C7
+    XK_Cyrillic_ha*: TKeySym = 0x000006C8
+    XK_Cyrillic_i*: TKeySym = 0x000006C9
+    XK_Cyrillic_shorti*: TKeySym = 0x000006CA
+    XK_Cyrillic_ka*: TKeySym = 0x000006CB
+    XK_Cyrillic_el*: TKeySym = 0x000006CC
+    XK_Cyrillic_em*: TKeySym = 0x000006CD
+    XK_Cyrillic_en*: TKeySym = 0x000006CE
+    XK_Cyrillic_o*: TKeySym = 0x000006CF
+    XK_Cyrillic_pe*: TKeySym = 0x000006D0
+    XK_Cyrillic_ya*: TKeySym = 0x000006D1
+    XK_Cyrillic_er*: TKeySym = 0x000006D2
+    XK_Cyrillic_es*: TKeySym = 0x000006D3
+    XK_Cyrillic_te*: TKeySym = 0x000006D4
+    XK_Cyrillic_u*: TKeySym = 0x000006D5
+    XK_Cyrillic_zhe*: TKeySym = 0x000006D6
+    XK_Cyrillic_ve*: TKeySym = 0x000006D7
+    XK_Cyrillic_softsign*: TKeySym = 0x000006D8
+    XK_Cyrillic_yeru*: TKeySym = 0x000006D9
+    XK_Cyrillic_ze*: TKeySym = 0x000006DA
+    XK_Cyrillic_sha*: TKeySym = 0x000006DB
+    XK_Cyrillic_e*: TKeySym = 0x000006DC
+    XK_Cyrillic_shcha*: TKeySym = 0x000006DD
+    XK_Cyrillic_che*: TKeySym = 0x000006DE
+    XK_Cyrillic_hardsign*: TKeySym = 0x000006DF
+    XKc_Cyrillic_YU*: TKeySym = 0x000006E0
+    XKc_Cyrillic_A*: TKeySym = 0x000006E1
+    XKc_Cyrillic_BE*: TKeySym = 0x000006E2
+    XKc_Cyrillic_TSE*: TKeySym = 0x000006E3
+    XKc_Cyrillic_DE*: TKeySym = 0x000006E4
+    XKc_Cyrillic_IE*: TKeySym = 0x000006E5
+    XKc_Cyrillic_EF*: TKeySym = 0x000006E6
+    XKc_Cyrillic_GHE*: TKeySym = 0x000006E7
+    XKc_Cyrillic_HA*: TKeySym = 0x000006E8
+    XKc_Cyrillic_I*: TKeySym = 0x000006E9
+    XKc_Cyrillic_SHORTI*: TKeySym = 0x000006EA
+    XKc_Cyrillic_KA*: TKeySym = 0x000006EB
+    XKc_Cyrillic_EL*: TKeySym = 0x000006EC
+    XKc_Cyrillic_EM*: TKeySym = 0x000006ED
+    XKc_Cyrillic_EN*: TKeySym = 0x000006EE
+    XKc_Cyrillic_O*: TKeySym = 0x000006EF
+    XKc_Cyrillic_PE*: TKeySym = 0x000006F0
+    XKc_Cyrillic_YA*: TKeySym = 0x000006F1
+    XKc_Cyrillic_ER*: TKeySym = 0x000006F2
+    XKc_Cyrillic_ES*: TKeySym = 0x000006F3
+    XKc_Cyrillic_TE*: TKeySym = 0x000006F4
+    XKc_Cyrillic_U*: TKeySym = 0x000006F5
+    XKc_Cyrillic_ZHE*: TKeySym = 0x000006F6
+    XKc_Cyrillic_VE*: TKeySym = 0x000006F7
+    XKc_Cyrillic_SOFTSIGN*: TKeySym = 0x000006F8
+    XKc_Cyrillic_YERU*: TKeySym = 0x000006F9
+    XKc_Cyrillic_ZE*: TKeySym = 0x000006FA
+    XKc_Cyrillic_SHA*: TKeySym = 0x000006FB
+    XKc_Cyrillic_E*: TKeySym = 0x000006FC
+    XKc_Cyrillic_SHCHA*: TKeySym = 0x000006FD
+    XKc_Cyrillic_CHE*: TKeySym = 0x000006FE
+    XKc_Cyrillic_HARDSIGN*: TKeySym = 0x000006FF
 # XK_CYRILLIC 
 #*
 # * Greek
@@ -1067,81 +1068,81 @@ when defined(XK_CYRILLIC) or true:
 
 when defined(XK_GREEK) or true: 
   const
-    XKc_Greek_ALPHAaccent* = 0x000007A1
-    XKc_Greek_EPSILONaccent* = 0x000007A2
-    XKc_Greek_ETAaccent* = 0x000007A3
-    XKc_Greek_IOTAaccent* = 0x000007A4
-    XKc_Greek_IOTAdieresis* = 0x000007A5
-    XKc_Greek_IOTAdiaeresis* = XKc_Greek_IOTAdieresis # old typo 
-    XKc_Greek_OMICRONaccent* = 0x000007A7
-    XKc_Greek_UPSILONaccent* = 0x000007A8
-    XKc_Greek_UPSILONdieresis* = 0x000007A9
-    XKc_Greek_OMEGAaccent* = 0x000007AB
-    XK_Greek_accentdieresis* = 0x000007AE
-    XK_Greek_horizbar* = 0x000007AF
-    XK_Greek_alphaaccent* = 0x000007B1
-    XK_Greek_epsilonaccent* = 0x000007B2
-    XK_Greek_etaaccent* = 0x000007B3
-    XK_Greek_iotaaccent* = 0x000007B4
-    XK_Greek_iotadieresis* = 0x000007B5
-    XK_Greek_iotaaccentdieresis* = 0x000007B6
-    XK_Greek_omicronaccent* = 0x000007B7
-    XK_Greek_upsilonaccent* = 0x000007B8
-    XK_Greek_upsilondieresis* = 0x000007B9
-    XK_Greek_upsilonaccentdieresis* = 0x000007BA
-    XK_Greek_omegaaccent* = 0x000007BB
-    XKc_Greek_ALPHA* = 0x000007C1
-    XKc_Greek_BETA* = 0x000007C2
-    XKc_Greek_GAMMA* = 0x000007C3
-    XKc_Greek_DELTA* = 0x000007C4
-    XKc_Greek_EPSILON* = 0x000007C5
-    XKc_Greek_ZETA* = 0x000007C6
-    XKc_Greek_ETA* = 0x000007C7
-    XKc_Greek_THETA* = 0x000007C8
-    XKc_Greek_IOTA* = 0x000007C9
-    XKc_Greek_KAPPA* = 0x000007CA
-    XKc_Greek_LAMDA* = 0x000007CB
-    XKc_Greek_LAMBDA* = 0x000007CB
-    XKc_Greek_MU* = 0x000007CC
-    XKc_Greek_NU* = 0x000007CD
-    XKc_Greek_XI* = 0x000007CE
-    XKc_Greek_OMICRON* = 0x000007CF
-    XKc_Greek_PI* = 0x000007D0
-    XKc_Greek_RHO* = 0x000007D1
-    XKc_Greek_SIGMA* = 0x000007D2
-    XKc_Greek_TAU* = 0x000007D4
-    XKc_Greek_UPSILON* = 0x000007D5
-    XKc_Greek_PHI* = 0x000007D6
-    XKc_Greek_CHI* = 0x000007D7
-    XKc_Greek_PSI* = 0x000007D8
-    XKc_Greek_OMEGA* = 0x000007D9
-    XK_Greek_alpha* = 0x000007E1
-    XK_Greek_beta* = 0x000007E2
-    XK_Greek_gamma* = 0x000007E3
-    XK_Greek_delta* = 0x000007E4
-    XK_Greek_epsilon* = 0x000007E5
-    XK_Greek_zeta* = 0x000007E6
-    XK_Greek_eta* = 0x000007E7
-    XK_Greek_theta* = 0x000007E8
-    XK_Greek_iota* = 0x000007E9
-    XK_Greek_kappa* = 0x000007EA
-    XK_Greek_lamda* = 0x000007EB
-    XK_Greek_lambda* = 0x000007EB
-    XK_Greek_mu* = 0x000007EC
-    XK_Greek_nu* = 0x000007ED
-    XK_Greek_xi* = 0x000007EE
-    XK_Greek_omicron* = 0x000007EF
-    XK_Greek_pi* = 0x000007F0
-    XK_Greek_rho* = 0x000007F1
-    XK_Greek_sigma* = 0x000007F2
-    XK_Greek_finalsmallsigma* = 0x000007F3
-    XK_Greek_tau* = 0x000007F4
-    XK_Greek_upsilon* = 0x000007F5
-    XK_Greek_phi* = 0x000007F6
-    XK_Greek_chi* = 0x000007F7
-    XK_Greek_psi* = 0x000007F8
-    XK_Greek_omega* = 0x000007F9
-    XK_Greek_switch* = 0x0000FF7E # Alias for mode_switch 
+    XKc_Greek_ALPHAaccent*: TKeySym = 0x000007A1
+    XKc_Greek_EPSILONaccent*: TKeySym = 0x000007A2
+    XKc_Greek_ETAaccent*: TKeySym = 0x000007A3
+    XKc_Greek_IOTAaccent*: TKeySym = 0x000007A4
+    XKc_Greek_IOTAdieresis*: TKeySym = 0x000007A5
+    XKc_Greek_IOTAdiaeresis*: TKeySym = XKc_Greek_IOTAdieresis # old typo 
+    XKc_Greek_OMICRONaccent*: TKeySym = 0x000007A7
+    XKc_Greek_UPSILONaccent*: TKeySym = 0x000007A8
+    XKc_Greek_UPSILONdieresis*: TKeySym = 0x000007A9
+    XKc_Greek_OMEGAaccent*: TKeySym = 0x000007AB
+    XK_Greek_accentdieresis*: TKeySym = 0x000007AE
+    XK_Greek_horizbar*: TKeySym = 0x000007AF
+    XK_Greek_alphaaccent*: TKeySym = 0x000007B1
+    XK_Greek_epsilonaccent*: TKeySym = 0x000007B2
+    XK_Greek_etaaccent*: TKeySym = 0x000007B3
+    XK_Greek_iotaaccent*: TKeySym = 0x000007B4
+    XK_Greek_iotadieresis*: TKeySym = 0x000007B5
+    XK_Greek_iotaaccentdieresis*: TKeySym = 0x000007B6
+    XK_Greek_omicronaccent*: TKeySym = 0x000007B7
+    XK_Greek_upsilonaccent*: TKeySym = 0x000007B8
+    XK_Greek_upsilondieresis*: TKeySym = 0x000007B9
+    XK_Greek_upsilonaccentdieresis*: TKeySym = 0x000007BA
+    XK_Greek_omegaaccent*: TKeySym = 0x000007BB
+    XKc_Greek_ALPHA*: TKeySym = 0x000007C1
+    XKc_Greek_BETA*: TKeySym = 0x000007C2
+    XKc_Greek_GAMMA*: TKeySym = 0x000007C3
+    XKc_Greek_DELTA*: TKeySym = 0x000007C4
+    XKc_Greek_EPSILON*: TKeySym = 0x000007C5
+    XKc_Greek_ZETA*: TKeySym = 0x000007C6
+    XKc_Greek_ETA*: TKeySym = 0x000007C7
+    XKc_Greek_THETA*: TKeySym = 0x000007C8
+    XKc_Greek_IOTA*: TKeySym = 0x000007C9
+    XKc_Greek_KAPPA*: TKeySym = 0x000007CA
+    XKc_Greek_LAMDA*: TKeySym = 0x000007CB
+    XKc_Greek_LAMBDA*: TKeySym = 0x000007CB
+    XKc_Greek_MU*: TKeySym = 0x000007CC
+    XKc_Greek_NU*: TKeySym = 0x000007CD
+    XKc_Greek_XI*: TKeySym = 0x000007CE
+    XKc_Greek_OMICRON*: TKeySym = 0x000007CF
+    XKc_Greek_PI*: TKeySym = 0x000007D0
+    XKc_Greek_RHO*: TKeySym = 0x000007D1
+    XKc_Greek_SIGMA*: TKeySym = 0x000007D2
+    XKc_Greek_TAU*: TKeySym = 0x000007D4
+    XKc_Greek_UPSILON*: TKeySym = 0x000007D5
+    XKc_Greek_PHI*: TKeySym = 0x000007D6
+    XKc_Greek_CHI*: TKeySym = 0x000007D7
+    XKc_Greek_PSI*: TKeySym = 0x000007D8
+    XKc_Greek_OMEGA*: TKeySym = 0x000007D9
+    XK_Greek_alpha*: TKeySym = 0x000007E1
+    XK_Greek_beta*: TKeySym = 0x000007E2
+    XK_Greek_gamma*: TKeySym = 0x000007E3
+    XK_Greek_delta*: TKeySym = 0x000007E4
+    XK_Greek_epsilon*: TKeySym = 0x000007E5
+    XK_Greek_zeta*: TKeySym = 0x000007E6
+    XK_Greek_eta*: TKeySym = 0x000007E7
+    XK_Greek_theta*: TKeySym = 0x000007E8
+    XK_Greek_iota*: TKeySym = 0x000007E9
+    XK_Greek_kappa*: TKeySym = 0x000007EA
+    XK_Greek_lamda*: TKeySym = 0x000007EB
+    XK_Greek_lambda*: TKeySym = 0x000007EB
+    XK_Greek_mu*: TKeySym = 0x000007EC
+    XK_Greek_nu*: TKeySym = 0x000007ED
+    XK_Greek_xi*: TKeySym = 0x000007EE
+    XK_Greek_omicron*: TKeySym = 0x000007EF
+    XK_Greek_pi*: TKeySym = 0x000007F0
+    XK_Greek_rho*: TKeySym = 0x000007F1
+    XK_Greek_sigma*: TKeySym = 0x000007F2
+    XK_Greek_finalsmallsigma*: TKeySym = 0x000007F3
+    XK_Greek_tau*: TKeySym = 0x000007F4
+    XK_Greek_upsilon*: TKeySym = 0x000007F5
+    XK_Greek_phi*: TKeySym = 0x000007F6
+    XK_Greek_chi*: TKeySym = 0x000007F7
+    XK_Greek_psi*: TKeySym = 0x000007F8
+    XK_Greek_omega*: TKeySym = 0x000007F9
+    XK_Greek_switch*: TKeySym = 0x0000FF7E # Alias for mode_switch 
 # XK_GREEK 
 #*
 # * Technical
@@ -1150,55 +1151,55 @@ when defined(XK_GREEK) or true:
 
 when defined(XK_TECHNICAL) or true: 
   const
-    XK_leftradical* = 0x000008A1
-    XK_topleftradical* = 0x000008A2
-    XK_horizconnector* = 0x000008A3
-    XK_topintegral* = 0x000008A4
-    XK_botintegral* = 0x000008A5
-    XK_vertconnector* = 0x000008A6
-    XK_topleftsqbracket* = 0x000008A7
-    XK_botleftsqbracket* = 0x000008A8
-    XK_toprightsqbracket* = 0x000008A9
-    XK_botrightsqbracket* = 0x000008AA
-    XK_topleftparens* = 0x000008AB
-    XK_botleftparens* = 0x000008AC
-    XK_toprightparens* = 0x000008AD
-    XK_botrightparens* = 0x000008AE
-    XK_leftmiddlecurlybrace* = 0x000008AF
-    XK_rightmiddlecurlybrace* = 0x000008B0
-    XK_topleftsummation* = 0x000008B1
-    XK_botleftsummation* = 0x000008B2
-    XK_topvertsummationconnector* = 0x000008B3
-    XK_botvertsummationconnector* = 0x000008B4
-    XK_toprightsummation* = 0x000008B5
-    XK_botrightsummation* = 0x000008B6
-    XK_rightmiddlesummation* = 0x000008B7
-    XK_lessthanequal* = 0x000008BC
-    XK_notequal* = 0x000008BD
-    XK_greaterthanequal* = 0x000008BE
-    XK_integral* = 0x000008BF
-    XK_therefore* = 0x000008C0
-    XK_variation* = 0x000008C1
-    XK_infinity* = 0x000008C2
-    XK_nabla* = 0x000008C5
-    XK_approximate* = 0x000008C8
-    XK_similarequal* = 0x000008C9
-    XK_ifonlyif* = 0x000008CD
-    XK_implies* = 0x000008CE
-    XK_identical* = 0x000008CF
-    XK_radical* = 0x000008D6
-    XK_includedin* = 0x000008DA
-    XK_includes* = 0x000008DB
-    XK_intersection* = 0x000008DC
-    XK_union* = 0x000008DD
-    XK_logicaland* = 0x000008DE
-    XK_logicalor* = 0x000008DF
-    XK_partialderivative* = 0x000008EF
-    XK_function* = 0x000008F6
-    XK_leftarrow* = 0x000008FB
-    XK_uparrow* = 0x000008FC
-    XK_rightarrow* = 0x000008FD
-    XK_downarrow* = 0x000008FE
+    XK_leftradical*: TKeySym = 0x000008A1
+    XK_topleftradical*: TKeySym = 0x000008A2
+    XK_horizconnector*: TKeySym = 0x000008A3
+    XK_topintegral*: TKeySym = 0x000008A4
+    XK_botintegral*: TKeySym = 0x000008A5
+    XK_vertconnector*: TKeySym = 0x000008A6
+    XK_topleftsqbracket*: TKeySym = 0x000008A7
+    XK_botleftsqbracket*: TKeySym = 0x000008A8
+    XK_toprightsqbracket*: TKeySym = 0x000008A9
+    XK_botrightsqbracket*: TKeySym = 0x000008AA
+    XK_topleftparens*: TKeySym = 0x000008AB
+    XK_botleftparens*: TKeySym = 0x000008AC
+    XK_toprightparens*: TKeySym = 0x000008AD
+    XK_botrightparens*: TKeySym = 0x000008AE
+    XK_leftmiddlecurlybrace*: TKeySym = 0x000008AF
+    XK_rightmiddlecurlybrace*: TKeySym = 0x000008B0
+    XK_topleftsummation*: TKeySym = 0x000008B1
+    XK_botleftsummation*: TKeySym = 0x000008B2
+    XK_topvertsummationconnector*: TKeySym = 0x000008B3
+    XK_botvertsummationconnector*: TKeySym = 0x000008B4
+    XK_toprightsummation*: TKeySym = 0x000008B5
+    XK_botrightsummation*: TKeySym = 0x000008B6
+    XK_rightmiddlesummation*: TKeySym = 0x000008B7
+    XK_lessthanequal*: TKeySym = 0x000008BC
+    XK_notequal*: TKeySym = 0x000008BD
+    XK_greaterthanequal*: TKeySym = 0x000008BE
+    XK_integral*: TKeySym = 0x000008BF
+    XK_therefore*: TKeySym = 0x000008C0
+    XK_variation*: TKeySym = 0x000008C1
+    XK_infinity*: TKeySym = 0x000008C2
+    XK_nabla*: TKeySym = 0x000008C5
+    XK_approximate*: TKeySym = 0x000008C8
+    XK_similarequal*: TKeySym = 0x000008C9
+    XK_ifonlyif*: TKeySym = 0x000008CD
+    XK_implies*: TKeySym = 0x000008CE
+    XK_identical*: TKeySym = 0x000008CF
+    XK_radical*: TKeySym = 0x000008D6
+    XK_includedin*: TKeySym = 0x000008DA
+    XK_includes*: TKeySym = 0x000008DB
+    XK_intersection*: TKeySym = 0x000008DC
+    XK_union*: TKeySym = 0x000008DD
+    XK_logicaland*: TKeySym = 0x000008DE
+    XK_logicalor*: TKeySym = 0x000008DF
+    XK_partialderivative*: TKeySym = 0x000008EF
+    XK_function*: TKeySym = 0x000008F6
+    XK_leftarrow*: TKeySym = 0x000008FB
+    XK_uparrow*: TKeySym = 0x000008FC
+    XK_rightarrow*: TKeySym = 0x000008FD
+    XK_downarrow*: TKeySym = 0x000008FE
 # XK_TECHNICAL 
 #*
 # *  Special
@@ -1207,30 +1208,30 @@ when defined(XK_TECHNICAL) or true:
 
 when defined(XK_SPECIAL): 
   const
-    XK_blank* = 0x000009DF
-    XK_soliddiamond* = 0x000009E0
-    XK_checkerboard* = 0x000009E1
-    XK_ht* = 0x000009E2
-    XK_ff* = 0x000009E3
-    XK_cr* = 0x000009E4
-    XK_lf* = 0x000009E5
-    XK_nl* = 0x000009E8
-    XK_vt* = 0x000009E9
-    XK_lowrightcorner* = 0x000009EA
-    XK_uprightcorner* = 0x000009EB
-    XK_upleftcorner* = 0x000009EC
-    XK_lowleftcorner* = 0x000009ED
-    XK_crossinglines* = 0x000009EE
-    XK_horizlinescan1* = 0x000009EF
-    XK_horizlinescan3* = 0x000009F0
-    XK_horizlinescan5* = 0x000009F1
-    XK_horizlinescan7* = 0x000009F2
-    XK_horizlinescan9* = 0x000009F3
-    XK_leftt* = 0x000009F4
-    XK_rightt* = 0x000009F5
-    XK_bott* = 0x000009F6
-    XK_topt* = 0x000009F7
-    XK_vertbar* = 0x000009F8
+    XK_blank*: TKeySym = 0x000009DF
+    XK_soliddiamond*: TKeySym = 0x000009E0
+    XK_checkerboard*: TKeySym = 0x000009E1
+    XK_ht*: TKeySym = 0x000009E2
+    XK_ff*: TKeySym = 0x000009E3
+    XK_cr*: TKeySym = 0x000009E4
+    XK_lf*: TKeySym = 0x000009E5
+    XK_nl*: TKeySym = 0x000009E8
+    XK_vt*: TKeySym = 0x000009E9
+    XK_lowrightcorner*: TKeySym = 0x000009EA
+    XK_uprightcorner*: TKeySym = 0x000009EB
+    XK_upleftcorner*: TKeySym = 0x000009EC
+    XK_lowleftcorner*: TKeySym = 0x000009ED
+    XK_crossinglines*: TKeySym = 0x000009EE
+    XK_horizlinescan1*: TKeySym = 0x000009EF
+    XK_horizlinescan3*: TKeySym = 0x000009F0
+    XK_horizlinescan5*: TKeySym = 0x000009F1
+    XK_horizlinescan7*: TKeySym = 0x000009F2
+    XK_horizlinescan9*: TKeySym = 0x000009F3
+    XK_leftt*: TKeySym = 0x000009F4
+    XK_rightt*: TKeySym = 0x000009F5
+    XK_bott*: TKeySym = 0x000009F6
+    XK_topt*: TKeySym = 0x000009F7
+    XK_vertbar*: TKeySym = 0x000009F8
 # XK_SPECIAL 
 #*
 # *  Publishing
@@ -1239,89 +1240,89 @@ when defined(XK_SPECIAL):
 
 when defined(XK_PUBLISHING) or true: 
   const
-    XK_emspace* = 0x00000AA1
-    XK_enspace* = 0x00000AA2
-    XK_em3space* = 0x00000AA3
-    XK_em4space* = 0x00000AA4
-    XK_digitspace* = 0x00000AA5
-    XK_punctspace* = 0x00000AA6
-    XK_thinspace* = 0x00000AA7
-    XK_hairspace* = 0x00000AA8
-    XK_emdash* = 0x00000AA9
-    XK_endash* = 0x00000AAA
-    XK_signifblank* = 0x00000AAC
-    XK_ellipsis* = 0x00000AAE
-    XK_doubbaselinedot* = 0x00000AAF
-    XK_onethird* = 0x00000AB0
-    XK_twothirds* = 0x00000AB1
-    XK_onefifth* = 0x00000AB2
-    XK_twofifths* = 0x00000AB3
-    XK_threefifths* = 0x00000AB4
-    XK_fourfifths* = 0x00000AB5
-    XK_onesixth* = 0x00000AB6
-    XK_fivesixths* = 0x00000AB7
-    XK_careof* = 0x00000AB8
-    XK_figdash* = 0x00000ABB
-    XK_leftanglebracket* = 0x00000ABC
-    XK_decimalpoint* = 0x00000ABD
-    XK_rightanglebracket* = 0x00000ABE
-    XK_marker* = 0x00000ABF
-    XK_oneeighth* = 0x00000AC3
-    XK_threeeighths* = 0x00000AC4
-    XK_fiveeighths* = 0x00000AC5
-    XK_seveneighths* = 0x00000AC6
-    XK_trademark* = 0x00000AC9
-    XK_signaturemark* = 0x00000ACA
-    XK_trademarkincircle* = 0x00000ACB
-    XK_leftopentriangle* = 0x00000ACC
-    XK_rightopentriangle* = 0x00000ACD
-    XK_emopencircle* = 0x00000ACE
-    XK_emopenrectangle* = 0x00000ACF
-    XK_leftsinglequotemark* = 0x00000AD0
-    XK_rightsinglequotemark* = 0x00000AD1
-    XK_leftdoublequotemark* = 0x00000AD2
-    XK_rightdoublequotemark* = 0x00000AD3
-    XK_prescription* = 0x00000AD4
-    XK_minutes* = 0x00000AD6
-    XK_seconds* = 0x00000AD7
-    XK_latincross* = 0x00000AD9
-    XK_hexagram* = 0x00000ADA
-    XK_filledrectbullet* = 0x00000ADB
-    XK_filledlefttribullet* = 0x00000ADC
-    XK_filledrighttribullet* = 0x00000ADD
-    XK_emfilledcircle* = 0x00000ADE
-    XK_emfilledrect* = 0x00000ADF
-    XK_enopencircbullet* = 0x00000AE0
-    XK_enopensquarebullet* = 0x00000AE1
-    XK_openrectbullet* = 0x00000AE2
-    XK_opentribulletup* = 0x00000AE3
-    XK_opentribulletdown* = 0x00000AE4
-    XK_openstar* = 0x00000AE5
-    XK_enfilledcircbullet* = 0x00000AE6
-    XK_enfilledsqbullet* = 0x00000AE7
-    XK_filledtribulletup* = 0x00000AE8
-    XK_filledtribulletdown* = 0x00000AE9
-    XK_leftpointer* = 0x00000AEA
-    XK_rightpointer* = 0x00000AEB
-    XK_club* = 0x00000AEC
-    XK_diamond* = 0x00000AED
-    XK_heart* = 0x00000AEE
-    XK_maltesecross* = 0x00000AF0
-    XK_dagger* = 0x00000AF1
-    XK_doubledagger* = 0x00000AF2
-    XK_checkmark* = 0x00000AF3
-    XK_ballotcross* = 0x00000AF4
-    XK_musicalsharp* = 0x00000AF5
-    XK_musicalflat* = 0x00000AF6
-    XK_malesymbol* = 0x00000AF7
-    XK_femalesymbol* = 0x00000AF8
-    XK_telephone* = 0x00000AF9
-    XK_telephonerecorder* = 0x00000AFA
-    XK_phonographcopyright* = 0x00000AFB
-    XK_caret* = 0x00000AFC
-    XK_singlelowquotemark* = 0x00000AFD
-    XK_doublelowquotemark* = 0x00000AFE
-    XK_cursor* = 0x00000AFF
+    XK_emspace*: TKeySym = 0x00000AA1
+    XK_enspace*: TKeySym = 0x00000AA2
+    XK_em3space*: TKeySym = 0x00000AA3
+    XK_em4space*: TKeySym = 0x00000AA4
+    XK_digitspace*: TKeySym = 0x00000AA5
+    XK_punctspace*: TKeySym = 0x00000AA6
+    XK_thinspace*: TKeySym = 0x00000AA7
+    XK_hairspace*: TKeySym = 0x00000AA8
+    XK_emdash*: TKeySym = 0x00000AA9
+    XK_endash*: TKeySym = 0x00000AAA
+    XK_signifblank*: TKeySym = 0x00000AAC
+    XK_ellipsis*: TKeySym = 0x00000AAE
+    XK_doubbaselinedot*: TKeySym = 0x00000AAF
+    XK_onethird*: TKeySym = 0x00000AB0
+    XK_twothirds*: TKeySym = 0x00000AB1
+    XK_onefifth*: TKeySym = 0x00000AB2
+    XK_twofifths*: TKeySym = 0x00000AB3
+    XK_threefifths*: TKeySym = 0x00000AB4
+    XK_fourfifths*: TKeySym = 0x00000AB5
+    XK_onesixth*: TKeySym = 0x00000AB6
+    XK_fivesixths*: TKeySym = 0x00000AB7
+    XK_careof*: TKeySym = 0x00000AB8
+    XK_figdash*: TKeySym = 0x00000ABB
+    XK_leftanglebracket*: TKeySym = 0x00000ABC
+    XK_decimalpoint*: TKeySym = 0x00000ABD
+    XK_rightanglebracket*: TKeySym = 0x00000ABE
+    XK_marker*: TKeySym = 0x00000ABF
+    XK_oneeighth*: TKeySym = 0x00000AC3
+    XK_threeeighths*: TKeySym = 0x00000AC4
+    XK_fiveeighths*: TKeySym = 0x00000AC5
+    XK_seveneighths*: TKeySym = 0x00000AC6
+    XK_trademark*: TKeySym = 0x00000AC9
+    XK_signaturemark*: TKeySym = 0x00000ACA
+    XK_trademarkincircle*: TKeySym = 0x00000ACB
+    XK_leftopentriangle*: TKeySym = 0x00000ACC
+    XK_rightopentriangle*: TKeySym = 0x00000ACD
+    XK_emopencircle*: TKeySym = 0x00000ACE
+    XK_emopenrectangle*: TKeySym = 0x00000ACF
+    XK_leftsinglequotemark*: TKeySym = 0x00000AD0
+    XK_rightsinglequotemark*: TKeySym = 0x00000AD1
+    XK_leftdoublequotemark*: TKeySym = 0x00000AD2
+    XK_rightdoublequotemark*: TKeySym = 0x00000AD3
+    XK_prescription*: TKeySym = 0x00000AD4
+    XK_minutes*: TKeySym = 0x00000AD6
+    XK_seconds*: TKeySym = 0x00000AD7
+    XK_latincross*: TKeySym = 0x00000AD9
+    XK_hexagram*: TKeySym = 0x00000ADA
+    XK_filledrectbullet*: TKeySym = 0x00000ADB
+    XK_filledlefttribullet*: TKeySym = 0x00000ADC
+    XK_filledrighttribullet*: TKeySym = 0x00000ADD
+    XK_emfilledcircle*: TKeySym = 0x00000ADE
+    XK_emfilledrect*: TKeySym = 0x00000ADF
+    XK_enopencircbullet*: TKeySym = 0x00000AE0
+    XK_enopensquarebullet*: TKeySym = 0x00000AE1
+    XK_openrectbullet*: TKeySym = 0x00000AE2
+    XK_opentribulletup*: TKeySym = 0x00000AE3
+    XK_opentribulletdown*: TKeySym = 0x00000AE4
+    XK_openstar*: TKeySym = 0x00000AE5
+    XK_enfilledcircbullet*: TKeySym = 0x00000AE6
+    XK_enfilledsqbullet*: TKeySym = 0x00000AE7
+    XK_filledtribulletup*: TKeySym = 0x00000AE8
+    XK_filledtribulletdown*: TKeySym = 0x00000AE9
+    XK_leftpointer*: TKeySym = 0x00000AEA
+    XK_rightpointer*: TKeySym = 0x00000AEB
+    XK_club*: TKeySym = 0x00000AEC
+    XK_diamond*: TKeySym = 0x00000AED
+    XK_heart*: TKeySym = 0x00000AEE
+    XK_maltesecross*: TKeySym = 0x00000AF0
+    XK_dagger*: TKeySym = 0x00000AF1
+    XK_doubledagger*: TKeySym = 0x00000AF2
+    XK_checkmark*: TKeySym = 0x00000AF3
+    XK_ballotcross*: TKeySym = 0x00000AF4
+    XK_musicalsharp*: TKeySym = 0x00000AF5
+    XK_musicalflat*: TKeySym = 0x00000AF6
+    XK_malesymbol*: TKeySym = 0x00000AF7
+    XK_femalesymbol*: TKeySym = 0x00000AF8
+    XK_telephone*: TKeySym = 0x00000AF9
+    XK_telephonerecorder*: TKeySym = 0x00000AFA
+    XK_phonographcopyright*: TKeySym = 0x00000AFB
+    XK_caret*: TKeySym = 0x00000AFC
+    XK_singlelowquotemark*: TKeySym = 0x00000AFD
+    XK_doublelowquotemark*: TKeySym = 0x00000AFE
+    XK_cursor*: TKeySym = 0x00000AFF
 # XK_PUBLISHING 
 #*
 # *  APL
@@ -1330,25 +1331,25 @@ when defined(XK_PUBLISHING) or true:
 
 when defined(XK_APL) or true: 
   const
-    XK_leftcaret* = 0x00000BA3
-    XK_rightcaret* = 0x00000BA6
-    XK_downcaret* = 0x00000BA8
-    XK_upcaret* = 0x00000BA9
-    XK_overbar* = 0x00000BC0
-    XK_downtack* = 0x00000BC2
-    XK_upshoe* = 0x00000BC3
-    XK_downstile* = 0x00000BC4
-    XK_underbar* = 0x00000BC6
-    XK_jot* = 0x00000BCA
-    XK_quad* = 0x00000BCC
-    XK_uptack* = 0x00000BCE
-    XK_circle* = 0x00000BCF
-    XK_upstile* = 0x00000BD3
-    XK_downshoe* = 0x00000BD6
-    XK_rightshoe* = 0x00000BD8
-    XK_leftshoe* = 0x00000BDA
-    XK_lefttack* = 0x00000BDC
-    XK_righttack* = 0x00000BFC
+    XK_leftcaret*: TKeySym = 0x00000BA3
+    XK_rightcaret*: TKeySym = 0x00000BA6
+    XK_downcaret*: TKeySym = 0x00000BA8
+    XK_upcaret*: TKeySym = 0x00000BA9
+    XK_overbar*: TKeySym = 0x00000BC0
+    XK_downtack*: TKeySym = 0x00000BC2
+    XK_upshoe*: TKeySym = 0x00000BC3
+    XK_downstile*: TKeySym = 0x00000BC4
+    XK_underbar*: TKeySym = 0x00000BC6
+    XK_jot*: TKeySym = 0x00000BCA
+    XK_quad*: TKeySym = 0x00000BCC
+    XK_uptack*: TKeySym = 0x00000BCE
+    XK_circle*: TKeySym = 0x00000BCF
+    XK_upstile*: TKeySym = 0x00000BD3
+    XK_downshoe*: TKeySym = 0x00000BD6
+    XK_rightshoe*: TKeySym = 0x00000BD8
+    XK_leftshoe*: TKeySym = 0x00000BDA
+    XK_lefttack*: TKeySym = 0x00000BDC
+    XK_righttack*: TKeySym = 0x00000BFC
 # XK_APL 
 #*
 # * Hebrew
@@ -1357,46 +1358,46 @@ when defined(XK_APL) or true:
 
 when defined(XK_HEBREW) or true: 
   const
-    XK_hebrew_doublelowline* = 0x00000CDF
-    XK_hebrew_aleph* = 0x00000CE0
-    XK_hebrew_bet* = 0x00000CE1
-    XK_hebrew_beth* = 0x00000CE1 # deprecated 
-    XK_hebrew_gimel* = 0x00000CE2
-    XK_hebrew_gimmel* = 0x00000CE2 # deprecated 
-    XK_hebrew_dalet* = 0x00000CE3
-    XK_hebrew_daleth* = 0x00000CE3 # deprecated 
-    XK_hebrew_he* = 0x00000CE4
-    XK_hebrew_waw* = 0x00000CE5
-    XK_hebrew_zain* = 0x00000CE6
-    XK_hebrew_zayin* = 0x00000CE6 # deprecated 
-    XK_hebrew_chet* = 0x00000CE7
-    XK_hebrew_het* = 0x00000CE7 # deprecated 
-    XK_hebrew_tet* = 0x00000CE8
-    XK_hebrew_teth* = 0x00000CE8 # deprecated 
-    XK_hebrew_yod* = 0x00000CE9
-    XK_hebrew_finalkaph* = 0x00000CEA
-    XK_hebrew_kaph* = 0x00000CEB
-    XK_hebrew_lamed* = 0x00000CEC
-    XK_hebrew_finalmem* = 0x00000CED
-    XK_hebrew_mem* = 0x00000CEE
-    XK_hebrew_finalnun* = 0x00000CEF
-    XK_hebrew_nun* = 0x00000CF0
-    XK_hebrew_samech* = 0x00000CF1
-    XK_hebrew_samekh* = 0x00000CF1 # deprecated 
-    XK_hebrew_ayin* = 0x00000CF2
-    XK_hebrew_finalpe* = 0x00000CF3
-    XK_hebrew_pe* = 0x00000CF4
-    XK_hebrew_finalzade* = 0x00000CF5
-    XK_hebrew_finalzadi* = 0x00000CF5 # deprecated 
-    XK_hebrew_zade* = 0x00000CF6
-    XK_hebrew_zadi* = 0x00000CF6 # deprecated 
-    XK_hebrew_qoph* = 0x00000CF7
-    XK_hebrew_kuf* = 0x00000CF7 # deprecated 
-    XK_hebrew_resh* = 0x00000CF8
-    XK_hebrew_shin* = 0x00000CF9
-    XK_hebrew_taw* = 0x00000CFA
-    XK_hebrew_taf* = 0x00000CFA # deprecated 
-    XK_Hebrew_switch* = 0x0000FF7E # Alias for mode_switch 
+    XK_hebrew_doublelowline*: TKeySym = 0x00000CDF
+    XK_hebrew_aleph*: TKeySym = 0x00000CE0
+    XK_hebrew_bet*: TKeySym = 0x00000CE1
+    XK_hebrew_beth*: TKeySym = 0x00000CE1 # deprecated 
+    XK_hebrew_gimel*: TKeySym = 0x00000CE2
+    XK_hebrew_gimmel*: TKeySym = 0x00000CE2 # deprecated 
+    XK_hebrew_dalet*: TKeySym = 0x00000CE3
+    XK_hebrew_daleth*: TKeySym = 0x00000CE3 # deprecated 
+    XK_hebrew_he*: TKeySym = 0x00000CE4
+    XK_hebrew_waw*: TKeySym = 0x00000CE5
+    XK_hebrew_zain*: TKeySym = 0x00000CE6
+    XK_hebrew_zayin*: TKeySym = 0x00000CE6 # deprecated 
+    XK_hebrew_chet*: TKeySym = 0x00000CE7
+    XK_hebrew_het*: TKeySym = 0x00000CE7 # deprecated 
+    XK_hebrew_tet*: TKeySym = 0x00000CE8
+    XK_hebrew_teth*: TKeySym = 0x00000CE8 # deprecated 
+    XK_hebrew_yod*: TKeySym = 0x00000CE9
+    XK_hebrew_finalkaph*: TKeySym = 0x00000CEA
+    XK_hebrew_kaph*: TKeySym = 0x00000CEB
+    XK_hebrew_lamed*: TKeySym = 0x00000CEC
+    XK_hebrew_finalmem*: TKeySym = 0x00000CED
+    XK_hebrew_mem*: TKeySym = 0x00000CEE
+    XK_hebrew_finalnun*: TKeySym = 0x00000CEF
+    XK_hebrew_nun*: TKeySym = 0x00000CF0
+    XK_hebrew_samech*: TKeySym = 0x00000CF1
+    XK_hebrew_samekh*: TKeySym = 0x00000CF1 # deprecated 
+    XK_hebrew_ayin*: TKeySym = 0x00000CF2
+    XK_hebrew_finalpe*: TKeySym = 0x00000CF3
+    XK_hebrew_pe*: TKeySym = 0x00000CF4
+    XK_hebrew_finalzade*: TKeySym = 0x00000CF5
+    XK_hebrew_finalzadi*: TKeySym = 0x00000CF5 # deprecated 
+    XK_hebrew_zade*: TKeySym = 0x00000CF6
+    XK_hebrew_zadi*: TKeySym = 0x00000CF6 # deprecated 
+    XK_hebrew_qoph*: TKeySym = 0x00000CF7
+    XK_hebrew_kuf*: TKeySym = 0x00000CF7 # deprecated 
+    XK_hebrew_resh*: TKeySym = 0x00000CF8
+    XK_hebrew_shin*: TKeySym = 0x00000CF9
+    XK_hebrew_taw*: TKeySym = 0x00000CFA
+    XK_hebrew_taf*: TKeySym = 0x00000CFA # deprecated 
+    XK_Hebrew_switch*: TKeySym = 0x0000FF7E # Alias for mode_switch 
 # XK_HEBREW 
 #*
 # * Thai
@@ -1405,90 +1406,90 @@ when defined(XK_HEBREW) or true:
 
 when defined(XK_THAI) or true: 
   const
-    XK_Thai_kokai* = 0x00000DA1
-    XK_Thai_khokhai* = 0x00000DA2
-    XK_Thai_khokhuat* = 0x00000DA3
-    XK_Thai_khokhwai* = 0x00000DA4
-    XK_Thai_khokhon* = 0x00000DA5
-    XK_Thai_khorakhang* = 0x00000DA6
-    XK_Thai_ngongu* = 0x00000DA7
-    XK_Thai_chochan* = 0x00000DA8
-    XK_Thai_choching* = 0x00000DA9
-    XK_Thai_chochang* = 0x00000DAA
-    XK_Thai_soso* = 0x00000DAB
-    XK_Thai_chochoe* = 0x00000DAC
-    XK_Thai_yoying* = 0x00000DAD
-    XK_Thai_dochada* = 0x00000DAE
-    XK_Thai_topatak* = 0x00000DAF
-    XK_Thai_thothan* = 0x00000DB0
-    XK_Thai_thonangmontho* = 0x00000DB1
-    XK_Thai_thophuthao* = 0x00000DB2
-    XK_Thai_nonen* = 0x00000DB3
-    XK_Thai_dodek* = 0x00000DB4
-    XK_Thai_totao* = 0x00000DB5
-    XK_Thai_thothung* = 0x00000DB6
-    XK_Thai_thothahan* = 0x00000DB7
-    XK_Thai_thothong* = 0x00000DB8
-    XK_Thai_nonu* = 0x00000DB9
-    XK_Thai_bobaimai* = 0x00000DBA
-    XK_Thai_popla* = 0x00000DBB
-    XK_Thai_phophung* = 0x00000DBC
-    XK_Thai_fofa* = 0x00000DBD
-    XK_Thai_phophan* = 0x00000DBE
-    XK_Thai_fofan* = 0x00000DBF
-    XK_Thai_phosamphao* = 0x00000DC0
-    XK_Thai_moma* = 0x00000DC1
-    XK_Thai_yoyak* = 0x00000DC2
-    XK_Thai_rorua* = 0x00000DC3
-    XK_Thai_ru* = 0x00000DC4
-    XK_Thai_loling* = 0x00000DC5
-    XK_Thai_lu* = 0x00000DC6
-    XK_Thai_wowaen* = 0x00000DC7
-    XK_Thai_sosala* = 0x00000DC8
-    XK_Thai_sorusi* = 0x00000DC9
-    XK_Thai_sosua* = 0x00000DCA
-    XK_Thai_hohip* = 0x00000DCB
-    XK_Thai_lochula* = 0x00000DCC
-    XK_Thai_oang* = 0x00000DCD
-    XK_Thai_honokhuk* = 0x00000DCE
-    XK_Thai_paiyannoi* = 0x00000DCF
-    XK_Thai_saraa* = 0x00000DD0
-    XK_Thai_maihanakat* = 0x00000DD1
-    XK_Thai_saraaa* = 0x00000DD2
-    XK_Thai_saraam* = 0x00000DD3
-    XK_Thai_sarai* = 0x00000DD4
-    XK_Thai_saraii* = 0x00000DD5
-    XK_Thai_saraue* = 0x00000DD6
-    XK_Thai_sarauee* = 0x00000DD7
-    XK_Thai_sarau* = 0x00000DD8
-    XK_Thai_sarauu* = 0x00000DD9
-    XK_Thai_phinthu* = 0x00000DDA
-    XK_Thai_maihanakat_maitho* = 0x00000DDE
-    XK_Thai_baht* = 0x00000DDF
-    XK_Thai_sarae* = 0x00000DE0
-    XK_Thai_saraae* = 0x00000DE1
-    XK_Thai_sarao* = 0x00000DE2
-    XK_Thai_saraaimaimuan* = 0x00000DE3
-    XK_Thai_saraaimaimalai* = 0x00000DE4
-    XK_Thai_lakkhangyao* = 0x00000DE5
-    XK_Thai_maiyamok* = 0x00000DE6
-    XK_Thai_maitaikhu* = 0x00000DE7
-    XK_Thai_maiek* = 0x00000DE8
-    XK_Thai_maitho* = 0x00000DE9
-    XK_Thai_maitri* = 0x00000DEA
-    XK_Thai_maichattawa* = 0x00000DEB
-    XK_Thai_thanthakhat* = 0x00000DEC
-    XK_Thai_nikhahit* = 0x00000DED
-    XK_Thai_leksun* = 0x00000DF0
-    XK_Thai_leknung* = 0x00000DF1
-    XK_Thai_leksong* = 0x00000DF2
-    XK_Thai_leksam* = 0x00000DF3
-    XK_Thai_leksi* = 0x00000DF4
-    XK_Thai_lekha* = 0x00000DF5
-    XK_Thai_lekhok* = 0x00000DF6
-    XK_Thai_lekchet* = 0x00000DF7
-    XK_Thai_lekpaet* = 0x00000DF8
-    XK_Thai_lekkao* = 0x00000DF9
+    XK_Thai_kokai*: TKeySym = 0x00000DA1
+    XK_Thai_khokhai*: TKeySym = 0x00000DA2
+    XK_Thai_khokhuat*: TKeySym = 0x00000DA3
+    XK_Thai_khokhwai*: TKeySym = 0x00000DA4
+    XK_Thai_khokhon*: TKeySym = 0x00000DA5
+    XK_Thai_khorakhang*: TKeySym = 0x00000DA6
+    XK_Thai_ngongu*: TKeySym = 0x00000DA7
+    XK_Thai_chochan*: TKeySym = 0x00000DA8
+    XK_Thai_choching*: TKeySym = 0x00000DA9
+    XK_Thai_chochang*: TKeySym = 0x00000DAA
+    XK_Thai_soso*: TKeySym = 0x00000DAB
+    XK_Thai_chochoe*: TKeySym = 0x00000DAC
+    XK_Thai_yoying*: TKeySym = 0x00000DAD
+    XK_Thai_dochada*: TKeySym = 0x00000DAE
+    XK_Thai_topatak*: TKeySym = 0x00000DAF
+    XK_Thai_thothan*: TKeySym = 0x00000DB0
+    XK_Thai_thonangmontho*: TKeySym = 0x00000DB1
+    XK_Thai_thophuthao*: TKeySym = 0x00000DB2
+    XK_Thai_nonen*: TKeySym = 0x00000DB3
+    XK_Thai_dodek*: TKeySym = 0x00000DB4
+    XK_Thai_totao*: TKeySym = 0x00000DB5
+    XK_Thai_thothung*: TKeySym = 0x00000DB6
+    XK_Thai_thothahan*: TKeySym = 0x00000DB7
+    XK_Thai_thothong*: TKeySym = 0x00000DB8
+    XK_Thai_nonu*: TKeySym = 0x00000DB9
+    XK_Thai_bobaimai*: TKeySym = 0x00000DBA
+    XK_Thai_popla*: TKeySym = 0x00000DBB
+    XK_Thai_phophung*: TKeySym = 0x00000DBC
+    XK_Thai_fofa*: TKeySym = 0x00000DBD
+    XK_Thai_phophan*: TKeySym = 0x00000DBE
+    XK_Thai_fofan*: TKeySym = 0x00000DBF
+    XK_Thai_phosamphao*: TKeySym = 0x00000DC0
+    XK_Thai_moma*: TKeySym = 0x00000DC1
+    XK_Thai_yoyak*: TKeySym = 0x00000DC2
+    XK_Thai_rorua*: TKeySym = 0x00000DC3
+    XK_Thai_ru*: TKeySym = 0x00000DC4
+    XK_Thai_loling*: TKeySym = 0x00000DC5
+    XK_Thai_lu*: TKeySym = 0x00000DC6
+    XK_Thai_wowaen*: TKeySym = 0x00000DC7
+    XK_Thai_sosala*: TKeySym = 0x00000DC8
+    XK_Thai_sorusi*: TKeySym = 0x00000DC9
+    XK_Thai_sosua*: TKeySym = 0x00000DCA
+    XK_Thai_hohip*: TKeySym = 0x00000DCB
+    XK_Thai_lochula*: TKeySym = 0x00000DCC
+    XK_Thai_oang*: TKeySym = 0x00000DCD
+    XK_Thai_honokhuk*: TKeySym = 0x00000DCE
+    XK_Thai_paiyannoi*: TKeySym = 0x00000DCF
+    XK_Thai_saraa*: TKeySym = 0x00000DD0
+    XK_Thai_maihanakat*: TKeySym = 0x00000DD1
+    XK_Thai_saraaa*: TKeySym = 0x00000DD2
+    XK_Thai_saraam*: TKeySym = 0x00000DD3
+    XK_Thai_sarai*: TKeySym = 0x00000DD4
+    XK_Thai_saraii*: TKeySym = 0x00000DD5
+    XK_Thai_saraue*: TKeySym = 0x00000DD6
+    XK_Thai_sarauee*: TKeySym = 0x00000DD7
+    XK_Thai_sarau*: TKeySym = 0x00000DD8
+    XK_Thai_sarauu*: TKeySym = 0x00000DD9
+    XK_Thai_phinthu*: TKeySym = 0x00000DDA
+    XK_Thai_maihanakat_maitho*: TKeySym = 0x00000DDE
+    XK_Thai_baht*: TKeySym = 0x00000DDF
+    XK_Thai_sarae*: TKeySym = 0x00000DE0
+    XK_Thai_saraae*: TKeySym = 0x00000DE1
+    XK_Thai_sarao*: TKeySym = 0x00000DE2
+    XK_Thai_saraaimaimuan*: TKeySym = 0x00000DE3
+    XK_Thai_saraaimaimalai*: TKeySym = 0x00000DE4
+    XK_Thai_lakkhangyao*: TKeySym = 0x00000DE5
+    XK_Thai_maiyamok*: TKeySym = 0x00000DE6
+    XK_Thai_maitaikhu*: TKeySym = 0x00000DE7
+    XK_Thai_maiek*: TKeySym = 0x00000DE8
+    XK_Thai_maitho*: TKeySym = 0x00000DE9
+    XK_Thai_maitri*: TKeySym = 0x00000DEA
+    XK_Thai_maichattawa*: TKeySym = 0x00000DEB
+    XK_Thai_thanthakhat*: TKeySym = 0x00000DEC
+    XK_Thai_nikhahit*: TKeySym = 0x00000DED
+    XK_Thai_leksun*: TKeySym = 0x00000DF0
+    XK_Thai_leknung*: TKeySym = 0x00000DF1
+    XK_Thai_leksong*: TKeySym = 0x00000DF2
+    XK_Thai_leksam*: TKeySym = 0x00000DF3
+    XK_Thai_leksi*: TKeySym = 0x00000DF4
+    XK_Thai_lekha*: TKeySym = 0x00000DF5
+    XK_Thai_lekhok*: TKeySym = 0x00000DF6
+    XK_Thai_lekchet*: TKeySym = 0x00000DF7
+    XK_Thai_lekpaet*: TKeySym = 0x00000DF8
+    XK_Thai_lekkao*: TKeySym = 0x00000DF9
 # XK_THAI 
 #*
 # *   Korean
@@ -1497,114 +1498,114 @@ when defined(XK_THAI) or true:
 
 when defined(XK_KOREAN) or true: 
   const
-    XK_Hangul* = 0x0000FF31     # Hangul start/stop(toggle) 
-    XK_Hangul_Start* = 0x0000FF32 # Hangul start 
-    XK_Hangul_End* = 0x0000FF33 # Hangul end, English start 
-    XK_Hangul_Hanja* = 0x0000FF34 # Start Hangul->Hanja Conversion 
-    XK_Hangul_Jamo* = 0x0000FF35 # Hangul Jamo mode 
-    XK_Hangul_Romaja* = 0x0000FF36 # Hangul Romaja mode 
-    XK_Hangul_Codeinput* = 0x0000FF37 # Hangul code input mode 
-    XK_Hangul_Jeonja* = 0x0000FF38 # Jeonja mode 
-    XK_Hangul_Banja* = 0x0000FF39 # Banja mode 
-    XK_Hangul_PreHanja* = 0x0000FF3A # Pre Hanja conversion 
-    XK_Hangul_PostHanja* = 0x0000FF3B # Post Hanja conversion 
-    XK_Hangul_SingleCandidate* = 0x0000FF3C # Single candidate 
-    XK_Hangul_MultipleCandidate* = 0x0000FF3D # Multiple candidate 
-    XK_Hangul_PreviousCandidate* = 0x0000FF3E # Previous candidate 
-    XK_Hangul_Special* = 0x0000FF3F # Special symbols 
-    XK_Hangul_switch* = 0x0000FF7E # Alias for mode_switch 
+    XK_Hangul*: TKeySym = 0x0000FF31     # Hangul start/stop(toggle) 
+    XK_Hangul_Start*: TKeySym = 0x0000FF32 # Hangul start 
+    XK_Hangul_End*: TKeySym = 0x0000FF33 # Hangul end, English start 
+    XK_Hangul_Hanja*: TKeySym = 0x0000FF34 # Start Hangul->Hanja Conversion 
+    XK_Hangul_Jamo*: TKeySym = 0x0000FF35 # Hangul Jamo mode 
+    XK_Hangul_Romaja*: TKeySym = 0x0000FF36 # Hangul Romaja mode 
+    XK_Hangul_Codeinput*: TKeySym = 0x0000FF37 # Hangul code input mode 
+    XK_Hangul_Jeonja*: TKeySym = 0x0000FF38 # Jeonja mode 
+    XK_Hangul_Banja*: TKeySym = 0x0000FF39 # Banja mode 
+    XK_Hangul_PreHanja*: TKeySym = 0x0000FF3A # Pre Hanja conversion 
+    XK_Hangul_PostHanja*: TKeySym = 0x0000FF3B # Post Hanja conversion 
+    XK_Hangul_SingleCandidate*: TKeySym = 0x0000FF3C # Single candidate 
+    XK_Hangul_MultipleCandidate*: TKeySym = 0x0000FF3D # Multiple candidate 
+    XK_Hangul_PreviousCandidate*: TKeySym = 0x0000FF3E # Previous candidate 
+    XK_Hangul_Special*: TKeySym = 0x0000FF3F # Special symbols 
+    XK_Hangul_switch*: TKeySym = 0x0000FF7E # Alias for mode_switch \
                                    # Hangul Consonant Characters 
-    XK_Hangul_Kiyeog* = 0x00000EA1
-    XK_Hangul_SsangKiyeog* = 0x00000EA2
-    XK_Hangul_KiyeogSios* = 0x00000EA3
-    XK_Hangul_Nieun* = 0x00000EA4
-    XK_Hangul_NieunJieuj* = 0x00000EA5
-    XK_Hangul_NieunHieuh* = 0x00000EA6
-    XK_Hangul_Dikeud* = 0x00000EA7
-    XK_Hangul_SsangDikeud* = 0x00000EA8
-    XK_Hangul_Rieul* = 0x00000EA9
-    XK_Hangul_RieulKiyeog* = 0x00000EAA
-    XK_Hangul_RieulMieum* = 0x00000EAB
-    XK_Hangul_RieulPieub* = 0x00000EAC
-    XK_Hangul_RieulSios* = 0x00000EAD
-    XK_Hangul_RieulTieut* = 0x00000EAE
-    XK_Hangul_RieulPhieuf* = 0x00000EAF
-    XK_Hangul_RieulHieuh* = 0x00000EB0
-    XK_Hangul_Mieum* = 0x00000EB1
-    XK_Hangul_Pieub* = 0x00000EB2
-    XK_Hangul_SsangPieub* = 0x00000EB3
-    XK_Hangul_PieubSios* = 0x00000EB4
-    XK_Hangul_Sios* = 0x00000EB5
-    XK_Hangul_SsangSios* = 0x00000EB6
-    XK_Hangul_Ieung* = 0x00000EB7
-    XK_Hangul_Jieuj* = 0x00000EB8
-    XK_Hangul_SsangJieuj* = 0x00000EB9
-    XK_Hangul_Cieuc* = 0x00000EBA
-    XK_Hangul_Khieuq* = 0x00000EBB
-    XK_Hangul_Tieut* = 0x00000EBC
-    XK_Hangul_Phieuf* = 0x00000EBD
-    XK_Hangul_Hieuh* = 0x00000EBE # Hangul Vowel Characters 
-    XK_Hangul_A* = 0x00000EBF
-    XK_Hangul_AE* = 0x00000EC0
-    XK_Hangul_YA* = 0x00000EC1
-    XK_Hangul_YAE* = 0x00000EC2
-    XK_Hangul_EO* = 0x00000EC3
-    XK_Hangul_E* = 0x00000EC4
-    XK_Hangul_YEO* = 0x00000EC5
-    XK_Hangul_YE* = 0x00000EC6
-    XK_Hangul_O* = 0x00000EC7
-    XK_Hangul_WA* = 0x00000EC8
-    XK_Hangul_WAE* = 0x00000EC9
-    XK_Hangul_OE* = 0x00000ECA
-    XK_Hangul_YO* = 0x00000ECB
-    XK_Hangul_U* = 0x00000ECC
-    XK_Hangul_WEO* = 0x00000ECD
-    XK_Hangul_WE* = 0x00000ECE
-    XK_Hangul_WI* = 0x00000ECF
-    XK_Hangul_YU* = 0x00000ED0
-    XK_Hangul_EU* = 0x00000ED1
-    XK_Hangul_YI* = 0x00000ED2
-    XK_Hangul_I* = 0x00000ED3   # Hangul syllable-final (JongSeong) Characters 
-    XK_Hangul_J_Kiyeog* = 0x00000ED4
-    XK_Hangul_J_SsangKiyeog* = 0x00000ED5
-    XK_Hangul_J_KiyeogSios* = 0x00000ED6
-    XK_Hangul_J_Nieun* = 0x00000ED7
-    XK_Hangul_J_NieunJieuj* = 0x00000ED8
-    XK_Hangul_J_NieunHieuh* = 0x00000ED9
-    XK_Hangul_J_Dikeud* = 0x00000EDA
-    XK_Hangul_J_Rieul* = 0x00000EDB
-    XK_Hangul_J_RieulKiyeog* = 0x00000EDC
-    XK_Hangul_J_RieulMieum* = 0x00000EDD
-    XK_Hangul_J_RieulPieub* = 0x00000EDE
-    XK_Hangul_J_RieulSios* = 0x00000EDF
-    XK_Hangul_J_RieulTieut* = 0x00000EE0
-    XK_Hangul_J_RieulPhieuf* = 0x00000EE1
-    XK_Hangul_J_RieulHieuh* = 0x00000EE2
-    XK_Hangul_J_Mieum* = 0x00000EE3
-    XK_Hangul_J_Pieub* = 0x00000EE4
-    XK_Hangul_J_PieubSios* = 0x00000EE5
-    XK_Hangul_J_Sios* = 0x00000EE6
-    XK_Hangul_J_SsangSios* = 0x00000EE7
-    XK_Hangul_J_Ieung* = 0x00000EE8
-    XK_Hangul_J_Jieuj* = 0x00000EE9
-    XK_Hangul_J_Cieuc* = 0x00000EEA
-    XK_Hangul_J_Khieuq* = 0x00000EEB
-    XK_Hangul_J_Tieut* = 0x00000EEC
-    XK_Hangul_J_Phieuf* = 0x00000EED
-    XK_Hangul_J_Hieuh* = 0x00000EEE # Ancient Hangul Consonant Characters 
-    XK_Hangul_RieulYeorinHieuh* = 0x00000EEF
-    XK_Hangul_SunkyeongeumMieum* = 0x00000EF0
-    XK_Hangul_SunkyeongeumPieub* = 0x00000EF1
-    XK_Hangul_PanSios* = 0x00000EF2
-    XK_Hangul_KkogjiDalrinIeung* = 0x00000EF3
-    XK_Hangul_SunkyeongeumPhieuf* = 0x00000EF4
-    XK_Hangul_YeorinHieuh* = 0x00000EF5 # Ancient Hangul Vowel Characters 
-    XK_Hangul_AraeA* = 0x00000EF6
-    XK_Hangul_AraeAE* = 0x00000EF7 # Ancient Hangul syllable-final (JongSeong) Characters 
-    XK_Hangul_J_PanSios* = 0x00000EF8
-    XK_Hangul_J_KkogjiDalrinIeung* = 0x00000EF9
-    XK_Hangul_J_YeorinHieuh* = 0x00000EFA # Korean currency symbol 
-    XK_Korean_Won* = 0x00000EFF
+    XK_Hangul_Kiyeog*: TKeySym = 0x00000EA1
+    XK_Hangul_SsangKiyeog*: TKeySym = 0x00000EA2
+    XK_Hangul_KiyeogSios*: TKeySym = 0x00000EA3
+    XK_Hangul_Nieun*: TKeySym = 0x00000EA4
+    XK_Hangul_NieunJieuj*: TKeySym = 0x00000EA5
+    XK_Hangul_NieunHieuh*: TKeySym = 0x00000EA6
+    XK_Hangul_Dikeud*: TKeySym = 0x00000EA7
+    XK_Hangul_SsangDikeud*: TKeySym = 0x00000EA8
+    XK_Hangul_Rieul*: TKeySym = 0x00000EA9
+    XK_Hangul_RieulKiyeog*: TKeySym = 0x00000EAA
+    XK_Hangul_RieulMieum*: TKeySym = 0x00000EAB
+    XK_Hangul_RieulPieub*: TKeySym = 0x00000EAC
+    XK_Hangul_RieulSios*: TKeySym = 0x00000EAD
+    XK_Hangul_RieulTieut*: TKeySym = 0x00000EAE
+    XK_Hangul_RieulPhieuf*: TKeySym = 0x00000EAF
+    XK_Hangul_RieulHieuh*: TKeySym = 0x00000EB0
+    XK_Hangul_Mieum*: TKeySym = 0x00000EB1
+    XK_Hangul_Pieub*: TKeySym = 0x00000EB2
+    XK_Hangul_SsangPieub*: TKeySym = 0x00000EB3
+    XK_Hangul_PieubSios*: TKeySym = 0x00000EB4
+    XK_Hangul_Sios*: TKeySym = 0x00000EB5
+    XK_Hangul_SsangSios*: TKeySym = 0x00000EB6
+    XK_Hangul_Ieung*: TKeySym = 0x00000EB7
+    XK_Hangul_Jieuj*: TKeySym = 0x00000EB8
+    XK_Hangul_SsangJieuj*: TKeySym = 0x00000EB9
+    XK_Hangul_Cieuc*: TKeySym = 0x00000EBA
+    XK_Hangul_Khieuq*: TKeySym = 0x00000EBB
+    XK_Hangul_Tieut*: TKeySym = 0x00000EBC
+    XK_Hangul_Phieuf*: TKeySym = 0x00000EBD
+    XK_Hangul_Hieuh*: TKeySym = 0x00000EBE # Hangul Vowel Characters 
+    XK_Hangul_A*: TKeySym = 0x00000EBF
+    XK_Hangul_AE*: TKeySym = 0x00000EC0
+    XK_Hangul_YA*: TKeySym = 0x00000EC1
+    XK_Hangul_YAE*: TKeySym = 0x00000EC2
+    XK_Hangul_EO*: TKeySym = 0x00000EC3
+    XK_Hangul_E*: TKeySym = 0x00000EC4
+    XK_Hangul_YEO*: TKeySym = 0x00000EC5
+    XK_Hangul_YE*: TKeySym = 0x00000EC6
+    XK_Hangul_O*: TKeySym = 0x00000EC7
+    XK_Hangul_WA*: TKeySym = 0x00000EC8
+    XK_Hangul_WAE*: TKeySym = 0x00000EC9
+    XK_Hangul_OE*: TKeySym = 0x00000ECA
+    XK_Hangul_YO*: TKeySym = 0x00000ECB
+    XK_Hangul_U*: TKeySym = 0x00000ECC
+    XK_Hangul_WEO*: TKeySym = 0x00000ECD
+    XK_Hangul_WE*: TKeySym = 0x00000ECE
+    XK_Hangul_WI*: TKeySym = 0x00000ECF
+    XK_Hangul_YU*: TKeySym = 0x00000ED0
+    XK_Hangul_EU*: TKeySym = 0x00000ED1
+    XK_Hangul_YI*: TKeySym = 0x00000ED2
+    XK_Hangul_I*: TKeySym = 0x00000ED3   # Hangul syllable-final (JongSeong) Characters 
+    XK_Hangul_J_Kiyeog*: TKeySym = 0x00000ED4
+    XK_Hangul_J_SsangKiyeog*: TKeySym = 0x00000ED5
+    XK_Hangul_J_KiyeogSios*: TKeySym = 0x00000ED6
+    XK_Hangul_J_Nieun*: TKeySym = 0x00000ED7
+    XK_Hangul_J_NieunJieuj*: TKeySym = 0x00000ED8
+    XK_Hangul_J_NieunHieuh*: TKeySym = 0x00000ED9
+    XK_Hangul_J_Dikeud*: TKeySym = 0x00000EDA
+    XK_Hangul_J_Rieul*: TKeySym = 0x00000EDB
+    XK_Hangul_J_RieulKiyeog*: TKeySym = 0x00000EDC
+    XK_Hangul_J_RieulMieum*: TKeySym = 0x00000EDD
+    XK_Hangul_J_RieulPieub*: TKeySym = 0x00000EDE
+    XK_Hangul_J_RieulSios*: TKeySym = 0x00000EDF
+    XK_Hangul_J_RieulTieut*: TKeySym = 0x00000EE0
+    XK_Hangul_J_RieulPhieuf*: TKeySym = 0x00000EE1
+    XK_Hangul_J_RieulHieuh*: TKeySym = 0x00000EE2
+    XK_Hangul_J_Mieum*: TKeySym = 0x00000EE3
+    XK_Hangul_J_Pieub*: TKeySym = 0x00000EE4
+    XK_Hangul_J_PieubSios*: TKeySym = 0x00000EE5
+    XK_Hangul_J_Sios*: TKeySym = 0x00000EE6
+    XK_Hangul_J_SsangSios*: TKeySym = 0x00000EE7
+    XK_Hangul_J_Ieung*: TKeySym = 0x00000EE8
+    XK_Hangul_J_Jieuj*: TKeySym = 0x00000EE9
+    XK_Hangul_J_Cieuc*: TKeySym = 0x00000EEA
+    XK_Hangul_J_Khieuq*: TKeySym = 0x00000EEB
+    XK_Hangul_J_Tieut*: TKeySym = 0x00000EEC
+    XK_Hangul_J_Phieuf*: TKeySym = 0x00000EED
+    XK_Hangul_J_Hieuh*: TKeySym = 0x00000EEE # Ancient Hangul Consonant Characters 
+    XK_Hangul_RieulYeorinHieuh*: TKeySym = 0x00000EEF
+    XK_Hangul_SunkyeongeumMieum*: TKeySym = 0x00000EF0
+    XK_Hangul_SunkyeongeumPieub*: TKeySym = 0x00000EF1
+    XK_Hangul_PanSios*: TKeySym = 0x00000EF2
+    XK_Hangul_KkogjiDalrinIeung*: TKeySym = 0x00000EF3
+    XK_Hangul_SunkyeongeumPhieuf*: TKeySym = 0x00000EF4
+    XK_Hangul_YeorinHieuh*: TKeySym = 0x00000EF5 # Ancient Hangul Vowel Characters 
+    XK_Hangul_AraeA*: TKeySym = 0x00000EF6
+    XK_Hangul_AraeAE*: TKeySym = 0x00000EF7 # Ancient Hangul syllable-final (JongSeong) Characters 
+    XK_Hangul_J_PanSios*: TKeySym = 0x00000EF8
+    XK_Hangul_J_KkogjiDalrinIeung*: TKeySym = 0x00000EF9
+    XK_Hangul_J_YeorinHieuh*: TKeySym = 0x00000EFA # Korean currency symbol 
+    XK_Korean_Won*: TKeySym = 0x00000EFF
 # XK_KOREAN 
 #*
 # *   Armenian
@@ -1613,108 +1614,108 @@ when defined(XK_KOREAN) or true:
 
 when defined(XK_ARMENIAN) or true: 
   const
-    XK_Armenian_eternity* = 0x000014A1
-    XK_Armenian_ligature_ew* = 0x000014A2
-    XK_Armenian_full_stop* = 0x000014A3
-    XK_Armenian_verjaket* = 0x000014A3
-    XK_Armenian_parenright* = 0x000014A4
-    XK_Armenian_parenleft* = 0x000014A5
-    XK_Armenian_guillemotright* = 0x000014A6
-    XK_Armenian_guillemotleft* = 0x000014A7
-    XK_Armenian_em_dash* = 0x000014A8
-    XK_Armenian_dot* = 0x000014A9
-    XK_Armenian_mijaket* = 0x000014A9
-    XK_Armenian_separation_mark* = 0x000014AA
-    XK_Armenian_but* = 0x000014AA
-    XK_Armenian_comma* = 0x000014AB
-    XK_Armenian_en_dash* = 0x000014AC
-    XK_Armenian_hyphen* = 0x000014AD
-    XK_Armenian_yentamna* = 0x000014AD
-    XK_Armenian_ellipsis* = 0x000014AE
-    XK_Armenian_exclam* = 0x000014AF
-    XK_Armenian_amanak* = 0x000014AF
-    XK_Armenian_accent* = 0x000014B0
-    XK_Armenian_shesht* = 0x000014B0
-    XK_Armenian_question* = 0x000014B1
-    XK_Armenian_paruyk* = 0x000014B1
-    XKc_Armenian_AYB* = 0x000014B2
-    XK_Armenian_ayb* = 0x000014B3
-    XKc_Armenian_BEN* = 0x000014B4
-    XK_Armenian_ben* = 0x000014B5
-    XKc_Armenian_GIM* = 0x000014B6
-    XK_Armenian_gim* = 0x000014B7
-    XKc_Armenian_DA* = 0x000014B8
-    XK_Armenian_da* = 0x000014B9
-    XKc_Armenian_YECH* = 0x000014BA
-    XK_Armenian_yech* = 0x000014BB
-    XKc_Armenian_ZA* = 0x000014BC
-    XK_Armenian_za* = 0x000014BD
-    XKc_Armenian_E* = 0x000014BE
-    XK_Armenian_e* = 0x000014BF
-    XKc_Armenian_AT* = 0x000014C0
-    XK_Armenian_at* = 0x000014C1
-    XKc_Armenian_TO* = 0x000014C2
-    XK_Armenian_to* = 0x000014C3
-    XKc_Armenian_ZHE* = 0x000014C4
-    XK_Armenian_zhe* = 0x000014C5
-    XKc_Armenian_INI* = 0x000014C6
-    XK_Armenian_ini* = 0x000014C7
-    XKc_Armenian_LYUN* = 0x000014C8
-    XK_Armenian_lyun* = 0x000014C9
-    XKc_Armenian_KHE* = 0x000014CA
-    XK_Armenian_khe* = 0x000014CB
-    XKc_Armenian_TSA* = 0x000014CC
-    XK_Armenian_tsa* = 0x000014CD
-    XKc_Armenian_KEN* = 0x000014CE
-    XK_Armenian_ken* = 0x000014CF
-    XKc_Armenian_HO* = 0x000014D0
-    XK_Armenian_ho* = 0x000014D1
-    XKc_Armenian_DZA* = 0x000014D2
-    XK_Armenian_dza* = 0x000014D3
-    XKc_Armenian_GHAT* = 0x000014D4
-    XK_Armenian_ghat* = 0x000014D5
-    XKc_Armenian_TCHE* = 0x000014D6
-    XK_Armenian_tche* = 0x000014D7
-    XKc_Armenian_MEN* = 0x000014D8
-    XK_Armenian_men* = 0x000014D9
-    XKc_Armenian_HI* = 0x000014DA
-    XK_Armenian_hi* = 0x000014DB
-    XKc_Armenian_NU* = 0x000014DC
-    XK_Armenian_nu* = 0x000014DD
-    XKc_Armenian_SHA* = 0x000014DE
-    XK_Armenian_sha* = 0x000014DF
-    XKc_Armenian_VO* = 0x000014E0
-    XK_Armenian_vo* = 0x000014E1
-    XKc_Armenian_CHA* = 0x000014E2
-    XK_Armenian_cha* = 0x000014E3
-    XKc_Armenian_PE* = 0x000014E4
-    XK_Armenian_pe* = 0x000014E5
-    XKc_Armenian_JE* = 0x000014E6
-    XK_Armenian_je* = 0x000014E7
-    XKc_Armenian_RA* = 0x000014E8
-    XK_Armenian_ra* = 0x000014E9
-    XKc_Armenian_SE* = 0x000014EA
-    XK_Armenian_se* = 0x000014EB
-    XKc_Armenian_VEV* = 0x000014EC
-    XK_Armenian_vev* = 0x000014ED
-    XKc_Armenian_TYUN* = 0x000014EE
-    XK_Armenian_tyun* = 0x000014EF
-    XKc_Armenian_RE* = 0x000014F0
-    XK_Armenian_re* = 0x000014F1
-    XKc_Armenian_TSO* = 0x000014F2
-    XK_Armenian_tso* = 0x000014F3
-    XKc_Armenian_VYUN* = 0x000014F4
-    XK_Armenian_vyun* = 0x000014F5
-    XKc_Armenian_PYUR* = 0x000014F6
-    XK_Armenian_pyur* = 0x000014F7
-    XKc_Armenian_KE* = 0x000014F8
-    XK_Armenian_ke* = 0x000014F9
-    XKc_Armenian_O* = 0x000014FA
-    XK_Armenian_o* = 0x000014FB
-    XKc_Armenian_FE* = 0x000014FC
-    XK_Armenian_fe* = 0x000014FD
-    XK_Armenian_apostrophe* = 0x000014FE
-    XK_Armenian_section_sign* = 0x000014FF
+    XK_Armenian_eternity*: TKeySym = 0x000014A1
+    XK_Armenian_ligature_ew*: TKeySym = 0x000014A2
+    XK_Armenian_full_stop*: TKeySym = 0x000014A3
+    XK_Armenian_verjaket*: TKeySym = 0x000014A3
+    XK_Armenian_parenright*: TKeySym = 0x000014A4
+    XK_Armenian_parenleft*: TKeySym = 0x000014A5
+    XK_Armenian_guillemotright*: TKeySym = 0x000014A6
+    XK_Armenian_guillemotleft*: TKeySym = 0x000014A7
+    XK_Armenian_em_dash*: TKeySym = 0x000014A8
+    XK_Armenian_dot*: TKeySym = 0x000014A9
+    XK_Armenian_mijaket*: TKeySym = 0x000014A9
+    XK_Armenian_separation_mark*: TKeySym = 0x000014AA
+    XK_Armenian_but*: TKeySym = 0x000014AA
+    XK_Armenian_comma*: TKeySym = 0x000014AB
+    XK_Armenian_en_dash*: TKeySym = 0x000014AC
+    XK_Armenian_hyphen*: TKeySym = 0x000014AD
+    XK_Armenian_yentamna*: TKeySym = 0x000014AD
+    XK_Armenian_ellipsis*: TKeySym = 0x000014AE
+    XK_Armenian_exclam*: TKeySym = 0x000014AF
+    XK_Armenian_amanak*: TKeySym = 0x000014AF
+    XK_Armenian_accent*: TKeySym = 0x000014B0
+    XK_Armenian_shesht*: TKeySym = 0x000014B0
+    XK_Armenian_question*: TKeySym = 0x000014B1
+    XK_Armenian_paruyk*: TKeySym = 0x000014B1
+    XKc_Armenian_AYB*: TKeySym = 0x000014B2
+    XK_Armenian_ayb*: TKeySym = 0x000014B3
+    XKc_Armenian_BEN*: TKeySym = 0x000014B4
+    XK_Armenian_ben*: TKeySym = 0x000014B5
+    XKc_Armenian_GIM*: TKeySym = 0x000014B6
+    XK_Armenian_gim*: TKeySym = 0x000014B7
+    XKc_Armenian_DA*: TKeySym = 0x000014B8
+    XK_Armenian_da*: TKeySym = 0x000014B9
+    XKc_Armenian_YECH*: TKeySym = 0x000014BA
+    XK_Armenian_yech*: TKeySym = 0x000014BB
+    XKc_Armenian_ZA*: TKeySym = 0x000014BC
+    XK_Armenian_za*: TKeySym = 0x000014BD
+    XKc_Armenian_E*: TKeySym = 0x000014BE
+    XK_Armenian_e*: TKeySym = 0x000014BF
+    XKc_Armenian_AT*: TKeySym = 0x000014C0
+    XK_Armenian_at*: TKeySym = 0x000014C1
+    XKc_Armenian_TO*: TKeySym = 0x000014C2
+    XK_Armenian_to*: TKeySym = 0x000014C3
+    XKc_Armenian_ZHE*: TKeySym = 0x000014C4
+    XK_Armenian_zhe*: TKeySym = 0x000014C5
+    XKc_Armenian_INI*: TKeySym = 0x000014C6
+    XK_Armenian_ini*: TKeySym = 0x000014C7
+    XKc_Armenian_LYUN*: TKeySym = 0x000014C8
+    XK_Armenian_lyun*: TKeySym = 0x000014C9
+    XKc_Armenian_KHE*: TKeySym = 0x000014CA
+    XK_Armenian_khe*: TKeySym = 0x000014CB
+    XKc_Armenian_TSA*: TKeySym = 0x000014CC
+    XK_Armenian_tsa*: TKeySym = 0x000014CD
+    XKc_Armenian_KEN*: TKeySym = 0x000014CE
+    XK_Armenian_ken*: TKeySym = 0x000014CF
+    XKc_Armenian_HO*: TKeySym = 0x000014D0
+    XK_Armenian_ho*: TKeySym = 0x000014D1
+    XKc_Armenian_DZA*: TKeySym = 0x000014D2
+    XK_Armenian_dza*: TKeySym = 0x000014D3
+    XKc_Armenian_GHAT*: TKeySym = 0x000014D4
+    XK_Armenian_ghat*: TKeySym = 0x000014D5
+    XKc_Armenian_TCHE*: TKeySym = 0x000014D6
+    XK_Armenian_tche*: TKeySym = 0x000014D7
+    XKc_Armenian_MEN*: TKeySym = 0x000014D8
+    XK_Armenian_men*: TKeySym = 0x000014D9
+    XKc_Armenian_HI*: TKeySym = 0x000014DA
+    XK_Armenian_hi*: TKeySym = 0x000014DB
+    XKc_Armenian_NU*: TKeySym = 0x000014DC
+    XK_Armenian_nu*: TKeySym = 0x000014DD
+    XKc_Armenian_SHA*: TKeySym = 0x000014DE
+    XK_Armenian_sha*: TKeySym = 0x000014DF
+    XKc_Armenian_VO*: TKeySym = 0x000014E0
+    XK_Armenian_vo*: TKeySym = 0x000014E1
+    XKc_Armenian_CHA*: TKeySym = 0x000014E2
+    XK_Armenian_cha*: TKeySym = 0x000014E3
+    XKc_Armenian_PE*: TKeySym = 0x000014E4
+    XK_Armenian_pe*: TKeySym = 0x000014E5
+    XKc_Armenian_JE*: TKeySym = 0x000014E6
+    XK_Armenian_je*: TKeySym = 0x000014E7
+    XKc_Armenian_RA*: TKeySym = 0x000014E8
+    XK_Armenian_ra*: TKeySym = 0x000014E9
+    XKc_Armenian_SE*: TKeySym = 0x000014EA
+    XK_Armenian_se*: TKeySym = 0x000014EB
+    XKc_Armenian_VEV*: TKeySym = 0x000014EC
+    XK_Armenian_vev*: TKeySym = 0x000014ED
+    XKc_Armenian_TYUN*: TKeySym = 0x000014EE
+    XK_Armenian_tyun*: TKeySym = 0x000014EF
+    XKc_Armenian_RE*: TKeySym = 0x000014F0
+    XK_Armenian_re*: TKeySym = 0x000014F1
+    XKc_Armenian_TSO*: TKeySym = 0x000014F2
+    XK_Armenian_tso*: TKeySym = 0x000014F3
+    XKc_Armenian_VYUN*: TKeySym = 0x000014F4
+    XK_Armenian_vyun*: TKeySym = 0x000014F5
+    XKc_Armenian_PYUR*: TKeySym = 0x000014F6
+    XK_Armenian_pyur*: TKeySym = 0x000014F7
+    XKc_Armenian_KE*: TKeySym = 0x000014F8
+    XK_Armenian_ke*: TKeySym = 0x000014F9
+    XKc_Armenian_O*: TKeySym = 0x000014FA
+    XK_Armenian_o*: TKeySym = 0x000014FB
+    XKc_Armenian_FE*: TKeySym = 0x000014FC
+    XK_Armenian_fe*: TKeySym = 0x000014FD
+    XK_Armenian_apostrophe*: TKeySym = 0x000014FE
+    XK_Armenian_section_sign*: TKeySym = 0x000014FF
 # XK_ARMENIAN 
 #*
 # *   Georgian
@@ -1723,45 +1724,45 @@ when defined(XK_ARMENIAN) or true:
 
 when defined(XK_GEORGIAN) or true: 
   const
-    XK_Georgian_an* = 0x000015D0
-    XK_Georgian_ban* = 0x000015D1
-    XK_Georgian_gan* = 0x000015D2
-    XK_Georgian_don* = 0x000015D3
-    XK_Georgian_en* = 0x000015D4
-    XK_Georgian_vin* = 0x000015D5
-    XK_Georgian_zen* = 0x000015D6
-    XK_Georgian_tan* = 0x000015D7
-    XK_Georgian_in* = 0x000015D8
-    XK_Georgian_kan* = 0x000015D9
-    XK_Georgian_las* = 0x000015DA
-    XK_Georgian_man* = 0x000015DB
-    XK_Georgian_nar* = 0x000015DC
-    XK_Georgian_on* = 0x000015DD
-    XK_Georgian_par* = 0x000015DE
-    XK_Georgian_zhar* = 0x000015DF
-    XK_Georgian_rae* = 0x000015E0
-    XK_Georgian_san* = 0x000015E1
-    XK_Georgian_tar* = 0x000015E2
-    XK_Georgian_un* = 0x000015E3
-    XK_Georgian_phar* = 0x000015E4
-    XK_Georgian_khar* = 0x000015E5
-    XK_Georgian_ghan* = 0x000015E6
-    XK_Georgian_qar* = 0x000015E7
-    XK_Georgian_shin* = 0x000015E8
-    XK_Georgian_chin* = 0x000015E9
-    XK_Georgian_can* = 0x000015EA
-    XK_Georgian_jil* = 0x000015EB
-    XK_Georgian_cil* = 0x000015EC
-    XK_Georgian_char* = 0x000015ED
-    XK_Georgian_xan* = 0x000015EE
-    XK_Georgian_jhan* = 0x000015EF
-    XK_Georgian_hae* = 0x000015F0
-    XK_Georgian_he* = 0x000015F1
-    XK_Georgian_hie* = 0x000015F2
-    XK_Georgian_we* = 0x000015F3
-    XK_Georgian_har* = 0x000015F4
-    XK_Georgian_hoe* = 0x000015F5
-    XK_Georgian_fi* = 0x000015F6
+    XK_Georgian_an*: TKeySym = 0x000015D0
+    XK_Georgian_ban*: TKeySym = 0x000015D1
+    XK_Georgian_gan*: TKeySym = 0x000015D2
+    XK_Georgian_don*: TKeySym = 0x000015D3
+    XK_Georgian_en*: TKeySym = 0x000015D4
+    XK_Georgian_vin*: TKeySym = 0x000015D5
+    XK_Georgian_zen*: TKeySym = 0x000015D6
+    XK_Georgian_tan*: TKeySym = 0x000015D7
+    XK_Georgian_in*: TKeySym = 0x000015D8
+    XK_Georgian_kan*: TKeySym = 0x000015D9
+    XK_Georgian_las*: TKeySym = 0x000015DA
+    XK_Georgian_man*: TKeySym = 0x000015DB
+    XK_Georgian_nar*: TKeySym = 0x000015DC
+    XK_Georgian_on*: TKeySym = 0x000015DD
+    XK_Georgian_par*: TKeySym = 0x000015DE
+    XK_Georgian_zhar*: TKeySym = 0x000015DF
+    XK_Georgian_rae*: TKeySym = 0x000015E0
+    XK_Georgian_san*: TKeySym = 0x000015E1
+    XK_Georgian_tar*: TKeySym = 0x000015E2
+    XK_Georgian_un*: TKeySym = 0x000015E3
+    XK_Georgian_phar*: TKeySym = 0x000015E4
+    XK_Georgian_khar*: TKeySym = 0x000015E5
+    XK_Georgian_ghan*: TKeySym = 0x000015E6
+    XK_Georgian_qar*: TKeySym = 0x000015E7
+    XK_Georgian_shin*: TKeySym = 0x000015E8
+    XK_Georgian_chin*: TKeySym = 0x000015E9
+    XK_Georgian_can*: TKeySym = 0x000015EA
+    XK_Georgian_jil*: TKeySym = 0x000015EB
+    XK_Georgian_cil*: TKeySym = 0x000015EC
+    XK_Georgian_char*: TKeySym = 0x000015ED
+    XK_Georgian_xan*: TKeySym = 0x000015EE
+    XK_Georgian_jhan*: TKeySym = 0x000015EF
+    XK_Georgian_hae*: TKeySym = 0x000015F0
+    XK_Georgian_he*: TKeySym = 0x000015F1
+    XK_Georgian_hie*: TKeySym = 0x000015F2
+    XK_Georgian_we*: TKeySym = 0x000015F3
+    XK_Georgian_har*: TKeySym = 0x000015F4
+    XK_Georgian_hoe*: TKeySym = 0x000015F5
+    XK_Georgian_fi*: TKeySym = 0x000015F6
 # XK_GEORGIAN 
 #*
 # * Azeri (and other Turkic or Caucasian languages of ex-USSR)
@@ -1771,35 +1772,35 @@ when defined(XK_GEORGIAN) or true:
 when defined(XK_CAUCASUS) or true: 
   # latin 
   const
-    XKc_Ccedillaabovedot* = 0x000016A2
-    XKc_Xabovedot* = 0x000016A3
-    XKc_Qabovedot* = 0x000016A5
-    XKc_Ibreve* = 0x000016A6
-    XKc_IE* = 0x000016A7
-    XKc_UO* = 0x000016A8
-    XKc_Zstroke* = 0x000016A9
-    XKc_Gcaron* = 0x000016AA
-    XKc_Obarred* = 0x000016AF
-    XK_ccedillaabovedot* = 0x000016B2
-    XK_xabovedot* = 0x000016B3
-    XKc_Ocaron* = 0x000016B4
-    XK_qabovedot* = 0x000016B5
-    XK_ibreve* = 0x000016B6
-    XK_ie* = 0x000016B7
-    XK_uo* = 0x000016B8
-    XK_zstroke* = 0x000016B9
-    XK_gcaron* = 0x000016BA
-    XK_ocaron* = 0x000016BD
-    XK_obarred* = 0x000016BF
-    XKc_SCHWA* = 0x000016C6
-    XK_schwa* = 0x000016F6 # those are not really Caucasus, but I put them here for now 
+    XKc_Ccedillaabovedot*: TKeySym = 0x000016A2
+    XKc_Xabovedot*: TKeySym = 0x000016A3
+    XKc_Qabovedot*: TKeySym = 0x000016A5
+    XKc_Ibreve*: TKeySym = 0x000016A6
+    XKc_IE*: TKeySym = 0x000016A7
+    XKc_UO*: TKeySym = 0x000016A8
+    XKc_Zstroke*: TKeySym = 0x000016A9
+    XKc_Gcaron*: TKeySym = 0x000016AA
+    XKc_Obarred*: TKeySym = 0x000016AF
+    XK_ccedillaabovedot*: TKeySym = 0x000016B2
+    XK_xabovedot*: TKeySym = 0x000016B3
+    XKc_Ocaron*: TKeySym = 0x000016B4
+    XK_qabovedot*: TKeySym = 0x000016B5
+    XK_ibreve*: TKeySym = 0x000016B6
+    XK_ie*: TKeySym = 0x000016B7
+    XK_uo*: TKeySym = 0x000016B8
+    XK_zstroke*: TKeySym = 0x000016B9
+    XK_gcaron*: TKeySym = 0x000016BA
+    XK_ocaron*: TKeySym = 0x000016BD
+    XK_obarred*: TKeySym = 0x000016BF
+    XKc_SCHWA*: TKeySym = 0x000016C6
+    XK_schwa*: TKeySym = 0x000016F6 # those are not really Caucasus, but I put them here for now\ 
                            # For Inupiak 
-    XKc_Lbelowdot* = 0x000016D1
-    XKc_Lstrokebelowdot* = 0x000016D2
-    XK_lbelowdot* = 0x000016E1
-    XK_lstrokebelowdot* = 0x000016E2 # For Guarani 
-    XKc_Gtilde* = 0x000016D3
-    XK_gtilde* = 0x000016E3
+    XKc_Lbelowdot*: TKeySym = 0x000016D1
+    XKc_Lstrokebelowdot*: TKeySym = 0x000016D2
+    XK_lbelowdot*: TKeySym = 0x000016E1
+    XK_lstrokebelowdot*: TKeySym = 0x000016E2 # For Guarani 
+    XKc_Gtilde*: TKeySym = 0x000016D3
+    XK_gtilde*: TKeySym = 0x000016E3
 # XK_CAUCASUS 
 #*
 # *   Vietnamese
@@ -1808,118 +1809,118 @@ when defined(XK_CAUCASUS) or true:
 
 when defined(XK_VIETNAMESE) or true:
   const 
-    XKc_Abelowdot* = 0x00001EA0
-    XK_abelowdot* = 0x00001EA1
-    XKc_Ahook* = 0x00001EA2
-    XK_ahook* = 0x00001EA3
-    XKc_Acircumflexacute* = 0x00001EA4
-    XK_acircumflexacute* = 0x00001EA5
-    XKc_Acircumflexgrave* = 0x00001EA6
-    XK_acircumflexgrave* = 0x00001EA7
-    XKc_Acircumflexhook* = 0x00001EA8
-    XK_acircumflexhook* = 0x00001EA9
-    XKc_Acircumflextilde* = 0x00001EAA
-    XK_acircumflextilde* = 0x00001EAB
-    XKc_Acircumflexbelowdot* = 0x00001EAC
-    XK_acircumflexbelowdot* = 0x00001EAD
-    XKc_Abreveacute* = 0x00001EAE
-    XK_abreveacute* = 0x00001EAF
-    XKc_Abrevegrave* = 0x00001EB0
-    XK_abrevegrave* = 0x00001EB1
-    XKc_Abrevehook* = 0x00001EB2
-    XK_abrevehook* = 0x00001EB3
-    XKc_Abrevetilde* = 0x00001EB4
-    XK_abrevetilde* = 0x00001EB5
-    XKc_Abrevebelowdot* = 0x00001EB6
-    XK_abrevebelowdot* = 0x00001EB7
-    XKc_Ebelowdot* = 0x00001EB8
-    XK_ebelowdot* = 0x00001EB9
-    XKc_Ehook* = 0x00001EBA
-    XK_ehook* = 0x00001EBB
-    XKc_Etilde* = 0x00001EBC
-    XK_etilde* = 0x00001EBD
-    XKc_Ecircumflexacute* = 0x00001EBE
-    XK_ecircumflexacute* = 0x00001EBF
-    XKc_Ecircumflexgrave* = 0x00001EC0
-    XK_ecircumflexgrave* = 0x00001EC1
-    XKc_Ecircumflexhook* = 0x00001EC2
-    XK_ecircumflexhook* = 0x00001EC3
-    XKc_Ecircumflextilde* = 0x00001EC4
-    XK_ecircumflextilde* = 0x00001EC5
-    XKc_Ecircumflexbelowdot* = 0x00001EC6
-    XK_ecircumflexbelowdot* = 0x00001EC7
-    XKc_Ihook* = 0x00001EC8
-    XK_ihook* = 0x00001EC9
-    XKc_Ibelowdot* = 0x00001ECA
-    XK_ibelowdot* = 0x00001ECB
-    XKc_Obelowdot* = 0x00001ECC
-    XK_obelowdot* = 0x00001ECD
-    XKc_Ohook* = 0x00001ECE
-    XK_ohook* = 0x00001ECF
-    XKc_Ocircumflexacute* = 0x00001ED0
-    XK_ocircumflexacute* = 0x00001ED1
-    XKc_Ocircumflexgrave* = 0x00001ED2
-    XK_ocircumflexgrave* = 0x00001ED3
-    XKc_Ocircumflexhook* = 0x00001ED4
-    XK_ocircumflexhook* = 0x00001ED5
-    XKc_Ocircumflextilde* = 0x00001ED6
-    XK_ocircumflextilde* = 0x00001ED7
-    XKc_Ocircumflexbelowdot* = 0x00001ED8
-    XK_ocircumflexbelowdot* = 0x00001ED9
-    XKc_Ohornacute* = 0x00001EDA
-    XK_ohornacute* = 0x00001EDB
-    XKc_Ohorngrave* = 0x00001EDC
-    XK_ohorngrave* = 0x00001EDD
-    XKc_Ohornhook* = 0x00001EDE
-    XK_ohornhook* = 0x00001EDF
-    XKc_Ohorntilde* = 0x00001EE0
-    XK_ohorntilde* = 0x00001EE1
-    XKc_Ohornbelowdot* = 0x00001EE2
-    XK_ohornbelowdot* = 0x00001EE3
-    XKc_Ubelowdot* = 0x00001EE4
-    XK_ubelowdot* = 0x00001EE5
-    XKc_Uhook* = 0x00001EE6
-    XK_uhook* = 0x00001EE7
-    XKc_Uhornacute* = 0x00001EE8
-    XK_uhornacute* = 0x00001EE9
-    XKc_Uhorngrave* = 0x00001EEA
-    XK_uhorngrave* = 0x00001EEB
-    XKc_Uhornhook* = 0x00001EEC
-    XK_uhornhook* = 0x00001EED
-    XKc_Uhorntilde* = 0x00001EEE
-    XK_uhorntilde* = 0x00001EEF
-    XKc_Uhornbelowdot* = 0x00001EF0
-    XK_uhornbelowdot* = 0x00001EF1
-    XKc_Ybelowdot* = 0x00001EF4
-    XK_ybelowdot* = 0x00001EF5
-    XKc_Yhook* = 0x00001EF6
-    XK_yhook* = 0x00001EF7
-    XKc_Ytilde* = 0x00001EF8
-    XK_ytilde* = 0x00001EF9
-    XKc_Ohorn* = 0x00001EFA     # U+01a0 
-    XK_ohorn* = 0x00001EFB      # U+01a1 
-    XKc_Uhorn* = 0x00001EFC     # U+01af 
-    XK_uhorn* = 0x00001EFD      # U+01b0 
-    XK_combining_tilde* = 0x00001E9F # U+0303 
-    XK_combining_grave* = 0x00001EF2 # U+0300 
-    XK_combining_acute* = 0x00001EF3 # U+0301 
-    XK_combining_hook* = 0x00001EFE # U+0309 
-    XK_combining_belowdot* = 0x00001EFF # U+0323 
+    XKc_Abelowdot*: TKeySym = 0x00001EA0
+    XK_abelowdot*: TKeySym = 0x00001EA1
+    XKc_Ahook*: TKeySym = 0x00001EA2
+    XK_ahook*: TKeySym = 0x00001EA3
+    XKc_Acircumflexacute*: TKeySym = 0x00001EA4
+    XK_acircumflexacute*: TKeySym = 0x00001EA5
+    XKc_Acircumflexgrave*: TKeySym = 0x00001EA6
+    XK_acircumflexgrave*: TKeySym = 0x00001EA7
+    XKc_Acircumflexhook*: TKeySym = 0x00001EA8
+    XK_acircumflexhook*: TKeySym = 0x00001EA9
+    XKc_Acircumflextilde*: TKeySym = 0x00001EAA
+    XK_acircumflextilde*: TKeySym = 0x00001EAB
+    XKc_Acircumflexbelowdot*: TKeySym = 0x00001EAC
+    XK_acircumflexbelowdot*: TKeySym = 0x00001EAD
+    XKc_Abreveacute*: TKeySym = 0x00001EAE
+    XK_abreveacute*: TKeySym = 0x00001EAF
+    XKc_Abrevegrave*: TKeySym = 0x00001EB0
+    XK_abrevegrave*: TKeySym = 0x00001EB1
+    XKc_Abrevehook*: TKeySym = 0x00001EB2
+    XK_abrevehook*: TKeySym = 0x00001EB3
+    XKc_Abrevetilde*: TKeySym = 0x00001EB4
+    XK_abrevetilde*: TKeySym = 0x00001EB5
+    XKc_Abrevebelowdot*: TKeySym = 0x00001EB6
+    XK_abrevebelowdot*: TKeySym = 0x00001EB7
+    XKc_Ebelowdot*: TKeySym = 0x00001EB8
+    XK_ebelowdot*: TKeySym = 0x00001EB9
+    XKc_Ehook*: TKeySym = 0x00001EBA
+    XK_ehook*: TKeySym = 0x00001EBB
+    XKc_Etilde*: TKeySym = 0x00001EBC
+    XK_etilde*: TKeySym = 0x00001EBD
+    XKc_Ecircumflexacute*: TKeySym = 0x00001EBE
+    XK_ecircumflexacute*: TKeySym = 0x00001EBF
+    XKc_Ecircumflexgrave*: TKeySym = 0x00001EC0
+    XK_ecircumflexgrave*: TKeySym = 0x00001EC1
+    XKc_Ecircumflexhook*: TKeySym = 0x00001EC2
+    XK_ecircumflexhook*: TKeySym = 0x00001EC3
+    XKc_Ecircumflextilde*: TKeySym = 0x00001EC4
+    XK_ecircumflextilde*: TKeySym = 0x00001EC5
+    XKc_Ecircumflexbelowdot*: TKeySym = 0x00001EC6
+    XK_ecircumflexbelowdot*: TKeySym = 0x00001EC7
+    XKc_Ihook*: TKeySym = 0x00001EC8
+    XK_ihook*: TKeySym = 0x00001EC9
+    XKc_Ibelowdot*: TKeySym = 0x00001ECA
+    XK_ibelowdot*: TKeySym = 0x00001ECB
+    XKc_Obelowdot*: TKeySym = 0x00001ECC
+    XK_obelowdot*: TKeySym = 0x00001ECD
+    XKc_Ohook*: TKeySym = 0x00001ECE
+    XK_ohook*: TKeySym = 0x00001ECF
+    XKc_Ocircumflexacute*: TKeySym = 0x00001ED0
+    XK_ocircumflexacute*: TKeySym = 0x00001ED1
+    XKc_Ocircumflexgrave*: TKeySym = 0x00001ED2
+    XK_ocircumflexgrave*: TKeySym = 0x00001ED3
+    XKc_Ocircumflexhook*: TKeySym = 0x00001ED4
+    XK_ocircumflexhook*: TKeySym = 0x00001ED5
+    XKc_Ocircumflextilde*: TKeySym = 0x00001ED6
+    XK_ocircumflextilde*: TKeySym = 0x00001ED7
+    XKc_Ocircumflexbelowdot*: TKeySym = 0x00001ED8
+    XK_ocircumflexbelowdot*: TKeySym = 0x00001ED9
+    XKc_Ohornacute*: TKeySym = 0x00001EDA
+    XK_ohornacute*: TKeySym = 0x00001EDB
+    XKc_Ohorngrave*: TKeySym = 0x00001EDC
+    XK_ohorngrave*: TKeySym = 0x00001EDD
+    XKc_Ohornhook*: TKeySym = 0x00001EDE
+    XK_ohornhook*: TKeySym = 0x00001EDF
+    XKc_Ohorntilde*: TKeySym = 0x00001EE0
+    XK_ohorntilde*: TKeySym = 0x00001EE1
+    XKc_Ohornbelowdot*: TKeySym = 0x00001EE2
+    XK_ohornbelowdot*: TKeySym = 0x00001EE3
+    XKc_Ubelowdot*: TKeySym = 0x00001EE4
+    XK_ubelowdot*: TKeySym = 0x00001EE5
+    XKc_Uhook*: TKeySym = 0x00001EE6
+    XK_uhook*: TKeySym = 0x00001EE7
+    XKc_Uhornacute*: TKeySym = 0x00001EE8
+    XK_uhornacute*: TKeySym = 0x00001EE9
+    XKc_Uhorngrave*: TKeySym = 0x00001EEA
+    XK_uhorngrave*: TKeySym = 0x00001EEB
+    XKc_Uhornhook*: TKeySym = 0x00001EEC
+    XK_uhornhook*: TKeySym = 0x00001EED
+    XKc_Uhorntilde*: TKeySym = 0x00001EEE
+    XK_uhorntilde*: TKeySym = 0x00001EEF
+    XKc_Uhornbelowdot*: TKeySym = 0x00001EF0
+    XK_uhornbelowdot*: TKeySym = 0x00001EF1
+    XKc_Ybelowdot*: TKeySym = 0x00001EF4
+    XK_ybelowdot*: TKeySym = 0x00001EF5
+    XKc_Yhook*: TKeySym = 0x00001EF6
+    XK_yhook*: TKeySym = 0x00001EF7
+    XKc_Ytilde*: TKeySym = 0x00001EF8
+    XK_ytilde*: TKeySym = 0x00001EF9
+    XKc_Ohorn*: TKeySym = 0x00001EFA     # U+01a0 
+    XK_ohorn*: TKeySym = 0x00001EFB      # U+01a1 
+    XKc_Uhorn*: TKeySym = 0x00001EFC     # U+01af 
+    XK_uhorn*: TKeySym = 0x00001EFD      # U+01b0 
+    XK_combining_tilde*: TKeySym = 0x00001E9F # U+0303 
+    XK_combining_grave*: TKeySym = 0x00001EF2 # U+0300 
+    XK_combining_acute*: TKeySym = 0x00001EF3 # U+0301 
+    XK_combining_hook*: TKeySym = 0x00001EFE # U+0309 
+    XK_combining_belowdot*: TKeySym = 0x00001EFF # U+0323 
 # XK_VIETNAMESE 
 
 when defined(XK_CURRENCY) or true: 
   const
-    XK_EcuSign* = 0x000020A0
-    XK_ColonSign* = 0x000020A1
-    XK_CruzeiroSign* = 0x000020A2
-    XK_FFrancSign* = 0x000020A3
-    XK_LiraSign* = 0x000020A4
-    XK_MillSign* = 0x000020A5
-    XK_NairaSign* = 0x000020A6
-    XK_PesetaSign* = 0x000020A7
-    XK_RupeeSign* = 0x000020A8
-    XK_WonSign* = 0x000020A9
-    XK_NewSheqelSign* = 0x000020AA
-    XK_DongSign* = 0x000020AB
-    XK_EuroSign* = 0x000020AC
+    XK_EcuSign*: TKeySym = 0x000020A0
+    XK_ColonSign*: TKeySym = 0x000020A1
+    XK_CruzeiroSign*: TKeySym = 0x000020A2
+    XK_FFrancSign*: TKeySym = 0x000020A3
+    XK_LiraSign*: TKeySym = 0x000020A4
+    XK_MillSign*: TKeySym = 0x000020A5
+    XK_NairaSign*: TKeySym = 0x000020A6
+    XK_PesetaSign*: TKeySym = 0x000020A7
+    XK_RupeeSign*: TKeySym = 0x000020A8
+    XK_WonSign*: TKeySym = 0x000020A9
+    XK_NewSheqelSign*: TKeySym = 0x000020AA
+    XK_DongSign*: TKeySym = 0x000020AB
+    XK_EuroSign*: TKeySym = 0x000020AC
 # implementation
diff --git a/lib/wrappers/x11/xlib.nim b/lib/wrappers/x11/xlib.nim
index e6010feb7..5ccacdd45 100644
--- a/lib/wrappers/x11/xlib.nim
+++ b/lib/wrappers/x11/xlib.nim
@@ -1811,210 +1811,217 @@ proc XSetAuthorization*(para1: cstring, para2: cint, para3: cstring, para4: cint
   #  _Xmbtowc?
   #  _Xwctomb?
   #
-when defined(MACROS): 
-  proc ConnectionNumber*(dpy: PDisplay): cint
-  proc RootWindow*(dpy: PDisplay, scr: cint): TWindow
-  proc DefaultScreen*(dpy: PDisplay): cint
-  proc DefaultRootWindow*(dpy: PDisplay): TWindow
-  proc DefaultVisual*(dpy: PDisplay, scr: cint): PVisual
-  proc DefaultGC*(dpy: PDisplay, scr: cint): TGC
-  proc BlackPixel*(dpy: PDisplay, scr: cint): culong
-  proc WhitePixel*(dpy: PDisplay, scr: cint): culong
-  proc QLength*(dpy: PDisplay): cint
-  proc DisplayWidth*(dpy: PDisplay, scr: cint): cint
-  proc DisplayHeight*(dpy: PDisplay, scr: cint): cint
-  proc DisplayWidthMM*(dpy: PDisplay, scr: cint): cint
-  proc DisplayHeightMM*(dpy: PDisplay, scr: cint): cint
-  proc DisplayPlanes*(dpy: PDisplay, scr: cint): cint
-  proc DisplayCells*(dpy: PDisplay, scr: cint): cint
-  proc ScreenCount*(dpy: PDisplay): cint
-  proc ServerVendor*(dpy: PDisplay): cstring
-  proc ProtocolVersion*(dpy: PDisplay): cint
-  proc ProtocolRevision*(dpy: PDisplay): cint
-  proc VendorRelease*(dpy: PDisplay): cint
-  proc DisplayString*(dpy: PDisplay): cstring
-  proc DefaultDepth*(dpy: PDisplay, scr: cint): cint
-  proc DefaultColormap*(dpy: PDisplay, scr: cint): TColormap
-  proc BitmapUnit*(dpy: PDisplay): cint
-  proc BitmapBitOrder*(dpy: PDisplay): cint
-  proc BitmapPad*(dpy: PDisplay): cint
-  proc ImageByteOrder*(dpy: PDisplay): cint
-  proc NextRequest*(dpy: PDisplay): culong
-  proc LastKnownRequestProcessed*(dpy: PDisplay): culong
-  proc ScreenOfDisplay*(dpy: PDisplay, scr: cint): PScreen
-  proc DefaultScreenOfDisplay*(dpy: PDisplay): PScreen
-  proc DisplayOfScreen*(s: PScreen): PDisplay
-  proc RootWindowOfScreen*(s: PScreen): TWindow
-  proc BlackPixelOfScreen*(s: PScreen): culong
-  proc WhitePixelOfScreen*(s: PScreen): culong
-  proc DefaultColormapOfScreen*(s: PScreen): TColormap
-  proc DefaultDepthOfScreen*(s: PScreen): cint
-  proc DefaultGCOfScreen*(s: PScreen): TGC
-  proc DefaultVisualOfScreen*(s: PScreen): PVisual
-  proc WidthOfScreen*(s: PScreen): cint
-  proc HeightOfScreen*(s: PScreen): cint
-  proc WidthMMOfScreen*(s: PScreen): cint
-  proc HeightMMOfScreen*(s: PScreen): cint
-  proc PlanesOfScreen*(s: PScreen): cint
-  proc CellsOfScreen*(s: PScreen): cint
-  proc MinCmapsOfScreen*(s: PScreen): cint
-  proc MaxCmapsOfScreen*(s: PScreen): cint
-  proc DoesSaveUnders*(s: PScreen): TBool
-  proc DoesBackingStore*(s: PScreen): cint
-  proc EventMaskOfScreen*(s: PScreen): clong
-  proc XAllocID*(dpy: PDisplay): TXID
+#when defined(MACROS): 
+proc ConnectionNumber*(dpy: PDisplay): cint
+proc RootWindow*(dpy: PDisplay, scr: cint): TWindow
+proc DefaultScreen*(dpy: PDisplay): cint
+proc DefaultRootWindow*(dpy: PDisplay): TWindow
+proc DefaultVisual*(dpy: PDisplay, scr: cint): PVisual
+proc DefaultGC*(dpy: PDisplay, scr: cint): TGC
+proc BlackPixel*(dpy: PDisplay, scr: cint): culong
+proc WhitePixel*(dpy: PDisplay, scr: cint): culong
+proc QLength*(dpy: PDisplay): cint
+proc DisplayWidth*(dpy: PDisplay, scr: cint): cint
+proc DisplayHeight*(dpy: PDisplay, scr: cint): cint
+proc DisplayWidthMM*(dpy: PDisplay, scr: cint): cint
+proc DisplayHeightMM*(dpy: PDisplay, scr: cint): cint
+proc DisplayPlanes*(dpy: PDisplay, scr: cint): cint
+proc DisplayCells*(dpy: PDisplay, scr: cint): cint
+proc ScreenCount*(dpy: PDisplay): cint
+proc ServerVendor*(dpy: PDisplay): cstring
+proc ProtocolVersion*(dpy: PDisplay): cint
+proc ProtocolRevision*(dpy: PDisplay): cint
+proc VendorRelease*(dpy: PDisplay): cint
+proc DisplayString*(dpy: PDisplay): cstring
+proc DefaultDepth*(dpy: PDisplay, scr: cint): cint
+proc DefaultColormap*(dpy: PDisplay, scr: cint): TColormap
+proc BitmapUnit*(dpy: PDisplay): cint
+proc BitmapBitOrder*(dpy: PDisplay): cint
+proc BitmapPad*(dpy: PDisplay): cint
+proc ImageByteOrder*(dpy: PDisplay): cint
+proc NextRequest*(dpy: PDisplay): culong
+proc LastKnownRequestProcessed*(dpy: PDisplay): culong
+proc ScreenOfDisplay*(dpy: PDisplay, scr: cint): PScreen
+proc DefaultScreenOfDisplay*(dpy: PDisplay): PScreen
+proc DisplayOfScreen*(s: PScreen): PDisplay
+proc RootWindowOfScreen*(s: PScreen): TWindow
+proc BlackPixelOfScreen*(s: PScreen): culong
+proc WhitePixelOfScreen*(s: PScreen): culong
+proc DefaultColormapOfScreen*(s: PScreen): TColormap
+proc DefaultDepthOfScreen*(s: PScreen): cint
+proc DefaultGCOfScreen*(s: PScreen): TGC
+proc DefaultVisualOfScreen*(s: PScreen): PVisual
+proc WidthOfScreen*(s: PScreen): cint
+proc HeightOfScreen*(s: PScreen): cint
+proc WidthMMOfScreen*(s: PScreen): cint
+proc HeightMMOfScreen*(s: PScreen): cint
+proc PlanesOfScreen*(s: PScreen): cint
+proc CellsOfScreen*(s: PScreen): cint
+proc MinCmapsOfScreen*(s: PScreen): cint
+proc MaxCmapsOfScreen*(s: PScreen): cint
+proc DoesSaveUnders*(s: PScreen): TBool
+proc DoesBackingStore*(s: PScreen): cint
+proc EventMaskOfScreen*(s: PScreen): clong
+proc XAllocID*(dpy: PDisplay): TXID
 # implementation
 
-when defined(MACROS): 
-  proc ConnectionNumber(dpy: PDisplay): cint = 
-    ConnectionNumber = (PXPrivDisplay(dpy))[] .fd
+#when defined(MACROS):
+template privDisp : expr = cast[PXPrivDisplay](dpy)
+ 
+proc ConnectionNumber(dpy: PDisplay): cint = 
+  privDisp.fd
 
-  proc RootWindow(dpy: PDisplay, scr: cint): TWindow = 
-    RootWindow = (ScreenOfDisplay(dpy, scr))[] .root
+proc RootWindow(dpy: PDisplay, scr: cint): TWindow = 
+  ScreenOfDisplay(dpy, scr).root
 
-  proc DefaultScreen(dpy: PDisplay): cint = 
-    DefaultScreen = (PXPrivDisplay(dpy))[] .default_screen
+proc DefaultScreen(dpy: PDisplay): cint = 
+  privDisp.default_screen
 
-  proc DefaultRootWindow(dpy: PDisplay): TWindow = 
-    DefaultRootWindow = (ScreenOfDisplay(dpy, DefaultScreen(dpy)))[] .root
+proc DefaultRootWindow(dpy: PDisplay): TWindow = 
+  ScreenOfDisplay(dpy, DefaultScreen(dpy)).root
 
-  proc DefaultVisual(dpy: PDisplay, scr: cint): PVisual = 
-    DefaultVisual = (ScreenOfDisplay(dpy, scr))[] .root_visual
+proc DefaultVisual(dpy: PDisplay, scr: cint): PVisual = 
+  ScreenOfDisplay(dpy, scr).root_visual
 
-  proc DefaultGC(dpy: PDisplay, scr: cint): TGC = 
-    DefaultGC = (ScreenOfDisplay(dpy, scr))[] .default_gc
+proc DefaultGC(dpy: PDisplay, scr: cint): TGC = 
+  ScreenOfDisplay(dpy, scr).default_gc
 
-  proc BlackPixel(dpy: PDisplay, scr: cint): culong = 
-    BlackPixel = (ScreenOfDisplay(dpy, scr))[] .black_pixel
+proc BlackPixel(dpy: PDisplay, scr: cint): culong = 
+  ScreenOfDisplay(dpy, scr).black_pixel
 
-  proc WhitePixel(dpy: PDisplay, scr: cint): culong = 
-    WhitePixel = (ScreenOfDisplay(dpy, scr))[] .white_pixel
+proc WhitePixel(dpy: PDisplay, scr: cint): culong = 
+  ScreenOfDisplay(dpy, scr).white_pixel
 
-  proc QLength(dpy: PDisplay): cint = 
-    QLength = (PXPrivDisplay(dpy))[] .qlen
+proc QLength(dpy: PDisplay): cint = 
+  privDisp.qlen
 
-  proc DisplayWidth(dpy: PDisplay, scr: cint): cint = 
-    DisplayWidth = (ScreenOfDisplay(dpy, scr))[] .width
+proc DisplayWidth(dpy: PDisplay, scr: cint): cint = 
+  ScreenOfDisplay(dpy, scr).width
 
-  proc DisplayHeight(dpy: PDisplay, scr: cint): cint = 
-    DisplayHeight = (ScreenOfDisplay(dpy, scr))[] .height
+proc DisplayHeight(dpy: PDisplay, scr: cint): cint = 
+  ScreenOfDisplay(dpy, scr).height
 
-  proc DisplayWidthMM(dpy: PDisplay, scr: cint): cint = 
-    DisplayWidthMM = (ScreenOfDisplay(dpy, scr))[] .mwidth
+proc DisplayWidthMM(dpy: PDisplay, scr: cint): cint = 
+  ScreenOfDisplay(dpy, scr).mwidth
 
-  proc DisplayHeightMM(dpy: PDisplay, scr: cint): cint = 
-    DisplayHeightMM = (ScreenOfDisplay(dpy, scr))[] .mheight
+proc DisplayHeightMM(dpy: PDisplay, scr: cint): cint = 
+  ScreenOfDisplay(dpy, scr).mheight
 
-  proc DisplayPlanes(dpy: PDisplay, scr: cint): cint = 
-    DisplayPlanes = (ScreenOfDisplay(dpy, scr))[] .root_depth
+proc DisplayPlanes(dpy: PDisplay, scr: cint): cint = 
+  ScreenOfDisplay(dpy, scr).root_depth
 
-  proc DisplayCells(dpy: PDisplay, scr: cint): cint = 
-    DisplayCells = (DefaultVisual(dpy, scr))[] .map_entries
+proc DisplayCells(dpy: PDisplay, scr: cint): cint = 
+  DefaultVisual(dpy, scr).map_entries
 
-  proc ScreenCount(dpy: PDisplay): cint = 
-    ScreenCount = (PXPrivDisplay(dpy))[] .nscreens
+proc ScreenCount(dpy: PDisplay): cint = 
+  privDisp.nscreens
 
-  proc ServerVendor(dpy: PDisplay): cstring = 
-    ServerVendor = (PXPrivDisplay(dpy))[] .vendor
+proc ServerVendor(dpy: PDisplay): cstring = 
+  privDisp.vendor
 
-  proc ProtocolVersion(dpy: PDisplay): cint = 
-    ProtocolVersion = (PXPrivDisplay(dpy))[] .proto_major_version
+proc ProtocolVersion(dpy: PDisplay): cint = 
+  privDisp.proto_major_version
 
-  proc ProtocolRevision(dpy: PDisplay): cint = 
-    ProtocolRevision = (PXPrivDisplay(dpy))[] .proto_minor_version
+proc ProtocolRevision(dpy: PDisplay): cint = 
+  privDisp.proto_minor_version
 
-  proc VendorRelease(dpy: PDisplay): cint = 
-    VendorRelease = (PXPrivDisplay(dpy))[] .release
+proc VendorRelease(dpy: PDisplay): cint = 
+  privDisp.release
 
-  proc DisplayString(dpy: PDisplay): cstring = 
-    DisplayString = (PXPrivDisplay(dpy))[] .display_name
+proc DisplayString(dpy: PDisplay): cstring = 
+  privDisp.display_name
 
-  proc DefaultDepth(dpy: PDisplay, scr: cint): cint = 
-    DefaultDepth = (ScreenOfDisplay(dpy, scr))[] .root_depth
+proc DefaultDepth(dpy: PDisplay, scr: cint): cint = 
+  ScreenOfDisplay(dpy, scr).root_depth
 
-  proc DefaultColormap(dpy: PDisplay, scr: cint): TColormap = 
-    DefaultColormap = (ScreenOfDisplay(dpy, scr))[] .cmap
+proc DefaultColormap(dpy: PDisplay, scr: cint): TColormap = 
+  ScreenOfDisplay(dpy, scr).cmap
 
-  proc BitmapUnit(dpy: PDisplay): cint = 
-    BitmapUnit = (PXPrivDisplay(dpy))[] .bitmap_unit
+proc BitmapUnit(dpy: PDisplay): cint = 
+  privDisp.bitmap_unit
 
-  proc BitmapBitOrder(dpy: PDisplay): cint = 
-    BitmapBitOrder = (PXPrivDisplay(dpy))[] .bitmap_bit_order
+proc BitmapBitOrder(dpy: PDisplay): cint = 
+  privDisp.bitmap_bit_order
 
-  proc BitmapPad(dpy: PDisplay): cint = 
-    BitmapPad = (PXPrivDisplay(dpy))[] .bitmap_pad
+proc BitmapPad(dpy: PDisplay): cint = 
+  privDisp.bitmap_pad
 
-  proc ImageByteOrder(dpy: PDisplay): cint = 
-    ImageByteOrder = (PXPrivDisplay(dpy))[] .byte_order
+proc ImageByteOrder(dpy: PDisplay): cint = 
+  privDisp.byte_order
 
-  proc NextRequest(dpy: PDisplay): culong = 
-    NextRequest = ((PXPrivDisplay(dpy))[] .request) + 1
+import unsigned
+proc NextRequest(dpy: PDisplay): culong = 
+  privDisp.request + 1.culong
 
-  proc LastKnownRequestProcessed(dpy: PDisplay): culong = 
-    LastKnownRequestProcessed = (PXPrivDisplay(dpy))[] .last_request_read
+proc LastKnownRequestProcessed(dpy: PDisplay): culong = 
+  privDisp.last_request_read
 
-  proc ScreenOfDisplay(dpy: PDisplay, scr: cint): PScreen = 
-    ScreenOfDisplay = addr((((PXPrivDisplay(dpy))[] .screens)[scr]))
+# from fowltek/pointer_arithm, required for ScreenOfDisplay()
+proc offset[A] (some: ptr A; b: int): ptr A =
+  cast[ptr A](cast[int](some) + (b * sizeof(A)))
+proc ScreenOfDisplay(dpy: PDisplay, scr: cint): PScreen =
+  #addr(((privDisp.screens)[scr])) 
+  privDisp.screens.offset(scr.int)
 
-  proc DefaultScreenOfDisplay(dpy: PDisplay): PScreen = 
-    DefaultScreenOfDisplay = ScreenOfDisplay(dpy, DefaultScreen(dpy))
+proc DefaultScreenOfDisplay(dpy: PDisplay): PScreen = 
+  ScreenOfDisplay(dpy, DefaultScreen(dpy))
 
-  proc DisplayOfScreen(s: PScreen): PDisplay = 
-    DisplayOfScreen = s[] .display
+proc DisplayOfScreen(s: PScreen): PDisplay = 
+  s.display
 
-  proc RootWindowOfScreen(s: PScreen): TWindow = 
-    RootWindowOfScreen = s[] .root
+proc RootWindowOfScreen(s: PScreen): TWindow = 
+  s.root
 
-  proc BlackPixelOfScreen(s: PScreen): culong = 
-    BlackPixelOfScreen = s[] .black_pixel
+proc BlackPixelOfScreen(s: PScreen): culong = 
+  s.black_pixel
 
-  proc WhitePixelOfScreen(s: PScreen): culong = 
-    WhitePixelOfScreen = s[] .white_pixel
+proc WhitePixelOfScreen(s: PScreen): culong = 
+  s.white_pixel
 
-  proc DefaultColormapOfScreen(s: PScreen): TColormap = 
-    DefaultColormapOfScreen = s[] .cmap
+proc DefaultColormapOfScreen(s: PScreen): TColormap = 
+  s.cmap
 
-  proc DefaultDepthOfScreen(s: PScreen): cint = 
-    DefaultDepthOfScreen = s[] .root_depth
+proc DefaultDepthOfScreen(s: PScreen): cint = 
+  s.root_depth
 
-  proc DefaultGCOfScreen(s: PScreen): TGC = 
-    DefaultGCOfScreen = s[] .default_gc
+proc DefaultGCOfScreen(s: PScreen): TGC = 
+  s.default_gc
 
-  proc DefaultVisualOfScreen(s: PScreen): PVisual = 
-    DefaultVisualOfScreen = s[] .root_visual
+proc DefaultVisualOfScreen(s: PScreen): PVisual = 
+  s.root_visual
 
-  proc WidthOfScreen(s: PScreen): cint = 
-    WidthOfScreen = s[] .width
+proc WidthOfScreen(s: PScreen): cint = 
+  s.width
 
-  proc HeightOfScreen(s: PScreen): cint = 
-    HeightOfScreen = s[] .height
+proc HeightOfScreen(s: PScreen): cint = 
+  s.height
 
-  proc WidthMMOfScreen(s: PScreen): cint = 
-    WidthMMOfScreen = s[] .mwidth
+proc WidthMMOfScreen(s: PScreen): cint = 
+  s.mwidth
 
-  proc HeightMMOfScreen(s: PScreen): cint = 
-    HeightMMOfScreen = s[] .mheight
+proc HeightMMOfScreen(s: PScreen): cint = 
+  s.mheight
 
-  proc PlanesOfScreen(s: PScreen): cint = 
-    PlanesOfScreen = s[] .root_depth
+proc PlanesOfScreen(s: PScreen): cint = 
+  s.root_depth
 
-  proc CellsOfScreen(s: PScreen): cint = 
-    CellsOfScreen = (DefaultVisualOfScreen(s))[] .map_entries
+proc CellsOfScreen(s: PScreen): cint = 
+  DefaultVisualOfScreen(s).map_entries
 
-  proc MinCmapsOfScreen(s: PScreen): cint = 
-    MinCmapsOfScreen = s[] .min_maps
+proc MinCmapsOfScreen(s: PScreen): cint = 
+  s.min_maps
 
-  proc MaxCmapsOfScreen(s: PScreen): cint = 
-    MaxCmapsOfScreen = s[] .max_maps
+proc MaxCmapsOfScreen(s: PScreen): cint = 
+  s.max_maps
 
-  proc DoesSaveUnders(s: PScreen): TBool = 
-    DoesSaveUnders = s[] .save_unders
+proc DoesSaveUnders(s: PScreen): TBool = 
+  s.save_unders
 
-  proc DoesBackingStore(s: PScreen): cint = 
-    DoesBackingStore = s[] .backing_store
+proc DoesBackingStore(s: PScreen): cint = 
+  s.backing_store
 
-  proc EventMaskOfScreen(s: PScreen): clong = 
-    EventMaskOfScreen = s[] .root_input_mask
+proc EventMaskOfScreen(s: PScreen): clong = 
+  s.root_input_mask
 
-  proc XAllocID(dpy: PDisplay): TXID = 
-    XAllocID = (PXPrivDisplay(dpy))[] .resource_alloc(dpy)
+proc XAllocID(dpy: PDisplay): TXID = 
+  privDisp.resource_alloc(dpy)
diff --git a/lib/wrappers/x11/xutil.nim b/lib/wrappers/x11/xutil.nim
index b66955927..9a3435aa5 100644
--- a/lib/wrappers/x11/xutil.nim
+++ b/lib/wrappers/x11/xutil.nim
@@ -1,6 +1,6 @@
 
 import 
-  x, xlib, keysym
+  x, xlib, keysym, unsigned
 
 #const 
 #  libX11* = "libX11.so"
@@ -356,57 +356,57 @@ proc XWMGeometry*(para1: PDisplay, para2: cint, para3: cstring, para4: cstring,
     dynlib: libX11, importc.}
 proc XXorRegion*(para1: TRegion, para2: TRegion, para3: TRegion): cint{.cdecl, 
     dynlib: libX11, importc.}
-when defined(MACROS): 
-  proc XDestroyImage*(ximage: PXImage): cint
-  proc XGetPixel*(ximage: PXImage, x, y: cint): culong
-  proc XPutPixel*(ximage: PXImage, x, y: cint, pixel: culong): cint
-  proc XSubImage*(ximage: PXImage, x, y: cint, width, height: cuint): PXImage
-  proc XAddPixel*(ximage: PXImage, value: clong): cint
-  proc IsKeypadKey*(keysym: TKeySym): bool
-  proc IsPrivateKeypadKey*(keysym: TKeySym): bool
-  proc IsCursorKey*(keysym: TKeySym): bool
-  proc IsPFKey*(keysym: TKeySym): bool
-  proc IsFunctionKey*(keysym: TKeySym): bool
-  proc IsMiscFunctionKey*(keysym: TKeySym): bool
-  proc IsModifierKey*(keysym: TKeySym): bool
-    #function XUniqueContext : TXContext;
-    #function XStringToContext(_string : Pchar) : TXContext;
+#when defined(MACROS): 
+proc XDestroyImage*(ximage: PXImage): cint
+proc XGetPixel*(ximage: PXImage, x, y: cint): culong
+proc XPutPixel*(ximage: PXImage, x, y: cint, pixel: culong): cint
+proc XSubImage*(ximage: PXImage, x, y: cint, width, height: cuint): PXImage
+proc XAddPixel*(ximage: PXImage, value: clong): cint
+proc IsKeypadKey*(keysym: TKeySym): bool
+proc IsPrivateKeypadKey*(keysym: TKeySym): bool
+proc IsCursorKey*(keysym: TKeySym): bool
+proc IsPFKey*(keysym: TKeySym): bool
+proc IsFunctionKey*(keysym: TKeySym): bool
+proc IsMiscFunctionKey*(keysym: TKeySym): bool
+proc IsModifierKey*(keysym: TKeySym): bool
+  #function XUniqueContext : TXContext;
+  #function XStringToContext(_string : Pchar) : TXContext;
 # implementation
 
-when defined(MACROS): 
-  proc XDestroyImage(ximage: PXImage): cint = 
-    XDestroyImage = ximage[] .f.destroy_image(ximage)
+#when defined(MACROS): 
+proc XDestroyImage(ximage: PXImage): cint = 
+  ximage.f.destroy_image(ximage)
 
-  proc XGetPixel(ximage: PXImage, x, y: cint): culong = 
-    XGetPixel = ximage[] .f.get_pixel(ximage, x, y)
+proc XGetPixel(ximage: PXImage, x, y: cint): culong = 
+  ximage.f.get_pixel(ximage, x, y)
 
-  proc XPutPixel(ximage: PXImage, x, y: cint, pixel: culong): cint = 
-    XPutPixel = ximage[] .f.put_pixel(ximage, x, y, pixel)
+proc XPutPixel(ximage: PXImage, x, y: cint, pixel: culong): cint = 
+  ximage.f.put_pixel(ximage, x, y, pixel)
 
-  proc XSubImage(ximage: PXImage, x, y: cint, width, height: cuint): PXImage = 
-    XSubImage = ximage[] .f.sub_image(ximage, x, y, width, height)
+proc XSubImage(ximage: PXImage, x, y: cint, width, height: cuint): PXImage = 
+  ximage.f.sub_image(ximage, x, y, width, height)
 
-  proc XAddPixel(ximage: PXImage, value: clong): cint = 
-    XAddPixel = ximage[] .f.add_pixel(ximage, value)
+proc XAddPixel(ximage: PXImage, value: clong): cint = 
+  ximage.f.add_pixel(ximage, value)
 
-  proc IsKeypadKey(keysym: TKeySym): bool = 
-    IsKeypadKey = (keysym >= XK_KP_Space) and (keysym <= XK_KP_Equal)
+proc IsKeypadKey(keysym: TKeySym): bool = 
+  (keysym >= XK_KP_Space) and (keysym <= XK_KP_Equal)
 
-  proc IsPrivateKeypadKey(keysym: TKeySym): bool = 
-    IsPrivateKeypadKey = (keysym >= 0x11000000) and (keysym <= 0x1100FFFF)
+proc IsPrivateKeypadKey(keysym: TKeySym): bool = 
+  (keysym >= 0x11000000.TKeySym) and (keysym <= 0x1100FFFF.TKeySym)
 
-  proc IsCursorKey(keysym: TKeySym): bool = 
-    IsCursorKey = (keysym >= XK_Home) and (keysym < XK_Select)
+proc IsCursorKey(keysym: TKeySym): bool = 
+  (keysym >= XK_Home) and (keysym < XK_Select)
 
-  proc IsPFKey(keysym: TKeySym): bool = 
-    IsPFKey = (keysym >= XK_KP_F1) and (keysym <= XK_KP_F4)
+proc IsPFKey(keysym: TKeySym): bool = 
+  (keysym >= XK_KP_F1) and (keysym <= XK_KP_F4)
 
-  proc IsFunctionKey(keysym: TKeySym): bool = 
-    IsFunctionKey = (keysym >= XK_F1) and (keysym <= XK_F35)
+proc IsFunctionKey(keysym: TKeySym): bool = 
+  (keysym >= XK_F1) and (keysym <= XK_F35)
 
-  proc IsMiscFunctionKey(keysym: TKeySym): bool = 
-    IsMiscFunctionKey = (keysym >= XK_Select) and (keysym <= XK_Break)
+proc IsMiscFunctionKey(keysym: TKeySym): bool = 
+  (keysym >= XK_Select) and (keysym <= XK_Break)
 
-  proc IsModifierKey(keysym: TKeySym): bool = 
-    IsModifierKey = ((keysym >= XK_Shift_L) And (keysym <= XK_Hyper_R)) Or
-        (keysym == XK_Mode_switch) Or (keysym == XK_Num_Lock)
+proc IsModifierKey(keysym: TKeySym): bool = 
+  ((keysym >= XK_Shift_L) And (keysym <= XK_Hyper_R)) Or
+      (keysym == XK_Mode_switch) Or (keysym == XK_Num_Lock)
diff --git a/lib/wrappers/zip/zlib.nim b/lib/wrappers/zip/zlib.nim
index de52a06e1..c4c6ac071 100644
--- a/lib/wrappers/zip/zlib.nim
+++ b/lib/wrappers/zip/zlib.nim
@@ -102,6 +102,7 @@ proc compress2*(dest: pbytef, destLen: puLongf, source: pbytef,
 proc uncompress*(dest: pbytef, destLen: puLongf, source: pbytef, 
                  sourceLen: uLong): cint{.cdecl, dynlib: libz, 
     importc: "uncompress".}
+proc compressBound*(sourceLen: uLong): uLong {.cdecl, dynlib: libz, importc.}
 proc gzopen*(path: cstring, mode: cstring): gzFile{.cdecl, dynlib: libz, 
     importc: "gzopen".}
 proc gzdopen*(fd: int32, mode: cstring): gzFile{.cdecl, dynlib: libz, 
diff --git a/readme.md b/readme.md
index f74f81283..8d42c66db 100644
--- a/readme.md
+++ b/readme.md
@@ -9,7 +9,7 @@ the C source of an older version of the compiler are needed to bootstrap the
 latest version. The C sources are available in a separate repo [here](http://github.com/nimrod-code/csources).
 
 Pre-compiled snapshots of the compiler are also available on
-[Nimbuild](http://build.nimrod-code.org/). Your platform however may not 
+[Nimbuild](http://build.nimrod-lang.org/). Your platform however may not 
 currently be built for.
 
 The compiler currently supports the following platform and architecture 
@@ -47,9 +47,11 @@ The above steps can be performed on Windows in a similar fashion, the
 instead of ``build.sh``.
 
 ## Getting help
-A [forum](http://forum.nimrod-code.org/) is available if you have any questions,
-and you can also get help in the IRC channel
-on [Freenode](irc://irc.freenode.net/nimrod) in #nimrod.
+A [forum](http://forum.nimrod-lang.org/) is available if you have any
+questions, and you can also get help in the IRC channel on
+[Freenode](irc://irc.freenode.net/nimrod) in #nimrod. If you ask questions on
+[StackOverflow use the nimrod
+tag](http://stackoverflow.com/questions/tagged/nimrod).
 
 ## License
 The compiler and the standard library are licensed under the MIT license, 
diff --git a/readme.txt b/readme.txt
index f74f81283..8d42c66db 100644
--- a/readme.txt
+++ b/readme.txt
@@ -9,7 +9,7 @@ the C source of an older version of the compiler are needed to bootstrap the
 latest version. The C sources are available in a separate repo [here](http://github.com/nimrod-code/csources).
 
 Pre-compiled snapshots of the compiler are also available on
-[Nimbuild](http://build.nimrod-code.org/). Your platform however may not 
+[Nimbuild](http://build.nimrod-lang.org/). Your platform however may not 
 currently be built for.
 
 The compiler currently supports the following platform and architecture 
@@ -47,9 +47,11 @@ The above steps can be performed on Windows in a similar fashion, the
 instead of ``build.sh``.
 
 ## Getting help
-A [forum](http://forum.nimrod-code.org/) is available if you have any questions,
-and you can also get help in the IRC channel
-on [Freenode](irc://irc.freenode.net/nimrod) in #nimrod.
+A [forum](http://forum.nimrod-lang.org/) is available if you have any
+questions, and you can also get help in the IRC channel on
+[Freenode](irc://irc.freenode.net/nimrod) in #nimrod. If you ask questions on
+[StackOverflow use the nimrod
+tag](http://stackoverflow.com/questions/tagged/nimrod).
 
 ## License
 The compiler and the standard library are licensed under the MIT license, 
diff --git a/tests/run/temit.nim b/tests/run/temit.nim
index 460bc3443..ff8df0585 100644
--- a/tests/run/temit.nim
+++ b/tests/run/temit.nim
@@ -9,9 +9,9 @@ static int cvariable = 420;
 
 """.}
 
-proc embedsC() {.noStackFrame.} = 
+proc embedsC() = 
   var nimrodVar = 89
-  {.emit: """fprintf(stdout, "%d\n", cvariable + (int)`nimrodVar`);""".}
+  {.emit: """printf("%d\n", cvariable + (int)`nimrodVar`);""".}
 
 embedsC()
 
diff --git a/tests/run/tstaticparams.nim b/tests/run/tstaticparams.nim
index 232748356..f2d6e1dd6 100644
--- a/tests/run/tstaticparams.nim
+++ b/tests/run/tstaticparams.nim
@@ -10,6 +10,10 @@ type
   TBar[T; I: expr[int]] = object
     data: array[I, T]
 
+  TA1[T; I: expr[int]] = array[I, T]
+  TA2[T; I: expr[int]] = array[0..I, T]
+  TA3[T; I: expr[int]] = array[I-1, T]
+
 proc takeFoo(x: TFoo) =
   echo "abracadabra"
   echo TFoo.Val
@@ -20,3 +24,8 @@ takeFoo(x)
 var y: TBar[float, 4]
 echo high(y.data)
 
+var
+  t1: TA1
+  t2: TA2
+  t3: TA3
+
diff --git a/tests/run/tusertypeclasses.nim b/tests/run/tusertypeclasses.nim
new file mode 100644
index 000000000..4c2f07b85
--- /dev/null
+++ b/tests/run/tusertypeclasses.nim
@@ -0,0 +1,28 @@
+discard """
+  output: "Sortable\nSortable\nContainer"
+"""
+
+import typetraits
+
+type
+  TObj = object
+    x: int
+
+  Sortable = generic x, y
+    (x < y) is bool
+
+  ObjectContainer = generic C
+    C.len is ordinal
+    for v in items(C):
+      v.type is tuple|object
+
+proc foo(c: ObjectContainer) =
+  echo "Container"
+
+proc foo(x: Sortable) =
+  echo "Sortable"
+
+foo 10
+foo "test"
+foo(@[TObj(x: 10), TObj(x: 20)])
+
diff --git a/tools/niminst/buildsh.tmpl b/tools/niminst/buildsh.tmpl
index 621020e75..0fb4907cf 100644
--- a/tools/niminst/buildsh.tmpl
+++ b/tools/niminst/buildsh.tmpl
@@ -54,7 +54,7 @@ case $uos in
     myos="linux" 
     LINK_FLAGS="$LINK_FLAGS -ldl -lm"
     ;;
-  *freebsd* ) 
+  *freebsd* | *dragonfly* ) 
     myos="freebsd"
     LINK_FLAGS="$LINK_FLAGS -lm"
     ;;