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

History from Perl 1.0 to Perl 6

AnaTofuZ
September 14, 2018

History from Perl 1.0 to Perl 6

Roppongi.pm #1でのトークです

AnaTofuZ

September 14, 2018
Tweet

More Decks by AnaTofuZ

Other Decks in Science

Transcript

  1. ؾʹͳΔPerl1.0࠷৽ಈ޲(2) • As a birthday present to Perl and Larry,

    through the work of the perl1-porters, in particular Richard Clamp, resurrected here is Perl 1.0 with minimal patches for modern machines. • ϕʔΦ΢ϧϑͷࢻͱڞʹ2002೥ͷ12݄19೔ʹ
 gcc-3ʹରԠͨ͠ύονͷtag͕ଧͨΕΔ • LarryͱPerl΁ͷ͓஀ੜ೔ϓϨθϯτ
  2. αϒϧʔνϯ΋͋Δͧ!! sub MAX { $max = pop(@_); while ($foo =

    pop(@_)) { $max = $foo if $max < $foo; } $max; } ... $bestday = do MAX($mon,$tue,$wed,$thu,$fri);
  3. for loop (੒ޭ) #!/usr/bin/env perl @array = (1,2,3,4,5,6,7,8,9,10); for (

    $i = 0; $i < $#array; $i++){ print $array["$i"] ."\n"; }
  4. Perl1.0/perl.h • Perlͷ಺෦σʔλܕ͸perl.hͰtypedef͠
 େจࣈͷํΛར༻͢Δ 1 typedef struct arg ARG; 2

    typedef struct cmd CMD; 3 typedef struct formcmd FCMD; 4 typedef struct scanpat SPAT; 5 typedef struct stab STAB; 6 typedef struct stio STIO; 7 typedef struct string STR; 8 typedef struct atbl ARRAY; 9 typedef struct htbl HASH;
  5. Perl2.0 • ֦ுਖ਼نදݱ͕αϙʔτ
 /(foo|bar)/, /(foo)*/,/(foo)+/ • \s,\S,\d,\D͕࢖༻Մೳʹ • αϒϧʔνϯͷ࠶ؼݺͼग़͕͠Մೳʹͳͬͨ •

    do ‘foo.pl’ ͳͲͰ֎෦ϑΝΠϧΛऔΓࠐΊΔ༷ʹ • libҎԼʹPerl੡ͷϞδϡʔϧ͕஀ੜ(getopt.plͳͲ)
  6. Perl2.0ͰϑΟϘφον਺ྻ 1 sub fib { 2 local($arg) = @_; 3

    local($foo); 4 $level++; 5 if ($arg <= 2) { 6 $foo = 1; 7 } 8 else { 9 $foo = do fib($arg-1) + do fib($arg-2); 10 } 11 $level--; 12 $foo; 13 }
  7. Perl2.0ͷStringܕ • STAB͕಺෦ʹຒΊࠐ·ΕΔΑ͏ʹͳͬͨ 1 struct string { 2 char *

    str_ptr; /* pointer to malloced string */ 3 double str_nval; /* numeric value, if any */ 4 int str_len; /* allocated size */ 5 int str_cur; /* length of str_ptr as a C string */ 6 union { 7 STR *str_next; /* while free, link to next free str */ 8 STAB *str_magic; /* while in use, ptr to magic stab, if an */ 9 } str_link; 10 char str_pok; /* state of str_ptr */ 11 char str_nok; /* state of str_nval */ 12 char str_rare; /* used by search strings */ 13 char str_prev; /* also used by search strings */ 14 };
  8. ൣғԋࢉࢠͷಈ͖ • scalar operatorͱͯ͠ͷಈ͖
 (҉໧తʹߦ൪߸$.ͱൺֱ) 2 if (101 .. 200)

    { print; } # print 2nd hundred lines 3 4 next line if (1 .. /^$/); # skip header lines 5 6 s/^/> / if (/^$/ .. eof()); # quote body 7 9 for (101 .. 200) { print; } # print $_ 100 times 10 11 @foo = @foo[$[ .. $#foo]; # an expensive no-op 12 @foo = @foo[$#foo-4 .. $#foo]; # slice last 5 items • array operatorͱͯ͠ͷಈ͖
  9. Perl3-Perl4ͷܕάϩϒ 1 #!../perl 2 3 $hoge = "wanwan"; 4 %hoge

    = ('cat' , "nyanya"); 5 *foo = *hoge; 6 7 print "$foo{'cat'}\n"; 8 *piyo = $_main{'hoge'}; 9 print "$piyo\n";
  10. (ࢀߟ)Perl5ͷܕάϩϒ 1 #!/usr/bin/env perl 2 our $hoge = 'wanwa'; 3

    $hoge_glob = *hoge{SCALAR}; 4 5 print "${$hoge_glob}\n";
  11. Perl3ͷεΧϥʔܕ 1 struct string { 2 char * str_ptr; /*

    pointer to malloced string */ 3 union { 4 double str_nval; /* numeric value, if any */ 5 STAB *str_stab; /* magic stab for magic "key" string */ 6 long str_useful; /* is this search optimization effective? */ 7 ARG *str_args; /* list of args for interpreted string */ 8 HASH *str_hash; /* string represents an assoc array (stab?) */ 9 ARRAY *str_array; /* string represents an array */ 10 } str_u; 11 int str_len; /* allocated size */ 12 int str_cur; /* length of str_ptr as a C string */ 13 STR *str_magic; /* while free, link to next free str */ 14 /* while in use, ptr to "key" for magic items */ 15 char str_pok; /* state of str_ptr */ 16 char str_nok; /* state of str_nval */ 17 unsigned char str_rare; /* used by search strings */ 18 unsigned char str_state; /* one of SS_* below */ 19 /* also used by search strings for backoff */ 20 #ifdef TAINT 21 bool str_tainted; /* 1 if possibly under control of $< */ 22 #endif 23 };
  12. Perl3ςΫχοΫ • ଟ࣍ݩ഑ྻ͸࿈૝഑ྻΛ࢖ͬͯΤϛϡϨʔτ ͍ͯͨ͠ 1 %hash = (); 2 3

    $hash{'piyo','foo'} = "hoge"; 4 5 print "$hash{'piyo','foo'}\n"; • ࿈૝഑ྻͷ =>͸·ͩ࢖͑ͣ, ’΍”΋লུෆՄ
  13. Perl4/perl.h 1 typedef struct arg ARG; 2 typedef struct cmd

    CMD; 3 typedef struct formcmd FCMD; 4 typedef struct scanpat SPAT; 5 typedef struct stio STIO; 6 typedef struct sub SUBR; 7 typedef struct string STR; 8 typedef struct atbl ARRAY; 9 typedef struct htbl HASH; 10 typedef struct regexp REGEXP; 11 typedef struct stabptrs STBP; 12 typedef struct stab STAB; 13 typedef struct callsave CSV; • Perl4Ͱ͸
  14. Perl5 • ϦϑΝϨϯε,blessొ৔ • strictϞʔυ͕ଘࡏ͍ͯ͠ͳ͍ͨΊ
 
 
 
 
 ͜Μͳॻ͖ํ΋ςετίʔυʹొ৔

    6 # Test real references. 7 8 $FOO = \$BAR; 9 $BAR = \$BAZ; 10 $BAZ = "ok 8\n"; 11 print $$$FOO;
  15. Perl5.0ͷSVܕ • ݱࡏͷPerl5ͱ͸த਎͕ҟͳΔ͕͓͓Αͦݪܕ ͕࡞ΒΕ͍ͯΔ 1 /* Using C's structural equivalence

    to help emulate C++ inheritance here... */ 2 3 struct sv { 4 void* sv_any; /* pointer to something */ 5 U32 sv_refcnt; /* how many references to us */ 6 U32 sv_flags; /* what we are */ 7 };
  16. perl.hͰtypedef͞Ε͍ͯΔ σʔλܕͷਪҠ • Perl1.0 • 9 • Perl2.0 • 11

    • Perl3.0 • 12 • Perl4.0 • 14 • Perl5.0 • 49
  17. Perl5/perl.h 1 typedef struct Outrec Outrec; 2 typedef struct interpreter

    PerlInterpreter; 3 typedef struct ff FF; 4 typedef struct sv SV; 5 typedef struct av AV; 6 typedef struct hv HV; 7 typedef struct cv CV; 8 typedef struct regexp REGEXP; 9 typedef struct gp GP; 10 typedef struct sv GV; 11 typedef struct io IO; 12 typedef struct context CONTEXT; 13 typedef struct block BLOCK;
  18. 231KͷϩάΞφϥΠζΛ͢Δ • Perl5 • 0.04s • Ruby • 0.15s •

    Python • 0.06s • Java • 0.27s • Perl6(Moar) • 0.86s • Perl6(JVM) • 21.48s
  19. 3GͷϩάΞφϥΠζΛ͢Δ • Perl5 • 41.35s • Ruby • 574.52s •

    Python • 101.16s • Java • 48.85s • Perl6(Moar) • 2331.08s • Perl6(JVM) • 1665.56s
  20. ػೳతͳൺֱ • 1ສͱ1ઍສͷFizzBuzzΛܭଌ • bytecodeʹམͱ͞ͳ͍෼
 ਺͕গͳ͍৔߹
 ॳظͷPerl͕ߴ଎ • ݅਺͕ଟ͍৔߹bytecode
 ʹམͱ͢Perl5͕ߴ଎

    5JUMF                        ສ ઍສ