# # # The Nimrod Compiler # (c) Copyright 2011 Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. # # ------------------------- Name Mangling -------------------------------- proc mangle(name: string): string = case name[0] of 'a'..'z': result = "" add(result, chr(ord(name[0]) - ord('a') + ord('A'))) of '0'..'9', 'A'..'Z': result = "" add(result, name[0]) else: result = "HEX" & toHex(ord(name[0]), 2) for i in countup(0 + 1, len(name) + 0 - 1): case name[i] of 'A'..'Z': add(result, chr(ord(name[i]) - ord('A') + ord('a'))) of '_': nil of 'a'..'z', '0'..'9': add(result, name[i]) else: add(result, "HEX") add(result, toHex(ord(name[i]), 2)) proc mangleName(s: PSym): PRope = result = s.loc.r if result == nil: if gCmd == cmdCompileToLLVM: case s.kind of skProc, skMethod, skConverter, skConst: result = toRope("@") of skVar, skResult: if sfGlobal in s.flags: result = toRope("@") else: result = toRope("%") of skForVar, skTemp, skParam, skType, skEnumField, skModule: result = toRope("%") else: InternalError(s.info, "mangleName") app(result, toRope(mangle(s.name.s))) app(result, "_") app(result, toRope(s.id)) when false: # deactivated to make mapping file smaller which is currently only used # for the list of generated C files if optGenMapping in gGlobalOptions: if s.owner != nil: appf(gMapping, "r\"$1.$2\": $3$n", [toRope(s.owner.Name.s), toRope(s.name.s), result]) s.loc.r = result proc getTypeName(typ: PType): PRope = if (typ.sym != nil) and ({sfImportc, sfExportc} * typ.sym.flags != {}) and (gCmd != cmdCompileToLLVM): result = typ.sym.loc.r else: if typ.loc.r == nil: typ.loc.r = ropeff("TY$1", "%TY$1", [toRope(typ.id)]) result = typ.loc.r if result == nil: InternalError("getTypeName: " & $typ.kind) proc mapSetType(typ: PType): TCTypeKind = case int(getSize(typ)) of 1: result = ctInt8 of 2: result = ctInt16 of 4: result = ctInt32 of 8: result = ctInt64 else: result = ctArray proc mapType(typ: PType): TCTypeKind = case typ.kind of tyNone: result = ctVoid of tyBool: result = ctBool of tyChar: result = ctChar of tySet: result = mapSetType(typ) of tyOpenArray, tyArrayConstr, tyArray: result = ctArray of tyObject, tyTuple: result = ctStruct of tyGenericBody, tyGenericInst, tyGenericParam, tyDistinct, tyOrdinal, tyConst, tyMutable, tyIter: result = mapType(lastSon(typ)) of tyEnum: if firstOrd(typ) < 0: result = ctInt32 else: case int(getSize(typ)) of 1: result = ctUInt8 of 2: result = ctUInt16 of 4: result = ctInt32 of 8: result = ctInt64 else: internalError("mapType") of tyRange: result = mapType(typ.sons[0]) of tyPtr, tyVar, tyRef: var base = skipTypes(typ.sons[0], abstractInst) case base.kind of tyOpenArray, tyArrayConstr, tyArray: result = ctArray else: result = ctPtr of tyPointer: result = ctPtr of tySequence: result = ctNimSeq of tyProc: result = ctProc of tyString: result = ctNimStr of tyCString: result = ctCString of tyInt..tyFloat128: result = TCTypeKind(ord(typ.kind) - ord(tyInt) + ord(ctInt)) else: InternalError("mapType") proc mapReturnType(typ: PType): TCTypeKind = if skipTypes(typ, abstractInst).kind == tyArray: result = ctPtr else: result = mapType(typ) proc getTypeDescAux(m: BModule, typ: PType, check: var TIntSet): PRope proc needsComplexAssignment(typ: PType): bool = result = containsGarbageCollectedRef(typ) proc isInvalidReturnType(rettype: PType): bool = # Arrays and sets cannot be returned by a C procedure, because C is # such a poor programming language. # We exclude records with refs too. This enhances efficiency and # is necessary for proper code generation of assignments. if rettype == nil: result = true else: case mapType(rettype) of ctArray: result = not (skipTypes(rettype, abstractInst).kind in {tyVar, tyRef, tyPtr}) of ctStruct: result = needsComplexAssignment(skipTypes(rettype, abstractInst)) else: result = false const CallingConvToStr: array[TCallingConvention, string] = ["N_NIMCALL", "N_STDCALL", "N_CDECL", "N_SAFECALL", "N_SYSCALL", # this is probably not correct for all platforms, # but one can #define it to what one wants "N_INLINE", "N_NOINLINE", "N_FASTCALL", "N_CLOSURE", "N_NOCONV"] CallingConvToStrLLVM: array[TCallingConvention, string] = ["fastcc $1", "stdcall $1", "ccc $1", "safecall $1", "syscall $1", "$1 alwaysinline", "$1 noinline", "fastcc $1", "ccc $1", "$1"] proc CacheGetType(tab: TIdTable, key: PType): PRope = # returns nil if we need to declare this type # since types are now unique via the ``GetUniqueType`` mechanism, this slow # linear search is not necessary anymore: result = PRope(IdTableGet(tab, key)) proc getTempName(): PRope = result = ropeff("TMP$1", "%TMP$1", [toRope(backendId())]) proc getGlobalTempName(): PRope = result = ropeff("TMP$1", "@TMP$1", [toRope(backendId())]) proc ccgIntroducedPtr(s: PSym): bool = var pt = skipTypes(s.typ, abstractInst) assert skResult != s.kind case pt.Kind of tyObject: # XXX quick hack floatSize*2 for the pegs module under 64bit if (optByRef in s.options) or (getSize(pt) > platform.floatSize * 2): result = true # requested anyway elif (tfFinal in pt.flags) and (pt.sons[0] == nil): result = false # no need, because no subtyping possible else: result = true # ordinary objects are always passed by reference, # otherwise casting doesn't work of tyTuple: result = (getSize(pt) > platform.floatSize) or (optByRef in s.options) else: result = false proc fillResult(param: PSym) = fillLoc(param.loc, locParam, param.typ, ropeff("Result", "%Result", []), OnStack) if (mapReturnType(param.typ) != ctArray) and IsInvalidReturnType(param.typ): incl(param.loc.flags, lfIndirect) param.loc.s = OnUnknown proc getParamTypeDesc(m: BModule, t: PType, check: var TIntSet): PRope = when false: if t.Kind in {tyRef, tyPtr, tyVar}: var b = skipTypes(t.sons[0], abstractInst) if b.kind == tySet and mapSetType(b) == ctArray: return getTypeDescAux(m, b, check) result = getTypeDescAux(m, t, check) proc genProcParams(m: BModule, t: PType, rettype, params: var PRope, check: var TIntSet) = params = nil if (t.sons[0] == nil) or isInvalidReturnType(t.sons[0]): rettype = toRope("void") else: rettype = getTypeDescAux(m, t.sons[0], check) for i in countup(1, sonsLen(t.n) - 1): if t.n.sons[i].kind != nkSym: InternalError(t.n.info, "genProcParams") var param = t.n.sons[i].sym fillLoc(param.loc, locParam, param.typ, mangleName(param), OnStack) app(params, getParamTypeDesc(m, param.typ, check)) if ccgIntroducedPtr(param): app(params, "*") incl(param.loc.flags, lfIndirect) param.loc.s = OnUnknown app(params, " ") app(params, param.loc.r) # declare the len field for open arrays: var arr = param.typ if arr.kind == tyVar: arr = arr.sons[0] var j = 0 while arr.Kind == tyOpenArray: # need to pass hidden parameter: appff(params, ", NI $1Len$2", ", @NI $1Len$2", [param.loc.r, j.toRope]) inc(j) arr = arr.sons[0] if i < sonsLen(t.n) - 1: app(params, ", ") if (t.sons[0] != nil) and isInvalidReturnType(t.sons[0]): if params != nil: app(params, ", ") var arr = t.sons[0] app(params, getTypeDescAux(m, arr, check)) if (mapReturnType(t.sons[0]) != ctArray) or (gCmd == cmdCompileToLLVM): app(params, "*") appff(params, " Result", " @Result", []) if t.callConv == ccClosure: if params != nil: app(params, ", ") app(params, "void* ClPart") if tfVarargs in t.flags: if params != nil: app(params, ", ") app(params, "...") if (params == nil) and (gCmd != cmdCompileToLLVM): app(params, "void)") else: app(params, ")") params = con("(", params) proc isImportedType(t: PType): bool = result = (t.sym != nil) and (sfImportc in t.sym.flags) proc typeNameOrLiteral(t: PType, literal: string): PRope = if (t.sym != nil) and (sfImportc in t.sym.flags) and (t.sym.magic == mNone): result = getTypeName(t) else:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module ranger.gui.ui</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head><body bgcolor="#f0f0f8">
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="ranger.html"><font color="#ffffff">ranger</font></a>.<a href="ranger.gui.html"><font color="#ffffff">gui</font></a>.ui</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/hut/work/ranger/ranger/gui/ui.py">/home/hut/work/ranger/ranger/gui/ui.py</a></font></td></tr></table>
<p><tt># Copyright (c) 2009, 2010 hut <hut@lavabit.com><br>
#<br>
# Permission to use, copy, modify, and/or distribute this software for any<br>
# purpose with or without fee is hereby granted, provided that the above<br>
# copyright notice and this permission notice appear in all copies.<br>
#<br>
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES<br>
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF<br>
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR<br>
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES<br>
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN<br>
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF<br>
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="_curses.html">_curses</a><br>
</td><td width="25%" valign=top><a href="curses.html">curses</a><br>
</td><td width="25%" valign=top></td><td width="25%&quo