rabbit-slide-hasumikin-RubyConf2021 2021.11.08.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. data/.rabbit +1 -0
  3. data/On-a-Keyboard-Ruby-on-Board--PicoRuby-and-PRK-Firmware.rab +816 -0
  4. data/README.rd +24 -0
  5. data/Rakefile +17 -0
  6. data/config.yaml +25 -0
  7. data/images/Multitasking.png +0 -0
  8. data/images/Multitasking_sandbox.png +0 -0
  9. data/images/Notepad.png +0 -0
  10. data/images/QR_prk_firmware.png +0 -0
  11. data/images/QR_raactivityreport.png +0 -0
  12. data/images/QR_raactivityreport_2.png +0 -0
  13. data/images/RAGrant.png +0 -0
  14. data/images/architecture_1.png +0 -0
  15. data/images/architecture_2.png +0 -0
  16. data/images/architecture_3.png +0 -0
  17. data/images/architecture_4.png +0 -0
  18. data/images/black.png +0 -0
  19. data/images/boot_button_1.png +0 -0
  20. data/images/crkbd.jpg +0 -0
  21. data/images/crkbd_2.jpg +0 -0
  22. data/images/drag_and_drop_1.png +0 -0
  23. data/images/drag_and_drop_2.png +0 -0
  24. data/images/firmware_logos.png +0 -0
  25. data/images/gem.gif +0 -0
  26. data/images/gem_32.gif +0 -0
  27. data/images/gem_40.gif +0 -0
  28. data/images/gem_48.gif +0 -0
  29. data/images/keyboard.rb.png +0 -0
  30. data/images/keycaps.png +0 -0
  31. data/images/kmk.jpg +0 -0
  32. data/images/matrix_claw44.jpg +0 -0
  33. data/images/matrix_helix.jpg +0 -0
  34. data/images/matrix_prk_firmware.jpg +0 -0
  35. data/images/meishi2.jpg +0 -0
  36. data/images/msc.png +0 -0
  37. data/images/picoruby.png +0 -0
  38. data/images/pipi_gherkin.jpg +0 -0
  39. data/images/pipigherkin_2.jpg +0 -0
  40. data/images/prk.png +0 -0
  41. data/images/promicro.jpg +0 -0
  42. data/images/promicro_rp2040.jpg +0 -0
  43. data/images/promicro_rp2040_boot_button.png +0 -0
  44. data/images/qmk.png +0 -0
  45. data/images/qmk_kmk_prk.png +0 -0
  46. data/images/qmk_kmk_prk_2.png +0 -0
  47. data/images/red_pill.png +0 -0
  48. data/images/red_pill_24.png +0 -0
  49. data/images/red_pill_32.png +0 -0
  50. data/images/red_pill_40.png +0 -0
  51. data/images/red_pill_48.png +0 -0
  52. data/images/regex_light.png +0 -0
  53. data/images/release.png +0 -0
  54. data/images/rpi_pico.jpg +0 -0
  55. data/images/shortage.jpg +0 -0
  56. data/images/shortage.png +0 -0
  57. data/images/switches.png +0 -0
  58. data/images/textedit.png +0 -0
  59. data/no_rabbit.rab +209 -0
  60. data/pdf/RubyConf2021-On-a-Keyboard-Ruby-on-Board--PicoRuby-and-PRK-Firmware.pdf +0 -0
  61. data/theme.rb +181 -0
  62. metadata +117 -0
