mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-19 07:21:19 +00:00
bugfix: bug499771
This commit is contained in:
@@ -256,7 +256,66 @@ proc fillRect*(sur: PSurface, r: TRect, col: TColor) =
|
||||
for j in r.x..min(sur.s.w, r.x+r.width-1)-1:
|
||||
setPix(video, pitch, j, i, col)
|
||||
|
||||
proc trunc(x: float): float {.importc: "trunc", nodecl.}
|
||||
|
||||
proc Plot4EllipsePoints(sur: PSurface, CX, CY, X, Y: Natural, col: TColor) =
|
||||
var video = cast[PPixels](sur.s.pixels)
|
||||
var pitch = sur.s.pitch div ColSize
|
||||
|
||||
setPix(video, pitch, CX+X, CY+Y, col)
|
||||
setPix(video, pitch, CX-X, CY+Y, col)
|
||||
setPix(video, pitch, CX-X, CY-Y, col)
|
||||
setPix(video, pitch, CX+X, CY-Y, col)
|
||||
|
||||
proc drawEllipse*(sur: PSurface, CX, CY, XRadius, YRadius: Natural, col: TColor) =
|
||||
var
|
||||
X, Y: Natural
|
||||
XChange, YChange: Natural
|
||||
EllipseError: Natural
|
||||
TwoASquare, TwoBSquare: Natural
|
||||
StoppingX, StoppingY: Natural
|
||||
|
||||
TwoASquare = 2 * XRadius * XRadius
|
||||
TwoBSquare = 2 * YRadius * YRadius
|
||||
X = XRadius
|
||||
Y = 0
|
||||
XChange = YRadius * YRadius * (1 - 2 * XRadius)
|
||||
YChange = XRadius * XRadius
|
||||
EllipseError = 0
|
||||
StoppingX = TwoBSquare * XRadius
|
||||
StoppingY = 0
|
||||
|
||||
while StoppingX >= StoppingY: # 1st set of points, y` > - 1
|
||||
sur.Plot4EllipsePoints(CX, CY, X, Y, col)
|
||||
inc(Y)
|
||||
inc(StoppingY, TwoASquare)
|
||||
inc(EllipseError, YChange)
|
||||
inc(YChange, TwoASquare)
|
||||
if (2 * EllipseError + XChange) > 0 :
|
||||
dec(x)
|
||||
dec(StoppingX, TwoBSquare)
|
||||
inc(EllipseError, XChange)
|
||||
inc(XChange, TwoBSquare)
|
||||
|
||||
# 1st point set is done; start the 2nd set of points
|
||||
X = 0
|
||||
Y = YRadius
|
||||
XChange = YRadius * YRadius
|
||||
YChange = XRadius * XRadius * (1 - 2 * YRadius)
|
||||
EllipseError = 0
|
||||
StoppingX = 0
|
||||
StoppingY = TwoASquare * YRadius
|
||||
while StoppingX <= StoppingY:
|
||||
sur.Plot4EllipsePoints(CX, CY, X, Y, col)
|
||||
inc(X)
|
||||
inc(StoppingX, TwoBSquare)
|
||||
inc(EllipseError, XChange)
|
||||
inc(XChange,TwoBSquare)
|
||||
if (2 * EllipseError + YChange) > 0:
|
||||
dec(Y)
|
||||
dec(StoppingY, TwoASquare)
|
||||
inc(EllipseError, YChange)
|
||||
inc(YChange,TwoASquare)
|
||||
|
||||
|
||||
proc plot(sur: PSurface, x, y, c: float, color: TColor) =
|
||||
var video = cast[PPixels](sur.s.pixels)
|
||||
@@ -265,7 +324,7 @@ proc plot(sur: PSurface, x, y, c: float, color: TColor) =
|
||||
|
||||
setPix(video, pitch, x.toInt(), y.toInt(),
|
||||
pixColor.intensity(1.0 - c) + color.intensity(c))
|
||||
|
||||
import math
|
||||
proc ipart(x: float): float =
|
||||
return x.trunc()
|
||||
proc fpart(x: float): float =
|
||||
@@ -273,7 +332,7 @@ proc fpart(x: float): float =
|
||||
proc rfpart(x: float): float =
|
||||
return 1.0 - fpart(x)
|
||||
|
||||
import math
|
||||
|
||||
|
||||
proc drawLineAA(sur: PSurface, p1: TPoint, p2: TPoint, color: TColor) =
|
||||
## Draws a line from ``p1`` to ``p2``, using the Xiaolin Wu's line algorithm
|
||||
@@ -321,8 +380,9 @@ when isMainModule:
|
||||
var surf = newSurface(800, 600)
|
||||
var r: TRect = (0, 0, 900, 900)
|
||||
surf.fillRect(r, colWhite)
|
||||
surf.drawLineAA((500, 300), (200, 200), colBlack)
|
||||
surf.drawLineAA((500, 300), (200, 270), colTan)
|
||||
|
||||
surf.drawEllipse(400, 300, 415, 200, colSeaGreen)
|
||||
|
||||
surf.drawHorLine(5, 5, 900, colRed)
|
||||
surf.drawVerLine(5, 60, 800, colRed)
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
#
|
||||
#
|
||||
# Nimrod's Runtime Library
|
||||
# (c) Copyright 2010 Andreas Rumpf, Dominik Picheta
|
||||
#
|
||||
# See the file "copying.txt", included in this
|
||||
# distribution, for details about the copyright.
|
||||
#
|
||||
|
||||
import posix, strutils, os
|
||||
|
||||
proc getSystemVersion*(): string =
|
||||
## retrieves the system name ("Linux", "Mac OS X") & the system version.
|
||||
## The implementation uses ``posix.uname``.
|
||||
var info: TUtsname
|
||||
if uname(info) < 0'i32: OSError()
|
||||
case $info.sysname
|
||||
of "Linux":
|
||||
result = "Linux " & $info.release & " " & $info.machine
|
||||
of "Darwin":
|
||||
result = "Mac OS X "
|
||||
if "10" in $info.release:
|
||||
result.add("v10.6 Snow Leopard")
|
||||
elif "0" in $info.release:
|
||||
result.add("Server 1.0 Hera")
|
||||
elif "1.3" in $info.release:
|
||||
result.add("v10.0 Cheetah")
|
||||
elif "1.4" in $info.release:
|
||||
result.add("v10.1 Puma")
|
||||
elif "6" in $info.release:
|
||||
result.add("v10.2 Jaguar")
|
||||
elif "7" in $info.release:
|
||||
result.add("v10.3 Panther")
|
||||
elif "8" in $info.release:
|
||||
result.add("v10.4 Tiger")
|
||||
elif "9" in $info.release:
|
||||
result.add("v10.5 Leopard")
|
||||
else:
|
||||
result = $info.sysname & " " & $info.release
|
||||
|
||||
when isMainModule:
|
||||
echo(getSystemVersion())
|
||||
@@ -1,390 +0,0 @@
|
||||
#
|
||||
#
|
||||
# Nimrod's Runtime Library
|
||||
# (c) Copyright 2010 Dominik Picheta
|
||||
#
|
||||
# See the file "copying.txt", included in this
|
||||
# distribution, for details about the copyright.
|
||||
#
|
||||
|
||||
import winlean
|
||||
|
||||
const
|
||||
INVALID_HANDLE_VALUE = int(- 1) # GetStockObject
|
||||
|
||||
type
|
||||
TMEMORYSTATUSEX {.final, pure.} = object
|
||||
dwLength: int32
|
||||
dwMemoryLoad: int32
|
||||
ullTotalPhys: int64
|
||||
ullAvailPhys: int64
|
||||
ullTotalPageFile: int64
|
||||
ullAvailPageFile: int64
|
||||
ullTotalVirtual: int64
|
||||
ullAvailVirtual: int64
|
||||
ullAvailExtendedVirtual: int64
|
||||
|
||||
SYSTEM_INFO {.final, pure.} = object
|
||||
wProcessorArchitecture*: int16
|
||||
wReserved*: int16
|
||||
dwPageSize*: int32
|
||||
lpMinimumApplicationAddress*: pointer
|
||||
lpMaximumApplicationAddress*: pointer
|
||||
dwActiveProcessorMask*: int32
|
||||
dwNumberOfProcessors*: int32
|
||||
dwProcessorType*: int32
|
||||
dwAllocationGranularity*: int32
|
||||
wProcessorLevel*: int16
|
||||
wProcessorRevision*: int16
|
||||
|
||||
LPSYSTEM_INFO = ptr SYSTEM_INFO
|
||||
|
||||
TMemoryInfo* = object
|
||||
MemoryLoad*: int ## occupied memory, in percent
|
||||
TotalPhysMem*: int64 ## Total Physical memory, in bytes
|
||||
AvailablePhysMem*: int64 ## Available physical memory, in bytes
|
||||
TotalPageFile*: int64 ## The current committed memory limit
|
||||
## for the system or the current process, whichever is smaller, in bytes.
|
||||
AvailablePageFile*: int64 ## The maximum amount of memory the current process can commit, in bytes.
|
||||
TotalVirtualMem*: int64 ## Total virtual memory, in bytes
|
||||
AvailableVirtualMem*: int64 ## Available virtual memory, in bytes
|
||||
|
||||
TOSVERSIONINFOEX {.final, pure.} = object
|
||||
dwOSVersionInfoSize: int32
|
||||
dwMajorVersion: int32
|
||||
dwMinorVersion: int32
|
||||
dwBuildNumber: int32
|
||||
dwPlatformId: int32
|
||||
szCSDVersion: array[0..127, char]
|
||||
wServicePackMajor: int16
|
||||
wServicePackMinor: int16
|
||||
wSuiteMask: int16
|
||||
wProductType: int8
|
||||
wReserved: char
|
||||
|
||||
TVersionInfo* = object
|
||||
majorVersion*: int
|
||||
minorVersion*: int
|
||||
buildNumber*: int
|
||||
platformID*: int
|
||||
SPVersion*: string ## Full Service pack version string
|
||||
SPMajor*: int ## Major service pack version
|
||||
SPMinor*: int ## Minor service pack version
|
||||
SuiteMask*: int
|
||||
ProductType*: int
|
||||
|
||||
TPartitionInfo* = tuple[FreeSpace, TotalSpace: biggestInt]
|
||||
|
||||
# All Windows editions...
|
||||
const
|
||||
# SuiteMask - VersionInfo.SuiteMask
|
||||
VER_SUITE_BACKOFFICE* = 0x00000004
|
||||
VER_SUITE_BLADE* = 0x00000400
|
||||
VER_SUITE_COMPUTE_SERVER* = 0x00004000
|
||||
VER_SUITE_DATACENTER* = 0x00000080
|
||||
VER_SUITE_ENTERPRISE* = 0x00000002
|
||||
VER_SUITE_EMBEDDEDNT* = 0x00000040
|
||||
VER_SUITE_PERSONAL* = 0x00000200
|
||||
VER_SUITE_SINGLEUSERTS* = 0x00000100
|
||||
VER_SUITE_SMALLBUSINESS* = 0x00000001
|
||||
VER_SUITE_SMALLBUSINESS_RESTRICTED* = 0x00000020
|
||||
VER_SUITE_STORAGE_SERVER* = 0x00002000
|
||||
VER_SUITE_TERMINAL* = 0x00000010
|
||||
VER_SUITE_WH_SERVER* = 0x00008000
|
||||
|
||||
# ProductType - VersionInfo.ProductType
|
||||
VER_NT_DOMAIN_CONTROLLER* = 0x0000002
|
||||
VER_NT_SERVER* = 0x0000003
|
||||
VER_NT_WORKSTATION* = 0x0000001
|
||||
|
||||
VER_PLATFORM_WIN32_NT* = 2
|
||||
|
||||
# Product Info - getProductInfo() - (Remove unused ones ?)
|
||||
PRODUCT_BUSINESS* = 0x00000006
|
||||
PRODUCT_BUSINESS_N* = 0x00000010
|
||||
PRODUCT_CLUSTER_SERVER* = 0x00000012
|
||||
PRODUCT_DATACENTER_SERVER* = 0x00000008
|
||||
PRODUCT_DATACENTER_SERVER_CORE* = 0x0000000C
|
||||
PRODUCT_DATACENTER_SERVER_CORE_V* = 0x00000027
|
||||
PRODUCT_DATACENTER_SERVER_V* = 0x00000025
|
||||
PRODUCT_ENTERPRISE* = 0x00000004
|
||||
PRODUCT_ENTERPRISE_E* = 0x00000046
|
||||
PRODUCT_ENTERPRISE_N* = 0x0000001B
|
||||
PRODUCT_ENTERPRISE_SERVER* = 0x0000000A
|
||||
PRODUCT_ENTERPRISE_SERVER_CORE* = 0x0000000E
|
||||
PRODUCT_ENTERPRISE_SERVER_CORE_V* = 0x00000029
|
||||
PRODUCT_ENTERPRISE_SERVER_IA64* = 0x0000000F
|
||||
PRODUCT_ENTERPRISE_SERVER_V* = 0x00000026
|
||||
PRODUCT_HOME_BASIC* = 0x00000002
|
||||
PRODUCT_HOME_BASIC_E* = 0x00000043
|
||||
PRODUCT_HOME_BASIC_N* = 0x00000005
|
||||
PRODUCT_HOME_PREMIUM* = 0x00000003
|
||||
PRODUCT_HOME_PREMIUM_E* = 0x00000044
|
||||
PRODUCT_HOME_PREMIUM_N* = 0x0000001A
|
||||
PRODUCT_HYPERV* = 0x0000002A
|
||||
PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT* = 0x0000001E
|
||||
PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING* = 0x00000020
|
||||
PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY* = 0x0000001F
|
||||
PRODUCT_PROFESSIONAL* = 0x00000030
|
||||
PRODUCT_PROFESSIONAL_E* = 0x00000045
|
||||
PRODUCT_PROFESSIONAL_N* = 0x00000031
|
||||
PRODUCT_SERVER_FOR_SMALLBUSINESS* = 0x00000018
|
||||
PRODUCT_SERVER_FOR_SMALLBUSINESS_V* = 0x00000023
|
||||
PRODUCT_SERVER_FOUNDATION* = 0x00000021
|
||||
PRODUCT_SMALLBUSINESS_SERVER* = 0x00000009
|
||||
PRODUCT_STANDARD_SERVER* = 0x00000007
|
||||
PRODUCT_STANDARD_SERVER_CORE * = 0x0000000D
|
||||
PRODUCT_STANDARD_SERVER_CORE_V* = 0x00000028
|
||||
PRODUCT_STANDARD_SERVER_V* = 0x00000024
|
||||
PRODUCT_STARTER* = 0x0000000B
|
||||
PRODUCT_STARTER_E* = 0x00000042
|
||||
PRODUCT_STARTER_N* = 0x0000002F
|
||||
PRODUCT_STORAGE_ENTERPRISE_SERVER* = 0x00000017
|
||||
PRODUCT_STORAGE_EXPRESS_SERVER* = 0x00000014
|
||||
PRODUCT_STORAGE_STANDARD_SERVER* = 0x00000015
|
||||
PRODUCT_STORAGE_WORKGROUP_SERVER* = 0x00000016
|
||||
PRODUCT_UNDEFINED* = 0x00000000
|
||||
PRODUCT_ULTIMATE* = 0x00000001
|
||||
PRODUCT_ULTIMATE_E* = 0x00000047
|
||||
PRODUCT_ULTIMATE_N* = 0x0000001C
|
||||
PRODUCT_WEB_SERVER* = 0x00000011
|
||||
PRODUCT_WEB_SERVER_CORE* = 0x0000001D
|
||||
|
||||
PROCESSOR_ARCHITECTURE_AMD64* = 9 ## x64 (AMD or Intel)
|
||||
PROCESSOR_ARCHITECTURE_IA64* = 6 ## Intel Itanium Processor Family (IPF)
|
||||
PROCESSOR_ARCHITECTURE_INTEL* = 0 ## x86
|
||||
PROCESSOR_ARCHITECTURE_UNKNOWN* = 0xffff ## Unknown architecture.
|
||||
|
||||
# GetSystemMetrics
|
||||
SM_SERVERR2 = 89
|
||||
|
||||
proc GlobalMemoryStatusEx(lpBuffer: var TMEMORYSTATUSEX){.stdcall, dynlib: "kernel32",
|
||||
importc: "GlobalMemoryStatusEx".}
|
||||
|
||||
proc getMemoryInfo*(): TMemoryInfo =
|
||||
## Retrieves memory info
|
||||
var statex: TMEMORYSTATUSEX
|
||||
statex.dwLength = sizeof(statex)
|
||||
|
||||
GlobalMemoryStatusEx(statex)
|
||||
result.MemoryLoad = statex.dwMemoryLoad
|
||||
result.TotalPhysMem = statex.ullTotalPhys
|
||||
result.AvailablePhysMem = statex.ullAvailPhys
|
||||
result.TotalPageFile = statex.ullTotalPageFile
|
||||
result.AvailablePageFile = statex.ullAvailPageFile
|
||||
result.TotalVirtualMem = statex.ullTotalVirtual
|
||||
result.AvailableVirtualMem = statex.ullAvailExtendedVirtual
|
||||
|
||||
proc GetVersionEx(lpVersionInformation: var TOSVERSIONINFOEX): WINBOOL{.stdcall,
|
||||
dynlib: "kernel32", importc: "GetVersionExA".}
|
||||
|
||||
proc GetProcAddress(hModule: int, lpProcName: cstring): pointer{.stdcall,
|
||||
dynlib: "kernel32", importc: "GetProcAddress".}
|
||||
|
||||
proc GetModuleHandleA(lpModuleName: cstring): int{.stdcall,
|
||||
dynlib: "kernel32", importc.}
|
||||
|
||||
proc getVersionInfo*(): TVersionInfo =
|
||||
## Retrieves operating system info
|
||||
var osvi: TOSVERSIONINFOEX
|
||||
osvi.dwOSVersionInfoSize = sizeof(osvi)
|
||||
discard GetVersionEx(osvi)
|
||||
result.majorVersion = osvi.dwMajorVersion
|
||||
result.minorVersion = osvi.dwMinorVersion
|
||||
result.buildNumber = osvi.dwBuildNumber
|
||||
result.platformID = osvi.dwPlatformId
|
||||
result.SPVersion = $osvi.szCSDVersion
|
||||
result.SPMajor = osvi.wServicePackMajor
|
||||
result.SPMinor = osvi.wServicePackMinor
|
||||
result.SuiteMask = osvi.wSuiteMask
|
||||
result.ProductType = osvi.wProductType
|
||||
|
||||
proc getProductInfo*(majorVersion, minorVersion, SPMajorVersion, SPMinorVersion: int): int =
|
||||
## Retrieves Windows' ProductInfo, this function only works in Vista and 7
|
||||
|
||||
var pGPI = cast[proc (dwOSMajorVersion, dwOSMinorVersion,
|
||||
dwSpMajorVersion, dwSpMinorVersion: int32, outValue: Pint32)](GetProcAddress(
|
||||
GetModuleHandleA("kernel32.dll"), "GetProductInfo"))
|
||||
|
||||
if pGPI != nil:
|
||||
var dwType: int32
|
||||
pGPI(int32(majorVersion), int32(minorVersion), int32(SPMajorVersion), int32(SPMinorVersion), addr(dwType))
|
||||
result = int(dwType)
|
||||
else:
|
||||
return PRODUCT_UNDEFINED
|
||||
|
||||
proc GetSystemInfo(lpSystemInfo: ptr SYSTEM_INFO){.stdcall, dynlib: "kernel32",
|
||||
importc: "GetSystemInfo".}
|
||||
|
||||
proc getSystemInfo*(): TSYSTEM_INFO =
|
||||
## Returns the SystemInfo
|
||||
|
||||
# Use GetNativeSystemInfo if it's available
|
||||
var pGNSI = cast[proc (lpSystemInfo: LPSYSTEM_INFO)](GetProcAddress(
|
||||
GetModuleHandleA("kernel32.dll"), "GetNativeSystemInfo"))
|
||||
|
||||
var systemi: TSYSTEM_INFO
|
||||
if pGNSI != nil:
|
||||
pGNSI(addr(systemi))
|
||||
else:
|
||||
GetSystemInfo(addr(systemi))
|
||||
|
||||
return systemi
|
||||
|
||||
proc GetSystemMetrics(nIndex: int32): int32{.stdcall, dynlib: "user32",
|
||||
importc: "GetSystemMetrics".}
|
||||
|
||||
proc `$`*(osvi: TVersionInfo): string =
|
||||
## Turns a VersionInfo object, into a string
|
||||
|
||||
if osvi.platformID == VER_PLATFORM_WIN32_NT and osvi.majorVersion > 4:
|
||||
result = "Microsoft "
|
||||
|
||||
var si = getSystemInfo()
|
||||
# Test for the specific product
|
||||
if osvi.majorVersion == 6:
|
||||
if osvi.minorVersion == 0:
|
||||
if osvi.ProductType == VER_NT_WORKSTATION:
|
||||
result.add("Windows Vista ")
|
||||
else: result.add("Windows Server 2008 ")
|
||||
elif osvi.minorVersion == 1:
|
||||
if osvi.ProductType == VER_NT_WORKSTATION:
|
||||
result.add("Windows 7 ")
|
||||
else: result.add("Windows Server 2008 R2 ")
|
||||
|
||||
var dwType = getProductInfo(osvi.majorVersion, osvi.minorVersion, 0, 0)
|
||||
case dwType
|
||||
of PRODUCT_ULTIMATE:
|
||||
result.add("Ultimate Edition")
|
||||
of PRODUCT_PROFESSIONAL:
|
||||
result.add("Professional")
|
||||
of PRODUCT_HOME_PREMIUM:
|
||||
result.add("Home Premium Edition")
|
||||
of PRODUCT_HOME_BASIC:
|
||||
result.add("Home Basic Edition")
|
||||
of PRODUCT_ENTERPRISE:
|
||||
result.add("Enterprise Edition")
|
||||
of PRODUCT_BUSINESS:
|
||||
result.add("Business Edition")
|
||||
of PRODUCT_STARTER:
|
||||
result.add("Starter Edition")
|
||||
of PRODUCT_CLUSTER_SERVER:
|
||||
result.add("Cluster Server Edition")
|
||||
of PRODUCT_DATACENTER_SERVER:
|
||||
result.add("Datacenter Edition")
|
||||
of PRODUCT_DATACENTER_SERVER_CORE:
|
||||
result.add("Datacenter Edition (core installation)")
|
||||
of PRODUCT_ENTERPRISE_SERVER:
|
||||
result.add("Enterprise Edition")
|
||||
of PRODUCT_ENTERPRISE_SERVER_CORE:
|
||||
result.add("Enterprise Edition (core installation)")
|
||||
of PRODUCT_ENTERPRISE_SERVER_IA64:
|
||||
result.add("Enterprise Edition for Itanium-based Systems")
|
||||
of PRODUCT_SMALLBUSINESS_SERVER:
|
||||
result.add("Small Business Server")
|
||||
of PRODUCT_STANDARD_SERVER:
|
||||
result.add("Standard Edition")
|
||||
of PRODUCT_STANDARD_SERVER_CORE:
|
||||
result.add("Standard Edition (core installation)")
|
||||
of PRODUCT_WEB_SERVER:
|
||||
result.add("Web Server Edition")
|
||||
else:
|
||||
nil
|
||||
# End of Windows 6.*
|
||||
|
||||
if osvi.majorVersion == 5 and osvi.minorVersion == 2:
|
||||
if GetSystemMetrics(SM_SERVERR2) != 0:
|
||||
result.add("Windows Server 2003 R2, ")
|
||||
elif (osvi.SuiteMask and VER_SUITE_PERSONAL) != 0: # Not sure if this will work
|
||||
result.add("Windows Storage Server 2003")
|
||||
elif (osvi.SuiteMask and VER_SUITE_WH_SERVER) != 0:
|
||||
result.add("Windows Home Server")
|
||||
elif osvi.ProductType == VER_NT_WORKSTATION and
|
||||
si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64:
|
||||
result.add("Windows XP Professional x64 Edition")
|
||||
else:
|
||||
result.add("Windows Server 2003, ")
|
||||
|
||||
# Test for the specific product
|
||||
if osvi.ProductType != VER_NT_WORKSTATION:
|
||||
if ze(si.wProcessorArchitecture) == PROCESSOR_ARCHITECTURE_IA64:
|
||||
if (osvi.SuiteMask and VER_SUITE_DATACENTER) != 0:
|
||||
result.add("Datacenter Edition for Itanium-based Systems")
|
||||
elif (osvi.SuiteMask and VER_SUITE_ENTERPRISE) != 0:
|
||||
result.add("Enterprise Edition for Itanium-based Systems")
|
||||
elif ze(si.wProcessorArchitecture) == PROCESSOR_ARCHITECTURE_AMD64:
|
||||
if (osvi.SuiteMask and VER_SUITE_DATACENTER) != 0:
|
||||
result.add("Datacenter x64 Edition")
|
||||
elif (osvi.SuiteMask and VER_SUITE_ENTERPRISE) != 0:
|
||||
result.add("Enterprise x64 Edition")
|
||||
else:
|
||||
result.add("Standard x64 Edition")
|
||||
else:
|
||||
if (osvi.SuiteMask and VER_SUITE_COMPUTE_SERVER) != 0:
|
||||
result.add("Compute Cluster Edition")
|
||||
elif (osvi.SuiteMask and VER_SUITE_DATACENTER) != 0:
|
||||
result.add("Datacenter Edition")
|
||||
elif (osvi.SuiteMask and VER_SUITE_ENTERPRISE) != 0:
|
||||
result.add("Enterprise Edition")
|
||||
elif (osvi.SuiteMask and VER_SUITE_BLADE) != 0:
|
||||
result.add("Web Edition")
|
||||
else:
|
||||
result.add("Standard Edition")
|
||||
# End of 5.2
|
||||
|
||||
if osvi.majorVersion == 5 and osvi.minorVersion == 1:
|
||||
result.add("Windows XP ")
|
||||
if (osvi.SuiteMask and VER_SUITE_PERSONAL) != 0:
|
||||
result.add("Home Edition")
|
||||
else:
|
||||
result.add("Professional")
|
||||
# End of 5.1
|
||||
|
||||
if osvi.majorVersion == 5 and osvi.minorVersion == 0:
|
||||
result.add("Windows 2000 ")
|
||||
if osvi.ProductType == VER_NT_WORKSTATION:
|
||||
result.add("Professional")
|
||||
else:
|
||||
if (osvi.SuiteMask and VER_SUITE_DATACENTER) != 0:
|
||||
result.add("Datacenter Server")
|
||||
elif (osvi.SuiteMask and VER_SUITE_ENTERPRISE) != 0:
|
||||
result.add("Advanced Server")
|
||||
else:
|
||||
result.add("Server")
|
||||
# End of 5.0
|
||||
|
||||
# Include service pack (if any) and build number.
|
||||
if len(osvi.SPVersion) > 0:
|
||||
result.add(" ")
|
||||
result.add(osvi.SPVersion)
|
||||
|
||||
result.add(" (build " & $osvi.buildNumber & ")")
|
||||
|
||||
if osvi.majorVersion >= 6:
|
||||
if ze(si.wProcessorArchitecture) == PROCESSOR_ARCHITECTURE_AMD64:
|
||||
result.add(", 64-bit")
|
||||
elif ze(si.wProcessorArchitecture) == PROCESSOR_ARCHITECTURE_INTEL:
|
||||
result.add(", 32-bit")
|
||||
|
||||
else:
|
||||
# Windows 98 etc...
|
||||
result = "Unknown version of windows[Kernel version <= 4]"
|
||||
|
||||
|
||||
proc GetDiskFreeSpaceEx(lpDirectoryName: cstring, lpFreeBytesAvailableToCaller,
|
||||
lpTotalNumberOfBytes, lpTotalNumberOfFreeBytes: var filetime): WINBOOL{.
|
||||
stdcall, dynlib: "kernel32", importc: "GetDiskFreeSpaceExA".}
|
||||
|
||||
proc getPartitionInfo*(partition: string): TPartitionInfo =
|
||||
## Retrieves partition info, for example ``partition`` may be ``"C:\"``
|
||||
var FreeBytes, TotalBytes, TotalFreeBytes: filetime
|
||||
var res = GetDiskFreeSpaceEx(r"C:\", FreeBytes, TotalBytes, TotalFreeBytes)
|
||||
return (rdFileTime(FreeBytes), rdFileTime(TotalBytes))
|
||||
|
||||
when isMainModule:
|
||||
var r = getMemoryInfo()
|
||||
echo("Memory load: ", r.MemoryLoad, "%")
|
||||
var osvi = getVersionInfo()
|
||||
|
||||
echo($osvi)
|
||||
echo(getPartitionInfo(r"C:\")[0])
|
||||
@@ -1,7 +1,7 @@
|
||||
#
|
||||
#
|
||||
# The Nimrod Compiler
|
||||
# (c) Copyright 2009 Andreas Rumpf
|
||||
# (c) Copyright 2010 Andreas Rumpf
|
||||
#
|
||||
# See the file "copying.txt", included in this
|
||||
# distribution, for details about the copyright.
|
||||
@@ -43,14 +43,24 @@ proc newStrNodeT(strVal: string, n: PNode): PNode =
|
||||
result.typ = n.typ
|
||||
result.info = n.info
|
||||
|
||||
proc enumValToString(a: PNode): string =
|
||||
proc ordinalValToString(a: PNode): string =
|
||||
# because $ has the param ordinal[T], `a` is not necessarily an enum, but an
|
||||
# ordinal
|
||||
var x = getInt(a)
|
||||
var n = skipTypes(a.typ, abstractInst).n
|
||||
for i in countup(0, sonsLen(n) - 1):
|
||||
if n.sons[i].kind != nkSym: InternalError(a.info, "enumValToString")
|
||||
var field = n.sons[i].sym
|
||||
if field.position == x: return field.name.s
|
||||
InternalError(a.info, "no symbol for ordinal value: " & $x)
|
||||
|
||||
var t = skipTypes(a.typ, abstractRange)
|
||||
case t.kind
|
||||
of tyChar:
|
||||
result = $chr(int(x) and 0xff)
|
||||
of tyEnum:
|
||||
var n = t.n
|
||||
for i in countup(0, sonsLen(n) - 1):
|
||||
if n.sons[i].kind != nkSym: InternalError(a.info, "ordinalValToString")
|
||||
var field = n.sons[i].sym
|
||||
if field.position == x: return field.name.s
|
||||
InternalError(a.info, "no symbol for ordinal value: " & $x)
|
||||
else:
|
||||
result = $x
|
||||
|
||||
proc evalOp(m: TMagic, n, a, b, c: PNode): PNode =
|
||||
# b and c may be nil
|
||||
@@ -180,7 +190,7 @@ proc evalOp(m: TMagic, n, a, b, c: PNode): PNode =
|
||||
of mFloatToStr: result = newStrNodeT($(getFloat(a)), n)
|
||||
of mCStrToStr, mCharToStr: result = newStrNodeT(getStrOrChar(a), n)
|
||||
of mStrToStr: result = a
|
||||
of mEnumToStr: result = newStrNodeT(enumValToString(a), n)
|
||||
of mEnumToStr: result = newStrNodeT(ordinalValToString(a), n)
|
||||
of mArrToSeq:
|
||||
result = copyTree(a)
|
||||
result.typ = n.typ
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#
|
||||
#
|
||||
# The Nimrod Compiler
|
||||
# (c) Copyright 2009 Andreas Rumpf
|
||||
# (c) Copyright 2010 Andreas Rumpf
|
||||
#
|
||||
# See the file "copying.txt", included in this
|
||||
# distribution, for details about the copyright.
|
||||
@@ -353,14 +353,12 @@ proc typeRel(mapping: var TIdTable, f, a: PType): TTypeRelation =
|
||||
of tyPointer: result = isEqual
|
||||
of tyNil: result = isSubtype
|
||||
of tyRef, tyPtr, tyProc, tyCString: result = isConvertible
|
||||
else:
|
||||
nil
|
||||
else: nil
|
||||
of tyString:
|
||||
case a.kind
|
||||
of tyString: result = isEqual
|
||||
of tyNil: result = isSubtype
|
||||
else:
|
||||
nil
|
||||
else: nil
|
||||
of tyCString:
|
||||
# conversion from string to cstring is automatic:
|
||||
case a.Kind
|
||||
@@ -418,8 +416,8 @@ proc typeRel(mapping: var TIdTable, f, a: PType): TTypeRelation =
|
||||
idTablePut(mapping, f, concrete)
|
||||
result = isGeneric
|
||||
else:
|
||||
InternalError(f.sym.info, "has constraints: " & f.sym.name.s) # check
|
||||
# constraints:
|
||||
InternalError(f.sym.info, "has constraints: " & f.sym.name.s)
|
||||
# check constraints:
|
||||
for i in countup(0, sonsLen(f) - 1):
|
||||
if typeRel(mapping, f.sons[i], a) >= isSubtype:
|
||||
concrete = concreteType(mapping, a)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#
|
||||
#
|
||||
# The Nimrod Compiler
|
||||
# (c) Copyright 2009 Andreas Rumpf
|
||||
# (c) Copyright 2010 Andreas Rumpf
|
||||
#
|
||||
# See the file "copying.txt", included in this
|
||||
# distribution, for details about the copyright.
|
||||
@@ -91,15 +91,14 @@ proc InvalidGenericInst(f: PType): bool =
|
||||
result = (f.kind == tyGenericInst) and (lastSon(f) == nil)
|
||||
|
||||
proc inheritanceDiff(a, b: PType): int =
|
||||
var x, y: PType
|
||||
# conversion to superclass?
|
||||
x = a
|
||||
var x = a
|
||||
result = 0
|
||||
while (x != nil):
|
||||
if x.id == b.id: return
|
||||
x = x.sons[0]
|
||||
dec(result)
|
||||
y = b
|
||||
var y = b
|
||||
result = 0
|
||||
while (y != nil):
|
||||
if y.id == a.id: return
|
||||
@@ -130,11 +129,10 @@ proc isCompatibleToCString(a: PType): bool =
|
||||
result = true
|
||||
|
||||
proc getProcHeader(sym: PSym): string =
|
||||
var n, p: PNode
|
||||
result = sym.name.s & '('
|
||||
n = sym.typ.n
|
||||
var n = sym.typ.n
|
||||
for i in countup(1, sonsLen(n) - 1):
|
||||
p = n.sons[i]
|
||||
var p = n.sons[i]
|
||||
if (p.kind != nkSym): InternalError("getProcHeader")
|
||||
add(result, p.sym.name.s)
|
||||
add(result, ": ")
|
||||
@@ -194,8 +192,7 @@ proc isOrdinalType(t: PType): bool =
|
||||
(t.Kind in {tyRange, tyOrdinal}) and isOrdinalType(t.sons[0])
|
||||
|
||||
proc enumHasWholes(t: PType): bool =
|
||||
var b: PType
|
||||
b = t
|
||||
var b = t
|
||||
while b.kind == tyRange: b = b.sons[0]
|
||||
result = (b.Kind == tyEnum) and (tfEnumHasWholes in b.flags)
|
||||
|
||||
@@ -235,8 +232,11 @@ proc IterOverType(t: PType, iter: TTypeIter, closure: PObject): bool =
|
||||
IntSetInit(marker)
|
||||
result = iterOverTypeAux(marker, t, iter, closure)
|
||||
|
||||
proc searchTypeForAux(t: PType, predicate: TTypePredicate, marker: var TIntSet): bool
|
||||
proc searchTypeNodeForAux(n: PNode, p: TTypePredicate, marker: var TIntSet): bool =
|
||||
proc searchTypeForAux(t: PType, predicate: TTypePredicate,
|
||||
marker: var TIntSet): bool
|
||||
|
||||
proc searchTypeNodeForAux(n: PNode, p: TTypePredicate,
|
||||
marker: var TIntSet): bool =
|
||||
result = false
|
||||
case n.kind
|
||||
of nkRecList:
|
||||
@@ -424,10 +424,7 @@ proc TypeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
|
||||
"set[$1]", "range[$1]", "ptr ", "ref ", "var ", "seq[$1]", "proc",
|
||||
"pointer", "OpenArray[$1]", "string", "CString", "Forward", "int", "int8",
|
||||
"int16", "int32", "int64", "float", "float32", "float64", "float128"]
|
||||
var
|
||||
t: PType
|
||||
prag: string
|
||||
t = typ
|
||||
var t = typ
|
||||
result = ""
|
||||
if t == nil: return
|
||||
if (prefer == preferName) and (t.sym != nil):
|
||||
@@ -486,6 +483,7 @@ proc TypeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
|
||||
if i < sonsLen(t) - 1: add(result, ", ")
|
||||
add(result, ')')
|
||||
if t.sons[0] != nil: add(result, ": " & TypeToString(t.sons[0]))
|
||||
var prag: string
|
||||
if t.callConv != ccDefault: prag = CallingConvToStr[t.callConv]
|
||||
else: prag = ""
|
||||
if tfNoSideEffect in t.flags:
|
||||
@@ -668,11 +666,10 @@ proc sameTuple(a, b: PType, DistinctOf: bool): bool =
|
||||
result = false
|
||||
|
||||
proc SameType(x, y: PType): bool =
|
||||
var a, b: PType
|
||||
if x == y:
|
||||
return true
|
||||
a = skipTypes(x, {tyGenericInst})
|
||||
b = skipTypes(y, {tyGenericInst})
|
||||
var a = skipTypes(x, {tyGenericInst})
|
||||
var b = skipTypes(y, {tyGenericInst})
|
||||
assert(a != nil)
|
||||
assert(b != nil)
|
||||
if a.kind != b.kind:
|
||||
@@ -706,13 +703,12 @@ proc SameType(x, y: PType): bool =
|
||||
result = false
|
||||
|
||||
proc equalOrDistinctOf(x, y: PType): bool =
|
||||
var a, b: PType
|
||||
if x == y:
|
||||
return true
|
||||
if (x == nil) or (y == nil):
|
||||
return false
|
||||
a = skipTypes(x, {tyGenericInst})
|
||||
b = skipTypes(y, {tyGenericInst})
|
||||
var a = skipTypes(x, {tyGenericInst})
|
||||
var b = skipTypes(y, {tyGenericInst})
|
||||
assert(a != nil)
|
||||
assert(b != nil)
|
||||
if a.kind != b.kind:
|
||||
|
||||
@@ -9,30 +9,30 @@ const width = 500
|
||||
const height = 500
|
||||
const outFile = "CairoTest.png"
|
||||
|
||||
var surface = Cairo_ImageSurfaceCreate(CAIRO_FORMAT_RGB24, width, height)
|
||||
var ç = Cairo_Create(surface)
|
||||
var surface = Cairo.ImageSurfaceCreate(CAIRO.FORMAT_RGB24, width, height)
|
||||
var ç = Cairo.Create(surface)
|
||||
|
||||
ç.Cairo_SetSourceRGB(1, 1, 1)
|
||||
ç.Cairo_Paint()
|
||||
ç.SetSourceRGB(1, 1, 1)
|
||||
ç.Paint()
|
||||
|
||||
ç.Cairo_SetLineWidth(10)
|
||||
ç.Cairo_SetLineCap(CAIRO_LINE_CAP_ROUND)
|
||||
ç.SetLineWidth(10)
|
||||
ç.SetLineCap(CAIRO.LINE_CAP_ROUND)
|
||||
|
||||
const count = 12
|
||||
var winc = width / count
|
||||
var hinc = width / count
|
||||
for i in 1 .. count-1:
|
||||
var amount = i / count
|
||||
ç.Cairo_SetSourceRGB(0, 1 - amount, amount)
|
||||
ç.Cairo_MoveTo(i * winc, hinc)
|
||||
ç.Cairo_LineTo(width - i * winc, height - hinc)
|
||||
ç.Cairo_Stroke()
|
||||
ç.SetSourceRGB(0, 1 - amount, amount)
|
||||
ç.MoveTo(i * winc, hinc)
|
||||
ç.LineTo(width - i * winc, height - hinc)
|
||||
ç.Stroke()
|
||||
|
||||
ç.Cairo_SetSourceRGB(1 - amount, 0, amount)
|
||||
ç.Cairo_MoveTo(winc, i * hinc)
|
||||
ç.Cairo_LineTo(width - winc, height - i * hinc)
|
||||
ç.Cairo_Stroke()
|
||||
ç.SetSourceRGB(1 - amount, 0, amount)
|
||||
ç.MoveTo(winc, i * hinc)
|
||||
ç.LineTo(width - winc, height - i * hinc)
|
||||
ç.Stroke()
|
||||
|
||||
echo(surface.Cairo_SurfaceWriteToPNG(outFile))
|
||||
surface.Cairo_SurfaceDestroy()
|
||||
echo(surface.WriteToPNG(outFile))
|
||||
surface.Destroy()
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ tbind1.nim;3
|
||||
tbind3.nim;1
|
||||
tbintre2.nim;halloworld99110223
|
||||
tbintree.nim;halloworld99110223
|
||||
tbug499771.nim;TSubRange: 5 from 1 to 10
|
||||
tbug511622.nim;10
|
||||
tcasestm.nim;ayyy
|
||||
tclosure.nim;2 4 6 8 10
|
||||
|
||||
|
6
tests/accept/run/tbug499771.nim
Executable file
6
tests/accept/run/tbug499771.nim
Executable file
@@ -0,0 +1,6 @@
|
||||
type TSubRange = range[1 .. 10]
|
||||
var sr: TSubRange = 5
|
||||
echo("TSubRange: " & $sr & " from " & $low(TSubRange) & " to " &
|
||||
$high(TSubRange))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user