summary refs log tree commit diff stats
path: root/compiler/lookups.nim
Commit message (Expand)AuthorAgeFilesLines
...
* nimfix now in its own directory; single file mode now the defaultAraq2014-10-051-1/+1
* 'pretty' command does not exist anymore; improvements for nimfixAraq2014-09-101-1/+0
* some improvements for nimfixAraq2014-09-091-0/+10
* added nimfix toolAraq2014-09-051-2/+25
* updated the compiler to use the new symbol namesAraq2014-08-281-8/+5
* the big renamefest: first stepsAraq2014-08-221-46/+45
* Renamed considerAccents to considerQuotedIdentClay Sweetser2014-05-261-10/+10
* Fixes #1200Clay Sweetser2014-05-241-1/+2
* Renamed 'considerAcc' to 'considerAccents' for clarityClay Sweetser2014-05-241-10/+10
* make some tests greenZahary Karadjov2014-03-161-1/+4
* Merge branch 'devel' of github.com:Araq/Nimrod into develZahary Karadjov2014-03-061-1/+1
|\
| * bugfix: unreported 'compiles' bugAraq2014-03-051-1/+1
* | split the inline and closure iterators into different symbol kinds for easier...Zahary Karadjov2014-03-061-1/+1
|/
* fixes #892Araq2014-02-141-0/+1
* bugfix: immediate templates are preferred consistently (danger: breaks code)Araq2014-02-041-1/+13
* 'nil' as a statement is deprecated, use an empty 'discard' insteadAraq2014-01-191-1/+1
* case consistency: cs:partial bootstraps on windowsAraq2013-12-291-7/+7
* case consistency part 4Araq2013-12-271-7/+7
* case consistency part 1Araq2013-12-271-43/+43
* attempt to merge newtemplAraq2013-12-241-2/+5
* small REPL improvementsAraq2013-06-281-1/+2
* fixes #437, fixes #436Araq2013-05-181-1/+1
* merged the persistent scopes work with the delayed proc compilation strategyZahary Karadjov2013-05-121-3/+1
|\
* | get rid of TOverloadIter.stackPtrZahary Karadjov2013-05-121-28/+36
* | get rid of ImportTablePos and ModuleTablePosZahary Karadjov2013-05-121-53/+52
* | get rid of the SymTab* procs in astalgoZahary Karadjov2013-05-121-19/+60
* | switch to a linked list of scopesZahary Karadjov2013-05-111-8/+4
|/
* Removes executable bit for text files.Grzegorz Adam Hankiewicz2013-03-161-0/+0
* fixes #73Araq2012-09-231-4/+8
* distinguish properly between nkOpen and nkClosedSymChoiceAraq2012-08-261-2/+2
* next steps to hygienic templatesAraq2012-08-201-14/+9
* idetools: 'usages' and 'def' should work now; documented js backendAraq2012-08-051-10/+13
* idetools improvementsAraq2012-08-031-1/+8
* made compiler more robust for idetools supportAraq2012-07-301-4/+9
* better error handling for better idetools supportAraq2012-07-291-9/+22
* improvements for idetools; system.compiles improvedAraq2012-07-291-1/+6
* next steps for closure consistency; fixes #176Araq2012-07-251-1/+1
* bugfix: UFCS for templates (ttempl3.nim enhanced)Araq2012-05-271-10/+11
* genSym support for hygienic macros and templates.Zahary Karadjov2012-03-261-1/+6
* allowing definitions of procs and templates to be overridden in local scopesZahary Karadjov2012-03-141-2/+9
* year 2012 for most copyright headersAraq2012-01-021-1/+1
* bugfix: preliminary symbol declaration in first pass of genericsAraq2011-12-301-1/+4
* bugfix: the code gen can now handle alias TLock = TSysLock; this fixes thread...Araq2011-12-231-1/+1
* support for C++ code generation; importcpp and importobjc pragmasAraq2011-08-071-2/+2
* bugfix: forwarding of generic procs now worksAraq2011-07-301-1/+1
* preparations for 0.8.12Araq2011-07-101-4/+4
* intsets are now a proper module and part of the stdlibAraq2011-06-141-8/+8
* cleaned up the tests; fixes #30; fixes #26Araq2011-05-011-30/+44
* got rid of some arcane module namesAraq2011-04-211-1/+1
* big repo cleanupAraq2011-04-121-0/+234
class="o">[1] = ri proc newFastAsgnStmt(le, ri: PNode): PNode = result = newNodeI(nkFastAsgn, le.info, 2) result.sons[0] = le result.sons[1] = ri proc lowerTupleUnpacking*(n: PNode; owner: PSym): PNode = assert n.kind == nkVarTuple let value = n.lastSon result = newNodeI(nkStmtList, n.info) var temp = newSym(skTemp, getIdent(genPrefix), owner, value.info) temp.typ = skipTypes(value.typ, abstractInst) incl(temp.flags, sfFromGeneric) var v = newNodeI(nkVarSection, value.info) v.addVar(newSymNode(temp)) result.add(v) result.add newAsgnStmt(newSymNode(temp), value) for i in 0 .. n.len-3: result.add newAsgnStmt(n.sons[i], newTupleAccess(value, i)) proc createObj*(owner: PSym, info: TLineInfo): PType = result = newType(tyObject, owner) rawAddSon(result, nil) incl result.flags, tfFinal result.n = newNodeI(nkRecList, info) proc addField*(obj: PType; s: PSym) = # because of 'gensym' support, we have to mangle the name with its ID. # This is hacky but the clean solution is much more complex than it looks. var field = newSym(skField, getIdent(s.name.s & $s.id), s.owner, s.info) let t = skipIntLit(s.typ) field.typ = t field.position = sonsLen(obj.n) addSon(obj.n, newSymNode(field)) proc newDotExpr(obj, b: PSym): PNode = result = newNodeI(nkDotExpr, obj.info) let field = getSymFromList(obj.typ.n, getIdent(b.name.s & $b.id)) assert field != nil, b.name.s addSon(result, newSymNode(obj)) addSon(result, newSymNode(field)) result.typ = field.typ proc indirectAccess*(a: PNode, b: PSym, info: TLineInfo): PNode = # returns a[].b as a node var deref = newNodeI(nkHiddenDeref, info) deref.typ = a.typ.sons[0] assert deref.typ.kind == tyObject let field = getSymFromList(deref.typ.n, getIdent(b.name.s & $b.id)) assert field != nil, b.name.s addSon(deref, a) result = newNodeI(nkDotExpr, info) addSon(result, deref) addSon(result, newSymNode(field)) result.typ = field.typ proc indirectAccess*(a, b: PSym, info: TLineInfo): PNode = result = indirectAccess(newSymNode(a), b, info) proc genAddrOf*(n: PNode): PNode = result = newNodeI(nkAddr, n.info, 1) result.sons[0] = n result.typ = newType(tyPtr, n.typ.owner) result.typ.rawAddSon(n.typ) proc callCodegenProc*(name: string, arg1: PNode; arg2, arg3: PNode = nil): PNode = result = newNodeI(nkCall, arg1.info) let sym = magicsys.getCompilerProc(name) if sym == nil: localError(arg1.info, errSystemNeeds, name) else: result.add newSymNode(sym) result.add arg1 if arg2 != nil: result.add arg2 if arg3 != nil: result.add arg3 proc createWrapperProc(f: PNode; threadParam, argsParam: PSym; varSection, call: PNode): PSym = var body = newNodeI(nkStmtList, f.info) body.add varSection body.add callCodeGenProc("nimArgsPassingDone", newSymNode(threadParam)) body.add call var params = newNodeI(nkFormalParams, f.info) params.add emptyNode params.add threadParam.newSymNode params.add argsParam.newSymNode var t = newType(tyProc, threadParam.owner) t.rawAddSon nil t.rawAddSon threadParam.typ t.rawAddSon argsParam.typ t.n = newNodeI(nkFormalParams, f.info) t.n.add newNodeI(nkEffectList, f.info) t.n.add threadParam.newSymNode t.n.add argsParam.newSymNode let name = (if f.kind == nkSym: f.sym.name.s else: genPrefix) & "Wrapper" result = newSym(skProc, getIdent(name), argsParam.owner, f.info) result.ast = newProcNode(nkProcDef, f.info, body, params, newSymNode(result)) result.typ = t proc createCastExpr(argsParam: PSym; objType: PType): PNode = result = newNodeI(nkCast, argsParam.info) result.add emptyNode result.add newSymNode(argsParam) result.typ = newType(tyPtr, objType.owner) result.typ.rawAddSon(objType) proc wrapProcForSpawn*(owner: PSym; n: PNode): PNode = result = newNodeI(nkStmtList, n.info) if n.kind notin nkCallKinds or not n.typ.isEmptyType: localError(n.info, "'spawn' takes a call expression of type void") return if optThreadAnalysis in gGlobalOptions: if {tfThread, tfNoSideEffect} * n[0].typ.flags == {}: localError(n.info, "'spawn' takes a GC safe call expression") var threadParam = newSym(skParam, getIdent"thread", owner, n.info) argsParam = newSym(skParam, getIdent"args", owner, n.info) block: let ptrType = getSysType(tyPointer) threadParam.typ = ptrType argsParam.typ = ptrType argsParam.position = 1 var objType = createObj(owner, n.info) incl(objType.flags, tfFinal) let castExpr = createCastExpr(argsParam, objType) var scratchObj = newSym(skVar, getIdent"scratch", owner, n.info) block: scratchObj.typ = objType incl(scratchObj.flags, sfFromGeneric) var varSectionB = newNodeI(nkVarSection, n.info) varSectionB.addVar(scratchObj.newSymNode) result.add varSectionB var call = newNodeI(nkCall, n.info) var fn = n.sons[0] # templates and macros are in fact valid here due to the nature of # the transformation: if not (fn.kind == nkSym and fn.sym.kind in {skProc, skTemplate, skMacro, skMethod, skConverter}): # for indirect calls we pass the function pointer in the scratchObj var argType = n[0].typ.skipTypes(abstractInst) var field = newSym(skField, getIdent"fn", owner, n.info) field.typ = argType objType.addField(field) result.add newFastAsgnStmt(newDotExpr(scratchObj, field), n[0]) fn = indirectAccess(castExpr, field, n.info) elif fn.kind == nkSym and fn.sym.kind in {skClosureIterator, skIterator}: localError(n.info, "iterator in spawn environment is not allowed") elif fn.typ.callConv == ccClosure: localError(n.info, "closure in spawn environment is not allowed") call.add(fn) var varSection = newNodeI(nkVarSection, n.info) let formals = n[0].typ.n let tmpName = getIdent(genPrefix) for i in 1 .. <n.len: # we pick n's type here, which hopefully is 'tyArray' and not # 'tyOpenArray': var argType = n[i].typ.skipTypes(abstractInst) if i < formals.len and formals[i].typ.kind == tyVar: localError(n[i].info, "'spawn'ed function cannot have a 'var' parameter") elif containsTyRef(argType): localError(n[i].info, "'spawn'ed function cannot refer to 'ref'/closure") let fieldname = if i < formals.len: formals[i].sym.name else: tmpName var field = newSym(skField, fieldname, owner, n.info) field.typ = argType objType.addField(field) result.add newFastAsgnStmt(newDotExpr(scratchObj, field), n[i]) var temp = newSym(skTemp, tmpName, owner, n.info) temp.typ = argType incl(temp.flags, sfFromGeneric) var vpart = newNodeI(nkIdentDefs, n.info, 3) vpart.sons[0] = newSymNode(temp) vpart.sons[1] = ast.emptyNode vpart.sons[2] = indirectAccess(castExpr, field, n.info) varSection.add vpart call.add(newSymNode(temp)) let wrapper = createWrapperProc(fn, threadParam, argsParam, varSection, call) result.add callCodeGenProc("nimSpawn", wrapper.newSymNode, genAddrOf(scratchObj.newSymNode))