- Timestamp:
- 10/10/08 01:03:49 (3 months ago)
- Location:
- misc
- Files:
-
- 9 modified
-
STD_red/match.rb (modified) (3 diffs)
-
elf/elf_h (modified) (5 diffs)
-
elf/elf_h_src/EmitSimpleP5.pm (modified) (2 diffs)
-
elf/elf_h_src/IRx1_FromAST.pm (modified) (2 diffs)
-
elf/elf_h_src/IRx1_FromAST_create.pl (modified) (2 diffs)
-
elfish/on_sbcl/EmitSBCL.pm (modified) (12 diffs)
-
elfish/on_sbcl/Makefile (modified) (2 diffs)
-
elfish/on_sbcl/PrimitivesSBCL.pm (modified) (12 diffs)
-
elfish/on_sbcl/README (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
misc/STD_red/match.rb
r22360 r22560 157 157 end 158 158 class String 159 def to_dump1; inspect.gsub(/\n/,"\n").gsub(/\t/,"\t")end159 def to_dump1; '"'+gsub(/([\\"])/){|w|"\\#{w}"}+'"' end 160 160 end 161 161 class Symbol … … 163 163 end 164 164 class FalseClass 165 def to_dump1; ' nil' end165 def to_dump1; ':false' end 166 166 end 167 167 class Fixnum … … 171 171 def to_dump1 172 172 b = as_b ? '1' : '0' 173 s = '"'+str.gsub(/([\\"])/){|w|"\\#{w}"}+'"'173 s = str.to_dump1 174 174 h = as_h.map{|k,v| 175 175 vs = v.to_dump1 -
misc/elf/elf_h
r22528 r22560 114 114 sub ucfirst { CORE::ucfirst($_[0]); } 115 115 sub unpack { CORE::unpack($_[0], @_[1..$#_]); } 116 sub quotemet { CORE::quotemeta($_[0]); }117 116 sub undef { $_[0] = undef } 118 117 sub m { [ $_[0] =~ m{$_[1]} ] } … … 2218 2217 (do{IRx1::For->newp($m, irbuild_ir($m->hash()->{"modifier_expr"}), $blackboard::statement_expr)})}; 2219 2218 my $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())})}; 2221 2220 my $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())})}; 2223 2222 my $construct_statement_control_58until = sub {my($m)=@_; 2224 2223 (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"}) )})};2224 IRx1::Loop->newp($m, $test, irbuild_ir($m->hash()->{"block"}), GLOBAL::undef(), GLOBAL::undef())})}; 2226 2225 my $construct_statement_mod_loop_58until = sub {my($m)=@_; 2227 2226 (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 )})};2227 IRx1::Loop->newp($m, $test, $blackboard::statement_expr, GLOBAL::undef(), GLOBAL::undef())})}; 2229 2228 my $construct_statement_control_58loop = sub {my($m)=@_; 2230 2229 (do{my $e1 = irbuild_ir($m->hash()->{"loop_eee"}->hash()->{"loop_e1"}); … … 2232 2231 my $e3 = irbuild_ir($m->hash()->{"loop_eee"}->hash()->{"loop_e3"}); 2233 2232 my $block = irbuild_ir($m->hash()->{"loop_block"}); 2234 my $body = IRx1::Loop->newp($m, $e2, IRx1::Block->newp($m, [$block, $e3]) );2233 my $body = IRx1::Loop->newp($m, $e2, IRx1::Block->newp($m, [$block, $e3]), GLOBAL::undef(), GLOBAL::undef()); 2235 2234 IRx1::Block->newp($m, [$e1, $body])})}; 2236 2235 my $construct_statement_control_58if = sub {my($m)=@_; … … 2957 2956 "}) 2958 2957 }})}; 2959 sub prelude{my $self=CORE::shift;my($n)=@_; 2960 (do{((("\#\!\/usr\/bin\/env\ perl\ 2958 sub prelude{my $self=CORE::shift;(do{((("\#\!\/usr\/bin\/env\ perl\ 2961 2959 use\ strict\;\ 2962 2960 no\ strict\ \"subs\"\;\ \#\ XXX\ remove\ once\ Type\-names\ are\ quoted\.\ \#\ say\ Int\.isa\(Any\)\ … … 3055 3053 \ \ sub\ ucfirst\ \ \{\ CORE\:\:ucfirst\(\$_\[0\]\)\;\ \}\ 3056 3054 \ \ sub\ unpack\ \ \ \{\ CORE\:\:unpack\(\$_\[0\]\,\ \@_\[1\.\.\$\#_\]\)\;\ \}\ 3057 \ \ sub\ quotemet\ \{\ CORE\:\:quotemeta\(\$_\[0\]\)\;\ \}\3058 3055 \ \ sub\ undef\ \ \ \ \{\ \$_\[0\]\ \=\ undef\ \}\ 3059 3056 \ \ sub\ m\ \ \ \ \ \ \ \ \{\ \[\ \$_\[0\]\ \=\~\ m\{\$_\[1\]\}\ \]\ \}\ -
misc/elf/elf_h_src/EmitSimpleP5.pm
r22528 r22560 49 49 } 50 50 }; 51 method prelude ($n){51 method prelude { 52 52 '#!/usr/bin/env perl 53 53 use strict; … … 147 147 sub ucfirst { CORE::ucfirst($_[0]); } 148 148 sub unpack { CORE::unpack($_[0], @_[1..$#_]); } 149 sub quotemet { CORE::quotemeta($_[0]); }150 149 sub undef { $_[0] = undef } 151 150 sub m { [ $_[0] =~ m{$_[1]} ] } -
misc/elf/elf_h_src/IRx1_FromAST.pm
r22528 r22560 343 343 344 344 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); 346 346 }; 347 347 348 348 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); 350 350 }; 351 351 352 352 my $construct_statement_control_58until = sub ($m) { 353 353 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'}) );354 IRx1::Loop.newp($m,$test,irbuild_ir($m.hash{'block'}),undef,undef); 355 355 }; 356 356 357 357 my $construct_statement_mod_loop_58until = sub ($m) { 358 358 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 );359 IRx1::Loop.newp($m,$test,$blackboard::statement_expr,undef,undef); 360 360 }; 361 361 … … 365 365 my $e3 = irbuild_ir($m.hash{'loop_eee'}.hash{'loop_e3'}); 366 366 my $block = irbuild_ir($m.hash{'loop_block'}); 367 my $body = IRx1::Loop.newp($m,$e2,IRx1::Block.newp($m,[$block,$e3]) );367 my $body = IRx1::Loop.newp($m,$e2,IRx1::Block.newp($m,[$block,$e3]),undef,undef); 368 368 IRx1::Block.newp($m,[$e1,$body]); 369 369 }; -
misc/elf/elf_h_src/IRx1_FromAST_create.pl
r22528 r22560 255 255 256 256 statement_control:while 257 Loop.newp($m<expr>,$m<block> )257 Loop.newp($m<expr>,$m<block>,undef,undef) 258 258 259 259 statement_mod_loop:while 260 Loop.newp($m<modifier_expr>,$blackboard::statement_expr )260 Loop.newp($m<modifier_expr>,$blackboard::statement_expr,undef,undef) 261 261 262 262 statement_control:until 263 263 my $test = Apply.newp("not",Capture.newp1([$m<expr>])); 264 Loop.newp($test,$m<block> )264 Loop.newp($test,$m<block>,undef,undef) 265 265 266 266 statement_mod_loop:until 267 267 my $test = Apply.newp("not",Capture.newp1([$m<modifier_expr>])); 268 Loop.newp($test,$blackboard::statement_expr )268 Loop.newp($test,$blackboard::statement_expr,undef,undef) 269 269 270 270 statement_control:loop … … 273 273 my $e3 = $m<loop_eee><loop_e3>; 274 274 my $block = $m<loop_block>; 275 my $body = Loop.newp($e2,Block.newp([$block,$e3]) );275 my $body = Loop.newp($e2,Block.newp([$block,$e3]),undef,undef); 276 276 Block.newp([$e1,$body]) 277 277 -
misc/elfish/on_sbcl/EmitSBCL.pm
r22528 r22560 91 91 92 92 (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)) 103 112 (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)) 106 115 (destructuring-bind ,typeless-sig args 107 116 ,@body)))) … … 237 246 ;; predecls 238 247 (defclass |Any/cls| () ()) 248 (defclass |Undef/cls| () ()) 239 249 (defclass |Bool/cls| () ()) 240 250 (defclass |Int/cls| () ()) 241 251 (defclass |Num/cls| () ()) 242 252 (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|) 243 268 244 269 ;; … … 258 283 (reduce #\'append 259 284 (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))) 265 286 args))) 266 287 267 ;; 288 ;; Any 268 289 (dm |M::new| ((co |Any/cls|) &rest argl) 269 (declare (ignor able argl))290 (declare (ignore argl)) 270 291 (set-slots (make-instance (class-of co)) argl)) 271 292 … … 274 295 (UP (can-p name self)))) 275 296 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 t281 282 297 ;;Array.new is defined here to a avoid cyclic dependency on *@args. 283 298 (pkg-declare "class" "Array" \'|Any/cls|) 284 299 (dm |M::new| ((co |Array/cls|) &rest argl) 285 (declare (ignor able co))300 (declare (ignore co)) 286 301 (let ((inst (make-instance \'|Array/cls|))) 287 302 (setf (slot-value inst \'|Array::._native_|) … … 289 304 inst)) 290 305 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))) 301 313 302 314 ;; Muffle warnings at compile and runtimes. 303 315 ;(declaim (sb-ext:muffle-conditions style-warning)) 304 (declaim (sb-ext:muffle-conditions warning))316 ;(declaim (sb-ext:muffle-conditions warning)) 305 317 306 318 ;(defparameter sb-ext:*muffled-warnings* style-warning) ;In sbcl-1.0.20 . … … 310 322 311 323 ;; 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))) 315 326 (defmethod UP ((x integer)) (fc #\'|M::new| |Int::/co| x)) 316 327 (defmethod UP ((x number)) (fc #\'|M::new| |Num::/co| x)) 317 328 (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. 319 330 ;; new- 320 331 (defun new-Array (lst) (ap #\'|M::new| (cons |Array::/co| lst))) … … 323 334 ;; to-b 324 335 (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) 330 342 (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))) 332 347 ;; to-n 333 348 (defgeneric to-n (x)) 334 (defmethod to- s ((x null)) 0) ;X unboxed Undef335 (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))) 336 351 (defmethod to-n ((x |Int/cls|)) (slot-value x \'|Int::._native_|)) 337 352 (defmethod to-n ((x |Num/cls|)) (slot-value x \'|Num::._native_|)) 338 (defmethod to-n ((x |Any/cls|)) (to-n (fc #\'|M::Num| x)))339 353 ;; to-s 340 354 (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(). 343 356 (defmethod to-s ((x |Str/cls|)) (slot-value x \'|Str::._native_|)) 344 357 (defmethod to-s ((x |Any/cls|)) (to-s (fc #\'|M::Str| x))) … … 356 369 (let* ((pat "(?:[^\\\\\\\\$]|\\\\\\\\.|.\\\\z|\\\\$[^{1])+|\\\\$1|\\\\$\\\\{1}") 357 370 (parts (ppcre::all-matches-as-strings pat rep))) 358 (write rep)(write parts)359 371 (assert (equal (length rep) 360 372 (length (apply #\'concatenate (cons \'string parts))))) … … 366 378 parts))) 367 379 368 ;; short-circuiting logicals 380 ;; short-circuiting logicals - codomain is actually domain+t,nil. :/ 369 381 (defmacro or6 (&rest args) 370 382 (if (null args) 371 \'nil383 `(undef) 372 384 (let ((sym (gensym))) 373 385 `(let ((,sym ,(car args))) 374 386 (if (or ,(null (cdr args)) (to-b ,sym)) ,sym (or6 ,@(cdr args))))))) 375 387 (defmacro and6 (&rest args) 376 (cond ((null args) t)388 (cond ((null args) `(true)) 377 389 ((null (cdr args)) (car args)) 378 390 (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)))) 380 392 )))) 381 393 … … 435 447 elsif $scope eq 'temp' { 436 448 my $v = $.e($d.var); 437 $lexicals = $lexicals ~ "("~$v~" (if (boundp '"~$v~") "~$v~" )) ";449 $lexicals = $lexicals ~ "("~$v~" (if (boundp '"~$v~") "~$v~" (undef))) "; 438 450 } 439 451 }); … … 535 547 } 536 548 else { 537 if ($sigil eq '$') { $default = ' nil' }#X549 if ($sigil eq '$') { $default = '(undef)' } 538 550 if ($sigil eq '@') { $default = $.emit_array('') } 539 551 if ($sigil eq '%') { $default = $.emit_hash('') } … … 563 575 if $default { $evar_d = '(setq '~$evar~' '~$default~')' } 564 576 $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"; 566 578 $whiteboard::block_header.push($init); 567 579 $evar_d; -
misc/elfish/on_sbcl/Makefile
r22528 r22560 10 10 elfcl:: have_parser_cache 11 11 ${ELF} -I ${ELFDIR} EmitSBCL.pm -x -o elfcl Elf_SBCL.pm 12 time ${SBCL} --eval '(compile-file "elfcl")' --eval '(quit)' >& elfcl.out12 /usr/bin/time ${SBCL} --eval '(compile-file "elfcl")' --eval '(quit)' >& elfcl.out 13 13 chmod a+x elfcl 14 14 … … 56 56 # Create a CL elf. 57 57 ${ELF} -I ${ELFDIR} EmitSBCL.pm -x -o ${TMP}/b0 Elf_SBCL.pm 58 # Compile it, with output to log.58 # Compile the CL elf. 59 59 ${SBCL} --disable-debugger --eval '(compile-file "${TMP}/b0")' --eval '(quit)' > ${TMP}/b0.log 2>&1 60 # Run it.60 # Run the CL elf. 61 61 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? 65 66 diff ${TMP}/b0 ${TMP}/b1 66 # C ompile 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 68 69 # Was it identical? 69 70 diff ${TMP}/a0 ${TMP}/a1 -
misc/elfish/on_sbcl/PrimitivesSBCL.pm
r22528 r22560 52 52 sub primitive_write_to_string ($x) is cl {' (UP (write-to-string |$x|)) '}; 53 53 54 sub undef () is cl {' 55 nil ;XX 56 '} 54 sub undef () is cl {' (undef) '} 57 55 58 56 multi infix:<+> ($a,$b) is cl {' (UP (+ (N |$a|) (N |$b|))) '} … … 94 92 95 93 multi exit ($status) is cl {' (sb-unix:unix-exit (N |$status|)) '} 94 # multi exit ($status) {} 96 95 multi die ($msg) { say $msg; exit(1); } 97 96 … … 104 103 multi unlink_ ($filename) is cl {' (sb-unix:unix-unlink (S |$filename|)) '} 105 104 multi not ($x) { if $x { undef } else { 1 } } 106 multi defined ($x) is cl {' (UP ( if |$x| 1 nil)) '} ;#X undef as nil105 multi defined ($x) is cl {' (UP (defined-p |$x|)) '} 107 106 multi substr($s,$offset,$length) { $s.substr($offset,$length) } 108 107 } … … 122 121 (labels 123 122 ((undump (node) 124 (cond ((null node) (undef)) 123 (cond ((null node) nil) 124 ((eq :false node) (undef)) 125 125 ((listp node) 126 126 (let ((args (mapcar #\'undump (cdr node)))) … … 156 156 exit(0); 157 157 } 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 158 163 sub module_require ($module) { 159 164 my $file = find_required_module($module); … … 185 190 eval_perl6($code,$env); 186 191 } 187 188 192 } 189 193 # regexp elf bootstrap primitives … … 203 207 '} 204 208 } 205 209 # For the Elf P5. 210 package 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 } 206 225 207 226 package Main { … … 253 272 method split ($pat) is cl {' 254 273 (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)))) 256 276 '} 257 277 method substr ($offset,$length) is cl {' … … 340 360 method reverse () is cl {' 341 361 (let* ((a (slot-value self \'|Array::._native_|))) 342 (new-Array ( reverse a)))362 (new-Array (coerce (reverse a) \'list ))) ;X 343 363 '} 344 364 } … … 400 420 (let ((hk (slot-value self \'|Hash::._keys_|)) 401 421 (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))) 403 423 '} 404 424 method delete ($key) is cl {' … … 448 468 449 469 # .Num() 470 class Undef { method Num () { 0 } } 450 471 class Int { method Num () { self } } 451 472 class Num { method Num () { self } } … … 457 478 # .Str() 458 479 class Any { method Str () { primitive_write_to_string(self) } } 480 class Undef { method Str () { "" } } 481 class Bool { method Str () { if self { "true" } else { "false " } } } 482 class True { method Str () { "true" } } 483 class False { method Str () { "false" } } 459 484 class Int { method Str () { primitive_write_to_string(self._native_) } } 460 485 class Num { method Str () { primitive_write_to_string(self._native_) } } -
misc/elfish/on_sbcl/README
r22522 r22560 69 69 # This dropped to 1/2x with Int's. 70 70 # This dropped to 1/4x while not being watched, for causes unknown. 71 # This dropped to 1/5x with boxed undef and booleans.
