point-x
] unit-test
+
+! Ensure we have a fresh word.
+DEFER: losing-eq FORGET: losing-eq
+[ t ] [ DEFER: losing-eq \ losing-eq TUPLE: losing-eq x y ; \ losing-eq eq? ]
+unit-test
USING: errors generic kernel lists math namespaces prettyprint
stdio unparser vectors words ;
+! Printing an overview of heap usage.
+
: kb. 1024 /i unparse write " KB" write ;
: (room.) ( free total -- )
"Data space: " write (room.)
"Code space: " write (room.) ;
-: heap-stat. ( type instances bytes -- )
- dup 0 = [
- 3drop
- ] [
- rot builtin-type word-name write ": " write
- unparse write " bytes, " write
- unparse write " instances" print
- ] ifte ;
-
-: heap-stats. ( -- )
- #! Print heap allocation breakdown.
- 0 heap-stats [ dupd uncons heap-stat. 1 + ] each drop ;
+! Some words for iterating through the heap.
: (each-object) ( quot -- )
next-object dup [
: instances ( class -- list )
#! Return a list of all instances of a built-in or tuple
- #! class.
+ #! class in the image.
[
[
dup class pick = [ , ] [ drop ] ifte
] each-object drop
] make-list ;
+
+: heap-stat. ( type instances bytes -- )
+ dup 0 = [
+ 3drop
+ ] [
+ rot builtin-type word-name write ": " write
+ unparse write " bytes, " write
+ unparse write " instances" print
+ ] ifte ;
+
+: heap-stats. ( -- )
+ #! Print heap allocation breakdown.
+ 0 heap-stats [ dupd uncons heap-stat. 1 + ] each drop ;
#! exposed facade issue.
tuck pick-up* dup t = [ drop ] [ nip ] ifte ;
-DEFER: world
-
! The hand is a special gadget that holds mouse position and
! mouse button click state. The hand's parent is the world, but
! it is special in that the world does not list it as part of
! - hand-gadget is the gadget under the mouse position
! - hand-clicked is the most recently clicked gadget
! - hand-focus is the gadget holding keyboard focus
-TUPLE: hand click-pos clicked buttons gadget focus delegate ;
+TUPLE: hand
+ world
+ click-pos clicked buttons
+ gadget focus delegate ;
C: hand ( world -- hand )
0 0 0 0 <rectangle> <gadget>
over set-hand-delegate
+ [ set-hand-world ] 2keep
[ set-gadget-parent ] 2keep
[ set-hand-gadget ] keep ;
: update-hand-gadget ( hand -- )
#! The hand gadget is the gadget under the hand right now.
- dup world get pick-up swap set-hand-gadget ;
+ dup dup hand-world pick-up swap set-hand-gadget ;
: fire-motion ( hand -- )
[ motion ] swap hand-gadget handle-gesture drop ;
void primitive_begin_scan(void)
{
+ primitive_gc();
heap_scan_ptr = active.base;
heap_scan_end = active.here;
heap_scan = true;