about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-07-20 22:17:57 -0700
committerKartik Agaram <vc@akkartik.com>2020-07-20 22:17:57 -0700
commit3a5512389ed0f545fff82723f16bdea69f2e4b85 (patch)
treeb05c16c62d50a1f4c2379bddaa914ff3f7a1e547
parent97dbe33fd41ec089adbf10a8b1f90d4b86c2bacd (diff)
downloadmu-3a5512389ed0f545fff82723f16bdea69f2e4b85.tar.gz
6661
-rw-r--r--apps/mu.subx6
1 files changed, 3 insertions, 3 deletions
diff --git a/apps/mu.subx b/apps/mu.subx
index b8d3d579..4fce90c7 100644
--- a/apps/mu.subx
+++ b/apps/mu.subx
@@ -2562,11 +2562,11 @@ test-stmt-defines-output-in-same-register-as-inout:
     89/<- %edx 4/r32/esp
     (flush _test-output-buffered-file)
     (flush _test-error-buffered-file)
-#?     # dump _test-output-stream {{{
+#?     # dump _test-error-stream {{{
 #?     (write 2 "^")
-#?     (write-stream 2 _test-output-stream)
+#?     (write-stream 2 _test-error-stream)
 #?     (write 2 "$\n")
-#?     (rewind-stream _test-output-stream)
+#?     (rewind-stream _test-error-stream)
 #?     # }}}
     # no error; we looked up 'y' correctly before pushing the binding for 'x'
     (check-stream-equal _test-error-stream  ""  "F - test-stmt-defines-output-in-same-register-as-inout: error stream should be empty")
olor: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
def random generator:&:stream:num -> result:num, fail?:bool, generator:&:stream:num [
  local-scope
  load-ingredients
  {
    break-if generator
    # generator is 0? use real random-number generator
    result <- real-random
    return result, 0/false
  }
  result, fail?, generator <- read generator
]

# helper for tests
def assume-random-numbers -> result:&:stream:num [
  local-scope
  load-ingredients
  # compute result-len, space to allocate in result
  result-len:num <- copy 0
  {
    _, arg-received?:bool <- next-ingredient
    break-unless arg-received?
    result-len <- add result-len, 1
    loop
  }
  rewind-ingredients
  result-data:&:@:num <- new number:type, result-len
  idx:num <- copy 0
  {
    curr:num, arg-received?:bool <- next-ingredient
    break-unless arg-received?
    *result-data <- put-index *result-data, idx, curr
    idx <- add idx, 1
    loop
  }
  result <- new-stream result-data
]

scenario random-numbers-in-scenario [
  local-scope
  source:&:stream:num <- assume-random-numbers 34, 35, 37
  1:num/raw, 2:bool/raw <- random source
  3:num/raw, 4:bool/raw <- random source
  5:num/raw, 6:bool/raw <- random source
  7:num/raw, 8:bool/raw <- random source
  memory-should-contain [
    1 <- 34
    2 <- 0  # everything went well
    3 <- 35
    4 <- 0  # everything went well
    5 <- 37
    6 <- 0  # everything went well
    7 <- 0  # empty result
    8 <- 1  # end of stream
  ]
]

def random-in-range generator:&:stream:num, start:num, end:num -> result:num, fail?:bool, generator:&:stream:num [
  local-scope
  load-ingredients
  result, fail?, generator <- random generator
  return-if fail?
  delta:num <- subtract end, start
  _, result <- divide-with-remainder result, delta
  result <- add result, start
]

scenario random-in-range [
  local-scope
  source:&:stream:num <- assume-random-numbers 91
  1:num/raw <- random-in-range source, 40, 50
  memory-should-contain [
    1 <- 41
  ]
]