about summary refs log tree commit diff stats
path: root/doc
Commit message (Expand)AuthorAgeFilesLines
* doc: Add draw.io dependency to man pagetoonn2022-03-182-0/+8
* Makefile: Drop README.md from man page requisitestoonn2022-03-181-3/+7
* doc: Split lines in man pagetoonn2022-03-181-2/+4
* doc: Add openscad dependency to man pagetoonn2022-03-181-0/+4
* doc: Fix manpage for name filter_stack filtertoonn2022-03-182-5/+5
* Revert "convert_papermode_to_metadata: Drop disappeared Pylint options"toonn2022-02-051-0/+2
* convert_papermode_to_metadata: Drop disappeared Pylint optionstoonn2022-02-051-2/+0
* doc: Add rsvg-convert to the man pagetoonn2022-02-052-2/+8
* doc: Drop Imagemagick for SVG previewtoonn2022-02-051-1/+1
* man: Regenerate ranger man pagetoonn2021-11-131-1/+1
* Fix wrong hotkeys in the manualGuillermo Gómez2021-11-122-6/+6
* doc: Document setinpath and setinregextoonn2021-09-052-23/+57
* man: Regex chars have to be escaped in setlocaljakanakae-envangel2021-09-022-3/+5
* Merge branch 'doc-deletion-confirmation'toonn2021-09-011-1/+1
|\
| * Fix deletion confirmation default indicationtoonn2020-08-222-2/+2
* | doc/tools: Silence encoding linttoonn2021-08-271-1/+5
* | Remove trailing whitespacea13460542021-08-251-1/+1
* | Fix incorrect information in manpagesa13460542021-08-252-4/+4
* | Merge branch 'libera'toonn2021-08-182-1/+16
|\ \
| * | doc: Use the same wording for the webchattoonn2021-05-282-4/+6
| * | doc: Add Libera.Chat webchat to man pagetoonn2021-05-282-4/+17
* | | ranger.1: Regenerate man page for correct datetoonn2021-08-141-2/+2
* | | Add DocsNash Pillai2021-08-131-1/+1
|/ /
* | cheatsheet: Update IRC referencetoonn2021-05-191-1/+1
* | manpage: Update IRC referencetoonn2021-05-192-4/+4
* | doc: Update man page re right clicking to open filestoonn2021-05-172-12/+12
* | doc: New -s flag for consoletoonn2021-01-222-10/+14
* | Remove redundant blank line in docstoonn2020-11-181-1/+0
* | Document draw_borders_multipanetoonn2020-11-182-2/+22
* | Regenerate rifle man pagetoonn2020-11-081-1/+1
* | Update the docs to reflect changes to codeZoran Plesivcak2020-11-082-4/+4
|/
* Fully migrate from distutils to setuptoolsWojciech Siewierski2020-05-131-1/+1
* Refer to the correct environment variable for selecting a theme for batDany Marcoux2020-03-032-3/+3
* doc: change trash locationemberfade2020-02-222-7/+7
* Clarify that defaults will not be loadedtoonn2020-02-082-3/+5
* doc(rifle): Add note of rifle config reading in manpageJames Wright2020-02-071-1/+1
* Tax loss harvesting release, nothing to see here v1.9.3toonn2019-12-312-3/+3
* Fix overflows in man page formattingtoonn2019-12-312-16/+20
* Refactor handle_multiplexertoonn2019-12-312-7/+3
* refactoring of redundant codearkedos2019-12-311-0/+4
* Merge branch 'aRkedos-unique-file'toonn2019-12-302-29/+240
|\
| * Improve filter_stack documentationtoonn2019-12-272-30/+232
* | add support for 3D files including STL and DXFsigurdb2019-12-291-0/+11
* | Merge branch 'wraptext' of https://github.com/toonn/rangerWojciech Siewierski2019-12-282-1/+10
|\ \
| * | Add a setting to wrap plain text previewstoonn2019-11-062-2/+11
| |/
* | Merge branch 'siikamiika-feat-update-icon-title'toonn2019-12-222-4/+4
|\ \
| * | Merge the title settingstoonn2019-12-222-13/+6
| * | Merge branch 'master' into feat-update-icon-titlesiikamiika2019-12-094-117/+184
| |\|
| * | add update_icon_title optionsiikamiika2019-07-252-0/+7
* | | Merge branch 'laktak-paste_conflict'toonn2019-12-222-1/+9
|\ \ \
2c4a1dbc0 ^

