bugfix: readline wrapper; bugfix: evaluation of type conversions

This commit is contained in:
Araq
2011-02-14 21:20:35 +01:00
parent 55c4074647
commit 5c7e3efbc3
10 changed files with 57 additions and 40 deletions

View File

@@ -271,6 +271,10 @@ Other
This module provides an easy to use sockets-style
Nimrod interface to the OpenSSL library.
* `rdstdin <rdstdin.html>`_
This module contains code for reading from `stdin`:idx:. On UNIX the GNU
readline library is wrapped and set up.
Wrappers
========
@@ -339,6 +343,13 @@ UNIX specific
* `xvlib <xvlib.html>`_
Part of the wrapper for X11.
* `readline <readline.html>`_
Part of the wrapper for the GNU readline library.
* `history <history.html>`_
Part of the wrapper for the GNU readline library.
* `rltypedefs <rltypedefs.html>`_
Part of the wrapper for the GNU readline library.
Regular expressions
-------------------

View File

@@ -238,7 +238,7 @@ The Nimrod compiler supports an `interactive mode`:idx:. This is also known as
a `REPL`:idx: (*read eval print loop*). If Nimrod has been built with the
``-d:useGnuReadline`` switch, it uses the GNU readline library for terminal
input management. To start Nimrod in interactive mode use the command
``nimrod i``. To quit use the ``quit()` command. To determine whether an input
``nimrod i``. To quit use the ``quit()`` command. To determine whether an input
line is an incomplete statement to be continued these rules are used:
1. The line ends with ``[-+*/\\<>!\?\|%&$@~,;:=#^]\s*$``.

View File

@@ -34,4 +34,3 @@ else:
# disable auto-complete:
discard readline.bind_key('\t'.ord, readline.abort)

View File

@@ -19,15 +19,11 @@
#
{.deadCodeElim: on.}
when defined(windows):
const
historyDll = "history.dll"
elif defined(macosx):
const
historyDll = "libhistory.dynlib"
else:
const
historyDll = "libhistory.so.6(|.0)"
import readline
const
historyDll = readlineDll
import times, rltypedefs

View File

@@ -21,13 +21,14 @@
{.deadCodeElim: on.}
when defined(windows):
const
readlineDll = "readline.dll"
readlineDll* = "readline.dll"
elif defined(macosx):
# Mac OS X ships with 'libedit'
const
readlineDll = "libreadline.dynlib"
readlineDll* = "libedit(.2|.1|).dylib"
else:
const
readlineDll = "libreadline.so.6(|.0)"
readlineDll* = "libreadline.so.6(|.0)"
## mangle "'TCommandFunc'" TCommandFunc
## mangle TvcpFunc TvcpFunc

View File

@@ -462,9 +462,13 @@ proc evalAddr(c: PEvalContext, n: PNode, flags: TEvalFlags): PNode =
addSon(result, a)
proc evalConv(c: PEvalContext, n: PNode): PNode =
# hm, I cannot think of any conversions that need to be handled here...
result = evalAux(c, n.sons[1], {})
result.typ = n.typ
result = evalAux(c, n.sons[1], {efLValue})
if isSpecial(result): return
var a = result
result = foldConv(n, a)
if result == nil:
# foldConv() cannot deal with everything that we want to do here:
result = a
proc evalCheckedFieldAccess(c: PEvalContext, n: PNode,
flags: TEvalFlags): PNode =

View File

@@ -293,6 +293,28 @@ proc getAppType(n: PNode): PNode =
else:
result = newStrNodeT("console", n)
proc foldConv*(n, a: PNode): PNode =
case skipTypes(n.typ, abstractRange).kind
of tyInt..tyInt64:
case skipTypes(a.typ, abstractRange).kind
of tyFloat..tyFloat64: result = newIntNodeT(system.toInt(getFloat(a)), n)
of tyChar: result = newIntNodeT(getOrdValue(a), n)
else:
result = a
result.typ = n.typ
of tyFloat..tyFloat64:
case skipTypes(a.typ, abstractRange).kind
of tyInt..tyInt64, tyEnum, tyBool, tyChar:
result = newFloatNodeT(toFloat(int(getOrdValue(a))), n)
else:
result = a
result.typ = n.typ
of tyOpenArray, tyProc:
nil
else:
result = a
result.typ = n.typ
proc getConstExpr(m: PSym, n: PNode): PNode =
result = nil
case n.kind
@@ -422,27 +444,6 @@ proc getConstExpr(m: PSym, n: PNode): PNode =
of nkHiddenStdConv, nkHiddenSubConv, nkConv, nkCast:
var a = getConstExpr(m, n.sons[1])
if a == nil: return
case skipTypes(n.typ, abstractRange).kind
of tyInt..tyInt64:
case skipTypes(a.typ, abstractRange).kind
of tyFloat..tyFloat64: result = newIntNodeT(system.toInt(getFloat(a)), n)
of tyChar: result = newIntNodeT(getOrdValue(a), n)
else:
result = a
result.typ = n.typ
of tyFloat..tyFloat64:
case skipTypes(a.typ, abstractRange).kind
of tyInt..tyInt64, tyEnum, tyBool, tyChar:
result = newFloatNodeT(toFloat(int(getOrdValue(a))), n)
else:
result = a
result.typ = n.typ
of tyOpenArray, tyProc:
nil
else:
#n.sons[1] := a;
#result := n;
result = a
result.typ = n.typ
result = foldConv(n, a)
else:
nil

View File

@@ -720,7 +720,7 @@ proc transform(c: PTransf, n: PNode): PTransNode =
result = transformSons(c, n)
var cnst = getConstExpr(c.module, PNode(result))
if cnst != nil:
result = PTransNode(cnst) # do not miss an optimization
result = PTransNode(cnst) # do not miss an optimization
proc processTransf(context: PPassContext, n: PNode): PNode =
# Note: For interactive mode we cannot call 'passes.skipCodegen' and skip

View File

@@ -1,4 +1,5 @@
- 'suggest'
- Bug: var x = 89; float(x)
- thread support: threadvar on Windows seems broken;
add --deadlock_prevention:on|off switch

View File

@@ -37,6 +37,7 @@ srcdoc: "pure/httpserver;pure/httpclient;pure/stmp;impure/ssl"
srcdoc: "pure/ropes;pure/unidecode/unidecode;pure/xmldom;pure/xmldomparser"
srcdoc: "pure/xmlparser;pure/htmlparser;pure/xmltree;pure/colors"
srcdoc: "pure/json;pure/base64;pure/scgi;impure/graphics"
srcdoc: "impure/rdstdin"
webdoc: "wrappers/libcurl;pure/md5;wrappers/mysql;wrappers/iup"
webdoc: "wrappers/sqlite3;wrappers/postgres;wrappers/tinyc"
@@ -49,4 +50,7 @@ webdoc: "wrappers/cairo"
webdoc: "wrappers/gtk"
webdoc: "windows"
webdoc: "wrappers/x11;wrappers/opengl;wrappers/sdl;wrappers/lua"
webdoc: "wrappers/readline/readline;wrappers/readline/history"
webdoc: "wrappers/readline/rltypedefs"