ときどきの雑記帖 RE* (新南口)
アクティブ・ハート
無糖
「キリン 午後の紅茶 おいしい無糖 ミルクティー」、3月7日より発売 | マイナビニュース
お、これはよさげ。 こんなのが欲しかった。
やる気スイッチ
やる気スイッチを押せる位置の店舗と押せない位置の店舗がある :: デイリーポータルZ
家の近く(の塾)にもあったなあ「やる気スイッチ」。 まだあるのかな?
glibc-2.37: The GNU C Library is the standard C library of the GNU system. It defines the system calls and other basic functionality necessary to write programs in the C language. It handles low-level functionality that communicates with the kernel, such as process and file management, as well as higher-level functionality such as string manipulation or command-line argument handling.
mes-0.24.2: GNU Mes aims to help create full source bootstrapping for GNU/Linux systems such as Guix System. It features a mutual self-hosting Scheme interpreter written in a simple C, and a Nyacc-based C compiler written in GNU Guile-compatible Scheme. The Mes C library supports bootstrapping gcc.
36
NESFab
スゴイ。ファミコンのゲームを新たに開発するために8bitの限界を念頭において設計した新しいプログラミング言語、NESfab。C言語よりも高速なマシン語を出力するとしている。さらにバンク切替もコンパイラが担当し、assetのloadingも抽象化されている。 https://t.co/23EGDQXHVE
— 高梨陣平 (@jingbay) March 7, 2023
8ビット、それも6502とCとの相性は良いとは思えないので 「Cより速いコード」を出力云々はあまり売りにはならんだろうってのと、 この人のことだからまた元記事をよく読まないで適当なこと言ってるのでは… と思ってサイトを読み直すと
NESFab is a new programming language for creating NES games. Designed with 8-bit limitations in mind, the language is more ergonomic to use than C, while also producing faster assembly code. It’s easy to get started with, and has a useful set of libraries for making your first — or hundredth — NES game.
NESFab generates better 6502 machine code than any high-level compiler tested, including GCC and LLVM. It’s possible that NESFab is the best performing 6502 compiler in existence.
みたいなことが書かれているし、Cコンパイラーの出力との性能比較やってるのね。
HNの方でも
This is a long-running personal project I’ve had to write an optimizing compiler from scratch. Everything was done by me, including the lexer/parser, SSA-based IR, high-performance data structures, and code generator.
Originally I wasn’t targeting the NES. It started as a scripting language, then it morphed into a C++ replacement, and then finally I turned it into what it is today. The large scope of the project and colorful history means it’s still a little rough around the edges, but it’s now working well enough to post.
とかある(このほかのコメントのやり取りも結構面白い)。
サンプルコードは
// This small program plays a sound effect.
// Variables:
vars /sound
UU pitch = 1000
// Sends 'pitch' variable to the APU, emitting sound:
fn play_sound()
{$4015}(%100)
{$4008}($FF)
{$400A}(pitch.a)
{$400B}(pitch.b & %111)
mode main()
{$2000}(%10000000)
while true
pitch *= 1.01
play_sound()
nmi
というのがあって、ぱっと見でもなかなかに特徴的 (Pythonと同じようにインデントでブロックを表現する)。
「面白い」のはそこかしこにあって全部あげるのは大変なのでいくつかに絞るけど、 たとえば
3.2. Operators
- The operators &, |, and ^ have a higher precedence than in C.
- Combined-assignment operators, like += or <⇐, return a value of type Bool, representing the carry.
- Division is unsupported.
- Array operators ([] and {}) are split into 8-bit and 16-bit versions, with the 8-bit versions having better performance.
- Types are not implicitly promoted. Different operators have different rules for how differing types are handled.
演算子に「除算」がない。とか
数値型に
Type | Size (bytes) | Value range |
---|---|---|
Int | 4 | [-2147483648, 2147483647] |
Real | 7 | [-$80000000.000000, $7FFFFFFF.FFFFFF] |
というのがある一方で (7バイトの実数型って、これ固定小数点数?)
17.1.1. Integer Types
Unsigned integer types are expressed using the character U, while signed integer types use S. The values of signed integers are expressed in two’s complement form.
The 6 integer types are listed below.
Type Size (bytes) Value range U 1 [0, 255] S 1 [-128, 127] UU 2 [0, 65535] SS 2 [-32768, 32767] UUU 3 [0, 16777215] SSS 3 [-8388608, 8388607]
17.1.2. Unit-Fractional Types
Type Size (bytes) Value range F 1 [$0.00, $0.FF] FF 2 [$0.0000, $0.FFFF] FFF 3 [$0.000000, $0.FFFFFF]
17.1.3. Fixed-point Types
An integer type and a unit-fractional type can be combined to form a fixed-point type, merging the ranges of both. The syntax is the integer type, followed by the unit-fractional type, without no other characters in-between.
There are 18 possible fixed-point types, but only 3 are listed below. The rest can be inferred from the tables above.
Type Size (bytes) Value range UF 1 [$00.00, $FF.FF] SSF 3 [-$8000.00, $7FFF.FF] UFFF 4 [$00.000000, $FF.FFFFFF]
といったものある。
Dragon
dancing link
メモ。
- Knuth’s doubly linked list “dancing links” in Go. This code also illustrates pointerless linked data structures, which are almost invisible to Go’s garbage collector : programming
- BUGFIX-66
- Knuth’s “dancing links” paper:
The same technique also appears in the new Volume 4B of The Art of Computer Programming.
- Another backtrack programming technique from Volume 4B is illustrated here:
- パラメトロン計算機: dancing links
- farhiongit/dancing-links: A user friendly implementation of Knuth’s dancing links algorithm for exact cover search.
- littleredcomputer/dancinglinks: Knuth’s Dancing Links algorithm in Java
- ポリオミノの敷き詰め問題をDancing LinksとKnuth’s Algorithm Xを使って解く - matsu7874のブログ
FORTRAN Compiler on IBM 704
ARITHMETIC STATEMENT
というのもあったのだけど、どこかで読めないものか…… で検索してみたが、これか?
これでよかったっぽい。 で、読み始めたはいいけど、論文を読み進める余裕がないのでちょっと困っている😓
余裕というか集中して読み込める場所。かなあ…
ところでFORTRANコンパイラーが最初に作られたころは
- LR
- LL
- 演算子順位
- 再帰下降
のような構文解析手法はまだ確立していなくて、 単純な算術式の解析でも
- replace + and – with ))+(( and ))-((, respectively;
- replace * and / with )*( and )/(, respectively;
- add (( at the beginning of each expression and after each left parenthesis in the original expression; and
- add )) at the end of the expression and before each right parenthesis in the original expression.
という手順でやっている。 もうちょっと詳しく書くと
A + B * C
という式があったとして、+
のまわりにカッコを置き
A ))+(( B * C
*
の周りにカッコを置き
A ))+(( B)*( C
先頭と末尾にカッコを置く
((A ))+(( B)*( C))
そしてカッコの内側から処理すると演算子の順位にしたがったものになると (簡単のためべき乗やら単項マイナス(あったのか?)は省略)。
…という話は大昔に中田先生のコンパイラー本で読んで知ってはいたのだけど、 具体的にどんなコードでやっているのかよくわからなからずじまいだったので ン十年ごしにその疑問が解決できるか?😄
コンパイラーや構文解析に関する本はそこそこ数があるけど、 この手法に触れているのってほとんどないのだよねえ。 触れていてもそれほど詳しい説明はなかったりするし。
一方で
第5章 Fortran最適化コンパイラ(西山博泰)
5.1 FortranI言語
5.2 FortranIコンパイラ
5.3 FortranI以降のプログラミング言語の発展
5.4 FortranI以降のコンパイラ技術の発展
5.5 まとめ
こういう本でも取り上げられていたりする。 この部分のためだけに買うのはキツイかなあ😓
3/6新刊:ISBN978-4-474-07973-1 第一法規『新版 システム開発紛争ハンドブック 第2訂』松島淳也、伊藤雅浩著 10冊入荷 pic.twitter.com/OunVWWsHzS
— ジュンク堂書店池袋本店 PC書担当 (@junkudo_ike_pc) March 6, 2023
なんかすごそうな本が。
仕事で疲れたときによく見る動画。やる気がみなぎってきます。 pic.twitter.com/tgScSunDHc
— プロレスリング加藤 (@q3jQd9xK0aZSvEL) March 2, 2023