import ast, modulegraphs, magicsys, lineinfos, options, cgmeth, types import std/[algorithm, tables, intsets, assertions] proc genVTableDispatcher(g: ModuleGraph; methods: seq[PSym]; index: int): PSym = #[ proc dispatch(x: Base, params: ...) = cast[proc bar(x: Base, params: ...)](x.vTable[index])(x, params) ]# var base = methods[0].ast[dispatcherPos].sym result = base var paramLen = base.typ.signatureLen var body = newNodeI(nkStmtList, base.info) var disp = newNodeI(nkIfStmt, base.info) var vTableAccess = newNodeIT(nkBracketExpr, base.info, base.typ) let nimGetVTableSym = getCompilerProc(g, "nimGetVTable") let ptrPNimType = nimGetVTableSym.typ.n[1].sym.typ var nTyp = base.typ.n[1].sym.typ var dispatchObject = newSymNode(base.typ.n[1].sym) if nTyp.kind == tyObject: dispatchObject = newTree(nkAddr, dispatchObject) else: if g.config.backend != backendCpp: # TODO: maybe handle ptr? if nTyp.kind == tyVar and nTyp.skipTypes({tyVar}).kind != tyObject: dispatchObject = newTree(nkDerefExpr, dispatchObject) var getVTableCall = newTree(nkCall, newSymNode(nimGetVTableSym), dispatchObject, newIntNode(nkIntLit, index) ) getVTableCall.typ = base.typ var vTableCall = newNodeIT(nkCall, base.info, base.typ.returnType) var castNode = newTree(nkCast, newNodeIT(nkType, base.info, base.typ), getVTableCall) castNode.typ = base.typ vTableCall.add castNode for col in 1..= y.depth: 1 else: -1 ) for item in g.objectTree[baseType.itemId]: if item.value.itemId notin itemTable: itemTable[item.value.itemId] = newSeq[LazySym](methodIndexLen) var mIndex = 0 # here is the correpsonding index if baseType.itemId notin rootItemIdCount: rootItemIdCount[baseType.itemId] = 1 else: mIndex = rootItemIdCount[baseType.itemId] rootItemIdCount.inc(baseType.itemId) for idx in 0..= y.depth: 1 else: -1 ) for item in g.objectTree[baseType.itemId]: if item.value.itemId notin itemTable: itemTable[item.value.itemId] = newSeq[LazySym](methodIndexLen) var mIndex = 0 # here is the correpsonding index if baseType.itemId notin rootItemIdCount: rootItemIdCount[baseType.itemId] = 1 else: mIndex = rootItemIdCount[baseType.itemId] rootItemIdCount.inc(baseType.itemId) for idx in 0..