From 524bce2dd2b4bc331db03ed8495d021d977852d2 Mon Sep 17 00:00:00 2001
From: Doug Coleman <doug.coleman@gmail.com>
Date: Fri, 29 Aug 2008 10:14:16 -0500
Subject: [PATCH] Revert "make alarms use new accessors"

This reverts commit e91129ba102ac7fd953b25ce10949c778e2d2f50.
---
 basis/alarms/alarms.factor | 41 +++++++++++++++++++-------------------
 1 file changed, 20 insertions(+), 21 deletions(-)

diff --git a/basis/alarms/alarms.factor b/basis/alarms/alarms.factor
index cbbebde579..a72960f20f 100755
--- a/basis/alarms/alarms.factor
+++ b/basis/alarms/alarms.factor
@@ -1,15 +1,11 @@
 ! Copyright (C) 2005, 2008 Slava Pestov, Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays calendar combinators generic init
-kernel math namespaces sequences heaps boxes threads debugger
-quotations assocs math.order ;
+USING: arrays calendar combinators generic init kernel math
+namespaces sequences heaps boxes threads debugger quotations
+assocs math.order ;
 IN: alarms
 
-TUPLE: alarm
-    { quot callable initial: [ ] }
-    { time timestamp }
-    interval
-    { entry box } ;
+TUPLE: alarm quot time interval entry ;
 
 <PRIVATE
 
@@ -19,28 +15,31 @@ SYMBOL: alarm-thread
 : notify-alarm-thread ( -- )
     alarm-thread get-global interrupt ;
 
-ERROR: bad-alarm-frequency frequency ;
-: check-alarm ( frequency/f -- frequency/f )
-    dup [ duration? ] [ not ] bi or [ bad-alarm-frequency ] unless ;
+: check-alarm
+    dup duration? over not or [ "Not a duration" throw ] unless
+    over timestamp? [ "Not a timestamp" throw ] unless
+    pick callable? [ "Not a quotation" throw ] unless ; inline
 
 : <alarm> ( quot time frequency -- alarm )
     check-alarm <box> alarm boa ;
 
 : register-alarm ( alarm -- )
-    dup dup time>> alarms get-global heap-push*
-    swap entry>> >box
+    dup dup alarm-time alarms get-global heap-push*
+    swap alarm-entry >box
     notify-alarm-thread ;
 
 : alarm-expired? ( alarm now -- ? )
-    [ time>> ] dip before=? ;
+    >r alarm-time r> before=? ;
 
 : reschedule-alarm ( alarm -- )
-    dup [ swap interval>> time+ ] change-time register-alarm ;
+    dup alarm-time over alarm-interval time+
+    over set-alarm-time
+    register-alarm ;
 
 : call-alarm ( alarm -- )
-    [ entry>> box> drop ]
-    [ quot>> "Alarm execution" spawn drop ]
-    [ dup interval>> [ reschedule-alarm ] [ drop ] if ] tri ;
+    dup alarm-entry box> drop
+    dup alarm-quot "Alarm execution" spawn drop
+    dup alarm-interval [ reschedule-alarm ] [ drop ] if ;
 
 : (trigger-alarms) ( alarms now -- )
     over heap-empty? [
@@ -58,7 +57,7 @@ ERROR: bad-alarm-frequency frequency ;
 
 : next-alarm ( alarms -- timestamp/f )
     dup heap-empty?
-    [ drop f ] [ heap-peek drop time>> ] if ;
+    [ drop f ] [ heap-peek drop alarm-time ] if ;
 
 : alarm-thread-loop ( -- )
     alarms get-global
@@ -67,7 +66,7 @@ ERROR: bad-alarm-frequency frequency ;
 
 : cancel-alarms ( alarms -- )
     [
-        heap-pop-all [ nip entry>> box> drop ] assoc-each
+        heap-pop-all [ nip alarm-entry box> drop ] assoc-each
     ] when* ;
 
 : init-alarms ( -- )
@@ -89,4 +88,4 @@ PRIVATE>
     [ hence ] keep add-alarm ;
 
 : cancel-alarm ( alarm -- )
-    entry>> [ alarms get-global heap-delete ] if-box? ;
+    alarm-entry [ alarms get-global heap-delete ] if-box? ;