devel of web frontend

This commit is contained in:
rumpf_a@web.de
2010-01-10 17:53:33 +01:00
parent a4ba67dd2e
commit 55e900bba2
9 changed files with 189 additions and 9 deletions

View File

@@ -15,6 +15,7 @@ cc = gcc
@end
path="$lib/pure"
path="$lib/devel"
path="$lib/impure"
path="$lib/wrappers"
path="$lib/wrappers/cairo"

View File

@@ -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 =

View File

@@ -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

View File

@@ -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
#+-------------------------------------------------------------------------

View File

@@ -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".}

64
noprefix.nim Normal file
View File

@@ -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)

View File

@@ -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))

71
rod/webrepl.nim Normal file
View File

@@ -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)

39
tests/tcolors.nim Normal file
View File

@@ -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)