Skip to content

Instantly share code, notes, and snippets.

@wanabe
wanabe / gist:bc6c4091d9e70164baa2b8d6162e5807
Created November 27, 2022 08:20
ruby sample/exyacc.rb parse.y at d055c44b0cfeeed2d02f8899200863d69758abc1
program : top_compstmt
;
top_compstmt : top_stmts opt_terms
;
top_stmts : none
| top_stmt
| top_stmts terms top_stmt
;
@wanabe
wanabe / gist:d1d6c0711b3ac7df4a94021477713b9a
Last active July 9, 2022 09:53
Feature #18875 がどういうことなのか読み解く

Feature #18875 https://bugs.ruby-lang.org/issues/18875 で、Ruby になにやら大きな変更が入ったようです。 チケットを読んでもどういうものなのかまだあまりわからず、気になったので調べつつメモします。

もっとも特徴的なのはこの部分です。

@@ -456,9 +460,12 @@ struct rb_iseq_constant_body {
     } variable;
 
 unsigned int local_table_size;

yjit についてメモ書き

めちゃ速い

$ for opt in '' '--jit' '--yjit'; do echo "opt": $opt; time ./miniruby $opt -e 'def fib(n); return n if n < 2; fib(n - 1) + fib(n-2); end; fib(35)'; done
opt:
diff --git a/compile.c b/compile.c
index 1cabb8cccd..9e3a1111dc 100644
--- a/compile.c
+++ b/compile.c
@@ -6562,7 +6562,7 @@ iseq_compile_array_deconstruct(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NO
ADD_INSNL(ret, line, branchunless, match_failed);
- ADD_SEND(ret, line, rb_intern("deconstruct"), INT2FIX(0));
+ ADD_INSN(ret, line, deconstruct);
@wanabe
wanabe / gist:5ba643a3b0e40c05f8de255081e829f0
Last active October 13, 2020 03:16
ruby が 0 という一文字を解釈する流れをわかりたい

この文章は

CRuby がプログラムをどう実行しているのかを自分がいまいち理解していないので、その理解のために書いていくものです。 実験的に、あっちこっちリンクで飛ぶように書きたいと思います。

はじまり

CRuby の実行ファイルである ruby(Windows であれば ruby.exe)は、Ruby スクリプトを解釈して実行します。 たとえば ruby -e 0 などとすると、0 という一文字の Ruby スクリプトだと解釈され、実行されます。画面に何も表示しないので本当かどうかよくわかりませんが、そうらしいです。

@wanabe
wanabe / gist:b4baf0d4459b60a0c31d794cd9801f27
Last active August 10, 2020 02:02
パターンマッチをわかりたい

この文書は

Ruby のパターンマッチングがどうやって実装されているのかわからないので実装を読んでわかったことを書いていく覚え書きです。

もともとは、パターンマッチング文法のコンパイル結果の命令列を見ていて、なんだかおかしいような気がしたけれども自信がないので、もうちょっと読んでおかしいかおかしくないか判断しよう、というのが動機です。

結論として「動きはするし顕在化とは思うが、微妙にまずそう」というところを見つけたのでそこまでの道筋を書きます。

パターンマッチングの書式

---------------------
[compile step 4.1 (iseq_set_sequence)]
-- raw disasm--------
trace: 8
trace: 1
0000 putobject false ( 1)
0002 setlocal_WC_0 4 ( 1)
0004 getlocal_WC_0 4 ( 1)
0006 branchunless <L002> ( 1)
0008 putnil ( 1)

この文章は

マイクロサービスを全然知らないので実験してみた作業記録です。

構想

gRPC で rejoiner 使ったら叩くときも楽かなー、やったことないから go やってみたいなー、くらいのことしか考えてません。 題材はなんでもいいんですが、git の GUI クライアントがほしいのでその想定で。

記録

@wanabe
wanabe / gist:827ef88896f655cfe46631bb5cfb5d6d
Last active August 11, 2019 10:11
たぶん互換性を壊している(メソッド定義が primary_value にならない)
diff --git a/parse.y b/parse.y
index a6a9a4160b..4470f226a8 100644
--- a/parse.y
+++ b/parse.y
@@ -1004,7 +1004,7 @@ static void token_info_warn(struct parser_params *p, const char *token, token_in
%type <node> words symbols symbol_list qwords qsymbols word_list qword_list qsym_list word
%type <node> literal numeric simple_numeric ssym dsym symbol cpath
%type <node> top_compstmt top_stmts top_stmt begin_block
-%type <node> bodystmt compstmt stmts stmt_or_begin stmt expr arg primary command command_call method_call
+%type <node> bodystmt compstmt stmts stmt_or_begin stmt expr arg primary1 primary2 primary command command_call method_call
$ cat bug13930.rb
1.times do
begin
next
rescue
p :unexpected_raise
exit!
ensure
p :ensure
raise