-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
1746 lines (1679 loc) · 513 KB
/
index.html
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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html><html lang=en><head><title>メモ帳 - 作業ログ</title><meta charset=utf-8><meta name=viewport content="width=device-width"><style>@font-face{src:url("https://cdn.jsdelivr.net/gh/Tyrrrz/DiscordFonts@master/ggsans-normal-400.woff2");font-family:gg sans;font-weight:400;font-style:normal}@font-face{src:url("https://cdn.jsdelivr.net/gh/Tyrrrz/DiscordFonts@master/ggsans-normal-500.woff2");font-family:gg sans;font-weight:500;font-style:normal}@font-face{src:url("https://cdn.jsdelivr.net/gh/Tyrrrz/DiscordFonts@master/ggsans-normal-600.woff2");font-family:gg sans;font-weight:600;font-style:normal}@font-face{src:url("https://cdn.jsdelivr.net/gh/Tyrrrz/DiscordFonts@master/ggsans-normal-700.woff2");font-family:gg sans;font-weight:700;font-style:normal}@font-face{src:url("https://cdn.jsdelivr.net/gh/Tyrrrz/DiscordFonts@master/ggsans-normal-800.woff2");font-family:gg sans;font-weight:800;font-style:normal}@font-face{src:url("https://cdn.jsdelivr.net/gh/Tyrrrz/DiscordFonts@master/ggsans-italic-400.woff2");font-family:gg sans;font-weight:400;font-style:italic}@font-face{src:url("https://cdn.jsdelivr.net/gh/Tyrrrz/DiscordFonts@master/ggsans-italic-500.woff2");font-family:gg sans;font-weight:500;font-style:italic}@font-face{src:url("https://cdn.jsdelivr.net/gh/Tyrrrz/DiscordFonts@master/ggsans-italic-600.woff2");font-family:gg sans;font-weight:600;font-style:italic}@font-face{src:url("https://cdn.jsdelivr.net/gh/Tyrrrz/DiscordFonts@master/ggsans-italic-700.woff2");font-family:gg sans;font-weight:700;font-style:italic}@font-face{src:url("https://cdn.jsdelivr.net/gh/Tyrrrz/DiscordFonts@master/ggsans-italic-800.woff2");font-family:gg sans;font-weight:800;font-style:italic}html,body{margin:0;padding:0;background-color:#36393e;color:#dcddde;font-family:"gg sans","Helvetica Neue",Helvetica,Arial,sans-serif;font-size:17px;font-weight:400;scroll-behavior:smooth}a{color:#00aff4;text-decoration:none}a:hover{text-decoration:underline}img{object-fit:contain;image-rendering:high-quality;image-rendering:-webkit-optimize-contrast}.preamble{display:grid;grid-template-columns:auto 1fr;max-width:100%;padding:1rem}.preamble__guild-icon-container{grid-column:1}.preamble__guild-icon{max-width:88px;max-height:88px}.preamble__entries-container{grid-column:2;margin-left:1rem}.preamble__entry{margin-bottom:0.15rem;color:#ffffff;font-size:1.4rem}.preamble__entry--small{font-size:1rem}.chatlog{padding:1rem 0;width:100%;border-top:1px solid rgba(255,255,255,0.1);border-bottom:1px solid rgba(255,255,255,0.1)}.chatlog__message-group{margin-bottom:1rem}.chatlog__message-container{background-color:transparent;transition:background-color 1s ease}.chatlog__message-container--highlighted{background-color:rgba(114,137,218,0.2)}.chatlog__message-container--pinned{background-color:rgba(249,168,37,0.05)}.chatlog__message{display:grid;grid-template-columns:auto 1fr;padding:0.15rem 0;direction:ltr;unicode-bidi:bidi-override}.chatlog__message:hover{background-color:#32353b}.chatlog__message:hover .chatlog__short-timestamp{display:block}.chatlog__message-aside{grid-column:1;width:72px;padding:0.15rem 0.15rem 0 0.15rem;text-align:center}.chatlog__reply-symbol{height:10px;margin:6px 4px 4px 36px;border-left:2px solid #4f545c;border-top:2px solid #4f545c;border-radius:8px 0 0 0}.chatlog__avatar{width:40px;height:40px;border-radius:50%}.chatlog__short-timestamp{display:none;color:#a3a6aa;font-size:0.75rem;font-weight:500;direction:ltr;unicode-bidi:bidi-override}.chatlog__message-primary{grid-column:2;min-width:0}.chatlog__reply{display:flex;margin-bottom:0.15rem;align-items:center;color:#b5b6b8;font-size:0.875rem;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.chatlog__reply-avatar{width:16px;height:16px;margin-right:0.25rem;border-radius:50%}.chatlog__reply-author{margin-right:0.3rem;font-weight:600}.chatlog__reply-content{overflow:hidden;text-overflow:ellipsis}.chatlog__reply-link{cursor:pointer}.chatlog__reply-link *{display:inline;pointer-events:none}.chatlog__reply-link .chatlog__markdown-quote{display:inline}.chatlog__reply-link .chatlog__markdown-pre{display:inline}.chatlog__reply-link:hover{color:#ffffff}.chatlog__reply-link:hover *:not(.chatlog__markdown-spoiler){color:inherit}.chatlog__reply-edited-timestamp{margin-left:0.25rem;color:#a3a6aa;font-size:0.75rem;font-weight:500;direction:ltr;unicode-bidi:bidi-override}.chatlog__system-notification-icon{width:18px;height:18px}.chatlog__system-notification-author{font-weight:500;color:#ffffff}.chatlog__system-notification-content{color:#96989d}.chatlog__system-notification-link{font-weight:500;color:#ffffff}.chatlog__system-notification-timestamp{margin-left:0.3rem;color:#a3a6aa;font-size:0.75rem;font-weight:500;direction:ltr;unicode-bidi:bidi-override}.chatlog__system-notification-timestamp a{color:inherit}.chatlog__header{margin-bottom:0.1rem}.chatlog__author{font-weight:500;color:#ffffff}.chatlog__author-tag{position:relative;top:-0.1rem;margin-left:0.3rem;padding:0.05rem 0.3rem;border-radius:3px;background-color:#5865F2;color:#ffffff;font-size:0.625rem;font-weight:500;line-height:1.3}.chatlog__timestamp{margin-left:0.3rem;color:#a3a6aa;font-size:0.75rem;font-weight:500;direction:ltr;unicode-bidi:bidi-override}.chatlog__timestamp a{color:inherit}.chatlog__content{padding-right:1rem;font-size:0.95rem;word-wrap:break-word}.chatlog__edited-timestamp{margin-left:0.15rem;color:#a3a6aa;font-size:0.75rem;font-weight:500}.chatlog__attachment{position:relative;width:fit-content;margin-top:0.3rem;border-radius:3px;overflow:hidden}.chatlog__attachment--hidden{cursor:pointer;box-shadow:0 0 1px 1px rgba(0,0,0,0.1)}.chatlog__attachment--hidden *{pointer-events:none}.chatlog__attachment-spoiler-caption{display:none;position:absolute;left:50%;top:50%;z-index:999;padding:0.4rem 0.8rem;border-radius:20px;transform:translate(-50%,-50%);background-color:rgba(0,0,0,0.9);color:#dcddde;font-size:0.9rem;font-weight:600;letter-spacing:0.05rem}.chatlog__attachment--hidden .chatlog__attachment-spoiler-caption{display:block}.chatlog__attachment--hidden:hover .chatlog__attachment-spoiler-caption{color:#fff}.chatlog__attachment-media{max-width:45vw;max-height:500px;vertical-align:top;border-radius:3px}.chatlog__attachment--hidden .chatlog__attachment-media{filter:blur(44px)}.chatlog__attachment-generic{max-width:520px;width:100%;height:40px;padding:10px;border:1px solid #292b2f;border-radius:3px;background-color:#2f3136;overflow:hidden}.chatlog__attachment--hidden .chatlog__attachment-generic{filter:blur(44px)}.chatlog__attachment-generic-icon{float:left;width:30px;height:100%;margin-right:10px}.chatlog__attachment-generic-size{color:#72767d;font-size:12px}.chatlog__attachment-generic-name{overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.chatlog__embed{display:flex;margin-top:0.3rem;max-width:520px}.chatlog__embed-color-pill{flex-shrink:0;width:0.25rem;border-top-left-radius:3px;border-bottom-left-radius:3px}.chatlog__embed-color-pill--default{background-color:#202225}.chatlog__embed-content-container{display:flex;flex-direction:column;padding:0.5rem 0.6rem;border:1px solid rgba(46,48,54,0.6);border-top-right-radius:3px;border-bottom-right-radius:3px;background-color:rgba(46,48,54,0.3)}.chatlog__embed-content{display:flex;width:100%}.chatlog__embed-text{flex:1}.chatlog__embed-author-container{display:flex;margin-bottom:0.5rem;align-items:center}.chatlog__embed-author-icon{width:20px;height:20px;margin-right:0.5rem;border-radius:50%}.chatlog__embed-author{color:#ffffff;font-size:0.875rem;font-weight:600;direction:ltr;unicode-bidi:bidi-override}.chatlog__embed-author-link{color:#ffffff}.chatlog__embed-title{margin-bottom:0.5rem;color:#ffffff;font-size:0.875rem;font-weight:600}.chatlog__embed-description{color:#dcddde;font-weight:500;font-size:0.85rem}.chatlog__embed-fields{display:flex;flex-wrap:wrap;gap:0 0.5rem}.chatlog__embed-field{flex:0;min-width:100%;max-width:506px;padding-top:0.6rem;font-size:0.875rem}.chatlog__embed-field--inline{flex:1;flex-basis:auto;min-width:50px}.chatlog__embed-field-name{margin-bottom:0.2rem;color:#ffffff;font-weight:600}.chatlog__embed-field-value{color:#dcddde;font-weight:500}.chatlog__embed-thumbnail{flex:0;max-width:80px;max-height:80px;margin-left:1.2rem;border-radius:3px}.chatlog__embed-images{display:grid;margin-top:0.6rem;grid-template-columns:repeat(2,1fr);gap:0.25rem}.chatlog__embed-images--single{display:block}.chatlog__embed-image{object-fit:cover;object-position:center;max-width:500px;max-height:400px;width:100%;height:100%;border-radius:3px}.chatlog__embed-footer{margin-top:0.6rem;color:#dcddde}.chatlog__embed-footer-icon{width:20px;height:20px;margin-right:0.2rem;border-radius:50%;vertical-align:middle}.chatlog__embed-footer-text{vertical-align:middle;font-size:0.75rem;font-weight:500}.chatlog__embed-invite-container{min-width:320px;padding:0.6rem 0.7rem;border:1px solid rgba(46,48,54,0.6);border-radius:3px;background-color:rgba(46,48,54,0.3)}.chatlog__embed-invite-title{margin:0 0 0.8rem 0;color:#b9bbbe;font-size:0.75rem;font-weight:700;text-transform:uppercase}.chatlog__embed-invite{display:flex}.chatlog__embed-invite-guild-icon{width:50px;height:50px;border-radius:0.85rem}.chatlog__embed-invite-info{margin-left:1rem}.chatlog__embed-invite-guild-name{color:#ffffff;font-weight:600}.chatlog__embed-invite-guild-name a{color:inherit}.chatlog__embed-invite-channel-icon{width:18px;height:18px;vertical-align:bottom}.chatlog__embed-invite-channel-name{font-size:0.9rem;font-weight:600}.chatlog__embed-generic-image{object-fit:contain;object-position:left;max-width:45vw;max-height:500px;vertical-align:top;border-radius:3px}.chatlog__embed-generic-video{object-fit:contain;object-position:left;max-width:45vw;max-height:500px;vertical-align:top;border-radius:3px}.chatlog__embed-generic-gifv{object-fit:contain;object-position:left;max-width:45vw;max-height:500px;vertical-align:top;border-radius:3px}.chatlog__embed-spotify{border:0}.chatlog__embed-youtube-container{margin-top:0.6rem}.chatlog__embed-youtube{border:0;border-radius:3px}.chatlog__sticker{width:180px;height:180px}.chatlog__sticker--media{max-width:100%;max-height:100%}.chatlog__reactions{display:flex}.chatlog__reaction{display:flex;margin:0.35rem 0.1rem 0.1rem 0;padding:0.125rem 0.375rem;border:1px solid transparent;border-radius:8px;background-color:#2f3136;align-items:center}.chatlog__reaction:hover{border:1px solid hsla(0,0%,100%,.2);background-color:transparent}.chatlog__reaction-count{min-width:9px;margin-left:0.35rem;color:#b9bbbe;font-size:0.875rem}.chatlog__reaction:hover .chatlog__reaction-count{color:#dcddde}.chatlog__markdown{max-width:100%;line-height:1.3;overflow-wrap:break-word}.chatlog__markdown h1{margin:1rem 0 0.5rem;color:#f2f3f5;font-size:1.5rem;line-height:1}.chatlog__markdown h2{margin:1rem 0 0.5rem;color:#f2f3f5;font-size:1.25rem;line-height:1}.chatlog__markdown h3{margin:1rem 0 0.5rem;color:#f2f3f5;font-size:1rem;line-height:1}.chatlog__markdown h1:first-child,h2:first-child,h3:first-child{margin-top:0.5rem}.chatlog__markdown ul,ol{margin:0 0 0 1rem;padding:0}.chatlog__markdown-preserve{white-space:pre-wrap}.chatlog__markdown-spoiler{background-color:rgba(255,255,255,0.1);padding:0 2px;border-radius:3px}.chatlog__markdown-spoiler--hidden{cursor:pointer;background-color:#202225;color:rgba(0,0,0,0)}.chatlog__markdown-spoiler--hidden:hover{background-color:rgba(32,34,37,0.8)}.chatlog__markdown-spoiler--hidden::selection{color:rgba(0,0,0,0)}.chatlog__markdown-quote{display:flex;margin:0.05rem 0}.chatlog__markdown-quote-border{margin-right:0.5rem;border:2px solid #4f545c;border-radius:3px}.chatlog__markdown-pre{background-color:#2f3136;font-family:"Consolas","Courier New",Courier,monospace;font-size:0.85rem;text-decoration:inherit}.chatlog__markdown-pre--multiline{display:block;margin-top:0.25rem;padding:0.5rem;border:2px solid #282b30;border-radius:5px;color:#b9bbbe}.chatlog__markdown-pre--multiline.hljs{background-color:#2f3136;color:#b9bbbe}.chatlog__markdown-pre--inline{display:inline-block;padding:2px;border-radius:3px}.chatlog__markdown-mention{border-radius:3px;padding:0 2px;background-color:rgba(88,101,242,.3);color:#dee0fc;font-weight:500}.chatlog__markdown-mention:hover{background-color:#5865f2;color:#ffffff}.chatlog__markdown-timestamp{background-color:rgba(255,255,255,0.1);padding:0 2px;border-radius:3px}.chatlog__emoji{width:1.325rem;height:1.325rem;margin:0 0.06rem;vertical-align:-0.4rem}.chatlog__emoji--small{width:1rem;height:1rem}.chatlog__emoji--large{width:2.8rem;height:2.8rem}.postamble{padding:1.25rem}.postamble__entry{color:#ffffff}</style><link rel=stylesheet href=https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/styles/solarized-dark.min.css><script src=https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/highlight.min.js></script><script>document.addEventListener('DOMContentLoaded',()=>{document.querySelectorAll('.chatlog__markdown-pre--multiline').forEach(e=>hljs.highlightBlock(e));});</script><script src=https://cdnjs.cloudflare.com/ajax/libs/lottie-web/5.8.1/lottie.min.js></script><script>document.addEventListener('DOMContentLoaded',()=>{document.querySelectorAll('.chatlog__sticker--media[data-source]').forEach(e=>{const anim=lottie.loadAnimation({container:e,renderer:'svg',loop:true,autoplay:true,path:e.getAttribute('data-source')});anim.addEventListener('data_failed',()=>e.innerHTML='<strong>[Sticker cannot be rendered]</strong>');});});</script><script>function scrollToMessage(event,id){const element=document.getElementById('chatlog__message-container-'+id);if(!element)
return;event.preventDefault();element.classList.add('chatlog__message-container--highlighted');window.scrollTo({top:element.getBoundingClientRect().top-document.body.getBoundingClientRect().top-(window.innerHeight/2),behavior:'smooth'});window.setTimeout(()=>element.classList.remove('chatlog__message-container--highlighted'),2000);}
function showSpoiler(event,element){if(!element)
return;if(element.classList.contains('chatlog__attachment--hidden')){event.preventDefault();element.classList.remove('chatlog__attachment--hidden');}
if(element.classList.contains('chatlog__markdown-spoiler--hidden')){event.preventDefault();element.classList.remove('chatlog__markdown-spoiler--hidden');}}</script><svg style=display:none xmlns=http://www.w3.org/2000/svg><defs><symbol id=attachment-icon viewBox="0 0 720 960"><path fill=#f4f5fb d=M50,935a25,25,0,0,1-25-25V50A25,25,0,0,1,50,25H519.6L695,201.32V910a25,25,0,0,1-25,25Z /><path fill=#7789c4 d=M509.21,50,670,211.63V910H50V50H509.21M530,0H50A50,50,0,0,0,0,50V910a50,50,0,0,0,50,50H670a50,50,0,0,0,50-50h0V191Z /><path fill=#f4f5fb d=M530,215a25,25,0,0,1-25-25V50a25,25,0,0,1,16.23-23.41L693.41,198.77A25,25,0,0,1,670,215Z /><path fill=#7789c4 d=M530,70.71,649.29,190H530V70.71M530,0a50,50,0,0,0-50,50V190a50,50,0,0,0,50,50H670a50,50,0,0,0,50-50Z /></symbol><symbol id=join-icon viewBox="0 0 18 18"><path fill=#3ba55c d="m0 8h14.2l-3.6-3.6 1.4-1.4 6 6-6 6-1.4-1.4 3.6-3.6h-14.2" /></symbol><symbol id=leave-icon viewBox="0 0 18 18"><path fill=#ed4245 d="m3.8 8 3.6-3.6-1.4-1.4-6 6 6 6 1.4-1.4-3.6-3.6h14.2v-2" /></symbol><symbol id=call-icon viewBox="0 0 18 18"><path fill=#3ba55c fill-rule=evenodd d="M17.7163041 15.36645368c-.0190957.02699568-1.9039523 2.6680735-2.9957762 2.63320406-3.0676659-.09785935-6.6733809-3.07188394-9.15694343-5.548738C3.08002193 9.9740657.09772497 6.3791404 0 3.3061316v-.024746C0 2.2060575 2.61386252.3152347 2.64082114.2972376c.7110335-.4971705 1.4917101-.3149497 1.80959713.1372281.19320342.2744561 2.19712724 3.2811005 2.42290565 3.6489167.09884826.1608492.14714912.3554431.14714912.5702838 0 .2744561-.07975258.5770327-.23701117.8751101-.1527655.2902036-.65262318 1.1664385-.89862055 1.594995.2673396.3768148.94804468 1.26429792 2.351016 2.66357424 1.39173858 1.39027775 2.28923588 2.07641807 2.67002628 2.34187563.4302146-.2452108 1.3086162-.74238132 1.5972981-.89423205.5447887-.28682915 1.0907006-.31944893 1.4568885-.08661115.3459689.2182151 3.3383754 2.21027167 3.6225641 2.41611376.2695862.19234426.4144887.5399137.4144887.91672846 0 .2969525-.089862.61190215-.2808189.88523346" /></symbol><symbol id=pencil-icon viewBox="0 0 18 18"><path fill=#99aab5 d="m0 14.25v3.75h3.75l11.06-11.06-3.75-3.75zm17.71-10.21c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.39-.39-1.02-.39-1.41 0l-1.83 1.83 3.75 3.75z" /></symbol><symbol id=pin-icon viewBox="0 0 18 18"><path fill=#b9bbbe d="m16.908 8.39684-8.29587-8.295827-1.18584 1.184157 1.18584 1.18584-4.14834 4.1475v.00167l-1.18583-1.18583-1.185 1.18583 3.55583 3.55502-4.740831 4.74 1.185001 1.185 4.74083-4.74 3.55581 3.555 1.185-1.185-1.185-1.185 4.1475-4.14836h.0009l1.185 1.185z" /></symbol><symbol id=channel-icon viewBox="0 0 24 24"><path fill=#b9bbbe d="M5.88657 21C5.57547 21 5.3399 20.7189 5.39427 20.4126L6.00001 17H2.59511C2.28449 17 2.04905 16.7198 2.10259 16.4138L2.27759 15.4138C2.31946 15.1746 2.52722 15 2.77011 15H6.35001L7.41001 9H4.00511C3.69449 9 3.45905 8.71977 3.51259 8.41381L3.68759 7.41381C3.72946 7.17456 3.93722 7 4.18011 7H7.76001L8.39677 3.41262C8.43914 3.17391 8.64664 3 8.88907 3H9.87344C10.1845 3 10.4201 3.28107 10.3657 3.58738L9.76001 7H15.76L16.3968 3.41262C16.4391 3.17391 16.6466 3 16.8891 3H17.8734C18.1845 3 18.4201 3.28107 18.3657 3.58738L17.76 7H21.1649C21.4755 7 21.711 7.28023 21.6574 7.58619L21.4824 8.58619C21.4406 8.82544 21.2328 9 20.9899 9H17.41L16.35 15H19.7549C20.0655 15 20.301 15.2802 20.2474 15.5862L20.0724 16.5862C20.0306 16.8254 19.8228 17 19.5799 17H16L15.3632 20.5874C15.3209 20.8261 15.1134 21 14.8709 21H13.8866C13.5755 21 13.3399 20.7189 13.3943 20.4126L14 17H8.00001L7.36325 20.5874C7.32088 20.8261 7.11337 21 6.87094 21H5.88657ZM9.41045 9L8.35045 15H14.3504L15.4104 9H9.41045Z" /></symbol><symbol id=thread-icon viewBox="0 0 24 24"><path fill=#b9bbbe d="M5.43309 21C5.35842 21 5.30189 20.9325 5.31494 20.859L5.99991 17H2.14274C2.06819 17 2.01168 16.9327 2.02453 16.8593L2.33253 15.0993C2.34258 15.0419 2.39244 15 2.45074 15H6.34991L7.40991 9H3.55274C3.47819 9 3.42168 8.93274 3.43453 8.85931L3.74253 7.09931C3.75258 7.04189 3.80244 7 3.86074 7H7.75991L8.45234 3.09903C8.46251 3.04174 8.51231 3 8.57049 3H10.3267C10.4014 3 10.4579 3.06746 10.4449 3.14097L9.75991 7H15.7599L16.4523 3.09903C16.4625 3.04174 16.5123 3 16.5705 3H18.3267C18.4014 3 18.4579 3.06746 18.4449 3.14097L17.7599 7H21.6171C21.6916 7 21.7481 7.06725 21.7353 7.14069L21.4273 8.90069C21.4172 8.95811 21.3674 9 21.3091 9H17.4099L17.0495 11.04H15.05L15.4104 9H9.41035L8.35035 15H10.5599V17H7.99991L7.30749 20.901C7.29732 20.9583 7.24752 21 7.18934 21H5.43309Z" /><path fill=#b9bbbe d="M13.4399 12.96C12.9097 12.96 12.4799 13.3898 12.4799 13.92V20.2213C12.4799 20.7515 12.9097 21.1813 13.4399 21.1813H14.3999C14.5325 21.1813 14.6399 21.2887 14.6399 21.4213V23.4597C14.6399 23.6677 14.8865 23.7773 15.0408 23.6378L17.4858 21.4289C17.6622 21.2695 17.8916 21.1813 18.1294 21.1813H22.5599C23.0901 21.1813 23.5199 20.7515 23.5199 20.2213V13.92C23.5199 13.3898 23.0901 12.96 22.5599 12.96H13.4399Z" /></symbol></defs></svg><body><div class=preamble><div class=preamble__guild-icon-container><img class=preamble__guild-icon src="https://cdn.discordapp.com/icons/1002995356033896448/46f0e7db9a1ddbb40036af3643ca9881.png?size=512" alt="Guild icon" loading=lazy></div><div class=preamble__entries-container><div class=preamble__entry>メモ帳</div><div class=preamble__entry>seccamp2022 / 作業ログ</div></div></div>
<div class="chatlog">
<div class=chatlog__message-group><div id=chatlog__message-container-1003859485078597664 class=chatlog__message-container data-message-id=1003859485078597664><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1003859485078597664>08/02/2022 11:59 AM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><strong>関数定義</strong></span> <span class=chatlog__edited-timestamp title="08/02/2022 11:59 AM">(edited)</span></div></div></div></div><div id=chatlog__message-container-1003859970841907201 class=chatlog__message-container data-message-id=1003859970841907201><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="08/02/2022 12:01 PM">12:01</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C">typedef struct Function Function;
struct Function {
Function *next;
Type *type; // 型
char *name; // 関数名
Lvar params_head; // 引数リストの先頭
Node *body; // statement
Lvar *locals; // ローカル変数のリスト
};</code></span> <span class=chatlog__edited-timestamp title="08/23/2022 12:48 PM">(edited)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1003903120457334805 class=chatlog__message-container data-message-id=1003903120457334805><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1003903120457334805>08/02/2022 2:52 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>1.整数を返すだけの関数が定義できるように</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1005153716363608106 class=chatlog__message-container data-message-id=1005153716363608106><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1005153716363608106>08/06/2022 1:42 AM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>offset計算するところでセグフォしてる</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1006719065391386644 class=chatlog__message-container data-message-id=1006719065391386644><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1006719065391386644>08/10/2022 9:22 AM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C">struct Expr typecheck_expression(struct AnalyzerState *ptr_ps,
const struct UntypedExpr *ref_uexpr)</code></span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1006728691843346582 class=chatlog__message-container data-message-id=1006728691843346582><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1006728691843346582>08/10/2022 10:00 AM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>hsjoihs「なので、それに一つずつ型情報を付与していく必要があります」
hsjoihs「やり方は二通りあって、一つは、いまある Node を書き換えて、型情報を書き込んでいく方法」
hsjoihs「もう一つは、今ある AST を見て、再帰的に『その AST の、型がついたバージョン』を作っていく方法」</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1006739418809389146 class=chatlog__message-container data-message-id=1006739418809389146><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1006739418809389146>08/10/2022 10:43 AM</a></span></div><div class=chatlog__attachment><a href="https://cdn.discordapp.com/attachments/1003859454191751178/1006739418532544643/unknown.png?ex=65542225&is=6541ad25&hm=d0ef41e44544ada6283cfdb302edf95ac1c29bf429246113362b2b4ea7aa4de7&"> <img class=chatlog__attachment-media src="https://cdn.discordapp.com/attachments/1003859454191751178/1006739418532544643/unknown.png?ex=65542225&is=6541ad25&hm=d0ef41e44544ada6283cfdb302edf95ac1c29bf429246113362b2b4ea7aa4de7&" alt="Image attachment" title="Image: unknown.png (2.22 MB)" loading=lazy> </a></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1006886070601912361 class=chatlog__message-container data-message-id=1006886070601912361><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1006886070601912361>08/10/2022 8:25 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>問題点
そもそも関数名とか型の情報とか渡ってなくね?
引数としてlistを受け取ってるけど結局使ってなくね?</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1007295518432575618 class=chatlog__message-container data-message-id=1007295518432575618><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1007295518432575618>08/11/2022 11:32 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><strong><s>TODO</s>(対応済み)</strong>
変数のサイズによってレジスタの名前が変わるので、それに対応できるように<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">codegen.c</code> を書き換える</span> <span class=chatlog__edited-timestamp title="10/21/2022 7:15 PM">(edited)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1007308547618517083 class=chatlog__message-container data-message-id=1007308547618517083><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1007308547618517083>08/12/2022 12:24 AM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><a href="http://yuma.ohgami.jp/Introduction-to-x86_64-Machine-Language/02_basic_operations.html">http://yuma.ohgami.jp/Introduction-to-x86_64-Machine-Language/02_basic_operations.html</a></span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1011275293190795284 class=chatlog__message-container data-message-id=1011275293190795284><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1011275293190795284>08/22/2022 11:06 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><strong>Step 21-2 配列からポインタへの暗黙の型変換を実装する</strong>
・右辺に配列型変数が現れた場合 <code class="chatlog__markdown-pre chatlog__markdown-pre--inline">a</code> → <code class="chatlog__markdown-pre chatlog__markdown-pre--inline">&a</code> のようにキャストする
・明示的に<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">&a</code> と書いたときは、上記のキャストを行わないようにする
・<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">*a = 1;</code> みたいな式が書けるように(次のステップで<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">a[i]</code> を<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">*(a+i)</code> に読み替えるための準備)
・<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">sizeof(a)</code> は<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">(1つ分のサイズ) * (要素数)</code> を返す</span> <span class=chatlog__edited-timestamp title="08/23/2022 1:15 AM">(edited)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1011309127210897538 class=chatlog__message-container data-message-id=1011309127210897538><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1011309127210897538>08/23/2022 1:21 AM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>新たに処理を書き足す必要がある(と思われる)演算子
・<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">+</code> <code class="chatlog__markdown-pre chatlog__markdown-pre--inline">-</code> (済)
・<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">==</code> <code class="chatlog__markdown-pre chatlog__markdown-pre--inline">!=</code> <code class="chatlog__markdown-pre chatlog__markdown-pre--inline"><</code> <code class="chatlog__markdown-pre chatlog__markdown-pre--inline"><=</code> <code class="chatlog__markdown-pre chatlog__markdown-pre--inline">></code> <code class="chatlog__markdown-pre chatlog__markdown-pre--inline">>=</code> → そもそもポインタに対しても対応していないので後回し
・<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">=</code> (済)
・<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">*</code> (dereference) オペランドとして直接配列が来た場合に対応する必要あり (済)
・<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">sizeof</code> (済)
※<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">&</code> について 明示的に<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">&</code> を書いているからキャストする必要ないはず)</span> <span class=chatlog__edited-timestamp title="08/23/2022 7:08 PM">(edited)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1011316338045763698 class=chatlog__message-container data-message-id=1011316338045763698><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1011316338045763698>08/23/2022 1:50 AM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>ポインタの加算・減算のうち
・<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">lhs</code> が数字/<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">rhs</code> がポインタのものは実装していないはず</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1011573441972932690 class=chatlog__message-container data-message-id=1011573441972932690><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1011573441972932690>08/23/2022 6:51 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>代入式の左辺(<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">lhs</code> )に直接配列が来ることはありえない</span></div></div></div></div><div id=chatlog__message-container-1011573563670671390 class=chatlog__message-container data-message-id=1011573563670671390><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="08/23/2022 6:52 PM">18:52</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C">#include <stdio.h>
int main(char *argv[], int argc) {
int a[2];
a = 80;
printf("%d", a[0]);
return 0;
}</code>
<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline nohighlight">./Main.c: In function ‘main’:
./Main.c:4:5: error: assignment to expression with array type
4 | a = 80;
| ^</code></span> <span class=chatlog__edited-timestamp title="08/23/2022 6:52 PM">(edited)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1014428976653021257 class=chatlog__message-container data-message-id=1014428976653021257><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1014428976653021257>08/31/2022 3:58 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><strong>TODO</strong>
・<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">int</code> を4byteに
・<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">(任意の型)*</code> を8byteに
・関数呼び出しの際、rspを16byte境界にalignする</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1014452314653855795 class=chatlog__message-container data-message-id=1014452314653855795><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1014452314653855795>08/31/2022 5:31 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C">void alloc4(int **p, int a, int b, int c, int d) {
*p = malloc(sizeof(int) * 5);
(*p)[0] = a;
(*p)[1] = b;
(*p)[2] = c;
(*p)[3] = d;
(*p)[4] = 100;
}</code>
<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline nohighlight">int alloc4(); int main(){int *p; alloc4(&p, 1, 2, 4, 8); return *(p+2);} => 100</code>
これはgccが<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">int</code> を4byteとして扱っている一方、9ccでは8byteとして扱っているため</span> <span class=chatlog__edited-timestamp title="08/31/2022 5:39 PM">(edited)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1014454543901261834 class=chatlog__message-container data-message-id=1014454543901261834><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1014454543901261834>08/31/2022 5:40 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--multiline nohighlight">int main() {int a; a = 4; int b[2]; int *p; p = b; *p = 1; *(p+1) = 2; return a + *p + *(p+1);} => 7 expected, but got 5</code>
となるが、
<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline nohighlight">int main() {int a; a = 4; int b[2]; int *p; p = b; *p = 1; *(p-1) = 2; return a + *p + *(p-1);} => 7</code>
とすると上手くいく</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1017940918155882537 class=chatlog__message-container data-message-id=1017940918155882537><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1017940918155882537>09/10/2022 8:33 AM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><div class="chatlog__markdown-quote"><div class="chatlog__markdown-quote-border"></div><div class="chatlog__markdown-quote-content">PUSH copies the specified register, memory location, or immediate value to the top of stack. This instruction decrements the stack pointer by 2, 4, or 8, depending on the operand size, and then copies the operand into the memory location pointed to by SS:rSP.</div></div></span> <span class=chatlog__edited-timestamp title="09/10/2022 8:34 AM">(edited)</span></div></div></div></div><div id=chatlog__message-container-1017941107734220840 class=chatlog__message-container data-message-id=1017941107734220840><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="09/10/2022 8:34 AM">08:34</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><div class="chatlog__markdown-quote"><div class="chatlog__markdown-quote-border"></div><div class="chatlog__markdown-quote-content">POP copies a word, doubleword, or quadword from the memory location pointed to by the SS:rSP registers (the top of stack) to a specified register or memory location. Then, the rSP register is incremented by 2, 4, or 8. After the POP operation, rSP points to the new top of stack.</div></div></span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1023567449330819163 class=chatlog__message-container data-message-id=1023567449330819163><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1023567449330819163>09/25/2022 9:11 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><div class="chatlog__markdown-quote"><div class="chatlog__markdown-quote-border"></div><div class="chatlog__markdown-quote-content">For addition, either both operands shall have arithmetic type, or one operand shall be a pointer to a complete object type and the other shall have integer type. (Incrementing is equivalent to adding 1.)</div></div></span></div></div></div></div><div id=chatlog__message-container-1023567616729677824 class=chatlog__message-container data-message-id=1023567616729677824><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="09/25/2022 9:12 PM">21:12</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><div class="chatlog__markdown-quote"><div class="chatlog__markdown-quote-border"></div><div class="chatlog__markdown-quote-content">For subtraction, one of the following shall hold:
・both operands have arithmetic type;
・both operands are pointers to qualified or unqualified versions of compatible complete object types; or
・the left operand is a pointer to a complete object type and the right operand has integer type.
(Decrementing is equivalent to subtracting 1.)
</div></div>ってなってるけど、スタック操作(<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">pop</code>とか<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">push</code>)を行うときは8byteレジスタしか引数に取れない?(あまりよく分かってない)</span> <span class=chatlog__edited-timestamp title="10/21/2022 7:17 PM">(edited)</span></div></div></div></div><div id=chatlog__message-container-1023567671561814016 class=chatlog__message-container data-message-id=1023567671561814016><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="09/25/2022 9:12 PM">21:12</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><a href="http://port70.net/~nsz/c/c11/n1570.html#6.5.6">http://port70.net/~nsz/c/c11/n1570.html#6.5.6</a></span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1024591355642662913 class=chatlog__message-container data-message-id=1024591355642662913><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1024591355642662913>09/28/2022 5:00 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>もしかしたらローカル変数のメモリ上での配置の仕方がgccとかと違うかも(おそらく逆順)</span> <span class=chatlog__edited-timestamp title="09/28/2022 5:19 PM">(edited)</span></div></div></div></div><div id=chatlog__message-container-1024591523922317313 class=chatlog__message-container data-message-id=1024591523922317313><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="09/28/2022 5:00 PM">17:00</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>そもそもこういうテストケース
<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C">int main() {int a; int b; a = 2; b = 8; int *p; int *q; p = &a; q = &b; return q - p;}</code>
に対して1が帰ってくる保証はないのでは?
(<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">int a</code> と <code class="chatlog__markdown-pre chatlog__markdown-pre--inline">int b</code> が連続して確保される保証はないため)</span> <span class=chatlog__edited-timestamp title="09/28/2022 5:02 PM">(edited)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1024595580221145088 class=chatlog__message-container data-message-id=1024595580221145088><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1024595580221145088>09/28/2022 5:17 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><div class="chatlog__markdown-quote"><div class="chatlog__markdown-quote-border"></div><div class="chatlog__markdown-quote-content">2つのポインタを減算する場合において、その両方のポインタが同じ配列オブジェクトの要素か、その配列オブジェクトの最後の要素を一つ越えたところを指していない場合。(6.5.6)</div></div></span></div></div></div></div><div id=chatlog__message-container-1024595592611115100 class=chatlog__message-container data-message-id=1024595592611115100><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="09/28/2022 5:17 PM">17:17</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><a href="http://www.c-lang.org/detail/undefined_behavior.html">http://www.c-lang.org/detail/undefined_behavior.html</a></span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1027862636542578709 class=chatlog__message-container data-message-id=1027862636542578709><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1027862636542578709>10/07/2022 5:39 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><strong>Step 25 文字列リテラルを実装する</strong></span></div></div></div></div><div id=chatlog__message-container-1027862986473345066 class=chatlog__message-container data-message-id=1027862986473345066><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="10/07/2022 5:40 PM">17:40</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>tokenizerはこういうコードを追加すればいいはず</span></div></div></div></div><div id=chatlog__message-container-1027863142962835487 class=chatlog__message-container data-message-id=1027863142962835487><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="10/07/2022 5:41 PM">17:41</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C">    // 文字列リテラルの場合
    if (startswith(p, "\"")) {
      char *start = ++p; // ダブルクオートを読み飛ばす
      while (*p != '\"')
        p++;
      cur = new_token(TK_STR, cur, start, p - 1);
      p++; // ダブルクオートを読み飛ばす
      continue;
    }</code></span></div></div></div></div><div id=chatlog__message-container-1027863913301291059 class=chatlog__message-container data-message-id=1027863913301291059><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="10/07/2022 5:44 PM">17:44</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--inline">launch.json</code>の<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">args</code>にテストケースを渡すとき、ダブルクオーテーションを<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">\\\"</code>とエスケープしないといけない</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1028670098250141767 class=chatlog__message-container data-message-id=1028670098250141767><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1028670098250141767>10/09/2022 11:07 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>文字列リテラルを変更しようとするとセグフォするのを実験
<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C">#include <stdio.h>
char *str = "Hello, implementation-defined behavior!";
int main(int argc, int **argv) {
printf("%s\n", str);
str[5] = '!'; // ここでセグフォする(けどコンパイル時にwarningさえ出ない)
printf("%s\n", str);
return 0;
}</code></span></div></div></div></div><div id=chatlog__message-container-1028670494356025435 class=chatlog__message-container data-message-id=1028670494356025435><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="10/09/2022 11:09 PM">23:09</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>文字列リテラルが<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">char</code>の配列として扱われるのは、例外的な場合のみ
<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C">char str[] = "Good bye"; // 初期化式だからcharの配列として書ける
str[5] = 'B';</code></span></div></div></div></div><div id=chatlog__message-container-1028670737910874143 class=chatlog__message-container data-message-id=1028670737910874143><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="10/09/2022 11:10 PM">23:10</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>なのでこの段階では気にする必要はなく、文字列リテラルはすべてグローバルに確保して、その領域へのアドレスを返すようにすればOKなはず</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1028719848391462912 class=chatlog__message-container data-message-id=1028719848391462912><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1028719848391462912>10/10/2022 2:25 AM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>既存のコンパイラの出力を観察してみる
<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C">int main() { char *str = "abc"; return str[0]; }</code>
に対する出力</span></div></div></div></div><div id=chatlog__message-container-1028720030839492638 class=chatlog__message-container data-message-id=1028720030839492638><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="10/10/2022 2:26 AM">02:26</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>x86-64 clang 15.0.0
<a href="https://godbolt.org/z/dYWx1zchq">https://godbolt.org/z/dYWx1zchq</a></span></div><div class=chatlog__embed><div class=chatlog__embed-color-pill style=background-color:rgba(242,242,242,255)></div><div class=chatlog__embed-content-container><div class=chatlog__embed-content><div class=chatlog__embed-text><div class=chatlog__embed-title><a class=chatlog__embed-title-link href=https://godbolt.org/z/dYWx1zchq><div class="chatlog__markdown chatlog__markdown-preserve">Compiler Explorer - C (x86-64 clang 15.0.0)</div></a></div><div class=chatlog__embed-description><div class="chatlog__markdown chatlog__markdown-preserve">int main() { char *str = "abc"; return str[0]; }</div></div></div><div class=chatlog__embed-thumbnail-container><a class=chatlog__embed-thumbnail-link href=https://images-ext-2.discordapp.net/external/jGTpmeGUxpLs6alHNMw1q89lgpPm0EpuohWGxIobk-o/%3Fraw%3Dtrue/https/github.com/compiler-explorer/infra/blob/main/logo/favicon.png> <img class=chatlog__embed-thumbnail src=https://images-ext-2.discordapp.net/external/jGTpmeGUxpLs6alHNMw1q89lgpPm0EpuohWGxIobk-o/%3Fraw%3Dtrue/https/github.com/compiler-explorer/infra/blob/main/logo/favicon.png alt=Thumbnail loading=lazy> </a></div></div></div></div></div></div></div><div id=chatlog__message-container-1028720133482496103 class=chatlog__message-container data-message-id=1028720133482496103><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="10/10/2022 2:26 AM">02:26</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>x86-64 gcc 12.2
<a href="https://godbolt.org/z/Y4c8r1Exr">https://godbolt.org/z/Y4c8r1Exr</a></span></div><div class=chatlog__embed><div class=chatlog__embed-color-pill style=background-color:rgba(242,242,242,255)></div><div class=chatlog__embed-content-container><div class=chatlog__embed-content><div class=chatlog__embed-text><div class=chatlog__embed-title><a class=chatlog__embed-title-link href=https://godbolt.org/z/Y4c8r1Exr><div class="chatlog__markdown chatlog__markdown-preserve">Compiler Explorer - C (x86-64 gcc 12.2)</div></a></div><div class=chatlog__embed-description><div class="chatlog__markdown chatlog__markdown-preserve">int main() { char *str = "abc"; return str[0]; }</div></div></div><div class=chatlog__embed-thumbnail-container><a class=chatlog__embed-thumbnail-link href=https://images-ext-2.discordapp.net/external/jGTpmeGUxpLs6alHNMw1q89lgpPm0EpuohWGxIobk-o/%3Fraw%3Dtrue/https/github.com/compiler-explorer/infra/blob/main/logo/favicon.png> <img class=chatlog__embed-thumbnail src=https://images-ext-2.discordapp.net/external/jGTpmeGUxpLs6alHNMw1q89lgpPm0EpuohWGxIobk-o/%3Fraw%3Dtrue/https/github.com/compiler-explorer/infra/blob/main/logo/favicon.png alt=Thumbnail loading=lazy> </a></div></div></div></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1029150919117516920 class=chatlog__message-container data-message-id=1029150919117516920><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1029150919117516920>10/11/2022 6:58 AM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><strong>エスケープシーケンスを実装する</strong>
<div class="chatlog__markdown-quote"><div class="chatlog__markdown-quote-border"></div><div class="chatlog__markdown-quote-content">Escape sequences are defined using themselves here. E.g. '\n' is implemented using '\n'. This tautological definition works because the compiler that compiles our compiler knows what '\n' actually is. In other words, we "inherit" the ASCII code of '\n' from the compiler that compiles our compiler, so we don't have to teach the actual code here. This fact has huge implications not only for the correctness of the compiler but also for the security of the generated code. For more info, read "Reflections on Trusting Trust" by Ken Thompson.
<a href="https://github.com/rui314/chibicc/wiki/thompson1984.pdf">https://github.com/rui314/chibicc/wiki/thompson1984.pdf</a></div></div></span> <span class=chatlog__edited-timestamp title="10/11/2022 6:58 AM">(edited)</span></div></div></div></div><div id=chatlog__message-container-1029151142422257724 class=chatlog__message-container data-message-id=1029151142422257724><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="10/11/2022 6:59 AM">06:59</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><a href="https://github.com/rui314/chibicc/blob/ad7749f2fad87a4b1df644d4e1c345b3f87d386d/tokenize.c">https://github.com/rui314/chibicc/blob/ad7749f2fad87a4b1df644d4e1c345b3f87d386d/tokenize.c</a></span></div><div class=chatlog__embed><div class=chatlog__embed-color-pill style=background-color:rgba(30,35,39,255)></div><div class=chatlog__embed-content-container><div class=chatlog__embed-content><div class=chatlog__embed-text><div class=chatlog__embed-title><a class=chatlog__embed-title-link href=https://github.com/rui314/chibicc/blob/ad7749f2fad87a4b1df644d4e1c345b3f87d386d/tokenize.c><div class="chatlog__markdown chatlog__markdown-preserve">chibicc/tokenize.c at ad7749f2fad87a4b1df644d4e1c345b3f87d386d · ru...</div></a></div><div class=chatlog__embed-description><div class="chatlog__markdown chatlog__markdown-preserve">A small C compiler. Contribute to rui314/chibicc development by creating an account on GitHub.</div></div></div><div class=chatlog__embed-thumbnail-container><a class=chatlog__embed-thumbnail-link href=https://images-ext-1.discordapp.net/external/BZz5v82krgIoVW42SJfqqS9WahmlHR6NL9PR674rjWg/https/opengraph.githubassets.com/9aae4711251a70fc3107b9452c18ff129ca07fd4cef63635c316cf9bf2363339/rui314/chibicc> <img class=chatlog__embed-thumbnail src=https://images-ext-1.discordapp.net/external/BZz5v82krgIoVW42SJfqqS9WahmlHR6NL9PR674rjWg/https/opengraph.githubassets.com/9aae4711251a70fc3107b9452c18ff129ca07fd4cef63635c316cf9bf2363339/rui314/chibicc alt=Thumbnail loading=lazy> </a></div></div></div></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1029745548217040936 class=chatlog__message-container data-message-id=1029745548217040936><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1029745548217040936>10/12/2022 10:21 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>・最後の"を認識して、文字列リテラルの文字数分のcharの配列を確保する
・一文字ずつ読んでいって、エスケープシーケンスじゃなかったらそのまま配列のi文字目に書き込む
・エスケープシーケンスの場合はうまく扱えるように文字を置き換えて配列のi文字目に格納する</span> <span class=chatlog__edited-timestamp title="10/12/2022 10:21 PM">(edited)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1031493155838771241 class=chatlog__message-container data-message-id=1031493155838771241><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1031493155838771241>10/17/2022 6:05 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><strong>Step27 行コメントとブロックコメントを実装する</strong>
たぶん<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">tokenize.c</code>に少し処理足せば一瞬でできるので、とりあえず後回しにして、Step28に進む(今のままだとテストが書きにくいので)</span> <span class=chatlog__edited-timestamp title="10/17/2022 6:07 PM">(edited)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1031497653185429534 class=chatlog__message-container data-message-id=1031497653185429534><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1031497653185429534>10/17/2022 6:23 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><strong>Step28 テストをCで書き直す</strong></span> <span class=chatlog__edited-timestamp title="10/17/2022 6:23 PM">(edited)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1031574915297587250 class=chatlog__message-container data-message-id=1031574915297587250><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1031574915297587250>10/17/2022 11:30 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><strong><code class="chatlog__markdown-pre chatlog__markdown-pre--inline">printf</code>を使うにあたって</strong>
・フォーマット指定子(<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">%d</code>など)については、とりあえず引数さえちゃんと渡せば大丈夫なはず
・可変長引数を取る関数を呼ぶので、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">call</code>命令の前で浮動小数点数引数の個数を<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">al</code>に入れておく必要あり</span> <span class=chatlog__edited-timestamp title="10/17/2022 11:33 PM">(edited)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1031803928846815272 class=chatlog__message-container data-message-id=1031803928846815272><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1031803928846815272>10/18/2022 2:40 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>デバッグ用
<a href="https://godbolt.org/z/6fb9K6c1a">https://godbolt.org/z/6fb9K6c1a</a></span></div><div class=chatlog__embed><div class=chatlog__embed-color-pill style=background-color:rgba(242,242,242,255)></div><div class=chatlog__embed-content-container><div class=chatlog__embed-content><div class=chatlog__embed-text><div class=chatlog__embed-title><a class=chatlog__embed-title-link href=https://godbolt.org/z/6fb9K6c1a><div class="chatlog__markdown chatlog__markdown-preserve">Compiler Explorer - C (x86-64 gcc 12.1)</div></a></div><div class=chatlog__embed-description><div class="chatlog__markdown chatlog__markdown-preserve">int printf();
int exit();
int assert(int expected, int actual, char *code) {
if (expected == actual) {
printf("%s => %d\n", code, actual);
}
else {
printf("%s => %d expected, but got %d\n", code, expected, actual);
exit(1);
}
return 0;
}
int main() {
return 0;
}</div></div></div><div class=chatlog__embed-thumbnail-container><a class=chatlog__embed-thumbnail-link href=https://images-ext-2.discordapp.net/external/jGTpmeGUxpLs6alHNMw1q89lgpPm0EpuohWGxIobk-o/%3Fraw%3Dtrue/https/github.com/compiler-explorer/infra/blob/main/logo/favicon.png> <img class=chatlog__embed-thumbnail src=https://images-ext-2.discordapp.net/external/jGTpmeGUxpLs6alHNMw1q89lgpPm0EpuohWGxIobk-o/%3Fraw%3Dtrue/https/github.com/compiler-explorer/infra/blob/main/logo/favicon.png alt=Thumbnail loading=lazy> </a></div></div></div></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1032959510630895617 class=chatlog__message-container data-message-id=1032959510630895617><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1032959510630895617>10/21/2022 7:12 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><strong>実装するときに考えてたことのメモ</strong>
何したらいいか分かりづらいので、とりあえず、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">test.c</code>1ファイルに全ての処理をベタ書きしてみる</span> <span class=chatlog__edited-timestamp title="10/21/2022 7:15 PM">(edited)</span></div></div></div></div><div id=chatlog__message-container-1032959584614232104 class=chatlog__message-container data-message-id=1032959584614232104><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="10/21/2022 7:12 PM">19:12</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>まずは整数1つを返すテストケースを通せるようにする</span></div></div></div></div><div id=chatlog__message-container-1032959631938564117 class=chatlog__message-container data-message-id=1032959631938564117><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="10/21/2022 7:12 PM">19:12</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>これが通ったので、あとはいい感じに拡張すればいけそう</span></div></div></div></div><div id=chatlog__message-container-1032959897370886224 class=chatlog__message-container data-message-id=1032959897370886224><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="10/21/2022 7:13 PM">19:13</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>関数の引数に渡せるのはexpressionであってstatementは渡せないので、statementを渡したいときは、別途関数を作って、引数としてその関数(の返り値)を渡せば良さそう</span></div></div></div></div><div id=chatlog__message-container-1032960114228989953 class=chatlog__message-container data-message-id=1032960114228989953><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="10/21/2022 7:14 PM">19:14</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>全てのテストケースを<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">test.c</code>に移すと800行とかになったので、いくつかのファイルに分割した方が良さそう</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1033071565492977715 class=chatlog__message-container data-message-id=1033071565492977715><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1033071565492977715>10/22/2022 2:37 AM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>適当に7ファイルくらいに分割した</span></div></div></div></div><div id=chatlog__message-container-1033071773001990216 class=chatlog__message-container data-message-id=1033071773001990216><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="10/22/2022 2:38 AM">02:38</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--inline">make clean</code>が、サブディレクトリに対してもいい感じに作用してほしい</span></div></div></div></div><div id=chatlog__message-container-1033071846440058960 class=chatlog__message-container data-message-id=1033071846440058960><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="10/22/2022 2:38 AM">02:38</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-makefile"># ccに渡すコンパイラオプションを指定
CFLAGS=-std=c11 -g -static
# src/*.cをソースとして指定
SRCS=$(wildcard src/*.c)
# SRCSの末尾を.oに置換した名前のファイルをオブジェクトファイルとして指定
OBJS=$(SRCS:.c=.o)
# テストのソースを指定
TEST_SRCS=$(wildcard test/test_src/*.c)
# 9ccの依存関係を指定し、それに対するルールを設定
9cc: $(OBJS)
$(CC) -o 9cc $(OBJS) $(LDFLAGS)
# OBJSの依存関係を指定
$(OBJS): src/9cc.h
# testの依存関係を指定し、それに対するルールを設定
test: 9cc
./test/test_driver.sh
# cleanに対するルールを設定
clean:
rm -f 9cc src/*.o test/*.s tmp* .gdb_history peda-session-*.txt src/peda-session-*.txt .vscode/peda-session-*.txt
# testとcleanをダミーターゲット(実際に存在しないファイル)に指定
.PHONY: test clean</code></span></div></div></div></div><div id=chatlog__message-container-1033072055853260881 class=chatlog__message-container data-message-id=1033072055853260881><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="10/22/2022 2:39 AM">02:39</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--inline">SUBDIR</code>的な変数を用意して、ゴニャゴニャしたらうまくいきそう(?)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1034028435594563665 class=chatlog__message-container data-message-id=1034028435594563665><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1034028435594563665>10/24/2022 5:59 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><strong>%演算子を実装する</strong></span></div></div></div></div><div id=chatlog__message-container-1034028464837242922 class=chatlog__message-container data-message-id=1034028464837242922><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="10/24/2022 5:59 PM">17:59</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><a href="http://port70.net/~nsz/c/c11/n1570.html#6.5.5">http://port70.net/~nsz/c/c11/n1570.html#6.5.5</a></span></div></div></div></div><div id=chatlog__message-container-1034028581141098507 class=chatlog__message-container data-message-id=1034028581141098507><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="10/24/2022 6:00 PM">18:00</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><div class="chatlog__markdown-quote"><div class="chatlog__markdown-quote-border"></div><div class="chatlog__markdown-quote-content">Each of the operands shall have arithmetic type. The operands of the % operator shall have integer type.</div></div></span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1034113984321835008 class=chatlog__message-container data-message-id=1034113984321835008><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1034113984321835008>10/24/2022 11:39 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>例のドーナツのテストケース
<a href="https://github.com/hsjoihs/c-compiler/blob/master/misc/donut_donut.c">https://github.com/hsjoihs/c-compiler/blob/master/misc/donut_donut.c</a></span></div><div class=chatlog__embed><div class=chatlog__embed-color-pill style=background-color:rgba(30,35,39,255)></div><div class=chatlog__embed-content-container><div class=chatlog__embed-content><div class=chatlog__embed-text><div class=chatlog__embed-title><a class=chatlog__embed-title-link href=https://github.com/hsjoihs/c-compiler/blob/master/misc/donut_donut.c><div class="chatlog__markdown chatlog__markdown-preserve">c-compiler/donut_donut.c at master · hsjoihs/c-compiler</div></a></div><div class=chatlog__embed-description><div class="chatlog__markdown chatlog__markdown-preserve">seccamp2018 c compiler. Contribute to hsjoihs/c-compiler development by creating an account on GitHub.</div></div></div><div class=chatlog__embed-thumbnail-container><a class=chatlog__embed-thumbnail-link href=https://images-ext-1.discordapp.net/external/vLLxuiw2QPIVJJL3UOAtcL5b-2yN48BTZnHG5BhWzYM/https/opengraph.githubassets.com/bb4c508b95c6221a9f1d8542652c6e03ea8ffa887d98ad3c322ba72dbe3d95aa/hsjoihs/c-compiler> <img class=chatlog__embed-thumbnail src=https://images-ext-1.discordapp.net/external/vLLxuiw2QPIVJJL3UOAtcL5b-2yN48BTZnHG5BhWzYM/https/opengraph.githubassets.com/bb4c508b95c6221a9f1d8542652c6e03ea8ffa887d98ad3c322ba72dbe3d95aa/hsjoihs/c-compiler alt=Thumbnail loading=lazy> </a></div></div></div></div></div></div></div><div id=chatlog__message-container-1034114492306554962 class=chatlog__message-container data-message-id=1034114492306554962><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="10/24/2022 11:41 PM">23:41</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>フォーマットしたやつ
<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C">int putchar();
void *memset();
int m(int a, int b) {
return (a * b + 5000) / 10000;
}
void a(int *c, int *s, int d, int t) {
int k = m(*c, d) - m(*s, t);
int l = m(*s, d) + m(*c, t);
*c = k;
*s = l;
}
int usleep();
int printf();
int main() {
int z[1760];
char b[1760];
printf("\e[2J");
int s = 10000;
int q = s;
int r = 0;
int u = s;
int v = 0;
for (;; a(&q, &r, s - 8, 400), a(&u, &v, s - 2, 200)) {
memset(b, 32, 1760);
memset(z, 0, 7040);
int l = 0;
int p = s;
for (int i = 0; i < 88; i++, a(&p, &l, 9974 + i % 2, 714)) {
int w = 0;
int e = s;
for (int j = 0; j < 314; j++, a(&e, &w, s - 2, 200)) {
int f = p + 2 * s;
int g = s * s / (m(m(w, f), r) + m(l, q) + 5 * s);
int t = m(m(w, q), f) - m(l, r);
int x = 40 + 30 * m(g, m(m(e, u), f) - m(t, v)) / s;
int y = 12 + 15 * m(g, m(m(e, v), f) + m(t, u)) / s;
int o = x + 80 * y;
int N = 8 * (m(m(l, r) - m(m(w, q), p), u) - m(m(w, r), p) - m(l, q) - m(m(e, v), p)) / s;
if (y > 0 && g > z[o] && y < 22 && x > 0 && 80 > x) {
z[o] = g;
b[o] = ".,-~:;=!*#$@"[N >= 1 ? N : 0] + 0;
}
}
}
printf("\e[H");
for (int k = 0; k < 1761; k++)
putchar(k % 80 ? b[k] : 10);
printf("Author: @a1k0n. Rewritten by @hsjoihs so that it works without floating types.\nNote that rounding errors gradually reduce the donut's size.\n");
usleep(50000);
}
return 0;
}</code></span></div></div></div></div><div id=chatlog__message-container-1034114582270189569 class=chatlog__message-container data-message-id=1034114582270189569><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="10/24/2022 11:42 PM">23:42</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>これ見ると、
・初期化式全般
・<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">void</code>型
<s>・<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">&&</code>演算子(というか論理演算子全般)</s>
<s>・インクリメント<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">++</code>とデクリメント<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">--</code>演算子</s>
あたりが足りなさそう</span> <span class=chatlog__edited-timestamp title="11/08/2022 7:38 PM">(edited)</span></div></div></div></div><div id=chatlog__message-container-1034115272107380766 class=chatlog__message-container data-message-id=1034115272107380766><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="10/24/2022 11:44 PM">23:44</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>ということで今週はこの辺を追加していきたい</span></div></div></div></div><div id=chatlog__message-container-1034115402973859950 class=chatlog__message-container data-message-id=1034115402973859950><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="10/24/2022 11:45 PM">23:45</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>あとポインタを返り値とするようなテストケースが全然ない気がするので、それも追加したい</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1034317782302589050 class=chatlog__message-container data-message-id=1034317782302589050><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1034317782302589050>10/25/2022 1:09 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>あと<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">sizeof(int)</code>みたいな記法が未実装</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1034327137114669136 class=chatlog__message-container data-message-id=1034327137114669136><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1034327137114669136>10/25/2022 1:46 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><a href="https://zenn.dev/kaityo256/articles/increment_operators">https://zenn.dev/kaityo256/articles/increment_operators</a></span></div><div class=chatlog__embed><div class="chatlog__embed-color-pill chatlog__embed-color-pill--default"></div><div class=chatlog__embed-content-container><div class=chatlog__embed-content><div class=chatlog__embed-text><div class=chatlog__embed-title><a class=chatlog__embed-title-link href=https://zenn.dev/kaityo256/articles/increment_operators><div class="chatlog__markdown chatlog__markdown-preserve">インクリメント演算子とコンパイラの気持ち</div></a></div></div><div class=chatlog__embed-thumbnail-container><a class=chatlog__embed-thumbnail-link href=https://images-ext-1.discordapp.net/external/2hQcq75oaK53d8oF9NABWkucZBvABQ6kQISpdUd_BH8/https/res.cloudinary.com/zenn/image/upload/s--j0O_bGLi--/co_rgb%3A222%252Cg_south_west%252Cl_text%3Anotosansjp-medium.otf_37_bold%3A%2525E3%252583%2525AD%2525E3%252583%25259C%2525E5%2525A4%2525AA%252Cx_203%252Cy_98/c_fit%252Cco_rgb%3A222%252Cg_north_west%252Cl_text%3Anotosansjp-medium.otf_70_bold%3A%2525E3%252582%2525A4%2525E3%252583%2525B3%2525E3%252582%2525AF%2525E3%252583%2525AA%2525E3%252583%2525A1%2525E3%252583%2525B3%2525E3%252583%252588%2525E6%2525BC%252594%2525E7%2525AE%252597%2525E5%2525AD%252590%2525E3%252581%2525A8%2525E3%252582%2525B3%2525E3%252583%2525B3%2525E3%252583%252591%2525E3%252582%2525A4%2525E3%252583%2525A9%2525E3%252581%2525AE%2525E6%2525B0%252597%2525E6%25258C%252581%2525E3%252581%2525A1%252Cw_1010%252Cx_90%252Cy_100/g_south_west%252Ch_90%252Cl_fetch%3AaHR0cHM6Ly9yZXMuY2xvdWRpbmFyeS5jb20vemVubi9pbWFnZS9mZXRjaC9zLS1semRkTWZ2Ry0tL2NfbGltaXQlMkNmX2F1dG8lMkNmbF9wcm9ncmVzc2l2ZSUyQ3FfYXV0byUyQ3dfNzAvaHR0cHM6Ly9zdG9yYWdlLmdvb2dsZWFwaXMuY29tL3plbm4tdXNlci11cGxvYWQvYXZhdGFyLzgzOGNiYTA0OWMuanBlZw%3D%3D%252Cr_max%252Cw_90%252Cx_87%252Cy_72/v1627274783/default/og-base_z4sxah.png> <img class=chatlog__embed-thumbnail src=https://images-ext-1.discordapp.net/external/2hQcq75oaK53d8oF9NABWkucZBvABQ6kQISpdUd_BH8/https/res.cloudinary.com/zenn/image/upload/s--j0O_bGLi--/co_rgb%3A222%252Cg_south_west%252Cl_text%3Anotosansjp-medium.otf_37_bold%3A%2525E3%252583%2525AD%2525E3%252583%25259C%2525E5%2525A4%2525AA%252Cx_203%252Cy_98/c_fit%252Cco_rgb%3A222%252Cg_north_west%252Cl_text%3Anotosansjp-medium.otf_70_bold%3A%2525E3%252582%2525A4%2525E3%252583%2525B3%2525E3%252582%2525AF%2525E3%252583%2525AA%2525E3%252583%2525A1%2525E3%252583%2525B3%2525E3%252583%252588%2525E6%2525BC%252594%2525E7%2525AE%252597%2525E5%2525AD%252590%2525E3%252581%2525A8%2525E3%252582%2525B3%2525E3%252583%2525B3%2525E3%252583%252591%2525E3%252582%2525A4%2525E3%252583%2525A9%2525E3%252581%2525AE%2525E6%2525B0%252597%2525E6%25258C%252581%2525E3%252581%2525A1%252Cw_1010%252Cx_90%252Cy_100/g_south_west%252Ch_90%252Cl_fetch%3AaHR0cHM6Ly9yZXMuY2xvdWRpbmFyeS5jb20vemVubi9pbWFnZS9mZXRjaC9zLS1semRkTWZ2Ry0tL2NfbGltaXQlMkNmX2F1dG8lMkNmbF9wcm9ncmVzc2l2ZSUyQ3FfYXV0byUyQ3dfNzAvaHR0cHM6Ly9zdG9yYWdlLmdvb2dsZWFwaXMuY29tL3plbm4tdXNlci11cGxvYWQvYXZhdGFyLzgzOGNiYTA0OWMuanBlZw%3D%3D%252Cr_max%252Cw_90%252Cx_87%252Cy_72/v1627274783/default/og-base_z4sxah.png alt=Thumbnail loading=lazy> </a></div></div></div></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1039489355485560873 class=chatlog__message-container data-message-id=1039489355485560873><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1039489355485560873>11/08/2022 7:39 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>未初期化のポインタを参照するのは未定義動作だが、その場合も考慮した実装
<a href="https://github.com/karintou8710/kcc/commit/8d56aea5861c72eae36a723aa662123268d67c2c">https://github.com/karintou8710/kcc/commit/8d56aea5861c72eae36a723aa662123268d67c2c</a></span> <span class=chatlog__edited-timestamp title="11/08/2022 7:39 PM">(edited)</span></div><div class=chatlog__embed><div class=chatlog__embed-color-pill style=background-color:rgba(30,35,39,255)></div><div class=chatlog__embed-content-container><div class=chatlog__embed-content><div class=chatlog__embed-text><div class=chatlog__embed-title><a class=chatlog__embed-title-link href=https://github.com/karintou8710/kcc/commit/8d56aea5861c72eae36a723aa662123268d67c2c><div class="chatlog__markdown chatlog__markdown-preserve">Fix 'logical and' and 'logical or' bug · karintou8710/kcc@8d56aea</div></a></div></div><div class=chatlog__embed-thumbnail-container><a class=chatlog__embed-thumbnail-link href=https://images-ext-1.discordapp.net/external/DLNgU5QQMbzkJYWVD-cL7jZx7m8PSjomCahIyOpp8dU/https/opengraph.githubassets.com/f9334fb266b23efb68634e93238acf1fb8791560b14205ea3815bfbf0afb4b76/karintou8710/kcc/commit/8d56aea5861c72eae36a723aa662123268d67c2c> <img class=chatlog__embed-thumbnail src=https://images-ext-1.discordapp.net/external/DLNgU5QQMbzkJYWVD-cL7jZx7m8PSjomCahIyOpp8dU/https/opengraph.githubassets.com/f9334fb266b23efb68634e93238acf1fb8791560b14205ea3815bfbf0afb4b76/karintou8710/kcc/commit/8d56aea5861c72eae36a723aa662123268d67c2c alt=Thumbnail loading=lazy> </a></div></div></div></div></div></div></div><div id=chatlog__message-container-1039489676781830196 class=chatlog__message-container data-message-id=1039489676781830196><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="11/08/2022 7:40 PM">19:40</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><a href="https://github.com/rui314/chibicc/commit/f30f78175c1fd50c8cdd132ca804573ae0d18453">https://github.com/rui314/chibicc/commit/f30f78175c1fd50c8cdd132ca804573ae0d18453</a></span></div><div class=chatlog__embed><div class=chatlog__embed-color-pill style=background-color:rgba(30,35,39,255)></div><div class=chatlog__embed-content-container><div class=chatlog__embed-content><div class=chatlog__embed-text><div class=chatlog__embed-title><a class=chatlog__embed-title-link href=https://github.com/rui314/chibicc/commit/f30f78175c1fd50c8cdd132ca804573ae0d18453><div class="chatlog__markdown chatlog__markdown-preserve">Add && and || · rui314/chibicc@f30f781</div></a></div></div><div class=chatlog__embed-thumbnail-container><a class=chatlog__embed-thumbnail-link href=https://images-ext-2.discordapp.net/external/x9XnbVPGp1aoYDvflByrrdm1L8eY4k3R5lF815QNumo/https/opengraph.githubassets.com/8b181f61450adf248433b456607e346386d195ac1adc1be153a25d072486ca0e/rui314/chibicc/commit/f30f78175c1fd50c8cdd132ca804573ae0d18453> <img class=chatlog__embed-thumbnail src=https://images-ext-2.discordapp.net/external/x9XnbVPGp1aoYDvflByrrdm1L8eY4k3R5lF815QNumo/https/opengraph.githubassets.com/8b181f61450adf248433b456607e346386d195ac1adc1be153a25d072486ca0e/rui314/chibicc/commit/f30f78175c1fd50c8cdd132ca804573ae0d18453 alt=Thumbnail loading=lazy> </a></div></div></div></div></div></div></div><div id=chatlog__message-container-1039489807715409960 class=chatlog__message-container data-message-id=1039489807715409960><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="11/08/2022 7:41 PM">19:41</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>(左辺で未定義動作踏んだらセグフォするとは思うけど)</span></div></div></div></div><div id=chatlog__message-container-1039490093762748506 class=chatlog__message-container data-message-id=1039490093762748506><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="11/08/2022 7:42 PM">19:42</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>とりあえず未定義動作踏まなければ大丈夫なはずなので、一旦これでいく</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1041355933797863525 class=chatlog__message-container data-message-id=1041355933797863525><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1041355933797863525>11/13/2022 11:16 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><strong>BNFの修正点</strong>
・関数宣言を追加
・<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">Func_name(void)</code> みたいな記法に対応
・関数のパラメータあたりのBNFがいろいろアレ</span> <span class=chatlog__edited-timestamp title="11/13/2022 11:24 PM">(edited)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1041945365349421077 class=chatlog__message-container data-message-id=1041945365349421077><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1041945365349421077>11/15/2022 2:18 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><s>関数宣言に今のところパラメータが書けない</s> (対応済)</span> <span class=chatlog__edited-timestamp title="11/28/2022 5:30 PM">(edited)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1041957099955044443 class=chatlog__message-container data-message-id=1041957099955044443><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1041957099955044443>11/15/2022 3:05 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><strong>Step ?? カンマ演算子を追加する</strong></span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1041960149100789781 class=chatlog__message-container data-message-id=1041960149100789781><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1041960149100789781>11/15/2022 3:17 PM</a></span></div><div class=chatlog__attachment><a href="https://cdn.discordapp.com/attachments/1003859454191751178/1041960148983357470/image.png?ex=65531102&is=65409c02&hm=26d82b78929ce84e67fc753ce68e9a5ab434a93c8ef6c565448d5b9dce895df6&"> <img class=chatlog__attachment-media src="https://cdn.discordapp.com/attachments/1003859454191751178/1041960148983357470/image.png?ex=65531102&is=65409c02&hm=26d82b78929ce84e67fc753ce68e9a5ab434a93c8ef6c565448d5b9dce895df6&" alt="Image attachment" title="Image: image.png (127.46 KB)" loading=lazy> </a></div></div></div></div><div id=chatlog__message-container-1041960311818829904 class=chatlog__message-container data-message-id=1041960311818829904><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="11/15/2022 3:18 PM">15:18</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>こんな感じの構文木にパースしないといけないはず</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1047774707174346822 class=chatlog__message-container data-message-id=1047774707174346822><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1047774707174346822>12/01/2022 4:22 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><strong>例のドーナツを動かす</strong></span></div></div></div></div><div id=chatlog__message-container-1047774726770135080 class=chatlog__message-container data-message-id=1047774726770135080><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="12/01/2022 4:22 PM">16:22</div></div><div class=chatlog__message-primary><div class=chatlog__attachment><a href="https://cdn.discordapp.com/attachments/1003859454191751178/1047774726442991616/image.png?ex=6555c341&is=65434e41&hm=d3a53c2352d9d30913666f9550e2d002e217c44cca63bf9f00a9e064016a7443&"> <img class=chatlog__attachment-media src="https://cdn.discordapp.com/attachments/1003859454191751178/1047774726442991616/image.png?ex=6555c341&is=65434e41&hm=d3a53c2352d9d30913666f9550e2d002e217c44cca63bf9f00a9e064016a7443&" alt="Image attachment" title="Image: image.png (36.76 KB)" loading=lazy> </a></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1047778351722541137 class=chatlog__message-container data-message-id=1047778351722541137><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1047778351722541137>12/01/2022 4:37 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><strong>破滅の刃() ~無限デバッグ編~</strong></span> <span class=chatlog__edited-timestamp title="12/01/2022 4:40 PM">(edited)</span></div></div></div></div><div id=chatlog__message-container-1047778383708291122 class=chatlog__message-container data-message-id=1047778383708291122><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="12/01/2022 4:37 PM">16:37</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>原因調査</span></div></div></div></div><div id=chatlog__message-container-1047778484438700043 class=chatlog__message-container data-message-id=1047778484438700043><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="12/01/2022 4:37 PM">16:37</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>まず、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">z[o]</code>のところで落ちてそう</span></div></div></div></div><div id=chatlog__message-container-1047778735677526046 class=chatlog__message-container data-message-id=1047778735677526046><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="12/01/2022 4:38 PM">16:38</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--inline">o</code>の値を調べてみると、定義した配列の要素数を大幅に上回っているので、これのせいで変なメモリアクセスが発生し、セグフォしてるっぽい</span></div></div></div></div><div id=chatlog__message-container-1047778947171111003 class=chatlog__message-container data-message-id=1047778947171111003><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="12/01/2022 4:39 PM">16:39</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>ということで各種変数の値について、ccの出力と9ccの出力を比較してみると、2ステップ目で既に<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">N</code>の値が異なっていることが分かる(上記画像参照)</span> <span class=chatlog__edited-timestamp title="12/01/2022 4:43 PM">(edited)</span></div></div></div></div><div id=chatlog__message-container-1047779081489481791 class=chatlog__message-container data-message-id=1047779081489481791><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="12/01/2022 4:39 PM">16:39</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>(恐らく)<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">N</code>の値がバグってることで、後々<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">o</code>も変な値になってる</span></div></div></div></div><div id=chatlog__message-container-1047779325644132373 class=chatlog__message-container data-message-id=1047779325644132373><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="12/01/2022 4:40 PM">16:40</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>ということで
<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C">N = 8 * (m(m(l, r) - m(m(w, q), p), u) - m(m(w, r), p) - m(l, q) - m(m(e, v), p)) / s;</code>
の各オペランドごとに値を出力してみた</span></div></div></div></div><div id=chatlog__message-container-1047779557152923728 class=chatlog__message-container data-message-id=1047779557152923728><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="12/01/2022 4:41 PM">16:41</div></div><div class=chatlog__message-primary><div class=chatlog__attachment><div class=chatlog__attachment-generic><svg class=chatlog__attachment-generic-icon><use href=#attachment-icon /></svg><div class=chatlog__attachment-generic-name><a href="https://cdn.discordapp.com/attachments/1003859454191751178/1047779556779634718/message.txt?ex=6555c7c1&is=654352c1&hm=19874493ad6d7f8f1791856b7ec656024549296d4065dc0d5f1c52d853c1b204&"> message.txt </a></div><div class=chatlog__attachment-generic-size>14.84 KB</div></div></div></div></div></div><div id=chatlog__message-container-1047779705656459294 class=chatlog__message-container data-message-id=1047779705656459294><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="12/01/2022 4:42 PM">16:42</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--inline">op1</code>の値がバグってる</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1047782998487081030 class=chatlog__message-container data-message-id=1047782998487081030><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1047782998487081030>12/01/2022 4:55 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>さらに<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">op1</code>を分解</span></div></div></div></div><div id=chatlog__message-container-1047783018846240809 class=chatlog__message-container data-message-id=1047783018846240809><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="12/01/2022 4:55 PM">16:55</div></div><div class=chatlog__message-primary><div class=chatlog__attachment><div class=chatlog__attachment-generic><svg class=chatlog__attachment-generic-icon><use href=#attachment-icon /></svg><div class=chatlog__attachment-generic-name><a href="https://cdn.discordapp.com/attachments/1003859454191751178/1047783018573602816/message.txt?ex=6555cafa&is=654355fa&hm=291bf4291dc7124f6190b0ea829212b5916fe63f1656332566343cab93afadab&"> message.txt </a></div><div class=chatlog__attachment-generic-size>16.53 KB</div></div></div></div></div></div><div id=chatlog__message-container-1047783267333582879 class=chatlog__message-container data-message-id=1047783267333582879><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="12/01/2022 4:56 PM">16:56</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>ちなみにここまで、こんな感じで展開している
<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C"> printf("<< %d >>\n", ++count);
if (count >= 90)
return 0;
// N = 8 * (m(m(l, r) - m(m(w, q), p), u) - m(m(w, r), p) - m(l, q) - m(m(e, v), p)) / s;
int opp1;
int opp2;
int diff;
int op1;
int op2;
int op3;
int op4;
opp1 = m(l, r);
opp2 = m(m(w, q), p);
diff = opp1 - opp2;
//op1 = m(m(l, r) - m(m(w, q), p), u);
op1 = m(diff, u);
op2 = m(m(w, r), p);
op3 = m(l, q);
op4 = m(m(e, v), p);
N = 8 * (op1 - op2 - op3 - op4) / s;
printf("opp1 = %d\n", opp1);
printf("opp2 = %d\n", opp2);
printf("diff = %d\n", diff);
printf("u = %d\n", u);
printf("op1 = %d\n\n", op1);
/*
printf("op1 = %d\n", op1);
printf("op2 = %d\n", op2);
printf("op3 = %d\n", op3);
printf("op4 = %d\n", op4);
printf("N = %d\n\n", N);
*/
/*
printf("f = %d\n", f);
printf("g = %d\n", g);
printf("t = %d\n", t);
printf("x = %d\n", x);
printf("y = %d\n", y);
printf("o = %d\n", o);
printf("N = %d\n\n", N);
*/</code></span></div></div></div></div><div id=chatlog__message-container-1047783900065304606 class=chatlog__message-container data-message-id=1047783900065304606><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="12/01/2022 4:59 PM">16:59</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>関数<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">int m(int a, int b);</code>が返している値がおかしいと考えられる</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1047790321762836590 class=chatlog__message-container data-message-id=1047790321762836590><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1047790321762836590>12/01/2022 5:24 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>テストコード<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C">int m(int a, int b) {
return (a * b + 5000) / 10000;
}
int printf();
int main() {
printf("m( 0, 10000) = %d\n", m(0, 10000));
printf("m(-200, 10000) = %d\n", m(-200, 10000));
printf("m(-400, 10000) = %d\n", m(-400, 10000));
printf("m(-600, 10000) = %d\n", m(-600, 10000));
printf("m(-800, 10000) = %d\n", m(-800, 10000));
printf("m(-999, 10000) = %d\n", m(-999, 10000));
printf("m(-1198, 10000) = %d\n", m(-1198, 10000));
printf("m(-1397, 10000) = %d\n", m(-1397, 10000));
printf("m(-1595, 10000) = %d\n", m(-1595, 10000));
printf("m(-1792, 10000) = %d\n", m(-1792, 10000));
printf("m(-1989, 10000) = %d\n", m(-1989, 10000));
return 0;
}</code></span> <span class=chatlog__edited-timestamp title="12/01/2022 5:25 PM">(edited)</span></div></div></div></div><div id=chatlog__message-container-1047790437961838644 class=chatlog__message-container data-message-id=1047790437961838644><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="12/01/2022 5:25 PM">17:25</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>出力結果
<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline nohighlight">m( 0, 10000) = 0 m( 0, 10000) = 0
m(-200, 10000) = 429297 | m(-200, 10000) = -199
m(-400, 10000) = 429097 | m(-400, 10000) = -399
m(-600, 10000) = 428897 | m(-600, 10000) = -599
m(-800, 10000) = 428697 | m(-800, 10000) = -799
m(-999, 10000) = 428498 | m(-999, 10000) = -998
m(-1198, 10000) = 428299 | m(-1198, 10000) = -1197
m(-1397, 10000) = 428100 | m(-1397, 10000) = -1396
m(-1595, 10000) = 427902 | m(-1595, 10000) = -1594
m(-1792, 10000) = 427705 | m(-1792, 10000) = -1791
m(-1989, 10000) = 427508 | m(-1989, 10000) = -1988</code></span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1047796233818877972 class=chatlog__message-container data-message-id=1047796233818877972><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1047796233818877972>12/01/2022 5:48 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--inline">m</code>のどこで事故ってるか調査
<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C">int printf();
int m(int a, int b) {
printf("a = %d\n", a);
printf("b = %d\n", b);
int product;
int sum;
int div;
product = a * b;
sum = product + 5000;
div = sum / 10000;
printf("product = %d\n", product);
printf("sum = %d\n", sum);
printf("div = %d\n", div);
return div;
//return (a * b + 5000) / 10000;
}
int main() {
printf("m(-200, 10000) = %d\n", m(-200, 10000));
/*
printf("m( 0, 10000) = %d\n", m(0, 10000));
printf("m(-400, 10000) = %d\n", m(-400, 10000));
printf("m(-600, 10000) = %d\n", m(-600, 10000));
printf("m(-800, 10000) = %d\n", m(-800, 10000));
printf("m(-999, 10000) = %d\n", m(-999, 10000));
printf("m(-1198, 10000) = %d\n", m(-1198, 10000));
printf("m(-1397, 10000) = %d\n", m(-1397, 10000));
printf("m(-1595, 10000) = %d\n", m(-1595, 10000));
printf("m(-1792, 10000) = %d\n", m(-1792, 10000));
printf("m(-1989, 10000) = %d\n", m(-1989, 10000));
*/
return 0;
}</code></span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1047812039256576030 class=chatlog__message-container data-message-id=1047812039256576030><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1047812039256576030>12/01/2022 6:50 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--inline">m</code>のどこで事故ってるか調査
<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C">int printf();
int m(int a, int b) {
printf("a = %d\n", a);
printf("b = %d\n", b);
int product;
int sum;
int div;
product = a * b;
sum = product + 5000;
div = sum / 10000;
printf("product = %d\n", product);
printf("sum = %d\n", sum);
printf("div = %d\n", div);
return div;
//return (a * b + 5000) / 10000;
}
int main() {
printf("m(-200, 10000) = %d\n", m(-200, 10000));
/*
printf("m( 0, 10000) = %d\n", m(0, 10000));
printf("m(-400, 10000) = %d\n", m(-400, 10000));
printf("m(-600, 10000) = %d\n", m(-600, 10000));
printf("m(-800, 10000) = %d\n", m(-800, 10000));
printf("m(-999, 10000) = %d\n", m(-999, 10000));
printf("m(-1198, 10000) = %d\n", m(-1198, 10000));
printf("m(-1397, 10000) = %d\n", m(-1397, 10000));
printf("m(-1595, 10000) = %d\n", m(-1595, 10000));
printf("m(-1792, 10000) = %d\n", m(-1792, 10000));
printf("m(-1989, 10000) = %d\n", m(-1989, 10000));
*/
return 0;
}</code></span></div></div></div></div><div id=chatlog__message-container-1047812166578884628 class=chatlog__message-container data-message-id=1047812166578884628><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="12/01/2022 6:51 PM">18:51</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>符号拡張を型のサイズによって変える必要があるっぽい</span></div></div></div></div><div id=chatlog__message-container-1047812394228912190 class=chatlog__message-container data-message-id=1047812394228912190><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="12/01/2022 6:52 PM">18:52</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><a href="https://sozysozbot.github.io/seccamp-2022-c-compiler-seminar/#permalink_4b6f8c795bc832e32c3a6745ceb68082">https://sozysozbot.github.io/seccamp-2022-c-compiler-seminar/#permalink_4b6f8c795bc832e32c3a6745ceb68082</a></span></div></div></div></div><div id=chatlog__message-container-1047812464328319027 class=chatlog__message-container data-message-id=1047812464328319027><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="12/01/2022 6:52 PM">18:52</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><a href="https://twitter.com/lemolatoon1/status/1598236585547350016">https://twitter.com/lemolatoon1/status/1598236585547350016</a></span></div><div class=chatlog__embed><div class=chatlog__embed-color-pill style=background-color:rgba(29,161,242,255)></div><div class=chatlog__embed-content-container><div class=chatlog__embed-content><div class=chatlog__embed-text><div class=chatlog__embed-author-container><img class=chatlog__embed-author-icon src=https://images-ext-1.discordapp.net/external/dek92cu8reaPLnsiUjh1wwhHIoucm7A4O5VwoFcsTMk/https/pbs.twimg.com/profile_images/1475101275390095362/_eA3Dnt4_400x400.jpg alt="Author icon" loading=lazy onerror="this.style.visibility='hidden'"> <a class=chatlog__embed-author-link href=https://twitter.com/lemolatoon1><div class=chatlog__embed-author>lemolatoon (@lemolatoon1)</div></a></div><div class=chatlog__embed-description><div class="chatlog__markdown chatlog__markdown-preserve">@mikikeen これ僕もバグらせたんですが、ログを「割り算」などで検索すると当時の会話でそのことについて話してます。<a href="https://t.co/pCdLWPAyRm">https://t.co/pCdLWPAyRm</a></div></div></div></div><div class=chatlog__embed-footer><img class=chatlog__embed-footer-icon src=https://images-ext-1.discordapp.net/external/bXJWV2Y_F3XSra_kEqIYXAAsI3m1meckfLhYuWzxIfI/https/abs.twimg.com/icons/apple-touch-icon-192x192.png alt="Footer icon" loading=lazy> <span class=chatlog__embed-footer-text> Twitter • 12/01/2022 5:44 PM </span></div></div></div></div></div></div><div id=chatlog__message-container-1047812743920631828 class=chatlog__message-container data-message-id=1047812743920631828><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="12/01/2022 6:53 PM">18:53</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>型のサイズに応じて符号拡張する関数書いたら、ドーナツ出た
(ただ、まだセグフォする)
<a href="https://twitter.com/mikikeen/status/1598726498948591616">https://twitter.com/mikikeen/status/1598726498948591616</a></span> <span class=chatlog__edited-timestamp title="02/14/2023 10:18 PM">(edited)</span></div><div class=chatlog__attachment><a href="https://cdn.discordapp.com/attachments/1003859454191751178/1047812743664783360/image.png?ex=6555e6a9&is=654371a9&hm=fd838c95a43de530045cf8bf93ec0b154db60524ce09d50209f0fb2fb20f35c1&"> <img class=chatlog__attachment-media src="https://cdn.discordapp.com/attachments/1003859454191751178/1047812743664783360/image.png?ex=6555e6a9&is=654371a9&hm=fd838c95a43de530045cf8bf93ec0b154db60524ce09d50209f0fb2fb20f35c1&" alt="Image attachment" title="Image: image.png (144.87 KB)" loading=lazy> </a></div><div class=chatlog__embed><div class=chatlog__embed-color-pill style=background-color:rgba(29,161,242,255)></div><div class=chatlog__embed-content-container><div class=chatlog__embed-content><div class=chatlog__embed-text><div class=chatlog__embed-author-container><img class=chatlog__embed-author-icon src=https://images-ext-2.discordapp.net/external/-pybTvpe-fvxiOIipD5NW9QwBcC744fe9NKXYMRNpa4/https/pbs.twimg.com/profile_images/1379802435837812738/J9bYEXNk_400x400.jpg alt="Author icon" loading=lazy onerror="this.style.visibility='hidden'"> <a class=chatlog__embed-author-link href=https://twitter.com/mikikeen><div class=chatlog__embed-author>mikiken (@mikikeen)</div></a></div><div class=chatlog__embed-description><div class="chatlog__markdown chatlog__markdown-preserve">自作コンパイラ、伝家の宝刀†printfデバッグ†してたら、printfの有無で挙動変わって頭抱えてる</div></div><div class=chatlog__embed-fields><div class="chatlog__embed-field chatlog__embed-field--inline"><div class=chatlog__embed-field-name><div class="chatlog__markdown chatlog__markdown-preserve">Likes</div></div><div class=chatlog__embed-field-value><div class="chatlog__markdown chatlog__markdown-preserve">149</div></div></div></div></div></div><div class=chatlog__embed-footer><img class=chatlog__embed-footer-icon src=https://images-ext-1.discordapp.net/external/bXJWV2Y_F3XSra_kEqIYXAAsI3m1meckfLhYuWzxIfI/https/abs.twimg.com/icons/apple-touch-icon-192x192.png alt="Footer icon" loading=lazy> <span class=chatlog__embed-footer-text> Twitter • 12/03/2022 2:11 AM </span></div></div></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1051813343461126236 class=chatlog__message-container data-message-id=1051813343461126236><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1051813343461126236>12/12/2022 7:50 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>久々にデバッグの続きをやっていく~~</span></div></div></div></div><div id=chatlog__message-container-1051813575116730378 class=chatlog__message-container data-message-id=1051813575116730378><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="12/12/2022 7:51 PM">19:51</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>とりあえず
・符号拡張直したやつ
・配列をポインタにキャストし忘れてたやつを追加
をcommitした</span></div></div></div></div><div id=chatlog__message-container-1051813719799242792 class=chatlog__message-container data-message-id=1051813719799242792><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="12/12/2022 7:52 PM">19:52</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>それで何がどうなっていたか、忘れてたのでMakeFileの差分もdiscardした</span></div></div></div></div><div id=chatlog__message-container-1051813850992889916 class=chatlog__message-container data-message-id=1051813850992889916><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="12/12/2022 7:52 PM">19:52</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>codegen.cのコメントアウトでいい感じにnodeの種類を表示するやつはそのまま置いてある</span></div></div></div></div><div id=chatlog__message-container-1051813954839658570 class=chatlog__message-container data-message-id=1051813954839658570><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="12/12/2022 7:53 PM">19:53</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><a href="https://github.com/hsjoihs/c-compiler/blob/17f53331a19e37594d07e69cc70bc71ae30eb6f4/misc/donut_donut.c">https://github.com/hsjoihs/c-compiler/blob/17f53331a19e37594d07e69cc70bc71ae30eb6f4/misc/donut_donut.c</a></span></div><div class=chatlog__embed><div class=chatlog__embed-color-pill style=background-color:rgba(30,35,39,255)></div><div class=chatlog__embed-content-container><div class=chatlog__embed-content><div class=chatlog__embed-text><div class=chatlog__embed-title><a class=chatlog__embed-title-link href=https://github.com/hsjoihs/c-compiler/blob/17f53331a19e37594d07e69cc70bc71ae30eb6f4/misc/donut_donut.c><div class="chatlog__markdown chatlog__markdown-preserve">c-compiler/donut_donut.c at 17f53331a19e37594d07e69cc70bc71ae30eb6f...</div></a></div><div class=chatlog__embed-description><div class="chatlog__markdown chatlog__markdown-preserve">seccamp2018 c compiler. Contribute to hsjoihs/c-compiler development by creating an account on GitHub.</div></div></div><div class=chatlog__embed-thumbnail-container><a class=chatlog__embed-thumbnail-link href=https://images-ext-1.discordapp.net/external/vLLxuiw2QPIVJJL3UOAtcL5b-2yN48BTZnHG5BhWzYM/https/opengraph.githubassets.com/bb4c508b95c6221a9f1d8542652c6e03ea8ffa887d98ad3c322ba72dbe3d95aa/hsjoihs/c-compiler> <img class=chatlog__embed-thumbnail src=https://images-ext-1.discordapp.net/external/vLLxuiw2QPIVJJL3UOAtcL5b-2yN48BTZnHG5BhWzYM/https/opengraph.githubassets.com/bb4c508b95c6221a9f1d8542652c6e03ea8ffa887d98ad3c322ba72dbe3d95aa/hsjoihs/c-compiler alt=Thumbnail loading=lazy> </a></div></div></div></div></div></div></div><div id=chatlog__message-container-1051814253620908052 class=chatlog__message-container data-message-id=1051814253620908052><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="12/12/2022 7:54 PM">19:54</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>donutifyされてるやつを普通に戻して初期化式を排除して、下のメッセージを消去したdonut.cがこれ</span></div></div></div></div><div id=chatlog__message-container-1051814513827139624 class=chatlog__message-container data-message-id=1051814513827139624><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="12/12/2022 7:55 PM">19:55</div></div><div class=chatlog__message-primary><div class=chatlog__attachment><div class=chatlog__attachment-generic><svg class=chatlog__attachment-generic-icon><use href=#attachment-icon /></svg><div class=chatlog__attachment-generic-name><a href="https://cdn.discordapp.com/attachments/1003859454191751178/1051814513470603264/donut_basic.c?ex=65520099&is=653f8b99&hm=4a5aa1343f43b2088e3cee4729d4facb74d495ecf23a691a5dea5c5bddbe4dca&"> donut_basic.c </a></div><div class=chatlog__attachment-generic-size>1.54 KB</div></div></div></div></div></div><div id=chatlog__message-container-1051814631053721641 class=chatlog__message-container data-message-id=1051814631053721641><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="12/12/2022 7:55 PM">19:55</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>とりあえず9ccでコンパイルしてみる</span></div></div></div></div><div id=chatlog__message-container-1051814665879035914 class=chatlog__message-container data-message-id=1051814665879035914><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="12/12/2022 7:55 PM">19:55</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>usleepでセグフォしてる</span></div></div></div></div><div id=chatlog__message-container-1051814771369979934 class=chatlog__message-container data-message-id=1051814771369979934><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="12/12/2022 7:56 PM">19:56</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>こういうの
<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C">void usleep();
int printf();
int main() {
usleep(2000000);
printf("Now testing usleep() calling.\n");
}</code></span></div></div></div></div><div id=chatlog__message-container-1051814830136381481 class=chatlog__message-container data-message-id=1051814830136381481><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="12/12/2022 7:56 PM">19:56</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>がコンパイルできるか確認したところ、これは通る</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1052277962868793375 class=chatlog__message-container data-message-id=1052277962868793375><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1052277962868793375>12/14/2022 2:36 AM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--multiline nohighlight">Program received signal SIGSEGV, Segmentation fault.
[----------------------------------registers-----------------------------------]
RAX: 0x7fffff7feffc
RBX: 0x2
RCX: 0xc8
RDX: 0x270e
RSI: 0x270e
RDI: 0xffffe7ea
RBP: 0x7fffff7ff000 --> 0x7fffff7ff048 --> 0x7fffffffddd0 --> 0x0
RSP: 0x7fffff7feff0
RIP: 0x555555555165 (<m+12>: mov DWORD PTR [rax],edi)
R8 : 0xa ('\n')
R9 : 0x3
R10: 0x555555558010 --> 0x7e2d2c2e00485b1b
R11: 0x246
R12: 0x555555555070 (<_start>: endbr64)
R13: 0x7fffffffdec0 --> 0x1
R14: 0x0
R15: 0x0
EFLAGS: 0x10206 (carry PARITY adjust zero sign trap INTERRUPT direction overflow)
[-------------------------------------code-------------------------------------]
0x55555555515a <m+1>: mov rbp,rsp
0x55555555515d <m+4>: sub rsp,0x10
0x555555555161 <m+8>: lea rax,[rbp-0x4]
=> 0x555555555165 <m+12>: mov DWORD PTR [rax],edi
0x555555555167 <m+14>: lea rax,[rbp-0x8]
0x55555555516b <m+18>: mov DWORD PTR [rax],esi
0x55555555516d <m+20>: lea rdi,[rbp-0x4]
0x555555555171 <m+24>: push rdi
[------------------------------------stack-------------------------------------]
Invalid $SP address: 0x7fffff7feff0
[------------------------------------------------------------------------------]
Legend: code, data, rodata, value
Stopped reason: SIGSEGV
m () at tmp.s:18
18 mov DWORD PTR [rax], edi
gdb-peda$ q</code></span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1052438684928053258 class=chatlog__message-container data-message-id=1052438684928053258><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1052438684928053258>12/14/2022 1:15 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>ワンチャン原因これか?</span></div></div></div></div><div id=chatlog__message-container-1052438713474494506 class=chatlog__message-container data-message-id=1052438713474494506><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="12/14/2022 1:15 PM">13:15</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--multiline nohighlight">mikiken@DESKTOP-CM4259U:~/compiler/9cc$ ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 31257
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1048576
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 31257
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited</code></span></div></div></div></div><div id=chatlog__message-container-1052439399788458074 class=chatlog__message-container data-message-id=1052439399788458074><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="12/14/2022 1:18 PM">13:18</div></div><div class=chatlog__message-primary><div class=chatlog__attachment><a href="https://cdn.discordapp.com/attachments/1003859454191751178/1052439399419347024/image.png?ex=65544692&is=6541d192&hm=f493b817b87ce739daeb829ed3b453d499c8f98c9b69ccca5f2cf1dc3d3b3487&"> <img class=chatlog__attachment-media src="https://cdn.discordapp.com/attachments/1003859454191751178/1052439399419347024/image.png?ex=65544692&is=6541d192&hm=f493b817b87ce739daeb829ed3b453d499c8f98c9b69ccca5f2cf1dc3d3b3487&" alt="Image attachment" title="Image: image.png (48.37 KB)" loading=lazy> </a></div></div></div></div><div id=chatlog__message-container-1052439449012817920 class=chatlog__message-container data-message-id=1052439449012817920><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="12/14/2022 1:18 PM">13:18</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>はい正解~~~</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1052493920925397063 class=chatlog__message-container data-message-id=1052493920925397063><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1052493920925397063>12/14/2022 4:55 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><a href="https://youreingaming.blog.fc2.com/blog-entry-92.html">https://youreingaming.blog.fc2.com/blog-entry-92.html</a></span></div><div class=chatlog__embed><div class="chatlog__embed-color-pill chatlog__embed-color-pill--default"></div><div class=chatlog__embed-content-container><div class=chatlog__embed-content><div class=chatlog__embed-text><div class=chatlog__embed-title><a class=chatlog__embed-title-link href=https://youreingaming.blog.fc2.com/blog-entry-92.html><div class="chatlog__markdown chatlog__markdown-preserve">C/C++でデカい配列がSegmentation faultを吐くときに読む記事 - PC関連</div></a></div><div class=chatlog__embed-description><div class="chatlog__markdown chatlog__markdown-preserve">顛末自作のmodintライブラリのテストがてら、( 10^6 \times 10 )サイズの配列を宣言してみたらsegmentation faultが出た。計算途中にオーバーフローを起こすような処理(例えばmodを取る前の値がlong longのmaxを超えているとか)を行っているわけではないのでおそらくメモリ関連のエラーであると推測する。同様のサイズの配列をWindows環境でMinGW G++を用いてコンパイルして実行しても正常に通るのでおそらくLinux(Ubuntu on WSL...</div></div></div></div></div></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1052504515150098452 class=chatlog__message-container data-message-id=1052504515150098452><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1052504515150098452>12/14/2022 5:37 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>なんか<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">usleep.c</code>がないって言われてるっぽい?</span> <span class=chatlog__edited-timestamp title="12/14/2022 5:37 PM">(edited)</span></div></div></div></div><div id=chatlog__message-container-1052504531478511708 class=chatlog__message-container data-message-id=1052504531478511708><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="12/14/2022 5:37 PM">17:37</div></div><div class=chatlog__message-primary><div class=chatlog__attachment><div class=chatlog__attachment-generic><svg class=chatlog__attachment-generic-icon><use href=#attachment-icon /></svg><div class=chatlog__attachment-generic-name><a href="https://cdn.discordapp.com/attachments/1003859454191751178/1052504531142979605/message.txt?ex=6554833a&is=65420e3a&hm=340a2647629d629320f2a616446482749c6f10c719abbd950d49a37ddef5a805&"> message.txt </a></div><div class=chatlog__attachment-generic-size>7.35 KB</div></div></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1054785145971953746 class=chatlog__message-container data-message-id=1054785145971953746><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1054785145971953746>12/21/2022 12:39 AM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>スタックの16byte-alignmentが崩れている</span></div></div></div></div><div id=chatlog__message-container-1054785191786323969 class=chatlog__message-container data-message-id=1054785191786323969><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="12/21/2022 12:39 AM">00:39</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--multiline nohighlight">.L.end.3:
lea rdi, [rbp-8844]
push rdi
lea rdi, [rbp-8844]
push rdi
pop rdi
mov eax, DWORD PTR [rdi]
push rax
push 1
pop rbx
pop rax
add eax, ebx
push rax
pop rax
pop rdi
mov DWORD PTR [rdi], eax
push rax
push 1
pop rbx
pop rax
sub eax, ebx
push rax
pop rax
lea rdi, [rbp-8840]
push rdi
lea rdi, [rbp-8836]
push rdi
lea rdi, [rbp-8804]
push rdi
pop rdi
mov eax, DWORD PTR [rdi]
push rax
push 2
pop rbx
pop rax
sub eax, ebx
push rax
push 200
pop rcx
pop rdx
pop rsi
pop rdi
mov al, 0
# stack_align % 16 = -8 // => 0
call a
push rax
jmp .L.begin.2
.L.end.2:</code></span></div></div></div></div><div id=chatlog__message-container-1054785600034713610 class=chatlog__message-container data-message-id=1054785600034713610><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="12/21/2022 12:41 AM">00:41</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>最初におかしくなってるのが、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">tmp.s</code>の1133行目で、これに対応するのは<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">donut.c</code>の50行目の
<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C"> for (j = 0; j < 314; j++, a(&e, &w, s - 2, 200)) {</code>
関数<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">a</code>を呼び出す部分だと考えられる</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1061648890408992909 class=chatlog__message-container data-message-id=1061648890408992909><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1061648890408992909>01/08/2023 11:13 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><strong>~1ヶ月経過<img
loading="lazy"
class="chatlog__emoji "
alt="😇"
title="innocent"
src="https://cdn.jsdelivr.net/gh/twitter/twemoji@latest/assets/svg/1f607.svg">~</strong>
<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">for(expr; expr; expr)</code>の<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">expr</code>の値がpushされたままになってたのが原因</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1062407993628565555 class=chatlog__message-container data-message-id=1062407993628565555><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1062407993628565555>01/11/2023 1:30 AM</a></span></div><div class=chatlog__attachment><a href="https://cdn.discordapp.com/attachments/1003859454191751178/1062407993406279771/f04e41a6-d9a3-4290-aed2-7004401a8058.png?ex=6553a08c&is=65412b8c&hm=627155e9b9b7ee7429a64a8c2374e9ea308366e11eb4bf0d354e9261b0a0319e&"> <img class=chatlog__attachment-media src="https://cdn.discordapp.com/attachments/1003859454191751178/1062407993406279771/f04e41a6-d9a3-4290-aed2-7004401a8058.png?ex=6553a08c&is=65412b8c&hm=627155e9b9b7ee7429a64a8c2374e9ea308366e11eb4bf0d354e9261b0a0319e&" alt="Image attachment" title="Image: f04e41a6-d9a3-4290-aed2-7004401a8058.png (28.2 KB)" loading=lazy> </a></div></div></div></div><div id=chatlog__message-container-1062408101120184472 class=chatlog__message-container data-message-id=1062408101120184472><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="01/11/2023 1:30 AM">01:30</div></div><div class=chatlog__message-primary><div class=chatlog__attachment><a href="https://cdn.discordapp.com/attachments/1003859454191751178/1062408101124386816/9ca27d31-95de-4b22-8805-68eb5697cf8d.png?ex=6553a0a5&is=65412ba5&hm=2a5b69076fc901303bf8e13af9108a4af8dc7c394744de0269f0d149db3bb716&"> <img class=chatlog__attachment-media src="https://cdn.discordapp.com/attachments/1003859454191751178/1062408101124386816/9ca27d31-95de-4b22-8805-68eb5697cf8d.png?ex=6553a0a5&is=65412ba5&hm=2a5b69076fc901303bf8e13af9108a4af8dc7c394744de0269f0d149db3bb716&" alt="Image attachment" title="Image: 9ca27d31-95de-4b22-8805-68eb5697cf8d.png (221.65 KB)" loading=lazy> </a></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1074988058958635059 class=chatlog__message-container data-message-id=1074988058958635059><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1074988058958635059>02/14/2023 6:38 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><strong>再び1ヶ月経過</strong></span></div></div></div></div><div id=chatlog__message-container-1074988115787268106 class=chatlog__message-container data-message-id=1074988115787268106><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="02/14/2023 6:38 PM">18:38</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><a href="https://twitter.com/mikikeen/status/1625040676474982400">https://twitter.com/mikikeen/status/1625040676474982400</a></span></div><div class=chatlog__embed><div class=chatlog__embed-color-pill style=background-color:rgba(29,161,242,255)></div><div class=chatlog__embed-content-container><div class=chatlog__embed-content><div class=chatlog__embed-text><div class=chatlog__embed-author-container><img class=chatlog__embed-author-icon src=https://images-ext-2.discordapp.net/external/-pybTvpe-fvxiOIipD5NW9QwBcC744fe9NKXYMRNpa4/https/pbs.twimg.com/profile_images/1379802435837812738/J9bYEXNk_400x400.jpg alt="Author icon" loading=lazy onerror="this.style.visibility='hidden'"> <a class=chatlog__embed-author-link href=https://twitter.com/mikikeen><div class=chatlog__embed-author>mikiken (@mikikeen)</div></a></div><div class=chatlog__embed-description><div class="chatlog__markdown chatlog__markdown-preserve">1ヶ月ぶりに自作コンパイラのコード見てるけど、何をしようとしてたか忘れた</div></div></div></div><div class=chatlog__embed-footer><img class=chatlog__embed-footer-icon src=https://images-ext-1.discordapp.net/external/bXJWV2Y_F3XSra_kEqIYXAAsI3m1meckfLhYuWzxIfI/https/abs.twimg.com/icons/apple-touch-icon-192x192.png alt="Footer icon" loading=lazy> <span class=chatlog__embed-footer-text> Twitter • 02/13/2023 4:54 PM </span></div></div></div></div></div></div><div id=chatlog__message-container-1074988147521368084 class=chatlog__message-container data-message-id=1074988147521368084><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="02/14/2023 6:39 PM">18:39</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><a href="https://twitter.com/mikikeen/status/1625040952728645633">https://twitter.com/mikikeen/status/1625040952728645633</a></span></div><div class=chatlog__embed><div class=chatlog__embed-color-pill style=background-color:rgba(29,161,242,255)></div><div class=chatlog__embed-content-container><div class=chatlog__embed-content><div class=chatlog__embed-text><div class=chatlog__embed-author-container><img class=chatlog__embed-author-icon src=https://images-ext-2.discordapp.net/external/-pybTvpe-fvxiOIipD5NW9QwBcC744fe9NKXYMRNpa4/https/pbs.twimg.com/profile_images/1379802435837812738/J9bYEXNk_400x400.jpg alt="Author icon" loading=lazy onerror="this.style.visibility='hidden'"> <a class=chatlog__embed-author-link href=https://twitter.com/mikikeen><div class=chatlog__embed-author>mikiken (@mikikeen)</div></a></div><div class=chatlog__embed-description><div class="chatlog__markdown chatlog__markdown-preserve">ローカルな配列の初期化式を実装しようとしてたっぽい</div></div></div></div><div class=chatlog__embed-footer><img class=chatlog__embed-footer-icon src=https://images-ext-1.discordapp.net/external/bXJWV2Y_F3XSra_kEqIYXAAsI3m1meckfLhYuWzxIfI/https/abs.twimg.com/icons/apple-touch-icon-192x192.png alt="Footer icon" loading=lazy> <span class=chatlog__embed-footer-text> Twitter • 02/13/2023 4:55 PM </span></div></div></div></div></div></div><div id=chatlog__message-container-1074988171848318996 class=chatlog__message-container data-message-id=1074988171848318996><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="02/14/2023 6:39 PM">18:39</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>というわけでやっていき</span></div></div></div></div><div id=chatlog__message-container-1074988377474076672 class=chatlog__message-container data-message-id=1074988377474076672><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="02/14/2023 6:40 PM">18:40</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>こんな感じのコードを追加し、
<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C">Node *array_init(Function *func, Token *ident, Token *tok) {
Node head;
Node *cur = &head;
for (int offset = 0; !consume(tok, TK_RIGHT_BRACE); offset++) {
cur = cur->next = new_node(ND_STMT);
cur->body = new_node(ND_ASSIGN);
cur->body->lhs = new_binary_node(ND_DEREF, new_binary_node(ND_ADD, var_node(func, ident), new_num_node(offset)), NULL);
cur->body->rhs = assign(func, tok);
if (consume(tok, TK_RIGHT_BRACE))
return head.next;
expect(tok, TK_COMMA);
}
return head.next;
}</code></span></div></div></div></div><div id=chatlog__message-container-1074988468708577340 class=chatlog__message-container data-message-id=1074988468708577340><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="02/14/2023 6:40 PM">18:40</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>こういうコードが通るようになった
<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C">int array_test13() {
int a[5] = {1, 2, 3, 4, 5};
int sum = 0;
for (int i = 0; i < 5; i++)
sum += a[i];
return sum;
}</code></span></div></div></div></div><div id=chatlog__message-container-1074988607590383687 class=chatlog__message-container data-message-id=1074988607590383687><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="02/14/2023 6:40 PM">18:40</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>ケツカンマがあっても通る実装になってる</span></div></div></div></div><div id=chatlog__message-container-1074988723474792480 class=chatlog__message-container data-message-id=1074988723474792480><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="02/14/2023 6:41 PM">18:41</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>あと実装しないといけない仕様としては、</span></div></div></div></div><div id=chatlog__message-container-1074988862515986533 class=chatlog__message-container data-message-id=1074988862515986533><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="02/14/2023 6:41 PM">18:41</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>配列の長さを明示的に書かずに初期化するやつ
<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C">int arr[] = {1,2,3};</code></span> <span class=chatlog__edited-timestamp title="02/14/2023 6:42 PM">(edited)</span></div></div></div></div><div id=chatlog__message-container-1074989266381324349 class=chatlog__message-container data-message-id=1074989266381324349><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="02/14/2023 6:43 PM">18:43</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>あとは初期化式が一部しか与えられてない場合に、残りの要素を0埋めするやつとか
<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C">int x[5] = {1, 2, 3}; // これは下と等価
int x[5] = {1, 2, 3, 0, 0};</code></span></div></div></div></div><div id=chatlog__message-container-1074989774835826699 class=chatlog__message-container data-message-id=1074989774835826699><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="02/14/2023 6:45 PM">18:45</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>そもそも、ただ配列を宣言しただけのときって、初期化されたっけ?
<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C">int arr[3]; // これの初期値どうなってる?</code></span></div></div></div></div><div id=chatlog__message-container-1074990583417937930 class=chatlog__message-container data-message-id=1074990583417937930><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="02/14/2023 6:48 PM">18:48</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>あとは、定義したデカさ以上の要素を参照しようとしたときに警告出すとか
(gccで試したらwarningになったので、未定義動作っぽい?)←確認が必要</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1075285812989669447 class=chatlog__message-container data-message-id=1075285812989669447><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1075285812989669447>02/15/2023 2:21 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>ポインタの配列のテストケース入れてないな、そういえば</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1075296950976532520 class=chatlog__message-container data-message-id=1075296950976532520><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1075296950976532520>02/15/2023 3:06 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>とりあえず配列の長さを明示的に書かないやつを実装していく</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1075340529346293820 class=chatlog__message-container data-message-id=1075340529346293820><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1075340529346293820>02/15/2023 5:59 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>適当にコード足したら、変数のオフセットの処理書き忘れたっぽくて、出力したアセンブリがセグフォする</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1075399719066538014 class=chatlog__message-container data-message-id=1075399719066538014><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1075399719066538014>02/15/2023 9:54 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>テストでコケても、他のテストケースも流せるようにしたいかも</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1075424838077911060 class=chatlog__message-container data-message-id=1075424838077911060><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1075424838077911060>02/15/2023 11:34 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><s>ND_LVARっていうNodekind、実質使ってないから抹消したさあるな</s>
(追記) <code class="chatlog__markdown-pre chatlog__markdown-pre--inline">int a[3];</code>みたいな感じで宣言のみを行う場合、木構造の葉にあたるnodeがなくなってしまうので、あった方が便利</span> <span class=chatlog__edited-timestamp title="02/17/2023 9:17 PM">(edited)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1075691101006090270 class=chatlog__message-container data-message-id=1075691101006090270><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1075691101006090270>02/16/2023 5:12 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>本来出力されるべきアセンブリと現状出力されているものとの差分</span></div></div></div></div><div id=chatlog__message-container-1075691133780365382 class=chatlog__message-container data-message-id=1075691133780365382><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="02/16/2023 5:12 PM">17:12</div></div><div class=chatlog__message-primary><div class=chatlog__attachment><div class=chatlog__attachment-generic><svg class=chatlog__attachment-generic-icon><use href=#attachment-icon /></svg><div class=chatlog__attachment-generic-name><a href="https://cdn.discordapp.com/attachments/1003859454191751178/1075691133444825109/message.txt?ex=6555ceef&is=654359ef&hm=247e899d0fcf327a308b5cba297029e4bece8ce0e9fa0cffe85f1c6157dab749&"> message.txt </a></div><div class=chatlog__attachment-generic-size>7.91 KB</div></div></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1076115712281681991 class=chatlog__message-container data-message-id=1076115712281681991><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1076115712281681991>02/17/2023 9:19 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>配列の長さを省略する記法をサポート
<a href="https://github.com/mikiken/9cc/commit/7335f8135ffd28916d86c738c526180645331b50">https://github.com/mikiken/9cc/commit/7335f8135ffd28916d86c738c526180645331b50</a></span> <span class=chatlog__edited-timestamp title="02/17/2023 9:19 PM">(edited)</span></div><div class=chatlog__embed><div class=chatlog__embed-color-pill style=background-color:rgba(30,35,39,255)></div><div class=chatlog__embed-content-container><div class=chatlog__embed-content><div class=chatlog__embed-text><div class=chatlog__embed-title><a class=chatlog__embed-title-link href=https://github.com/mikiken/9cc/commit/7335f8135ffd28916d86c738c526180645331b50><div class="chatlog__markdown chatlog__markdown-preserve">Allow to omit array length if an initializer is given · mikiken/9cc...</div></a></div></div><div class=chatlog__embed-thumbnail-container><a class=chatlog__embed-thumbnail-link href=https://images-ext-1.discordapp.net/external/0ZGkO16pJj21_oG5LBYbRe-Ot86qBHttua0xfgXwqhA/https/opengraph.githubassets.com/34191cdb8ca6ec6bf682f87ab36f5f98d22718cf75ce344ad7c789fdd3d8f28f/mikiken/9cc/commit/7335f8135ffd28916d86c738c526180645331b50> <img class=chatlog__embed-thumbnail src=https://images-ext-1.discordapp.net/external/0ZGkO16pJj21_oG5LBYbRe-Ot86qBHttua0xfgXwqhA/https/opengraph.githubassets.com/34191cdb8ca6ec6bf682f87ab36f5f98d22718cf75ce344ad7c789fdd3d8f28f/mikiken/9cc/commit/7335f8135ffd28916d86c738c526180645331b50 alt=Thumbnail loading=lazy> </a></div></div></div></div></div></div></div><div id=chatlog__message-container-1076115951134707732 class=chatlog__message-container data-message-id=1076115951134707732><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="02/17/2023 9:20 PM">21:20</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>あと初期化の要素が配列の長さより短い場合に、残りの要素に0を代入するやつを実装した
<a href="https://github.com/mikiken/9cc/commit/e45a6b45485e02bdcf6d5855b96f2641cfb337c3">https://github.com/mikiken/9cc/commit/e45a6b45485e02bdcf6d5855b96f2641cfb337c3</a></span> <span class=chatlog__edited-timestamp title="02/17/2023 9:20 PM">(edited)</span></div><div class=chatlog__embed><div class=chatlog__embed-color-pill style=background-color:rgba(30,35,39,255)></div><div class=chatlog__embed-content-container><div class=chatlog__embed-content><div class=chatlog__embed-text><div class=chatlog__embed-title><a class=chatlog__embed-title-link href=https://github.com/mikiken/9cc/commit/e45a6b45485e02bdcf6d5855b96f2641cfb337c3><div class="chatlog__markdown chatlog__markdown-preserve">Assign 0 to the array elements · mikiken/9cc@e45a6b4</div></a></div><div class=chatlog__embed-description><div class="chatlog__markdown chatlog__markdown-preserve">if not all elements are given at initalizer</div></div></div><div class=chatlog__embed-thumbnail-container><a class=chatlog__embed-thumbnail-link href=https://images-ext-2.discordapp.net/external/sx2G_DRAumcWnXEOezWZEWtqIsZgoc8izFb3KxcRRDA/https/opengraph.githubassets.com/95b1d0206585e34118ba7c7a919774e26461f559a3e908640495553dcbe4d69d/mikiken/9cc/commit/e45a6b45485e02bdcf6d5855b96f2641cfb337c3> <img class=chatlog__embed-thumbnail src=https://images-ext-2.discordapp.net/external/sx2G_DRAumcWnXEOezWZEWtqIsZgoc8izFb3KxcRRDA/https/opengraph.githubassets.com/95b1d0206585e34118ba7c7a919774e26461f559a3e908640495553dcbe4d69d/mikiken/9cc/commit/e45a6b45485e02bdcf6d5855b96f2641cfb337c3 alt=Thumbnail loading=lazy> </a></div></div></div></div></div></div></div><div id=chatlog__message-container-1076116083146244097 class=chatlog__message-container data-message-id=1076116083146244097><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="02/17/2023 9:21 PM">21:21</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><a href="https://twitter.com/mikikeen/status/1626471284287897600">https://twitter.com/mikikeen/status/1626471284287897600</a></span></div><div class=chatlog__embed><div class=chatlog__embed-color-pill style=background-color:rgba(29,161,242,255)></div><div class=chatlog__embed-content-container><div class=chatlog__embed-content><div class=chatlog__embed-text><div class=chatlog__embed-author-container><img class=chatlog__embed-author-icon src=https://images-ext-2.discordapp.net/external/-pybTvpe-fvxiOIipD5NW9QwBcC744fe9NKXYMRNpa4/https/pbs.twimg.com/profile_images/1379802435837812738/J9bYEXNk_400x400.jpg alt="Author icon" loading=lazy onerror="this.style.visibility='hidden'"> <a class=chatlog__embed-author-link href=https://twitter.com/mikikeen><div class=chatlog__embed-author>mikiken (@mikikeen)</div></a></div><div class=chatlog__embed-description><div class="chatlog__markdown chatlog__markdown-preserve">char str[] = "hoge"; みたいな構文を実装しようとしたが、文字リテラルをまだ実装していなかった
(文字列リテラルはある)</div></div></div></div><div class=chatlog__embed-footer><img class=chatlog__embed-footer-icon src=https://images-ext-1.discordapp.net/external/bXJWV2Y_F3XSra_kEqIYXAAsI3m1meckfLhYuWzxIfI/https/abs.twimg.com/icons/apple-touch-icon-192x192.png alt="Footer icon" loading=lazy> <span class=chatlog__embed-footer-text> Twitter • 02/17/2023 3:39 PM </span></div></div></div></div></div></div><div id=chatlog__message-container-1076116131942772797 class=chatlog__message-container data-message-id=1076116131942772797><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="02/17/2023 9:21 PM">21:21</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>というわけで、文字リテラルを実装していく</span></div></div></div></div><div id=chatlog__message-container-1076116463716405348 class=chatlog__message-container data-message-id=1076116463716405348><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="02/17/2023 9:22 PM">21:22</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>大体できたけど、エスケープシーケンスが2文字と解釈されてエラーでる(それはそう)</span></div></div></div></div><div id=chatlog__message-container-1076116726107865118 class=chatlog__message-container data-message-id=1076116726107865118><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="02/17/2023 9:23 PM">21:23</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>こんな感じのコードを追加し、tok->valの値とすることで、ひとまず動くようにはなった
<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C">char read_escape_char(char *p) {
switch (*p) {
case 'a':
return 7;
case 'b':
return 8;
case 't':
return 9;
case 'n':
return 10;
case 'v':
return 11;
case 'f':
return 12;
case 'r':
return 13;
case 'e':
return 27;
case '"':
return 34;
case '\'':
return 39;
case '\\':
return 92;
default:
return *p;
}
}</code></span></div></div></div></div><div id=chatlog__message-container-1076116890914664489 class=chatlog__message-container data-message-id=1076116890914664489><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="02/17/2023 9:24 PM">21:24</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>文字列リテラルでも似たようなコードを書いてしまってるのをどうにかしたい</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1076119302354239548 class=chatlog__message-container data-message-id=1076119302354239548><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1076119302354239548>02/17/2023 9:33 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>実は文字列リテラル実装するとき、Compiler Explorerの出力を見ようみまねで真似ただけで、いまいち仕組みが分かっていない<img
loading="lazy"
class="chatlog__emoji "
alt="😇"
title="innocent"
src="https://cdn.jsdelivr.net/gh/twitter/twemoji@latest/assets/svg/1f607.svg"></span> <span class=chatlog__edited-timestamp title="02/21/2023 4:31 PM">(edited)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1077483881617424424 class=chatlog__message-container data-message-id=1077483881617424424><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1077483881617424424>02/21/2023 3:56 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>えーとchibiccでは、文字列リテラルはdataセクションに<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">char</code>の配列として記録されているっぽい</span> <span class=chatlog__edited-timestamp title="02/21/2023 4:29 PM">(edited)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1077492322754895913 class=chatlog__message-container data-message-id=1077492322754895913><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1077492322754895913>02/21/2023 4:29 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>一方、自分のやつの場合、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">.string</code>という記法を使って<s>お茶を濁して</s>いる</span> <span class=chatlog__edited-timestamp title="02/23/2023 10:10 PM">(edited)</span></div></div></div></div><div id=chatlog__message-container-1077493473499938856 class=chatlog__message-container data-message-id=1077493473499938856><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="02/21/2023 4:34 PM">16:34</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>このディレクティブあたりの話は、以下のURL見ると良さそう
<a href="http://www.swlab.cs.okayama-u.ac.jp/~nom/lect/p3/what-is-directive.html">http://www.swlab.cs.okayama-u.ac.jp/~nom/lect/p3/what-is-directive.html</a>
<a href="https://suu-g.hateblo.jp/entry/20080510/1210408956">https://suu-g.hateblo.jp/entry/20080510/1210408956</a></span> <span class=chatlog__edited-timestamp title="02/21/2023 4:35 PM">(edited)</span></div><div class=chatlog__embed><div class="chatlog__embed-color-pill chatlog__embed-color-pill--default"></div><div class=chatlog__embed-content-container><div class=chatlog__embed-content><div class=chatlog__embed-text><div class=chatlog__embed-author-container><a class=chatlog__embed-author-link href="https://blog.hatena.ne.jp/suu-g/"><div class=chatlog__embed-author>suu-g</div></a></div><div class=chatlog__embed-title><a class=chatlog__embed-title-link href=https://suu-g.hateblo.jp/entry/20080510/1210408956><div class="chatlog__markdown chatlog__markdown-preserve">gasのディレクティブについて - suu-g's diary</div></a></div><div class=chatlog__embed-description><div class="chatlog__markdown chatlog__markdown-preserve">アセンブリコードをアセンブルすると機械語になる。こういう説明が世の中じゃされてるけど、でもそれは半分ウソ。アセンブリコードの中でも機械語に直接対応しないものがある。それがディレクティブと呼ばれているもので、ドットから始まる命令がこれにあたる。 疑似命令 (psuedo-ops) とも呼ばれるこのアセンブラディレクティブは、機械語への直接の対応ではなくて、アセンブラ(GNU as)に対する命令。 前回の記事で説明したのはセクションについてだけだったけれども、ディレクティブにはもっといろいろな意味がある。 以下、その具体的な例を挙げていくよ。 文字列を配置する [.ascii .asciz .st…</div></div></div><div class=chatlog__embed-thumbnail-container><a class=chatlog__embed-thumbnail-link href=https://images-ext-2.discordapp.net/external/N8qYrXlufnSaPq0OkN1_xiaq-3oRO0LFWVc_2GER8aM/https/ogimage.blog.st-hatena.com/12704538227038519244/10328749687242444203/1493731778> <img class=chatlog__embed-thumbnail src=https://images-ext-2.discordapp.net/external/N8qYrXlufnSaPq0OkN1_xiaq-3oRO0LFWVc_2GER8aM/https/ogimage.blog.st-hatena.com/12704538227038519244/10328749687242444203/1493731778 alt=Thumbnail loading=lazy> </a></div></div></div></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1077498179282550784 class=chatlog__message-container data-message-id=1077498179282550784><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1077498179282550784>02/21/2023 4:53 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>現在の<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">find_string_literal_end()</code>の実装
<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C">char *find_string_literal_end(char *start) {
char *p;
for (p = start; *p != '\"'; p++) {
if (*p == '\0' || *p == '\n')
error_at(start, "文字列リテラルが閉じていません");
if (*p == '\\')
p++;
}
return p;
}</code></span></div></div></div></div><div id=chatlog__message-container-1077499499863343104 class=chatlog__message-container data-message-id=1077499499863343104><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="02/21/2023 4:58 PM">16:58</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>ちょっと実験
<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C">int main() {
char c = '"'; // => Program returned: 34
return c;
}</code></span></div></div></div></div><div id=chatlog__message-container-1077499605677256804 class=chatlog__message-container data-message-id=1077499605677256804><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="02/21/2023 4:58 PM">16:58</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C">int main() {
char c = '\"'; // => Program returned: 34
return c;
}</code></span></div></div></div></div><div id=chatlog__message-container-1077500101200719893 class=chatlog__message-container data-message-id=1077500101200719893><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="02/21/2023 5:00 PM">17:00</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C">int main() {
// char c = '\'; // => コンパイルエラー (2個目のシングルクオートがエスケープされている)
char c = '\\'; // => Program returned: 92
return c;
}</code></span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1077946228345675887 class=chatlog__message-container data-message-id=1077946228345675887><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1077946228345675887>02/22/2023 10:33 PM</a></span></div><div class=chatlog__attachment><a href="https://cdn.discordapp.com/attachments/1003859454191751178/1077946228060467341/Java-for.png?ex=6554c8a8&is=654253a8&hm=9f45e81e2b40e5d23e8c24e07cec1cfe04f9c1ea1d3b732dd206a2131a70341f&"> <img class=chatlog__attachment-media src="https://cdn.discordapp.com/attachments/1003859454191751178/1077946228060467341/Java-for.png?ex=6554c8a8&is=654253a8&hm=9f45e81e2b40e5d23e8c24e07cec1cfe04f9c1ea1d3b732dd206a2131a70341f&" alt="Image attachment" title="Image: Java-for.png (73.17 KB)" loading=lazy> </a></div></div></div></div><div id=chatlog__message-container-1077946455844728932 class=chatlog__message-container data-message-id=1077946455844728932><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="02/22/2023 10:34 PM">22:34</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--inline">find_string_literal_end()</code>関数は、<strong>for文の更新式は条件判定の前に評価される</strong>ことを上手く利用している</span> <span class=chatlog__edited-timestamp title="02/23/2023 9:46 PM">(edited)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1078297160304574606 class=chatlog__message-container data-message-id=1078297160304574606><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1078297160304574606>02/23/2023 9:47 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>文字列リテラルの実装をとりあえずこうしてみた
<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C"> // 文字列リテラルの場合
if (startswith(p, "\"")) {
char *start = ++p; // ダブルクオートを読み飛ばす
char *end = find_string_literal_end(p);
char *buf = calloc(end - start, sizeof(char));
int len = 0;
#if 1
while (p < end) {
#if 0
// エスケープシーケンスの場合
if (*p == '\\') {
buf[len++] = '\\';
buf[len++] = str_literal_escape_char(p + 1);
p += 2;
}
else {
buf[len++] = *p++;
}
#else
buf[len++] = *p++;
#endif
}
#else
memcpy(buf, start, end - start - 1);
#endif
cur = new_token(TK_STR, cur, buf, buf + len - 1);
p++; // ダブルクオートを読み飛ばす
continue;
}</code></span></div></div></div></div><div id=chatlog__message-container-1078297558671179847 class=chatlog__message-container data-message-id=1078297558671179847><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="02/23/2023 9:49 PM">21:49</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--inline">\a</code>とか<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">\e</code>が動かないのは、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">.string</code>ディレクティブがこれらのエスケープシーケンスに対応していないっぽい</span></div></div></div></div><div id=chatlog__message-container-1078297841086234645 class=chatlog__message-container data-message-id=1078297841086234645><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="02/23/2023 9:50 PM">21:50</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><a href="http://web.mit.edu/gnu/doc/html/as_7.html#SEC120">http://web.mit.edu/gnu/doc/html/as_7.html#SEC120</a>
<div class="chatlog__markdown-quote"><div class="chatlog__markdown-quote-border"></div><div class="chatlog__markdown-quote-content"><strong>.string "str"</strong>
Copy the characters in str to the object file. You may specify more than one string to copy, separated by commas. Unless otherwise specified for a particular machine, the assembler marks the end of each string with a 0 byte. You can use any of the escape sequences described in section <u>Strings</u>.</div></div></span> <span class=chatlog__edited-timestamp title="02/23/2023 9:51 PM">(edited)</span></div></div></div></div><div id=chatlog__message-container-1078298011383386142 class=chatlog__message-container data-message-id=1078298011383386142><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="02/23/2023 9:51 PM">21:51</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>Stringsのsectionを見てみると、</span></div></div></div></div><div id=chatlog__message-container-1078298965738537060 class=chatlog__message-container data-message-id=1078298965738537060><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="02/23/2023 9:55 PM">21:55</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><div class="chatlog__markdown-quote"><div class="chatlog__markdown-quote-border"></div><div class="chatlog__markdown-quote-content"><strong>Strings</strong>
A string is written between double-quotes. It may contain double-quotes or null characters. The way to get special characters into a string is to escape these characters: precede them with a backslash <code class="chatlog__markdown-pre chatlog__markdown-pre--inline">\</code> character. For example <code class="chatlog__markdown-pre chatlog__markdown-pre--inline">\\</code> represents one backslash: the first <code class="chatlog__markdown-pre chatlog__markdown-pre--inline">\</code> is an escape which tells <em>as</em> to interpret the second character literally as a backslash (which prevents <em>as</em> from recognizing the second <code class="chatlog__markdown-pre chatlog__markdown-pre--inline">\</code> as an escape character). The complete list of escapes follows.</div></div></span> <span class=chatlog__edited-timestamp title="02/23/2023 10:23 PM">(edited)</span></div></div></div></div><div id=chatlog__message-container-1078299095065698354 class=chatlog__message-container data-message-id=1078299095065698354><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="02/23/2023 9:55 PM">21:55</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><div class="chatlog__markdown-quote"><div class="chatlog__markdown-quote-border"></div><div class="chatlog__markdown-quote-content"><code class="chatlog__markdown-pre chatlog__markdown-pre--inline">\b</code>
Mnemonic for backspace; for ASCII this is octal code 010.
<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">\f</code>
Mnemonic for FormFeed; for ASCII this is octal code 014.
<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">\n</code>
Mnemonic for newline; for ASCII this is octal code 012.
<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">\r</code>
Mnemonic for carriage-Return; for ASCII this is octal code 015.
<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">\t</code>
Mnemonic for horizontal Tab; for ASCII this is octal code 011.
<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">\ digit digit digit</code>
An octal character code. The numeric code is 3 octal digits. For compatibility with other Unix systems, 8 and 9 are accepted as digits: for example, <code class="chatlog__markdown-pre chatlog__markdown-pre--inline">\008</code> has the value 010, and <code class="chatlog__markdown-pre chatlog__markdown-pre--inline">\009</code> the value 011.
<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">\x hex-digit hex-digit</code>
A hex character code. The numeric code is 2 hexadecimal digits. Either upper or lower case x works.
<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">\\</code>
Represents one <code class="chatlog__markdown-pre chatlog__markdown-pre--inline">\</code> character.
<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">\"</code>
Represents one <code class="chatlog__markdown-pre chatlog__markdown-pre--inline">"</code> character. Needed in strings to represent this character, because an unescaped <code class="chatlog__markdown-pre chatlog__markdown-pre--inline">"</code> would end the string.
<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">\ anything-else</code>
Any other character when escaped by <code class="chatlog__markdown-pre chatlog__markdown-pre--inline">\</code> gives a warning, but assembles as if the <code class="chatlog__markdown-pre chatlog__markdown-pre--inline">\</code> was not present. The idea is that if you used an escape sequence you clearly didn't want the literal interpretation of the following character. However <em>as</em> has no other interpretation, so <em>as</em> knows it is giving you the wrong code and warns you of the fact.
Which characters are escapable, and what those escapes represent, varies widely among assemblers. The current set is what we think the BSD 4.2 assembler recognizes, and is a subset of what most C compilers recognize. If you are in doubt, do not use an escape sequence.</div></div></span> <span class=chatlog__edited-timestamp title="02/23/2023 10:25 PM">(edited)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1078324790634487910 class=chatlog__message-container data-message-id=1078324790634487910><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1078324790634487910>02/23/2023 11:37 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>gccは上記に記載されていないエスケープシーケンスの場合(例えば<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">\a</code>)、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">\007</code>のように8進コードポイントを使って表現している</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1078549028922470491 class=chatlog__message-container data-message-id=1078549028922470491><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1078549028922470491>02/24/2023 2:28 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><a href="https://note.com/ruiu/n/ncacaa6cf8d8f">https://note.com/ruiu/n/ncacaa6cf8d8f</a></span></div><div class=chatlog__embed><div class="chatlog__embed-color-pill chatlog__embed-color-pill--default"></div><div class=chatlog__embed-content-container><div class=chatlog__embed-content><div class=chatlog__embed-text><div class=chatlog__embed-title><a class=chatlog__embed-title-link href=https://note.com/ruiu/n/ncacaa6cf8d8f><div class="chatlog__markdown chatlog__markdown-preserve">コンパイラに仕込まれた細工とシステムのセキュリティの話|Rui Ueyama|note</div></a></div><div class=chatlog__embed-description><div class="chatlog__markdown chatlog__markdown-preserve">コンパイラのソースには書いていないのにバイナリだけで代々伝わっていく情報というのがあって、それはコンピュータのセキュリティに大きく関わっている。ここではそれについて書いてみよう。 僕は8ccというCコンパイラをスクラッチから書いたことがあるのだけど、8ccには文字列を読む部分で、""の後に"n"がきたら"\n"という文字(改行文字)を読んだことにするという箇所がある。これはよく考えてみれば自己言及的になっていて、ソースコードの中に、コンパイラが実際に必要とする改行文字のASCIIコードの情報が含まれていない。しかしコンパイラをコンパイルするコンパイラからその情報が受け継がれるので、</div></div></div><div class=chatlog__embed-thumbnail-container><a class=chatlog__embed-thumbnail-link href=https://images-ext-2.discordapp.net/external/NK6FFNgakmxwTYHxBOO9a2RmHEtJ3EfNQPEmh9cqMaY/%3Ffit%3Dbounds%26format%3Djpeg%26quality%3D85%26width%3D330/https/assets.st-note.com/production/uploads/images/903591/profile_3cbfe950fdd5a01d7eb0be427dc798a5.jpg> <img class=chatlog__embed-thumbnail src=https://images-ext-2.discordapp.net/external/NK6FFNgakmxwTYHxBOO9a2RmHEtJ3EfNQPEmh9cqMaY/%3Ffit%3Dbounds%26format%3Djpeg%26quality%3D85%26width%3D330/https/assets.st-note.com/production/uploads/images/903591/profile_3cbfe950fdd5a01d7eb0be427dc798a5.jpg alt=Thumbnail loading=lazy> </a></div></div></div></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1078551067253542982 class=chatlog__message-container data-message-id=1078551067253542982><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1078551067253542982>02/24/2023 2:36 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>そういえば、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">gen_data_section()</code>のコードを書き換えてたときに、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">printf</code>とか<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">putchar</code>の出力がすぐには表示されなかったが、これは一旦出力がストリームにバッファリングされるのが原因
(必要な場合は<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">fflush</code>関数を用いることで、即座にバッファを吐き出すことができる)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1078576754706358303 class=chatlog__message-container data-message-id=1078576754706358303><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1078576754706358303>02/24/2023 4:18 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>とりあえず、文字列リテラル内のエスケープシーケンスがちゃんと出力されるようになった
<a href="https://github.com/mikiken/9cc/commit/613ade31af9bbad8bfef1d13cbc9dc0ae5f57593">https://github.com/mikiken/9cc/commit/613ade31af9bbad8bfef1d13cbc9dc0ae5f57593</a></span> <span class=chatlog__edited-timestamp title="02/24/2023 4:29 PM">(edited)</span></div><div class=chatlog__embed><div class=chatlog__embed-color-pill style=background-color:rgba(30,35,39,255)></div><div class=chatlog__embed-content-container><div class=chatlog__embed-content><div class=chatlog__embed-text><div class=chatlog__embed-title><a class=chatlog__embed-title-link href=https://github.com/mikiken/9cc/commit/613ade31af9bbad8bfef1d13cbc9dc0ae5f57593><div class="chatlog__markdown chatlog__markdown-preserve">Fix the code for putting escape sequences in <code class="chatlog__markdown-pre chatlog__markdown-pre--inline">.string</code> directive · ...</div></a></div></div><div class=chatlog__embed-thumbnail-container><a class=chatlog__embed-thumbnail-link href=https://images-ext-2.discordapp.net/external/CcUqLKPOeqrjzPatmGlB4wsNFjNhyuYTlp0B1CML45Q/https/opengraph.githubassets.com/fc83e972b7bed95451c7f825871af6dc81e97c9eab34860f1f08728bfb9ce538/mikiken/9cc/commit/613ade31af9bbad8bfef1d13cbc9dc0ae5f57593> <img class=chatlog__embed-thumbnail src=https://images-ext-2.discordapp.net/external/CcUqLKPOeqrjzPatmGlB4wsNFjNhyuYTlp0B1CML45Q/https/opengraph.githubassets.com/fc83e972b7bed95451c7f825871af6dc81e97c9eab34860f1f08728bfb9ce538/mikiken/9cc/commit/613ade31af9bbad8bfef1d13cbc9dc0ae5f57593 alt=Thumbnail loading=lazy> </a></div></div></div></div></div></div></div><div id=chatlog__message-container-1078577254566739998 class=chatlog__message-container data-message-id=1078577254566739998><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="02/24/2023 4:20 PM">16:20</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>かなり横道に逸れたけど、なにをしていたかというと、
<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C">char str[] = "hoge";</code>
みたいな構文を書けるようにしようとしていたはず</span></div></div></div></div><div id=chatlog__message-container-1078578000867635241 class=chatlog__message-container data-message-id=1078578000867635241><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="02/24/2023 4:23 PM">16:23</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C">char *str = "hoge";</code>
とは違って、上記の構文はちゃんとスタック領域に確保されたcharの配列として扱わないとだめ</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1079299713939026020 class=chatlog__message-container data-message-id=1079299713939026020><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1079299713939026020>02/26/2023 4:11 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>実装した
<a href="https://github.com/mikiken/9cc/commit/724a72c7e3d6c6f2f3718832c421713ddacc0973">https://github.com/mikiken/9cc/commit/724a72c7e3d6c6f2f3718832c421713ddacc0973</a></span></div><div class=chatlog__embed><div class=chatlog__embed-color-pill style=background-color:rgba(30,35,39,255)></div><div class=chatlog__embed-content-container><div class=chatlog__embed-content><div class=chatlog__embed-text><div class=chatlog__embed-title><a class=chatlog__embed-title-link href=https://github.com/mikiken/9cc/commit/724a72c7e3d6c6f2f3718832c421713ddacc0973><div class="chatlog__markdown chatlog__markdown-preserve">Implement initialization expressions for string literals · mikiken/...</div></a></div></div><div class=chatlog__embed-thumbnail-container><a class=chatlog__embed-thumbnail-link href=https://images-ext-2.discordapp.net/external/RTIEk3phFR_Z2RRII_FN1xw9uUxNOgzElL15wFJBvww/https/opengraph.githubassets.com/adafd5b427d1b5cfbcee4ef39f7728d20e1909621d73265306de58b2f1a09ce3/mikiken/9cc/commit/724a72c7e3d6c6f2f3718832c421713ddacc0973> <img class=chatlog__embed-thumbnail src=https://images-ext-2.discordapp.net/external/RTIEk3phFR_Z2RRII_FN1xw9uUxNOgzElL15wFJBvww/https/opengraph.githubassets.com/adafd5b427d1b5cfbcee4ef39f7728d20e1909621d73265306de58b2f1a09ce3/mikiken/9cc/commit/724a72c7e3d6c6f2f3718832c421713ddacc0973 alt=Thumbnail loading=lazy> </a></div></div></div></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1079303796376743956 class=chatlog__message-container data-message-id=1079303796376743956><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1079303796376743956>02/26/2023 4:27 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><s>続いてグローバル変数の初期化式を実装していく</s>
<strong>(追記)一旦保留</strong></span> <span class=chatlog__edited-timestamp title="03/03/2023 11:12 PM">(edited)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1079396626398982164 class=chatlog__message-container data-message-id=1079396626398982164><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1079396626398982164>02/26/2023 10:36 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>とりあえず文字列リテラルの初期化式は後回しにして、ただのグローバル変数の初期化式とグローバルの配列の初期化式を実装していく</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1080795511541473340 class=chatlog__message-container data-message-id=1080795511541473340><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1080795511541473340>03/02/2023 7:15 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>ローカル変数の初期化式は、単に宣言の式と代入の式に分解してパースすれば良いだけだったけど、グローバル変数の場合はそうはいかない</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1081045045743976458 class=chatlog__message-container data-message-id=1081045045743976458><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1081045045743976458>03/03/2023 11:47 AM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>例えば、トップレベルに
<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C">int x = 3;</code>
と書いた場合、
<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-wasm">x:
.long 3</code>
とコンパイルしないといけない</span> <span class=chatlog__edited-timestamp title="03/03/2023 11:48 AM">(edited)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1081055095761932407 class=chatlog__message-container data-message-id=1081055095761932407><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1081055095761932407>03/03/2023 12:26 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>現状、
<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">codegen.c</code>
<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C">void gen_data_secton(Obj *gvar_list) {
printf(".data\n");
for (Obj *obj = gvar_list; obj->next != NULL; obj = obj->next) {
// 文字列リテラルの場合
if (obj->init_data)
print_string_literal(obj->str_id, obj->init_data);
// グローバル変数の場合
else {
printf("%s:\n", obj->name);
printf(" .zero %d\n", calc_gvar_size(obj->type));
}
}
printf("\n");
}</code>
となっているので、</span> <span class=chatlog__edited-timestamp title="03/03/2023 12:28 PM">(edited)</span></div></div></div></div><div id=chatlog__message-container-1081055811545088010 class=chatlog__message-container data-message-id=1081055811545088010><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/03/2023 12:29 PM">12:29</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--inline">Obj</code>に<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">init_expr</code>みたいなメンバを追加するのが良さそう
<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C">typedef struct Obj Obj;
struct Obj {
Obj *next; // 次のオブジェクトまたはNULL
Type *type; // 型
int len; // 識別子または文字列リテラルの文字数
// 変数
char *name; // 変数の名前
int offset; // RBPからのオフセット(ローカル変数のときのみ使用)
// 文字列リテラル
char *init_data;
int str_id;
};</code></span> <span class=chatlog__edited-timestamp title="03/03/2023 12:30 PM">(edited)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1081216973129650267 class=chatlog__message-container data-message-id=1081216973129650267><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1081216973129650267>03/03/2023 11:10 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>と思ったけど、めんどくさそうなので、グローバル変数の初期化式は、一旦後回しにしようかな</span></div></div></div></div><div id=chatlog__message-container-1081217261978779658 class=chatlog__message-container data-message-id=1081217261978779658><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/03/2023 11:11 PM">23:11</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>例えば、
<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C">int x = 3 + 2 * 4;</code>
みたいな式もトップレベルに書けるはずだが、これをコンパイルしようとすると、静的解析の時点で値を計算しておかないといけない気がする(?)</span></div></div></div></div><div id=chatlog__message-container-1081217523590111243 class=chatlog__message-container data-message-id=1081217523590111243><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/03/2023 11:12 PM">23:12</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>とりあえず、単に定数を代入する場合のみ書けるようにしてもいいけど、そもそも今の実装でグローバル変数を0以外で初期化してるところってそんなにないと思うから、とりあえず後に回そうという判断</span></div></div></div></div><div id=chatlog__message-container-1081218348597129286 class=chatlog__message-container data-message-id=1081218348597129286><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/03/2023 11:15 PM">23:15</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>現時点での<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">parse.c</code>を保存しておく</span></div></div></div></div><div id=chatlog__message-container-1081218368025145394 class=chatlog__message-container data-message-id=1081218368025145394><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/03/2023 11:15 PM">23:15</div></div><div class=chatlog__message-primary><div class=chatlog__attachment><div class=chatlog__attachment-generic><svg class=chatlog__attachment-generic-icon><use href=#attachment-icon /></svg><div class=chatlog__attachment-generic-name><a href="https://cdn.discordapp.com/attachments/1003859454191751178/1081218367576358993/parse.c?ex=65577592&is=65450092&hm=80290f5b1c63753dd7809469b05a74e1a08990c1954198c45eeb249fbc4a2b8c&"> parse.c </a></div><div class=chatlog__attachment-generic-size>26.75 KB</div></div></div></div></div></div><div id=chatlog__message-container-1081218550766784533 class=chatlog__message-container data-message-id=1081218550766784533><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/03/2023 11:16 PM">23:16</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>ということで、次に実装したいと思ってた多次元配列を実装していく</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1081253835726671923 class=chatlog__message-container data-message-id=1081253835726671923><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1081253835726671923>03/04/2023 1:36 AM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><a href="https://hsjoihs.hatenablog.com/entry/2018/12/17/235557#f-f5c5ed98">https://hsjoihs.hatenablog.com/entry/2018/12/17/235557#f-f5c5ed98</a></span></div><div class=chatlog__embed><div class="chatlog__embed-color-pill chatlog__embed-color-pill--default"></div><div class=chatlog__embed-content-container><div class=chatlog__embed-content><div class=chatlog__embed-text><div class=chatlog__embed-author-container><a class=chatlog__embed-author-link href="https://blog.hatena.ne.jp/hsjoihs/"><div class=chatlog__embed-author>hsjoihs</div></a></div><div class=chatlog__embed-title><a class=chatlog__embed-title-link href=https://hsjoihs.hatenablog.com/entry/2018/12/17/235557><div class="chatlog__markdown chatlog__markdown-preserve">C(のサブセット)コンパイラを書く上でハマった点:配列編 - hsjoihs’s diary</div></a></div><div class=chatlog__embed-description><div class="chatlog__markdown chatlog__markdown-preserve">初めに 「配列編」と銘打っていますが、続編が投稿される保証はありません。 そうそう この記事は言語実装 Advent Calendar 2018とC言語 Advent Calendar 2018の17日目の記事です。 想定している読者層 (どういう読者層を想定しているんだろう、書いていて自分でもよく分からなくなった)(Cコンパイラ書いていて「配列の配列(いわゆる二次元配列)がなんかバグるなぁ」となった人のための記事かもなぁ)(というか、多分バグらせていた当時の自分への手紙) 本題に入ろう Cコンパイラを書く上で微妙にハマった、配列へのポインタの話、それに付随して構造体を実装する際の話について軽…</div></div></div><div class=chatlog__embed-thumbnail-container><a class=chatlog__embed-thumbnail-link href=https://images-ext-2.discordapp.net/external/Iju3bue1DzyfaNefAfRRxt1Oi9lsFear8sWvDR0Ala4/https/ogimage.blog.st-hatena.com/10257846132626756034/10257846132686209724/1545058557> <img class=chatlog__embed-thumbnail src=https://images-ext-2.discordapp.net/external/Iju3bue1DzyfaNefAfRRxt1Oi9lsFear8sWvDR0Ala4/https/ogimage.blog.st-hatena.com/10257846132626756034/10257846132686209724/1545058557 alt=Thumbnail loading=lazy> </a></div></div></div></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1081256341315801098 class=chatlog__message-container data-message-id=1081256341315801098><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1081256341315801098>03/04/2023 1:46 AM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>たぶん<strong>配列全体へのポインタ</strong>さえ実装できれば、割とすぐに実装できそう</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1081601004103016458 class=chatlog__message-container data-message-id=1081601004103016458><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1081601004103016458>03/05/2023 12:36 AM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--inline">int arr[3][5];</code>という宣言に対して、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">arr[2][4]</code>は<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">*(*(arr+2)+4)</code>としてパースすればOK</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1082148337253355561 class=chatlog__message-container data-message-id=1082148337253355561><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1082148337253355561>03/06/2023 12:51 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--inline">parse_type()</code>と<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">declaration()</code>で型のパースを(実質)2回やってるの、設計悪そう</span></div></div></div></div><div id=chatlog__message-container-1082148526366150736 class=chatlog__message-container data-message-id=1082148526366150736><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/06/2023 12:51 PM">12:51</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>識別子だけ保存しといて、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">parse_type()</code>でトークンを読み進めておけばよさそう?</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1082201627131379792 class=chatlog__message-container data-message-id=1082201627131379792><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1082201627131379792>03/06/2023 4:22 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>とりあえず、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">parse_type()</code>を<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">parse_base_type()</code>と<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">parse_variable_type()</code>に分割し、各関数の中でトークンを読み進めるようにした</span></div></div></div></div><div id=chatlog__message-container-1082201718407831582 class=chatlog__message-container data-message-id=1082201718407831582><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/06/2023 4:23 PM">16:23</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--inline">declaration()</code>の中がまだ直せてないので、直す</span> <span class=chatlog__edited-timestamp title="03/06/2023 4:23 PM">(edited)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1082288146051514439 class=chatlog__message-container data-message-id=1082288146051514439><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1082288146051514439>03/06/2023 10:06 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>一旦メモ
<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C"> // 配列の場合
if (dec_type->kind == TYPE_ARRAY) {
while (dec_type->ptr_to) {
// 配列の要素数が明示されている場合
if (dec_type->array_size) {
Node *node = new_lvar_definition(func, dec_type, ident);
skip_token(tok, 4);
// 初期化式がある場合
if (consume(tok, TK_ASSIGN)) {
// 文字列リテラルの初期化式の場合
if (consume_nostep(tok, TK_STR)) {
node = init_str_literal_array(func, dec_type, tok, var_node(func, ident));
next_token(tok);
}
else {
expect(tok, TK_LEFT_BRACE);
node = array_init(func, dec_type, tok, var_node(func, ident));
}
}
return node;
}
// 配列の要素数が明示されていない場合
else {
skip_token(tok, 3);
expect(tok, TK_ASSIGN); // 配列の要素数が明示されていない場合、初期化式が続くはず
Node *node;
Node *array_node = new_node(ND_LVAR);
// 文字列リテラルの初期化式の場合
if (consume_nostep(tok, TK_STR)) {
node = init_str_literal_array(func, dec_type, tok, array_node);
next_token(tok);
}
else {
expect(tok, TK_LEFT_BRACE);
node = array_init(func, dec_type, tok, array_node);
}
(void)new_lvar_definition(func, dec_type, ident);
*array_node = *var_node(func, ident);
return node;
}
}
}</code></span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1082290187578658836 class=chatlog__message-container data-message-id=1082290187578658836><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1082290187578658836>03/06/2023 10:14 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>初期化式が存在するときに配列宣言の要素数を省略できる記法は、難しそうなので、一旦消してから後で復活させるか</span> <span class=chatlog__edited-timestamp title="03/07/2023 1:07 AM">(edited)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1082333901458002012 class=chatlog__message-container data-message-id=1082333901458002012><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1082333901458002012>03/07/2023 1:08 AM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--inline">semantic_analysis.c</code>で、
<div class="chatlog__markdown-quote"><div class="chatlog__markdown-quote-border"></div><div class="chatlog__markdown-quote-content">不正な加算を行うことはできません
</div></div>というエラーが出たので、原因を調べる</span> <span class=chatlog__edited-timestamp title="03/07/2023 1:08 AM">(edited)</span></div></div></div></div><div id=chatlog__message-container-1082334093573898282 class=chatlog__message-container data-message-id=1082334093573898282><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/07/2023 1:09 AM">01:09</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>ここで、配列全体へのポインタを実装する必要が出てくるのだと思われる</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1082667033302413362 class=chatlog__message-container data-message-id=1082667033302413362><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1082667033302413362>03/07/2023 11:12 PM</a></span></div><div class=chatlog__attachment><a href="https://cdn.discordapp.com/attachments/1003859454191751178/1082667033063325847/P_20230307_231121.jpg?ex=6553803f&is=65410b3f&hm=9ea5bb5745abfaa6bce1cf4f010db6fe4a618682224f19de992284dfb77e8ab5&"> <img class=chatlog__attachment-media src="https://cdn.discordapp.com/attachments/1003859454191751178/1082667033063325847/P_20230307_231121.jpg?ex=6553803f&is=65410b3f&hm=9ea5bb5745abfaa6bce1cf4f010db6fe4a618682224f19de992284dfb77e8ab5&" alt="Image attachment" title="Image: P_20230307_231121.jpg (269.34 KB)" loading=lazy> </a></div></div></div></div><div id=chatlog__message-container-1082667858212950016 class=chatlog__message-container data-message-id=1082667858212950016><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/07/2023 11:15 PM">23:15</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><strong><code class="chatlog__markdown-pre chatlog__markdown-pre--inline">int arr[2][3]</code>が<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">int [3]</code>の要素数2の配列型である</strong>ことに注意する必要がある
(直感に反する)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1082670971426713712 class=chatlog__message-container data-message-id=1082670971426713712><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1082670971426713712>03/07/2023 11:27 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>多次元配列のパースの仕方をミスってたので、直す
順方向に伸びるLinked Listとして実装すればOKなはず</span> <span class=chatlog__edited-timestamp title="03/07/2023 11:47 PM">(edited)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1082676141158047784 class=chatlog__message-container data-message-id=1082676141158047784><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1082676141158047784>03/07/2023 11:48 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>直せた</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1082694114505666610 class=chatlog__message-container data-message-id=1082694114505666610><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1082694114505666610>03/08/2023 12:59 AM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>今までは、一次元配列であることを(暗黙に)仮定してたので、
<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C"> case ND_ADD: {
Node *lhs = add_type_to_node(lvar_list, node->lhs);
Node *rhs = add_type_to_node(lvar_list, node->rhs);
// 左辺が配列の場合、ポインタにキャストする
if (is_array_type_node(lhs))
lhs = cast_array_to_pointer(lhs);
// 右辺が配列の場合、ポインタにキャストする
if (is_array_type_node(rhs))
rhs = cast_array_to_pointer(rhs);
// ポインタ同士の加算は禁止されているのでエラーにする
if (lhs->type->kind == TYPE_PTR && rhs->type->kind == TYPE_PTR)
error("ポインタ同士を加算することはできません");
// 左辺がint型、右辺がポインタの場合は両辺を入れ替える
if (lhs->type->kind == TYPE_INT && rhs->type->kind == TYPE_PTR) {
Node *original_lhs = lhs;
lhs = rhs;
rhs = original_lhs;
}
// 左辺がポインタ型、右辺がint型の場合
if (lhs->type->kind == TYPE_PTR && rhs->type->kind == TYPE_INT) {
Node *size = new_size_node(lhs->type->ptr_to->kind);
Node *mul_scaling = new_typed_binary(new_typed_node(new_type(TYPE_INT), new_node(ND_MUL)), size, rhs);
return new_typed_binary(new_typed_node(lhs->type, node), lhs, mul_scaling);
}
// 両辺が算術型の場合
else if (is_arithmeric_type(lhs->type->kind) && is_arithmeric_type(rhs->type->kind)) {
fix_rhs_type(lhs, rhs);
return new_typed_binary(new_typed_node(new_type(TYPE_INT), node), lhs, rhs);
}
else {
error("不正な加算を行うことはできません");
}
}</code></span></div></div></div></div><div id=chatlog__message-container-1082694276577763450 class=chatlog__message-container data-message-id=1082694276577763450><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/08/2023 1:00 AM">01:00</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>の中で、
<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C"> // 左辺がポインタ型、右辺がint型の場合
if (lhs->type->kind == TYPE_PTR && rhs->type->kind == TYPE_INT) {
Node *size = new_size_node(lhs->type->ptr_to->kind);
Node *mul_scaling = new_typed_binary(new_typed_node(new_type(TYPE_INT), new_node(ND_MUL)), size, rhs);
return new_typed_binary(new_typed_node(lhs->type, node), lhs, mul_scaling);
}</code>
のようにキャストすることで、上手くいっていた</span></div></div></div></div><div id=chatlog__message-container-1082694517347581982 class=chatlog__message-container data-message-id=1082694517347581982><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/08/2023 1:01 AM">01:01</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>しかし、多次元配列の場合は、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">lhs->type->ptr_to</code>に<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">int</code>のような基本型が来るとは限らない
実際、二次元配列の場合は、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">lhs->type->ptr_to</code>に<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">TYPE_ARRAY</code>が来ている</span> <span class=chatlog__edited-timestamp title="03/08/2023 1:02 AM">(edited)</span></div></div></div></div><div id=chatlog__message-container-1082695059432034364 class=chatlog__message-container data-message-id=1082695059432034364><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/08/2023 1:03 AM">01:03</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--inline">add_type_to_node</code>を再帰的に呼び出す際に、型情報も、1段深いものを渡す必要がある(?)</span></div></div></div></div><div id=chatlog__message-container-1082696248471081031 class=chatlog__message-container data-message-id=1082696248471081031><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/08/2023 1:08 AM">01:08</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>話が戻るけど、グローバル変数の初期化式、定数をベタ書きする記法だけサポートしておくのはありかもしれない</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1082854606033391726 class=chatlog__message-container data-message-id=1082854606033391726><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1082854606033391726>03/08/2023 11:37 AM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>やっていき</span></div></div></div></div><div id=chatlog__message-container-1082855209786675270 class=chatlog__message-container data-message-id=1082855209786675270><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/08/2023 11:40 AM">11:40</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--inline">int arr[2][3]</code>という宣言があったとして、
<div class="chatlog__markdown-quote"><div class="chatlog__markdown-quote-border"></div><div class="chatlog__markdown-quote-content">1回目の間接参照では、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">ND_DEREF</code>の型は<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">int [3]</code>であるべきであり、
2回目の間接参照では、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">ND_DEREF</code>の型は<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">int</code>であるべきである
</div></div>ってことになるはず</span> <span class=chatlog__edited-timestamp title="03/08/2023 11:40 AM">(edited)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1082955591124783185 class=chatlog__message-container data-message-id=1082955591124783185><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1082955591124783185>03/08/2023 6:18 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><a href="https://natsutan.hatenablog.com/entry/2022/11/10/100813">https://natsutan.hatenablog.com/entry/2022/11/10/100813</a></span></div><div class=chatlog__embed><div class="chatlog__embed-color-pill chatlog__embed-color-pill--default"></div><div class=chatlog__embed-content-container><div class=chatlog__embed-content><div class=chatlog__embed-text><div class=chatlog__embed-author-container><a class=chatlog__embed-author-link href="https://blog.hatena.ne.jp/natsutan/"><div class=chatlog__embed-author>natsutan</div></a></div><div class=chatlog__embed-title><a class=chatlog__embed-title-link href=https://natsutan.hatenablog.com/entry/2022/11/10/100813><div class="chatlog__markdown chatlog__markdown-preserve">低レイヤを知りたい人のためのCコンパイラ作成入門の多次元配列 - ぱたへね</div></a></div><div class=chatlog__embed-description><div class="chatlog__markdown chatlog__markdown-preserve">低レイヤを知りたい人のためのCコンパイラ作成入門を、Rustでコツコツとやっている。 www.sigbus.info 今まで苦労しながらもgithubのソースを見ながらまっすぐに来れたが、二次元配列の所で躓いたので整理してみた。 動かしたいソース まだここまでは動かないけど、やりたいことはこのCソースの演算部分を動かす事。二次元配列の宣言と、ポインターへの変換、デリファレンス。 流石にCの動きが分からないと言うことはないが、ちゃんと動くアセンブラを自力で出力するのには難しい。 #include int main() { int x [2][3]; int *y = x; i…</div></div></div><div class=chatlog__embed-thumbnail-container><a class=chatlog__embed-thumbnail-link href=https://images-ext-2.discordapp.net/external/CP7WmgjWy-Evcz1cAMmsnE4JQBByod4Iwdi3NWaRkyA/https/cdn-ak.f.st-hatena.com/images/fotolife/n/natsutan/20221110/20221110002823.png> <img class=chatlog__embed-thumbnail src=https://images-ext-2.discordapp.net/external/CP7WmgjWy-Evcz1cAMmsnE4JQBByod4Iwdi3NWaRkyA/https/cdn-ak.f.st-hatena.com/images/fotolife/n/natsutan/20221110/20221110002823.png alt=Thumbnail loading=lazy> </a></div></div></div></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1082958066808537118 class=chatlog__message-container data-message-id=1082958066808537118><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1082958066808537118>03/08/2023 6:28 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--inline">int x[2][3];</code>という宣言に対して、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">int (*x_ptr)[3] = &x[2]</code>みたいなコードも動かないといけないはず(要検証)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1082960301932163092 class=chatlog__message-container data-message-id=1082960301932163092><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1082960301932163092>03/08/2023 6:37 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>とりあえず、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">add_type_to_node</code>の<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">ND_DEREF</code>で<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">lhs</code>の型を見て、その型が配列型である場合は、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">ptr_to</code>に入っている型情報を与えた上で、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">add_type_to_node</code>を再度呼び出せばOKそう?</span> <span class=chatlog__edited-timestamp title="03/08/2023 6:38 PM">(edited)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1083912058900332646 class=chatlog__message-container data-message-id=1083912058900332646><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1083912058900332646>03/11/2023 9:39 AM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><strong>数日経過</strong></span></div></div></div></div><div id=chatlog__message-container-1083912248227020820 class=chatlog__message-container data-message-id=1083912248227020820><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/11/2023 9:40 AM">09:40</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>そもそも、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">add_type_to_node</code>がデカすぎる説はあるな</span></div></div></div></div><div id=chatlog__message-container-1083912936277409913 class=chatlog__message-container data-message-id=1083912936277409913><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/11/2023 9:43 AM">09:43</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>この関数は、ただ機械的に型をつけるだけにして、その上で、後から型を修正したり、ポインタ演算用にnodeを追加した方が見通し良さそう</span> <span class=chatlog__edited-timestamp title="03/11/2023 10:11 AM">(edited)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1083919964077047832 class=chatlog__message-container data-message-id=1083919964077047832><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1083919964077047832>03/11/2023 10:10 AM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C">// ND_DEREFで間接参照を行った場合、そのnodeの以下の型はnode->type->ptr_toとなるので、型を付け直す
Node *fix_node_type_to_ptr_to(Node *node, Type *node_type) {
switch (node->kind) {
case ND_DEREF:
node->type = node_type->ptr_to;
return node;
default:
return node;
}
}</code></span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1084143832687456356 class=chatlog__message-container data-message-id=1084143832687456356><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1084143832687456356>03/12/2023 1:00 AM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>テンプレを書いた
<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C">Node *add_type_to_node(Node *node) {
switch (node->kind) {
case ND_STMT:
return;
case ND_EXPR:
return;
case ND_COMMA:
return;
case ND_ADD:
return;
case ND_SUB:
return;
case ND_MUL:
return;
case ND_DIV:
return;
case ND_MOD:
return;
case ND_EQ:
return;
case ND_NE:
return;
case ND_LT:
return;
case ND_LE:
return;
case ND_NOT:
return;
case ND_AND:
return;
case ND_OR:
return;
case ND_COND:
return;
case ND_ASSIGN:
return;
case ND_NUM:
return;
case ND_STR:
return;
case ND_LVARDEF:
return;
case ND_LVAR:
return;
case ND_GVAR:
return;
case ND_RETURN:
return;
case ND_IF:
return;
case ND_FOR:
return;
case ND_FUNCALL:
return;
case ND_ADDR:
return;
case ND_DEREF:
return;
case ND_SIZEOF:
return;
}
}</code></span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1084457343963643945 class=chatlog__message-container data-message-id=1084457343963643945><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1084457343963643945>03/12/2023 9:46 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>(作り直し中の)<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">add_type_to_node</code>に<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">ND_GVAR</code>があるが、これはあくまで関数のスコープの中でグローバル変数を読んだ場合であって、トップレベルにグローバル変数に宣言を書いた場合ではない</span></div></div></div></div><div id=chatlog__message-container-1084457441623822346 class=chatlog__message-container data-message-id=1084457441623822346><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/12/2023 9:46 PM">21:46</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>(そもそもグローバル変数の初期化式を実装していない以上、それはそう)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1086191582094565396 class=chatlog__message-container data-message-id=1086191582094565396><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1086191582094565396>03/17/2023 4:37 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><strong>さらに数日経過</strong></span></div></div></div></div><div id=chatlog__message-container-1086191779902136351 class=chatlog__message-container data-message-id=1086191779902136351><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/17/2023 4:38 PM">16:38</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>とりあえず、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">add_type_to_node</code>では機械的に型を付けるだけにした</span></div></div></div></div><div id=chatlog__message-container-1086192063940399115 class=chatlog__message-container data-message-id=1086192063940399115><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/17/2023 4:39 PM">16:39</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>配列をその先頭要素へのポインタにキャストする処理や、ポインタの加算減算で、オフセットを<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">sizeof(lhs->type->ptr_to)</code>倍する処理は、別の関数で行うことにした</span></div></div></div></div><div id=chatlog__message-container-1086192573493809272 class=chatlog__message-container data-message-id=1086192573493809272><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/17/2023 4:41 PM">16:41</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>なんか、改めて意味解析の処理を見返すと、型の扱い方合ってる?って思う箇所があるけど、とりあえず気にせずに分割していく</span> <span class=chatlog__edited-timestamp title="03/22/2023 4:44 PM">(edited)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1088005564572913714 class=chatlog__message-container data-message-id=1088005564572913714><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1088005564572913714>03/22/2023 4:45 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>とりあえず関数を分割したが、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">semantic_analysis() : 代入式の両辺の型が異なります</code>が出るな</span></div></div></div></div><div id=chatlog__message-container-1088006142648660018 class=chatlog__message-container data-message-id=1088006142648660018><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/22/2023 4:47 PM">16:47</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>どこでエラーが出てるかというと、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">test/array.c</code>の<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">array_test1</code>の代入式<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">*p=1</code>の部分</span> <span class=chatlog__edited-timestamp title="03/22/2023 4:49 PM">(edited)</span></div></div></div></div><div id=chatlog__message-container-1088006480957030440 class=chatlog__message-container data-message-id=1088006480957030440><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/22/2023 4:49 PM">16:49</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C">int array_test1() {
int a[2];
int *p;
p = a;
*p = 1;
*(p + 1) = 2;
return *p + *(p + 1);
}</code></span></div></div></div></div><div id=chatlog__message-container-1088006911372312629 class=chatlog__message-container data-message-id=1088006911372312629><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/22/2023 4:51 PM">16:51</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--inline">ND_DEREF</code>自体の型は、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">lhs->type->ptr_to</code>にしないといけないのに、そうなってなかったので修正した</span> <span class=chatlog__edited-timestamp title="03/22/2023 5:18 PM">(edited)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1088015199136645140 class=chatlog__message-container data-message-id=1088015199136645140><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1088015199136645140>03/22/2023 5:23 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>それはそうとして、大量の<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">Segmentation fault</code>と<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">semantic_analysis() : 代入式の両辺の型が異なります</code>が出ているのが気になる</span></div></div></div></div><div id=chatlog__message-container-1088015300743675974 class=chatlog__message-container data-message-id=1088015300743675974><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/22/2023 5:24 PM">17:24</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--inline">arith.c</code>ですらセグフォしてるので原因を調査する</span></div></div></div></div><div id=chatlog__message-container-1088016597240778784 class=chatlog__message-container data-message-id=1088016597240778784><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/22/2023 5:29 PM">17:29</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--inline">codegen.c</code>で関数呼び出しの引数の型を参照しようとしたところ、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">ND_FUNCALL</code>の<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">body->type</code>に型情報が入っておらずエラーになっているらしい</span></div></div></div></div><div id=chatlog__message-container-1088017302424928296 class=chatlog__message-container data-message-id=1088017302424928296><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/22/2023 5:32 PM">17:32</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--inline">semantic_analysis()</code>を確認したところ、普通に<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">case ND_FUNCALL:</code>の実装忘れてたわ<img
loading="lazy"
class="chatlog__emoji "
alt="😇"
title="innocent"
src="https://cdn.jsdelivr.net/gh/twitter/twemoji@latest/assets/svg/1f607.svg"></span> <span class=chatlog__edited-timestamp title="03/22/2023 5:32 PM">(edited)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1088022370322763806 class=chatlog__message-container data-message-id=1088022370322763806><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1088022370322763806>03/22/2023 5:52 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>実装した</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1088025815532441650 class=chatlog__message-container data-message-id=1088025815532441650><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1088025815532441650>03/22/2023 6:06 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--inline">arith.c</code>を9ccでコンパイルすると、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline"> assert(21, 5 + 20 - 4, "5 + 20 - 4");</code>のテストケースでコケてる</span></div></div></div></div><div id=chatlog__message-container-1088026168944513095 class=chatlog__message-container data-message-id=1088026168944513095><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/22/2023 6:07 PM">18:07</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>そもそも<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">ND_NUM</code>に型情報が入っていないっぽい</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1088457854651998311 class=chatlog__message-container data-message-id=1088457854651998311><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1088457854651998311>03/23/2023 10:42 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--inline">add_type_to_node</code>と<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">semantic_analysis</code>で、for文で<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">arg->body</code>に対して処理を行うべきところが<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">arg</code>に対して処理を行ってたのが原因</span></div></div></div></div><div id=chatlog__message-container-1088457953411084379 class=chatlog__message-container data-message-id=1088457953411084379><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/23/2023 10:43 PM">22:43</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>これで、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">arith.c</code>のコンパイルは通るようになった</span></div></div></div></div><div id=chatlog__message-container-1088458032637300887 class=chatlog__message-container data-message-id=1088458032637300887><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/23/2023 10:43 PM">22:43</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>次に、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">array.c</code>のコンパイルを試みると、やはりセグフォ</span></div></div></div></div><div id=chatlog__message-container-1088459132312502282 class=chatlog__message-container data-message-id=1088459132312502282><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/23/2023 10:47 PM">22:47</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>やはり同じところでセグフォしてるな
<a href="https://discord.com/channels/1002995356033896448/1003859454191751178/1088006142648660018" onclick="scrollToMessage(event, '1088006142648660018')">https://discord.com/channels/1002995356033896448/1003859454191751178/1088006142648660018</a></span></div></div></div></div><div id=chatlog__message-container-1088459392309002313 class=chatlog__message-container data-message-id=1088459392309002313><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/23/2023 10:49 PM">22:49</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>とりあえず、代入式に型情報が入っていないことが分かる</span></div></div></div></div><div id=chatlog__message-container-1088460502818095135 class=chatlog__message-container data-message-id=1088460502818095135><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/23/2023 10:53 PM">22:53</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>確かに<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">semantic_analysis()</code>の<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">ND_ASSIGN</code>のところを見ると、node自体の型を指定し忘れてるな</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1088658640019398666 class=chatlog__message-container data-message-id=1088658640019398666><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1088658640019398666>03/24/2023 12:00 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>左辺の型に合わせるようにした</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1088664901448376441 class=chatlog__message-container data-message-id=1088664901448376441><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1088664901448376441>03/24/2023 12:25 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>なんか<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">codegen.c</code>でメモリ上の値をレジスタにセットしようとしたときに配列型が登場してエラーになってる</span></div></div></div></div><div id=chatlog__message-container-1088664942200225862 class=chatlog__message-container data-message-id=1088664942200225862><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/24/2023 12:25 PM">12:25</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>どのテストケースでコケてるんだろ</span> <span class=chatlog__edited-timestamp title="03/24/2023 12:25 PM">(edited)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1088713326302855168 class=chatlog__message-container data-message-id=1088713326302855168><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1088713326302855168>03/24/2023 3:38 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>構文木はこんな感じ</span></div></div></div></div><div id=chatlog__message-container-1088713367830671400 class=chatlog__message-container data-message-id=1088713367830671400><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/24/2023 3:38 PM">15:38</div></div><div class=chatlog__message-primary><div class=chatlog__attachment><a href="https://cdn.discordapp.com/attachments/1003859454191751178/1088713367486734367/P_20230324_153750.jpg?ex=65570a56&is=65449556&hm=23cdac0e45910416160d6be8ca8b598ca15003a62876030be9c9ad994570d529&"> <img class=chatlog__attachment-media src="https://cdn.discordapp.com/attachments/1003859454191751178/1088713367486734367/P_20230324_153750.jpg?ex=65570a56&is=65449556&hm=23cdac0e45910416160d6be8ca8b598ca15003a62876030be9c9ad994570d529&" alt="Image attachment" title="Image: P_20230324_153750.jpg (584.29 KB)" loading=lazy> </a></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1088719623207272458 class=chatlog__message-container data-message-id=1088719623207272458><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1088719623207272458>03/24/2023 4:03 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><s>該当するテストケース無くね?</s>
(追記) callstackを確認したら<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">array_test13()</code>でコケてることが判明</span> <span class=chatlog__edited-timestamp title="03/26/2023 4:37 PM">(edited)</span></div></div></div></div><div id=chatlog__message-container-1088720601411227659 class=chatlog__message-container data-message-id=1088720601411227659><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/24/2023 4:06 PM">16:06</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--inline">parse.c</code>は特に触ってないから、意味解析のところで構文木を構築するのをミスってそう</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1089446715951689748 class=chatlog__message-container data-message-id=1089446715951689748><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1089446715951689748>03/26/2023 4:12 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>現時点で
<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline nohighlight">arith.c
array.c
control_statement.c
function.c
string.c
test.c
variable.c</code>
はコンパイル可能</span> <span class=chatlog__edited-timestamp title="03/26/2023 5:03 PM">(edited)</span></div></div></div></div><div id=chatlog__message-container-1089446783991693393 class=chatlog__message-container data-message-id=1089446783991693393><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/26/2023 4:12 PM">16:12</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>一方で、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">pointer.c</code>はコンパイルエラーになる</span> <span class=chatlog__edited-timestamp title="03/26/2023 5:03 PM">(edited)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1089453250660540506 class=chatlog__message-container data-message-id=1089453250660540506><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__reply-symbol></div><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__reply><img class=chatlog__reply-avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy><div class=chatlog__reply-author title=mikiken>mikiken</div><div class=chatlog__reply-content><span class=chatlog__reply-link onclick="scrollToMessage(event,'1088719623207272458')"> <s>該当するテストケース無くね?</s>
(追記) callstackを確認したら<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">array_test13()</code>でコケてることが判明 </span> <span class=chatlog__reply-edited-timestamp title="03/26/2023 4:37 PM">(edited)</span></div></div><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1089453250660540506>03/26/2023 4:38 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>VSCodeのgdb拡張(?)、めっちゃ便利</span> <span class=chatlog__edited-timestamp title="03/31/2023 4:11 PM">(edited)</span></div><div class=chatlog__attachment><a href="https://cdn.discordapp.com/attachments/1003859454191751178/1089453250484371526/image.png?ex=6559bb67&is=65474667&hm=7eb685fe9f95c39107a67c88f1fa3d09de6c23e6ff18088a5c280446109f7d7d&"> <img class=chatlog__attachment-media src="https://cdn.discordapp.com/attachments/1003859454191751178/1089453250484371526/image.png?ex=6559bb67&is=65474667&hm=7eb685fe9f95c39107a67c88f1fa3d09de6c23e6ff18088a5c280446109f7d7d&" alt="Image attachment" title="Image: image.png (12.93 KB)" loading=lazy> </a></div></div></div></div><div id=chatlog__message-container-1089453518768848979 class=chatlog__message-container data-message-id=1089453518768848979><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/26/2023 4:39 PM">16:39</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C">int array_test13() {
int a[5] = {1, 2, 3, 4, 5};
int sum = 0;
for (int i = 0; i < 5; i++)
sum += a[i];
return sum;
}</code></span></div></div></div></div><div id=chatlog__message-container-1089454289660944476 class=chatlog__message-container data-message-id=1089454289660944476><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/26/2023 4:42 PM">16:42</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>この関数の<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">sum += a[i]</code>のところで型の不一致が起きてる</span></div></div></div></div><div id=chatlog__message-container-1089455233073168404 class=chatlog__message-container data-message-id=1089455233073168404><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/26/2023 4:46 PM">16:46</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>右辺の配列<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">a</code>がポインタにキャストされてないのが原因っぽい</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1089457532432564244 class=chatlog__message-container data-message-id=1089457532432564244><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1089457532432564244>03/26/2023 4:55 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--inline">semantic_analysis()</code>で<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">ND_FOR</code>の<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">node->then</code>の構文木の意味解析をし忘れてるのが原因</span></div></div></div></div><div id=chatlog__message-container-1089459102700290148 class=chatlog__message-container data-message-id=1089459102700290148><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/26/2023 5:01 PM">17:01</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C"> case ND_FOR:
if (node->init)
semantic_analysis(node->init);
if (node->cond)
semantic_analysis(node->cond);
// for文の中身の処理
semantic_analysis(node->then);
if (node->inc)
semantic_analysis(node->inc);
// node自体の型はNULLのはず
if (node->type->kind == TYPE_NULL)
return;
else
error("semantic_analysis() : if文の意味解析を行うことができませんでした");</code></span></div></div></div></div><div id=chatlog__message-container-1089459195750920203 class=chatlog__message-container data-message-id=1089459195750920203><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/26/2023 5:01 PM">17:01</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>真ん中に1行追加したら<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">array.c</code>のコンパイルが通るようになった</span> <span class=chatlog__edited-timestamp title="03/26/2023 5:02 PM">(edited)</span></div></div></div></div><div id=chatlog__message-container-1089460180518969354 class=chatlog__message-container data-message-id=1089460180518969354><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/26/2023 5:05 PM">17:05</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>あと<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">pointer.c</code>を通せば、移植完了しそう</span></div></div></div></div><div id=chatlog__message-container-1089460272172892171 class=chatlog__message-container data-message-id=1089460272172892171><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/26/2023 5:06 PM">17:06</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--inline">pointer.c</code>の<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">pointer_test12()</code>でコケてる</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1089466893913555035 class=chatlog__message-container data-message-id=1089466893913555035><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1089466893913555035>03/26/2023 5:32 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C">int pointer_test12() {
int a[2];
int k;
k = &a[1] - &a[0];
return k;
}</code></span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1089474852290842625 class=chatlog__message-container data-message-id=1089474852290842625><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1089474852290842625>03/26/2023 6:04 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--inline">ND_SUB</code>でポインタ同士の引き算をいい感じに意味解析するところのコード
<code class="chatlog__markdown-pre chatlog__markdown-pre--multiline language-C"> // 両辺がポインタ型の場合
else if (is_ptr_type(node->lhs->type) && is_ptr_type(node->rhs->type)) {
if (node->lhs->type->ptr_to->kind != node->rhs->type->ptr_to->kind)
error("semantic_analysis() : 異なる型へのポインタ同士で減算を行うことはできません");
Node *size = new_size_node(node->lhs->type->ptr_to);
Node *diff_addr = new_typed_binary(new_typed_node(node->lhs->type, new_node(ND_SUB)), node->lhs, node->rhs);
*node = *new_typed_binary(new_typed_node(new_type(TYPE_INT), new_node(ND_DIV)), diff_addr, size);
return;
}</code></span> <span class=chatlog__edited-timestamp title="03/26/2023 6:04 PM">(edited)</span></div></div></div></div><div id=chatlog__message-container-1089475042192134224 class=chatlog__message-container data-message-id=1089475042192134224><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/26/2023 6:04 PM">18:04</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--inline">node = new_typed_binary(~);</code>となっていたが、これでは<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">ND_ASSIGN</code>の<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">node->rhs</code>の参照先は古い構文木のままになってしまう。そこで、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">*node = *new_typed_binary(~);</code>として、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">Node *node</code>の参照先自体を新しい構文木に書き換える必要がある。</span> <span class=chatlog__edited-timestamp title="03/26/2023 6:06 PM">(edited)</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1090120404418437120 class=chatlog__message-container data-message-id=1090120404418437120><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1090120404418437120>03/28/2023 12:49 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>これで、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">pointer.c</code>のコンパイルも通るようになった</span></div></div></div></div><div id=chatlog__message-container-1090120818526265445 class=chatlog__message-container data-message-id=1090120818526265445><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/28/2023 12:50 PM">12:50</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--inline">make test</code>すると、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">string.c</code>でエラーが出るな</span></div></div></div></div><div id=chatlog__message-container-1090120859911462945 class=chatlog__message-container data-message-id=1090120859911462945><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/28/2023 12:51 PM">12:51</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve><code class="chatlog__markdown-pre chatlog__markdown-pre--multiline nohighlight">[FAIL] {char x[3]; x[0] = -1; x[1] = 2; int y; y = 4; return x[0] + y;} => 3 expected, but got -253</code></span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1090122840952537170 class=chatlog__message-container data-message-id=1090122840952537170><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1090122840952537170>03/28/2023 12:58 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>gdbで<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">char_type_test1()</code>からreturnした直後のraxの値を観察すると何か分かりそう</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1090243350906548314 class=chatlog__message-container data-message-id=1090243350906548314><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1090243350906548314>03/28/2023 8:57 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>gdbで調べた感じこんな感じっぽい</span></div><div class=chatlog__attachment><div class=chatlog__attachment-generic><svg class=chatlog__attachment-generic-icon><use href=#attachment-icon /></svg><div class=chatlog__attachment-generic-name><a href="https://cdn.discordapp.com/attachments/1003859454191751178/1090243350633914368/message.txt?ex=655360be&is=6540ebbe&hm=00ba2ddc5e746159b3b05af5c5de78aa86e0562613b198f45e88236cc5eb7ca0&"> message.txt </a></div><div class=chatlog__attachment-generic-size>6.41 KB</div></div></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1091257481675685899 class=chatlog__message-container data-message-id=1091257481675685899><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1091257481675685899>03/31/2023 4:07 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>たぶん元々raxのビットがすべて立ってる状態<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">0xffffffff</code>から、raxの下位1byteのみ書き換えられた結果、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">0xffffff03</code>というビットパターンになった</span> <span class=chatlog__edited-timestamp title="03/31/2023 4:08 PM">(edited)</span></div></div></div></div><div id=chatlog__message-container-1091257863172792321 class=chatlog__message-container data-message-id=1091257863172792321><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/31/2023 4:09 PM">16:09</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>なので<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">rax</code>のビットパターンの下位1byteのみを読むと、ちゃんと<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">3</code>という値になる</span></div></div></div></div><div id=chatlog__message-container-1091258133374042132 class=chatlog__message-container data-message-id=1091258133374042132><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/31/2023 4:10 PM">16:10</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>一方で、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">rax</code>のビットパターンを<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">(signed) int</code>として読むと、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">0xff03</code>となるので、<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">-253</code>という値になる</span></div></div></div></div><div id=chatlog__message-container-1091258166165110794 class=chatlog__message-container data-message-id=1091258166165110794><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/31/2023 4:10 PM">16:10</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>ってことだと思う</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1091276501883813888 class=chatlog__message-container data-message-id=1091276501883813888><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1091276501883813888>03/31/2023 5:23 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>とりあえず、古い実装が吐くアセンブリと新しい実装が吐くアセンブリの差分を取ってみた</span></div></div></div></div><div id=chatlog__message-container-1091276871993413773 class=chatlog__message-container data-message-id=1091276871993413773><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/31/2023 5:24 PM">17:24</div></div><div class=chatlog__message-primary><div class=chatlog__attachment><div class=chatlog__attachment-generic><svg class=chatlog__attachment-generic-icon><use href=#attachment-icon /></svg><div class=chatlog__attachment-generic-name><a href="https://cdn.discordapp.com/attachments/1003859454191751178/1091276871473311754/message.txt?ex=65572349&is=6544ae49&hm=7089f0c8489db1756489ff18822e9a82f6de33d36dd5040b8869054eaa37b1cd&"> message.txt </a></div><div class=chatlog__attachment-generic-size>8.9 KB</div></div></div></div></div></div><div id=chatlog__message-container-1091278185150296074 class=chatlog__message-container data-message-id=1091278185150296074><div class=chatlog__message><div class=chatlog__message-aside><div class=chatlog__short-timestamp title="03/31/2023 5:29 PM">17:29</div></div><div class=chatlog__message-primary><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>少なくとも、表面的に出力されるアセンブリを比較すると、古い方ではきちんと<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">rdi</code>の下位1byteを読んでいる一方、新しい方では<code class="chatlog__markdown-pre chatlog__markdown-pre--inline">rdi</code>の下位4byteを読んでしまっていることが分かる</span></div></div></div></div></div>
<div class=chatlog__message-group><div id=chatlog__message-container-1091290357901316226 class=chatlog__message-container data-message-id=1091290357901316226><div class=chatlog__message><div class=chatlog__message-aside><img class=chatlog__avatar src="https://cdn.discordapp.com/avatars/986457461722599425/4960b153bbadabdb9d46b99107442482.png?size=512" alt=Avatar loading=lazy></div><div class=chatlog__message-primary><div class=chatlog__header><span class=chatlog__author title=mikiken data-user-id=986457461722599425>mikiken</span> <span class=chatlog__timestamp><a href=#chatlog__message-container-1091290357901316226>03/31/2023 6:18 PM</a></span></div><div class="chatlog__content chatlog__markdown"><span class=chatlog__markdown-preserve>テストケースがデカいので、バグが再現するもう少し小さいテストケースを考える