@@ -0,0 +1,816 @@
1
+ = On a Keyboard Ruby on Board
2
+
3
+ : subtitle
4
+ PicoRuby and PRK Firmware
5
+ : author
6
+ hasumikin
7
+ : place
8
+ RubyConf 2021 / Nov 8-10
9
+ : allotted-time
10
+ 30m
11
+ : theme
12
+ theme
13
+
14
+ = HIDE
15
+ Wake up, Ruby...
16
+
17
+ = HIDE
18
+ The Micon has you...
19
+
20
+ = HIDE
21
+ Follow the white rabbit.
22
+
23
+ = HIDE
24
+ \n\n\n\n
25
+ \n\n\n\n
26
+ \n\n
27
+ (('tag:small:Hi!'))
28
+
29
+ = VCENTER HCENTER XXLARGE
30
+ PicoRuby
31
+ \n
32
+ and
33
+ \n
34
+ PRK Firmware
35
+
36
+ = VCENTER HCENTER XLARGE
37
+ PicoRuby
38
+ \n
39
+ is a Ruby interpreter
40
+ \n
41
+ for Microcontorollers
42
+
43
+ = VCENTER HCENTER XLARGE
44
+ PRK Firmware
45
+ \n
46
+ is a keyboard firmware
47
+ \n
48
+ framework in PicoRuby
49
+
50
+ = VCENTER HCENTER XXLARGE
51
+ PRK Firmware
52
+
53
+ = Hardware became familiar
54
+ * You can design your PCB even on a web browser
55
+ * PCB manufacturers are willing to accept your PCB data via the internet
56
+ * You can receive your PCB or even PCBA (assembled PCB) that arrives from overseas
57
+
58
+ = When you build a keyboard
59
+ * You can choose
60
+ * Keycaps for appearance and touch
61
+ # image
62
+ # src = images/keycaps.png
63
+ # relative_width = 90
64
+
65
+ (('tag:xx-small'))(('tag:right'))
66
+ https://talpkeyboard.net/?category_id=59be183f428f2d49120007b1
67
+
68
+ = When you build a keyboard
69
+ * You can choose
70
+ * Keycaps for appearance and touch
71
+ * Switches for touch
72
+ # image
73
+ # src = images/switches.png
74
+ # relative_width = 90
75
+
76
+ (('tag:xx-small'))(('tag:right'))
77
+ https://talpkeyboard.net/?category_id=59cf8860ed05e668db003f5d
78
+
79
+ = When you build a keyboard
80
+ * You can choose
81
+ * Keycaps for appearance and touch
82
+ * Switches for touch
83
+ * Layout for usability and appearance
84
+ # image
85
+ # src = images/crkbd_2.jpg
86
+ # relative_height = 110
87
+
88
+ = When you build a keyboard
89
+ * You can choose
90
+ * Keycaps for appearance and touch
91
+ * Switches for touch
92
+ * Layout for usability and appearance
93
+ * Firmware for programmability
94
+ # image
95
+ # src = images/firmware_logos.png
96
+ # relative_height = 90
97
+
98
+ = Keyboard firmware
99
+ * QMK Firmware ... C
100
+ * KMK Firmware ... Python
101
+ * PRK Firmware ... ((*Ruby*))
102
+ # image
103
+ # src = images/firmware_logos.png
104
+ # relative_height = 90
105
+
106
+ = Keyboard firmware
107
+ # image
108
+ # src = images/qmk_kmk_prk.png
109
+ # relative_height = 103
110
+ # relative_margin_top = 0
111
+
112
+ = Stargaze at picoruby/prk_firmware!
113
+ # image
114
+ # src = images/qmk_kmk_prk_2.png
115
+ # relative_height = 103
116
+ # relative_margin_top = 0
117
+
118
+ = e.g.) picoruby/prk_pipigherkin
119
+ * Gherkin for the Raspberry Pi Pico
120
+ * PCB available on talpkeyboard.net
121
+ * Easy to explain but ((*hard for newbies*)) to build
122
+
123
+ # image
124
+ # src = images/pipigherkin_2.jpg
125
+ # relative-height = 90
126
+
127
+ (('tag:right'))\n\n
128
+ (('tag:xx-small:https://www.40percent.club/2021/02/pipi-gherkin.html'))
129
+
130
+ = e.g.) prk_pipigherkin/keymap.rb
131
+ # enscript ruby
132
+ # Initialize Keyboard
133
+ kbd = Keyboard.new
134
+ # Initialize GPIO pins
135
+ kbd.init_pins(
136
+ [ 12, 11, 10, 9, 8 ], # row0, row1,... respectively
137
+ [ 7, 6, 5, 4, 3, 2 ] # col0, col1,... respectively
138
+ )
139
+
140
+ = e.g.) prk_pipigherkin/keymap.rb
141
+ # enscript ruby
142
+ # Default keymap
143
+ kbd.add_layer :default, %i(
144
+ KC_Q KC_W KC_E KC_R KC_T KC_Y KC_U KC_I KC_O KC_P
145
+ KC_A KC_S KC_D KC_F KC_G KC_H KC_J KC_K KC_L KC_BSPACE
146
+ Z_LSFT X_LGUI C_LALT V_LCTL SPC_LOWER ENT_RAISE B_RCTL N_RALT M_RGUI UNDS_RSFT
147
+ )
148
+ kbd.add_layer :raise, %i(
149
+ KC_EXLM KC_AT KC_HASH KC_DLR KC_PERC KC_CIRC KC_AMPR KC_ASTER KC_EQUAL KC_PLUS
150
+ KC_LABK KC_LCBR KC_LBRACKET KC_LPRN KC_MINUS KC_LEFT KC_DOWN KC_UP KC_RIGHT KC_BSPACE
151
+ KC_RABK KC_RCBR KC_RBRACKET KC_RPRN ADJUST ENT_RAISE KC_BSLASH KC_COMMA KC_DOT KC_SLASH
152
+ )
153
+ kbd.add_layer :lower, %i(
154
+ KC_1 KC_2 KC_3 KC_4 KC_5 KC_6 KC_7 KC_8 KC_9 KC_0
155
+ KC_TAB KC_NO KC_QUOTE KC_DQUO KC_MINUS KC_GRAVE KC_TILD KC_PIPE KC_COLON KC_SCOLON
156
+ KC_ESCAPE KC_LGUI KC_LALT KC_LCTL SPC_LOWER ADJUST KC_RCTL KC_RALT KC_RGUI KC_RSFT
157
+ )
158
+ # Mode keys
159
+ kbd.define_mode_key :Z_LSFT, [ :KC_Z, :KC_LSFT, 150, 150 ]
160
+ # ...
161
+ kbd.define_mode_key :UNDS_RSFT, [ :KC_UNDS, :KC_RSFT, 200, 150 ]
162
+ kbd.define_mode_key :ENT_RAISE, [ :KC_ENTER, :raise, 150, 150 ]
163
+ kbd.define_mode_key :SPC_LOWER, [ :KC_SPACE, :lower, 300, 250 ]
164
+
165
+ = picoruby/prk_firmware/releases
166
+ # image
167
+ # src = images/release.png
168
+ # relative-height = 95
169
+
170
+ = Install into the microcontroller
171
+ * Connect USB cable while\npressing "boot button"
172
+ * RPI-RP2 will be mounted\nas storage, then
173
+
174
+ # image
175
+ # align = right
176
+ # src = images/boot_button_1.png
177
+ # relative-height = 83
178
+ # relative_margin_left = 7
179
+ # relative_margin_top = -3
180
+
181
+ (('tag:right'))
182
+ (('tag:xx-small'))\n\n\n\n\n\n\n\n\n\n\n
183
+ https://www.raspberrypi.org/documentation/rp2040/getting-started
184
+
185
+ = Install into the microcontroller
186
+ # image
187
+ # src = images/promicro_rp2040_boot_button.png
188
+ # relative-height = 80
189
+
190
+ (('tag:center'))Boot button on Pro Micro RP2040
191
+
192
+ = Install into the microcontroller
193
+ # image
194
+ # src = images/drag_and_drop_1.png
195
+ # relative-height = 95
196
+
197
+ = A new drive automatically mounted
198
+ \n
199
+ (('tag:xx-large'))๐Ÿ˜Ž
200
+
201
+ # image
202
+ # align = right
203
+ # src = images/msc.png
204
+ # relative-height = 95
205
+ # relative_margin_left = 5
206
+
207
+ = ((*Drag & drop keymap.rb*))
208
+ # image
209
+ # src = images/drag_and_drop_2.png
210
+ # relative-height = 95
211
+
212
+ = HCENTER VCENTER XXLARGE TITLE
213
+ (('tag:small:T H E'))
214
+ \n
215
+ KEYMAP
216
+ \n
217
+ RELOADED
218
+
219
+ = VCENTER HCENTER XLARGE
220
+ Unlike QMK Firmware,\n
221
+ You don't need\n
222
+ to ((*compile*))\n
223
+ anything!
224
+
225
+ = Demonstrations
226
+ # image
227
+ # src = images/meishi2.jpg
228
+ # relative-height = 60
229
+
230
+ * meishi keypad
231
+ * meishi means "name card"
232
+ * Four keys macro pad
233
+
234
+ = VCENTER HCENTER XLARGE
235
+ Fibonacci number
236
+ \n
237
+ (DEMO)
238
+
239
+ = Fibonacci in keymap.rb
240
+ # enscript ruby
241
+ class Fibonacci
242
+ def initialize
243
+ @a = 0 ; @b = 1
244
+ end
245
+ # Omits F0 and F1
246
+ def take
247
+ result = @a + @b
248
+ @a = @b
249
+ @b = result
250
+ end
251
+ end
252
+ fibonacci = Fibonacci.new
253
+ kbd.define_mode_key :FIBONACCI,
254
+ [ Proc.new { kbd.macro fibonacci.take },
255
+ :KC_NO, 300, nil ]
256
+
257
+ = VCENTER HCENTER XLARGE
258
+ Password generator
259
+ \n
260
+ (DEMO)
261
+
262
+ = Password generator in keymap.rb
263
+ # enscript ruby
264
+ class Password
265
+ def initialize(c = nil)
266
+ @c = c || 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_!@#$%^&*()=-+/[]{}<>'
267
+ end
268
+ def generate
269
+ unless @srand
270
+ srand(board_millis) # generate rand()'s seed by board_millis
271
+ @srand = true
272
+ end
273
+ password = ""
274
+ while true
275
+ i = rand % 100
276
+ password << @c[i].to_s
277
+ break if password.length == 8
278
+ end
279
+ return password
280
+ end
281
+ end
282
+ passwd = Password.new
283
+ kbd.define_mode_key :PASSWD,
284
+ [ Proc.new { kbd.macro passwd.generate, [] },
285
+ :KC_NO, 300, nil ]
286
+
287
+ (('tag:center'))(('tag:x-small:Use it at your own risk'))
288
+
289
+ = Extend your keyboard
290
+ \n
291
+ If you wanna input ((*";"*)) with SHIFT and ((*":"*)) without SHIFT,
292
+
293
+ # enscript ruby
294
+ kbd.before_report do
295
+ kbd.invert_sft if kbd.keys_include?(:KC_SCOLON)
296
+ end
297
+
298
+ (('tag:center'))
299
+ You no longer need to modify .vimrc
300
+
301
+ = Extend your keyboard
302
+ # enscript ruby
303
+ class Keyboard
304
+ def invert_ctl
305
+ # KC_LCTL: 0b00000001 ๐Ÿ‘ˆ
306
+ # KC_LSFT: 0b00000010
307
+ # KC_LALT: 0b00000100
308
+ # KC_LGUI: 0b00001000
309
+ # KC_RCTL: 0b00010000 ๐Ÿ‘ˆ
310
+ # KC_RSFT: 0b00100000
311
+ # KC_RALT: 0b01000000
312
+ # KC_RGUI: 0b10000000
313
+ if (@modifier & 0b00010001) > 0
314
+ @modifier &= 0b11101110
315
+ else
316
+ @modifier |= 0b00000001
317
+ end
318
+ end
319
+ end
320
+ kbd.before_report do
321
+ kbd.invert_ctl if kbd.keys_include?(:KC_V)
322
+ end
323
+
324
+ = VCENTER HCENTER XLARGE
325
+ Ruby-mode key
326
+ \n
327
+ (DEMO)
328
+
329
+ = HCENTER VCENTER XXLARGE TITLE
330
+ (('tag:small:T H E'))
331
+ \n
332
+ KEYBOARD
333
+ \n
334
+ REVOLUTIONS
335
+
336
+ = Micon of PRK Firmware
337
+ * Target MCU is "RP2040"
338
+ * Raspberry Silicon
339
+ * Implemented on Raspberry Pi Pico
340
+ * 264KB RAM
341
+ * Arm 32bit Cortex-M0+ (dual)
342
+
343
+ (('tag:right'))
344
+ (('tag:xx-small'))
345
+ \n\n\n\n\n\n\n\n\n\n\n
346
+ https://pc.watch.impress.co.jp/docs/news/1301670.html
347
+
348
+ # image
349
+ # src = images/rpi_pico.jpg
350
+ # align = right
351
+ # relative-height = 90
352
+ # relative_margin_left = 2
353
+
354
+ = Micon of PRK Firmware
355
+ * RP2040 assembled\non Pro Micro\n((*SPARKFUN*))\n((*PRO MICRO - RP2040*))\n[model no. DEV-18288]
356
+
357
+ # image
358
+ # src = images/promicro_rp2040.jpg
359
+ # align = right
360
+ # relative-height = 85
361
+ # relative_margin_left = 10
362
+
363
+ (('tag:right'))\n\n\n\n
364
+ (('tag:xx-small:https://www.sparkfun.com/products/18288'))
365
+
366
+ = VCENTER HCENTER XXLARGE
367
+ PicoRuby
368
+
369
+ = https://ruby.or.jp/en
370
+ # image
371
+ # src = images/RAGrant.png
372
+ # relative_width = 94
373
+
374
+ = Multitasking
375
+ # image
376
+ # src = images/Multitasking.png
377
+ # relative_width = 100
378
+ # relative_margin_top = 0
379
+
380
+ = Multitasking
381
+ # image
382
+ # src = images/Multitasking_sandbox.png
383
+ # relative_width = 100
384
+ # relative_margin_top = 0
385
+
386
+ = HCENTER VCENTER XXLARGE TITLE
387
+ (('tag:small:T H E'))
388
+ \n
389
+ RUBY
390
+ \n
391
+ RESURRECTIONS
392
+
393
+ = Architecture
394
+ # image
395
+ # src = images/architecture_1.png
396
+ # relative_width = 100
397
+ # relative_margin_top = 0
398
+
399
+ * An mruby app generally consists of ((*VM code*)) and ((*VM*))
400
+ * mruby-compiler has somehow big footprint
401
+ * It isn't assumed to be embedded
402
+
403
+ = Architecture
404
+ # image
405
+ # src = images/architecture_2.png
406
+ # relative_width = 100
407
+ # relative_margin_top = 0
408
+
409
+ * Technically, you can embed also ((*Ruby script*)) and ((*mruby-compiler*))
410
+ * It makes sense if the computing resource is big enough
411
+
412
+ = Architecture
413
+ # image
414
+ # src = images/architecture_3.png
415
+ # relative_width = 100
416
+ # relative_margin_top = 0
417
+
418
+ * mruby/c is a smaller VM for one-chip microcontrollers
419
+ * Naturally, we don't embed mruby-compiler with it
420
+
421
+ = Architecture
422
+ # image
423
+ # src = images/architecture_4.png
424
+ # relative_width = 100
425
+ # relative_margin_top = 0
426
+
427
+ (('tag:center:PicoRuby = PicoRuby-compiler + mruby/cVM'))
428
+
429
+ = Architecture
430
+ * As you know, the syntax of Ruby is complicated
431
+ * Easy to imagine that a Ruby compiler consumes large memory
432
+
433
+ = Architecture
434
+ * You might think that you can use a microcontroller that has a big RAM
435
+ * The answer is "Yes and No"
436
+ * You should do it if you can
437
+ * The bigger RAM, the bigger electric energy consumption
438
+ * The bigger resource, the more expensive in general
439
+
440
+ = To make a small Ruby compiler
441
+ * mruby-compiler depends on mruby
442
+ * The main reason for big footprint
443
+ * PicoRuby compiler should be coded from scratch
444
+ * To make PicoRuby compiler small
445
+ * Every fine logic should be minimal
446
+ * Lemon parser generator instead of Bison/Yacc
447
+ * A part of SQLite project
448
+
449
+ = RAM consumption
450
+ $ valgrind \
451
+ --tool=massif \
452
+ --stacks=yes \
453
+ mrbc hello_world.rb
454
+
455
+ $ valgrind \
456
+ --tool=massif \
457
+ --stacks=yes \
458
+ picorbc hello_world.rb
459
+
460
+ $ ms_print massif.out.xxx | less
461
+
462
+ = hello_world.rb (20 bytes)
463
+ \n\n\n\n
464
+ (('tag:center:puts "Hello World!"'))
465
+
466
+ = mrbc hello_world.rb -> 133.5 KB
467
+ --------------------------------------------------------------------------------
468
+ Command: mrbc hello_world.rb
469
+ Massif arguments: --stacks=yes
470
+ --------------------------------------------------------------------------------
471
+ KB
472
+ 133.5^ #
473
+ | #
474
+ | #
475
+ | #
476
+ | #
477
+ | #
478
+ | #
479
+ | #
480
+ | #
481
+ | @:::@#:
482
+ | :::@:::::::@:::@:::@:::@#::
483
+ | ::::::@:::::@::@:::@::@::@:: ::::@:::@:::@:::@#::
484
+ | @@@@::::::: :@:: ::@::@: :@: @::@:: ::::@:::@:::@:::@#::
485
+ | @ :: :::: :@:: ::@::@: :@: @::@:: ::::@:::@:::@:::@#::
486
+ | @ :: :::: :@:: ::@::@: :@: @::@:: ::::@:::@:::@:::@#::
487
+ | @ :: :::: :@:: ::@::@: :@: @::@:: ::::@:::@:::@:::@#::
488
+ | @ :: :::: :@:: ::@::@: :@: @::@:: ::::@:::@:::@:::@#::
489
+ | @ :: :::: :@:: ::@::@: :@: @::@:: ::::@:::@:::@:::@#::
490
+ | @ :: :::: :@:: ::@::@: :@: @::@:: ::::@:::@:::@:::@#::
491
+ | @@ :: :::: :@:: ::@::@: :@: @::@:: ::::@:::@:::@:::@#::
492
+ 0 +----------------------------------------------------------------------->ki
493
+ 0 936.3
494
+
495
+ = picorbc hello_world.rb -> 16.98 KB
496
+ --------------------------------------------------------------------------------
497
+ Command: picorbc hello_world.rb
498
+ Massif arguments: --stacks=yes
499
+ --------------------------------------------------------------------------------
500
+ KB
501
+ 16.98^ #
502
+ | @::@# :::@:: @
503
+ | :@::@#::::@::::@ :::
504
+ | :@::@#::::@::::@::::
505
+ | :@::@#::::@::::@::::
506
+ | :@::@#::::@::::@::::
507
+ | :@::@#::::@::::@::::
508
+ | :@::@#::::@::::@::::@
509
+ | :@::@#::::@::::@::::@
510
+ | :@::@#::::@::::@::::@
511
+ | @@::@::@#::::@::::@::::@
512
+ | @ ::@::@#::::@::::@::::@
513
+ | @ ::@::@#::::@::::@::::@
514
+ | :: @ ::@::@#::::@::::@::::@
515
+ | : : @ ::@::@#::::@::::@::::@
516
+ | : : @ ::@::@#::::@::::@::::@
517
+ | : :: @ ::@::@#::::@::::@::::@
518
+ | : :: @ ::@::@#::::@::::@::::@
519
+ | : :: @ ::@::@#::::@::::@::::@
520
+ | :: :: :::::::::::::::::::::::::::@:::@: @ ::@::@#::::@::::@::::@:
521
+ 0 +----------------------------------------------------------------------->ki
522
+ 0 222.0
523
+
524
+ = keymap.rb of meish2 (2388 bytes)
525
+ #enscript ruby
526
+ while !$mutex
527
+ relinquish
528
+ end
529
+ kbd = Keyboard.new
530
+ kbd.init_pins(
531
+ [ 6, 7 ], # row0, row1
532
+ [ 28, 27 ] # col0, col1
533
+ )
534
+ kbd.add_layer :default, %i[ RUBY_GUI KC_1 RAISE_ENTER LOWER_SPACE ]
535
+ kbd.add_layer :raise, %i[ FIBONACCI PASSWD RAISE_ENTER ADJUST ]
536
+ kbd.add_layer :lower, %i[ KC_E KC_F RAISE_ENTER LOWER_SPACE) ]
537
+ kbd.add_layer :adjust, %i[ KC_SCOLON KC_LSFT RAISE_ENTER ADJUST ]
538
+ kbd.define_mode_key :RAISE_ENTER, [ :KC_ENTER, :raise, 200, 150 ]
539
+ kbd.define_mode_key :LOWER_SPACE, [ :KC_SPACE, :lower, 300, 400 ]
540
+ kbd.define_mode_key :ADJUST, [ nil, :adjust, nil, nil ]
541
+ kbd.define_mode_key :RUBY_GUI, [ Proc.new { kbd.ruby }, :KC_RGUI, 300, nil ]
542
+ class Fibonacci
543
+ def initialize
544
+ @a = 0 ; @b = 1
545
+ end
546
+ def take
547
+ result = @a + @b
548
+ @a = @b
549
+ @b = result
550
+ end
551
+ end
552
+ fibonacci = Fibonacci.new
553
+ kbd.define_mode_key :FIBONACCI, [ Proc.new { kbd.macro fibonacci.take }, :KC_NO, 300, nil ]
554
+ class Password
555
+ def initialize
556
+ @c = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_!@#$%^&*()=-+/[]{}<>'
557
+ end
558
+ def generate
559
+ unless @srand
560
+ # generate seed with board_millis
561
+ srand(board_millis)
562
+ @srand = true
563
+ end
564
+ password = ""
565
+ while true
566
+ i = rand % 100
567
+ password << @c[i].to_s
568
+ break if password.length == 8
569
+ end
570
+ return password
571
+ end
572
+ end
573
+ password = Password.new
574
+ kbd.define_mode_key :PASSWD, [ Proc.new { kbd.macro password.generate, [] }, :KC_NO, 300, nil ]
575
+ kbd.before_report do
576
+ kbd.invert_sft if kbd.keys_include?(:KC_SCOLON)
577
+ end
578
+ kbd.start!
579
+
580
+ = mrbc keymap.rb -> 206.1 KB
581
+ --------------------------------------------------------------------------------
582
+ Command: mrbc keymap.rb
583
+ Massif arguments: --stacks=yes
584
+ --------------------------------------------------------------------------------
585
+ KB
586
+ 206.1^ ##
587
+ | @#
588
+ | @#
589
+ | @#
590
+ | @#
591
+ | @#
592
+ | :@#
593
+ | :@#
594
+ | :@#
595
+ | ::::@#
596
+ | :: :@# :
597
+ | @::::::::::::::::::::: :@# :
598
+ | @::: :: ::: : :: ::::: :@# :
599
+ | @:::::@::: :: ::: : :: ::::: :@# :
600
+ | ::::::::@@::::::::@:: : @::: :: ::: : :: ::::: :@# ::
601
+ | @@::::::::: : :: @ :: : :: @:: : @::: :: ::: : :: ::::: :@# ::
602
+ | @ : :: : :: : :: @ :: : :: @:: : @::: :: ::: : :: ::::: :@# ::
603
+ | @ : :: : :: : :: @ :: : :: @:: : @::: :: ::: : :: ::::: :@# ::
604
+ | @ : :: : :: : :: @ :: : :: @:: : @::: :: ::: : :: ::::: :@# ::
605
+ | @ : :: : :: : :: @ :: : :: @:: : @::: :: ::: : :: ::::: :@# ::
606
+ 0 +----------------------------------------------------------------------->Mi
607
+ 0 1.476
608
+
609
+ = picorbc keymap.rb -> 61.98 KB
610
+ --------------------------------------------------------------------------------
611
+ Command: picorbc keymap.rb
612
+ Massif arguments: --stacks=yes
613
+ --------------------------------------------------------------------------------
614
+ KB
615
+ 61.98^ #
616
+ | @#
617
+ | @ @@#
618
+ | @@:@@#
619
+ | : @ @@:@@#
620
+ | @::::@:@:::@@:@@#
621
+ | : @::::@:@:::@@:@@#
622
+ | @@:@:::@::::@::::@:@:::@@:@@#
623
+ | @@:@:::@::::@::::@:@:::@@:@@#
624
+ | ::::@:::::@@:@:::@::::@::::@:@:::@@:@@#
625
+ | ::: @: :: @@:@:::@::::@::::@:@:::@@:@@#
626
+ | @@@::: ::::::: @: :: @@:@:::@::::@::::@:@:::@@:@@#
627
+ | @@ :::@::::: ::: @: :: @@:@:::@::::@::::@:@:::@@:@@#
628
+ | @:::: ::::@@ :::@::::: ::: @: :: @@:@:::@::::@::::@:@:::@@:@@#
629
+ | @:::::::: @@ :::@::::: ::: @: :: @@:@:::@::::@::::@:@:::@@:@@#
630
+ | @@: :::::@:::::::: @@ :::@::::: ::: @: :: @@:@:::@::::@::::@:@:::@@:@@#
631
+ | @ ::: :::@:::::::: @@ :::@::::: ::: @: :: @@:@:::@::::@::::@:@:::@@:@@#
632
+ | @ ::: :::@:::::::: @@ :::@::::: ::: @: :: @@:@:::@::::@::::@:@:::@@:@@#
633
+ | @ ::: :::@:::::::: @@ :::@::::: ::: @: :: @@:@:::@::::@::::@:@:::@@:@@#
634
+ | @ ::: :::@:::::::: @@ :::@::::: ::: @: :: @@:@:::@::::@::::@:@:::@@:@@#
635
+ 0 +----------------------------------------------------------------------->Mi
636
+ 0 7.101
637
+
638
+ = Summary
639
+ # script size mrbc picorbc
640
+ ====================================================
641
+ hello_world.rb 20 bytes 133.5 KB 16.98 KB
642
+ ----------------------------------------------------
643
+ keymap.rb(meishi2) 2388 bytes 206.1 KB 61.98 KB
644
+ ----------------------------------------------------
645
+
646
+ (('tag:center'))
647
+ (('tag:small'))
648
+ Note: Figures are measured in 64 bit Ubuntu
649
+
650
+ = Implementation
651
+ * Depending on only libc and less
652
+ * Considering paddings and Pooled allocation
653
+ * Freeing heap memory in a loop instead of recursion
654
+
655
+ = Depending on only libc and less
656
+ * glibc for desktop/server application
657
+ * newlib for embedded application
658
+ * Small code size
659
+ * Doesn't have regex.c
660
+
661
+ # image
662
+ # src = images/regex_light.png
663
+ # relative_width = 80
664
+
665
+ = Padding in a struct
666
+ struct LinkedList {
667
+ struct LinkedList *next; // 4 bytes (in 32-bit architecture)
668
+ uint8_t value; // 1 byte
669
+ }
670
+
671
+ sizeof(LinkedList);
672
+ => 5 ๐Ÿ™… No
673
+ => 8 ๐Ÿ™† Yes
674
+
675
+ (('tag:center'))
676
+ (('tag:small'))
677
+ โœ”Data structure alignment (at least in C99)\n
678
+ pointer[4] + uint8_t[1] + ((*padding[3]*)) = sum[8]\n
679
+ ๐Ÿ‘‰You need to pack them well
680
+
681
+ = Paddings waste memomy
682
+ # enscript c
683
+ LinkedList *top;
684
+ (...)
685
+ top->next->next->next->next; // 5 items in the list
686
+
687
+ * Consumes 40 bytes to store 5 values of uint8_t
688
+ * Total size of pointers will be 1 KB if there are 250 items in a list
689
+
690
+ (('tag:center'))
691
+ \nPooled allocation ๐Ÿ’ก
692
+
693
+ = Pooled allocation
694
+ # enscript bash
695
+ [n]: bytes
696
+
697
+ *next[4] -----------> *next[4] -----------> *next[4] ------------>
698
+ size[2] size[2] size[2]
699
+ index[2] index[2] index[2]
700
+ data[sizeof(Data)] data[sizeof(Data)] data[sizeof(Data)]
701
+ data[sizeof(Data)] data[sizeof(Data)] data[sizeof(Data)]
702
+ ... ... ...
703
+ data[sizeof(Data)] data[sizeof(Data)] data[sizeof(Data)]
704
+
705
+ * Reduces paddings of data structure alignment
706
+ * Reduces the number of pointers
707
+ * Reduces fragmentation
708
+
709
+ = Before improvement -> 53.20 KB
710
+ --------------------------------------------------------------------------------
711
+ Massif arguments: --stacks=yes
712
+ --------------------------------------------------------------------------------
713
+ KB
714
+ 53.20^ #
715
+ | #
716
+ | @# :::
717
+ | @# : :
718
+ | @# : :
719
+ | @@# : :
720
+ | @@# :: :
721
+ | @@#::: :
722
+ | @@#::: :
723
+ | @@::@@#::: :
724
+ | @@: @@#::: :
725
+ | @@:@:::@::::@@: @@#::: ::
726
+ | @::@::@ :@:: @:: :@@: @@#::: ::
727
+ | @:::@@@:@::@: @ :@:: @:: :@@: @@#::: ::
728
+ | @@:@::@:: @@ :@::@: @ :@:: @:: :@@: @@#::: ::
729
+ | ::@@@ :@: @:: @@ :@::@: @ :@:: @:: :@@: @@#::: ::
730
+ | :::::: :::::@ @ :@: @:: @@ :@::@: @ :@:: @:: :@@: @@#::: ::
731
+ | :::::@@:: :::::: ::@ @ :@: @:: @@ :@::@: @ :@:: @:: :@@: @@#::: ::
732
+ | : :: @ :: :::::: ::@ @ :@: @:: @@ :@::@: @ :@:: @:: :@@: @@#::: ::
733
+ | : :: @ :: :::::: ::@ @ :@: @:: @@ :@::@: @ :@:: @:: :@@: @@#::: ::
734
+ 0 +----------------------------------------------------------------------->Mi
735
+ 0 1.616
736
+
737
+ = After improvement -> 24.21 KB
738
+ --------------------------------------------------------------------------------
739
+ Massif arguments: --stacks=yes
740
+ --------------------------------------------------------------------------------
741
+ KB
742
+ 24.21^ #
743
+ | @ @:@:@:#
744
+ | @:@@@:@:@:@:#: @
745
+ | @@:::@:@@@:@:@:@:#::::::@
746
+ | @ :::@:@@@:@:@:@:#::::::@
747
+ | @ :::@:@@@:@:@:@:#::::::@
748
+ | @ :::@:@@@:@:@:@:#::::::@
749
+ | @ :::@:@@@:@:@:@:#::::::@
750
+ | @@:::::::::::::::@::::: ::::@::@::::::@ :::@:@@@:@:@:@:#::::::@
751
+ | @ ::::::: :::: : @:: ::@:: :@::@:: :: @ :::@:@@@:@:@:@:#::::::@
752
+ | @ ::::::: :::: : @:: ::@:: :@::@:: :: @ :::@:@@@:@:@:@:#::::::@
753
+ | @ ::::::: :::: : @:: ::@:: :@::@:: :: @ :::@:@@@:@:@:@:#::::::@
754
+ | @ ::::::: :::: : @:: ::@:: :@::@:: :: @ :::@:@@@:@:@:@:#::::::@
755
+ | @ ::::::: :::: : @:: ::@:: :@::@:: :: @ :::@:@@@:@:@:@:#::::::@
756
+ | @ ::::::: :::: : @:: ::@:: :@::@:: :: @ :::@:@@@:@:@:@:#::::::@
757
+ | @ ::::::: :::: : @:: ::@:: :@::@:: :: @ :::@:@@@:@:@:@:#::::::@
758
+ | @ ::::::: :::: : @:: ::@:: :@::@:: :: @ :::@:@@@:@:@:@:#::::::@
759
+ | @ ::::::: :::: : @:: ::@:: :@::@:: :: @ :::@:@@@:@:@:@:#::::::@
760
+ | @ ::::::: :::: : @:: ::@:: :@::@:: :: @ :::@:@@@:@:@:@:#::::::@
761
+ | ::::@ ::::::: :::: : @:: ::@:: :@::@:: :: @ :::@:@@@:@:@:@:#::::::@
762
+ 0 +----------------------------------------------------------------------->Mi
763
+ 0 1.082
764
+
765
+ = Freeing in a loop
766
+ * Freeing long linked list in recursion causes "stack spike"
767
+ * Because the call stack becomes deep until the recursive call reaches the bottom of the list
768
+ * Freeing in a loop instead of recursion
769
+ * The call stack doesn't stack up at the cost of a bit complicated code
770
+
771
+ = Summary
772
+ # script size mrbc picorbc
773
+ ====================================================
774
+ hello_world.rb 20 bytes 133.5 KB 16.98 KB
775
+ ----------------------------------------------------
776
+ keymap.rb(meishi2) 2388 bytes 206.1 KB 61.98 KB
777
+ ----------------------------------------------------
778
+
779
+ (('tag:center'))
780
+ (('tag:x-small:Note: Figures are measured in 64 bit Ubuntu'))
781
+ \n\n
782
+ (('tag:large:Finally, I could make'))\n(('tag:large:PicoRuby work on the Micon!'))
783
+
784
+ = VCENTER HCENTER XXLARGE
785
+ The (('del:Matrix')) Micon
786
+ \n
787
+ is Everywhere.
788
+
789
+ = HCENTER VCENTER XXLARGE TITLE
790
+ On a Keyboard
791
+ \n
792
+ Ruby on Board
793
+
794
+ = HCENTER VCENTER MONO
795
+ (('tag:x-small:written and presented by'))
796
+ \n
797
+ HASUMIKIN
798
+
799
+ = HCENTER VCENTER MONO
800
+ (('tag:x-small:supported by'))
801
+ \n
802
+ RUBY ASSOCIATION (('tag:x-small:and')) MONSTARLAB
803
+
804
+ = HCENTER VCENTER MONO
805
+ (('tag:x-small:mentor'))
806
+ \n
807
+ MATZ
808
+
809
+ = HCENTER VCENTER MONO
810
+ (('tag:x-small:follow the'))
811
+ # image
812
+ # src = images/picoruby.png
813
+ # relative_width = 20
814
+
815
+ = HCENTER VCENTER MONO
816
+ (('tag:x-small:an')) ESSENTIALLY RUBY (('tag:x-small:production'))