This commit is contained in:
Araq 2012-10-19 20:45:26 +02:00
commit 172b6aacf8
4 changed files with 57 additions and 10 deletions

View file

@ -555,10 +555,10 @@ proc genDeref(p: BProc, e: PNode, d: var TLoc) =
putIntoDest(p, d, a.t.sons[0], ropef("(*$1)", [rdLoc(a)])) putIntoDest(p, d, a.t.sons[0], ropef("(*$1)", [rdLoc(a)]))
proc genAddr(p: BProc, e: PNode, d: var TLoc) = proc genAddr(p: BProc, e: PNode, d: var TLoc) =
var a: TLoc
if mapType(e.sons[0].typ) == ctArray: if mapType(e.sons[0].typ) == ctArray:
expr(p, e.sons[0], d) expr(p, e.sons[0], d)
else: else:
var a: TLoc
InitLocExpr(p, e.sons[0], a) InitLocExpr(p, e.sons[0], a)
putIntoDest(p, d, e.typ, addrLoc(a)) putIntoDest(p, d, e.typ, addrLoc(a))
@ -1634,7 +1634,8 @@ proc downConv(p: BProc, n: PNode, d: var TLoc) =
var a: TLoc var a: TLoc
initLocExpr(p, n.sons[0], a) initLocExpr(p, n.sons[0], a)
var r = rdLoc(a) var r = rdLoc(a)
if skipTypes(n.sons[0].typ, abstractInst).kind in {tyRef, tyPtr, tyVar}: if skipTypes(n.sons[0].typ, abstractInst).kind in {tyRef, tyPtr, tyVar} and
n.sons[0].kind notin {nkHiddenAddr, nkAddr}:
app(r, "->Sup") app(r, "->Sup")
for i in countup(2, abs(inheritanceDiff(dest, src))): app(r, ".Sup") for i in countup(2, abs(inheritanceDiff(dest, src))): app(r, ".Sup")
r = con("&", r) r = con("&", r)

View file

@ -86,14 +86,7 @@ Lexical elements
Let us look at Nimrod's lexical elements in more detail: like other Let us look at Nimrod's lexical elements in more detail: like other
programming languages Nimrod consists of (string) literals, identifiers, programming languages Nimrod consists of (string) literals, identifiers,
keywords, comments, operators, and other punctuation marks. Case is keywords, comments, operators, and other punctuation marks.
*insignificant* in Nimrod and even underscores are ignored:
``This_is_an_identifier`` and ``ThisIsAnIdentifier`` are the same identifier.
This feature enables you to use other
people's code without bothering about a naming convention that conflicts with
yours. A Nimrod-aware editor or IDE can show the identifiers as
preferred. It also frees you from remembering the exact spelling of an
identifier (was it ``parseURL`` or ``parseUrl`` or ``parse_URL``?).
String and character literals String and character literals

View file

@ -0,0 +1,52 @@
discard """
output: '''Subobject test called
5'''
"""
type
TClassOfTCustomObject {.pure, inheritable.} = object
base* : ptr TClassOfTCustomObject
className* : string
TClassOfTobj = object of TClassOfTCustomObject
nil
TCustomObject = ref object {.inheritable.}
class* : ptr TClassOfTCustomObject
TObj = ref object of TCustomObject
data: int
var ClassOfTObj: TClassOfTObj
proc initClassOfTObj() =
ClassOfTObj.base = nil
ClassOfTObj.className = "TObj"
initClassOfTObj()
proc initialize*(self: TObj) =
self.class = addr ClassOfTObj
# this generates wrong C code: && instead of &
proc newInstance(T: typedesc): T =
mixin initialize
new(result)
initialize(result)
var o = TObj.newInstance()
type
TestObj* = object of TObject
t:int
SubObject* = object of TestObj
method test*(t:var TestObj) =
echo "test called"
method test*(t:var SubObject) =
echo "Subobject test called"
t.t= 5
var a: SubObject
a.test()
echo a.t

View file

@ -359,6 +359,7 @@ proc main() =
writeResults(rejectJson, r) writeResults(rejectJson, r)
of "compile": of "compile":
compile(r, "tests/compile/t*.nim", p.cmdLineRest.string) compile(r, "tests/compile/t*.nim", p.cmdLineRest.string)
compile(r, "tests/ccg/t*.nim", p.cmdLineRest.string)
compile(r, "tests/ecmas.nim", p.cmdLineRest.string) compile(r, "tests/ecmas.nim", p.cmdLineRest.string)
compileExample(r, "lib/pure/*.nim", p.cmdLineRest.string) compileExample(r, "lib/pure/*.nim", p.cmdLineRest.string)
compileExample(r, "examples/*.nim", p.cmdLineRest.string) compileExample(r, "examples/*.nim", p.cmdLineRest.string)