diff options
-rwxr-xr-x | config/nimrod.cfg | 1 | ||||
-rwxr-xr-x | lib/devel/httpserver.nim | 6 | ||||
-rwxr-xr-x | lib/pure/osproc.nim | 4 | ||||
-rwxr-xr-x | lib/windows/shellapi.nim | 1 | ||||
-rwxr-xr-x | lib/windows/winlean.nim | 6 | ||||
-rw-r--r-- | noprefix.nim | 64 | ||||
-rwxr-xr-x | rod/main.nim | 6 | ||||
-rw-r--r-- | rod/webrepl.nim | 71 | ||||
-rw-r--r-- | tests/tcolors.nim | 39 |
9 files changed, 189 insertions, 9 deletions
diff --git a/config/nimrod.cfg b/config/nimrod.cfg index 5f4c12786..6a9289a5e 100755 --- a/config/nimrod.cfg +++ b/config/nimrod.cfg @@ -15,6 +15,7 @@ cc = gcc @end path="$lib/pure" +path="$lib/devel" path="$lib/impure" path="$lib/wrappers" path="$lib/wrappers/cairo" diff --git a/lib/devel/httpserver.nim b/lib/devel/httpserver.nim index 285dadf0a..be317c952 100755 --- a/lib/devel/httpserver.nim +++ b/lib/devel/httpserver.nim @@ -12,7 +12,7 @@ import strutils, os, osproc, strtabs, streams, sockets const - wwwNL = "\r\L" + wwwNL* = "\r\L" ServerSig = "Server: httpserver.nim/1.0.0" & wwwNL # --------------- output messages -------------------------------------------- @@ -222,12 +222,12 @@ proc run*(handleRequest: proc (client: TSocket, path, query: string): bool, ## encapsulates the server object and main loop var s: TServer open(s, port) - echo("httpserver running on port ", s.port) + #echo("httpserver running on port ", s.port) while true: next(s) if handleRequest(s.client, s.path, s.query): break close(s.client) - close(s.socket) + close(s) when false: proc main = diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim index d76825531..bbdea1eee 100755 --- a/lib/pure/osproc.nim +++ b/lib/pure/osproc.nim @@ -1,7 +1,7 @@ # # # Nimrod's Runtime Library -# (c) Copyright 2009 Andreas Rumpf +# (c) Copyright 2010 Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. @@ -33,7 +33,7 @@ type TProcessOption* = enum ## options that can be passed `startProcess` poEchoCmd, ## echo the command before execution poUseShell, ## use the shell to execute the command; NOTE: This - ## often creates a security whole! + ## often creates a security hole! poStdErrToStdOut, ## merge stdout and stderr to the stdout stream poParentStreams ## use the parent's streams diff --git a/lib/windows/shellapi.nim b/lib/windows/shellapi.nim index af6972c96..a4a976c60 100755 --- a/lib/windows/shellapi.nim +++ b/lib/windows/shellapi.nim @@ -6,6 +6,7 @@ # See the file "copying.txt", included in this # distribution, for details about the copyright. # + # leave out unused functions so the unit can be used on win2000 as well #+------------------------------------------------------------------------- diff --git a/lib/windows/winlean.nim b/lib/windows/winlean.nim index d6ef9ffbb..f384a04e8 100755 --- a/lib/windows/winlean.nim +++ b/lib/windows/winlean.nim @@ -60,6 +60,8 @@ const STD_ERROR_HANDLE* = -12'i32 DETACHED_PROCESS* = 8'i32 + + SW_SHOWNORMAL* = 1'i32 proc CloseHandle*(hObject: THANDLE): WINBOOL {.stdcall, dynlib: "kernel32", importc: "CloseHandle".} @@ -190,4 +192,8 @@ proc rdFileTime*(f: FILETIME): int64 = proc Sleep*(dwMilliseconds: int32){.stdcall, dynlib: "kernel32", importc: "Sleep".} +proc ShellExecute*(HWND: THandle, lpOperation, lpFile, + lpParameters, lpDirectory: cstring, + nShowCmd: int32): THandle{. + stdcall, dynlib: "shell32.dll", importc: "ShellExecuteA".} diff --git a/noprefix.nim b/noprefix.nim new file mode 100644 index 000000000..e7ec26c56 --- /dev/null +++ b/noprefix.nim @@ -0,0 +1,64 @@ +# strip those silly GTK/ATK prefixes... + +import + expandimportc, os + +const + filelist = [ + ("sdl/sdl", "sdl"), + ("sdl/sdl_net", "sdl"), + ("sdl/sdl_gfx", "sdl"), + ("sdl/sdl_image", "sdl"), + ("sdl/sdl_mixer_nosmpeg", "sdl"), + ("sdl/sdl_mixer", "sdl"), + ("sdl/sdl_ttf", "sdl"), + ("sdl/smpeg", "sdl"), + + ("libcurl", "curl"), + ("mysql", "mysql"), + ("postgres", ""), + ("sqlite3", "sqlite3"), + ("tcl", "tcl"), + ("cairo/cairo", "cairo"), + ("cairo/cairoft", "cairo"), + ("cairo/cairowin32", "cairo"), + ("cairo/cairoxlib", "cairo"), + + ("gtk/atk", "atk"), + ("gtk/gdk2", "gdk"), + ("gtk/gdk2pixbuf", "gdk"), + ("gtk/gdkglext", "gdk"), + ("gtk/glib2", ""), + ("gtk/gtk2", "gtk"), + ("gtk/gtkglext", "gtk"), + ("gtk/gtkhtml", "gtk"), + ("gtk/libglade2", "glade"), + ("gtk/pango", "pango"), + ("gtk/pangoutils", "pango"), + + ("lua/lua", "lua"), + ("lua/lauxlib", "luaL"), + ("lua/lualib", "lua"), + + ("opengl/gl", ""), + ("opengl/glext", ""), + ("opengl/wingl", ""), + ("opengl/glu", ""), + ("opengl/glut", ""), + ("opengl/glx", ""), + + ("pcre/pcre", "pcre") + ] + +proc createDirs = + createDir("lib/newwrap/sdl") + createDir("lib/newwrap/cairo") + createDir("lib/newwrap/gtk") + createDir("lib/newwrap/lua") + createDir("lib/newwrap/opengl") + createDir("lib/newwrap/pcre") + +for filename, prefix in items(filelist): + var f = addFileExt(filename, "nim") + main("lib/wrappers" / f, "lib/newwrap" / f, prefix) + diff --git a/rod/main.nim b/rod/main.nim index d386a10aa..6cdd026b5 100755 --- a/rod/main.nim +++ b/rod/main.nim @@ -170,15 +170,13 @@ proc exSymbols(n: PNode) = proc CommandExportSymbols(filename: string) = # now unused! - var module: PNode - module = parseFile(addFileExt(filename, NimExt)) + var module = parseFile(addFileExt(filename, NimExt)) if module != nil: exSymbols(module) renderModule(module, getOutFile(filename, "pretty." & NimExt)) proc CommandPretty(filename: string) = - var module: PNode - module = parseFile(addFileExt(filename, NimExt)) + var module = parseFile(addFileExt(filename, NimExt)) if module != nil: renderModule(module, getOutFile(filename, "pretty." & NimExt)) diff --git a/rod/webrepl.nim b/rod/webrepl.nim new file mode 100644 index 000000000..bf59bbfec --- /dev/null +++ b/rod/webrepl.nim @@ -0,0 +1,71 @@ +# +# +# The Nimrod Compiler +# (c) Copyright 2010 Andreas Rumpf +# +# See the file "copying.txt", included in this +# distribution, for details about the copyright. +# + +## Creates a server, opens a browser and starts serving a Repl for the user. +## Unfortunately it doesn't ever stop... + +import httpserver, sockets, browsers, strutils, cgi, options + +const + gui = """ +<html> + <head> + <title>Nimrod Interactive Web Console</title> + </head> + + <body> + <form action="exec" method="get"> + <input type="submit" value="Run" /><br /> + <textarea name="code" cols="80" rows="30">import strutils, os + +# your code here</textarea> + <table border="0"> + <tr> + <td><input type="checkbox" name="objChecks" checked="true" + value="on">objChecks</input></td> + <td><input type="checkbox" name="fieldChecks" checked="true" + value="on">fieldChecks</input></td> + <td><input type="checkbox" name="rangeChecks" checked="true" + value="on">rangeChecks</input></td> + </tr><tr> + <td><input type="checkbox" name="boundChecks" checked="true" + value="on">boundChecks</input></td> + <td><input type="checkbox" name="overflowChecks" checked="true" + value="on">overflowChecks</input></td> + <td><input type="checkbox" name="nanChecks" checked="true" + value="on">nanChecks</input></td> + </tr><tr> + <td><input type="checkbox" name="infChecks" checked="true" + value="on">infChecks</input></td> + <td><input type="checkbox" name="assertions" checked="true" + value="on">assertions</input></td> + </tr> + </table> + </form> + $1 + </body> +</html> +""" + +proc runCode(input: string): string = + nil + +proc handleRequest(client: TSocket, path, query: string) = + var output = query + client.send(gui % output & wwwNL) + + +var s: TServer +open(s, TPort(0)) +browsers.openDefaultBrowser("http://localhost:" & $s.port) +while true: + next(s) + handleRequest(s.client, s.path, s.query) + close(s.client) +close(s) diff --git a/tests/tcolors.nim b/tests/tcolors.nim new file mode 100644 index 000000000..9d1034405 --- /dev/null +++ b/tests/tcolors.nim @@ -0,0 +1,39 @@ +import strutils + +type + TColor = distinct int32 + +proc rgb(r, g, b: range[0..255]): TColor = + result = TColor(r or g shl 8 or b shl 16) + +proc `$`(c: TColor): string = + result = "#" & toHex(int32(c), 6) + +echo rgb(34, 55, 255) + +when false: + type + TColor = distinct int32 + TColorComponent = distinct int8 + + proc red(a: TColor): TColorComponent = + result = TColorComponent(int32(a) and 0xff'i32) + + proc green(a: TColor): TColorComponent = + result = TColorComponent(int32(a) shr 8'i32 and 0xff'i32) + + proc blue(a: TColor): TColorComponent = + result = TColorComponent(int32(a) shr 16'i32 and 0xff'i32) + + proc rgb(r, g, b: range[0..255]): TColor = + result = TColor(r or g shl 8 or b shl 8) + + proc `+!` (a, b: TColorComponent): TColorComponent = + ## saturated arithmetic: + result = TColorComponent(min(ze(int8(a)) + ze(int8(b)), 255)) + + proc `+` (a, b: TColor): TColor = + ## saturated arithmetic for colors makes sense, I think: + return rgb(red(a) +! red(b), green(a) +! green(b), blue(a) +! blue(b)) + + rgb(34, 55, 255) |