\r
+ oop:\r
\r
-- make see work with generics\r
+- make see work with union, builtin, predicate\r
- doc comments of generics\r
- redo traits with generic method map\r
\r
new String[args.size()]));
external = new ExternalFactor(PORT);
-
- process.getErrorStream().close();
- process.getInputStream().close();
- process.getOutputStream().close();
}
catch(Exception e)
{
external.close();
try
{
+ process.getErrorStream().close();
+ process.getInputStream().close();
+ process.getOutputStream().close();
process.waitFor();
}
catch(Exception e)
Log.log(Log.DEBUG,FactorPlugin.class,e);
}
external = null;
+ process = null;
}
} //}}}
try
{
state = getConsoleState(console);
+ state.openStream();
state.packetLoop(output);
}
catch(Exception e)
}
else
{
- /* try
+ try
{
packetLoop(output);
}
catch(Exception e)
{
Log.log(Log.ERROR,this,e);
- } */
+ }
}
}
if(waitingForInput)
return;
- openStream();
-
if(stream == null)
return;
builtin 50 "priority" set-word-property
+! All builtin types are equivalent in ordering
+builtin [ 2drop t ] "class<" set-word-property
+
: builtin-predicate ( type# symbol -- )
over f type = [
nip [ not ] "predicate" set-word-property
: class-ord ( class -- n ) metaclass "priority" word-property ;
: class< ( cls1 cls2 -- ? )
- swap class-ord swap class-ord < ;
+ over metaclass over metaclass = [
+ dup metaclass "class<" word-property call
+ ] [
+ swap class-ord swap class-ord <
+ ] ifte ;
-: sort-methods ( methods -- alist )
- hash>alist [ 2car class< ] sort ;
+: methods ( generic -- alist )
+ "methods" word-property hash>alist [ 2car class< ] sort ;
: add-method ( generic vtable definition class -- )
#! Add the method entry to the vtable. Unlike define-method,
: <empty-vtable> ( -- vtable )
num-types [ drop [ undefined-method ] ] vector-project ;
-: <vtable> ( generic methods -- vtable )
- >r <empty-vtable> r> sort-methods [
+: <vtable> ( generic -- vtable )
+ <empty-vtable> over methods [
+ ( generic vtable method )
>r 2dup r> unswons add-method
] each nip ;
over "combination" word-property cons define-compound ;
: (define-method) ( definition class generic -- )
- [ "methods" word-property set-hash ] keep
- dup dup "methods" word-property <vtable>
+ [ "methods" word-property set-hash ] keep dup <vtable>
define-generic ;
+: init-methods ( word -- )
+ dup "methods" word-property [
+ drop
+ ] [
+ <namespace> "methods" set-word-property
+ ] ifte ;
+
! Defining generic words
-: (GENERIC) ( combination -- )
+: (GENERIC) ( combination definer -- )
#! Takes a combination parameter. A combination is a
#! quotation that takes some objects and a vtable from the
#! stack, and calls the appropriate row of the vtable.
- CREATE [ swap "combination" set-word-property ] keep
- dup dup "methods" word-property [
- dup <namespace> [ "methods" set-word-property ] keep
- ] unless* <vtable> define-generic ;
+ CREATE
+ [ swap "definer" set-word-property ] keep
+ [ swap "combination" set-word-property ] keep
+ dup init-methods
+ dup <vtable> define-generic ;
-PREDICATE: word generic ( word -- ? )
+PREDICATE: compound generic ( word -- ? )
"combination" word-property ;
: single-combination ( obj vtable -- )
: GENERIC:
#! GENERIC: bar creates a generic word bar. Add methods to
#! the generic word using M:.
- [ single-combination ] (GENERIC) ; parsing
+ [ single-combination ] \ GENERIC: (GENERIC) ; parsing
: arithmetic-combination ( n n vtable -- )
#! Note that the numbers remain on the stack, possibly after
#! the generic word using M:. 2GENERIC words dispatch on
#! arithmetic types and should not be used for non-numerical
#! types.
- [ arithmetic-combination ] (GENERIC) ; parsing
+ [ arithmetic-combination ] \ 2GENERIC: (GENERIC) ; parsing
: define-method ( class -- quotation )
#! In a vain attempt at something resembling a "meta object
object 100 "priority" set-word-property
+object [ 2drop t ] "class<" set-word-property
+
object object define-class
predicate 25 "priority" set-word-property
+predicate [
+ 2dup = [
+ 2drop t
+ ] [
+ >r "superclass" word-property r> class<
+ ] ifte
+] "class<" set-word-property
+
: define-predicate ( class predicate definition -- )
rot "superclass" word-property "predicate" word-property
[ \ dup , append, , [ drop f ] , \ ifte , ] make-list
traits 10 "priority" set-word-property
+traits [ 2drop t ] "class<" set-word-property
+
: init-traits-map ( word -- )
<namespace> "traits-map" set-word-property ;
union 30 "priority" set-word-property
+union [ 2drop t ] "class<" set-word-property
+
: union-predicate ( definition -- list )
[
[
: prettyprint-newline ( indent -- )
"\n" write indent ;
-: prettyprint-space ( -- )
- " " write ;
-
: prettyprint-element ( indent obj -- indent )
over prettyprint-limit get >= [
unparse write
] [
prettyprint*
- ] ifte prettyprint-space ;
+ ] ifte " " write ;
: <prettyprint ( indent -- indent )
tab-size +
"prettyprint-single-line" get [
- prettyprint-space
+ " " write
] [
dup prettyprint-newline
] ifte ;
] [
[
\ | prettyprint*
- prettyprint-space prettyprint-element
+ " " write prettyprint-element
] when*
] ifte
] when* ;
dup vector-length 0 = [
drop
\ { prettyprint*
- prettyprint-space
+ " " write
\ } prettyprint*
] [
swap prettyprint-{ swap prettyprint-vector prettyprint-}
hash>alist dup length 0 = [
drop
\ {{ prettyprint*
- prettyprint-space
+ " " write
\ }} prettyprint*
] [
swap prettyprint-{{ swap prettyprint-list prettyprint-}}
dup vocab-attrs write-attr ;
: prettyprint-IN: ( word -- )
- \ IN: prettyprint* prettyprint-space
- word-vocabulary prettyprint-vocab prettyprint-space ;
+ \ IN: prettyprint* " " write
+ word-vocabulary prettyprint-vocab " " write ;
: prettyprint-: ( indent -- indent )
- \ : prettyprint* prettyprint-space
+ \ : prettyprint* " " write
tab-size + ;
: prettyprint-; ( indent -- indent )
: prettyprint-prop ( word prop -- )
tuck word-name word-property [
- prettyprint-space prettyprint-1
+ " " write prettyprint-1
] [
drop
] ifte ;
stack-effect. dup prettyprint-newline
] keep documentation. ;
-GENERIC: see ( word -- )
+: prettyprint-M: ( indent -- indent )
+ \ M: prettyprint-1 " " write tab-size + ;
-M: object see ( obj -- )
- "Not a word: " write . ;
+GENERIC: see ( word -- )
M: compound see ( word -- )
- [ prettyprint-IN: ] keep
+ dup prettyprint-IN:
0 prettyprint-: swap
[ prettyprint-1 ] keep
[ prettyprint-docs ] keep
[ word-parameter prettyprint-list prettyprint-; ] keep
prettyprint-plist prettyprint-newline ;
+: see-method ( indent word class method -- indent )
+ >r >r >r prettyprint-M:
+ r> prettyprint-1 " " write
+ r> prettyprint-1 " " write
+ dup prettyprint-newline
+ r> prettyprint-list
+ prettyprint-;
+ terpri ;
+
+M: generic see ( word -- )
+ dup prettyprint-IN:
+ 0 swap
+ dup "definer" word-property prettyprint-1 " " write
+ dup prettyprint-1 terpri
+ dup methods [ over >r uncons see-method r> ] each 2drop ;
+
M: primitive see ( word -- )
dup prettyprint-IN:
"PRIMITIVE: " write dup prettyprint-1 stack-effect. terpri ;
M: symbol see ( word -- )
dup prettyprint-IN:
- 0 swap
- \ SYMBOL: prettyprint-1 prettyprint-space . ;
+ \ SYMBOL: prettyprint-1 " " write . ;
M: undefined see ( word -- )
dup prettyprint-IN:
- \ DEFER: prettyprint-1 prettyprint-space . ;
+ \ DEFER: prettyprint-1 " " write . ;
[ t ] [ del1 builtin-supertypes [ integer? ] all? ] unit-test
[ cons ] [ [ 1 2 ] class ] unit-test
+
+[ t ] [ \ generic \ compound class< ] unit-test
+[ f ] [ \ compound \ generic class< ] unit-test