summary refs log tree commit diff stats
path: root/compiler
Commit message (Collapse)AuthorAgeFilesLines
* cache rope when threads are enabled (#19981)flywind2022-07-071-6/+5
| | | | | * cache rope * add threadvar
* rename gc to mm (#19971)flywind2022-07-051-1/+1
|
* Fixing `nimRawSetJmp` for vcc and clangcl on Windows (#19959)rockcavera2022-07-041-7/+12
| | | | | | | | | | | | | * fix vcc rawsetjmp * changing `_longjmp()` to `longjmp()` and `_setjmp()` to `setjmp()` * fix * fix setjmp to clangcl on Windows * fix genTrySetjmp() to clangcl on Windows
* Allow recursive closure iterators (#19939)Tanguy2022-06-301-1/+2
|
* once C++, always C++ [backport] (#19938)Jacek Sieka2022-06-301-10/+16
| | | | | | | | | | | * once C++, always C++ When using `{.compile: "file.cc".}` in a nim module, even when compiling with `nim c` the C++ compiler should be used - once any C++ file has been compiled, the C++ linker also needs to be used. * more strict C++ check * simplify code
* dec inLoop after exiting the while scope in computeLiveRanges [backport] ↵flywind2022-06-291-1/+1
| | | | | | | (#19918) * dec inLoop after exiting the while scope in computeLiveRanges * add testcase
* ref #19830; multiple definition of in Nim generated static libraries (#19934)flywind2022-06-271-18/+18
| | | | | * ref #19830; multiple definition of in Nim generated static libraries * fix compile errors
* [vm]fixes #15974 #12551 #19464 #16020 #16780 #16613 #14553 #19909 #18641 ↵flywind2022-06-222-13/+18
| | | | | | | | | | | | | | | (#19902) [backport] * revert #12217 since the root problem seems to have been fixed; fix #15974;fix #12551; fix #19464 * fix #16020; fix #16780 * fix tests and #16613 * fix #14553 * fix #19909; skip skipRegisterAddr * fix #18641
* [Tiny] correct comment opcDeref => opcLdDeref (#19908)flywind2022-06-211-1/+1
| | | correct comment opcDeref => opcLdDeref
* [vm] refactor `stdlib.marshal.load` (#19905)flywind2022-06-191-17/+1
| | | refactor stdlib.marshal.load
* Better range error messages (#19867)Tanguy2022-06-151-3/+3
| | | | | | | * Better range error messages * Revert to old behavior for arrays * Small corrections
* Fixes #19883 so genscript works with vcc (#19893)Don-Duong Quach2022-06-151-2/+8
|
* Initial implementation of nimsuggest v3 (#19826)Ivan Yonchovski2022-06-134-21/+91
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Initial implementation of nimsuggest v3 Rework `nimsuggest` to use caching to make usage of ide commands more efficient. Previously, all commands no matter what the state of the process is were causing clean build. In the context of Language Server Protocol(LSP) and lsp clients this was causing perf issues and overall instability. Overall, the goal of v3 is to fit to LSP Server needs - added two new commands: - `recompile` to do clean compilation - `changed` which can be used by the IDEs to notify that a particular file has been changed. The later can be utilized when using LSP file watches. - `globalSymbols` - searching global references - added `segfaults` dependency to allow fallback to clean build when incremental fails. I wish the error to be propagated to the client so we can work on fixing the incremental build failures (typically hitting pointer) - more efficient rebuild flow. ATM incremental rebuild is triggered when the command needs that(i. e. it is global) while the commands that work on the current source rebuild only it Things missing in this PR: - Documentation - Extensive unit testing. Although functional I still see this more as a POC that this approach can work. Next steps: - Implement `sug` request. - Rework/extend the protocol to allow better client/server communication. Ideally we will need push events, diagnostics should be restructored to allow per file notifications, etc. - implement v3 test suite. - better logging * Add tests for v3 and implement ideSug * Remove typeInstCache/procInstCache cleanup * Add ideChkFile command * Avoid contains call when adding symbol info * Remove log * Remove segfaults
* [semfold] fix #19199; properly fold uint to float conversion (#19890) [backport]flywind2022-06-131-1/+1
| | | fix #19199; properly fold float conversion
* [cleanup] remove unnecessary procs in vm (#19888)flywind2022-06-132-6/+2
| | | remove unused procs
* Friendlier error message with solution (#19880)Carlo Capocasa2022-06-111-1/+2
| | | | | | | | | | | | | * Add helpful suggestion, should always apply * mention var param limitation in async docs * Update compiler/lambdalifting.nim whoops thanks Co-authored-by: flywind <43030857+xflywind@users.noreply.github.com> Co-authored-by: flywind <43030857+xflywind@users.noreply.github.com>
* Extend and document compiler debugging utilities (#19841)quantimnot2022-06-101-0/+16
| | | | | | | | | * Add two debugutils procs that native debuggers can break on use to execute commands when code of interest is being compiled. * Add GDB and LLDB programs to disable and enable breakpoints and watchpoints when code of interest is being compiled. * Extend the `intern.rst` docs regarding debugging the compiler. Co-authored-by: quantimnot <quantimnot@users.noreply.github.com>
* remove noop option `gc:v2` (#19810)flywind2022-06-104-6/+3
| | | | | * remove noop option gc:v2 * changelog
* not generate initStackBottomWith in arc/orc [backport] (#19875)flywind2022-06-101-1/+1
| | | not generate initStackBottomWith in arc/orc
* give a better error message for some template expansions (#19871)Andreas Rumpf2022-06-091-2/+4
|
* RST: improve simple tables (#19859)Andrey Makarov2022-06-042-0/+3
| | | | | | | * RST: improve simple tables * nim 1.0 gotchas * Still allow legacy boundaries like `----`
* Stop type aliases from inheriting sfUsed (#19861)quantimnot2022-06-041-1/+1
| | | | | Fixes #18201 Co-authored-by: quantimnot <quantimnot@users.noreply.github.com>
* Refactor and doc package handling, module name mangling (#19821)quantimnot2022-05-3015-243/+129
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Refactor and doc package handling, module name mangling * Consolidate, de-duplicate and extend package handling * Alter how duplicate module names of a package are handled * Alter how module names are mangled * Fix crash when another package is named 'stdlib' (test case added) * Doc what defines a package in the manual Modules with duplicate names within a package used to be given 'fake' packages to resolve conflicts. That prevented the ability to discern if a module belonged to the current project package or a foreign package. They now have the proper package owner and the names are mangled in a consistent manner to prevent codegen clashes. All module names are now mangled the same. Stdlib was treated special before, but now it is same as any other package. This fixes a crash when a foreign package is named 'stdlib'. Module mangling is altered for both file paths and symbols used by the backends. Removed an unused module name to package mapping that may have been intended for IC. The mapping was removed because it wasn't being used and was complicating the issue of package modules with duplicate names not having the proper package owner assigned. * Fix some tests * Refactor `packagehandling` * Remove `packagehandling.withPackageName` and its uses * Move module path mangling from `packagehandling` to `modulepaths` * Move `options.toRodFile` to `ic` to break import cycle * Changed import style to match preferred style Co-authored-by: quantimnot <quantimnot@users.noreply.github.com>
* [vm] remove unused opcSubstr opcode (#19834)flywind2022-05-302-10/+2
| | | remove unused opcSubstr
* Fix global destructor injection for JS backend (#19797)quantimnot2022-05-231-5/+25
| | | | | | | | | | | | | | * Fix global destructor injection for JS backend * Moved global destructors injection before the final call to transform and generate JS code. It had previously been after and thus not no JS was generated for them. * Added some internal documentation of `jsgen`. * Enable a current destructor test to cover the JS backend as well. * Fixes the JS aspect of #17237. * Fixed global destructor injection order for JS backend Co-authored-by: quantimnot <quantimnot@users.noreply.github.com>
* Add 'usages' option to the --stylechecks error msg (#19759)Zoom2022-05-041-2/+2
|
* Fix fixAbstractType for user defined typeclasses, fixes #19730 & #18409 (#19732)nc-x2022-04-301-1/+1
|
* Make sure that field usage preserves the original line info (#19751)Ivan Yonchovski2022-04-291-0/+2
| | | | Currently `struct.field` will generate a node with `info` that points to the symbol definition instead of having the actual node location.
* fixes #18612; apply cache and memcmp for methods in arc/orc (#19749)flywind2022-04-261-2/+5
| | | | | | | | | | | | | | | | | * try using endsWith * use memcmp * add cache * cleanup * better * minor * fix * improve test coverage for methods with ARC
* use signed comparisons for the index checking in the hope it improves the ↵Andreas Rumpf2022-04-261-7/+7
| | | | code generation (#19712)
* fixes #19662; Indent level errored for first line (#19718)flywind2022-04-253-1/+6
|
* fix NimNode comment repr() regression [backport: 1.2] (#19726)flywind2022-04-251-0/+2
|
* add warnings for gc:option (#19722)flywind2022-04-251-42/+49
|
* fix #19435; don't create TypeBoundOps for tyOpenArray, tyVarargs [backport: ↵flywind2022-04-251-1/+1
| | | | | | | | | 1.6] (#19723) * fix #19435; openArray wronyly registers typebounds * add testcase * don't create TypeBoundOps for tyOpenArray, tyVarargs
* Move common Latex code into class nimdoc.cls (#19734)Andrey Makarov2022-04-212-1/+7
|
* fix #19680; check if stderr is static (#19709)flywind2022-04-121-1/+1
|
* fix #17286 nim check -b:js works (#19704)flywind2022-04-091-0/+2
| | | | | * fix #17286 nim check -b:js works * fix
* fix stylecheck bug with nre (#19356)flywind2022-04-081-3/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | * stylecheck usages part two: stdlib cleanup typeinfo.nim: importCompilerProc => importcompilerproc nre.nim: newLineFlags => newlineFlags system.nim: JSRoot => JsRoot ref #19319 * prefer importCompilerProc * fix stylecheck error with asyncdispatch it is a partial regression since #12842 * add tests * don't use echo in tests * fix stylecheck bug with nre * Update compiler/linter.nim * no need to check dotexpr again * neither did let/var/const
* [nimsuggest] return the type when on symbol in let/var (#19639)Ivan Yonchovski2022-04-071-3/+6
| | | - make sure `suggestSym` is called after `PSym.typ` is set.
* fix #18986; Import/except doesn't work on devel [backport: 1.6] (#19687)flywind2022-04-061-1/+1
| | | | | * fix #18986; Import/except doesn't work on devel [backport: 1.6] * add testcase
* Fix bug in freshVarForClosureIter. Fixes #18474 (#19675) [backport]flywind2022-04-043-21/+17
| | | | | | | | | | * Fix bug in freshVarForClosureIter. Fixes #18474. freshVarForClosureIter was returning non-fresh symbols sometimes. Fixed by making addField return the generated PSym. * remove discardable Co-authored-by: Nick Smallbone <nick@smallbone.se>
* fixes #14318 (#14335)Andreas Rumpf2022-03-261-1/+1
|
* fix #8219; nim check/dump shouldn't run single nimscript project [backport: ↵flywind2022-03-261-1/+2
| | | | | | 1.6] (#19641) * fix #8219; nim check/dump shouldn't run single nimscript project [backport: 1.6]
* remove tmpFramePtr when optStackTrace is absent (#19649)flywind2022-03-261-4/+0
|
* fixes #19603; some pragmas were really only supported as top level ↵Andreas Rumpf2022-03-262-7/+16
| | | | statements. Now this is enforced properly. (#19646)
* mitigates #19364 [backport]; we make this bug more unlikely to appear by ↵Andreas Rumpf2022-03-261-6/+12
| | | | producing better code to begin with; real fix will come later (#19647)
* remove unnecessary framePtr code (#19645)flywind2022-03-251-3/+6
|
* fix nim check nimscript [backport: 1.6] (#19444)flywind2022-03-232-1/+7
| | | | fix #19440; fix #3858
* output byref types into --header file [backport: 1.6] (#19505)flywind2022-03-231-2/+7
| | | | | | | | | * output byref types into --header file fix #19445 * fix comments * set targets
* move assertions out of system (#19599)flywind2022-03-2379-1/+251
|
tik K. Agaram <vc@akkartik.com> 2022-12-23 19:26:05 -0800 committer Kartik K. Agaram <vc@akkartik.com> 2022-12-23 19:32:58 -0800 consistent names in a few more places' href='/akkartik/text.love/commit/source.lua?id=e0448d7d7f1f6ec7ff88b222f59abe88503437e6'>e0448d7 ^
e1c5a42 ^



2b3e09c ^
e1c5a42 ^

2b3e09c ^
e1c5a42 ^
2b3e09c ^
e1c5a42 ^


99faf61 ^








2b3e09c ^
e1c5a42 ^
936d3b4 ^
2b3e09c ^
936d3b4 ^

e1c5a42 ^
2b3e09c ^
e1c5a42 ^
2b3e09c ^
e1c5a42 ^


2b3e09c ^
e1c5a42 ^


2b3e09c ^
e1c5a42 ^





69f4062 ^
a874747 ^

69f4062 ^

e1c5a42 ^
a874747 ^


0cc8c70 ^
e1c5a42 ^

f9bea77 ^



076611f ^
f9bea77 ^
076611f ^
f9bea77 ^




e1c5a42 ^

e1c5a42 ^


2b3e09c ^
e1c5a42 ^
2b3e09c ^
e1c5a42 ^


2b3e09c ^
e1c5a42 ^

2b3e09c ^
e1c5a42 ^
2b3e09c ^
e1c5a42 ^

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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399











                                                 
                      



                  

                




                   

                      


















                          
                
                                                      
   
                                                                                      
 
                                                                
 





                            
                   





                                        
                               




                                                                        



                                                                                        
                                             


 

   
                                 
                                                                                                           


                                      






                                                                                         
                               
 





                                                             






                           




                         


                                                                    




                                                                          







                                                                                                                                  
                                                                                                                                                      








                                                                                         


                                                           






                                                                                     




                                                           
                                     
                                                                                              
                                   

                                                        

   
                                            









                                                                             
                                   
                                                                          


















                                                                                       
                               











                                                       



                                                                                        
                                             


 

   
                                                   




                                                       

                                                                                                                       



                                     






                                                                            


                      
                                                                 




                                                                                                     
                                                                                 
     
                        






                                                                                                    













                                             


                          

                                                         
                                                                                            
                                                                                                                       



                                                                                        
                                   
                                    




                                                
                                              



                                                                         

                                                                                                                   
                                                     

          
                                               


                                   
            
       
                                                     



                                                                                                   
            
       
                                                                 



                                                                                                                 
                                                

                                                                         
                                                              
      
                                                                          


     








                                                                         
                             
                                                                         
                             
                                   

          
                         
                                           
      
                                                       


     
                                          


                                                                         
                                                





                                                     
                                                            

                                                               

                                                               
        


                                                               
       

          



                                                
                                       
                 
                                                          




                                                       

                              


                         
                                                        
      
                                                                    


     
                                          

                                                                         
                                                        
      
                                                                            

     
source = {}

Editor_state = {}

-- called both in tests and real run
function source.initialize_globals()
  -- tests currently mostly clear their own state

  Show_log_browser_side = false
  Focus = 'edit'
  Show_file_navigator = false
  File_navigation = {
    all_candidates = {
      'run',
      'run_tests',
      'log',
      'edit',
      'drawing',
      'help',
      'text',
      'search',
      'select',
      'undo',
      'text_tests',
      'geom',
      'drawing_tests',
      'file',
      'source',
      'source_tests',
      'commands',
      'log_browser',
      'source_edit',
      'source_text',
      'source_undo',
      'colorize',
      'source_text_tests',
      'source_file',
      'main',
      'button',
      'keychord',
      'app',
      'test',
      'json',
    },
    index = 1,
    filter = '',
    cursors = {},  -- filename to cursor1, screen_top1
  }
  File_navigation.candidates = File_navigation.all_candidates  -- modified with filter

  Menu_status_bar_height = 5 + --[[line height in tests]] 15 + 5

  -- blinking cursor
  Cursor_time = 0
end

-- called only for real run
function source.initialize()
  log_new('source')
  if Settings and Settings.source then
    source.load_settings()
  else
    source.initialize_default_settings()
  end

  source.initialize_edit_side()
  source.initialize_log_browser_side()

  Menu_status_bar_height = 5 + Editor_state.line_height + 5
  Editor_state.top = Editor_state.top + Menu_status_bar_height
  Log_browser_state.top = Log_browser_state.top + Menu_status_bar_height



  -- keep a few blank lines around: https://merveilles.town/@akkartik/110084833821965708
  love.window.setTitle('lines.love - source')



end

-- environment for a mutable file
-- TODO: some initialization is also happening in load_settings/initialize_default_settings. Clean that up.
function source.initialize_edit_side()
  load_from_disk(Editor_state)
  Text.redraw_all(Editor_state)
  if File_navigation.cursors[Editor_state.filename] then
    Editor_state.screen_top1 = File_navigation.cursors[Editor_state.filename].screen_top1
    Editor_state.cursor1 = File_navigation.cursors[Editor_state.filename].cursor1
  else
    Editor_state.screen_top1 = {line=1, pos=1}
    Editor_state.cursor1 = {line=1, pos=1}
  end
  edit.check_locs(Editor_state)

  if Editor_state.cursor1.line > #Editor_state.lines then
    Editor_state.cursor1 = {line=1, pos=1}
  end
  if Editor_state.screen_top1.line > #Editor_state.lines then
    Editor_state.screen_top1 = {line=1, pos=1}
  end

  if rawget(_G, 'jit') then
    jit.off()
    jit.flush()
  end
end

function print_and_log(s)
  print(s)
  log(3, s)
end

function source.load_settings()
  local settings = Settings.source
  love.graphics.setFont(love.graphics.newFont(settings.font_height))
  -- set up desired window dimensions and make window resizable
  _, _, App.screen.flags = App.screen.size()
  App.screen.flags.resizable = true
  App.screen.width, App.screen.height = settings.width, settings.height
  App.screen.resize(App.screen.width, App.screen.height, App.screen.flags)
  source.set_window_position_from_settings(settings)
  Show_log_browser_side = settings.show_log_browser_side
  local right = App.screen.width - Margin_right
  if Show_log_browser_side then
    right = App.screen.width/2 - Margin_right
  end
  Editor_state = edit.initialize_state(Margin_top, Margin_left, right, settings.font_height, math.floor(settings.font_height*1.3))
  Editor_state.filename = settings.filename
  Editor_state.filename = basename(Editor_state.filename)  -- migrate settings that used full paths; we now support only relative paths within the app
  if settings.cursors then
    File_navigation.cursors = settings.cursors
    Editor_state.screen_top1 = File_navigation.cursors[Editor_state.filename].screen_top1
    Editor_state.cursor1 = File_navigation.cursors[Editor_state.filename].cursor1
  else
    -- migrate old settings
    Editor_state.screen_top1 = {line=1, pos=1}
    Editor_state.cursor1 = {line=1, pos=1}
  end
end

function source.set_window_position_from_settings(settings)
  local os = love.system.getOS()
  if os == 'Linux' then
    -- love.window.setPosition doesn't quite seem to do what is asked of it on Linux.
    App.screen.move(settings.x, settings.y-37, settings.displayindex)
  else
    App.screen.move(settings.x, settings.y, settings.displayindex)
  end
end

function source.initialize_default_settings()
  local font_height = 20
  love.graphics.setFont(love.graphics.newFont(font_height))
  source.initialize_window_geometry()
  Editor_state = edit.initialize_state(Margin_top, Margin_left, App.screen.width-Margin_right)
  Editor_state.filename = 'run.lua'
  Editor_state.font_height = font_height
  Editor_state.line_height = math.floor(font_height*1.3)
end

function source.initialize_window_geometry()
  -- Initialize window width/height and make window resizable.
  --
  -- I get tempted to have opinions about window dimensions here, but they're
  -- non-portable:
  --  - maximizing doesn't work on mobile and messes things up
  --  - maximizing keeps the title bar on screen in Linux, but off screen on
  --    Windows. And there's no way to get the height of the title bar.
  -- It seems more robust to just follow LÖVE's default window size until
  -- someone overrides it.
  App.screen.width, App.screen.height, App.screen.flags = App.screen.size()
  App.screen.flags.resizable = true
  App.screen.resize(App.screen.width, App.screen.height, App.screen.flags)
end

function source.resize(w, h)
--?   print(("Window resized to width: %d and height: %d."):format(w, h))
  App.screen.width, App.screen.height = w, h
  Text.redraw_all(Editor_state)
  Editor_state.selection1 = {}  -- no support for shift drag while we're resizing
  if Show_log_browser_side then
    Editor_state.right = App.screen.width/2 - Margin_right
  else
    Editor_state.right = App.screen.width-Margin_right
  end
  Log_browser_state.left = App.screen.width/2 + Margin_right
  Log_browser_state.right = App.screen.width-Margin_right
  Editor_state.width = Editor_state.right-Editor_state.left
  Text.tweak_screen_top_and_cursor(Editor_state, Editor_state.left, Editor_state.right)
--?   print('end resize')
end

function source.file_drop(file)
  -- first make sure to save edits on any existing file
  if Editor_state.next_save then
    save_to_disk(Editor_state)
  end
  -- clear the slate for the new file
  Editor_state.filename = file:getFilename()
  file:open('r')
  Editor_state.lines = load_from_file(file)
  file:close()
  Text.redraw_all(Editor_state)
  Editor_state.screen_top1 = {line=1, pos=1}
  Editor_state.cursor1 = {line=1, pos=1}



  -- keep a few blank lines around: https://merveilles.town/@akkartik/110084833821965708
  love.window.setTitle('lines.love - source')



end

-- a copy of source.file_drop when given a filename
function source.switch_to_file(filename)
  -- first make sure to save edits on any existing file
  if Editor_state.next_save then
    save_to_disk(Editor_state)
  end
  -- save cursor position
  File_navigation.cursors[Editor_state.filename] = {cursor1=Editor_state.cursor1, screen_top1=Editor_state.screen_top1}
  -- clear the slate for the new file
  Editor_state.filename = filename
  load_from_disk(Editor_state)
  Text.redraw_all(Editor_state)
  if File_navigation.cursors[filename] then
    Editor_state.screen_top1 = File_navigation.cursors[filename].screen_top1
    Editor_state.cursor1 = File_navigation.cursors[filename].cursor1
  else
    Editor_state.screen_top1 = {line=1, pos=1}
    Editor_state.cursor1 = {line=1, pos=1}
  end
end

function source.draw()
  edit.draw(Editor_state, --[[hide cursor?]] Show_file_navigator)
  if Show_log_browser_side then
    -- divider
    App.color(Divider_color)
    love.graphics.rectangle('fill', App.screen.width/2-1,Menu_status_bar_height, 3,App.screen.height)
    --
    log_browser.draw(Log_browser_state, --[[hide_cursor]] Focus ~= 'log_browser')
  end
  source.draw_menu_bar()
  if Error_message then
    local height = math.min(20*Editor_state.line_height, App.screen.height*0.2)
    App.color{r=0.8,g=0,b=0}
    love.graphics.rectangle('fill', 150, App.screen.height - height-10, App.screen.width, height+10)
    App.color{r=0,g=0,b=0}
    love.graphics.print(Error_message, 150+10, App.screen.height - height)
  end
end

function source.update(dt)
  Cursor_time = Cursor_time + dt
  if App.mouse_x() < Editor_state.right then
    edit.update(Editor_state, dt)
  elseif Show_log_browser_side then
    log_browser.update(Log_browser_state, dt)
  end
end

function source.quit()
  edit.quit(Editor_state)
  log_browser.quit(Log_browser_state)
end

function source.settings()
  if Settings == nil then Settings = {} end
  if Settings.source == nil then Settings.source = {} end
  Settings.source.x, Settings.source.y, Settings.source.displayindex = App.screen.position()
  File_navigation.cursors[Editor_state.filename] = {cursor1=Editor_state.cursor1, screen_top1=Editor_state.screen_top1}
  return {
    x=Settings.source.x, y=Settings.source.y, displayindex=Settings.source.displayindex,
    width=App.screen.width, height=App.screen.height,
    font_height=Editor_state.font_height,
    filename=Editor_state.filename,
    cursors=File_navigation.cursors,
    show_log_browser_side=Show_log_browser_side,
    focus=Focus,
  }
end

function source.mouse_press(x,y, mouse_button)
  Cursor_time = 0  -- ensure cursor is visible immediately after it moves
--?   print('mouse click', x, y)
--?   print(Editor_state.left, Editor_state.right)
--?   print(Log_browser_state.left, Log_browser_state.right)
  if Show_file_navigator and y < Menu_status_bar_height + File_navigation.num_lines * Editor_state.line_height then
    -- send click to buttons
    edit.mouse_press(Editor_state, x,y, mouse_button)
    return
  end
  if x < Editor_state.right + Margin_right then
--?     print('click on edit side')
    if Focus ~= 'edit' then
      Focus = 'edit'
      return
    end
    edit.mouse_press(Editor_state, x,y, mouse_button)
  elseif Show_log_browser_side and Log_browser_state.left <= x and x < Log_browser_state.right then
--?     print('click on log_browser side')
    if Focus ~= 'log_browser' then
      Focus = 'log_browser'
      return
    end
    log_browser.mouse_press(Log_browser_state, x,y, mouse_button)
    for _,line_cache in ipairs(Editor_state.line_cache) do line_cache.starty = nil end  -- just in case we scroll
  end
end

function source.mouse_release(x,y, mouse_button)
  Cursor_time = 0  -- ensure cursor is visible immediately after it moves
  if Focus == 'edit' then
    return edit.mouse_release(Editor_state, x,y, mouse_button)
  else
    return log_browser.mouse_release(Log_browser_state, x,y, mouse_button)
  end
end

function source.mouse_wheel_move(dx,dy)
  Cursor_time = 0  -- ensure cursor is visible immediately after it moves
  if Focus == 'edit' then
    return edit.mouse_wheel_move(Editor_state, dx,dy)
  else
    return log_browser.mouse_wheel_move(Log_browser_state, dx,dy)
  end
end

function source.text_input(t)
  Cursor_time = 0  -- ensure cursor is visible immediately after it moves
  if Show_file_navigator then
    text_input_on_file_navigator(t)
    return
  end
  if Focus == 'edit' then
    return edit.text_input(Editor_state, t)
  else
    return log_browser.text_input(Log_browser_state, t)
  end
end

function source.keychord_press(chord, key)
  Cursor_time = 0  -- ensure cursor is visible immediately after it moves
--?   print('source keychord')
  if Show_file_navigator then
    keychord_press_on_file_navigator(chord, key)
    return
  end
  if chord == 'C-l' then
--?     print('C-l')
    Show_log_browser_side = not Show_log_browser_side
    if Show_log_browser_side then
      Editor_state.right = App.screen.width/2 - Margin_right
      Editor_state.width = Editor_state.right-Editor_state.left
      Text.redraw_all(Editor_state)
      Log_browser_state.left = App.screen.width/2 + Margin_left
      Log_browser_state.right = App.screen.width - Margin_right
    else
      Editor_state.right = App.screen.width - Margin_right
      Editor_state.width = Editor_state.right-Editor_state.left
      Text.redraw_all(Editor_state)
    end
    return
  end
  if chord == 'C-k' then
    -- clear logs
    love.filesystem.remove('log')
    -- restart to reload state of logs on screen
    Settings.source = source.settings()
    source.quit()
    love.filesystem.write('config', json.encode(Settings))
    load_file_from_source_or_save_directory('main.lua')
    App.undo_initialize()
    App.run_tests_and_initialize()
    return
  end
  if chord == 'C-g' then
    Show_file_navigator = true
    return
  end
  if Focus == 'edit' then
    return edit.keychord_press(Editor_state, chord, key)
  else
    return log_browser.keychord_press(Log_browser_state, chord, key)
  end
end

function source.key_release(key, scancode)
  Cursor_time = 0  -- ensure cursor is visible immediately after it moves
  if Focus == 'edit' then
    return edit.key_release(Editor_state, key, scancode)
  else
    return log_browser.keychord_press(Log_browser_state, chordkey, scancode)
  end
end