51850b546 ^
2c4a1dbc0 ^

2633e3fb2 ^
632aece19 ^
2633e3fb2 ^
2c4a1dbc0 ^

2633e3fb2 ^
632aece19 ^

2633e3fb2 ^

2c4a1dbc0 ^

2633e3fb2 ^


632aece19 ^
2633e3fb2 ^
632aece19 ^

2633e3fb2 ^
2c4a1dbc0 ^



2633e3fb2 ^
632aece19 ^
2633e3fb2 ^


2c4a1dbc0 ^






f3f3fc01a ^
2c4a1dbc0 ^












2633e3fb2 ^


632aece19 ^
2c4a1dbc0 ^







2633e3fb2 ^





632aece19 ^
2633e3fb2 ^







632aece19 ^
2633e3fb2 ^


632aece19 ^

2633e3fb2 ^
632aece19 ^



560a3bad2 ^
2c4a1dbc0 ^



2633e3fb2 ^
2c4a1dbc0 ^
632aece19 ^











2633e3fb2 ^






2c4a1dbc0 ^




632aece19 ^
2c4a1dbc0 ^
2633e3fb2 ^

2c4a1dbc0 ^
632aece19 ^
2633e3fb2 ^
632aece19 ^


2c4a1dbc0 ^






2633e3fb2 ^
632aece19 ^
2633e3fb2 ^
2c4a1dbc0 ^
2633e3fb2 ^
632aece19 ^
2633e3fb2 ^
632aece19 ^


2633e3fb2 ^

632aece19 ^
2633e3fb2 ^



2c4a1dbc0 ^
2633e3fb2 ^

632aece19 ^
2c4a1dbc0 ^
2633e3fb2 ^
632aece19 ^
2633e3fb2 ^


161f6f722 ^

632aece19 ^

2633e3fb2 ^


632aece19 ^
2633e3fb2 ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256









                                                                    
                          
 
     
                                                                           
                                            
 
                                                          
                           

                                           
                           

                                                 
                  
                                    
                       




                                   
 



                                           
 












                                                        



                                                                            

                                                                            


                 
                                                        

                                  
                                                     
       
                                         
                                              
 
                                                               
                                      


                       
                                                    
                                           
                                                  
         

                                       

                                                 
                             

                                                                   
 
                                                       
                                                                             

                                                    
 

                                                               

             

                                                  


                                                     
                                                       
  

                                                                      
                             



                                                            
  
                                                                      


                         






                                                                           
                            












                                                                           


                                                     
                                                       







                                            





                                   
                                                                          







                                                                           
                                                             


                              

                                                      
                                 



                                                                       
                             



                                                                             
  
                                               











                                                 






                                                      




                                                               
  
                                                                      

                                                      
                        
                                    
 


                                      






                                                  
  
                  
                                                             
                                        
                                               
                                    
  


                                                                         

                                          
                                             



                                                                        
                                                                           

                                 
                                    
                      
 
                                                                


                                                                    

                                                                              

                                                       


                     
                                                              

  
#
#
#           The Nimrod Compiler
#        (c) Copyright 2012 Andreas Rumpf
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#

# This include file implements lambda lifting for the transformator.
# included from transf.nim

const
  declarativeDefs = {nkProcDef, nkMethodDef, nkIteratorDef, nkConverterDef}
  procDefs = nkLambdaKinds + declarativeDefs

proc indirectAccess(a, b: PSym, info: TLineInfo): PNode = 
  # returns a[].b as a node
  let x = newSymNode(a)
  var deref = newNodeI(nkHiddenDeref, info)
  deref.typ = x.typ.sons[0]
  
  let field = getSymFromList(deref.typ.n, b.name)
  addSon(deref, x)
  result = newNodeI(nkDotExpr, info)
  addSon(result, deref)
  addSon(result, newSymNode(field))
  result.typ = field.typ

type
  TCapture = seq[PSym]

proc Capture(cap: var TCapture, s: PSym) = 
  for x in cap:
    if x.name.id == s.name.id: return
  cap.add(s)

proc captureToTuple(cap: TCapture, owner: PSym): PType =
  result = newType(tyTuple, owner)
  result.n = newNodeI(nkRecList, owner.info)
  for s in cap:
    var field = newSym(skField, s.name, s.owner)
    
    let typ = s.typ
    field.typ = typ
    field.position = sonsLen(result)
    
    addSon(result.n, newSymNode(field))
    addSon(result, typ)

