summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2011-07-31 00:21:32 +0200
committerAraq <rumpf_a@web.de>2011-07-31 00:21:32 +0200
commit6a8a409f1b8694e380e27afddff3cd9c29452b8c (patch)
tree4dcda408e2db40d0ce6b243c74d9160cad54c6c1 /compiler
parent2d62738bbb5e7a664fab3f7a49313b5fb839a47c (diff)
downloadNim-6a8a409f1b8694e380e27afddff3cd9c29452b8c.tar.gz
preparation for new 'is' operator; breaks bootstrapping again, sorry (use generated C code)
Diffstat (limited to 'compiler')
-rwxr-xr-xcompiler/ast.nim3
-rwxr-xr-xcompiler/ccgexprs.nim8
-rwxr-xr-xcompiler/cgmeth.nim2
-rwxr-xr-xcompiler/evals.nim6
-rwxr-xr-xcompiler/msgs.nim10
-rwxr-xr-xcompiler/parser.nim2
-rwxr-xr-xcompiler/semexprs.nim24
-rwxr-xr-xcompiler/semtypes.nim7
-rwxr-xr-xcompiler/types.nim3
9 files changed, 44 insertions, 21 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim
index 58ef9f6c2..817b37d60 100755
--- a/compiler/ast.nim
+++ b/compiler/ast.nim
@@ -310,7 +310,7 @@ type
   TSymKinds* = set[TSymKind]
 
   TMagic* = enum # symbols that require compiler magic:
-    mNone, mDefined, mDefinedInScope, mLow, mHigh, mSizeOf, mIs, 
+    mNone, mDefined, mDefinedInScope, mLow, mHigh, mSizeOf, mIs, mOf,
     mEcho, mShallowCopy,
     mUnaryLt, mSucc, 
     mPred, mInc, mDec, mOrd, mNew, mNewFinalize, mNewSeq, mLengthOpenArray, 
@@ -346,6 +346,7 @@ type
     mOrdinal, mInt, mInt8, mInt16, mInt32, 
     mInt64, mFloat, mFloat32, mFloat64, mBool, mChar, mString, mCstring, 
     mPointer, mEmptySet, mIntSetBaseType, mNil, mExpr, mStmt, mTypeDesc, 
+    mVoidType,
     mIsMainModule, mCompileDate, mCompileTime, mNimrodVersion, mNimrodMajor, 
     mNimrodMinor, mNimrodPatch, mCpuEndian, mHostOS, mHostCPU, mAppType, 
     mNaN, mInf, mNegInf, 
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim
index e92673909..1e30df7ad 100755
--- a/compiler/ccgexprs.nim
+++ b/compiler/ccgexprs.nim
@@ -962,7 +962,7 @@ proc genNewSeq(p: BProc, e: PNode) =
                genTypeInfo(p.module, seqType), rdLoc(b)])
   genAssignment(p, a, c, {})
 
-proc genIs(p: BProc, x: PNode, typ: PType, d: var TLoc) =
+proc genOf(p: BProc, x: PNode, typ: PType, d: var TLoc) =
   var
     a: TLoc
     dest, t: PType
@@ -987,8 +987,8 @@ proc genIs(p: BProc, x: PNode, typ: PType, d: var TLoc) =
     r = ropecg(p.module, "#isObj($1.m_type, $2)", [r, genTypeInfo(p.module, dest)])
   putIntoDest(p, d, getSysType(tyBool), r)
 
-proc genIs(p: BProc, n: PNode, d: var TLoc) =
-  genIs(p, n.sons[1], n.sons[2].typ, d)
+proc genOf(p: BProc, n: PNode, d: var TLoc) =
+  genOf(p, n.sons[1], n.sons[2].typ, d)
 
 proc genNewFinalize(p: BProc, e: PNode) =
   var
@@ -1438,7 +1438,7 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
       filen = makeCString(ToFilename(e.info))
       appcg(p, cpsStmts, "#internalAssert($1, $2, $3);$n",
            [filen, line, rdLoc(d)])
-  of mIs: genIs(p, e, d)
+  of mOf: genOf(p, e, d)
   of mNew: genNew(p, e)
   of mNewFinalize: genNewFinalize(p, e)
   of mNewSeq: genNewSeq(p, e)
diff --git a/compiler/cgmeth.nim b/compiler/cgmeth.nim
index dd1ab944e..2751e0900 100755
--- a/compiler/cgmeth.nim
+++ b/compiler/cgmeth.nim
@@ -127,7 +127,7 @@ proc genDispatcher(methods: TSymSeq, relevantCols: TIntSet): PSym =
   var paramLen = sonsLen(base.typ)
   var disp = newNodeI(nkIfStmt, base.info)
   var ands = getSysSym("and")
-  var iss = getSysSym("is")
+  var iss = getSysSym("of")
   for meth in countup(0, high(methods)):
     var curr = methods[meth]      # generate condition:
     var cond: PNode = nil
