explicit types for generic routines
This commit is contained in:
parent
e90665bff2
commit
6c20509121
25 changed files with 411 additions and 343 deletions
|
|
@ -9,8 +9,7 @@
|
|||
|
||||
|
||||
## This module implements portable dialogs for Nimrod; the implementation
|
||||
## builds on the GTK interface. On Windows, native dialogs are shown if
|
||||
## appropriate.
|
||||
## builds on the GTK interface. On Windows, native dialogs are shown instead.
|
||||
|
||||
import
|
||||
glib2, gtk2
|
||||
|
|
@ -174,7 +173,7 @@ proc ChooseFileToSave*(window: PWindow, root: string = ""): string =
|
|||
var chooser = file_chooser_dialog_new("Save File", window,
|
||||
FILE_CHOOSER_ACTION_SAVE,
|
||||
STOCK_CANCEL, RESPONSE_CANCEL,
|
||||
STOCK_OPEN, RESPONSE_OK, nil)
|
||||
STOCK_SAVE, RESPONSE_OK, nil)
|
||||
if root.len > 0:
|
||||
discard set_current_folder(chooser, root)
|
||||
set_do_overwrite_confirmation(chooser, true)
|
||||
|
|
|
|||
|
|
@ -24,6 +24,13 @@ __TINYC__
|
|||
|
||||
#if !defined(__TINYC__)
|
||||
# include <math.h>
|
||||
#else
|
||||
/*# define __GNUC__ 3
|
||||
# define GCC_MAJOR 4
|
||||
# define __GNUC_MINOR__ 4
|
||||
# define __GNUC_PATCHLEVEL__ 5 */
|
||||
|
||||
# define __DECLSPEC_SUPPORTED 1
|
||||
#endif
|
||||
|
||||
/* calling convention mess ----------------------------------------------- */
|
||||
|
|
|
|||
|
|
@ -953,8 +953,8 @@ proc parseCmdLine*(c: string): seq[string] =
|
|||
## causing a literal double quotation mark (") to be placed in argv.
|
||||
##
|
||||
## On Posix systems, it uses the following parsing rules:
|
||||
## components are separated by
|
||||
## whitespace unless the whitespace occurs within ``"`` or ``'`` quotes.
|
||||
## Components are separated by whitespace unless the whitespace
|
||||
## occurs within ``"`` or ``'`` quotes.
|
||||
result = @[]
|
||||
var i = 0
|
||||
var a = ""
|
||||
|
|
@ -963,6 +963,7 @@ proc parseCmdLine*(c: string): seq[string] =
|
|||
while c[i] == ' ' or c[i] == '\t': inc(i)
|
||||
when defined(windows):
|
||||
# parse a single argument according to the above rules:
|
||||
if c[i] == '\0': break
|
||||
var inQuote = false
|
||||
while true:
|
||||
case c[i]
|
||||
|
|
@ -971,7 +972,7 @@ proc parseCmdLine*(c: string): seq[string] =
|
|||
var j = i
|
||||
while c[j] == '\\': inc(j)
|
||||
if c[j] == '"':
|
||||
for k in 0..(j-i) div 2: a.add('\\')
|
||||
for k in 1..(j-i) div 2: a.add('\\')
|
||||
if (j-i) mod 2 == 0:
|
||||
i = j
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -26,6 +26,19 @@ type
|
|||
when defined(posix):
|
||||
type
|
||||
TTime* = distinct int ## distinct type that represents a time
|
||||
|
||||
Ttimeval {.importc: "struct timeval", header: "<sys/select.h>",
|
||||
final, pure.} = object ## struct timeval
|
||||
tv_sec: int ## Seconds.
|
||||
tv_usec: int ## Microseconds.
|
||||
|
||||
# we cannot import posix.nim here, because posix.nim depends on times.nim.
|
||||
# Ok, we could, but I don't want circular dependencies.
|
||||
# And gettimeofday() is not defined in the posix module anyway. Sigh.
|
||||
|
||||
proc posix_gettimeofday(tp: var Ttimeval, unused: pointer = nil) {.
|
||||
importc: "gettimeofday", header: "<sys/time.h>".}
|
||||
|
||||
elif defined(windows):
|
||||
when defined(vcc):
|
||||
# newest version of Visual C++ defines time_t to be of 64 bits
|
||||
|
|
@ -147,7 +160,7 @@ when not defined(ECMAScript):
|
|||
PTimeInfo = ptr structTM
|
||||
PTime = ptr TTime
|
||||
|
||||
TClock {.importc: "clock_t".} = range[low(int)..high(int)]
|
||||
TClock {.importc: "clock_t".} = distinct int #range[low(int)..high(int)]
|
||||
|
||||
proc localtime(timer: PTime): PTimeInfo {.
|
||||
importc: "localtime", header: "<time.h>".}
|
||||
|
|
@ -197,9 +210,17 @@ when not defined(ECMAScript):
|
|||
return toBiggestInt(difftime(a, b))
|
||||
|
||||
proc getStartMilsecs(): int =
|
||||
#echo "clocks per sec: ", clocksPerSec
|
||||
#echo "clocks per sec: ", clocksPerSec, "clock: ", int(clock())
|
||||
#return clock() div (clocksPerSec div 1000)
|
||||
result = toInt(toFloat(clock()) / (toFloat(clocksPerSec) / 1000.0))
|
||||
when defined(posix):
|
||||
var a: Ttimeval
|
||||
posix_gettimeofday(a)
|
||||
result = a.tv_sec * 1000 + a.tv_usec
|
||||
else:
|
||||
result = int(clock()) div (clocksPerSec div 1000)
|
||||
when false:
|
||||
when defined(macosx):
|
||||
result = toInt(toFloat(clock()) / (toFloat(clocksPerSec) / 1000.0))
|
||||
|
||||
proc getTime(): TTime = return timec(nil)
|
||||
proc getLocalTime(t: TTime): TTimeInfo =
|
||||
|
|
|
|||
|
|
@ -1176,3 +1176,5 @@ proc cmpRunesIgnoreCase*(a, b: string): int =
|
|||
if result != 0: return
|
||||
result = a.len - b.len
|
||||
|
||||
proc substringAt*(s, sub: string, start: int): int =
|
||||
|
||||
|
|
|
|||
|
|
@ -981,6 +981,9 @@ when not defined(NimrodVM):
|
|||
proc getCurrentExceptionMsg*(): string {.exportc.}
|
||||
## retrieves the error message that was attached to the current
|
||||
## exception; if there is none, "" is returned.
|
||||
|
||||
proc getCurrentException*(): ref E_Base
|
||||
## retrieves the current exception; if there is none, nil is returned.
|
||||
|
||||
# new constants:
|
||||
const
|
||||
|
|
@ -1390,6 +1393,13 @@ when not defined(EcmaScript) and not defined(NimrodVM):
|
|||
##
|
||||
## Default mode is readonly. Returns true iff the file could be opened.
|
||||
|
||||
proc reopen*(f: TFile, filename: string, mode: TFileMode = fmRead): bool
|
||||
## reopens the file `f` with given `filename` and `mode`. This
|
||||
## is often used to redirect the `stdin`, `stdout` or `stderr`
|
||||
## file variables.
|
||||
##
|
||||
## Default mode is readonly. Returns true iff the file could be reopened.
|
||||
|
||||
proc CloseFile*(f: TFile) {.importc: "fclose", nodecl, deprecated.}
|
||||
## Closes the file.
|
||||
## **Deprecated since version 0.8.0**: Use `close` instead.
|
||||
|
|
@ -1554,6 +1564,7 @@ when not defined(EcmaScript) and not defined(NimrodVM):
|
|||
else:
|
||||
result = n.sons[n.len]
|
||||
|
||||
include "system/systhread"
|
||||
include "system/mm"
|
||||
include "system/sysstr"
|
||||
include "system/assign"
|
||||
|
|
@ -1564,6 +1575,10 @@ when not defined(EcmaScript) and not defined(NimrodVM):
|
|||
if excHandler == nil: return ""
|
||||
return $excHandler.exc.msg
|
||||
|
||||
proc getCurrentException(): ref E_Base =
|
||||
if excHandler != nil:
|
||||
result = excHandler.exc
|
||||
|
||||
{.push stack_trace: off.}
|
||||
when defined(endb):
|
||||
include "system/debugger"
|
||||
|
|
|
|||
|
|
@ -376,10 +376,10 @@ proc freeBigChunk(a: var TAllocator, c: PBigChunk) =
|
|||
|
||||
proc splitChunk(a: var TAllocator, c: PBigChunk, size: int) =
|
||||
var rest = cast[PBigChunk](cast[TAddress](c) +% size)
|
||||
if rest in a.freeChunksList:
|
||||
c_fprintf(c_stdout, "to add: %p\n", rest)
|
||||
writeFreeList(allocator)
|
||||
assert false
|
||||
assert(rest notin a.freeChunksList)
|
||||
# c_fprintf(c_stdout, "to add: %p\n", rest)
|
||||
# writeFreeList(allocator)
|
||||
# assert false
|
||||
rest.size = c.size - size
|
||||
rest.used = false
|
||||
rest.next = nil
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#
|
||||
#
|
||||
# Nimrod's Runtime Library
|
||||
# (c) Copyright 2009 Andreas Rumpf
|
||||
# (c) Copyright 2010 Andreas Rumpf
|
||||
#
|
||||
# See the file "copying.txt", included in this
|
||||
# distribution, for details about the copyright.
|
||||
|
|
@ -478,6 +478,10 @@ proc gcMark(p: pointer) {.inline.} =
|
|||
cell.refcount = cell.refcount +% rcIncrement
|
||||
add(gch.decStack, cell)
|
||||
|
||||
proc markThreadStacks(gch: var TGcHeap) =
|
||||
when isMultiThreaded:
|
||||
nil
|
||||
|
||||
# ----------------- stack management --------------------------------------
|
||||
# inspired from Smart Eiffel
|
||||
|
||||
|
|
@ -613,6 +617,7 @@ proc collectCT(gch: var TGcHeap) =
|
|||
gch.stat.maxStackSize = max(gch.stat.maxStackSize, stackSize())
|
||||
assert(gch.decStack.len == 0)
|
||||
markStackAndRegisters(gch)
|
||||
markThreadStacks(gch)
|
||||
gch.stat.maxStackCells = max(gch.stat.maxStackCells, gch.decStack.len)
|
||||
inc(gch.stat.stackScans)
|
||||
collectZCT(gch)
|
||||
|
|
|
|||
|
|
@ -27,6 +27,9 @@ proc strlen(c: cstring): int {.importc: "strlen", nodecl.}
|
|||
proc setvbuf(stream: TFile, buf: pointer, typ, size: cint): cint {.
|
||||
importc, nodecl.}
|
||||
|
||||
proc freopen(path, mode: cstring, stream: TFile): TFile {.importc: "freopen",
|
||||
nodecl.}
|
||||
|
||||
proc write(f: TFile, c: cstring) = fputs(c, f)
|
||||
|
||||
var
|
||||
|
|
@ -112,9 +115,7 @@ const
|
|||
proc Open(f: var TFile, filename: string,
|
||||
mode: TFileMode = fmRead,
|
||||
bufSize: int = -1): Bool =
|
||||
var
|
||||
p: pointer
|
||||
p = fopen(filename, FormatOpen[mode])
|
||||
var p: pointer = fopen(filename, FormatOpen[mode])
|
||||
result = (p != nil)
|
||||
f = cast[TFile](p)
|
||||
if bufSize > 0:
|
||||
|
|
@ -123,6 +124,10 @@ proc Open(f: var TFile, filename: string,
|
|||
elif bufSize == 0:
|
||||
discard setvbuf(f, nil, IONBF, 0)
|
||||
|
||||
proc reopen(f: TFile, filename: string, mode: TFileMode = fmRead): bool =
|
||||
var p: pointer = freopen(filename, FormatOpen[mode], f)
|
||||
result = p != nil
|
||||
|
||||
proc fdopen(filehandle: TFileHandle, mode: cstring): TFile {.
|
||||
importc: pccHack & "fdopen", header: "<stdio.h>".}
|
||||
|
||||
|
|
|
|||
|
|
@ -278,7 +278,7 @@ elif defined(macosx):
|
|||
LibName = "libSDL-1.2.0.dylib"
|
||||
else:
|
||||
const
|
||||
LibName = "libSDL.so"
|
||||
LibName = "libSDL.so(|.1|.0)"
|
||||
const
|
||||
MAJOR_VERSION* = 1'i8
|
||||
MINOR_VERSION* = 2'i8
|
||||
|
|
|
|||
|
|
@ -163,7 +163,7 @@ elif defined(macosx):
|
|||
ttfLibName = "libSDL_ttf-2.0.0.dylib"
|
||||
else:
|
||||
const
|
||||
ttfLibName = "libSDL_ttf.so"
|
||||
ttfLibName = "libSDL_ttf.so(|.1|.0)"
|
||||
const
|
||||
MAJOR_VERSION* = 2'i8
|
||||
MINOR_VERSION* = 0'i8
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue