version 0.7.0

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

View file

@ -47,7 +47,7 @@ else:
# only Mac OS X has this shit
proc c_longjmp(jmpb: C_JmpBuf, retval: cint) {.nodecl, importc: "longjmp".}
proc c_setjmp(jmpb: var C_JmpBuf) {.nodecl, importc: "setjmp".}
proc c_setjmp(jmpb: var C_JmpBuf): cint {.nodecl, importc: "setjmp".}
proc c_signal(sig: cint, handler: proc (a: cint) {.noconv.}) {.
importc: "signal", header: "<signal.h>".}

View file

@ -1,7 +1,7 @@
#
#
# Nimrod's Runtime Library
# (c) Copyright 2006 Andreas Rumpf
# (c) Copyright 2008 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
@ -10,11 +10,11 @@
# simple integer arithmetic with overflow checking
proc raiseOverflow {.exportc: "raiseOverflow".} =
proc raiseOverflow {.compilerproc, noinline.} =
# a single proc to reduce code size to a minimum
raise newException(EOverflow, "over- or underflow")
proc raiseDivByZero {.exportc: "raiseDivByZero".} =
proc raiseDivByZero {.exportc: "raiseDivByZero", noinline.} =
raise newException(EDivByZero, "divison by zero")
proc addInt64(a, b: int64): int64 {.compilerProc, inline.} =
@ -75,9 +75,9 @@ proc mulInt64(a, b: int64): int64 {.compilerproc.} =
var
resAsFloat, floatProd: float64
result = a *% b
floatProd = float64(a) # conversion
floatProd = floatProd * float64(b)
resAsFloat = float64(result)
floatProd = toBiggestFloat(a) # conversion
floatProd = floatProd * toBiggestFloat(b)
resAsFloat = toBiggestFloat(result)
# Fast path for normal case: small multiplicands, and no info
# is lost in either method.
@ -101,16 +101,14 @@ proc absInt(a: int): int {.compilerProc, inline.} =
else: return -a
raiseOverflow()
when defined(I386) and (defined(vcc) or defined(wcc) or defined(dmc)):
# or defined(gcc)):
{.define: asmVersion.}
# my Version of Borland C++Builder does not have
# tasm32, which is needed for assembler blocks
# this is why Borland is not included in the 'when'
else:
{.define: useInline.}
const
asmVersion = defined(I386) and (defined(vcc) or defined(wcc) or defined(dmc))
# my Version of Borland C++Builder does not have
# tasm32, which is needed for assembler blocks
# this is why Borland is not included in the 'when'
useInline = not asmVersion
when defined(asmVersion) and defined(gcc):
when asmVersion and defined(gcc):
proc addInt(a, b: int): int {.compilerProc, pure, inline.}
proc subInt(a, b: int): int {.compilerProc, pure, inline.}
proc mulInt(a, b: int): int {.compilerProc, pure, inline.}
@ -118,7 +116,7 @@ when defined(asmVersion) and defined(gcc):
proc modInt(a, b: int): int {.compilerProc, pure, inline.}
proc negInt(a: int): int {.compilerProc, pure, inline.}
elif defined(asmVersion):
elif asmVersion:
proc addInt(a, b: int): int {.compilerProc, pure.}
proc subInt(a, b: int): int {.compilerProc, pure.}
proc mulInt(a, b: int): int {.compilerProc, pure.}
@ -126,7 +124,7 @@ elif defined(asmVersion):
proc modInt(a, b: int): int {.compilerProc, pure.}
proc negInt(a: int): int {.compilerProc, pure.}
elif defined(useInline):
elif useInline:
proc addInt(a, b: int): int {.compilerProc, inline.}
proc subInt(a, b: int): int {.compilerProc, inline.}
proc mulInt(a, b: int): int {.compilerProc.}
@ -145,7 +143,7 @@ else:
# implementation:
when defined(asmVersion) and not defined(gcc):
when asmVersion and not defined(gcc):
# assembler optimized versions for compilers that
# have an intel syntax assembler:
proc addInt(a, b: int): int =
@ -210,7 +208,7 @@ when defined(asmVersion) and not defined(gcc):
theEnd:
"""
elif defined(asmVersion) and defined(gcc):
elif asmVersion and defined(gcc):
proc addInt(a, b: int): int =
asm """ "addl %1,%%eax\n"
"jno 1\n"

View file

@ -1,120 +1,120 @@
#
#
# Nimrod's Runtime Library
# (c) Copyright 2006 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
#when defined(debugGC):
# {.define: logAssign.}
proc genericAssign(dest, src: Pointer, mt: PNimType) {.compilerProc.}
proc genericAssignAux(dest, src: Pointer, n: ptr TNimNode) =
var
d = cast[TAddress](dest)
s = cast[TAddress](src)
case n.kind
of nkNone: assert(false)
of nkSlot:
genericAssign(cast[pointer](d +% n.offset), cast[pointer](s +% n.offset),
n.typ)
of nkList:
for i in 0..n.len-1:
genericAssignAux(dest, src, n.sons[i])
of nkCase:
copyMem(cast[pointer](d +% n.offset), cast[pointer](s +% n.offset),
n.typ.size)
var m = selectBranch(src, n)
if m != nil: genericAssignAux(dest, src, m)
proc genericAssign(dest, src: Pointer, mt: PNimType) =
var
d = cast[TAddress](dest)
s = cast[TAddress](src)
assert(mt != nil)
case mt.Kind
of tySequence:
var s2 = cast[ppointer](src)^
var seq = cast[PGenericSeq](s2)
if s2 == nil: # this can happen! nil sequences are allowed
var x = cast[ppointer](dest)
x^ = nil
return
assert(dest != nil)
unsureAsgnRef(cast[ppointer](dest),
newObj(mt, seq.len * mt.base.size + GenericSeqSize))
var dst = cast[taddress](cast[ppointer](dest)^)
for i in 0..seq.len-1:
genericAssign(
cast[pointer](dst +% i*% mt.base.size +% GenericSeqSize),
cast[pointer](cast[taddress](s2) +% i *% mt.base.size +%
GenericSeqSize),
mt.Base)
var dstseq = cast[PGenericSeq](dst)
dstseq.len = seq.len
dstseq.space = seq.len
of tyObject, tyTuple, tyPureObject:
# we don't need to copy m_type field for tyObject, as they are equal anyway
genericAssignAux(dest, src, mt.node)
of tyArray, tyArrayConstr:
for i in 0..(mt.size div mt.base.size)-1:
genericAssign(cast[pointer](d +% i*% mt.base.size),
cast[pointer](s +% i*% mt.base.size), mt.base)
of tyString: # a leaf
var s2 = cast[ppointer](s)^
if s2 != nil: # nil strings are possible!
unsureAsgnRef(cast[ppointer](dest), copyString(cast[mstring](s2)))
else:
var x = cast[ppointer](dest)
x^ = nil
return
of tyRef: # BUGFIX: a long time this has been forgotten!
unsureAsgnRef(cast[ppointer](dest), cast[ppointer](s)^)
else:
copyMem(dest, src, mt.size) # copy raw bits
proc genericSeqAssign(dest, src: Pointer, mt: PNimType) {.compilerProc.} =
var src = src # ugly, but I like to stress the parser sometimes :-)
genericAssign(dest, addr(src), mt)
proc genericAssignOpenArray(dest, src: pointer, len: int,
mt: PNimType) {.compilerproc.} =
var
d = cast[TAddress](dest)
s = cast[TAddress](src)
for i in 0..len-1:
genericAssign(cast[pointer](d +% i*% mt.base.size),
cast[pointer](s +% i*% mt.base.size), mt.base)
proc objectInit(dest: Pointer, typ: PNimType) {.compilerProc.}
proc objectInitAux(dest: Pointer, n: ptr TNimNode) =
var d = cast[TAddress](dest)
case n.kind
of nkNone: assert(false)
of nkSLot: objectInit(cast[pointer](d +% n.offset), n.typ)
of nkList:
for i in 0..n.len-1:
objectInitAux(dest, n.sons[i])
of nkCase:
var m = selectBranch(dest, n)
if m != nil: objectInitAux(dest, m)
proc objectInit(dest: Pointer, typ: PNimType) =
# the generic init proc that takes care of initialization of complex
# objects on the stack or heap
var d = cast[TAddress](dest)
case typ.kind
of tyObject:
# iterate over any structural type
# here we have to init the type field:
var pint = cast[ptr PNimType](dest)
pint^ = typ
objectInitAux(dest, typ.node)
of tyTuple, tyPureObject:
objectInitAux(dest, typ.node)
of tyArray, tyArrayConstr:
for i in 0..(typ.size div typ.base.size)-1:
objectInit(cast[pointer](d +% i * typ.base.size), typ.base)
else: nil # nothing to do
#
#
# Nimrod's Runtime Library
# (c) Copyright 2006 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
#when defined(debugGC):
# {.define: logAssign.}
proc genericAssign(dest, src: Pointer, mt: PNimType) {.compilerProc.}
proc genericAssignAux(dest, src: Pointer, n: ptr TNimNode) =
var
d = cast[TAddress](dest)
s = cast[TAddress](src)
case n.kind
of nkNone: assert(false)
of nkSlot:
genericAssign(cast[pointer](d +% n.offset), cast[pointer](s +% n.offset),
n.typ)
of nkList:
for i in 0..n.len-1:
genericAssignAux(dest, src, n.sons[i])
of nkCase:
copyMem(cast[pointer](d +% n.offset), cast[pointer](s +% n.offset),
n.typ.size)
var m = selectBranch(src, n)
if m != nil: genericAssignAux(dest, src, m)
proc genericAssign(dest, src: Pointer, mt: PNimType) =
var
d = cast[TAddress](dest)
s = cast[TAddress](src)
assert(mt != nil)
case mt.Kind
of tySequence:
var s2 = cast[ppointer](src)^
var seq = cast[PGenericSeq](s2)
if s2 == nil: # this can happen! nil sequences are allowed
var x = cast[ppointer](dest)
x^ = nil
return
assert(dest != nil)
unsureAsgnRef(cast[ppointer](dest),
newObj(mt, seq.len * mt.base.size + GenericSeqSize))
var dst = cast[taddress](cast[ppointer](dest)^)
for i in 0..seq.len-1:
genericAssign(
cast[pointer](dst +% i*% mt.base.size +% GenericSeqSize),
cast[pointer](cast[taddress](s2) +% i *% mt.base.size +%
GenericSeqSize),
mt.Base)
var dstseq = cast[PGenericSeq](dst)
dstseq.len = seq.len
dstseq.space = seq.len
of tyObject, tyTuple, tyPureObject:
# we don't need to copy m_type field for tyObject, as they are equal anyway
genericAssignAux(dest, src, mt.node)
of tyArray, tyArrayConstr:
for i in 0..(mt.size div mt.base.size)-1:
genericAssign(cast[pointer](d +% i*% mt.base.size),
cast[pointer](s +% i*% mt.base.size), mt.base)
of tyString: # a leaf
var s2 = cast[ppointer](s)^
if s2 != nil: # nil strings are possible!
unsureAsgnRef(cast[ppointer](dest), copyString(cast[NimString](s2)))
else:
var x = cast[ppointer](dest)
x^ = nil
return
of tyRef: # BUGFIX: a long time this has been forgotten!
unsureAsgnRef(cast[ppointer](dest), cast[ppointer](s)^)
else:
copyMem(dest, src, mt.size) # copy raw bits
proc genericSeqAssign(dest, src: Pointer, mt: PNimType) {.compilerProc.} =
var src = src # ugly, but I like to stress the parser sometimes :-)
genericAssign(dest, addr(src), mt)
proc genericAssignOpenArray(dest, src: pointer, len: int,
mt: PNimType) {.compilerproc.} =
var
d = cast[TAddress](dest)
s = cast[TAddress](src)
for i in 0..len-1:
genericAssign(cast[pointer](d +% i*% mt.base.size),
cast[pointer](s +% i*% mt.base.size), mt.base)
proc objectInit(dest: Pointer, typ: PNimType) {.compilerProc.}
proc objectInitAux(dest: Pointer, n: ptr TNimNode) =
var d = cast[TAddress](dest)
case n.kind
of nkNone: assert(false)
of nkSLot: objectInit(cast[pointer](d +% n.offset), n.typ)
of nkList:
for i in 0..n.len-1:
objectInitAux(dest, n.sons[i])
of nkCase:
var m = selectBranch(dest, n)
if m != nil: objectInitAux(dest, m)
proc objectInit(dest: Pointer, typ: PNimType) =
# the generic init proc that takes care of initialization of complex
# objects on the stack or heap
var d = cast[TAddress](dest)
case typ.kind
of tyObject:
# iterate over any structural type
# here we have to init the type field:
var pint = cast[ptr PNimType](dest)
pint^ = typ
objectInitAux(dest, typ.node)
of tyTuple, tyPureObject:
objectInitAux(dest, typ.node)
of tyArray, tyArrayConstr:
for i in 0..(typ.size div typ.base.size)-1:
objectInit(cast[pointer](d +% i * typ.base.size), typ.base)
else: nil # nothing to do

View file

@ -58,7 +58,7 @@ else:
type
PByte = cstring
cairo_status_t* = enum
TCairoStatus* = enum
CAIRO_STATUS_SUCCESS = 0, CAIRO_STATUS_NO_MEMORY,
CAIRO_STATUS_INVALID_RESTORE, CAIRO_STATUS_INVALID_POP_GROUP,
CAIRO_STATUS_NO_CURRENT_POINT, CAIRO_STATUS_INVALID_MATRIX,
@ -69,93 +69,93 @@ type
CAIRO_STATUS_PATTERN_TYPE_MISMATCH, CAIRO_STATUS_INVALID_CONTENT,
CAIRO_STATUS_INVALID_FORMAT, CAIRO_STATUS_INVALID_VISUAL,
CAIRO_STATUS_FILE_NOT_FOUND, CAIRO_STATUS_INVALID_DASH
cairo_operator_t* = enum
TCairoOperator* = enum
CAIRO_OPERATOR_CLEAR, CAIRO_OPERATOR_SOURCE, CAIRO_OPERATOR_OVER,
CAIRO_OPERATOR_IN, CAIRO_OPERATOR_OUT, CAIRO_OPERATOR_ATOP,
CAIRO_OPERATOR_DEST, CAIRO_OPERATOR_DEST_OVER, CAIRO_OPERATOR_DEST_IN,
CAIRO_OPERATOR_DEST_OUT, CAIRO_OPERATOR_DEST_ATOP, CAIRO_OPERATOR_XOR,
CAIRO_OPERATOR_ADD, CAIRO_OPERATOR_SATURATE
cairo_antialias_t* = enum
TCairoAntialias* = enum
CAIRO_ANTIALIAS_DEFAULT, CAIRO_ANTIALIAS_NONE, CAIRO_ANTIALIAS_GRAY,
CAIRO_ANTIALIAS_SUBPIXEL
cairo_fill_rule_t* = enum
TCairoFillRule* = enum
CAIRO_FILL_RULE_WINDING, CAIRO_FILL_RULE_EVEN_ODD
cairo_line_cap_t* = enum
TCairoLineCap* = enum
CAIRO_LINE_CAP_BUTT, CAIRO_LINE_CAP_ROUND, CAIRO_LINE_CAP_SQUARE
cairo_line_join_t* = enum
TCairoLineJoin* = enum
CAIRO_LINE_JOIN_MITER, CAIRO_LINE_JOIN_ROUND, CAIRO_LINE_JOIN_BEVEL
cairo_font_slant_t* = enum
TCairoFontSlant* = enum
CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_SLANT_ITALIC, CAIRO_FONT_SLANT_OBLIQUE
cairo_font_weight_t* = enum
TCairoFontWeight* = enum
CAIRO_FONT_WEIGHT_NORMAL, CAIRO_FONT_WEIGHT_BOLD
cairo_subpixel_order_t* = enum
TCairoSubpixelOrder* = enum
CAIRO_SUBPIXEL_ORDER_DEFAULT, CAIRO_SUBPIXEL_ORDER_RGB,
CAIRO_SUBPIXEL_ORDER_BGR, CAIRO_SUBPIXEL_ORDER_VRGB,
CAIRO_SUBPIXEL_ORDER_VBGR
cairo_hint_style_t* = enum
TCairoHintStyle* = enum
CAIRO_HINT_STYLE_DEFAULT, CAIRO_HINT_STYLE_NONE, CAIRO_HINT_STYLE_SLIGHT,
CAIRO_HINT_STYLE_MEDIUM, CAIRO_HINT_STYLE_FULL
cairo_hint_metrics_t* = enum
TCairoHintMetrics* = enum
CAIRO_HINT_METRICS_DEFAULT, CAIRO_HINT_METRICS_OFF, CAIRO_HINT_METRICS_ON
cairo_path_data_type_t* = enum
TCairoPathDataType* = enum
CAIRO_PATH_MOVE_TO, CAIRO_PATH_LINE_TO, CAIRO_PATH_CURVE_TO,
CAIRO_PATH_CLOSE_PATH
cairo_content_t* = enum
TCairoContent* = enum
CAIRO_CONTENT_COLOR = 0x00001000, CAIRO_CONTENT_ALPHA = 0x00002000,
CAIRO_CONTENT_COLOR_ALPHA = 0x00003000
cairo_format_t* = enum
TCairoFormat* = enum
CAIRO_FORMAT_ARGB32, CAIRO_FORMAT_RGB24, CAIRO_FORMAT_A8, CAIRO_FORMAT_A1
cairo_extend_t* = enum
TCairoExtend* = enum
CAIRO_EXTEND_NONE, CAIRO_EXTEND_REPEAT, CAIRO_EXTEND_REFLECT,
CAIRO_EXTEND_PAD
cairo_filter_t* = enum
TCairoFilter* = enum
CAIRO_FILTER_FAST, CAIRO_FILTER_GOOD, CAIRO_FILTER_BEST,
CAIRO_FILTER_NEAREST, CAIRO_FILTER_BILINEAR, CAIRO_FILTER_GAUSSIAN
cairo_font_type_t* = enum
TCairoFontType* = enum
CAIRO_FONT_TYPE_TOY, CAIRO_FONT_TYPE_FT, CAIRO_FONT_TYPE_WIN32,
CAIRO_FONT_TYPE_ATSUI
cairo_pattern_type_t* = enum
TCairoPatternType* = enum
CAIRO_PATTERN_TYPE_SOLID, CAIRO_PATTERN_TYPE_SURFACE,
CAIRO_PATTERN_TYPE_LINEAR, CAIRO_PATTERN_TYPE_RADIAL
cairo_surface_type_t* = enum
TCairoSurfaceType* = enum
CAIRO_SURFACE_TYPE_IMAGE, CAIRO_SURFACE_TYPE_PDF, CAIRO_SURFACE_TYPE_PS,
CAIRO_SURFACE_TYPE_XLIB, CAIRO_SURFACE_TYPE_XCB, CAIRO_SURFACE_TYPE_GLITZ,
CAIRO_SURFACE_TYPE_QUARTZ, CAIRO_SURFACE_TYPE_WIN32,
CAIRO_SURFACE_TYPE_BEOS, CAIRO_SURFACE_TYPE_DIRECTFB,
CAIRO_SURFACE_TYPE_SVG, CAIRO_SURFACE_TYPE_OS2
cairo_svg_version_t* = enum
TCairoSvgVersion* = enum
CAIRO_SVG_VERSION_1_1, CAIRO_SVG_VERSION_1_2
Pcairo_surface_t* = ref cairo_surface_t
PPcairo_surface_t* = ref Pcairo_surface_t
Pcairo_t* = ref cairo_t
Pcairo_pattern_t* = ref cairo_pattern_t
Pcairo_font_options_t* = ref cairo_font_options_t
Pcairo_font_face_t* = ref cairo_font_face_t
Pcairo_scaled_font_t* = ref cairo_scaled_font_t
Pcairo_bool_t* = ref cairo_bool_t
cairo_bool_t* = int32
Pcairo_matrix_t* = ref cairo_matrix_t
Pcairo_user_data_key_t* = ref cairo_user_data_key_t
Pcairo_glyph_t* = ref cairo_glyph_t
Pcairo_text_extents_t* = ref cairo_text_extents_t
Pcairo_font_extents_t* = ref cairo_font_extents_t
Pcairo_path_data_type_t* = ref cairo_path_data_type_t
Pcairo_path_data_t* = ref cairo_path_data_t
Pcairo_path_t* = ref cairo_path_t
Pcairo_rectangle_t* = ref cairo_rectangle_t
Pcairo_rectangle_list_t* = ref cairo_rectangle_list_t
cairo_destroy_func_t* = proc (data: Pointer){.cdecl.}
cairo_write_func_t* = proc (closure: Pointer, data: PByte, len: int32): cairo_status_t{.
PCairoSurface* = ptr TCairoSurface
PPCairoSurface* = ptr PCairoSurface
PCairo* = ptr TCairo
PCairoPattern* = ptr TCairoPattern
PCairoFontOptions* = ptr TCairoFontOptions
PCairoFontFace* = ptr TCairoFontFace
PCairoScaledFont* = ptr TCairoScaledFont
PCairoBool* = ptr TCairoBool
TCairoBool* = int32
PCairoMatrix* = ptr TCairoMatrix
PCairoUserDataKey* = ptr TCairoUserDataKey
PCairoGlyph* = ptr TCairoGlyph
PCairoTextExtents* = ptr TCairoTextExtents
PCairoFontExtents* = ptr TCairoFontExtents
PCairoPathDataType* = ptr TCairoPathDataType
PCairoPathData* = ptr TCairoPathData
PCairoPath* = ptr TCairoPath
PCairoRectangle* = ptr TCairoRectangle
PCairoRectangleList* = ptr TCairoRectangleList
TCairoDestroyFunc* = proc (data: Pointer){.cdecl.}
TCairoWriteFunc* = proc (closure: Pointer, data: PByte, len: int32): TCairoStatus{.
cdecl.}
cairo_read_func_t* = proc (closure: Pointer, data: PByte, len: int32): cairo_status_t{.
TCairoReadFunc* = proc (closure: Pointer, data: PByte, len: int32): TCairoStatus{.
cdecl.}
cairo_t* {.final.} = object #OPAQUE
cairo_surface_t* {.final.} = object #OPAQUE
cairo_pattern_t* {.final.} = object #OPAQUE
cairo_scaled_font_t* {.final.} = object #OPAQUE
cairo_font_face_t* {.final.} = object #OPAQUE
cairo_font_options_t* {.final.} = object #OPAQUE
cairo_matrix_t* {.final.} = object
TCairo* {.final.} = object #OPAQUE
TCairoSurface* {.final.} = object #OPAQUE
TCairoPattern* {.final.} = object #OPAQUE
TCairoScaledFont* {.final.} = object #OPAQUE
TCairoFontFace* {.final.} = object #OPAQUE
TCairoFontOptions* {.final.} = object #OPAQUE
TCairoMatrix* {.final.} = object
xx: float64
yx: float64
xy: float64
@ -163,15 +163,15 @@ type
x0: float64
y0: float64
cairo_user_data_key_t* {.final.} = object
TCairoUserDataKey* {.final.} = object
unused: int32
cairo_glyph_t* {.final.} = object
TCairoGlyph* {.final.} = object
index: int32
x: float64
y: float64
cairo_text_extents_t* {.final.} = object
TCairoTextExtents* {.final.} = object
x_bearing: float64
y_bearing: float64
width: float64
@ -179,30 +179,30 @@ type
x_advance: float64
y_advance: float64
cairo_font_extents_t* {.final.} = object
TCairoFontExtents* {.final.} = object
ascent: float64
descent: float64
height: float64
max_x_advance: float64
max_y_advance: float64
cairo_path_data_t* {.final.} = object #* _type : cairo_path_data_type_t;
# length : LongInt;
# end
TCairoPathData* {.final.} = object #* _type : TCairoPathDataType;
# length : LongInt;
# end
x: float64
y: float64
cairo_path_t* {.final.} = object
status: cairo_status_t
data: Pcairo_path_data_t
TCairoPath* {.final.} = object
status: TCairoStatus
data: PCairoPathData
num_data: int32
cairo_rectangle_t* {.final.} = object
TCairoRectangle* {.final.} = object
x, y, width, height: float64
cairo_rectangle_list_t* {.final.} = object
status: cairo_status_t
rectangles: Pcairo_rectangle_t
TCairoRectangleList* {.final.} = object
status: TCairoStatus
rectangles: PCairoRectangle
num_rectangles: int32
@ -211,480 +211,480 @@ proc cairo_version_string*(): cstring{.cdecl, importc, dynlib: LIB_CAIRO.}
#Helper function to retrieve decoded version
proc cairo_version*(major, minor, micro: var int32)
#* Functions for manipulating state objects
proc cairo_create*(target: Pcairo_surface_t): Pcairo_t{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_reference*(cr: Pcairo_t): Pcairo_t{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_destroy*(cr: Pcairo_t){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_get_reference_count*(cr: Pcairo_t): int32{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_get_user_data*(cr: Pcairo_t, key: Pcairo_user_data_key_t): pointer{.
proc cairo_create*(target: PCairoSurface): PCairo{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_reference*(cr: PCairo): PCairo{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_destroy*(cr: PCairo){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_get_reference_count*(cr: PCairo): int32{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_get_user_data*(cr: PCairo, key: PCairoUserDataKey): pointer{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_set_user_data*(cr: PCairo_t, key: Pcairo_user_data_key_t,
user_data: Pointer, destroy: cairo_destroy_func_t): cairo_status_t{.
proc cairo_set_user_data*(cr: PCairo, key: PCairoUserDataKey,
user_data: Pointer, destroy: TCairoDestroyFunc): TCairoStatus{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_save*(cr: Pcairo_t){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_restore*(cr: Pcairo_t){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_push_group*(cr: PCairo_t){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_push_group_with_content*(cr: PCairo_t, content: cairo_content_t){.
proc cairo_save*(cr: PCairo){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_restore*(cr: PCairo){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_push_group*(cr: PCairo){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_push_group_with_content*(cr: PCairo, content: TCairoContent){.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_pop_group*(cr: PCairo_t): Pcairo_pattern_t{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_pop_group_to_source*(cr: PCairo_t){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_pop_group*(cr: PCairo): PCairoPattern{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_pop_group_to_source*(cr: PCairo){.cdecl, importc, dynlib: LIB_CAIRO.}
#* Modify state
proc cairo_set_operator*(cr: Pcairo_t, op: cairo_operator_t){.cdecl, importc,
proc cairo_set_operator*(cr: PCairo, op: TCairoOperator){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_set_source*(cr: Pcairo_t, source: Pcairo_pattern_t){.cdecl, importc,
proc cairo_set_source*(cr: PCairo, source: PCairoPattern){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_set_source_rgb*(cr: Pcairo_t, red, green, blue: float64){.cdecl, importc,
proc cairo_set_source_rgb*(cr: PCairo, red, green, blue: float64){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_set_source_rgba*(cr: Pcairo_t, red, green, blue, alpha: float64){.
proc cairo_set_source_rgba*(cr: PCairo, red, green, blue, alpha: float64){.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_set_source_surface*(cr: Pcairo_t, surface: Pcairo_surface_t,
proc cairo_set_source_surface*(cr: PCairo, surface: PCairoSurface,
x, y: float64){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_set_tolerance*(cr: Pcairo_t, tolerance: float64){.cdecl, importc,
proc cairo_set_tolerance*(cr: PCairo, tolerance: float64){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_set_antialias*(cr: Pcairo_t, antialias: cairo_antialias_t){.cdecl, importc,
proc cairo_set_antialias*(cr: PCairo, antialias: TCairoAntialias){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_set_fill_rule*(cr: Pcairo_t, fill_rule: cairo_fill_rule_t){.cdecl, importc,
proc cairo_set_fill_rule*(cr: PCairo, fill_rule: TCairoFillRule){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_set_line_width*(cr: Pcairo_t, width: float64){.cdecl, importc,
proc cairo_set_line_width*(cr: PCairo, width: float64){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_set_line_cap*(cr: Pcairo_t, line_cap: cairo_line_cap_t){.cdecl, importc,
proc cairo_set_line_cap*(cr: PCairo, line_cap: TCairoLineCap){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_set_line_join*(cr: Pcairo_t, line_join: cairo_line_join_t){.cdecl, importc,
proc cairo_set_line_join*(cr: PCairo, line_join: TCairoLineJoin){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_set_dash*(cr: Pcairo_t, dashes: openarray[float64],
proc cairo_set_dash*(cr: PCairo, dashes: openarray[float64],
offset: float64){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_set_miter_limit*(cr: Pcairo_t, limit: float64){.cdecl, importc,
proc cairo_set_miter_limit*(cr: PCairo, limit: float64){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_translate*(cr: Pcairo_t, tx, ty: float64){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_scale*(cr: Pcairo_t, sx, sy: float64){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_rotate*(cr: Pcairo_t, angle: float64){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_transform*(cr: Pcairo_t, matrix: Pcairo_matrix_t){.cdecl, importc,
proc cairo_translate*(cr: PCairo, tx, ty: float64){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_scale*(cr: PCairo, sx, sy: float64){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_rotate*(cr: PCairo, angle: float64){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_transform*(cr: PCairo, matrix: PCairoMatrix){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_set_matrix*(cr: Pcairo_t, matrix: Pcairo_matrix_t){.cdecl, importc,
proc cairo_set_matrix*(cr: PCairo, matrix: PCairoMatrix){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_identity_matrix*(cr: Pcairo_t){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_user_to_device*(cr: Pcairo_t, x, y: var float64){.cdecl, importc,
proc cairo_identity_matrix*(cr: PCairo){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_user_to_device*(cr: PCairo, x, y: var float64){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_user_to_device_distance*(cr: Pcairo_t, dx, dy: var float64){.cdecl, importc,
proc cairo_user_to_device_distance*(cr: PCairo, dx, dy: var float64){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_device_to_user*(cr: Pcairo_t, x, y: var float64){.cdecl, importc,
proc cairo_device_to_user*(cr: PCairo, x, y: var float64){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_device_to_user_distance*(cr: Pcairo_t, dx, dy: var float64){.cdecl, importc,
proc cairo_device_to_user_distance*(cr: PCairo, dx, dy: var float64){.cdecl, importc,
dynlib: LIB_CAIRO.}
#* Path creation functions
proc cairo_new_path*(cr: Pcairo_t){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_move_to*(cr: Pcairo_t, x, y: float64){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_new_sub_path*(cr: Pcairo_t){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_line_to*(cr: Pcairo_t, x, y: float64){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_curve_to*(cr: Pcairo_t, x1, y1, x2, y2, x3, y3: float64){.cdecl, importc,
proc cairo_new_path*(cr: PCairo){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_move_to*(cr: PCairo, x, y: float64){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_new_sub_path*(cr: PCairo){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_line_to*(cr: PCairo, x, y: float64){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_curve_to*(cr: PCairo, x1, y1, x2, y2, x3, y3: float64){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_arc*(cr: Pcairo_t, xc, yc, radius, angle1, angle2: float64){.cdecl, importc,
proc cairo_arc*(cr: PCairo, xc, yc, radius, angle1, angle2: float64){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_arc_negative*(cr: Pcairo_t, xc, yc, radius, angle1, angle2: float64){.
proc cairo_arc_negative*(cr: PCairo, xc, yc, radius, angle1, angle2: float64){.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_rel_move_to*(cr: Pcairo_t, dx, dy: float64){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_rel_line_to*(cr: Pcairo_t, dx, dy: float64){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_rel_curve_to*(cr: Pcairo_t, dx1, dy1, dx2, dy2, dx3, dy3: float64){.
proc cairo_rel_move_to*(cr: PCairo, dx, dy: float64){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_rel_line_to*(cr: PCairo, dx, dy: float64){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_rel_curve_to*(cr: PCairo, dx1, dy1, dx2, dy2, dx3, dy3: float64){.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_rectangle*(cr: Pcairo_t, x, y, width, height: float64){.cdecl, importc,
proc cairo_rectangle*(cr: PCairo, x, y, width, height: float64){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_close_path*(cr: Pcairo_t){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_close_path*(cr: PCairo){.cdecl, importc, dynlib: LIB_CAIRO.}
#* Painting functions
proc cairo_paint*(cr: Pcairo_t){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_paint_with_alpha*(cr: Pcairo_t, alpha: float64){.cdecl, importc,
proc cairo_paint*(cr: PCairo){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_paint_with_alpha*(cr: PCairo, alpha: float64){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_mask*(cr: Pcairo_t, pattern: Pcairo_pattern_t){.cdecl, importc,
proc cairo_mask*(cr: PCairo, pattern: PCairoPattern){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_mask_surface*(cr: Pcairo_t, surface: Pcairo_surface_t,
proc cairo_mask_surface*(cr: PCairo, surface: PCairoSurface,
surface_x, surface_y: float64){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_stroke*(cr: Pcairo_t){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_stroke_preserve*(cr: Pcairo_t){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_fill*(cr: Pcairo_t){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_fill_preserve*(cr: Pcairo_t){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_copy_page*(cr: Pcairo_t){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_show_page*(cr: Pcairo_t){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_stroke*(cr: PCairo){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_stroke_preserve*(cr: PCairo){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_fill*(cr: PCairo){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_fill_preserve*(cr: PCairo){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_copy_page*(cr: PCairo){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_show_page*(cr: PCairo){.cdecl, importc, dynlib: LIB_CAIRO.}
#* Insideness testing
proc cairo_in_stroke*(cr: Pcairo_t, x, y: float64): cairo_bool_t{.cdecl, importc,
proc cairo_in_stroke*(cr: PCairo, x, y: float64): TCairoBool{.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_in_fill*(cr: Pcairo_t, x, y: float64): cairo_bool_t{.cdecl, importc,
proc cairo_in_fill*(cr: PCairo, x, y: float64): TCairoBool{.cdecl, importc,
dynlib: LIB_CAIRO.}
#* Rectangular extents
proc cairo_stroke_extents*(cr: Pcairo_t, x1, y1, x2, y2: var float64){.cdecl, importc,
proc cairo_stroke_extents*(cr: PCairo, x1, y1, x2, y2: var float64){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_fill_extents*(cr: Pcairo_t, x1, y1, x2, y2: var float64){.cdecl, importc,
proc cairo_fill_extents*(cr: PCairo, x1, y1, x2, y2: var float64){.cdecl, importc,
dynlib: LIB_CAIRO.}
#* Clipping
proc cairo_reset_clip*(cr: Pcairo_t){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_clip*(cr: Pcairo_t){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_clip_preserve*(cr: Pcairo_t){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_clip_extents*(cr: Pcairo_t, x1, y1, x2, y2: var float64){.cdecl, importc,
proc cairo_reset_clip*(cr: PCairo){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_clip*(cr: PCairo){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_clip_preserve*(cr: PCairo){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_clip_extents*(cr: PCairo, x1, y1, x2, y2: var float64){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_copy_clip_rectangle_list*(cr: Pcairo_t): Pcairo_rectangle_list_t{.
proc cairo_copy_clip_rectangle_list*(cr: PCairo): PCairoRectangleList{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_rectangle_list_destroy*(rectangle_list: Pcairo_rectangle_list_t){.
proc cairo_rectangle_list_destroy*(rectangle_list: PCairoRectangleList){.
cdecl, importc, dynlib: LIB_CAIRO.}
#* Font/Text functions
proc cairo_font_options_create*(): Pcairo_font_options_t{.cdecl, importc,
proc cairo_font_options_create*(): PCairoFontOptions{.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_font_options_copy*(original: Pcairo_font_options_t): Pcairo_font_options_t{.
proc cairo_font_options_copy*(original: PCairoFontOptions): PCairoFontOptions{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_font_options_destroy*(options: Pcairo_font_options_t){.cdecl, importc,
proc cairo_font_options_destroy*(options: PCairoFontOptions){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_font_options_status*(options: Pcairo_font_options_t): cairo_status_t{.
proc cairo_font_options_status*(options: PCairoFontOptions): TCairoStatus{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_font_options_merge*(options, other: Pcairo_font_options_t){.cdecl, importc,
proc cairo_font_options_merge*(options, other: PCairoFontOptions){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_font_options_equal*(options, other: Pcairo_font_options_t): cairo_bool_t{.
proc cairo_font_options_equal*(options, other: PCairoFontOptions): TCairoBool{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_font_options_hash*(options: Pcairo_font_options_t): int32{.cdecl, importc,
proc cairo_font_options_hash*(options: PCairoFontOptions): int32{.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_font_options_set_antialias*(options: Pcairo_font_options_t,
antialias: cairo_antialias_t){.cdecl, importc,
proc cairo_font_options_set_antialias*(options: PCairoFontOptions,
antialias: TCairoAntialias){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_font_options_get_antialias*(options: Pcairo_font_options_t): cairo_antialias_t{.
proc cairo_font_options_get_antialias*(options: PCairoFontOptions): TCairoAntialias{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_font_options_set_subpixel_order*(options: Pcairo_font_options_t,
subpixel_order: cairo_subpixel_order_t){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_font_options_get_subpixel_order*(options: Pcairo_font_options_t): cairo_subpixel_order_t{.
proc cairo_font_options_set_subpixel_order*(options: PCairoFontOptions,
subpixel_order: TCairoSubpixelOrder){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_font_options_get_subpixel_order*(options: PCairoFontOptions): TCairoSubpixelOrder{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_font_options_set_hint_style*(options: Pcairo_font_options_t,
hint_style: cairo_hint_style_t){.cdecl, importc,
proc cairo_font_options_set_hint_style*(options: PCairoFontOptions,
hint_style: TCairoHintStyle){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_font_options_get_hint_style*(options: Pcairo_font_options_t): cairo_hint_style_t{.
proc cairo_font_options_get_hint_style*(options: PCairoFontOptions): TCairoHintStyle{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_font_options_set_hint_metrics*(options: Pcairo_font_options_t,
hint_metrics: cairo_hint_metrics_t){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_font_options_get_hint_metrics*(options: Pcairo_font_options_t): cairo_hint_metrics_t{.
proc cairo_font_options_set_hint_metrics*(options: PCairoFontOptions,
hint_metrics: TCairoHintMetrics){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_font_options_get_hint_metrics*(options: PCairoFontOptions): TCairoHintMetrics{.
cdecl, importc, dynlib: LIB_CAIRO.}
#* This interface is for dealing with text as text, not caring about the
# font object inside the the cairo_t.
proc cairo_select_font_face*(cr: Pcairo_t, family: cstring,
slant: cairo_font_slant_t,
weight: cairo_font_weight_t){.cdecl, importc,
# font object inside the the TCairo.
proc cairo_select_font_face*(cr: PCairo, family: cstring,
slant: TCairoFontSlant,
weight: TCairoFontWeight){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_set_font_size*(cr: Pcairo_t, size: float64){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_set_font_matrix*(cr: Pcairo_t, matrix: Pcairo_matrix_t){.cdecl, importc,
proc cairo_set_font_size*(cr: PCairo, size: float64){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_set_font_matrix*(cr: PCairo, matrix: PCairoMatrix){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_get_font_matrix*(cr: Pcairo_t, matrix: Pcairo_matrix_t){.cdecl, importc,
proc cairo_get_font_matrix*(cr: PCairo, matrix: PCairoMatrix){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_set_font_options*(cr: Pcairo_t, options: Pcairo_font_options_t){.
proc cairo_set_font_options*(cr: PCairo, options: PCairoFontOptions){.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_get_font_options*(cr: Pcairo_t, options: Pcairo_font_options_t){.
proc cairo_get_font_options*(cr: PCairo, options: PCairoFontOptions){.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_set_font_face*(cr: Pcairo_t, font_face: Pcairo_font_face_t){.cdecl, importc,
proc cairo_set_font_face*(cr: PCairo, font_face: PCairoFontFace){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_get_font_face*(cr: Pcairo_t): Pcairo_font_face_t{.cdecl, importc,
proc cairo_get_font_face*(cr: PCairo): PCairoFontFace{.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_set_scaled_font*(cr: PCairo_t, scaled_font: Pcairo_scaled_font_t){.
proc cairo_set_scaled_font*(cr: PCairo, scaled_font: PCairoScaledFont){.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_get_scaled_font*(cr: Pcairo_t): Pcairo_scaled_font_t{.cdecl, importc,
proc cairo_get_scaled_font*(cr: PCairo): PCairoScaledFont{.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_show_text*(cr: Pcairo_t, utf8: cstring){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_show_glyphs*(cr: Pcairo_t, glyphs: Pcairo_glyph_t, num_glyphs: int32){.
proc cairo_show_text*(cr: PCairo, utf8: cstring){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_show_glyphs*(cr: PCairo, glyphs: PCairoGlyph, num_glyphs: int32){.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_text_path*(cr: Pcairo_t, utf8: cstring){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_glyph_path*(cr: Pcairo_t, glyphs: Pcairo_glyph_t, num_glyphs: int32){.
proc cairo_text_path*(cr: PCairo, utf8: cstring){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_glyph_path*(cr: PCairo, glyphs: PCairoGlyph, num_glyphs: int32){.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_text_extents*(cr: Pcairo_t, utf8: cstring,
extents: Pcairo_text_extents_t){.cdecl, importc,
proc cairo_text_extents*(cr: PCairo, utf8: cstring,
extents: PCairoTextExtents){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_glyph_extents*(cr: Pcairo_t, glyphs: Pcairo_glyph_t,
num_glyphs: int32, extents: Pcairo_text_extents_t){.
proc cairo_glyph_extents*(cr: PCairo, glyphs: PCairoGlyph,
num_glyphs: int32, extents: PCairoTextExtents){.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_font_extents*(cr: Pcairo_t, extents: Pcairo_font_extents_t){.cdecl, importc,
proc cairo_font_extents*(cr: PCairo, extents: PCairoFontExtents){.cdecl, importc,
dynlib: LIB_CAIRO.}
#* Generic identifier for a font style
proc cairo_font_face_reference*(font_face: Pcairo_font_face_t): Pcairo_font_face_t{.
proc cairo_font_face_reference*(font_face: PCairoFontFace): PCairoFontFace{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_font_face_destroy*(font_face: Pcairo_font_face_t){.cdecl, importc,
proc cairo_font_face_destroy*(font_face: PCairoFontFace){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_font_face_get_reference_count*(font_face: Pcairo_font_face_t): int32{.
proc cairo_font_face_get_reference_count*(font_face: PCairoFontFace): int32{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_font_face_status*(font_face: Pcairo_font_face_t): cairo_status_t{.
proc cairo_font_face_status*(font_face: PCairoFontFace): TCairoStatus{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_font_face_get_type*(font_face: Pcairo_font_face_t): cairo_font_type_t{.
proc cairo_font_face_get_type*(font_face: PCairoFontFace): TCairoFontType{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_font_face_get_user_data*(font_face: Pcairo_font_face_t,
key: Pcairo_user_data_key_t): pointer{.
proc cairo_font_face_get_user_data*(font_face: PCairoFontFace,
key: PCairoUserDataKey): pointer{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_font_face_set_user_data*(font_face: Pcairo_font_face_t,
key: Pcairo_user_data_key_t,
proc cairo_font_face_set_user_data*(font_face: PCairoFontFace,
key: PCairoUserDataKey,
user_data: pointer,
destroy: cairo_destroy_func_t): cairo_status_t{.
destroy: TCairoDestroyFunc): TCairoStatus{.
cdecl, importc, dynlib: LIB_CAIRO.}
#* Portable interface to general font features
proc cairo_scaled_font_create*(font_face: Pcairo_font_face_t,
font_matrix: Pcairo_matrix_t,
ctm: Pcairo_matrix_t,
options: Pcairo_font_options_t): Pcairo_scaled_font_t{.
proc cairo_scaled_font_create*(font_face: PCairoFontFace,
font_matrix: PCairoMatrix,
ctm: PCairoMatrix,
options: PCairoFontOptions): PCairoScaledFont{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_scaled_font_reference*(scaled_font: Pcairo_scaled_font_t): Pcairo_scaled_font_t{.
proc cairo_scaled_font_reference*(scaled_font: PCairoScaledFont): PCairoScaledFont{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_scaled_font_destroy*(scaled_font: Pcairo_scaled_font_t){.cdecl, importc,
proc cairo_scaled_font_destroy*(scaled_font: PCairoScaledFont){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_scaled_font_get_reference_count*(scaled_font: Pcairo_scaled_font_t): int32{.
proc cairo_scaled_font_get_reference_count*(scaled_font: PCairoScaledFont): int32{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_scaled_font_status*(scaled_font: Pcairo_scaled_font_t): cairo_status_t{.
proc cairo_scaled_font_status*(scaled_font: PCairoScaledFont): TCairoStatus{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_scaled_font_get_type*(scaled_font: Pcairo_scaled_font_t): cairo_font_type_t{.
proc cairo_scaled_font_get_type*(scaled_font: PCairoScaledFont): TCairoFontType{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_scaled_font_get_user_data*(scaled_font: Pcairo_scaled_font_t,
key: Pcairo_user_data_key_t): Pointer{.
proc cairo_scaled_font_get_user_data*(scaled_font: PCairoScaledFont,
key: PCairoUserDataKey): Pointer{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_scaled_font_set_user_data*(scaled_font: Pcairo_scaled_font_t,
key: Pcairo_user_data_key_t,
proc cairo_scaled_font_set_user_data*(scaled_font: PCairoScaledFont,
key: PCairoUserDataKey,
user_data: Pointer,
destroy: cairo_destroy_func_t): cairo_status_t{.
destroy: TCairoDestroyFunc): TCairoStatus{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_scaled_font_extents*(scaled_font: Pcairo_scaled_font_t,
extents: Pcairo_font_extents_t){.cdecl, importc,
proc cairo_scaled_font_extents*(scaled_font: PCairoScaledFont,
extents: PCairoFontExtents){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_scaled_font_text_extents*(scaled_font: Pcairo_scaled_font_t,
proc cairo_scaled_font_text_extents*(scaled_font: PCairoScaledFont,
utf8: cstring,
extents: Pcairo_text_extents_t){.cdecl, importc,
extents: PCairoTextExtents){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_scaled_font_glyph_extents*(scaled_font: Pcairo_scaled_font_t,
glyphs: Pcairo_glyph_t, num_glyphs: int32,
extents: Pcairo_text_extents_t){.cdecl, importc,
proc cairo_scaled_font_glyph_extents*(scaled_font: PCairoScaledFont,
glyphs: PCairoGlyph, num_glyphs: int32,
extents: PCairoTextExtents){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_scaled_font_get_font_face*(scaled_font: Pcairo_scaled_font_t): Pcairo_font_face_t{.
proc cairo_scaled_font_get_font_face*(scaled_font: PCairoScaledFont): PCairoFontFace{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_scaled_font_get_font_matrix*(scaled_font: Pcairo_scaled_font_t,
font_matrix: Pcairo_matrix_t){.cdecl, importc,
proc cairo_scaled_font_get_font_matrix*(scaled_font: PCairoScaledFont,
font_matrix: PCairoMatrix){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_scaled_font_get_ctm*(scaled_font: Pcairo_scaled_font_t,
ctm: Pcairo_matrix_t){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_scaled_font_get_font_options*(scaled_font: Pcairo_scaled_font_t,
options: Pcairo_font_options_t){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_scaled_font_get_ctm*(scaled_font: PCairoScaledFont,
ctm: PCairoMatrix){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_scaled_font_get_font_options*(scaled_font: PCairoScaledFont,
options: PCairoFontOptions){.cdecl, importc, dynlib: LIB_CAIRO.}
#* Query functions
proc cairo_get_operator*(cr: Pcairo_t): cairo_operator_t{.cdecl, importc,
proc cairo_get_operator*(cr: PCairo): TCairoOperator{.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_get_source*(cr: Pcairo_t): Pcairo_pattern_t{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_get_tolerance*(cr: Pcairo_t): float64{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_get_antialias*(cr: Pcairo_t): cairo_antialias_t{.cdecl, importc,
proc cairo_get_source*(cr: PCairo): PCairoPattern{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_get_tolerance*(cr: PCairo): float64{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_get_antialias*(cr: PCairo): TCairoAntialias{.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_get_current_point*(cr: Pcairo_t, x, y: var float64){.cdecl, importc,
proc cairo_get_current_point*(cr: PCairo, x, y: var float64){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_get_fill_rule*(cr: Pcairo_t): cairo_fill_rule_t{.cdecl, importc,
proc cairo_get_fill_rule*(cr: PCairo): TCairoFillRule{.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_get_line_width*(cr: Pcairo_t): float64{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_get_line_cap*(cr: Pcairo_t): cairo_line_cap_t{.cdecl, importc,
proc cairo_get_line_width*(cr: PCairo): float64{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_get_line_cap*(cr: PCairo): TCairoLineCap{.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_get_line_join*(cr: Pcairo_t): cairo_line_join_t{.cdecl, importc,
proc cairo_get_line_join*(cr: PCairo): TCairoLineJoin{.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_get_miter_limit*(cr: Pcairo_t): float64{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_get_dash_count*(cr: Pcairo_t): int32{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_get_dash*(cr: Pcairo_t, dashes, offset: var float64){.cdecl, importc,
proc cairo_get_miter_limit*(cr: PCairo): float64{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_get_dash_count*(cr: PCairo): int32{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_get_dash*(cr: PCairo, dashes, offset: var float64){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_get_matrix*(cr: Pcairo_t, matrix: Pcairo_matrix_t){.cdecl, importc,
proc cairo_get_matrix*(cr: PCairo, matrix: PCairoMatrix){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_get_target*(cr: Pcairo_t): Pcairo_surface_t{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_get_group_target*(cr: Pcairo_t): Pcairo_surface_t{.cdecl, importc,
proc cairo_get_target*(cr: PCairo): PCairoSurface{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_get_group_target*(cr: PCairo): PCairoSurface{.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_copy_path*(cr: Pcairo_t): Pcairo_path_t{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_copy_path_flat*(cr: Pcairo_t): Pcairo_path_t{.cdecl, importc,
proc cairo_copy_path*(cr: PCairo): PCairoPath{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_copy_path_flat*(cr: PCairo): PCairoPath{.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_append_path*(cr: Pcairo_t, path: Pcairo_path_t){.cdecl, importc,
proc cairo_append_path*(cr: PCairo, path: PCairoPath){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_path_destroy*(path: Pcairo_path_t){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_path_destroy*(path: PCairoPath){.cdecl, importc, dynlib: LIB_CAIRO.}
#* Error status queries
proc cairo_status*(cr: Pcairo_t): cairo_status_t{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_status_to_string*(status: cairo_status_t): cstring{.cdecl, importc,
proc cairo_status*(cr: PCairo): TCairoStatus{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_status_to_string*(status: TCairoStatus): cstring{.cdecl, importc,
dynlib: LIB_CAIRO.}
#* Surface manipulation
proc cairo_surface_create_similar*(other: Pcairo_surface_t,
content: cairo_content_t,
width, height: int32): Pcairo_surface_t{.
proc cairo_surface_create_similar*(other: PCairoSurface,
content: TCairoContent,
width, height: int32): PCairoSurface{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_surface_reference*(surface: Pcairo_surface_t): Pcairo_surface_t{.
proc cairo_surface_reference*(surface: PCairoSurface): PCairoSurface{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_surface_finish*(surface: Pcairo_surface_t){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_surface_destroy*(surface: Pcairo_surface_t){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_surface_get_reference_count*(surface: Pcairo_surface_t): int32{.
proc cairo_surface_finish*(surface: PCairoSurface){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_surface_destroy*(surface: PCairoSurface){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_surface_get_reference_count*(surface: PCairoSurface): int32{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_surface_status*(surface: Pcairo_surface_t): cairo_status_t{.cdecl, importc,
proc cairo_surface_status*(surface: PCairoSurface): TCairoStatus{.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_surface_get_type*(surface: Pcairo_surface_t): cairo_surface_type_t{.
proc cairo_surface_get_type*(surface: PCairoSurface): TCairoSurfaceType{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_surface_get_content*(surface: Pcairo_surface_t): cairo_content_t{.
proc cairo_surface_get_content*(surface: PCairoSurface): TCairoContent{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_surface_write_to_png*(surface: Pcairo_surface_t, filename: cstring): cairo_status_t{.
proc cairo_surface_write_to_png*(surface: PCairoSurface, filename: cstring): TCairoStatus{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_surface_write_to_png_stream*(surface: Pcairo_surface_t,
write_func: cairo_write_func_t,
closure: pointer): cairo_status_t{.
proc cairo_surface_write_to_png_stream*(surface: PCairoSurface,
write_func: TCairoWriteFunc,
closure: pointer): TCairoStatus{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_surface_get_user_data*(surface: Pcairo_surface_t,
key: Pcairo_user_data_key_t): pointer{.cdecl, importc,
proc cairo_surface_get_user_data*(surface: PCairoSurface,
key: PCairoUserDataKey): pointer{.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_surface_set_user_data*(surface: Pcairo_surface_t,
key: Pcairo_user_data_key_t,
proc cairo_surface_set_user_data*(surface: PCairoSurface,
key: PCairoUserDataKey,
user_data: pointer,
destroy: cairo_destroy_func_t): cairo_status_t{.
destroy: TCairoDestroyFunc): TCairoStatus{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_surface_get_font_options*(surface: Pcairo_surface_t,
options: Pcairo_font_options_t){.cdecl, importc,
proc cairo_surface_get_font_options*(surface: PCairoSurface,
options: PCairoFontOptions){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_surface_flush*(surface: Pcairo_surface_t){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_surface_mark_dirty*(surface: Pcairo_surface_t){.cdecl, importc,
proc cairo_surface_flush*(surface: PCairoSurface){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_surface_mark_dirty*(surface: PCairoSurface){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_surface_mark_dirty_rectangle*(surface: Pcairo_surface_t,
proc cairo_surface_mark_dirty_rectangle*(surface: PCairoSurface,
x, y, width, height: int32){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_surface_set_device_offset*(surface: Pcairo_surface_t,
proc cairo_surface_set_device_offset*(surface: PCairoSurface,
x_offset, y_offset: float64){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_surface_get_device_offset*(surface: Pcairo_surface_t,
proc cairo_surface_get_device_offset*(surface: PCairoSurface,
x_offset, y_offset: var float64){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_surface_set_fallback_resolution*(surface: Pcairo_surface_t,
proc cairo_surface_set_fallback_resolution*(surface: PCairoSurface,
x_pixels_per_inch, y_pixels_per_inch: float64){.cdecl, importc, dynlib: LIB_CAIRO.}
#* Image-surface functions
proc cairo_image_surface_create*(format: cairo_format_t, width, height: int32): Pcairo_surface_t{.
proc cairo_image_surface_create*(format: TCairoFormat, width, height: int32): PCairoSurface{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_image_surface_create_for_data*(data: Pbyte, format: cairo_format_t,
width, height, stride: int32): Pcairo_surface_t{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_image_surface_get_data*(surface: Pcairo_surface_t): cstring{.cdecl, importc,
proc cairo_image_surface_create_for_data*(data: Pbyte, format: TCairoFormat,
width, height, stride: int32): PCairoSurface{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_image_surface_get_data*(surface: PCairoSurface): cstring{.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_image_surface_get_format*(surface: Pcairo_surface_t): cairo_format_t{.
proc cairo_image_surface_get_format*(surface: PCairoSurface): TCairoFormat{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_image_surface_get_width*(surface: Pcairo_surface_t): int32{.cdecl, importc,
proc cairo_image_surface_get_width*(surface: PCairoSurface): int32{.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_image_surface_get_height*(surface: Pcairo_surface_t): int32{.cdecl, importc,
proc cairo_image_surface_get_height*(surface: PCairoSurface): int32{.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_image_surface_get_stride*(surface: Pcairo_surface_t): int32{.cdecl, importc,
proc cairo_image_surface_get_stride*(surface: PCairoSurface): int32{.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_image_surface_create_from_png*(filename: cstring): Pcairo_surface_t{.
proc cairo_image_surface_create_from_png*(filename: cstring): PCairoSurface{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_image_surface_create_from_png_stream*(read_func: cairo_read_func_t,
closure: pointer): Pcairo_surface_t{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_image_surface_create_from_png_stream*(read_func: TCairoReadFunc,
closure: pointer): PCairoSurface{.cdecl, importc, dynlib: LIB_CAIRO.}
#* Pattern creation functions
proc cairo_pattern_create_rgb*(red, green, blue: float64): Pcairo_pattern_t{.
proc cairo_pattern_create_rgb*(red, green, blue: float64): PCairoPattern{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_pattern_create_rgba*(red, green, blue, alpha: float64): Pcairo_pattern_t{.
proc cairo_pattern_create_rgba*(red, green, blue, alpha: float64): PCairoPattern{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_pattern_create_for_surface*(surface: Pcairo_surface_t): Pcairo_pattern_t{.
proc cairo_pattern_create_for_surface*(surface: PCairoSurface): PCairoPattern{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_pattern_create_linear*(x0, y0, x1, y1: float64): Pcairo_pattern_t{.
proc cairo_pattern_create_linear*(x0, y0, x1, y1: float64): PCairoPattern{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_pattern_create_radial*(cx0, cy0, radius0, cx1, cy1, radius1: float64): Pcairo_pattern_t{.
proc cairo_pattern_create_radial*(cx0, cy0, radius0, cx1, cy1, radius1: float64): PCairoPattern{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_pattern_reference*(pattern: Pcairo_pattern_t): Pcairo_pattern_t{.
proc cairo_pattern_reference*(pattern: PCairoPattern): PCairoPattern{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_pattern_destroy*(pattern: Pcairo_pattern_t){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_pattern_get_reference_count*(pattern: Pcairo_pattern_t): int32{.
proc cairo_pattern_destroy*(pattern: PCairoPattern){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_pattern_get_reference_count*(pattern: PCairoPattern): int32{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_pattern_status*(pattern: Pcairo_pattern_t): cairo_status_t{.cdecl, importc,
proc cairo_pattern_status*(pattern: PCairoPattern): TCairoStatus{.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_pattern_get_user_data*(pattern: Pcairo_pattern_t,
key: Pcairo_user_data_key_t): Pointer{.cdecl, importc,
proc cairo_pattern_get_user_data*(pattern: PCairoPattern,
key: PCairoUserDataKey): Pointer{.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_pattern_set_user_data*(pattern: Pcairo_pattern_t,
key: Pcairo_user_data_key_t,
proc cairo_pattern_set_user_data*(pattern: PCairoPattern,
key: PCairoUserDataKey,
user_data: Pointer,
destroy: cairo_destroy_func_t): cairo_status_t{.
destroy: TCairoDestroyFunc): TCairoStatus{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_pattern_get_type*(pattern: Pcairo_pattern_t): cairo_pattern_type_t{.
proc cairo_pattern_get_type*(pattern: PCairoPattern): TCairoPatternType{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_pattern_add_color_stop_rgb*(pattern: Pcairo_pattern_t,
proc cairo_pattern_add_color_stop_rgb*(pattern: PCairoPattern,
offset, red, green, blue: float64){.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_pattern_add_color_stop_rgba*(pattern: Pcairo_pattern_t, offset, red,
proc cairo_pattern_add_color_stop_rgba*(pattern: PCairoPattern, offset, red,
green, blue, alpha: float64){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_pattern_set_matrix*(pattern: Pcairo_pattern_t,
matrix: Pcairo_matrix_t){.cdecl, importc,
proc cairo_pattern_set_matrix*(pattern: PCairoPattern,
matrix: PCairoMatrix){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_pattern_get_matrix*(pattern: Pcairo_pattern_t,
matrix: Pcairo_matrix_t){.cdecl, importc,
proc cairo_pattern_get_matrix*(pattern: PCairoPattern,
matrix: PCairoMatrix){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_pattern_set_extend*(pattern: Pcairo_pattern_t, extend: cairo_extend_t){.
proc cairo_pattern_set_extend*(pattern: PCairoPattern, extend: TCairoExtend){.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_pattern_get_extend*(pattern: Pcairo_pattern_t): cairo_extend_t{.
proc cairo_pattern_get_extend*(pattern: PCairoPattern): TCairoExtend{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_pattern_set_filter*(pattern: Pcairo_pattern_t, filter: cairo_filter_t){.
proc cairo_pattern_set_filter*(pattern: PCairoPattern, filter: TCairoFilter){.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_pattern_get_filter*(pattern: Pcairo_pattern_t): cairo_filter_t{.
proc cairo_pattern_get_filter*(pattern: PCairoPattern): TCairoFilter{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_pattern_get_rgba*(pattern: Pcairo_pattern_t,
red, green, blue, alpha: var float64): cairo_status_t{.
proc cairo_pattern_get_rgba*(pattern: PCairoPattern,
red, green, blue, alpha: var float64): TCairoStatus{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_pattern_get_surface*(pattern: Pcairo_pattern_t,
surface: PPcairo_surface_t): cairo_status_t{.
proc cairo_pattern_get_surface*(pattern: PCairoPattern,
surface: PPCairoSurface): TCairoStatus{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_pattern_get_color_stop_rgba*(pattern: Pcairo_pattern_t, index: int32,
offset, red, green, blue, alpha: var float64): cairo_status_t{.cdecl, importc,
proc cairo_pattern_get_color_stop_rgba*(pattern: PCairoPattern, index: int32,
offset, red, green, blue, alpha: var float64): TCairoStatus{.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_pattern_get_color_stop_count*(pattern: Pcairo_pattern_t,
count: var int32): cairo_status_t{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_pattern_get_linear_points*(pattern: Pcairo_pattern_t,
x0, y0, x1, y1: var float64): cairo_status_t{.
proc cairo_pattern_get_color_stop_count*(pattern: PCairoPattern,
count: var int32): TCairoStatus{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_pattern_get_linear_points*(pattern: PCairoPattern,
x0, y0, x1, y1: var float64): TCairoStatus{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_pattern_get_radial_circles*(pattern: Pcairo_pattern_t,
x0, y0, r0, x1, y1, r1: var float64): cairo_status_t{.
proc cairo_pattern_get_radial_circles*(pattern: PCairoPattern,
x0, y0, r0, x1, y1, r1: var float64): TCairoStatus{.
cdecl, importc, dynlib: LIB_CAIRO.}
#* Matrix functions
proc cairo_matrix_init*(matrix: Pcairo_matrix_t, xx, yx, xy, yy, x0, y0: float64){.
proc cairo_matrix_init*(matrix: PCairoMatrix, xx, yx, xy, yy, x0, y0: float64){.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_matrix_init_identity*(matrix: Pcairo_matrix_t){.cdecl, importc,
proc cairo_matrix_init_identity*(matrix: PCairoMatrix){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_matrix_init_translate*(matrix: Pcairo_matrix_t, tx, ty: float64){.
proc cairo_matrix_init_translate*(matrix: PCairoMatrix, tx, ty: float64){.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_matrix_init_scale*(matrix: Pcairo_matrix_t, sx, sy: float64){.cdecl, importc,
proc cairo_matrix_init_scale*(matrix: PCairoMatrix, sx, sy: float64){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_matrix_init_rotate*(matrix: Pcairo_matrix_t, radians: float64){.
proc cairo_matrix_init_rotate*(matrix: PCairoMatrix, radians: float64){.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_matrix_translate*(matrix: Pcairo_matrix_t, tx, ty: float64){.cdecl, importc,
proc cairo_matrix_translate*(matrix: PCairoMatrix, tx, ty: float64){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_matrix_scale*(matrix: Pcairo_matrix_t, sx, sy: float64){.cdecl, importc,
proc cairo_matrix_scale*(matrix: PCairoMatrix, sx, sy: float64){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_matrix_rotate*(matrix: Pcairo_matrix_t, radians: float64){.cdecl, importc,
proc cairo_matrix_rotate*(matrix: PCairoMatrix, radians: float64){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_matrix_invert*(matrix: Pcairo_matrix_t): cairo_status_t{.cdecl, importc,
proc cairo_matrix_invert*(matrix: PCairoMatrix): TCairoStatus{.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_matrix_multiply*(result, a, b: Pcairo_matrix_t){.cdecl, importc,
proc cairo_matrix_multiply*(result, a, b: PCairoMatrix){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_matrix_transform_distance*(matrix: Pcairo_matrix_t, dx, dy: var float64){.
proc cairo_matrix_transform_distance*(matrix: PCairoMatrix, dx, dy: var float64){.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_matrix_transform_point*(matrix: Pcairo_matrix_t, x, y: var float64){.
proc cairo_matrix_transform_point*(matrix: PCairoMatrix, x, y: var float64){.
cdecl, importc, dynlib: LIB_CAIRO.}
#* PDF functions
proc cairo_pdf_surface_create*(filename: cstring,
width_in_points, height_in_points: float64): Pcairo_surface_t{.
width_in_points, height_in_points: float64): PCairoSurface{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_pdf_surface_create_for_stream*(write_func: cairo_write_func_t,
closure: Pointer, width_in_points, height_in_points: float64): Pcairo_surface_t{.
proc cairo_pdf_surface_create_for_stream*(write_func: TCairoWriteFunc,
closure: Pointer, width_in_points, height_in_points: float64): PCairoSurface{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_pdf_surface_set_size*(surface: Pcairo_surface_t,
proc cairo_pdf_surface_set_size*(surface: PCairoSurface,
width_in_points, height_in_points: float64){.
cdecl, importc, dynlib: LIB_CAIRO.}
#* PS functions
proc cairo_ps_surface_create*(filename: cstring,
width_in_points, height_in_points: float64): Pcairo_surface_t{.
width_in_points, height_in_points: float64): PCairoSurface{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_ps_surface_create_for_stream*(write_func: cairo_write_func_t,
closure: Pointer, width_in_points, height_in_points: float64): Pcairo_surface_t{.
proc cairo_ps_surface_create_for_stream*(write_func: TCairoWriteFunc,
closure: Pointer, width_in_points, height_in_points: float64): PCairoSurface{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_ps_surface_set_size*(surface: Pcairo_surface_t,
proc cairo_ps_surface_set_size*(surface: PCairoSurface,
width_in_points, height_in_points: float64){.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_ps_surface_dsc_comment*(surface: Pcairo_surface_t, comment: cstring){.
proc cairo_ps_surface_dsc_comment*(surface: PCairoSurface, comment: cstring){.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_ps_surface_dsc_begin_setup*(surface: Pcairo_surface_t){.cdecl, importc,
proc cairo_ps_surface_dsc_begin_setup*(surface: PCairoSurface){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_ps_surface_dsc_begin_page_setup*(surface: Pcairo_surface_t){.cdecl, importc,
proc cairo_ps_surface_dsc_begin_page_setup*(surface: PCairoSurface){.cdecl, importc,
dynlib: LIB_CAIRO.}
#* SVG functions
proc cairo_svg_surface_create*(filename: cstring,
width_in_points, height_in_points: float64): Pcairo_surface_t{.
width_in_points, height_in_points: float64): PCairoSurface{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_svg_surface_create_for_stream*(write_func: cairo_write_func_t,
closure: Pointer, width_in_points, height_in_points: float64): Pcairo_surface_t{.
proc cairo_svg_surface_create_for_stream*(write_func: TCairoWriteFunc,
closure: Pointer, width_in_points, height_in_points: float64): PCairoSurface{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_svg_surface_restrict_to_version*(surface: Pcairo_surface_t,
version: cairo_svg_version_t){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_svg_surface_restrict_to_version*(surface: PCairoSurface,
version: TCairoSvgVersion){.cdecl, importc, dynlib: LIB_CAIRO.}
#todo: see how translate this
#procedure cairo_svg_get_versions(cairo_svg_version_t const **versions,
#procedure cairo_svg_get_versions(TCairoSvgVersion const **versions,
# int *num_versions);
proc cairo_svg_version_to_string*(version: cairo_svg_version_t): cstring{.cdecl, importc,
proc cairo_svg_version_to_string*(version: TCairoSvgVersion): cstring{.cdecl, importc,
dynlib: LIB_CAIRO.}
#* Functions to be used while debugging (not intended for use in production code)
proc cairo_debug_reset_static_data*(){.cdecl, importc, dynlib: LIB_CAIRO.}
@ -693,6 +693,6 @@ proc cairo_debug_reset_static_data*(){.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_version(major, minor, micro: var int32) =
var version: int32
version = cairo_version()
major = version div 10000
minor = (version mod (major * 10000)) div 100
micro = (version mod ((major * 10000) + (minor * 100)))
major = version div 10000'i32
minor = (version mod (major * 10000'i32)) div 100'i32
micro = (version mod ((major * 10000'i32) + (minor * 100'i32)))

View file

@ -4,7 +4,7 @@
# updated to version 1.4 by Luiz Américo Pereira Câmara 2007
#
import Cairo, freetypeh
import cairo, freetypeh
#todo: properly define FcPattern:
#It will require translate FontConfig header
@ -20,17 +20,17 @@ import Cairo, freetypeh
type
FcPattern* = Pointer
PFcPattern* = ref FcPattern
PFcPattern* = ptr FcPattern
proc cairo_ft_font_face_create_for_pattern*(pattern: PFcPattern): Pcairo_font_face_t{.
proc cairo_ft_font_face_create_for_pattern*(pattern: PFcPattern): PCairoFontFace{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_ft_font_options_substitute*(options: Pcairo_font_options_t,
proc cairo_ft_font_options_substitute*(options: PCairoFontOptions,
pattern: PFcPattern){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_ft_font_face_create_for_ft_face*(face: TFT_Face,
load_flags: int32): Pcairo_font_face_t {.cdecl, importc, dynlib: LIB_CAIRO.}
load_flags: int32): PCairoFontFace {.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_ft_scaled_font_lock_face*(
scaled_font: Pcairo_scaled_font_t): TFT_Face{.cdecl, importc, dynlib: LIB_CAIRO.}
scaled_font: PCairoScaledFont): TFT_Face{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_ft_scaled_font_unlock_face*(
scaled_font: Pcairo_scaled_font_t){.cdecl, importc, dynlib: LIB_CAIRO.}
scaled_font: PCairoScaledFont){.cdecl, importc, dynlib: LIB_CAIRO.}

View file

@ -7,30 +7,30 @@
import
Cairo, windows
proc cairo_win32_surface_create*(hdc: HDC): Pcairo_surface_t{.cdecl, importc,
proc cairo_win32_surface_create*(hdc: HDC): PCairoSurface{.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_win32_surface_create_with_ddb*(hdc: HDC, format: cairo_format_t,
width, height: int32): Pcairo_surface_t{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_win32_surface_create_with_dib*(format: cairo_format_t,
width, height: int32): Pcairo_surface_t{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_win32_surface_get_dc*(surface: pcairo_surface_t): HDC{.cdecl, importc,
proc cairo_win32_surface_create_with_ddb*(hdc: HDC, format: TCairoFormat,
width, height: int32): PCairoSurface{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_win32_surface_create_with_dib*(format: TCairoFormat,
width, height: int32): PCairoSurface{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_win32_surface_get_dc*(surface: PCairoSurface): HDC{.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_win32_surface_get_image*(surface: pcairo_surface_t): Pcairo_surface_t{.
proc cairo_win32_surface_get_image*(surface: PCairoSurface): PCairoSurface{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_win32_font_face_create_for_logfontw*(logfont: pLOGFONTW): Pcairo_font_face_t{.
proc cairo_win32_font_face_create_for_logfontw*(logfont: pLOGFONTW): PCairoFontFace{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_win32_font_face_create_for_hfont*(font: HFONT): Pcairo_font_face_t{.
proc cairo_win32_font_face_create_for_hfont*(font: HFONT): PCairoFontFace{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_win32_scaled_font_select_font*(scaled_font: pcairo_scaled_font_t,
hdc: HDC): cairo_status_t{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_win32_scaled_font_done_font*(scaled_font: pcairo_scaled_font_t){.
proc cairo_win32_scaled_font_select_font*(scaled_font: PCairoScaledFont,
hdc: HDC): TCairoStatus{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_win32_scaled_font_done_font*(scaled_font: PCairoScaledFont){.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_win32_scaled_font_get_metrics_factor*(
scaled_font: pcairo_scaled_font_t): float64{.cdecl, importc, dynlib: LIB_CAIRO.}
scaled_font: PCairoScaledFont): float64{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_win32_scaled_font_get_logical_to_device*(
scaled_font: pcairo_scaled_font_t, logical_to_device: pcairo_matrix_t){.
scaled_font: PCairoScaledFont, logical_to_device: PCairoMatrix){.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_win32_scaled_font_get_device_to_logical*(
scaled_font: pcairo_scaled_font_t, device_to_logical: pcairo_matrix_t){.
scaled_font: PCairoScaledFont, device_to_logical: PCairoMatrix){.
cdecl, importc, dynlib: LIB_CAIRO.}
# implementation

View file

@ -9,32 +9,32 @@ import
Cairo, x, xlib, xrender
proc cairo_xlib_surface_create*(dpy: PDisplay, drawable: TDrawable,
visual: PVisual, width, height: int32): Pcairo_surface_t{.
visual: PVisual, width, height: int32): PCairoSurface{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_xlib_surface_create_for_bitmap*(dpy: PDisplay, bitmap: TPixmap,
screen: PScreen, width, height: int32): Pcairo_surface_t{.cdecl, importc,
screen: PScreen, width, height: int32): PCairoSurface{.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_xlib_surface_create_with_xrender_format*(dpy: PDisplay,
drawable: TDrawable, screen: PScreen, format: PXRenderPictFormat,
width, height: int32): Pcairo_surface_t{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_xlib_surface_get_depth*(surface: Pcairo_surface_t): int32{.cdecl, importc,
width, height: int32): PCairoSurface{.cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_xlib_surface_get_depth*(surface: PCairoSurface): int32{.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_xlib_surface_get_display*(surface: Pcairo_surface_t): PDisplay{.
proc cairo_xlib_surface_get_display*(surface: PCairoSurface): PDisplay{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_xlib_surface_get_drawable*(surface: Pcairo_surface_t): TDrawable{.
proc cairo_xlib_surface_get_drawable*(surface: PCairoSurface): TDrawable{.
cdecl, importc, dynlib: LIB_CAIRO.}
proc cairo_xlib_surface_get_height*(surface: Pcairo_surface_t): int32{.cdecl, importc,
proc cairo_xlib_surface_get_height*(surface: PCairoSurface): int32{.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_xlib_surface_get_screen*(surface: Pcairo_surface_t): PScreen{.cdecl, importc,
proc cairo_xlib_surface_get_screen*(surface: PCairoSurface): PScreen{.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_xlib_surface_get_visual*(surface: Pcairo_surface_t): PVisual{.cdecl, importc,
proc cairo_xlib_surface_get_visual*(surface: PCairoSurface): PVisual{.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_xlib_surface_get_width*(surface: Pcairo_surface_t): int32{.cdecl, importc,
proc cairo_xlib_surface_get_width*(surface: PCairoSurface): int32{.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_xlib_surface_set_size*(surface: Pcairo_surface_t,
proc cairo_xlib_surface_set_size*(surface: PCairoSurface,
width, height: int32){.cdecl, importc,
dynlib: LIB_CAIRO.}
proc cairo_xlib_surface_set_drawable*(surface: Pcairo_surface_t,
proc cairo_xlib_surface_set_drawable*(surface: PCairoSurface,
drawable: TDrawable, width, height: int32){.
cdecl, importc, dynlib: LIB_CAIRO.}
# implementation

View file

@ -90,7 +90,7 @@ proc ChooseFileToOpen*(window: PWindow, root: string = ""): string =
GTK_STOCK_OPEN, GTK_RESPONSE_OK, nil))
if root.len > 0:
discard gtk_file_chooser_set_current_folder(chooser, root)
if gtk_dialog_run(chooser) == GTK_RESPONSE_OK:
if gtk_dialog_run(chooser) == cint(GTK_RESPONSE_OK):
var x = gtk_file_chooser_get_filename(chooser)
result = $x
g_free(x)
@ -99,7 +99,7 @@ proc ChooseFileToOpen*(window: PWindow, root: string = ""): string =
gtk_widget_destroy(chooser)
proc ChooseFilesToOpen*(window: PWindow, root: string = ""): seq[string] =
## Opens a dialog that requests filenames from the user. Returns []
## Opens a dialog that requests filenames from the user. Returns ``@[]``
## if the user closed the dialog without selecting a file. On Windows,
## the native dialog is used, else the GTK dialog is used.
when defined(Windows):
@ -114,7 +114,7 @@ proc ChooseFilesToOpen*(window: PWindow, root: string = ""): seq[string] =
opf.lpstrFile = buf
opf.nMaxFile = sizeof(buf)
var res = GetOpenFileName(addr(opf))
result = []
result = @[]
if res != 0:
# parsing the result is horrible:
var
@ -145,8 +145,8 @@ proc ChooseFilesToOpen*(window: PWindow, root: string = ""): seq[string] =
if root.len > 0:
discard gtk_file_chooser_set_current_folder(chooser, root)
gtk_file_chooser_set_select_multiple(chooser, true)
result = []
if gtk_dialog_run(chooser) == GTK_RESPONSE_OK:
result = @[]
if gtk_dialog_run(chooser) == cint(GTK_RESPONSE_OK):
var L = gtk_file_chooser_get_filenames(chooser)
var it = L
while it != nil:
@ -187,7 +187,7 @@ proc ChooseFileToSave*(window: PWindow, root: string = ""): string =
if root.len > 0:
discard gtk_file_chooser_set_current_folder(chooser, root)
gtk_file_chooser_set_do_overwrite_confirmation(chooser, true)
if gtk_dialog_run(chooser) == GTK_RESPONSE_OK:
if gtk_dialog_run(chooser) == cint(GTK_RESPONSE_OK):
var x = gtk_file_chooser_get_filename(chooser)
result = $x
g_free(x)
@ -224,7 +224,7 @@ proc ChooseDir*(window: PWindow, root: string = ""): string =
GTK_STOCK_OPEN, GTK_RESPONSE_OK, nil))
if root.len > 0:
discard gtk_file_chooser_set_current_folder(chooser, root)
if gtk_dialog_run(chooser) == GTK_RESPONSE_OK:
if gtk_dialog_run(chooser) == cint(GTK_RESPONSE_OK):
var x = gtk_file_chooser_get_filename(chooser)
result = $x
g_free(x)

View file

@ -2,7 +2,6 @@ import
glib2
when defined(windows):
{.define: atkwin.}
const
atklib = "libatk-1.0-0.dll"
else:

File diff suppressed because it is too large Load diff

View file

@ -1,12 +1,11 @@
import
import
glib2
when defined(win32):
{.define: gdkpixbufwin.}
const
when defined(win32):
const
gdkpixbuflib = "libgdk_pixbuf-2.0-0.dll"
elif defined(darwin):
const
elif defined(darwin):
const
gdkpixbuflib = "gdk_pixbuf-2.0.0"
# linklib gtk-x11-2.0
# linklib gdk-x11-2.0
@ -15,29 +14,28 @@ elif defined(darwin):
# linklib gobject-2.0.0
# linklib gdk_pixbuf-2.0.0
# linklib atk-1.0.0
else:
const
else:
const
gdkpixbuflib = "libgdk_pixbuf-2.0.so"
{.define: HasGTK2_4.}
{.define: HasGTK2_6.}
type
type
PGdkPixbuf* = pointer
PGdkPixbufAnimation* = pointer
PGdkPixbufAnimationIter* = pointer
PGdkPixbufAlphaMode* = ptr TGdkPixbufAlphaMode
TGdkPixbufAlphaMode* = enum
TGdkPixbufAlphaMode* = enum
GDK_PIXBUF_ALPHA_BILEVEL, GDK_PIXBUF_ALPHA_FULL
PGdkColorspace* = ptr TGdkColorspace
TGdkColorspace* = enum
TGdkColorspace* = enum
GDK_COLORSPACE_RGB
TGdkPixbufDestroyNotify* = proc (pixels: Pguchar, data: gpointer){.cdecl.}
PGdkPixbufError* = ptr TGdkPixbufError
TGdkPixbufError* = enum
GDK_PIXBUF_ERROR_CORRUPT_IMAGE, GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
GDK_PIXBUF_ERROR_BAD_OPTION, GDK_PIXBUF_ERROR_UNKNOWN_TYPE,
TGdkPixbufError* = enum
GDK_PIXBUF_ERROR_CORRUPT_IMAGE, GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
GDK_PIXBUF_ERROR_BAD_OPTION, GDK_PIXBUF_ERROR_UNKNOWN_TYPE,
GDK_PIXBUF_ERROR_UNSUPPORTED_OPERATION, GDK_PIXBUF_ERROR_FAILED
PGdkInterpType* = ptr TGdkInterpType
TGdkInterpType* = enum
TGdkInterpType* = enum
GDK_INTERP_NEAREST, GDK_INTERP_TILES, GDK_INTERP_BILINEAR, GDK_INTERP_HYPER
proc GDK_TYPE_PIXBUF*(): GType
@ -50,117 +48,115 @@ proc GDK_TYPE_PIXBUF_ANIMATION_ITER*(): GType
proc GDK_PIXBUF_ANIMATION_ITER*(anObject: pointer): PGdkPixbufAnimationIter
proc GDK_IS_PIXBUF_ANIMATION_ITER*(anObject: pointer): bool
proc GDK_PIXBUF_ERROR*(): TGQuark
proc gdk_pixbuf_error_quark*(): TGQuark{.cdecl, dynlib: gdkpixbuflib,
proc gdk_pixbuf_error_quark*(): TGQuark{.cdecl, dynlib: gdkpixbuflib,
importc: "gdk_pixbuf_error_quark".}
proc gdk_pixbuf_get_type*(): GType{.cdecl, dynlib: gdkpixbuflib,
proc gdk_pixbuf_get_type*(): GType{.cdecl, dynlib: gdkpixbuflib,
importc: "gdk_pixbuf_get_type".}
when not defined(GDK_PIXBUF_DISABLE_DEPRECATED):
proc gdk_pixbuf_ref(pixbuf: PGdkPixbuf): PGdkPixbuf{.cdecl,
when not defined(GDK_PIXBUF_DISABLE_DEPRECATED):
proc gdk_pixbuf_ref*(pixbuf: PGdkPixbuf): PGdkPixbuf{.cdecl,
dynlib: gdkpixbuflib, importc: "gdk_pixbuf_ref".}
proc gdk_pixbuf_unref(pixbuf: PGdkPixbuf){.cdecl, dynlib: gdkpixbuflib,
proc gdk_pixbuf_unref*(pixbuf: PGdkPixbuf){.cdecl, dynlib: gdkpixbuflib,
importc: "gdk_pixbuf_unref".}
proc gdk_pixbuf_get_colorspace*(pixbuf: PGdkPixbuf): TGdkColorspace{.cdecl,
proc gdk_pixbuf_get_colorspace*(pixbuf: PGdkPixbuf): TGdkColorspace{.cdecl,
dynlib: gdkpixbuflib, importc: "gdk_pixbuf_get_colorspace".}
proc gdk_pixbuf_get_n_channels*(pixbuf: PGdkPixbuf): int32{.cdecl,
proc gdk_pixbuf_get_n_channels*(pixbuf: PGdkPixbuf): int32{.cdecl,
dynlib: gdkpixbuflib, importc: "gdk_pixbuf_get_n_channels".}
proc gdk_pixbuf_get_has_alpha*(pixbuf: PGdkPixbuf): gboolean{.cdecl,
proc gdk_pixbuf_get_has_alpha*(pixbuf: PGdkPixbuf): gboolean{.cdecl,
dynlib: gdkpixbuflib, importc: "gdk_pixbuf_get_has_alpha".}
proc gdk_pixbuf_get_bits_per_sample*(pixbuf: PGdkPixbuf): int32{.cdecl,
proc gdk_pixbuf_get_bits_per_sample*(pixbuf: PGdkPixbuf): int32{.cdecl,
dynlib: gdkpixbuflib, importc: "gdk_pixbuf_get_bits_per_sample".}
proc gdk_pixbuf_get_pixels*(pixbuf: PGdkPixbuf): Pguchar{.cdecl,
proc gdk_pixbuf_get_pixels*(pixbuf: PGdkPixbuf): Pguchar{.cdecl,
dynlib: gdkpixbuflib, importc: "gdk_pixbuf_get_pixels".}
proc gdk_pixbuf_get_width*(pixbuf: PGdkPixbuf): int32{.cdecl,
proc gdk_pixbuf_get_width*(pixbuf: PGdkPixbuf): int32{.cdecl,
dynlib: gdkpixbuflib, importc: "gdk_pixbuf_get_width".}
proc gdk_pixbuf_get_height*(pixbuf: PGdkPixbuf): int32{.cdecl,
proc gdk_pixbuf_get_height*(pixbuf: PGdkPixbuf): int32{.cdecl,
dynlib: gdkpixbuflib, importc: "gdk_pixbuf_get_height".}
proc gdk_pixbuf_get_rowstride*(pixbuf: PGdkPixbuf): int32{.cdecl,
proc gdk_pixbuf_get_rowstride*(pixbuf: PGdkPixbuf): int32{.cdecl,
dynlib: gdkpixbuflib, importc: "gdk_pixbuf_get_rowstride".}
proc gdk_pixbuf_new*(colorspace: TGdkColorspace, has_alpha: gboolean,
proc gdk_pixbuf_new*(colorspace: TGdkColorspace, has_alpha: gboolean,
bits_per_sample: int32, width: int32, height: int32): PGdkPixbuf{.
cdecl, dynlib: gdkpixbuflib, importc: "gdk_pixbuf_new".}
proc gdk_pixbuf_copy*(pixbuf: PGdkPixbuf): PGdkPixbuf{.cdecl,
proc gdk_pixbuf_copy*(pixbuf: PGdkPixbuf): PGdkPixbuf{.cdecl,
dynlib: gdkpixbuflib, importc: "gdk_pixbuf_copy".}
proc gdk_pixbuf_new_subpixbuf*(src_pixbuf: PGdkPixbuf, src_x: int32,
proc gdk_pixbuf_new_subpixbuf*(src_pixbuf: PGdkPixbuf, src_x: int32,
src_y: int32, width: int32, height: int32): PGdkPixbuf{.
cdecl, dynlib: gdkpixbuflib, importc: "gdk_pixbuf_new_subpixbuf".}
proc gdk_pixbuf_new_from_file*(filename: cstring, error: pointer): PGdkPixbuf{.
cdecl, dynlib: gdkpixbuflib, importc: "gdk_pixbuf_new_from_file".}
proc gdk_pixbuf_new_from_data*(data: Pguchar, colorspace: TGdkColorspace,
has_alpha: gboolean, bits_per_sample: int32,
width: int32, height: int32, rowstride: int32,
destroy_fn: TGdkPixbufDestroyNotify,
destroy_fn_data: gpointer): PGdkPixbuf{.cdecl,
proc gdk_pixbuf_new_from_data*(data: Pguchar, colorspace: TGdkColorspace,
has_alpha: gboolean, bits_per_sample: int32,
width: int32, height: int32, rowstride: int32,
destroy_fn: TGdkPixbufDestroyNotify,
destroy_fn_data: gpointer): PGdkPixbuf{.cdecl,
dynlib: gdkpixbuflib, importc: "gdk_pixbuf_new_from_data".}
proc gdk_pixbuf_new_from_xpm_data*(data: PPchar): PGdkPixbuf{.cdecl,
proc gdk_pixbuf_new_from_xpm_data*(data: PPchar): PGdkPixbuf{.cdecl,
dynlib: gdkpixbuflib, importc: "gdk_pixbuf_new_from_xpm_data".}
proc gdk_pixbuf_new_from_inline*(data_length: gint, a: var guint8,
proc gdk_pixbuf_new_from_inline*(data_length: gint, a: var guint8,
copy_pixels: gboolean, error: pointer): PGdkPixbuf{.
cdecl, dynlib: gdkpixbuflib, importc: "gdk_pixbuf_new_from_inline".}
when defined(HasGTK2_4):
proc gdk_pixbuf_new_from_file_at_size(filename: cstring, width, height: gint,
error: pointer): PGdkPixbuf{.cdecl,
dynlib: gdkpixbuflib, importc: "gdk_pixbuf_new_from_file_at_size".}
when defined(HasGTK2_6):
proc gdk_pixbuf_new_from_file_at_scale(filename: cstring, width, height: gint,
preserve_aspect_ratio: gboolean, error: pointer): PGdkPixbuf{.cdecl,
dynlib: gdkpixbuflib, importc: "gdk_pixbuf_new_from_file_at_scale".}
proc gdk_pixbuf_fill*(pixbuf: PGdkPixbuf, pixel: guint32){.cdecl,
proc gdk_pixbuf_new_from_file_at_size*(filename: cstring, width, height: gint,
error: pointer): PGdkPixbuf{.cdecl,
dynlib: gdkpixbuflib, importc: "gdk_pixbuf_new_from_file_at_size".}
proc gdk_pixbuf_new_from_file_at_scale*(filename: cstring, width, height: gint,
preserve_aspect_ratio: gboolean, error: pointer): PGdkPixbuf{.cdecl,
dynlib: gdkpixbuflib, importc: "gdk_pixbuf_new_from_file_at_scale".}
proc gdk_pixbuf_fill*(pixbuf: PGdkPixbuf, pixel: guint32){.cdecl,
dynlib: gdkpixbuflib, importc: "gdk_pixbuf_fill".}
proc gdk_pixbuf_save*(pixbuf: PGdkPixbuf, filename: cstring, `type`: cstring,
error: pointer): gboolean{.cdecl, varargs,
proc gdk_pixbuf_save*(pixbuf: PGdkPixbuf, filename: cstring, `type`: cstring,
error: pointer): gboolean{.cdecl, varargs,
dynlib: gdkpixbuflib, importc: "gdk_pixbuf_save".}
proc gdk_pixbuf_savev*(pixbuf: PGdkPixbuf, filename: cstring, `type`: cstring,
option_keys: PPchar, option_values: PPchar,
error: pointer): gboolean{.cdecl, dynlib: gdkpixbuflib,
proc gdk_pixbuf_savev*(pixbuf: PGdkPixbuf, filename: cstring, `type`: cstring,
option_keys: PPchar, option_values: PPchar,
error: pointer): gboolean{.cdecl, dynlib: gdkpixbuflib,
importc: "gdk_pixbuf_savev".}
proc gdk_pixbuf_add_alpha*(pixbuf: PGdkPixbuf, substitute_color: gboolean,
r: guchar, g: guchar, b: guchar): PGdkPixbuf{.cdecl,
proc gdk_pixbuf_add_alpha*(pixbuf: PGdkPixbuf, substitute_color: gboolean,
r: guchar, g: guchar, b: guchar): PGdkPixbuf{.cdecl,
dynlib: gdkpixbuflib, importc: "gdk_pixbuf_add_alpha".}
proc gdk_pixbuf_copy_area*(src_pixbuf: PGdkPixbuf, src_x: int32, src_y: int32,
width: int32, height: int32, dest_pixbuf: PGdkPixbuf,
dest_x: int32, dest_y: int32){.cdecl,
proc gdk_pixbuf_copy_area*(src_pixbuf: PGdkPixbuf, src_x: int32, src_y: int32,
width: int32, height: int32, dest_pixbuf: PGdkPixbuf,
dest_x: int32, dest_y: int32){.cdecl,
dynlib: gdkpixbuflib, importc: "gdk_pixbuf_copy_area".}
proc gdk_pixbuf_saturate_and_pixelate*(src: PGdkPixbuf, dest: PGdkPixbuf,
proc gdk_pixbuf_saturate_and_pixelate*(src: PGdkPixbuf, dest: PGdkPixbuf,
saturation: gfloat, pixelate: gboolean){.
cdecl, dynlib: gdkpixbuflib, importc: "gdk_pixbuf_saturate_and_pixelate".}
proc gdk_pixbuf_scale*(src: PGdkPixbuf, dest: PGdkPixbuf, dest_x: int32,
dest_y: int32, dest_width: int32, dest_height: int32,
offset_x: float64, offset_y: float64, scale_x: float64,
scale_y: float64, interp_type: TGdkInterpType){.cdecl,
proc gdk_pixbuf_scale*(src: PGdkPixbuf, dest: PGdkPixbuf, dest_x: int32,
dest_y: int32, dest_width: int32, dest_height: int32,
offset_x: float64, offset_y: float64, scale_x: float64,
scale_y: float64, interp_type: TGdkInterpType){.cdecl,
dynlib: gdkpixbuflib, importc: "gdk_pixbuf_scale".}
proc gdk_pixbuf_composite*(src: PGdkPixbuf, dest: PGdkPixbuf, dest_x: int32,
dest_y: int32, dest_width: int32, dest_height: int32,
offset_x: float64, offset_y: float64,
scale_x: float64, scale_y: float64,
proc gdk_pixbuf_composite*(src: PGdkPixbuf, dest: PGdkPixbuf, dest_x: int32,
dest_y: int32, dest_width: int32, dest_height: int32,
offset_x: float64, offset_y: float64,
scale_x: float64, scale_y: float64,
interp_type: TGdkInterpType, overall_alpha: int32){.
cdecl, dynlib: gdkpixbuflib, importc: "gdk_pixbuf_composite".}
proc gdk_pixbuf_composite_color*(src: PGdkPixbuf, dest: PGdkPixbuf,
dest_x: int32, dest_y: int32,
dest_width: int32, dest_height: int32,
offset_x: float64, offset_y: float64,
scale_x: float64, scale_y: float64,
interp_type: TGdkInterpType,
overall_alpha: int32, check_x: int32,
check_y: int32, check_size: int32,
color1: guint32, color2: guint32){.cdecl,
proc gdk_pixbuf_composite_color*(src: PGdkPixbuf, dest: PGdkPixbuf,
dest_x: int32, dest_y: int32,
dest_width: int32, dest_height: int32,
offset_x: float64, offset_y: float64,
scale_x: float64, scale_y: float64,
interp_type: TGdkInterpType,
overall_alpha: int32, check_x: int32,
check_y: int32, check_size: int32,
color1: guint32, color2: guint32){.cdecl,
dynlib: gdkpixbuflib, importc: "gdk_pixbuf_composite_color".}
proc gdk_pixbuf_scale_simple*(src: PGdkPixbuf, dest_width: int32,
proc gdk_pixbuf_scale_simple*(src: PGdkPixbuf, dest_width: int32,
dest_height: int32, interp_type: TGdkInterpType): PGdkPixbuf{.
cdecl, dynlib: gdkpixbuflib, importc: "gdk_pixbuf_scale_simple".}
proc gdk_pixbuf_composite_color_simple*(src: PGdkPixbuf, dest_width: int32,
dest_height: int32,
interp_type: TGdkInterpType,
overall_alpha: int32, check_size: int32,
proc gdk_pixbuf_composite_color_simple*(src: PGdkPixbuf, dest_width: int32,
dest_height: int32,
interp_type: TGdkInterpType,
overall_alpha: int32, check_size: int32,
color1: guint32, color2: guint32): PGdkPixbuf{.
cdecl, dynlib: gdkpixbuflib, importc: "gdk_pixbuf_composite_color_simple".}
proc gdk_pixbuf_animation_get_type*(): GType{.cdecl, dynlib: gdkpixbuflib,
proc gdk_pixbuf_animation_get_type*(): GType{.cdecl, dynlib: gdkpixbuflib,
importc: "gdk_pixbuf_animation_get_type".}
proc gdk_pixbuf_animation_new_from_file*(filename: cstring, error: pointer): PGdkPixbufAnimation{.
cdecl, dynlib: gdkpixbuflib, importc: "gdk_pixbuf_animation_new_from_file".}
when not defined(GDK_PIXBUF_DISABLE_DEPRECATED):
proc gdk_pixbuf_animation_ref(animation: PGdkPixbufAnimation): PGdkPixbufAnimation{.
when not defined(GDK_PIXBUF_DISABLE_DEPRECATED):
proc gdk_pixbuf_animation_ref*(animation: PGdkPixbufAnimation): PGdkPixbufAnimation{.
cdecl, dynlib: gdkpixbuflib, importc: "gdk_pixbuf_animation_ref".}
proc gdk_pixbuf_animation_unref(animation: PGdkPixbufAnimation){.cdecl,
proc gdk_pixbuf_animation_unref*(animation: PGdkPixbufAnimation){.cdecl,
dynlib: gdkpixbuflib, importc: "gdk_pixbuf_animation_unref".}
proc gdk_pixbuf_animation_get_width*(animation: PGdkPixbufAnimation): int32{.
cdecl, dynlib: gdkpixbuflib, importc: "gdk_pixbuf_animation_get_width".}
@ -169,37 +165,37 @@ proc gdk_pixbuf_animation_get_height*(animation: PGdkPixbufAnimation): int32{.
proc gdk_pixbuf_animation_is_static_image*(animation: PGdkPixbufAnimation): gboolean{.
cdecl, dynlib: gdkpixbuflib, importc: "gdk_pixbuf_animation_is_static_image".}
proc gdk_pixbuf_animation_get_static_image*(animation: PGdkPixbufAnimation): PGdkPixbuf{.
cdecl, dynlib: gdkpixbuflib,
cdecl, dynlib: gdkpixbuflib,
importc: "gdk_pixbuf_animation_get_static_image".}
proc gdk_pixbuf_animation_get_iter*(animation: PGdkPixbufAnimation,
proc gdk_pixbuf_animation_get_iter*(animation: PGdkPixbufAnimation,
e: var TGTimeVal): PGdkPixbufAnimationIter{.
cdecl, dynlib: gdkpixbuflib, importc: "gdk_pixbuf_animation_get_iter".}
proc gdk_pixbuf_animation_iter_get_type*(): GType{.cdecl, dynlib: gdkpixbuflib,
proc gdk_pixbuf_animation_iter_get_type*(): GType{.cdecl, dynlib: gdkpixbuflib,
importc: "gdk_pixbuf_animation_iter_get_type".}
proc gdk_pixbuf_animation_iter_get_delay_time*(iter: PGdkPixbufAnimationIter): int32{.
cdecl, dynlib: gdkpixbuflib,
cdecl, dynlib: gdkpixbuflib,
importc: "gdk_pixbuf_animation_iter_get_delay_time".}
proc gdk_pixbuf_animation_iter_get_pixbuf*(iter: PGdkPixbufAnimationIter): PGdkPixbuf{.
cdecl, dynlib: gdkpixbuflib, importc: "gdk_pixbuf_animation_iter_get_pixbuf".}
proc gdk_pixbuf_animation_iter_on_currently_loading_frame*(
iter: PGdkPixbufAnimationIter): gboolean{.cdecl, dynlib: gdkpixbuflib,
iter: PGdkPixbufAnimationIter): gboolean{.cdecl, dynlib: gdkpixbuflib,
importc: "gdk_pixbuf_animation_iter_on_currently_loading_frame".}
proc gdk_pixbuf_animation_iter_advance*(iter: PGdkPixbufAnimationIter,
e: var TGTimeVal): gboolean{.cdecl,
proc gdk_pixbuf_animation_iter_advance*(iter: PGdkPixbufAnimationIter,
e: var TGTimeVal): gboolean{.cdecl,
dynlib: gdkpixbuflib, importc: "gdk_pixbuf_animation_iter_advance".}
proc gdk_pixbuf_get_option*(pixbuf: PGdkPixbuf, key: cstring): cstring{.cdecl,
proc gdk_pixbuf_get_option*(pixbuf: PGdkPixbuf, key: cstring): cstring{.cdecl,
dynlib: gdkpixbuflib, importc: "gdk_pixbuf_get_option".}
type
type
PGdkPixbufLoader* = ptr TGdkPixbufLoader
TGdkPixbufLoader* {.final.} = object
TGdkPixbufLoader* {.final.} = object
parent_instance*: TGObject
priv*: gpointer
PGdkPixbufLoaderClass* = ptr TGdkPixbufLoaderClass
TGdkPixbufLoaderClass* {.final.} = object
TGdkPixbufLoaderClass* {.final.} = object
parent_class*: TGObjectClass
area_prepared*: proc (loader: PGdkPixbufLoader){.cdecl.}
area_updated*: proc (loader: PGdkPixbufLoader, x: int32, y: int32,
area_updated*: proc (loader: PGdkPixbufLoader, x: int32, y: int32,
width: int32, height: int32){.cdecl.}
closed*: proc (loader: PGdkPixbufLoader){.cdecl.}
@ -210,70 +206,70 @@ proc GDK_PIXBUF_LOADER_CLASS*(klass: pointer): PGdkPixbufLoaderClass
proc GDK_IS_PIXBUF_LOADER*(obj: pointer): bool
proc GDK_IS_PIXBUF_LOADER_CLASS*(klass: pointer): bool
proc GDK_PIXBUF_LOADER_GET_CLASS*(obj: pointer): PGdkPixbufLoaderClass
proc gdk_pixbuf_loader_get_type*(): GType{.cdecl, dynlib: gdkpixbuflib,
proc gdk_pixbuf_loader_get_type*(): GType{.cdecl, dynlib: gdkpixbuflib,
importc: "gdk_pixbuf_loader_get_type".}
proc gdk_pixbuf_loader_new*(): PGdkPixbufLoader{.cdecl, dynlib: gdkpixbuflib,
proc gdk_pixbuf_loader_new*(): PGdkPixbufLoader{.cdecl, dynlib: gdkpixbuflib,
importc: "gdk_pixbuf_loader_new".}
proc gdk_pixbuf_loader_new_with_type*(image_type: cstring, error: pointer): PGdkPixbufLoader{.
cdecl, dynlib: gdkpixbuflib, importc: "gdk_pixbuf_loader_new_with_type".}
proc gdk_pixbuf_loader_write*(loader: PGdkPixbufLoader, buf: Pguchar,
count: gsize, error: pointer): gboolean{.cdecl,
proc gdk_pixbuf_loader_write*(loader: PGdkPixbufLoader, buf: Pguchar,
count: gsize, error: pointer): gboolean{.cdecl,
dynlib: gdkpixbuflib, importc: "gdk_pixbuf_loader_write".}
proc gdk_pixbuf_loader_get_pixbuf*(loader: PGdkPixbufLoader): PGdkPixbuf{.cdecl,
proc gdk_pixbuf_loader_get_pixbuf*(loader: PGdkPixbufLoader): PGdkPixbuf{.cdecl,
dynlib: gdkpixbuflib, importc: "gdk_pixbuf_loader_get_pixbuf".}
proc gdk_pixbuf_loader_get_animation*(loader: PGdkPixbufLoader): PGdkPixbufAnimation{.
cdecl, dynlib: gdkpixbuflib, importc: "gdk_pixbuf_loader_get_animation".}
proc gdk_pixbuf_loader_close*(loader: PGdkPixbufLoader, error: pointer): gboolean{.
cdecl, dynlib: gdkpixbuflib, importc: "gdk_pixbuf_loader_close".}
proc GDK_TYPE_PIXBUF_LOADER*(): GType =
proc GDK_TYPE_PIXBUF_LOADER*(): GType =
result = gdk_pixbuf_loader_get_type()
proc GDK_PIXBUF_LOADER*(obj: pointer): PGdkPixbufLoader =
result = cast[PGdkPixbufLoader](G_TYPE_CHECK_INSTANCE_CAST(obj,
proc GDK_PIXBUF_LOADER*(obj: pointer): PGdkPixbufLoader =
result = cast[PGdkPixbufLoader](G_TYPE_CHECK_INSTANCE_CAST(obj,
GDK_TYPE_PIXBUF_LOADER()))
proc GDK_PIXBUF_LOADER_CLASS*(klass: pointer): PGdkPixbufLoaderClass =
result = cast[PGdkPixbufLoaderClass](G_TYPE_CHECK_CLASS_CAST(klass,
proc GDK_PIXBUF_LOADER_CLASS*(klass: pointer): PGdkPixbufLoaderClass =
result = cast[PGdkPixbufLoaderClass](G_TYPE_CHECK_CLASS_CAST(klass,
GDK_TYPE_PIXBUF_LOADER()))
proc GDK_IS_PIXBUF_LOADER*(obj: pointer): bool =
proc GDK_IS_PIXBUF_LOADER*(obj: pointer): bool =
result = G_TYPE_CHECK_INSTANCE_TYPE(obj, GDK_TYPE_PIXBUF_LOADER())
proc GDK_IS_PIXBUF_LOADER_CLASS*(klass: pointer): bool =
proc GDK_IS_PIXBUF_LOADER_CLASS*(klass: pointer): bool =
result = G_TYPE_CHECK_CLASS_TYPE(klass, GDK_TYPE_PIXBUF_LOADER())
proc GDK_PIXBUF_LOADER_GET_CLASS*(obj: pointer): PGdkPixbufLoaderClass =
result = cast[PGdkPixbufLoaderClass](G_TYPE_INSTANCE_GET_CLASS(obj,
proc GDK_PIXBUF_LOADER_GET_CLASS*(obj: pointer): PGdkPixbufLoaderClass =
result = cast[PGdkPixbufLoaderClass](G_TYPE_INSTANCE_GET_CLASS(obj,
GDK_TYPE_PIXBUF_LOADER()))
proc GDK_TYPE_PIXBUF*(): GType =
proc GDK_TYPE_PIXBUF*(): GType =
result = gdk_pixbuf_get_type()
proc GDK_PIXBUF*(anObject: pointer): PGdkPixbuf =
proc GDK_PIXBUF*(anObject: pointer): PGdkPixbuf =
result = cast[PGdkPixbuf](G_TYPE_CHECK_INSTANCE_CAST(anObject, GDK_TYPE_PIXBUF()))
proc GDK_IS_PIXBUF*(anObject: pointer): bool =
proc GDK_IS_PIXBUF*(anObject: pointer): bool =
result = G_TYPE_CHECK_INSTANCE_TYPE(anObject, GDK_TYPE_PIXBUF())
proc GDK_TYPE_PIXBUF_ANIMATION*(): GType =
proc GDK_TYPE_PIXBUF_ANIMATION*(): GType =
result = gdk_pixbuf_animation_get_type()
proc GDK_PIXBUF_ANIMATION*(anObject: pointer): PGdkPixbufAnimation =
result = cast[PGdkPixbufAnimation](G_TYPE_CHECK_INSTANCE_CAST(anObject,
proc GDK_PIXBUF_ANIMATION*(anObject: pointer): PGdkPixbufAnimation =
result = cast[PGdkPixbufAnimation](G_TYPE_CHECK_INSTANCE_CAST(anObject,
GDK_TYPE_PIXBUF_ANIMATION()))
proc GDK_IS_PIXBUF_ANIMATION*(anObject: pointer): bool =
proc GDK_IS_PIXBUF_ANIMATION*(anObject: pointer): bool =
result = G_TYPE_CHECK_INSTANCE_TYPE(anObject, GDK_TYPE_PIXBUF_ANIMATION())
proc GDK_TYPE_PIXBUF_ANIMATION_ITER*(): GType =
proc GDK_TYPE_PIXBUF_ANIMATION_ITER*(): GType =
result = gdk_pixbuf_animation_iter_get_type()
proc GDK_PIXBUF_ANIMATION_ITER*(anObject: pointer): PGdkPixbufAnimationIter =
result = cast[PGdkPixbufAnimationIter](G_TYPE_CHECK_INSTANCE_CAST(anObject,
proc GDK_PIXBUF_ANIMATION_ITER*(anObject: pointer): PGdkPixbufAnimationIter =
result = cast[PGdkPixbufAnimationIter](G_TYPE_CHECK_INSTANCE_CAST(anObject,
GDK_TYPE_PIXBUF_ANIMATION_ITER()))
proc GDK_IS_PIXBUF_ANIMATION_ITER*(anObject: pointer): bool =
proc GDK_IS_PIXBUF_ANIMATION_ITER*(anObject: pointer): bool =
result = G_TYPE_CHECK_INSTANCE_TYPE(anObject, GDK_TYPE_PIXBUF_ANIMATION_ITER())
proc GDK_PIXBUF_ERROR*(): TGQuark =
proc GDK_PIXBUF_ERROR*(): TGQuark =
result = gdk_pixbuf_error_quark()

View file

@ -1,16 +1,16 @@
when defined(windows):
{.define: gtkwin.}
const
gliblib = "libglib-2.0-0.dll"
gthreadlib = "libgthread-2.0-0.dll"
gmodulelib = "libgmodule-2.0-0.dll"
gobjectlib = "libgobject-2.0-0.dll"
else:
const
gliblib = "libglib-2.0.so"
gthreadlib = "libgthread-2.0.so"
gmodulelib = "libgmodule-2.0.so"
gobjectlib = "libgobject-2.0.so"
# gthreadlib = "libgthread-2.0.so"
type
PGTypePlugin* = pointer
PGParamSpecPool* = pointer
@ -19,29 +19,29 @@ type
PPPgchar* = ptr PPgchar
PPgchar* = ptr cstring
gchar* = char
Pgshort* = ptr gshort
gshort* = cshort
Pglong* = ptr glong
glong* = clong
Pgint* = ptr gint
PPgint* = ptr Pgint
gint* = cint
Pgboolean* = ptr gboolean
gboolean* = bool
Pguchar* = ptr guchar
PPguchar* = ptr Pguchar
guchar* = char
Pgushort* = ptr gushort
gushort* = int16
Pgulong* = ptr gulong
gulong* = int
guint* = cint
Pguint* = ptr guint
gfloat* = cfloat
Pgfloat* = ptr gfloat
gdouble* = cdouble
Pgdouble* = ptr gdouble
gpointer* = pointer
Pgshort* = ptr gshort
Pglong* = ptr glong
Pgint* = ptr gint
PPgint* = ptr Pgint
Pgboolean* = ptr gboolean
Pguchar* = ptr guchar
PPguchar* = ptr Pguchar
Pgushort* = ptr gushort
Pgulong* = ptr gulong
Pguint* = ptr guint
Pgfloat* = ptr gfloat
Pgdouble* = ptr gdouble
pgpointer* = ptr gpointer
gconstpointer* = pointer
PGCompareFunc* = ptr TGCompareFunc
@ -118,8 +118,8 @@ type
g_type*: GType
data*: array[0..1, gdouble]
PPGData* = ptr PGData
PGData* = pointer
PPGData* = ptr PGData
PGSList* = ptr TGSList
PPGSList* = ptr PGSList
TGSList* {.final.} = object
@ -132,8 +132,8 @@ type
next*: PGList
prev*: PGList
PGParamFlags* = ptr TGParamFlags
TGParamFlags* = int32
PGParamFlags* = ptr TGParamFlags
PGParamSpec* = ptr TGParamSpec
PPGParamSpec* = ptr PGParamSpec
TGParamSpec* {.final.} = object
@ -194,7 +194,7 @@ const
G_TYPE_PARAM* = GType(19 shl G_TYPE_FUNDAMENTAL_SHIFT)
G_TYPE_OBJECT* = GType(20 shl G_TYPE_FUNDAMENTAL_SHIFT)
proc G_TYPE_MAKE_FUNDAMENTAL*(x: int32): GType
proc G_TYPE_MAKE_FUNDAMENTAL*(x: int): GType
const
G_TYPE_RESERVED_GLIB_FIRST* = 21
G_TYPE_RESERVED_GLIB_LAST* = 31
@ -226,8 +226,8 @@ proc G_TYPE_FROM_INSTANCE*(instance: Pointer): GType
proc G_TYPE_FROM_CLASS*(g_class: Pointer): GType
proc G_TYPE_FROM_INTERFACE*(g_iface: Pointer): GType
type
PGTypeDebugFlags* = ptr TGTypeDebugFlags
TGTypeDebugFlags* = int32
PGTypeDebugFlags* = ptr TGTypeDebugFlags
const
G_TYPE_DEBUG_NONE* = 0
@ -296,8 +296,8 @@ const
G_TYPE_FLAG_DEEP_DERIVABLE* = 1 shl 3
type
PGTypeFlags* = ptr TGTypeFlags
TGTypeFlags* = int32
PGTypeFlags* = ptr TGTypeFlags
const
G_TYPE_FLAG_ABSTRACT* = 1 shl 4
@ -562,8 +562,8 @@ proc g_strdup_value_contents*(value: PGValue): cstring{.cdecl,
proc g_value_set_string_take_ownership*(value: PGValue, v_string: cstring){.
cdecl, dynlib: gobjectlib, importc: "g_value_set_string_take_ownership".}
type
Pgchararray* = ptr Tgchararray
Tgchararray* = gchar
Pgchararray* = ptr Tgchararray
proc G_TYPE_IS_PARAM*(theType: GType): bool
proc G_PARAM_SPEC*(pspec: Pointer): PGParamSpec
@ -692,26 +692,26 @@ proc G_CLOSURE_N_NOTIFIERS*(cl: PGClosure): int32
proc G_CCLOSURE_SWAP_DATA*(cclosure: PGClosure): int32
proc G_CALLBACK*(f: pointer): TGCallback
const
bm_TGClosure_ref_count* = 0x00007FFF
bp_TGClosure_ref_count* = 0
bm_TGClosure_meta_marshal* = 0x00008000
bp_TGClosure_meta_marshal* = 15
bm_TGClosure_n_guards* = 0x00010000
bp_TGClosure_n_guards* = 16
bm_TGClosure_n_fnotifiers* = 0x00060000
bp_TGClosure_n_fnotifiers* = 17
bm_TGClosure_n_inotifiers* = 0x07F80000
bp_TGClosure_n_inotifiers* = 19
bm_TGClosure_in_inotify* = 0x08000000
bp_TGClosure_in_inotify* = 27
bm_TGClosure_floating* = 0x10000000
bp_TGClosure_floating* = 28
bm_TGClosure_derivative_flag* = 0x20000000
bp_TGClosure_derivative_flag* = 29
bm_TGClosure_in_marshal* = 0x40000000
bp_TGClosure_in_marshal* = 30
bm_TGClosure_is_invalid* = 0x80000000
bp_TGClosure_is_invalid* = 31
bm_TGClosure_ref_count* = 0x00007FFF'i32
bp_TGClosure_ref_count* = 0'i32
bm_TGClosure_meta_marshal* = 0x00008000'i32
bp_TGClosure_meta_marshal* = 15'i32
bm_TGClosure_n_guards* = 0x00010000'i32
bp_TGClosure_n_guards* = 16'i32
bm_TGClosure_n_fnotifiers* = 0x00060000'i32
bp_TGClosure_n_fnotifiers* = 17'i32
bm_TGClosure_n_inotifiers* = 0x07F80000'i32
bp_TGClosure_n_inotifiers* = 19'i32
bm_TGClosure_in_inotify* = 0x08000000'i32
bp_TGClosure_in_inotify* = 27'i32
bm_TGClosure_floating* = 0x10000000'i32
bp_TGClosure_floating* = 28'i32
bm_TGClosure_derivative_flag* = 0x20000000'i32
bp_TGClosure_derivative_flag* = 29'i32
bm_TGClosure_in_marshal* = 0x40000000'i32
bp_TGClosure_in_marshal* = 30'i32
bm_TGClosure_is_invalid* = 0x80000000'i32
bp_TGClosure_is_invalid* = 31'i32
proc ref_count*(a: var TGClosure): guint
proc set_ref_count*(a: var TGClosure, ref_count: guint)
@ -2061,16 +2061,16 @@ type
TGHookFlagMask* = int
const
G_HOOK_FLAG_ACTIVE* = 1 shl 0
G_HOOK_FLAG_IN_CALL* = 1 shl 1
G_HOOK_FLAG_MASK* = 0x0000000F
G_HOOK_FLAG_ACTIVE* = 1'i32 shl 0'i32
G_HOOK_FLAG_IN_CALL* = 1'i32 shl 1'i32
G_HOOK_FLAG_MASK* = 0x0000000F'i32
const
G_HOOK_FLAG_USER_SHIFT* = 4
bm_TGHookList_hook_size* = 0x0000FFFF
bp_TGHookList_hook_size* = 0
bm_TGHookList_is_setup* = 0x00010000
bp_TGHookList_is_setup* = 16
G_HOOK_FLAG_USER_SHIFT* = 4'i32
bm_TGHookList_hook_size* = 0x0000FFFF'i32
bp_TGHookList_hook_size* = 0'i32
bm_TGHookList_is_setup* = 0x00010000'i32
bp_TGHookList_is_setup* = 16'i32
proc TGHookList_hook_size*(a: var TGHookList): guint
proc TGHookList_set_hook_size*(a: var TGHookList, `hook_size`: guint)
@ -2502,18 +2502,18 @@ type
const
bm_TGIOChannel_use_buffer* = 0x00000001
bp_TGIOChannel_use_buffer* = 0
bm_TGIOChannel_do_encode* = 0x00000002
bp_TGIOChannel_do_encode* = 1
bm_TGIOChannel_close_on_unref* = 0x00000004
bp_TGIOChannel_close_on_unref* = 2
bm_TGIOChannel_is_readable* = 0x00000008
bp_TGIOChannel_is_readable* = 3
bm_TGIOChannel_is_writeable* = 0x00000010
bp_TGIOChannel_is_writeable* = 4
bm_TGIOChannel_is_seekable* = 0x00000020
bp_TGIOChannel_is_seekable* = 5
bm_TGIOChannel_use_buffer* = 0x00000001'i16
bp_TGIOChannel_use_buffer* = 0'i16
bm_TGIOChannel_do_encode* = 0x00000002'i16
bp_TGIOChannel_do_encode* = 1'i16
bm_TGIOChannel_close_on_unref* = 0x00000004'i16
bp_TGIOChannel_close_on_unref* = 2'i16
bm_TGIOChannel_is_readable* = 0x00000008'i16
bp_TGIOChannel_is_readable* = 3'i16
bm_TGIOChannel_is_writeable* = 0x00000010'i16
bp_TGIOChannel_is_writeable* = 4'i16
bm_TGIOChannel_is_seekable* = 0x00000020'i16
bp_TGIOChannel_is_seekable* = 5'i16
proc TGIOChannel_use_buffer*(a: var TGIOChannel): guint
proc TGIOChannel_set_use_buffer*(a: var TGIOChannel, `use_buffer`: guint)
@ -3046,48 +3046,48 @@ const
G_CSET_DIGITS* = "0123456789"
const
bm_TGScannerConfig_case_sensitive* = 0x00000001
bp_TGScannerConfig_case_sensitive* = 0
bm_TGScannerConfig_skip_comment_multi* = 0x00000002
bp_TGScannerConfig_skip_comment_multi* = 1
bm_TGScannerConfig_skip_comment_single* = 0x00000004
bp_TGScannerConfig_skip_comment_single* = 2
bm_TGScannerConfig_scan_comment_multi* = 0x00000008
bp_TGScannerConfig_scan_comment_multi* = 3
bm_TGScannerConfig_scan_identifier* = 0x00000010
bp_TGScannerConfig_scan_identifier* = 4
bm_TGScannerConfig_scan_identifier_1char* = 0x00000020
bp_TGScannerConfig_scan_identifier_1char* = 5
bm_TGScannerConfig_scan_identifier_NULL* = 0x00000040
bp_TGScannerConfig_scan_identifier_NULL* = 6
bm_TGScannerConfig_scan_symbols* = 0x00000080
bp_TGScannerConfig_scan_symbols* = 7
bm_TGScannerConfig_scan_binary* = 0x00000100
bp_TGScannerConfig_scan_binary* = 8
bm_TGScannerConfig_scan_octal* = 0x00000200
bp_TGScannerConfig_scan_octal* = 9
bm_TGScannerConfig_scan_float* = 0x00000400
bp_TGScannerConfig_scan_float* = 10
bm_TGScannerConfig_scan_hex* = 0x00000800
bp_TGScannerConfig_scan_hex* = 11
bm_TGScannerConfig_scan_hex_dollar* = 0x00001000
bp_TGScannerConfig_scan_hex_dollar* = 12
bm_TGScannerConfig_scan_string_sq* = 0x00002000
bp_TGScannerConfig_scan_string_sq* = 13
bm_TGScannerConfig_scan_string_dq* = 0x00004000
bp_TGScannerConfig_scan_string_dq* = 14
bm_TGScannerConfig_numbers_2_int* = 0x00008000
bp_TGScannerConfig_numbers_2_int* = 15
bm_TGScannerConfig_int_2_float* = 0x00010000
bp_TGScannerConfig_int_2_float* = 16
bm_TGScannerConfig_identifier_2_string* = 0x00020000
bp_TGScannerConfig_identifier_2_string* = 17
bm_TGScannerConfig_char_2_token* = 0x00040000
bp_TGScannerConfig_char_2_token* = 18
bm_TGScannerConfig_symbol_2_token* = 0x00080000
bp_TGScannerConfig_symbol_2_token* = 19
bm_TGScannerConfig_scope_0_fallback* = 0x00100000
bp_TGScannerConfig_scope_0_fallback* = 20
bm_TGScannerConfig_case_sensitive* = 0x00000001'i32
bp_TGScannerConfig_case_sensitive* = 0'i32
bm_TGScannerConfig_skip_comment_multi* = 0x00000002'i32
bp_TGScannerConfig_skip_comment_multi* = 1'i32
bm_TGScannerConfig_skip_comment_single* = 0x00000004'i32
bp_TGScannerConfig_skip_comment_single* = 2'i32
bm_TGScannerConfig_scan_comment_multi* = 0x00000008'i32
bp_TGScannerConfig_scan_comment_multi* = 3'i32
bm_TGScannerConfig_scan_identifier* = 0x00000010'i32
bp_TGScannerConfig_scan_identifier* = 4'i32
bm_TGScannerConfig_scan_identifier_1char* = 0x00000020'i32
bp_TGScannerConfig_scan_identifier_1char* = 5'i32
bm_TGScannerConfig_scan_identifier_NULL* = 0x00000040'i32
bp_TGScannerConfig_scan_identifier_NULL* = 6'i32
bm_TGScannerConfig_scan_symbols* = 0x00000080'i32
bp_TGScannerConfig_scan_symbols* = 7'i32
bm_TGScannerConfig_scan_binary* = 0x00000100'i32
bp_TGScannerConfig_scan_binary* = 8'i32
bm_TGScannerConfig_scan_octal* = 0x00000200'i32
bp_TGScannerConfig_scan_octal* = 9'i32
bm_TGScannerConfig_scan_float* = 0x00000400'i32
bp_TGScannerConfig_scan_float* = 10'i32
bm_TGScannerConfig_scan_hex* = 0x00000800'i32
bp_TGScannerConfig_scan_hex* = 11'i32
bm_TGScannerConfig_scan_hex_dollar* = 0x00001000'i32
bp_TGScannerConfig_scan_hex_dollar* = 12'i32
bm_TGScannerConfig_scan_string_sq* = 0x00002000'i32
bp_TGScannerConfig_scan_string_sq* = 13'i32
bm_TGScannerConfig_scan_string_dq* = 0x00004000'i32
bp_TGScannerConfig_scan_string_dq* = 14'i32
bm_TGScannerConfig_numbers_2_int* = 0x00008000'i32
bp_TGScannerConfig_numbers_2_int* = 15'i32
bm_TGScannerConfig_int_2_float* = 0x00010000'i32
bp_TGScannerConfig_int_2_float* = 16'i32
bm_TGScannerConfig_identifier_2_string* = 0x00020000'i32
bp_TGScannerConfig_identifier_2_string* = 17'i32
bm_TGScannerConfig_char_2_token* = 0x00040000'i32
bp_TGScannerConfig_char_2_token* = 18'i32
bm_TGScannerConfig_symbol_2_token* = 0x00080000'i32
bp_TGScannerConfig_symbol_2_token* = 19'i32
bm_TGScannerConfig_scope_0_fallback* = 0x00100000'i32
bp_TGScannerConfig_scope_0_fallback* = 20'i32
proc TGScannerConfig_case_sensitive*(a: var TGScannerConfig): guint
proc TGScannerConfig_set_case_sensitive*(a: var TGScannerConfig,
@ -3439,19 +3439,21 @@ proc g_cclosure_marshal_BOOL__FLAGS*(closure: PGClosure, return_value: PGValue,
marshal_data: GPointer){.cdecl,
dynlib: gliblib, importc: "g_cclosure_marshal_BOOLEAN__FLAGS".}
proc GUINT16_SWAP_LE_BE_CONSTANT*(val: guint16): guint16 =
Result = ((val and 0x000000FF) shl 8) or ((val and 0x0000FF00) shr 8)
Result = ((val and 0x00FF'i16) shl 8'i16) or ((val and 0xFF00'i16) shr 8'i16)
proc GUINT32_SWAP_LE_BE_CONSTANT*(val: guint32): guint32 =
Result = ((val and 0x000000FF) shl 24) or ((val and 0x0000FF00) shl 8) or
((val and 0x00FF0000) shr 8) or ((val and 0xFF000000) shr 24)
Result = ((val and 0x000000FF'i32) shl 24'i32) or ((val and 0x0000FF00'i32) shl 8'i32) or
((val and 0x00FF0000'i32) shr 8'i32) or ((val and 0xFF000000'i32) shr 24'i32)
proc GUINT_TO_POINTER*(i: guint): pointer =
Result = cast[Pointer](TAddress(i))
type
PGArray = pointer
when false:
type
PGArray* = pointer
proc g_array_append_val*(a: PGArray, v: gpointer): PGArray =
result = g_array_append_vals(a, addr(v), 1)
@ -3678,17 +3680,17 @@ proc G_HOOK_FLAGS*(hook: PGHook): guint =
result = hook.flags
proc G_HOOK_ACTIVE*(hook: PGHook): bool =
result = (hook.flags and G_HOOK_FLAG_ACTIVE) != 0
result = (hook.flags and G_HOOK_FLAG_ACTIVE) != 0'i32
proc G_HOOK_IN_CALL*(hook: PGHook): bool =
result = (hook.flags and G_HOOK_FLAG_IN_CALL) != 0
result = (hook.flags and G_HOOK_FLAG_IN_CALL) != 0'i32
proc G_HOOK_IS_VALID*(hook: PGHook): bool =
result = (hook.hook_id != 0) and G_HOOK_ACTIVE(hook)
proc G_HOOK_IS_UNLINKED*(hook: PGHook): bool =
result = (hook.next == nil) and (hook.prev == nil) and
(hook.hook_id == 0) and (hook.ref_count == 0)
(hook.hook_id == 0) and (hook.ref_count == 0'i32)
proc g_hook_append*(hook_list: PGHookList, hook: PGHook) =
g_hook_insert_before(hook_list, nil, hook)
@ -3702,7 +3704,7 @@ proc TGIOChannel_use_buffer*(a: var TGIOChannel): guint =
proc TGIOChannel_set_use_buffer*(a: var TGIOChannel, `use_buffer`: guint) =
a.flag0 = a.flag0 or
((`use_buffer` shl bp_TGIOChannel_use_buffer) and
(int16(`use_buffer` shl bp_TGIOChannel_use_buffer) and
bm_TGIOChannel_use_buffer)
proc TGIOChannel_do_encode*(a: var TGIOChannel): guint =
@ -3711,7 +3713,7 @@ proc TGIOChannel_do_encode*(a: var TGIOChannel): guint =
proc TGIOChannel_set_do_encode*(a: var TGIOChannel, `do_encode`: guint) =
a.flag0 = a.flag0 or
((`do_encode` shl bp_TGIOChannel_do_encode) and
(int16(`do_encode` shl bp_TGIOChannel_do_encode) and
bm_TGIOChannel_do_encode)
proc TGIOChannel_close_on_unref*(a: var TGIOChannel): guint =
@ -3720,7 +3722,7 @@ proc TGIOChannel_close_on_unref*(a: var TGIOChannel): guint =
proc TGIOChannel_set_close_on_unref*(a: var TGIOChannel, `close_on_unref`: guint) =
a.flag0 = a.flag0 or
((`close_on_unref` shl bp_TGIOChannel_close_on_unref) and
(int16(`close_on_unref` shl bp_TGIOChannel_close_on_unref) and
bm_TGIOChannel_close_on_unref)
proc TGIOChannel_is_readable*(a: var TGIOChannel): guint =
@ -3729,7 +3731,7 @@ proc TGIOChannel_is_readable*(a: var TGIOChannel): guint =
proc TGIOChannel_set_is_readable*(a: var TGIOChannel, `is_readable`: guint) =
a.flag0 = a.flag0 or
((`is_readable` shl bp_TGIOChannel_is_readable) and
(int16(`is_readable` shl bp_TGIOChannel_is_readable) and
bm_TGIOChannel_is_readable)
proc TGIOChannel_is_writeable*(a: var TGIOChannel): guint =
@ -3738,7 +3740,7 @@ proc TGIOChannel_is_writeable*(a: var TGIOChannel): guint =
proc TGIOChannel_set_is_writeable*(a: var TGIOChannel, `is_writeable`: guint) =
a.flag0 = a.flag0 or
((`is_writeable` shl bp_TGIOChannel_is_writeable) and
(int16(`is_writeable` shl bp_TGIOChannel_is_writeable) and
bm_TGIOChannel_is_writeable)
proc TGIOChannel_is_seekable*(a: var TGIOChannel): guint =
@ -3747,7 +3749,7 @@ proc TGIOChannel_is_seekable*(a: var TGIOChannel): guint =
proc TGIOChannel_set_is_seekable*(a: var TGIOChannel, `is_seekable`: guint) =
a.flag0 = a.flag0 or
((`is_seekable` shl bp_TGIOChannel_is_seekable) and
(int16(`is_seekable` shl bp_TGIOChannel_is_seekable) and
bm_TGIOChannel_is_seekable)
proc g_utf8_next_char*(p: pguchar): pguchar =
@ -3816,10 +3818,10 @@ proc g_node_first_child*(node: PGNode): PGNode =
result = nil
proc g_rand_boolean*(rand: PGRand): gboolean =
result = ((g_rand_int(rand)) and (1 shl 15)) != 0
result = (int(g_rand_int(rand)) and (1 shl 15)) != 0
proc g_random_boolean*(): gboolean =
result = (g_random_int() and (1 shl 15)) != 0
result = (int(g_random_int()) and (1 shl 15)) != 0
proc TGScannerConfig_case_sensitive*(a: var TGScannerConfig): guint =
result = (a.flag0 and bm_TGScannerConfig_case_sensitive) shr
@ -4077,7 +4079,7 @@ when false:
proc g_strstrip*(str: cstring): cstring =
result = g_strchomp(g_strchug(str))
proc G_TYPE_MAKE_FUNDAMENTAL*(x: int32): GType =
proc G_TYPE_MAKE_FUNDAMENTAL*(x: int): GType =
result = GType(x shl G_TYPE_FUNDAMENTAL_SHIFT)
proc G_TYPE_IS_FUNDAMENTAL*(theType: GType): bool =
@ -4202,7 +4204,7 @@ proc G_CLOSURE_NEEDS_MARSHAL*(closure: Pointer): bool =
result = cast[PGClosure](closure).marshal == nil
proc G_CLOSURE_N_NOTIFIERS*(cl: PGClosure): int32 =
result = ((meta_marshal(cl) + ((n_guards(cl)) shl 1)) + (n_fnotifiers(cl))) +
result = ((meta_marshal(cl) + ((n_guards(cl)) shl 1'i32)) + (n_fnotifiers(cl))) +
(n_inotifiers(cl))
proc G_CCLOSURE_SWAP_DATA*(cclosure: PGClosure): int32 =

File diff suppressed because it is too large Load diff

View file

@ -1,14 +1,13 @@
import
import
glib2, gtk2
when defined(win32):
{.define: gtkwin.}
const
when defined(win32):
const
LibGladeLib = "libglade-2.0-0.dll"
else:
const
else:
const
LibGladeLib = "libglade-2.0.so"
type
type
PLongint* = ptr int32
PSmallInt* = ptr int16
PByte* = ptr int8
@ -17,11 +16,11 @@ type
PDouble* = ptr float64
proc glade_init*(){.cdecl, dynlib: LibGladeLib, importc: "glade_init".}
proc glade_require*(TheLibrary: cstring){.cdecl, dynlib: LibGladeLib,
proc glade_require*(TheLibrary: cstring){.cdecl, dynlib: LibGladeLib,
importc: "glade_require".}
proc glade_provide*(TheLibrary: cstring){.cdecl, dynlib: LibGladeLib,
proc glade_provide*(TheLibrary: cstring){.cdecl, dynlib: LibGladeLib,
importc: "glade_provide".}
type
type
PGladeXMLPrivate* = pointer
PGladeXML* = ptr TGladeXML
TGladeXML* = object of TGObject
@ -31,9 +30,9 @@ type
PGladeXMLClass* = ptr TGladeXMLClass
TGladeXMLClass* = object of TGObjectClass
TGladeXMLConnectFunc* = proc (handler_name: cstring, anObject: PGObject,
signal_name: cstring, signal_data: cstring,
connect_object: PGObject, after: gboolean,
TGladeXMLConnectFunc* = proc (handler_name: cstring, anObject: PGObject,
signal_name: cstring, signal_data: cstring,
connect_object: PGObject, after: gboolean,
user_data: gpointer){.cdecl.}
proc GLADE_TYPE_XML*(): GType
@ -42,76 +41,76 @@ proc GLADE_XML_CLASS*(klass: pointer): PGladeXMLClass
proc GLADE_IS_XML*(obj: pointer): gboolean
proc GLADE_IS_XML_CLASS*(klass: pointer): gboolean
proc GLADE_XML_GET_CLASS*(obj: pointer): PGladeXMLClass
proc glade_xml_get_type*(): GType{.cdecl, dynlib: LibGladeLib,
proc glade_xml_get_type*(): GType{.cdecl, dynlib: LibGladeLib,
importc: "glade_xml_get_type".}
proc glade_xml_new*(fname: cstring, root: cstring, domain: cstring): PGladeXML{.
cdecl, dynlib: LibGladeLib, importc: "glade_xml_new".}
proc glade_xml_new_from_buffer*(buffer: cstring, size: int32, root: cstring,
domain: cstring): PGladeXML{.cdecl,
proc glade_xml_new_from_buffer*(buffer: cstring, size: int32, root: cstring,
domain: cstring): PGladeXML{.cdecl,
dynlib: LibGladeLib, importc: "glade_xml_new_from_buffer".}
proc glade_xml_construct*(self: PGladeXML, fname: cstring, root: cstring,
domain: cstring): gboolean{.cdecl,
proc glade_xml_construct*(self: PGladeXML, fname: cstring, root: cstring,
domain: cstring): gboolean{.cdecl,
dynlib: LibGladeLib, importc: "glade_xml_construct".}
proc glade_xml_signal_connect*(self: PGladeXML, handlername: cstring,
func: TGCallback){.cdecl, dynlib: LibGladeLib,
proc glade_xml_signal_connect*(self: PGladeXML, handlername: cstring,
func: TGCallback){.cdecl, dynlib: LibGladeLib,
importc: "glade_xml_signal_connect".}
proc glade_xml_signal_connect_data*(self: PGladeXML, handlername: cstring,
proc glade_xml_signal_connect_data*(self: PGladeXML, handlername: cstring,
func: TGCallback, user_data: gpointer){.
cdecl, dynlib: LibGladeLib, importc: "glade_xml_signal_connect_data".}
proc glade_xml_signal_autoconnect*(self: PGladeXML){.cdecl, dynlib: LibGladeLib,
proc glade_xml_signal_autoconnect*(self: PGladeXML){.cdecl, dynlib: LibGladeLib,
importc: "glade_xml_signal_autoconnect".}
proc glade_xml_signal_connect_full*(self: PGladeXML, handler_name: cstring,
func: TGladeXMLConnectFunc,
user_data: gpointer){.cdecl,
proc glade_xml_signal_connect_full*(self: PGladeXML, handler_name: cstring,
func: TGladeXMLConnectFunc,
user_data: gpointer){.cdecl,
dynlib: LibGladeLib, importc: "glade_xml_signal_connect_full".}
proc glade_xml_signal_autoconnect_full*(self: PGladeXML,
func: TGladeXMLConnectFunc,
user_data: gpointer){.cdecl,
proc glade_xml_signal_autoconnect_full*(self: PGladeXML,
func: TGladeXMLConnectFunc,
user_data: gpointer){.cdecl,
dynlib: LibGladeLib, importc: "glade_xml_signal_autoconnect_full".}
proc glade_xml_get_widget*(self: PGladeXML, name: cstring): PGtkWidget{.cdecl,
proc glade_xml_get_widget*(self: PGladeXML, name: cstring): PGtkWidget{.cdecl,
dynlib: LibGladeLib, importc: "glade_xml_get_widget".}
proc glade_xml_get_widget_prefix*(self: PGladeXML, name: cstring): PGList{.
cdecl, dynlib: LibGladeLib, importc: "glade_xml_get_widget_prefix".}
proc glade_xml_relative_file*(self: PGladeXML, filename: cstring): cstring{.cdecl,
proc glade_xml_relative_file*(self: PGladeXML, filename: cstring): cstring{.cdecl,
dynlib: LibGladeLib, importc: "glade_xml_relative_file".}
proc glade_get_widget_name*(widget: PGtkWidget): cstring{.cdecl,
proc glade_get_widget_name*(widget: PGtkWidget): cstring{.cdecl,
dynlib: LibGladeLib, importc: "glade_get_widget_name".}
proc glade_get_widget_tree*(widget: PGtkWidget): PGladeXML{.cdecl,
proc glade_get_widget_tree*(widget: PGtkWidget): PGladeXML{.cdecl,
dynlib: LibGladeLib, importc: "glade_get_widget_tree".}
type
type
PGladeXMLCustomWidgetHandler* = ptr TGladeXMLCustomWidgetHandler
TGladeXMLCustomWidgetHandler* = TGtkWidget
proc glade_set_custom_handler*(handler: TGladeXMLCustomWidgetHandler,
user_data: gpointer){.cdecl, dynlib: LibGladeLib,
proc glade_set_custom_handler*(handler: TGladeXMLCustomWidgetHandler,
user_data: gpointer){.cdecl, dynlib: LibGladeLib,
importc: "glade_set_custom_handler".}
proc glade_gnome_init*() =
proc glade_gnome_init*() =
glade_init()
proc glade_bonobo_init*() =
proc glade_bonobo_init*() =
glade_init()
proc glade_xml_new_with_domain*(fname: cstring, root: cstring, domain: cstring): PGladeXML =
proc glade_xml_new_with_domain*(fname: cstring, root: cstring, domain: cstring): PGladeXML =
result = glade_xml_new(fname, root, domain)
proc glade_xml_new_from_memory*(buffer: cstring, size: int32, root: cstring,
domain: cstring): PGladeXML =
proc glade_xml_new_from_memory*(buffer: cstring, size: int32, root: cstring,
domain: cstring): PGladeXML =
result = glade_xml_new_from_buffer(buffer, size, root, domain)
proc GLADE_TYPE_XML*(): GType =
proc GLADE_TYPE_XML*(): GType =
result = glade_xml_get_type()
proc GLADE_XML*(obj: pointer): PGladeXML =
proc GLADE_XML*(obj: pointer): PGladeXML =
result = cast[PGladeXML](G_TYPE_CHECK_INSTANCE_CAST(obj, GLADE_TYPE_XML()))
proc GLADE_XML_CLASS*(klass: pointer): PGladeXMLClass =
proc GLADE_XML_CLASS*(klass: pointer): PGladeXMLClass =
result = cast[PGladeXMLClass](G_TYPE_CHECK_CLASS_CAST(klass, GLADE_TYPE_XML()))
proc GLADE_IS_XML*(obj: pointer): gboolean =
proc GLADE_IS_XML*(obj: pointer): gboolean =
result = G_TYPE_CHECK_INSTANCE_TYPE(obj, GLADE_TYPE_XML())
proc GLADE_IS_XML_CLASS*(klass: pointer): gboolean =
proc GLADE_IS_XML_CLASS*(klass: pointer): gboolean =
result = G_TYPE_CHECK_CLASS_TYPE(klass, GLADE_TYPE_XML())
proc GLADE_XML_GET_CLASS*(obj: pointer): PGladeXMLClass =
proc GLADE_XML_GET_CLASS*(obj: pointer): PGladeXMLClass =
result = cast[PGladeXMLClass](G_TYPE_INSTANCE_GET_CLASS(obj, GLADE_TYPE_XML()))

File diff suppressed because it is too large Load diff

View file

@ -1,29 +1,28 @@
import
import
glib2, pango
type
type
pint32* = ptr int32
proc pango_split_file_list*(str: cstring): PPchar{.cdecl, dynlib: pangolib,
proc pango_split_file_list*(str: cstring): PPchar{.cdecl, dynlib: pangolib,
importc: "pango_split_file_list".}
proc pango_trim_string*(str: cstring): cstring{.cdecl, dynlib: pangolib,
proc pango_trim_string*(str: cstring): cstring{.cdecl, dynlib: pangolib,
importc: "pango_trim_string".}
proc pango_read_line*(stream: TFile, str: PGString): gint{.cdecl,
proc pango_read_line*(stream: TFile, str: PGString): gint{.cdecl,
dynlib: pangolib, importc: "pango_read_line".}
proc pango_skip_space*(pos: PPchar): gboolean{.cdecl, dynlib: pangolib,
proc pango_skip_space*(pos: PPchar): gboolean{.cdecl, dynlib: pangolib,
importc: "pango_skip_space".}
proc pango_scan_word*(pos: PPchar, OutStr: PGString): gboolean{.cdecl,
proc pango_scan_word*(pos: PPchar, OutStr: PGString): gboolean{.cdecl,
dynlib: pangolib, importc: "pango_scan_word".}
proc pango_scan_string*(pos: PPchar, OutStr: PGString): gboolean{.cdecl,
proc pango_scan_string*(pos: PPchar, OutStr: PGString): gboolean{.cdecl,
dynlib: pangolib, importc: "pango_scan_string".}
proc pango_scan_int*(pos: PPchar, OutInt: pint32): gboolean{.cdecl,
proc pango_scan_int*(pos: PPchar, OutInt: pint32): gboolean{.cdecl,
dynlib: pangolib, importc: "pango_scan_int".}
when defined(PANGO_ENABLE_BACKEND):
proc pango_config_key_get(key: cstring): cstring{.cdecl, dynlib: pangolib,
importc: "pango_config_key_get".}
proc pango_lookup_aliases(fontname: cstring, families: PPPchar,
n_families: pint32){.cdecl, dynlib: pangolib,
importc: "pango_lookup_aliases".}
proc pango_config_key_get(key: cstring): cstring{.cdecl, dynlib: pangolib,
importc: "pango_config_key_get".}
proc pango_lookup_aliases(fontname: cstring, families: PPPchar,
n_families: pint32){.cdecl, dynlib: pangolib,
importc: "pango_lookup_aliases".}
proc pango_parse_style*(str: cstring, style: PPangoStyle, warn: gboolean): gboolean{.
cdecl, dynlib: pangolib, importc: "pango_parse_style".}
proc pango_parse_variant*(str: cstring, variant: PPangoVariant, warn: gboolean): gboolean{.
@ -32,15 +31,14 @@ proc pango_parse_weight*(str: cstring, weight: PPangoWeight, warn: gboolean): gb
cdecl, dynlib: pangolib, importc: "pango_parse_weight".}
proc pango_parse_stretch*(str: cstring, stretch: PPangoStretch, warn: gboolean): gboolean{.
cdecl, dynlib: pangolib, importc: "pango_parse_stretch".}
when defined(PANGO_ENABLE_BACKEND):
proc pango_get_sysconf_subdirectory(): cstring{.cdecl, dynlib: pangolib,
importc: "pango_get_sysconf_subdirectory".}
proc pango_get_lib_subdirectory(): cstring{.cdecl, dynlib: pangolib,
importc: "pango_get_lib_subdirectory".}
proc pango_log2vis_get_embedding_levels*(str: Pgunichar, len: int32,
pbase_dir: PPangoDirection, embedding_level_list: Pguint8): gboolean{.cdecl,
proc pango_get_sysconf_subdirectory(): cstring{.cdecl, dynlib: pangolib,
importc: "pango_get_sysconf_subdirectory".}
proc pango_get_lib_subdirectory(): cstring{.cdecl, dynlib: pangolib,
importc: "pango_get_lib_subdirectory".}
proc pango_log2vis_get_embedding_levels*(str: Pgunichar, len: int32,
pbase_dir: PPangoDirection, embedding_level_list: Pguint8): gboolean{.cdecl,
dynlib: pangolib, importc: "pango_log2vis_get_embedding_levels".}
proc pango_get_mirror_char*(ch: gunichar, mirrored_ch: Pgunichar): gboolean{.
cdecl, dynlib: pangolib, importc: "pango_get_mirror_char".}
proc pango_language_get_sample_string*(language: PPangoLanguage): cstring{.
cdecl, dynlib: pangolib, importc: "pango_language_get_sample_string".}
cdecl, dynlib: pangolib, importc: "pango_language_get_sample_string".}

View file

@ -1,73 +0,0 @@
# Lexer generator for Nimrod
# (c) 2008 Andreas Rumpf
# Stress testing for the macro feature
# the syntax that should be supported is:
# template numpostfix =
# '\'' & 'F'|'f'|'i'|'I' & "32"|"64"|"8"|"16"
# template edigits =
# 'e'|'E' & +digits
# tokens(
# tkIdent: +UniIdentStart & *UniIdentRest,
# tkHexNumber: '0' & ('x'|'X') & +hexDigits & ?( numpostfix ),
# tkOctNumber: '0' & ('c'|'C') & +octDigits & ?( numpostfix ),
# tkBinNumber: '0' & ('b'|'B') & +binDigits & ?( numpostfix ),
# tkIntNumber: +digits & ?( numpostfix ),
# tkFloatNumber: +digits & ('.' & +digits & ?(edigits) | edigits) & ?(numpostfix),
#
# )
# actions(
# tkIdent: lookup
# )
#
#
# match inputstream
# of +('A'..'Z' | '_' | 'a'..'z') *('A'..'Z' | '_' | 'a'..'z' | '0'..'9') :
#
# x = inputstream[pos..length]
# of '0' 'x' +('0'..'9' | 'a'..'f' | '_' | 'A'..'F') :
# y = ...
const
AsciiLetter = {'A'..'Z', 'a'..'z'}
uniLetter = AsciiLetter + {'\128'..'\255'}
digits = {'0'..'9'}
hexDigits = {'0'..'9', 'a'..'f', 'A'..'F'}
octDigits = {'0'..'7'}
binDigits = {'0'..'1'}
AsciiIdentStart = AsciiLetter + {'_'}
AsciiIdentRest = AsciiIdentStart + Digits
UniIdentStart = UniLetter + {'_'}
UniIdentRest = UniIdentStart + Digits
# --> if match(s, +AsciiIdentStart & *AsciiIdentRest):
# Regular expressions in Nimrod itself!
# -------------------------------------
#
# 'a' -- matches the character a
# 'a'..'z' -- range operator '-'
# 'A' | 'B' -- alternative operator |
# * 'a' -- prefix * is needed
# + 'a' -- prefix + is needed
# ? 'a' -- prefix ? is needed
# *? prefix is needed
# +? prefix is needed
# letter -- character classes with real names!
# letters
# white
# whites
# any -- any character
# () -- are Nimrod syntax
# ! 'a'-'z'
#
# -- concatentation via proc call:
#
# re('A' 'Z' *word )
macro re(n: expr): expr =
result = newCall("magic_re", x)

View file

@ -1,124 +0,0 @@
# new implementation of regular expressions
type
TRegexKind = enum
regNone,
regChar,
regSet,
regConc,
regAlt,
regStar,
regPlus,
regMN,
regNewline
TRegex = object of TObject
case kind: TRegexKind
of regChar: c: char
of regSet: s: ref set[char]
else: a, b: PRegEx
PRegEx* = ref TRegEx
TRegExFlag* = enum ## Flags concerning the semantics of regular expressions
reCaseInsensitive, ## case insensitive match
reStyleInsensitive ## style insensitive match
TRegExFlags* = set[TRegExFlag]
## Flags concerning the semantics of regular expressions
proc raiseRegex(msg: string) {.noreturn.} =
var e: ref Exception
new(e)
e.msg = msg
raise e
proc compileAux(i: int, s: string, r: PRegEx): int
proc compileBackslash(i: int, s: string, r: PRegEx): int =
var i = i
inc(i)
case s[i]
of 'A'..'Z':
of 'a'..'z':
of '0':
of '1'..'9':
else:
r.kind = regChar
r.c = s[i]
inc(i)
result = i
proc compileAtom(i: int, s: string, r: PRegEx): int =
var i = i
case s[i]
of '[':
inc(i)
var inverse = s[i] == '^'
if inverse: inc(i)
r.kind = regSet
new(r.s)
while true:
case s[i]
of '\\': i = compileBackslash(i, s, r)
of ']':
inc(i)
break
of '\0':
raiseRegex("']' expected")
elif s[i+1] == '-':
var x = s[i]
inc(i, 2)
var y = s[i]
inc(i)
r.s = r.s + {x..y}
else:
incl(r.s, s[i])
inc(i)
if inverse:
r.s = {'\0'..'\255'} - r.s
of '\\':
inc(i)
i = compileBackslash(i, s, r)
of '.':
r.kind = regAny
inc(i)
of '(':
inc(i)
i = compileAux(i, s, r)
if s[i] = ')': inc(i)
else: raiseRegex("')' expected")
of '\0': nil # do nothing
else:
r.kind = regChar
r.c = s[i]
inc(i)
result = i
proc compilePostfix(i: int, s: string, r: PRegEx): int =
var i = compileAtom(i, s, r)
var a: PRegEx
case s[i]
of '*':
of '+':
of '?':
else: nil
proc compileAux(i: int, s: string, r: PRegEx): int =
var i = i
i = compileAtom(i, s, r)
while s[i] != '\0':
result = i
proc compile*(regex: string, flags: TRegExFlags = {}): PRegEx =
## Compiles the string `regex` that represents a regular expression into
## an internal data structure that can be used for matching.
new(result)
var i = compileAux(0, regex, result)
if i < len(regex)-1:
# not all characters used for the regular expression?
raiseRegEx("invalid regular expression")

View file

@ -1,296 +1,291 @@
#
#
# Nimrod's Runtime Library
# (c) Copyright 2006 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
# This file was created by a complicated procedure which saved me a considerable
# amount of time: the pcre.h header was converted to modpcre.h by hand, so that
# h2pas could handle it. Then I used pas2mor to generate a Morpork binding.
# Unfortunately, I had to fix some things later on; thus don't do all this
# again! My manual changes will be lost!
# Converted by Pas2mor v1.37
#
# Automatically converted by H2Pas 0.99.16 from modpcre.h
# The following command line parameters were used:
# -D -c -l pcre.lib -T modpcre.h
{.compile: "pcre_all.c" .}
type
Pbyte = ptr byte
Pchar = CString
PPchar = ptr PChar
Pint = ptr cint
Ppcre* = ptr TPcre
Ppcre_callout_block = ptr tpcre_callout_block
Ppcre_extra = ptr Tpcre_extra
#************************************************
#* Perl-Compatible Regular Expressions *
#************************************************
#
# Modified by Andreas Rumpf for h2pas.
# In its original form, this is the .in file that is transformed by
# "configure" into pcre.h.
#
# Copyright (c) 1997-2005 University of Cambridge
#
# -----------------------------------------------------------------------------
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# * Neither the name of the University of Cambridge nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# -----------------------------------------------------------------------------
# The file pcre.h is build by "configure". Do not edit it; instead
# make changes to pcre.in.
const
PCRE_MAJOR* = 6
PCRE_MINOR* = 3
PCRE_DATE* = "2005/11/29"
# Options
PCRE_CASELESS* = 0x00000001
PCRE_MULTILINE* = 0x00000002
PCRE_DOTALL* = 0x00000004
PCRE_EXTENDED* = 0x00000008
PCRE_ANCHORED* = 0x00000010
PCRE_DOLLAR_ENDONLY* = 0x00000020
PCRE_EXTRA* = 0x00000040
PCRE_NOTBOL* = 0x00000080
PCRE_NOTEOL* = 0x00000100
PCRE_UNGREEDY* = 0x00000200
PCRE_NOTEMPTY* = 0x00000400
PCRE_UTF8* = 0x00000800
PCRE_NO_AUTO_CAPTURE* = 0x00001000
PCRE_NO_UTF8_CHECK* = 0x00002000
PCRE_AUTO_CALLOUT* = 0x00004000
PCRE_PARTIAL* = 0x00008000
PCRE_DFA_SHORTEST* = 0x00010000
PCRE_DFA_RESTART* = 0x00020000
PCRE_FIRSTLINE* = 0x00040000
# Exec-time and get/set-time error codes
PCRE_ERROR_NOMATCH* = -(1)
PCRE_ERROR_NULL* = -(2)
PCRE_ERROR_BADOPTION* = -(3)
PCRE_ERROR_BADMAGIC* = -(4)
PCRE_ERROR_UNKNOWN_NODE* = -(5)
PCRE_ERROR_NOMEMORY* = -(6)
PCRE_ERROR_NOSUBSTRING* = -(7)
PCRE_ERROR_MATCHLIMIT* = -(8)
# Never used by PCRE itself
PCRE_ERROR_CALLOUT* = -(9)
PCRE_ERROR_BADUTF8* = -(10)
PCRE_ERROR_BADUTF8_OFFSET* = -(11)
PCRE_ERROR_PARTIAL* = -(12)
PCRE_ERROR_BADPARTIAL* = -(13)
PCRE_ERROR_INTERNAL* = -(14)
PCRE_ERROR_BADCOUNT* = -(15)
PCRE_ERROR_DFA_UITEM* = -(16)
PCRE_ERROR_DFA_UCOND* = -(17)
PCRE_ERROR_DFA_UMLIMIT* = -(18)
PCRE_ERROR_DFA_WSSIZE* = -(19)
PCRE_ERROR_DFA_RECURSE* = -(20)
# Request types for pcre_fullinfo()
PCRE_INFO_OPTIONS* = 0
PCRE_INFO_SIZE* = 1
PCRE_INFO_CAPTURECOUNT* = 2
PCRE_INFO_BACKREFMAX* = 3
PCRE_INFO_FIRSTBYTE* = 4
# For backwards compatibility
PCRE_INFO_FIRSTCHAR* = 4
PCRE_INFO_FIRSTTABLE* = 5
PCRE_INFO_LASTLITERAL* = 6
PCRE_INFO_NAMEENTRYSIZE* = 7
PCRE_INFO_NAMECOUNT* = 8
PCRE_INFO_NAMETABLE* = 9
PCRE_INFO_STUDYSIZE* = 10
PCRE_INFO_DEFAULT_TABLES* = 11
# Request types for pcre_config()
PCRE_CONFIG_UTF8* = 0
PCRE_CONFIG_NEWLINE* = 1
PCRE_CONFIG_LINK_SIZE* = 2
PCRE_CONFIG_POSIX_MALLOC_THRESHOLD* = 3
PCRE_CONFIG_MATCH_LIMIT* = 4
PCRE_CONFIG_STACKRECURSE* = 5
PCRE_CONFIG_UNICODE_PROPERTIES* = 6
# Bit flags for the pcre_extra structure
PCRE_EXTRA_STUDY_DATA* = 0x0001
PCRE_EXTRA_MATCH_LIMIT* = 0x0002
PCRE_EXTRA_CALLOUT_DATA* = 0x0004
PCRE_EXTRA_TABLES* = 0x0008
# Types
type
TPcre = record
#undefined structure
# The structure for passing additional data to pcre_exec(). This is defined
# in such as way as to be extensible. Always add new fields at the end,
# in order to remain compatible.
# Bits for which fields are set
# Opaque data from pcre_study()
# Maximum number of calls to match()
# Data passed back in callouts
# Const before type ignored
# Pointer to character tables
Tpcre_extra* {.final.} = object
flags: cuint
study_data: pointer
match_limit: cuint
callout_data: pointer
tables: ptr byte
# The structure for passing out data via the pcre_callout_function. We use a
# structure so that new fields can be added on the end in future versions,
# without changing the API of the function, thereby allowing old clients to
# work without modification.
# Identifies version of block
# ------------------------ Version 0 -------------------------------
# Number compiled into pattern
# The offset vector
# Const before type ignored
# The subject being matched
# The length of the subject
# Offset to start of this match attempt
# Where we currently are in the subject
# Max current capture
# Most recently closed capture
# Data passed in with the call
# ------------------- Added for Version 1 --------------------------
# Offset to next item in the pattern
# Length of next item in the pattern
# ------------------------------------------------------------------
TPcre_callout_block* {.final.} = object
version: cint
callout_number: cint
offset_vector: ptr cint
subject: ptr char
subject_length: cint
start_match: cint
current_position: cint
capture_top: cint
capture_last: cint
callout_data: pointer
pattern_position: cint
next_item_length: cint
# Exported PCRE functions
proc pcre_compile*(para1: Pchar, para2: cint, para3: ptr Pchar,
para4: Pint, para5: Pbyte): Ppcre {.
importc: "pcre_compile", noconv.}
proc pcre_compile2*(para1: Pchar, para2: cint, para3: Pint, para4: PPchar,
para5: Pint, para6: Pbyte): Ppcre {.
importc: "pcre_compile2", noconv.}
proc pcre_config*(para1: cint, para2: pointer): cint {.
importc: "pcre_config", noconv.}
proc pcre_copy_named_substring*(para1: Ppcre, para2: Pchar, para3: Pint,
para4: cint, para5: Pchar, para6: Pchar,
para7: cint): cint {.
importc: "pcre_copy_named_substring", noconv.}
proc pcre_copy_substring*(para1: Pchar, para2: Pint, para3: cint, para4: cint,
para5: Pchar, para6: cint): cint {.
importc: "pcre_copy_substring", noconv.}
proc pcre_dfa_exec*(para1: Ppcre, para2: Ppcre_extra, para3: Pchar,
para4: cint, para5: cint, para6: cint, para7: Pint,
para8: cint, para9: Pint, para10: cint): cint {.
importc: "pcre_dfa_exec", noconv.}
proc pcre_exec*(para1: Ppcre, para2: Ppcre_extra, para3: Pchar,
para4: cint, para5: cint, para6: cint, para7: Pint,
para8: cint): cint {.importc: "pcre_exec", noconv.}
proc pcre_free_substring*(para1: Pchar) {.
importc: "pcre_free_substring", noconv.}
proc pcre_free_substring_list*(para1: PPchar) {.
importc: "pcre_free_substring_list", noconv.}
proc pcre_fullinfo*(para1: Ppcre, para2: Ppcre_extra, para3: cint,
para4: pointer): cint {.importc: "pcre_fullinfo", noconv.}
proc pcre_get_named_substring*(para1: Ppcre, para2: Pchar, para3: Pint,
para4: cint, para5: Pchar, para6: PPchar): cint {.
importc: "pcre_get_named_substring", noconv.}
proc pcre_get_stringnumber*(para1: Ppcre, para2: Pchar): cint {.
importc: "pcre_get_stringnumber", noconv.}
proc pcre_get_substring*(para1: Pchar, para2: Pint, para3: cint,
para4: cint, para5: PPchar): cint {.
importc: "pcre_get_substring", noconv.}
proc pcre_get_substring_list*(para1: Pchar, para2: Pint, para3: cint,
para4: ptr PPchar): cint {.
importc: "pcre_get_substring_list", noconv.}
proc pcre_info*(para1: Ppcre, para2: Pint, para3: Pint): cint {.
importc: "pcre_info", noconv.}
proc pcre_maketables*: ptr byte {.
importc: "pcre_maketables", noconv.}
proc pcre_refcount*(para1: Ppcre, para2: cint): cint {.
importc: "pcre_refcount", noconv.}
proc pcre_study*(para1: Ppcre, para2: cint,
para3: ptr CString): Ppcre_extra {.importc, noconv.}
proc pcre_version*: CString {.importc: "pcre_version", noconv.}
# Indirection for store get and free functions. These can be set to
# alternative malloc/free functions if required. Special ones are used in the
# non-recursive case for "frames". There is also an optional callout function
# that is triggered by the (?) regex item.
#
# we use Nimrod's memory manager (but not GC!) for these functions:
var
pcre_malloc {.importc: "pcre_malloc".}: proc (para1: int): pointer {.noconv.}
pcre_free {.importc: "pcre_free".}: proc (para1: pointer) {.noconv.}
pcre_stack_malloc {.importc: "pcre_stack_malloc".}:
proc (para1: int): pointer {.noconv.}
pcre_stack_free {.importc: "pcre_stack_free".}:
proc (para1: pointer) {.noconv.}
pcre_callout {.importc: "pcre_callout".}:
proc (para1: Ppcre_callout_block): cint {.noconv.}
pcre_malloc = system.alloc
pcre_free = system.dealloc
pcre_stack_malloc = system.alloc
pcre_stack_free = system.dealloc
pcre_callout = nil
#
#
# Nimrod's Runtime Library
# (c) Copyright 2006 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
# This file was created by a complicated procedure which saved me a considerable
# amount of time: the pcre.h header was converted to modpcre.h by hand, so that
# h2pas could handle it. Then I used pas2mor to generate a Nimrod binding.
# Unfortunately, I had to fix some things later on; thus don't do all this
# again! My manual changes will be lost!
# Converted by Pas2mor v1.37
#
# Automatically converted by H2Pas 0.99.16 from modpcre.h
# The following command line parameters were used:
# -D -c -l pcre.lib -T modpcre.h
{.compile: "pcre_all.c" .}
type
Pbyte = ptr byte
PPchar = ptr cstring
Pint = ptr cint
Ppcre* = ptr TPcre
Ppcre_callout_block* = ptr tpcre_callout_block
Ppcre_extra* = ptr Tpcre_extra
TPcre {.final, pure.} = object
# The structure for passing additional data to pcre_exec(). This is defined
# in such as way as to be extensible.
# Bits for which fields are set
# Opaque data from pcre_study()
# Maximum number of calls to match()
# Data passed back in callouts
# Const before type ignored
# Pointer to character tables
Tpcre_extra* {.final, pure.} = object
flags: cint
study_data: pointer
match_limit: cint
callout_data: pointer
tables: ptr byte
# The structure for passing out data via the pcre_callout_function. We use a
# structure so that new fields can be added on the end in future versions,
# without changing the API of the function, thereby allowing old clients to
# work without modification.
# Identifies version of block
# ------------------------ Version 0 -------------------------------
# Number compiled into pattern
# The offset vector
# Const before type ignored
# The subject being matched
# The length of the subject
# Offset to start of this match attempt
# Where we currently are in the subject
# Max current capture
# Most recently closed capture
# Data passed in with the call
# ------------------- Added for Version 1 --------------------------
# Offset to next item in the pattern
# Length of next item in the pattern
# ------------------------------------------------------------------
TPcre_callout_block* {.final, pure.} = object
version: cint
callout_number: cint
offset_vector: ptr cint
subject: ptr char
subject_length: cint
start_match: cint
current_position: cint
capture_top: cint
capture_last: cint
callout_data: pointer
pattern_position: cint
next_item_length: cint
#************************************************
#* Perl-Compatible Regular Expressions *
#************************************************
#
# Modified by Andreas Rumpf for h2pas.
# In its original form, this is the .in file that is transformed by
# "configure" into pcre.h.
#
# Copyright (c) 1997-2005 University of Cambridge
#
# -----------------------------------------------------------------------------
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# * Neither the name of the University of Cambridge nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# -----------------------------------------------------------------------------
# The file pcre.h is build by "configure". Do not edit it; instead
# make changes to pcre.in.
const
PCRE_MAJOR* = 6
PCRE_MINOR* = 3
PCRE_DATE* = "2005/11/29"
# Options
PCRE_CASELESS* = 0x00000001
PCRE_MULTILINE* = 0x00000002
PCRE_DOTALL* = 0x00000004
PCRE_EXTENDED* = 0x00000008
PCRE_ANCHORED* = 0x00000010
PCRE_DOLLAR_ENDONLY* = 0x00000020
PCRE_EXTRA* = 0x00000040
PCRE_NOTBOL* = 0x00000080
PCRE_NOTEOL* = 0x00000100
PCRE_UNGREEDY* = 0x00000200
PCRE_NOTEMPTY* = 0x00000400
PCRE_UTF8* = 0x00000800
PCRE_NO_AUTO_CAPTURE* = 0x00001000
PCRE_NO_UTF8_CHECK* = 0x00002000
PCRE_AUTO_CALLOUT* = 0x00004000
PCRE_PARTIAL* = 0x00008000
PCRE_DFA_SHORTEST* = 0x00010000
PCRE_DFA_RESTART* = 0x00020000
PCRE_FIRSTLINE* = 0x00040000
# Exec-time and get/set-time error codes
PCRE_ERROR_NOMATCH* = -(1)
PCRE_ERROR_NULL* = -(2)
PCRE_ERROR_BADOPTION* = -(3)
PCRE_ERROR_BADMAGIC* = -(4)
PCRE_ERROR_UNKNOWN_NODE* = -(5)
PCRE_ERROR_NOMEMORY* = -(6)
PCRE_ERROR_NOSUBSTRING* = -(7)
PCRE_ERROR_MATCHLIMIT* = -(8)
# Never used by PCRE itself
PCRE_ERROR_CALLOUT* = -(9)
PCRE_ERROR_BADUTF8* = -(10)
PCRE_ERROR_BADUTF8_OFFSET* = -(11)
PCRE_ERROR_PARTIAL* = -(12)
PCRE_ERROR_BADPARTIAL* = -(13)
PCRE_ERROR_INTERNAL* = -(14)
PCRE_ERROR_BADCOUNT* = -(15)
PCRE_ERROR_DFA_UITEM* = -(16)
PCRE_ERROR_DFA_UCOND* = -(17)
PCRE_ERROR_DFA_UMLIMIT* = -(18)
PCRE_ERROR_DFA_WSSIZE* = -(19)
PCRE_ERROR_DFA_RECURSE* = -(20)
# Request types for pcre_fullinfo()
PCRE_INFO_OPTIONS* = 0
PCRE_INFO_SIZE* = 1
PCRE_INFO_CAPTURECOUNT* = 2
PCRE_INFO_BACKREFMAX* = 3
PCRE_INFO_FIRSTBYTE* = 4
# For backwards compatibility
PCRE_INFO_FIRSTCHAR* = 4
PCRE_INFO_FIRSTTABLE* = 5
PCRE_INFO_LASTLITERAL* = 6
PCRE_INFO_NAMEENTRYSIZE* = 7
PCRE_INFO_NAMECOUNT* = 8
PCRE_INFO_NAMETABLE* = 9
PCRE_INFO_STUDYSIZE* = 10
PCRE_INFO_DEFAULT_TABLES* = 11
# Request types for pcre_config()
PCRE_CONFIG_UTF8* = 0
PCRE_CONFIG_NEWLINE* = 1
PCRE_CONFIG_LINK_SIZE* = 2
PCRE_CONFIG_POSIX_MALLOC_THRESHOLD* = 3
PCRE_CONFIG_MATCH_LIMIT* = 4
PCRE_CONFIG_STACKRECURSE* = 5
PCRE_CONFIG_UNICODE_PROPERTIES* = 6
# Bit flags for the pcre_extra structure
PCRE_EXTRA_STUDY_DATA* = 0x0001
PCRE_EXTRA_MATCH_LIMIT* = 0x0002
PCRE_EXTRA_CALLOUT_DATA* = 0x0004
PCRE_EXTRA_TABLES* = 0x0008
# Exported PCRE functions
proc pcre_compile*(para1: cstring, para2: cint, para3: ptr cstring,
para4: ptr int, para5: Pbyte): Ppcre {.
importc: "pcre_compile", noconv.}
proc pcre_compile2*(para1: cstring, para2: cint, para3: Pint, para4: PPchar,
para5: ptr int, para6: Pbyte): Ppcre {.
importc: "pcre_compile2", noconv.}
proc pcre_config*(para1: cint, para2: pointer): cint {.
importc: "pcre_config", noconv.}
proc pcre_copy_named_substring*(para1: Ppcre, para2: cstring, para3: Pint,
para4: cint, para5: cstring, para6: cstring,
para7: cint): cint {.
importc: "pcre_copy_named_substring", noconv.}
proc pcre_copy_substring*(para1: cstring, para2: Pint, para3: cint, para4: cint,
para5: cstring, para6: cint): cint {.
importc: "pcre_copy_substring", noconv.}
proc pcre_dfa_exec*(para1: Ppcre, para2: Ppcre_extra, para3: cstring,
para4: cint, para5: cint, para6: cint, para7: Pint,
para8: cint, para9: Pint, para10: cint): cint {.
importc: "pcre_dfa_exec", noconv.}
proc pcre_exec*(para1: Ppcre, para2: Ppcre_extra, para3: cstring,
para4: cint, para5: cint, para6: cint, para7: Pint,
para8: cint): cint {.importc: "pcre_exec", noconv.}
proc pcre_free_substring*(para1: cstring) {.
importc: "pcre_free_substring", noconv.}
proc pcre_free_substring_list*(para1: PPchar) {.
importc: "pcre_free_substring_list", noconv.}
proc pcre_fullinfo*(para1: Ppcre, para2: Ppcre_extra, para3: cint,
para4: pointer): cint {.importc: "pcre_fullinfo", noconv.}
proc pcre_get_named_substring*(para1: Ppcre, para2: cstring, para3: Pint,
para4: cint, para5: cstring, para6: PPchar): cint {.
importc: "pcre_get_named_substring", noconv.}
proc pcre_get_stringnumber*(para1: Ppcre, para2: cstring): cint {.
importc: "pcre_get_stringnumber", noconv.}
proc pcre_get_substring*(para1: cstring, para2: Pint, para3: cint,
para4: cint, para5: PPchar): cint {.
importc: "pcre_get_substring", noconv.}
proc pcre_get_substring_list*(para1: cstring, para2: Pint, para3: cint,
para4: ptr PPchar): cint {.
importc: "pcre_get_substring_list", noconv.}
proc pcre_info*(para1: Ppcre, para2: Pint, para3: Pint): cint {.
importc: "pcre_info", noconv.}
proc pcre_maketables*: ptr byte {.
importc: "pcre_maketables", noconv.}
proc pcre_refcount*(para1: Ppcre, para2: cint): cint {.
importc: "pcre_refcount", noconv.}
proc pcre_study*(para1: Ppcre, para2: cint,
para3: ptr CString): Ppcre_extra {.importc, noconv.}
proc pcre_version*: CString {.importc: "pcre_version", noconv.}
# Indirection for store get and free functions. These can be set to
# alternative malloc/free functions if required. Special ones are used in the
# non-recursive case for "frames". There is also an optional callout function
# that is triggered by the (?) regex item.
#
# we use Nimrod's memory manager (but not GC!) for these functions:
type
TMalloc = proc (para1: int): pointer {.noconv.}
TFree = proc (para1: pointer) {.noconv.}
var
pcre_malloc {.importc: "pcre_malloc".}: TMalloc
pcre_free {.importc: "pcre_free".}: TFree
pcre_stack_malloc {.importc: "pcre_stack_malloc".}: TMalloc
pcre_stack_free {.importc: "pcre_stack_free".}: TFree
pcre_callout {.importc: "pcre_callout".}:
proc (para1: Ppcre_callout_block): cint {.noconv.}
pcre_malloc = cast[TMalloc](system.alloc)
pcre_free = cast[TFree](system.dealloc)
pcre_stack_malloc = cast[TMalloc](system.alloc)
pcre_stack_free = cast[TFree](system.dealloc)
pcre_callout = nil

View file

@ -1,114 +1,115 @@
#
#
# Nimrod's Runtime Library
# (c) Copyright 2006 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
## Regular expression support for Nimrod.
## Currently this module is implemented by providing a wrapper around the
## `PRCE (Perl-Compatible Regular Expressions) <http://www.pcre.org>`_
## C library. This means that your application will depend on the PRCE
## library's licence when using this module, which should not be a problem
## though.
## PRCE's licence follows:
##
## .. include:: ../doc/regexprs.txt
##
# This is not just a convenient wrapper for the pcre library; the
# API will stay the same if the implementation should change.
import
pcre, strutils
type
EInvalidRegEx* = object of EInvalidValue
## is raised if the pattern is no valid regular expression.
const
MaxSubpatterns* = 10
## defines the maximum number of subpatterns that can be captured.
## More subpatterns cannot be captured!
proc match*(s, pattern: string, substrs: var openarray[string],
start: int = 0): bool
## returns ``true`` if ``s`` matches the ``pattern[start..]`` and
## the captured substrings in the array ``substrs``. If it does not
## match, nothing is written into ``substrs`` and ``false`` is
## returned.
proc match*(s, pattern: string, start: int = 0): bool
## returns ``true`` if ``s`` matches the ``pattern`` beginning from ``start``.
proc matchLen*(s, pattern: string, substrs: var openarray[string],
start: int = 0): int
## the same as ``match``, but it returns the length of the match,
## if there is no match, -1 is returned. Note that a match length
## of zero can happen.
proc find*(s, pattern: string, substrs: var openarray[string],
start: int = 0): bool
## returns ``true`` if ``pattern`` occurs in ``s`` and the captured
## substrings in the array ``substrs``. If it does not match, nothing
## is written into ``substrs``.
proc find*(s, pattern: string, start: int = 0): bool
## returns ``true`` if ``pattern`` occurs in ``s``.
proc rawCompile(pattern: string, flags: cint): PPcre =
var
msg: CString
offset: cint
com = pcreCompile(pattern, flags, addr(msg), addr(offset), nil)
if com == nil:
var e: ref EInvalidRegEx
new(e)
e.msg = $msg & "\n" & pattern & "\n" & repeatChar(offset) & "^\n"
raise e
return com
proc matchOrFind(s: string, pattern: PPcre, substrs: var openarray[string],
start: cint): cint =
var
rawMatches: array [0..maxSubpatterns * 3 - 1, cint]
res = int(pcreExec(pattern, nil, s, length(s), start, 0,
cast[pint](addr(rawMatches)), maxSubpatterns * 3))
dealloc(pattern)
if res < 0: return res
for i in 0..res-1:
var
a = rawMatches[i * 3]
b = rawMatches[i * 3 + 1]
if a >= 0: substrs[i] = copy(s, a, b)
else: substrs[i] = ""
return res
proc matchOrFind(s: string, pattern: PPcre, start: cint): cint =
var
rawMatches: array [0..maxSubpatterns * 3 - 1, cint]
res = pcreExec(pattern, nil, s, length(s), start, 0,
cast[pint](addr(rawMatches)), maxSubpatterns * 3)
dealloc(pattern)
return res
proc match(s, pattern: string, substrs: var openarray[string],
start: int = 0): bool =
return matchOrFind(s, rawCompile(pattern, PCRE_ANCHORED),
substrs, start) >= 0
proc matchLen(s, pattern: string, substrs: var openarray[string],
start: int = 0): int =
return matchOrFind(s, rawCompile(pattern, PCRE_ANCHORED), substrs, start)
proc find(s, pattern: string, substrs: var openarray[string],
start: int = 0): bool =
return matchOrFind(s, rawCompile(pattern, 0), substrs, start) >= 0
proc match(s, pattern: string, start: int = 0): bool =
return matchOrFind(s, rawCompile(pattern, PCRE_ANCHORED), start) >= 0
proc find(s, pattern: string, start: int = 0): bool =
return matchOrFind(s, rawCompile(pattern, 0), start) >= 0
#
#
# Nimrod's Runtime Library
# (c) Copyright 2006 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
## Regular expression support for Nimrod.
## Currently this module is implemented by providing a wrapper around the
## `PRCE (Perl-Compatible Regular Expressions) <http://www.pcre.org>`_
## C library. This means that your application will depend on the PRCE
## library's licence when using this module, which should not be a problem
## though.
## PRCE's licence follows:
##
## .. include:: ../doc/regexprs.txt
##
# This is not just a convenient wrapper for the pcre library; the
# API will stay the same if the implementation should change.
import
pcre, strutils
type
EInvalidRegEx* = object of EInvalidValue
## is raised if the pattern is no valid regular expression.
const
MaxSubpatterns* = 10
## defines the maximum number of subpatterns that can be captured.
## More subpatterns cannot be captured!
proc match*(s, pattern: string, matches: var openarray[string],
start: int = 0): bool
## returns ``true`` if ``s`` matches the ``pattern[start..]`` and
## the captured substrings in the array ``matches``. If it does not
## match, nothing is written into ``matches`` and ``false`` is
## returned.
proc match*(s, pattern: string, start: int = 0): bool
## returns ``true`` if ``s`` matches the ``pattern`` beginning from ``start``.
proc matchLen*(s, pattern: string, matches: var openarray[string],
start: int = 0): int
## the same as ``match``, but it returns the length of the match,
## if there is no match, -1 is returned. Note that a match length
## of zero can happen.
proc find*(s, pattern: string, matches: var openarray[string],
start: int = 0): bool
## returns ``true`` if ``pattern`` occurs in ``s`` and the captured
## substrings in the array ``matches``. If it does not match, nothing
## is written into ``matches``.
proc find*(s, pattern: string, start: int = 0): bool
## returns ``true`` if ``pattern`` occurs in ``s``.
proc rawCompile(pattern: string, flags: cint): PPcre =
var
msg: CString
offset: int
com = pcreCompile(pattern, flags, addr(msg), addr(offset), nil)
if com == nil:
var e: ref EInvalidRegEx
new(e)
e.msg = $msg & "\n" & pattern & "\n" & repeatChar(offset) & "^\n"
raise e
return com
proc matchOrFind(s: string, pattern: PPcre, matches: var openarray[string],
start: cint): cint =
var
rawMatches: array [0..maxSubpatterns * 3 - 1, cint]
res = int(pcreExec(pattern, nil, s, len(s), start, 0,
cast[ptr cint](addr(rawMatches)), maxSubpatterns * 3))
dealloc(pattern)
if res < 0: return res
for i in 0..res-1:
var
a = rawMatches[i * 2]
b = rawMatches[i * 2 + 1]
if a >= 0'i32: matches[i] = copy(s, a, int(b)-1)
else: matches[i] = ""
return res
proc matchOrFind(s: string, pattern: PPcre, start: cint): cint =
var
rawMatches: array [0..maxSubpatterns * 3 - 1, cint]
res = pcreExec(pattern, nil, s, len(s), start, 0,
cast[ptr cint](addr(rawMatches)), maxSubpatterns * 3)
dealloc(pattern)
return res
proc match(s, pattern: string, matches: var openarray[string],
start: int = 0): bool =
return matchOrFind(s, rawCompile(pattern, PCRE_ANCHORED),
matches, start) >= 0'i32
proc matchLen(s, pattern: string, matches: var openarray[string],
start: int = 0): int =
return matchOrFind(s, rawCompile(pattern, PCRE_ANCHORED), matches, start)
proc find(s, pattern: string, matches: var openarray[string],
start: int = 0): bool =
return matchOrFind(s, rawCompile(pattern, PCRE_MULTILINE),
matches, start) >= 0'i32
proc match(s, pattern: string, start: int = 0): bool =
return matchOrFind(s, rawCompile(pattern, PCRE_ANCHORED), start) >= 0'i32
proc find(s, pattern: string, start: int = 0): bool =
return matchOrFind(s, rawCompile(pattern, PCRE_MULTILINE), start) >= 0'i32

View file

@ -1,20 +1,20 @@
#
#
# Nimrod's Runtime Library
# (c) Copyright 2006 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
proc population16(a: int): int {.inline.} =
var x = a
x = ((x and 0xAAAA) shr 1) + (x and 0x5555)
x = ((x and 0xCCCC) shr 2) + (x and 0x3333)
x = ((x and 0xF0F0) shr 4) + (x and 0x0F0F)
x = ((x and 0xFF00) shr 8) + (x and 0x00FF)
return x
proc countBits(n: int32): int =
result = population16(n and 0xffff) + population16(n shr 16)
#
#
# Nimrod's Runtime Library
# (c) Copyright 2006 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
proc population16(a: int): int {.inline.} =
var x = a
x = ((x and 0xAAAA) shr 1) + (x and 0x5555)
x = ((x and 0xCCCC) shr 2) + (x and 0x3333)
x = ((x and 0xF0F0) shr 4) + (x and 0x0F0F)
x = ((x and 0xFF00) shr 8) + (x and 0x00FF)
return x
proc countBits(n: int32): int =
result = population16(n and 0xffff'i32) + population16(n shr 16'i32)

View file

@ -1,106 +1,106 @@
#
#
# Nimrod's Runtime Library
# (c) Copyright 2006 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
## This module implements complex numbers.
{.push checks:off, line_dir:off, stack_trace:off, debugger:off.}
# the user does not want to trace a part
# of the standard library!
import
math
type
TComplex* = tuple[re, im: float]
## a complex number, consisting of a real and an imaginary part
proc `==` *(x, y: TComplex): bool =
## Compare two complex numbers `x` and `y` for equality.
result = x.re == y.re and x.im == y.im
proc `+` *(x, y: TComplex): TComplex =
## Add two complex numbers.
result.re = x.re + y.re
result.im = x.im + y.im
proc `-` *(x, y: TComplex): TComplex =
## Subtract two complex numbers.
result.re = x.re - y.re
result.im = x.im - y.im
proc `-` *(z: TComplex): TComplex =
## Unary minus for complex numbers.
result.re = -z.re
result.im = -z.im
proc `/` *(x, y: TComplex): TComplex =
## Divide `x` by `y`.
var
r, den: float
if abs(y.re) < abs(y.im):
r = y.re / y.im
den = y.im + r * y.re
result.re = (x.re * r + x.im) / den
result.im = (x.im * r - x.re) / den
else:
r = y.im / y.re
den = y.re + r * y.im
result.re = (x.re + r * x.im) / den
result.im = (x.im - r * x.re) / den
proc `*` *(x, y: TComplex): TComplex =
## Multiply `x` with `y`.
result.re = x.re * y.re - x.im * y.im
result.im = x.im * y.re + x.re * y.im
proc abs*(z: TComplex): float =
## Return the distance from (0,0) to `z`.
# optimized by checking special cases (sqrt is expensive)
var x, y, temp: float
x = abs(z.re)
y = abs(z.im)
if x == 0.0:
result = y
elif y == 0.0:
result = x
elif x > y:
temp = y / x
result = x * sqrt(1.0 + temp * temp)
else:
temp = x / y
result = y * sqrt(1.0 + temp * temp)
proc sqrt*(z: TComplex): TComplex =
## Square root for a complex number `z`.
var x, y, w, r: float
if z.re == 0.0 and z.im == 0.0:
result = z
else:
x = abs(z.re)
y = abs(z.im)
if x >= y:
r = y / x
w = sqrt(x) * sqrt(0.5 * (1.0 + sqrt(1.0 + r * r)))
else:
r = x / y
w = sqrt(y) * sqrt(0.5 * (r + sqrt(1.0 + r * r)))
if z.re >= 0.0:
result.re = w
result.im = z.im / (w * 2)
else:
if z.im >= 0.0: result.im = w
else: result.im = -w
result.re = z.im / (c.im + c.im)
{.pop.}
#
#
# Nimrod's Runtime Library
# (c) Copyright 2006 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
## This module implements complex numbers.
{.push checks:off, line_dir:off, stack_trace:off, debugger:off.}
# the user does not want to trace a part
# of the standard library!
import
math
type
TComplex* = tuple[re, im: float]
## a complex number, consisting of a real and an imaginary part
proc `==` *(x, y: TComplex): bool =
## Compare two complex numbers `x` and `y` for equality.
result = x.re == y.re and x.im == y.im
proc `+` *(x, y: TComplex): TComplex =
## Add two complex numbers.
result.re = x.re + y.re
result.im = x.im + y.im
proc `-` *(x, y: TComplex): TComplex =
## Subtract two complex numbers.
result.re = x.re - y.re
result.im = x.im - y.im
proc `-` *(z: TComplex): TComplex =
## Unary minus for complex numbers.
result.re = -z.re
result.im = -z.im
proc `/` *(x, y: TComplex): TComplex =
## Divide `x` by `y`.
var
r, den: float
if abs(y.re) < abs(y.im):
r = y.re / y.im
den = y.im + r * y.re
result.re = (x.re * r + x.im) / den
result.im = (x.im * r - x.re) / den
else:
r = y.im / y.re
den = y.re + r * y.im
result.re = (x.re + r * x.im) / den
result.im = (x.im - r * x.re) / den
proc `*` *(x, y: TComplex): TComplex =
## Multiply `x` with `y`.
result.re = x.re * y.re - x.im * y.im
result.im = x.im * y.re + x.re * y.im
proc abs*(z: TComplex): float =
## Return the distance from (0,0) to `z`.
# optimized by checking special cases (sqrt is expensive)
var x, y, temp: float
x = abs(z.re)
y = abs(z.im)
if x == 0.0:
result = y
elif y == 0.0:
result = x
elif x > y:
temp = y / x
result = x * sqrt(1.0 + temp * temp)
else:
temp = x / y
result = y * sqrt(1.0 + temp * temp)
proc sqrt*(z: TComplex): TComplex =
## Square root for a complex number `z`.
var x, y, w, r: float
if z.re == 0.0 and z.im == 0.0:
result = z
else:
x = abs(z.re)
y = abs(z.im)
if x >= y:
r = y / x
w = sqrt(x) * sqrt(0.5 * (1.0 + sqrt(1.0 + r * r)))
else:
r = x / y
w = sqrt(y) * sqrt(0.5 * (r + sqrt(1.0 + r * r)))
if z.re >= 0.0:
result.re = w
result.im = z.im / (w * 2)
else:
if z.im >= 0.0: result.im = w
else: result.im = -w
result.re = z.im / (c.im + c.im)
{.pop.}

View file

@ -1,5 +1,4 @@
# Container library for Nimrod
# Implemented with macros, because generics sucks in many ways
# Data structures for now:
# TTable, TSet, TList

File diff suppressed because it is too large Load diff

View file

@ -1,12 +1,15 @@
#define USE_DL_PREFIX
#define USE_DL_PREFIX
#define ASSEMBLY_VERSION
/*
#define FOOTERS 1
#define DEBUG 1
/*
#define ABORT_ON_ASSERT_FAILURE 0
*/
#define ABORT do { printf("abort was called\n"); abort(); } while (0)
#define ABORT do { /*printf("abort was called\n");*/ abort(); } while (0)
/*
This is a version (aka dlmalloc) of malloc/free/realloc written by
@ -2210,7 +2213,7 @@ static size_t traverse_and_check(mstate m);
#define treebin_at(M,i) (&((M)->treebins[i]))
/* assign tree index for size S to variable I */
#if defined(__GNUC__) && defined(i386)
#if defined(__GNUC__) && defined(i386) && defined(ASSEMBLY_VERSION)
#define compute_tree_index(S, I)\
{\
size_t X = S >> TREEBIN_SHIFT;\
@ -2275,7 +2278,7 @@ static size_t traverse_and_check(mstate m);
/* index corresponding to given bit */
#if defined(__GNUC__) && defined(i386)
#if defined(__GNUC__) && defined(i386) && defined(ASSEMBLY_VERSION)
#define compute_bit2idx(X, I)\
{\
unsigned int J;\

View file

@ -7,25 +7,14 @@
# distribution, for details about the copyright.
#
#
# This file implements the ability to call native procs from libraries.
# It is not possible to do this in a platform independant way, unfortunately.
# However, the interface has been designed to take platform differences into
# account and been ported to all major platforms.
#
# interface
type
EInvalidLibrary = object of EOS
when defined(windows) or defined(dos):
{.define: USE_DLL.}
elif defined(posix):
{.define: USE_DLOPEN.}
elif defined(mac):
{.define: USE_DYLD.}
type
TLibHandle = pointer # private type
TProcAddr = pointer # libary loading and loading of procs:
@ -37,15 +26,13 @@ proc nimLoadLibrary(path: string): TLibHandle {.compilerproc.}
proc nimUnloadLibrary(lib: TLibHandle) {.compilerproc.}
proc nimGetProcAddr(lib: TLibHandle, name: cstring): TProcAddr {.compilerproc.}
#implementation
# this code was inspired from Lua's source code:
# Lua - An Extensible Extension Language
# Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil
# http://www.lua.org
# mailto:info@lua.org
when defined(USE_DLOPEN):
when defined(posix):
#
# =========================================================================
# This is an implementation based on the dlfcn interface.
@ -76,7 +63,7 @@ when defined(USE_DLOPEN):
proc nimGetProcAddr(lib: TLibHandle, name: cstring): TProcAddr =
result = dlsym(lib, name)
elif defined(USE_DLL):
elif defined(windows) or defined(dos):
#
# =======================================================================
# Native Windows Implementation
@ -96,13 +83,13 @@ elif defined(USE_DLL):
proc nimLoadLibrary(path: string): TLibHandle =
result = cast[TLibHandle](winLoadLibrary(path))
if result == nil:
if result == nil:
raise newException(EInvalidLibrary, "could not load: " & path)
proc nimGetProcAddr(lib: TLibHandle, name: cstring): TProcAddr =
result = GetProcAddress(cast[THINSTANCE](lib), name)
elif defined(USE_DYLD):
elif defined(mac):
#
# =======================================================================
# Native Mac OS X / Darwin Implementation

View file

@ -15,6 +15,7 @@ proc GC_fullCollect() = nil
proc GC_setStrategy(strategy: TGC_Strategy) = nil
proc GC_enableMarkAndSweep() = nil
proc GC_disableMarkAndSweep() = nil
proc GC_getStatistics(): string = return ""
proc getOccupiedMem(): int = return -1
proc getFreeMem(): int = return -1

View file

@ -171,8 +171,7 @@ var
proc signalHandler(sig: cint) {.exportc: "signalHandler", noconv.} =
# print stack trace and quit
var
s = int(sig)
var s = sig
GC_disable()
setLen(buf, 0)
rawWriteStackTrace(buf)
@ -199,7 +198,8 @@ proc registerSignalHandler() =
c_signal(SIGILL, signalHandler)
c_signal(SIGBUS, signalHandler)
registerSignalHandler() # call it in initialization section
when not defined(noSignalHandler):
registerSignalHandler() # call it in initialization section
# for easier debugging of the GC, this memory is only allocated after the
# signal handlers have been registered
new(gAssertionFailed)
@ -256,3 +256,12 @@ proc chckObj(obj, subclass: PNimType) {.compilerproc.} =
proc chckObjAsgn(a, b: PNimType) {.compilerproc, inline.} =
if a != b:
raise newException(EInvalidObjectAssignment, "invalid object assignment")
proc isObj(obj, subclass: PNimType): bool {.compilerproc.} =
# checks if obj is of type subclass:
var x = obj
if x == subclass: return true # optimized fast path
while x != subclass:
if x == nil: return false
x = x.base
return true

1154
lib/gc.nim

File diff suppressed because it is too large Load diff

View file

@ -104,8 +104,7 @@ const
growthFactor = 2 # must be power of two
proc init*[TKey, TValue](t: var TTable[TKey, TValue], capacity: natural = 32) =
t.d = [] # XXX
setLen(t.d, capacity)
newSeq(t.d, capacity)
proc len*[TKey, TValue](t: TTable[TKey, TValue]): natural = return t.counter
@ -136,8 +135,8 @@ proc TableRawInsert[TKey, TValue](data: var seq[TPair[TKey, TValue]],
data[h].val = val
proc TableEnlarge[TKey, TValue](t: var TTable[TKey, TValue]) =
var n: seq[TPair[TKey,TValue]] = []
setLen(n, len(t.d) * growthFactor) # XXX
var n: seq[TPair[TKey,TValue]]
newSeq(n, len(t.d) * growthFactor)
for i in 0..high(t.d):
if not isNil(t.d[i].key):
TableRawInsert(n, t.d[i].key, t.d[i].val)

View file

@ -1,97 +1,97 @@
#
#
# Nimrod's Runtime Library
# (c) Copyright 2008 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
## This module implements efficient computations of hash values for diverse
## Nimrod types.
import
strutils
type
THash* = int ## a hash value; hash tables using these values should
## always have a size of a power of two and can use the ``and``
## operator instead of ``mod`` for truncation of the hash value.
proc concHash(h: THash, val: int): THash {.inline.} =
result = h +% val
result = result +% result shl 10
result = result xor (result shr 6)
proc finishHash(h: THash): THash {.inline.} =
result = h +% h shl 3
result = result xor (result shr 11)
result = result +% result shl 15
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
while s > 0:
h = concHash(h, ord(p[i]))
Inc(i)
Dec(s)
result = finishHash(h)
proc hash*(x: Pointer): THash {.inline.} =
## efficient hashing of pointers
result = (cast[THash](x)) shr 3 # skip the alignment
proc hash*(x: int): THash {.inline.} =
## efficient hashing of integers
result = x
proc hash*(x: int64): THash {.inline.} =
## efficient hashing of integers
result = toU32(x)
proc hash*(x: char): THash {.inline.} =
## efficient hashing of characters
result = ord(x)
proc hash*(x: string): THash =
## efficient hashing of strings
var h: THash
h = 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
for i in 0..x.len-1:
c = x[i]
if c == '_':
continue # skip _
if c in {'A'..'Z'}:
c = chr(ord(c) + (ord('a') - ord('A'))) # toLower()
h = concHash(h, ord(c))
result = finishHash(h)
proc hashIgnoreCase*(x: string): THash =
## efficient hashing of strings; case is ignored
var
h: THash
c: Char
h = 0
for i in 0..x.len-1:
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)
#
#
# Nimrod's Runtime Library
# (c) Copyright 2008 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
## This module implements efficient computations of hash values for diverse
## Nimrod types.
import
strutils
type
THash* = int ## a hash value; hash tables using these values should
## always have a size of a power of two and can use the ``and``
## operator instead of ``mod`` for truncation of the hash value.
proc concHash(h: THash, val: int): THash {.inline.} =
result = h +% val
result = result +% result shl 10
result = result xor (result shr 6)
proc finishHash(h: THash): THash {.inline.} =
result = h +% h shl 3
result = result xor (result shr 11)
result = result +% result shl 15
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
while s > 0:
h = concHash(h, ord(p[i]))
Inc(i)
Dec(s)
result = finishHash(h)
proc hash*(x: Pointer): THash {.inline.} =
## efficient hashing of pointers
result = (cast[THash](x)) shr 3 # skip the alignment
proc hash*(x: int): THash {.inline.} =
## efficient hashing of integers
result = x
proc hash*(x: int64): THash {.inline.} =
## efficient hashing of integers
result = toU32(x)
proc hash*(x: char): THash {.inline.} =
## efficient hashing of characters
result = ord(x)
proc hash*(x: string): THash =
## efficient hashing of strings
var h: THash
h = 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
for i in 0..x.len-1:
c = x[i]
if c == '_':
continue # skip _
if c in {'A'..'Z'}:
c = chr(ord(c) + (ord('a') - ord('A'))) # toLower()
h = concHash(h, ord(c))
result = finishHash(h)
proc hashIgnoreCase*(x: string): THash =
## efficient hashing of strings; case is ignored
var
h: THash
c: Char
h = 0
for i in 0..x.len-1:
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)

View file

@ -13,7 +13,7 @@ type # This should be he same as ast.TTypeKind
tyNone, # 0
tyBool, # 1
tyChar, # 2
tyEmptySet, # 3
tyEmpty, # 3
tyArrayConstr, # 4
tyNil, # 5
tyGeneric, # 6
@ -49,9 +49,13 @@ type # This should be he same as ast.TTypeKind
len: int
sons: ptr array [0..0x7fff, ptr TNimNode]
TNimTypeFlag = enum
ntfNoRefs = 0, # type contains no tyRef, tySequence, tyString
ntfAcyclic = 1 # type cannot form a cycle
TNimType {.compilerproc, final.} = object
size: int
kind: TNimKind
flags: set[TNimTypeFlag]
base: ptr TNimType
node: ptr TNimNode # valid for tyRecord, tyObject, tyTuple, tyEnum
finalizer: pointer # the finalizer for the type

View file

@ -1,71 +1,71 @@
#
#
# Nimrod's Runtime Library
# (c) Copyright 2006 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
# 64 bit integers for platforms that don't have those
type
IInt64 = tuple[lo, hi: int32]
proc cmpI64(x, y: IInt64): int32 {.compilerproc.} =
result = x.hi -% y.hi
if result == 0: result = x.lo -% y.lo
proc addI64(x, y: IInt64): IInt64 {.compilerproc.} =
result = x
result.lo = result.lo +% y.lo
result.hi = result.hi +% y.hi
if y.lo > 0 and result.lo < y.lo:
inc(result.hi)
elif y.lo < 0 and result.lo > y.lo:
dec(result.hi)
proc subI64(x, y: IInt64): IInt64 {.compilerproc.} =
result = x
result.lo = result.lo -% y.lo
result.hi = result.hi -% y.hi
if y.lo > 0 and result.lo < y.lo:
inc(result.hi)
elif y.lo < 0 and result.lo > y.lo:
dec(result.hi)
proc mulI64(x, y: IInt64): IInt64 {.compilerproc.} =
result.lo = x.lo *% y.lo
result.hi = y.hi *% y.hi
if y.lo > 0 and result.lo < y.lo:
inc(result.hi)
elif y.lo < 0 and result.lo > y.lo:
dec(result.hi)
proc divI64(x, y: IInt64): IInt64 {.compilerproc.} =
# XXX: to implement
proc modI64(x, y: IInt64): IInt64 {.compilerproc.} =
# XXX: to implement
proc bitandI64(x, y: IInt64): IInt64 {.compilerproc.} =
result.hi = x.hi and y.hi
result.lo = x.lo and y.lo
proc bitorI64(x, y: IInt64): IInt64 {.compilerproc.} =
result.hi = x.hi or y.hi
result.lo = x.lo or y.lo
proc bitxorI64(x, y: IInt64): IInt64 {.compilerproc.} =
result.hi = x.hi xor y.hi
result.lo = x.lo xor y.lo
proc bitnotI64(x: IInt64): IInt64 {.compilerproc.} =
result.lo = not x.lo
result.hi = not x.hi
proc shlI64(x, y: IInt64): IInt64 {.compilerproc.} =
# XXX: to implement
proc shrI64(x, y: IInt64): IInt64 {.compilerproc.} =
# XXX: to implement
#
#
# Nimrod's Runtime Library
# (c) Copyright 2006 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
# 64 bit integers for platforms that don't have those
type
IInt64 = tuple[lo, hi: int32]
proc cmpI64(x, y: IInt64): int32 {.compilerproc.} =
result = x.hi -% y.hi
if result == 0: result = x.lo -% y.lo
proc addI64(x, y: IInt64): IInt64 {.compilerproc.} =
result = x
result.lo = result.lo +% y.lo
result.hi = result.hi +% y.hi
if y.lo > 0 and result.lo < y.lo:
inc(result.hi)
elif y.lo < 0 and result.lo > y.lo:
dec(result.hi)
proc subI64(x, y: IInt64): IInt64 {.compilerproc.} =
result = x
result.lo = result.lo -% y.lo
result.hi = result.hi -% y.hi
if y.lo > 0 and result.lo < y.lo:
inc(result.hi)
elif y.lo < 0 and result.lo > y.lo:
dec(result.hi)
proc mulI64(x, y: IInt64): IInt64 {.compilerproc.} =
result.lo = x.lo *% y.lo
result.hi = y.hi *% y.hi
if y.lo > 0 and result.lo < y.lo:
inc(result.hi)
elif y.lo < 0 and result.lo > y.lo:
dec(result.hi)
proc divI64(x, y: IInt64): IInt64 {.compilerproc.} =
# XXX: to implement
proc modI64(x, y: IInt64): IInt64 {.compilerproc.} =
# XXX: to implement
proc bitandI64(x, y: IInt64): IInt64 {.compilerproc.} =
result.hi = x.hi and y.hi
result.lo = x.lo and y.lo
proc bitorI64(x, y: IInt64): IInt64 {.compilerproc.} =
result.hi = x.hi or y.hi
result.lo = x.lo or y.lo
proc bitxorI64(x, y: IInt64): IInt64 {.compilerproc.} =
result.hi = x.hi xor y.hi
result.lo = x.lo xor y.lo
proc bitnotI64(x: IInt64): IInt64 {.compilerproc.} =
result.lo = not x.lo
result.hi = not x.hi
proc shlI64(x, y: IInt64): IInt64 {.compilerproc.} =
# XXX: to implement
proc shrI64(x, y: IInt64): IInt64 {.compilerproc.} =
# XXX: to implement

View file

@ -1,186 +1,167 @@
#
#
# The Nimrod Compiler
# (c) Copyright 2008 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
## This module implements a base object of a lexer with efficient buffer
## handling. In fact I believe that this is the most efficient method of
## buffer handling that exists! Only at line endings checks are necessary
## if the buffer needs refilling.
import
strutils
const
EndOfFile* = '\0' ## end of file marker
# A little picture makes everything clear :-)
# buf:
# "Example Text\n ha!" bufLen = 17
# ^pos = 0 ^ sentinel = 12
#
NewLines* = {'\c', '\L'}
type
TBaseLexer* = object of TObject ## the base lexer. Inherit your lexer from
## this object.
bufpos*: int ## the current position within the buffer
buf*: cstring ## the buffer itself
bufLen*: int ## length of buffer in characters
f*: tfile ## the file that is read
LineNumber*: int ## the current line number
sentinel: int
lineStart: int # index of last line start in buffer
fileOpened: bool
proc initBaseLexer*(L: var TBaseLexer, filename: string, bufLen: int = 8192): bool
## inits the TBaseLexer object with a file to scan
proc initBaseLexerFromBuffer*(L: var TBaseLexer, buffer: string)
## inits the TBaseLexer with a buffer to scan
proc deinitBaseLexer*(L: var TBaseLexer)
## deinitializes the base lexer. This needs to be called to close the file.
proc getCurrentLine*(L: TBaseLexer, marker: bool = true): string
## retrieves the current line.
proc getColNumber*(L: TBaseLexer, pos: int): int
## retrieves the current column.
proc HandleCR*(L: var TBaseLexer, pos: int): int
## Call this if you scanned over '\c' in the buffer; it returns the the
## position to continue the scanning from. `pos` must be the position
## of the '\c'.
proc HandleLF*(L: var TBaseLexer, pos: int): int
## Call this if you scanned over '\L' in the buffer; it returns the the
## position to continue the scanning from. `pos` must be the position
## of the '\L'.
# implementation
const
chrSize = sizeof(char)
proc deinitBaseLexer(L: var TBaseLexer) =
dealloc(L.buf)
if L.fileOpened: closeFile(L.f)
proc FillBuffer(L: var TBaseLexer) =
var
charsRead, toCopy, s: int # all are in characters,
# not bytes (in case this
# is not the same)
oldBufLen: int
# we know here that pos == L.sentinel, but not if this proc
# is called the first time by initBaseLexer()
assert(L.sentinel < L.bufLen)
toCopy = L.BufLen - L.sentinel - 1
assert(toCopy >= 0)
if toCopy > 0:
MoveMem(L.buf, addr(L.buf[L.sentinel + 1]), toCopy * chrSize) # "moveMem" handles overlapping regions
charsRead = ReadBuffer(L.f, addr(L.buf[toCopy]), (L.sentinel + 1) * chrSize) div
chrSize
s = toCopy + charsRead
if charsRead < L.sentinel + 1:
L.buf[s] = EndOfFile # set end marker
L.sentinel = s
else:
# compute sentinel:
dec(s) # BUGFIX (valgrind)
while true:
assert(s < L.bufLen)
while (s >= 0) and not (L.buf[s] in NewLines): Dec(s)
if s >= 0:
# we found an appropriate character for a sentinel:
L.sentinel = s
break
else:
# rather than to give up here because the line is too long,
# double the buffer's size and try again:
oldBufLen = L.BufLen
L.bufLen = L.BufLen * 2
L.buf = cast[cstring](realloc(L.buf, L.bufLen * chrSize))
assert(L.bufLen - oldBuflen == oldBufLen)
charsRead = ReadBuffer(L.f, addr(L.buf[oldBufLen]), oldBufLen * chrSize) div
chrSize
if charsRead < oldBufLen:
L.buf[oldBufLen + charsRead] = EndOfFile
L.sentinel = oldBufLen + charsRead
break
s = L.bufLen - 1
proc fillBaseLexer(L: var TBaseLexer, pos: int): int =
assert(pos <= L.sentinel)
if pos < L.sentinel:
result = pos + 1 # nothing to do
else:
fillBuffer(L)
L.bufpos = 0 # XXX: is this really correct?
result = 0
L.lineStart = result
proc HandleCR(L: var TBaseLexer, pos: int): int =
assert(L.buf[pos] == '\c')
inc(L.linenumber)
result = fillBaseLexer(L, pos)
if L.buf[result] == '\L':
result = fillBaseLexer(L, result)
proc HandleLF(L: var TBaseLexer, pos: int): int =
assert(L.buf[pos] == '\L')
inc(L.linenumber)
result = fillBaseLexer(L, pos) #L.lastNL := result-1; // BUGFIX: was: result;
proc skip_UTF_8_BOM(L: var TBaseLexer) =
if (L.buf[0] == '\xEF') and (L.buf[1] == '\xBB') and (L.buf[2] == '\xBF'):
inc(L.bufpos, 3)
inc(L.lineStart, 3)
proc initBaseLexer(L: var TBaseLexer, filename: string, bufLen: int = 8192): bool =
assert(bufLen > 0)
L.bufpos = 0
L.bufLen = bufLen
L.buf = cast[cstring](alloc(bufLen * chrSize))
L.sentinel = bufLen - 1
L.lineStart = 0
L.linenumber = 1 # lines start at 1
L.fileOpened = openFile(L.f, filename)
result = L.fileOpened
if result:
fillBuffer(L)
skip_UTF_8_BOM(L)
proc initBaseLexerFromBuffer(L: var TBaseLexer, buffer: string) =
L.bufpos = 0
L.bufLen = len(buffer) + 1
L.buf = cast[cstring](alloc(L.bufLen * chrSize))
L.sentinel = L.bufLen - 1
L.lineStart = 0
L.linenumber = 1 # lines start at 1
L.fileOpened = false
if L.bufLen > 0:
copyMem(L.buf, cast[pointer](buffer), L.bufLen)
L.buf[L.bufLen - 1] = EndOfFile
else:
L.buf[0] = EndOfFile
skip_UTF_8_BOM(L)
proc getColNumber(L: TBaseLexer, pos: int): int =
result = pos - L.lineStart
assert(result >= 0)
proc getCurrentLine(L: TBaseLexer, marker: bool = true): string =
var i: int
result = ""
i = L.lineStart
while not (L.buf[i] in {'\c', '\L', EndOfFile}):
add(result, L.buf[i])
inc(i)
add(result, "\n")
if marker:
add(result, RepeatChar(getColNumber(L, L.bufpos)) & "^\n")
#
#
# The Nimrod Compiler
# (c) Copyright 2008 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
## This module implements a base object of a lexer with efficient buffer
## handling. Only at line endings checks are necessary if the buffer
## needs refilling.
import
strutils, streams
const
EndOfFile* = '\0' ## end of file marker
NewLines* = {'\c', '\L'}
# Buffer handling:
# buf:
# "Example Text\n ha!" bufLen = 17
# ^pos = 0 ^ sentinel = 12
#
type
TBaseLexer* = object of TObject ## the base lexer. Inherit your lexer from
## this object.
bufpos*: int ## the current position within the buffer
buf*: cstring ## the buffer itself
bufLen*: int ## length of buffer in characters
input: PStream ## the input stream
LineNumber*: int ## the current line number
sentinel: int
lineStart: int # index of last line start in buffer
fileOpened: bool
proc open*(L: var TBaseLexer, input: PStream, bufLen: int = 8192)
## inits the TBaseLexer with a stream to read from
proc close*(L: var TBaseLexer)
## closes the base lexer. This closes `L`'s associated stream too.
proc getCurrentLine*(L: TBaseLexer, marker: bool = true): string
## retrieves the current line.
proc getColNumber*(L: TBaseLexer, pos: int): int
## retrieves the current column.
proc HandleCR*(L: var TBaseLexer, pos: int): int
## Call this if you scanned over '\c' in the buffer; it returns the the
## position to continue the scanning from. `pos` must be the position
## of the '\c'.
proc HandleLF*(L: var TBaseLexer, pos: int): int
## Call this if you scanned over '\L' in the buffer; it returns the the
## position to continue the scanning from. `pos` must be the position
## of the '\L'.
# implementation
const
chrSize = sizeof(char)
proc close(L: var TBaseLexer) =
dealloc(L.buf)
L.input.close(L.input)
proc FillBuffer(L: var TBaseLexer) =
var
charsRead, toCopy, s: int # all are in characters,
# not bytes (in case this
# is not the same)
oldBufLen: int
# we know here that pos == L.sentinel, but not if this proc
# is called the first time by initBaseLexer()
assert(L.sentinel < L.bufLen)
toCopy = L.BufLen - L.sentinel - 1
assert(toCopy >= 0)
if toCopy > 0:
MoveMem(L.buf, addr(L.buf[L.sentinel + 1]), toCopy * chrSize) # "moveMem" handles overlapping regions
charsRead = L.input.readData(L.input, addr(L.buf[toCopy]),
(L.sentinel + 1) * chrSize) div chrSize
s = toCopy + charsRead
if charsRead < L.sentinel + 1:
L.buf[s] = EndOfFile # set end marker
L.sentinel = s
else:
# compute sentinel:
dec(s) # BUGFIX (valgrind)
while true:
assert(s < L.bufLen)
while (s >= 0) and not (L.buf[s] in NewLines): Dec(s)
if s >= 0:
# we found an appropriate character for a sentinel:
L.sentinel = s
break
else:
# rather than to give up here because the line is too long,
# double the buffer's size and try again:
oldBufLen = L.BufLen
L.bufLen = L.BufLen * 2
L.buf = cast[cstring](realloc(L.buf, L.bufLen * chrSize))
assert(L.bufLen - oldBuflen == oldBufLen)
charsRead = L.input.ReadData(L.input, addr(L.buf[oldBufLen]),
oldBufLen * chrSize) div chrSize
if charsRead < oldBufLen:
L.buf[oldBufLen + charsRead] = EndOfFile
L.sentinel = oldBufLen + charsRead
break
s = L.bufLen - 1
proc fillBaseLexer(L: var TBaseLexer, pos: int): int =
assert(pos <= L.sentinel)
if pos < L.sentinel:
result = pos + 1 # nothing to do
else:
fillBuffer(L)
L.bufpos = 0 # XXX: is this really correct?
result = 0
L.lineStart = result
proc HandleCR(L: var TBaseLexer, pos: int): int =
assert(L.buf[pos] == '\c')
inc(L.linenumber)
result = fillBaseLexer(L, pos)
if L.buf[result] == '\L':
result = fillBaseLexer(L, result)
proc HandleLF(L: var TBaseLexer, pos: int): int =
assert(L.buf[pos] == '\L')
inc(L.linenumber)
result = fillBaseLexer(L, pos) #L.lastNL := result-1; // BUGFIX: was: result;
proc skip_UTF_8_BOM(L: var TBaseLexer) =
if (L.buf[0] == '\xEF') and (L.buf[1] == '\xBB') and (L.buf[2] == '\xBF'):
inc(L.bufpos, 3)
inc(L.lineStart, 3)
proc open(L: var TBaseLexer, input: PStream, bufLen: int = 8192) =
assert(bufLen > 0)
assert(input != nil)
L.input = input
L.bufpos = 0
L.bufLen = bufLen
L.buf = cast[cstring](alloc(bufLen * chrSize))
L.sentinel = bufLen - 1
L.lineStart = 0
L.linenumber = 1 # lines start at 1
fillBuffer(L)
skip_UTF_8_BOM(L)
proc getColNumber(L: TBaseLexer, pos: int): int =
result = pos - L.lineStart
assert(result >= 0)
proc getCurrentLine(L: TBaseLexer, marker: bool = true): string =
var i: int
result = ""
i = L.lineStart
while not (L.buf[i] in {'\c', '\L', EndOfFile}):
add(result, L.buf[i])
inc(i)
add(result, "\n")
if marker:
add(result, RepeatChar(getColNumber(L, L.bufpos)) & "^\n")

View file

@ -1,176 +1,175 @@
#
#
# Nimrod's Runtime Library
# (c) Copyright 2008 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
## This module contains the interface to the compiler's abstract syntax tree.
## Abstract syntax trees should be modified in macros.
#[[[cog
#def toEnum(name, elems, prefix):
# body = ""
# counter = 0
# for e in elems:
# if counter % 4 == 0: p = "\n "
# else: p = ""
# body += p + prefix + e[2:] + ', '
# counter += 1
#
# return " TNimrod%s* = enum%s\n TNim%ss* = set[TNimrod%s]\n" \
# % (name, body.rstrip(", "), name, name)
#
#enums = eval(file("data/ast.yml").read())
#cog.out("type\n")
#i = 0
#for key, val in enums.iteritems():
# if key.endswith("Flag"): continue
# cog.out(toEnum(key, val, ["nnk", "nty", "nsk"][i]))
# i += 1
#]]]
type
TNimrodNodeKind* = enum
nnkNone, nnkEmpty, nnkIdent, nnkSym,
nnkType, nnkCharLit, nnkIntLit, nnkInt8Lit,
nnkInt16Lit, nnkInt32Lit, nnkInt64Lit, nnkFloatLit,
nnkFloat32Lit, nnkFloat64Lit, nnkStrLit, nnkRStrLit,
nnkTripleStrLit, nnkMetaNode, nnkNilLit, nnkDotCall,
nnkCommand, nnkCall, nnkGenericCall, nnkExplicitTypeListCall,
nnkExprEqExpr, nnkExprColonExpr, nnkIdentDefs, nnkInfix,
nnkPrefix, nnkPostfix, nnkPar, nnkCurly,
nnkBracket, nnkBracketExpr, nnkPragmaExpr, nnkRange,
nnkDotExpr, nnkCheckedFieldExpr, nnkDerefExpr, nnkIfExpr,
nnkElifExpr, nnkElseExpr, nnkLambda, nnkAccQuoted,
nnkHeaderQuoted, nnkTableConstr, nnkQualified, nnkHiddenStdConv,
nnkHiddenSubConv, nnkHiddenCallConv, nnkConv, nnkCast,
nnkAddr, nnkHiddenAddr, nnkHiddenDeref, nnkObjDownConv,
nnkObjUpConv, nnkChckRangeF, nnkChckRange64, nnkChckRange,
nnkStringToCString, nnkCStringToString, nnkPassAsOpenArray, nnkAsgn,
nnkDefaultTypeParam, nnkGenericParams, nnkFormalParams, nnkOfInherit,
nnkModule, nnkProcDef, nnkConverterDef, nnkMacroDef,
nnkTemplateDef, nnkIteratorDef, nnkOfBranch, nnkElifBranch,
nnkExceptBranch, nnkElse, nnkMacroStmt, nnkAsmStmt,
nnkPragma, nnkIfStmt, nnkWhenStmt, nnkForStmt,
nnkWhileStmt, nnkCaseStmt, nnkVarSection, nnkConstSection,
nnkConstDef, nnkTypeSection, nnkTypeDef, nnkYieldStmt,
nnkTryStmt, nnkFinally, nnkRaiseStmt, nnkReturnStmt,
nnkBreakStmt, nnkContinueStmt, nnkBlockStmt, nnkDiscardStmt,
nnkStmtList, nnkImportStmt, nnkFromStmt, nnkImportAs,
nnkIncludeStmt, nnkAccessStmt, nnkCommentStmt, nnkStmtListExpr,
nnkBlockExpr, nnkVm, nnkTypeOfExpr, nnkObjectTy,
nnkTupleTy, nnkRecList, nnkRecCase, nnkRecWhen,
nnkRefTy, nnkPtrTy, nnkVarTy, nnkProcTy,
nnkEnumTy, nnkEnumFieldDef, nnkReturnToken
TNimNodeKinds* = set[TNimrodNodeKind]
TNimrodTypeKind* = enum
ntyNone, ntyBool, ntyChar, ntyEmptySet,
ntyArrayConstr, ntyNil, ntyGeneric, ntyGenericInst,
ntyGenericParam, ntyEnum, ntyAnyEnum, ntyArray,
ntyObject, ntyTuple, ntySet, ntyRange,
ntyPtr, ntyRef, ntyVar, ntySequence,
ntyProc, ntyPointer, ntyOpenArray, ntyString,
ntyCString, ntyForward, ntyInt, ntyInt8,
ntyInt16, ntyInt32, ntyInt64, ntyFloat,
ntyFloat32, ntyFloat64, ntyFloat128
TNimTypeKinds* = set[TNimrodTypeKind]
TNimrodSymKind* = enum
nskUnknownSym, nskConditional, nskDynLib, nskParam,
nskTypeParam, nskTemp, nskType, nskConst,
nskVar, nskProc, nskIterator, nskConverter,
nskMacro, nskTemplate, nskField, nskEnumField,
nskForVar, nskModule, nskLabel
TNimSymKinds* = set[TNimrodSymKind]
#[[[end]]]
type
TNimrodNode {.final.} = object # hidden
TNimrodSymbol {.final.} = object # hidden
TNimrodType {.final.} = object # hidden
PNimrodType* {.compilerproc.} = ref TNimrodType
PNimrodSymbol* {.compilerproc.} = ref TNimrodSymbol
PNimrodNode* {.compilerproc.} = ref TNimrodNode
expr* = PNimrodNode
stmt* = PNimrodNode
# Nodes should be reference counted to make the `copy` operation very fast!
# However, this is difficult to achieve: modify(n[0][1]) should propagate to
# its father. How to do this without back references?
proc `[]`* (n: PNimrodNode, i: int): PNimrodNode {.magic: "NChild".}
proc `[]=`* (n: PNimrodNode, i: int, child: PNimrodNode) {.magic: "NSetChild".}
## provide access to `n`'s children
type
TNimrodIdent = object of TObject
converter StrToIdent*(s: string): TNimrodIdent {.magic: "StrToIdent".}
proc `$`*(i: TNimrodIdent): string {.magic: "IdentToStr".}
proc `==`* (a, b: TNimrodIdent): bool {.magic: "EqIdent".}
proc len*(n: PNimrodNode): int {.magic: "NLen".}
## returns the number of children that a node has
proc add*(father, child: PNimrodNode) {.magic: "NAdd".}
proc add*(father: PNimrodNode, child: openArray[PNimrodNode]) {.magic: "NAddMultiple".}
proc del*(father: PNimrodNode, idx = 0, n = 1) {.magic: "NDel".}
proc kind*(n: PNimrodNode): TNimrodNodeKind {.magic: "NKind".}
proc intVal*(n: PNimrodNode): biggestInt {.magic: "NIntVal".}
proc floatVal*(n: PNimrodNode): biggestFloat {.magic: "NFloatVal".}
proc symbol*(n: PNimrodNode): PNimrodSymbol {.magic: "NSymbol".}
proc ident*(n: PNimrodNode): TNimrodIdent {.magic: "NIdent".}
proc typ*(n: PNimrodNode): PNimrodType {.magic: "NGetType".}
proc strVal*(n: PNimrodNode): string {.magic: "NStrVal".}
proc `intVal=`*(n: PNimrodNode, val: biggestInt) {.magic: "NSetIntVal".}
proc `floatVal=`*(n: PNimrodNode, val: biggestFloat) {.magic: "NSetFloatVal".}
proc `symbol=`*(n: PNimrodNode, val: PNimrodSymbol) {.magic: "NSetSymbol".}
proc `ident=`*(n: PNimrodNode, val: TNimrodIdent) {.magic: "NSetIdent".}
proc `typ=`*(n: PNimrodNode, typ: PNimrodType) {.magic: "NSetType".}
proc `strVal=`*(n: PNimrodNode, val: string) {.magic: "NSetStrVal".}
proc newNimNode*(kind: TNimrodNodeKind,
n: PNimrodNode=nil): PNimrodNode {.magic: "NNewNimNode".}
proc copyNimNode*(n: PNimrodNode): PNimrodNode {.magic: "NCopyNimNode".}
proc copyNimTree*(n: PNimrodNode): PNimrodNode {.magic: "NCopyNimTree".}
proc error*(msg: string) {.magic: "NError".}
proc warning*(msg: string) {.magic: "NWarning".}
proc hint*(msg: string) {.magic: "NHint".}
proc newStrLitNode*(s: string): PNimrodNode {.nodecl.} =
result = newNimNode(nnkStrLit)
result.strVal = s
proc newIntLitNode*(i: biggestInt): PNimrodNode {.nodecl.} =
result = newNimNode(nnkIntLit)
result.intVal = i
proc newIntLitNode*(f: biggestFloat): PNimrodNode {.nodecl.} =
result = newNimNode(nnkFloatLit)
result.floatVal = f
proc newIdentNode*(i: TNimrodIdent): PNimrodNode {.nodecl.} =
result = newNimNode(nnkIdent)
result.ident = i
proc toStrLit*(n: PNimrodNode): PNimrodNode {.nodecl.} =
return newStrLitNode(repr(n))
proc expectKind*(n: PNimrodNode, k: TNimrodNodeKind) {.nodecl.} =
if n.kind != k: error("macro expects a node of kind: " & repr(k))
proc expectMinLen*(n: PNimrodNode, min: int) {.nodecl.} =
if n.len < min: error("macro expects a node with " & $min & " children")
proc newCall*(theProc: TNimrodIdent,
args: openArray[PNimrodNode]): PNimrodNode {.nodecl.} =
## produces a new call node. `theProc` is the proc that is called with
## the arguments ``args[0..]``.
result = newNimNode(nnkCall)
result.add(newIdentNode(theProc))
result.add(args)
#
#
# Nimrod's Runtime Library
# (c) Copyright 2008 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
## This module contains the interface to the compiler's abstract syntax tree.
## Abstract syntax trees should be modified in macros.
#[[[cog
#def toEnum(name, elems):
# body = ""
# counter = 0
# for e in elems:
# if counter % 4 == 0: p = "\n "
# else: p = ""
# body = body + p + 'n' + e + ', '
# counter = counter + 1
#
# return (" TNimrod%s* = enum%s\n TNim%ss* = set[TNimrod%s]\n" %
# (name, body[:-2], name, name))
#
#enums = eval(open("data/ast.yml").read())
#cog.out("type\n")
#for key, val in enums.items():
# if key[-4:] == "Flag": continue
# cog.out(toEnum(key, val))
#]]]
type
TNimrodTypeKind* = enum
ntyNone, ntyBool, ntyChar, ntyEmpty,
ntyArrayConstr, ntyNil, ntyGeneric, ntyGenericInst,
ntyGenericParam, ntyEnum, ntyAnyEnum, ntyArray,
ntyObject, ntyTuple, ntySet, ntyRange,
ntyPtr, ntyRef, ntyVar, ntySequence,
ntyProc, ntyPointer, ntyOpenArray, ntyString,
ntyCString, ntyForward, ntyInt, ntyInt8,
ntyInt16, ntyInt32, ntyInt64, ntyFloat,
ntyFloat32, ntyFloat64, ntyFloat128
TNimTypeKinds* = set[TNimrodTypeKind]
TNimrodSymKind* = enum
nskUnknownSym, nskConditional, nskDynLib, nskParam,
nskTypeParam, nskTemp, nskType, nskConst,
nskVar, nskProc, nskIterator, nskConverter,
nskMacro, nskTemplate, nskField, nskEnumField,
nskForVar, nskModule, nskLabel, nskStub
TNimSymKinds* = set[TNimrodSymKind]
TNimrodNodeKind* = enum
nnkNone, nnkEmpty, nnkIdent, nnkSym,
nnkType, nnkCharLit, nnkIntLit, nnkInt8Lit,
nnkInt16Lit, nnkInt32Lit, nnkInt64Lit, nnkFloatLit,
nnkFloat32Lit, nnkFloat64Lit, nnkStrLit, nnkRStrLit,
nnkTripleStrLit, nnkMetaNode, nnkNilLit, nnkDotCall,
nnkCommand, nnkCall, nnkGenericCall, nnkExplicitTypeListCall,
nnkExprEqExpr, nnkExprColonExpr, nnkIdentDefs, nnkInfix,
nnkPrefix, nnkPostfix, nnkPar, nnkCurly,
nnkBracket, nnkBracketExpr, nnkPragmaExpr, nnkRange,
nnkDotExpr, nnkCheckedFieldExpr, nnkDerefExpr, nnkIfExpr,
nnkElifExpr, nnkElseExpr, nnkLambda, nnkAccQuoted,
nnkHeaderQuoted, nnkTableConstr, nnkQualified, nnkHiddenStdConv,
nnkHiddenSubConv, nnkHiddenCallConv, nnkConv, nnkCast,
nnkAddr, nnkHiddenAddr, nnkHiddenDeref, nnkObjDownConv,
nnkObjUpConv, nnkChckRangeF, nnkChckRange64, nnkChckRange,
nnkStringToCString, nnkCStringToString, nnkPassAsOpenArray, nnkAsgn,
nnkDefaultTypeParam, nnkGenericParams, nnkFormalParams, nnkOfInherit,
nnkModule, nnkProcDef, nnkConverterDef, nnkMacroDef,
nnkTemplateDef, nnkIteratorDef, nnkOfBranch, nnkElifBranch,
nnkExceptBranch, nnkElse, nnkMacroStmt, nnkAsmStmt,
nnkPragma, nnkIfStmt, nnkWhenStmt, nnkForStmt,
nnkWhileStmt, nnkCaseStmt, nnkVarSection, nnkConstSection,
nnkConstDef, nnkTypeSection, nnkTypeDef, nnkYieldStmt,
nnkTryStmt, nnkFinally, nnkRaiseStmt, nnkReturnStmt,
nnkBreakStmt, nnkContinueStmt, nnkBlockStmt, nnkDiscardStmt,
nnkStmtList, nnkImportStmt, nnkFromStmt, nnkImportAs,
nnkIncludeStmt, nnkAccessStmt, nnkCommentStmt, nnkStmtListExpr,
nnkBlockExpr, nnkStmtListType, nnkBlockType, nnkVm,
nnkTypeOfExpr, nnkObjectTy, nnkTupleTy, nnkRecList,
nnkRecCase, nnkRecWhen, nnkRefTy, nnkPtrTy,
nnkVarTy, nnkProcTy, nnkEnumTy, nnkEnumFieldDef,
nnkReturnToken
TNimNodeKinds* = set[TNimrodNodeKind]
#[[[end]]]
type
TNimrodNode {.final.} = object # hidden
TNimrodSymbol {.final.} = object # hidden
TNimrodType {.final.} = object # hidden
PNimrodType* {.compilerproc.} = ref TNimrodType
PNimrodSymbol* {.compilerproc.} = ref TNimrodSymbol
PNimrodNode* {.compilerproc.} = ref TNimrodNode
expr* = PNimrodNode
stmt* = PNimrodNode
# Nodes should be reference counted to make the `copy` operation very fast!
# However, this is difficult to achieve: modify(n[0][1]) should propagate to
# its father. How to do this without back references?
proc `[]`* (n: PNimrodNode, i: int): PNimrodNode {.magic: "NChild".}
proc `[]=`* (n: PNimrodNode, i: int, child: PNimrodNode) {.magic: "NSetChild".}
## provide access to `n`'s children
type
TNimrodIdent = object of TObject
converter StrToIdent*(s: string): TNimrodIdent {.magic: "StrToIdent".}
proc `$`*(i: TNimrodIdent): string {.magic: "IdentToStr".}
proc `==`* (a, b: TNimrodIdent): bool {.magic: "EqIdent".}
proc len*(n: PNimrodNode): int {.magic: "NLen".}
## returns the number of children that a node has
proc add*(father, child: PNimrodNode) {.magic: "NAdd".}
proc add*(father: PNimrodNode, child: openArray[PNimrodNode]) {.magic: "NAddMultiple".}
proc del*(father: PNimrodNode, idx = 0, n = 1) {.magic: "NDel".}
proc kind*(n: PNimrodNode): TNimrodNodeKind {.magic: "NKind".}
proc intVal*(n: PNimrodNode): biggestInt {.magic: "NIntVal".}
proc floatVal*(n: PNimrodNode): biggestFloat {.magic: "NFloatVal".}
proc symbol*(n: PNimrodNode): PNimrodSymbol {.magic: "NSymbol".}
proc ident*(n: PNimrodNode): TNimrodIdent {.magic: "NIdent".}
proc typ*(n: PNimrodNode): PNimrodType {.magic: "NGetType".}
proc strVal*(n: PNimrodNode): string {.magic: "NStrVal".}
proc `intVal=`*(n: PNimrodNode, val: biggestInt) {.magic: "NSetIntVal".}
proc `floatVal=`*(n: PNimrodNode, val: biggestFloat) {.magic: "NSetFloatVal".}
proc `symbol=`*(n: PNimrodNode, val: PNimrodSymbol) {.magic: "NSetSymbol".}
proc `ident=`*(n: PNimrodNode, val: TNimrodIdent) {.magic: "NSetIdent".}
proc `typ=`*(n: PNimrodNode, typ: PNimrodType) {.magic: "NSetType".}
proc `strVal=`*(n: PNimrodNode, val: string) {.magic: "NSetStrVal".}
proc newNimNode*(kind: TNimrodNodeKind,
n: PNimrodNode=nil): PNimrodNode {.magic: "NNewNimNode".}
proc copyNimNode*(n: PNimrodNode): PNimrodNode {.magic: "NCopyNimNode".}
proc copyNimTree*(n: PNimrodNode): PNimrodNode {.magic: "NCopyNimTree".}
proc error*(msg: string) {.magic: "NError".}
proc warning*(msg: string) {.magic: "NWarning".}
proc hint*(msg: string) {.magic: "NHint".}
proc newStrLitNode*(s: string): PNimrodNode {.compileTime.} =
result = newNimNode(nnkStrLit)
result.strVal = s
proc newIntLitNode*(i: biggestInt): PNimrodNode {.compileTime.} =
result = newNimNode(nnkIntLit)
result.intVal = i
proc newIntLitNode*(f: biggestFloat): PNimrodNode {.compileTime.} =
result = newNimNode(nnkFloatLit)
result.floatVal = f
proc newIdentNode*(i: TNimrodIdent): PNimrodNode {.compileTime.} =
result = newNimNode(nnkIdent)
result.ident = i
proc toStrLit*(n: PNimrodNode): PNimrodNode {.compileTime.} =
return newStrLitNode(repr(n))
proc expectKind*(n: PNimrodNode, k: TNimrodNodeKind) {.compileTime.} =
if n.kind != k: error("macro expects a node of kind: " & repr(k))
proc expectMinLen*(n: PNimrodNode, min: int) {.compileTime.} =
if n.len < min: error("macro expects a node with " & $min & " children")
proc newCall*(theProc: TNimrodIdent,
args: openArray[PNimrodNode]): PNimrodNode {.compileTime.} =
## produces a new call node. `theProc` is the proc that is called with
## the arguments ``args[0..]``.
result = newNimNode(nnkCall)
result.add(newIdentNode(theProc))
result.add(args)

View file

@ -18,6 +18,10 @@
when defined(Posix):
{.passl: "-lm".}
const
PI* = 3.1415926535897932384626433 ## the circle constant PI (Ludolph's number)
E* = 2.71828182845904523536028747 ## Euler's number
type
TFloatClass* = enum ## describes the class a floating point value belongs to.
## This is the type that is returned by `classify`.
@ -35,7 +39,7 @@ proc classify*(x: float): TFloatClass =
# ECMAScript and most C compilers have no classify:
if x == 0.0:
if 1.0/x == 1.0/0.0:
if 1.0/x == Inf:
return fcZero
else:
return fcNegZero
@ -129,7 +133,7 @@ when not defined(ECMAScript):
proc rand(): cint {.importc: "rand", nodecl.}
proc randomize() = srand(gettime(nil))
proc random(max: int): int = return rand() mod max
proc random(max: int): int = return int(rand()) mod max
else:
proc mathrandom(): float {.importc: "Math.random", nodecl.}

View file

@ -164,7 +164,7 @@ else:
# the fact that the OS is likely to give us pages with contingous numbers.
# A page contains either small fixed size objects of the same size or
# variable length objects. An object's size is always aligned at 16 byte
# boundry. Huge objects are dealt with the TLSF algorithm.
# boundary. Huge objects are dealt with the TLSF algorithm.
# The design supports iterating over any object in a fast way.
# A bitset contains any page that starts an allocated page. The page may be
@ -230,6 +230,7 @@ type
zct: TCellArray
stackCells: TCellArray
smallBlocks: array [PageSize div MemAlign, ptr TPageDesc]
freeLists: array [PageSize div MemAlign, ptr TFreeList]
pages: TPageManager
usedPages: TPageList
freePages: TPageList
@ -237,6 +238,11 @@ type
# small blocks:
proc allocSmall(var h: TGcHeap, size: int): pointer =
var s = align(size)
var f = h.freeLists[s]
if f != nil:
f.prev = f.next # remove from list
f.next.prev = f.prev
return f
var p = h.smallBlocks[s]
if p == nil or p.free == nil:
p = newSmallBlock(s, p)

View file

@ -10,6 +10,8 @@
#ifndef NIMBASE_H
#define NIMBASE_H
#include <math.h>
/* calling convention mess ----------------------------------------------- */
#if defined(__GNUC__) || defined(__LCC__) || defined(__POCC__) \
|| defined(__TINYC__)
@ -37,12 +39,16 @@
#if defined(__POCC__)
# define NIM_CONST /* PCC is really picky with const modifiers */
# undef _MSC_VER /* Yeah, right PCC defines _MSC_VER even if it is
not that compatible. Well done. */
#elif defined(__cplusplus)
# define NIM_CONST /* C++ is picky with const modifiers */
#else
# define NIM_CONST const
#endif
#define NIM_THREADVAR __thread
/* --------------- how int64 constants should be declared: ----------- */
#if defined(__GNUC__) || defined(__LCC__) || \
defined(__POCC__) || defined(__DMC__)
@ -51,6 +57,14 @@
# define IL64(x) x
#endif
/* ---------------- casting without correct aliasing rules ----------- */
#if defined(__GNUCC__)
# define NIM_CAST(type, ptr) (((union{type __x__;}*)(ptr))->__x__)
#else
# define NIM_CAST(type, ptr) ((type)(ptr))
#endif
/* ------------------------------------------------------------------- */
#if defined(WIN32) || defined(_WIN32) /* only Windows has this mess... */
@ -94,6 +108,16 @@
#define N_CLOSURE_PTR(rettype, name) rettype (*name)
#if defined(__GNUC__) || defined(__ICC__)
# define N_NOINLINE(rettype, name) rettype __attribute__((noinline)) name
#elif defined(_MSC_VER)
# define N_NOINLINE(rettype, name) __declspec(noinline) rettype name
#else
# define N_NOINLINE(rettype, name) rettype name
#endif
#define N_NOINLINE_PTR(rettype, name) rettype (*name)
#if defined(__BORLANDC__) || defined(__WATCOMC__) || \
defined(__POCC__) || defined(_MSC_VER)
/* these compilers have a fastcall so use it: */
@ -164,13 +188,10 @@
# define _ISOC99_SOURCE 1
# define __USE_ISOC9X 1
# define __USE_ISOC99 1
# include <math.h>
#elif (defined(WIN32) || defined(_WIN32) || defined(__WIN32__)) \
&& !defined(__BORLANDC__) && !defined(__POCC__)
# include <math.h>
/* Win32 doesn't seem to have these functions.
** Therefore implement inline versions of these functions here.
*/
@ -194,8 +215,6 @@ static N_INLINE(long int, lrintf)(float flt) {
#else
# include <math.h>
# ifndef lrint
# define lrint(dbl) ((long int)(dbl))
# endif
@ -214,11 +233,6 @@ static N_INLINE(long int, lrintf)(float flt) {
#include <signal.h>
#include <setjmp.h>
#ifndef NAN
static unsigned long nimNaN[2]={0xffffffff, 0x7fffffff};
# define NAN (*(double*) nimNaN)
#endif
/*
#ifndef INF
static unsigned long nimInf[2]={0xffffffff, 0x7fffffff};
@ -241,8 +255,7 @@ __TINYC__
# define HAVE_STDINT_H
#endif
#if defined(__LCC__) || defined(__GNUC__) || defined(__DMC__) \
|| defined(__POCC__)
#if defined(__LCC__) || defined(__DMC__) || defined(__POCC__)
# define HAVE_STDINT_H
#endif
@ -328,14 +341,16 @@ static N_INLINE(NI32, float32ToInt32)(float val) {
return float64ToInt32((double)val);
}
#define float64ToInt64(x) ((NI64) (x))
#define zeroMem(a, size) memset(a, 0, size)
#define equalMem(a, b, size) (memcmp(a, b, size) == 0)
#define STRING_LITERAL(name, str, length) \
static const struct { \
NI len, space; \
TGenericSeq Sup; \
NIM_CHAR data[length + 1]; \
} name = {length, length, str}
} name = {{length, length}, str}
typedef struct TStringDesc* string;
@ -343,7 +358,7 @@ typedef struct TStringDesc* string;
#if defined(__GNUC__)
# define SEQ_DECL_SIZE /* empty is correct! */
#else
# define SEQ_DECL_SIZE 1000000
# define SEQ_DECL_SIZE 1000000
#endif
#define ALLOC_0(size) calloc(1, size)
@ -352,6 +367,13 @@ typedef struct TStringDesc* string;
#define GenericSeqSize sizeof(TGenericSeq)
#define paramCount() cmdCount
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__i386__)
# ifndef NAN
static unsigned long nimNaN[2]={0xffffffff, 0x7fffffff};
# define NAN (*(double*) nimNaN)
# endif
#endif
#ifndef NAN
# define NAN (0.0 / 0.0)
#endif
@ -399,6 +421,7 @@ struct NimException {
};
#endif
#if 0
typedef struct TStringDesc {
NI len;
NI space;
@ -410,5 +433,6 @@ typedef struct {
} TGenericSeq;
typedef TGenericSeq* PGenericSeq;
#endif
#endif

File diff suppressed because it is too large Load diff

View file

@ -25,7 +25,7 @@
import
hashes, strutils, lexbase
hashes, strutils, lexbase, streams
type
TCfgEventKind* = enum ## enumation of all events that may occur when parsing
@ -37,7 +37,7 @@ type
TCfgEvent* = object of TObject ## describes a parsing event
case kind*: TCfgEventKind ## the kind of the event
of cfgEof: dummy: string
of cfgEof: nil
of cfgSectionStart:
section*: string ## `section` contains the name of the
## parsed section start (syntax: ``[section]``)
@ -59,21 +59,18 @@ type
literal: string # the parsed (string) literal
TParserState = enum
startState, commaState
startState # , commaState # not yet used
TCfgParser* = object of TBaseLexer ## the parser object.
tok: TToken
state: TParserState
filename: string
proc Open*(c: var TCfgParser, filename: string): bool
## initializes the parser, open the file for reading and returns true if
## successful (the file has been found).
proc OpenFromBuffer*(c: var TCfgParser, buf: string)
## initializes the parser with a buffer. This cannot fail.
proc open*(c: var TCfgParser, input: PStream, filename: string)
## initializes the parser with an input stream. `Filename` is only used
## for nice error messages.
proc close*(c: var TCfgParser)
## closes the parser `c`.
## closes the parser `c` and its associated input stream.
proc next*(c: var TCfgParser): TCfgEvent
## retrieves the first/next event. This controls the parser.
@ -87,6 +84,10 @@ proc getLine*(c: TCfgParser): int
proc getFilename*(c: TCfgParser): string
## get the filename of the file that the parser processes.
proc errorStr*(c: TCfgParser, msg: string): string
## returns a properly formated error message containing current line and
## column information.
# implementation
@ -94,24 +95,16 @@ const
SymChars: TCharSet = {'a'..'z', 'A'..'Z', '0'..'9', '_', '\x80'..'\xFF'}
proc rawGetTok(c: var TCfgParser, tok: var TToken)
proc open(c: var TCfgParser, filename: string): bool =
result = initBaseLexer(c, filename)
proc open(c: var TCfgParser, input: PStream, filename: string) =
lexbase.open(c, input)
c.filename = filename
c.state = startState
c.tok.kind = tkInvalid
c.tok.literal = ""
if result: rawGetTok(c, c.tok)
proc openFromBuffer(c: var TCfgParser, buf: string) =
initBaseLexerFromBuffer(c, buf)
c.filename = "buffer"
c.state = startState
c.tok.kind = tkInvalid
c.tok.literal = ""
rawGetTok(c, c.tok)
proc close(c: var TCfgParser) =
deinitBaseLexer(c)
lexbase.close(c)
proc getColumn(c: TCfgParser): int =
result = getColNumber(c, c.bufPos)
@ -285,6 +278,7 @@ proc rawGetTok(c: var TCfgParser, tok: var TToken) =
of '=':
tok.kind = tkEquals
inc(c.bufpos)
tok.literal = "="
of '-':
inc(c.bufPos)
if c.buf[c.bufPos] == '-': inc(c.bufPos)
@ -312,6 +306,7 @@ proc rawGetTok(c: var TCfgParser, tok: var TToken) =
getString(c, tok, false)
of lexbase.EndOfFile:
tok.kind = tkEof
tok.literal = "[EOF]"
else: getSymbol(c, tok)
proc errorStr(c: TCfgParser, msg: string): string =

View file

@ -1,7 +1,7 @@
#
#
# Nimrod's Runtime Library
# (c) Copyright 2006 Andreas Rumpf
# (c) Copyright 2008 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
@ -20,12 +20,16 @@
## ALL types are named the same as in the POSIX standard except that they start
## with 'T' or 'P' (if they are pointers) and without the '_t' prefix to be
## consistent with Nimrod conventions. If an identifier is a Nimrod keyword
## the `identifier` notation is used.
## the \`identifier\` notation is used.
##
## This library relies on the header files of your C compiler. Thus the
## resulting C code will just include <XYZ.h> and *not* define the
## symbols declared here.
const
hasSpawnH = defined(linux)
hasAioH = defined(linux)
const
C_IRUSR* = 0c000400 ## Read by owner.
C_IWUSR* = 0c000200 ## Write by owner.
@ -55,28 +59,19 @@ const
MM_NULLACT* = nil
MM_NULLTAG* = nil
STDERR_FILENO = 2 ## File number of stderr;
STDIN_FILENO = 0 ## File number of stdin;
STDOUT_FILENO = 1 ## File number of stdout;
STDERR_FILENO* = 2 ## File number of stderr;
STDIN_FILENO* = 0 ## File number of stdin;
STDOUT_FILENO* = 1 ## File number of stdout;
type
Taiocb* {.importc: "struct aiocb", header: "<aio.h>", final.} = object
aio_fildes*: cint ## File descriptor.
aio_offset*: TOff ## File offset.
aio_buf*: pointer ## Location of buffer.
aio_nbytes*: int ## Length of transfer.
aio_reqprio*: cint ## Request priority offset.
aio_sigevent*: TSigEvent ## Signal number and value.
aio_lio_opcode: cint ## Operation to be performed.
TDIR* {.importc: "DIR", header: "<dirent.h>", final.} = object
TDIR* {.importc: "DIR", header: "<dirent.h>", final, pure.} = object
## A type representing a directory stream.
Tdirent* {.importc: "struct dirent", header: "<dirent.h>", final.} = object
Tdirent* {.importc: "struct dirent", header: "<dirent.h>", final, pure.} = object
d_ino*: TIno ## File serial number.
d_name*: array [0..255, char] ## Name of entry.
Tflock* {.importc: "flock", header: "<fcntl>", final.} = object
Tflock* {.importc: "flock", header: "<fcntl.h>", final, pure.} = object
l_type*: cshort ## Type of lock; F_RDLCK, F_WRLCK, F_UNLCK.
l_whence*: cshort ## Flag for starting offset.
l_start*: Toff ## Relative offset in bytes.
@ -84,12 +79,12 @@ type
l_pid*: TPid ## Process ID of the process holding the lock;
## returned with F_GETLK.
Tfenv* {.importc: "fenv_t", header: "<fenv.h>", final.} =
Tfenv* {.importc: "fenv_t", header: "<fenv.h>", final, pure.} =
object ## Represents the entire floating-point environment. The
## floating-point environment refers collectively to any
## floating-point status flags and control modes supported
## by the implementation.
Tfexcept* {.importc: "fexcept_t", header: "<fenv.h>", final.} =
Tfexcept* {.importc: "fexcept_t", header: "<fenv.h>", final, pure.} =
object ## Represents the floating-point status flags collectively,
## including any status the implementation associates with the
## flags. A floating-point status flag is a system variable
@ -100,25 +95,25 @@ type
## whose value may be set by the user to affect the subsequent
## behavior of floating-point arithmetic.
TFTW* {.importc: "struct FTW", header: "<ftw.h>", final.} = object
TFTW* {.importc: "struct FTW", header: "<ftw.h>", final, pure.} = object
base*: cint
level*: cint
TGlob* {.importc: "glob_t", header: "<glob.h>", final.} = object
TGlob* {.importc: "glob_t", header: "<glob.h>", final, pure.} = object
gl_pathc*: int ## Count of paths matched by pattern.
gl_pathv*: ptr cstring ## Pointer to a list of matched pathnames.
gl_offs*: int ## Slots to reserve at the beginning of gl_pathv.
TGroup* {.importc: "struct group", header: "<grp.h>", final.} = object
TGroup* {.importc: "struct group", header: "<grp.h>", final, pure.} = object
gr_name*: cstring ## The name of the group.
gr_gid*: TGid ## Numerical group ID.
gr_mem*: cstringArray ## Pointer to a null-terminated array of character
## pointers to member names.
Ticonv* {.importc: "iconv_t", header: "<iconv.h>", final.} =
Ticonv* {.importc: "iconv_t", header: "<iconv.h>", final, pure.} =
object ## Identifies the conversion from one codeset to another.
Tlconv* {.importc: "struct lconv", header: "<locale.h>", final.} = object
Tlconv* {.importc: "struct lconv", header: "<locale.h>", final, pure.} = object
currency_symbol*: cstring
decimal_point*: cstring
frac_digits*: char
@ -144,14 +139,14 @@ type
p_sign_posn*: char
thousands_sep*: cstring
TMqd* {.importc: "mqd_t", header: "<mqueue.h>", final.} = object
TMqAttr* {.importc: "struct mq_attr", header: "<mqueue.h>", final.} = object
TMqd* {.importc: "mqd_t", header: "<mqueue.h>", final, pure.} = object
TMqAttr* {.importc: "struct mq_attr", header: "<mqueue.h>", final, pure.} = object
mq_flags*: int ## Message queue flags.
mq_maxmsg*: int ## Maximum number of messages.
mq_msgsize*: int ## Maximum message size.
mq_curmsgs*: int ## Number of messages currently queued.
TPasswd* {.importc: "struct passwd", header: "<pwd.h>", final.} = object
TPasswd* {.importc: "struct passwd", header: "<pwd.h>", final, pure.} = object
pw_name*: cstring ## User's login name.
pw_uid*: TUid ## Numerical user ID.
pw_gid*: TGid ## Numerical group ID.
@ -198,7 +193,7 @@ type
Tuid* {.importc: "uid_t", header: "<sys/types.h>".} = int
Tuseconds* {.importc: "useconds_t", header: "<sys/types.h>".} = int
Tutsname* {.importc: "struct utsname", header: "<sys/utsname.h>", final.} = object
Tutsname* {.importc: "struct utsname", header: "<sys/utsname.h>", final, pure.} = object
sysname*, ## Name of this implementation of the operating system.
nodename*, ## Name of this node within the communications
## network to which this node is attached, if any.
@ -207,15 +202,15 @@ type
machine*: array [0..255, char] ## Name of the hardware type on which the
## system is running.
TSem* {.importc: "sem_t", header: "<semaphore.h>", final.} = object
Tipc_perm* {.importc: "struct ipc_perm", header: "<sys/ipc.h>", final.} = object
TSem* {.importc: "sem_t", header: "<semaphore.h>", final, pure.} = object
Tipc_perm* {.importc: "struct ipc_perm", header: "<sys/ipc.h>", final, pure.} = object
uid*: tuid ## Owner's user ID.
gid*: tgid ## Owner's group ID.
cuid*: Tuid ## Creator's user ID.
cgid*: Tgid ## Creator's group ID.
mode*: TMode ## Read/write permission.
TStat* {.importc: "struct stat", header: "<sys/stat.h>", final.} = object
TStat* {.importc: "struct stat", header: "<sys/stat.h>", final, pure.} = object
st_dev*: TDev ## Device ID of device containing file.
st_ino*: TIno ## File serial number.
st_mode*: TMode ## Mode of file (see below).
@ -239,7 +234,7 @@ type
st_blocks*: Tblkcnt ## Number of blocks allocated for this object.
TStatvfs* {.importc: "struct statvfs", header: "<sys/statvfs.h>", final.} = object
TStatvfs* {.importc: "struct statvfs", header: "<sys/statvfs.h>", final, pure.} = object
f_bsize*: int ## File system block size.
f_frsize*: int ## Fundamental file system block size.
f_blocks*: Tfsblkcnt ## Total number of blocks on file system in units of f_frsize.
@ -255,10 +250,10 @@ type
f_namemax*: int ## Maximum filename length.
Tposix_typed_mem_info* {.importc: "struct posix_typed_mem_info",
header: "<sys/mman.h>", final.} = object
header: "<sys/mman.h>", final, pure.} = object
posix_tmi_length*: int
Ttm* {.importc: "struct tm", header: "<time.h>", final.} = object
Ttm* {.importc: "struct tm", header: "<time.h>", final, pure.} = object
tm_sec*: cint ## Seconds [0,60].
tm_min*: cint ## Minutes [0,59].
tm_hour*: cint ## Hour [0,23].
@ -268,10 +263,10 @@ type
tm_wday*: cint ## Day of week [0,6] (Sunday =0).
tm_yday*: cint ## Day of year [0,365].
tm_isdst*: cint ## Daylight Savings flag.
Ttimespec* {.importc: "struct timespec", header: "<time.h>", final.} = object
Ttimespec* {.importc: "struct timespec", header: "<time.h>", final, pure.} = object
tv_sec*: Ttime ## Seconds.
tv_nsec*: int ## Nanoseconds.
titimerspec* {.importc: "struct itimerspec", header: "<time.h>", final.} = object
titimerspec* {.importc: "struct itimerspec", header: "<time.h>", final, pure.} = object
it_interval*: ttimespec ## Timer period.
it_value*: ttimespec ## Timer expiration.
@ -279,19 +274,19 @@ type
## Possibly volatile-qualified integer type of an object that can be
## accessed as an atomic entity, even in the presence of asynchronous
## interrupts.
Tsigset* {.importc: "sigset_t", header: "<signal.h>", final.} = object
Tsigset* {.importc: "sigset_t", header: "<signal.h>", final, pure.} = object
TsigEvent* {.importc: "struct sigevent", header: "<signal.h>", final.} = object
TsigEvent* {.importc: "struct sigevent", header: "<signal.h>", final, pure.} = object
sigev_notify*: cint ## Notification type.
sigev_signo*: cint ## Signal number.
sigev_value*: Tsigval ## Signal value.
sigev_notify_function*: proc (x: TSigval) {.noconv.} ## Notification function.
sigev_notify_attributes*: ptr Tpthreadattr ## Notification attributes.
TsigVal* {.importc: "union sigval", header: "<signal.h>", final.} = object
TsigVal* {.importc: "union sigval", header: "<signal.h>", final, pure.} = object
sival_ptr*: pointer ## pointer signal value;
## integer signal value not defined!
TSigaction* {.importc: "struct sigaction", header: "<signal.h>", final.} = object
TSigaction* {.importc: "struct sigaction", header: "<signal.h>", final, pure.} = object
sa_handler*: proc (x: cint) {.noconv.} ## Pointer to a signal-catching
## function or one of the macros
## SIG_IGN or SIG_DFL.
@ -300,16 +295,16 @@ type
sa_flags*: cint ## Special flags.
sa_sigaction*: proc (x: cint, y: var TSigInfo, z: pointer) {.noconv.}
TStack* {.importc: "stack_t", header: "<signal.h>", final.} = object
TStack* {.importc: "stack_t", header: "<signal.h>", final, pure.} = object
ss_sp*: pointer ## Stack base or pointer.
ss_size*: int ## Stack size.
ss_flags*: cint ## Flags.
TSigStack* {.importc: "struct sigstack", header: "<signal.h>", final.} = object
TSigStack* {.importc: "struct sigstack", header: "<signal.h>", final, pure.} = object
ss_onstack*: cint ## Non-zero when signal stack is in use.
ss_sp*: pointer ## Signal stack pointer.
TsigInfo* {.importc: "siginfo_t", header: "<signal.h>", final.} = object
TsigInfo* {.importc: "siginfo_t", header: "<signal.h>", final, pure.} = object
si_signo*: cint ## Signal number.
si_code*: cint ## Signal code.
si_errno*: cint ## If non-zero, an errno value associated with
@ -324,7 +319,7 @@ type
Tnl_item* {.importc: "nl_item", header: "<nl_types.h>".} = cint
Tnl_catd* {.importc: "nl_catd", header: "<nl_types.h>".} = cint
Tsched_param* {.importc: "struct sched_param", header: "<sched.h>", final.} = object
Tsched_param* {.importc: "struct sched_param", header: "<sched.h>", final, pure.} = object
sched_priority*: cint
sched_ss_low_priority*: cint ## Low scheduling priority for
## sporadic server.
@ -334,15 +329,12 @@ type
sched_ss_max_repl*: cint ## Maximum pending replenishments for
## sporadic server.
Ttimeval* {.importc: "struct timeval", header: "<sys/select.h>", final.} = object
Ttimeval* {.importc: "struct timeval", header: "<sys/select.h>", final, pure.} = object
tv_sec*: ttime ## Seconds.
tv_usec*: tsuseconds ## Microseconds.
Tfd_set* {.importc: "struct fd_set", header: "<sys/select.h>", final.} = object
Tposix_spawnattr* {.importc: "posix_spawnattr_t", header: "<spawn.h>".} = cint
Tposix_spawn_file_actions* {.importc: "posix_spawn_file_actions_t", header: "<spawn.h>".} = cint
Tmcontext* {.importc: "mcontext_t", header: "<ucontext.h>", final.} = object
Tucontext* {.importc: "ucontext_t", header: "<ucontext.h>", final.} = object
Tfd_set* {.importc: "struct fd_set", header: "<sys/select.h>", final, pure.} = object
Tmcontext* {.importc: "mcontext_t", header: "<ucontext.h>", final, pure.} = object
Tucontext* {.importc: "ucontext_t", header: "<ucontext.h>", final, pure.} = object
uc_link*: ptr Tucontext ## Pointer to the context that is resumed
## when this context returns.
uc_sigmask*: Tsigset ## The set of signals that are blocked when this
@ -351,35 +343,52 @@ type
uc_mcontext*: Tmcontext ## A machine-specific representation of the saved
## context.
when hasAioH:
type
Taiocb* {.importc: "struct aiocb", header: "<aio.h>", final, pure.} = object
aio_fildes*: cint ## File descriptor.
aio_offset*: TOff ## File offset.
aio_buf*: pointer ## Location of buffer.
aio_nbytes*: int ## Length of transfer.
aio_reqprio*: cint ## Request priority offset.
aio_sigevent*: TSigEvent ## Signal number and value.
aio_lio_opcode: cint ## Operation to be performed.
when hasSpawnH:
type
Tposix_spawnattr* {.importc: "posix_spawnattr_t", header: "<spawn.h>".} = cint
Tposix_spawn_file_actions* {.importc: "posix_spawn_file_actions_t", header: "<spawn.h>".} = cint
# Constants as variables:
var
AIO_ALLDONE* {.importc, header: "<aio.h>".}: cint
## A return value indicating that none of the requested operations
## could be canceled since they are already complete.
AIO_CANCELED* {.importc, header: "<aio.h>".}: cint
## A return value indicating that all requested operations have
## been canceled.
AIO_NOTCANCELED* {.importc, header: "<aio.h>".}: cint
## A return value indicating that some of the requested operations could
## not be canceled since they are in progress.
LIO_NOP* {.importc, header: "<aio.h>".}: cint
## A lio_listio() element operation option indicating that no transfer is
## requested.
LIO_NOWAIT* {.importc, header: "<aio.h>".}: cint
## A lio_listio() synchronization operation indicating that the calling
## thread is to continue execution while the lio_listio() operation is
## being performed, and no notification is given when the operation is
## complete.
LIO_READ* {.importc, header: "<aio.h>".}: cint
## A lio_listio() element operation option requesting a read.
LIO_WAIT* {.importc, header: "<aio.h>".}: cint
## A lio_listio() synchronization operation indicating that the calling
## thread is to suspend until the lio_listio() operation is complete.
LIO_WRITE* {.importc, header: "<aio.h>".}: cint
## A lio_listio() element operation option requesting a write.
when hasAioH:
var
AIO_ALLDONE* {.importc, header: "<aio.h>".}: cint
## A return value indicating that none of the requested operations
## could be canceled since they are already complete.
AIO_CANCELED* {.importc, header: "<aio.h>".}: cint
## A return value indicating that all requested operations have
## been canceled.
AIO_NOTCANCELED* {.importc, header: "<aio.h>".}: cint
## A return value indicating that some of the requested operations could
## not be canceled since they are in progress.
LIO_NOP* {.importc, header: "<aio.h>".}: cint
## A lio_listio() element operation option indicating that no transfer is
## requested.
LIO_NOWAIT* {.importc, header: "<aio.h>".}: cint
## A lio_listio() synchronization operation indicating that the calling
## thread is to continue execution while the lio_listio() operation is
## being performed, and no notification is given when the operation is
## complete.
LIO_READ* {.importc, header: "<aio.h>".}: cint
## A lio_listio() element operation option requesting a read.
LIO_WAIT* {.importc, header: "<aio.h>".}: cint
## A lio_listio() synchronization operation indicating that the calling
## thread is to suspend until the lio_listio() operation is complete.
LIO_WRITE* {.importc, header: "<aio.h>".}: cint
## A lio_listio() element operation option requesting a write.
var
RTLD_LAZY* {.importc, header: "<dlfcn.h>".}: cint
## Relocations are performed at an implementation-defined time.
RTLD_NOW* {.importc, header: "<dlfcn.h>".}: cint
@ -1246,23 +1255,30 @@ var
SCHED_OTHER* {.importc, header: "<sched.h>".}: cint
FD_SETSIZE* {.importc, header: "<sys/select.h>".}: cint
POSIX_SPAWN_RESETIDS* {.importc, header: "<spawn.h>".}: cint
POSIX_SPAWN_SETPGROUP* {.importc, header: "<spawn.h>".}: cint
POSIX_SPAWN_SETSCHEDPARAM* {.importc, header: "<spawn.h>".}: cint
POSIX_SPAWN_SETSCHEDULER* {.importc, header: "<spawn.h>".}: cint
POSIX_SPAWN_SETSIGDEF* {.importc, header: "<spawn.h>".}: cint
POSIX_SPAWN_SETSIGMASK* {.importc, header: "<spawn.h>".}: cint
SEEK_SET* {.importc, header: "<unistd.h>".}: cint
SEEK_CUR* {.importc, header: "<unistd.h>".}: cint
SEEK_END* {.importc, header: "<unistd.h>".}: cint
proc aio_cancel*(a1: cint, a2: ptr Taiocb): cint {.importc, header: "<aio.h>".}
proc aio_error*(a1: ptr Taiocb): cint {.importc, header: "<aio.h>".}
proc aio_fsync*(a1: cint, a2: ptr Taiocb): cint {.importc, header: "<aio.h>".}
proc aio_read*(a1: ptr Taiocb): cint {.importc, header: "<aio.h>".}
proc aio_return*(a1: ptr Taiocb): int {.importc, header: "<aio.h>".}
proc aio_suspend*(a1: ptr ptr Taiocb, a2: cint, a3: ptr ttimespec): cint {.
importc, header: "<aio.h>".}
proc aio_write*(a1: ptr Taiocb): cint {.importc, header: "<aio.h>".}
proc lio_listio*(a1: cint, a2: ptr ptr Taiocb, a3: cint,
a4: ptr Tsigevent): cint {.importc, header: "<aio.h>".}
when hasSpawnh:
var
POSIX_SPAWN_RESETIDS* {.importc, header: "<spawn.h>".}: cint
POSIX_SPAWN_SETPGROUP* {.importc, header: "<spawn.h>".}: cint
POSIX_SPAWN_SETSCHEDPARAM* {.importc, header: "<spawn.h>".}: cint
POSIX_SPAWN_SETSCHEDULER* {.importc, header: "<spawn.h>".}: cint
POSIX_SPAWN_SETSIGDEF* {.importc, header: "<spawn.h>".}: cint
POSIX_SPAWN_SETSIGMASK* {.importc, header: "<spawn.h>".}: cint
when hasAioH:
proc aio_cancel*(a1: cint, a2: ptr Taiocb): cint {.importc, header: "<aio.h>".}
proc aio_error*(a1: ptr Taiocb): cint {.importc, header: "<aio.h>".}
proc aio_fsync*(a1: cint, a2: ptr Taiocb): cint {.importc, header: "<aio.h>".}
proc aio_read*(a1: ptr Taiocb): cint {.importc, header: "<aio.h>".}
proc aio_return*(a1: ptr Taiocb): int {.importc, header: "<aio.h>".}
proc aio_suspend*(a1: ptr ptr Taiocb, a2: cint, a3: ptr ttimespec): cint {.
importc, header: "<aio.h>".}
proc aio_write*(a1: ptr Taiocb): cint {.importc, header: "<aio.h>".}
proc lio_listio*(a1: cint, a2: ptr ptr Taiocb, a3: cint,
a4: ptr Tsigevent): cint {.importc, header: "<aio.h>".}
# arpa/inet.h
proc htonl*(a1: int32): int32 {.importc, header: "<arpa/inet.h>".}
@ -1371,8 +1387,8 @@ proc mq_unlink*(a1: cstring): cint {.importc, header: "<mqueue.h>".}
proc getpwnam*(a1: cstring): ptr TPasswd {.importc, header: "<pwd.h>".}
proc getpwuid*(a1: Tuid): ptr TPasswd {.importc, header: "<pwd.h>".}
proc getpwnam_r(a1: cstring, a2: ptr Tpasswd, a3: cstring, a4: int,
a5: ptr ptr Tpasswd): cint {.importc, header: "<pwd.h>".}
proc getpwnam_r*(a1: cstring, a2: ptr Tpasswd, a3: cstring, a4: int,
a5: ptr ptr Tpasswd): cint {.importc, header: "<pwd.h>".}
proc getpwuid_r*(a1: Tuid, a2: ptr Tpasswd, a3: cstring,
a4: int, a5: ptr ptr Tpasswd): cint {.importc, header: "<pwd.h>".}
proc endpwent*() {.importc, header: "<pwd.h>".}
@ -1771,46 +1787,47 @@ proc pselect*(a1: cint, a2, a3, a4: var Tfd_set, a5: var ttimespec,
proc select*(a1: cint, a2, a3, a4: var Tfd_set, a5: var ttimeval): cint {.
importc, header: "<sys/select.h>".}
proc posix_spawn*(a1: var tpid, a2: cstring,
a3: var Tposix_spawn_file_actions,
a4: var Tposix_spawnattr, a5, a6: cstringArray): cint {.importc, header: "<spawn.h>".}
proc posix_spawn_file_actions_addclose*(a1: var tposix_spawn_file_actions,
a2: cint): cint {.importc, header: "<spawn.h>".}
proc posix_spawn_file_actions_adddup2*(a1: var tposix_spawn_file_actions,
a2, a3: cint): cint {.importc, header: "<spawn.h>".}
proc posix_spawn_file_actions_addopen*(a1: var tposix_spawn_file_actions,
a2: cint, a3: cstring, a4: cint, a5: tmode): cint {.importc, header: "<spawn.h>".}
proc posix_spawn_file_actions_destroy*(a1: var tposix_spawn_file_actions): cint {.importc, header: "<spawn.h>".}
proc posix_spawn_file_actions_init*(a1: var tposix_spawn_file_actions): cint {.importc, header: "<spawn.h>".}
proc posix_spawnattr_destroy*(a1: var tposix_spawnattr): cint {.importc, header: "<spawn.h>".}
proc posix_spawnattr_getsigdefault*(a1: var tposix_spawnattr,
a2: var Tsigset): cint {.importc, header: "<spawn.h>".}
proc posix_spawnattr_getflags*(a1: var tposix_spawnattr,
a2: var cshort): cint {.importc, header: "<spawn.h>".}
proc posix_spawnattr_getpgroup*(a1: var tposix_spawnattr,
a2: var tpid): cint {.importc, header: "<spawn.h>".}
proc posix_spawnattr_getschedparam*(a1: var tposix_spawnattr,
a2: var tsched_param): cint {.importc, header: "<spawn.h>".}
proc posix_spawnattr_getschedpolicy*(a1: var tposix_spawnattr,
a2: var cint): cint {.importc, header: "<spawn.h>".}
proc posix_spawnattr_getsigmask*(a1: var tposix_spawnattr,
a2: var tsigset): cint {.importc, header: "<spawn.h>".}
proc posix_spawnattr_init*(a1: var tposix_spawnattr): cint {.importc, header: "<spawn.h>".}
proc posix_spawnattr_setsigdefault*(a1: var tposix_spawnattr,
a2: var tsigset): cint {.importc, header: "<spawn.h>".}
proc posix_spawnattr_setflags*(a1: var tposix_spawnattr, a2: cshort): cint {.importc, header: "<spawn.h>".}
proc posix_spawnattr_setpgroup*(a1: var tposix_spawnattr, a2: tpid): cint {.importc, header: "<spawn.h>".}
proc posix_spawnattr_setschedparam*(a1: var tposix_spawnattr,
a2: var tsched_param): cint {.importc, header: "<spawn.h>".}
proc posix_spawnattr_setschedpolicy*(a1: var tposix_spawnattr, a2: cint): cint {.importc, header: "<spawn.h>".}
proc posix_spawnattr_setsigmask*(a1: var tposix_spawnattr,
a2: var tsigset): cint {.importc, header: "<spawn.h>".}
proc posix_spawnp*(a1: var tpid, a2: cstring,
a3: var tposix_spawn_file_actions,
a4: var tposix_spawnattr,
a5, a6: cstringArray): cint {.importc, header: "<spawn.h>".}
when hasSpawnH:
proc posix_spawn*(a1: var tpid, a2: cstring,
a3: var Tposix_spawn_file_actions,
a4: var Tposix_spawnattr, a5, a6: cstringArray): cint {.importc, header: "<spawn.h>".}
proc posix_spawn_file_actions_addclose*(a1: var tposix_spawn_file_actions,
a2: cint): cint {.importc, header: "<spawn.h>".}
proc posix_spawn_file_actions_adddup2*(a1: var tposix_spawn_file_actions,
a2, a3: cint): cint {.importc, header: "<spawn.h>".}
proc posix_spawn_file_actions_addopen*(a1: var tposix_spawn_file_actions,
a2: cint, a3: cstring, a4: cint, a5: tmode): cint {.importc, header: "<spawn.h>".}
proc posix_spawn_file_actions_destroy*(a1: var tposix_spawn_file_actions): cint {.importc, header: "<spawn.h>".}
proc posix_spawn_file_actions_init*(a1: var tposix_spawn_file_actions): cint {.importc, header: "<spawn.h>".}
proc posix_spawnattr_destroy*(a1: var tposix_spawnattr): cint {.importc, header: "<spawn.h>".}
proc posix_spawnattr_getsigdefault*(a1: var tposix_spawnattr,
a2: var Tsigset): cint {.importc, header: "<spawn.h>".}
proc posix_spawnattr_getflags*(a1: var tposix_spawnattr,
a2: var cshort): cint {.importc, header: "<spawn.h>".}
proc posix_spawnattr_getpgroup*(a1: var tposix_spawnattr,
a2: var tpid): cint {.importc, header: "<spawn.h>".}
proc posix_spawnattr_getschedparam*(a1: var tposix_spawnattr,
a2: var tsched_param): cint {.importc, header: "<spawn.h>".}
proc posix_spawnattr_getschedpolicy*(a1: var tposix_spawnattr,
a2: var cint): cint {.importc, header: "<spawn.h>".}
proc posix_spawnattr_getsigmask*(a1: var tposix_spawnattr,
a2: var tsigset): cint {.importc, header: "<spawn.h>".}
proc posix_spawnattr_init*(a1: var tposix_spawnattr): cint {.importc, header: "<spawn.h>".}
proc posix_spawnattr_setsigdefault*(a1: var tposix_spawnattr,
a2: var tsigset): cint {.importc, header: "<spawn.h>".}
proc posix_spawnattr_setflags*(a1: var tposix_spawnattr, a2: cshort): cint {.importc, header: "<spawn.h>".}
proc posix_spawnattr_setpgroup*(a1: var tposix_spawnattr, a2: tpid): cint {.importc, header: "<spawn.h>".}
proc posix_spawnattr_setschedparam*(a1: var tposix_spawnattr,
a2: var tsched_param): cint {.importc, header: "<spawn.h>".}
proc posix_spawnattr_setschedpolicy*(a1: var tposix_spawnattr, a2: cint): cint {.importc, header: "<spawn.h>".}
proc posix_spawnattr_setsigmask*(a1: var tposix_spawnattr,
a2: var tsigset): cint {.importc, header: "<spawn.h>".}
proc posix_spawnp*(a1: var tpid, a2: cstring,
a3: var tposix_spawn_file_actions,
a4: var tposix_spawnattr,
a5, a6: cstringArray): cint {.importc, header: "<spawn.h>".}
proc getcontext*(a1: var Tucontext): cint {.importc, header: "<ucontext.h>".}
proc makecontext*(a1: var Tucontext, a4: proc (){.noconv.}, a3: cint) {.varargs, importc, header: "<ucontext.h>".}

File diff suppressed because it is too large Load diff

View file

@ -85,7 +85,7 @@ proc reprSetAux(result: var string, p: pointer, typ: PNimType) =
else:
var a = cast[pbyteArray](p)
for i in 0 .. typ.size*8-1:
if (a[i div 8] and (1 shl (i mod 8))) != 0:
if (ze(a[i div 8]) and (1 shl (i mod 8))) != 0:
if elemCounter > 0: add result, ", "
addSetElem(result, i+typ.node.len, typ.base)
inc(elemCounter)

View file

@ -24,36 +24,36 @@ include cntbits
proc unionSets(res: var TNimSet, a, b: TNimSet, len: int) {.
compilerproc, inline.} =
for i in countup(0, len-1): res[i] = toU8(ze(a[i]) or ze(b[i]))
for i in countup(0, len-1): res[i] = a[i] or b[i]
proc diffSets(res: var TNimSet, a, b: TNimSet, len: int) {.
compilerproc, inline.} =
for i in countup(0, len-1): res[i] = toU8(ze(a[i]) and not ze(b[i]))
for i in countup(0, len-1): res[i] = a[i] and not b[i]
proc intersectSets(res: var TNimSet, a, b: TNimSet, len: int) {.
compilerproc, inline.} =
for i in countup(0, len-1): res[i] = toU8(ze(a[i]) and ze(b[i]))
for i in countup(0, len-1): res[i] = a[i] and b[i]
proc symdiffSets(res: var TNimSet, a, b: TNimSet, len: int) {.
compilerproc, inline.} =
for i in countup(0, len-1): res[i] = toU8(ze(a[i]) xor ze(b[i]))
for i in countup(0, len-1): res[i] = a[i] xor b[i]
proc containsSets(a, b: TNimSet, len: int): bool {.compilerproc, inline.} =
# s1 <= s2 ?
for i in countup(0, len-1):
if (ze(a[i]) and not ze(b[i])) != 0: return false
if (a[i] and not b[i]) != 0'i8: return false
return true
proc containsSubsets(a, b: TNimSet, len: int): bool {.compilerproc, inline.} =
# s1 < s2 ?
result = false # assume they are equal
for i in countup(0, len-1):
if (ze(a[i]) and not ze(b[i])) != 0: return false
if ze(a[i]) != ze(b[i]): result = true # they are not equal
if (a[i]) and not b[i]) != 0'i32: return false
if a[i] != b[i]: result = true # they are not equal
proc equalSets(a, b: TNimSet, len: int): bool {.compilerproc, inline.} =
for i in countup(0, len-1):
if ze(a[i]) != ze(b[i]): return false
if a[i] != b[i]: return false
return true
proc cardSet(s: TNimSet, len: int): int {.compilerproc, inline.} =
@ -68,7 +68,7 @@ proc inSet(s: TNimSet, elem: int): bool {.compilerproc, inline.} =
return (s[elem /% WORD_SIZE] and (1 shl (elem %% WORD_SIZE))) != 0
proc inclSets(s: var TNimSet, e: int) {.compilerproc, inline.} =
s[e /% WORD_SIZE] = toU8(s[e /% WORD_SIZE] or (1 shl (e %% WORD_SIZE)))
s[e /% WORD_SIZE] = s[e /% WORD_SIZE] or toU8(1 shl (e %% WORD_SIZE))
proc inclRange(s: var TNimSet, first, last: int) {.compilerproc.} =
# not very fast, but it is seldom used
@ -80,8 +80,8 @@ proc smallInclRange(s: var int, first, last: int) {.compilerproc.} =
s = s or (1 shl (i %% sizeof(int)*8))
proc exclSets(s: var TNimSet, e: int) {.compilerproc, inline.} =
s[e /% WORD_SIZE] = toU8(s[e /% WORD_SIZE] and
not (1 shl (e %% WORD_SIZE)))
s[e /% WORD_SIZE] = s[e /% WORD_SIZE] and
not toU8(1 shl (e %% WORD_SIZE))
proc smallContainsSubsets(a, b: int): bool {.compilerProc, inline.} =
# not used by new code generator

View file

@ -1,19 +0,0 @@
# Handle small allocations efficiently
# We allocate and manage memory by pages. All objects within a page belong to
# the same type. Thus, we safe the type field. Minimum requested block is
# 8 bytes. Alignment is 8 bytes.
type
TChunk {.pure.} = object
kind: TChunkKind
prev, next: ptr TChunk
TSmallChunk = object of TChunk # all objects of the same size
typ: PNimType
free: int
data: array [0.., int]
proc allocSmall(typ: PNimType): pointer =

View file

@ -11,11 +11,11 @@
## from strings to strings. Supports a case-sensitive, case-insensitive and
## style-insensitive mode. An efficient string substitution operator ``%``
## for the string table is also provided.
import
import
os, hashes, strutils
type
type
TStringTableMode* = enum # describes the tables operation mode
modeCaseSensitive, # the table is case sensitive
modeCaseInsensitive, # the table is case insensitive
@ -29,16 +29,16 @@ type
PStringTable* = ref TStringTable ## use this type to declare string tables
proc newStringTable*(keyValuePairs: openarray[string],
proc newStringTable*(keyValuePairs: openarray[string],
mode: TStringTableMode = modeCaseSensitive): PStringTable
## creates a new string table with given key value pairs.
## Example::
## var mytab = newStringTable("key1", "val1", "key2", "val2",
## var mytab = newStringTable("key1", "val1", "key2", "val2",
## modeCaseInsensitive)
proc newStringTable*(mode: TStringTableMode = modeCaseSensitive): PStringTable
## creates a new string table that is empty.
proc `[]=`*(t: PStringTable, key, val: string)
## puts a (key, value)-pair into `t`.
@ -54,13 +54,13 @@ proc len*(t: PStringTable): int =
## returns the number of keys in `t`.
result = t.counter
iterator pairs*(t: PStringTable): tuple[key, value: string] =
iterator pairs*(t: PStringTable): tuple[key, value: string] =
## iterates over any (key, value) pair in the table `t`.
for h in 0..high(t.data):
if not isNil(t.data[h].key):
yield (t.data[h].key, t.data[h].val)
type
type
TFormatFlag* = enum # flags for the `%` operator
useEnvironment, # use environment variable if the ``$key``
# is not found in the table
@ -75,136 +75,131 @@ proc `%`*(f: string, t: PStringTable, flags: set[TFormatFlag] = {}): string
# implementation
const
const
growthFactor = 2
startSize = 64
proc newStringTable(mode: TStringTableMode = modeCaseSensitive): PStringTable =
proc newStringTable(mode: TStringTableMode = modeCaseSensitive): PStringTable =
new(result)
result.mode = mode
result.counter = 0
result.data = []
setlen(result.data, startSize) # XXX
newSeq(result.data, startSize)
proc newStringTable(keyValuePairs: openarray[string],
mode: TStringTableMode = modeCaseSensitive): PStringTable =
proc newStringTable(keyValuePairs: openarray[string],
mode: TStringTableMode = modeCaseSensitive): PStringTable =
result = newStringTable(mode)
var i = 0
while i < high(keyValuePairs):
while i < high(keyValuePairs):
result[keyValuePairs[i]] = keyValuePairs[i + 1]
inc(i, 2)
proc myhash(t: PStringTable, key: string): THash =
proc myhash(t: PStringTable, key: string): THash =
case t.mode
of modeCaseSensitive: result = hashes.hash(key)
of modeCaseInsensitive: result = hashes.hashIgnoreCase(key)
of modeStyleInsensitive: result = hashes.hashIgnoreStyle(key)
proc myCmp(t: PStringTable, a, b: string): bool =
proc myCmp(t: PStringTable, a, b: string): bool =
case t.mode
of modeCaseSensitive: result = cmp(a, b) == 0
of modeCaseInsensitive: result = cmpIgnoreCase(a, b) == 0
of modeStyleInsensitive: result = cmpIgnoreStyle(a, b) == 0
proc mustRehash(length, counter: int): bool =
proc mustRehash(length, counter: int): bool =
assert(length > counter)
result = (length * 2 < counter * 3) or (length - counter < 4)
const
EmptySeq = []
proc nextTry(h, maxHash: THash): THash =
proc nextTry(h, maxHash: THash): THash =
result = ((5 * h) + 1) and maxHash # For any initial h in range(maxHash), repeating that maxHash times
# generates each int in range(maxHash) exactly once (see any text on
# random-number generation for proof).
proc RawGet(t: PStringTable, key: string): int =
proc RawGet(t: PStringTable, key: string): int =
var h: THash
h = myhash(t, key) and high(t.data) # start with real hash value
while not isNil(t.data[h].key):
if mycmp(t, t.data[h].key, key):
while not isNil(t.data[h].key):
if mycmp(t, t.data[h].key, key):
return h
h = nextTry(h, high(t.data))
result = - 1
proc `[]`(t: PStringTable, key: string): string =
proc `[]`(t: PStringTable, key: string): string =
var index: int
index = RawGet(t, key)
if index >= 0: result = t.data[index].val
else: result = ""
proc hasKey(t: PStringTable, key: string): bool =
proc hasKey(t: PStringTable, key: string): bool =
result = rawGet(t, key) >= 0
proc RawInsert(t: PStringTable, data: var TKeyValuePairSeq, key, val: string) =
proc RawInsert(t: PStringTable, data: var TKeyValuePairSeq, key, val: string) =
var h: THash
h = myhash(t, key) and high(data)
while not isNil(data[h].key):
while not isNil(data[h].key):
h = nextTry(h, high(data))
data[h].key = key
data[h].val = val
proc Enlarge(t: PStringTable) =
proc Enlarge(t: PStringTable) =
var n: TKeyValuePairSeq
n = emptySeq
setlen(n, len(t.data) * growthFactor)
for i in countup(0, high(t.data)):
newSeq(n, len(t.data) * growthFactor)
for i in countup(0, high(t.data)):
if not isNil(t.data[i].key): RawInsert(t, n, t.data[i].key, t.data[i].val)
swap(t.data, n)
proc `[]=`(t: PStringTable, key, val: string) =
proc `[]=`(t: PStringTable, key, val: string) =
var index = RawGet(t, key)
if index >= 0:
if index >= 0:
t.data[index].val = val
else:
else:
if mustRehash(len(t.data), t.counter): Enlarge(t)
RawInsert(t, t.data, key, val)
inc(t.counter)
proc RaiseFormatException(s: string) =
proc RaiseFormatException(s: string) =
var e: ref EInvalidValue
new(e)
e.msg = "format string: key not found: " & s
raise e
proc getValue(t: PStringTable, flags: set[TFormatFlag], key: string): string =
proc getValue(t: PStringTable, flags: set[TFormatFlag], key: string): string =
if hasKey(t, key): return t[key]
if useEnvironment in flags: result = os.getEnv(key)
else: result = ""
if (result == ""):
if (result == ""):
if useKey in flags: result = '$' & key
elif not (useEmpty in flags): raiseFormatException(key)
proc `%`(f: string, t: PStringTable, flags: set[TFormatFlag] = {}): string =
const
proc `%`(f: string, t: PStringTable, flags: set[TFormatFlag] = {}): string =
const
PatternChars = {'a'..'z', 'A'..'Z', '0'..'9', '_', '\x80'..'\xFF'}
var
var
i, j: int
key: string
result = ""
i = strStart
while i <= len(f) + strStart - 1:
if f[i] == '$':
while i <= len(f) + strStart - 1:
if f[i] == '$':
case f[i + 1]
of '$':
of '$':
add(result, '$')
inc(i, 2)
of '{':
of '{':
j = i + 1
while (j <= len(f) + strStart - 1) and (f[j] != '}'): inc(j)
key = copy(f, i + 2, j - 1)
result = result & getValue(t, flags, key)
i = j + 1
of 'a'..'z', 'A'..'Z', '\x80'..'\xFF', '_':
of 'a'..'z', 'A'..'Z', '\x80'..'\xFF', '_':
j = i + 1
while (j <= len(f) + strStart - 1) and (f[j] in PatternChars): inc(j)
key = copy(f, i+1, j - 1)
result = result & getValue(t, flags, key)
i = j
else:
else:
add(result, f[i])
inc(i)
else:
else:
add(result, f[i])
inc(i)

View file

@ -24,6 +24,7 @@ template newException(exceptn, message: expr): expr =
e.msg = message
e
type
TCharSet* = set[char] # for compability for Nim
@ -73,6 +74,9 @@ proc findSubStr*(sub: char, s: string, start: int = 0): int {.noSideEffect.}
proc replaceStr*(s, sub, by: string): string {.noSideEffect.}
## Replaces `sub` in `s` by the string `by`.
proc replaceStr*(s: string, sub, by: char): string {.noSideEffect.}
## optimized version for characters.
proc deleteStr*(s: var string, first, last: int)
## Deletes in `s` the characters at position `first`..`last`. This modifies
## `s` itself, it does not return a copy.
@ -113,6 +117,43 @@ iterator split*(s: string, seps: set[char] = Whitespace): string =
while last < len(s) and s[last] not_in seps: inc(last) # BUGFIX!
yield copy(s, first, last-1)
iterator splitLines*(s: string): string =
## Splits the string `s` into its containing lines. Each newline
## combination (CR, LF, CR-LF) is supported. The result strings contain
## no trailing ``\n``.
##
## Example::
##
## for line in lines("\nthis\nis\nan\n\nexample\n"):
## writeln(stdout, line)
##
## Results in::
##
## ""
## "this"
## "is"
## "an"
## ""
## "example"
## ""
var first = 0
var last = 0
while true:
while s[last] notin {'\0', '\c', '\l'}: inc(last)
yield copy(s, first, last-1)
# skip newlines:
if s[last] == '\l': inc(last)
elif s[last] == '\c':
inc(last)
if s[last] == '\l': inc(last)
else: break # was '\0'
first = last
proc splitLinesSeq*(s: string): seq[string] {.noSideEffect.} =
## The same as `split`, but is a proc that returns a sequence of substrings.
result = @[]
for line in splitLines(s): add(result, line)
proc splitSeq*(s: string, seps: set[char] = Whitespace): seq[string] {.
noSideEffect.}
## The same as `split`, but is a proc that returns a sequence of substrings.
@ -159,7 +200,8 @@ proc ParseBiggestInt*(s: string): biggestInt {.noSideEffect.}
proc ParseFloat*(s: string): float {.noSideEffect.}
## Parses a decimal floating point value contained in `s`. If `s` is not
## a valid floating point number, `EInvalidValue` is raised.
## a valid floating point number, `EInvalidValue` is raised. ``NAN``,
## ``INF``, ``-INF`` are also supported (case insensitive comparison).
# XXX: make this biggestfloat.
# the stringify and format operators:
@ -344,7 +386,7 @@ proc cmpIgnoreStyle(a, b: string): int =
# ---------- splitting -----------------------------------------------------
proc splitSeq(s: string, seps: set[char]): seq[string] =
result = []
result = @[]
for sub in split(s, seps): add result, sub
# ---------------------------------------------------------------------------
@ -469,6 +511,14 @@ proc replaceStr(s, sub, by: string): string =
# copy the rest:
add result, copy(s, i)
proc replaceStr(s: string, sub, by: char): string =
result = newString(s.len)
var i = 0
while i < s.len:
if s[i] == sub: result[i] = by
else: result[i] = s[i]
inc(i)
proc deleteStr(s: var string, first, last: int) =
# example: "abc___uvwxyz\0" (___ is to be deleted)
# --> first == 3, last == 5
@ -489,7 +539,7 @@ proc toHex(x: BiggestInt, len: int): string =
shift: BiggestInt
result = newString(len)
for j in countdown(len-1, 0):
result[j] = HexChars[toU32(x shr shift) and 0xF]
result[j] = HexChars[toU32(x shr shift) and 0xF'i32]
shift = shift + 4
{.push overflowChecks: on.}
@ -552,6 +602,16 @@ proc ParseFloat(s: string): float =
elif s[i] == '-':
sign = -1.0
inc(i)
if s[i] == 'N' or s[i] == 'n':
if s[i+1] == 'A' or s[i+1] == 'a':
if s[i+2] == 'N' or s[i+2] == 'n':
if s[i+3] == '\0': return NaN
raise newException(EInvalidValue, "invalid float: " & s)
if s[i] == 'I' or s[i] == 'i':
if s[i+1] == 'N' or s[i+1] == 'n':
if s[i+2] == 'F' or s[i+2] == 'f':
if s[i+3] == '\0': return Inf*sign
raise newException(EInvalidValue, "invalid float: " & s)
while s[i] in {'0'..'9'}:
# Read integer part
flags = flags or 1
@ -572,7 +632,7 @@ proc ParseFloat(s: string): float =
result = result / hd # this complicated way preserves precision
# Again, read integer and fractional part
if flags == 0:
raise newException(EInvalidValue, "invalid float:" & s)
raise newException(EInvalidValue, "invalid float: " & s)
# Exponent?
if s[i] in {'e', 'E'}:
inc(i)
@ -624,4 +684,113 @@ proc toBin*(x: BiggestInt, len: int): string =
shift = shift + 1
mask = mask shl 1
proc escape*(s: string, prefix, suffix = "\""): string =
## Escapes a string `s`. This does these operations (at the same time):
## * replaces any ``\`` by ``\\``
## * replaces any ``'`` by ``\'``
## * replaces any ``"`` by ``\"``
## * replaces any other character in the set ``{'\0'..'\31', '\128'..'\255'}``
## by ``\xHH`` where ``HH`` is its hexadecimal value.
## The procedure has been designed so that its output is usable for many
## different common syntaxes. The resulting string is prefixed with
## ``prefix`` and suffixed with ``suffix``. Both may be empty strings.
result = prefix
for c in items(s):
case c
of '\0'..'\31', '\128'..'\255':
add(result, '\\')
add(result, toHex(ord(c), 2))
of '\\': add(result, "\\\\")
of '\'': add(result, "\\'")
of '\"': add(result, "\\\"")
else: add(result, c)
add(result, suffix)
proc editDistance*(a, b: string): int =
## returns the edit distance between `s` and `t`. This uses the Levenshtein
## distance algorithm with only a linear memory overhead. This implementation
## is highly optimized!
var len1 = a.len
var len2 = b.len
if len1 > len2:
# make `b` the longer string
return editDistance(b, a)
# strip common prefix:
var s = 0
while a[s] == b[s] and a[s] != '\0':
inc(s)
dec(len1)
dec(len2)
# strip common suffix:
while len1 > 0 and len2 > 0 and a[s+len1-1] == b[s+len2-1]:
dec(len1)
dec(len2)
# trivial cases:
if len1 == 0: return len2
if len2 == 0: return len1
# another special case:
if len1 == 1:
for j in s..len2-1:
if a[s] == b[j]: return len2 - 1
return len2
inc(len1)
inc(len2)
var half = len1 shr 1
# initalize first row:
#var row = cast[ptr array[0..high(int) div 8, int]](alloc(len2 * sizeof(int)))
var row: seq[int]
newSeq(row, len2)
var e = s + len2 - 1 # end marker
for i in 1..len2 - half - 1: row[i] = i
row[0] = len1 - half - 1
for i in 1 .. len1 - 1:
var char1 = a[i + s - 1]
var char2p: int
var D, x: int
var p: int
if i >= len1 - half:
# skip the upper triangle:
var offset = i - len1 + half
char2p = offset
p = offset
var c3 = row[p] + ord(char1 != b[s + char2p])
inc(p)
inc(char2p)
x = row[p] + 1
D = x
if x > c3: x = c3
row[p] = x
inc(p)
else:
p = 1
char2p = 0
D = i
x = i
if i <= half + 1:
# skip the lower triangle:
e = len2 + i - half - 2
# main:
while p <= e:
dec(D)
var c3 = D + ord(char1 != b[char2p + s])
inc(char2p)
inc(x)
if x > c3: x = c3
D = row[p] + 1
if x > D: x = D
row[p] = x
inc(p)
# lower triangle sentinel:
if i <= half:
dec(D)
var c3 = D + ord(char1 != b[char2p + s])
inc(x)
if x > c3: x = c3
row[p] = x
result = row[e]
#dealloc(row)
{.pop.}

View file

@ -19,7 +19,7 @@
proc fputs(c: cstring, f: TFile) {.importc: "fputs", noDecl.}
proc fgets(c: cstring, n: int, f: TFile): cstring {.importc: "fgets", noDecl.}
proc fgetc(stream: TFile): int {.importc: "fgetc", nodecl.}
proc ungetc(c: int, f: TFile) {.importc: "ungetc", nodecl.}
proc ungetc(c: cint, f: TFile) {.importc: "ungetc", nodecl.}
proc putc(c: Char, stream: TFile) {.importc: "putc", nodecl.}
proc fprintf(f: TFile, frmt: CString) {.importc: "fprintf", nodecl, varargs.}
proc strlen(c: cstring): int {.importc: "strlen", nodecl.}
@ -33,7 +33,7 @@ var
IOFBF {.importc: "_IOFBF", nodecl.}: cint
IONBF {.importc: "_IONBF", nodecl.}: cint
proc rawReadLine(f: TFile, result: var string) {.noStatic.} =
proc rawReadLine(f: TFile, result: var string) =
# of course this could be optimized a bit; but IO is slow anyway...
# and it was difficult to get this CORRECT with Ansi C's methods
var
@ -41,13 +41,11 @@ proc rawReadLine(f: TFile, result: var string) {.noStatic.} =
setLen(result, 0) # reuse the buffer!
while True:
c = fgetc(f)
if c < 0:
result = nil
break # EOF
if c == 10: break # LF
if c == 13: # CR
if c < 0'i32: break # EOF
if c == 10'i32: break # LF
if c == 13'i32: # CR
c = fgetc(f) # is the next char LF?
if c != 10: ungetc(c, f) # no, put the character back
if c != 10'i32: ungetc(c, f) # no, put the character back
break
add result, chr(int(c))
@ -72,7 +70,7 @@ proc readFile(filename: string): string =
proc write(f: TFile, s: string) = fputs(s, f)
proc write(f: TFile, i: int) = fprintf(f, "%ld", i)
proc write(f: TFile, b: bool) =
proc write(f: TFile, b: bool) =
if b: write(f, "true")
else: write(f, "false")
proc write(f: TFile, r: float) = fprintf(f, "%g", r)
@ -117,11 +115,18 @@ proc OpenFile(f: var TFile, filename: string,
result = (p != nil)
f = cast[TFile](p)
if bufSize > 0:
if setvbuf(f, nil, IOFBF, bufSize) != 0:
if setvbuf(f, nil, IOFBF, bufSize) != 0'i32:
raise newException(EOutOfMemory, "out of memory")
elif bufSize == 0:
discard setvbuf(f, nil, IONBF, 0)
proc fdopen(filehandle: TFileHandle, mode: cstring): TFile {.
importc: pccHack & "fdopen", header: "<stdio.h>".}
proc openFile(f: var TFile, filehandle: TFileHandle, mode: TFileMode): bool =
f = fdopen(filehandle, FormatOpen[mode])
result = f != nil
# C routine that is used here:
proc fread(buf: Pointer, size, n: int, f: TFile): int {.
importc: "fread", noDecl.}

View file

@ -16,53 +16,55 @@
# the programmer may not want
type
TStringDesc {.importc, nodecl, final.} = object
len, space: int # len and space without counting the terminating zero
data: array[0..0, char] # for the '\0' character
# len and space without counting the terminating zero:
NimStringDesc {.compilerproc, final.} = object of TGenericSeq
data: array[0..100_000_000, char] # for the '\0' character
mstring {.importc: "string".} = ptr TStringDesc
NimString = ptr NimStringDesc
# implementation:
proc resize(old: int): int {.inline.} =
if old <= 0: return 1
if old <= 0: return 4
elif old < 65536: return old * 2
else: return old * 3 div 2 # for large arrays * 3/2 is better
proc cmpStrings(a, b: mstring): int {.inline, compilerProc.} =
proc cmpStrings(a, b: NimString): int {.inline, compilerProc.} =
if a == b: return 0
if a == nil: return -1
if b == nil: return 1
return c_strcmp(a.data, b.data)
proc eqStrings(a, b: mstring): bool {.inline, compilerProc.} =
proc eqStrings(a, b: NimString): bool {.inline, compilerProc.} =
if a == b: return true
if a == nil or b == nil: return false
return a.len == b.len and
c_memcmp(a.data, b.data, a.len * sizeof(char)) == 0
c_memcmp(a.data, b.data, a.len * sizeof(char)) == 0'i32
proc rawNewString(space: int): mstring {.compilerProc.} =
result = cast[mstring](newObj(addr(strDesc), sizeof(TStringDesc) +
space * sizeof(char)))
result.len = 0
result.space = space
result.data[0] = '\0'
proc rawNewString(space: int): NimString {.compilerProc.} =
var s = space
if s < 8: s = 7
result = cast[NimString](newObj(addr(strDesc), sizeof(TGenericSeq) +
(s+1) * sizeof(char)))
#result.len = 0
result.space = s
#result.data[0] = '\0'
proc mnewString(len: int): mstring {.exportc.} =
proc mnewString(len: int): NimString {.exportc.} =
result = rawNewString(len)
result.len = len
result.data[len] = '\0'
#result.data[len] = '\0'
proc toNimStr(str: CString, len: int): mstring {.compilerProc.} =
proc toNimStr(str: CString, len: int): NimString {.compilerProc.} =
result = rawNewString(len)
result.len = len
c_memcpy(result.data, str, (len+1) * sizeof(Char))
result.data[len] = '\0' # IO.readline relies on this!
proc cstrToNimstr(str: CString): mstring {.compilerProc.} =
proc cstrToNimstr(str: CString): NimString {.compilerProc.} =
return toNimstr(str, c_strlen(str))
proc copyString(src: mstring): mstring {.compilerProc.} =
proc copyString(src: NimString): NimString {.compilerProc.} =
if src == nil: return nil
result = rawNewString(src.space)
result.len = src.len
@ -71,9 +73,7 @@ proc copyString(src: mstring): mstring {.compilerProc.} =
proc hashString(s: string): int {.compilerproc.} =
# the compiler needs exactly the same hash function!
# this used to be used for efficient generation of string case statements
var
h: int
h = 0
var h = 0
for i in 0..Len(s)-1:
h = h +% Ord(s[i])
h = h +% h shl 10
@ -91,8 +91,7 @@ proc hashString(s: string): int {.compilerproc.} =
# setLength(var s: string, newlen: int)
# {.extern: "setLengthStr", noDecl, noSideEffect.}
proc copyStrLast(s: mstring, start, last: int): mstring {.exportc.} =
proc copyStrLast(s: NimString, start, last: int): NimString {.exportc.} =
var
len: int
if start >= s.len: return mnewString(0) # BUGFIX
@ -105,15 +104,19 @@ proc copyStrLast(s: mstring, start, last: int): mstring {.exportc.} =
c_memcpy(result.data, addr(s.data[start]), len * sizeof(Char))
result.data[len] = '\0'
proc copyStr(s: mstring, start: int): mstring {.exportc.} =
proc copyStr(s: NimString, start: int): NimString {.exportc.} =
return copyStrLast(s, start, s.len-1)
proc addChar(s: mstring, c: char): mstring {.compilerProc.} =
proc addChar(s: NimString, c: char): NimString {.compilerProc.} =
result = s
if result.len >= result.space:
result.space = resize(result.space)
result = cast[mstring](growObj(result,
sizeof(TStringDesc) + result.space * sizeof(char)))
result = cast[NimString](growObj(result,
sizeof(TGenericSeq) + (result.space+1) * sizeof(char)))
#var space = resize(result.space)
#result = rawNewString(space)
#copyMem(result, s, s.len * sizeof(char) + sizeof(TGenericSeq))
#result.space = space
result.data[result.len] = c
result.data[result.len+1] = '\0'
inc(result.len)
@ -149,27 +152,28 @@ proc addChar(s: mstring, c: char): mstring {.compilerProc.} =
# <generated C code>
# s = rawNewString(0);
proc resizeString(dest: mstring, addlen: int): mstring {.compilerproc.} =
proc resizeString(dest: NimString, addlen: int): NimString {.compilerproc.} =
if dest.len + addLen + 1 <= dest.space: # BUGFIX: this is horrible!
result = dest
else: # slow path:
var
sp = max(resize(dest.space), dest.len + addLen + 1)
result = cast[mstring](growObj(dest, sizeof(TStringDesc) +
sp * sizeof(Char)))
# DO NOT UPDATE LEN YET: dest.len = newLen
var sp = max(resize(dest.space), dest.len + addLen + 1)
result = cast[NimString](growObj(dest, sizeof(TGenericSeq) +
(sp+1) * sizeof(Char)))
result.space = sp
#result = rawNewString(sp)
#copyMem(result, dest, dest.len * sizeof(char) + sizeof(TGenericSeq))
# DO NOT UPDATE LEN YET: dest.len = newLen
proc appendString(dest, src: mstring) {.compilerproc, inline.} =
proc appendString(dest, src: NimString) {.compilerproc, inline.} =
c_memcpy(addr(dest.data[dest.len]), src.data, (src.len + 1) * sizeof(Char))
inc(dest.len, src.len)
proc appendChar(dest: mstring, c: char) {.compilerproc, inline.} =
proc appendChar(dest: NimString, c: char) {.compilerproc, inline.} =
dest.data[dest.len] = c
dest.data[dest.len+1] = '\0'
inc(dest.len)
proc setLengthStr(s: mstring, newLen: int): mstring {.compilerProc.} =
proc setLengthStr(s: NimString, newLen: int): NimString {.compilerProc.} =
var n = max(newLen, 0)
if n <= s.space:
result = s
@ -187,37 +191,54 @@ proc incrSeq(seq: PGenericSeq, elemSize: int): PGenericSeq {.compilerProc.} =
# add seq x generates:
# seq = incrSeq(seq, sizeof(x));
# seq[seq->len-1] = x;
result = seq
if result.len >= result.space:
var
s: TAddress
result.space = resize(result.space)
result = cast[PGenericSeq](growObj(result, elemSize * result.space +
GenericSeqSize))
# set new elements to zero:
s = cast[TAddress](result)
zeroMem(cast[pointer](s + GenericSeqSize + (result.len * elemSize)),
(result.space - result.len) * elemSize)
# for i in len .. space-1:
# seq->data[i] = 0
inc(result.len)
when false:
# broken version:
result = seq
if result.len >= result.space:
var s = resize(result.space)
result = cast[PGenericSeq](newSeq(extGetCellType(seq), s))
genericSeqAssign(result, seq, XXX)
#copyMem(result, seq, seq.len * elemSize + GenericSeqSize)
inc(result.len)
else:
result = seq
if result.len >= result.space:
result.space = resize(result.space)
result = cast[PGenericSeq](growObj(result, elemSize * result.space +
GenericSeqSize))
# set new elements to zero:
#var s = cast[TAddress](result)
#zeroMem(cast[pointer](s + GenericSeqSize + (result.len * elemSize)),
# (result.space - result.len) * elemSize)
# for i in len .. space-1:
# seq->data[i] = 0
inc(result.len)
proc setLengthSeq(seq: PGenericSeq, elemSize, newLen: int): PGenericSeq {.
compilerProc.} =
result = seq
if result.space < newLen:
var
s: TAddress
result.space = max(resize(result.space), newLen)
result = cast[PGenericSeq](growObj(result, elemSize * result.space +
GenericSeqSize))
# set new elements to zero (needed for GC):
s = cast[TAddress](result)
zeroMem(cast[pointer](s + GenericSeqSize + (result.len * elemSize)),
(result.space - result.len) * elemSize)
# Else: We could decref references, if we had type information here :-(
# However, this does not happen often
result.len = newLen
when false:
# broken version:
result = seq
if result.space < newLen:
var s = max(resize(result.space), newLen)
result = cast[PGenericSeq](newSeq(extGetCellType(seq), s))
result.len = newLen
else:
result = seq
if result.space < newLen:
result.space = max(resize(result.space), newLen)
result = cast[PGenericSeq](growObj(result, elemSize * result.space +
GenericSeqSize))
elif newLen < result.len:
# we need to decref here, otherwise the GC leaks!
for i in newLen..result.len-1:
forAllChildrenAux(cast[pointer](cast[TAddress](result) +%
GenericSeqSize +% (i*%elemSize)),
extGetCellType(result).base, waZctDecRef)
# and set the memory to nil:
zeroMem(cast[pointer](cast[TAddress](result) +% GenericSeqSize +%
(newLen*%elemSize)), (result.len-%newLen) *% elemSize)
result.len = newLen
# --------------- other string routines ----------------------------------
proc nimIntToStr(x: int): string {.compilerproc.} =

View file

@ -19,6 +19,30 @@
{.push hints: off.}
type
int* {.magic: Int.} ## default integer type; bitwidth depends on
## architecture, but is always the same as a pointer
int8* {.magic: Int8.} ## signed 8 bit integer type
int16* {.magic: Int16.} ## signed 16 bit integer type
int32* {.magic: Int32.} ## signed 32 bit integer type
int64* {.magic: Int64.} ## signed 64 bit integer type
float* {.magic: Float.} ## default floating point type
float32* {.magic: Float32.} ## 32 bit floating point type
float64* {.magic: Float64.} ## 64 bit floating point type
type # we need to start a new type section here, so that ``0`` can have a type
bool* {.magic: Bool.} = enum ## built-in boolean type
false = 0, true = 1
type
char* {.magic: Char.} ## built-in 8 bit character type (unsigned)
string* {.magic: String.} ## built-in string type
cstring* {.magic: Cstring.} ## built-in cstring (*compatible string*) type
pointer* {.magic: Pointer.} ## built-in pointer type
TAnyEnum {.magic: AnyEnum.}
type
`nil` {.magic: "Nil".}
proc defined*[T] (x: T): bool {.magic: "Defined", noSideEffect.}
## Special comile-time procedure that checks whether `x` is
## defined. `x` has to be an identifier or a qualified identifier.
@ -30,23 +54,6 @@ proc defined*[T] (x: T): bool {.magic: "Defined", noSideEffect.}
## # provide our own toUpper proc here, because strutils is
## # missing it.
when defined(macosX):
{.define: useDL.}
when defined(linux):
{.define: useDL.}
when defined(unix):
# This may seem strange, but we cannot write "when not defined"
# here, because ``not`` has not been defined yet.
{.hint: "unix is defined".}
else:
{.define: useDL.}
{.hint: "unix is not defined".}
# use Doug Lea's memory allocator; you can undefine it if you
# know that your system uses this library anyway (smaller code) or if
# your malloc() doesn't suck (most systems use it anyway)
# these require compiler magic:
proc `not` *(x: bool): bool {.magic: "Not", noSideEffect.}
## Boolean not; returns true iff ``x == false``.
@ -98,9 +105,10 @@ type
## is an int type ranging from one to the maximum value
## of an int. This type is often useful for documentation and debugging.
TObject* = object ## the root of Nimrod's object hierarchy. Objects should
## inherit from TObject or one of its descendants. However,
## objects that have no ancestor are allowed.
TObject* {.exportc: "TNimObject".} =
object ## the root of Nimrod's object hierarchy. Objects should
## inherit from TObject or one of its descendants. However,
## objects that have no ancestor are allowed.
PObject* = ref TObject ## reference to TObject
E_Base* {.compilerproc.} = object of TObject ## base exception class;
@ -206,8 +214,14 @@ proc dec*[T](x: var T, y = 1) {.magic: "Dec".}
## exist, ``EOutOfRange`` is raised or a compile time error occurs. This is a
## short notation for: ``x = pred(x, y)``.
proc newSeq*[T](s: var seq[T], len: int) {.magic: "NewSeq".}
## creates a new sequence of type ``seq[T]`` with length ``len``.
## This is equivalent to ``s = []; setlen(s, len)``, but more
## efficient since no relocation is needed.
proc len*[T](x: openarray[T]): int {.magic: "LengthOpenArray", noSideEffect.}
proc len*(x: string): int {.magic: "LengthStr", noSideEffect.}
proc len*(x: cstring): int {.magic: "LengthStr", noSideEffect.}
proc len*[I, T](x: array[I, T]): int {.magic: "LengthArray", noSideEffect.}
proc len*[T](x: seq[T]): int {.magic: "LengthSeq", noSideEffect.}
## returns the length of an array, a sequence or a string.
@ -236,79 +250,241 @@ proc chr*(u: range[0..255]): char {.magic: "Chr", noSideEffect.}
# --------------------------------------------------------------------------
# built-in operators
proc ze*(x: int8): int {.magic: "Ze8ToI", noSideEffect.}
## zero extends a smaller integer type to ``int``. This treats `x` as
## unsigned.
proc ze*(x: int16): int {.magic: "Ze16ToI", noSideEffect.}
## zero extends a smaller integer type to ``int``. This treats `x` as
## unsigned.
proc ze64*(x: int8): int64 {.magic: "Ze8ToI64", noSideEffect.}
## zero extends a smaller integer type to ``int64``. This treats `x` as
## unsigned.
proc ze64*(x: int16): int64 {.magic: "Ze16ToI64", noSideEffect.}
## zero extends a smaller integer type to ``int64``. This treats `x` as
## unsigned.
proc ze64*(x: int32): int64 {.magic: "Ze32ToI64", noSideEffect.}
## zero extends a smaller integer type to ``int64``. This treats `x` as
## unsigned.
proc ze64*(x: int): int64 {.magic: "ZeIToI64", noDecl, noSideEffect.}
## zero extends a smaller integer type to ``int64``. This treats `x` as
## unsigned. Does nothing if the size of an ``int`` is the same as ``int64``.
## (This is the case on 64 bit processors.)
proc toU8*(x: int): int8 {.magic: "ToU8", noSideEffect.}
## treats `x` as unsigned and converts it to a byte by taking the last 8 bits
## from `x`.
proc toU16*(x: int): int16 {.magic: "ToU16", noSideEffect.}
## treats `x` as unsigned and converts it to an ``int16`` by taking the last
## 16 bits from `x`.
proc toU32*(x: int64): int32 {.magic: "ToU32", noSideEffect.}
## treats `x` as unsigned and converts it to an ``int32`` by taking the
## last 32 bits from `x`.
# integer calculations:
proc `+` *(x: int): int {.magic: "UnaryPlusI", noSideEffect.}
proc `+` *(x: int8): int8 {.magic: "UnaryPlusI", noSideEffect.}
proc `+` *(x: int16): int16 {.magic: "UnaryPlusI", noSideEffect.}
proc `+` *(x: int32): int32 {.magic: "UnaryPlusI", noSideEffect.}
proc `+` *(x: int64): int64 {.magic: "UnaryPlusI64", noSideEffect.}
## Unary `+` operator for an integer. Has no effect.
proc `-` *(x: int): int {.magic: "UnaryMinusI", noSideEffect.}
proc `-` *(x: int8): int8 {.magic: "UnaryMinusI", noSideEffect.}
proc `-` *(x: int16): int16 {.magic: "UnaryMinusI", noSideEffect.}
proc `-` *(x: int32): int32 {.magic: "UnaryMinusI", noSideEffect.}
proc `-` *(x: int64): int64 {.magic: "UnaryMinusI64", noSideEffect.}
## Unary `-` operator for an integer. Negates `x`.
proc `not` *(x: int): int {.magic: "BitnotI", noSideEffect.}
proc `not` *(x: int8): int8 {.magic: "BitnotI", noSideEffect.}
proc `not` *(x: int16): int16 {.magic: "BitnotI", noSideEffect.}
proc `not` *(x: int32): int32 {.magic: "BitnotI", noSideEffect.}
proc `not` *(x: int64): int64 {.magic: "BitnotI64", noSideEffect.}
## computes the `bitwise complement` of the integer `x`.
proc `+` *(x, y: int): int {.magic: "AddI", noSideEffect.}
proc `+` *(x, y: int8): int8 {.magic: "AddI", noSideEffect.}
proc `+` *(x, y: int16): int16 {.magic: "AddI", noSideEffect.}
proc `+` *(x, y: int32): int32 {.magic: "AddI", noSideEffect.}
proc `+` *(x, y: int64): int64 {.magic: "AddI64", noSideEffect.}
## Binary `+` operator for an integer.
proc `-` *(x, y: int): int {.magic: "SubI", noSideEffect.}
proc `-` *(x, y: int8): int8 {.magic: "SubI", noSideEffect.}
proc `-` *(x, y: int16): int16 {.magic: "SubI", noSideEffect.}
proc `-` *(x, y: int32): int32 {.magic: "SubI", noSideEffect.}
proc `-` *(x, y: int64): int64 {.magic: "SubI64", noSideEffect.}
## Binary `-` operator for an integer.
proc `*` *(x, y: int): int {.magic: "MulI", noSideEffect.}
proc `*` *(x, y: int8): int8 {.magic: "MulI", noSideEffect.}
proc `*` *(x, y: int16): int16 {.magic: "MulI", noSideEffect.}
proc `*` *(x, y: int32): int32 {.magic: "MulI", noSideEffect.}
proc `*` *(x, y: int64): int64 {.magic: "MulI64", noSideEffect.}
## Binary `*` operator for an integer.
proc `div` *(x, y: int): int {.magic: "DivI", noSideEffect.}
proc `div` *(x, y: int8): int8 {.magic: "DivI", noSideEffect.}
proc `div` *(x, y: int16): int16 {.magic: "DivI", noSideEffect.}
proc `div` *(x, y: int32): int32 {.magic: "DivI", noSideEffect.}
proc `div` *(x, y: int64): int64 {.magic: "DivI64", noSideEffect.}
## computes the integer division. This is roughly the same as
## ``floor(x/y)``.
proc `mod` *(x, y: int): int {.magic: "ModI", noSideEffect.}
proc `mod` *(x, y: int8): int8 {.magic: "ModI", noSideEffect.}
proc `mod` *(x, y: int16): int16 {.magic: "ModI", noSideEffect.}
proc `mod` *(x, y: int32): int32 {.magic: "ModI", noSideEffect.}
proc `mod` *(x, y: int64): int64 {.magic: "ModI64", noSideEffect.}
## computes the integer modulo operation. This is the same as
## ``x - (x div y) * y``.
proc `shr` *(x, y: int): int {.magic: "ShrI", noSideEffect.}
## computes the `shift right` operation of `x` and `y`.
proc `shl` *(x, y: int): int {.magic: "ShlI", noSideEffect.}
## computes the `shift left` operation of `x` and `y`.
proc `and` *(x, y: int): int {.magic: "BitandI", noSideEffect.}
## computes the `bitwise and` of numbers `x` and `y`.
proc `or` *(x, y: int): int {.magic: "BitorI", noSideEffect.}
## computes the `bitwise or` of numbers `x` and `y`.
proc `xor` *(x, y: int): int {.magic: "BitxorI", noSideEffect.}
## computes the `bitwise xor` of numbers `x` and `y`.
proc `==` *(x, y: int): bool {.magic: "EqI", noSideEffect.}
proc `<=` *(x, y: int): bool {.magic: "LeI", noSideEffect.}
proc `<` *(x, y: int): bool {.magic: "LtI", noSideEffect.}
proc abs*(x: int): int {.magic: "AbsI", noSideEffect.}
proc min*(x, y: int): int {.magic: "MinI", noSideEffect.}
proc max*(x, y: int): int {.magic: "MaxI", noSideEffect.}
proc `+` *(x: int64): int64 {.magic: "UnaryPlusI64", noSideEffect.}
proc `-` *(x: int64): int64 {.magic: "UnaryMinusI64", noSideEffect.}
proc `not` *(x: int64): int64 {.magic: "BitnotI64", noSideEffect.}
## computes the `bitwise complement` of the integer `x`.
proc `+` *(x, y: int64): int64 {.magic: "AddI64", noSideEffect.}
## Unary `+` operator for an integer. Has no effect.
proc `-` *(x, y: int64): int64 {.magic: "SubI64", noSideEffect.}
## Unary `-` operator for an int64. Negates `x`.
proc `*` *(x, y: int64): int64 {.magic: "MulI64", noSideEffect.}
proc `div` *(x, y: int64): int64 {.magic: "DivI64", noSideEffect.}
## computes the integer division. This is roughly the same as
## ``floor(x/y)``.
proc `mod` *(x, y: int64): int64 {.magic: "ModI64", noSideEffect.}
## computes the integer modulo operation. This is the same as
## ``x - (x div y) * y``.
proc `shr` *(x, y: int8): int8 {.magic: "ShrI", noSideEffect.}
proc `shr` *(x, y: int16): int16 {.magic: "ShrI", noSideEffect.}
proc `shr` *(x, y: int32): int32 {.magic: "ShrI", noSideEffect.}
proc `shr` *(x, y: int64): int64 {.magic: "ShrI64", noSideEffect.}
## computes the `shift right` operation of `x` and `y`.
proc `shl` *(x, y: int): int {.magic: "ShlI", noSideEffect.}
proc `shl` *(x, y: int8): int8 {.magic: "ShlI", noSideEffect.}
proc `shl` *(x, y: int16): int16 {.magic: "ShlI", noSideEffect.}
proc `shl` *(x, y: int32): int32 {.magic: "ShlI", noSideEffect.}
proc `shl` *(x, y: int64): int64 {.magic: "ShlI64", noSideEffect.}
## computes the `shift left` operation of `x` and `y`.
proc `and` *(x, y: int): int {.magic: "BitandI", noSideEffect.}
proc `and` *(x, y: int8): int8 {.magic: "BitandI", noSideEffect.}
proc `and` *(x, y: int16): int16 {.magic: "BitandI", noSideEffect.}
proc `and` *(x, y: int32): int32 {.magic: "BitandI", noSideEffect.}
proc `and` *(x, y: int64): int64 {.magic: "BitandI64", noSideEffect.}
## computes the `bitwise and` of numbers `x` and `y`.
proc `or` *(x, y: int): int {.magic: "BitorI", noSideEffect.}
proc `or` *(x, y: int8): int8 {.magic: "BitorI", noSideEffect.}
proc `or` *(x, y: int16): int16 {.magic: "BitorI", noSideEffect.}
proc `or` *(x, y: int32): int32 {.magic: "BitorI", noSideEffect.}
proc `or` *(x, y: int64): int64 {.magic: "BitorI64", noSideEffect.}
## computes the `bitwise or` of numbers `x` and `y`.
proc `xor` *(x, y: int): int {.magic: "BitxorI", noSideEffect.}
proc `xor` *(x, y: int8): int8 {.magic: "BitxorI", noSideEffect.}
proc `xor` *(x, y: int16): int16 {.magic: "BitxorI", noSideEffect.}
proc `xor` *(x, y: int32): int32 {.magic: "BitxorI", noSideEffect.}
proc `xor` *(x, y: int64): int64 {.magic: "BitxorI64", noSideEffect.}
## computes the `bitwise xor` of numbers `x` and `y`.
proc `==` *(x, y: int): bool {.magic: "EqI", noSideEffect.}
proc `==` *(x, y: int8): bool {.magic: "EqI", noSideEffect.}
proc `==` *(x, y: int16): bool {.magic: "EqI", noSideEffect.}
proc `==` *(x, y: int32): bool {.magic: "EqI", noSideEffect.}
proc `==` *(x, y: int64): bool {.magic: "EqI64", noSideEffect.}
proc `<=` *(x, y: int64): bool {.magic: "LeI64", noSideEffect.}
proc `<` *(x, y: int64): bool {.magic: "LtI64", noSideEffect.}
proc abs*(x: int64): int64 {.magic: "AbsI64", noSideEffect.}
proc min*(x, y: int64): int64 {.magic: "MinI64", noSideEffect.}
proc max*(x, y: int64): int64 {.magic: "MaxI64", noSideEffect.}
## Compares two integers for equality.
# same for floating point:
proc `<=` *(x, y: int): bool {.magic: "LeI", noSideEffect.}
proc `<=` *(x, y: int8): bool {.magic: "LeI", noSideEffect.}
proc `<=` *(x, y: int16): bool {.magic: "LeI", noSideEffect.}
proc `<=` *(x, y: int32): bool {.magic: "LeI", noSideEffect.}
proc `<=` *(x, y: int64): bool {.magic: "LeI64", noSideEffect.}
## Returns true iff `x` is less than or equal to `y`.
proc `<` *(x, y: int): bool {.magic: "LtI", noSideEffect.}
proc `<` *(x, y: int8): bool {.magic: "LtI", noSideEffect.}
proc `<` *(x, y: int16): bool {.magic: "LtI", noSideEffect.}
proc `<` *(x, y: int32): bool {.magic: "LtI", noSideEffect.}
proc `<` *(x, y: int64): bool {.magic: "LtI64", noSideEffect.}
## Returns true iff `x` is less than `y`.
proc abs*(x: int): int {.magic: "AbsI", noSideEffect.}
proc abs*(x: int8): int8 {.magic: "AbsI", noSideEffect.}
proc abs*(x: int16): int16 {.magic: "AbsI", noSideEffect.}
proc abs*(x: int32): int32 {.magic: "AbsI", noSideEffect.}
proc abs*(x: int64): int64 {.magic: "AbsI64", noSideEffect.}
## returns the absolute value of `x`. If `x` is ``low(x)`` (that is
## -MININT for its type), an overflow exception is thrown (if overflow
## checking is turned on).
proc min*(x, y: int): int {.magic: "MinI", noSideEffect.}
proc min*(x, y: int8): int8 {.magic: "MinI", noSideEffect.}
proc min*(x, y: int16): int16 {.magic: "MinI", noSideEffect.}
proc min*(x, y: int32): int32 {.magic: "MinI", noSideEffect.}
proc min*(x, y: int64): int64 {.magic: "MinI64", noSideEffect.}
## The minimum value of two integers.
proc max*(x, y: int): int {.magic: "MaxI", noSideEffect.}
proc max*(x, y: int8): int8 {.magic: "MaxI", noSideEffect.}
proc max*(x, y: int16): int16 {.magic: "MaxI", noSideEffect.}
proc max*(x, y: int32): int32 {.magic: "MaxI", noSideEffect.}
proc max*(x, y: int64): int64 {.magic: "MaxI64", noSideEffect.}
## The maximum value of two integers.
proc `+%` *(x, y: int): int {.magic: "AddU", noSideEffect.}
proc `+%` *(x, y: int8): int8 {.magic: "AddU", noSideEffect.}
proc `+%` *(x, y: int16): int16 {.magic: "AddU", noSideEffect.}
proc `+%` *(x, y: int32): int32 {.magic: "AddU", noSideEffect.}
proc `+%` *(x, y: int64): int64 {.magic: "AddU64", noSideEffect.}
## treats `x` and `y` as unsigned and adds them. The result is truncated to
## fit into the result. This implements modulo arithmetic. No overflow
## errors are possible.
proc `-%` *(x, y: int): int {.magic: "SubU", noSideEffect.}
proc `-%` *(x, y: int8): int8 {.magic: "SubU", noSideEffect.}
proc `-%` *(x, y: int16): int16 {.magic: "SubU", noSideEffect.}
proc `-%` *(x, y: int32): int32 {.magic: "SubU", noSideEffect.}
proc `-%` *(x, y: int64): int64 {.magic: "SubU64", noSideEffect.}
## treats `x` and `y` as unsigned and subtracts them. The result is
## truncated to fit into the result. This implements modulo arithmetic.
## No overflow errors are possible.
proc `*%` *(x, y: int): int {.magic: "MulU", noSideEffect.}
proc `*%` *(x, y: int8): int8 {.magic: "MulU", noSideEffect.}
proc `*%` *(x, y: int16): int16 {.magic: "MulU", noSideEffect.}
proc `*%` *(x, y: int32): int32 {.magic: "MulU", noSideEffect.}
proc `*%` *(x, y: int64): int64 {.magic: "MulU64", noSideEffect.}
## treats `x` and `y` as unsigned and multiplies them. The result is
## truncated to fit into the result. This implements modulo arithmetic.
## No overflow errors are possible.
proc `/%` *(x, y: int): int {.magic: "DivU", noSideEffect.}
proc `/%` *(x, y: int8): int8 {.magic: "DivU", noSideEffect.}
proc `/%` *(x, y: int16): int16 {.magic: "DivU", noSideEffect.}
proc `/%` *(x, y: int32): int32 {.magic: "DivU", noSideEffect.}
proc `/%` *(x, y: int64): int64 {.magic: "DivU64", noSideEffect.}
## treats `x` and `y` as unsigned and divides them. The result is
## truncated to fit into the result. This implements modulo arithmetic.
## No overflow errors are possible.
proc `%%` *(x, y: int): int {.magic: "ModU", noSideEffect.}
proc `%%` *(x, y: int8): int8 {.magic: "ModU", noSideEffect.}
proc `%%` *(x, y: int16): int16 {.magic: "ModU", noSideEffect.}
proc `%%` *(x, y: int32): int32 {.magic: "ModU", noSideEffect.}
proc `%%` *(x, y: int64): int64 {.magic: "ModU64", noSideEffect.}
## treats `x` and `y` as unsigned and compute the modulo of `x` and `y`.
## The result is truncated to fit into the result.
## This implements modulo arithmetic.
## No overflow errors are possible.
proc `<=%` *(x, y: int): bool {.magic: "LeU", noSideEffect.}
proc `<=%` *(x, y: int8): bool {.magic: "LeU", noSideEffect.}
proc `<=%` *(x, y: int16): bool {.magic: "LeU", noSideEffect.}
proc `<=%` *(x, y: int32): bool {.magic: "LeU", noSideEffect.}
proc `<=%` *(x, y: int64): bool {.magic: "LeU64", noSideEffect.}
## treats `x` and `y` as unsigned and compares them.
## Returns true iff ``unsigned(x) <= unsigned(y)``.
proc `<%` *(x, y: int): bool {.magic: "LtU", noSideEffect.}
proc `<%` *(x, y: int8): bool {.magic: "LtU", noSideEffect.}
proc `<%` *(x, y: int16): bool {.magic: "LtU", noSideEffect.}
proc `<%` *(x, y: int32): bool {.magic: "LtU", noSideEffect.}
proc `<%` *(x, y: int64): bool {.magic: "LtU64", noSideEffect.}
## treats `x` and `y` as unsigned and compares them.
## Returns true iff ``unsigned(x) < unsigned(y)``.
# floating point operations:
proc `+` *(x: float): float {.magic: "UnaryPlusF64", noSideEffect.}
proc `-` *(x: float): float {.magic: "UnaryMinusF64", noSideEffect.}
proc `+` *(x, y: float): float {.magic: "AddF64", noSideEffect.}
@ -423,11 +599,21 @@ proc cmp*[T](x, y: T): int =
proc cmp*(x, y: string): int {.noSideEffect.}
## Compare proc for strings. More efficient than the generic version.
proc `@` * [IDX, T](a: array[IDX, T]): seq[T] {.
magic: "ArrToSeq", nosideeffect.}
## turns an array into a sequence. This most often useful for constructing
## sequences with the array constructor: ``@[1, 2, 3]`` has the type
## ``seq[int]``, while ``[1, 2, 3]`` has the type ``array[0..2, int]``.
# concat operator:
proc `&` * (x: string, y: char): string {.magic: "ConStrStr", noSideEffect.}
proc `&` * (x: char, y: char): string {.magic: "ConStrStr", noSideEffect.}
proc `&` * (x, y: string): string {.magic: "ConStrStr", noSideEffect.}
proc `&` * (x: char, y: string): string {.magic: "ConStrStr", noSideEffect.}
proc `&` * (x: string, y: char): string {.
magic: "ConStrStr", noSideEffect, merge.}
proc `&` * (x: char, y: char): string {.
magic: "ConStrStr", noSideEffect, merge.}
proc `&` * (x, y: string): string {.
magic: "ConStrStr", noSideEffect, merge.}
proc `&` * (x: char, y: string): string {.
magic: "ConStrStr", noSideEffect, merge.}
## is the `concatenation operator`. It concatenates `x` and `y`.
proc add * (x: var string, y: char) {.magic: "AppendStrCh".}
@ -466,7 +652,7 @@ proc repr*[T](x: T): string {.magic: "Repr", noSideEffect.}
type
TAddress* = int
## is the signed integer type that should be used for converting
## pointers to integer addresses.
## pointers to integer addresses for readability.
type
BiggestInt* = int64
@ -500,7 +686,7 @@ type # these work for most platforms:
## This is the same as the type ``long double`` in *C*.
## This C type is not supported by Nimrod's code generator
cstringArray* {.importc: "char**", nodecl.} = array [0..50_000, cstring]
cstringArray* {.importc: "char**", nodecl.} = ptr array [0..50_000, cstring]
## This is the same as the type ``char**`` in *C*.
TEndian* = enum ## is a type describing the endianness of a processor.
@ -512,50 +698,49 @@ type # these work for most platforms:
PInt32* = ptr Int32 ## an alias for ``ptr int32``
const
QuitSuccess* = 0
## is the value that should be passed to ``quit`` to indicate
## success.
QuitFailure* = 1
## is the value that should be passed to ``quit`` to indicate
## failure.
isMainModule* {.magic: "IsMainModule".}: bool = false
## is true only when accessed in the main module. This works thanks to
## compiler magic. It is useful to embed testing code in a module.
CompileDate* {.magic: "CompileDate"}: string = "0000-00-00"
## is the date of compilation as a string of the form
## ``YYYY-MM-DD``.
## ``YYYY-MM-DD``. This works thanks to compiler magic.
CompileTime* {.magic: "CompileTime"}: string = "00:00:00"
## is the time of compilation as a string of the form
## ``HH:MM:SS``.
## ``HH:MM:SS``. This works thanks to compiler magic.
NimrodVersion* {.magic: "NimrodVersion"}: string = "0.0.0"
## is the version of Nimrod as a string.
## This works thanks to compiler magic.
NimrodMajor* {.magic: "NimrodMajor"}: int = 0
## is the major number of Nimrod's version.
## This works thanks to compiler magic.
NimrodMinor* {.magic: "NimrodMinor"}: int = 0
## is the minor number of Nimrod's version.
## This works thanks to compiler magic.
NimrodPatch* {.magic: "NimrodPatch"}: int = 0
## is the patch number of Nimrod's version.
## This works thanks to compiler magic.
cpuEndian* {.magic: "CpuEndian"}: TEndian = littleEndian
## is the endianness of the target CPU. This is a valuable information
## for low-level code only.
## is the endianness of the target CPU. This is a valuable piece of
## information for low-level code only. This works thanks to compiler magic.
proc toFloat*(i: int): float {.
magic: "ToFloat", noSideEffect, importc: "toFloat".}
## converts an integer `i` into a ``float``. If the conversion
## fails, `EInvalidValue` is raised. Note that on most platforms the
## conversion cannot fail, however.
## fails, `EInvalidValue` is raised. However, on most platforms the
## conversion cannot fail.
proc toBiggestFloat*(i: biggestint): biggestfloat {.
magic: "ToBiggestFloat", noSideEffect, importc: "toBiggestFloat".}
## converts an biggestint `i` into a ``biggestfloat``. If the conversion
## fails, `EInvalidValue` is raised. Note that on most platforms the
## conversion cannot fail, however.
## fails, `EInvalidValue` is raised. However, on most platforms the
## conversion cannot fail.
proc toInt*(f: float): int {.
magic: "ToInt", noSideEffect, importc: "toInt".}
@ -569,15 +754,6 @@ proc toBiggestInt*(f: biggestfloat): biggestint {.
## rounds `f` if it does not contain an integer value. If the conversion
## fails (because `f` is infinite for example), `EInvalidValue` is raised.
proc quit*(errorcode: int = QuitSuccess) {.
magic: "Exit", importc: "exit", noDecl, noReturn.}
## stops the program immediately; before stopping the program the
## "quit procedures" are called in the opposite order they were added
## with ``addQuitProc``. ``quit`` never returns and ignores any
## exception that may have been raised by the quit procedures.
## It does *not* call the garbage collector to free all the memory,
## unless a quit procedure calls ``GC_collect``.
proc addQuitProc*(QuitProc: proc {.noconv.}) {.importc: "atexit", nodecl.}
## adds/registers a quit procedure. Each call to ``addQuitProc``
## registers another quit procedure. Up to 30 procedures can be
@ -636,33 +812,29 @@ proc equalMem*(a, b: Pointer, size: int): bool {.
## *unsafe*.
const
mallocHeader = if defined(useDL): "dlmalloc.h" else: "<stdlib.h>"
mallocHeader = "<stdlib.h>"
proc alloc*(size: int): pointer {.
importc: if defined(useDL): "dlmalloc" else: "malloc",
header: mallocHeader, noconv.}
importc: "malloc", header: mallocHeader, noconv.}
## allocates a new memory block with at least ``size`` bytes. The
## block has to be freed with ``realloc(block, 0)`` or
## ``dealloc(block)``. The block is not initialized, so reading
## from it before writing to it is undefined behaviour!
proc alloc0*(size: int): pointer {.
importc: if defined(useDL): "DL_ALLOC_0" else: "ALLOC_0",
header: mallocHeader, noconv.}
importc: "ALLOC_0", header: mallocHeader, noconv.}
## allocates a new memory block with at least ``size`` bytes. The
## block has to be freed with ``realloc(block, 0)`` or
## ``dealloc(block)``. The block is initialized with all bytes
## containing zero, so it is somewhat safer than ``alloc``.
proc realloc*(p: Pointer, newsize: int): pointer {.
importc: if defined(useDL): "dlrealloc" else: "realloc",
header: mallocHeader, noconv.}
importc: "realloc", header: mallocHeader, noconv.}
## grows or shrinks a given memory block. If p is **nil** then a new
## memory block is returned. In either way the block has at least
## ``newsize`` bytes. If ``newsize == 0`` and p is not **nil**
## ``realloc`` calls ``dealloc(p)``. In other cases the block has to
## be freed with ``dealloc``.
proc dealloc*(p: Pointer) {.
importc: if defined(useDL): "dlfree" else: "free",
header: mallocHeader, noconv.}
importc: "free", header: mallocHeader, noconv.}
## frees the memory allocated with ``alloc``, ``alloc0`` or
## ``realloc``. This procedure is dangerous! If one forgets to
## free the memory a leak occurs; if one tries to access freed
@ -687,79 +859,6 @@ proc swap*[T](a, b: var T) {.magic: "Swap".}
## swaps the values `a` and `b`. This is often more efficient than
## ``tmp = a; a = b; b = tmp``. Particularly useful for sorting algorithms.
proc ze*(x: int8): int {.magic: "Ze8ToI", noSideEffect.}
## zero extends a smaller integer type to ``int``. This treats `x` as
## unsigned.
proc ze*(x: int16): int {.magic: "Ze16ToI", noSideEffect.}
## zero extends a smaller integer type to ``int``. This treats `x` as
## unsigned.
proc ze64*(x: int8): int64 {.magic: "Ze8ToI64", noSideEffect.}
## zero extends a smaller integer type to ``int64``. This treats `x` as
## unsigned.
proc ze64*(x: int16): int64 {.magic: "Ze16ToI64", noSideEffect.}
## zero extends a smaller integer type to ``int64``. This treats `x` as
## unsigned.
proc ze64*(x: int32): int64 {.magic: "Ze32ToI64", noSideEffect.}
## zero extends a smaller integer type to ``int64``. This treats `x` as
## unsigned.
proc ze64*(x: int): int64 {.magic: "ZeIToI64", noDecl, noSideEffect.}
## zero extends a smaller integer type to ``int64``. This treats `x` as
## unsigned. Does nothing if the size of an ``int`` is the same as ``int64``.
## (This is the case on 64 bit processors.)
proc toU8*(x: int): int8 {.magic: "ToU8", noSideEffect.}
## treats `x` as unsigned and converts it to a byte by taking the last 8 bits
## from `x`.
proc toU16*(x: int): int16 {.magic: "ToU16", noSideEffect.}
## treats `x` as unsigned and converts it to an ``int16`` by taking the last
## 16 bits from `x`.
proc toU32*(x: int64): int32 {.magic: "ToU32", noSideEffect.}
## treats `x` as unsigned and converts it to an ``int32`` by taking the
## last 32 bits from `x`.
proc `+%` *(x, y: int): int {.magic: "AddU", noSideEffect.}
proc `+%` *(x, y: int64): int64 {.magic: "AddU64", noSideEffect.}
## treats `x` and `y` as unsigned and adds them. The result is truncated to
## fit into the result. This implements modulo arithmetic. No overflow
## errors are possible.
proc `-%` *(x, y: int): int {.magic: "SubU", noSideEffect.}
proc `-%` *(x, y: int64): int64 {.magic: "SubU64", noSideEffect.}
## treats `x` and `y` as unsigned and subtracts them. The result is
## truncated to fit into the result. This implements modulo arithmetic.
## No overflow errors are possible.
proc `*%` *(x, y: int): int {.magic: "MulU", noSideEffect.}
proc `*%` *(x, y: int64): int64 {.magic: "MulU64", noSideEffect.}
## treats `x` and `y` as unsigned and multiplies them. The result is
## truncated to fit into the result. This implements modulo arithmetic.
## No overflow errors are possible.
proc `/%` *(x, y: int): int {.magic: "DivU", noSideEffect.}
proc `/%` *(x, y: int64): int64 {.magic: "DivU64", noSideEffect.}
## treats `x` and `y` as unsigned and divides them. The result is
## truncated to fit into the result. This implements modulo arithmetic.
## No overflow errors are possible.
proc `%%` *(x, y: int): int {.magic: "ModU", noSideEffect.}
proc `%%` *(x, y: int64): int64 {.magic: "ModU64", noSideEffect.}
## treats `x` and `y` as unsigned and compute the modulo of `x` and `y`.
## The result is truncated to fit into the result.
## This implements modulo arithmetic.
## No overflow errors are possible.
proc `<=%` *(x, y: int): bool {.magic: "LeU", noSideEffect.}
proc `<=%` *(x, y: int64): bool {.magic: "LeU64", noSideEffect.}
## treats `x` and `y` as unsigned and compares them.
## Returns true iff ``unsigned(x) <= unsigned(y)``.
proc `<%` *(x, y: int): bool {.magic: "LtU", noSideEffect.}
proc `<%` *(x, y: int64): bool {.magic: "LtU64", noSideEffect.}
## treats `x` and `y` as unsigned and compares them.
## Returns true iff ``unsigned(x) < unsigned(y)``.
template `>=%` *(x, y: expr): expr = y <=% x
## treats `x` and `y` as unsigned and compares them.
## Returns true iff ``unsigned(x) >= unsigned(y)``.
@ -803,17 +902,19 @@ proc getRefcount*[T](x: ref T): int {.importc: "getRefcount".}
## value is implementation-dependant.
#proc writeStackTrace() {.export: "writeStackTrace".}
proc getCurrentExceptionMsg*(): string {.exportc.}
## retrieves the error message that was attached to the current
## exception; if there is none, "" is returned.
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.
# new constants:
const
inf* {.magic: "Inf".} = 0.0
inf* {.magic: "Inf".} = 1.0 / 0.0
## contains the IEEE floating point value of positive infinity.
neginf* {.magic: "NegInf".} = 0.0
neginf* {.magic: "NegInf".} = -inf
## contains the IEEE floating point value of negative infinity.
nan* {.magic: "NaN".} = 0.0
nan* {.magic: "NaN".} = 0.0 / 0.0
## contains an IEEE floating point value of *Not A Number*. Note
## that you cannot compare a floating point value to this value
## and expect a reasonable result - use the `classify` procedure
@ -826,20 +927,16 @@ var
## Only code compiled with the ``debugger:on`` switch calls this hook.
# GC interface:
when defined(Unix) and not defined(macosX) and not defined(linux):
# BUGFIX for macosX
{.define: nativeDL.}
when defined(useDL) or defined(nativeDL):
proc getOccupiedMem*(): int
## returns the number of bytes that are owned by the process and hold data.
proc getOccupiedMem*(): int
## returns the number of bytes that are owned by the process and hold data.
proc getFreeMem*(): int
## returns the number of bytes that are owned by the process, but do not
## hold any meaningful data.
proc getFreeMem*(): int
## returns the number of bytes that are owned by the process, but do not
## hold any meaningful data.
proc getTotalMem*(): int
## returns the number of bytes that are owned by the process.
proc getTotalMem*(): int
## returns the number of bytes that are owned by the process.
iterator countdown*[T](a, b: T, step = 1): T {.inline.} =
@ -906,7 +1003,6 @@ iterator items*(a: cstring): char {.inline.} =
yield a[i]
inc(i)
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".}
@ -922,23 +1018,20 @@ proc isNil*(x: cstring): bool {.noSideEffect, magic: "IsNil".}
# once in the system module.
proc `&` *[T](x, y: seq[T]): seq[T] {.noSideEffect.} =
result = []
setLen(result, x.len + y.len)
newSeq(result, x.len + y.len)
for i in 0..x.len-1:
result[i] = x[i]
for i in 0..y.len-1:
result[i] = y[i]
proc `&` *[T](x: seq[T], y: T): seq[T] {.noSideEffect.} =
result = []
setLen(x.len + 1)
newSeq(result, x.len + 1)
for i in 0..x.len-1:
result[i] = x[i]
result[x.len] = y
proc `&` *[T](x: T, y: seq[T]): seq[T] {.noSideEffect.} =
result = []
setLen(y.len + 1)
newSeq(result, y.len + 1)
for i in 0..y.len-1:
result[i] = y[i]
result[y.len] = x
@ -946,24 +1039,35 @@ proc `&` *[T](x: T, y: seq[T]): seq[T] {.noSideEffect.} =
proc `&` *[T](x, y: T): seq[T] {.noSideEffect.} =
return [x, y]
when not defined(ECMAScript): # XXX make this local procs
proc seqToPtr*[T](x: seq[T]): pointer {.inline, nosideeffect.} =
result = cast[pointer](x)
else:
proc seqToPtr*[T](x: seq[T]): pointer {.pure, nosideeffect.} =
asm """return `x`"""
when not defined(NimrodVM):
when not defined(ECMAScript):
# XXX make this local procs
proc seqToPtr*[T](x: seq[T]): pointer {.inline, nosideeffect.} =
result = cast[pointer](x)
else:
proc seqToPtr*[T](x: seq[T]): pointer {.pure, nosideeffect.} =
asm """return `x`"""
proc `==` *[T](x, y: seq[T]): bool {.noSideEffect.} =
## Generic equals operator for sequences: relies on a equals operator for
## the element type `T`.
if seqToPtr(x) == seqToPtr(y):
result = true
elif seqToPtr(x) == nil or seqToPtr(y) == nil:
result = false
elif x.len == y.len:
for i in 0..x.len-1:
if x[i] != y[i]: return false
result = true
proc `==` *[T](x, y: seq[T]): bool {.noSideEffect.} =
## Generic equals operator for sequences: relies on a equals operator for
## the element type `T`.
if seqToPtr(x) == seqToPtr(y):
result = true
elif seqToPtr(x) == nil or seqToPtr(y) == nil:
result = false
elif x.len == y.len:
for i in 0..x.len-1:
if x[i] != y[i]: return false
result = true
proc find*[T, S](a: T, item: S): int {.inline.} =
## Returns the first index of `item` in `a` or -1 if not found. This requires
## appropriate `==` and `items` procs to work.
result = 0
for i in items(a):
if i == item: return
inc(result)
result = -1
# ----------------- FPU ------------------------------------------------------
@ -985,7 +1089,7 @@ proc GC_enable*()
proc GC_fullCollect*()
## forces a full garbage collection pass.
## Ordinary code does not need to call this.
## Ordinary code does not need to call this (and should not).
type
TGC_Strategy* = enum ## the strategy the GC should use for the application
@ -1005,12 +1109,28 @@ proc GC_disableMarkAndSweep*()
## does not create cycles. Thus the mark and sweep phase can be deactivated
## and activated separately from the rest of the GC.
proc GC_getStatistics*(): string
## returns an informative string about the GC's activity. This may be useful
## for tweaking.
proc GC_ref*[T](x: ref T) {.magic: "GCref".}
proc GC_ref*[T](x: seq[T]) {.magic: "GCref".}
proc GC_ref*(x: string) {.magic: "GCref".}
## marks the object `x` as referenced, so that it will not be freed until
## it is unmarked via `GC_unref`. If called n-times for the same object `x`,
## n calls to `GC_unref` are needed to unmark `x`.
proc GC_unref*[T](x: ref T) {.magic: "GCunref".}
proc GC_unref*[T](x: seq[T]) {.magic: "GCunref".}
proc GC_unref*(x: string) {.magic: "GCunref".}
## see the documentation of `GC_ref`.
{.push checks: off, line_dir: off, debugger: off,
assertions: on.} # obviously we cannot generate checking operations here :-)
# because it would yield into an endless recursion
# however, stack-traces are available for most parts
# of the code
{.push checks: off, line_dir: off, debugger: off.}
# obviously we cannot generate checking operations here :-)
# because it would yield into an endless recursion
# however, stack-traces are available for most parts
# of the code
proc echo*[Ty](x: Ty) {.inline.}
## equivalent to ``writeln(stdout, x); flush(stdout)``. BUT: This is
@ -1025,7 +1145,29 @@ template newException(exceptn, message: expr): expr =
e.msg = message
e
when not defined(EcmaScript):
const
QuitSuccess* = 0
## is the value that should be passed to ``quit`` to indicate
## success.
QuitFailure* = 1
## is the value that should be passed to ``quit`` to indicate
## failure.
proc quit*(errorcode: int = QuitSuccess) {.
magic: "Exit", importc: "exit", noDecl, noReturn.}
## stops the program immediately; before stopping the program the
## "quit procedures" are called in the opposite order they were added
## with ``addQuitProc``. ``quit`` never returns and ignores any
## exception that may have been raised by the quit procedures.
## It does *not* call the garbage collector to free all the memory,
## unless a quit procedure calls ``GC_collect``.
when not defined(EcmaScript) and not defined(NimrodVM):
proc quit*(errormsg: string) {.noReturn.}
## a shorthand for ``echo(errormsg); quit(quitFailure)``.
when not defined(EcmaScript) and not defined(NimrodVM):
include hti
@ -1036,6 +1178,7 @@ when not defined(EcmaScript):
strDesc.size = sizeof(string)
strDesc.kind = tyString
strDesc.flags = {ntfAcyclic}
initGC() # BUGFIX: need to be called here!
{.push stack_trace: off.}
@ -1043,12 +1186,12 @@ when not defined(EcmaScript):
include ansi_c
proc cmp(x, y: string): int =
return c_strcmp(x, y)
return int(c_strcmp(x, y))
const pccHack = if defined(pcc): "_" else: "" # Hack for PCC
when defined(windows):
# work-around C's sucking abstraction:
# BUGFIX: stdin and stdout should be binary files!
const pccHack = if defined(pcc): "_" else: "" # Hack for PCC
proc setmode(handle, mode: int) {.importc: pccHack & "setmode",
header: "<io.h>".}
proc fileno(f: C_TextFileStar): int {.importc: pccHack & "fileno",
@ -1082,6 +1225,9 @@ when not defined(EcmaScript):
fmAppend ## Open the file for writing only; append data
## at the end.
TFileHandle* = cint ## type that represents an OS file handle; this is
## useful for low-level file access
# text file handling:
var
stdin* {.importc: "stdin", noDecl.}: TFile ## The standard input stream.
@ -1106,6 +1252,12 @@ when not defined(EcmaScript):
## that the programmer needs to provide an appropriate error message anyway
## (yes, even in scripts).
proc OpenFile*(f: var TFile, filehandle: TFileHandle,
mode: TFileMode = fmRead): Bool
## Creates a ``TFile`` from a `filehandle` with given `mode`.
##
## Default mode is readonly. Returns true iff the file could be opened.
proc CloseFile*(f: TFile) {.importc: "fclose", nodecl.}
## Closes the file.
proc EndOfFile*(f: TFile): Bool
@ -1201,6 +1353,15 @@ when not defined(EcmaScript):
yield res
CloseFile(f)
proc fileHandle*(f: TFile): TFileHandle {.importc: "fileno",
header: "<stdio.h>"}
## returns the OS file handle of the file ``f``. This is only useful for
## platform specific programming.
proc quit(errormsg: string) =
echo(errormsg)
quit(quitFailure)
# ----------------------------------------------------------------------------
include excpt
@ -1211,10 +1372,10 @@ when not defined(EcmaScript):
# sequence type declarations here because the GC needs them too:
type
TGenericSeq {.importc, nodecl, final.} = object
TGenericSeq {.compilerproc, pure.} = object
len, space: int
PGenericSeq {.importc, nodecl.} = ptr TGenericSeq
PGenericSeq {.exportc.} = ptr TGenericSeq
const
GenericSeqSize = (2 * sizeof(int))
@ -1235,10 +1396,32 @@ when not defined(EcmaScript):
{.push stack_trace: off.}
when defined(endb):
include debugger
when defined(profiler):
include profiler
{.pop.} # stacktrace
else:
elif defined(ecmaScript):
include ecmasys
elif defined(NimrodVM):
# Stubs for the GC interface:
proc GC_disable() = nil
proc GC_enable() = nil
proc GC_fullCollect() = nil
proc GC_setStrategy(strategy: TGC_Strategy) = nil
proc GC_enableMarkAndSweep() = nil
proc GC_disableMarkAndSweep() = nil
proc GC_getStatistics(): string = return ""
proc getOccupiedMem(): int = return -1
proc getFreeMem(): int = return -1
proc getTotalMem(): int = return -1
proc echo[Ty](x: Ty) = nil
proc cmp(x, y: string): int =
if x == y: return 0
if x < y: return -1
return 1
include macros

View file

@ -23,8 +23,8 @@ type
TWeekDay* = enum ## represents a weekday
dMon, dTue, dWed, dThu, dFri, dSat, dSun
TTime* {.importc: "time_t", final.} = object ## abstract type that
## represents a time
TTime* {.importc: "time_t", header: "<time.h>", final.} = object ## abstract type that
## represents a time
when defined(ECMAScript):
getDay: proc (): int
getFullYear: proc (): int
@ -96,11 +96,9 @@ proc TimeInfoToTime*(timeInfo: TTimeInfo): TTime
## them from the other information in the broken-down time structure.
proc `$` *(timeInfo: TTimeInfo): string
## converts a `TTimeInfo` object to a
## string representation.
## converts a `TTimeInfo` object to a string representation.
proc `$` *(time: TTime): string
## converts a calendar time to a
## string representation.
## converts a calendar time to a string representation.
proc getDateStr*(): string
## gets the current date as a string of the format
@ -111,6 +109,14 @@ proc getClockStr*(): string
proc `-` *(a, b: TTime): int64
## computes the difference of two calendar times. Result is in seconds.
proc `<` * (a, b: TTime): bool =
## returns true iff ``a < b``, that is iff a happened before b.
result = a - b < 0
proc `<=` * (a, b: TTime): bool =
## returns true iff ``a <= b``.
result = a - b <= 0
proc getStartMilsecs*(): int
## get the miliseconds from the start of the program
@ -162,7 +168,7 @@ when not defined(ECMAScript):
result.hour = int(tm.hour)
result.monthday = int(tm.monthday)
result.month = TMonth(tm.month)
result.year = tm.year + 1900
result.year = tm.year + 1900'i32
result.weekday = weekDays[int(tm.weekDay)]
result.yearday = int(tm.yearday)
@ -180,8 +186,7 @@ when not defined(ECMAScript):
result.isdst = -1
proc `-` (a, b: TTime): int64 =
return toInt(difftime(a, b)) # XXX: toBiggestInt is needed here, but
# Nim does not support it!
return toBiggestInt(difftime(a, b))
proc getStartMilsecs(): int = return clock() div (clocksPerSec div 1000)
proc getTime(): TTime = return timec(nil)
@ -202,12 +207,23 @@ when not defined(ECMAScript):
# because the header of mktime is broken in my version of libc
return mktime(timeInfoToTM(cTimeInfo))
proc toStringTillNL(p: cstring): string =
result = ""
var i = 0
while p[i] != '\0' and p[i] != '\10' and p[i] != '\13':
add(result, p[i])
inc(i)
return result
proc `$`(timeInfo: TTimeInfo): string =
return $asctime(timeInfoToTM(timeInfo))
# BUGFIX: asctime returns a newline at the end!
var p = asctime(timeInfoToTM(timeInfo))
result = toStringTillNL(p)
proc `$`(time: TTime): string =
# BUGFIX: ctime returns a newline at the end!
var a = time
return $ctime(addr(a))
return toStringTillNL(ctime(addr(a)))
else:
proc getTime(): TTime {.importc: "new Date", nodecl.}

View file

@ -1,7 +1,7 @@
#
#
# Nimrod's Runtime Library
# (c) Copyright 2006 Andreas Rumpf
# (c) Copyright 2008 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
@ -9,7 +9,7 @@
type
TUniChar* = int32 ## type that can hold any Unicode character
TUniChar16* = int16 ##
TUniChar16* = int16 ## 16 bit Unicode character
template ones(n) = ((1 shl n)-1)

File diff suppressed because it is too large Load diff