ugh, maybe broke git

This commit is contained in:
Araq 2011-04-01 15:07:16 +02:00
commit 4741e8f9a1
25 changed files with 587 additions and 172 deletions

View file

@ -1,7 +1,7 @@
#
#
# Nimrod's Runtime Library
# (c) Copyright 2008 Andreas Rumpf
# (c) Copyright 2011 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
@ -30,14 +30,10 @@ proc finishHash(h: THash): THash {.inline.} =
proc hashData*(Data: Pointer, Size: int): THash =
## hashes an array of bytes of size `size`
var
h: THash
p: cstring
i, s: int
h = 0
p = cast[cstring](Data)
i = 0
s = size
var h: THash = 0
var p = cast[cstring](Data)
var i = 0
var s = size
while s > 0:
h = concHash(h, ord(p[i]))
Inc(i)
@ -62,20 +58,16 @@ proc hash*(x: char): THash {.inline.} =
proc hash*(x: string): THash =
## efficient hashing of strings
var h: THash
h = 0
var h: THash = 0
for i in 0..x.len-1:
h = concHash(h, ord(x[i]))
result = finishHash(h)
proc hashIgnoreStyle*(x: string): THash =
## efficient hashing of strings; style is ignored
var
h: THash
c: Char
h = 0
var h: THash = 0
for i in 0..x.len-1:
c = x[i]
var c = x[i]
if c == '_':
continue # skip _
if c in {'A'..'Z'}:
@ -85,13 +77,17 @@ proc hashIgnoreStyle*(x: string): THash =
proc hashIgnoreCase*(x: string): THash =
## efficient hashing of strings; case is ignored
var
h: THash
c: Char
h = 0
var h: THash = 0
for i in 0..x.len-1:
c = x[i]
var c = x[i]
if c in {'A'..'Z'}:
c = chr(ord(c) + (ord('a') - ord('A'))) # toLower()
h = concHash(h, ord(c))
result = finishHash(h)
proc hash*[T: tuple](x: T): THash =
## efficient hashing of tuples.
for f in fields(x):
result = concHash(result, hash(f))
result = finishHash(result)

View file

@ -237,10 +237,7 @@ proc request*(url: string, httpMethod = httpGET, extraHeaders = "",
var r = parseUrl(url)
var headers = copy($httpMethod, len("http"))
if r.path != "":
headers.add(" /" & r.path & r.query)
else:
headers.add(" /")
headers.add(" /" & r.path & r.query)
headers.add(" HTTP/1.1\c\L")
add(headers, "Host: " & r.hostname & "\c\L")

View file

@ -700,6 +700,18 @@ proc `$`*(node: PJsonNode): String =
result = ""
toPretty(result, node, 1, False)
iterator items*(node: PJsonNode): PJSonNode =
## Iterator for the items of `node`. `node` has to be a JArray.
assert node.kind == JArray
for i in items(node.elems):
yield i
iterator pairs*(node: PJsonNode): tuple[key: string, val: PJsonNode] =
## Iterator for the child elements of `node`. `node` has to be a JObject.
assert node.kind == JObject
for key, val in items(node.fields):
yield (key, val)
proc eat(p: var TJsonParser, tok: TTokKind) =
if p.tok == tok: discard getTok(p)
else: raiseParseErr(p, tokToStr[tok])
@ -711,7 +723,7 @@ proc parseJson(p: var TJsonParser): PJsonNode =
result = newJString(p.a)
discard getTok(p)
of tkInt:
result = newJInt(parseInt(p.a))
result = newJInt(parseBiggestInt(p.a))
discard getTok(p)
of tkFloat:
result = newJFloat(parseFloat(p.a))

View file

@ -1130,6 +1130,12 @@ proc getConfigDir*(): string {.rtl, extern: "nos$1".} =
when defined(windows): return getEnv("APPDATA") & "\\"
else: return getEnv("HOME") & "/.config/"
proc getTempDir*(): string {.rtl, extern: "nos$1".} =
## Returns the temporary directory of the current user for applications to
## save temporary files in.
when defined(windows): return getEnv("TEMP") & "\\"
else: return "/tmp/"
when defined(windows):
# Since we support GUI applications with Nimrod, we sometimes generate
# a WinMain entry proc. But a WinMain proc has no access to the parsed

View file

@ -586,11 +586,11 @@ proc next*(my: var TXmlParser) =
of stateNormal:
getTok(my)
of stateStart:
my.state = stateNormal
getTok(my)
if my.kind == xmlPI and my.a == "xml":
# just skip the first ``<?xml >`` processing instruction
getTok(my)
my.state = stateNormal
of stateAttr:
# parse an attribute key-value pair:
if my.buf[my.bufpos] == '>':

View file

@ -68,11 +68,11 @@ proc parse(x: var TXmlParser, errors: var seq[string]): PXmlNode =
of xmlElementOpen:
result = newElement(x.elementName)
next(x)
result.attr = newStringTable()
result.attrs = newStringTable()
while true:
case x.kind
of xmlAttribute:
result.attr[x.attrKey] = x.attrValue
result.attrs[x.attrKey] = x.attrValue
next(x)
of xmlElementClose:
next(x)

View file

@ -98,17 +98,17 @@ iterator items*(n: PXmlNode): PXmlNode {.inline.} =
assert n.k == xnElement
for i in 0 .. n.len-1: yield n[i]
proc attr*(n: PXmlNode): PXmlAttributes {.inline.} =
proc attrs*(n: PXmlNode): PXmlAttributes {.inline.} =
## gets the attributes belonging to `n`.
assert n.k == xnElement
result = n.fAttr
proc `attr=`*(n: PXmlNode, attr: PXmlAttributes) {.inline.} =
proc `attrs=`*(n: PXmlNode, attr: PXmlAttributes) {.inline.} =
## sets the attributes belonging to `n`.
assert n.k == xnElement
n.fAttr = attr
proc attrLen*(n: PXmlNode): int {.inline.} =
proc attrsLen*(n: PXmlNode): int {.inline.} =
## returns the number of `n`'s attributes.
assert n.k == xnElement
if not isNil(n.fAttr): result = len(n.fAttr)
@ -262,3 +262,16 @@ macro `<>`*(x: expr): expr =
##
result = xmlConstructor(x)
proc child*(n: PXmlNode, name: string): PXmlNode =
## Finds the first child element of `n` with a name of `name`.
## Returns `nil` on failure.
assert n.kind == xnElement
for i in items(n):
if i.kind == xnElement:
if i.tag == name:
return i
proc attr*(n: PXmlNode, name: string): string =
## Finds the first attribute of `n` with a name of `name`.
assert n.kind == xnElement
return n.attrs[name]

View file

@ -765,7 +765,7 @@ proc add *[T](x: var seq[T], y: openArray[T]) {.noSideEffect.} =
setLen(x, xl + y.len)
for i in 0..high(y): x[xl+i] = y[i]
proc del* [T](x: var seq[T], i: int) {.noSideEffect.} =
proc del*[T](x: var seq[T], i: int) {.noSideEffect.} =
## deletes the item at index `i` by putting ``x[high(x)]`` into position `i`.
## This is an O(1) operation.
var xl = x.len
@ -1111,15 +1111,6 @@ iterator items*(a: cstring): char {.inline.} =
yield a[i]
inc(i)
iterator enumerate*[TContainer, TItem](a: TContainer): tuple[
index: int, item: TItem] {.inline.} =
## iterates over each item of `a` via `items` and yields an additional
## counter/index starting from 0.
var j = 0
for it in items(a):
yield (j, a)
inc j
proc isNil*[T](x: seq[T]): bool {.noSideEffect, magic: "IsNil".}
proc isNil*[T](x: ref T): bool {.noSideEffect, magic: "IsNil".}
proc isNil*(x: string): bool {.noSideEffect, magic: "IsNil".}
@ -1170,7 +1161,7 @@ when not defined(NimrodVM):
proc find*[T, S: typeDesc](a: T, item: S): int {.inline.}=
## Returns the first index of `item` in `a` or -1 if not found. This requires
## appropriate `items` and `==` procs to work.
## appropriate `items` and `==` operations to work.
for i in items(a):
if i == item: return
inc(result)
@ -1200,6 +1191,62 @@ proc each*[T](data: var openArray[T], op: proc (x: var T)) =
## `op` to every item in `data`.
for i in 0..data.len-1: op(data[i])
iterator fields*(x: tuple[]): expr {.magic: "Fields", noSideEffect.}
## iterates over every field of `x`. Warning: This is really transforms
## the 'for' and unrolls the loop. The current implementation also has a bug
## that affects symbol binding in the loop body.
iterator fields*(x, y: tuple[]): tuple[a, b: expr] {.
magic: "Fields", noSideEffect.}
## iterates over every field of `x` and `y`.
## Warning: This is really transforms the 'for' and unrolls the loop.
## The current implementation also has a bug that affects symbol binding
## in the loop body.
iterator fieldPairs*(x: tuple[]): expr {.magic: "FieldPairs", noSideEffect.}
## iterates over every field of `x`. Warning: This is really transforms
## the 'for' and unrolls the loop. The current implementation also has a bug
## that affects symbol binding in the loop body.
iterator fieldPairs*(x, y: tuple[]): tuple[a, b: expr] {.
magic: "FieldPairs", noSideEffect.}
## iterates over every field of `x` and `y`.
## Warning: This is really transforms the 'for' and unrolls the loop.
## The current implementation also has a bug that affects symbol binding
## in the loop body.
proc `==`*[T: tuple](x, y: T): bool =
## generic ``==`` operator that is lifted from the components
## of `x` and `y`.
for a, b in fields(x, y):
if a != b: return false
return true
proc `<=`*[T: tuple](x, y: T): bool =
## generic ``<=`` operator that is lifted from the components
## of `x` and `y`. This implementation uses `cmp`.
for a, b in fields(x, y):
var c = cmp(a, b)
if c < 0: return true
if c > 0: return false
return true
proc `<`*[T: tuple](x, y: T): bool =
## generic ``<`` operator that is lifted from the components
## of `x` and `y`. This implementation uses `cmp`.
for a, b in fields(x, y):
var c = cmp(a, b)
if c < 0: return true
if c > 0: return false
return false
proc `$`*[T: tuple](x: T): string =
## generic ``$`` operator that is lifted from the components of `x`.
result = "("
for name, value in fieldPairs(x):
if result.len > 1: result.add(", ")
result.add(name)
result.add(": ")
result.add($value)
result.add(")")
# ----------------- GC interface ---------------------------------------------
proc GC_disable*() {.rtl, inl.}

View file

@ -1059,7 +1059,7 @@ type
TResponseType* = int32
PDialog* = ptr TDialog
TDialog* = object of TWindow
vbox*: PWidget
vbox*: PBox
action_area*: PWidget
separator*: PWidget
@ -16866,6 +16866,9 @@ proc set_do_overwrite_confirmation*(chooser: PFileChooser,
do_overwrite_confirmation: gboolean){.cdecl, dynlib: lib,
importc: "gtk_file_chooser_set_do_overwrite_confirmation".}
proc get_realized*(w: PWidget): gboolean {.cdecl, dynlib: lib,
importc: "gtk_widget_get_realized".}
proc nimrod_init*() =
var
cmdLine{.importc: "cmdLine".}: array[0..255, cstring]