Changeset 22528

Show
Ignore:
Timestamp:
10/07/08 21:28:28 (6 weeks ago)
Author:
putter
Message:

[elfish/on_sbcl] Still struggling towards self compilation.
[elf_h] Tweaks.

Location:
misc
Files:
9 modified

Legend:

Unmodified
Added
Removed
  • misc/elf/elf_h

    r22521 r22528  
    100100  sub lcfirst  { CORE::lcfirst($_[0]); } 
    101101 
    102   sub length   { CORE::length($_[0]); } 
    103102  sub bytes    { use bytes; CORE::length($_[0]); } 
    104103  sub chars    { CORE::length($_[0]); } 
     
    22042203(do{my $v = ($m->match_string()); 
    22052204my $s = GLOBAL::substr($v, 0, 1); 
    2206 my $n = GLOBAL::substr($v, 1, $v->length()); 
     2205my $n = GLOBAL::substr($v, 1, $v->chars()); 
    22072206IRx1::Var->newp($m, $s, GLOBAL::undef(), $n)})}; 
    22082207my $construct_circumfix = sub {my($m)=@_; 
     
    23362335(do{($multisig = [IRx1::Signature->newp($m, [], GLOBAL::undef())])}) 
    23372336}; 
    2338 IRx1::MethodDecl->newp($m, GLOBAL::undef(), GLOBAL::undef(), $plurality, irbuild_ir($m->hash()->{"ident"}), $multisig->[0], irbuild_ir($m->hash()->{"trait"}), irbuild_ir($m->hash()->{"block"}))})}; 
     2337IRx1::MethodDecl->newp($m, GLOBAL::undef(), GLOBAL::undef(), $plurality, irbuild_ir($m->hash()->{"ident"}), $multisig->[0], irbuild_ir($m->hash()->{"trait"}), irbuild_ir($m->hash()->{"block"}), GLOBAL::undef(), GLOBAL::undef())})}; 
    23392338my $construct_signature = sub {my($m)=@_; 
    23402339(do{IRx1::Signature->newp($m, irbuild_ir($m->hash()->{"parsep"}), GLOBAL::undef())})}; 
     
    29042903; 
    29052904 
     2905{ package IRx1::Apply; 
     2906use base "Any";(do{sub provides_a_list{my $self=CORE::shift;(do{(($self->function eq "infix\:\,") && $self->capture->contains_a_list())})}}) 
     2907} 
     2908; 
     2909 
    29062910{ package IRx1::Capture; 
    2907 use base "Any";(do{sub contains_a_list{my $self=CORE::shift;(do{my $found; 
    2908 $self->arguments->map(sub {my($e)=@_; 
    2909 (do{if((($e->isa("IRx1\:\:Base") && $e->provides_a_list()))) { 
    2910 (do{($found = 1)}) 
    2911 }})}); 
    2912 $found})}}) 
     2911use base "Any";(do{sub contains_a_list{my $self=CORE::shift;(do{for(($self->arguments)->flatten){ 
     2912(do{if((($_->isa("IRx1\:\:Base") && $_->provides_a_list()))) { 
     2913(do{return(1)}) 
     2914}}) 
     2915}; 
     2916GLOBAL::undef()})}}) 
    29132917} 
    29142918; 
     
    30373041\ \ sub\ lcfirst\ \ \{\ CORE\:\:lcfirst\(\$_\[0\]\)\;\ \}\ 
    30383042\ 
    3039 \ \ sub\ length\ \ \ \{\ CORE\:\:length\(\$_\[0\]\)\;\ \}\ 
    30403043\ \ sub\ bytes\ \ \ \ \{\ use\ bytes\;\ CORE\:\:length\(\$_\[0\]\)\;\ \}\ 
    30413044\ \ sub\ chars\ \ \ \ \{\ CORE\:\:length\(\$_\[0\]\)\;\ \}\ 
     
    39143917; 
    39153918($GLOBAL::PID = (sub {$$})->()); 
     3919($GLOBAL::OS = (sub {$^O})->()); 
     3920($GLOBAL::OSVER = (sub {`/bin/uname -a`})->()); 
     3921($GLOBAL::EXECUTABLE_NAME = (sub {$0})->()); 
     3922sub not_used_only_once{(do{[$GLOBAL::OS, $GLOBAL::OSVER, $GLOBAL::EXECUTABLE_NAME]})}; 
    39163923 
    39173924{ package GLOBAL; 
  • misc/elf/elf_h_src/EmitSimpleP5.pm

    r22501 r22528  
    133133  sub lcfirst  { CORE::lcfirst($_[0]); } 
    134134 
    135   sub length   { CORE::length($_[0]); } 
    136135  sub bytes    { use bytes; CORE::length($_[0]); } 
    137136  sub chars    { CORE::length($_[0]); } 
  • misc/elf/elf_h_src/IRx1_Analysis.pm

    r22521 r22528  
    239239  method provides_a_list { self.method eq "flatten" } 
    240240} 
     241class IRx1::Apply { 
     242  method provides_a_list { 
     243    $.function eq 'infix:,' && $.capture.contains_a_list; 
     244  } 
     245} 
    241246class IRx1::Capture { 
    242247  method contains_a_list { 
    243     my $found; 
    244     $.arguments.map(sub($e){ 
    245       if ($e.isa('IRx1::Base') && $e.provides_a_list) { $found = 1 }}); 
    246     $found; 
    247   } 
    248 } 
     248    for $.arguments { 
     249      if ($_.isa('IRx1::Base') && $_.provides_a_list) { return 1 } 
     250    } 
     251    undef; 
     252  } 
     253} 
  • misc/elf/elf_h_src/IRx1_FromAST.pm

    r22521 r22528  
    322322      my $v = ($m.match_string); 
    323323my $s = substr($v,0,1); 
    324 my $n = substr($v,1,$v.length); 
     324my $n = substr($v,1,$v.chars); 
    325325IRx1::Var.newp($m,$s,undef,$n); 
    326326    }; 
     
    492492my $multisig = irbuild_ir($m.hash{'multisig'}); 
    493493if not($multisig) { $multisig = [IRx1::Signature.newp($m,[],undef)]; } 
    494 IRx1::MethodDecl.newp($m,undef,undef,$plurality,irbuild_ir($m.hash{'ident'}),$multisig.[0],irbuild_ir($m.hash{'trait'}),irbuild_ir($m.hash{'block'})); 
     494IRx1::MethodDecl.newp($m,undef,undef,$plurality,irbuild_ir($m.hash{'ident'}),$multisig.[0],irbuild_ir($m.hash{'trait'}),irbuild_ir($m.hash{'block'}),undef,undef); 
    495495    }; 
    496496 
  • misc/elf/elf_h_src/IRx1_FromAST_create.pl

    r22521 r22528  
    237237my $v = *text*; 
    238238my $s = substr($v,0,1); 
    239 my $n = substr($v,1,$v.length); 
     239my $n = substr($v,1,$v.chars); 
    240240Var.newp($s,undef,$n) 
    241241 
     
    372372my $multisig = $m<multisig>; 
    373373if not($multisig) { $multisig = [Signature.newp([],undef)]; } 
    374 MethodDecl.newp(undef,undef,$plurality,$m<ident>,$multisig.[0],$m<trait>,$m<block>) 
     374MethodDecl.newp(undef,undef,$plurality,$m<ident>,$multisig.[0],$m<trait>,$m<block>,undef,undef) 
    375375 
    376376signature 
  • misc/elf/elf_h_src/PrimitivesP5.pm

    r22521 r22528  
    99 
    1010$*PID = (sub () is p5 {'$$'}).(); 
     11$*OS = (sub () is p5 {'$^O'}).(); 
     12$*OSVER = (sub () is p5 {'`/bin/uname -a`'}).(); 
     13$*EXECUTABLE_NAME = (sub () is p5 {'$0'}).(); 
     14sub not_used_only_once { [$*OS,$*OSVER,$*EXECUTABLE_NAME] } 
    1115 
    1216package GLOBAL { # sub *f(){} isn't working yet. 
  • misc/elfish/on_sbcl/EmitSBCL.pm

    r22522 r22528  
    2121   ''; 
    2222  } 
    23   method prelude ($n) { 
     23  method prelude { 
    2424  '#| 
    25 #fasl=`dirname $0`/`basename $0 .lisp`.fasl 
    26 #[ $fasl -ot $0 ] && sbcl --noinform --eval "(compile-file \"$0\")" --eval "(quit)" 
    27 #exec sbcl --noinform --load $fasl --end-toplevel-options "$@" 
    28 exec sbcl --noinform --load $0 --eval "(quit)" --end-toplevel-options "$@" 
     25fasl=`dirname $0`/`basename $0 .lisp`.fasl 
     26[ $fasl -ot $0 ] && sbcl --noinform --eval "(compile-file \"$0\")" --eval "(quit)" 
     27exec sbcl --noinform --load $fasl --end-toplevel-options "$@" 
     28#exec sbcl --noinform --load $0 --eval "(quit)" --end-toplevel-options "$@" 
    2929|# 
    3030 
     
    257257(defun flatten-lists (args) 
    258258  (reduce #\'append 
    259           (mapcar (lambda (e) (if (and (listp e) (not (null e))) 
    260                                   e (list e))) 
     259          (mapcar (lambda (e) 
     260                    (if (and (listp e) 
     261                             ;;(not (null e)) ;#XXX disappears undef args! 
     262                             ;;# boxing undef is now important. :/ 
     263                             ) 
     264                        e (list e))) 
    261265                  args))) 
    262266 
     
    292296 
    293297(dm |M::Str| ((x null) &rest argl) (declare (ignorable x argl)) "") 
    294 (dm |M::WHAT| ((x null) &rest argl) (declare (ignorable x argl)) "nil") 
     298(dm |M::WHAT| ((x null) &rest argl) (declare (ignorable x argl)) "Undef") 
    295299(dm |M::substr| ((s string) from len) (subseq s from (+ from len))) 
    296300 
     
    367371      \'nil 
    368372    (let ((sym (gensym))) 
    369       `(let ((,sym ,(car args))) (if (to-b ,sym) ,sym (or6 ,@(cdr args))))))) 
     373      `(let ((,sym ,(car args))) 
     374         (if (or ,(null (cdr args)) (to-b ,sym)) ,sym (or6 ,@(cdr args))))))) 
    370375(defmacro and6 (&rest args) 
    371376  (cond ((null args) t) 
     
    380385  } 
    381386 
    382   method e($x) { 
     387  method e ($x) { 
    383388    my $ref = $x.WHAT; 
    384389    if $ref eq 'Undef' { $x } 
     
    676681        my $words = $s.split('\s+'); 
    677682        my $self = self; 
    678         $e_capture = $words.map(sub($x){$self.qstr($x)}).join(" "); 
     683        $e_capture = $words.map(sub($x){$self.UP_qstr($x)}).join(" "); 
    679684      } 
    680685    } 
    681686    if $n.capture.contains_a_list { 
    682       '(ap '~$meth~' (cons '~$invocant~' (flatten-lists '~$e_capture~')))'; 
     687      '(ap '~$meth~' (cons '~$invocant~' (flatten-lists (list '~$e_capture~'))))'; 
    683688    } 
    684689    else { 
     
    694699  method qstr ($str) { 
    695700     '"'~$str.re_gsub('\\\\','\\\\').re_gsub('"','\"')~'"' 
     701  } 
     702  method UP_qstr ($str) { 
     703     '(UP "'~$str.re_gsub('\\\\','\\\\').re_gsub('"','\"')~'")' 
    696704  } 
    697705 
     
    763771        my $words = $s.split('\s+'); 
    764772        my $self = self; 
    765         return $.emit_array($words.map(sub($x){$self.qstr($x)}).join(" ")); 
     773        return $.emit_array($words.map(sub($x){$self.UP_qstr($x)}).join(" ")); 
    766774      } 
    767775    } 
     
    789797    if $n.capture.contains_a_list { 
    790798      $pre = '(ap '; 
    791       $mid = ' (flatten-lists '; 
    792       $post = '))'; 
     799      $mid = ' (flatten-lists (list '; 
     800      $post = ')))'; 
    793801    } 
    794802 
  • misc/elfish/on_sbcl/Makefile

    r22522 r22528  
    1111        ${ELF} -I ${ELFDIR} EmitSBCL.pm -x -o elfcl Elf_SBCL.pm 
    1212        time ${SBCL} --eval '(compile-file "elfcl")' --eval '(quit)' >& elfcl.out 
     13        chmod a+x elfcl 
    1314 
    1415have_parser_cache: 
  • misc/elfish/on_sbcl/PrimitivesSBCL.pm

    r22522 r22528  
    104104  multi unlink_ ($filename) is cl {' (sb-unix:unix-unlink (S |$filename|)) '} 
    105105  multi not ($x) { if $x { undef } else { 1 } } 
    106   multi defined ($x) is cl {' (UP (if |$x| 1 nil)) '} #X undef as nil 
     106  multi defined ($x) is cl {' (UP (if |$x| 1 nil)) '} ;#X undef as nil 
     107  multi substr($s,$offset,$length) { $s.substr($offset,$length) } 
    107108} 
    108109 
     
    151152    (UP (if (probe-file (S |$filename|)) t nil)) 
    152153  '} 
    153   sub elf_main () { Program.new().main(@*ARGS); } 
     154  sub elf_main () { 
     155    Program.new().main(@*ARGS); 
     156    exit(0); 
     157  } 
     158  sub module_require ($module) { 
     159    my $file = find_required_module($module); 
     160    $file || die("Cant locate $module in ( "~@*INC.join(" ")~" ).\n"); 
     161    eval_file($file); 
     162  }; 
     163  sub find_required_module ($module) { 
     164    my $names = [$module, $module~".pm", $module~".p6"]; 
     165    for @*INC { my $dir = $_; 
     166      for $names { my $name = $_; 
     167        my $file = $dir~"/"~$name; 
     168        if file_exists($file) { 
     169          return $file; 
     170        } 
     171      } 
     172    } 
     173    return undef; 
     174  } 
     175  sub import ($module,*@args) { 
     176    undef 
     177  } 
     178  sub eval_file ($file) { 
     179    $*compiler0.eval_file($file); 
     180  } 
     181  sub eval_perl6 ($code,$env) { 
     182    $*compiler0.eval_perl6($code,$env); 
     183  } 
     184  sub eval ($code,$env) { 
     185    eval_perl6($code,$env); 
     186  } 
     187 
    154188} 
    155189# regexp elf bootstrap primitives 
     
    227261      (UP (subseq s off (min len (+ off (N |$length|)))))) 
    228262  '} 
     263  method chars () is cl {' 
     264    (let* ((s (slot-value self \'|Str::._native_|)) 
     265           (len (length s))) 
     266      (UP len)) 
     267  '} 
    229268} 
    230269 
     
    297336           (from (wrapped-index len (N |$from|))) 
    298337           (to (wrapped-index len (N |$to|)))) 
    299       (new-Array (subseq a from to))) 
     338      (new-Array (coerce (subseq a from to) \'list))) 
    300339  '} 
    301340  method reverse () is cl {'