Merge branch 'master' of git://factorcode.org/git/factor

db4
Anton Gorenko 2010-07-25 17:58:56 +06:00
commit 3989f0b406
50 changed files with 486 additions and 339 deletions

View File

@ -258,7 +258,7 @@ M: pointer c-type
2 >>align 2 >>align
2 >>align-first 2 >>align-first
"from_signed_2" >>boxer "from_signed_2" >>boxer
"to_fixnum" >>unboxer "to_signed_2" >>unboxer
[ >fixnum ] >>unboxer-quot [ >fixnum ] >>unboxer-quot
\ short define-primitive-type \ short define-primitive-type
@ -271,7 +271,7 @@ M: pointer c-type
2 >>align 2 >>align
2 >>align-first 2 >>align-first
"from_unsigned_2" >>boxer "from_unsigned_2" >>boxer
"to_cell" >>unboxer "to_unsigned_2" >>unboxer
[ >fixnum ] >>unboxer-quot [ >fixnum ] >>unboxer-quot
\ ushort define-primitive-type \ ushort define-primitive-type
@ -284,7 +284,7 @@ M: pointer c-type
1 >>align 1 >>align
1 >>align-first 1 >>align-first
"from_signed_1" >>boxer "from_signed_1" >>boxer
"to_fixnum" >>unboxer "to_signed_1" >>unboxer
[ >fixnum ] >>unboxer-quot [ >fixnum ] >>unboxer-quot
\ char define-primitive-type \ char define-primitive-type
@ -297,7 +297,7 @@ M: pointer c-type
1 >>align 1 >>align
1 >>align-first 1 >>align-first
"from_unsigned_1" >>boxer "from_unsigned_1" >>boxer
"to_cell" >>unboxer "to_unsigned_1" >>unboxer
[ >fixnum ] >>unboxer-quot [ >fixnum ] >>unboxer-quot
\ uchar define-primitive-type \ uchar define-primitive-type
@ -338,7 +338,7 @@ M: pointer c-type
4 >>align 4 >>align
4 >>align-first 4 >>align-first
"from_signed_4" >>boxer "from_signed_4" >>boxer
"to_fixnum" >>unboxer "to_signed_4" >>unboxer
[ >fixnum ] >>unboxer-quot [ >fixnum ] >>unboxer-quot
\ int define-primitive-type \ int define-primitive-type
@ -351,7 +351,7 @@ M: pointer c-type
4 >>align 4 >>align
4 >>align-first 4 >>align-first
"from_unsigned_4" >>boxer "from_unsigned_4" >>boxer
"to_cell" >>unboxer "to_unsigned_4" >>unboxer
[ >fixnum ] >>unboxer-quot [ >fixnum ] >>unboxer-quot
\ uint define-primitive-type \ uint define-primitive-type

View File

@ -185,3 +185,6 @@ IN: calendar.tests
2008 1 29 <date> 1 months time+ 2008 1 29 <date> 1 months time+
2008 2 29 <date> = 2008 2 29 <date> =
] unit-test ] unit-test
[ 0 ]
[ gmt gmt-offset>> duration>seconds ] unit-test

View File

@ -532,7 +532,7 @@ M: integer end-of-year 12 31 <date> ;
dup midnight time- ; dup midnight time- ;
: since-1970 ( duration -- timestamp ) : since-1970 ( duration -- timestamp )
unix-1970 time+ >local-time ; unix-1970 time+ ;
: timestamp>unix-time ( timestamp -- seconds ) : timestamp>unix-time ( timestamp -- seconds )
unix-1970 time- second>> ; unix-1970 time- second>> ;

View File

@ -11,14 +11,14 @@ IN: calendar.unix
: timeval>unix-time ( timeval -- timestamp ) : timeval>unix-time ( timeval -- timestamp )
timeval>duration since-1970 ; timeval>duration since-1970 ;
: timespec>seconds ( timespec -- seconds ) : timespec>duration ( timespec -- seconds )
[ sec>> seconds ] [ nsec>> nanoseconds ] bi time+ ; [ sec>> seconds ] [ nsec>> nanoseconds ] bi time+ ;
: timespec>nanoseconds ( timespec -- seconds ) : timespec>nanoseconds ( timespec -- seconds )
[ sec>> 1000000000 * ] [ nsec>> ] bi + ; [ sec>> 1000000000 * ] [ nsec>> ] bi + ;
: timespec>unix-time ( timespec -- timestamp ) : timespec>unix-time ( timespec -- timestamp )
timespec>seconds since-1970 ; timespec>duration since-1970 ;
: get-time ( -- alien ) : get-time ( -- alien )
f time <time_t> localtime ; f time <time_t> localtime ;

View File

