Changeset 22522

Show
Ignore:
Timestamp:
10/07/08 05:27:30 (6 weeks ago)
Author:
putter
Message:

[elfish/on_sbcl] elfcl runs fib.

Location:
misc/elfish/on_sbcl
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • misc/elfish/on_sbcl/Elf_SBCL.pm

    r22308 r22522  
    1 use Prelude; 
     1use PrimitivesSBCL; 
     2use EmitSBCL; 
     3 
    24use Match; 
    35use IRx1_Nodes; 
    46use IRx1_FromAST; 
    57use IRx1_Analysis; 
    6 use EmitSimpleP5; 
    7 use PrimitivesP5; 
    88use Parser; 
    99use Compiler; 
    10  
    11 use EmitSBCL; 
    12 #use PrimitivesSBCL; #XXX tmp hack because elf_g can't add files after CommandLine. 
    13  
    1410use CommandLine; 
     11elf_main(); 
  • misc/elfish/on_sbcl/EmitSBCL.pm

    r22502 r22522  
    255255 
    256256;; 
     257(defun flatten-lists (args) 
     258  (reduce #\'append 
     259          (mapcar (lambda (e) (if (and (listp e) (not (null e))) 
     260                                  e (list e))) 
     261                  args))) 
     262 
     263;; 
    257264(dm |M::new| ((co |Any/cls|) &rest argl) 
    258265  (declare (ignorable argl)) 
     
    271278 ;;Array.new is defined here to a avoid cyclic dependency on *@args. 
    272279(pkg-declare "class" "Array" \'|Any/cls|) 
    273 (eval \'(dm |M::new| ((co |Array/cls|) &rest argl) 
     280(dm |M::new| ((co |Array/cls|) &rest argl) 
    274281  (declare (ignorable co)) 
    275282  (let ((inst (make-instance \'|Array/cls|))) 
     
    277284          (make-array (length argl) :adjustable t :initial-contents argl)) 
    278285    inst)) 
    279 ) 
    280286 
    281287;; Hack until Str, Int, Num, etc are p6 objects. 
    282 (eval \'(dm |M::Str| ((s string) &rest argl) (declare (ignorable argl)) s)) 
    283 (eval \'(dm |M::Str| ((n number) &rest argl) (declare (ignorable argl)) (write-to-string n))) 
    284 (eval \'(dm |M::WHAT| ((s string) &rest argl) (declare (ignorable s argl)) "str")) 
    285 (eval \'(dm |M::WHAT| ((n number) &rest argl) (declare (ignorable n argl)) "num")) 
    286  
    287 (eval \'(dm |M::Str| ((x null) &rest argl) (declare (ignorable x argl)) "")) 
    288 (eval \'(dm |M::WHAT| ((x null) &rest argl) (declare (ignorable x argl)) "nil")) 
    289 (eval \'(dm |M::substr| ((s string) from len) (subseq s from (+ from len)))) 
     288(dm |M::Str| ((s string) &rest argl) (declare (ignorable argl)) s) 
     289(dm |M::Str| ((n number) &rest argl) (declare (ignorable argl)) (write-to-string n)) 
     290(dm |M::WHAT| ((s string) &rest argl) (declare (ignorable s argl)) "str") 
     291(dm |M::WHAT| ((n number) &rest argl) (declare (ignorable n argl)) "num") 
     292 
     293(dm |M::Str| ((x null) &rest argl) (declare (ignorable x argl)) "") 
     294(dm |M::WHAT| ((x null) &rest argl) (declare (ignorable x argl)) "nil") 
     295(dm |M::substr| ((s string) from len) (subseq s from (+ from len))) 
    290296 
    291297 
     
    322328;; to-n 
    323329(defgeneric to-n (x)) 
     330(defmethod to-s ((x null)) 0) ;X unboxed Undef 
    324331(defmethod to-n ((x number)) x) 
    325332(defmethod to-n ((x |Int/cls|)) (slot-value x \'|Int::._native_|)) 
     
    328335;; to-s 
    329336(defgeneric to-s (x)) 
     337(defmethod to-s ((x null)) "") ;X unboxed Undef 
    330338(defmethod to-s ((x string)) x) 
    331339(defmethod to-s ((x |Str/cls|)) (slot-value x \'|Str::._native_|)) 
     
    384392    $n.do_all_analysis(); 
    385393    my $decls = $n.notes<lexical_variable_decls>; 
    386     my $code = "(let (\n"; 
     394    my $code = ""; 
     395    my $lexicals = ""; 
     396    my $lexicals_foot = ""; 
    387397    $decls.map(sub($d){if $d.scope eq 'my' { 
    388       #$code = $code ~ $.e($d.var)~" "; #X SubDecl :/ 
    389       # ~$d.twigil~ not included because STD_red is using 0 as false, 
    390       #   and the 0 is mutating into a '0'.  Switch to undef? 
    391       $code = $code ~ $.qsym($d.sigil~$d.name)~" "; 
     398      $lexicals = $lexicals ~ $.qsym($d.sigil~$d.name)~" "; 
    392399    }}); 
    393     $code = $code ~")\n"; 
     400    if $lexicals { 
     401      $code = $code~"(let (\n"~$lexicals ~")\n"; 
     402      $lexicals_foot = ")"; 
     403    } 
    394404    temp $whiteboard::in_package = []; 
    395405    temp $whiteboard::emit_pairs_inline = 0; 
     
    403413    my $foot = $whiteboard::compunit_footer.join("\n"); 
    404414    my $blk_head = $whiteboard::block_header.join(""); 
    405     $code ~ $declare ~ $blk_head ~ $head ~ $stmts ~$foot~"\n)\n"; 
     415    $code ~ $declare ~ $blk_head ~ $head ~ $stmts ~$foot~"\n"~$lexicals_foot~"\n"; 
    406416  } 
    407417  method cb__Block ($n) { 
     
    410420    temp $whiteboard::block_header = []; 
    411421    my $decls = $n.notes<lexical_variable_decls>; 
    412     my $code = "(let ("; 
     422    my $code = ""; 
     423    my $lexicals = ""; 
     424    my $lexicals_foot = ""; 
    413425    $decls.map(sub($d){ 
    414426       my $scope = $d.scope; 
    415427       if $scope eq 'my' { 
    416          $code = $code ~ $.e($d.var)~" "; 
     428         $lexicals = $lexicals ~ $.e($d.var)~" "; 
    417429       } 
    418430       elsif $scope eq 'temp' { 
    419431         my $v = $.e($d.var); 
    420          $code = $code ~ "("~$v~" (if (boundp '"~$v~") "~$v~")) "; 
     432         $lexicals = $lexicals ~ "("~$v~" (if (boundp '"~$v~") "~$v~")) "; 
    421433       } 
    422434    }); 
     435    if $lexicals { 
     436      $code = $code~"(let (\n"~$lexicals ~")\n"; 
     437      $lexicals_foot = ")"; 
     438    } 
    423439    my $stmts = $.e($n.statements).join("\n"); 
    424440    my $declare = $whiteboard::declares.join(""); 
    425441    my $blk_head = $whiteboard::block_header.join(""); 
    426     $code~")\n"~$declare~$blk_head~$stmts~')' 
     442    $code~$declare~$blk_head~$stmts~$lexicals_foot; 
    427443  } 
    428444 
     
    526542      my $accname = '|M::'~$name~'|'; 
    527543      my $code = 
    528         ('(eval \'(dm '~$accname~' ((self '~$cls~'))'~ 
     544        ('(dm '~$accname~' ((self '~$cls~'))'~ 
    529545         ' (let ((setter (lambda (o v) (setf (slot-value o \''~$slotname~') v))))'~ 
    530          '   (rw-able (slot-value self \''~$slotname~') setter self))))'~"\n"); 
     546         '   (rw-able (slot-value self \''~$slotname~') setter self)))'~"\n"); 
    531547      my $slot_specifier = '('~$slotname; 
    532548      if $default { 
     
    565581    my $enc_name = $.qsym('M::'~$.e($n.name)); 
    566582    my $sig = $.e($n.multisig); 
    567     my $decl = ('(eval \'(dm '~$enc_name~' ((self '~$cls~') '~$sig~ 
    568                 ' (declare (ignorable self))'~ 
    569                 ' (block __f__ '~$body~')))'); 
    570     $whiteboard::compunit_header.push($decl); 
     583    my $decl = ('(dm '~$enc_name~' ((self '~$cls~') '~$sig~ 
     584                #' (let () (declare (ignorable self))'~ 
     585                ' (block __f__ '~$body~'))'); 
     586    $whiteboard::block_header.push($decl); 
    571587    ""; 
    572588  } 
     
    611627      $code = '(lambda '~$most~')'; 
    612628    } 
    613     $whiteboard::compunit_header.push($decl); 
     629    $whiteboard::block_header.push($decl); 
    614630    $code; 
    615631  } 
     
    663679      } 
    664680    } 
    665     my $call = '(fc '~$meth~' '~$invocant~' '~$e_capture~')'; 
    666     $call; 
     681    if $n.capture.contains_a_list { 
     682      '(ap '~$meth~' (cons '~$invocant~' (flatten-lists '~$e_capture~')))'; 
     683    } 
     684    else { 
     685      '(fc '~$meth~' '~$invocant~' '~$e_capture~')'; 
     686    } 
    667687  } 
    668688  method fqsym ($name) { 
     
    763783    } 
    764784 
     785    if not(defined($e_capture)) { $e_capture = $.e($n.capture) } 
     786    my $pre = '(fc '; 
     787    my $mid = ' '; 
     788    my $post = ')'; 
     789    if $n.capture.contains_a_list { 
     790      $pre = '(ap '; 
     791      $mid = ' (flatten-lists '; 
     792      $post = '))'; 
     793    } 
     794 
    765795    if $fun.re_matchp('^\w') { 
    766796      my $fe = $.qsym('GLOBAL::&'~$fun); 
    767       if not(defined($e_capture)) { $e_capture = $.e($n.capture) } 
    768       return '(fc '~$fe~' '~$e_capture~')' 
     797      return $pre~$fe~$mid~$e_capture~$post; 
    769798    } 
    770799    if $fun.re_matchp('^[$@%&]') { 
    771        return  '(fc '~$.qsym($fun)~' '~$.e($n.capture)~')'; 
     800       return  $pre~$.qsym($fun)~$mid~$e_capture~$post; 
    772801    } 
    773802    else { 
    774        return  '(fc '~$fun~' '~$.e($n.capture)~')'; 
     803       return $pre~$fun~$mid~$e_capture~$post; 
    775804    } 
    776805  } 
  • misc/elfish/on_sbcl/Makefile

    r22447 r22522  
    11 
     2ELF=../../elf/elf_h 
     3ELFDIR=../../elf/elf_h_src 
     4TMP=deleteme 
     5SBCL=sbcl --dynamic-space-size 1800 
    26 
    37elfx:: have_parser_cache 
    4         ELF_STD_RED_RUN=../../STD_red/STD_red_run ../../elf/elf_h -x -o ./elfx -I ../../elf/elf_h_src Elf_SBCL.pm 
     8        ELF_STD_RED_RUN=../../STD_red/STD_red_run ../../elf/elf_h -x -o ./elfx -I ../../elf/elf_h_src -e 'use Elf_wo_main' EmitSBCL.pm -e elf_main 
    59 
    6 #XXX no main() call yet, so CommandLine must come after last file... 
    7 # but doesnt here. 
    8 #       ELF_STD_RED_RUN=../../STD_red/STD_red_run ../../elf/elf_h -x -o ./elfx -I ../../elf/elf_h_src Elf.pm EmitSBCL.pm 
    9  
    10  
     10elfcl:: have_parser_cache 
     11        ${ELF} -I ${ELFDIR} EmitSBCL.pm -x -o elfcl Elf_SBCL.pm 
     12        time ${SBCL} --eval '(compile-file "elfcl")' --eval '(quit)' >& elfcl.out 
    1113 
    1214have_parser_cache: 
     
    4648        ./lib-cl_compile.lisp 
    4749 
     50check: have_parser_cache 
     51        -mkdir ${TMP} 
     52        -rm ${TMP}/[ab]* 
     53        # Create a p5 elf. 
     54        ${ELF} -I ${ELFDIR} -x -o ${TMP}/a0 ${ELFDIR}/Elf.pm 
     55        # Create a CL elf. 
     56        ${ELF} -I ${ELFDIR} EmitSBCL.pm -x -o ${TMP}/b0 Elf_SBCL.pm 
     57        # Compile it, with output to log. 
     58        ${SBCL} --disable-debugger --eval '(compile-file "${TMP}/b0")' --eval '(quit)' > ${TMP}/b0.log 2>&1 
     59        # Run it. 
     60        chmod a+x ${TMP}/b0 
     61        ${TMP}/b0 -e 'say 3' 
     62        # Check CL bootstrap. 
     63        ${TMP}/b0 -I ${ELFDIR} -x -o ${TMP}/b1 Elf_SBCL.pm 
     64        diff ${TMP}/b0 ${TMP}/b1 
     65        # Compile a p5 elf with a CL one. 
     66        ${TMP}/b0 -I ${ELFDIR} -e 'use EmitSimpleP5' -x -o ${TMP}/a1 -e 'use Elf' 
     67        # Was it identical? 
     68        diff ${TMP}/a0 ${TMP}/a1 
  • misc/elfish/on_sbcl/PrimitivesSBCL.pm

    r22502 r22522  
    146146  sub private_tidy ($s) { $s } 
    147147  sub eval_runtime_code($code,$env) is cl {' 
    148     (eval (read-from-string (S |$code|))) 
     148    (eval (read-from-string (concatenate \'string "(progn " (S |$code|) ")"))) 
    149149  '} 
    150150  sub file_exists ($filename) is cl {' 
    151151    (UP (if (probe-file (S |$filename|)) t nil)) 
    152152  '} 
     153  sub elf_main () { Program.new().main(@*ARGS); } 
    153154} 
    154155# regexp elf bootstrap primitives 
     
    158159    (multiple-value-bind (match_str a) (ppcre::scan-to-strings (S |$re|) (S self)) 
    159160      (declare (ignorable match_str)) 
    160       (new-Array (mapcar #\'UP a))) 
     161      (new-Array (mapcar #\'UP (coerce a \'list)))) 
    161162  '} 
    162163  method re_gsub ($re,$replacement_str) is cl {' 
  • misc/elfish/on_sbcl/README

    r22465 r22522  
    3636NOTES 
    3737 
     38  SBCL is a verbose beast.  Anything which compiles should be run 
     39  from a fast terminal.  Like xterm, not gnome terminal.  Otherwise, 
     40  terminal scrolling will determine compile time. 
     41 
     42  Compiling the CL elf requires about 2GB of ram. 
     43 
    3844  Warnings are sometimes muffled before check in, to improve the 
    3945  experience of causal users.  For real development, comment out 
     
    6268  # This remained 1x with general rw-ability added, still native integers. 
    6369  # This dropped to 1/2x with Int's. 
     70  # This dropped to 1/4x while not being watched, for causes unknown.