Changeset 22560

Show
Ignore:
Timestamp:
10/10/08 01:03:49 (6 weeks ago)
Author:
putter
Message:

[elfish/on_sbcl] Self-compiles.
Undef and bool boxing. Dispatch and misc fixes. Slower.
Doesn't quite compile the p5 version.
[STD_red] Improved --format=cl string and nil dumping.
[elf_h] Yet more missing argument fixes.

Location:
misc
Files:
9 modified

Legend:

Unmodified
Added
Removed
  • misc/STD_red/match.rb

    r22360 r22560  
    157157end 
    158158class String 
    159   def to_dump1; inspect.gsub(/\n/,"\n").gsub(/\t/,"\t") end 
     159  def to_dump1; '"'+gsub(/([\\"])/){|w|"\\#{w}"}+'"' end 
    160160end 
    161161class Symbol 
     
    163163end 
    164164class FalseClass 
    165   def to_dump1; 'nil' end 
     165  def to_dump1; ':false' end 
    166166end 
    167167class Fixnum 
     
    171171  def to_dump1 
    172172    b = as_b ? '1' : '0' 
    173     s = '"'+str.gsub(/([\\"])/){|w|"\\#{w}"}+'"' 
     173    s = str.to_dump1 
    174174    h = as_h.map{|k,v| 
    175175      vs = v.to_dump1 
  • misc/elf/elf_h

    r22528 r22560  
    114114  sub ucfirst  { CORE::ucfirst($_[0]); } 
    115115  sub unpack   { CORE::unpack($_[0], @_[1..$#_]); } 
    116   sub quotemet { CORE::quotemeta($_[0]); } 
    117116  sub undef    { $_[0] = undef } 
    118117  sub m        { [ $_[0] =~ m{$_[1]} ] } 
     
    22182217(do{IRx1::For->newp($m, irbuild_ir($m->hash()->{"modifier_expr"}), $blackboard::statement_expr)})}; 
    22192218my $construct_statement_control_58while = sub {my($m)=@_; 
    2220 (do{IRx1::Loop->newp($m, irbuild_ir($m->hash()->{"expr"}), irbuild_ir($m->hash()->{"block"}))})}; 
     2219(do{IRx1::Loop->newp($m, irbuild_ir($m->hash()->{"expr"}), irbuild_ir($m->hash()->{"block"}), GLOBAL::undef(), GLOBAL::undef())})}; 
    22212220my $construct_statement_mod_loop_58while = sub {my($m)=@_; 
    2222 (do{IRx1::Loop->newp($m, irbuild_ir($m->hash()->{"modifier_expr"}), $blackboard::statement_expr)})}; 
     2221(do{IRx1::Loop->newp($m, irbuild_ir($m->hash()->{"modifier_expr"}), $blackboard::statement_expr, GLOBAL::undef(), GLOBAL::undef())})}; 
    22232222my $construct_statement_control_58until = sub {my($m)=@_; 
    22242223(do{my $test = IRx1::Apply->newp($m, "not", IRx1::Capture->newp1($m, [irbuild_ir($m->hash()->{"expr"})])); 
    2225 IRx1::Loop->newp($m, $test, irbuild_ir($m->hash()->{"block"}))})}; 
     2224IRx1::Loop->newp($m, $test, irbuild_ir($m->hash()->{"block"}), GLOBAL::undef(), GLOBAL::undef())})}; 
    22262225my $construct_statement_mod_loop_58until = sub {my($m)=@_; 
    22272226(do{my $test = IRx1::Apply->newp($m, "not", IRx1::Capture->newp1($m, [irbuild_ir($m->hash()->{"modifier_expr"})])); 
    2228 IRx1::Loop->newp($m, $test, $blackboard::statement_expr)})}; 
     2227IRx1::Loop->newp($m, $test, $blackboard::statement_expr, GLOBAL::undef(), GLOBAL::undef())})}; 
    22292228my $construct_statement_control_58loop = sub {my($m)=@_; 
    22302229(do{my $e1 = irbuild_ir($m->hash()->{"loop_eee"}->hash()->{"loop_e1"}); 
     
    22322231my $e3 = irbuild_ir($m->hash()->{"loop_eee"}->hash()->{"loop_e3"}); 
    22332232my $block = irbuild_ir($m->hash()->{"loop_block"}); 
    2234 my $body = IRx1::Loop->newp($m, $e2, IRx1::Block->newp($m, [$block, $e3])); 
     2233my $body = IRx1::Loop->newp($m, $e2, IRx1::Block->newp($m, [$block, $e3]), GLOBAL::undef(), GLOBAL::undef()); 
    22352234IRx1::Block->newp($m, [$e1, $body])})}; 
    22362235my $construct_statement_control_58if = sub {my($m)=@_; 
     
    29572956"}) 
    29582957}})}; 
    2959 sub prelude{my $self=CORE::shift;my($n)=@_; 
    2960 (do{((("\#\!\/usr\/bin\/env\ perl\ 
     2958sub prelude{my $self=CORE::shift;(do{((("\#\!\/usr\/bin\/env\ perl\ 
    29612959use\ strict\;\ 
    29622960no\ strict\ \"subs\"\;\ \#\ XXX\ remove\ once\ Type\-names\ are\ quoted\.\ \#\ say\ Int\.isa\(Any\)\ 
     
    30553053\ \ sub\ ucfirst\ \ \{\ CORE\:\:ucfirst\(\$_\[0\]\)\;\ \}\ 
    30563054\ \ sub\ unpack\ \ \ \{\ CORE\:\:unpack\(\$_\[0\]\,\ \@_\[1\.\.\$\#_\]\)\;\ \}\ 
    3057 \ \ sub\ quotemet\ \{\ CORE\:\:quotemeta\(\$_\[0\]\)\;\ \}\ 
    30583055\ \ sub\ undef\ \ \ \ \{\ \$_\[0\]\ \=\ undef\ \}\ 
    30593056\ \ sub\ m\ \ \ \ \ \ \ \ \{\ \[\ \$_\[0\]\ \=\~\ m\{\$_\[1\]\}\ \]\ \}\ 
  • misc/elf/elf_h_src/EmitSimpleP5.pm

    r22528 r22560  
    4949    } 
    5050  }; 
    51   method prelude ($n) { 
     51  method prelude { 
    5252  '#!/usr/bin/env perl 
    5353use strict; 
     
    147147  sub ucfirst  { CORE::ucfirst($_[0]); } 
    148148  sub unpack   { CORE::unpack($_[0], @_[1..$#_]); } 
    149   sub quotemet { CORE::quotemeta($_[0]); } 
    150149  sub undef    { $_[0] = undef } 
    151150  sub m        { [ $_[0] =~ m{$_[1]} ] } 
  • misc/elf/elf_h_src/IRx1_FromAST.pm

    r22528 r22560  
    343343 
    344344    my $construct_statement_control_58while = sub ($m) { 
    345       IRx1::Loop.newp($m,irbuild_ir($m.hash{'expr'}),irbuild_ir($m.hash{'block'})); 
     345      IRx1::Loop.newp($m,irbuild_ir($m.hash{'expr'}),irbuild_ir($m.hash{'block'}),undef,undef); 
    346346    }; 
    347347 
    348348    my $construct_statement_mod_loop_58while = sub ($m) { 
    349       IRx1::Loop.newp($m,irbuild_ir($m.hash{'modifier_expr'}),$blackboard::statement_expr); 
     349      IRx1::Loop.newp($m,irbuild_ir($m.hash{'modifier_expr'}),$blackboard::statement_expr,undef,undef); 
    350350    }; 
    351351 
    352352    my $construct_statement_control_58until = sub ($m) { 
    353353      my $test = IRx1::Apply.newp($m,"not",IRx1::Capture.newp1($m,[irbuild_ir($m.hash{'expr'})])); 
    354 IRx1::Loop.newp($m,$test,irbuild_ir($m.hash{'block'})); 
     354IRx1::Loop.newp($m,$test,irbuild_ir($m.hash{'block'}),undef,undef); 
    355355    }; 
    356356 
    357357    my $construct_statement_mod_loop_58until = sub ($m) { 
    358358      my $test = IRx1::Apply.newp($m,"not",IRx1::Capture.newp1($m,[irbuild_ir($m.hash{'modifier_expr'})])); 
    359 IRx1::Loop.newp($m,$test,$blackboard::statement_expr); 
     359IRx1::Loop.newp($m,$test,$blackboard::statement_expr,undef,undef); 
    360360    }; 
    361361 
     
    365365my $e3 = irbuild_ir($m.hash{'loop_eee'}.hash{'loop_e3'}); 
    366366my $block = irbuild_ir($m.hash{'loop_block'}); 
    367 my $body = IRx1::Loop.newp($m,$e2,IRx1::Block.newp($m,[$block,$e3])); 
     367my $body = IRx1::Loop.newp($m,$e2,IRx1::Block.newp($m,[$block,$e3]),undef,undef); 
    368368IRx1::Block.newp($m,[$e1,$body]); 
    369369    }; 
  • misc/elf/elf_h_src/IRx1_FromAST_create.pl

    r22528 r22560  
    255255 
    256256statement_control:while 
    257 Loop.newp($m<expr>,$m<block>) 
     257Loop.newp($m<expr>,$m<block>,undef,undef) 
    258258 
    259259statement_mod_loop:while 
    260 Loop.newp($m<modifier_expr>,$blackboard::statement_expr) 
     260Loop.newp($m<modifier_expr>,$blackboard::statement_expr,undef,undef) 
    261261 
    262262statement_control:until 
    263263my $test = Apply.newp("not",Capture.newp1([$m<expr>])); 
    264 Loop.newp($test,$m<block>) 
     264Loop.newp($test,$m<block>,undef,undef) 
    265265 
    266266statement_mod_loop:until 
    267267my $test = Apply.newp("not",Capture.newp1([$m<modifier_expr>])); 
    268 Loop.newp($test,$blackboard::statement_expr) 
     268Loop.newp($test,$blackboard::statement_expr,undef,undef) 
    269269 
    270270statement_control:loop 
     
    273273my $e3 = $m<loop_eee><loop_e3>; 
    274274my $block = $m<loop_block>; 
    275 my $body = Loop.newp($e2,Block.newp([$block,$e3])); 
     275my $body = Loop.newp($e2,Block.newp([$block,$e3]),undef,undef); 
    276276Block.newp([$e1,$body]) 
    277277 
  • misc/elfish/on_sbcl/EmitSBCL.pm

    r22528 r22560  
    9191 
    9292(defmacro ncgf-defmethod (name sig &rest body) 
    93   (let* ((n (1+ *maximum-number-of-dispatch-affecting-variables*)) 
    94          (n-1 (1- n)) 
    95          (vars (parameters-in-lambda-list sig)) 
    96          (len (length vars)) 
    97          (real-vars (subseq vars 0 (min n-1 len))) 
    98          (bounds-var (list (if (find \'&rest sig) 
    99                                (gensym) 
    100                              `(,(gensym) ,(class-of nil))))) 
    101          (pad-vars (n-gensyms (max 0 (- n-1 len)))) 
    102          (dispatch-vars (concatenate \'list real-vars bounds-var pad-vars)) 
     93  (let* ((n *maximum-number-of-dispatch-affecting-variables*) 
     94         (params (parameters-in-lambda-list sig)) 
     95         (arity (length params)) 
     96         (real-dispatch-params (subseq params 0 (min arity n))) 
     97         (an-arity-check-var (gensym)) 
     98         (an-arity-check-param (if (find \'&rest sig) 
     99                                   an-arity-check-var 
     100                                 (list an-arity-check-var \'null))) 
     101         (a-noop-var (gensym)) 
     102         (pad-vars (n-gensyms (max 0 (- n arity)))) 
     103         (fake-dispatch-params 
     104          (cond ((> arity n) (list a-noop-var)) 
     105                (t (cons an-arity-check-param pad-vars)))) 
     106         (fake-vars 
     107          (cond ((> arity n) (list a-noop-var)) 
     108                (t (cons an-arity-check-var pad-vars)))) 
     109         (dispatch-params (concatenate \'list 
     110                                       real-dispatch-params 
     111                                       fake-dispatch-params)) 
    103112         (typeless-sig (map \'list (lambda (p) (if (listp p) (car p) p)) sig)) 
    104          (def `(defmethod ,name (args ,@dispatch-vars) 
    105                  (declare (ignore ,@pad-vars)) 
     113         (def `(defmethod ,name (args ,@dispatch-params) 
     114                 (declare (ignore ,@fake-vars)) 
    106115                 (destructuring-bind ,typeless-sig args 
    107116                                     ,@body)))) 
     
    237246;; predecls 
    238247(defclass |Any/cls| () ()) 
     248(defclass |Undef/cls| () ()) 
    239249(defclass |Bool/cls| () ()) 
    240250(defclass |Int/cls| () ()) 
    241251(defclass |Num/cls| () ()) 
    242252(defclass |Str/cls| () ()) 
     253 
     254;; Undef 
     255(defparameter |Undef::/co| nil) 
     256(defun undef () |Undef::/co|) 
     257(defgeneric defined-p (x)) 
     258(defmethod defined-p (x) (declare (ignore x)) t) 
     259(defmethod defined-p ((x |Undef/cls|)) (declare (ignore x)) nil) 
     260;; Kludge until a Prim::null is available. 
     261(dm |M::make_ir_from_Match_tree| ((self null)) (undef)) 
     262 
     263;; Bool 
     264(pkg-declare "class" "False" \'|Bool/cls|) 
     265(pkg-declare "class" "True" \'|Bool/cls|) 
     266(defun true () |True::/co|) 
     267(defun false () |False::/co|) 
    243268 
    244269;; 
     
    258283  (reduce #\'append 
    259284          (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))) 
     285                    (if (listp e) e (list e))) 
    265286                  args))) 
    266287 
    267 ;; 
     288;; Any 
    268289(dm |M::new| ((co |Any/cls|) &rest argl) 
    269   (declare (ignorable argl)) 
     290  (declare (ignore argl)) 
    270291  (set-slots (make-instance (class-of co)) argl)) 
    271292 
     
    274295      (UP (can-p name self)))) 
    275296 
    276 ;; Undef is still being kludged as nil.  And Bools. 
    277 (defmacro undef () nil) 
    278 (dm |M::make_ir_from_Match_tree| ((self null) ) (block __f__ (let () self))) 
    279 (dm |M::isa| ((x null) str) (declare (ignorable x)) (equal (S str) "Undef")) 
    280 (dm |M::Str| ((x symbol)) (UP (symbol-name x))) ;X for t 
    281  
    282297 ;;Array.new is defined here to a avoid cyclic dependency on *@args. 
    283298(pkg-declare "class" "Array" \'|Any/cls|) 
    284299(dm |M::new| ((co |Array/cls|) &rest argl) 
    285   (declare (ignorable co)) 
     300  (declare (ignore co)) 
    286301  (let ((inst (make-instance \'|Array/cls|))) 
    287302    (setf (slot-value inst \'|Array::._native_|) 
     
    289304    inst)) 
    290305 
    291 ;; Hack until Str, Int, Num, etc are p6 objects. 
    292 (dm |M::Str| ((s string) &rest argl) (declare (ignorable argl)) s) 
    293 (dm |M::Str| ((n number) &rest argl) (declare (ignorable argl)) (write-to-string n)) 
    294 (dm |M::WHAT| ((s string) &rest argl) (declare (ignorable s argl)) "str") 
    295 (dm |M::WHAT| ((n number) &rest argl) (declare (ignorable n argl)) "num") 
    296  
    297 (dm |M::Str| ((x null) &rest argl) (declare (ignorable x argl)) "") 
    298 (dm |M::WHAT| ((x null) &rest argl) (declare (ignorable x argl)) "Undef") 
    299 (dm |M::substr| ((s string) from len) (subseq s from (+ from len))) 
    300  
     306;; Primitive Str, Int, Num. 
     307;(dm |M::WHAT| ((s string)) "str") 
     308;(dm |M::WHAT| ((n integer)) "int") 
     309;(dm |M::WHAT| ((n number)) "num") 
     310;(dm |M::Str| ((s string)) (UP s)) 
     311;(dm |M::Str| ((n number)) (UP (write-to-string n))) 
     312;(dm |M::substr| ((s string) from len) (subseq s from (+ from len))) 
    301313 
    302314;; Muffle warnings at compile and runtimes. 
    303315;(declaim (sb-ext:muffle-conditions style-warning)) 
    304 (declaim (sb-ext:muffle-conditions warning)) 
     316;(declaim (sb-ext:muffle-conditions warning)) 
    305317 
    306318;(defparameter sb-ext:*muffled-warnings* style-warning) ;In sbcl-1.0.20 . 
     
    310322 
    311323;; UP 
    312 ;(defgeneric UP (x)) 
    313 (defmethod UP ((x null)) nil) 
    314 (defmethod UP ((x symbol)) x) 
     324(defmethod UP ((x null)) |False::/co|) 
     325(defmethod UP ((x symbol)) (if (eq x t) |True::/co| (trigger-debug))) 
    315326(defmethod UP ((x integer)) (fc #\'|M::new| |Int::/co| x)) 
    316327(defmethod UP ((x number)) (fc #\'|M::new| |Num::/co| x)) 
    317328(defmethod UP ((x string)) (fc #\'|M::new| |Str::/co| x)) 
    318 (defmethod UP ((bug |Str/cls|)) (write (S bug)) (die)) 
     329;(defmethod UP ((x |Any/cls|)) x) ; For eventual mixed boxing. 
    319330;; new- 
    320331(defun new-Array (lst) (ap #\'|M::new| (cons |Array::/co| lst))) 
     
    323334;; to-b 
    324335(defgeneric to-b (x)) 
    325 (defmethod to-b (x) t) 
    326 (defmethod to-b ((x null)) nil) 
    327 (defmethod to-b ((x symbol)) t) ;for t. #X should check. 
    328 (defmethod to-b ((x string)) (if (equal x "") nil t)) 
    329 (defmethod to-b ((x number)) (if (= x 0) nil t)) 
     336(defmethod to-b (x) t) ; Eg, currently unboxed Code. 
     337(defmethod to-b ((x null)) nil) ;X shouldnt be needed. 
     338(defmethod to-b ((x string)) (if (equal x "") nil t)) ;X shouldnt be needed. 
     339(defmethod to-b ((x number)) (if (= x 0) nil t)) ;X shouldnt be needed. 
     340(defmethod to-b ((x |Any/cls|)) (to-b (fc #\'|M::Bool| x))) 
     341(defmethod to-b ((x |Undef/cls|)) nil) 
    330342(defmethod to-b ((x |Bool/cls|)) (slot-value x \'|Bool::._native_|)) 
    331 (defmethod to-b ((x |Any/cls|)) (to-b (fc #\'|M::Bool| x))) 
     343(defmethod to-b ((x |False/cls|)) nil) 
     344(defmethod to-b ((x |True/cls|)) t) 
     345(defmethod to-b ((x |Int/cls|)) (not (= (slot-value x \'|Int::._native_|) 0))) 
     346(defmethod to-b ((x |Num/cls|)) (not (= (slot-value x \'|Num::._native_|) 0))) 
    332347;; to-n 
    333348(defgeneric to-n (x)) 
    334 (defmethod to-s ((x null)) 0) ;X unboxed Undef 
    335 (defmethod to-n ((x number)) x) 
     349(defmethod to-n ((x number)) x) ; For Int.new(). 
     350(defmethod to-n ((x |Any/cls|)) (to-n (fc #\'|M::Num| x))) 
    336351(defmethod to-n ((x |Int/cls|)) (slot-value x \'|Int::._native_|)) 
    337352(defmethod to-n ((x |Num/cls|)) (slot-value x \'|Num::._native_|)) 
    338 (defmethod to-n ((x |Any/cls|)) (to-n (fc #\'|M::Num| x))) 
    339353;; to-s 
    340354(defgeneric to-s (x)) 
    341 (defmethod to-s ((x null)) "") ;X unboxed Undef 
    342 (defmethod to-s ((x string)) x) 
     355(defmethod to-s ((x string)) x) ; For Str.new(). 
    343356(defmethod to-s ((x |Str/cls|)) (slot-value x \'|Str::._native_|)) 
    344357(defmethod to-s ((x |Any/cls|)) (to-s (fc #\'|M::Str| x))) 
     
    356369  (let* ((pat "(?:[^\\\\\\\\$]|\\\\\\\\.|.\\\\z|\\\\$[^{1])+|\\\\$1|\\\\$\\\\{1}") 
    357370         (parts (ppcre::all-matches-as-strings pat rep))) 
    358     (write rep)(write parts) 
    359371    (assert (equal (length rep) 
    360372                   (length (apply #\'concatenate (cons \'string parts))))) 
     
    366378     parts))) 
    367379 
    368 ;; short-circuiting logicals 
     380;; short-circuiting logicals - codomain is actually domain+t,nil. :/ 
    369381(defmacro or6 (&rest args) 
    370382  (if (null args) 
    371       \'nil 
     383      `(undef) 
    372384    (let ((sym (gensym))) 
    373385      `(let ((,sym ,(car args))) 
    374386         (if (or ,(null (cdr args)) (to-b ,sym)) ,sym (or6 ,@(cdr args))))))) 
    375387(defmacro and6 (&rest args) 
    376   (cond ((null args) t) 
     388  (cond ((null args) `(true)) 
    377389        ((null (cdr args)) (car args)) 
    378390        (t (let ((sym (gensym))) 
    379              `(let ((,sym ,(car args))) (if (not (to-b ,sym)) nil (and6 ,@(cdr args)))) 
     391             `(let ((,sym ,(car args))) (if (not (to-b ,sym)) (undef) (and6 ,@(cdr args)))) 
    380392             )))) 
    381393    
     
    435447       elsif $scope eq 'temp' { 
    436448         my $v = $.e($d.var); 
    437          $lexicals = $lexicals ~ "("~$v~" (if (boundp '"~$v~") "~$v~")) "; 
     449         $lexicals = $lexicals ~ "("~$v~" (if (boundp '"~$v~") "~$v~" (undef))) "; 
    438450       } 
    439451    }); 
     
    535547    } 
    536548    else { 
    537       if ($sigil eq '$') { $default = 'nil' }#X 
     549      if ($sigil eq '$') { $default = '(undef)' } 
    538550      if ($sigil eq '@') { $default = $.emit_array('') } 
    539551      if ($sigil eq '%') { $default = $.emit_hash('') } 
     
    563575      if $default { $evar_d = '(setq '~$evar~' '~$default~')' } 
    564576      $whiteboard::declares.push("(declare (special "~$evar~"))\n"); 
    565       my $init = "(unless (boundp '"~$evar~") (setq "~$evar~" nil))\n"; 
     577      my $init = "(unless (boundp '"~$evar~") (setq "~$evar~" (undef)))\n"; 
    566578      $whiteboard::block_header.push($init); 
    567579      $evar_d; 
  • misc/elfish/on_sbcl/Makefile

    r22528 r22560  
    1010elfcl:: have_parser_cache 
    1111        ${ELF} -I ${ELFDIR} EmitSBCL.pm -x -o elfcl Elf_SBCL.pm 
    12         time ${SBCL} --eval '(compile-file "elfcl")' --eval '(quit)' >& elfcl.out 
     12        /usr/bin/time ${SBCL} --eval '(compile-file "elfcl")' --eval '(quit)' >& elfcl.out 
    1313        chmod a+x elfcl 
    1414 
     
    5656        # Create a CL elf. 
    5757        ${ELF} -I ${ELFDIR} EmitSBCL.pm -x -o ${TMP}/b0 Elf_SBCL.pm 
    58         # Compile it, with output to log. 
     58        # Compile the CL elf. 
    5959        ${SBCL} --disable-debugger --eval '(compile-file "${TMP}/b0")' --eval '(quit)' > ${TMP}/b0.log 2>&1 
    60         # Run it. 
     60        # Run the CL elf. 
    6161        chmod a+x ${TMP}/b0 
    62         ${TMP}/b0 -e 'say 3' 
    63         # Check CL bootstrap. 
    64         ${TMP}/b0 -I ${ELFDIR} -x -o ${TMP}/b1 Elf_SBCL.pm 
     62        ${TMP}/b0 -e 'say "hello"' 2>/dev/null 
     63        # Check bootstrap - CL elf compiles a CL elf. 
     64        ${TMP}/b0 -I ${ELFDIR} -x -o ${TMP}/b1 Elf_SBCL.pm 2>/dev/null 
     65        # Was it identical? 
    6566        diff ${TMP}/b0 ${TMP}/b1 
    66         # Compile a p5 elf with a CL one. 
    67         ${TMP}/b0 -I ${ELFDIR} -e 'use EmitSimpleP5' -x -o ${TMP}/a1 -e 'use Elf' 
     67        # Check cross-bootstrap - CL elf compiles a P5 elf. 
     68        ${TMP}/b0 -I ${ELFDIR} -e 'use EmitSimpleP5' -x -o ${TMP}/a1 -e 'use Elf' 2>/dev/null 
    6869        # Was it identical? 
    6970        diff ${TMP}/a0 ${TMP}/a1 
  • misc/elfish/on_sbcl/PrimitivesSBCL.pm

    r22528 r22560  
    5252  sub primitive_write_to_string ($x) is cl {' (UP (write-to-string |$x|)) '}; 
    5353 
    54   sub undef () is cl {' 
    55     nil ;XX 
    56   '} 
     54  sub undef () is cl {' (undef) '} 
    5755 
    5856  multi infix:<+> ($a,$b) is cl {' (UP (+ (N |$a|) (N |$b|))) '} 
     
    9492 
    9593  multi exit ($status) is cl {' (sb-unix:unix-exit (N |$status|)) '} 
     94#  multi exit ($status) {} 
    9695  multi die ($msg) { say $msg; exit(1); } 
    9796 
     
    104103  multi unlink_ ($filename) is cl {' (sb-unix:unix-unlink (S |$filename|)) '} 
    105104  multi not ($x) { if $x { undef } else { 1 } } 
    106   multi defined ($x) is cl {' (UP (if |$x| 1 nil)) '} ;#X undef as nil 
     105  multi defined ($x) is cl {' (UP (defined-p |$x|)) '} 
    107106  multi substr($s,$offset,$length) { $s.substr($offset,$length) } 
    108107} 
     
    122121      (labels 
    123122       ((undump (node) 
    124            (cond ((null node) (undef)) 
     123           (cond ((null node) nil) 
     124                 ((eq :false node) (undef)) 
    125125                 ((listp node) 
    126126                  (let ((args (mapcar #\'undump (cdr node)))) 
     
    156156    exit(0); 
    157157  } 
     158  sub chmod_exe ($file) is cl {' 
     159    (sb-posix:chmod (S |$file|) 
     160                    (logior sb-posix::s-irusr sb-posix::s-iwusr sb-posix::s-ixusr)) 
     161  '} 
     162 
    158163  sub module_require ($module) { 
    159164    my $file = find_required_module($module); 
     
    185190    eval_perl6($code,$env); 
    186191  } 
    187  
    188192} 
    189193# regexp elf bootstrap primitives 
     
    203207  '} 
    204208} 
    205  
     209# For the Elf P5. 
     210package GLOBAL { 
     211  sub mangle_name ($name) is cl {' 
     212     ; $name =~ s/([^\w])/"_".CORE::ord($1)/eg; 
     213     (UP (ppcre::regex-replace-all "([^\\\\w])" (S |$name|) 
     214            (lambda (match g1) 
     215              (concatenate \'string "_" (write-to-string (char-code (aref g1 0))))) 
     216            :simple-calls t)) 
     217  '} 
     218  #sub quotemeta ($str) { $str.re_gsub_pat('([^\\w])','\\\\$1') } 
     219  sub quotemeta ($str) is cl {' ;#XXX flee backslash insanity 
     220     (UP (ppcre::regex-replace-all "([^\\\\w])" (S |$str|) 
     221            (lambda (match g1) (concatenate \'string "\\\\" g1)) 
     222            :simple-calls t)) 
     223  '} 
     224} 
    206225 
    207226package Main { 
     
    253272  method split ($pat) is cl {' 
    254273    (let ((s (slot-value self \'|Str::._native_|))) 
    255       (new-Array (ppcre::split (S |$pat|) s))) 
     274      (new-Array (mapcar (lambda (x) (UP x)) 
     275                         (ppcre::split (S |$pat|) s)))) 
    256276  '} 
    257277  method substr ($offset,$length) is cl {' 
     
    340360  method reverse () is cl {' 
    341361    (let* ((a (slot-value self \'|Array::._native_|))) 
    342       (new-Array (reverse a))) 
     362      (new-Array (coerce (reverse a) \'list ))) ;X 
    343363  '} 
    344364} 
     
    400420    (let ((hk (slot-value self \'|Hash::._keys_|)) 
    401421          (hv (slot-value self \'|Hash::._values_|))) 
    402       (if (nth-value 1 (gethash (cl-hash |$key|) hk)) t nil)) 
     422      (UP (if (nth-value 1 (gethash (cl-hash |$key|) hk)) t nil))) 
    403423  '} 
    404424  method delete ($key) is cl {' 
     
    448468 
    449469# .Num() 
     470class Undef { method Num () { 0 } } 
    450471class Int   { method Num () { self } } 
    451472class Num   { method Num () { self } } 
     
    457478# .Str() 
    458479class Any   { method Str () { primitive_write_to_string(self) } } 
     480class Undef { method Str () { "" } } 
     481class Bool  { method Str () { if self { "true" } else { "false " } } } 
     482class True  { method Str () { "true" } } 
     483class False { method Str () { "false" } } 
    459484class Int   { method Str () { primitive_write_to_string(self._native_) } } 
    460485class Num   { method Str () { primitive_write_to_string(self._native_) } } 
  • misc/elfish/on_sbcl/README

    r22522 r22560  
    6969  # This dropped to 1/2x with Int's. 
    7070  # This dropped to 1/4x while not being watched, for causes unknown. 
     71  # This dropped to 1/5x with boxed undef and booleans.