diff --git a/compiler/evals.nim b/compiler/evals.nim
index 9aa67de3e..1ccf0d599 100755
--- a/compiler/evals.nim
+++ b/compiler/evals.nim
@@ -614,8 +614,8 @@ proc evalHigh(c: PEvalContext, n: PNode): PNode =
   of tyOpenArray, tySequence: result = newIntNodeT(sonsLen(result), n)
   of tyString: result = newIntNodeT(len(result.strVal) - 1, n)
   else: InternalError(n.info, "evalHigh")
-  
-proc evalIs(c: PEvalContext, n: PNode): PNode = 
+
+proc evalOf(c: PEvalContext, n: PNode): PNode = 
   result = evalAux(c, n.sons[1], {})
   if isSpecial(result): return 
   result = newIntNodeT(ord(inheritanceDiff(result.typ, n.sons[2].typ) >= 0), n)
@@ -755,7 +755,7 @@ proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode =
   var m = getMagic(n)
   case m
   of mNone: result = evalCall(c, n)
-  of mIs: result = evalIs(c, n)
+  of mOf: result = evalOf(c, n)
   of mSizeOf: internalError(n.info, "sizeof() should have been evaluated")
   of mHigh: result = evalHigh(c, n)
   of mAssert: result = evalAssert(c, n)
diff --git a/compiler/msgs.nim b/compiler/msgs.nim
index 27b5c7f67..c3aa30891 100755
--- a/compiler/msgs.nim
+++ b/compiler/msgs.nim
@@ -82,8 +82,10 @@ type
     errInvalidIndexValueForTuple, errCommandExpectsFilename, errXExpected, 
     errInvalidSectionStart, errGridTableNotImplemented, errGeneralParseError, 
     errNewSectionExpected, errWhitespaceExpected, errXisNoValidIndexFile, 
-    errCannotRenderX, errVarVarTypeNotAllowed, errIsExpectsTwoArguments, 
-    errIsExpectsObjectTypes, errXcanNeverBeOfThisSubtype, errTooManyIterations, 
+    errCannotRenderX, errVarVarTypeNotAllowed, 
+    
+    errXExpectsTwoArguments, 
+    errXExpectsObjectTypes, errXcanNeverBeOfThisSubtype, errTooManyIterations, 
     errCannotInterpretNodeX, errFieldXNotFound, errInvalidConversionFromTypeX, 
     errAssertionFailed, errCannotGenerateCodeForX, errXRequiresOneArgument, 
     errUnhandledExceptionX, errCyclicTree, errXisNoMacroOrTemplate, 
@@ -298,8 +300,8 @@ const
     errXisNoValidIndexFile: "\'$1\' is no valid index file", 
     errCannotRenderX: "cannot render reStructuredText element \'$1\'", 
     errVarVarTypeNotAllowed: "type \'var var\' is not allowed",
-    errIsExpectsTwoArguments: "\'is\' expects two arguments", 
-    errIsExpectsObjectTypes: "\'is\' expects object types",
+    errXExpectsTwoArguments: "\'$1\' expects two arguments", 
+    errXExpectsObjectTypes: "\'$1\' expects object types",
     errXcanNeverBeOfThisSubtype: "\'$1\' can never be of this subtype", 
     errTooManyIterations: "interpretation requires too many iterations", 
     errCannotInterpretNodeX: "cannot interpret node kind \'$1\'", 
diff --git a/compiler/parser.nim b/compiler/parser.nim
index aca891863..003bd9219 100755
--- a/compiler/parser.nim
+++ b/compiler/parser.nim
@@ -154,7 +154,7 @@ proc getPrecedence(tok: TToken): int =
     of '.': result = 5
     else: result = 1
   of tkDiv, tkMod, tkShl, tkShr: result = 8
-  of tkIn, tkNotIn, tkIs, tkIsNot, tkNot: result = 4
+  of tkIn, tkNotIn, tkIs, tkIsNot, tkNot, tkOf: result = 4
   of tkDotDot: result = 5
   of tkAnd: result = 3
   of tkOr, tkXor: result = 2
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index 28076754f..ac375e793 100755
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -202,20 +202,39 @@ proc semSizeof(c: PContext, n: PNode): PNode =
   n.typ = getSysType(tyInt)
   result = n
 