@ -299,6 +299,7 @@ M: ##compare analyze-aliases
\ ##alien-global set-new-ac ; \ ##alien-global set-new-ac ;
M: factor-call-insn analyze-aliases M: factor-call-insn analyze-aliases
call-next-method
heap-ac get ac>vregs [ heap-ac get ac>vregs [
[ live-slots get at clear-assoc ] [ live-slots get at clear-assoc ]
[ recent-stores get at clear-assoc ] bi [ recent-stores get at clear-assoc ] bi

View File

@ -6,6 +6,7 @@ sequences sequences.generalizations system
compiler.cfg.builder.alien.params compiler.cfg.hats compiler.cfg.builder.alien.params compiler.cfg.hats
compiler.cfg.registers compiler.cfg.instructions compiler.cfg.registers compiler.cfg.instructions
compiler.cfg.intrinsics.allot cpu.architecture ; compiler.cfg.intrinsics.allot cpu.architecture ;
QUALIFIED-WITH: alien.c-types c
IN: compiler.cfg.builder.alien.boxing IN: compiler.cfg.builder.alien.boxing
SYMBOL: struct-return-area SYMBOL: struct-return-area
@ -49,9 +50,15 @@ M: c-type unbox
[ rep>> ] [ unboxer>> ] bi [ rep>> ] [ unboxer>> ] bi
[ [
{ {
! { "to_float" [ drop ] } { "to_float" [ drop ] }
! { "to_double" [ drop ] } { "to_double" [ drop ] }
! { "alien_offset" [ drop ^^unbox-any-c-ptr ] } { "to_signed_1" [ drop ] }
{ "to_unsigned_1" [ drop ] }
{ "to_signed_2" [ drop ] }
{ "to_unsigned_2" [ drop ] }
{ "to_signed_4" [ drop ] }
{ "to_unsigned_4" [ drop ] }
{ "alien_offset" [ drop ^^unbox-any-c-ptr ] }
[ swap ^^unbox ] [ swap ^^unbox ]
} case 1array } case 1array
] ]
@ -107,9 +114,15 @@ GENERIC: box ( vregs reps c-type -- dst )
M: c-type box M: c-type box
[ [ first ] bi@ ] [ boxer>> ] bi* [ [ first ] bi@ ] [ boxer>> ] bi*
{ {
! { "from_float" [ drop ] } { "from_float" [ drop ] }
! { "from_double" [ drop ] } { "from_double" [ drop ] }
! { "allot_alien" [ drop ^^box-alien ] } { "from_signed_1" [ drop c:char ^^convert-integer ] }
{ "from_unsigned_1" [ drop c:uchar ^^convert-integer ] }
{ "from_signed_2" [ drop c:short ^^convert-integer ] }
{ "from_unsigned_2" [ drop c:ushort ^^convert-integer ] }
{ "from_signed_4" [ drop c:int ^^convert-integer ] }
{ "from_unsigned_4" [ drop c:uint ^^convert-integer ] }
{ "allot_alien" [ drop ^^box-alien ] }
[ swap <gc-map> ^^box ] [ swap <gc-map> ^^box ]
} case ; } case ;

View File

@ -80,12 +80,9 @@ M: ##callback-outputs uses-vregs
tri tri
] with-compilation-unit ] with-compilation-unit
! Computing def-use chains. SYMBOLS: defs insns ;
SYMBOLS: defs insns uses ;
: def-of ( vreg -- node ) defs get at ; : def-of ( vreg -- node ) defs get at ;
: uses-of ( vreg -- nodes ) uses get at ;
: insn-of ( vreg -- insn ) insns get at ; : insn-of ( vreg -- insn ) insns get at ;
: set-def-of ( obj insn assoc -- ) : set-def-of ( obj insn assoc -- )
@ -98,8 +95,7 @@ SYMBOLS: defs insns uses ;
_ set-def-of _ set-def-of
] with each ] with each
] each-basic-block ] each-basic-block
] keep ] keep defs set ;
defs set ;
: compute-insns ( cfg -- ) : compute-insns ( cfg -- )
H{ } clone [ H{ } clone [

View File

@ -591,6 +591,12 @@ FOLDABLE-INSN: ##unbox-alien
def: dst/int-rep def: dst/int-rep
use: src/tagged-rep ; use: src/tagged-rep ;
! Zero-extending and sign-extending integers
FOLDABLE-INSN: ##convert-integer
def: dst/int-rep
use: src/int-rep
literal: c-type ;
! Raw memory accessors ! Raw memory accessors
FLUSHABLE-INSN: ##load-memory FLUSHABLE-INSN: ##load-memory
def: dst def: dst

View File

@ -48,52 +48,33 @@ IN: compiler.cfg.linear-scan.allocation
2dup spill-at-sync-point? 2dup spill-at-sync-point?
[ swap n>> spill f ] [ 2drop t ] if ; [ swap n>> spill f ] [ 2drop t ] if ;
: handle-interval ( live-interval -- ) GENERIC: handle ( obj -- )
M: live-interval handle
[ start>> deactivate-intervals ] [ start>> deactivate-intervals ]
[ start>> activate-intervals ] [ start>> activate-intervals ]
[ assign-register ] [ assign-register ]
tri ; tri ;
: (handle-sync-point) ( sync-point -- ) : handle-sync-point ( sync-point -- )
active-intervals get values active-intervals get values
[ [ spill-at-sync-point ] with filter! drop ] with each ; [ [ spill-at-sync-point ] with filter! drop ] with each ;
: handle-sync-point ( sync-point -- ) M: sync-point handle ( sync-point -- )
[ n>> deactivate-intervals ] [ n>> deactivate-intervals ]
[ (handle-sync-point) ] [ handle-sync-point ]
[ n>> activate-intervals ] [ n>> activate-intervals ]
tri ; tri ;
: smallest-heap ( heap1 heap2 -- heap )
[ [ heap-peek nip ] bi@ <= ] most ;
:: (allocate-registers-step) ( unhandled-intervals unhandled-sync-points -- ) :: (allocate-registers-step) ( unhandled-intervals unhandled-sync-points -- )
{ {
{ { [ unhandled-intervals heap-empty? ] [ unhandled-sync-points ] }
[ unhandled-intervals heap-empty? ] { [ unhandled-sync-points heap-empty? ] [ unhandled-intervals ] }
[ unhandled-sync-points heap-pop drop handle-sync-point ] [ unhandled-intervals unhandled-sync-points smallest-heap ]
} } cond heap-pop drop handle ;
{
[ unhandled-sync-points heap-empty? ]
[ unhandled-intervals heap-pop drop handle-interval ]
}
[
unhandled-intervals heap-peek :> ( i ik )
unhandled-sync-points heap-peek :> ( s sk )
{
{
[ ik sk < ]
[ unhandled-intervals heap-pop* i handle-interval ]
}
{
[ ik sk > ]
[ unhandled-sync-points heap-pop* s handle-sync-point ]
}
[
unhandled-intervals heap-pop*
i handle-interval
s (handle-sync-point)
]
} cond
]
} cond ;
: (allocate-registers) ( unhandled-intervals unhandled-sync-points -- ) : (allocate-registers) ( unhandled-intervals unhandled-sync-points -- )
2dup [ heap-empty? ] both? [ 2drop ] [ 2dup [ heap-empty? ] both? [ 2drop ] [

View File

@ -79,12 +79,13 @@ ERROR: bad-live-ranges interval ;
: split-for-spill ( live-interval n -- before after ) : split-for-spill ( live-interval n -- before after )
split-interval [ spill-before ] [ spill-after ] bi* ; split-interval [ spill-before ] [ spill-after ] bi* ;
: find-use-position ( live-interval new -- n ) : find-next-use ( live-interval new -- n )
[ uses>> ] [ start>> '[ n>> _ >= ] ] bi* find nip [ uses>> ] [ start>> ] bi*
'[ [ spill-slot?>> not ] [ n>> ] bi _ >= and ] find nip
[ n>> ] [ 1/0. ] if* ; [ n>> ] [ 1/0. ] if* ;
: find-use-positions ( live-intervals new assoc -- ) : find-use-positions ( live-intervals new assoc -- )
'[ [ _ find-use-position ] [ reg>> ] bi _ add-use-position ] each ; '[ [ _ find-next-use ] [ reg>> ] bi _ add-use-position ] each ;
: active-positions ( new assoc -- ) : active-positions ( new assoc -- )
[ [ active-intervals-for ] keep ] dip [ [ active-intervals-for ] keep ] dip

View File

@ -16,7 +16,7 @@ TUPLE: live-range from to ;
C: <live-range> live-range C: <live-range> live-range
TUPLE: vreg-use n def-rep use-rep ; TUPLE: vreg-use n def-rep use-rep spill-slot? ;
: <vreg-use> ( n -- vreg-use ) vreg-use new swap >>n ; : <vreg-use> ( n -- vreg-use ) vreg-use new swap >>n ;
@ -36,8 +36,10 @@ reg-class ;
: last-use? ( insn# uses -- use/f ) : last-use? ( insn# uses -- use/f )
[ drop f ] [ last [ n>> = ] keep and ] if-empty ; [ drop f ] [ last [ n>> = ] keep and ] if-empty ;
: (add-use) ( insn# live-interval -- use ) :: (add-use) ( insn# live-interval spill-slot? -- use )
uses>> 2dup last-use? dup [ 2nip ] [ drop new-use ] if ; live-interval uses>> :> uses
insn# uses last-use? [ insn# uses new-use ] unless*
spill-slot? [ t >>spill-slot? ] when ;
GENERIC: covers? ( insn# obj -- ? ) GENERIC: covers? ( insn# obj -- ? )
@ -105,28 +107,42 @@ GENERIC: compute-live-intervals* ( insn -- )
M: insn compute-live-intervals* drop ; M: insn compute-live-intervals* drop ;
:: record-def ( vreg n -- ) :: record-def ( vreg n spill-slot? -- )
vreg live-interval :> live-interval vreg live-interval :> live-interval
n live-interval shorten-range n live-interval shorten-range
n live-interval (add-use) vreg rep-of >>def-rep drop ; n live-interval spill-slot? (add-use) vreg rep-of >>def-rep drop ;
:: record-use ( vreg n -- ) :: record-use ( vreg n spill-slot? -- )
vreg live-interval :> live-interval vreg live-interval :> live-interval
from get n live-interval add-range from get n live-interval add-range
n live-interval (add-use) vreg rep-of >>use-rep drop ; n live-interval spill-slot? (add-use) vreg rep-of >>use-rep drop ;
:: record-temp ( vreg n -- ) :: record-temp ( vreg n -- )
vreg live-interval :> live-interval vreg live-interval :> live-interval
n n live-interval add-range n n live-interval add-range
n live-interval (add-use) vreg rep-of >>def-rep drop ; n live-interval f (add-use) vreg rep-of >>def-rep drop ;
M: vreg-insn compute-live-intervals* ( insn -- ) M: vreg-insn compute-live-intervals* ( insn -- )
dup insn#>> dup insn#>>
[ [ defs-vregs ] dip '[ _ record-def ] each ] [ [ defs-vregs ] dip '[ _ f record-def ] each ]
[ [ uses-vregs ] dip '[ _ record-use ] each ] [ [ uses-vregs ] dip '[ _ f record-use ] each ]
[ [ temp-vregs ] dip '[ _ record-temp ] each ]
2tri ;
M: clobber-insn compute-live-intervals* ( insn -- )
dup insn#>>
[ [ defs-vregs ] dip '[ _ f record-def ] each ]
[ [ uses-vregs ] dip '[ _ t record-use ] each ]
[ [ temp-vregs ] dip '[ _ record-temp ] each ]
2tri ;
M: hairy-clobber-insn compute-live-intervals* ( insn -- )
dup insn#>>
[ [ defs-vregs ] dip '[ _ t record-def ] each ]
[ [ uses-vregs ] dip '[ _ t record-use ] each ]
[ [ temp-vregs ] dip '[ _ record-temp ] each ] [ [ temp-vregs ] dip '[ _ record-temp ] each ]
2tri ; 2tri ;

View File

@ -1,13 +1,19 @@
USING: compiler.cfg.liveness compiler.cfg.debugger USING: compiler.cfg.liveness compiler.cfg.liveness.ssa
compiler.cfg.instructions compiler.cfg.predecessors compiler.cfg.debugger compiler.cfg.instructions
compiler.cfg.registers compiler.cfg cpu.architecture compiler.cfg.predecessors compiler.cfg.registers compiler.cfg
accessors namespaces sequences kernel tools.test vectors ; cpu.architecture accessors namespaces sequences kernel
tools.test vectors alien math compiler.cfg.comparisons
cpu.x86.assembler.operands ;
IN: compiler.cfg.liveness.tests IN: compiler.cfg.liveness.tests
: test-liveness ( -- ) : test-liveness ( -- )
cfg new 1 get >>entry cfg new 1 get >>entry
compute-live-sets ; compute-live-sets ;
: test-ssa-liveness ( -- )
cfg new 1 get >>entry
compute-ssa-live-sets ;
! Sanity check... ! Sanity check...
V{ V{
@ -30,7 +36,7 @@ V{
1 { 2 3 } edges 1 { 2 3 } edges
test-liveness [ ] [ test-liveness ] unit-test
[ [
H{ H{
@ -56,6 +62,95 @@ V{
1 2 edge 1 2 edge
test-liveness [ ] [ test-liveness ] unit-test
[ H{ { 0 0 } } ] [ 2 get live-in ] unit-test [ H{ { 0 0 } } ] [ 2 get live-in ] unit-test
! Regression
V{
T{ ##prologue }
T{ ##branch }
} 0 test-bb
V{
T{ ##inc-r f 2 }
T{ ##inc-d f -2 }
T{ ##peek f 21 D -1 }
T{ ##peek f 22 D -2 }
T{ ##replace f 21 R 0 }
T{ ##replace f 22 R 1 }
T{ ##branch }
} 1 test-bb
V{
T{ ##call f >c-ptr }
T{ ##branch }
} 2 test-bb
V{
T{ ##inc-r f -1 }
T{ ##inc-d f 1 }
T{ ##peek f 25 R -1 }
T{ ##replace f 25 D 0 }
T{ ##branch }
} 3 test-bb
V{
T{ ##call f >float }
T{ ##branch }
} 4 test-bb
V{
T{ ##inc-r f -1 }
T{ ##inc-d f 2 }
T{ ##peek f 27 R -1 }
T{ ##peek f 28 D 2 }
T{ ##peek f 29 D 3 }
T{ ##load-integer f 30 1 }
T{ ##load-integer f 31 0 }
T{ ##compare-imm-branch f 27 f cc/= }
} 5 test-bb
V{
T{ ##inc-d f -1 }
T{ ##branch }
} 6 test-bb
V{
T{ ##inc-d f -1 }
T{ ##branch }
} 7 test-bb
V{
T{ ##phi f 36 H{ { 6 30 } { 7 31 } } }
T{ ##inc-d f -2 }
T{ ##unbox f 37 29 "alien_offset" int-rep }
T{ ##unbox f 38 28 "to_double" double-rep }
T{ ##unbox f 39 36 "to_cell" int-rep }
T{ ##alien-invoke f V{ } V{ { 37 int-rep 0 } { 38 double-rep 4 } { 39 int-rep 12 } } { { 40 int-rep EAX } } 0 16 "CFRunLoopRunInMode" f T{ gc-map } }
T{ ##box f 41 40 "from_signed_cell" int-rep T{ gc-map } }
T{ ##replace f 41 D 0 }
T{ ##branch }
} 8 test-bb
V{
T{ ##epilogue }
T{ ##return }
} 9 test-bb
0 1 edge
1 2 edge
2 3 edge
3 4 edge
4 5 edge
5 { 6 7 } edges
6 8 edge
7 8 edge
8 9 edge
[ ] [ test-ssa-liveness ] unit-test
[ H{ { 28 28 } { 29 29 } { 30 30 } { 31 31 } } ] [ 5 get live-out ] unit-test
[ H{ { 28 28 } { 29 29 } { 30 30 } } ] [ 6 get live-in ] unit-test
[ H{ { 28 28 } { 29 29 } { 31 31 } } ] [ 7 get live-in ] unit-test
[ H{ { 30 30 } } ] [ 6 get 8 get edge-live-in ] unit-test

View File

@ -62,3 +62,20 @@ V{
] [ ] [
0 get instructions>> 0 get instructions>>
] unit-test ] unit-test
V{
T{ ##phi }
T{ ##box }
} 0 test-bb
0 get insert-save-context
[
V{
T{ ##phi }
T{ ##save-context f 7 8 }
T{ ##box }
}
] [
0 get instructions>>
] unit-test

View File

@ -18,6 +18,7 @@ M: insn needs-save-context? drop f ;
GENERIC: modifies-context? ( insn -- ? ) GENERIC: modifies-context? ( insn -- ? )
M: ##phi modifies-context? drop t ;
M: ##inc-d modifies-context? drop t ; M: ##inc-d modifies-context? drop t ;
M: ##inc-r modifies-context? drop t ; M: ##inc-r modifies-context? drop t ;
M: ##callback-inputs modifies-context? drop t ; M: ##callback-inputs modifies-context? drop t ;

View File

@ -236,6 +236,7 @@ CODEGEN: ##box-alien %box-alien
CODEGEN: ##box-displaced-alien %box-displaced-alien CODEGEN: ##box-displaced-alien %box-displaced-alien
CODEGEN: ##unbox-alien %unbox-alien CODEGEN: ##unbox-alien %unbox-alien
CODEGEN: ##unbox-any-c-ptr %unbox-any-c-ptr CODEGEN: ##unbox-any-c-ptr %unbox-any-c-ptr
CODEGEN: ##convert-integer %convert-integer
CODEGEN: ##load-memory %load-memory CODEGEN: ##load-memory %load-memory
CODEGEN: ##load-memory-imm %load-memory-imm CODEGEN: ##load-memory-imm %load-memory-imm
CODEGEN: ##store-memory %store-memory CODEGEN: ##store-memory %store-memory

View File

@ -6,7 +6,7 @@ math memory namespaces namespaces.private parser
quotations sequences specialized-arrays stack-checker quotations sequences specialized-arrays stack-checker
stack-checker.errors system threads tools.test words stack-checker.errors system threads tools.test words
alien.complex concurrency.promises alien.data alien.complex concurrency.promises alien.data
byte-arrays classes ; byte-arrays classes compiler.test ;
FROM: alien.c-types => float short ; FROM: alien.c-types => float short ;
SPECIALIZED-ARRAY: float SPECIALIZED-ARRAY: float
SPECIALIZED-ARRAY: char SPECIALIZED-ARRAY: char
@ -804,3 +804,20 @@ mingw? [
] with-out-parameters ; ] with-out-parameters ;
[ 12 ] [ 6 out-param-callback out-param-indirect ] unit-test [ 12 ] [ 6 out-param-callback out-param-indirect ] unit-test
! Alias analysis regression
: aa-callback-1 ( -- c )
double { } cdecl [ 5.0 ] alien-callback ;
: aa-indirect-1 ( c -- x )
double { } cdecl alien-indirect ; inline
TUPLE: some-tuple x ;
[ T{ some-tuple f 5.0 } ] [
[
some-tuple new
aa-callback-1
aa-indirect-1 >>x
] compile-call
] unit-test

View File

@ -105,3 +105,24 @@ IN: compiler.tests.low-level-ir
T{ ##add-imm f 0 0 -16 } T{ ##add-imm f 0 0 -16 }
} compile-test-bb } compile-test-bb
] unit-test ] unit-test
[ -1 ] [
V{
T{ ##load-tagged f 1 $[ -1 tag-fixnum ] }
T{ ##convert-integer f 0 1 char }
} compile-test-bb
] unit-test
[ -1 ] [
V{
T{ ##load-tagged f 1 $[ -1 9 2^ bitxor tag-fixnum ] }
T{ ##convert-integer f 0 1 char }
} compile-test-bb
] unit-test
[ $[ 255 tag-bits get neg shift ] ] [
V{
T{ ##load-tagged f 1 $[ -1 9 2^ bitxor tag-fixnum ] }
T{ ##convert-integer f 0 1 uchar }
} compile-test-bb
] unit-test

View File

@ -1,7 +1,7 @@
USING: compiler.test compiler.units tools.test kernel kernel.private USING: compiler.test compiler.units tools.test kernel kernel.private
sequences.private math.private math combinators strings alien sequences.private math.private math combinators strings alien
arrays memory vocabs parser eval quotations compiler.errors arrays memory vocabs parser eval quotations compiler.errors
definitions ; definitions generic.single ;
IN: compiler.tests.simple IN: compiler.tests.simple
! Test empty word ! Test empty word
@ -249,3 +249,6 @@ M: quotation bad-effect-test call ; inline
! Don't want compiler error to stick around ! Don't want compiler error to stick around
[ ] [ [ M\ quotation bad-effect-test forget ] with-compilation-unit ] unit-test [ ] [ [ M\ quotation bad-effect-test forget ] with-compilation-unit ] unit-test
! Make sure time bombs literalize
[ [ \ + call ] compile-call ] [ no-method? ] must-fail-with

View File

@ -8,3 +8,9 @@ TUPLE: color red green blue ;
[ T{ color f f f f } ] [ T{ color f f f f } ]
[ [ color new ] compile-call ] unit-test [ [ color new ] compile-call ] unit-test
SYMBOL: foo
[ [ foo new ] compile-call ] must-fail
[ [ foo boa ] compile-call ] must-fail

View File

@ -1,8 +1,9 @@
! Copyright (C) 2008, 2009 Slava Pestov. ! Copyright (C) 2008, 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: kernel accessors sequences words memoize combinators USING: kernel accessors sequences words memoize combinators
classes classes.builtin classes.tuple classes.singleton classes classes.builtin classes.tuple classes.singleton
math.partial-dispatch fry assocs combinators.short-circuit math.partial-dispatch fry assocs combinators.short-circuit
stack-checker.dependencies
compiler.tree compiler.tree
compiler.tree.combinators compiler.tree.combinators
compiler.tree.propagation.info compiler.tree.propagation.info
@ -26,6 +27,9 @@ GENERIC: finalize* ( node -- nodes )
: splice-final ( quot -- nodes ) splice-quot finalize ; : splice-final ( quot -- nodes ) splice-quot finalize ;
: splice-predicate ( word -- nodes )
[ depends-on-definition ] [ def>> splice-final ] bi ;
M: #copy finalize* drop f ; M: #copy finalize* drop f ;
M: #shuffle finalize* M: #shuffle finalize*
@ -44,8 +48,8 @@ GENERIC: finalize-word ( #call word -- nodes )
M: predicate finalize-word M: predicate finalize-word
"predicating" word-prop { "predicating" word-prop {
{ [ dup builtin-class? ] [ drop word>> cached-expansion ] } { [ dup builtin-class? ] [ drop word>> cached-expansion ] }
{ [ dup tuple-class? ] [ drop word>> def>> splice-final ] } { [ dup tuple-class? ] [ drop word>> splice-predicate ] }
{ [ dup singleton-class? ] [ drop word>> def>> splice-final ] } { [ dup singleton-class? ] [ drop word>> splice-predicate ] }
[ drop ] [ drop ]
} cond ; } cond ;

View File

@ -473,6 +473,8 @@ HOOK: %unbox-any-c-ptr cpu ( dst src -- )
HOOK: %box-alien cpu ( dst src temp -- ) HOOK: %box-alien cpu ( dst src temp -- )
HOOK: %box-displaced-alien cpu ( dst displacement base temp base-class -- ) HOOK: %box-displaced-alien cpu ( dst displacement base temp base-class -- )
HOOK: %convert-integer cpu ( dst src c-type -- )
HOOK: %load-memory cpu ( dst base displacement scale offset rep c-type -- ) HOOK: %load-memory cpu ( dst base displacement scale offset rep c-type -- )
HOOK: %load-memory-imm cpu ( dst base offset rep c-type -- ) HOOK: %load-memory-imm cpu ( dst base offset rep c-type -- )
HOOK: %store-memory cpu ( value base displacement scale offset rep c-type -- ) HOOK: %store-memory cpu ( value base displacement scale offset rep c-type -- )

View File

@ -209,6 +209,8 @@ M:: x86.32 %binary-float-function ( dst src1 src2 func -- )
#! MINGW ABI incompatibility disaster #! MINGW ABI incompatibility disaster
[ large-struct? ] [ mingw eq? os windows? not or ] bi* and ; [ large-struct? ] [ mingw eq? os windows? not or ] bi* and ;
M: x86.32 %prepare-var-args ( -- ) ;
M:: x86.32 stack-cleanup ( stack-size return abi -- n ) M:: x86.32 stack-cleanup ( stack-size return abi -- n )
#! a) Functions which are stdcall/fastcall/thiscall have to #! a) Functions which are stdcall/fastcall/thiscall have to
#! clean up the caller's stack frame. #! clean up the caller's stack frame.

View File

@ -140,6 +140,8 @@ M:: x86.64 %binary-float-function ( dst src1 src2 func -- )
func "libm" load-library f %c-invoke func "libm" load-library f %c-invoke
dst double-rep %load-return ; dst double-rep %load-return ;
M: x86.64 %prepare-var-args ( -- ) RAX RAX XOR ;
M: x86.64 stack-cleanup 3drop 0 ; M: x86.64 stack-cleanup 3drop 0 ;
M: x86.64 %cleanup 0 assert= ; M: x86.64 %cleanup 0 assert= ;

View File

@ -345,6 +345,29 @@ M: x86.64 has-small-reg? 2drop t ;
[ quot call ] with-save/restore [ quot call ] with-save/restore
] if ; inline ] if ; inline
:: (%convert-integer) ( dst src bits quot -- )
dst { src } bits [| new-dst |
new-dst src int-rep %copy
new-dst dup bits n-bit-version-of quot call
dst new-dst int-rep %copy
] with-small-register ; inline
: %zero-extend ( dst src bits -- )
[ MOVZX ] (%convert-integer) ; inline
: %sign-extend ( dst src bits -- )
[ MOVSX ] (%convert-integer) ; inline
M: x86 %convert-integer ( dst src c-type -- )
{
{ c:char [ 8 %sign-extend ] }
{ c:uchar [ 8 %zero-extend ] }
{ c:short [ 16 %sign-extend ] }
{ c:ushort [ 16 %zero-extend ] }
{ c:int [ 32 %sign-extend ] }
{ c:uint [ 32 [ 2drop ] (%convert-integer) ] }
} case ;
:: %alien-integer-getter ( dst exclude address bits quot -- ) :: %alien-integer-getter ( dst exclude address bits quot -- )
dst exclude bits [| new-dst | dst exclude bits [| new-dst |
new-dst dup bits n-bit-version-of dup address MOV new-dst dup bits n-bit-version-of dup address MOV
@ -621,6 +644,7 @@ HOOK: %cleanup cpu ( n -- )
:: emit-alien-insn ( reg-inputs stack-inputs reg-outputs cleanup stack-size quot -- ) :: emit-alien-insn ( reg-inputs stack-inputs reg-outputs cleanup stack-size quot -- )
stack-inputs [ first3 %store-stack-param ] each stack-inputs [ first3 %store-stack-param ] each
reg-inputs [ first3 %store-reg-param ] each reg-inputs [ first3 %store-reg-param ] each
%prepare-var-args
quot call quot call
cleanup %cleanup cleanup %cleanup
reg-outputs [ first3 %load-reg-param ] each ; inline reg-outputs [ first3 %load-reg-param ] each ; inline

View File

@ -94,7 +94,7 @@ prepare-test-file
test-file now test-file now
[ set-file-access-time ] 2keep [ set-file-access-time ] 2keep
[ file-info accessed>> ] [ file-info accessed>> ]
[ [ [ truncate >integer ] change-second ] bi@ ] bi* = [ [ [ truncate >integer ] change-second >gmt ] bi@ ] bi* =
] unit-test ] unit-test
[ t ] [ t ]
@ -102,7 +102,7 @@ prepare-test-file
test-file now test-file now
[ set-file-modified-time ] 2keep [ set-file-modified-time ] 2keep
[ file-info modified>> ] [ file-info modified>> ]
[ [ [ truncate >integer ] change-second ] bi@ ] bi* = [ [ [ truncate >integer ] change-second >gmt ] bi@ ] bi* =
] unit-test ] unit-test
[ t ] [ t ]
@ -110,7 +110,7 @@ prepare-test-file
test-file now [ dup 2array set-file-times ] 2keep test-file now [ dup 2array set-file-times ] 2keep
[ file-info [ modified>> ] [ accessed>> ] bi ] dip [ file-info [ modified>> ] [ accessed>> ] bi ] dip
3array 3array
[ [ truncate >integer ] change-second ] map all-equal? [ [ truncate >integer ] change-second >gmt ] map all-equal?
] unit-test ] unit-test
[ ] [ test-file f now 2array set-file-times ] unit-test [ ] [ test-file f now 2array set-file-times ] unit-test

View File

@ -103,7 +103,7 @@ USING: math.matrices math.vectors tools.test math ;
[ { 1 0 0 } ] [ { 0 1 0 } { 0 0 1 } cross ] unit-test [ { 1 0 0 } ] [ { 0 1 0 } { 0 0 1 } cross ] unit-test
[ { 0 1 0 } ] [ { 0 0 1 } { 1 0 0 } cross ] unit-test [ { 0 1 0 } ] [ { 0 0 1 } { 1 0 0 } cross ] unit-test
[ { 0.0 -0.707 0.707 } ] [ { 1.0 0.0 0.0 } { 0.0 0.707 0.707 } cross ] unit-test [ { 0.0 -0.707 0.707 } ] [ { 1.0 0.0 0.0 } { 0.0 0.707 0.707 } cross ] unit-test
[ { 0 -2 2 } ] [ { -1 -1 -1 } { 1 -1 -1 } cross ] unit-test
[ { 1 0 0 } ] [ { 1 1 0 } { 1 0 0 } proj ] unit-test [ { 1 0 0 } ] [ { 1 1 0 } { 1 0 0 } proj ] unit-test
[ { { 4181 6765 } { 6765 10946 } } ] [ { { 4181 6765 } { 6765 10946 } } ]

View File

@ -114,6 +114,9 @@ IN: math.matrices
[ [ { 1 2 0 } vshuffle ] [ { 2 0 1 } vshuffle ] bi* v* ] [ [ { 1 2 0 } vshuffle ] [ { 2 0 1 } vshuffle ] bi* v* ]
[ [ { 2 0 1 } vshuffle ] [ { 1 2 0 } vshuffle ] bi* v* ] 2bi v- ; inline [ [ { 2 0 1 } vshuffle ] [ { 1 2 0 } vshuffle ] bi* v* ] 2bi v- ; inline
:: normal ( vec1 vec2 vec3 -- vec4 )
vec2 vec1 v- vec3 vec1 v- cross normalize ; inline
: proj ( v u -- w ) : proj ( v u -- w )
[ [ v. ] [ norm-sq ] bi / ] keep n*v ; [ [ v. ] [ norm-sq ] bi / ] keep n*v ;

View File

@ -616,10 +616,14 @@ STRUCT: simd-struct
! Test cross product ! Test cross product
[ float-4{ 0.0 0.0 1.0 0.0 } ] [ float-4{ 1.0 0.0 0.0 0.0 } float-4{ 0.0 1.0 0.0 0.0 } cross ] unit-test [ float-4{ 0.0 0.0 1.0 0.0 } ] [ float-4{ 1.0 0.0 0.0 0.0 } float-4{ 0.0 1.0 0.0 0.0 } cross ] unit-test
[ float-4{ 0.0 0.0 1.0 0.0 } ] [ float-4{ 1.0 0.0 0.0 0.0 } float-4{ 0.0 1.0 0.0 0.0 } [ { float-4 float-4 } declare cross ] compile-call ] unit-test
[ float-4{ 0.0 -1.0 0.0 0.0 } ] [ float-4{ 1.0 0.0 0.0 0.0 } float-4{ 0.0 0.0 1.0 0.0 } cross ] unit-test [ float-4{ 0.0 -1.0 0.0 0.0 } ] [ float-4{ 1.0 0.0 0.0 0.0 } float-4{ 0.0 0.0 1.0 0.0 } cross ] unit-test
[ float-4{ 0.0 -1.0 0.0 0.0 } ] [ float-4{ 1.0 0.0 0.0 0.0 } float-4{ 0.0 0.0 1.0 0.0 } [ { float-4 float-4 } declare cross ] compile-call ] unit-test
[ double-4{ 0.0 0.0 1.0 0.0 } ] [ double-4{ 1.0 0.0 0.0 0.0 } double-4{ 0.0 1.0 0.0 0.0 } cross ] unit-test [ double-4{ 0.0 0.0 1.0 0.0 } ] [ double-4{ 1.0 0.0 0.0 0.0 } double-4{ 0.0 1.0 0.0 0.0 } cross ] unit-test
[ double-4{ 0.0 0.0 1.0 0.0 } ] [ double-4{ 1.0 0.0 0.0 0.0 } double-4{ 0.0 1.0 0.0 0.0 } [ { double-4 double-4 } declare cross ] compile-call ] unit-test
[ double-4{ 0.0 -1.0 0.0 0.0 } ] [ double-4{ 1.0 0.0 0.0 0.0 } double-4{ 0.0 0.0 1.0 0.0 } cross ] unit-test [ double-4{ 0.0 -1.0 0.0 0.0 } ] [ double-4{ 1.0 0.0 0.0 0.0 } double-4{ 0.0 0.0 1.0 0.0 } cross ] unit-test
[ double-4{ 0.0 -1.0 0.0 0.0 } ] [ double-4{ 1.0 0.0 0.0 0.0 } double-4{ 0.0 0.0 1.0 0.0 } [ { double-4 double-4 } declare cross ] compile-call ] unit-test
! CSSA bug ! CSSA bug
[ 4000000 ] [ [ 4000000 ] [

View File

@ -1,7 +1,5 @@
! Copyright (C) 2008, 2009 Doug Coleman, Daniel Ehrenberg USING: arrays regexp tools.test kernel sequences regexp.parser
! See http://factorcode.org/license.txt for BSD license. regexp.private eval strings multiline accessors ;
USING: regexp tools.test kernel sequences regexp.parser regexp.private
eval strings multiline accessors ;
IN: regexp-tests IN: regexp-tests
[ f ] [ "b" "a*" <regexp> matches? ] unit-test [ f ] [ "b" "a*" <regexp> matches? ] unit-test
@ -241,6 +239,9 @@ IN: regexp-tests
[ t ] [ 3 "xabc" R/ abc/r match-index-from >boolean ] unit-test [ t ] [ 3 "xabc" R/ abc/r match-index-from >boolean ] unit-test
[ t ] [ 3 "xabc" R/ a[bB][cC]/r match-index-from >boolean ] unit-test [ t ] [ 3 "xabc" R/ a[bB][cC]/r match-index-from >boolean ] unit-test
[ 2 ] [ 0 "llamallol" R/ ll/ match-index-from ] unit-test
[ 5 ] [ 8 "lolmallol" R/ lol/r match-index-from ] unit-test
[ t ] [ "s@f" "[a-z.-]@[a-z]" <regexp> matches? ] unit-test [ t ] [ "s@f" "[a-z.-]@[a-z]" <regexp> matches? ] unit-test
[ f ] [ "a" "[a-z.-]@[a-z]" <regexp> matches? ] unit-test [ f ] [ "a" "[a-z.-]@[a-z]" <regexp> matches? ] unit-test
[ t ] [ ".o" "\\.[a-z]" <regexp> matches? ] unit-test [ t ] [ ".o" "\\.[a-z]" <regexp> matches? ] unit-test
@ -272,6 +273,10 @@ IN: regexp-tests
[ "b" ] [ "aaaaaaaaaaaaaaaaaaaaaaab" "((a*)*b)*b" <regexp> first-match >string ] unit-test [ "b" ] [ "aaaaaaaaaaaaaaaaaaaaaaab" "((a*)*b)*b" <regexp> first-match >string ] unit-test
[ T{ slice { from 5 } { to 10 } { seq "hellohello" } } ]
[ "hellohello" R/ hello/r first-match ]
unit-test
[ { "1" "2" "3" "4" } ] [ { "1" "2" "3" "4" } ]
[ "1ABC2DEF3GHI4" R/ [A-Z]+/ re-split [ >string ] map ] unit-test [ "1ABC2DEF3GHI4" R/ [A-Z]+/ re-split [ >string ] map ] unit-test
@ -282,18 +287,52 @@ IN: regexp-tests
[ { "a" "" } ] [ "a=" R/ =/ re-split [ >string ] map ] unit-test [ { "a" "" } ] [ "a=" R/ =/ re-split [ >string ] map ] unit-test
[ { "he" "o" } ] [ "hello" R/ l+/ re-split [ >string ] map ] unit-test
[ { "h" "llo" } ] [ "hello" R/ e+/ re-split [ >string ] map ] unit-test
[ { "" "h" "" "l" "l" "o" "" } ] [ "hello" R/ e*/ re-split [ >string ] map ] unit-test
[ { { 0 5 "hellohello" } { 5 10 "hellohello" } } ]
[ "hellohello" R/ hello/ [ 3array ] map-matches ]
unit-test
[ { { 5 10 "hellohello" } { 0 5 "hellohello" } } ]
[ "hellohello" R/ hello/r [ 3array ] map-matches ]
unit-test
[ { "ABC" "DEF" "GHI" } ] [ { "ABC" "DEF" "GHI" } ]
[ "1ABC2DEF3GHI4" R/ [A-Z]+/ all-matching-subseqs ] unit-test [ "1ABC2DEF3GHI4" R/ [A-Z]+/ all-matching-subseqs ] unit-test
[ 3 ] [ { "ee" "e" } ] [ "heellohello" R/ e+/ all-matching-subseqs ] unit-test
[ "1ABC2DEF3GHI4" R/ [A-Z]+/ count-matches ] unit-test [ { "e" "ee" } ] [ "heellohello" R/ e+/r all-matching-subseqs ] unit-test
[ 0 ] [ 3 ] [ "1ABC2DEF3GHI4" R/ [A-Z]+/ count-matches ] unit-test
[ "123" R/ [A-Z]+/ count-matches ] unit-test
[ "1.2.3.4." ] [ 3 ] [ "1ABC2DEF3GHI4" R/ [A-Z]+/r count-matches ] unit-test
[ "1ABC2DEF3GHI4JK" R/ [A-Z]+/ "." re-replace ] unit-test
[ 1 ] [ "" R/ / count-matches ] unit-test
[ 1 ] [ "" R/ /r count-matches ] unit-test
[ 0 ] [ "123" R/ [A-Z]+/ count-matches ] unit-test
[ 0 ] [ "123" R/ [A-Z]+/r count-matches ] unit-test
[ 6 ] [ "hello" R/ e*/ count-matches ] unit-test
[ 6 ] [ "hello" R/ e*/r count-matches ] unit-test
[ 11 ] [ "hello world" R/ l*/ count-matches ] unit-test
[ 11 ] [ "hello world" R/ l*/r count-matches ] unit-test
[ 1 ] [ "hello" R/ e+/ count-matches ] unit-test
[ 2 ] [ "hello world" R/ l+/r count-matches ] unit-test
[ "1.2.3.4." ] [ "1ABC2DEF3GHI4JK" R/ [A-Z]+/ "." re-replace ] unit-test
[ "XhXXlXlXoX XwXoXrXlXdX" ] [ "hello world" R/ e*/ "X" re-replace ] unit-test
[ "-- title --" ] [ "== title ==" R/ =/ "-" re-replace ] unit-test [ "-- title --" ] [ "== title ==" R/ =/ "-" re-replace ] unit-test
[ "" ] [ "ab" "a(?!b)" <regexp> first-match >string ] unit-test [ "" ] [ "ab" "a(?!b)" <regexp> first-match >string ] unit-test

View File

@ -50,33 +50,49 @@ PRIVATE>
<PRIVATE <PRIVATE
:: (next-match) ( i string regexp quot: ( i string regexp -- j ) reverse? -- i start end ? )
i string regexp quot call dup [| j |
j i j
reverse? [ swap [ 1 + ] bi@ ] when
string
] [ drop f f f f ] if ; inline
: search-range ( i string reverse? -- seq ) : search-range ( i string reverse? -- seq )
[ drop dup 1 + -1 ] [ length 1 ] if range boa ; inline [ drop -1 ] [ length ] if [a,b] ; inline
:: next-match ( i string regexp quot: ( i string regexp -- j ) reverse? -- i start end ? ) :: (next-match) ( i string regexp quot: ( i string regexp -- j ) reverse? -- start end ? )
f f f f i string regexp quot call dup
[| j | reverse? [ j i ] [ i j ] if string ] [ drop f f f ] if ; inline
:: next-match ( i string regexp quot: ( i string regexp -- j ) reverse? -- start end ? )
f f f
i string reverse? search-range i string reverse? search-range
[ [ 2drop 2drop ] dip string regexp quot reverse? (next-match) dup ] find 2drop ; inline [ [ 3drop ] dip string regexp quot reverse? (next-match) dup ] find 2drop ; inline
: do-next-match ( i string regexp -- i start end ? ) : do-next-match ( i string regexp -- start end ? )
dup next-match>> dup next-match>>
execute( i string regexp -- i start end ? ) ; inline execute( i string regexp -- start end ? ) ; inline
:: (each-match) ( ... i string regexp quot: ( ... start end string -- ... ) -- ... ) :: (each-match-forward) ( ... i string regexp quot: ( ... start end string -- ... ) -- ... )
i string regexp do-next-match [| i' start end | i string length <= [
i string regexp do-next-match [| start end |
start end string quot call start end string quot call
i' string regexp quot (each-match) start end eq? [ end 1 + ] [ end ] if
] [ 3drop ] if ; inline recursive string regexp quot (each-match-forward)
] [ 2drop ] if
] when ; inline recursive
:: (each-match-backward) ( ... i string regexp quot: ( ... start end string -- ... ) -- ... )
i -1 >= [
i string regexp do-next-match [| start end |
start 1 + end 1 + string quot call
start end eq? [ start 1 - ] [ start ] if
string regexp quot (each-match-backward)
] [ 2drop ] if
] when ; inline recursive
: (each-match) ( ... i string regexp quot: ( ... start end string -- ... ) -- ... )
over reverse-regexp? [ (each-match-backward) ] [ (each-match-forward) ] if ; inline
GENERIC: match-iterator-start ( string regexp -- start )
M: regexp match-iterator-start 2drop 0 ;
M: reverse-regexp match-iterator-start drop length ;
: prepare-match-iterator ( string regexp -- i string regexp ) : prepare-match-iterator ( string regexp -- i string regexp )
[ check-string ] dip [ end/start nip ] 2keep ; inline [ check-string ] dip [ match-iterator-start ] 2keep ; inline
PRIVATE> PRIVATE>
@ -107,12 +123,14 @@ PRIVATE>
PRIVATE> PRIVATE>
: first-match ( string regexp -- slice/f ) :: first-match ( string regexp -- slice/f )
[ prepare-match-iterator do-next-match ] [ drop ] 2bi string regexp prepare-match-iterator do-next-match [
'[ _ slice boa nip ] [ 3drop f ] if ; regexp reverse-regexp? [ [ 1 + ] bi@ ] when
string slice boa
] [ 2drop f ] if ;
: re-contains? ( string regexp -- ? ) : re-contains? ( string regexp -- ? )
prepare-match-iterator do-next-match [ 3drop ] dip >boolean ; prepare-match-iterator do-next-match [ 2drop ] dip >boolean ;
: re-split ( string regexp -- seq ) : re-split ( string regexp -- seq )
[ slice boa ] (re-split) ; [ slice boa ] (re-split) ;
@ -141,7 +159,7 @@ M: reverse-regexp compile-regexp ( regexp -- regexp )
DEFER: compile-next-match DEFER: compile-next-match
: next-initial-word ( i string regexp -- i start end string ) : next-initial-word ( i string regexp -- start end string )
[ compile-next-match ] with-compilation-unit do-next-match ; [ compile-next-match ] with-compilation-unit do-next-match ;
: compile-next-match ( regexp -- regexp ) : compile-next-match ( regexp -- regexp )
@ -149,7 +167,7 @@ DEFER: compile-next-match
dup \ next-initial-word = [ dup \ next-initial-word = [
drop _ [ compile-regexp dfa>> def>> ] [ reverse-regexp? ] bi drop _ [ compile-regexp dfa>> def>> ] [ reverse-regexp? ] bi
'[ { array-capacity string regexp } declare _ _ next-match ] '[ { array-capacity string regexp } declare _ _ next-match ]
(( i string regexp -- i start end string )) define-temp (( i string regexp -- start end string )) define-temp
] when ] when
] change-next-match ; ] change-next-match ;

View File

@ -110,13 +110,11 @@ M: object apply-object push-literal ;
infer-quot-here infer-quot-here
] dip recursive-state set ; ] dip recursive-state set ;
: time-bomb ( error -- ) : time-bomb-quot ( obj generic -- quot )
'[ _ throw ] infer-quot-here ; [ literalize ] [ "default-method" word-prop ] bi* [ ] 2sequence ;
ERROR: bad-call obj ; : time-bomb ( obj generic -- )
time-bomb-quot infer-quot-here ;
M: bad-call summary
drop "call must be given a callable" ;
: infer-literal-quot ( literal -- ) : infer-literal-quot ( literal -- )
dup recursive-quotation? [ dup recursive-quotation? [
@ -127,7 +125,7 @@ M: bad-call summary
[ [ recursion>> ] keep add-local-quotation ] [ [ recursion>> ] keep add-local-quotation ]
bi infer-quot bi infer-quot
] [ ] [
value>> \ bad-call boa time-bomb value>> \ call time-bomb
] if ] if
] if ; ] if ;

View File

@ -156,17 +156,12 @@ M: object infer-call* \ call bad-macro-input ;
\ compose [ infer-compose ] "special" set-word-prop \ compose [ infer-compose ] "special" set-word-prop
ERROR: bad-executable obj ;
M: bad-executable summary
drop "execute must be given a word" ;
: infer-execute ( -- ) : infer-execute ( -- )
pop-literal nip pop-literal nip
dup word? [ dup word? [
apply-object apply-object
] [ ] [
\ bad-executable boa time-bomb \ execute time-bomb
] if ; ] if ;
\ execute [ infer-execute ] "special" set-word-prop \ execute [ infer-execute ] "special" set-word-prop

View File

@ -145,7 +145,9 @@ IN: stack-checker.transforms
[ depends-on-tuple-layout ] [ depends-on-tuple-layout ]
[ [ "boa-check" word-prop [ ] or ] dip ] 2bi [ [ "boa-check" word-prop [ ] or ] dip ] 2bi
'[ @ _ <tuple-boa> ] '[ @ _ <tuple-boa> ]
] [ drop f ] if ] [
\ boa time-bomb
] if
] 1 define-transform ] 1 define-transform
\ boa t "no-compile" set-word-prop \ boa t "no-compile" set-word-prop

View File

@ -106,12 +106,12 @@ M: f >label drop <gadget> ;
{ 5 5 } >>gap ; inline { 5 5 } >>gap ; inline
PRIVATE> PRIVATE>
: label-on-left ( gadget label -- button ) : label-on-left ( gadget label -- track )
label-on-left/right label-on-left/right
swap >label f track-add swap >label f track-add
swap 1 track-add ; swap 1 track-add ;
: label-on-right ( label gadget -- button ) : label-on-right ( label gadget -- track )
label-on-left/right label-on-left/right
swap f track-add swap f track-add
swap >label 1 track-add ; swap >label 1 track-add ;

View File

@ -129,6 +129,7 @@ M: world request-focus-on ( child gadget -- )
[ T{ rgba f 1.0 1.0 1.0 1.0 } ] if ; [ T{ rgba f 1.0 1.0 1.0 1.0 } ] if ;
GENERIC# apply-world-attributes 1 ( world attributes -- world ) GENERIC# apply-world-attributes 1 ( world attributes -- world )
M: world apply-world-attributes M: world apply-world-attributes
{ {
[ title>> >>title ] [ title>> >>title ]
@ -166,15 +167,11 @@ flush-layout-cache-hook [ [ ] ] initialize
GENERIC: begin-world ( world -- ) GENERIC: begin-world ( world -- )
GENERIC: end-world ( world -- ) GENERIC: end-world ( world -- )
GENERIC: resize-world ( world -- ) GENERIC: resize-world ( world -- )
M: world begin-world M: world begin-world drop ;
drop ; M: world end-world drop ;
M: world end-world M: world resize-world drop ;
drop ;
M: world resize-world
drop ;
M: world dim<< M: world dim<<
[ call-next-method ] [ call-next-method ]

View File

@ -81,6 +81,9 @@ M: world graft*
[ [ clean-up-broken-window ] [ ui-error ] bi* ] recover [ [ clean-up-broken-window ] [ ui-error ] bi* ] recover
] bi ; ] bi ;
: dispose-window-resources ( world -- )
[ <reversed> [ [ dispose ] when* ] each V{ } clone ] change-window-resources drop ;
M: world ungraft* M: world ungraft*
{ {
[ set-gl-context ] [ set-gl-context ]
@ -89,9 +92,9 @@ M: world ungraft*
[ hand-clicked close-global ] [ hand-clicked close-global ]
[ hand-gadget close-global ] [ hand-gadget close-global ]
[ end-world ] [ end-world ]
[ [ <reversed> [ [ dispose ] when* ] each V{ } clone ] change-window-resources drop ] [ dispose-window-resources ]
[ [ (close-window) f ] change-handle drop ]
[ unfocus-world ] [ unfocus-world ]
[ [ (close-window) f ] change-handle drop ]
[ promise>> t swap fulfill ] [ promise>> t swap fulfill ]
} cleave ; } cleave ;

View File

@ -273,8 +273,14 @@ test-server-slot-values
! Dynamically changing inheritance hierarchy ! Dynamically changing inheritance hierarchy
TUPLE: electronic-device ; TUPLE: electronic-device ;
: computer?' ( a -- b ) computer? ;
[ t ] [ laptop new computer?' ] unit-test
[ ] [ "IN: classes.tuple.tests TUPLE: computer < electronic-device cpu ram ; C: <computer> computer C: <laptop> laptop C: <server> server" eval( -- ) ] unit-test [ ] [ "IN: classes.tuple.tests TUPLE: computer < electronic-device cpu ram ; C: <computer> computer C: <laptop> laptop C: <server> server" eval( -- ) ] unit-test
[ t ] [ laptop new computer?' ] unit-test
[ f ] [ electronic-device laptop class<= ] unit-test [ f ] [ electronic-device laptop class<= ] unit-test
[ t ] [ server electronic-device class<= ] unit-test [ t ] [ server electronic-device class<= ] unit-test
[ t ] [ laptop server class-or electronic-device class<= ] unit-test [ t ] [ laptop server class-or electronic-device class<= ] unit-test

View File

@ -1,7 +1,7 @@
! Copyright (C) 2010 Dmitry Shubin. ! Copyright (C) 2010 Dmitry Shubin.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays continuations gdbm io.directories USING: accessors arrays continuations gdbm io.directories
io.files.temp kernel sequences sets tools.test ; io.files.temp kernel sequences sets system tools.test ;
IN: gdbm.tests IN: gdbm.tests
: db-path ( -- filename ) "test.db" temp-file ; : db-path ( -- filename ) "test.db" temp-file ;
@ -12,7 +12,7 @@ IN: gdbm.tests
: with-test.db ( quot -- ) test.db swap with-gdbm ; inline : with-test.db ( quot -- ) test.db swap with-gdbm ; inline
os windows? cpu x86.64? and [
CLEANUP CLEANUP
@ -61,3 +61,4 @@ CLEANUP
CLEANUP CLEANUP
] unless

View File

@ -119,10 +119,6 @@ UNIFORM-TUPLE: loading-uniforms
100000 <uint-vector> 100000 <uint-vector>
(parse-bunny-model) ; inline (parse-bunny-model) ; inline
:: normal ( a b c -- normal )
c a v-
b a v- cross normalize ; inline
:: calc-bunny-normal ( a b c vertexes -- ) :: calc-bunny-normal ( a b c vertexes -- )
a b c [ vertexes nth vertex>> ] tri@ normal :> n a b c [ vertexes nth vertex>> ] tri@ normal :> n
a b c [ vertexes nth [ n v+ ] change-normal drop ] tri@ ; inline a b c [ vertexes nth [ n v+ ] change-normal drop ] tri@ ; inline

View File

@ -27,11 +27,6 @@ char *factor_vm::pinned_alien_offset(cell obj)
} }
} }
VM_C_API char *pinned_alien_offset(cell obj, factor_vm *parent)
{
return parent->pinned_alien_offset(obj);
}
/* make an alien */ /* make an alien */
cell factor_vm::allot_alien(cell delegate_, cell displacement) cell factor_vm::allot_alien(cell delegate_, cell displacement)
{ {
@ -62,11 +57,6 @@ cell factor_vm::allot_alien(void *address)
return allot_alien(false_object,(cell)address); return allot_alien(false_object,(cell)address);
} }
VM_C_API cell allot_alien(void *address, factor_vm *vm)
{
return vm->allot_alien(address);
}
/* make an alien pointing at an offset of another alien */ /* make an alien pointing at an offset of another alien */
void factor_vm::primitive_displaced_alien() void factor_vm::primitive_displaced_alien()
{ {
@ -90,7 +80,7 @@ void factor_vm::primitive_displaced_alien()
if the object is a byte array, as a sanity check. */ if the object is a byte array, as a sanity check. */
void factor_vm::primitive_alien_address() void factor_vm::primitive_alien_address()
{ {
ctx->push(allot_cell((cell)pinned_alien_offset(ctx->pop()))); ctx->push(from_unsigned_cell((cell)pinned_alien_offset(ctx->pop())));
} }
/* pop ( alien n ) from datastack, return alien's address plus n */ /* pop ( alien n ) from datastack, return alien's address plus n */
@ -182,9 +172,4 @@ char *factor_vm::alien_offset(cell obj)
} }
} }
VM_C_API char *alien_offset(cell obj, factor_vm *parent)
{
return parent->alien_offset(obj);
}
} }

View File

@ -1,8 +1,4 @@
namespace factor namespace factor
{ {
VM_C_API char *alien_offset(cell object, factor_vm *vm);
VM_C_API char *pinned_alien_offset(cell object, factor_vm *vm);
VM_C_API cell allot_alien(void *address, factor_vm *vm);
} }

View File

@ -222,9 +222,10 @@ struct code_block_accumulator {
/* Note: the entry point is always a multiple of the heap /* Note: the entry point is always a multiple of the heap
alignment (16 bytes). We cannot allocate while iterating alignment (16 bytes). We cannot allocate while iterating
through the code heap, so it is not possible to call allot_cell() through the code heap, so it is not possible to call
here. It is OK, however, to add it as if it were a fixnum, and from_unsigned_cell() here. It is OK, however, to add it as
have library code shift it to the left by 4. */ if it were a fixnum, and have library code shift it to the
left by 4. */
cell entry_point = (cell)compiled->entry_point(); cell entry_point = (cell)compiled->entry_point();
assert((entry_point & (data_alignment - 1)) == 0); assert((entry_point & (data_alignment - 1)) == 0);
assert((entry_point & TAG_MASK) == FIXNUM_TYPE); assert((entry_point & TAG_MASK) == FIXNUM_TYPE);

View File

@ -102,12 +102,12 @@ void factor_vm::memory_protection_error(cell addr, stack_frame *stack)
else if(ctx->callstack_seg->overflow_p(addr)) else if(ctx->callstack_seg->overflow_p(addr))
general_error(ERROR_CALLSTACK_UNDERFLOW,false_object,false_object,stack); general_error(ERROR_CALLSTACK_UNDERFLOW,false_object,false_object,stack);
else else
general_error(ERROR_MEMORY,allot_cell(addr),false_object,stack); general_error(ERROR_MEMORY,from_unsigned_cell(addr),false_object,stack);
} }
void factor_vm::signal_error(cell signal, stack_frame *stack) void factor_vm::signal_error(cell signal, stack_frame *stack)
{ {
general_error(ERROR_SIGNAL,allot_cell(signal),false_object,stack); general_error(ERROR_SIGNAL,from_unsigned_cell(signal),false_object,stack);
} }
void factor_vm::divide_by_zero_error() void factor_vm::divide_by_zero_error()

View File

@ -21,7 +21,7 @@ void factor_vm::primitive_fixnum_divint()
fixnum x = untag_fixnum(ctx->peek()); fixnum x = untag_fixnum(ctx->peek());
fixnum result = x / y; fixnum result = x / y;
if(result == -fixnum_min) if(result == -fixnum_min)
ctx->replace(allot_integer(-fixnum_min)); ctx->replace(from_signed_cell(-fixnum_min));
else else
ctx->replace(tag_fixnum(result)); ctx->replace(tag_fixnum(result));
} }
@ -32,7 +32,7 @@ void factor_vm::primitive_fixnum_divmod()
cell x = ((cell *)ctx->datastack)[-1]; cell x = ((cell *)ctx->datastack)[-1];
if(y == tag_fixnum(-1) && x == tag_fixnum(fixnum_min)) if(y == tag_fixnum(-1) && x == tag_fixnum(fixnum_min))
{ {
((cell *)ctx->datastack)[-1] = allot_integer(-fixnum_min); ((cell *)ctx->datastack)[-1] = from_signed_cell(-fixnum_min);
((cell *)ctx->datastack)[0] = tag_fixnum(0); ((cell *)ctx->datastack)[0] = tag_fixnum(0);
} }
else else
@ -335,7 +335,7 @@ void factor_vm::primitive_float_greatereq()
void factor_vm::primitive_float_bits() void factor_vm::primitive_float_bits()
{ {
ctx->push(from_unsigned_4(float_bits((float)untag_float_check(ctx->pop())))); ctx->push(from_unsigned_cell(float_bits((float)untag_float_check(ctx->pop()))));
} }
void factor_vm::primitive_bits_float() void factor_vm::primitive_bits_float()
@ -383,76 +383,6 @@ VM_C_API cell to_cell(cell tagged, factor_vm *parent)
return parent->to_cell(tagged); return parent->to_cell(tagged);
} }
cell factor_vm::from_signed_1(s8 n)
{
return tag_fixnum(n);
}
VM_C_API cell from_signed_1(s8 n, factor_vm *parent)
{
return parent->from_signed_1(n);
}
cell factor_vm::from_unsigned_1(u8 n)
{
return tag_fixnum(n);
}
VM_C_API cell from_unsigned_1(u8 n, factor_vm *parent)
{
return parent->from_unsigned_1(n);
}
cell factor_vm::from_signed_2(s16 n)
{
return tag_fixnum(n);
}
VM_C_API cell from_signed_2(s16 n, factor_vm *parent)
{
return parent->from_signed_2(n);
}
cell factor_vm::from_unsigned_2(u16 n)
{
return tag_fixnum(n);
}
VM_C_API cell from_unsigned_2(u16 n, factor_vm *parent)
{
return parent->from_unsigned_2(n);
}
cell factor_vm::from_signed_4(s32 n)
{
return allot_integer(n);
}
VM_C_API cell from_signed_4(s32 n, factor_vm *parent)
{
return parent->from_signed_4(n);
}
cell factor_vm::from_unsigned_4(u32 n)
{
return allot_cell(n);
}
VM_C_API cell from_unsigned_4(u32 n, factor_vm *parent)
{
return parent->from_unsigned_4(n);
}
cell factor_vm::from_signed_cell(fixnum integer)
{
return allot_integer(integer);
}
cell factor_vm::from_unsigned_cell(cell integer)
{
return allot_cell(integer);
}
VM_C_API cell from_signed_cell(fixnum integer, factor_vm *parent) VM_C_API cell from_signed_cell(fixnum integer, factor_vm *parent)
{ {
return parent->from_signed_cell(integer); return parent->from_signed_cell(integer);
@ -529,38 +459,18 @@ VM_C_API u64 to_unsigned_8(cell obj, factor_vm *parent)
return parent->to_unsigned_8(obj); return parent->to_unsigned_8(obj);
} }
VM_C_API cell from_float(float flo, factor_vm *parent)
{
return parent->allot_float(flo);
}
/* Cannot allocate */ /* Cannot allocate */
float factor_vm::to_float(cell value) float factor_vm::to_float(cell value)
{ {
return (float)untag_float_check(value); return (float)untag_float_check(value);
} }
VM_C_API float to_float(cell value, factor_vm *parent)
{
return parent->to_float(value);
}
VM_C_API cell from_double(double flo, factor_vm *parent)
{
return parent->allot_float(flo);
}
/* Cannot allocate */ /* Cannot allocate */
double factor_vm::to_double(cell value) double factor_vm::to_double(cell value)
{ {
return untag_float_check(value); return untag_float_check(value);
} }
VM_C_API double to_double(cell value, factor_vm *parent)
{
return parent->to_double(value);
}
/* The fixnum+, fixnum- and fixnum* primitives are defined in cpu_*.S. On /* The fixnum+, fixnum- and fixnum* primitives are defined in cpu_*.S. On
overflow, they call these functions. */ overflow, they call these functions. */
inline void factor_vm::overflow_fixnum_add(fixnum x, fixnum y) inline void factor_vm::overflow_fixnum_add(fixnum x, fixnum y)

View File

@ -5,7 +5,7 @@ static const fixnum fixnum_max = (((fixnum)1 << (WORD_SIZE - TAG_BITS - 1)) - 1)
static const fixnum fixnum_min = (-((fixnum)1 << (WORD_SIZE - TAG_BITS - 1))); static const fixnum fixnum_min = (-((fixnum)1 << (WORD_SIZE - TAG_BITS - 1)));
static const fixnum array_size_max = ((cell)1 << (WORD_SIZE - TAG_BITS - 2)); static const fixnum array_size_max = ((cell)1 << (WORD_SIZE - TAG_BITS - 2));
inline cell factor_vm::allot_integer(fixnum x) inline cell factor_vm::from_signed_cell(fixnum x)
{ {
if(x < fixnum_min || x > fixnum_max) if(x < fixnum_min || x > fixnum_max)
return tag<bignum>(fixnum_to_bignum(x)); return tag<bignum>(fixnum_to_bignum(x));
@ -13,7 +13,7 @@ inline cell factor_vm::allot_integer(fixnum x)
return tag_fixnum(x); return tag_fixnum(x);
} }
inline cell factor_vm::allot_cell(cell x) inline cell factor_vm::from_unsigned_cell(cell x)
{ {
if(x > (cell)fixnum_max) if(x > (cell)fixnum_max)
return tag<bignum>(cell_to_bignum(x)); return tag<bignum>(cell_to_bignum(x));
@ -74,17 +74,6 @@ inline cell factor_vm::unbox_array_size()
return unbox_array_size_slow(); return unbox_array_size_slow();
} }
VM_C_API cell from_float(float flo, factor_vm *vm);
VM_C_API float to_float(cell value, factor_vm *vm);
VM_C_API cell from_double(double flo, factor_vm *vm);
VM_C_API double to_double(cell value, factor_vm *vm);
VM_C_API cell from_signed_1(s8 n, factor_vm *vm);
VM_C_API cell from_unsigned_1(u8 n, factor_vm *vm);
VM_C_API cell from_signed_2(s16 n, factor_vm *vm);
VM_C_API cell from_unsigned_2(u16 n, factor_vm *vm);
VM_C_API cell from_signed_4(s32 n, factor_vm *vm);
VM_C_API cell from_unsigned_4(u32 n, factor_vm *vm);
VM_C_API cell from_signed_cell(fixnum integer, factor_vm *vm); VM_C_API cell from_signed_cell(fixnum integer, factor_vm *vm);
VM_C_API cell from_unsigned_cell(cell integer, factor_vm *vm); VM_C_API cell from_unsigned_cell(cell integer, factor_vm *vm);
VM_C_API cell from_signed_8(s64 n, factor_vm *vm); VM_C_API cell from_signed_8(s64 n, factor_vm *vm);

View File

@ -79,7 +79,7 @@ cell factor_vm::object_size(cell tagged)
void factor_vm::primitive_size() void factor_vm::primitive_size()
{ {
ctx->push(allot_cell(object_size(ctx->pop()))); ctx->push(from_unsigned_cell(object_size(ctx->pop())));
} }
struct slot_become_fixup : no_fixup { struct slot_become_fixup : no_fixup {

View File

@ -138,12 +138,12 @@ namespace factor
_(unsigned_cell,cell,from_unsigned_cell,to_cell) \ _(unsigned_cell,cell,from_unsigned_cell,to_cell) \
_(signed_8,s64,from_signed_8,to_signed_8) \ _(signed_8,s64,from_signed_8,to_signed_8) \
_(unsigned_8,u64,from_unsigned_8,to_unsigned_8) \ _(unsigned_8,u64,from_unsigned_8,to_unsigned_8) \
_(signed_4,s32,from_signed_4,to_fixnum) \ _(signed_4,s32,from_signed_cell,to_fixnum) \
_(unsigned_4,u32,from_unsigned_4,to_cell) \ _(unsigned_4,u32,from_unsigned_cell,to_cell) \
_(signed_2,s16,from_signed_2,to_fixnum) \ _(signed_2,s16,from_signed_cell,to_fixnum) \
_(unsigned_2,u16,from_unsigned_2,to_cell) \ _(unsigned_2,u16,from_unsigned_cell,to_cell) \
_(signed_1,s8,from_signed_1,to_fixnum) \ _(signed_1,s8,from_signed_cell,to_fixnum) \
_(unsigned_1,u8,from_unsigned_1,to_cell) \ _(unsigned_1,u8,from_unsigned_cell,to_cell) \
_(float,float,allot_float,to_float) \ _(float,float,allot_float,to_float) \
_(double,double,allot_float,to_double) \ _(double,double,allot_float,to_double) \
_(cell,void *,allot_alien,pinned_alien_offset) _(cell,void *,allot_alien,pinned_alien_offset)

View File

@ -328,8 +328,8 @@ void factor_vm::primitive_quotation_code()
{ {
quotation *quot = untag_check<quotation>(ctx->pop()); quotation *quot = untag_check<quotation>(ctx->pop());
ctx->push(allot_cell((cell)quot->code->entry_point())); ctx->push(from_unsigned_cell((cell)quot->code->entry_point()));
ctx->push(allot_cell((cell)quot->code + quot->code->size())); ctx->push(from_unsigned_cell((cell)quot->code + quot->code->size()));
} }
/* Allocates memory */ /* Allocates memory */

View File

@ -475,14 +475,6 @@ struct factor_vm
void primitive_bits_double(); void primitive_bits_double();
fixnum to_fixnum(cell tagged); fixnum to_fixnum(cell tagged);
cell to_cell(cell tagged); cell to_cell(cell tagged);
cell from_signed_1(s8 n);
cell from_unsigned_1(u8 n);
cell from_signed_2(s16 n);
cell from_unsigned_2(u16 n);
cell from_signed_4(s32 n);
cell from_unsigned_4(u32 n);
cell from_signed_cell(fixnum integer);
cell from_unsigned_cell(cell integer);
cell from_signed_8(s64 n); cell from_signed_8(s64 n);
s64 to_signed_8(cell obj); s64 to_signed_8(cell obj);
cell from_unsigned_8(u64 n); cell from_unsigned_8(u64 n);
@ -492,8 +484,8 @@ struct factor_vm
inline void overflow_fixnum_add(fixnum x, fixnum y); inline void overflow_fixnum_add(fixnum x, fixnum y);
inline void overflow_fixnum_subtract(fixnum x, fixnum y); inline void overflow_fixnum_subtract(fixnum x, fixnum y);
inline void overflow_fixnum_multiply(fixnum x, fixnum y); inline void overflow_fixnum_multiply(fixnum x, fixnum y);
inline cell allot_integer(fixnum x); inline cell from_signed_cell(fixnum x);
inline cell allot_cell(cell x); inline cell from_unsigned_cell(cell x);
inline cell allot_float(double n); inline cell allot_float(double n);
inline bignum *float_to_bignum(cell tagged); inline bignum *float_to_bignum(cell tagged);
inline double bignum_to_float(cell tagged); inline double bignum_to_float(cell tagged);

View File

@ -91,13 +91,13 @@ void factor_vm::primitive_word_code()
if(profiling_p) if(profiling_p)
{ {
ctx->push(allot_cell((cell)w->profiling->entry_point())); ctx->push(from_unsigned_cell((cell)w->profiling->entry_point()));
ctx->push(allot_cell((cell)w->profiling + w->profiling->size())); ctx->push(from_unsigned_cell((cell)w->profiling + w->profiling->size()));
} }
else else
{ {
ctx->push(allot_cell((cell)w->code->entry_point())); ctx->push(from_unsigned_cell((cell)w->code->entry_point()));
ctx->push(allot_cell((cell)w->code + w->code->size())); ctx->push(from_unsigned_cell((cell)w->code + w->code->size()));
} }
} }