- Timestamp:
- 10/07/08 05:27:30 (3 months ago)
- Location:
- misc/elfish/on_sbcl
- Files:
-
- 5 modified
-
Elf_SBCL.pm (modified) (1 diff)
-
EmitSBCL.pm (modified) (13 diffs)
-
Makefile (modified) (2 diffs)
-
PrimitivesSBCL.pm (modified) (2 diffs)
-
README (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
misc/elfish/on_sbcl/Elf_SBCL.pm
r22308 r22522 1 use Prelude; 1 use PrimitivesSBCL; 2 use EmitSBCL; 3 2 4 use Match; 3 5 use IRx1_Nodes; 4 6 use IRx1_FromAST; 5 7 use IRx1_Analysis; 6 use EmitSimpleP5;7 use PrimitivesP5;8 8 use Parser; 9 9 use Compiler; 10 11 use EmitSBCL;12 #use PrimitivesSBCL; #XXX tmp hack because elf_g can't add files after CommandLine.13 14 10 use CommandLine; 11 elf_main(); -
misc/elfish/on_sbcl/EmitSBCL.pm
r22502 r22522 255 255 256 256 ;; 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 ;; 257 264 (dm |M::new| ((co |Any/cls|) &rest argl) 258 265 (declare (ignorable argl)) … … 271 278 ;;Array.new is defined here to a avoid cyclic dependency on *@args. 272 279 (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) 274 281 (declare (ignorable co)) 275 282 (let ((inst (make-instance \'|Array/cls|))) … … 277 284 (make-array (length argl) :adjustable t :initial-contents argl)) 278 285 inst)) 279 )280 286 281 287 ;; 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))) 290 296 291 297 … … 322 328 ;; to-n 323 329 (defgeneric to-n (x)) 330 (defmethod to-s ((x null)) 0) ;X unboxed Undef 324 331 (defmethod to-n ((x number)) x) 325 332 (defmethod to-n ((x |Int/cls|)) (slot-value x \'|Int::._native_|)) … … 328 335 ;; to-s 329 336 (defgeneric to-s (x)) 337 (defmethod to-s ((x null)) "") ;X unboxed Undef 330 338 (defmethod to-s ((x string)) x) 331 339 (defmethod to-s ((x |Str/cls|)) (slot-value x \'|Str::._native_|)) … … 384 392 $n.do_all_analysis(); 385 393 my $decls = $n.notes<lexical_variable_decls>; 386 my $code = "(let (\n"; 394 my $code = ""; 395 my $lexicals = ""; 396 my $lexicals_foot = ""; 387 397 $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)~" "; 392 399 }}); 393 $code = $code ~")\n"; 400 if $lexicals { 401 $code = $code~"(let (\n"~$lexicals ~")\n"; 402 $lexicals_foot = ")"; 403 } 394 404 temp $whiteboard::in_package = []; 395 405 temp $whiteboard::emit_pairs_inline = 0; … … 403 413 my $foot = $whiteboard::compunit_footer.join("\n"); 404 414 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"; 406 416 } 407 417 method cb__Block ($n) { … … 410 420 temp $whiteboard::block_header = []; 411 421 my $decls = $n.notes<lexical_variable_decls>; 412 my $code = "(let ("; 422 my $code = ""; 423 my $lexicals = ""; 424 my $lexicals_foot = ""; 413 425 $decls.map(sub($d){ 414 426 my $scope = $d.scope; 415 427 if $scope eq 'my' { 416 $ code = $code~ $.e($d.var)~" ";428 $lexicals = $lexicals ~ $.e($d.var)~" "; 417 429 } 418 430 elsif $scope eq 'temp' { 419 431 my $v = $.e($d.var); 420 $ code = $code~ "("~$v~" (if (boundp '"~$v~") "~$v~")) ";432 $lexicals = $lexicals ~ "("~$v~" (if (boundp '"~$v~") "~$v~")) "; 421 433 } 422 434 }); 435 if $lexicals { 436 $code = $code~"(let (\n"~$lexicals ~")\n"; 437 $lexicals_foot = ")"; 438 } 423 439 my $stmts = $.e($n.statements).join("\n"); 424 440 my $declare = $whiteboard::declares.join(""); 425 441 my $blk_head = $whiteboard::block_header.join(""); 426 $code~ ")\n"~$declare~$blk_head~$stmts~')'442 $code~$declare~$blk_head~$stmts~$lexicals_foot; 427 443 } 428 444 … … 526 542 my $accname = '|M::'~$name~'|'; 527 543 my $code = 528 ('( eval \'(dm '~$accname~' ((self '~$cls~'))'~544 ('(dm '~$accname~' ((self '~$cls~'))'~ 529 545 ' (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"); 531 547 my $slot_specifier = '('~$slotname; 532 548 if $default { … … 565 581 my $enc_name = $.qsym('M::'~$.e($n.name)); 566 582 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); 571 587 ""; 572 588 } … … 611 627 $code = '(lambda '~$most~')'; 612 628 } 613 $whiteboard:: compunit_header.push($decl);629 $whiteboard::block_header.push($decl); 614 630 $code; 615 631 } … … 663 679 } 664 680 } 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 } 667 687 } 668 688 method fqsym ($name) { … … 763 783 } 764 784 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 765 795 if $fun.re_matchp('^\w') { 766 796 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; 769 798 } 770 799 if $fun.re_matchp('^[$@%&]') { 771 return '(fc '~$.qsym($fun)~' '~$.e($n.capture)~')';800 return $pre~$.qsym($fun)~$mid~$e_capture~$post; 772 801 } 773 802 else { 774 return '(fc '~$fun~' '~$.e($n.capture)~')';803 return $pre~$fun~$mid~$e_capture~$post; 775 804 } 776 805 } -
misc/elfish/on_sbcl/Makefile
r22447 r22522 1 1 2 ELF=../../elf/elf_h 3 ELFDIR=../../elf/elf_h_src 4 TMP=deleteme 5 SBCL=sbcl --dynamic-space-size 1800 2 6 3 7 elfx:: 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.pm8 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 5 9 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 10 elfcl:: 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 11 13 12 14 have_parser_cache: … … 46 48 ./lib-cl_compile.lisp 47 49 50 check: 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 146 146 sub private_tidy ($s) { $s } 147 147 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|) ")"))) 149 149 '} 150 150 sub file_exists ($filename) is cl {' 151 151 (UP (if (probe-file (S |$filename|)) t nil)) 152 152 '} 153 sub elf_main () { Program.new().main(@*ARGS); } 153 154 } 154 155 # regexp elf bootstrap primitives … … 158 159 (multiple-value-bind (match_str a) (ppcre::scan-to-strings (S |$re|) (S self)) 159 160 (declare (ignorable match_str)) 160 (new-Array (mapcar #\'UP a)))161 (new-Array (mapcar #\'UP (coerce a \'list)))) 161 162 '} 162 163 method re_gsub ($re,$replacement_str) is cl {' -
misc/elfish/on_sbcl/README
r22465 r22522 36 36 NOTES 37 37 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 38 44 Warnings are sometimes muffled before check in, to improve the 39 45 experience of causal users. For real development, comment out … … 62 68 # This remained 1x with general rw-ability added, still native integers. 63 69 # This dropped to 1/2x with Int's. 70 # This dropped to 1/4x while not being watched, for causes unknown.