+proc semOf(c: PContext, n: PNode): PNode = 
+  if sonsLen(n) == 3: 
+    #LocalError(n.info, errXcanNeverBeOfThisSubtype, " CAME HERE")
+    n.sons[1] = semExprWithType(c, n.sons[1], {efAllowType})
+    n.sons[2] = semExprWithType(c, n.sons[2], {efAllowType})
+    var a = skipTypes(n.sons[1].typ, abstractPtrs)
+    var b = skipTypes(n.sons[2].typ, abstractPtrs)
+    if b.kind != tyObject or a.kind != tyObject: 
+      GlobalError(n.info, errXExpectsObjectTypes, "of")
+    while b != nil and b.id != a.id: b = b.sons[0]
+    if b == nil:
+      GlobalError(n.info, errXcanNeverBeOfThisSubtype, typeToString(a))
+    n.typ = getSysType(tyBool)
+  else: 
+    GlobalError(n.info, errXExpectsTwoArguments, "of")
+  result = n
+
 proc semIs(c: PContext, n: PNode): PNode = 
+  GlobalError(n.info, errXExpectsTwoArguments, "is")
   if sonsLen(n) == 3: 
+    #LocalError(n.info, errXcanNeverBeOfThisSubtype, " CAME HERE")
     n.sons[1] = semExprWithType(c, n.sons[1], {efAllowType})
     n.sons[2] = semExprWithType(c, n.sons[2], {efAllowType})
     var a = skipTypes(n.sons[1].typ, abstractPtrs)
     var b = skipTypes(n.sons[2].typ, abstractPtrs)
     if b.kind != tyObject or a.kind != tyObject: 
-      GlobalError(n.info, errIsExpectsObjectTypes)
+      GlobalError(n.info, errXExpectsObjectTypes, "is")
     while b != nil and b.id != a.id: b = b.sons[0]
     if b == nil:
       GlobalError(n.info, errXcanNeverBeOfThisSubtype, typeToString(a))
     n.typ = getSysType(tyBool)
   else: 
-    GlobalError(n.info, errIsExpectsTwoArguments)
+    GlobalError(n.info, errXExpectsTwoArguments, "is")
   result = n
 
 proc semOpAux(c: PContext, n: PNode) = 
@@ -884,6 +903,7 @@ proc semMagic(c: PContext, n: PNode, s: PSym, flags: TExprFlags): PNode =
   of mHigh: result = semLowHigh(c, setMs(n, s), mHigh)
   of mSizeOf: result = semSizeof(c, setMs(n, s))
   of mIs: result = semIs(c, setMs(n, s))
+  of mOf: result = semOf(c, setMs(n, s))
   of mEcho: result = semEcho(c, setMs(n, s))
   of mShallowCopy:
     if sonsLen(n) == 3:
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim
index fb7f46007..400844902 100755
--- a/compiler/semtypes.nim
+++ b/compiler/semtypes.nim
@@ -220,15 +220,15 @@ proc semGeneric(c: PContext, n: PNode, s: PSym, prev: PType): PType =
   var 
     elem: PType
     isConcrete: bool
-  if (s.typ == nil) or (s.typ.kind != tyGenericBody): 
+  if s.typ == nil or s.typ.kind != tyGenericBody: 
     GlobalError(n.info, errCannotInstantiateX, s.name.s)
   result = newOrPrevType(tyGenericInvokation, prev, c)
-  if (s.typ.containerID == 0): InternalError(n.info, "semtypes.semGeneric")
+  if s.typ.containerID == 0: InternalError(n.info, "semtypes.semGeneric")
   if sonsLen(n) != sonsLen(s.typ): 
     GlobalError(n.info, errWrongNumberOfArguments)
   addSon(result, s.typ)
   isConcrete = true           # iterate over arguments:
-  for i in countup(1, sonsLen(n) - 1): 
+  for i in countup(1, sonsLen(n)-1): 
     elem = semTypeNode(c, n.sons[i], nil)
     if elem.kind == tyGenericParam: isConcrete = false
     addSon(result, elem)
@@ -704,6 +704,7 @@ proc processMagicType(c: PContext, m: PSym) =
   of mExpr: setMagicType(m, tyExpr, 0)
   of mStmt: setMagicType(m, tyStmt, 0)
   of mTypeDesc: setMagicType(m, tyTypeDesc, 0)
+  of mVoidType: setMagicType(m, tyEmpty, 0)
   of mArray, mOpenArray, mRange, mSet, mSeq, mOrdinal: nil 
   else: GlobalError(m.info, errTypeExpected)
   
diff --git a/compiler/types.nim b/compiler/types.nim
index 2e4262ecc..bfa20066f 100755
--- a/compiler/types.nim
+++ b/compiler/types.nim
@@ -361,11 +361,10 @@ proc canFormAcycleNode(marker: var TIntSet, n: PNode, startId: int): bool =
           if result: return 
   
 proc canFormAcycleAux(marker: var TIntSet, typ: PType, startId: int): bool = 
-  var t: PType
   result = false
   if typ == nil: return 
   if tfAcyclic in typ.flags: return 
-  t = skipTypes(typ, abstractInst)
+  var t = skipTypes(typ, abstractInst)
   if tfAcyclic in t.flags: return 
   case t.kind
   of tyTuple, tyObject, tyRef, tySequence, tyArray, tyArrayConstr, tyOpenArray: