Merge branch 'master' of git://factorcode.org/git/factor
commit
dfb638e30c
|
@ -7,7 +7,7 @@ IN: alien
|
||||||
|
|
||||||
! Some predicate classes used by the compiler for optimization
|
! Some predicate classes used by the compiler for optimization
|
||||||
! purposes
|
! purposes
|
||||||
PREDICATE: alien simple-alien
|
PREDICATE: simple-alien < alien
|
||||||
underlying-alien not ;
|
underlying-alien not ;
|
||||||
|
|
||||||
UNION: simple-c-ptr
|
UNION: simple-c-ptr
|
||||||
|
@ -18,7 +18,7 @@ alien POSTPONE: f byte-array bit-array float-array ;
|
||||||
|
|
||||||
DEFER: pinned-c-ptr?
|
DEFER: pinned-c-ptr?
|
||||||
|
|
||||||
PREDICATE: alien pinned-alien
|
PREDICATE: pinned-alien < alien
|
||||||
underlying-alien pinned-c-ptr? ;
|
underlying-alien pinned-c-ptr? ;
|
||||||
|
|
||||||
UNION: pinned-c-ptr
|
UNION: pinned-c-ptr
|
||||||
|
|
|
@ -31,4 +31,4 @@ INSTANCE: array sequence
|
||||||
|
|
||||||
: 4array ( w x y z -- array ) { } 4sequence ; flushable
|
: 4array ( w x y z -- array ) { } 4sequence ; flushable
|
||||||
|
|
||||||
PREDICATE: array pair length 2 number= ;
|
PREDICATE: pair < array length 2 number= ;
|
||||||
|
|
|
@ -93,3 +93,14 @@ unit-test
|
||||||
] [
|
] [
|
||||||
F{ 1.0 2.0 } [ dup ] H{ } map>assoc
|
F{ 1.0 2.0 } [ dup ] H{ } map>assoc
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
[ { 3 } ] [
|
||||||
|
[
|
||||||
|
3
|
||||||
|
H{ } clone
|
||||||
|
2 [
|
||||||
|
2dup [ , f ] cache
|
||||||
|
] times
|
||||||
|
2drop
|
||||||
|
] make
|
||||||
|
] unit-test
|
||||||
|
|
|
@ -134,11 +134,11 @@ M: assoc assoc-clone-like ( assoc exemplar -- newassoc )
|
||||||
(substitute) map ;
|
(substitute) map ;
|
||||||
|
|
||||||
: cache ( key assoc quot -- value )
|
: cache ( key assoc quot -- value )
|
||||||
2over at [
|
2over at* [
|
||||||
>r 3drop r>
|
>r 3drop r>
|
||||||
] [
|
] [
|
||||||
pick rot >r >r call dup r> r> set-at
|
drop pick rot >r >r call dup r> r> set-at
|
||||||
] if* ; inline
|
] if ; inline
|
||||||
|
|
||||||
: change-at ( key assoc quot -- )
|
: change-at ( key assoc quot -- )
|
||||||
[ >r at r> call ] 3keep drop set-at ; inline
|
[ >r at r> call ] 3keep drop set-at ; inline
|
||||||
|
|
|
@ -36,7 +36,7 @@ nl
|
||||||
{
|
{
|
||||||
roll -roll declare not
|
roll -roll declare not
|
||||||
|
|
||||||
tuple-class-eq? array? hashtable? vector?
|
array? hashtable? vector?
|
||||||
tuple? sbuf? node? tombstone?
|
tuple? sbuf? node? tombstone?
|
||||||
|
|
||||||
array-capacity array-nth set-array-nth
|
array-capacity array-nth set-array-nth
|
||||||
|
|
|
@ -4,7 +4,7 @@ USING: alien arrays bit-arrays byte-arrays generic assocs
|
||||||
hashtables assocs hashtables.private io kernel kernel.private
|
hashtables assocs hashtables.private io kernel kernel.private
|
||||||
math namespaces parser prettyprint sequences sequences.private
|
math namespaces parser prettyprint sequences sequences.private
|
||||||
strings sbufs vectors words quotations assocs system layouts
|
strings sbufs vectors words quotations assocs system layouts
|
||||||
splitting growable classes tuples words.private
|
splitting growable classes tuples tuples.private words.private
|
||||||
io.binary io.files vocabs vocabs.loader source-files
|
io.binary io.files vocabs vocabs.loader source-files
|
||||||
definitions debugger float-arrays quotations.private
|
definitions debugger float-arrays quotations.private
|
||||||
sequences.private combinators io.encodings.binary ;
|
sequences.private combinators io.encodings.binary ;
|
||||||
|
@ -294,17 +294,14 @@ M: bit-array ' bit-array emit-dummy-array ;
|
||||||
|
|
||||||
M: float-array ' float-array emit-dummy-array ;
|
M: float-array ' float-array emit-dummy-array ;
|
||||||
|
|
||||||
! Arrays
|
! Tuples
|
||||||
: emit-array ( list type tag -- pointer )
|
: emit-tuple ( tuple -- pointer )
|
||||||
>r >r [ ' ] map r> r> [
|
|
||||||
dup length emit-fixnum
|
|
||||||
emit-seq
|
|
||||||
] emit-object ;
|
|
||||||
|
|
||||||
: emit-tuple ( obj -- pointer )
|
|
||||||
[
|
[
|
||||||
[ tuple>array unclip transfer-word , % ] { } make
|
[
|
||||||
tuple type-number dup emit-array
|
dup class transfer-word tuple-layout ' ,
|
||||||
|
tuple>array 1 tail-slice [ ' ] map %
|
||||||
|
] { } make
|
||||||
|
tuple type-number dup [ emit-seq ] emit-object
|
||||||
]
|
]
|
||||||
! Hack
|
! Hack
|
||||||
over class word-name "tombstone" =
|
over class word-name "tombstone" =
|
||||||
|
@ -312,11 +309,31 @@ M: float-array ' float-array emit-dummy-array ;
|
||||||
|
|
||||||
M: tuple ' emit-tuple ;
|
M: tuple ' emit-tuple ;
|
||||||
|
|
||||||
|
M: tuple-layout '
|
||||||
|
objects get [
|
||||||
|
[
|
||||||
|
dup layout-hashcode ' ,
|
||||||
|
dup layout-class ' ,
|
||||||
|
dup layout-size ' ,
|
||||||
|
dup layout-superclasses ' ,
|
||||||
|
layout-echelon ' ,
|
||||||
|
] { } make
|
||||||
|
\ tuple-layout type-number
|
||||||
|
object tag-number [ emit-seq ] emit-object
|
||||||
|
] cache ;
|
||||||
|
|
||||||
M: tombstone '
|
M: tombstone '
|
||||||
delegate
|
delegate
|
||||||
"((tombstone))" "((empty))" ? "hashtables.private" lookup
|
"((tombstone))" "((empty))" ? "hashtables.private" lookup
|
||||||
word-def first objects get [ emit-tuple ] cache ;
|
word-def first objects get [ emit-tuple ] cache ;
|
||||||
|
|
||||||
|
! Arrays
|
||||||
|
: emit-array ( list type tag -- pointer )
|
||||||
|
>r >r [ ' ] map r> r> [
|
||||||
|
dup length emit-fixnum
|
||||||
|
emit-seq
|
||||||
|
] emit-object ;
|
||||||
|
|
||||||
M: array '
|
M: array '
|
||||||
array type-number object tag-number emit-array ;
|
array type-number object tag-number emit-array ;
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,13 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: namespaces math words kernel alien byte-arrays
|
USING: namespaces math words kernel alien byte-arrays
|
||||||
hashtables vectors strings sbufs arrays bit-arrays
|
hashtables vectors strings sbufs arrays bit-arrays
|
||||||
float-arrays quotations assocs layouts tuples ;
|
float-arrays quotations assocs layouts tuples tuples.private ;
|
||||||
|
|
||||||
BIN: 111 tag-mask set
|
BIN: 111 tag-mask set
|
||||||
8 num-tags set
|
8 num-tags set
|
||||||
3 tag-bits set
|
3 tag-bits set
|
||||||
|
|
||||||
19 num-types set
|
20 num-types set
|
||||||
|
|
||||||
H{
|
H{
|
||||||
{ fixnum BIN: 000 }
|
{ fixnum BIN: 000 }
|
||||||
|
@ -33,4 +33,5 @@ tag-numbers get H{
|
||||||
{ alien 16 }
|
{ alien 16 }
|
||||||
{ word 17 }
|
{ word 17 }
|
||||||
{ byte-array 18 }
|
{ byte-array 18 }
|
||||||
|
{ tuple-layout 19 }
|
||||||
} union type-numbers set
|
} union type-numbers set
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
USING: alien arrays byte-arrays generic hashtables
|
USING: alien arrays byte-arrays generic hashtables
|
||||||
hashtables.private io kernel math namespaces parser sequences
|
hashtables.private io kernel math namespaces parser sequences
|
||||||
strings vectors words quotations assocs layouts classes tuples
|
strings vectors words quotations assocs layouts classes tuples
|
||||||
kernel.private vocabs vocabs.loader source-files definitions
|
tuples.private kernel.private vocabs vocabs.loader source-files
|
||||||
slots.deprecated classes.union compiler.units
|
definitions slots.deprecated classes.union compiler.units
|
||||||
bootstrap.image.private io.files ;
|
bootstrap.image.private io.files ;
|
||||||
IN: bootstrap.primitives
|
IN: bootstrap.primitives
|
||||||
|
|
||||||
|
@ -33,7 +33,6 @@ H{ } clone changed-words set
|
||||||
H{ } clone root-cache set
|
H{ } clone root-cache set
|
||||||
H{ } clone source-files set
|
H{ } clone source-files set
|
||||||
H{ } clone update-map set
|
H{ } clone update-map set
|
||||||
num-types get f <array> builtins set
|
|
||||||
init-caches
|
init-caches
|
||||||
|
|
||||||
! Vocabulary for slot accessors
|
! Vocabulary for slot accessors
|
||||||
|
@ -47,6 +46,9 @@ call
|
||||||
call
|
call
|
||||||
call
|
call
|
||||||
|
|
||||||
|
! After we execute bootstrap/layouts
|
||||||
|
num-types get f <array> builtins set
|
||||||
|
|
||||||
! Create some empty vocabs where the below primitives and
|
! Create some empty vocabs where the below primitives and
|
||||||
! classes will go
|
! classes will go
|
||||||
{
|
{
|
||||||
|
@ -141,8 +143,6 @@ call
|
||||||
"bignum" "math" create { } define-builtin
|
"bignum" "math" create { } define-builtin
|
||||||
"bignum" "math" create ">bignum" "math" create 1quotation "coercer" set-word-prop
|
"bignum" "math" create ">bignum" "math" create 1quotation "coercer" set-word-prop
|
||||||
|
|
||||||
"tuple" "kernel" create { } define-builtin
|
|
||||||
|
|
||||||
"ratio" "math" create {
|
"ratio" "math" create {
|
||||||
{
|
{
|
||||||
{ "integer" "math" }
|
{ "integer" "math" }
|
||||||
|
@ -178,8 +178,6 @@ call
|
||||||
|
|
||||||
"f" "syntax" lookup { } define-builtin
|
"f" "syntax" lookup { } define-builtin
|
||||||
|
|
||||||
! do not word...
|
|
||||||
|
|
||||||
"array" "arrays" create { } define-builtin
|
"array" "arrays" create { } define-builtin
|
||||||
|
|
||||||
"wrapper" "kernel" create {
|
"wrapper" "kernel" create {
|
||||||
|
@ -293,6 +291,48 @@ define-builtin
|
||||||
|
|
||||||
"callstack" "kernel" create { } define-builtin
|
"callstack" "kernel" create { } define-builtin
|
||||||
|
|
||||||
|
"tuple-layout" "tuples.private" create {
|
||||||
|
{
|
||||||
|
{ "fixnum" "math" }
|
||||||
|
"hashcode"
|
||||||
|
{ "layout-hashcode" "tuples.private" }
|
||||||
|
f
|
||||||
|
}
|
||||||
|
{
|
||||||
|
{ "word" "words" }
|
||||||
|
"class"
|
||||||
|
{ "layout-class" "tuples.private" }
|
||||||
|
f
|
||||||
|
}
|
||||||
|
{
|
||||||
|
{ "fixnum" "math" }
|
||||||
|
"size"
|
||||||
|
{ "layout-size" "tuples.private" }
|
||||||
|
f
|
||||||
|
}
|
||||||
|
{
|
||||||
|
{ "array" "arrays" }
|
||||||
|
"superclasses"
|
||||||
|
{ "layout-superclasses" "tuples.private" }
|
||||||
|
f
|
||||||
|
}
|
||||||
|
{
|
||||||
|
{ "fixnum" "math" }
|
||||||
|
"echelon"
|
||||||
|
{ "layout-echelon" "tuples.private" }
|
||||||
|
f
|
||||||
|
}
|
||||||
|
} define-builtin
|
||||||
|
|
||||||
|
"tuple" "kernel" create {
|
||||||
|
{
|
||||||
|
{ "tuple-layout" "tuples.private" }
|
||||||
|
"layout"
|
||||||
|
{ "tuple-layout" "tuples.private" }
|
||||||
|
f
|
||||||
|
}
|
||||||
|
} define-builtin
|
||||||
|
|
||||||
! Define general-t type, which is any object that is not f.
|
! Define general-t type, which is any object that is not f.
|
||||||
"general-t" "kernel" create
|
"general-t" "kernel" create
|
||||||
"f" "syntax" lookup builtins get remove [ ] subset f union-class
|
"f" "syntax" lookup builtins get remove [ ] subset f union-class
|
||||||
|
@ -318,7 +358,9 @@ builtins get num-tags get tail f union-class define-class
|
||||||
"null" "kernel" create { } f union-class define-class
|
"null" "kernel" create { } f union-class define-class
|
||||||
|
|
||||||
! Create special tombstone values
|
! Create special tombstone values
|
||||||
"tombstone" "hashtables.private" create { } define-tuple-class
|
"tombstone" "hashtables.private" create
|
||||||
|
"tuple" "kernel" lookup
|
||||||
|
{ } define-tuple-class
|
||||||
|
|
||||||
"((empty))" "hashtables.private" create
|
"((empty))" "hashtables.private" create
|
||||||
"tombstone" "hashtables.private" lookup f
|
"tombstone" "hashtables.private" lookup f
|
||||||
|
@ -330,6 +372,7 @@ builtins get num-tags get tail f union-class define-class
|
||||||
|
|
||||||
! Some tuple classes
|
! Some tuple classes
|
||||||
"hashtable" "hashtables" create
|
"hashtable" "hashtables" create
|
||||||
|
"tuple" "kernel" lookup
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
{ "array-capacity" "sequences.private" }
|
{ "array-capacity" "sequences.private" }
|
||||||
|
@ -350,6 +393,7 @@ builtins get num-tags get tail f union-class define-class
|
||||||
} define-tuple-class
|
} define-tuple-class
|
||||||
|
|
||||||
"sbuf" "sbufs" create
|
"sbuf" "sbufs" create
|
||||||
|
"tuple" "kernel" lookup
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
{ "string" "strings" }
|
{ "string" "strings" }
|
||||||
|
@ -365,6 +409,7 @@ builtins get num-tags get tail f union-class define-class
|
||||||
} define-tuple-class
|
} define-tuple-class
|
||||||
|
|
||||||
"vector" "vectors" create
|
"vector" "vectors" create
|
||||||
|
"tuple" "kernel" lookup
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
{ "array" "arrays" }
|
{ "array" "arrays" }
|
||||||
|
@ -380,6 +425,7 @@ builtins get num-tags get tail f union-class define-class
|
||||||
} define-tuple-class
|
} define-tuple-class
|
||||||
|
|
||||||
"byte-vector" "byte-vectors" create
|
"byte-vector" "byte-vectors" create
|
||||||
|
"tuple" "kernel" lookup
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
{ "byte-array" "byte-arrays" }
|
{ "byte-array" "byte-arrays" }
|
||||||
|
@ -395,6 +441,7 @@ builtins get num-tags get tail f union-class define-class
|
||||||
} define-tuple-class
|
} define-tuple-class
|
||||||
|
|
||||||
"bit-vector" "bit-vectors" create
|
"bit-vector" "bit-vectors" create
|
||||||
|
"tuple" "kernel" lookup
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
{ "bit-array" "bit-arrays" }
|
{ "bit-array" "bit-arrays" }
|
||||||
|
@ -410,6 +457,7 @@ builtins get num-tags get tail f union-class define-class
|
||||||
} define-tuple-class
|
} define-tuple-class
|
||||||
|
|
||||||
"float-vector" "float-vectors" create
|
"float-vector" "float-vectors" create
|
||||||
|
"tuple" "kernel" lookup
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
{ "float-array" "float-arrays" }
|
{ "float-array" "float-arrays" }
|
||||||
|
@ -425,6 +473,7 @@ builtins get num-tags get tail f union-class define-class
|
||||||
} define-tuple-class
|
} define-tuple-class
|
||||||
|
|
||||||
"curry" "kernel" create
|
"curry" "kernel" create
|
||||||
|
"tuple" "kernel" lookup
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
{ "object" "kernel" }
|
{ "object" "kernel" }
|
||||||
|
@ -439,7 +488,12 @@ builtins get num-tags get tail f union-class define-class
|
||||||
}
|
}
|
||||||
} define-tuple-class
|
} define-tuple-class
|
||||||
|
|
||||||
|
"curry" "kernel" lookup
|
||||||
|
dup f "inline" set-word-prop
|
||||||
|
dup tuple-layout [ <tuple-boa> ] curry define
|
||||||
|
|
||||||
"compose" "kernel" create
|
"compose" "kernel" create
|
||||||
|
"tuple" "kernel" lookup
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
{ "object" "kernel" }
|
{ "object" "kernel" }
|
||||||
|
@ -454,6 +508,10 @@ builtins get num-tags get tail f union-class define-class
|
||||||
}
|
}
|
||||||
} define-tuple-class
|
} define-tuple-class
|
||||||
|
|
||||||
|
"compose" "kernel" lookup
|
||||||
|
dup f "inline" set-word-prop
|
||||||
|
dup tuple-layout [ <tuple-boa> ] curry define
|
||||||
|
|
||||||
! Primitive words
|
! Primitive words
|
||||||
: make-primitive ( word vocab n -- )
|
: make-primitive ( word vocab n -- )
|
||||||
>r create dup reset-word r>
|
>r create dup reset-word r>
|
||||||
|
@ -628,11 +686,10 @@ builtins get num-tags get tail f union-class define-class
|
||||||
{ "<wrapper>" "kernel" }
|
{ "<wrapper>" "kernel" }
|
||||||
{ "(clone)" "kernel" }
|
{ "(clone)" "kernel" }
|
||||||
{ "<string>" "strings" }
|
{ "<string>" "strings" }
|
||||||
{ "(>tuple)" "tuples.private" }
|
|
||||||
{ "array>quotation" "quotations.private" }
|
{ "array>quotation" "quotations.private" }
|
||||||
{ "quotation-xt" "quotations" }
|
{ "quotation-xt" "quotations" }
|
||||||
{ "<tuple>" "tuples.private" }
|
{ "<tuple>" "tuples.private" }
|
||||||
{ "tuple>array" "tuples" }
|
{ "<tuple-layout>" "tuples.private" }
|
||||||
{ "profiling" "tools.profiler.private" }
|
{ "profiling" "tools.profiler.private" }
|
||||||
{ "become" "kernel.private" }
|
{ "become" "kernel.private" }
|
||||||
{ "(sleep)" "threads.private" }
|
{ "(sleep)" "threads.private" }
|
||||||
|
|
|
@ -39,15 +39,15 @@ HELP: sort-classes
|
||||||
{ $description "Outputs a topological sort of a sequence of classes. Larger classes come before their subclasses." } ;
|
{ $description "Outputs a topological sort of a sequence of classes. Larger classes come before their subclasses." } ;
|
||||||
|
|
||||||
HELP: class-or
|
HELP: class-or
|
||||||
{ $values { "class1" class } { "class2" class } { "class" class } }
|
{ $values { "first" class } { "second" class } { "class" class } }
|
||||||
{ $description "Outputs the smallest anonymous class containing both " { $snippet "class1" } " and " { $snippet "class2" } "." } ;
|
{ $description "Outputs the smallest anonymous class containing both " { $snippet "class1" } " and " { $snippet "class2" } "." } ;
|
||||||
|
|
||||||
HELP: class-and
|
HELP: class-and
|
||||||
{ $values { "class1" class } { "class2" class } { "class" class } }
|
{ $values { "first" class } { "second" class } { "class" class } }
|
||||||
{ $description "Outputs the largest anonymous class contained in both " { $snippet "class1" } " and " { $snippet "class2" } "." } ;
|
{ $description "Outputs the largest anonymous class contained in both " { $snippet "class1" } " and " { $snippet "class2" } "." } ;
|
||||||
|
|
||||||
HELP: classes-intersect?
|
HELP: classes-intersect?
|
||||||
{ $values { "class1" class } { "class2" class } { "?" "a boolean" } }
|
{ $values { "first" class } { "second" class } { "?" "a boolean" } }
|
||||||
{ $description "Tests if two classes have a non-empty intersection. If the intersection is empty, no object can be an instance of both classes at once." } ;
|
{ $description "Tests if two classes have a non-empty intersection. If the intersection is empty, no object can be an instance of both classes at once." } ;
|
||||||
|
|
||||||
HELP: min-class
|
HELP: min-class
|
||||||
|
|
|
@ -51,7 +51,7 @@ UNION: both first-one union-class ;
|
||||||
[ f ] [ \ reversed \ slice class< ] unit-test
|
[ f ] [ \ reversed \ slice class< ] unit-test
|
||||||
[ f ] [ \ slice \ reversed class< ] unit-test
|
[ f ] [ \ slice \ reversed class< ] unit-test
|
||||||
|
|
||||||
PREDICATE: word no-docs "documentation" word-prop not ;
|
PREDICATE: no-docs < word "documentation" word-prop not ;
|
||||||
|
|
||||||
UNION: no-docs-union no-docs integer ;
|
UNION: no-docs-union no-docs integer ;
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ M: union-1 generic-update-test drop "union-1" ;
|
||||||
[ f ] [ union-1 number class< ] unit-test
|
[ f ] [ union-1 number class< ] unit-test
|
||||||
[ "union-1" ] [ { 1.0 } generic-update-test ] unit-test
|
[ "union-1" ] [ { 1.0 } generic-update-test ] unit-test
|
||||||
|
|
||||||
"IN: classes.tests USE: math PREDICATE: integer union-1 even? ;" eval
|
"IN: classes.tests USE: math PREDICATE: union-1 < integer even? ;" eval
|
||||||
|
|
||||||
[ f ] [ union-1 union-class? ] unit-test
|
[ f ] [ union-1 union-class? ] unit-test
|
||||||
[ t ] [ union-1 predicate-class? ] unit-test
|
[ t ] [ union-1 predicate-class? ] unit-test
|
||||||
|
|
|
@ -25,15 +25,15 @@ SYMBOL: class-or-cache
|
||||||
class-and-cache get clear-assoc
|
class-and-cache get clear-assoc
|
||||||
class-or-cache get clear-assoc ;
|
class-or-cache get clear-assoc ;
|
||||||
|
|
||||||
PREDICATE: word class ( obj -- ? ) "class" word-prop ;
|
PREDICATE: class < word ( obj -- ? ) "class" word-prop ;
|
||||||
|
|
||||||
SYMBOL: update-map
|
SYMBOL: update-map
|
||||||
SYMBOL: builtins
|
SYMBOL: builtins
|
||||||
|
|
||||||
PREDICATE: class builtin-class
|
PREDICATE: builtin-class < class
|
||||||
"metaclass" word-prop builtin-class eq? ;
|
"metaclass" word-prop builtin-class eq? ;
|
||||||
|
|
||||||
PREDICATE: class tuple-class
|
PREDICATE: tuple-class < class
|
||||||
"metaclass" word-prop tuple-class eq? ;
|
"metaclass" word-prop tuple-class eq? ;
|
||||||
|
|
||||||
: classes ( -- seq ) all-words [ class? ] subset ;
|
: classes ( -- seq ) all-words [ class? ] subset ;
|
||||||
|
@ -47,7 +47,7 @@ PREDICATE: class tuple-class
|
||||||
|
|
||||||
: predicate-effect 1 { "?" } <effect> ;
|
: predicate-effect 1 { "?" } <effect> ;
|
||||||
|
|
||||||
PREDICATE: word predicate "predicating" word-prop >boolean ;
|
PREDICATE: predicate < word "predicating" word-prop >boolean ;
|
||||||
|
|
||||||
: define-predicate ( class quot -- )
|
: define-predicate ( class quot -- )
|
||||||
>r "predicate" word-prop first
|
>r "predicate" word-prop first
|
||||||
|
@ -118,10 +118,3 @@ GENERIC: update-methods ( assoc -- )
|
||||||
GENERIC: class ( object -- class ) inline
|
GENERIC: class ( object -- class ) inline
|
||||||
|
|
||||||
M: object class type type>class ;
|
M: object class type type>class ;
|
||||||
|
|
||||||
<PRIVATE
|
|
||||||
|
|
||||||
: class-of-tuple ( obj -- class )
|
|
||||||
2 slot { word } declare ; inline
|
|
||||||
|
|
||||||
PRIVATE>
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ USING: classes classes.union words kernel sequences
|
||||||
definitions combinators arrays ;
|
definitions combinators arrays ;
|
||||||
IN: classes.mixin
|
IN: classes.mixin
|
||||||
|
|
||||||
PREDICATE: union-class mixin-class "mixin" word-prop ;
|
PREDICATE: mixin-class < union-class "mixin" word-prop ;
|
||||||
|
|
||||||
M: mixin-class reset-class
|
M: mixin-class reset-class
|
||||||
{ "metaclass" "members" "mixin" } reset-props ;
|
{ "metaclass" "members" "mixin" } reset-props ;
|
||||||
|
|
|
@ -14,7 +14,7 @@ ARTICLE: "predicates" "Predicate classes"
|
||||||
ABOUT: "predicates"
|
ABOUT: "predicates"
|
||||||
|
|
||||||
HELP: define-predicate-class
|
HELP: define-predicate-class
|
||||||
{ $values { "superclass" class } { "class" class } { "definition" "a quotation with stack effect " { $snippet "( superclass -- ? )" } } }
|
{ $values { "class" class } { "superclass" class } { "definition" "a quotation with stack effect " { $snippet "( superclass -- ? )" } } }
|
||||||
{ $description "Defines a predicate class. This is the run time equivalent of " { $link POSTPONE: PREDICATE: } "." }
|
{ $description "Defines a predicate class. This is the run time equivalent of " { $link POSTPONE: PREDICATE: } "." }
|
||||||
{ $notes "This word must be called from inside " { $link with-compilation-unit } "." }
|
{ $notes "This word must be called from inside " { $link with-compilation-unit } "." }
|
||||||
{ $side-effects "class" } ;
|
{ $side-effects "class" } ;
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
! Copyright (C) 2004, 2007 Slava Pestov.
|
! Copyright (C) 2004, 2008 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: classes kernel namespaces words ;
|
USING: classes kernel namespaces words ;
|
||||||
IN: classes.predicate
|
IN: classes.predicate
|
||||||
|
|
||||||
PREDICATE: class predicate-class
|
PREDICATE: predicate-class < class
|
||||||
"metaclass" word-prop predicate-class eq? ;
|
"metaclass" word-prop predicate-class eq? ;
|
||||||
|
|
||||||
: predicate-quot ( class -- quot )
|
: predicate-quot ( class -- quot )
|
||||||
|
@ -13,8 +13,8 @@ PREDICATE: class predicate-class
|
||||||
"predicate-definition" word-prop , [ drop f ] , \ if ,
|
"predicate-definition" word-prop , [ drop f ] , \ if ,
|
||||||
] [ ] make ;
|
] [ ] make ;
|
||||||
|
|
||||||
: define-predicate-class ( superclass class definition -- )
|
: define-predicate-class ( class superclass definition -- )
|
||||||
>r dup f roll predicate-class define-class r>
|
>r >r dup f r> predicate-class define-class r>
|
||||||
dupd "predicate-definition" set-word-prop
|
dupd "predicate-definition" set-word-prop
|
||||||
dup predicate-quot define-predicate ;
|
dup predicate-quot define-predicate ;
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ USING: words sequences kernel assocs combinators classes
|
||||||
generic.standard namespaces arrays math quotations ;
|
generic.standard namespaces arrays math quotations ;
|
||||||
IN: classes.union
|
IN: classes.union
|
||||||
|
|
||||||
PREDICATE: class union-class
|
PREDICATE: union-class < class
|
||||||
"metaclass" word-prop union-class eq? ;
|
"metaclass" word-prop union-class eq? ;
|
||||||
|
|
||||||
! Union classes for dispatch on multiple classes.
|
! Union classes for dispatch on multiple classes.
|
||||||
|
|
|
@ -15,7 +15,7 @@ IN: compiler.constants
|
||||||
: byte-array-offset 2 bootstrap-cells object tag-number - ;
|
: byte-array-offset 2 bootstrap-cells object tag-number - ;
|
||||||
: alien-offset 3 bootstrap-cells object tag-number - ;
|
: alien-offset 3 bootstrap-cells object tag-number - ;
|
||||||
: underlying-alien-offset bootstrap-cell object tag-number - ;
|
: underlying-alien-offset bootstrap-cell object tag-number - ;
|
||||||
: tuple-class-offset 2 bootstrap-cells tuple tag-number - ;
|
: tuple-class-offset bootstrap-cell tuple tag-number - ;
|
||||||
: class-hash-offset bootstrap-cell object tag-number - ;
|
: class-hash-offset bootstrap-cell object tag-number - ;
|
||||||
: word-xt-offset 8 bootstrap-cells object tag-number - ;
|
: word-xt-offset 8 bootstrap-cells object tag-number - ;
|
||||||
: word-code-offset 9 bootstrap-cells object tag-number - ;
|
: word-code-offset 9 bootstrap-cells object tag-number - ;
|
||||||
|
|
|
@ -153,11 +153,11 @@ M: f v>operand drop \ f tag-number ;
|
||||||
|
|
||||||
M: object load-literal v>operand load-indirect ;
|
M: object load-literal v>operand load-indirect ;
|
||||||
|
|
||||||
PREDICATE: integer small-slot cells small-enough? ;
|
PREDICATE: small-slot < integer cells small-enough? ;
|
||||||
|
|
||||||
PREDICATE: integer small-tagged v>operand small-enough? ;
|
PREDICATE: small-tagged < integer v>operand small-enough? ;
|
||||||
|
|
||||||
PREDICATE: integer inline-array 32 < ;
|
PREDICATE: inline-array < integer 32 < ;
|
||||||
|
|
||||||
: if-small-struct ( n size true false -- ? )
|
: if-small-struct ( n size true false -- ? )
|
||||||
>r >r over not over struct-small-enough? and
|
>r >r over not over struct-small-enough? and
|
||||||
|
|
|
@ -27,7 +27,7 @@ SYMBOL: R15
|
||||||
{ R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 }
|
{ R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 }
|
||||||
define-registers
|
define-registers
|
||||||
|
|
||||||
PREDICATE: word register register >boolean ;
|
PREDICATE: register < word register >boolean ;
|
||||||
|
|
||||||
GENERIC: register ( register -- n )
|
GENERIC: register ( register -- n )
|
||||||
M: word register "register" word-prop ;
|
M: word register "register" word-prop ;
|
||||||
|
|
|
@ -479,19 +479,17 @@ IN: cpu.ppc.intrinsics
|
||||||
} define-intrinsic
|
} define-intrinsic
|
||||||
|
|
||||||
\ <tuple> [
|
\ <tuple> [
|
||||||
tuple "n" get 2 + cells %allot
|
tuple "layout" get layout-size 2 + cells %allot
|
||||||
! Store length
|
! Store layout
|
||||||
"n" operand 12 LI
|
"layout" operand 12 LOAD32
|
||||||
12 11 cell STW
|
12 11 cell STW
|
||||||
! Store class
|
|
||||||
"class" operand 11 2 cells STW
|
|
||||||
! Zero out the rest of the tuple
|
! Zero out the rest of the tuple
|
||||||
f v>operand 12 LI
|
f v>operand 12 LI
|
||||||
"n" get 1- [ 12 11 rot 3 + cells STW ] each
|
"layout" get layout-size [ 12 11 rot 2 + cells STW ] each
|
||||||
! Store tagged ptr in reg
|
! Store tagged ptr in reg
|
||||||
"tuple" get tuple %store-tagged
|
"tuple" get tuple %store-tagged
|
||||||
] H{
|
] H{
|
||||||
{ +input+ { { f "class" } { [ inline-array? ] "n" } } }
|
{ +input+ { { [ tuple-layout? ] "layout" } }
|
||||||
{ +scratch+ { { f "tuple" } } }
|
{ +scratch+ { { f "tuple" } } }
|
||||||
{ +output+ { "tuple" } }
|
{ +output+ { "tuple" } }
|
||||||
} define-intrinsic
|
} define-intrinsic
|
||||||
|
|
|
@ -8,7 +8,7 @@ alien.compiler combinators command-line
|
||||||
compiler compiler.units io vocabs.loader accessors ;
|
compiler compiler.units io vocabs.loader accessors ;
|
||||||
IN: cpu.x86.32
|
IN: cpu.x86.32
|
||||||
|
|
||||||
PREDICATE: x86-backend x86-32-backend
|
PREDICATE: x86-32-backend < x86-backend
|
||||||
x86-backend-cell 4 = ;
|
x86-backend-cell 4 = ;
|
||||||
|
|
||||||
! We implement the FFI for Linux, OS X and Windows all at once.
|
! We implement the FFI for Linux, OS X and Windows all at once.
|
||||||
|
|
|
@ -8,7 +8,7 @@ layouts alien alien.accessors alien.compiler alien.structs slots
|
||||||
splitting assocs ;
|
splitting assocs ;
|
||||||
IN: cpu.x86.64
|
IN: cpu.x86.64
|
||||||
|
|
||||||
PREDICATE: x86-backend amd64-backend
|
PREDICATE: amd64-backend < x86-backend
|
||||||
x86-backend-cell 8 = ;
|
x86-backend-cell 8 = ;
|
||||||
|
|
||||||
M: amd64-backend ds-reg R14 ;
|
M: amd64-backend ds-reg R14 ;
|
||||||
|
|
|
@ -52,13 +52,23 @@ GENERIC: extended? ( op -- ? )
|
||||||
|
|
||||||
M: object extended? drop f ;
|
M: object extended? drop f ;
|
||||||
|
|
||||||
PREDICATE: word register "register" word-prop ;
|
PREDICATE: register < word
|
||||||
|
"register" word-prop ;
|
||||||
|
|
||||||
PREDICATE: register register-8 "register-size" word-prop 8 = ;
|
PREDICATE: register-8 < register
|
||||||
PREDICATE: register register-16 "register-size" word-prop 16 = ;
|
"register-size" word-prop 8 = ;
|
||||||
PREDICATE: register register-32 "register-size" word-prop 32 = ;
|
|
||||||
PREDICATE: register register-64 "register-size" word-prop 64 = ;
|
PREDICATE: register-16 < register
|
||||||
PREDICATE: register register-128 "register-size" word-prop 128 = ;
|
"register-size" word-prop 16 = ;
|
||||||
|
|
||||||
|
PREDICATE: register-32 < register
|
||||||
|
"register-size" word-prop 32 = ;
|
||||||
|
|
||||||
|
PREDICATE: register-64 < register
|
||||||
|
"register-size" word-prop 64 = ;
|
||||||
|
|
||||||
|
PREDICATE: register-128 < register
|
||||||
|
"register-size" word-prop 128 = ;
|
||||||
|
|
||||||
M: register extended? "register" word-prop 7 > ;
|
M: register extended? "register" word-prop 7 > ;
|
||||||
|
|
||||||
|
@ -285,7 +295,7 @@ GENERIC: (MOV-I) ( src dst -- )
|
||||||
M: register (MOV-I) t HEX: b8 short-operand cell, ;
|
M: register (MOV-I) t HEX: b8 short-operand cell, ;
|
||||||
M: operand (MOV-I) BIN: 000 t HEX: c7 1-operand 4, ;
|
M: operand (MOV-I) BIN: 000 t HEX: c7 1-operand 4, ;
|
||||||
|
|
||||||
PREDICATE: word callable register? not ;
|
PREDICATE: callable < word register? not ;
|
||||||
|
|
||||||
GENERIC: MOV ( dst src -- )
|
GENERIC: MOV ( dst src -- )
|
||||||
M: integer MOV swap (MOV-I) ;
|
M: integer MOV swap (MOV-I) ;
|
||||||
|
|
|
@ -336,19 +336,20 @@ IN: cpu.x86.intrinsics
|
||||||
} define-intrinsic
|
} define-intrinsic
|
||||||
|
|
||||||
\ <tuple> [
|
\ <tuple> [
|
||||||
tuple "n" get 2 + cells [
|
tuple "layout" get layout-size 2 + cells [
|
||||||
! Store length
|
! Store layout
|
||||||
1 object@ "n" operand MOV
|
"layout" get "scratch" get load-literal
|
||||||
! Store class
|
1 object@ "scratch" operand MOV
|
||||||
2 object@ "class" operand MOV
|
|
||||||
! Zero out the rest of the tuple
|
! Zero out the rest of the tuple
|
||||||
"n" operand 1- [ 3 + object@ f v>operand MOV ] each
|
"layout" get layout-size [
|
||||||
|
2 + object@ f v>operand MOV
|
||||||
|
] each
|
||||||
! Store tagged ptr in reg
|
! Store tagged ptr in reg
|
||||||
"tuple" get tuple %store-tagged
|
"tuple" get tuple %store-tagged
|
||||||
] %allot
|
] %allot
|
||||||
] H{
|
] H{
|
||||||
{ +input+ { { f "class" } { [ inline-array? ] "n" } } }
|
{ +input+ { { [ tuple-layout? ] "layout" } } }
|
||||||
{ +scratch+ { { f "tuple" } } }
|
{ +scratch+ { { f "tuple" } { f "scratch" } } }
|
||||||
{ +output+ { "tuple" } }
|
{ +output+ { "tuple" } }
|
||||||
} define-intrinsic
|
} define-intrinsic
|
||||||
|
|
||||||
|
|
|
@ -156,7 +156,7 @@ M: relative-overflow summary
|
||||||
: primitive-error.
|
: primitive-error.
|
||||||
"Unimplemented primitive" print drop ;
|
"Unimplemented primitive" print drop ;
|
||||||
|
|
||||||
PREDICATE: array kernel-error ( obj -- ? )
|
PREDICATE: kernel-error < array
|
||||||
{
|
{
|
||||||
{ [ dup empty? ] [ drop f ] }
|
{ [ dup empty? ] [ drop f ] }
|
||||||
{ [ dup first "kernel-error" = not ] [ drop f ] }
|
{ [ dup first "kernel-error" = not ] [ drop f ] }
|
||||||
|
|
|
@ -44,7 +44,7 @@ M: object funny drop 0 ;
|
||||||
[ 2 ] [ [ { } ] funny ] unit-test
|
[ 2 ] [ [ { } ] funny ] unit-test
|
||||||
[ 0 ] [ { } funny ] unit-test
|
[ 0 ] [ { } funny ] unit-test
|
||||||
|
|
||||||
PREDICATE: funnies very-funny number? ;
|
PREDICATE: very-funny < funnies number? ;
|
||||||
|
|
||||||
GENERIC: gooey ( x -- y )
|
GENERIC: gooey ( x -- y )
|
||||||
M: very-funny gooey sq ;
|
M: very-funny gooey sq ;
|
||||||
|
|
|
@ -19,7 +19,8 @@ M: object perform-combination
|
||||||
|
|
||||||
GENERIC: make-default-method ( generic combination -- method )
|
GENERIC: make-default-method ( generic combination -- method )
|
||||||
|
|
||||||
PREDICATE: word generic "combination" word-prop >boolean ;
|
PREDICATE: generic < word
|
||||||
|
"combination" word-prop >boolean ;
|
||||||
|
|
||||||
M: generic definition drop f ;
|
M: generic definition drop f ;
|
||||||
|
|
||||||
|
@ -30,7 +31,7 @@ M: generic definition drop f ;
|
||||||
: method ( class generic -- method/f )
|
: method ( class generic -- method/f )
|
||||||
"methods" word-prop at ;
|
"methods" word-prop at ;
|
||||||
|
|
||||||
PREDICATE: pair method-spec
|
PREDICATE: method-spec < pair
|
||||||
first2 generic? swap class? and ;
|
first2 generic? swap class? and ;
|
||||||
|
|
||||||
: order ( generic -- seq )
|
: order ( generic -- seq )
|
||||||
|
@ -55,7 +56,7 @@ TUPLE: check-method class generic ;
|
||||||
: method-word-name ( class word -- string )
|
: method-word-name ( class word -- string )
|
||||||
word-name "/" rot word-name 3append ;
|
word-name "/" rot word-name 3append ;
|
||||||
|
|
||||||
PREDICATE: word method-body
|
PREDICATE: method-body < word
|
||||||
"method-generic" word-prop >boolean ;
|
"method-generic" word-prop >boolean ;
|
||||||
|
|
||||||
M: method-body stack-effect
|
M: method-body stack-effect
|
||||||
|
|
|
@ -5,7 +5,7 @@ math namespaces sequences words quotations layouts combinators
|
||||||
sequences.private classes classes.algebra definitions ;
|
sequences.private classes classes.algebra definitions ;
|
||||||
IN: generic.math
|
IN: generic.math
|
||||||
|
|
||||||
PREDICATE: class math-class ( object -- ? )
|
PREDICATE: math-class < class
|
||||||
dup null bootstrap-word eq? [
|
dup null bootstrap-word eq? [
|
||||||
drop f
|
drop f
|
||||||
] [
|
] [
|
||||||
|
@ -79,7 +79,7 @@ M: math-combination perform-combination
|
||||||
] if nip
|
] if nip
|
||||||
] math-vtable nip ;
|
] math-vtable nip ;
|
||||||
|
|
||||||
PREDICATE: generic math-generic ( word -- ? )
|
PREDICATE: math-generic < generic ( word -- ? )
|
||||||
"combination" word-prop math-combination? ;
|
"combination" word-prop math-combination? ;
|
||||||
|
|
||||||
M: math-generic definer drop \ MATH: f ;
|
M: math-generic definer drop \ MATH: f ;
|
||||||
|
|
|
@ -174,13 +174,13 @@ M: hook-combination perform-combination
|
||||||
: define-simple-generic ( word -- )
|
: define-simple-generic ( word -- )
|
||||||
T{ standard-combination f 0 } define-generic ;
|
T{ standard-combination f 0 } define-generic ;
|
||||||
|
|
||||||
PREDICATE: generic standard-generic
|
PREDICATE: standard-generic < generic
|
||||||
"combination" word-prop standard-combination? ;
|
"combination" word-prop standard-combination? ;
|
||||||
|
|
||||||
PREDICATE: standard-generic simple-generic
|
PREDICATE: simple-generic < standard-generic
|
||||||
"combination" word-prop standard-combination-# zero? ;
|
"combination" word-prop standard-combination-# zero? ;
|
||||||
|
|
||||||
PREDICATE: generic hook-generic
|
PREDICATE: hook-generic < generic
|
||||||
"combination" word-prop hook-combination? ;
|
"combination" word-prop hook-combination? ;
|
||||||
|
|
||||||
GENERIC: dispatch# ( word -- n )
|
GENERIC: dispatch# ( word -- n )
|
||||||
|
|
|
@ -102,7 +102,7 @@ TUPLE: #label word loop? ;
|
||||||
: #label ( word label -- node )
|
: #label ( word label -- node )
|
||||||
\ #label param-node [ set-#label-word ] keep ;
|
\ #label param-node [ set-#label-word ] keep ;
|
||||||
|
|
||||||
PREDICATE: #label #loop #label-loop? ;
|
PREDICATE: #loop < #label #label-loop? ;
|
||||||
|
|
||||||
TUPLE: #entry ;
|
TUPLE: #entry ;
|
||||||
|
|
||||||
|
@ -309,9 +309,9 @@ SYMBOL: node-stack
|
||||||
|
|
||||||
DEFER: #tail?
|
DEFER: #tail?
|
||||||
|
|
||||||
PREDICATE: #merge #tail-merge node-successor #tail? ;
|
PREDICATE: #tail-merge < #merge node-successor #tail? ;
|
||||||
|
|
||||||
PREDICATE: #values #tail-values node-successor #tail? ;
|
PREDICATE: #tail-values < #values node-successor #tail? ;
|
||||||
|
|
||||||
UNION: #tail
|
UNION: #tail
|
||||||
POSTPONE: f #return #tail-values #tail-merge #terminate ;
|
POSTPONE: f #return #tail-values #tail-merge #terminate ;
|
||||||
|
|
|
@ -135,7 +135,7 @@ M: object infer-call
|
||||||
! Variadic tuple constructor
|
! Variadic tuple constructor
|
||||||
\ <tuple-boa> [
|
\ <tuple-boa> [
|
||||||
\ <tuple-boa>
|
\ <tuple-boa>
|
||||||
peek-d value-literal { tuple } <effect>
|
peek-d value-literal layout-size { tuple } <effect>
|
||||||
make-call-node
|
make-call-node
|
||||||
] "infer" set-word-prop
|
] "infer" set-word-prop
|
||||||
|
|
||||||
|
@ -565,14 +565,11 @@ set-primitive-effect
|
||||||
\ quotation-xt { quotation } { integer } <effect> set-primitive-effect
|
\ quotation-xt { quotation } { integer } <effect> set-primitive-effect
|
||||||
\ quotation-xt make-flushable
|
\ quotation-xt make-flushable
|
||||||
|
|
||||||
\ <tuple> { word integer } { quotation } <effect> set-primitive-effect
|
\ <tuple> { tuple-layout } { tuple } <effect> set-primitive-effect
|
||||||
\ <tuple> make-flushable
|
\ <tuple> make-flushable
|
||||||
|
|
||||||
\ (>tuple) { array } { tuple } <effect> set-primitive-effect
|
\ <tuple-layout> { word fixnum array fixnum } { tuple-layout } <effect> set-primitive-effect
|
||||||
\ (>tuple) make-flushable
|
\ <tuple-layout> make-foldable
|
||||||
|
|
||||||
\ tuple>array { tuple } { array } <effect> set-primitive-effect
|
|
||||||
\ tuple>array make-flushable
|
|
||||||
|
|
||||||
\ datastack { } { array } <effect> set-primitive-effect
|
\ datastack { } { array } <effect> set-primitive-effect
|
||||||
\ datastack make-flushable
|
\ datastack make-flushable
|
||||||
|
|
|
@ -76,7 +76,7 @@ M: duplicated-slots-error summary
|
||||||
|
|
||||||
\ construct-boa [
|
\ construct-boa [
|
||||||
dup +inlined+ depends-on
|
dup +inlined+ depends-on
|
||||||
dup tuple-size [ <tuple-boa> ] 2curry
|
tuple-layout [ <tuple-boa> ] curry
|
||||||
] 1 define-transform
|
] 1 define-transform
|
||||||
|
|
||||||
\ construct-empty [
|
\ construct-empty [
|
||||||
|
@ -84,7 +84,7 @@ M: duplicated-slots-error summary
|
||||||
peek-d value? [
|
peek-d value? [
|
||||||
pop-literal
|
pop-literal
|
||||||
dup +inlined+ depends-on
|
dup +inlined+ depends-on
|
||||||
dup tuple-size [ <tuple> ] 2curry
|
tuple-layout [ <tuple> ] curry
|
||||||
swap infer-quot
|
swap infer-quot
|
||||||
] [
|
] [
|
||||||
\ construct-empty 1 1 <effect> make-call-node
|
\ construct-empty 1 1 <effect> make-call-node
|
||||||
|
|
|
@ -6,7 +6,7 @@ IN: io.streams.encodings.tests
|
||||||
resource-path ascii <file-reader> ;
|
resource-path ascii <file-reader> ;
|
||||||
|
|
||||||
[ { } ]
|
[ { } ]
|
||||||
[ "/core/io/test/empty-file.txt" <resource-reader> lines ]
|
[ "core/io/test/empty-file.txt" <resource-reader> lines ]
|
||||||
unit-test
|
unit-test
|
||||||
|
|
||||||
: lines-test ( stream -- line1 line2 )
|
: lines-test ( stream -- line1 line2 )
|
||||||
|
@ -16,21 +16,21 @@ unit-test
|
||||||
"This is a line."
|
"This is a line."
|
||||||
"This is another line."
|
"This is another line."
|
||||||
] [
|
] [
|
||||||
"/core/io/test/windows-eol.txt" <resource-reader> lines-test
|
"core/io/test/windows-eol.txt" <resource-reader> lines-test
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[
|
[
|
||||||
"This is a line."
|
"This is a line."
|
||||||
"This is another line."
|
"This is another line."
|
||||||
] [
|
] [
|
||||||
"/core/io/test/mac-os-eol.txt" <resource-reader> lines-test
|
"core/io/test/mac-os-eol.txt" <resource-reader> lines-test
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[
|
[
|
||||||
"This is a line."
|
"This is a line."
|
||||||
"This is another line."
|
"This is another line."
|
||||||
] [
|
] [
|
||||||
"/core/io/test/unix-eol.txt" <resource-reader> lines-test
|
"core/io/test/unix-eol.txt" <resource-reader> lines-test
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[
|
[
|
||||||
|
|
|
@ -4,7 +4,7 @@ io.encodings.binary ;
|
||||||
IN: io.tests
|
IN: io.tests
|
||||||
|
|
||||||
[ f ] [
|
[ f ] [
|
||||||
"resource:/core/io/test/no-trailing-eol.factor" run-file
|
"resource:core/io/test/no-trailing-eol.factor" run-file
|
||||||
"foo" "io.tests" lookup
|
"foo" "io.tests" lookup
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
@ -14,14 +14,14 @@ IN: io.tests
|
||||||
[
|
[
|
||||||
"This is a line.\rThis is another line.\r"
|
"This is a line.\rThis is another line.\r"
|
||||||
] [
|
] [
|
||||||
"/core/io/test/mac-os-eol.txt" <resource-reader>
|
"core/io/test/mac-os-eol.txt" <resource-reader>
|
||||||
[ 500 read ] with-stream
|
[ 500 read ] with-stream
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[
|
[
|
||||||
255
|
255
|
||||||
] [
|
] [
|
||||||
"/core/io/test/binary.txt" <resource-reader>
|
"core/io/test/binary.txt" <resource-reader>
|
||||||
[ read1 ] with-stream >fixnum
|
[ read1 ] with-stream >fixnum
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ IN: io.tests
|
||||||
}
|
}
|
||||||
] [
|
] [
|
||||||
[
|
[
|
||||||
"/core/io/test/separator-test.txt" <resource-reader> [
|
"core/io/test/separator-test.txt" <resource-reader> [
|
||||||
"J" read-until 2array ,
|
"J" read-until 2array ,
|
||||||
"i" read-until 2array ,
|
"i" read-until 2array ,
|
||||||
"X" read-until 2array ,
|
"X" read-until 2array ,
|
||||||
|
|
|
@ -67,29 +67,7 @@ DEFER: if
|
||||||
[ >r tuck 2slip r> while ]
|
[ >r tuck 2slip r> while ]
|
||||||
[ 2nip call ] if ; inline
|
[ 2nip call ] if ; inline
|
||||||
|
|
||||||
! Quotation building
|
|
||||||
USE: tuples.private
|
|
||||||
|
|
||||||
: curry ( obj quot -- curry )
|
|
||||||
\ curry 4 <tuple-boa> ;
|
|
||||||
|
|
||||||
: 2curry ( obj1 obj2 quot -- curry )
|
|
||||||
curry curry ; inline
|
|
||||||
|
|
||||||
: 3curry ( obj1 obj2 obj3 quot -- curry )
|
|
||||||
curry curry curry ; inline
|
|
||||||
|
|
||||||
: with ( param obj quot -- obj curry )
|
|
||||||
swapd [ swapd call ] 2curry ; inline
|
|
||||||
|
|
||||||
: compose ( quot1 quot2 -- curry )
|
|
||||||
\ compose 4 <tuple-boa> ;
|
|
||||||
|
|
||||||
: 3compose ( quot1 quot2 quot3 -- curry )
|
|
||||||
compose compose ; inline
|
|
||||||
|
|
||||||
! Object protocol
|
! Object protocol
|
||||||
|
|
||||||
GENERIC: delegate ( obj -- delegate )
|
GENERIC: delegate ( obj -- delegate )
|
||||||
|
|
||||||
M: object delegate drop f ;
|
M: object delegate drop f ;
|
||||||
|
@ -118,7 +96,6 @@ M: object clone ;
|
||||||
M: callstack clone (clone) ;
|
M: callstack clone (clone) ;
|
||||||
|
|
||||||
! Tuple construction
|
! Tuple construction
|
||||||
|
|
||||||
GENERIC# get-slots 1 ( tuple slots -- ... )
|
GENERIC# get-slots 1 ( tuple slots -- ... )
|
||||||
|
|
||||||
GENERIC# set-slots 1 ( ... tuple slots -- )
|
GENERIC# set-slots 1 ( ... tuple slots -- )
|
||||||
|
@ -132,8 +109,22 @@ GENERIC: construct-boa ( ... class -- tuple )
|
||||||
: construct-delegate ( delegate class -- tuple )
|
: construct-delegate ( delegate class -- tuple )
|
||||||
>r { set-delegate } r> construct ; inline
|
>r { set-delegate } r> construct ; inline
|
||||||
|
|
||||||
! Booleans
|
! Quotation building
|
||||||
|
USE: tuples.private
|
||||||
|
|
||||||
|
: 2curry ( obj1 obj2 quot -- curry )
|
||||||
|
curry curry ; inline
|
||||||
|
|
||||||
|
: 3curry ( obj1 obj2 obj3 quot -- curry )
|
||||||
|
curry curry curry ; inline
|
||||||
|
|
||||||
|
: with ( param obj quot -- obj curry )
|
||||||
|
swapd [ swapd call ] 2curry ; inline
|
||||||
|
|
||||||
|
: 3compose ( quot1 quot2 quot3 -- curry )
|
||||||
|
compose compose ; inline
|
||||||
|
|
||||||
|
! Booleans
|
||||||
: not ( obj -- ? ) f eq? ; inline
|
: not ( obj -- ? ) f eq? ; inline
|
||||||
|
|
||||||
: >boolean ( obj -- ? ) t f ? ; inline
|
: >boolean ( obj -- ? ) t f ? ; inline
|
||||||
|
|
|
@ -11,12 +11,11 @@ classes.algebra optimizer.def-use optimizer.backend
|
||||||
optimizer.pattern-match optimizer.inlining float-arrays
|
optimizer.pattern-match optimizer.inlining float-arrays
|
||||||
sequences.private combinators ;
|
sequences.private combinators ;
|
||||||
|
|
||||||
! the output of <tuple> and <tuple-boa> has the class which is
|
|
||||||
! its second-to-last input
|
|
||||||
{ <tuple> <tuple-boa> } [
|
{ <tuple> <tuple-boa> } [
|
||||||
[
|
[
|
||||||
dup node-in-d dup length 2 - swap nth node-literal
|
dup node-in-d peek node-literal
|
||||||
dup class? [ drop tuple ] unless 1array f
|
dup tuple-layout? [ layout-class ] [ drop tuple ] if
|
||||||
|
1array f
|
||||||
] "output-classes" set-word-prop
|
] "output-classes" set-word-prop
|
||||||
] each
|
] each
|
||||||
|
|
||||||
|
|
|
@ -389,7 +389,7 @@ IN: parser.tests
|
||||||
] with-scope
|
] with-scope
|
||||||
|
|
||||||
[ ] [
|
[ ] [
|
||||||
"IN: parser.tests USE: kernel PREDICATE: object foo ( x -- y ) ;" eval
|
"IN: parser.tests USE: kernel PREDICATE: foo < object ( x -- y ) ;" eval
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[ t ] [
|
[ t ] [
|
||||||
|
|
|
@ -214,7 +214,7 @@ SYMBOL: in
|
||||||
|
|
||||||
ERROR: unexpected want got ;
|
ERROR: unexpected want got ;
|
||||||
|
|
||||||
PREDICATE: unexpected unexpected-eof
|
PREDICATE: unexpected-eof < unexpected
|
||||||
unexpected-got not ;
|
unexpected-got not ;
|
||||||
|
|
||||||
: unexpected-eof ( word -- * ) f unexpected ;
|
: unexpected-eof ( word -- * ) f unexpected ;
|
||||||
|
@ -288,6 +288,14 @@ M: no-word summary
|
||||||
: CREATE-METHOD ( -- method )
|
: CREATE-METHOD ( -- method )
|
||||||
scan-word bootstrap-word scan-word create-method-in ;
|
scan-word bootstrap-word scan-word create-method-in ;
|
||||||
|
|
||||||
|
: parse-tuple-definition ( -- class superclass slots )
|
||||||
|
CREATE-CLASS
|
||||||
|
scan {
|
||||||
|
{ ";" [ tuple f ] }
|
||||||
|
{ "<" [ scan-word ";" parse-tokens ] }
|
||||||
|
[ >r tuple ";" parse-tokens r> add* ]
|
||||||
|
} case ;
|
||||||
|
|
||||||
ERROR: staging-violation word ;
|
ERROR: staging-violation word ;
|
||||||
|
|
||||||
M: staging-violation summary
|
M: staging-violation summary
|
||||||
|
|
|
@ -4,7 +4,7 @@ USING: arrays byte-arrays byte-vectors bit-arrays bit-vectors
|
||||||
generic hashtables io assocs kernel math namespaces sequences
|
generic hashtables io assocs kernel math namespaces sequences
|
||||||
strings sbufs io.styles vectors words prettyprint.config
|
strings sbufs io.styles vectors words prettyprint.config
|
||||||
prettyprint.sections quotations io io.files math.parser effects
|
prettyprint.sections quotations io io.files math.parser effects
|
||||||
tuples classes float-arrays float-vectors ;
|
tuples tuples.private classes float-arrays float-vectors ;
|
||||||
IN: prettyprint.backend
|
IN: prettyprint.backend
|
||||||
|
|
||||||
GENERIC: pprint* ( obj -- )
|
GENERIC: pprint* ( obj -- )
|
||||||
|
@ -202,3 +202,6 @@ M: wrapper pprint*
|
||||||
] [
|
] [
|
||||||
pprint-object
|
pprint-object
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
|
M: tuple-layout pprint*
|
||||||
|
"( tuple layout )" swap present-text ;
|
||||||
|
|
|
@ -329,3 +329,9 @@ M: f generic-see-test-with-f ;
|
||||||
[ "USING: prettyprint.tests ;\nM: f generic-see-test-with-f ;\n" ] [
|
[ "USING: prettyprint.tests ;\nM: f generic-see-test-with-f ;\n" ] [
|
||||||
[ \ f \ generic-see-test-with-f method see ] with-string-writer
|
[ \ f \ generic-see-test-with-f method see ] with-string-writer
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
PREDICATE: predicate-see-test < integer even? ;
|
||||||
|
|
||||||
|
[ "USING: math ;\nIN: prettyprint.tests\nPREDICATE: predicate-see-test < integer even? ;\n" ] [
|
||||||
|
[ \ predicate-see-test see ] with-string-writer
|
||||||
|
] unit-test
|
||||||
|
|
|
@ -247,8 +247,9 @@ M: mixin-class see-class*
|
||||||
|
|
||||||
M: predicate-class see-class*
|
M: predicate-class see-class*
|
||||||
<colon \ PREDICATE: pprint-word
|
<colon \ PREDICATE: pprint-word
|
||||||
dup superclass pprint-word
|
|
||||||
dup pprint-word
|
dup pprint-word
|
||||||
|
"<" text
|
||||||
|
dup superclass pprint-word
|
||||||
<block
|
<block
|
||||||
"predicate-definition" word-prop pprint-elements
|
"predicate-definition" word-prop pprint-elements
|
||||||
pprint-; block> block> ;
|
pprint-; block> block> ;
|
||||||
|
@ -256,6 +257,9 @@ M: predicate-class see-class*
|
||||||
M: tuple-class see-class*
|
M: tuple-class see-class*
|
||||||
<colon \ TUPLE: pprint-word
|
<colon \ TUPLE: pprint-word
|
||||||
dup pprint-word
|
dup pprint-word
|
||||||
|
dup superclass tuple eq? [
|
||||||
|
"<" text dup superclass pprint-word
|
||||||
|
] unless
|
||||||
"slot-names" word-prop [ text ] each
|
"slot-names" word-prop [ text ] each
|
||||||
pprint-; block> ;
|
pprint-; block> ;
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,9 @@ IN: quotations
|
||||||
|
|
||||||
M: quotation call (call) ;
|
M: quotation call (call) ;
|
||||||
|
|
||||||
M: curry call dup 4 slot swap 5 slot call ;
|
M: curry call dup 3 slot swap 4 slot call ;
|
||||||
|
|
||||||
M: compose call dup 4 slot swap 5 slot slip call ;
|
M: compose call dup 3 slot swap 4 slot slip call ;
|
||||||
|
|
||||||
M: wrapper equal?
|
M: wrapper equal?
|
||||||
over wrapper? [ [ wrapped ] 2apply = ] [ 2drop f ] if ;
|
over wrapper? [ [ wrapped ] 2apply = ] [ 2drop f ] if ;
|
||||||
|
|
|
@ -60,7 +60,7 @@ INSTANCE: immutable-sequence sequence
|
||||||
#! A bit of a pain; can't call cell-bits here
|
#! A bit of a pain; can't call cell-bits here
|
||||||
7 getenv 8 * 5 - 2^ 1- ; foldable
|
7 getenv 8 * 5 - 2^ 1- ; foldable
|
||||||
|
|
||||||
PREDICATE: fixnum array-capacity
|
PREDICATE: array-capacity < fixnum
|
||||||
0 max-array-capacity between? ;
|
0 max-array-capacity between? ;
|
||||||
|
|
||||||
: array-capacity ( array -- n )
|
: array-capacity ( array -- n )
|
||||||
|
|
|
@ -8,7 +8,7 @@ IN: slots.deprecated
|
||||||
: reader-effect ( class spec -- effect )
|
: reader-effect ( class spec -- effect )
|
||||||
>r ?word-name 1array r> slot-spec-name 1array <effect> ;
|
>r ?word-name 1array r> slot-spec-name 1array <effect> ;
|
||||||
|
|
||||||
PREDICATE: word slot-reader "reading" word-prop >boolean ;
|
PREDICATE: slot-reader < word "reading" word-prop >boolean ;
|
||||||
|
|
||||||
: set-reader-props ( class spec -- )
|
: set-reader-props ( class spec -- )
|
||||||
2dup reader-effect
|
2dup reader-effect
|
||||||
|
@ -30,7 +30,7 @@ PREDICATE: word slot-reader "reading" word-prop >boolean ;
|
||||||
: writer-effect ( class spec -- effect )
|
: writer-effect ( class spec -- effect )
|
||||||
slot-spec-name swap ?word-name 2array 0 <effect> ;
|
slot-spec-name swap ?word-name 2array 0 <effect> ;
|
||||||
|
|
||||||
PREDICATE: word slot-writer "writing" word-prop >boolean ;
|
PREDICATE: slot-writer < word "writing" word-prop >boolean ;
|
||||||
|
|
||||||
: set-writer-props ( class spec -- )
|
: set-writer-props ( class spec -- )
|
||||||
2dup writer-effect
|
2dup writer-effect
|
||||||
|
|
|
@ -12,7 +12,7 @@ ARTICLE: "accessors" "Slot accessors"
|
||||||
}
|
}
|
||||||
"In addition, two utility words are defined for each distinct slot name used in the system:"
|
"In addition, two utility words are defined for each distinct slot name used in the system:"
|
||||||
{ $list
|
{ $list
|
||||||
{ "The " { $emphasis "setter" } " is named " { $snippet "(>>" { $emphasis "slot" } ")" } " and stores a value into a slot. It has stack effect " { $snippet "( object value -- object )" } "." }
|
{ "The " { $emphasis "setter" } " is named " { $snippet ">>" { $emphasis "slot" } } " and stores a value into a slot. It has stack effect " { $snippet "( object value -- object )" } "." }
|
||||||
{ "The " { $emphasis "changer" } " is named " { $snippet "change-" { $emphasis "slot" } } ". It applies a quotation to the current slot value and stores the result back in the slot; it has stack effect " { $snippet "( object quot -- object )" } "." }
|
{ "The " { $emphasis "changer" } " is named " { $snippet "change-" { $emphasis "slot" } } ". It applies a quotation to the current slot value and stores the result back in the slot; it has stack effect " { $snippet "( object quot -- object )" } "." }
|
||||||
}
|
}
|
||||||
"Since the reader and writer are generic, words can be written which do not depend on the specific class of tuple passed in, but instead work on any tuple that defines slots with certain names."
|
"Since the reader and writer are generic, words can be written which do not depend on the specific class of tuple passed in, but instead work on any tuple that defines slots with certain names."
|
||||||
|
|
|
@ -46,7 +46,7 @@ C: <slot-spec> slot-spec
|
||||||
: define-writer ( class slot name -- )
|
: define-writer ( class slot name -- )
|
||||||
writer-word [ set-slot ] define-slot-word ;
|
writer-word [ set-slot ] define-slot-word ;
|
||||||
|
|
||||||
: setter-effect T{ effect f { "object" "value" } { "value" } } ; inline
|
: setter-effect T{ effect f { "object" "value" } { "object" } } ; inline
|
||||||
|
|
||||||
: setter-word ( name -- word )
|
: setter-word ( name -- word )
|
||||||
">>" prepend setter-effect create-accessor ;
|
">>" prepend setter-effect create-accessor ;
|
||||||
|
|
|
@ -543,8 +543,8 @@ HELP: INSTANCE:
|
||||||
{ $description "Makes " { $snippet "instance" } " an instance of " { $snippet "mixin" } "." } ;
|
{ $description "Makes " { $snippet "instance" } " an instance of " { $snippet "mixin" } "." } ;
|
||||||
|
|
||||||
HELP: PREDICATE:
|
HELP: PREDICATE:
|
||||||
{ $syntax "PREDICATE: superclass class predicate... ;" }
|
{ $syntax "PREDICATE: class < superclass predicate... ;" }
|
||||||
{ $values { "superclass" "an existing class word" } { "class" "a new class word to define" } { "predicate" "membership test with stack effect " { $snippet "( superclass -- ? )" } } }
|
{ $values { "class" "a new class word to define" } { "superclass" "an existing class word" } { "predicate" "membership test with stack effect " { $snippet "( superclass -- ? )" } } }
|
||||||
{ $description
|
{ $description
|
||||||
"Defines a predicate class deriving from " { $snippet "superclass" } "."
|
"Defines a predicate class deriving from " { $snippet "superclass" } "."
|
||||||
$nl
|
$nl
|
||||||
|
@ -557,11 +557,9 @@ HELP: PREDICATE:
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
HELP: TUPLE:
|
HELP: TUPLE:
|
||||||
{ $syntax "TUPLE: class slots... ;" }
|
{ $syntax "TUPLE: class slots... ;" "TUPLE: class < superclass slots ... ;" }
|
||||||
{ $values { "class" "a new tuple class to define" } { "slots" "a list of slot names" } }
|
{ $values { "class" "a new tuple class to define" } { "slots" "a list of slot names" } }
|
||||||
{ $description "Defines a new tuple class."
|
{ $description "Defines a new tuple class. The superclass is optional; if left unspecified, it defaults to " { $link tuple } "." } ;
|
||||||
$nl
|
|
||||||
"Tuples are user-defined classes with instances composed of named slots. All tuple classes are subtypes of the built-in " { $link tuple } " type." } ;
|
|
||||||
|
|
||||||
HELP: ERROR:
|
HELP: ERROR:
|
||||||
{ $syntax "ERROR: class slots... ;" }
|
{ $syntax "ERROR: class slots... ;" }
|
||||||
|
|
|
@ -6,7 +6,7 @@ namespaces parser sequences strings sbufs vectors words
|
||||||
quotations io assocs splitting tuples generic.standard
|
quotations io assocs splitting tuples generic.standard
|
||||||
generic.math classes io.files vocabs float-arrays float-vectors
|
generic.math classes io.files vocabs float-arrays float-vectors
|
||||||
classes.union classes.mixin classes.predicate compiler.units
|
classes.union classes.mixin classes.predicate compiler.units
|
||||||
combinators ;
|
combinators debugger ;
|
||||||
IN: bootstrap.syntax
|
IN: bootstrap.syntax
|
||||||
|
|
||||||
! These words are defined as a top-level form, instead of with
|
! These words are defined as a top-level form, instead of with
|
||||||
|
@ -148,13 +148,14 @@ IN: bootstrap.syntax
|
||||||
] define-syntax
|
] define-syntax
|
||||||
|
|
||||||
"PREDICATE:" [
|
"PREDICATE:" [
|
||||||
scan-word
|
|
||||||
CREATE-CLASS
|
CREATE-CLASS
|
||||||
|
scan "<" assert=
|
||||||
|
scan-word
|
||||||
parse-definition define-predicate-class
|
parse-definition define-predicate-class
|
||||||
] define-syntax
|
] define-syntax
|
||||||
|
|
||||||
"TUPLE:" [
|
"TUPLE:" [
|
||||||
CREATE-CLASS ";" parse-tokens define-tuple-class
|
parse-tuple-definition define-tuple-class
|
||||||
] define-syntax
|
] define-syntax
|
||||||
|
|
||||||
"C:" [
|
"C:" [
|
||||||
|
@ -164,9 +165,9 @@ IN: bootstrap.syntax
|
||||||
] define-syntax
|
] define-syntax
|
||||||
|
|
||||||
"ERROR:" [
|
"ERROR:" [
|
||||||
CREATE-CLASS dup ";" parse-tokens define-tuple-class
|
parse-tuple-definition
|
||||||
dup save-location
|
pick save-location
|
||||||
dup [ construct-boa throw ] curry define
|
define-error-class
|
||||||
] define-syntax
|
] define-syntax
|
||||||
|
|
||||||
"FORGET:" [
|
"FORGET:" [
|
||||||
|
|
|
@ -153,10 +153,6 @@ HELP: tuple=
|
||||||
{ $description "Low-level tuple equality test. User code should use " { $link = } " instead." }
|
{ $description "Low-level tuple equality test. User code should use " { $link = } " instead." }
|
||||||
{ $warning "This word is in the " { $vocab-link "tuples.private" } " vocabulary because it does not do any type checking. Passing values which are not tuples can result in memory corruption." } ;
|
{ $warning "This word is in the " { $vocab-link "tuples.private" } " vocabulary because it does not do any type checking. Passing values which are not tuples can result in memory corruption." } ;
|
||||||
|
|
||||||
HELP: tuple-class-eq?
|
|
||||||
{ $values { "obj" object } { "class" tuple-class } { "?" "a boolean" } }
|
|
||||||
{ $description "Tests if " { $snippet "obj" } " is an instance of " { $snippet "class" } "." } ;
|
|
||||||
|
|
||||||
HELP: permutation
|
HELP: permutation
|
||||||
{ $values { "seq1" sequence } { "seq2" sequence } { "permutation" "a sequence whose elements are integers or " { $link f } } }
|
{ $values { "seq1" sequence } { "seq2" sequence } { "permutation" "a sequence whose elements are integers or " { $link f } } }
|
||||||
{ $description "Outputs a permutation for taking " { $snippet "seq1" } " to " { $snippet "seq2" } "." } ;
|
{ $description "Outputs a permutation for taking " { $snippet "seq1" } " to " { $snippet "seq2" } "." } ;
|
||||||
|
@ -169,7 +165,7 @@ HELP: reshape-tuples
|
||||||
{ $values { "class" tuple-class } { "newslots" "a sequence of strings" } }
|
{ $values { "class" tuple-class } { "newslots" "a sequence of strings" } }
|
||||||
{ $description "Changes the shape of every instance of " { $snippet "class" } " for a new slot layout." } ;
|
{ $description "Changes the shape of every instance of " { $snippet "class" } " for a new slot layout." } ;
|
||||||
|
|
||||||
HELP: old-slots
|
HELP: removed-slots
|
||||||
{ $values { "class" tuple-class } { "newslots" "a sequence of strings" } { "seq" "a sequence of strings" } }
|
{ $values { "class" tuple-class } { "newslots" "a sequence of strings" } { "seq" "a sequence of strings" } }
|
||||||
{ $description "Outputs the sequence of existing tuple slot names not in " { $snippet "newslots" } "." } ;
|
{ $description "Outputs the sequence of existing tuple slot names not in " { $snippet "newslots" } "." } ;
|
||||||
|
|
||||||
|
@ -194,8 +190,8 @@ HELP: define-tuple-predicate
|
||||||
{ $description "Defines a predicate word that tests if the top of the stack is an instance of " { $snippet "class" } ". This will only work if " { $snippet "class" } " is a tuple class." }
|
{ $description "Defines a predicate word that tests if the top of the stack is an instance of " { $snippet "class" } ". This will only work if " { $snippet "class" } " is a tuple class." }
|
||||||
$low-level-note ;
|
$low-level-note ;
|
||||||
|
|
||||||
HELP: check-shape
|
HELP: redefine-tuple-class
|
||||||
{ $values { "class" class } { "newslots" "a sequence of strings" } }
|
{ $values { "class" class } { "superclass" class } { "newslots" "a sequence of strings" } }
|
||||||
{ $description "If the new slot layout differs from the existing one, updates all existing instances of this tuple class, and forgets any slot accessor words which are no longer needed."
|
{ $description "If the new slot layout differs from the existing one, updates all existing instances of this tuple class, and forgets any slot accessor words which are no longer needed."
|
||||||
$nl
|
$nl
|
||||||
"If the class is not a tuple class word, this word does nothing." }
|
"If the class is not a tuple class word, this word does nothing." }
|
||||||
|
@ -218,8 +214,8 @@ HELP: check-tuple
|
||||||
{ $error-description "Thrown if " { $link POSTPONE: C: } " is called with a word which does not name a tuple class." } ;
|
{ $error-description "Thrown if " { $link POSTPONE: C: } " is called with a word which does not name a tuple class." } ;
|
||||||
|
|
||||||
HELP: define-tuple-class
|
HELP: define-tuple-class
|
||||||
{ $values { "class" word } { "slots" "a sequence of strings" } }
|
{ $values { "class" word } { "superclass" class } { "slots" "a sequence of strings" } }
|
||||||
{ $description "Defines a tuple class with slots named by " { $snippet "slots" } ". This is the run time equivalent of " { $link POSTPONE: TUPLE: } "." }
|
{ $description "Defines a tuple class inheriting from " { $snippet "superclass" } " with slots named by " { $snippet "slots" } ". This is the run time equivalent of " { $link POSTPONE: TUPLE: } "." }
|
||||||
{ $notes "This word must be called from inside " { $link with-compilation-unit } "." }
|
{ $notes "This word must be called from inside " { $link with-compilation-unit } "." }
|
||||||
{ $side-effects "class" } ;
|
{ $side-effects "class" } ;
|
||||||
|
|
||||||
|
@ -246,9 +242,13 @@ HELP: tuple>array ( tuple -- array )
|
||||||
{ $values { "tuple" tuple } { "array" array } }
|
{ $values { "tuple" tuple } { "array" array } }
|
||||||
{ $description "Outputs an array having the tuple's slots as elements. The first element is the tuple class word and the second is the delegate; the remainder are declared slots." } ;
|
{ $description "Outputs an array having the tuple's slots as elements. The first element is the tuple class word and the second is the delegate; the remainder are declared slots." } ;
|
||||||
|
|
||||||
HELP: <tuple> ( class n -- tuple )
|
HELP: <tuple> ( layout -- tuple )
|
||||||
{ $values { "class" tuple-class } { "n" "a non-negative integer" } { "tuple" tuple } }
|
{ $values { "layout" tuple-layout } { "tuple" tuple } }
|
||||||
{ $description "Low-level tuple constructor. User code should never call this directly, and instead use the constructor word which is defined for each tuple. See " { $link "tuples" } "." } ;
|
{ $description "Low-level tuple constructor. User code should never call this directly, and instead use " { $link construct-empty } "." } ;
|
||||||
|
|
||||||
|
HELP: <tuple-boa> ( ... layout -- tuple )
|
||||||
|
{ $values { "..." "values" } { "layout" tuple-layout } { "tuple" tuple } }
|
||||||
|
{ $description "Low-level tuple constructor. User code should never call this directly, and instead use " { $link construct-boa } "." } ;
|
||||||
|
|
||||||
HELP: construct-empty
|
HELP: construct-empty
|
||||||
{ $values { "class" tuple-class } { "tuple" tuple } }
|
{ $values { "class" tuple-class } { "tuple" tuple } }
|
||||||
|
|
|
@ -2,18 +2,19 @@ USING: definitions generic kernel kernel.private math
|
||||||
math.constants parser sequences tools.test words assocs
|
math.constants parser sequences tools.test words assocs
|
||||||
namespaces quotations sequences.private classes continuations
|
namespaces quotations sequences.private classes continuations
|
||||||
generic.standard effects tuples tuples.private arrays vectors
|
generic.standard effects tuples tuples.private arrays vectors
|
||||||
strings compiler.units ;
|
strings compiler.units accessors classes.algebra calendar
|
||||||
|
prettyprint io.streams.string splitting ;
|
||||||
IN: tuples.tests
|
IN: tuples.tests
|
||||||
|
|
||||||
TUPLE: rect x y w h ;
|
TUPLE: rect x y w h ;
|
||||||
: <rect> rect construct-boa ;
|
: <rect> rect construct-boa ;
|
||||||
|
|
||||||
: move ( x rect -- )
|
: move ( x rect -- rect )
|
||||||
[ rect-x + ] keep set-rect-x ;
|
[ + ] change-x ;
|
||||||
|
|
||||||
[ f ] [ 10 20 30 40 <rect> dup clone 5 swap [ move ] keep = ] unit-test
|
[ f ] [ 10 20 30 40 <rect> dup clone 5 swap move = ] unit-test
|
||||||
|
|
||||||
[ t ] [ 10 20 30 40 <rect> dup clone 0 swap [ move ] keep = ] unit-test
|
[ t ] [ 10 20 30 40 <rect> dup clone 0 swap move = ] unit-test
|
||||||
|
|
||||||
GENERIC: delegation-test
|
GENERIC: delegation-test
|
||||||
M: object delegation-test drop 3 ;
|
M: object delegation-test drop 3 ;
|
||||||
|
@ -34,27 +35,46 @@ TUPLE: quuux-tuple-2 ;
|
||||||
|
|
||||||
[ 4 ] [ <quux-tuple-2> <quuux-tuple-2> delegation-test-2 ] unit-test
|
[ 4 ] [ <quux-tuple-2> <quuux-tuple-2> delegation-test-2 ] unit-test
|
||||||
|
|
||||||
|
! Make sure we handle tuple class redefinition
|
||||||
|
TUPLE: redefinition-test ;
|
||||||
|
|
||||||
|
C: <redefinition-test> redefinition-test
|
||||||
|
|
||||||
|
<redefinition-test> "redefinition-test" set
|
||||||
|
|
||||||
|
[ t ] [ "redefinition-test" get redefinition-test? ] unit-test
|
||||||
|
|
||||||
|
"IN: tuples.tests TUPLE: redefinition-test ;" eval
|
||||||
|
|
||||||
|
[ t ] [ "redefinition-test" get redefinition-test? ] unit-test
|
||||||
|
|
||||||
! Make sure we handle changing shapes!
|
! Make sure we handle changing shapes!
|
||||||
TUPLE: point x y ;
|
TUPLE: point x y ;
|
||||||
|
|
||||||
C: <point> point
|
C: <point> point
|
||||||
|
|
||||||
100 200 <point> "p" set
|
[ ] [ 100 200 <point> "p" set ] unit-test
|
||||||
|
|
||||||
! Use eval to sequence parsing explicitly
|
! Use eval to sequence parsing explicitly
|
||||||
"IN: tuples.tests TUPLE: point x y z ;" eval
|
[ ] [ "IN: tuples.tests TUPLE: point x y z ;" eval ] unit-test
|
||||||
|
|
||||||
[ 100 ] [ "p" get point-x ] unit-test
|
[ 100 ] [ "p" get x>> ] unit-test
|
||||||
[ 200 ] [ "p" get point-y ] unit-test
|
[ 200 ] [ "p" get y>> ] unit-test
|
||||||
[ f ] [ "p" get "point-z" "tuples.tests" lookup execute ] unit-test
|
[ f ] [ "p" get "z>>" "accessors" lookup execute ] unit-test
|
||||||
|
|
||||||
300 "p" get "set-point-z" "tuples.tests" lookup execute
|
"p" get 300 ">>z" "accessors" lookup execute drop
|
||||||
|
|
||||||
|
[ 4 ] [ "p" get tuple-size ] unit-test
|
||||||
|
|
||||||
|
[ 300 ] [ "p" get "z>>" "accessors" lookup execute ] unit-test
|
||||||
|
|
||||||
"IN: tuples.tests TUPLE: point z y ;" eval
|
"IN: tuples.tests TUPLE: point z y ;" eval
|
||||||
|
|
||||||
[ "p" get point-x ] must-fail
|
[ 3 ] [ "p" get tuple-size ] unit-test
|
||||||
[ 200 ] [ "p" get point-y ] unit-test
|
|
||||||
[ 300 ] [ "p" get "point-z" "tuples.tests" lookup execute ] unit-test
|
[ "p" get x>> ] must-fail
|
||||||
|
[ 200 ] [ "p" get y>> ] unit-test
|
||||||
|
[ 300 ] [ "p" get "z>>" "accessors" lookup execute ] unit-test
|
||||||
|
|
||||||
TUPLE: predicate-test ;
|
TUPLE: predicate-test ;
|
||||||
|
|
||||||
|
@ -64,14 +84,14 @@ C: <predicate-test> predicate-test
|
||||||
|
|
||||||
[ t ] [ <predicate-test> predicate-test? ] unit-test
|
[ t ] [ <predicate-test> predicate-test? ] unit-test
|
||||||
|
|
||||||
PREDICATE: tuple silly-pred
|
PREDICATE: silly-pred < tuple
|
||||||
class \ rect = ;
|
class \ rect = ;
|
||||||
|
|
||||||
GENERIC: area
|
GENERIC: area
|
||||||
M: silly-pred area dup rect-w swap rect-h * ;
|
M: silly-pred area dup w>> swap h>> * ;
|
||||||
|
|
||||||
TUPLE: circle radius ;
|
TUPLE: circle radius ;
|
||||||
M: circle area circle-radius sq pi * ;
|
M: circle area radius>> sq pi * ;
|
||||||
|
|
||||||
[ 200 ] [ T{ rect f 0 0 10 20 } area ] unit-test
|
[ 200 ] [ T{ rect f 0 0 10 20 } area ] unit-test
|
||||||
|
|
||||||
|
@ -88,7 +108,7 @@ TUPLE: delegate-clone ;
|
||||||
[ T{ delegate-clone T{ empty f } } clone ] unit-test
|
[ T{ delegate-clone T{ empty f } } clone ] unit-test
|
||||||
|
|
||||||
! Compiler regression
|
! Compiler regression
|
||||||
[ t length ] [ no-method-object t eq? ] must-fail-with
|
[ t length ] [ object>> t eq? ] must-fail-with
|
||||||
|
|
||||||
[ "<constructor-test>" ]
|
[ "<constructor-test>" ]
|
||||||
[ "TUPLE: constructor-test ; C: <constructor-test> constructor-test" eval word word-name ] unit-test
|
[ "TUPLE: constructor-test ; C: <constructor-test> constructor-test" eval word word-name ] unit-test
|
||||||
|
@ -96,7 +116,7 @@ TUPLE: delegate-clone ;
|
||||||
TUPLE: size-test a b c d ;
|
TUPLE: size-test a b c d ;
|
||||||
|
|
||||||
[ t ] [
|
[ t ] [
|
||||||
T{ size-test } array-capacity
|
T{ size-test } tuple-size
|
||||||
size-test tuple-size =
|
size-test tuple-size =
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
@ -213,22 +233,69 @@ C: <erg's-reshape-problem> erg's-reshape-problem
|
||||||
! tuples are reshaped
|
! tuples are reshaped
|
||||||
: cons-test-1 \ erg's-reshape-problem construct-empty ;
|
: cons-test-1 \ erg's-reshape-problem construct-empty ;
|
||||||
: cons-test-2 \ erg's-reshape-problem construct-boa ;
|
: cons-test-2 \ erg's-reshape-problem construct-boa ;
|
||||||
: cons-test-3
|
|
||||||
{ set-erg's-reshape-problem-a }
|
|
||||||
\ erg's-reshape-problem construct ;
|
|
||||||
|
|
||||||
"IN: tuples.tests TUPLE: erg's-reshape-problem a b c d e f ;" eval
|
"IN: tuples.tests TUPLE: erg's-reshape-problem a b c d e f ;" eval
|
||||||
|
|
||||||
[ ] [ 1 2 3 4 5 6 cons-test-2 "a" set ] unit-test
|
[ ] [ 1 2 3 4 5 6 cons-test-2 "a" set ] unit-test
|
||||||
|
|
||||||
[ t ] [ cons-test-1 array-capacity "a" get array-capacity = ] unit-test
|
[ t ] [ cons-test-1 tuple-size "a" get tuple-size = ] unit-test
|
||||||
|
|
||||||
[ t ] [ 1 cons-test-3 array-capacity "a" get array-capacity = ] unit-test
|
|
||||||
|
|
||||||
[
|
[
|
||||||
"IN: tuples.tests SYMBOL: not-a-class C: <not-a-class> not-a-class" eval
|
"IN: tuples.tests SYMBOL: not-a-class C: <not-a-class> not-a-class" eval
|
||||||
] [ [ no-tuple-class? ] is? ] must-fail-with
|
] [ [ no-tuple-class? ] is? ] must-fail-with
|
||||||
|
|
||||||
|
! Inheritance
|
||||||
|
TUPLE: computer cpu ram ;
|
||||||
|
|
||||||
|
[ "TUPLE: computer cpu ram ;" ] [
|
||||||
|
[ \ computer see ] with-string-writer string-lines second
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
TUPLE: laptop < computer battery ;
|
||||||
|
C: <laptop> laptop
|
||||||
|
|
||||||
|
[ t ] [ laptop tuple-class? ] unit-test
|
||||||
|
[ t ] [ laptop tuple class< ] unit-test
|
||||||
|
[ t ] [ laptop computer class< ] unit-test
|
||||||
|
[ t ] [ laptop computer classes-intersect? ] unit-test
|
||||||
|
|
||||||
|
[ ] [ "Pentium" 128 3 hours <laptop> "laptop" set ] unit-test
|
||||||
|
[ t ] [ "laptop" get laptop? ] unit-test
|
||||||
|
[ t ] [ "laptop" get computer? ] unit-test
|
||||||
|
[ t ] [ "laptop" get tuple? ] unit-test
|
||||||
|
|
||||||
|
[ "TUPLE: laptop < computer battery ;" ] [
|
||||||
|
[ \ laptop see ] with-string-writer string-lines second
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
TUPLE: server < computer rackmount? ;
|
||||||
|
C: <server> server
|
||||||
|
|
||||||
|
[ t ] [ server tuple-class? ] unit-test
|
||||||
|
[ t ] [ server tuple class< ] unit-test
|
||||||
|
[ t ] [ server computer class< ] unit-test
|
||||||
|
[ t ] [ server computer classes-intersect? ] unit-test
|
||||||
|
|
||||||
|
[ ] [ "Pentium" 128 "1U" <server> "server" set ] unit-test
|
||||||
|
[ t ] [ "server" get server? ] unit-test
|
||||||
|
[ t ] [ "server" get computer? ] unit-test
|
||||||
|
[ t ] [ "server" get tuple? ] unit-test
|
||||||
|
|
||||||
|
[ f ] [ "server" get laptop? ] unit-test
|
||||||
|
[ f ] [ "laptop" get server? ] unit-test
|
||||||
|
|
||||||
|
[ f ] [ server laptop class< ] unit-test
|
||||||
|
[ f ] [ laptop server class< ] unit-test
|
||||||
|
[ f ] [ laptop server classes-intersect? ] unit-test
|
||||||
|
|
||||||
|
[ "TUPLE: server < computer rackmount? ;" ] [
|
||||||
|
[ \ server see ] with-string-writer string-lines second
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
[
|
||||||
|
"IN: tuples.tests TUPLE: bad-superclass < word ;" eval
|
||||||
|
] must-fail
|
||||||
|
|
||||||
! Hardcore unit tests
|
! Hardcore unit tests
|
||||||
USE: threads
|
USE: threads
|
||||||
|
|
||||||
|
@ -236,14 +303,14 @@ USE: threads
|
||||||
|
|
||||||
[ ] [
|
[ ] [
|
||||||
[
|
[
|
||||||
\ thread { "xxx" } "slot-names" get append
|
\ thread tuple { "xxx" } "slot-names" get append
|
||||||
define-tuple-class
|
define-tuple-class
|
||||||
] with-compilation-unit
|
] with-compilation-unit
|
||||||
|
|
||||||
[ 1337 sleep ] "Test" spawn drop
|
[ 1337 sleep ] "Test" spawn drop
|
||||||
|
|
||||||
[
|
[
|
||||||
\ thread "slot-names" get
|
\ thread tuple "slot-names" get
|
||||||
define-tuple-class
|
define-tuple-class
|
||||||
] with-compilation-unit
|
] with-compilation-unit
|
||||||
] unit-test
|
] unit-test
|
||||||
|
@ -254,14 +321,14 @@ USE: vocabs
|
||||||
|
|
||||||
[ ] [
|
[ ] [
|
||||||
[
|
[
|
||||||
\ vocab { "xxx" } "slot-names" get append
|
\ vocab tuple { "xxx" } "slot-names" get append
|
||||||
define-tuple-class
|
define-tuple-class
|
||||||
] with-compilation-unit
|
] with-compilation-unit
|
||||||
|
|
||||||
all-words drop
|
all-words drop
|
||||||
|
|
||||||
[
|
[
|
||||||
\ vocab "slot-names" get
|
\ vocab tuple "slot-names" get
|
||||||
define-tuple-class
|
define-tuple-class
|
||||||
] with-compilation-unit
|
] with-compilation-unit
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
|
@ -1,31 +1,91 @@
|
||||||
! Copyright (C) 2005, 2007 Slava Pestov.
|
! Copyright (C) 2005, 2008 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: arrays definitions hashtables kernel
|
USING: arrays definitions hashtables kernel
|
||||||
kernel.private math namespaces sequences sequences.private
|
kernel.private math namespaces sequences sequences.private
|
||||||
strings vectors words quotations memory combinators generic
|
strings vectors words quotations memory combinators generic
|
||||||
classes classes.private slots slots.deprecated slots.private
|
classes classes.private slots.deprecated slots.private slots
|
||||||
compiler.units ;
|
compiler.units ;
|
||||||
IN: tuples
|
IN: tuples
|
||||||
|
|
||||||
M: tuple delegate 3 slot ;
|
M: tuple delegate 2 slot ;
|
||||||
|
|
||||||
M: tuple set-delegate 3 set-slot ;
|
M: tuple set-delegate 2 set-slot ;
|
||||||
|
|
||||||
M: tuple class class-of-tuple ;
|
M: tuple class 1 slot 2 slot { word } declare ;
|
||||||
|
|
||||||
|
ERROR: no-tuple-class class ;
|
||||||
|
|
||||||
|
<PRIVATE
|
||||||
|
|
||||||
|
: tuple-size tuple-layout layout-size ; inline
|
||||||
|
|
||||||
|
PRIVATE>
|
||||||
|
|
||||||
|
: check-tuple ( class -- )
|
||||||
|
dup tuple-class?
|
||||||
|
[ drop ] [ no-tuple-class ] if ;
|
||||||
|
|
||||||
|
: tuple>array ( tuple -- array )
|
||||||
|
dup tuple-layout
|
||||||
|
[ layout-size swap [ array-nth ] curry map ] keep
|
||||||
|
layout-class add* ;
|
||||||
|
|
||||||
|
: >tuple ( sequence -- tuple )
|
||||||
|
dup first tuple-layout <tuple> [
|
||||||
|
>r 1 tail-slice dup length r>
|
||||||
|
[ tuple-size min ] keep
|
||||||
|
[ set-array-nth ] curry
|
||||||
|
2each
|
||||||
|
] keep ;
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
: tuple= ( tuple1 tuple2 -- ? )
|
: tuple= ( tuple1 tuple2 -- ? )
|
||||||
over array-capacity over array-capacity tuck number= [
|
over tuple-layout over tuple-layout eq? [
|
||||||
-rot
|
dup tuple-size -rot
|
||||||
[ >r over r> array-nth >r array-nth r> = ] 2curry
|
[ >r over r> array-nth >r array-nth r> = ] 2curry
|
||||||
all-integers?
|
all-integers?
|
||||||
] [
|
] [
|
||||||
3drop f
|
2drop f
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
: tuple-class-eq? ( obj class -- ? )
|
M: tuple-class tuple-layout "layout" word-prop ;
|
||||||
over tuple? [ swap 2 slot eq? ] [ 2drop f ] if ; inline
|
|
||||||
|
: define-tuple-predicate ( class -- )
|
||||||
|
dup tuple-layout
|
||||||
|
[ over tuple? [ swap 1 slot eq? ] [ 2drop f ] if ] curry
|
||||||
|
define-predicate ;
|
||||||
|
|
||||||
|
: delegate-slot-spec
|
||||||
|
T{ slot-spec f
|
||||||
|
object
|
||||||
|
"delegate"
|
||||||
|
2
|
||||||
|
delegate
|
||||||
|
set-delegate
|
||||||
|
} ;
|
||||||
|
|
||||||
|
: define-tuple-slots ( class slots -- )
|
||||||
|
dupd 3 simple-slots
|
||||||
|
2dup [ slot-spec-name ] map "slot-names" set-word-prop
|
||||||
|
2dup delegate-slot-spec add* "slots" set-word-prop
|
||||||
|
2dup define-slots
|
||||||
|
define-accessors ;
|
||||||
|
|
||||||
|
: define-tuple-layout ( class -- )
|
||||||
|
dup
|
||||||
|
dup "slot-names" word-prop length 1+ { } 0 <tuple-layout>
|
||||||
|
"layout" set-word-prop ;
|
||||||
|
|
||||||
|
: removed-slots ( class newslots -- seq )
|
||||||
|
swap "slot-names" word-prop seq-diff ;
|
||||||
|
|
||||||
|
: forget-slots ( class newslots -- )
|
||||||
|
dupd removed-slots [
|
||||||
|
2dup
|
||||||
|
reader-word forget-method
|
||||||
|
writer-word forget-method
|
||||||
|
] with each ;
|
||||||
|
|
||||||
: permutation ( seq1 seq2 -- permutation )
|
: permutation ( seq1 seq2 -- permutation )
|
||||||
swap [ index ] curry map ;
|
swap [ index ] curry map ;
|
||||||
|
@ -33,7 +93,7 @@ M: tuple class class-of-tuple ;
|
||||||
: reshape-tuple ( oldtuple permutation -- newtuple )
|
: reshape-tuple ( oldtuple permutation -- newtuple )
|
||||||
>r tuple>array 2 cut r>
|
>r tuple>array 2 cut r>
|
||||||
[ [ swap ?nth ] [ drop f ] if* ] with map
|
[ [ swap ?nth ] [ drop f ] if* ] with map
|
||||||
append (>tuple) ;
|
append >tuple ;
|
||||||
|
|
||||||
: reshape-tuples ( class newslots -- )
|
: reshape-tuples ( class newslots -- )
|
||||||
>r dup "slot-names" word-prop r> permutation
|
>r dup "slot-names" word-prop r> permutation
|
||||||
|
@ -43,63 +103,40 @@ M: tuple class class-of-tuple ;
|
||||||
become
|
become
|
||||||
] 2curry after-compilation ;
|
] 2curry after-compilation ;
|
||||||
|
|
||||||
: old-slots ( class newslots -- seq )
|
: tuple-class-unchanged ( class superclass slots -- ) 3drop ;
|
||||||
swap "slots" word-prop 1 tail-slice
|
|
||||||
[ slot-spec-name swap member? not ] with subset ;
|
|
||||||
|
|
||||||
: forget-slots ( class newslots -- )
|
: prepare-tuple-class ( class slots -- )
|
||||||
dupd old-slots [
|
dupd define-tuple-slots
|
||||||
2dup
|
dup define-tuple-layout
|
||||||
slot-spec-reader 2array forget
|
define-tuple-predicate ;
|
||||||
slot-spec-writer 2array forget
|
|
||||||
] with each ;
|
|
||||||
|
|
||||||
: check-shape ( class newslots -- )
|
: change-superclass "not supported" throw ;
|
||||||
over tuple-class? [
|
|
||||||
over "slot-names" word-prop over = [
|
|
||||||
2dup forget-slots
|
|
||||||
2dup reshape-tuples
|
|
||||||
over changed-word
|
|
||||||
over redefined
|
|
||||||
] unless
|
|
||||||
] when 2drop ;
|
|
||||||
|
|
||||||
GENERIC: tuple-size ( class -- size )
|
: redefine-tuple-class ( class superclass slots -- )
|
||||||
|
>r 2dup swap superclass eq?
|
||||||
|
[ drop ] [ dupd change-superclass ] if r>
|
||||||
|
2dup forget-slots
|
||||||
|
2dup reshape-tuples
|
||||||
|
over changed-word
|
||||||
|
over redefined
|
||||||
|
prepare-tuple-class ;
|
||||||
|
|
||||||
M: tuple-class tuple-size "slot-names" word-prop length 2 + ;
|
: define-new-tuple-class ( class superclass slots -- )
|
||||||
|
>r dupd f swap tuple-class define-class r>
|
||||||
|
prepare-tuple-class ;
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
: define-tuple-predicate ( class -- )
|
: define-tuple-class ( class superclass slots -- )
|
||||||
dup [ tuple-class-eq? ] curry define-predicate ;
|
{
|
||||||
|
{ [ pick tuple-class? not ] [ define-new-tuple-class ] }
|
||||||
|
{ [ pick "slot-names" word-prop over = ] [ tuple-class-unchanged ] }
|
||||||
|
{ [ t ] [ redefine-tuple-class ] }
|
||||||
|
} cond ;
|
||||||
|
|
||||||
: delegate-slot-spec
|
: define-error-class ( class superclass slots -- )
|
||||||
T{ slot-spec f
|
pick >r define-tuple-class r>
|
||||||
object
|
dup [ construct-boa throw ] curry define ;
|
||||||
"delegate"
|
|
||||||
3
|
|
||||||
delegate
|
|
||||||
set-delegate
|
|
||||||
} ;
|
|
||||||
|
|
||||||
: define-tuple-slots ( class slots -- )
|
|
||||||
dupd 4 simple-slots
|
|
||||||
2dup [ slot-spec-name ] map "slot-names" set-word-prop
|
|
||||||
2dup delegate-slot-spec add* "slots" set-word-prop
|
|
||||||
2dup define-slots
|
|
||||||
define-accessors ;
|
|
||||||
|
|
||||||
ERROR: no-tuple-class class ;
|
|
||||||
|
|
||||||
: check-tuple ( class -- )
|
|
||||||
dup tuple-class?
|
|
||||||
[ drop ] [ no-tuple-class ] if ;
|
|
||||||
|
|
||||||
: define-tuple-class ( class slots -- )
|
|
||||||
2dup check-shape
|
|
||||||
over f tuple tuple-class define-class
|
|
||||||
over define-tuple-predicate
|
|
||||||
define-tuple-slots ;
|
|
||||||
|
|
||||||
M: tuple clone
|
M: tuple clone
|
||||||
(clone) dup delegate clone over set-delegate ;
|
(clone) dup delegate clone over set-delegate ;
|
||||||
|
@ -107,21 +144,14 @@ M: tuple clone
|
||||||
M: tuple equal?
|
M: tuple equal?
|
||||||
over tuple? [ tuple= ] [ 2drop f ] if ;
|
over tuple? [ tuple= ] [ 2drop f ] if ;
|
||||||
|
|
||||||
: (delegates) ( obj -- )
|
|
||||||
[ dup , delegate (delegates) ] when* ;
|
|
||||||
|
|
||||||
: delegates ( obj -- seq )
|
: delegates ( obj -- seq )
|
||||||
[ dup ] [ [ delegate ] keep ] [ ] unfold nip ;
|
[ dup ] [ [ delegate ] keep ] [ ] unfold nip ;
|
||||||
|
|
||||||
: is? ( obj quot -- ? ) >r delegates r> contains? ; inline
|
: is? ( obj quot -- ? ) >r delegates r> contains? ; inline
|
||||||
|
|
||||||
: >tuple ( seq -- tuple )
|
|
||||||
>vector dup first tuple-size over set-length
|
|
||||||
>array (>tuple) ;
|
|
||||||
|
|
||||||
M: tuple hashcode*
|
M: tuple hashcode*
|
||||||
[
|
[
|
||||||
dup array-capacity -rot 0 -rot [
|
dup tuple-size -rot 0 -rot [
|
||||||
swapd array-nth hashcode* bitxor
|
swapd array-nth hashcode* bitxor
|
||||||
] 2curry reduce
|
] 2curry reduce
|
||||||
] recursive-hashcode ;
|
] recursive-hashcode ;
|
||||||
|
@ -131,7 +161,7 @@ M: tuple hashcode*
|
||||||
! Definition protocol
|
! Definition protocol
|
||||||
M: tuple-class reset-class
|
M: tuple-class reset-class
|
||||||
{
|
{
|
||||||
"metaclass" "superclass" "slot-names" "slots"
|
"metaclass" "superclass" "slot-names" "slots" "layout"
|
||||||
} reset-props ;
|
} reset-props ;
|
||||||
|
|
||||||
M: object get-slots ( obj slots -- ... )
|
M: object get-slots ( obj slots -- ... )
|
||||||
|
@ -141,10 +171,10 @@ M: object set-slots ( ... obj slots -- )
|
||||||
<reversed> get-slots ;
|
<reversed> get-slots ;
|
||||||
|
|
||||||
M: object construct-empty ( class -- tuple )
|
M: object construct-empty ( class -- tuple )
|
||||||
dup tuple-size <tuple> ;
|
tuple-layout <tuple> ;
|
||||||
|
|
||||||
M: object construct ( ... slots class -- tuple )
|
M: object construct ( ... slots class -- tuple )
|
||||||
construct-empty [ swap set-slots ] keep ;
|
construct-empty [ swap set-slots ] keep ;
|
||||||
|
|
||||||
M: object construct-boa ( ... class -- tuple )
|
M: object construct-boa ( ... class -- tuple )
|
||||||
dup tuple-size <tuple-boa> ;
|
tuple-layout <tuple-boa> ;
|
||||||
|
|
|
@ -23,17 +23,17 @@ M: word definition word-def ;
|
||||||
|
|
||||||
ERROR: undefined ;
|
ERROR: undefined ;
|
||||||
|
|
||||||
PREDICATE: word deferred ( obj -- ? )
|
PREDICATE: deferred < word ( obj -- ? )
|
||||||
word-def [ undefined ] = ;
|
word-def [ undefined ] = ;
|
||||||
M: deferred definer drop \ DEFER: f ;
|
M: deferred definer drop \ DEFER: f ;
|
||||||
M: deferred definition drop f ;
|
M: deferred definition drop f ;
|
||||||
|
|
||||||
PREDICATE: word symbol ( obj -- ? )
|
PREDICATE: symbol < word ( obj -- ? )
|
||||||
dup <wrapper> 1array swap word-def sequence= ;
|
dup <wrapper> 1array swap word-def sequence= ;
|
||||||
M: symbol definer drop \ SYMBOL: f ;
|
M: symbol definer drop \ SYMBOL: f ;
|
||||||
M: symbol definition drop f ;
|
M: symbol definition drop f ;
|
||||||
|
|
||||||
PREDICATE: word primitive ( obj -- ? )
|
PREDICATE: primitive < word ( obj -- ? )
|
||||||
word-def [ do-primitive ] tail? ;
|
word-def [ do-primitive ] tail? ;
|
||||||
M: primitive definer drop \ PRIMITIVE: f ;
|
M: primitive definer drop \ PRIMITIVE: f ;
|
||||||
M: primitive definition drop f ;
|
M: primitive definition drop f ;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
USING: kernel system namespaces sequences splitting combinators
|
USING: kernel system namespaces sequences splitting combinators
|
||||||
io.files io.launcher
|
io io.files io.launcher
|
||||||
bake combinators.cleave builder.common builder.util ;
|
bake combinators.cleave builder.common builder.util ;
|
||||||
|
|
||||||
IN: builder.release
|
IN: builder.release
|
||||||
|
@ -91,6 +91,39 @@ IN: builder.release
|
||||||
: remove-factor-app ( -- )
|
: remove-factor-app ( -- )
|
||||||
macosx? not [ { "rm" "-rf" "Factor.app" } try-process ] when ;
|
macosx? not [ { "rm" "-rf" "Factor.app" } try-process ] when ;
|
||||||
|
|
||||||
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
|
SYMBOL: upload-to-factorcode
|
||||||
|
|
||||||
|
: platform ( -- string ) { os cpu- } to-strings "-" join ;
|
||||||
|
|
||||||
|
: remote-location ( -- dest )
|
||||||
|
"factorcode.org:/var/www/factorcode.org/newsite/downloads"
|
||||||
|
platform
|
||||||
|
append-path ;
|
||||||
|
|
||||||
|
: upload ( -- )
|
||||||
|
{ "scp" archive-name remote-location } to-strings
|
||||||
|
[ "Error uploading binary to factorcode" print ]
|
||||||
|
run-or-bail ;
|
||||||
|
|
||||||
|
: maybe-upload ( -- )
|
||||||
|
upload-to-factorcode get
|
||||||
|
[ upload ]
|
||||||
|
when ;
|
||||||
|
|
||||||
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
|
! : release ( -- )
|
||||||
|
! "factor"
|
||||||
|
! [
|
||||||
|
! remove-factor-app
|
||||||
|
! remove-common-files
|
||||||
|
! ]
|
||||||
|
! with-directory
|
||||||
|
! make-archive
|
||||||
|
! archive-name releases move-file-into ;
|
||||||
|
|
||||||
: release ( -- )
|
: release ( -- )
|
||||||
"factor"
|
"factor"
|
||||||
[
|
[
|
||||||
|
@ -99,6 +132,7 @@ IN: builder.release
|
||||||
]
|
]
|
||||||
with-directory
|
with-directory
|
||||||
make-archive
|
make-archive
|
||||||
|
maybe-upload
|
||||||
archive-name releases move-file-into ;
|
archive-name releases move-file-into ;
|
||||||
|
|
||||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
! Copyright (C) 2007 Slava Pestov, Chris Double, Doug Coleman,
|
! Copyright (C) 2007, 2008 Slava Pestov, Chris Double,
|
||||||
! Eduardo Cavazos, Daniel Ehrenberg.
|
! Doug Coleman, Eduardo Cavazos,
|
||||||
|
! Daniel Ehrenberg.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: kernel combinators namespaces quotations hashtables
|
USING: kernel combinators fry namespaces quotations hashtables
|
||||||
sequences assocs arrays inference effects math math.ranges
|
sequences assocs arrays inference effects math math.ranges
|
||||||
arrays.lib shuffle macros bake combinators.cleave
|
arrays.lib shuffle macros bake combinators.cleave
|
||||||
continuations ;
|
continuations ;
|
||||||
|
@ -34,9 +35,8 @@ MACRO: nwith ( quot n -- )
|
||||||
|
|
||||||
MACRO: napply ( n -- )
|
MACRO: napply ( n -- )
|
||||||
2 [a,b]
|
2 [a,b]
|
||||||
[ [ ] [ 1- ] bi
|
[ [ 1- ] [ ] bi
|
||||||
[ , ntuck , nslip ]
|
'[ , ntuck , nslip ] ]
|
||||||
bake ]
|
|
||||||
map concat >quotation [ call ] append ;
|
map concat >quotation [ call ] append ;
|
||||||
|
|
||||||
: 3apply ( obj obj obj quot -- ) 3 napply ; inline
|
: 3apply ( obj obj obj quot -- ) 3 napply ; inline
|
||||||
|
@ -88,26 +88,21 @@ MACRO: || ( quots -- ? ) [ [ t ] ] f short-circuit ;
|
||||||
! ifte
|
! ifte
|
||||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
|
MACRO: preserving ( predicate -- quot )
|
||||||
|
dup infer effect-in
|
||||||
|
dup 1+
|
||||||
|
'[ , , nkeep , nrot ] ;
|
||||||
|
|
||||||
MACRO: ifte ( quot quot quot -- )
|
MACRO: ifte ( quot quot quot -- )
|
||||||
pick infer effect-in
|
'[ , preserving , , if ] ;
|
||||||
dup 1+ swap
|
|
||||||
[ >r >r , nkeep , nrot r> r> if ]
|
|
||||||
bake ;
|
|
||||||
|
|
||||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
! switch
|
! switch
|
||||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
: preserving ( predicate -- quot )
|
|
||||||
dup infer effect-in
|
|
||||||
dup 1+ spin
|
|
||||||
[ , , nkeep , nrot ]
|
|
||||||
bake ;
|
|
||||||
|
|
||||||
MACRO: switch ( quot -- )
|
MACRO: switch ( quot -- )
|
||||||
[ [ preserving ] [ ] bi* ] assoc-map
|
[ [ [ preserving ] curry ] dip ] assoc-map
|
||||||
[ , cond ]
|
[ cond ] curry ;
|
||||||
bake ;
|
|
||||||
|
|
||||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ IN: delegate
|
||||||
CREATE-WORD dup define-symbol
|
CREATE-WORD dup define-symbol
|
||||||
parse-definition swap define-protocol ; parsing
|
parse-definition swap define-protocol ; parsing
|
||||||
|
|
||||||
PREDICATE: word protocol "protocol-words" word-prop ;
|
PREDICATE: protocol < word "protocol-words" word-prop ;
|
||||||
|
|
||||||
GENERIC: group-words ( group -- words )
|
GENERIC: group-words ( group -- words )
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ IN: help.markup
|
||||||
|
|
||||||
! Element types are words whose name begins with $.
|
! Element types are words whose name begins with $.
|
||||||
|
|
||||||
PREDICATE: array simple-element
|
PREDICATE: simple-element < array
|
||||||
dup empty? [ drop t ] [ first word? not ] if ;
|
dup empty? [ drop t ] [ first word? not ] if ;
|
||||||
|
|
||||||
SYMBOL: last-element
|
SYMBOL: last-element
|
||||||
|
|
|
@ -16,7 +16,7 @@ M: link >link ;
|
||||||
M: vocab-spec >link ;
|
M: vocab-spec >link ;
|
||||||
M: object >link link construct-boa ;
|
M: object >link link construct-boa ;
|
||||||
|
|
||||||
PREDICATE: link word-link link-name word? ;
|
PREDICATE: word-link < link link-name word? ;
|
||||||
|
|
||||||
M: link summary
|
M: link summary
|
||||||
[
|
[
|
||||||
|
|
|
@ -54,9 +54,9 @@ M: no-inverse summary
|
||||||
: undo-literal ( object -- quot )
|
: undo-literal ( object -- quot )
|
||||||
[ =/fail ] curry ;
|
[ =/fail ] curry ;
|
||||||
|
|
||||||
PREDICATE: word normal-inverse "inverse" word-prop ;
|
PREDICATE: normal-inverse < word "inverse" word-prop ;
|
||||||
PREDICATE: word math-inverse "math-inverse" word-prop ;
|
PREDICATE: math-inverse < word "math-inverse" word-prop ;
|
||||||
PREDICATE: word pop-inverse "pop-length" word-prop ;
|
PREDICATE: pop-inverse < word "pop-length" word-prop ;
|
||||||
UNION: explicit-inverse normal-inverse math-inverse pop-inverse ;
|
UNION: explicit-inverse normal-inverse math-inverse pop-inverse ;
|
||||||
|
|
||||||
: inline-word ( word -- )
|
: inline-word ( word -- )
|
||||||
|
|
|
@ -54,10 +54,8 @@ IN: io.encodings.8-bit
|
||||||
[ byte>ch ] [ ch>byte ] bi ;
|
[ byte>ch ] [ ch>byte ] bi ;
|
||||||
|
|
||||||
: empty-tuple-class ( string -- class )
|
: empty-tuple-class ( string -- class )
|
||||||
in get create
|
"io.encodings.8-bit" create
|
||||||
dup { f } "slots" set-word-prop
|
dup tuple { } define-tuple-class ;
|
||||||
dup predicate-word drop
|
|
||||||
dup { } define-tuple-class ;
|
|
||||||
|
|
||||||
: data-quot ( class word data -- quot )
|
: data-quot ( class word data -- quot )
|
||||||
>r [ word-name ] 2apply "/" swap 3append
|
>r [ word-name ] 2apply "/" swap 3append
|
||||||
|
|
|
@ -22,8 +22,8 @@ M: port set-timeout set-port-timeout ;
|
||||||
|
|
||||||
SYMBOL: closed
|
SYMBOL: closed
|
||||||
|
|
||||||
PREDICATE: port input-port port-type input-port eq? ;
|
PREDICATE: input-port < port port-type input-port eq? ;
|
||||||
PREDICATE: port output-port port-type output-port eq? ;
|
PREDICATE: output-port < port port-type output-port eq? ;
|
||||||
|
|
||||||
GENERIC: init-handle ( handle -- )
|
GENERIC: init-handle ( handle -- )
|
||||||
GENERIC: close-handle ( handle -- )
|
GENERIC: close-handle ( handle -- )
|
||||||
|
|
|
@ -29,23 +29,23 @@ TUPLE: wlet bindings body ;
|
||||||
|
|
||||||
C: <wlet> wlet
|
C: <wlet> wlet
|
||||||
|
|
||||||
PREDICATE: word local "local?" word-prop ;
|
PREDICATE: local < word "local?" word-prop ;
|
||||||
|
|
||||||
: <local> ( name -- word )
|
: <local> ( name -- word )
|
||||||
#! Create a local variable identifier
|
#! Create a local variable identifier
|
||||||
f <word> dup t "local?" set-word-prop ;
|
f <word> dup t "local?" set-word-prop ;
|
||||||
|
|
||||||
PREDICATE: word local-word "local-word?" word-prop ;
|
PREDICATE: local-word < word "local-word?" word-prop ;
|
||||||
|
|
||||||
: <local-word> ( name -- word )
|
: <local-word> ( name -- word )
|
||||||
f <word> dup t "local-word?" set-word-prop ;
|
f <word> dup t "local-word?" set-word-prop ;
|
||||||
|
|
||||||
PREDICATE: word local-reader "local-reader?" word-prop ;
|
PREDICATE: local-reader < word "local-reader?" word-prop ;
|
||||||
|
|
||||||
: <local-reader> ( name -- word )
|
: <local-reader> ( name -- word )
|
||||||
f <word> dup t "local-reader?" set-word-prop ;
|
f <word> dup t "local-reader?" set-word-prop ;
|
||||||
|
|
||||||
PREDICATE: word local-writer "local-writer?" word-prop ;
|
PREDICATE: local-writer < word "local-writer?" word-prop ;
|
||||||
|
|
||||||
: <local-writer> ( reader -- word )
|
: <local-writer> ( reader -- word )
|
||||||
dup word-name "!" append f <word>
|
dup word-name "!" append f <word>
|
||||||
|
@ -357,7 +357,7 @@ M: wlet pprint* \ [wlet pprint-let ;
|
||||||
|
|
||||||
M: let* pprint* \ [let* pprint-let ;
|
M: let* pprint* \ [let* pprint-let ;
|
||||||
|
|
||||||
PREDICATE: word lambda-word
|
PREDICATE: lambda-word < word
|
||||||
"lambda" word-prop >boolean ;
|
"lambda" word-prop >boolean ;
|
||||||
|
|
||||||
M: lambda-word definer drop \ :: \ ; ;
|
M: lambda-word definer drop \ :: \ ; ;
|
||||||
|
@ -373,7 +373,7 @@ M: lambda-word definition
|
||||||
|
|
||||||
M: lambda-word synopsis* lambda-word-synopsis ;
|
M: lambda-word synopsis* lambda-word-synopsis ;
|
||||||
|
|
||||||
PREDICATE: macro lambda-macro
|
PREDICATE: lambda-macro < macro
|
||||||
"lambda" word-prop >boolean ;
|
"lambda" word-prop >boolean ;
|
||||||
|
|
||||||
M: lambda-macro definer drop \ MACRO:: \ ; ;
|
M: lambda-macro definer drop \ MACRO:: \ ; ;
|
||||||
|
@ -383,7 +383,7 @@ M: lambda-macro definition
|
||||||
|
|
||||||
M: lambda-macro synopsis* lambda-word-synopsis ;
|
M: lambda-macro synopsis* lambda-word-synopsis ;
|
||||||
|
|
||||||
PREDICATE: method-body lambda-method
|
PREDICATE: lambda-method < method-body
|
||||||
"lambda" word-prop >boolean ;
|
"lambda" word-prop >boolean ;
|
||||||
|
|
||||||
M: lambda-method definer drop \ M:: \ ; ;
|
M: lambda-method definer drop \ M:: \ ; ;
|
||||||
|
|
|
@ -17,7 +17,7 @@ IN: macros
|
||||||
: MACRO:
|
: MACRO:
|
||||||
(:) define-macro ; parsing
|
(:) define-macro ; parsing
|
||||||
|
|
||||||
PREDICATE: word macro "macro" word-prop >boolean ;
|
PREDICATE: macro < word "macro" word-prop >boolean ;
|
||||||
|
|
||||||
M: macro definer drop \ MACRO: \ ; ;
|
M: macro definer drop \ MACRO: \ ; ;
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ IN: memoize
|
||||||
: MEMO:
|
: MEMO:
|
||||||
CREATE-WORD parse-definition define-memoized ; parsing
|
CREATE-WORD parse-definition define-memoized ; parsing
|
||||||
|
|
||||||
PREDICATE: word memoized "memoize" word-prop ;
|
PREDICATE: memoized < word "memoize" word-prop ;
|
||||||
|
|
||||||
M: memoized definer drop \ MEMO: \ ; ;
|
M: memoized definer drop \ MEMO: \ ; ;
|
||||||
M: memoized definition "memo-quot" word-prop ;
|
M: memoized definition "memo-quot" word-prop ;
|
||||||
|
|
|
@ -64,7 +64,8 @@ GENERIC: method-prologue ( combination -- quot )
|
||||||
|
|
||||||
TUPLE: method word def classes generic loc ;
|
TUPLE: method word def classes generic loc ;
|
||||||
|
|
||||||
PREDICATE: word method-body "multi-method" word-prop >boolean ;
|
PREDICATE: method-body < word
|
||||||
|
"multi-method" word-prop >boolean ;
|
||||||
|
|
||||||
M: method-body stack-effect
|
M: method-body stack-effect
|
||||||
"multi-method" word-prop method-generic stack-effect ;
|
"multi-method" word-prop method-generic stack-effect ;
|
||||||
|
@ -209,13 +210,13 @@ M: hook-combination generic-prologue
|
||||||
USE: qualified
|
USE: qualified
|
||||||
QUALIFIED: syntax
|
QUALIFIED: syntax
|
||||||
|
|
||||||
PREDICATE: word generic
|
PREDICATE: generic < word
|
||||||
"multi-combination" word-prop >boolean ;
|
"multi-combination" word-prop >boolean ;
|
||||||
|
|
||||||
PREDICATE: word standard-generic
|
PREDICATE: standard-generic < word
|
||||||
"multi-combination" word-prop standard-combination? ;
|
"multi-combination" word-prop standard-combination? ;
|
||||||
|
|
||||||
PREDICATE: word hook-generic
|
PREDICATE: hook-generic < word
|
||||||
"multi-combination" word-prop hook-combination? ;
|
"multi-combination" word-prop hook-combination? ;
|
||||||
|
|
||||||
syntax:M: standard-generic definer drop \ GENERIC: f ;
|
syntax:M: standard-generic definer drop \ GENERIC: f ;
|
||||||
|
@ -233,7 +234,7 @@ syntax:M: hook-generic synopsis*
|
||||||
dup "multi-combination" word-prop
|
dup "multi-combination" word-prop
|
||||||
hook-combination-var pprint-word stack-effect. ;
|
hook-combination-var pprint-word stack-effect. ;
|
||||||
|
|
||||||
PREDICATE: array method-spec
|
PREDICATE: method-spec < array
|
||||||
unclip generic? >r [ class? ] all? r> and ;
|
unclip generic? >r [ class? ] all? r> and ;
|
||||||
|
|
||||||
syntax:M: method-spec where
|
syntax:M: method-spec where
|
||||||
|
|
|
@ -55,9 +55,9 @@ IN: opengl.shaders
|
||||||
|
|
||||||
: delete-gl-shader ( shader -- ) glDeleteShader ; inline
|
: delete-gl-shader ( shader -- ) glDeleteShader ; inline
|
||||||
|
|
||||||
PREDICATE: integer gl-shader (gl-shader?) ;
|
PREDICATE: gl-shader < integer (gl-shader?) ;
|
||||||
PREDICATE: gl-shader vertex-shader (vertex-shader?) ;
|
PREDICATE: vertex-shader < gl-shader (vertex-shader?) ;
|
||||||
PREDICATE: gl-shader fragment-shader (fragment-shader?) ;
|
PREDICATE: fragment-shader < gl-shader (fragment-shader?) ;
|
||||||
|
|
||||||
! Programs
|
! Programs
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ PREDICATE: gl-shader fragment-shader (fragment-shader?) ;
|
||||||
MACRO: with-gl-program ( uniforms quot -- )
|
MACRO: with-gl-program ( uniforms quot -- )
|
||||||
(make-with-gl-program) ;
|
(make-with-gl-program) ;
|
||||||
|
|
||||||
PREDICATE: integer gl-program (gl-program?) ;
|
PREDICATE: gl-program < integer (gl-program?) ;
|
||||||
|
|
||||||
: <simple-gl-program> ( vertex-shader-source fragment-shader-source -- program )
|
: <simple-gl-program> ( vertex-shader-source fragment-shader-source -- program )
|
||||||
>r <vertex-shader> check-gl-shader
|
>r <vertex-shader> check-gl-shader
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespaces math math.parser openssl prettyprint sequences tools.test ;
|
||||||
|
|
||||||
[ ] [ ssl-v23 new-ctx ] unit-test
|
[ ] [ ssl-v23 new-ctx ] unit-test
|
||||||
|
|
||||||
[ ] [ get-ctx "/extra/openssl/test/server.pem" resource-path use-cert-chain ] unit-test
|
[ ] [ get-ctx "extra/openssl/test/server.pem" resource-path use-cert-chain ] unit-test
|
||||||
|
|
||||||
! TODO: debug 'Memory protection fault at address 6c'
|
! TODO: debug 'Memory protection fault at address 6c'
|
||||||
! get-ctx 1024 "char" malloc-array 1024 0 f password-cb set-default-passwd
|
! get-ctx 1024 "char" malloc-array 1024 0 f password-cb set-default-passwd
|
||||||
|
@ -33,10 +33,10 @@ namespaces math math.parser openssl prettyprint sequences tools.test ;
|
||||||
[ ] [ get-ctx "password" string>char-alien set-default-passwd-userdata ] unit-test
|
[ ] [ get-ctx "password" string>char-alien set-default-passwd-userdata ] unit-test
|
||||||
|
|
||||||
! Enter PEM pass phrase: password
|
! Enter PEM pass phrase: password
|
||||||
[ ] [ get-ctx "/extra/openssl/test/server.pem" resource-path
|
[ ] [ get-ctx "extra/openssl/test/server.pem" resource-path
|
||||||
SSL_FILETYPE_PEM use-private-key ] unit-test
|
SSL_FILETYPE_PEM use-private-key ] unit-test
|
||||||
|
|
||||||
[ ] [ get-ctx "/extra/openssl/test/root.pem" resource-path f
|
[ ] [ get-ctx "extra/openssl/test/root.pem" resource-path f
|
||||||
verify-load-locations ] unit-test
|
verify-load-locations ] unit-test
|
||||||
|
|
||||||
[ ] [ get-ctx 1 set-verify-depth ] unit-test
|
[ ] [ get-ctx 1 set-verify-depth ] unit-test
|
||||||
|
@ -45,7 +45,7 @@ verify-load-locations ] unit-test
|
||||||
! Load Diffie-Hellman parameters
|
! Load Diffie-Hellman parameters
|
||||||
! =========================================================
|
! =========================================================
|
||||||
|
|
||||||
[ ] [ "/extra/openssl/test/dh1024.pem" resource-path "r" bio-new-file ] unit-test
|
[ ] [ "extra/openssl/test/dh1024.pem" resource-path "r" bio-new-file ] unit-test
|
||||||
|
|
||||||
[ ] [ get-bio f f f read-pem-dh-params ] unit-test
|
[ ] [ get-bio f f f read-pem-dh-params ] unit-test
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ verify-load-locations ] unit-test
|
||||||
! Dump errors to file
|
! Dump errors to file
|
||||||
! =========================================================
|
! =========================================================
|
||||||
|
|
||||||
[ ] [ "/extra/openssl/test/errors.txt" resource-path "w" bio-new-file ] unit-test
|
[ ] [ "extra/openssl/test/errors.txt" resource-path "w" bio-new-file ] unit-test
|
||||||
|
|
||||||
[ 6 ] [ get-bio "Hello\n" bio-print ] unit-test
|
[ 6 ] [ get-bio "Hello\n" bio-print ] unit-test
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,9 @@ sequences words ;
|
||||||
IN: singleton
|
IN: singleton
|
||||||
|
|
||||||
: define-singleton ( token -- )
|
: define-singleton ( token -- )
|
||||||
\ word swap create-class-in
|
create-class-in
|
||||||
dup [ eq? ] curry define-predicate-class ;
|
\ word
|
||||||
|
over [ eq? ] curry define-predicate-class ;
|
||||||
|
|
||||||
: SINGLETON:
|
: SINGLETON:
|
||||||
scan define-singleton ; parsing
|
scan define-singleton ; parsing
|
||||||
|
|
|
@ -155,7 +155,6 @@ IN: tools.deploy.shaker
|
||||||
layouts:tag-numbers
|
layouts:tag-numbers
|
||||||
layouts:type-numbers
|
layouts:type-numbers
|
||||||
lexer-factory
|
lexer-factory
|
||||||
lexer-factory
|
|
||||||
listener:listener-hook
|
listener:listener-hook
|
||||||
root-cache
|
root-cache
|
||||||
vocab-roots
|
vocab-roots
|
||||||
|
|
|
@ -9,7 +9,7 @@ SYMBOL: +nullary+
|
||||||
SYMBOL: +listener+
|
SYMBOL: +listener+
|
||||||
SYMBOL: +description+
|
SYMBOL: +description+
|
||||||
|
|
||||||
PREDICATE: word listener-command +listener+ word-prop ;
|
PREDICATE: listener-command < word +listener+ word-prop ;
|
||||||
|
|
||||||
GENERIC: invoke-command ( target command -- )
|
GENERIC: invoke-command ( target command -- )
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ TUPLE: operation predicate command translator hook listener? ;
|
||||||
set-operation-hook
|
set-operation-hook
|
||||||
} operation construct ;
|
} operation construct ;
|
||||||
|
|
||||||
PREDICATE: operation listener-operation
|
PREDICATE: listener-operation < operation
|
||||||
dup operation-command listener-command?
|
dup operation-command listener-command?
|
||||||
swap operation-listener? or ;
|
swap operation-listener? or ;
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ IN: unicode.syntax
|
||||||
] [ ] make ;
|
] [ ] make ;
|
||||||
|
|
||||||
: define-category ( word categories -- )
|
: define-category ( word categories -- )
|
||||||
[category] fixnum -rot define-predicate-class ;
|
[category] integer swap define-predicate-class ;
|
||||||
|
|
||||||
: CATEGORY:
|
: CATEGORY:
|
||||||
CREATE ";" parse-tokens define-category ; parsing
|
CREATE ";" parse-tokens define-category ; parsing
|
||||||
|
|
|
@ -17,7 +17,7 @@ M: integer item>xml
|
||||||
[ "Integers must fit in 32 bits" throw ] unless
|
[ "Integers must fit in 32 bits" throw ] unless
|
||||||
number>string "i4" build-tag ;
|
number>string "i4" build-tag ;
|
||||||
|
|
||||||
PREDICATE: object boolean { t f } member? ;
|
PREDICATE: boolean < object { t f } member? ;
|
||||||
|
|
||||||
M: boolean item>xml
|
M: boolean item>xml
|
||||||
"1" "0" ? "boolean" build-tag ;
|
"1" "0" ? "boolean" build-tag ;
|
||||||
|
|
|
@ -139,5 +139,5 @@ M: xml like
|
||||||
: <contained-tag> ( name attrs -- tag )
|
: <contained-tag> ( name attrs -- tag )
|
||||||
f <tag> ;
|
f <tag> ;
|
||||||
|
|
||||||
PREDICATE: tag contained-tag tag-children not ;
|
PREDICATE: contained-tag < tag tag-children not ;
|
||||||
PREDICATE: tag open-tag tag-children ;
|
PREDICATE: open-tag < tag tag-children ;
|
||||||
|
|
10
vm/data_gc.c
10
vm/data_gc.c
|
@ -156,10 +156,12 @@ CELL untagged_object_size(CELL pointer)
|
||||||
/* Size of the data area of an object pointed to by an untagged pointer */
|
/* Size of the data area of an object pointed to by an untagged pointer */
|
||||||
CELL unaligned_object_size(CELL pointer)
|
CELL unaligned_object_size(CELL pointer)
|
||||||
{
|
{
|
||||||
|
F_TUPLE *tuple;
|
||||||
|
F_TUPLE_LAYOUT *layout;
|
||||||
|
|
||||||
switch(untag_header(get(pointer)))
|
switch(untag_header(get(pointer)))
|
||||||
{
|
{
|
||||||
case ARRAY_TYPE:
|
case ARRAY_TYPE:
|
||||||
case TUPLE_TYPE:
|
|
||||||
case BIGNUM_TYPE:
|
case BIGNUM_TYPE:
|
||||||
return array_size(array_capacity((F_ARRAY*)pointer));
|
return array_size(array_capacity((F_ARRAY*)pointer));
|
||||||
case BYTE_ARRAY_TYPE:
|
case BYTE_ARRAY_TYPE:
|
||||||
|
@ -173,6 +175,10 @@ CELL unaligned_object_size(CELL pointer)
|
||||||
float_array_capacity((F_FLOAT_ARRAY*)pointer));
|
float_array_capacity((F_FLOAT_ARRAY*)pointer));
|
||||||
case STRING_TYPE:
|
case STRING_TYPE:
|
||||||
return string_size(string_capacity((F_STRING*)pointer));
|
return string_size(string_capacity((F_STRING*)pointer));
|
||||||
|
case TUPLE_TYPE:
|
||||||
|
tuple = untag_object(pointer);
|
||||||
|
layout = untag_object(tuple->layout);
|
||||||
|
return tuple_size(layout);
|
||||||
case QUOTATION_TYPE:
|
case QUOTATION_TYPE:
|
||||||
return sizeof(F_QUOTATION);
|
return sizeof(F_QUOTATION);
|
||||||
case WORD_TYPE:
|
case WORD_TYPE:
|
||||||
|
@ -192,6 +198,8 @@ CELL unaligned_object_size(CELL pointer)
|
||||||
case CALLSTACK_TYPE:
|
case CALLSTACK_TYPE:
|
||||||
return callstack_size(
|
return callstack_size(
|
||||||
untag_fixnum_fast(((F_CALLSTACK *)pointer)->length));
|
untag_fixnum_fast(((F_CALLSTACK *)pointer)->length));
|
||||||
|
case TUPLE_LAYOUT_TYPE:
|
||||||
|
return sizeof(F_TUPLE_LAYOUT);
|
||||||
default:
|
default:
|
||||||
critical_error("Invalid header",pointer);
|
critical_error("Invalid header",pointer);
|
||||||
return -1; /* can't happen */
|
return -1; /* can't happen */
|
||||||
|
|
31
vm/debug.c
31
vm/debug.c
|
@ -57,6 +57,35 @@ void print_array(F_ARRAY* array, CELL nesting)
|
||||||
printf("...");
|
printf("...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void print_tuple(F_TUPLE* tuple, CELL nesting)
|
||||||
|
{
|
||||||
|
F_TUPLE_LAYOUT *layout = untag_object(tuple->layout);
|
||||||
|
CELL length = to_fixnum(layout->size);
|
||||||
|
|
||||||
|
printf(" ");
|
||||||
|
print_nested_obj(layout->class,nesting);
|
||||||
|
|
||||||
|
CELL i;
|
||||||
|
bool trimmed;
|
||||||
|
|
||||||
|
if(length > 10)
|
||||||
|
{
|
||||||
|
trimmed = true;
|
||||||
|
length = 10;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
trimmed = false;
|
||||||
|
|
||||||
|
for(i = 0; i < length; i++)
|
||||||
|
{
|
||||||
|
printf(" ");
|
||||||
|
print_nested_obj(tuple_nth(tuple,i),nesting);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(trimmed)
|
||||||
|
printf("...");
|
||||||
|
}
|
||||||
|
|
||||||
void print_nested_obj(CELL obj, F_FIXNUM nesting)
|
void print_nested_obj(CELL obj, F_FIXNUM nesting)
|
||||||
{
|
{
|
||||||
if(nesting <= 0)
|
if(nesting <= 0)
|
||||||
|
@ -83,7 +112,7 @@ void print_nested_obj(CELL obj, F_FIXNUM nesting)
|
||||||
break;
|
break;
|
||||||
case TUPLE_TYPE:
|
case TUPLE_TYPE:
|
||||||
printf("T{");
|
printf("T{");
|
||||||
print_array(untag_object(obj),nesting - 1);
|
print_tuple(untag_object(obj),nesting - 1);
|
||||||
printf(" }");
|
printf(" }");
|
||||||
break;
|
break;
|
||||||
case ARRAY_TYPE:
|
case ARRAY_TYPE:
|
||||||
|
|
56
vm/image.c
56
vm/image.c
|
@ -216,25 +216,45 @@ void fixup_callstack_object(F_CALLSTACK *stack)
|
||||||
/* Initialize an object in a newly-loaded image */
|
/* Initialize an object in a newly-loaded image */
|
||||||
void relocate_object(CELL relocating)
|
void relocate_object(CELL relocating)
|
||||||
{
|
{
|
||||||
do_slots(relocating,data_fixup);
|
/* Tuple relocation is a bit trickier; we have to fix up the
|
||||||
|
fixup object before we can get the tuple size, so do_slots is
|
||||||
switch(untag_header(get(relocating)))
|
out of the question */
|
||||||
|
if(untag_header(get(relocating)) == TUPLE_TYPE)
|
||||||
{
|
{
|
||||||
case WORD_TYPE:
|
data_fixup((CELL *)relocating + 1);
|
||||||
fixup_word((F_WORD *)relocating);
|
|
||||||
break;
|
CELL scan = relocating + 2 * CELLS;
|
||||||
case QUOTATION_TYPE:
|
CELL size = untagged_object_size(relocating);
|
||||||
fixup_quotation((F_QUOTATION *)relocating);
|
CELL end = relocating + size;
|
||||||
break;
|
|
||||||
case DLL_TYPE:
|
while(scan < end)
|
||||||
ffi_dlopen((F_DLL *)relocating);
|
{
|
||||||
break;
|
data_fixup((CELL *)scan);
|
||||||
case ALIEN_TYPE:
|
scan += CELLS;
|
||||||
fixup_alien((F_ALIEN *)relocating);
|
}
|
||||||
break;
|
}
|
||||||
case CALLSTACK_TYPE:
|
else
|
||||||
fixup_callstack_object((F_CALLSTACK *)relocating);
|
{
|
||||||
break;
|
do_slots(relocating,data_fixup);
|
||||||
|
|
||||||
|
switch(untag_header(get(relocating)))
|
||||||
|
{
|
||||||
|
case WORD_TYPE:
|
||||||
|
fixup_word((F_WORD *)relocating);
|
||||||
|
break;
|
||||||
|
case QUOTATION_TYPE:
|
||||||
|
fixup_quotation((F_QUOTATION *)relocating);
|
||||||
|
break;
|
||||||
|
case DLL_TYPE:
|
||||||
|
ffi_dlopen((F_DLL *)relocating);
|
||||||
|
break;
|
||||||
|
case ALIEN_TYPE:
|
||||||
|
fixup_alien((F_ALIEN *)relocating);
|
||||||
|
break;
|
||||||
|
case CALLSTACK_TYPE:
|
||||||
|
fixup_callstack_object((F_CALLSTACK *)relocating);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
25
vm/layouts.h
25
vm/layouts.h
|
@ -58,8 +58,9 @@ typedef signed long long s64;
|
||||||
#define ALIEN_TYPE 16
|
#define ALIEN_TYPE 16
|
||||||
#define WORD_TYPE 17
|
#define WORD_TYPE 17
|
||||||
#define BYTE_ARRAY_TYPE 18
|
#define BYTE_ARRAY_TYPE 18
|
||||||
|
#define TUPLE_LAYOUT_TYPE 19
|
||||||
|
|
||||||
#define TYPE_COUNT 19
|
#define TYPE_COUNT 20
|
||||||
|
|
||||||
INLINE bool immediate_p(CELL obj)
|
INLINE bool immediate_p(CELL obj)
|
||||||
{
|
{
|
||||||
|
@ -224,3 +225,25 @@ typedef struct
|
||||||
/* Frame size in bytes */
|
/* Frame size in bytes */
|
||||||
CELL size;
|
CELL size;
|
||||||
} F_STACK_FRAME;
|
} F_STACK_FRAME;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
CELL header;
|
||||||
|
/* tagged fixnum */
|
||||||
|
CELL hashcode;
|
||||||
|
/* tagged */
|
||||||
|
CELL class;
|
||||||
|
/* tagged fixnum */
|
||||||
|
CELL size;
|
||||||
|
/* tagged array */
|
||||||
|
CELL superclasses;
|
||||||
|
/* tagged fixnum */
|
||||||
|
CELL echelon;
|
||||||
|
} F_TUPLE_LAYOUT;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
CELL header;
|
||||||
|
/* tagged layout */
|
||||||
|
CELL layout;
|
||||||
|
} F_TUPLE;
|
||||||
|
|
|
@ -169,11 +169,10 @@ void *primitives[] = {
|
||||||
primitive_wrapper,
|
primitive_wrapper,
|
||||||
primitive_clone,
|
primitive_clone,
|
||||||
primitive_string,
|
primitive_string,
|
||||||
primitive_to_tuple,
|
|
||||||
primitive_array_to_quotation,
|
primitive_array_to_quotation,
|
||||||
primitive_quotation_xt,
|
primitive_quotation_xt,
|
||||||
primitive_tuple,
|
primitive_tuple,
|
||||||
primitive_tuple_to_array,
|
primitive_tuple_layout,
|
||||||
primitive_profiling,
|
primitive_profiling,
|
||||||
primitive_become,
|
primitive_become,
|
||||||
primitive_sleep,
|
primitive_sleep,
|
||||||
|
|
5
vm/run.c
5
vm/run.c
|
@ -320,8 +320,9 @@ DEFINE_PRIMITIVE(class_hash)
|
||||||
CELL tag = TAG(obj);
|
CELL tag = TAG(obj);
|
||||||
if(tag == TUPLE_TYPE)
|
if(tag == TUPLE_TYPE)
|
||||||
{
|
{
|
||||||
F_WORD *class = untag_object(get(SLOT(obj,2)));
|
F_TUPLE *tuple = untag_object(obj);
|
||||||
drepl(class->hashcode);
|
F_TUPLE_LAYOUT *layout = untag_object(tuple->layout);
|
||||||
|
drepl(layout->hashcode);
|
||||||
}
|
}
|
||||||
else if(tag == OBJECT_TYPE)
|
else if(tag == OBJECT_TYPE)
|
||||||
drepl(get(UNTAG(obj)));
|
drepl(get(UNTAG(obj)));
|
||||||
|
|
66
vm/types.c
66
vm/types.c
|
@ -379,45 +379,61 @@ DEFINE_PRIMITIVE(resize_float_array)
|
||||||
dpush(tag_object(reallot_float_array(array,capacity)));
|
dpush(tag_object(reallot_float_array(array,capacity)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Tuple layouts */
|
||||||
|
DEFINE_PRIMITIVE(tuple_layout)
|
||||||
|
{
|
||||||
|
F_TUPLE_LAYOUT *layout = allot_object(TUPLE_LAYOUT_TYPE,sizeof(F_TUPLE_LAYOUT));
|
||||||
|
layout->echelon = dpop();
|
||||||
|
layout->superclasses = dpop();
|
||||||
|
layout->size = dpop();
|
||||||
|
layout->class = dpop();
|
||||||
|
layout->hashcode = untag_word(layout->class)->hashcode;
|
||||||
|
dpush(tag_object(layout));
|
||||||
|
}
|
||||||
|
|
||||||
/* Tuples */
|
/* Tuples */
|
||||||
|
|
||||||
/* push a new tuple on the stack */
|
/* push a new tuple on the stack */
|
||||||
|
F_TUPLE *allot_tuple(F_TUPLE_LAYOUT *layout)
|
||||||
|
{
|
||||||
|
REGISTER_UNTAGGED(layout);
|
||||||
|
F_TUPLE *tuple = allot_object(TUPLE_TYPE,tuple_size(layout));
|
||||||
|
UNREGISTER_UNTAGGED(layout);
|
||||||
|
tuple->layout = tag_object(layout);
|
||||||
|
return tuple;
|
||||||
|
}
|
||||||
|
|
||||||
DEFINE_PRIMITIVE(tuple)
|
DEFINE_PRIMITIVE(tuple)
|
||||||
{
|
{
|
||||||
CELL size = unbox_array_size();
|
F_TUPLE_LAYOUT *layout = untag_object(dpop());
|
||||||
F_ARRAY *array = allot_array(TUPLE_TYPE,size,F);
|
F_FIXNUM size = to_fixnum(layout->size);
|
||||||
set_array_nth(array,0,dpop());
|
|
||||||
dpush(tag_tuple(array));
|
F_TUPLE *tuple = allot_tuple(layout);
|
||||||
|
F_FIXNUM i;
|
||||||
|
for(i = size - 1; i >= 0; i--)
|
||||||
|
put(AREF(tuple,i),F);
|
||||||
|
|
||||||
|
dpush(tag_tuple(tuple));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* push a new tuple on the stack, filling its slots from the stack */
|
/* push a new tuple on the stack, filling its slots from the stack */
|
||||||
DEFINE_PRIMITIVE(tuple_boa)
|
DEFINE_PRIMITIVE(tuple_boa)
|
||||||
{
|
{
|
||||||
CELL size = unbox_array_size();
|
F_TUPLE_LAYOUT *layout = untag_object(dpop());
|
||||||
F_ARRAY *array = allot_array(TUPLE_TYPE,size,F);
|
F_FIXNUM size = to_fixnum(layout->size);
|
||||||
set_array_nth(array,0,dpop());
|
|
||||||
|
|
||||||
CELL i;
|
REGISTER_UNTAGGED(layout);
|
||||||
for(i = size - 1; i >= 2; i--)
|
F_TUPLE *tuple = allot_tuple(layout);
|
||||||
set_array_nth(array,i,dpop());
|
UNREGISTER_UNTAGGED(layout);
|
||||||
|
|
||||||
dpush(tag_tuple(array));
|
/* set delegate slot */
|
||||||
}
|
put(AREF(tuple,0),F);
|
||||||
|
|
||||||
DEFINE_PRIMITIVE(tuple_to_array)
|
F_FIXNUM i;
|
||||||
{
|
for(i = size - 1; i >= 1; i--)
|
||||||
CELL object = dpeek();
|
put(AREF(tuple,i),dpop());
|
||||||
type_check(TUPLE_TYPE,object);
|
|
||||||
object = RETAG(clone(object),OBJECT_TYPE);
|
|
||||||
set_slot(object,0,tag_header(ARRAY_TYPE));
|
|
||||||
drepl(object);
|
|
||||||
}
|
|
||||||
|
|
||||||
DEFINE_PRIMITIVE(to_tuple)
|
dpush(tag_tuple(tuple));
|
||||||
{
|
|
||||||
CELL object = RETAG(clone(dpeek()),TUPLE_TYPE);
|
|
||||||
set_slot(object,0,tag_header(TUPLE_TYPE));
|
|
||||||
drepl(object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Strings */
|
/* Strings */
|
||||||
|
|
28
vm/types.h
28
vm/types.h
|
@ -96,11 +96,34 @@ DEFINE_UNTAG(F_QUOTATION,QUOTATION_TYPE,quotation)
|
||||||
|
|
||||||
DEFINE_UNTAG(F_WORD,WORD_TYPE,word)
|
DEFINE_UNTAG(F_WORD,WORD_TYPE,word)
|
||||||
|
|
||||||
INLINE CELL tag_tuple(F_ARRAY *tuple)
|
INLINE CELL tag_tuple(F_TUPLE *tuple)
|
||||||
{
|
{
|
||||||
return RETAG(tuple,TUPLE_TYPE);
|
return RETAG(tuple,TUPLE_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
INLINE F_TUPLE *untag_tuple(CELL object)
|
||||||
|
{
|
||||||
|
type_check(TUPLE_TYPE,object);
|
||||||
|
return untag_object(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
INLINE CELL tuple_size(F_TUPLE_LAYOUT *layout)
|
||||||
|
{
|
||||||
|
CELL size = untag_fixnum_fast(layout->size);
|
||||||
|
return sizeof(F_TUPLE) + size * CELLS;
|
||||||
|
}
|
||||||
|
|
||||||
|
INLINE CELL tuple_nth(F_TUPLE *tuple, CELL slot)
|
||||||
|
{
|
||||||
|
return get(AREF(tuple,slot));
|
||||||
|
}
|
||||||
|
|
||||||
|
INLINE void set_tuple_nth(F_TUPLE *tuple, CELL slot, CELL value)
|
||||||
|
{
|
||||||
|
put(AREF(tuple,slot),value);
|
||||||
|
write_barrier((CELL)tuple);
|
||||||
|
}
|
||||||
|
|
||||||
/* Prototypes */
|
/* Prototypes */
|
||||||
DLLEXPORT void box_boolean(bool value);
|
DLLEXPORT void box_boolean(bool value);
|
||||||
DLLEXPORT bool to_boolean(CELL value);
|
DLLEXPORT bool to_boolean(CELL value);
|
||||||
|
@ -116,12 +139,11 @@ CELL allot_array_4(CELL v1, CELL v2, CELL v3, CELL v4);
|
||||||
DECLARE_PRIMITIVE(array);
|
DECLARE_PRIMITIVE(array);
|
||||||
DECLARE_PRIMITIVE(tuple);
|
DECLARE_PRIMITIVE(tuple);
|
||||||
DECLARE_PRIMITIVE(tuple_boa);
|
DECLARE_PRIMITIVE(tuple_boa);
|
||||||
|
DECLARE_PRIMITIVE(tuple_layout);
|
||||||
DECLARE_PRIMITIVE(byte_array);
|
DECLARE_PRIMITIVE(byte_array);
|
||||||
DECLARE_PRIMITIVE(bit_array);
|
DECLARE_PRIMITIVE(bit_array);
|
||||||
DECLARE_PRIMITIVE(float_array);
|
DECLARE_PRIMITIVE(float_array);
|
||||||
DECLARE_PRIMITIVE(clone);
|
DECLARE_PRIMITIVE(clone);
|
||||||
DECLARE_PRIMITIVE(tuple_to_array);
|
|
||||||
DECLARE_PRIMITIVE(to_tuple);
|
|
||||||
|
|
||||||
F_ARRAY *reallot_array(F_ARRAY* array, CELL capacity, CELL fill);
|
F_ARRAY *reallot_array(F_ARRAY* array, CELL capacity, CELL fill);
|
||||||
DECLARE_PRIMITIVE(resize_array);
|
DECLARE_PRIMITIVE(resize_array);
|
||||||
|
|
Loading…
Reference in New Issue