about summary refs log tree commit diff stats
path: root/071channel.mu
diff options
context:
space:
mode:
Diffstat (limited to '071channel.mu')
-rw-r--r--071channel.mu56
1 files changed, 21 insertions, 35 deletions
diff --git a/071channel.mu b/071channel.mu
index c8ca6cc9..d0dc3f88 100644
--- a/071channel.mu
+++ b/071channel.mu
@@ -32,10 +32,10 @@ container channel [
 ]
 
 # result:address:channel <- new-channel capacity:number
-recipe new-channel [
+recipe new-channel capacity:number -> result:address:channel [
   local-scope
-  # result = new channel
-  result:address:channel <- new channel:type
+  load-ingredients
+  result <- new channel:type
   # result.first-full = 0
   full:address:number <- get-address *result, first-full:offset
   *full <- copy 0
@@ -43,18 +43,14 @@ recipe new-channel [
   free:address:number <- get-address *result, first-free:offset
   *free <- copy 0
   # result.data = new location[ingredient+1]
-  capacity:number <- next-ingredient
   capacity <- add capacity, 1  # unused slot for 'full?' below
   dest:address:address:array:character <- get-address *result, data:offset
   *dest <- new character:type, capacity
-  reply result
 ]
 
-# chan <- write chan:address:channel, val:character
-recipe write [
+recipe write chan:address:channel, val:character -> chan:address:channel [
   local-scope
-  chan:address:channel <- next-ingredient
-  val:character <- next-ingredient
+  load-ingredients
   {
     # block if chan is full
     full:boolean <- channel-full? chan
@@ -76,13 +72,11 @@ recipe write [
     break-unless at-end?
     *free <- copy 0
   }
-  reply chan/same-as-ingredient:0
 ]
 
-# result:character, chan <- read chan:address:channel
-recipe read [
+recipe read chan:address:channel -> result:character, chan:address:channel [
   local-scope
-  chan:address:channel <- next-ingredient
+  load-ingredients
   {
     # block if chan is empty
     empty?:boolean <- channel-empty? chan
@@ -93,7 +87,7 @@ recipe read [
   # read result
   full:address:number <- get-address *chan, first-full:offset
   circular-buffer:address:array:character <- get *chan, data:offset
-  result:character <- index *circular-buffer, *full
+  result <- index *circular-buffer, *full
   # mark its slot as empty
   *full <- add *full, 1
   {
@@ -103,18 +97,16 @@ recipe read [
     break-unless at-end?
     *full <- copy 0
   }
-  reply result, chan/same-as-ingredient:0
 ]
 
-recipe clear-channel [
+recipe clear-channel chan:address:channel -> chan:address:channel [
   local-scope
-  chan:address:channel <- next-ingredient
+  load-ingredients
   {
     empty?:boolean <- channel-empty? chan
     break-if empty?
     _, chan <- read chan
   }
-  reply chan/same-as-ingredient:0
 ]
 
 scenario channel-initialization [
@@ -184,21 +176,20 @@ scenario channel-wrap [
 ## helpers
 
 # An empty channel has first-empty and first-full both at the same value.
-recipe channel-empty? [
+recipe channel-empty? chan:address:channel -> result:boolean [
   local-scope
-  chan:address:channel <- next-ingredient
+  load-ingredients
   # return chan.first-full == chan.first-free
   full:number <- get *chan, first-full:offset
   free:number <- get *chan, first-free:offset
-  result:boolean <- equal full, free
-  reply result
+  result <- equal full, free
 ]
 
 # A full channel has first-empty just before first-full, wasting one slot.
 # (Other alternatives: https://en.wikipedia.org/wiki/Circular_buffer#Full_.2F_Empty_Buffer_Distinction)
-recipe channel-full? [
+recipe channel-full? chan:address:channel -> result:boolean [
   local-scope
-  chan:address:channel <- next-ingredient
+  load-ingredients
   # tmp = chan.first-free + 1
   tmp:number <- get *chan, first-free:offset
   tmp <- add tmp, 1
@@ -211,17 +202,15 @@ recipe channel-full? [
   }
   # return chan.first-full == tmp
   full:number <- get *chan, first-full:offset
-  result:boolean <- equal full, tmp
-  reply result
+  result <- equal full, tmp
 ]
 
 # result:number <- channel-capacity chan:address:channel
-recipe channel-capacity [
+recipe channel-capacity chan:address:channel -> result:number [
   local-scope
-  chan:address:channel <- next-ingredient
+  load-ingredients
   q:address:array:character <- get *chan, data:offset
-  result:number <- length *q
-  reply result
+  result <- length *q
 ]
 
 scenario channel-new-empty-not-full [
@@ -277,11 +266,9 @@ scenario channel-read-not-full [
 ]
 
 # helper for channels of characters in particular
-# out <- buffer-lines in:address:channel, out:address:channel
-recipe buffer-lines [
+recipe buffer-lines in:address:channel, out:address:channel -> out:address:channel, in:address:channel [
   local-scope
-  in:address:channel <- next-ingredient
-  out:address:channel <- next-ingredient
+  load-ingredients
   # repeat forever
   {
     line:address:buffer <- new-buffer, 30
@@ -327,7 +314,6 @@ recipe buffer-lines [
     }
     loop
   }
-  reply out/same-as-ingredient:1
 ]
 
 scenario buffer-lines-blocks-until-newline [
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653