about summary refs log tree commit diff stats
path: root/999spaces.cc
blob: 5fe52b261b88234f78ff0cc21810884c1b3fce1b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//: Since different layers all carve out different parts of various namespaces
//: (recipes, memory, etc.) for their own use, there's no previous place where
//: we can lay out the big picture of what uses what. So we'll do that here
//: and just have to manually remember to update it when we move boundaries
//: around.
//:
//:: Memory
//:
//: Location 0 - unused (since it can help uncover bugs)
//: Locations 1-899 - reserved for tests
//: Locations 900-999 - reserved for predefined globals in mu scenarios, like keyboard, screen, etc.
:(before "End Setup")
assert(Max_variables_in_scenarios == 900);
//: Locations 1000 ('Reserved_for_tests') onward - available to the allocator in chunks of size Initial_memory_per_routine.
assert(Reserved_for_tests == 1000);

//:: Recipes
//:
//: 0 - unused (IDLE; do nothing)
//: 1-199 - primitives
assert(MAX_PRIMITIVE_RECIPES < 200);
//: 200-999 - defined in .mu files as sequences of primitives
assert(Next_recipe_ordinal == 1000);
//: 1000 onwards - reserved for tests, cleared between tests

//:: Depths for tracing
//:
//: 0 - unused
//: 1-100 - app-level trace statements in mu
//: 101-9998 - call-stack statements (mostly label run)
assert(Initial_callstack_depth == 101);
assert(Max_callstack_depth == 9998);
//: 9999 - intra-instruction lines (mostly label mem)
assert(Primitive_recipe_depth == 9999);
ss="w"> <- new {(stream _elem): type} *result <- put *result, index:offset, 0 *result <- put *result, data:offset, s ] def rewind in:&:stream:_elem -> in:&:stream:_elem [ local-scope load-inputs return-unless in *in <- put *in, index:offset, 0 ] def read in:&:stream:_elem -> result:_elem, empty?:bool, in:&:stream:_elem [ local-scope load-inputs assert in, [cannot read; stream has no data] empty? <- copy false idx:num <- get *in, index:offset s:&:@:_elem <- get *in, data:offset len:num <- length *s at-end?:bool <- greater-or-equal idx len { break-unless at-end? empty-result:&:_elem <- new _elem:type return *empty-result, true } result <- index *s, idx idx <- add idx, 1 *in <- put *in, index:offset, idx ] def peek in:&:stream:_elem -> result:_elem, empty?:bool [ local-scope load-inputs assert in, [cannot peek; stream has no data] empty?:bool <- copy false idx:num <- get *in, index:offset s:&:@:_elem <- get *in, data:offset len:num <- length *s at-end?:bool <- greater-or-equal idx len { break-unless at-end? empty-result:&:_elem <- new _elem:type return *empty-result, true } result <- index *s, idx ] def read-line in:&:stream:char -> result:text, in:&:stream:char [ local-scope load-inputs assert in, [cannot read-line; stream has no data] idx:num <- get *in, index:offset s:text <- get *in, data:offset next-idx:num <- find-next s, 10/newline, idx result <- copy-range s, idx, next-idx idx <- add next-idx, 1 # skip newline # write back *in <- put *in, index:offset, idx ] def end-of-stream? in:&:stream:_elem -> result:bool [ local-scope load-inputs assert in, [cannot check end-of-stream?; stream has no data] idx:num <- get *in, index:offset s:&:@:_elem <- get *in, data:offset len:num <- length *s result <- greater-or-equal idx, len ]