preparation for new 'is' operator; breaks bootstrapping again, sorry (use generated C code)

This commit is contained in:
Araq 2011-07-31 00:21:32 +02:00
commit 6a8a409f1b
19 changed files with 86 additions and 203 deletions

View file

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

View file

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

View file

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

View file

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

View file

@ -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\'",

View file

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

View file

@ -202,20 +202,39 @@ proc semSizeof(c: PContext, n: PNode): PNode =
n.typ = getSysType(tyInt)
result = n
proc semIs(c: PContext, n: PNode): PNode =
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, errIsExpectsObjectTypes)
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, errIsExpectsTwoArguments)
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, 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, 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:

View file

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

View file

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