Upgrade to Pro — share decks privately, control downloads, hide ads and more …

楽にコンパイラを書く話

 楽にコンパイラを書く話

Yuya Kono

May 19, 2019
Tweet

More Decks by Yuya Kono

Other Decks in Programming

Transcript

  1. ύλʔϯϚονͬͯʁ type Result = Ok(int) | Err(string) match input {

    Ok(value) => return value, Err(_) => error("something bad happend"), } ͜Μͳͷɻ
 ༩͑ΒΕͨ஋ JOQVU ͷܗʹԠͯ͡෼ذ͢Δɻ
 3FTVMUͷఆٛ΋$ʹม׵͠ͳ͍ͱ͍͚ͳ͍ɻ
  2. ܕͷม׵ struct Result { int tag; union { int val_0;

    string val_1; }; } int Ok = 0; int Err = 1; ܕ͸$ʹม׵Ͱ͖ͨɻ
  3. NBUDI@UBHʹม׵ match_tag (input, Ok) { value = input.val_0; return value;

    } else match_tag (input, Err) { _ = input.val_1; error("something bad happend"); } NBUDI@UBH͸ୈҰҾ਺ͷUBH͕ୈೋҾ਺ʹ౳͚͠Ε͹ଓ͘
 ϒϩοΫΛ࣮ߦ͢ΔɻJGͷѥछɻ
  4. $ʹม׵ struct Result { int tag; union { int val_0;

    char* val_1; } }; int Ok = 0; int Err = 1; if (input.tag == Ok) { int value = input.val_0; return value; } else if (input.tag == Err) { error("something bad happened"); }