Browse Source

Move everything over to new bcom semantics: just bcom the handler only!

machines
Christopher Lemmer Webber 6 years ago
parent
commit
6c8a31ec2d
No known key found for this signature in database
GPG Key ID: 4BC025925FF8F4D3
  1. 26
      examples/cauldron.rkt
  2. 8
      goblins/actor-lib/env.rkt
  3. 6
      goblins/actor-lib/hash-st8.rkt
  4. 8
      goblins/actor-lib/ticker.rkt
  5. 10
      goblins/actor-lib/ticker2.rkt
  6. 25
      goblins/core.rkt
  7. 2
      goblins/vat.rkt
  8. 8
      misc/perf-tests.rkt

26
examples/cauldron.rkt

@ -116,7 +116,7 @@
(random -1 2))
(max -1 (min 1 (+ drift drift-it))))
(define raise-delay (random 10 30))
(define ((lp bcom x y time-till-raise drift))
(define ((lp x y time-till-raise drift))
(define time-to-live
(- bubble-lifetime y))
(define bubble-shape
@ -140,16 +140,16 @@
;; o/~ I tried so hard... and went so far... o/~
'die
;; Time to move and adjust
(bcom lp (max 0 ; drift, but stay within confines
(min (+ x drift)
(sub1 cauldron-width)))
new-y ; move up
raise-delay ; reset
(modify-drift drift)))]
(bcom (lp (max 0 ; drift, but stay within confines
(min (+ x drift)
(sub1 cauldron-width)))
new-y ; move up
raise-delay ; reset
(modify-drift drift))))]
;; stay the same..
[else
(bcom lp x y (sub1 time-till-raise) drift)]))
(lp bcom (random 2 (- cauldron-width 2))
(bcom (lp x y (sub1 time-till-raise) drift))]))
(lp (random 2 (- cauldron-width 2))
0 raise-delay 0))
(define (^cauldron bcom spawn-ticked display-cell env)
@ -159,7 +159,7 @@
(raart:blank cauldron-width bubble-max-height))
(define (new-bubble-cooldown)
(random 15 40))
(define ((^next bcom [bubble-cooldown (new-bubble-cooldown)]))
(define ((next [bubble-cooldown (new-bubble-cooldown)]))
(define bubble-time? (eqv? bubble-cooldown 0))
(when bubble-time?
(spawn-ticked ^bubble env bubble-display-key))
@ -183,10 +183,10 @@
(raart:fg 'yellow
cauldron-raart)))
($ display-cell do-display)
(bcom ^next (if bubble-time?
(bcom (next (if bubble-time?
(new-bubble-cooldown)
(sub1 bubble-cooldown))))
(^next bcom))
(sub1 bubble-cooldown)))))
(next))
(define (val->raart val)
(match val

8
goblins/actor-lib/env.rkt

@ -71,7 +71,7 @@
[(list 'write id)
id])]))
(define (^next-env bcom ht)
(define (next ht)
(methods
[(new-key [key-name 'some-key])
;; unique by eq?
@ -94,11 +94,11 @@
(define updated-ht
(hash-set ht id
(cons val (hash-ref ht id '()))))
(bcom ^next-env updated-ht)]
(bcom (next updated-ht))]
[(reset)
(bcom ^next-env #hasheq())]))
(bcom (next #hasheq()))]))
(^next-env bcom #hasheq()))
(next #hasheq()))
(define (spawn-env-pair)
(define this-env

6
goblins/actor-lib/hash-st8.rkt

@ -24,7 +24,7 @@
([kw kws]
[kw-arg kw-args])
(hash-set ht (string->symbol (keyword->string kw)) kw-arg)))
(define (^next bcom ht)
(define (next ht)
(make-keyword-procedure
(lambda (kws kw-args . args)
(match args
@ -56,9 +56,9 @@
key val)]
[_
(raise-invalid-st8-pairs kv-pairs)])))
(bcom ^next new-ht)]))))
(bcom (next new-ht))]))))
(^next bcom initial-ht))))
(next initial-ht))))
(define ^st8
(procedure-rename (make-^st8 #f)

8
goblins/actor-lib/ticker.rkt

@ -34,7 +34,7 @@
'()
updated-ticked))
;; update ourself
(bcom ^ticker next-tickers))))
(bcom (^ticker bcom next-tickers)))))
(list (spawn ^tick-register)
(spawn ^ticker '())))
@ -50,7 +50,7 @@
(actormap-spawn! am ^cell))
(define (^malaise-sufferer bcom name speaking-cell
[maximum-suffering 3])
(define ((loop bcom n))
(define ((loop n))
(if (> n maximum-suffering)
(begin
($ speaking-cell
@ -61,8 +61,8 @@
($ speaking-cell
(format "<~a> sigh number ~a"
name n))
(bcom loop (add1 n)))))
(loop bcom 1))
(bcom (loop (add1 n))))))
(loop 1))
(define joe
(actormap-spawn! am ^malaise-sufferer "joe"
joe-speaks-here))