proc interestingVar(s: PSym): bool {.inline.} =
  result = s.kind in {skVar, skLet, skTemp, skForVar, skParam, skResult} and
    sfGlobal notin s.flags

proc gatherVars(c: PTransf, n: PNode, outerProc: PSym, cap: var TCapture) = 
  # gather used vars for closure generation into 'cap'
  case n.kind
  of nkSym:
    var s = n.sym
    if interestingVar(s) and outerProc.id == s.owner.id:
      #echo "captured: ", s.name.s
      Capture(cap, s)
  of nkEmpty..pred(nkSym), succ(nkSym)..nkNilLit: nil
  else:
    for i in countup(0, sonsLen(n) - 1): 
      gatherVars(c, n.sons[i], outerProc, cap)

proc replaceVars(c: PTransf, n: PNode, outerProc, env: PSym) = 
  for i in countup(0, safeLen(n) - 1):
    let a = n.sons[i]
    if a.kind == nkSym:
      let s = a.sym
      if interestingVar(s) and outerProc == s.owner:
        # access through the closure param:
        n.sons[i] = indirectAccess(env, s, n.info)
    else:
      replaceVars(c, a, outerProc, env)

proc addHiddenParam(routine: PSym, param: PSym) =
  var params = routine.ast.sons[paramsPos]
  param.position = params.len
  addSon(params, newSymNode(param))
  #echo "produced environment: ", param.id, " for ", routine.name.s

proc isInnerProc(s, outerProc: PSym): bool {.inline.} =
  result = s.kind in {skProc, skMacro, skIterator, skMethod, skConverter} and
    s.owner == outerProc and not isGenericRoutine(s)
  #s.typ.callConv == ccClosure

proc searchForInnerProcs(c: PTransf, n: PNode, outerProc: PSym,
                         cap: var TCapture) =
  case n.kind
  of nkSym:
    if isInnerProc(n.sym, outerProc):
      gatherVars(c, n.sym.getBody, outerProc, cap)
  of nkEmpty..pred(nkSym), succ(nkSym)..nkNilLit: nil
  else:
    for i in 0.. <len(n):
      searchForInnerProcs(c, n.sons[i], outerProc, cap)
  
proc makeClosure(c: PTransf, prc, env: PSym, info: TLineInfo): PNode =
  result = newNodeIT(nkClosure, info, prc.typ)
  result.add(newSymNode(prc))
  if env == nil:
    result.add(newNodeIT(nkNilLit, info, getSysType(tyNil)))
  else:
    result.add(newSymNode(env))
  
proc transformInnerProcs(c: PTransf, n: PNode, outerProc, env: PSym) =
  case n.kind
  of nkSym:
    let innerProc = n.sym
    if isInnerProc(innerProc, outerProc) and not 
        containsOrIncl(c.transformedInnerProcs, innerProc.id):
      if env == nil:
        innerProc.ast.sons[bodyPos] = transform(c, innerProc.getBody).pnode
      else:
        # inner proc could capture outer vars:
        var param = newTemp(c, env.typ, n.info)
        param.kind = skParam
        
        # recursive calls go through (f, hiddenParam):
        IdNodeTablePut(c.transCon.mapping, innerProc, 
                       makeClosure(c, innerProc, param, n.info))
        # access all non-local vars through the 'env' param:
        replaceVars(c, innerProc.getBody, outerProc, param)

        innerProc.ast.sons[bodyPos] = transform(c, innerProc.getBody).pnode
        addHiddenParam(innerProc, param)
        
        # 'anon' should be replaced by '(anon, env)' in the outer proc:
        IdNodeTablePut(c.transCon.mapping, innerProc, 
                       makeClosure(c, innerProc, env, n.info))
  of nkEmpty..pred(nkSym), succ(nkSym)..nkNilLit: nil
  else:
    for i in 0.. <len(n):
      transformInnerProcs(c, n.sons[i], outerProc, env)
  
template checkInvariant(n: PNode, s: PSym) =
  when false:
    if s.ast != n:
      echo renderTree(s.ast)
      echo " -------------- "
      echo n.renderTree
    assert s.ast == n

proc newCall(a, b: PSym): PNode =
  result = newNodeI(nkCall, a.info)
  result.add newSymNode(a)
  result.add newSymNode(b)