10
goblins/actor-lib/ticker2.rkt

@ -25,7 +25,7 @@
(define (^ticky bcom dead?)
(methods
[(die)
(bcom ^ticky #t)]
(bcom (^ticky bcom #t))]
[(dead?)
dead?]
[to-tick to-tick]))
@ -71,7 +71,7 @@
;; ok it's dead now too
(cons this-ticked
(lp tick-rest)))))])])))
(bcom ^ticker next-tickers)))]
(bcom (^ticker bcom next-tickers))))]
;; Used for collision detection, etc.
[(foldr proc init)
(foldr (match-lambda*
@ -94,7 +94,7 @@
(actormap-spawn! am ^cell))
(define (^malaise-sufferer bcom ticky name speaking-cell
[maximum-suffering 3])
(define ((loop bcom n))
(define ((loop n))
(if (> n maximum-suffering)
(begin
($ speaking-cell
@ -105,8 +105,8 @@
($ speaking-cell
(format "<~a> sigh number ~a"
name n))
(bcom loop (add1 n)))))
(loop bcom 1))
(bcom (loop (add1 n))))))
(loop 1))
(define joe
(actormap-poke! am ticker 'to-tick
(lambda (ticky)

25
goblins/core.rkt

@ -200,9 +200,8 @@
(define become
(procedure-rename
(make-keyword-procedure
(lambda (kws kw-args constructor . args)
(make-seal
(keyword-apply constructor kws kw-args become args))))
(lambda (kws kw-args new-handler)
(make-seal new-handler)))
'become))
(define unseal-handler
(make-struct-field-accessor seal-ref 0))
@ -870,7 +869,7 @@
obj]
;; if it's a procedure, let's spawn it
[(? procedure?)
(define (^already-ran bcom)
(define already-ran
(make-keyword-procedure
(lambda _
(error "Already ran for automatically generated listener"))))
@ -878,7 +877,7 @@
(procedure-rename
(lambda (bcom)
(lambda args
(values (bcom ^already-ran)
(values (bcom already-ran)
(apply obj args))))
proc-name))]
;; If it's #f, leave it as #f
@ -1159,7 +1158,7 @@
(define am (make-whactormap))
(define ((counter bcom n))
(values (bcom counter (add1 n))
(values (bcom (counter bcom (add1 n)))
n))
;; can actors update themselves?
@ -1188,12 +1187,12 @@
(check-eqv? turned-val3 3)
(define ((^friend-spawner bcom) friend-name)
(define ((^a-friend bcom [called-times 0]))
(define new-called-times
(add1 called-times))
(values (bcom ^a-friend new-called-times)
(format "Hello! My name is ~a and I've been called ~a times!"
friend-name new-called-times)))
(define (^a-friend bcom)
(define ((next called-times))
(values (bcom (next (add1 called-times)))
(format "Hello! My name is ~a and I've been called ~a times!"
friend-name called-times)))
(next 1))
(spawn ^a-friend))
(define fr-spwn (actormap-spawn! am ^friend-spawner))
(define joe (actormap-poke! am fr-spwn 'joe))
@ -1265,7 +1264,7 @@
(case-lambda
[() val]
[(new-val)
(bcom ^cell new-val)]))
(bcom (^cell bcom new-val))]))
(define (spawn-cell [val #f])
(spawn ^cell val))

2
goblins/vat.rkt

@ -301,7 +301,7 @@
'hello)
(define ((^ctr bcom [n 0]))
(values (bcom ^ctr (add1 n))
(values (bcom (^ctr bcom (add1 n)))
n))
(define a-ctr
(a-vat 'spawn ^ctr))

8
misc/perf-tests.rkt

@ -49,11 +49,11 @@
(for ([i 1000000])
(call friend))))))
;;; 2019-10-29
;;; 2019-11-03
;; perf-tests.rkt> (bcom-a-lot)
;; cpu time: 1567 real time: 1566 gc time: 36
;; cpu time: 1473 real time: 1472 gc time: 49
;; perf-tests.rkt> (bcom-a-lot #:reckless? #t)
;; cpu time: 1352 real time: 1352 gc time: 29
;; cpu time: 1262 real time: 1262 gc time: 24
;; A bunch of actors updating themselves
(define (bcom-a-lot [actormap (make-whactormap)]
@ -61,7 +61,7 @@
#:iterations [iterations 1000]
#:reckless? [reckless? #f])
(define ((^incrementing-actor bcom [i 0]))
(values (bcom ^incrementing-actor (add1 i))
(values (bcom (^incrementing-actor bcom (add1 i)))
i))
(define i-as
(for/list ([i num-actors])

Loading…
Cancel
Save