proc createEnvStmt(c: PTransf, varList: TCapture, env: PSym): PTransNode =
  # 'varlist' can contain parameters or variables. We don't eliminate yet
  # local vars that end up in an environment. This could even be a for loop
  # var!
  result = newTransNode(nkStmtList, env.info, 0)
  var v = newNodeI(nkVarSection, env.info)
  addVar(v, newSymNode(env))
  result.add(v.ptransNode)
  # add 'new' statement:
  result.add(newCall(getSysSym"internalNew", env).ptransnode)
  
  # add assignment statements:
  for v in varList:
    let fieldAccess = indirectAccess(env, v, env.info)
    if v.kind == skParam:
      # add ``env.param = param``
      result.add(newAsgnStmt(c, fieldAccess, newSymNode(v).ptransNode))
    IdNodeTablePut(c.transCon.mapping, v, fieldAccess)
  
proc transformProcFin(c: PTransf, n: PNode, s: PSym): PTransNode =
  if n.kind in nkLambdaKinds:
    # for lambdas we transformed 'n.sons[bodyPos]', but not 'ast.n[bodyPos]'!
    s.ast.sons[bodyPos] = n.sons[bodyPos]
  else:
    assert s.ast == n
  
  if n.kind == nkMethodDef: methodDef(s, false)
  # should 's' be replaced by a tuple ('s', env)?
  var tc = c.transCon
  var repl: PNode = nil
  while tc != nil:
    repl = IdNodeTableGet(tc.mapping, s)
    if repl != nil: break
    tc = tc.next
  if repl != nil:
    result = PTransNode(repl)
  else:
    result = PTransNode(n)

proc transformProc(c: PTransf, n: PNode): PTransNode =
  # don't process generics:
  if n.sons[genericParamsPos].kind != nkEmpty:
    return PTransNode(n)
  
  var s = n.sons[namePos].sym
  var body = s.getBody
  if body.kind == nkEmpty or n.sons[bodyPos].kind == nkEmpty or
     containsOrIncl(c.transformedInnerProcs, s.id):
    return PTransNode(n)
    
  checkInvariant(n, s)
  
  if not containsNode(body, procDefs) and s.typ.callConv != ccClosure:
    # fast path: no inner procs, so no closure needed:
    n.sons[bodyPos] = PNode(transform(c, body))
    checkInvariant(n, s)
    return transformProcFin(c, n, s)

  # create environment:
  var cap: TCapture = @[]
  searchForInnerProcs(c, body, s, cap)

  var envType = newType(tyRef, s)
  addSon(envType, captureToTuple(cap, s))
  if s.typ.callConv == ccClosure:
    addHiddenParam(s, newTemp(c, envType, n.info))
    IdNodeTablePut(c.transCon.mapping, s, 
                   makeClosure(c, s, nil, n.info))
  
  if cap.len == 0:
    # fast path: no captured variables, so no closure needed:
    transformInnerProcs(c, body, s, nil)
    n.sons[bodyPos] = PNode(transform(c, body))
    return transformProcFin(c, n, s)
  
  # Currently we always do a heap allocation. A simple escape analysis
  # could turn the closure into a stack allocation. Later versions might 
  # implement that. This would require backend changes too though.
  var envSym = newTemp(c, envType, s.info)
  
  var newBody = createEnvStmt(c, cap, envSym)
  # modify any local proc to gain a new parameter; this also creates the
  # mapping entries that turn (localProc) into (localProc, env):
  transformInnerProcs(c, body, s, envSym)

  # now we can transform 'body' as all rewriting entries have been created:
  newBody.add(transform(c, body))
  n.sons[bodyPos] = newBody.pnode
  result = transformProcFin(c, n, s)
  checkInvariant(n, s)

proc generateThunk(c: PTransf, prc: PNode, dest: PType): PNode =
  ## Converts 'prc' into '(thunk, nil)' so that it's compatible with
  ## a closure.
  
  # we cannot generate a proper thunk here for GC-safety reasons (see internal
  # documentation):
  result = newNodeIT(nkClosure, prc.info, dest)
  var conv = newNodeIT(nkHiddenStdConv, prc.info, dest)
  conv.add(emptyNode)
  conv.add(prc)
  result.add(conv)
  result.add(newNodeIT(nkNilLit, prc.info, getSysType(tyNil)))