diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-04-24 11:54:30 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-04-24 11:54:30 -0700 |
commit | b0bf5321de2ba32f3b92c2faf6b7b68a06b6b432 (patch) | |
tree | 9e0473bddd0d9a2d4aec7ac58dec8d85c2833a5d | |
parent | 15936c91a9f8023dc868a021029f84b45aa50176 (diff) | |
download | mu-b0bf5321de2ba32f3b92c2faf6b7b68a06b6b432.tar.gz |
2864 - replace all address:shared with just address
Now that we no longer have non-shared addresses, we can just always track refcounts for all addresses. Phew!
64 files changed, 4413 insertions, 4392 deletions
diff --git a/020run.cc b/020run.cc index fbe53f15..7764adc9 100644 --- a/020run.cc +++ b/020run.cc @@ -34,7 +34,7 @@ def main [ :(before "End Types") // Book-keeping while running a recipe. -//: Later layers will replace this. +//: Later layers will replace this to support running multiple routines at once. struct routine { recipe_ordinal running_recipe; int running_step_index; diff --git a/027call_ingredient.cc b/027call_ingredient.cc index f109076b..21f9f7ff 100644 --- a/027call_ingredient.cc +++ b/027call_ingredient.cc @@ -176,10 +176,8 @@ bool is_mu_string(const reagent& x) { return x.type && x.type->value == get(Type_ordinal, "address") && x.type->right - && x.type->right->value == get(Type_ordinal, "shared") + && x.type->right->value == get(Type_ordinal, "array") && x.type->right->right - && x.type->right->right->value == get(Type_ordinal, "array") - && x.type->right->right->right - && x.type->right->right->right->value == get(Type_ordinal, "character") - && x.type->right->right->right->right == NULL; + && x.type->right->right->value == get(Type_ordinal, "character") + && x.type->right->right->right == NULL; } diff --git a/031array.cc b/031array.cc index ac1cc848..c2cbfd7f 100644 --- a/031array.cc +++ b/031array.cc @@ -54,7 +54,7 @@ case CREATE_ARRAY: { trace(9999, "mem") << "storing " << array_length << " in location " << base_address << end(); put(Memory, base_address, array_length); // in array elements int size = size_of(product); // in locations - trace(9998, "run") << "creating array of size " << size << '\n' << end(); + trace(9998, "run") << "creating array of size " << size << end(); // initialize array for (int i = 1; i <= size_of(product); ++i) { put(Memory, base_address+i, 0); diff --git a/033address.cc b/033address.cc index 1b956fe0..29beec1e 100644 --- a/033address.cc +++ b/033address.cc @@ -1,14 +1,400 @@ -//: Instructions can read from addresses pointing at other locations using the -//: 'lookup' property. +//: Addresses help us spend less time copying data around. + +//: So far we've been operating on primitives like numbers and characters, and +//: we've started combining these primitives together into larger logical +//: units (containers or arrays) that may contain many different primitives at +//: once. Containers and arrays can grow quite large in complex programs, and +//: we'd like some way to efficiently share them between recipes without +//: constantly having to make copies. Right now 'next-ingredient' and 'reply' +//: copy data across recipe boundaries. To avoid copying large quantities of +//: data around, we'll use *addresses*. An address is a bookmark to some +//: arbitrary quantity of data (the *payload*). It's a primitive, so it's as +//: efficient to copy as a number. To read or modify the payload 'pointed to' +//: by an address, we'll perform a *lookup*. +//: +//: The notion of 'lookup' isn't an instruction like 'add' or 'subtract'. +//: Instead it's an operation that can be performed when reading any of the +//: ingredients of an instruction, and when writing to any of the products. +//: Modern computers provide efficient support for addresses and lookups, +//: making this a realistic feature. +//: +//: To recap: an address is a bookmark to some potentially large payload, and +//: you can replace any ingredient or product with a lookup to an address of +//: the appropriate type. But how do we get addresses to begin with? That +//: requires a little more explanation. Once we introduce the notion of +//: bookmarks to data, we have to think about the life cycle of a piece of +//: data and its bookmark. Otherwise several bad outcomes can result (and +//: indeed *have* resulted in past languages like C): +//: +//: a) You can run out of memory if you don't have a way to reclaim +//: data. +//: b) If you allow data to be reclaimed, you have to be careful not to +//: leave any stale addresses pointing at it. Otherwise your program might +//: try to lookup such an address and find something unexpected. Such +//: problems can be very hard to track down, and they can also be exploited +//: to break into your computer over the network, etc. +//: +//: To avoid these problems, we introduce a *reference count* or refcount. The +//: life cycle of a bit of data accessed through addresses looks like this. +//: +//: We create space in computer memory for it using the 'new' instruction. +//: The 'new' instruction takes a type as an ingredient, allocates +//: sufficient space to hold that type, and returns an address (bookmark) +//: to the allocated space. +//: +//: x:address:number <- new number:type +//: +//: +------------+ +//: x -------> | number | +//: +------------+ +//: +//: That isn't entirely accurate. Under the hood, 'new' allocates an extra +//: number -- the refcount: +//: +//: +------------+------------+ +//: x -------> | refcount | number | +//: +------------+------------+ +//: +//: This probably seems like a waste of space. In practice it isn't worth +//: allocating individual numbers and our payload will tend to be larger, +//: so the picture would look more like this (zooming out a bit): +//: +//: +-------------------------+ +//: +---+ | +//: x -------> | r | | +//: +---+ DATA | +//: | | +//: | | +//: +-------------------------+ +//: +//: (Here 'r' denotes the refcount. It occupies a tiny amount of space +//: compared to the payload.) +//: +//: Anyways, back to our example where the data is just a single number. +//: After the call to 'new', Mu's map of memory looks like this: +//: +//: +---+------------+ +//: x -------> | 1 | number | +//: +---+------------+ +//: +//: The refcount of 1 here indicates that this number has one bookmark +//: outstanding. If you then make a copy of x, the refcount increments: +//: +//: y:address:number <- copy x +//: +//: x ---+ +---+------------+ +//: +---> | 2 | number | +//: y ---+ +---+------------+ +//: +//: Whether you access the payload through x or y, Mu knows how many +//: bookmarks are outstanding to it. When you change x or y, the refcount +//: transparently decrements: +//: +//: x <- copy 0 # an address is just a number, you can always write 0 to it +//: +//: +---+------------+ +//: y -------> | 1 | number | +//: +---+------------+ +//: +//: The final flourish is what happens when the refcount goes down to 0: Mu +//: reclaims the space occupied by both refcount and payload in memory, and +//: they're ready to be reused by later calls to 'new'. +//: +//: y <- copy 0 +//: +//: +---+------------+ +//: | 0 | XXXXXXX | +//: +---+------------+ +//: +//: Using refcounts fixes both our problems a) and b) above: you can use +//: memory for many different purposes as many times as you want without +//: running out of memory, and you don't have to worry about ever leaving a +//: dangling bookmark when you reclaim memory. +//: +//: Ok, let's rewind the clock back to this situation where we have an +//: address: +//: +//: +---+------------+ +//: x -------> | 1 | number | +//: +---+------------+ +//: +//: Once you have an address you can read or modify its payload by performing +//: a lookup: +//: +//: x/lookup <- copy 34 +//: +//: or more concisely: +//: +//: *x <- copy 34 +//: +//: This modifies not x, but the payload x points to: +//: +//: +---+------------+ +//: x -------> | 1 | 34 | +//: +---+------------+ +//: +//: You can also read from the payload in instructions like this: +//: +//: z:number <- add *x, 1 +//: +//: After this instruction runs the value of z will be 35. +//: +//: The rest of this (long) layer is divided up into 4 sections: +//: the implementation of the 'new' instruction +//: how instructions lookup addresses +//: how instructions update refcounts when modifying address variables +//: how instructions abandon and reclaim memory when refcounts drop to 0 + +//:: the 'new' instruction allocates unique memory including a refcount +//: todo: give 'new' a custodian ingredient. Following malloc/free is a temporary hack. + +:(scenario new) +# call 'new' two times with identical types without modifying the results; you +# should get back different results +def main [ + 1:address:number/raw <- new number:type + 2:address:number/raw <- new number:type + 3:boolean/raw <- equal 1:address:number/raw, 2:address:number/raw +] ++mem: storing 0 in location 3 + +//: 'new' takes a weird 'type' as its first ingredient; don't error on it +:(before "End Mu Types Initialization") +put(Type_ordinal, "type", 0); +:(code) +bool is_mu_type_literal(reagent r) { + return is_literal(r) && r.type && r.type->name == "type"; +} + +:(before "End Primitive Recipe Declarations") +NEW, +:(before "End Primitive Recipe Numbers") +put(Recipe_ordinal, "new", NEW); +:(before "End Primitive Recipe Checks") +case NEW: { + const recipe& caller = get(Recipe, r); + if (inst.ingredients.empty() || SIZE(inst.ingredients) > 2) { + raise << maybe(caller.name) << "'new' requires one or two ingredients, but got " << to_original_string(inst) << '\n' << end(); + break; + } + // End NEW Check Special-cases + reagent type = inst.ingredients.at(0); + if (!is_mu_type_literal(type)) { + raise << maybe(caller.name) << "first ingredient of 'new' should be a type, but got " << type.original_string << '\n' << end(); + break; + } + if (inst.products.empty()) { + raise << maybe(caller.name) << "result of 'new' should never be ignored\n" << end(); + break; + } + if (!product_of_new_is_valid(inst)) { + raise << maybe(caller.name) << "product of 'new' has incorrect type: " << to_original_string(inst) << '\n' << end(); + break; + } + break; +} +:(code) +bool product_of_new_is_valid(const instruction& inst) { + reagent product = inst.products.at(0); + canonize_type(product); + if (!product.type || product.type->value != get(Type_ordinal, "address")) + return false; + drop_from_type(product, "address"); + if (SIZE(inst.ingredients) > 1) { + // array allocation + if (!product.type || product.type->value != get(Type_ordinal, "array")) return false; + drop_from_type(product, "array"); + } + reagent expected_product("x:"+inst.ingredients.at(0).name); + // End Post-processing(expected_product) When Checking 'new' + return types_strictly_match(product, expected_product); +} + +//: To implement 'new', a Mu transform turns all 'new' instructions into +//: 'allocate' instructions that precompute the amount of memory they want to +//: allocate. + +//: Ensure that we never call 'allocate' directly, and that there's no 'new' +//: instructions left after the transforms have run. +:(before "End Primitive Recipe Checks") +case ALLOCATE: { + raise << "never call 'allocate' directly'; always use 'new'\n" << end(); + break; +} +:(before "End Primitive Recipe Implementations") +case NEW: { + raise << "no implementation for 'new'; why wasn't it translated to 'allocate'? Please save a copy of your program and send it to Kartik.\n" << end(); + break; +} + +:(after "Transform.push_back(check_instruction)") // check_instruction will guard against direct 'allocate' instructions below +Transform.push_back(transform_new_to_allocate); // idempotent + +:(code) +void transform_new_to_allocate(const recipe_ordinal r) { + trace(9991, "transform") << "--- convert 'new' to 'allocate' for recipe " << get(Recipe, r).name << end(); + for (int i = 0; i < SIZE(get(Recipe, r).steps); ++i) { + instruction& inst = get(Recipe, r).steps.at(i); + // Convert 'new' To 'allocate' + if (inst.name == "new") { + inst.operation = ALLOCATE; + string_tree* type_name = new string_tree(inst.ingredients.at(0).name); + // End Post-processing(type_name) When Converting 'new' + type_tree* type = new_type_tree(type_name); + inst.ingredients.at(0).set_value(size_of(type)); + trace(9992, "new") << "size of " << to_string(type_name) << " is " << inst.ingredients.at(0).value << end(); + delete type; + delete type_name; + } + } +} + +//: implement 'allocate' based on size + +:(before "End Globals") +const int Reserved_for_tests = 1000; +int Memory_allocated_until = Reserved_for_tests; +int Initial_memory_per_routine = 100000; +:(before "End Setup") +Memory_allocated_until = Reserved_for_tests; +Initial_memory_per_routine = 100000; +:(before "End routine Fields") +int alloc, alloc_max; +:(before "End routine Constructor") +alloc = Memory_allocated_until; +Memory_allocated_until += Initial_memory_per_routine; +alloc_max = Memory_allocated_until; +trace(9999, "new") << "routine allocated memory from " << alloc << " to " << alloc_max << end(); + +:(before "End Primitive Recipe Declarations") +ALLOCATE, +:(before "End Primitive Recipe Numbers") +put(Recipe_ordinal, "allocate", ALLOCATE); +:(before "End Primitive Recipe Implementations") +case ALLOCATE: { + // compute the space we need + int size = ingredients.at(0).at(0); + if (SIZE(ingredients) > 1) { + // array allocation + trace(9999, "mem") << "array size is " << ingredients.at(1).at(0) << end(); + size = /*space for length*/1 + size*ingredients.at(1).at(0); + } + // include space for refcount + size++; + trace(9999, "mem") << "allocating size " << size << end(); +//? Total_alloc += size; +//? Num_alloc++; + // compute the region of memory to return + // really crappy at the moment + ensure_space(size); + const int result = Current_routine->alloc; + trace(9999, "mem") << "new alloc: " << result << end(); + // save result + products.resize(1); + products.at(0).push_back(result); + // initialize allocated space + for (int address = result; address < result+size; ++address) + put(Memory, address, 0); + if (SIZE(current_instruction().ingredients) > 1) { + // initialize array length + trace(9999, "mem") << "storing " << ingredients.at(1).at(0) << " in location " << result+/*skip refcount*/1 << end(); + put(Memory, result+/*skip refcount*/1, ingredients.at(1).at(0)); + } + Current_routine->alloc += size; + // no support yet for reclaiming memory between routines + assert(Current_routine->alloc <= Current_routine->alloc_max); + break; +} + +//: statistics for debugging +//? :(before "End Globals") +//? int Total_alloc = 0; +//? int Num_alloc = 0; +//? int Total_free = 0; +//? int Num_free = 0; +//? :(before "End Setup") +//? Total_alloc = Num_alloc = Total_free = Num_free = 0; +//? :(before "End Teardown") +//? cerr << Total_alloc << "/" << Num_alloc +//? << " vs " << Total_free << "/" << Num_free << '\n'; +//? cerr << SIZE(Memory) << '\n'; + +:(code) +void ensure_space(int size) { + if (size > Initial_memory_per_routine) { + tb_shutdown(); + cerr << "can't allocate " << size << " locations, that's too much compared to " << Initial_memory_per_routine << ".\n"; + exit(0); + } + if (Current_routine->alloc + size > Current_routine->alloc_max) { + // waste the remaining space and create a new chunk + Current_routine->alloc = Memory_allocated_until; + Memory_allocated_until += Initial_memory_per_routine; + Current_routine->alloc_max = Memory_allocated_until; + trace(9999, "new") << "routine allocated memory from " << Current_routine->alloc << " to " << Current_routine->alloc_max << end(); + } +} + +:(scenario new_initializes) +% Memory_allocated_until = 10; +% put(Memory, Memory_allocated_until, 1); +def main [ + 1:address:number <- new number:type + 2:number <- copy 1:address:number/lookup +] ++mem: storing 0 in location 2 + +:(scenario new_error) +% Hide_errors = true; +def main [ + 1:number/raw <- new number:type +] ++error: main: product of 'new' has incorrect type: 1:number/raw <- new number:type + +:(scenario new_array) +def main [ + 1:address:array:number/raw <- new number:type, 5 + 2:address:number/raw <- new number:type + 3:number/raw <- subtract 2:address:number/raw, 1:address:array:number/raw +] ++run: {1: ("address" "array" "number"), "raw": ()} <- new {number: "type"}, {5: "literal"} ++mem: array size is 5 +# don't forget the extra location for array size, and the second extra location for the refcount ++mem: storing 7 in location 3 + +:(scenario new_empty_array) +def main [ + 1:address:array:number/raw <- new number:type, 0 + 2:address:number/raw <- new number:type + 3:number/raw <- subtract 2:address:number/raw, 1:address:array:number/raw +] ++run: {1: ("address" "array" "number"), "raw": ()} <- new {number: "type"}, {0: "literal"} ++mem: array size is 0 +# one location for array size, and one for the refcount ++mem: storing 2 in location 3 + +//: If a routine runs out of its initial allocation, it should allocate more. +:(scenario new_overflow) +% Initial_memory_per_routine = 3; // barely enough room for point allocation below +def main [ + 1:address:number/raw <- new number:type + 2:address:point/raw <- new point:type # not enough room in initial page +] ++new: routine allocated memory from 1000 to 1003 ++new: routine allocated memory from 1003 to 1006 + +//:: /lookup can go from an address to the payload it points at, skipping the refcount +//: the tests in this section use unsafe operations so as to stay decoupled from 'new' :(scenario copy_indirect) def main [ - 1:address:number <- copy 2/unsafe - 2:number <- copy 34 + 1:address:number <- copy 10/unsafe + 11:number <- copy 34 # This loads location 1 as an address and looks up *that* location. - 3:number <- copy 1:address:number/lookup + 2:number <- copy 1:address:number/lookup ] -+mem: storing 34 in location 3 +# 1 contains 10. Skip refcount and lookup location 11. ++mem: storing 34 in location 2 :(before "End Preprocess read_memory(x)") canonize(x); @@ -17,10 +403,10 @@ canonize(x); //: 'lookup' property :(scenario store_indirect) def main [ - 1:address:number <- copy 2/unsafe + 1:address:number <- copy 10/unsafe 1:address:number/lookup <- copy 34 ] -+mem: storing 34 in location 2 ++mem: storing 34 in location 11 :(before "End Preprocess write_memory(x)") canonize(x); @@ -60,10 +446,31 @@ void lookup_memory(reagent& x) { trace(9999, "mem") << "location " << x.value << " is " << no_scientific(get_or_insert(Memory, x.value)) << end(); x.set_value(get_or_insert(Memory, x.value)); drop_from_type(x, "address"); - // End Drop Address In lookup_memory(x) + if (x.value != 0) { + trace(9999, "mem") << "skipping refcount at " << x.value << end(); + x.set_value(x.value+1); // skip refcount + } drop_one_lookup(x); } +void test_lookup_address_skips_refcount() { + reagent x("*x:address:number"); + x.set_value(34); // unsafe + put(Memory, 34, 1000); + lookup_memory(x); + CHECK_TRACE_CONTENTS("mem: skipping refcount at 1000"); + CHECK_EQ(x.value, 1001); +} + +void test_lookup_zero_address_does_not_skip_refcount() { + reagent x("*x:address:number"); + x.set_value(34); // unsafe + put(Memory, 34, 0); + lookup_memory(x); + CHECK_TRACE_DOESNT_CONTAIN("mem: skipping refcount at 0"); + CHECK_EQ(x.value, 0); +} + :(after "bool types_strictly_match(reagent to, reagent from)") if (!canonize_type(to)) return false; if (!canonize_type(from)) return false; @@ -98,7 +505,6 @@ bool canonize_type(reagent& r) { return false; } drop_from_type(r, "address"); - // End Drop Address In canonize_type(r) drop_one_lookup(r); } return true; @@ -125,34 +531,40 @@ void drop_one_lookup(reagent& r) { assert(false); } -//:: 'get' can read from container address +//: Tedious fixup to support addresses in container/array instructions of previous layers. +//: Most instructions don't require fixup if they use the 'ingredients' and +//: 'products' variables in run_current_routine(). + :(scenario get_indirect) def main [ - 1:number <- copy 2 - 2:number <- copy 34 - 3:number <- copy 35 - 4:number <- get 1:address:point/lookup, 0:offset + 1:address:point <- copy 10/unsafe + # 10 reserved for refcount + 11:number <- copy 34 + 12:number <- copy 35 + 2:number <- get 1:address:point/lookup, 0:offset ] -+mem: storing 34 in location 4 ++mem: storing 34 in location 2 :(scenario get_indirect2) def main [ - 1:number <- copy 2 - 2:number <- copy 34 - 3:number <- copy 35 - 4:address:number <- copy 5/unsafe - *4:address:number <- get 1:address:point/lookup, 0:offset + 1:address:point <- copy 10/unsafe + # 10 reserved for refcount + 11:number <- copy 34 + 12:number <- copy 35 + 2:address:number <- copy 20/unsafe + 2:address:number/lookup <- get 1:address:point/lookup, 0:offset ] -+mem: storing 34 in location 5 ++mem: storing 34 in location 21 :(scenario include_nonlookup_properties) def main [ - 1:number <- copy 2 - 2:number <- copy 34 - 3:number <- copy 35 - 4:number <- get 1:address:point/lookup/foo, 0:offset + 1:address:point <- copy 10/unsafe + # 10 reserved for refcount + 11:number <- copy 34 + 12:number <- copy 35 + 2:number <- get 1:address:point/lookup/foo, 0:offset ] -+mem: storing 34 in location 4 ++mem: storing 34 in location 2 :(after "Update GET base in Check") if (!canonize_type(base)) break; @@ -162,14 +574,14 @@ if (!canonize_type(product)) break; canonize(base); :(scenario put_indirect) -# 'put' can read from container address def main [ - 1:number <- copy 2 - 2:number <- copy 34 - 3:number <- copy 35 + 1:address:point <- copy 10/unsafe + # 10 reserved for refcount + 11:number <- copy 34 + 12:number <- copy 35 1:address:point/lookup <- put 1:address:point/lookup, 0:offset, 36 ] -+mem: storing 36 in location 2 ++mem: storing 36 in location 11 :(after "Update PUT base in Check") if (!canonize_type(base)) break; @@ -180,17 +592,18 @@ canonize(base); :(scenario copy_array_indirect) def main [ - 1:array:number:3 <- create-array - 2:number <- copy 14 - 3:number <- copy 15 - 4:number <- copy 16 - 5:address:array:number <- copy 1/unsafe - 6:array:number <- copy *5:address:array:number + # 10 reserved for refcount + 11:array:number:3 <- create-array + 12:number <- copy 14 + 13:number <- copy 15 + 14:number <- copy 16 + 1:address:array:number <- copy 10/unsafe + 2:array:number <- copy 1:address:array:number/lookup ] -+mem: storing 3 in location 6 -+mem: storing 14 in location 7 -+mem: storing 15 in location 8 -+mem: storing 16 in location 9 ++mem: storing 3 in location 2 ++mem: storing 14 in location 3 ++mem: storing 15 in location 4 ++mem: storing 16 in location 5 :(before "Update CREATE_ARRAY product in Check") // 'create-array' does not support indirection. Static arrays are meant to be @@ -203,14 +616,15 @@ assert(!has_property(product, "lookup")); :(scenario index_indirect) def main [ - 1:array:number:3 <- create-array - 2:number <- copy 14 - 3:number <- copy 15 - 4:number <- copy 16 - 5:address:array:number <- copy 1/unsafe - 6:number <- index 5:address:array:number/lookup, 1 + # 10 reserved for refcount + 11:array:number:3 <- create-array + 12:number <- copy 14 + 13:number <- copy 15 + 14:number <- copy 16 + 1:address:array:number <- copy 10/unsafe + 2:number <- index 1:address:array:number/lookup, 1 ] -+mem: storing 15 in location 6 ++mem: storing 15 in location 2 :(before "Update INDEX base in Check") if (!canonize_type(base)) break; @@ -226,14 +640,15 @@ canonize(index); :(scenario put_index_indirect) def main [ - 1:array:number:3 <- create-array - 2:number <- copy 14 - 3:number <- copy 15 - 4:number <- copy 16 - 5:address:array:number <- copy 1/unsafe - 5:address:array:number/lookup <- put-index 5:address:array:number/lookup, 1, 34 + # 10 reserved for refcount + 11:array:number:3 <- create-array + 12:number <- copy 14 + 13:number <- copy 15 + 14:number <- copy 16 + 1:address:array:number <- copy 10/unsafe + 1:address:array:number/lookup <- put-index 1:address:array:number/lookup, 1, 34 ] -+mem: storing 34 in location 3 ++mem: storing 34 in location 13 :(scenario put_index_indirect_2) def main [ @@ -241,8 +656,9 @@ def main [ 2:number <- copy 14 3:number <- copy 15 4:number <- copy 16 - 5:address:number <- copy 6/unsafe - 6:number <- copy 1 + 5:address:number <- copy 10/unsafe + # 10 reserved for refcount + 11:number <- copy 1 5:address:array:number/lookup <- put-index 1:array:number:3, 5:address:number/lookup, 34 ] +mem: storing 34 in location 3 @@ -261,14 +677,15 @@ canonize(index); :(scenario length_indirect) def main [ - 1:array:number:3 <- create-array - 2:number <- copy 14 - 3:number <- copy 15 - 4:number <- copy 16 - 5:address:array:number <- copy 1/unsafe - 6:number <- length 5:address:array:number/lookup + # 10 reserved for refcount + 11:array:number:3 <- create-array + 12:number <- copy 14 + 13:number <- copy 15 + 14:number <- copy 16 + 1:address:array:number <- copy 10/unsafe + 2:number <- length 1:address:array:number/lookup ] -+mem: storing 3 in location 6 ++mem: storing 3 in location 2 :(before "Update LENGTH array in Check") if (!canonize_type(array)) break; @@ -277,32 +694,35 @@ canonize(array); :(scenario maybe_convert_indirect) def main [ - 1:number-or-point <- merge 0/number, 34 - 10:address:number-or-point <- copy 1/unsafe - 11:number, 12:boolean <- maybe-convert 10:address:number-or-point/lookup, i:variant + # 10 reserved for refcount + 11:number-or-point <- merge 0/number, 34 + 1:address:number-or-point <- copy 10/unsafe + 2:number, 3:boolean <- maybe-convert 1:address:number-or-point/lookup, i:variant ] -+mem: storing 34 in location 11 -+mem: storing 1 in location 12 ++mem: storing 34 in location 2 ++mem: storing 1 in location 3 :(scenario maybe_convert_indirect_2) def main [ - 1:number-or-point <- merge 0/number, 34 - 10:address:number-or-point <- copy 1/unsafe - 11:address:number <- copy 20/unsafe - 11:address:number/lookup, 12:boolean <- maybe-convert 10:address:number-or-point/lookup, i:variant + # 10 reserved for refcount + 11:number-or-point <- merge 0/number, 34 + 1:address:number-or-point <- copy 10/unsafe + 2:address:number <- copy 20/unsafe + 2:address:number/lookup, 3:boolean <- maybe-convert 1:address:number-or-point/lookup, i:variant ] -+mem: storing 34 in location 20 -+mem: storing 1 in location 12 ++mem: storing 34 in location 21 ++mem: storing 1 in location 3 :(scenario maybe_convert_indirect_3) def main [ - 1:number-or-point <- merge 0/number, 34 - 10:address:number-or-point <- copy 1/unsafe - 12:address:boolean <- copy 20/unsafe - 11:number, 12:address:boolean/lookup <- maybe-convert 10:address:number-or-point/lookup, i:variant + # 10 reserved for refcount + 11:number-or-point <- merge 0/number, 34 + 1:address:number-or-point <- copy 10/unsafe + 2:address:boolean <- copy 20/unsafe + 3:number, 2:address:boolean/lookup <- maybe-convert 1:address:number-or-point/lookup, i:variant ] -+mem: storing 34 in location 11 -+mem: storing 1 in location 20 ++mem: storing 34 in location 3 ++mem: storing 1 in location 21 :(before "Update MAYBE_CONVERT base in Check") if (!canonize_type(base)) break; @@ -323,18 +743,20 @@ def main [ 1:address:number-or-point <- copy 10/unsafe 1:address:number-or-point/lookup <- merge 0/number, 34 ] -+mem: storing 0 in location 10 -+mem: storing 34 in location 11 +# skip 10 for refcount ++mem: storing 0 in location 11 ++mem: storing 34 in location 12 :(before "Update size_mismatch Check for MERGE(x) canonize(x); -//:: abbreviation for '/lookup': a prefix '*' +//: abbreviation for '/lookup': a prefix '*' :(scenario lookup_abbreviation) def main [ - 1:address:number <- copy 2/unsafe - 2:number <- copy 34 + 1:address:number <- copy 10/unsafe + # 10 reserved for refcount + 11:number <- copy 34 3:number <- copy *1:address:number ] +parse: ingredient: {1: ("address" "number"), "lookup": ()} @@ -350,6 +772,220 @@ def main [ raise << "illegal name " << original_string << '\n' << end(); } +//:: update refcounts when copying addresses + +:(scenario refcounts) +def main [ + 1:address:number <- copy 1000/unsafe + 2:address:number <- copy 1:address:number + 1:address:number <- copy 0 + 2:address:number <- copy 0 +] ++run: {1: ("address" "number")} <- copy {1000: "literal", "unsafe": ()} ++mem: incrementing refcount of 1000: 0 -> 1 ++run: {2: ("address" "number")} <- copy {1: ("address" "number")} ++mem: incrementing refcount of 1000: 1 -> 2 ++run: {1: ("address" "number")} <- copy {0: "literal"} ++mem: decrementing refcount of 1000: 2 -> 1 ++run: {2: ("address" "number")} <- copy {0: "literal"} ++mem: decrementing refcount of 1000: 1 -> 0 +# the /unsafe corrupts memory but fortunately we won't be running any more 'new' in this scenario ++mem: automatically abandoning 1000 + +:(before "End write_memory(reagent x) Special-cases") +if (x.type->value == get(Type_ordinal, "address")) { + // compute old address of x, as well as new address we want to write in + int old_address = get_or_insert(Memory, x.value); + assert(scalar(data)); + int new_address = data.at(0); + // decrement refcount of old address + if (old_address) { + int old_refcount = get_or_insert(Memory, old_address); + trace(9999, "mem") << "decrementing refcount of " << old_address << ": " << old_refcount << " -> " << (old_refcount-1) << end(); + put(Memory, old_address, old_refcount-1); + } + // perform the write + trace(9999, "mem") << "storing " << no_scientific(data.at(0)) << " in location " << x.value << end(); + put(Memory, x.value, new_address); + // increment refcount of new address + if (new_address) { + int new_refcount = get_or_insert(Memory, new_address); + assert(new_refcount >= 0); // == 0 only when new_address == old_address + trace(9999, "mem") << "incrementing refcount of " << new_address << ": " << new_refcount << " -> " << (new_refcount+1) << end(); + put(Memory, new_address, new_refcount+1); + } + // abandon old address if necessary + // do this after all refcount updates are done just in case old and new are identical + assert(old_address >= 0); + if (old_address == 0) return; + if (get_or_insert(Memory, old_address) < 0) { + DUMP(""); + cerr << old_address << ' ' << get_or_insert(Memory, old_address) << '\n'; + } + assert(get_or_insert(Memory, old_address) >= 0); + if (get_or_insert(Memory, old_address) > 0) return; + // lookup_memory without drop_one_lookup { + trace(9999, "mem") << "automatically abandoning " << old_address << end(); + trace(9999, "mem") << "computing size to abandon at " << x.value << end(); + x.set_value(old_address+/*skip refcount*/1); + drop_from_type(x, "address"); + // } + abandon(old_address, size_of(x)+/*refcount*/1); + return; +} + +:(scenario refcounts_2) +def main [ + 1:address:number <- new number:type + # over-writing one allocation with another + 1:address:number <- new number:type + 1:address:number <- copy 0 +] ++run: {1: ("address" "number")} <- new {number: "type"} ++mem: incrementing refcount of 1000: 0 -> 1 ++run: {1: ("address" "number")} <- new {number: "type"} ++mem: automatically abandoning 1000 + +:(scenario refcounts_3) +def main [ + 1:address:number <- new number:type + # passing in addresses to recipes increments refcount + foo 1:address:number + 1:address:number <- copy 0 +] +def foo [ + 2:address:number <- next-ingredient + # return does NOT yet decrement refcount; memory must be explicitly managed + 2:address:number <- copy 0 +] ++run: {1: ("address" "number")} <- new {number: "type"} ++mem: incrementing refcount of 1000: 0 -> 1 ++run: {2: ("address" "number")} <- next-ingredient ++mem: incrementing refcount of 1000: 1 -> 2 ++run: {2: ("address" "number")} <- copy {0: "literal"} ++mem: decrementing refcount of 1000: 2 -> 1 ++run: {1: ("address" "number")} <- copy {0: "literal"} ++mem: decrementing refcount of 1000: 1 -> 0 ++mem: automatically abandoning 1000 + +:(scenario refcounts_4) +def main [ + 1:address:number <- new number:type + # idempotent copies leave refcount unchanged + 1:address:number <- copy 1:address:number +] ++run: {1: ("address" "number")} <- new {number: "type"} ++mem: incrementing refcount of 1000: 0 -> 1 ++run: {1: ("address" "number")} <- copy {1: ("address" "number")} ++mem: decrementing refcount of 1000: 1 -> 0 ++mem: incrementing refcount of 1000: 0 -> 1 + +:(scenario refcounts_5) +def main [ + 1:address:number <- new number:type + # passing in addresses to recipes increments refcount + foo 1:address:number + # return does NOT yet decrement refcount; memory must be explicitly managed + 1:address:number <- new number:type +] +def foo [ + 2:address:number <- next-ingredient +] ++run: {1: ("address" "number")} <- new {number: "type"} ++mem: incrementing refcount of 1000: 0 -> 1 ++run: {2: ("address" "number")} <- next-ingredient ++mem: incrementing refcount of 1000: 1 -> 2 ++run: {1: ("address" "number")} <- new {number: "type"} ++mem: decrementing refcount of 1000: 2 -> 1 + +:(scenario refcounts_array) +def main [ + 1:number <- copy 30 + # allocate an array + 10:address:array:number <- new number:type, 20 + 11:number <- copy 10:address:array:number + # allocate another array in its place, implicitly freeing the previous allocation + 10:address:array:number <- new number:type, 25 +] ++run: {10: ("address" "array" "number")} <- new {number: "type"}, {20: "literal"} +# abandoned array is of old size (20, not 25) ++abandon: saving in free-list of size 22 + +//:: abandon and reclaim memory when refcount drops to 0 + +:(scenario new_reclaim) +def main [ + 1:address:number <- new number:type + 2:number <- copy 1:address:number # because 1 will get reset during abandon below + 1:address:number <- copy 0 # abandon + 3:address:number <- new number:type # must be same size as abandoned memory to reuse + 4:boolean <- equal 2:number, 3:address:number +] +# both allocations should have returned the same address ++mem: storing 1 in location 4 + +//: When abandoning addresses we'll save them to a 'free list', segregated by size. + +:(before "End routine Fields") +map<int, int> free_list; + +:(code) +void abandon(int address, int size) { + trace(9999, "abandon") << "saving in free-list of size " << size << end(); +//? Total_free += size; +//? Num_free++; +//? cerr << "abandon: " << size << '\n'; + // clear memory + for (int curr = address; curr < address+size; ++curr) + put(Memory, curr, 0); + // append existing free list to address + put(Memory, address, get_or_insert(Current_routine->free_list, size)); + put(Current_routine->free_list, size, address); +} + +:(before "ensure_space(size)" following "case ALLOCATE") +if (get_or_insert(Current_routine->free_list, size)) { + trace(9999, "abandon") << "picking up space from free-list of size " << size << end(); + int result = get_or_insert(Current_routine->free_list, size); + trace(9999, "mem") << "new alloc from free list: " << result << end(); + put(Current_routine->free_list, size, get_or_insert(Memory, result)); + for (int curr = result+1; curr < result+size; ++curr) { + if (get_or_insert(Memory, curr) != 0) { + raise << maybe(current_recipe_name()) << "memory in free list was not zeroed out: " << curr << '/' << result << "; somebody wrote to us after free!!!\n" << end(); + break; // always fatal + } + } + if (SIZE(current_instruction().ingredients) > 1) + put(Memory, result+/*skip refcount*/1, ingredients.at(1).at(0)); + else + put(Memory, result, 0); + products.resize(1); + products.at(0).push_back(result); + break; +} + +:(scenario new_differing_size_no_reclaim) +def main [ + 1:address:number <- new number:type + 2:number <- copy 1:address:number + 1:address:number <- copy 0 # abandon + 3:address:array:number <- new number:type, 2 # different size + 4:boolean <- equal 2:number, 3:address:array:number +] +# no reuse ++mem: storing 0 in location 4 + +:(scenario new_reclaim_array) +def main [ + 1:address:array:number <- new number:type, 2 + 2:number <- copy 1:address:array:number + 1:address:array:number <- copy 0 # abandon + 3:address:array:number <- new number:type, 2 # same size + 4:boolean <- equal 2:number, 3:address:array:number +] +# reuse ++mem: storing 1 in location 4 + //:: helpers for debugging :(before "End Primitive Recipe Declarations") diff --git a/034new.cc b/034new.cc deleted file mode 100644 index ec30fee1..00000000 --- a/034new.cc +++ /dev/null @@ -1,686 +0,0 @@ -//: Creating space for new variables at runtime. - -//: Mu has two primitives for managing allocations: -//: - 'allocate' reserves a specified amount of space -//: - 'abandon' returns allocated space to be reused by future calls to 'allocate' -//: -//: In practice it's useful to let programs copy addresses anywhere they want, -//: but a prime source of (particularly security) bugs is accessing memory -//: after it's been abandoned. To avoid this, mu programs use a safer -//: primitive called 'new', which adds two features: -//: -//: - it takes a type rather than a size, to save you the trouble of -//: calculating sizes of different variables. -//: - it allocates an extra location where it tracks so-called 'reference -//: counts' or refcounts: the number of address variables in your program that -//: point to this allocation. The initial refcount of an allocation starts out -//: at 1 (the product of the 'new' instruction). When other variables are -//: copied from it the refcount is incremented. When a variable stops pointing -//: at it the refcount is decremented. When the refcount goes to 0 the -//: allocation is automatically abandoned. -//: -//: Mu programs guarantee you'll have no memory corruption bugs as long as you -//: use 'new' and never use 'allocate' or 'abandon'. However, they don't help -//: you at all to remember to abandon memory after you're done with it. To -//: minimize memory use, be sure to reset allocated addresses to 0 when you're -//: done with them. - -//: interlude { -//: To help you distinguish addresses that point at allocations, 'new' returns -//: type address:shared:___. Think of 'shared' as a generic container that -//: contains one extra field: the refcount. However, lookup operations will -//: transparently drop the 'shared' and access to the refcount. Copying -//: between shared and non-shared addresses is forbidden. -:(before "End Mu Types Initialization") -type_ordinal shared = put(Type_ordinal, "shared", Next_type_ordinal++); -get_or_insert(Type, shared).name = "shared"; -:(before "End Drop Address In lookup_memory(x)") -if (x.type->name == "shared" && x.value != 0) { - trace(9999, "mem") << "skipping refcount at " << x.value << end(); - x.set_value(x.value+1); // skip refcount - drop_from_type(x, "shared"); -} -:(before "End Drop Address In canonize_type(r)") -if (r.type->name == "shared") { - drop_from_type(r, "shared"); -} - -:(code) -void test_lookup_shared_address() { - reagent x("*x:address:shared:number"); - x.set_value(34); // unsafe - put(Memory, 34, 1000); - lookup_memory(x); - CHECK_TRACE_CONTENTS("mem: skipping refcount at 1000"); - CHECK_EQ(x.value, 1001); -} - -void test_lookup_shared_address_skip_zero() { - reagent x("*x:address:shared:number"); - x.set_value(34); // unsafe - put(Memory, 34, 0); - lookup_memory(x); - CHECK_TRACE_DOESNT_CONTAIN("mem: skipping refcount at 0"); - CHECK_EQ(x.value, 0); -} - -//: } end interlude - -:(scenarios run) -:(scenario new) -# call new two times with identical arguments; you should get back different results -def main [ - 1:address:shared:number/raw <- new number:type - 2:address:shared:number/raw <- new number:type - 3:boolean/raw <- equal 1:address:shared:number/raw, 2:address:shared:number/raw -] -+mem: storing 0 in location 3 - -:(before "End Globals") -const int Reserved_for_tests = 1000; -int Memory_allocated_until = Reserved_for_tests; -int Initial_memory_per_routine = 100000; -:(before "End Setup") -Memory_allocated_until = Reserved_for_tests; -Initial_memory_per_routine = 100000; -:(before "End routine Fields") -int alloc, alloc_max; -:(before "End routine Constructor") -alloc = Memory_allocated_until; -Memory_allocated_until += Initial_memory_per_routine; -alloc_max = Memory_allocated_until; -trace(9999, "new") << "routine allocated memory from " << alloc << " to " << alloc_max << end(); - -//:: 'new' takes a weird 'type' as its first ingredient; don't error on it -:(before "End Mu Types Initialization") -put(Type_ordinal, "type", 0); - -//:: typecheck 'new' instructions -:(before "End Primitive Recipe Declarations") -NEW, -:(before "End Primitive Recipe Numbers") -put(Recipe_ordinal, "new", NEW); -:(before "End Primitive Recipe Checks") -case NEW: { - const recipe& caller = get(Recipe, r); - if (inst.ingredients.empty() || SIZE(inst.ingredients) > 2) { - raise << maybe(caller.name) << "'new' requires one or two ingredients, but got " << to_original_string(inst) << '\n' << end(); - break; - } - // End NEW Check Special-cases - reagent type = inst.ingredients.at(0); - if (!is_mu_type_literal(type)) { - raise << maybe(caller.name) << "first ingredient of 'new' should be a type, but got " << type.original_string << '\n' << end(); - break; - } - if (inst.products.empty()) { - raise << maybe(caller.name) << "result of 'new' should never be ignored\n" << end(); - break; - } - if (!product_of_new_is_valid(inst)) { - raise << maybe(caller.name) << "product of 'new' has incorrect type: " << to_original_string(inst) << '\n' << end(); - break; - } - break; -} -:(code) -bool product_of_new_is_valid(const instruction& inst) { - reagent product = inst.products.at(0); - canonize_type(product); - if (!product.type || product.type->value != get(Type_ordinal, "address")) return false; - drop_from_type(product, "address"); - if (!product.type || product.type->value != get(Type_ordinal, "shared")) return false; - drop_from_type(product, "shared"); - if (SIZE(inst.ingredients) > 1) { - // array allocation - if (!product.type || product.type->value != get(Type_ordinal, "array")) return false; - drop_from_type(product, "array"); - } - reagent expected_product("x:"+inst.ingredients.at(0).name); - // End Post-processing(expected_product) When Checking 'new' - return types_strictly_match(product, expected_product); -} - -//:: translate 'new' to 'allocate' instructions that take a size instead of a type -:(after "Transform.push_back(check_instruction)") // check_instruction will guard against direct 'allocate' instructions below -Transform.push_back(transform_new_to_allocate); // idempotent - -:(code) -void transform_new_to_allocate(const recipe_ordinal r) { - trace(9991, "transform") << "--- convert 'new' to 'allocate' for recipe " << get(Recipe, r).name << end(); - for (int i = 0; i < SIZE(get(Recipe, r).steps); ++i) { - instruction& inst = get(Recipe, r).steps.at(i); - // Convert 'new' To 'allocate' - if (inst.name == "new") { - inst.operation = ALLOCATE; - string_tree* type_name = new string_tree(inst.ingredients.at(0).name); - // End Post-processing(type_name) When Converting 'new' - type_tree* type = new_type_tree(type_name); - inst.ingredients.at(0).set_value(size_of(type)); - trace(9992, "new") << "size of " << to_string(type_name) << " is " << inst.ingredients.at(0).value << end(); - delete type; - delete type_name; - } - } -} - -//:: implement 'allocate' based on size - -:(before "End Primitive Recipe Declarations") -ALLOCATE, -:(before "End Primitive Recipe Numbers") -put(Recipe_ordinal, "allocate", ALLOCATE); -:(before "End Primitive Recipe Implementations") -case ALLOCATE: { - // compute the space we need - int size = ingredients.at(0).at(0); - if (SIZE(ingredients) > 1) { - // array - trace(9999, "mem") << "array size is " << ingredients.at(1).at(0) << end(); - size = /*space for length*/1 + size*ingredients.at(1).at(0); - } - // include space for refcount - size++; - trace(9999, "mem") << "allocating size " << size << end(); -//? Total_alloc += size; -//? Num_alloc++; - // compute the region of memory to return - // really crappy at the moment - ensure_space(size); - const int result = Current_routine->alloc; - trace(9999, "mem") << "new alloc: " << result << end(); - // save result - products.resize(1); - products.at(0).push_back(result); - // initialize allocated space - for (int address = result; address < result+size; ++address) - put(Memory, address, 0); - // initialize array length - if (SIZE(current_instruction().ingredients) > 1) { - trace(9999, "mem") << "storing " << ingredients.at(1).at(0) << " in location " << result+/*skip refcount*/1 << end(); - put(Memory, result+/*skip refcount*/1, ingredients.at(1).at(0)); - } - // bump - Current_routine->alloc += size; - // no support for reclaiming memory - assert(Current_routine->alloc <= Current_routine->alloc_max); - break; -} - -//:: ensure we never call 'allocate' directly; its types are not checked -:(before "End Primitive Recipe Checks") -case ALLOCATE: { - raise << "never call 'allocate' directly'; always use 'new'\n" << end(); - break; -} - -//:: ensure we never call 'new' without translating it (unless we add special-cases later) -:(before "End Primitive Recipe Implementations") -case NEW: { - raise << "no implementation for 'new'; why wasn't it translated to 'allocate'? Please save a copy of your program and send it to Kartik.\n" << end(); - break; -} - -//? :(before "End Globals") -//? int Total_alloc = 0; -//? int Num_alloc = 0; -//? int Total_free = 0; -//? int Num_free = 0; -//? :(before "End Setup") -//? Total_alloc = Num_alloc = Total_free = Num_free = 0; -//? :(before "End Teardown") -//? cerr << Total_alloc << "/" << Num_alloc -//? << " vs " << Total_free << "/" << Num_free << '\n'; -//? cerr << SIZE(Memory) << '\n'; - -:(code) -void ensure_space(int size) { - if (size > Initial_memory_per_routine) { - tb_shutdown(); - cerr << "can't allocate " << size << " locations, that's too much compared to " << Initial_memory_per_routine << ".\n"; - exit(0); - } - if (Current_routine->alloc + size > Current_routine->alloc_max) { - // waste the remaining space and create a new chunk - Current_routine->alloc = Memory_allocated_until; - Memory_allocated_until += Initial_memory_per_routine; - Current_routine->alloc_max = Memory_allocated_until; - trace(9999, "new") << "routine allocated memory from " << Current_routine->alloc << " to " << Current_routine->alloc_max << end(); - } -} - -:(scenario new_initializes) -% Memory_allocated_until = 10; -% put(Memory, Memory_allocated_until, 1); -def main [ - 1:address:shared:number <- new number:type - 2:number <- copy *1:address:shared:number -] -+mem: storing 0 in location 2 - -:(scenario new_error) -% Hide_errors = true; -def main [ - 1:address:number/raw <- new number:type -] -+error: main: product of 'new' has incorrect type: 1:address:number/raw <- new number:type - -:(scenario new_array) -def main [ - 1:address:shared:array:number/raw <- new number:type, 5 - 2:address:shared:number/raw <- new number:type - 3:number/raw <- subtract 2:address:shared:number/raw, 1:address:shared:array:number/raw -] -+run: {1: ("address" "shared" "array" "number"), "raw": ()} <- new {number: "type"}, {5: "literal"} -+mem: array size is 5 -# don't forget the extra location for array size, and the second extra location for the refcount -+mem: storing 7 in location 3 - -:(scenario new_empty_array) -def main [ - 1:address:shared:array:number/raw <- new number:type, 0 - 2:address:shared:number/raw <- new number:type - 3:number/raw <- subtract 2:address:shared:number/raw, 1:address:shared:array:number/raw -] -+run: {1: ("address" "shared" "array" "number"), "raw": ()} <- new {number: "type"}, {0: "literal"} -+mem: array size is 0 -# one location for array size, and one for the refcount -+mem: storing 2 in location 3 - -//: If a routine runs out of its initial allocation, it should allocate more. -:(scenario new_overflow) -% Initial_memory_per_routine = 3; // barely enough room for point allocation below -def main [ - 1:address:shared:number/raw <- new number:type - 2:address:shared:point/raw <- new point:type # not enough room in initial page -] -+new: routine allocated memory from 1000 to 1003 -+new: routine allocated memory from 1003 to 1006 - -//:: A way to return memory, and to reuse reclaimed memory. -//: todo: custodians, etc. Following malloc/free is a temporary hack. - -:(scenario new_reclaim) -def main [ - 1:address:shared:number <- new number:type - 2:address:shared:number <- copy 1:address:shared:number # because 1 will get reset during abandon below - abandon 1:address:shared:number # unsafe - 3:address:shared:number <- new number:type # must be same size as abandoned memory to reuse - 4:boolean <- equal 2:address:shared:number, 3:address:shared:number -] -# both allocations should have returned the same address -+mem: storing 1 in location 4 - -:(before "End routine Fields") -map<int, int> free_list; - -:(before "End Primitive Recipe Declarations") -ABANDON, -:(before "End Primitive Recipe Numbers") -put(Recipe_ordinal, "abandon", ABANDON); -:(before "End Primitive Recipe Checks") -case ABANDON: { - if (SIZE(inst.ingredients) != 1) { - raise << maybe(get(Recipe, r).name) << "'abandon' requires one ingredient, but got '" << to_original_string(inst) << "'\n" << end(); - break; - } - reagent types = inst.ingredients.at(0); - canonize_type(types); - if (!types.type || types.type->value != get(Type_ordinal, "address") || types.type->right->value != get(Type_ordinal, "shared")) { - raise << maybe(get(Recipe, r).name) << "first ingredient of 'abandon' should be an address:shared:___, but got " << inst.ingredients.at(0).original_string << '\n' << end(); - break; - } - break; -} -:(before "End Primitive Recipe Implementations") -case ABANDON: { - int address = ingredients.at(0).at(0); - trace(9999, "abandon") << "address to abandon is " << address << end(); - reagent types = current_instruction().ingredients.at(0); - trace(9999, "abandon") << "value of ingredient is " << types.value << end(); - canonize(types); - // lookup_memory without drop_one_lookup { - trace(9999, "abandon") << "value of ingredient after canonization is " << types.value << end(); - int address_location = types.value; - types.set_value(get_or_insert(Memory, types.value)+/*skip refcount*/1); - drop_from_type(types, "address"); - drop_from_type(types, "shared"); - // } - abandon(address, size_of(types)+/*refcount*/1); - // clear the address - trace(9999, "mem") << "resetting location " << address_location << end(); - put(Memory, address_location, 0); - break; -} - -:(code) -void abandon(int address, int size) { - trace(9999, "abandon") << "saving in free-list of size " << size << end(); -//? Total_free += size; -//? Num_free++; -//? cerr << "abandon: " << size << '\n'; - // clear memory - for (int curr = address; curr < address+size; ++curr) - put(Memory, curr, 0); - // append existing free list to address - put(Memory, address, get_or_insert(Current_routine->free_list, size)); - put(Current_routine->free_list, size, address); -} - -:(before "ensure_space(size)" following "case ALLOCATE") -if (get_or_insert(Current_routine->free_list, size)) { - trace(9999, "abandon") << "picking up space from free-list of size " << size << end(); - int result = get_or_insert(Current_routine->free_list, size); - trace(9999, "mem") << "new alloc from free list: " << result << end(); - put(Current_routine->free_list, size, get_or_insert(Memory, result)); - for (int curr = result+1; curr < result+size; ++curr) { - if (get_or_insert(Memory, curr) != 0) { - raise << maybe(current_recipe_name()) << "memory in free list was not zeroed out: " << curr << '/' << result << "; somebody wrote to us after free!!!\n" << end(); - break; // always fatal - } - } - if (SIZE(current_instruction().ingredients) > 1) - put(Memory, result+/*skip refcount*/1, ingredients.at(1).at(0)); - else - put(Memory, result, 0); - products.resize(1); - products.at(0).push_back(result); - break; -} - -:(scenario new_differing_size_no_reclaim) -def main [ - 1:address:shared:number <- new number:type - 2:address:shared:number <- copy 1:address:shared:number - abandon 1:address:shared:number - 3:address:shared:array:number <- new number:type, 2 # different size - 4:boolean <- equal 2:address:shared:number, 3:address:shared:array:number -] -# no reuse -+mem: storing 0 in location 4 - -:(scenario new_reclaim_array) -def main [ - 1:address:shared:array:number <- new number:type, 2 - 2:address:shared:array:number <- copy 1:address:shared:array:number - abandon 1:address:shared:array:number # unsafe - 3:address:shared:array:number <- new number:type, 2 - 4:boolean <- equal 2:address:shared:array:number, 3:address:shared:array:number -] -# reuse -+mem: storing 1 in location 4 - -:(scenario reset_on_abandon) -def main [ - 1:address:shared:number <- new number:type - abandon 1:address:shared:number -] -# reuse -+run: abandon {1: ("address" "shared" "number")} -+mem: resetting location 1 - -//:: Manage refcounts when copying addresses. - -:(scenario refcounts) -def main [ - 1:address:shared:number <- copy 1000/unsafe - 2:address:shared:number <- copy 1:address:shared:number - 1:address:shared:number <- copy 0 - 2:address:shared:number <- copy 0 -] -+run: {1: ("address" "shared" "number")} <- copy {1000: "literal", "unsafe": ()} -+mem: incrementing refcount of 1000: 0 -> 1 -+run: {2: ("address" "shared" "number")} <- copy {1: ("address" "shared" "number")} -+mem: incrementing refcount of 1000: 1 -> 2 -+run: {1: ("address" "shared" "number")} <- copy {0: "literal"} -+mem: decrementing refcount of 1000: 2 -> 1 -+run: {2: ("address" "shared" "number")} <- copy {0: "literal"} -+mem: decrementing refcount of 1000: 1 -> 0 -# the /unsafe corrupts memory but fortunately we won't be running any more 'new' in this scenario -+mem: automatically abandoning 1000 - -:(before "End write_memory(reagent x) Special-cases") -if (x.type->value == get(Type_ordinal, "address") - && x.type->right - && x.type->right->value == get(Type_ordinal, "shared")) { - // compute old address of x, as well as new address we want to write in - int old_address = get_or_insert(Memory, x.value); - assert(scalar(data)); - int new_address = data.at(0); - // decrement refcount of old address - if (old_address) { - int old_refcount = get_or_insert(Memory, old_address); - trace(9999, "mem") << "decrementing refcount of " << old_address << ": " << old_refcount << " -> " << (old_refcount-1) << end(); - put(Memory, old_address, old_refcount-1); - } - // perform the write - trace(9999, "mem") << "storing " << no_scientific(data.at(0)) << " in location " << x.value << end(); - put(Memory, x.value, new_address); - // increment refcount of new address - if (new_address) { - int new_refcount = get_or_insert(Memory, new_address); - assert(new_refcount >= 0); // == 0 only when new_address == old_address - trace(9999, "mem") << "incrementing refcount of " << new_address << ": " << new_refcount << " -> " << (new_refcount+1) << end(); - put(Memory, new_address, new_refcount+1); - } - // abandon old address if necessary - // do this after all refcount updates are done just in case old and new are identical - assert(old_address >= 0); - if (old_address == 0) return; - assert(get_or_insert(Memory, old_address) >= 0); - if (get_or_insert(Memory, old_address) > 0) return; - // lookup_memory without drop_one_lookup { - trace(9999, "mem") << "automatically abandoning " << old_address << end(); - trace(9999, "mem") << "computing size to abandon at " << x.value << end(); - x.set_value(old_address+/*skip refcount*/1); - drop_from_type(x, "address"); - drop_from_type(x, "shared"); - // } - abandon(old_address, size_of(x)+/*refcount*/1); - return; -} - -:(scenario refcounts_2) -def main [ - 1:address:shared:number <- new number:type - # over-writing one allocation with another - 1:address:shared:number <- new number:type - 1:address:shared:number <- copy 0 -] -+run: {1: ("address" "shared" "number")} <- new {number: "type"} -+mem: incrementing refcount of 1000: 0 -> 1 -+run: {1: ("address" "shared" "number")} <- new {number: "type"} -+mem: automatically abandoning 1000 - -:(scenario refcounts_3) -def main [ - 1:address:shared:number <- new number:type - # passing in addresses to recipes increments refcount - foo 1:address:shared:number - 1:address:shared:number <- copy 0 -] -def foo [ - 2:address:shared:number <- next-ingredient - # return does NOT yet decrement refcount; memory must be explicitly managed - 2:address:shared:number <- copy 0 -] -+run: {1: ("address" "shared" "number")} <- new {number: "type"} -+mem: incrementing refcount of 1000: 0 -> 1 -+run: {2: ("address" "shared" "number")} <- next-ingredient -+mem: incrementing refcount of 1000: 1 -> 2 -+run: {2: ("address" "shared" "number")} <- copy {0: "literal"} -+mem: decrementing refcount of 1000: 2 -> 1 -+run: {1: ("address" "shared" "number")} <- copy {0: "literal"} -+mem: decrementing refcount of 1000: 1 -> 0 -+mem: automatically abandoning 1000 - -:(scenario refcounts_4) -def main [ - 1:address:shared:number <- new number:type - # idempotent copies leave refcount unchanged - 1:address:shared:number <- copy 1:address:shared:number -] -+run: {1: ("address" "shared" "number")} <- new {number: "type"} -+mem: incrementing refcount of 1000: 0 -> 1 -+run: {1: ("address" "shared" "number")} <- copy {1: ("address" "shared" "number")} -+mem: decrementing refcount of 1000: 1 -> 0 -+mem: incrementing refcount of 1000: 0 -> 1 - -:(scenario refcounts_5) -def main [ - 1:address:shared:number <- new number:type - # passing in addresses to recipes increments refcount - foo 1:address:shared:number - # return does NOT yet decrement refcount; memory must be explicitly managed - 1:address:shared:number <- new number:type -] -def foo [ - 2:address:shared:number <- next-ingredient -] -+run: {1: ("address" "shared" "number")} <- new {number: "type"} -+mem: incrementing refcount of 1000: 0 -> 1 -+run: {2: ("address" "shared" "number")} <- next-ingredient -+mem: incrementing refcount of 1000: 1 -> 2 -+run: {1: ("address" "shared" "number")} <- new {number: "type"} -+mem: decrementing refcount of 1000: 2 -> 1 - -:(scenario refcounts_array) -def main [ - 1:number <- copy 30 - # allocate an array - 10:address:shared:array:number <- new number:type, 20 - 11:number <- copy 10:address:shared:array:number - # allocate another array in its place, implicitly freeing the previous allocation - 10:address:shared:array:number <- new number:type, 25 -] -+run: {10: ("address" "shared" "array" "number")} <- new {number: "type"}, {20: "literal"} -# abandoned array is of old size (20, not 25) -+abandon: saving in free-list of size 22 - -//:: Extend 'new' to handle a unicode string literal argument. - -:(scenario new_string) -def main [ - 1:address:shared:array:character <- new [abc def] - 2:character <- index *1:address:shared:array:character, 5 -] -# number code for 'e' -+mem: storing 101 in location 2 - -:(scenario new_string_handles_unicode) -def main [ - 1:address:shared:array:character <- new [a«c] - 2:number <- length *1:address:shared:array:character - 3:character <- index *1:address:shared:array:character, 1 -] -+mem: storing 3 in location 2 -# unicode for '«' -+mem: storing 171 in location 3 - -:(before "End NEW Check Special-cases") -if (is_literal_string(inst.ingredients.at(0))) break; -:(before "Convert 'new' To 'allocate'") -if (inst.name == "new" && is_literal_string(inst.ingredients.at(0))) continue; -:(after "case NEW" following "Primitive Recipe Implementations") - if (is_literal_string(current_instruction().ingredients.at(0))) { - products.resize(1); - products.at(0).push_back(new_mu_string(current_instruction().ingredients.at(0).name)); - trace(9999, "mem") << "new string alloc: " << products.at(0).at(0) << end(); - break; - } - -:(code) -int new_mu_string(const string& contents) { - // allocate an array just large enough for it - int string_length = unicode_length(contents); -//? Total_alloc += string_length+1; -//? Num_alloc++; - ensure_space(string_length+1); // don't forget the extra location for array size - // initialize string - int result = Current_routine->alloc; - // initialize refcount - put(Memory, Current_routine->alloc++, 0); - // store length - put(Memory, Current_routine->alloc++, string_length); - int curr = 0; - const char* raw_contents = contents.c_str(); - for (int i = 0; i < string_length; ++i) { - uint32_t curr_character; - assert(curr < SIZE(contents)); - tb_utf8_char_to_unicode(&curr_character, &raw_contents[curr]); - put(Memory, Current_routine->alloc, curr_character); - curr += tb_utf8_char_length(raw_contents[curr]); - ++Current_routine->alloc; - } - // mu strings are not null-terminated in memory - return result; -} - -//: stash recognizes strings - -:(scenario stash_string) -def main [ - 1:address:shared:array:character <- new [abc] - stash [foo:], 1:address:shared:array:character -] -+app: foo: abc - -:(before "End print Special-cases(reagent r, data)") -if (is_mu_string(r)) { - assert(scalar(data)); - return read_mu_string(data.at(0))+' '; -} - -:(scenario unicode_string) -def main [ - 1:address:shared:array:character <- new [♠] - stash [foo:], 1:address:shared:array:character -] -+app: foo: ♠ - -:(scenario stash_space_after_string) -def main [ - 1:address:shared:array:character <- new [abc] - stash 1:address:shared:array:character, [foo] -] -+app: abc foo - -//: Allocate more to routine when initializing a literal string -:(scenario new_string_overflow) -% Initial_memory_per_routine = 2; -def main [ - 1:address:shared:number/raw <- new number:type - 2:address:shared:array:character/raw <- new [a] # not enough room in initial page, if you take the array size into account -] -+new: routine allocated memory from 1000 to 1002 -+new: routine allocated memory from 1002 to 1004 - -//: helpers -:(code) -int unicode_length(const string& s) { - const char* in = s.c_str(); - int result = 0; - int curr = 0; - while (curr < SIZE(s)) { // carefully bounds-check on the string - // before accessing its raw pointer - ++result; - curr += tb_utf8_char_length(in[curr]); - } - return result; -} - -string read_mu_string(int address) { - if (address == 0) return ""; - address++; // skip refcount - int size = get_or_insert(Memory, address); - if (size == 0) return ""; - ostringstream tmp; - for (int curr = address+1; curr <= address+size; ++curr) { - tmp << to_unicode(static_cast<uint32_t>(get_or_insert(Memory, curr))); - } - return tmp.str(); -} - -bool is_mu_type_literal(reagent r) { - return is_literal(r) && r.type && r.type->name == "type"; -} diff --git a/034new_text.cc b/034new_text.cc new file mode 100644 index 00000000..4b3ad536 --- /dev/null +++ b/034new_text.cc @@ -0,0 +1,123 @@ +//: Extend 'new' to handle a unicode string literal argument. + +:(scenario new_string) +def main [ + 1:address:array:character <- new [abc def] + 2:character <- index *1:address:array:character, 5 +] +# number code for 'e' ++mem: storing 101 in location 2 + +:(scenario new_string_handles_unicode) +def main [ + 1:address:array:character <- new [a«c] + 2:number <- length *1:address:array:character + 3:character <- index *1:address:array:character, 1 +] ++mem: storing 3 in location 2 +# unicode for '«' ++mem: storing 171 in location 3 + +:(before "End NEW Check Special-cases") +if (is_literal_string(inst.ingredients.at(0))) break; +:(before "Convert 'new' To 'allocate'") +if (inst.name == "new" && is_literal_string(inst.ingredients.at(0))) continue; +:(after "case NEW" following "Primitive Recipe Implementations") + if (is_literal_string(current_instruction().ingredients.at(0))) { + products.resize(1); + products.at(0).push_back(new_mu_string(current_instruction().ingredients.at(0).name)); + trace(9999, "mem") << "new string alloc: " << products.at(0).at(0) << end(); + break; + } + +:(code) +int new_mu_string(const string& contents) { + // allocate an array just large enough for it + int string_length = unicode_length(contents); +//? Total_alloc += string_length+1; +//? Num_alloc++; + ensure_space(string_length+1); // don't forget the extra location for array size + // initialize string + int result = Current_routine->alloc; + // initialize refcount + put(Memory, Current_routine->alloc++, 0); + // store length + put(Memory, Current_routine->alloc++, string_length); + int curr = 0; + const char* raw_contents = contents.c_str(); + for (int i = 0; i < string_length; ++i) { + uint32_t curr_character; + assert(curr < SIZE(contents)); + tb_utf8_char_to_unicode(&curr_character, &raw_contents[curr]); + put(Memory, Current_routine->alloc, curr_character); + curr += tb_utf8_char_length(raw_contents[curr]); + ++Current_routine->alloc; + } + // mu strings are not null-terminated in memory + return result; +} + +//: stash recognizes strings + +:(scenario stash_string) +def main [ + 1:address:array:character <- new [abc] + stash [foo:], 1:address:array:character +] ++app: foo: abc + +:(before "End print Special-cases(reagent r, data)") +if (is_mu_string(r)) { + assert(scalar(data)); + return read_mu_string(data.at(0))+' '; +} + +:(scenario unicode_string) +def main [ + 1:address:array:character <- new [♠] + stash [foo:], 1:address:array:character +] ++app: foo: ♠ + +:(scenario stash_space_after_string) +def main [ + 1:address:array:character <- new [abc] + stash 1:address:array:character, [foo] +] ++app: abc foo + +//: Allocate more to routine when initializing a literal string +:(scenario new_string_overflow) +% Initial_memory_per_routine = 2; +def main [ + 1:address:number/raw <- new number:type + 2:address:array:character/raw <- new [a] # not enough room in initial page, if you take the array size into account +] ++new: routine allocated memory from 1000 to 1002 ++new: routine allocated memory from 1002 to 1004 + +//: helpers +:(code) +int unicode_length(const string& s) { + const char* in = s.c_str(); + int result = 0; + int curr = 0; + while (curr < SIZE(s)) { // carefully bounds-check on the string + // before accessing its raw pointer + ++result; + curr += tb_utf8_char_length(in[curr]); + } + return result; +} + +string read_mu_string(int address) { + if (address == 0) return ""; + address++; // skip refcount + int size = get_or_insert(Memory, address); + if (size == 0) return ""; + ostringstream tmp; + for (int curr = address+1; curr <= address+size; ++curr) { + tmp << to_unicode(static_cast<uint32_t>(get_or_insert(Memory, curr))); + } + return tmp.str(); +} diff --git a/035location_array.cc b/035location_array.cc index 86cf8e97..191e6d38 100644 --- a/035location_array.cc +++ b/035location_array.cc @@ -5,19 +5,17 @@ put(Recipe_ordinal, "to-location-array", TO_LOCATION_ARRAY); :(before "End Primitive Recipe Checks") case TO_LOCATION_ARRAY: { const recipe& caller = get(Recipe, r); - if (!is_shared_address_of_array_of_numbers(inst.products.at(0))) { + if (!is_address_of_array_of_numbers(inst.products.at(0))) { raise << maybe(caller.name) << "product of 'to-location-array' has incorrect type: " << to_original_string(inst) << '\n' << end(); break; } break; } :(code) -bool is_shared_address_of_array_of_numbers(reagent product) { +bool is_address_of_array_of_numbers(reagent product) { canonize_type(product); if (!product.type || product.type->value != get(Type_ordinal, "address")) return false; drop_from_type(product, "address"); - if (!product.type || product.type->value != get(Type_ordinal, "shared")) return false; - drop_from_type(product, "shared"); if (!product.type || product.type->value != get(Type_ordinal, "array")) return false; drop_from_type(product, "array"); if (!product.type || product.type->value != get(Type_ordinal, "number")) return false; diff --git a/042name.cc b/042name.cc index a65731e6..a53144ea 100644 --- a/042name.cc +++ b/042name.cc @@ -112,9 +112,8 @@ int lookup_name(const reagent& r, const recipe_ordinal default_recipe) { type_ordinal skip_addresses(type_tree* type) { type_ordinal address = get(Type_ordinal, "address"); - type_ordinal shared = get(Type_ordinal, "shared"); for (; type; type = type->right) { - if (type->value != address && type->value != shared) + if (type->value != address) return type->value; } return -1; diff --git a/043space.cc b/043space.cc index 151c23cd..d29cf983 100644 --- a/043space.cc +++ b/043space.cc @@ -6,24 +6,24 @@ # if default-space is 10, and if an array of 5 locals lies from location 12 to 16 (inclusive), # then local 0 is really location 12, local 1 is really location 13, and so on. def main [ - # pretend shared:array:location; in practice we'll use new + # pretend address:array:location; in practice we'll use new 10:number <- copy 0 # refcount 11:number <- copy 5 # length - default-space:address:shared:array:location <- copy 10/unsafe + default-space:address:array:location <- copy 10/unsafe 1:number <- copy 23 ] +mem: storing 23 in location 13 :(scenario lookup_sidesteps_default_space) def main [ - # pretend pointer from outside - 3:number <- copy 34 - # pretend shared:array:location; in practice we'll use new + # pretend pointer from outside (2000 reserved for refcount) + 2001:number <- copy 34 + # pretend address:array:location; in practice we'll use new 1000:number <- copy 0 # refcount 1001:number <- copy 5 # length # actual start of this recipe - default-space:address:shared:array:location <- copy 1000/unsafe - 1:address:number <- copy 3/unsafe + default-space:address:array:location <- copy 1000/unsafe + 1:address:number <- copy 2000/unsafe # even local variables always contain raw addresses 8:number/raw <- copy *1:address:number ] +mem: storing 34 in location 8 @@ -88,13 +88,11 @@ int address(int offset, int base) { || !x.type || x.type->value != get(Type_ordinal, "address") || !x.type->right - || x.type->right->value != get(Type_ordinal, "shared") + || x.type->right->value != get(Type_ordinal, "array") || !x.type->right->right - || x.type->right->right->value != get(Type_ordinal, "array") - || !x.type->right->right->right - || x.type->right->right->right->value != get(Type_ordinal, "location") - || x.type->right->right->right->right) { - raise << maybe(current_recipe_name()) << "'default-space' should be of type address:shared:array:location, but tried to write " << to_string(data) << '\n' << end(); + || x.type->right->right->value != get(Type_ordinal, "location") + || x.type->right->right->right) { + raise << maybe(current_recipe_name()) << "'default-space' should be of type address:array:location, but tried to write " << to_string(data) << '\n' << end(); } current_call().default_space = data.at(0); return; @@ -102,8 +100,8 @@ int address(int offset, int base) { :(scenario get_default_space) def main [ - default-space:address:shared:array:location <- copy 10/unsafe - 1:address:shared:array:location/raw <- copy default-space:address:shared:array:location + default-space:address:array:location <- copy 10/unsafe + 1:address:array:location/raw <- copy default-space:address:array:location ] +mem: storing 10 in location 1 @@ -118,15 +116,15 @@ def main [ :(scenario lookup_sidesteps_default_space_in_get) def main [ - # pretend pointer to container from outside - 12:number <- copy 34 - 13:number <- copy 35 - # pretend shared:array:location; in practice we'll use new + # pretend pointer to container from outside (2000 reserved for refcount) + 2001:number <- copy 34 + 2002:number <- copy 35 + # pretend address:array:location; in practice we'll use new 1000:number <- copy 0 # refcount 1001:number <- copy 5 # length # actual start of this recipe - default-space:address:shared:array:location <- copy 1000/unsafe - 1:address:point <- copy 12/unsafe + default-space:address:array:location <- copy 1000/unsafe + 1:address:point <- copy 2000/unsafe 9:number/raw <- get *1:address:point, 1:offset ] +mem: storing 35 in location 9 @@ -138,16 +136,16 @@ element.properties.push_back(pair<string, string_tree*>("raw", NULL)); :(scenario lookup_sidesteps_default_space_in_index) def main [ - # pretend pointer to array from outside - 12:number <- copy 2 - 13:number <- copy 34 - 14:number <- copy 35 - # pretend shared:array:location; in practice we'll use new + # pretend pointer to array from outside (2000 reserved for refcount) + 2001:number <- copy 2 # length + 2002:number <- copy 34 + 2003:number <- copy 35 + # pretend address:array:location; in practice we'll use new 1000:number <- copy 0 # refcount 1001:number <- copy 5 # length # actual start of this recipe - default-space:address:shared:array:location <- copy 1000/unsafe - 1:address:array:number <- copy 12/unsafe + default-space:address:array:location <- copy 1000/unsafe + 1:address:array:number <- copy 2000/unsafe 9:number/raw <- index *1:address:array:number, 1 ] +mem: storing 35 in location 9 @@ -175,7 +173,7 @@ if (s == "number-of-locals") return true; :(before "End Rewrite Instruction(curr, recipe result)") // rewrite `new-default-space` to -// `default-space:address:shared:array:location <- new location:type, number-of-locals:literal` +// `default-space:address:array:location <- new location:type, number-of-locals:literal` // where N is Name[recipe][""] if (curr.name == "new-default-space") { rewrite_default_space_instruction(curr); @@ -206,7 +204,7 @@ def main [ def foo [ local-scope x:number <- copy 34 - return default-space:address:shared:array:location + return default-space:address:array:location ] # both calls to foo should have received the same default-space +mem: storing 1 in location 3 @@ -215,9 +213,9 @@ def foo [ //? :(scenario local_scope_frees_up_allocations) //? def main [ //? local-scope -//? x:address:shared:array:character <- new [abc] +//? x:address:array:character <- new [abc] //? ] -//? +mem: clearing x:address:shared:array:character +//? +mem: clearing x:address:array:character //: todo: do this in a transform, rather than magically in the reply instruction :(after "Falling Through End Of Recipe") @@ -241,7 +239,7 @@ void try_reclaim_locals() { const instruction& inst = exiting_recipe.steps.at(0); if (inst.old_name != "local-scope") return; // reclaim any local variables unless they're being returned - // TODO: this isn't working yet. Doesn't handle address:shared stored in + // TODO: this isn't working yet. Doesn't handle address stored in // containers created by 'copy' or 'merge'. We'd end up deleting the address // even if some container containing it was returned. // This might doom our whole refcounting-based approach :/ @@ -282,7 +280,7 @@ void rewrite_default_space_instruction(instruction& curr) { curr.ingredients.push_back(reagent("number-of-locals:literal")); if (!curr.products.empty()) raise << "new-default-space can't take any results\n" << end(); - curr.products.push_back(reagent("default-space:address:shared:array:location")); + curr.products.push_back(reagent("default-space:address:array:location")); } //:: all recipes must set default-space one way or another diff --git a/044space_surround.cc b/044space_surround.cc index 2231860e..d9830230 100644 --- a/044space_surround.cc +++ b/044space_surround.cc @@ -7,15 +7,15 @@ :(scenario surrounding_space) # location 1 in space 1 refers to the space surrounding the default space, here 20. def main [ - # pretend shared:array:location; in practice we'll use new + # pretend address:array:location; in practice we'll use new 10:number <- copy 0 # refcount 11:number <- copy 5 # length - # pretend shared:array:location; in practice we'll use new + # pretend address:array:location; in practice we'll use new 20:number <- copy 0 # refcount 21:number <- copy 5 # length # actual start of this recipe - default-space:address:shared:array:location <- copy 10/unsafe - 0:address:shared:array:location/names:dummy <- copy 20/unsafe # later layers will explain the /names: property + default-space:address:array:location <- copy 10/unsafe + 0:address:array:location/names:dummy <- copy 20/unsafe # later layers will explain the /names: property 1:number <- copy 32 1:number/space:1 <- copy 33 ] diff --git a/045closure_name.cc b/045closure_name.cc index 23b10f0c..48a84442 100644 --- a/045closure_name.cc +++ b/045closure_name.cc @@ -5,22 +5,22 @@ :(scenario closure) def main [ - default-space:address:shared:array:location <- new location:type, 30 - 1:address:shared:array:location/names:new-counter <- new-counter - 2:number/raw <- increment-counter 1:address:shared:array:location/names:new-counter - 3:number/raw <- increment-counter 1:address:shared:array:location/names:new-counter + default-space:address:array:location <- new location:type, 30 + 1:address:array:location/names:new-counter <- new-counter + 2:number/raw <- increment-counter 1:address:array:location/names:new-counter + 3:number/raw <- increment-counter 1:address:array:location/names:new-counter ] def new-counter [ - default-space:address:shared:array:location <- new location:type, 30 + default-space:address:array:location <- new location:type, 30 x:number <- copy 23 y:number <- copy 3 # variable that will be incremented - return default-space:address:shared:array:location + return default-space:address:array:location ] def increment-counter [ - default-space:address:shared:array:location <- new location:type, 30 - 0:address:shared:array:location/names:new-counter <- next-ingredient # outer space must be created by 'new-counter' above + default-space:address:array:location <- new location:type, 30 + 0:address:array:location/names:new-counter <- next-ingredient # outer space must be created by 'new-counter' above y:number/space:1 <- add y:number/space:1, 1 # increment y:number <- copy 234 # dummy return y:number/space:1 @@ -52,13 +52,11 @@ void collect_surrounding_spaces(const recipe_ordinal r) { if (!type || type->value != get(Type_ordinal, "address") || !type->right - || type->right->value != get(Type_ordinal, "shared") + || type->right->value != get(Type_ordinal, "array") || !type->right->right - || type->right->right->value != get(Type_ordinal, "array") - || !type->right->right->right - || type->right->right->right->value != get(Type_ordinal, "location") - || type->right->right->right->right) { - raise << "slot 0 should always have type address:shared:array:location, but is " << to_string(inst.products.at(j)) << '\n' << end(); + || type->right->right->value != get(Type_ordinal, "location") + || type->right->right->right) { + raise << "slot 0 should always have type address:array:location, but is " << to_string(inst.products.at(j)) << '\n' << end(); continue; } string_tree* s = property(inst.products.at(j), "names"); diff --git a/046global.cc b/046global.cc index 0a5878cf..40cef9d8 100644 --- a/046global.cc +++ b/046global.cc @@ -11,15 +11,15 @@ :(scenario global_space) def main [ - # pretend shared:array:location; in practice we'll use new + # pretend address:array:location; in practice we'll use new 10:number <- copy 0 # refcount 11:number <- copy 5 # length - # pretend shared:array:location; in practice we'll use new + # pretend address:array:location; in practice we'll use new 20:number <- copy 0 # refcount 21:number <- copy 5 # length # actual start of this recipe - global-space:address:shared:array:location <- copy 20/unsafe - default-space:address:shared:array:location <- copy 10/unsafe + global-space:address:array:location <- copy 20/unsafe + default-space:address:array:location <- copy 10/unsafe 1:number <- copy 23 1:number/space:global <- copy 24 ] @@ -46,13 +46,11 @@ global_space = 0; || !x.type || x.type->value != get(Type_ordinal, "address") || !x.type->right - || x.type->right->value != get(Type_ordinal, "shared") + || x.type->right->value != get(Type_ordinal, "array") || !x.type->right->right - || x.type->right->right->value != get(Type_ordinal, "array") - || !x.type->right->right->right - || x.type->right->right->right->value != get(Type_ordinal, "location") - || x.type->right->right->right->right) { - raise << maybe(current_recipe_name()) << "'global-space' should be of type address:shared:array:location, but tried to write " << to_string(data) << '\n' << end(); + || x.type->right->right->value != get(Type_ordinal, "location") + || x.type->right->right->right) { + raise << maybe(current_recipe_name()) << "'global-space' should be of type address:array:location, but tried to write " << to_string(data) << '\n' << end(); } if (Current_routine->global_space) raise << "routine already has a global-space; you can't over-write your globals" << end(); @@ -73,7 +71,7 @@ global_space = 0; :(scenario global_space_with_names) def main [ - global-space:address:shared:array:location <- new location:type, 10 + global-space:address:array:location <- new location:type, 10 x:number <- copy 23 1:number/space:global <- copy 24 ] diff --git a/047check_type_by_name.cc b/047check_type_by_name.cc index ed45119f..5aa196ee 100644 --- a/047check_type_by_name.cc +++ b/047check_type_by_name.cc @@ -60,7 +60,7 @@ void check_type(set<reagent>& known, const reagent& x, const recipe& caller) { return; } if (!x.type->right->right) { - raise << caller.name << " can't determine the size of array variable " << x.name << ". Either allocate it separately and make the type of " << x.name << " address:shared:..., or specify the length of the array in the type of " << x.name << ".\n" << end(); + raise << caller.name << " can't determine the size of array variable " << x.name << ". Either allocate it separately and make the type of " << x.name << " address:..., or specify the length of the array in the type of " << x.name << ".\n" << end(); return; } } @@ -96,17 +96,17 @@ def main [ :(scenario typo_in_address_type_fails) % Hide_errors = true; def main [ - y:address:shared:charcter <- new character:type + y:address:charcter <- new character:type *y <- copy 67 ] -+error: main: unknown type charcter in 'y:address:shared:charcter <- new character:type' ++error: main: unknown type charcter in 'y:address:charcter <- new character:type' :(scenario array_type_without_size_fails) % Hide_errors = true; def main [ x:array:number <- merge 2, 12, 13 ] -+error: main can't determine the size of array variable x. Either allocate it separately and make the type of x address:shared:..., or specify the length of the array in the type of x. ++error: main can't determine the size of array variable x. Either allocate it separately and make the type of x address:..., or specify the length of the array in the type of x. :(scenarios transform) :(scenario transform_checks_types_of_identical_reagents_in_multiple_spaces) @@ -114,7 +114,7 @@ def foo [ # dummy ] def main [ local-scope - 0:address:shared:array:location/names:foo <- copy 0 # specify surrounding space + 0:address:array:location/names:foo <- copy 0 # specify surrounding space x:boolean <- copy 1/true x:number/space:1 <- copy 34 x/space:1 <- copy 35 diff --git a/050scenario.cc b/050scenario.cc index ef0ef4ff..97974a0a 100644 --- a/050scenario.cc +++ b/050scenario.cc @@ -99,9 +99,9 @@ scenario foo [ :(scenario read_scenario_with_bracket_in_comment_in_nested_string) scenario foo [ - 1:address:shared:array:character <- new [# not a comment] + 1:address:array:character <- new [# not a comment] ] -+run: {1: ("address" "shared" "array" "character")} <- new {"# not a comment": "literal-string"} ++run: {1: ("address" "array" "character")} <- new {"# not a comment": "literal-string"} //:: Run scenarios when we run 'mu test'. //: Treat the text of the scenario as a regular series of instructions. diff --git a/054parse_tree.cc b/054parse_tree.cc index 0ad8773f..b5082e58 100644 --- a/054parse_tree.cc +++ b/054parse_tree.cc @@ -71,11 +71,11 @@ container bar [ :(scenario dilated_reagent_in_static_array) def main [ - {1: (array (address shared number) 3)} <- create-array - 5:address:shared:number <- new number:type - {1: (array (address shared number) 3)} <- put-index {1: (array (address shared number) 3)}, 0, 5:address:shared:number - *5:address:shared:number <- copy 34 - 6:number <- copy *5:address:shared:number + {1: (array (address number) 3)} <- create-array + 5:address:number <- new number:type + {1: (array (address number) 3)} <- put-index {1: (array (address number) 3)}, 0, 5:address:number + *5:address:number <- copy 34 + 6:number <- copy *5:address:number ] +run: creating array of size 4 +mem: storing 34 in location 6 @@ -84,7 +84,7 @@ def main [ :(scenario dilated_reagent_with_new) def main [ - x:address:shared:address:number <- new {(address number): type} + x:address:address:number <- new {(address number): type} ] +new: size of ("address" "number") is 1 diff --git a/055recipe_header.cc b/055recipe_header.cc index cb95020a..a9ac73ba 100644 --- a/055recipe_header.cc +++ b/055recipe_header.cc @@ -220,54 +220,16 @@ void check_calls_against_header(const recipe_ordinal r) { // ingredients coerced from call to callee if (!types_coercible(callee.ingredients.at(i), inst.ingredients.at(i))) raise << maybe(caller.name) << "ingredient " << i << " has the wrong type at '" << to_original_string(inst) << "'\n" << end(); - if (is_unique_address(inst.ingredients.at(i))) - raise << maybe(caller.name) << "avoid passing non-shared addresses into calls, like ingredient " << i << " at '" << to_original_string(inst) << "'\n" << end(); } for (long int i = 0; i < min(SIZE(inst.products), SIZE(callee.products)); ++i) { if (is_dummy(inst.products.at(i))) continue; // products coerced from callee to call if (!types_coercible(inst.products.at(i), callee.products.at(i))) raise << maybe(caller.name) << "product " << i << " has the wrong type at '" << to_original_string(inst) << "'\n" << end(); - if (is_unique_address(inst.products.at(i))) - raise << maybe(caller.name) << "avoid getting non-shared addresses out of calls, like product " << i << " at '" << to_original_string(inst) << "'\n" << end(); } } } -bool is_unique_address(reagent x) { - if (!canonize_type(x)) return false; - if (!x.type) return false; - if (x.type->value != get(Type_ordinal, "address")) return false; - if (!x.type->right) return true; - return x.type->right->value != get(Type_ordinal, "shared"); -} - -//: additionally, flag an error on calls receiving non-shared addresses - -:(scenario forbid_calls_with_nonshared_addresses) -% Hide_errors = true; -def main [ - 1:address:number <- copy 0 - foo 1:address:number -] -def foo x:address:number [ - local-scope - load-ingredients -] -+error: main: avoid passing non-shared addresses into calls, like ingredient 0 at 'foo 1:address:number' - -:(scenario forbid_calls_with_nonshared_addresses_2) -% Hide_errors = true; -def main [ - 1:address:number <- foo -] -def foo -> x:address:number [ - local-scope - load-ingredients - x <- copy 0 -] -+error: main: avoid getting non-shared addresses out of calls, like product 0 at '1:address:number <- foo ' - //:: Check types going in and out of all recipes with headers. :(scenarios transform) diff --git a/056static_dispatch.cc b/056static_dispatch.cc index 1d57872d..ef99ae43 100644 --- a/056static_dispatch.cc +++ b/056static_dispatch.cc @@ -404,13 +404,13 @@ $error: 0 :(scenario static_dispatch_works_with_compound_type_containing_container_defined_after_first_use) def main [ - x:address:shared:foo <- new foo:type + x:address:foo <- new foo:type test x ] container foo [ x:number ] -def test a:address:shared:foo -> z:number [ +def test a:address:foo -> z:number [ local-scope load-ingredients z:number <- get *a, x:offset @@ -419,10 +419,10 @@ $error: 0 :(scenario static_dispatch_works_with_compound_type_containing_container_defined_after_second_use) def main [ - x:address:shared:foo <- new foo:type + x:address:foo <- new foo:type test x ] -def test a:address:shared:foo -> z:number [ +def test a:address:foo -> z:number [ local-scope load-ingredients z:number <- get *a, x:offset diff --git a/057shape_shifting_container.cc b/057shape_shifting_container.cc index 40ec3521..d5eacbc2 100644 --- a/057shape_shifting_container.cc +++ b/057shape_shifting_container.cc @@ -32,9 +32,9 @@ container foo:_a:_b [ y:_b ] def main [ - 1:address:shared:array:character <- new [abc] + 1:address:array:character <- new [abc] # compound types for type ingredients - {2: (foo number (address shared array character))} <- merge 34/x, 1:address:shared:array:character/y + {2: (foo number (address array character))} <- merge 34/x, 1:address:array:character/y ] $error: 0 @@ -45,11 +45,11 @@ container foo:_a:_b [ ] container bar:_a:_b [ # dilated element - {data: (foo _a (address shared _b))} + {data: (foo _a (address _b))} ] def main [ - 1:address:shared:array:character <- new [abc] - 2:bar:number:array:character <- merge 34/x, 1:address:shared:array:character/y + 1:address:array:character <- new [abc] + 2:bar:number:array:character <- merge 34/x, 1:address:array:character/y ] $error: 0 @@ -156,9 +156,9 @@ container foo:_t [ ] def main [ 1:foo:address:point <- merge 34/unsafe, 48 - 2:address:point <- get 1:foo:address:point, x:offset + 3:address:point <- get 1:foo:address:point, x:offset ] -+mem: storing 34 in location 2 ++mem: storing 34 in location 3 :(scenario get_on_shape_shifting_container_inside_container) container foo:_t [ @@ -181,10 +181,10 @@ container foo:_a:_b [ y:_b ] def main [ - 1:address:shared:array:character <- new [abc] - {2: (foo number (address shared array character))} <- merge 34/x, 1:address:shared:array:character/y - 3:address:shared:array:character <- get {2: (foo number (address shared array character))}, y:offset - 4:boolean <- equal 1:address:shared:array:character, 3:address:shared:array:character + 1:address:array:character <- new [abc] + {2: (foo number (address array character))} <- merge 34/x, 1:address:array:character/y + 3:address:array:character <- get {2: (foo number (address array character))}, y:offset + 4:boolean <- equal 1:address:array:character, 3:address:array:character ] +mem: storing 1 in location 4 @@ -327,15 +327,14 @@ void test_replace_type_ingredients_head_tail_multiple() { "container bar:_elem [\n" " x:foo:_elem\n" "]\n"); - reagent callsite("x:bar:address:shared:array:character"); + reagent callsite("x:bar:address:array:character"); reagent element = element_type(callsite, 0); CHECK_EQ(element.name, "x"); CHECK_EQ(element.type->name, "foo"); CHECK_EQ(element.type->right->name, "address"); - CHECK_EQ(element.type->right->right->name, "shared"); - CHECK_EQ(element.type->right->right->right->name, "array"); - CHECK_EQ(element.type->right->right->right->right->name, "character"); - CHECK(!element.type->right->right->right->right->right); + CHECK_EQ(element.type->right->right->name, "array"); + CHECK_EQ(element.type->right->right->right->name, "character"); + CHECK(!element.type->right->right->right->right); } void test_replace_type_ingredients_head_middle() { @@ -362,7 +361,7 @@ void test_replace_last_type_ingredient_with_multiple() { " x:_a\n" " y:_b\n" "]\n"); - reagent callsite("{f: (foo number (address shared array character))}"); + reagent callsite("{f: (foo number (address array character))}"); reagent element1 = element_type(callsite, 0); CHECK_EQ(element1.name, "x"); CHECK_EQ(element1.type->name, "number"); @@ -370,10 +369,9 @@ void test_replace_last_type_ingredient_with_multiple() { reagent element2 = element_type(callsite, 1); CHECK_EQ(element2.name, "y"); CHECK_EQ(element2.type->name, "address"); - CHECK_EQ(element2.type->right->name, "shared"); - CHECK_EQ(element2.type->right->right->name, "array"); - CHECK_EQ(element2.type->right->right->right->name, "character"); - CHECK(!element2.type->right->right->right->right); + CHECK_EQ(element2.type->right->name, "array"); + CHECK_EQ(element2.type->right->right->name, "character"); + CHECK(!element2.type->right->right->right); } void test_replace_middle_type_ingredient_with_multiple() { @@ -382,7 +380,7 @@ void test_replace_middle_type_ingredient_with_multiple() { " y:_b\n" " z:_c\n" "]\n"); - reagent callsite("{f: (foo number (address shared array character) boolean)}"); + reagent callsite("{f: (foo number (address array character) boolean)}"); reagent element1 = element_type(callsite, 0); CHECK_EQ(element1.name, "x"); CHECK_EQ(element1.type->name, "number"); @@ -390,10 +388,9 @@ void test_replace_middle_type_ingredient_with_multiple() { reagent element2 = element_type(callsite, 1); CHECK_EQ(element2.name, "y"); CHECK_EQ(element2.type->name, "address"); - CHECK_EQ(element2.type->right->name, "shared"); - CHECK_EQ(element2.type->right->right->name, "array"); - CHECK_EQ(element2.type->right->right->right->name, "character"); - CHECK(!element2.type->right->right->right->right); + CHECK_EQ(element2.type->right->name, "array"); + CHECK_EQ(element2.type->right->right->name, "character"); + CHECK(!element2.type->right->right->right); reagent element3 = element_type(callsite, 2); CHECK_EQ(element3.name, "z"); CHECK_EQ(element3.type->name, "boolean"); @@ -405,39 +402,36 @@ void test_replace_middle_type_ingredient_with_multiple2() { " key:_key\n" " value:_value\n" "]\n"); - reagent callsite("{f: (foo (address shared array character) number)}"); + reagent callsite("{f: (foo (address array character) number)}"); reagent element = element_type(callsite, 0); CHECK_EQ(element.name, "key"); CHECK_EQ(element.type->name, "address"); - CHECK_EQ(element.type->right->name, "shared"); - CHECK_EQ(element.type->right->right->name, "array"); - CHECK_EQ(element.type->right->right->right->name, "character"); - CHECK(!element.type->right->right->right->right); + CHECK_EQ(element.type->right->name, "array"); + CHECK_EQ(element.type->right->right->name, "character"); + CHECK(!element.type->right->right->right); } void test_replace_middle_type_ingredient_with_multiple3() { run("container foo_table:_key:_value [\n" - " data:address:shared:array:foo_table_row:_key:_value\n" + " data:address:array:foo_table_row:_key:_value\n" "]\n" "\n" "container foo_table_row:_key:_value [\n" " key:_key\n" " value:_value\n" "]\n"); - reagent callsite("{f: (foo_table (address shared array character) number)}"); + reagent callsite("{f: (foo_table (address array character) number)}"); reagent element = element_type(callsite, 0); CHECK_EQ(element.name, "data"); CHECK_EQ(element.type->name, "address"); - CHECK_EQ(element.type->right->name, "shared"); - CHECK_EQ(element.type->right->right->name, "array"); - CHECK_EQ(element.type->right->right->right->name, "foo_table_row"); - CHECK(element.type->right->right->right->right->left); - CHECK_EQ(element.type->right->right->right->right->left->name, "address"); - CHECK_EQ(element.type->right->right->right->right->left->right->name, "shared"); - CHECK_EQ(element.type->right->right->right->right->left->right->right->name, "array"); - CHECK_EQ(element.type->right->right->right->right->left->right->right->right->name, "character"); - CHECK_EQ(element.type->right->right->right->right->right->name, "number"); - CHECK(!element.type->right->right->right->right->right->right); + CHECK_EQ(element.type->right->name, "array"); + CHECK_EQ(element.type->right->right->name, "foo_table_row"); + CHECK(element.type->right->right->right->left); + CHECK_EQ(element.type->right->right->right->left->name, "address"); + CHECK_EQ(element.type->right->right->right->left->right->name, "array"); + CHECK_EQ(element.type->right->right->right->left->right->right->name, "character"); + CHECK_EQ(element.type->right->right->right->right->name, "number"); + CHECK(!element.type->right->right->right->right->right); } bool has_nth_type(const type_tree* base, int n) { diff --git a/058shape_shifting_recipe.cc b/058shape_shifting_recipe.cc index c046e72b..6067fe7e 100644 --- a/058shape_shifting_recipe.cc +++ b/058shape_shifting_recipe.cc @@ -561,8 +561,8 @@ container c:_a:_b [ b:_b ] def main [ - s:address:shared:array:character <- new [abc] - {x: (c (address shared array character) number)} <- merge s, 34 + s:address:array:character <- new [abc] + {x: (c (address array character) number)} <- merge s, 34 foo x ] def foo x:c:_bar:_baz [ @@ -599,14 +599,14 @@ def foo a:_t [ :(scenario shape_shifting_recipe_handles_shape_shifting_new_ingredient) def main [ - 1:address:shared:foo:point <- bar 3 - 11:foo:point <- copy *1:address:shared:foo:point + 1:address:foo:point <- bar 3 + 11:foo:point <- copy *1:address:foo:point ] container foo:_t [ x:_t y:number ] -def bar x:number -> result:address:shared:foo:_t [ +def bar x:number -> result:address:foo:_t [ local-scope load-ingredients # new refers to _t in its ingredient *value* @@ -618,10 +618,10 @@ def bar x:number -> result:address:shared:foo:_t [ :(scenario shape_shifting_recipe_handles_shape_shifting_new_ingredient_2) def main [ - 1:address:shared:foo:point <- bar 3 - 11:foo:point <- copy *1:address:shared:foo:point + 1:address:foo:point <- bar 3 + 11:foo:point <- copy *1:address:foo:point ] -def bar x:number -> result:address:shared:foo:_t [ +def bar x:number -> result:address:foo:_t [ local-scope load-ingredients # new refers to _t in its ingredient *value* @@ -640,7 +640,7 @@ container foo:_t [ def main [ _ <- bar 34 ] -def bar x:_t -> result:address:shared:_t [ +def bar x:_t -> result:address:_t [ local-scope load-ingredients result <- copy 0 @@ -656,7 +656,7 @@ void test_shape_shifting_new_ingredient_does_not_pollute_global_namespace() { transform("def barz x:_elem [\n" " local-scope\n" " load-ingredients\n" - " y:address:shared:number <- new _elem:type\n" + " y:address:number <- new _elem:type\n" "]\n" "def fooz [\n" " local-scope\n" @@ -678,10 +678,10 @@ void test_shape_shifting_new_ingredient_does_not_pollute_global_namespace() { :(scenario shape_shifting_recipe_supports_compound_types) def main [ - 1:address:shared:point <- new point:type - *1:address:shared:point <- put *1:address:shared:point, y:offset, 34 - 3:address:shared:point <- bar 1:address:shared:point # specialize _t to address:shared:point - 4:point <- copy *3:address:shared:point + 1:address:point <- new point:type + *1:address:point <- put *1:address:point, y:offset, 34 + 3:address:point <- bar 1:address:point # specialize _t to address:point + 4:point <- copy *3:address:point ] def bar a:_t -> result:_t [ local-scope @@ -694,13 +694,13 @@ def bar a:_t -> result:_t [ % Hide_errors = true; def main [ a:number <- copy 3 - b:address:shared:number <- foo a + b:address:number <- foo a ] def foo a:_t -> b:_t [ load-ingredients b <- copy a ] -+error: main: no call found for 'b:address:shared:number <- foo a' ++error: main: no call found for 'b:address:number <- foo a' :(scenario specialize_inside_recipe_without_header) def main [ @@ -748,7 +748,7 @@ def foo x:_elem -> y:_elem [ def main [ local-scope # permit '0' to map to address to shape-shifting type-ingredient - 1:address:shared:character/raw <- foo 0 + 1:address:character/raw <- foo 0 ] def foo x:address:_elem -> y:address:_elem [ local-scope @@ -818,7 +818,7 @@ container d2:_elem [ # static dispatch between shape-shifting variants, _including pointer lookups_ def main [ e1:d1:number <- merge 3 - e2:address:shared:d2:number <- new {(d2 number): type} + e2:address:d2:number <- new {(d2 number): type} 1:number/raw <- foo e1 2:number/raw <- foo *e2 # different from previous scenario ] @@ -901,15 +901,15 @@ def foo x:_elem -> y:number [ :(scenarios run) :(scenario specialize_most_similar_variant) def main [ - 1:address:shared:number <- new number:type - 2:number <- foo 1:address:shared:number + 1:address:number <- new number:type + 2:number <- foo 1:address:number ] def foo x:_elem -> y:number [ local-scope load-ingredients return 34 ] -def foo x:address:shared:_elem -> y:number [ +def foo x:address:_elem -> y:number [ local-scope load-ingredients return 35 @@ -920,17 +920,17 @@ def foo x:address:shared:_elem -> y:number [ # version with headers padded with lots of unrelated concrete types def main [ 1:number <- copy 23 - 2:address:shared:array:number <- copy 0 - 3:number <- foo 2:address:shared:array:number, 1:number + 2:address:array:number <- copy 0 + 3:number <- foo 2:address:array:number, 1:number ] # variant with concrete type -def foo dummy:address:shared:array:number, x:number -> y:number, dummy:address:shared:array:number [ +def foo dummy:address:array:number, x:number -> y:number, dummy:address:array:number [ local-scope load-ingredients return 34 ] # shape-shifting variant -def foo dummy:address:shared:array:number, x:_elem -> y:number, dummy:address:shared:array:number [ +def foo dummy:address:array:number, x:_elem -> y:number, dummy:address:array:number [ local-scope load-ingredients return 35 @@ -940,10 +940,10 @@ def foo dummy:address:shared:array:number, x:_elem -> y:number, dummy:address:sh :(scenario specialize_most_similar_variant_3) def main [ - 1:address:shared:array:character <- new [abc] - foo 1:address:shared:array:character + 1:address:array:character <- new [abc] + foo 1:address:array:character ] -def foo x:address:shared:array:character [ +def foo x:address:array:character [ 2:number <- copy 34 ] def foo x:address:_elem [ @@ -980,7 +980,7 @@ def foo x:number -> y:number [ return 34 ] # shape-shifting variant -def foo x:address:shared:_elem -> y:number [ +def foo x:address:_elem -> y:number [ local-scope load-ingredients return 35 diff --git a/062scheduler.cc b/062scheduler.cc index 6ffe15b3..a1209738 100644 --- a/062scheduler.cc +++ b/062scheduler.cc @@ -537,16 +537,16 @@ case LIMIT_TIME: { :(scenario new_concurrent) def f1 [ start-running f2 - 1:address:shared:number/raw <- new number:type + 1:address:number/raw <- new number:type # wait for f2 to complete { loop-unless 4:number/raw } ] def f2 [ - 2:address:shared:number/raw <- new number:type + 2:address:number/raw <- new number:type # hack: assumes scheduler implementation - 3:boolean/raw <- equal 1:address:shared:number/raw, 2:address:shared:number/raw + 3:boolean/raw <- equal 1:address:number/raw, 2:address:number/raw # signal f2 complete 4:number/raw <- copy 1 ] diff --git a/063wait.cc b/063wait.cc index 71e3123e..d25c5467 100644 --- a/063wait.cc +++ b/063wait.cc @@ -207,22 +207,24 @@ def main [ :(scenario get_location_indirect) # 'get-location' can read from container address def main [ - 1:number <- copy 2 - 2:number <- copy 34 - 3:number <- copy 35 + 1:number <- copy 10 + # 10 reserved for refcount + 11:number <- copy 34 + 12:number <- copy 35 4:location <- get-location 1:address:point/lookup, 0:offset ] -+mem: storing 2 in location 4 ++mem: storing 11 in location 4 -:(scenario get_location_indirect2) +:(scenario get_location_indirect_2) def main [ - 1:number <- copy 2 - 2:number <- copy 34 - 3:number <- copy 35 - 4:address:number <- copy 5/unsafe + 1:number <- copy 10 + # 10 reserved for refcount + 11:number <- copy 34 + 12:number <- copy 35 + 4:address:number <- copy 20/unsafe 4:address:location/lookup <- get-location 1:address:point/lookup, 0:offset ] -+mem: storing 2 in location 5 ++mem: storing 11 in location 21 //: also allow waiting on a routine to stop running diff --git a/064rewrite_literal_string.cc b/064rewrite_literal_string.cc index 88618be4..81260c5e 100644 --- a/064rewrite_literal_string.cc +++ b/064rewrite_literal_string.cc @@ -4,7 +4,7 @@ def main [ 1:number/raw <- foo [abc] ] -def foo x:address:shared:array:character -> n:number [ +def foo x:address:array:character -> n:number [ local-scope load-ingredients n <- length *x @@ -46,7 +46,7 @@ void rewrite_literal_string_to_text(recipe_ordinal r) { if (!is_literal_string(inst.ingredients.at(j))) continue; instruction def; ostringstream ingredient_name; - ingredient_name << inst.name << '_' << i << '_' << j << ":address:shared:array:character"; + ingredient_name << inst.name << '_' << i << '_' << j << ":address:array:character"; def.name = "new"; def.ingredients.push_back(inst.ingredients.at(j)); def.products.push_back(reagent(ingredient_name.str())); diff --git a/070text.mu b/070text.mu index 93fe3f41..49317557 100644 --- a/070text.mu +++ b/070text.mu @@ -2,27 +2,27 @@ # to-text-line gets called implicitly in various places # define it to be identical to 'to-text' by default -def to-text-line x:_elem -> y:address:shared:array:character [ +def to-text-line x:_elem -> y:address:array:character [ local-scope load-ingredients y <- to-text x ] # variant for arrays (since we can't pass them around otherwise) -def array-to-text-line x:address:shared:array:_elem -> y:address:shared:array:character [ +def array-to-text-line x:address:array:_elem -> y:address:array:character [ local-scope load-ingredients y <- to-text *x ] # to-text on text is just the identity function -def to-text x:address:shared:array:character -> y:address:shared:array:character [ +def to-text x:address:array:character -> y:address:array:character [ local-scope load-ingredients return x ] -def equal a:address:shared:array:character, b:address:shared:array:character -> result:boolean [ +def equal a:address:array:character, b:address:array:character -> result:boolean [ local-scope load-ingredients a-len:number <- length *a @@ -55,8 +55,8 @@ def equal a:address:shared:array:character, b:address:shared:array:character -> scenario text-equal-reflexive [ run [ - default-space:address:shared:array:location <- new location:type, 30 - x:address:shared:array:character <- new [abc] + default-space:address:array:location <- new location:type, 30 + x:address:array:character <- new [abc] 3:boolean/raw <- equal x, x ] memory-should-contain [ @@ -66,9 +66,9 @@ scenario text-equal-reflexive [ scenario text-equal-identical [ run [ - default-space:address:shared:array:location <- new location:type, 30 - x:address:shared:array:character <- new [abc] - y:address:shared:array:character <- new [abc] + default-space:address:array:location <- new location:type, 30 + x:address:array:character <- new [abc] + y:address:array:character <- new [abc] 3:boolean/raw <- equal x, y ] memory-should-contain [ @@ -78,9 +78,9 @@ scenario text-equal-identical [ scenario text-equal-distinct-lengths [ run [ - default-space:address:shared:array:location <- new location:type, 30 - x:address:shared:array:character <- new [abc] - y:address:shared:array:character <- new [abcd] + default-space:address:array:location <- new location:type, 30 + x:address:array:character <- new [abc] + y:address:array:character <- new [abcd] 3:boolean/raw <- equal x, y ] memory-should-contain [ @@ -96,9 +96,9 @@ scenario text-equal-distinct-lengths [ scenario text-equal-with-empty [ run [ - default-space:address:shared:array:location <- new location:type, 30 - x:address:shared:array:character <- new [] - y:address:shared:array:character <- new [abcd] + default-space:address:array:location <- new location:type, 30 + x:address:array:character <- new [] + y:address:array:character <- new [abcd] 3:boolean/raw <- equal x, y ] memory-should-contain [ @@ -108,9 +108,9 @@ scenario text-equal-with-empty [ scenario text-equal-common-lengths-but-distinct [ run [ - default-space:address:shared:array:location <- new location:type, 30 - x:address:shared:array:character <- new [abc] - y:address:shared:array:character <- new [abd] + default-space:address:array:location <- new location:type, 30 + x:address:array:character <- new [abc] + y:address:array:character <- new [abd] 3:boolean/raw <- equal x, y ] memory-should-contain [ @@ -121,27 +121,27 @@ scenario text-equal-common-lengths-but-distinct [ # A new type to help incrementally construct texts. container buffer [ length:number - data:address:shared:array:character + data:address:array:character ] -def new-buffer capacity:number -> result:address:shared:buffer [ +def new-buffer capacity:number -> result:address:buffer [ local-scope load-ingredients result <- new buffer:type *result <- put *result, length:offset, 0 - data:address:shared:array:character <- new character:type, capacity + data:address:array:character <- new character:type, capacity *result <- put *result, data:offset, data return result ] -def grow-buffer in:address:shared:buffer -> in:address:shared:buffer [ +def grow-buffer in:address:buffer -> in:address:buffer [ local-scope load-ingredients # double buffer size - olddata:address:shared:array:character <- get *in, data:offset + olddata:address:array:character <- get *in, data:offset oldlen:number <- length *olddata newlen:number <- multiply oldlen, 2 - newdata:address:shared:array:character <- new character:type, newlen + newdata:address:array:character <- new character:type, newlen *in <- put *in, data:offset, newdata # copy old contents i:number <- copy 0 @@ -155,20 +155,20 @@ def grow-buffer in:address:shared:buffer -> in:address:shared:buffer [ } ] -def buffer-full? in:address:shared:buffer -> result:boolean [ +def buffer-full? in:address:buffer -> result:boolean [ local-scope load-ingredients len:number <- get *in, length:offset - s:address:shared:array:character <- get *in, data:offset + s:address:array:character <- get *in, data:offset capacity:number <- length *s result <- greater-or-equal len, capacity ] # most broadly applicable definition of append to a buffer: just call to-text -def append buf:address:shared:buffer, x:_elem -> buf:address:shared:buffer [ +def append buf:address:buffer, x:_elem -> buf:address:buffer [ local-scope load-ingredients - text:address:shared:array:character <- to-text x + text:address:array:character <- to-text x len:number <- length *text i:number <- copy 0 { @@ -181,7 +181,7 @@ def append buf:address:shared:buffer, x:_elem -> buf:address:shared:buffer [ } ] -def append in:address:shared:buffer, c:character -> in:address:shared:buffer [ +def append in:address:buffer, c:character -> in:address:buffer [ local-scope load-ingredients len:number <- get *in, length:offset @@ -201,7 +201,7 @@ def append in:address:shared:buffer, c:character -> in:address:shared:buffer [ break-unless full? in <- grow-buffer in } - s:address:shared:array:character <- get *in, data:offset + s:address:array:character <- get *in, data:offset *s <- put-index *s, len, c len <- add len, 1 *in <- put *in, length:offset, len @@ -210,21 +210,21 @@ def append in:address:shared:buffer, c:character -> in:address:shared:buffer [ scenario buffer-append-works [ run [ local-scope - x:address:shared:buffer <- new-buffer 3 - s1:address:shared:array:character <- get *x, data:offset + x:address:buffer <- new-buffer 3 + s1:address:array:character <- get *x, data:offset c:character <- copy 97/a x <- append x, c c:character <- copy 98/b x <- append x, c c:character <- copy 99/c x <- append x, c - s2:address:shared:array:character <- get *x, data:offset + s2:address:array:character <- get *x, data:offset 1:boolean/raw <- equal s1, s2 2:array:character/raw <- copy *s2 +buffer-filled c:character <- copy 100/d x <- append x, c - s3:address:shared:array:character <- get *x, data:offset + s3:address:array:character <- get *x, data:offset 10:boolean/raw <- equal s1, s3 11:number/raw <- get *x, length:offset 12:array:character/raw <- copy *s3 @@ -252,14 +252,14 @@ scenario buffer-append-works [ scenario buffer-append-handles-backspace [ run [ local-scope - x:address:shared:buffer <- new-buffer 3 + x:address:buffer <- new-buffer 3 c:character <- copy 97/a x <- append x, c c:character <- copy 98/b x <- append x, c c:character <- copy 8/backspace x <- append x, c - s:address:shared:array:character <- buffer-to-array x + s:address:array:character <- buffer-to-array x 1:array:character/raw <- copy *s ] memory-should-contain [ @@ -269,7 +269,7 @@ scenario buffer-append-handles-backspace [ ] ] -def to-text n:number -> result:address:shared:array:character [ +def to-text n:number -> result:address:array:character [ local-scope load-ingredients # is n zero? @@ -287,14 +287,14 @@ def to-text n:number -> result:address:shared:array:character [ n <- multiply n, -1 } # add digits from right to left into intermediate buffer - tmp:address:shared:buffer <- new-buffer 30 + tmp:address:buffer <- new-buffer 30 digit-base:number <- copy 48 # '0' { done?:boolean <- equal n, 0 break-if done? n, digit:number <- divide-with-remainder n, 10 c:character <- add digit-base, digit - tmp:address:shared:buffer <- append tmp, c + tmp:address:buffer <- append tmp, c loop } # add sign @@ -305,7 +305,7 @@ def to-text n:number -> result:address:shared:array:character [ } # reverse buffer into text result len:number <- get *tmp, length:offset - buf:address:shared:array:character <- get *tmp, data:offset + buf:address:array:character <- get *tmp, data:offset result <- new character:type, len i:number <- subtract len, 1 # source index, decreasing j:number <- copy 0 # destination index, increasing @@ -322,21 +322,21 @@ def to-text n:number -> result:address:shared:array:character [ } ] -def to-text x:boolean -> result:address:shared:array:character [ +def to-text x:boolean -> result:address:array:character [ local-scope load-ingredients n:number <- copy x:boolean result <- to-text n ] -def to-text x:address:_elem -> result:address:shared:array:character [ +def to-text x:address:_elem -> result:address:array:character [ local-scope load-ingredients n:number <- copy x result <- to-text n ] -def buffer-to-array in:address:shared:buffer -> result:address:shared:array:character [ +def buffer-to-array in:address:buffer -> result:address:array:character [ local-scope load-ingredients { @@ -345,7 +345,7 @@ def buffer-to-array in:address:shared:buffer -> result:address:shared:array:char return 0 } len:number <- get *in, length:offset - s:address:shared:array:character <- get *in, data:offset + s:address:array:character <- get *in, data:offset # we can't just return s because it is usually the wrong length result <- new character:type, len i:number <- copy 0 @@ -361,8 +361,8 @@ def buffer-to-array in:address:shared:buffer -> result:address:shared:array:char scenario integer-to-decimal-digit-zero [ run [ - 1:address:shared:array:character/raw <- to-text 0 - 2:array:character/raw <- copy *1:address:shared:array:character/raw + 1:address:array:character/raw <- to-text 0 + 2:array:character/raw <- copy *1:address:array:character/raw ] memory-should-contain [ 2:array:character <- [0] @@ -371,8 +371,8 @@ scenario integer-to-decimal-digit-zero [ scenario integer-to-decimal-digit-positive [ run [ - 1:address:shared:array:character/raw <- to-text 234 - 2:array:character/raw <- copy *1:address:shared:array:character/raw + 1:address:array:character/raw <- to-text 234 + 2:array:character/raw <- copy *1:address:array:character/raw ] memory-should-contain [ 2:array:character <- [234] @@ -381,8 +381,8 @@ scenario integer-to-decimal-digit-positive [ scenario integer-to-decimal-digit-negative [ run [ - 1:address:shared:array:character/raw <- to-text -1 - 2:array:character/raw <- copy *1:address:shared:array:character/raw + 1:address:array:character/raw <- to-text -1 + 2:array:character/raw <- copy *1:address:array:character/raw ] memory-should-contain [ 2 <- 2 @@ -391,7 +391,7 @@ scenario integer-to-decimal-digit-negative [ ] ] -def append a:address:shared:array:character, b:address:shared:array:character -> result:address:shared:array:character [ +def append a:address:array:character, b:address:array:character -> result:address:array:character [ local-scope load-ingredients # result = new character[a.length + b.length] @@ -430,10 +430,10 @@ def append a:address:shared:array:character, b:address:shared:array:character -> scenario text-append-1 [ run [ - 1:address:shared:array:character/raw <- new [hello,] - 2:address:shared:array:character/raw <- new [ world!] - 3:address:shared:array:character/raw <- append 1:address:shared:array:character/raw, 2:address:shared:array:character/raw - 4:array:character/raw <- copy *3:address:shared:array:character/raw + 1:address:array:character/raw <- new [hello,] + 2:address:array:character/raw <- new [ world!] + 3:address:array:character/raw <- append 1:address:array:character/raw, 2:address:array:character/raw + 4:array:character/raw <- copy *3:address:array:character/raw ] memory-should-contain [ 4:array:character <- [hello, world!] @@ -442,16 +442,16 @@ scenario text-append-1 [ scenario replace-character-in-text [ run [ - 1:address:shared:array:character/raw <- new [abc] - 1:address:shared:array:character/raw <- replace 1:address:shared:array:character/raw, 98/b, 122/z - 2:array:character/raw <- copy *1:address:shared:array:character/raw + 1:address:array:character/raw <- new [abc] + 1:address:array:character/raw <- replace 1:address:array:character/raw, 98/b, 122/z + 2:array:character/raw <- copy *1:address:array:character/raw ] memory-should-contain [ 2:array:character <- [azc] ] ] -def replace s:address:shared:array:character, oldc:character, newc:character, from:number/optional -> s:address:shared:array:character [ +def replace s:address:array:character, oldc:character, newc:character, from:number/optional -> s:address:array:character [ local-scope load-ingredients len:number <- length *s @@ -465,9 +465,9 @@ def replace s:address:shared:array:character, oldc:character, newc:character, fr scenario replace-character-at-start [ run [ - 1:address:shared:array:character/raw <- new [abc] - 1:address:shared:array:character/raw <- replace 1:address:shared:array:character/raw, 97/a, 122/z - 2:array:character/raw <- copy *1:address:shared:array:character/raw + 1:address:array:character/raw <- new [abc] + 1:address:array:character/raw <- replace 1:address:array:character/raw, 97/a, 122/z + 2:array:character/raw <- copy *1:address:array:character/raw ] memory-should-contain [ 2:array:character <- [zbc] @@ -476,9 +476,9 @@ scenario replace-character-at-start [ scenario replace-character-at-end [ run [ - 1:address:shared:array:character/raw <- new [abc] - 1:address:shared:array:character/raw <- replace 1:address:shared:array:character/raw, 99/c, 122/z - 2:array:character/raw <- copy *1:address:shared:array:character/raw + 1:address:array:character/raw <- new [abc] + 1:address:array:character/raw <- replace 1:address:array:character/raw, 99/c, 122/z + 2:array:character/raw <- copy *1:address:array:character/raw ] memory-should-contain [ 2:array:character <- [abz] @@ -487,9 +487,9 @@ scenario replace-character-at-end [ scenario replace-character-missing [ run [ - 1:address:shared:array:character/raw <- new [abc] - 1:address:shared:array:character/raw <- replace 1:address:shared:array:character/raw, 100/d, 122/z - 2:array:character/raw <- copy *1:address:shared:array:character/raw + 1:address:array:character/raw <- new [abc] + 1:address:array:character/raw <- replace 1:address:array:character/raw, 100/d, 122/z + 2:array:character/raw <- copy *1:address:array:character/raw ] memory-should-contain [ 2:array:character <- [abc] @@ -498,9 +498,9 @@ scenario replace-character-missing [ scenario replace-all-characters [ run [ - 1:address:shared:array:character/raw <- new [banana] - 1:address:shared:array:character/raw <- replace 1:address:shared:array:character/raw, 97/a, 122/z - 2:array:character/raw <- copy *1:address:shared:array:character/raw + 1:address:array:character/raw <- new [banana] + 1:address:array:character/raw <- replace 1:address:array:character/raw, 97/a, 122/z + 2:array:character/raw <- copy *1:address:array:character/raw ] memory-should-contain [ 2:array:character <- [bznznz] @@ -508,7 +508,7 @@ scenario replace-all-characters [ ] # replace underscores in first with remaining args -def interpolate template:address:shared:array:character -> result:address:shared:array:character [ +def interpolate template:address:array:character -> result:address:array:character [ local-scope load-ingredients # consume just the template # compute result-len, space to allocate for result @@ -516,7 +516,7 @@ def interpolate template:address:shared:array:character -> result:address:shared result-len:number <- copy tem-len { # while ingredients remain - a:address:shared:array:character, arg-received?:boolean <- next-ingredient + a:address:array:character, arg-received?:boolean <- next-ingredient break-unless arg-received? # result-len = result-len + arg.length - 1 (for the 'underscore' being replaced) a-len:number <- length *a @@ -532,7 +532,7 @@ def interpolate template:address:shared:array:character -> result:address:shared i:number <- copy 0 { # while arg received - a:address:shared:array:character, arg-received?:boolean <- next-ingredient + a:address:array:character, arg-received?:boolean <- next-ingredient break-unless arg-received? # copy template into result until '_' { @@ -583,10 +583,10 @@ def interpolate template:address:shared:array:character -> result:address:shared scenario interpolate-works [ run [ - 1:address:shared:array:character/raw <- new [abc _] - 2:address:shared:array:character/raw <- new [def] - 3:address:shared:array:character/raw <- interpolate 1:address:shared:array:character/raw, 2:address:shared:array:character/raw - 4:array:character/raw <- copy *3:address:shared:array:character/raw + 1:address:array:character/raw <- new [abc _] + 2:address:array:character/raw <- new [def] + 3:address:array:character/raw <- interpolate 1:address:array:character/raw, 2:address:array:character/raw + 4:array:character/raw <- copy *3:address:array:character/raw ] memory-should-contain [ 4:array:character <- [abc def] @@ -595,10 +595,10 @@ scenario interpolate-works [ scenario interpolate-at-start [ run [ - 1:address:shared:array:character/raw <- new [_, hello!] - 2:address:shared:array:character/raw <- new [abc] - 3:address:shared:array:character/raw <- interpolate 1:address:shared:array:character/raw, 2:address:shared:array:character/raw - 4:array:character/raw <- copy *3:address:shared:array:character/raw + 1:address:array:character/raw <- new [_, hello!] + 2:address:array:character/raw <- new [abc] + 3:address:array:character/raw <- interpolate 1:address:array:character/raw, 2:address:array:character/raw + 4:array:character/raw <- copy *3:address:array:character/raw ] memory-should-contain [ 4:array:character <- [abc, hello!] @@ -608,10 +608,10 @@ scenario interpolate-at-start [ scenario interpolate-at-end [ run [ - 1:address:shared:array:character/raw <- new [hello, _] - 2:address:shared:array:character/raw <- new [abc] - 3:address:shared:array:character/raw <- interpolate 1:address:shared:array:character/raw, 2:address:shared:array:character/raw - 4:array:character/raw <- copy *3:address:shared:array:character/raw + 1:address:array:character/raw <- new [hello, _] + 2:address:array:character/raw <- new [abc] + 3:address:array:character/raw <- interpolate 1:address:array:character/raw, 2:address:array:character/raw + 4:array:character/raw <- copy *3:address:array:character/raw ] memory-should-contain [ 4:array:character <- [hello, abc] @@ -680,7 +680,7 @@ def space? c:character -> result:boolean [ result <- equal c, 12288/ideographic-space ] -def trim s:address:shared:array:character -> result:address:shared:array:character [ +def trim s:address:array:character -> result:address:array:character [ local-scope load-ingredients len:number <- length *s @@ -712,7 +712,7 @@ def trim s:address:shared:array:character -> result:address:shared:array:charact } # result = new character[end+1 - start] new-len:number <- subtract end, start, -1 - result:address:shared:array:character <- new character:type, new-len + result:address:array:character <- new character:type, new-len # copy the untrimmed parts between start and end i:number <- copy start j:number <- copy 0 @@ -731,9 +731,9 @@ def trim s:address:shared:array:character -> result:address:shared:array:charact scenario trim-unmodified [ run [ - 1:address:shared:array:character <- new [abc] - 2:address:shared:array:character <- trim 1:address:shared:array:character - 3:array:character <- copy *2:address:shared:array:character + 1:address:array:character <- new [abc] + 2:address:array:character <- trim 1:address:array:character + 3:array:character <- copy *2:address:array:character ] memory-should-contain [ 3:array:character <- [abc] @@ -742,9 +742,9 @@ scenario trim-unmodified [ scenario trim-left [ run [ - 1:address:shared:array:character <- new [ abc] - 2:address:shared:array:character <- trim 1:address:shared:array:character - 3:array:character <- copy *2:address:shared:array:character + 1:address:array:character <- new [ abc] + 2:address:array:character <- trim 1:address:array:character + 3:array:character <- copy *2:address:array:character ] memory-should-contain [ 3:array:character <- [abc] @@ -753,9 +753,9 @@ scenario trim-left [ scenario trim-right [ run [ - 1:address:shared:array:character <- new [abc ] - 2:address:shared:array:character <- trim 1:address:shared:array:character - 3:array:character <- copy *2:address:shared:array:character + 1:address:array:character <- new [abc ] + 2:address:array:character <- trim 1:address:array:character + 3:array:character <- copy *2:address:array:character ] memory-should-contain [ 3:array:character <- [abc] @@ -764,9 +764,9 @@ scenario trim-right [ scenario trim-left-right [ run [ - 1:address:shared:array:character <- new [ abc ] - 2:address:shared:array:character <- trim 1:address:shared:array:character - 3:array:character <- copy *2:address:shared:array:character + 1:address:array:character <- new [ abc ] + 2:address:array:character <- trim 1:address:array:character + 3:array:character <- copy *2:address:array:character ] memory-should-contain [ 3:array:character <- [abc] @@ -775,17 +775,17 @@ scenario trim-left-right [ scenario trim-newline-tab [ run [ - 1:address:shared:array:character <- new [ abc + 1:address:array:character <- new [ abc ] - 2:address:shared:array:character <- trim 1:address:shared:array:character - 3:array:character <- copy *2:address:shared:array:character + 2:address:array:character <- trim 1:address:array:character + 3:array:character <- copy *2:address:array:character ] memory-should-contain [ 3:array:character <- [abc] ] ] -def find-next text:address:shared:array:character, pattern:character, idx:number -> next-index:number [ +def find-next text:address:array:character, pattern:character, idx:number -> next-index:number [ local-scope load-ingredients len:number <- length *text @@ -803,8 +803,8 @@ def find-next text:address:shared:array:character, pattern:character, idx:number scenario text-find-next [ run [ - 1:address:shared:array:character <- new [a/b] - 2:number <- find-next 1:address:shared:array:character, 47/slash, 0/start-index + 1:address:array:character <- new [a/b] + 2:number <- find-next 1:address:array:character, 47/slash, 0/start-index ] memory-should-contain [ 2 <- 1 @@ -813,8 +813,8 @@ scenario text-find-next [ scenario text-find-next-empty [ run [ - 1:address:shared:array:character <- new [] - 2:number <- find-next 1:address:shared:array:character, 47/slash, 0/start-index + 1:address:array:character <- new [] + 2:number <- find-next 1:address:array:character, 47/slash, 0/start-index ] memory-should-contain [ 2 <- 0 @@ -823,8 +823,8 @@ scenario text-find-next-empty [ scenario text-find-next-initial [ run [ - 1:address:shared:array:character <- new [/abc] - 2:number <- find-next 1:address:shared:array:character, 47/slash, 0/start-index + 1:address:array:character <- new [/abc] + 2:number <- find-next 1:address:array:character, 47/slash, 0/start-index ] memory-should-contain [ 2 <- 0 # prefix match @@ -833,8 +833,8 @@ scenario text-find-next-initial [ scenario text-find-next-final [ run [ - 1:address:shared:array:character <- new [abc/] - 2:number <- find-next 1:address:shared:array:character, 47/slash, 0/start-index + 1:address:array:character <- new [abc/] + 2:number <- find-next 1:address:array:character, 47/slash, 0/start-index ] memory-should-contain [ 2 <- 3 # suffix match @@ -843,8 +843,8 @@ scenario text-find-next-final [ scenario text-find-next-missing [ run [ - 1:address:shared:array:character <- new [abc] - 2:number <- find-next 1:address:shared:array:character, 47/slash, 0/start-index + 1:address:array:character <- new [abc] + 2:number <- find-next 1:address:array:character, 47/slash, 0/start-index ] memory-should-contain [ 2 <- 3 # no match @@ -853,8 +853,8 @@ scenario text-find-next-missing [ scenario text-find-next-invalid-index [ run [ - 1:address:shared:array:character <- new [abc] - 2:number <- find-next 1:address:shared:array:character, 47/slash, 4/start-index + 1:address:array:character <- new [abc] + 2:number <- find-next 1:address:array:character, 47/slash, 4/start-index ] memory-should-contain [ 2 <- 4 # no change @@ -863,8 +863,8 @@ scenario text-find-next-invalid-index [ scenario text-find-next-first [ run [ - 1:address:shared:array:character <- new [ab/c/] - 2:number <- find-next 1:address:shared:array:character, 47/slash, 0/start-index + 1:address:array:character <- new [ab/c/] + 2:number <- find-next 1:address:array:character, 47/slash, 0/start-index ] memory-should-contain [ 2 <- 2 # first '/' of multiple @@ -873,8 +873,8 @@ scenario text-find-next-first [ scenario text-find-next-second [ run [ - 1:address:shared:array:character <- new [ab/c/] - 2:number <- find-next 1:address:shared:array:character, 47/slash, 3/start-index + 1:address:array:character <- new [ab/c/] + 2:number <- find-next 1:address:array:character, 47/slash, 3/start-index ] memory-should-contain [ 2 <- 4 # second '/' of multiple @@ -883,7 +883,7 @@ scenario text-find-next-second [ # search for a pattern of multiple characters # fairly dumb algorithm -def find-next text:address:shared:array:character, pattern:address:shared:array:character, idx:number -> next-index:number [ +def find-next text:address:array:character, pattern:address:array:character, idx:number -> next-index:number [ local-scope load-ingredients first:character <- index *pattern, 0 @@ -905,9 +905,9 @@ def find-next text:address:shared:array:character, pattern:address:shared:array: scenario find-next-text-1 [ run [ - 1:address:shared:array:character <- new [abc] - 2:address:shared:array:character <- new [bc] - 3:number <- find-next 1:address:shared:array:character, 2:address:shared:array:character, 0 + 1:address:array:character <- new [abc] + 2:address:array:character <- new [bc] + 3:number <- find-next 1:address:array:character, 2:address:array:character, 0 ] memory-should-contain [ 3 <- 1 @@ -916,9 +916,9 @@ scenario find-next-text-1 [ scenario find-next-text-2 [ run [ - 1:address:shared:array:character <- new [abcd] - 2:address:shared:array:character <- new [bc] - 3:number <- find-next 1:address:shared:array:character, 2:address:shared:array:character, 1 + 1:address:array:character <- new [abcd] + 2:address:array:character <- new [bc] + 3:number <- find-next 1:address:array:character, 2:address:array:character, 1 ] memory-should-contain [ 3 <- 1 @@ -927,9 +927,9 @@ scenario find-next-text-2 [ scenario find-next-no-match [ run [ - 1:address:shared:array:character <- new [abc] - 2:address:shared:array:character <- new [bd] - 3:number <- find-next 1:address:shared:array:character, 2:address:shared:array:character, 0 + 1:address:array:character <- new [abc] + 2:address:array:character <- new [bd] + 3:number <- find-next 1:address:array:character, 2:address:array:character, 0 ] memory-should-contain [ 3 <- 3 # not found @@ -938,9 +938,9 @@ scenario find-next-no-match [ scenario find-next-suffix-match [ run [ - 1:address:shared:array:character <- new [abcd] - 2:address:shared:array:character <- new [cd] - 3:number <- find-next 1:address:shared:array:character, 2:address:shared:array:character, 0 + 1:address:array:character <- new [abcd] + 2:address:array:character <- new [cd] + 3:number <- find-next 1:address:array:character, 2:address:array:character, 0 ] memory-should-contain [ 3 <- 2 @@ -949,9 +949,9 @@ scenario find-next-suffix-match [ scenario find-next-suffix-match-2 [ run [ - 1:address:shared:array:character <- new [abcd] - 2:address:shared:array:character <- new [cde] - 3:number <- find-next 1:address:shared:array:character, 2:address:shared:array:character, 0 + 1:address:array:character <- new [abcd] + 2:address:array:character <- new [cde] + 3:number <- find-next 1:address:array:character, 2:address:array:character, 0 ] memory-should-contain [ 3 <- 4 # not found @@ -959,7 +959,7 @@ scenario find-next-suffix-match-2 [ ] # checks if pattern matches at index 'idx' -def match-at text:address:shared:array:character, pattern:address:shared:array:character, idx:number -> result:boolean [ +def match-at text:address:array:character, pattern:address:array:character, idx:number -> result:boolean [ local-scope load-ingredients pattern-len:number <- length *pattern @@ -992,9 +992,9 @@ def match-at text:address:shared:array:character, pattern:address:shared:array:c scenario match-at-checks-pattern-at-index [ run [ - 1:address:shared:array:character <- new [abc] - 2:address:shared:array:character <- new [ab] - 3:boolean <- match-at 1:address:shared:array:character, 2:address:shared:array:character, 0 + 1:address:array:character <- new [abc] + 2:address:array:character <- new [ab] + 3:boolean <- match-at 1:address:array:character, 2:address:array:character, 0 ] memory-should-contain [ 3 <- 1 # match found @@ -1003,8 +1003,8 @@ scenario match-at-checks-pattern-at-index [ scenario match-at-reflexive [ run [ - 1:address:shared:array:character <- new [abc] - 3:boolean <- match-at 1:address:shared:array:character, 1:address:shared:array:character, 0 + 1:address:array:character <- new [abc] + 3:boolean <- match-at 1:address:array:character, 1:address:array:character, 0 ] memory-should-contain [ 3 <- 1 # match found @@ -1013,9 +1013,9 @@ scenario match-at-reflexive [ scenario match-at-outside-bounds [ run [ - 1:address:shared:array:character <- new [abc] - 2:address:shared:array:character <- new [a] - 3:boolean <- match-at 1:address:shared:array:character, 2:address:shared:array:character, 4 + 1:address:array:character <- new [abc] + 2:address:array:character <- new [a] + 3:boolean <- match-at 1:address:array:character, 2:address:array:character, 4 ] memory-should-contain [ 3 <- 0 # never matches @@ -1024,9 +1024,9 @@ scenario match-at-outside-bounds [ scenario match-at-empty-pattern [ run [ - 1:address:shared:array:character <- new [abc] - 2:address:shared:array:character <- new [] - 3:boolean <- match-at 1:address:shared:array:character, 2:address:shared:array:character, 0 + 1:address:array:character <- new [abc] + 2:address:array:character <- new [] + 3:boolean <- match-at 1:address:array:character, 2:address:array:character, 0 ] memory-should-contain [ 3 <- 1 # always matches empty pattern given a valid index @@ -1035,9 +1035,9 @@ scenario match-at-empty-pattern [ scenario match-at-empty-pattern-outside-bound [ run [ - 1:address:shared:array:character <- new [abc] - 2:address:shared:array:character <- new [] - 3:boolean <- match-at 1:address:shared:array:character, 2:address:shared:array:character, 4 + 1:address:array:character <- new [abc] + 2:address:array:character <- new [] + 3:boolean <- match-at 1:address:array:character, 2:address:array:character, 4 ] memory-should-contain [ 3 <- 0 # no match @@ -1046,9 +1046,9 @@ scenario match-at-empty-pattern-outside-bound [ scenario match-at-empty-text [ run [ - 1:address:shared:array:character <- new [] - 2:address:shared:array:character <- new [abc] - 3:boolean <- match-at 1:address:shared:array:character, 2:address:shared:array:character, 0 + 1:address:array:character <- new [] + 2:address:array:character <- new [abc] + 3:boolean <- match-at 1:address:array:character, 2:address:array:character, 0 ] memory-should-contain [ 3 <- 0 # no match @@ -1057,8 +1057,8 @@ scenario match-at-empty-text [ scenario match-at-empty-against-empty [ run [ - 1:address:shared:array:character <- new [] - 3:boolean <- match-at 1:address:shared:array:character, 1:address:shared:array:character, 0 + 1:address:array:character <- new [] + 3:boolean <- match-at 1:address:array:character, 1:address:array:character, 0 ] memory-should-contain [ 3 <- 1 # matches because pattern is also empty @@ -1067,9 +1067,9 @@ scenario match-at-empty-against-empty [ scenario match-at-inside-bounds [ run [ - 1:address:shared:array:character <- new [abc] - 2:address:shared:array:character <- new [bc] - 3:boolean <- match-at 1:address:shared:array:character, 2:address:shared:array:character, 1 + 1:address:array:character <- new [abc] + 2:address:array:character <- new [bc] + 3:boolean <- match-at 1:address:array:character, 2:address:array:character, 1 ] memory-should-contain [ 3 <- 1 # match @@ -1078,16 +1078,16 @@ scenario match-at-inside-bounds [ scenario match-at-inside-bounds-2 [ run [ - 1:address:shared:array:character <- new [abc] - 2:address:shared:array:character <- new [bc] - 3:boolean <- match-at 1:address:shared:array:character, 2:address:shared:array:character, 0 + 1:address:array:character <- new [abc] + 2:address:array:character <- new [bc] + 3:boolean <- match-at 1:address:array:character, 2:address:array:character, 0 ] memory-should-contain [ 3 <- 0 # no match ] ] -def split s:address:shared:array:character, delim:character -> result:address:shared:array:address:shared:array:character [ +def split s:address:array:character, delim:character -> result:address:array:address:array:character [ local-scope load-ingredients # empty text? return empty array @@ -1095,7 +1095,7 @@ def split s:address:shared:array:character, delim:character -> result:address:sh { empty?:boolean <- equal len, 0 break-unless empty? - result <- new {(address shared array character): type}, 0 + result <- new {(address array character): type}, 0 return } # count #pieces we need room for @@ -1110,7 +1110,7 @@ def split s:address:shared:array:character, delim:character -> result:address:sh loop } # allocate space - result <- new {(address shared array character): type}, count + result <- new {(address array character): type}, count # repeatedly copy slices start..end until delimiter into result[curr-result] curr-result:number <- copy 0 start:number <- copy 0 @@ -1120,7 +1120,7 @@ def split s:address:shared:array:character, delim:character -> result:address:sh break-if done? end:number <- find-next s, delim, start # copy start..end into result[curr-result] - dest:address:shared:array:character <- copy-range s, start, end + dest:address:array:character <- copy-range s, start, end *result <- put-index *result, curr-result, dest # slide over to next slice start <- add end, 1 @@ -1131,13 +1131,13 @@ def split s:address:shared:array:character, delim:character -> result:address:sh scenario text-split-1 [ run [ - 1:address:shared:array:character <- new [a/b] - 2:address:shared:array:address:shared:array:character <- split 1:address:shared:array:character, 47/slash - 3:number <- length *2:address:shared:array:address:shared:array:character - 4:address:shared:array:character <- index *2:address:shared:array:address:shared:array:character, 0 - 5:address:shared:array:character <- index *2:address:shared:array:address:shared:array:character, 1 - 10:array:character <- copy *4:address:shared:array:character - 20:array:character <- copy *5:address:shared:array:character + 1:address:array:character <- new [a/b] + 2:address:array:address:array:character <- split 1:address:array:character, 47/slash + 3:number <- length *2:address:array:address:array:character + 4:address:array:character <- index *2:address:array:address:array:character, 0 + 5:address:array:character <- index *2:address:array:address:array:character, 1 + 10:array:character <- copy *4:address:array:character + 20:array:character <- copy *5:address:array:character ] memory-should-contain [ 3 <- 2 # length of result @@ -1148,15 +1148,15 @@ scenario text-split-1 [ scenario text-split-2 [ run [ - 1:address:shared:array:character <- new [a/b/c] - 2:address:shared:array:address:shared:array:character <- split 1:address:shared:array:character, 47/slash - 3:number <- length *2:address:shared:array:address:shared:array:character - 4:address:shared:array:character <- index *2:address:shared:array:address:shared:array:character, 0 - 5:address:shared:array:character <- index *2:address:shared:array:address:shared:array:character, 1 - 6:address:shared:array:character <- index *2:address:shared:array:address:shared:array:character, 2 - 10:array:character <- copy *4:address:shared:array:character - 20:array:character <- copy *5:address:shared:array:character - 30:array:character <- copy *6:address:shared:array:character + 1:address:array:character <- new [a/b/c] + 2:address:array:address:array:character <- split 1:address:array:character, 47/slash + 3:number <- length *2:address:array:address:array:character + 4:address:array:character <- index *2:address:array:address:array:character, 0 + 5:address:array:character <- index *2:address:array:address:array:character, 1 + 6:address:array:character <- index *2:address:array:address:array:character, 2 + 10:array:character <- copy *4:address:array:character + 20:array:character <- copy *5:address:array:character + 30:array:character <- copy *6:address:array:character ] memory-should-contain [ 3 <- 3 # length of result @@ -1168,11 +1168,11 @@ scenario text-split-2 [ scenario text-split-missing [ run [ - 1:address:shared:array:character <- new [abc] - 2:address:shared:array:address:shared:array:character <- split 1:address:shared:array:character, 47/slash - 3:number <- length *2:address:shared:array:address:shared:array:character - 4:address:shared:array:character <- index *2:address:shared:array:address:shared:array:character, 0 - 10:array:character <- copy *4:address:shared:array:character + 1:address:array:character <- new [abc] + 2:address:array:address:array:character <- split 1:address:array:character, 47/slash + 3:number <- length *2:address:array:address:array:character + 4:address:array:character <- index *2:address:array:address:array:character, 0 + 10:array:character <- copy *4:address:array:character ] memory-should-contain [ 3 <- 1 # length of result @@ -1182,9 +1182,9 @@ scenario text-split-missing [ scenario text-split-empty [ run [ - 1:address:shared:array:character <- new [] - 2:address:shared:array:address:shared:array:character <- split 1:address:shared:array:character, 47/slash - 3:number <- length *2:address:shared:array:address:shared:array:character + 1:address:array:character <- new [] + 2:address:array:address:array:character <- split 1:address:array:character, 47/slash + 3:number <- length *2:address:array:address:array:character ] memory-should-contain [ 3 <- 0 # empty result @@ -1193,17 +1193,17 @@ scenario text-split-empty [ scenario text-split-empty-piece [ run [ - 1:address:shared:array:character <- new [a/b//c] - 2:address:shared:array:address:shared:array:character <- split 1:address:shared:array:character, 47/slash - 3:number <- length *2:address:shared:array:address:shared:array:character - 4:address:shared:array:character <- index *2:address:shared:array:address:shared:array:character, 0 - 5:address:shared:array:character <- index *2:address:shared:array:address:shared:array:character, 1 - 6:address:shared:array:character <- index *2:address:shared:array:address:shared:array:character, 2 - 7:address:shared:array:character <- index *2:address:shared:array:address:shared:array:character, 3 - 10:array:character <- copy *4:address:shared:array:character - 20:array:character <- copy *5:address:shared:array:character - 30:array:character <- copy *6:address:shared:array:character - 40:array:character <- copy *7:address:shared:array:character + 1:address:array:character <- new [a/b//c] + 2:address:array:address:array:character <- split 1:address:array:character, 47/slash + 3:number <- length *2:address:array:address:array:character + 4:address:array:character <- index *2:address:array:address:array:character, 0 + 5:address:array:character <- index *2:address:array:address:array:character, 1 + 6:address:array:character <- index *2:address:array:address:array:character, 2 + 7:address:array:character <- index *2:address:array:address:array:character, 3 + 10:array:character <- copy *4:address:array:character + 20:array:character <- copy *5:address:array:character + 30:array:character <- copy *6:address:array:character + 40:array:character <- copy *7:address:array:character ] memory-should-contain [ 3 <- 4 # length of result @@ -1214,7 +1214,7 @@ scenario text-split-empty-piece [ ] ] -def split-first text:address:shared:array:character, delim:character -> x:address:shared:array:character, y:address:shared:array:character [ +def split-first text:address:array:character, delim:character -> x:address:array:character, y:address:array:character [ local-scope load-ingredients # empty text? return empty texts @@ -1222,22 +1222,22 @@ def split-first text:address:shared:array:character, delim:character -> x:addres { empty?:boolean <- equal len, 0 break-unless empty? - x:address:shared:array:character <- new [] - y:address:shared:array:character <- new [] + x:address:array:character <- new [] + y:address:array:character <- new [] return } idx:number <- find-next text, delim, 0 - x:address:shared:array:character <- copy-range text, 0, idx + x:address:array:character <- copy-range text, 0, idx idx <- add idx, 1 - y:address:shared:array:character <- copy-range text, idx, len + y:address:array:character <- copy-range text, idx, len ] scenario text-split-first [ run [ - 1:address:shared:array:character <- new [a/b] - 2:address:shared:array:character, 3:address:shared:array:character <- split-first 1:address:shared:array:character, 47/slash - 10:array:character <- copy *2:address:shared:array:character - 20:array:character <- copy *3:address:shared:array:character + 1:address:array:character <- new [a/b] + 2:address:array:character, 3:address:array:character <- split-first 1:address:array:character, 47/slash + 10:array:character <- copy *2:address:array:character + 20:array:character <- copy *3:address:array:character ] memory-should-contain [ 10:array:character <- [a] @@ -1245,7 +1245,7 @@ scenario text-split-first [ ] ] -def copy-range buf:address:shared:array:character, start:number, end:number -> result:address:shared:array:character [ +def copy-range buf:address:array:character, start:number, end:number -> result:address:array:character [ local-scope load-ingredients # if end is out of bounds, trim it @@ -1253,7 +1253,7 @@ def copy-range buf:address:shared:array:character, start:number, end:number -> r end:number <- min len, end # allocate space for result len <- subtract end, start - result:address:shared:array:character <- new character:type, len + result:address:array:character <- new character:type, len # copy start..end into result[curr-result] src-idx:number <- copy start dest-idx:number <- copy 0 @@ -1270,9 +1270,9 @@ def copy-range buf:address:shared:array:character, start:number, end:number -> r scenario text-copy-copies-partial-text [ run [ - 1:address:shared:array:character <- new [abc] - 2:address:shared:array:character <- copy-range 1:address:shared:array:character, 1, 3 - 3:array:character <- copy *2:address:shared:array:character + 1:address:array:character <- new [abc] + 2:address:array:character <- copy-range 1:address:array:character, 1, 3 + 3:array:character <- copy *2:address:array:character ] memory-should-contain [ 3:array:character <- [bc] @@ -1281,9 +1281,9 @@ scenario text-copy-copies-partial-text [ scenario text-copy-out-of-bounds [ run [ - 1:address:shared:array:character <- new [abc] - 2:address:shared:array:character <- copy-range 1:address:shared:array:character, 2, 4 - 3:array:character <- copy *2:address:shared:array:character + 1:address:array:character <- new [abc] + 2:address:array:character <- copy-range 1:address:array:character, 2, 4 + 3:array:character <- copy *2:address:array:character ] memory-should-contain [ 3:array:character <- [c] @@ -1292,9 +1292,9 @@ scenario text-copy-out-of-bounds [ scenario text-copy-out-of-bounds-2 [ run [ - 1:address:shared:array:character <- new [abc] - 2:address:shared:array:character <- copy-range 1:address:shared:array:character, 3, 3 - 3:array:character <- copy *2:address:shared:array:character + 1:address:array:character <- new [abc] + 2:address:array:character <- copy-range 1:address:array:character, 3, 3 + 3:array:character <- copy *2:address:array:character ] memory-should-contain [ 3:array:character <- [] diff --git a/071rewrite_stash.cc b/071rewrite_stash.cc index 7b6696f5..6e2368e6 100644 --- a/071rewrite_stash.cc +++ b/071rewrite_stash.cc @@ -8,8 +8,8 @@ recipe main [ n:number <- copy 34 stash n ] -+transform: {stash_2_0: ("address" "shared" "array" "character")} <- to-text-line {n: "number"} -+transform: stash {stash_2_0: ("address" "shared" "array" "character")} ++transform: {stash_2_0: ("address" "array" "character")} <- to-text-line {n: "number"} ++transform: stash {stash_2_0: ("address" "array" "character")} //: special case: rewrite attempts to stash contents of most arrays to avoid //: passing addresses around @@ -17,11 +17,11 @@ recipe main [ :(scenario rewrite_stashes_of_arrays) recipe main [ local-scope - n:address:shared:array:number <- new number:type, 3 + n:address:array:number <- new number:type, 3 stash *n ] -+transform: {stash_2_0: ("address" "shared" "array" "character")} <- array-to-text-line {n: ("address" "shared" "array" "number")} -+transform: stash {stash_2_0: ("address" "shared" "array" "character")} ++transform: {stash_2_0: ("address" "array" "character")} <- array-to-text-line {n: ("address" "array" "number")} ++transform: stash {stash_2_0: ("address" "array" "character")} :(scenario ignore_stashes_of_static_arrays) recipe main [ @@ -70,7 +70,7 @@ void rewrite_stashes_to_text(recipe& caller) { def.ingredients.push_back(inst.ingredients.at(j)); } ostringstream ingredient_name; - ingredient_name << "stash_" << i << '_' << j << ":address:shared:array:character"; + ingredient_name << "stash_" << i << '_' << j << ":address:array:character"; def.products.push_back(reagent(ingredient_name.str())); trace(9993, "transform") << to_string(def) << end(); new_instructions.push_back(def); diff --git a/072channel.mu b/072channel.mu index 0847f2ce..c6a40ef7 100644 --- a/072channel.mu +++ b/072channel.mu @@ -10,9 +10,9 @@ scenario channel [ run [ - 1:address:shared:source:number, 2:address:shared:sink:number <- new-channel 3/capacity - 2:address:shared:sink:number <- write 2:address:shared:sink:number, 34 - 3:number, 1:address:shared:source:number <- read 1:address:shared:source:number + 1:address:source:number, 2:address:sink:number <- new-channel 3/capacity + 2:address:sink:number <- write 2:address:sink:number, 34 + 3:number, 1:address:source:number <- read 1:address:source:number ] memory-should-contain [ 3 <- 34 @@ -28,28 +28,28 @@ container channel:_elem [ # A circular buffer contains values from index first-full up to (but not # including) index first-empty. The reader always modifies it at first-full, # while the writer always modifies it at first-empty. - data:address:shared:array:_elem + data:address:array:_elem ] # Since channels have two ends, and since it's an error to use either end from # multiple routines, let's distinguish the ends. container source:_elem [ - chan:address:shared:channel:_elem + chan:address:channel:_elem ] container sink:_elem [ - chan:address:shared:channel:_elem + chan:address:channel:_elem ] -def new-channel capacity:number -> in:address:shared:source:_elem, out:address:shared:sink:_elem [ +def new-channel capacity:number -> in:address:source:_elem, out:address:sink:_elem [ local-scope load-ingredients - result:address:shared:channel:_elem <- new {(channel _elem): type} + result:address:channel:_elem <- new {(channel _elem): type} *result <- put *result, first-full:offset, 0 *result <- put *result, first-free:offset, 0 capacity <- add capacity, 1 # unused slot for 'full?' below - data:address:shared:array:_elem <- new _elem:type, capacity + data:address:array:_elem <- new _elem:type, capacity *result <- put *result, data:offset, data in <- new {(source _elem): type} *in <- put *in, chan:offset, result @@ -57,10 +57,10 @@ def new-channel capacity:number -> in:address:shared:source:_elem, out:address:s *out <- put *out, chan:offset, result ] -def write out:address:shared:sink:_elem, val:_elem -> out:address:shared:sink:_elem [ +def write out:address:sink:_elem, val:_elem -> out:address:sink:_elem [ local-scope load-ingredients - chan:address:shared:channel:_elem <- get *out, chan:offset + chan:address:channel:_elem <- get *out, chan:offset { # block if chan is full full:boolean <- channel-full? chan @@ -69,7 +69,7 @@ def write out:address:shared:sink:_elem, val:_elem -> out:address:shared:sink:_e wait-for-location full-address } # store val - circular-buffer:address:shared:array:_elem <- get *chan, data:offset + circular-buffer:address:array:_elem <- get *chan, data:offset free:number <- get *chan, first-free:offset *circular-buffer <- put-index *circular-buffer, free, val # mark its slot as filled @@ -86,10 +86,10 @@ def write out:address:shared:sink:_elem, val:_elem -> out:address:shared:sink:_e *chan <- put *chan, first-free:offset, free ] -def read in:address:shared:source:_elem -> result:_elem, in:address:shared:source:_elem [ +def read in:address:source:_elem -> result:_elem, in:address:source:_elem [ local-scope load-ingredients - chan:address:shared:channel:_elem <- get *in, chan:offset + chan:address:channel:_elem <- get *in, chan:offset { # block if chan is empty empty?:boolean <- channel-empty? chan @@ -99,7 +99,7 @@ def read in:address:shared:source:_elem -> result:_elem, in:address:shared:sourc } # pull result off full:number <- get *chan, first-full:offset - circular-buffer:address:shared:array:_elem <- get *chan, data:offset + circular-buffer:address:array:_elem <- get *chan, data:offset result <- index *circular-buffer, full # mark its slot as empty # todo: clear the slot itself @@ -115,10 +115,10 @@ def read in:address:shared:source:_elem -> result:_elem, in:address:shared:sourc *chan <- put *chan, first-full:offset, full ] -def clear in:address:shared:source:_elem -> in:address:shared:source:_elem [ +def clear in:address:source:_elem -> in:address:source:_elem [ local-scope load-ingredients - chan:address:shared:channel:_elem <- get *in, chan:offset + chan:address:channel:_elem <- get *in, chan:offset { empty?:boolean <- channel-empty? chan break-if empty? @@ -128,10 +128,10 @@ def clear in:address:shared:source:_elem -> in:address:shared:source:_elem [ scenario channel-initialization [ run [ - 1:address:shared:source:number <- new-channel 3/capacity - 2:address:shared:channel:number <- get *1:address:shared:source:number, chan:offset - 3:number <- get *2:address:shared:channel:number, first-full:offset - 4:number <- get *2:address:shared:channel:number, first-free:offset + 1:address:source:number <- new-channel 3/capacity + 2:address:channel:number <- get *1:address:source:number, chan:offset + 3:number <- get *2:address:channel:number, first-full:offset + 4:number <- get *2:address:channel:number, first-free:offset ] memory-should-contain [ 3 <- 0 # first-full @@ -141,11 +141,11 @@ scenario channel-initialization [ scenario channel-write-increments-free [ run [ - _, 1:address:shared:sink:number <- new-channel 3/capacity - 1:address:shared:sink:number <- write 1:address:shared:sink:number, 34 - 2:address:shared:channel:number <- get *1:address:shared:sink:number, chan:offset - 3:number <- get *2:address:shared:channel:character, first-full:offset - 4:number <- get *2:address:shared:channel:character, first-free:offset + _, 1:address:sink:number <- new-channel 3/capacity + 1:address:sink:number <- write 1:address:sink:number, 34 + 2:address:channel:number <- get *1:address:sink:number, chan:offset + 3:number <- get *2:address:channel:character, first-full:offset + 4:number <- get *2:address:channel:character, first-free:offset ] memory-should-contain [ 3 <- 0 # first-full @@ -155,12 +155,12 @@ scenario channel-write-increments-free [ scenario channel-read-increments-full [ run [ - 1:address:shared:source:number, 2:address:shared:sink:number <- new-channel 3/capacity - 2:address:shared:sink:number <- write 2:address:shared:sink:number, 34 - _, 1:address:shared:source:number <- read 1:address:shared:source:number - 3:address:shared:channel:number <- get *1:address:shared:source:number, chan:offset - 4:number <- get *3:address:shared:channel:number, first-full:offset - 5:number <- get *3:address:shared:channel:number, first-free:offset + 1:address:source:number, 2:address:sink:number <- new-channel 3/capacity + 2:address:sink:number <- write 2:address:sink:number, 34 + _, 1:address:source:number <- read 1:address:source:number + 3:address:channel:number <- get *1:address:source:number, chan:offset + 4:number <- get *3:address:channel:number, first-full:offset + 5:number <- get *3:address:channel:number, first-free:offset ] memory-should-contain [ 4 <- 1 # first-full @@ -171,20 +171,20 @@ scenario channel-read-increments-full [ scenario channel-wrap [ run [ # channel with just 1 slot - 1:address:shared:source:number, 2:address:shared:sink:number <- new-channel 1/capacity - 3:address:shared:channel:number <- get *1:address:shared:source:number, chan:offset + 1:address:source:number, 2:address:sink:number <- new-channel 1/capacity + 3:address:channel:number <- get *1:address:source:number, chan:offset # write and read a value - 2:address:shared:sink:number <- write 2:address:shared:sink:number, 34 - _, 1:address:shared:source:number <- read 1:address:shared:source:number + 2:address:sink:number <- write 2:address:sink:number, 34 + _, 1:address:source:number <- read 1:address:source:number # first-free will now be 1 - 4:number <- get *3:address:shared:channel:number, first-free:offset - 5:number <- get *3:address:shared:channel:number, first-free:offset + 4:number <- get *3:address:channel:number, first-free:offset + 5:number <- get *3:address:channel:number, first-free:offset # write second value, verify that first-free wraps - 2:address:shared:sink:number <- write 2:address:shared:sink:number, 34 - 6:number <- get *3:address:shared:channel:number, first-free:offset + 2:address:sink:number <- write 2:address:sink:number, 34 + 6:number <- get *3:address:channel:number, first-free:offset # read second value, verify that first-full wraps - _, 1:address:shared:source:number <- read 1:address:shared:source:number - 7:number <- get *3:address:shared:channel:number, first-full:offset + _, 1:address:source:number <- read 1:address:source:number + 7:number <- get *3:address:channel:number, first-full:offset ] memory-should-contain [ 4 <- 1 # first-free after first write @@ -197,7 +197,7 @@ scenario channel-wrap [ ## helpers # An empty channel has first-empty and first-full both at the same value. -def channel-empty? chan:address:shared:channel:_elem -> result:boolean [ +def channel-empty? chan:address:channel:_elem -> result:boolean [ local-scope load-ingredients # return chan.first-full == chan.first-free @@ -208,7 +208,7 @@ def channel-empty? chan:address:shared:channel:_elem -> result:boolean [ # 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) -def channel-full? chan:address:shared:channel:_elem -> result:boolean [ +def channel-full? chan:address:channel:_elem -> result:boolean [ local-scope load-ingredients # tmp = chan.first-free + 1 @@ -226,19 +226,19 @@ def channel-full? chan:address:shared:channel:_elem -> result:boolean [ result <- equal full, tmp ] -def capacity chan:address:shared:channel:_elem -> result:number [ +def capacity chan:address:channel:_elem -> result:number [ local-scope load-ingredients - q:address:shared:array:_elem <- get *chan, data:offset + q:address:array:_elem <- get *chan, data:offset result <- length *q ] scenario channel-new-empty-not-full [ run [ - 1:address:shared:source:number, 2:address:shared:sink:number <- new-channel 3/capacity - 3:address:shared:channel:number <- get *1:address:shared:source:number, chan:offset - 4:boolean <- channel-empty? 3:address:shared:channel:number - 5:boolean <- channel-full? 3:address:shared:channel:number + 1:address:source:number, 2:address:sink:number <- new-channel 3/capacity + 3:address:channel:number <- get *1:address:source:number, chan:offset + 4:boolean <- channel-empty? 3:address:channel:number + 5:boolean <- channel-full? 3:address:channel:number ] memory-should-contain [ 4 <- 1 # empty? @@ -248,11 +248,11 @@ scenario channel-new-empty-not-full [ scenario channel-write-not-empty [ run [ - 1:address:shared:source:number, 2:address:shared:sink:number <- new-channel 3/capacity - 3:address:shared:channel:number <- get *1:address:shared:source:number, chan:offset - 2:address:shared:sink:number <- write 2:address:shared:sink:number, 34 - 4:boolean <- channel-empty? 3:address:shared:channel:number - 5:boolean <- channel-full? 3:address:shared:channel:number + 1:address:source:number, 2:address:sink:number <- new-channel 3/capacity + 3:address:channel:number <- get *1:address:source:number, chan:offset + 2:address:sink:number <- write 2:address:sink:number, 34 + 4:boolean <- channel-empty? 3:address:channel:number + 5:boolean <- channel-full? 3:address:channel:number ] memory-should-contain [ 4 <- 0 # empty? @@ -262,11 +262,11 @@ scenario channel-write-not-empty [ scenario channel-write-full [ run [ - 1:address:shared:source:number, 2:address:shared:sink:number <- new-channel 1/capacity - 3:address:shared:channel:number <- get *1:address:shared:source:number, chan:offset - 2:address:shared:sink:number <- write 2:address:shared:sink:number, 34 - 4:boolean <- channel-empty? 3:address:shared:channel:number - 5:boolean <- channel-full? 3:address:shared:channel:number + 1:address:source:number, 2:address:sink:number <- new-channel 1/capacity + 3:address:channel:number <- get *1:address:source:number, chan:offset + 2:address:sink:number <- write 2:address:sink:number, 34 + 4:boolean <- channel-empty? 3:address:channel:number + 5:boolean <- channel-full? 3:address:channel:number ] memory-should-contain [ 4 <- 0 # empty? @@ -276,12 +276,12 @@ scenario channel-write-full [ scenario channel-read-not-full [ run [ - 1:address:shared:source:number, 2:address:shared:sink:number <- new-channel 1/capacity - 3:address:shared:channel:number <- get *1:address:shared:source:number, chan:offset - 2:address:shared:sink:number <- write 2:address:shared:sink:number, 34 - _, 1:address:shared:source:number <- read 1:address:shared:source:number - 4:boolean <- channel-empty? 3:address:shared:channel:number - 5:boolean <- channel-full? 3:address:shared:channel:number + 1:address:source:number, 2:address:sink:number <- new-channel 1/capacity + 3:address:channel:number <- get *1:address:source:number, chan:offset + 2:address:sink:number <- write 2:address:sink:number, 34 + _, 1:address:source:number <- read 1:address:source:number + 4:boolean <- channel-empty? 3:address:channel:number + 5:boolean <- channel-full? 3:address:channel:number ] memory-should-contain [ 4 <- 1 # empty? @@ -290,12 +290,12 @@ scenario channel-read-not-full [ ] # helper for channels of characters in particular -def buffer-lines in:address:shared:source:character, buffered-out:address:shared:sink:character -> buffered-out:address:shared:sink:character, in:address:shared:source:character [ +def buffer-lines in:address:source:character, buffered-out:address:sink:character -> buffered-out:address:sink:character, in:address:source:character [ local-scope load-ingredients # repeat forever { - line:address:shared:buffer <- new-buffer 30 + line:address:buffer <- new-buffer 30 # read characters from 'in' until newline, copy into line { +next-character @@ -327,7 +327,7 @@ def buffer-lines in:address:shared:source:character, buffered-out:address:shared } # copy line into 'buffered-out' i:number <- copy 0 - line-contents:address:shared:array:character <- get *line, data:offset + line-contents:address:array:character <- get *line, data:offset max:number <- get *line, length:offset { done?:boolean <- greater-or-equal i, max @@ -343,37 +343,37 @@ def buffer-lines in:address:shared:source:character, buffered-out:address:shared scenario buffer-lines-blocks-until-newline [ run [ - 1:address:shared:source:number, 2:address:shared:sink:number <- new-channel 10/capacity - _, 3:address:shared:sink:number/buffered-stdin <- new-channel 10/capacity - 4:address:shared:channel:number/buffered-stdin <- get *3:address:shared:source:number, chan:offset - 5:boolean <- channel-empty? 4:address:shared:channel:character/buffered-stdin + 1:address:source:number, 2:address:sink:number <- new-channel 10/capacity + _, 3:address:sink:number/buffered-stdin <- new-channel 10/capacity + 4:address:channel:number/buffered-stdin <- get *3:address:source:number, chan:offset + 5:boolean <- channel-empty? 4:address:channel:character/buffered-stdin assert 5:boolean, [ F buffer-lines-blocks-until-newline: channel should be empty after init] # buffer stdin into buffered-stdin, try to read from buffered-stdin - 6:number/buffer-routine <- start-running buffer-lines, 1:address:shared:source:character/stdin, 3:address:shared:sink:character/buffered-stdin + 6:number/buffer-routine <- start-running buffer-lines, 1:address:source:character/stdin, 3:address:sink:character/buffered-stdin wait-for-routine 6:number/buffer-routine - 7:boolean <- channel-empty? 4:address:shared:channel:character/buffered-stdin + 7:boolean <- channel-empty? 4:address:channel:character/buffered-stdin assert 7:boolean, [ F buffer-lines-blocks-until-newline: channel should be empty after buffer-lines bring-up] # write 'a' - 2:address:shared:sink:character <- write 2:address:shared:sink:character, 97/a + 2:address:sink:character <- write 2:address:sink:character, 97/a restart 6:number/buffer-routine wait-for-routine 6:number/buffer-routine - 8:boolean <- channel-empty? 4:address:shared:channel:character/buffered-stdin + 8:boolean <- channel-empty? 4:address:channel:character/buffered-stdin assert 8:boolean, [ F buffer-lines-blocks-until-newline: channel should be empty after writing 'a'] # write 'b' - 2:address:shared:sink:character <- write 2:address:shared:sink:character, 98/b + 2:address:sink:character <- write 2:address:sink:character, 98/b restart 6:number/buffer-routine wait-for-routine 6:number/buffer-routine - 9:boolean <- channel-empty? 4:address:shared:channel:character/buffered-stdin + 9:boolean <- channel-empty? 4:address:channel:character/buffered-stdin assert 9:boolean, [ F buffer-lines-blocks-until-newline: channel should be empty after writing 'b'] # write newline - 2:address:shared:sink:character <- write 2:address:shared:sink:character, 10/newline + 2:address:sink:character <- write 2:address:sink:character, 10/newline restart 6:number/buffer-routine wait-for-routine 6:number/buffer-routine - 10:boolean <- channel-empty? 4:address:shared:channel:character/buffered-stdin + 10:boolean <- channel-empty? 4:address:channel:character/buffered-stdin 11:boolean/completed? <- not 10:boolean assert 11:boolean/completed?, [ F buffer-lines-blocks-until-newline: channel should contain data after writing newline] diff --git a/073array.mu b/073array.mu index 7fa580c5..7e1bf807 100644 --- a/073array.mu +++ b/073array.mu @@ -1,7 +1,7 @@ scenario array-from-args [ run [ - 1:address:shared:array:character <- new-array 0, 1, 2 - 2:array:character <- copy *1:address:shared:array:character + 1:address:array:character <- new-array 0, 1, 2 + 2:array:character <- copy *1:address:array:character ] memory-should-contain [ 2 <- 3 # array length @@ -12,7 +12,7 @@ scenario array-from-args [ ] # create an array out of a list of scalar args -def new-array -> result:address:shared:array:character [ +def new-array -> result:address:array:character [ local-scope capacity:number <- copy 0 { diff --git a/074list.mu b/074list.mu index 089533e0..833a52cb 100644 --- a/074list.mu +++ b/074list.mu @@ -5,24 +5,24 @@ container list:_elem [ value:_elem - next:address:shared:list:_elem + next:address:list:_elem ] -def push x:_elem, in:address:shared:list:_elem -> in:address:shared:list:_elem [ +def push x:_elem, in:address:list:_elem -> in:address:list:_elem [ local-scope load-ingredients - result:address:shared:list:_elem <- new {(list _elem): type} + result:address:list:_elem <- new {(list _elem): type} *result <- merge x, in return result # needed explicitly because we need to replace 'in' with 'result' ] -def first in:address:shared:list:_elem -> result:_elem [ +def first in:address:list:_elem -> result:_elem [ local-scope load-ingredients result <- get *in, value:offset ] -def rest in:address:shared:list:_elem -> result:address:shared:list:_elem/contained-in:in [ +def rest in:address:list:_elem -> result:address:list:_elem/contained-in:in [ local-scope load-ingredients result <- get *in, next:offset @@ -30,15 +30,15 @@ def rest in:address:shared:list:_elem -> result:address:shared:list:_elem/contai scenario list-handling [ run [ - 1:address:shared:list:number <- push 3, 0 - 1:address:shared:list:number <- push 4, 1:address:shared:list:number - 1:address:shared:list:number <- push 5, 1:address:shared:list:number - 2:number <- first 1:address:shared:list:number - 1:address:shared:list:number <- rest 1:address:shared:list:number - 3:number <- first 1:address:shared:list:number - 1:address:shared:list:number <- rest 1:address:shared:list:number - 4:number <- first 1:address:shared:list:number - 1:address:shared:list:number <- rest 1:address:shared:list:number + 1:address:list:number <- push 3, 0 + 1:address:list:number <- push 4, 1:address:list:number + 1:address:list:number <- push 5, 1:address:list:number + 2:number <- first 1:address:list:number + 1:address:list:number <- rest 1:address:list:number + 3:number <- first 1:address:list:number + 1:address:list:number <- rest 1:address:list:number + 4:number <- first 1:address:list:number + 1:address:list:number <- rest 1:address:list:number ] memory-should-contain [ 1 <- 0 # empty to empty, dust to dust.. @@ -48,24 +48,24 @@ scenario list-handling [ ] ] -def to-text in:address:shared:list:_elem -> result:address:shared:array:character [ +def to-text in:address:list:_elem -> result:address:array:character [ local-scope load-ingredients - buf:address:shared:buffer <- new-buffer 80 + buf:address:buffer <- new-buffer 80 buf <- to-buffer in, buf result <- buffer-to-array buf ] # variant of 'to-text' which stops printing after a few elements (and so is robust to cycles) -def to-text-line in:address:shared:list:_elem -> result:address:shared:array:character [ +def to-text-line in:address:list:_elem -> result:address:array:character [ local-scope load-ingredients - buf:address:shared:buffer <- new-buffer 80 + buf:address:buffer <- new-buffer 80 buf <- to-buffer in, buf, 6 # max elements to display result <- buffer-to-array buf ] -def to-buffer in:address:shared:list:_elem, buf:address:shared:buffer -> buf:address:shared:buffer [ +def to-buffer in:address:list:_elem, buf:address:buffer -> buf:address:buffer [ local-scope load-ingredients { @@ -77,7 +77,7 @@ def to-buffer in:address:shared:list:_elem, buf:address:shared:buffer -> buf:add val:_elem <- get *in, value:offset buf <- append buf, val # now prepare next - next:address:shared:list:_elem <- rest in + next:address:list:_elem <- rest in nextn:number <- copy next return-unless next buf <- append buf, [ -> ] diff --git a/076duplex_list.mu b/076duplex_list.mu index d6970916..b8db1981 100644 --- a/076duplex_list.mu +++ b/076duplex_list.mu @@ -2,15 +2,15 @@ container duplex-list:_elem [ value:_elem - next:address:shared:duplex-list:_elem - prev:address:shared:duplex-list:_elem + next:address:duplex-list:_elem + prev:address:duplex-list:_elem ] # should I say in/contained-in:result, allow ingredients to refer to products? -def push x:_elem, in:address:shared:duplex-list:_elem -> in:address:shared:duplex-list:_elem [ +def push x:_elem, in:address:duplex-list:_elem -> in:address:duplex-list:_elem [ local-scope load-ingredients - result:address:shared:duplex-list:_elem <- new {(duplex-list _elem): type} + result:address:duplex-list:_elem <- new {(duplex-list _elem): type} *result <- merge x, in, 0 { break-unless in @@ -19,21 +19,21 @@ def push x:_elem, in:address:shared:duplex-list:_elem -> in:address:shared:duple return result # needed explicitly because we need to replace 'in' with 'result' ] -def first in:address:shared:duplex-list:_elem -> result:_elem [ +def first in:address:duplex-list:_elem -> result:_elem [ local-scope load-ingredients return-unless in, 0 result <- get *in, value:offset ] -def next in:address:shared:duplex-list:_elem -> result:address:shared:duplex-list:_elem/contained-in:in [ +def next in:address:duplex-list:_elem -> result:address:duplex-list:_elem/contained-in:in [ local-scope load-ingredients return-unless in, 0 result <- get *in, next:offset ] -def prev in:address:shared:duplex-list:_elem -> result:address:shared:duplex-list:_elem/contained-in:in [ +def prev in:address:duplex-list:_elem -> result:address:duplex-list:_elem/contained-in:in [ local-scope load-ingredients return-unless in, 0 @@ -46,24 +46,24 @@ scenario duplex-list-handling [ # reserve locations 0, 1 and 2 to check for missing null check 1:number <- copy 34 2:number <- copy 35 - 3:address:shared:duplex-list:character <- push 3, 0 - 3:address:shared:duplex-list:character <- push 4, 3:address:shared:duplex-list:character - 3:address:shared:duplex-list:character <- push 5, 3:address:shared:duplex-list:character - 4:address:shared:duplex-list:character <- copy 3:address:shared:duplex-list:character - 5:character <- first 4:address:shared:duplex-list:character - 4:address:shared:duplex-list:character <- next 4:address:shared:duplex-list:character - 6:character <- first 4:address:shared:duplex-list:character - 4:address:shared:duplex-list:character <- next 4:address:shared:duplex-list:character - 7:character <- first 4:address:shared:duplex-list:character - 8:address:shared:duplex-list:character <- next 4:address:shared:duplex-list:character - 9:character <- first 8:address:shared:duplex-list:character - 10:address:shared:duplex-list:character <- next 8:address:shared:duplex-list:character - 11:address:shared:duplex-list:character <- prev 8:address:shared:duplex-list:character - 4:address:shared:duplex-list:character <- prev 4:address:shared:duplex-list:character - 12:character <- first 4:address:shared:duplex-list:character - 4:address:shared:duplex-list:character <- prev 4:address:shared:duplex-list:character - 13:character <- first 4:address:shared:duplex-list:character - 14:boolean <- equal 3:address:shared:duplex-list:character, 4:address:shared:duplex-list:character + 3:address:duplex-list:character <- push 3, 0 + 3:address:duplex-list:character <- push 4, 3:address:duplex-list:character + 3:address:duplex-list:character <- push 5, 3:address:duplex-list:character + 4:address:duplex-list:character <- copy 3:address:duplex-list:character + 5:character <- first 4:address:duplex-list:character + 4:address:duplex-list:character <- next 4:address:duplex-list:character + 6:character <- first 4:address:duplex-list:character + 4:address:duplex-list:character <- next 4:address:duplex-list:character + 7:character <- first 4:address:duplex-list:character + 8:address:duplex-list:character <- next 4:address:duplex-list:character + 9:character <- first 8:address:duplex-list:character + 10:address:duplex-list:character <- next 8:address:duplex-list:character + 11:address:duplex-list:character <- prev 8:address:duplex-list:character + 4:address:duplex-list:character <- prev 4:address:duplex-list:character + 12:character <- first 4:address:duplex-list:character + 4:address:duplex-list:character <- prev 4:address:duplex-list:character + 13:character <- first 4:address:duplex-list:character + 14:boolean <- equal 3:address:duplex-list:character, 4:address:duplex-list:character ] memory-should-contain [ 0 <- 0 # no modifications to null pointers @@ -83,13 +83,13 @@ scenario duplex-list-handling [ ] # insert 'x' after 'in' -def insert x:_elem, in:address:shared:duplex-list:_elem -> in:address:shared:duplex-list:_elem [ +def insert x:_elem, in:address:duplex-list:_elem -> in:address:duplex-list:_elem [ local-scope load-ingredients - new-node:address:shared:duplex-list:_elem <- new {(duplex-list _elem): type} + new-node:address:duplex-list:_elem <- new {(duplex-list _elem): type} *new-node <- put *new-node, value:offset, x # save old next before changing it - next-node:address:shared:duplex-list:_elem <- get *in, next:offset + next-node:address:duplex-list:_elem <- get *in, next:offset *in <- put *in, next:offset, new-node *new-node <- put *new-node, prev:offset, in *new-node <- put *new-node, next:offset, next-node @@ -99,27 +99,27 @@ def insert x:_elem, in:address:shared:duplex-list:_elem -> in:address:shared:dup scenario inserting-into-duplex-list [ run [ - 1:address:shared:duplex-list:character <- push 3, 0 - 1:address:shared:duplex-list:character <- push 4, 1:address:shared:duplex-list:character - 1:address:shared:duplex-list:character <- push 5, 1:address:shared:duplex-list:character - 2:address:shared:duplex-list:character <- next 1:address:shared:duplex-list:character # 2 points inside list - 2:address:shared:duplex-list:character <- insert 6, 2:address:shared:duplex-list:character + 1:address:duplex-list:character <- push 3, 0 + 1:address:duplex-list:character <- push 4, 1:address:duplex-list:character + 1:address:duplex-list:character <- push 5, 1:address:duplex-list:character + 2:address:duplex-list:character <- next 1:address:duplex-list:character # 2 points inside list + 2:address:duplex-list:character <- insert 6, 2:address:duplex-list:character # check structure like before - 2:address:shared:duplex-list:character <- copy 1:address:shared:duplex-list:character - 3:character <- first 2:address:shared:duplex-list:character - 2:address:shared:duplex-list:character <- next 2:address:shared:duplex-list:character - 4:character <- first 2:address:shared:duplex-list:character - 2:address:shared:duplex-list:character <- next 2:address:shared:duplex-list:character - 5:character <- first 2:address:shared:duplex-list:character - 2:address:shared:duplex-list:character <- next 2:address:shared:duplex-list:character - 6:character <- first 2:address:shared:duplex-list:character - 2:address:shared:duplex-list:character <- prev 2:address:shared:duplex-list:character - 7:character <- first 2:address:shared:duplex-list:character - 2:address:shared:duplex-list:character <- prev 2:address:shared:duplex-list:character - 8:character <- first 2:address:shared:duplex-list:character - 2:address:shared:duplex-list:character <- prev 2:address:shared:duplex-list:character - 9:character <- first 2:address:shared:duplex-list:character - 10:boolean <- equal 1:address:shared:duplex-list:character, 2:address:shared:duplex-list:character + 2:address:duplex-list:character <- copy 1:address:duplex-list:character + 3:character <- first 2:address:duplex-list:character + 2:address:duplex-list:character <- next 2:address:duplex-list:character + 4:character <- first 2:address:duplex-list:character + 2:address:duplex-list:character <- next 2:address:duplex-list:character + 5:character <- first 2:address:duplex-list:character + 2:address:duplex-list:character <- next 2:address:duplex-list:character + 6:character <- first 2:address:duplex-list:character + 2:address:duplex-list:character <- prev 2:address:duplex-list:character + 7:character <- first 2:address:duplex-list:character + 2:address:duplex-list:character <- prev 2:address:duplex-list:character + 8:character <- first 2:address:duplex-list:character + 2:address:duplex-list:character <- prev 2:address:duplex-list:character + 9:character <- first 2:address:duplex-list:character + 10:boolean <- equal 1:address:duplex-list:character, 2:address:duplex-list:character ] memory-should-contain [ 3 <- 5 # scanning next @@ -135,28 +135,28 @@ scenario inserting-into-duplex-list [ scenario inserting-at-end-of-duplex-list [ run [ - 1:address:shared:duplex-list:character <- push 3, 0 - 1:address:shared:duplex-list:character <- push 4, 1:address:shared:duplex-list:character - 1:address:shared:duplex-list:character <- push 5, 1:address:shared:duplex-list:character - 2:address:shared:duplex-list:character <- next 1:address:shared:duplex-list:character # 2 points inside list - 2:address:shared:duplex-list:character <- next 2:address:shared:duplex-list:character # now at end of list - 2:address:shared:duplex-list:character <- insert 6, 2:address:shared:duplex-list:character + 1:address:duplex-list:character <- push 3, 0 + 1:address:duplex-list:character <- push 4, 1:address:duplex-list:character + 1:address:duplex-list:character <- push 5, 1:address:duplex-list:character + 2:address:duplex-list:character <- next 1:address:duplex-list:character # 2 points inside list + 2:address:duplex-list:character <- next 2:address:duplex-list:character # now at end of list + 2:address:duplex-list:character <- insert 6, 2:address:duplex-list:character # check structure like before - 2:address:shared:duplex-list:character <- copy 1:address:shared:duplex-list:character - 3:character <- first 2:address:shared:duplex-list:character - 2:address:shared:duplex-list:character <- next 2:address:shared:duplex-list:character - 4:character <- first 2:address:shared:duplex-list:character - 2:address:shared:duplex-list:character <- next 2:address:shared:duplex-list:character - 5:character <- first 2:address:shared:duplex-list:character - 2:address:shared:duplex-list:character <- next 2:address:shared:duplex-list:character - 6:character <- first 2:address:shared:duplex-list:character - 2:address:shared:duplex-list:character <- prev 2:address:shared:duplex-list:character - 7:character <- first 2:address:shared:duplex-list:character - 2:address:shared:duplex-list:character <- prev 2:address:shared:duplex-list:character - 8:character <- first 2:address:shared:duplex-list:character - 2:address:shared:duplex-list:character <- prev 2:address:shared:duplex-list:character - 9:character <- first 2:address:shared:duplex-list:character - 10:boolean <- equal 1:address:shared:duplex-list:character, 2:address:shared:duplex-list:character + 2:address:duplex-list:character <- copy 1:address:duplex-list:character + 3:character <- first 2:address:duplex-list:character + 2:address:duplex-list:character <- next 2:address:duplex-list:character + 4:character <- first 2:address:duplex-list:character + 2:address:duplex-list:character <- next 2:address:duplex-list:character + 5:character <- first 2:address:duplex-list:character + 2:address:duplex-list:character <- next 2:address:duplex-list:character + 6:character <- first 2:address:duplex-list:character + 2:address:duplex-list:character <- prev 2:address:duplex-list:character + 7:character <- first 2:address:duplex-list:character + 2:address:duplex-list:character <- prev 2:address:duplex-list:character + 8:character <- first 2:address:duplex-list:character + 2:address:duplex-list:character <- prev 2:address:duplex-list:character + 9:character <- first 2:address:duplex-list:character + 10:boolean <- equal 1:address:duplex-list:character, 2:address:duplex-list:character ] memory-should-contain [ 3 <- 5 # scanning next @@ -172,26 +172,26 @@ scenario inserting-at-end-of-duplex-list [ scenario inserting-after-start-of-duplex-list [ run [ - 1:address:shared:duplex-list:character <- push 3, 0 - 1:address:shared:duplex-list:character <- push 4, 1:address:shared:duplex-list:character - 1:address:shared:duplex-list:character <- push 5, 1:address:shared:duplex-list:character - 1:address:shared:duplex-list:character <- insert 6, 1:address:shared:duplex-list:character + 1:address:duplex-list:character <- push 3, 0 + 1:address:duplex-list:character <- push 4, 1:address:duplex-list:character + 1:address:duplex-list:character <- push 5, 1:address:duplex-list:character + 1:address:duplex-list:character <- insert 6, 1:address:duplex-list:character # check structure like before - 2:address:shared:duplex-list:character <- copy 1:address:shared:duplex-list:character - 3:character <- first 2:address:shared:duplex-list:character - 2:address:shared:duplex-list:character <- next 2:address:shared:duplex-list:character - 4:character <- first 2:address:shared:duplex-list:character - 2:address:shared:duplex-list:character <- next 2:address:shared:duplex-list:character - 5:character <- first 2:address:shared:duplex-list:character - 2:address:shared:duplex-list:character <- next 2:address:shared:duplex-list:character - 6:character <- first 2:address:shared:duplex-list:character - 2:address:shared:duplex-list:character <- prev 2:address:shared:duplex-list:character - 7:character <- first 2:address:shared:duplex-list:character - 2:address:shared:duplex-list:character <- prev 2:address:shared:duplex-list:character - 8:character <- first 2:address:shared:duplex-list:character - 2:address:shared:duplex-list:character <- prev 2:address:shared:duplex-list:character - 9:character <- first 2:address:shared:duplex-list:character - 10:boolean <- equal 1:address:shared:duplex-list:character, 2:address:shared:duplex-list:character + 2:address:duplex-list:character <- copy 1:address:duplex-list:character + 3:character <- first 2:address:duplex-list:character + 2:address:duplex-list:character <- next 2:address:duplex-list:character + 4:character <- first 2:address:duplex-list:character + 2:address:duplex-list:character <- next 2:address:duplex-list:character + 5:character <- first 2:address:duplex-list:character + 2:address:duplex-list:character <- next 2:address:duplex-list:character + 6:character <- first 2:address:duplex-list:character + 2:address:duplex-list:character <- prev 2:address:duplex-list:character + 7:character <- first 2:address:duplex-list:character + 2:address:duplex-list:character <- prev 2:address:duplex-list:character + 8:character <- first 2:address:duplex-list:character + 2:address:duplex-list:character <- prev 2:address:duplex-list:character + 9:character <- first 2:address:duplex-list:character + 10:boolean <- equal 1:address:duplex-list:character, 2:address:duplex-list:character ] memory-should-contain [ 3 <- 5 # scanning next @@ -209,13 +209,13 @@ scenario inserting-after-start-of-duplex-list [ # # Returns null if and only if list is empty. Beware: in that case any other # pointers to the head are now invalid. -def remove x:address:shared:duplex-list:_elem/contained-in:in, in:address:shared:duplex-list:_elem -> in:address:shared:duplex-list:_elem [ +def remove x:address:duplex-list:_elem/contained-in:in, in:address:duplex-list:_elem -> in:address:duplex-list:_elem [ local-scope load-ingredients # if 'x' is null, return return-unless x - next-node:address:shared:duplex-list:_elem <- get *x, next:offset - prev-node:address:shared:duplex-list:_elem <- get *x, prev:offset + next-node:address:duplex-list:_elem <- get *x, next:offset + prev-node:address:duplex-list:_elem <- get *x, prev:offset # null x's pointers *x <- put *x, next:offset, 0 *x <- put *x, prev:offset, 0 @@ -237,21 +237,21 @@ def remove x:address:shared:duplex-list:_elem/contained-in:in, in:address:shared scenario removing-from-duplex-list [ run [ - 1:address:shared:duplex-list:character <- push 3, 0 - 1:address:shared:duplex-list:character <- push 4, 1:address:shared:duplex-list:character - 1:address:shared:duplex-list:character <- push 5, 1:address:shared:duplex-list:character - 2:address:shared:duplex-list:character <- next 1:address:shared:duplex-list:character # 2 points at second element - 1:address:shared:duplex-list:character <- remove 2:address:shared:duplex-list:character, 1:address:shared:duplex-list:character - 3:boolean <- equal 2:address:shared:duplex-list:character, 0 + 1:address:duplex-list:character <- push 3, 0 + 1:address:duplex-list:character <- push 4, 1:address:duplex-list:character + 1:address:duplex-list:character <- push 5, 1:address:duplex-list:character + 2:address:duplex-list:character <- next 1:address:duplex-list:character # 2 points at second element + 1:address:duplex-list:character <- remove 2:address:duplex-list:character, 1:address:duplex-list:character + 3:boolean <- equal 2:address:duplex-list:character, 0 # check structure like before - 2:address:shared:duplex-list:character <- copy 1:address:shared:duplex-list:character - 4:character <- first 2:address:shared:duplex-list:character - 2:address:shared:duplex-list:character <- next 2:address:shared:duplex-list:character - 5:character <- first 2:address:shared:duplex-list:character - 6:address:shared:duplex-list:character <- next 2:address:shared:duplex-list:character - 2:address:shared:duplex-list:character <- prev 2:address:shared:duplex-list:character - 7:character <- first 2:address:shared:duplex-list:character - 8:boolean <- equal 1:address:shared:duplex-list:character, 2:address:shared:duplex-list:character + 2:address:duplex-list:character <- copy 1:address:duplex-list:character + 4:character <- first 2:address:duplex-list:character + 2:address:duplex-list:character <- next 2:address:duplex-list:character + 5:character <- first 2:address:duplex-list:character + 6:address:duplex-list:character <- next 2:address:duplex-list:character + 2:address:duplex-list:character <- prev 2:address:duplex-list:character + 7:character <- first 2:address:duplex-list:character + 8:boolean <- equal 1:address:duplex-list:character, 2:address:duplex-list:character ] memory-should-contain [ 3 <- 0 # remove returned non-null @@ -265,19 +265,19 @@ scenario removing-from-duplex-list [ scenario removing-from-start-of-duplex-list [ run [ - 1:address:shared:duplex-list:character <- push 3, 0 - 1:address:shared:duplex-list:character <- push 4, 1:address:shared:duplex-list:character - 1:address:shared:duplex-list:character <- push 5, 1:address:shared:duplex-list:character - 1:address:shared:duplex-list:character <- remove 1:address:shared:duplex-list:character, 1:address:shared:duplex-list:character + 1:address:duplex-list:character <- push 3, 0 + 1:address:duplex-list:character <- push 4, 1:address:duplex-list:character + 1:address:duplex-list:character <- push 5, 1:address:duplex-list:character + 1:address:duplex-list:character <- remove 1:address:duplex-list:character, 1:address:duplex-list:character # check structure like before - 2:address:shared:duplex-list:character <- copy 1:address:shared:duplex-list:character - 3:character <- first 2:address:shared:duplex-list:character - 2:address:shared:duplex-list:character <- next 2:address:shared:duplex-list:character - 4:character <- first 2:address:shared:duplex-list:character - 5:address:shared:duplex-list:character <- next 2:address:shared:duplex-list:character - 2:address:shared:duplex-list:character <- prev 2:address:shared:duplex-list:character - 6:character <- first 2:address:shared:duplex-list:character - 7:boolean <- equal 1:address:shared:duplex-list:character, 2:address:shared:duplex-list:character + 2:address:duplex-list:character <- copy 1:address:duplex-list:character + 3:character <- first 2:address:duplex-list:character + 2:address:duplex-list:character <- next 2:address:duplex-list:character + 4:character <- first 2:address:duplex-list:character + 5:address:duplex-list:character <- next 2:address:duplex-list:character + 2:address:duplex-list:character <- prev 2:address:duplex-list:character + 6:character <- first 2:address:duplex-list:character + 7:boolean <- equal 1:address:duplex-list:character, 2:address:duplex-list:character ] memory-should-contain [ 3 <- 4 # scanning next, skipping deleted element @@ -290,23 +290,23 @@ scenario removing-from-start-of-duplex-list [ scenario removing-from-end-of-duplex-list [ run [ - 1:address:shared:duplex-list:character <- push 3, 0 - 1:address:shared:duplex-list:character <- push 4, 1:address:shared:duplex-list:character - 1:address:shared:duplex-list:character <- push 5, 1:address:shared:duplex-list:character + 1:address:duplex-list:character <- push 3, 0 + 1:address:duplex-list:character <- push 4, 1:address:duplex-list:character + 1:address:duplex-list:character <- push 5, 1:address:duplex-list:character # delete last element - 2:address:shared:duplex-list:character <- next 1:address:shared:duplex-list:character - 2:address:shared:duplex-list:character <- next 2:address:shared:duplex-list:character - 1:address:shared:duplex-list:character <- remove 2:address:shared:duplex-list:character, 1:address:shared:duplex-list:character - 3:boolean <- equal 2:address:shared:duplex-list:character, 0 + 2:address:duplex-list:character <- next 1:address:duplex-list:character + 2:address:duplex-list:character <- next 2:address:duplex-list:character + 1:address:duplex-list:character <- remove 2:address:duplex-list:character, 1:address:duplex-list:character + 3:boolean <- equal 2:address:duplex-list:character, 0 # check structure like before - 2:address:shared:duplex-list:character <- copy 1:address:shared:duplex-list:character - 4:character <- first 2:address:shared:duplex-list:character - 2:address:shared:duplex-list:character <- next 2:address:shared:duplex-list:character - 5:character <- first 2:address:shared:duplex-list:character - 6:address:shared:duplex-list:character <- next 2:address:shared:duplex-list:character - 2:address:shared:duplex-list:character <- prev 2:address:shared:duplex-list:character - 7:character <- first 2:address:shared:duplex-list:character - 8:boolean <- equal 1:address:shared:duplex-list:character, 2:address:shared:duplex-list:character + 2:address:duplex-list:character <- copy 1:address:duplex-list:character + 4:character <- first 2:address:duplex-list:character + 2:address:duplex-list:character <- next 2:address:duplex-list:character + 5:character <- first 2:address:duplex-list:character + 6:address:duplex-list:character <- next 2:address:duplex-list:character + 2:address:duplex-list:character <- prev 2:address:duplex-list:character + 7:character <- first 2:address:duplex-list:character + 8:boolean <- equal 1:address:duplex-list:character, 2:address:duplex-list:character ] memory-should-contain [ 3 <- 0 # remove returned non-null @@ -320,8 +320,8 @@ scenario removing-from-end-of-duplex-list [ scenario removing-from-singleton-list [ run [ - 1:address:shared:duplex-list:character <- push 3, 0 - 1:address:shared:duplex-list:character <- remove 1:address:shared:duplex-list:character, 1:address:shared:duplex-list:character + 1:address:duplex-list:character <- push 3, 0 + 1:address:duplex-list:character <- remove 1:address:duplex-list:character, 1:address:duplex-list:character ] memory-should-contain [ 1 <- 0 # back to an empty list @@ -333,10 +333,10 @@ scenario removing-from-singleton-list [ # set end to 0 to delete everything past start. # can't set start to 0 to delete everything before end, because there's no # clean way to return the new head pointer. -def remove-between start:address:shared:duplex-list:_elem, end:address:shared:duplex-list:_elem/contained-in:start -> start:address:shared:duplex-list:_elem [ +def remove-between start:address:duplex-list:_elem, end:address:duplex-list:_elem/contained-in:start -> start:address:duplex-list:_elem [ local-scope load-ingredients - next:address:shared:duplex-list:_elem <- get *start, next:offset + next:address:duplex-list:_elem <- get *start, next:offset nothing-to-delete?:boolean <- equal next, end return-if nothing-to-delete? assert next, [malformed duplex list] @@ -347,7 +347,7 @@ def remove-between start:address:shared:duplex-list:_elem, end:address:shared:du return-unless end # end->prev->next = 0 # end->prev = start - prev:address:shared:duplex-list:_elem <- get *end, prev:offset + prev:address:duplex-list:_elem <- get *end, prev:offset assert prev, [malformed duplex list - 2] *prev <- put *prev, next:offset, 0 *end <- put *end, prev:offset, start @@ -355,25 +355,25 @@ def remove-between start:address:shared:duplex-list:_elem, end:address:shared:du scenario remove-range [ # construct a duplex list with six elements [13, 14, 15, 16, 17, 18] - 1:address:shared:duplex-list:character <- push 18, 0 - 1:address:shared:duplex-list:character <- push 17, 1:address:shared:duplex-list:character - 1:address:shared:duplex-list:character <- push 16, 1:address:shared:duplex-list:character - 1:address:shared:duplex-list:character <- push 15, 1:address:shared:duplex-list:character - 1:address:shared:duplex-list:character <- push 14, 1:address:shared:duplex-list:character - 1:address:shared:duplex-list:character <- push 13, 1:address:shared:duplex-list:character + 1:address:duplex-list:character <- push 18, 0 + 1:address:duplex-list:character <- push 17, 1:address:duplex-list:character + 1:address:duplex-list:character <- push 16, 1:address:duplex-list:character + 1:address:duplex-list:character <- push 15, 1:address:duplex-list:character + 1:address:duplex-list:character <- push 14, 1:address:duplex-list:character + 1:address:duplex-list:character <- push 13, 1:address:duplex-list:character run [ # delete 16 onwards # first pointer: to the third element - 2:address:shared:duplex-list:character <- next 1:address:shared:duplex-list:character - 2:address:shared:duplex-list:character <- next 2:address:shared:duplex-list:character - 2:address:shared:duplex-list:character <- remove-between 2:address:shared:duplex-list:character, 0 + 2:address:duplex-list:character <- next 1:address:duplex-list:character + 2:address:duplex-list:character <- next 2:address:duplex-list:character + 2:address:duplex-list:character <- remove-between 2:address:duplex-list:character, 0 # now check the list - 4:character <- get *1:address:shared:duplex-list:character, value:offset - 5:address:shared:duplex-list:character <- next 1:address:shared:duplex-list:character - 6:character <- get *5:address:shared:duplex-list:character, value:offset - 7:address:shared:duplex-list:character <- next 5:address:shared:duplex-list:character - 8:character <- get *7:address:shared:duplex-list:character, value:offset - 9:address:shared:duplex-list:character <- next 7:address:shared:duplex-list:character + 4:character <- get *1:address:duplex-list:character, value:offset + 5:address:duplex-list:character <- next 1:address:duplex-list:character + 6:character <- get *5:address:duplex-list:character, value:offset + 7:address:duplex-list:character <- next 5:address:duplex-list:character + 8:character <- get *7:address:duplex-list:character, value:offset + 9:address:duplex-list:character <- next 7:address:duplex-list:character ] memory-should-contain [ 4 <- 13 @@ -385,29 +385,29 @@ scenario remove-range [ scenario remove-range-to-final [ # construct a duplex list with six elements [13, 14, 15, 16, 17, 18] - 1:address:shared:duplex-list:character <- push 18, 0 - 1:address:shared:duplex-list:character <- push 17, 1:address:shared:duplex-list:character - 1:address:shared:duplex-list:character <- push 16, 1:address:shared:duplex-list:character - 1:address:shared:duplex-list:character <- push 15, 1:address:shared:duplex-list:character - 1:address:shared:duplex-list:character <- push 14, 1:address:shared:duplex-list:character - 1:address:shared:duplex-list:character <- push 13, 1:address:shared:duplex-list:character + 1:address:duplex-list:character <- push 18, 0 + 1:address:duplex-list:character <- push 17, 1:address:duplex-list:character + 1:address:duplex-list:character <- push 16, 1:address:duplex-list:character + 1:address:duplex-list:character <- push 15, 1:address:duplex-list:character + 1:address:duplex-list:character <- push 14, 1:address:duplex-list:character + 1:address:duplex-list:character <- push 13, 1:address:duplex-list:character run [ # delete 15, 16 and 17 # start pointer: to the second element - 2:address:shared:duplex-list:character <- next 1:address:shared:duplex-list:character + 2:address:duplex-list:character <- next 1:address:duplex-list:character # end pointer: to the last (sixth) element - 3:address:shared:duplex-list:character <- next 2:address:shared:duplex-list:character - 3:address:shared:duplex-list:character <- next 3:address:shared:duplex-list:character - 3:address:shared:duplex-list:character <- next 3:address:shared:duplex-list:character - 3:address:shared:duplex-list:character <- next 3:address:shared:duplex-list:character - remove-between 2:address:shared:duplex-list:character, 3:address:shared:duplex-list:character + 3:address:duplex-list:character <- next 2:address:duplex-list:character + 3:address:duplex-list:character <- next 3:address:duplex-list:character + 3:address:duplex-list:character <- next 3:address:duplex-list:character + 3:address:duplex-list:character <- next 3:address:duplex-list:character + remove-between 2:address:duplex-list:character, 3:address:duplex-list:character # now check the list - 4:character <- get *1:address:shared:duplex-list:character, value:offset - 5:address:shared:duplex-list:character <- next 1:address:shared:duplex-list:character - 6:character <- get *5:address:shared:duplex-list:character, value:offset - 7:address:shared:duplex-list:character <- next 5:address:shared:duplex-list:character - 8:character <- get *7:address:shared:duplex-list:character, value:offset - 9:address:shared:duplex-list:character <- next 7:address:shared:duplex-list:character + 4:character <- get *1:address:duplex-list:character, value:offset + 5:address:duplex-list:character <- next 1:address:duplex-list:character + 6:character <- get *5:address:duplex-list:character, value:offset + 7:address:duplex-list:character <- next 5:address:duplex-list:character + 8:character <- get *7:address:duplex-list:character, value:offset + 9:address:duplex-list:character <- next 7:address:duplex-list:character ] memory-should-contain [ 4 <- 13 @@ -419,20 +419,20 @@ scenario remove-range-to-final [ scenario remove-range-empty [ # construct a duplex list with three elements [13, 14, 15] - 1:address:shared:duplex-list:character <- push 15, 0 - 1:address:shared:duplex-list:character <- push 14, 1:address:shared:duplex-list:character - 1:address:shared:duplex-list:character <- push 13, 1:address:shared:duplex-list:character + 1:address:duplex-list:character <- push 15, 0 + 1:address:duplex-list:character <- push 14, 1:address:duplex-list:character + 1:address:duplex-list:character <- push 13, 1:address:duplex-list:character run [ # delete between first and second element (i.e. nothing) - 2:address:shared:duplex-list:character <- next 1:address:shared:duplex-list:character - remove-between 1:address:shared:duplex-list:character, 2:address:shared:duplex-list:character + 2:address:duplex-list:character <- next 1:address:duplex-list:character + remove-between 1:address:duplex-list:character, 2:address:duplex-list:character # now check the list - 4:character <- get *1:address:shared:duplex-list:character, value:offset - 5:address:shared:duplex-list:character <- next 1:address:shared:duplex-list:character - 6:character <- get *5:address:shared:duplex-list:character, value:offset - 7:address:shared:duplex-list:character <- next 5:address:shared:duplex-list:character - 8:character <- get *7:address:shared:duplex-list:character, value:offset - 9:address:shared:duplex-list:character <- next 7:address:shared:duplex-list:character + 4:character <- get *1:address:duplex-list:character, value:offset + 5:address:duplex-list:character <- next 1:address:duplex-list:character + 6:character <- get *5:address:duplex-list:character, value:offset + 7:address:duplex-list:character <- next 5:address:duplex-list:character + 8:character <- get *7:address:duplex-list:character, value:offset + 9:address:duplex-list:character <- next 7:address:duplex-list:character ] # no change memory-should-contain [ @@ -445,21 +445,21 @@ scenario remove-range-empty [ scenario remove-range-to-end [ # construct a duplex list with six elements [13, 14, 15, 16, 17, 18] - 1:address:shared:duplex-list:character <- push 18, 0 - 1:address:shared:duplex-list:character <- push 17, 1:address:shared:duplex-list:character - 1:address:shared:duplex-list:character <- push 16, 1:address:shared:duplex-list:character - 1:address:shared:duplex-list:character <- push 15, 1:address:shared:duplex-list:character - 1:address:shared:duplex-list:character <- push 14, 1:address:shared:duplex-list:character - 1:address:shared:duplex-list:character <- push 13, 1:address:shared:duplex-list:character + 1:address:duplex-list:character <- push 18, 0 + 1:address:duplex-list:character <- push 17, 1:address:duplex-list:character + 1:address:duplex-list:character <- push 16, 1:address:duplex-list:character + 1:address:duplex-list:character <- push 15, 1:address:duplex-list:character + 1:address:duplex-list:character <- push 14, 1:address:duplex-list:character + 1:address:duplex-list:character <- push 13, 1:address:duplex-list:character run [ # remove the third element and beyond - 2:address:shared:duplex-list:character <- next 1:address:shared:duplex-list:character - remove-between 2:address:shared:duplex-list:character, 0 + 2:address:duplex-list:character <- next 1:address:duplex-list:character + remove-between 2:address:duplex-list:character, 0 # now check the list - 4:character <- get *1:address:shared:duplex-list:character, value:offset - 5:address:shared:duplex-list:character <- next 1:address:shared:duplex-list:character - 6:character <- get *5:address:shared:duplex-list:character, value:offset - 7:address:shared:duplex-list:character <- next 5:address:shared:duplex-list:character + 4:character <- get *1:address:duplex-list:character, value:offset + 5:address:duplex-list:character <- next 1:address:duplex-list:character + 6:character <- get *5:address:duplex-list:character, value:offset + 7:address:duplex-list:character <- next 5:address:duplex-list:character ] memory-should-contain [ 4 <- 13 @@ -469,19 +469,19 @@ scenario remove-range-to-end [ ] # insert list beginning at 'new' after 'in' -def insert-range in:address:shared:duplex-list:_elem, start:address:shared:duplex-list:_elem/contained-in:in -> in:address:shared:duplex-list:_elem [ +def insert-range in:address:duplex-list:_elem, start:address:duplex-list:_elem/contained-in:in -> in:address:duplex-list:_elem [ local-scope load-ingredients return-unless in return-unless start - end:address:shared:duplex-list:_elem <- copy start + end:address:duplex-list:_elem <- copy start { - next:address:shared:duplex-list:_elem <- next end/insert-range + next:address:duplex-list:_elem <- next end/insert-range break-unless next end <- copy next loop } - next:address:shared:duplex-list:_elem <- next in + next:address:duplex-list:_elem <- next in *end <- put *end, next:offset, next { break-unless next @@ -491,21 +491,21 @@ def insert-range in:address:shared:duplex-list:_elem, start:address:shared:duple *start <- put *start, prev:offset, in ] -def append in:address:shared:duplex-list:_elem, new:address:shared:duplex-list:_elem/contained-in:in -> in:address:shared:duplex-list:_elem [ +def append in:address:duplex-list:_elem, new:address:duplex-list:_elem/contained-in:in -> in:address:duplex-list:_elem [ local-scope load-ingredients - last:address:shared:duplex-list:_elem <- last in + last:address:duplex-list:_elem <- last in *last <- put *last, next:offset, new return-unless new *new <- put *new, prev:offset, last ] -def last in:address:shared:duplex-list:_elem -> result:address:shared:duplex-list:_elem [ +def last in:address:duplex-list:_elem -> result:address:duplex-list:_elem [ local-scope load-ingredients result <- copy in { - next:address:shared:duplex-list:_elem <- next result + next:address:duplex-list:_elem <- next result break-unless next result <- copy next loop @@ -513,7 +513,7 @@ def last in:address:shared:duplex-list:_elem -> result:address:shared:duplex-lis ] # helper for debugging -def dump-from x:address:shared:duplex-list:_elem [ +def dump-from x:address:duplex-list:_elem [ local-scope load-ingredients $print x, [: ] diff --git a/077stream.mu b/077stream.mu index 305a150f..db7c189a 100644 --- a/077stream.mu +++ b/077stream.mu @@ -1,10 +1,10 @@ # new type to help incrementally read texts (arrays of characters) container stream [ index:number - data:address:shared:array:character + data:address:array:character ] -def new-stream s:address:shared:array:character -> result:address:shared:stream [ +def new-stream s:address:array:character -> result:address:stream [ local-scope load-ingredients result <- new stream:type @@ -12,17 +12,17 @@ def new-stream s:address:shared:array:character -> result:address:shared:stream *result <- put *result, data:offset, s ] -def rewind-stream in:address:shared:stream -> in:address:shared:stream [ +def rewind-stream in:address:stream -> in:address:stream [ local-scope load-ingredients *in <- put *in, index:offset, 0 ] -def read-line in:address:shared:stream -> result:address:shared:array:character, in:address:shared:stream [ +def read-line in:address:stream -> result:address:array:character, in:address:stream [ local-scope load-ingredients idx:number <- get *in, index:offset - s:address:shared:array:character <- get *in, data:offset + s:address:array:character <- get *in, data:offset next-idx:number <- find-next s, 10/newline, idx result <- copy-range s, idx, next-idx idx <- add next-idx, 1 # skip newline @@ -30,11 +30,11 @@ def read-line in:address:shared:stream -> result:address:shared:array:character, *in <- put *in, index:offset, idx ] -def end-of-stream? in:address:shared:stream -> result:boolean [ +def end-of-stream? in:address:stream -> result:boolean [ local-scope load-ingredients idx:number <- get *in, index:offset - s:address:shared:array:character <- get *in, data:offset + s:address:array:character <- get *in, data:offset len:number <- length *s result <- greater-or-equal idx, len ] diff --git a/078hash.cc b/078hash.cc index 454a9003..59b3e222 100644 --- a/078hash.cc +++ b/078hash.cc @@ -55,12 +55,13 @@ size_t hash_mu_scalar(size_t h, const reagent& r) { size_t hash_mu_address(size_t h, reagent& r) { if (r.value == 0) return 0; + trace(9999, "mem") << "location " << r.value << " is " << no_scientific(get_or_insert(Memory, r.value)) << end(); r.value = get_or_insert(Memory, r.value); - drop_from_type(r, "address"); - if (r.type->name == "shared") { - ++r.value; - drop_from_type(r, "shared"); + if (r.value != 0) { + trace(9999, "mem") << "skipping refcount at " << r.value << end(); + r.set_value(r.value+1); // skip refcount } + drop_from_type(r, "address"); return hash(h, r); } @@ -221,8 +222,8 @@ def main [ 13:number <- copy 99 2:number <- hash 10:array:number/unsafe return-unless 2:number - 3:address:shared:array:character <- new [abc] - 4:number <- hash 3:address:shared:array:character + 3:address:array:character <- new [abc] + 4:number <- hash 3:address:array:character return-unless 4:number 5:boolean <- equal 2:number, 4:number ] @@ -230,12 +231,12 @@ def main [ :(scenario hash_ignores_address_value) def main [ - 1:address:shared:number <- new number:type - *1:address:shared:number <- copy 34 - 2:number <- hash 1:address:shared:number - 3:address:shared:number <- new number:type - *3:address:shared:number <- copy 34 - 4:number <- hash 3:address:shared:number + 1:address:number <- new number:type + *1:address:number <- copy 34 + 2:number <- hash 1:address:number + 3:address:number <- new number:type + *3:address:number <- copy 34 + 4:number <- hash 3:address:number 5:boolean <- equal 2:number, 4:number ] # different addresses hash to the same result as long as the values the point to do so @@ -243,13 +244,13 @@ def main [ :(scenario hash_ignores_address_refcount) def main [ - 1:address:shared:number <- new number:type - *1:address:shared:number <- copy 34 - 2:number <- hash 1:address:shared:number + 1:address:number <- new number:type + *1:address:number <- copy 34 + 2:number <- hash 1:address:number return-unless 2:number # increment refcount - 3:address:shared:number <- copy 1:address:shared:number - 4:number <- hash 3:address:shared:number + 3:address:number <- copy 1:address:number + 4:number <- hash 3:address:number return-unless 4:number 5:boolean <- equal 2:number, 4:number ] @@ -281,17 +282,17 @@ def main [ container foo [ x:number y:character - z:address:shared:number + z:address:number ] def main [ - 1:address:shared:number <- new number:type - *1:address:shared:number <- copy 34 - 2:foo <- merge 34, 97/a, 1:address:shared:number + 1:address:number <- new number:type + *1:address:number <- copy 34 + 2:foo <- merge 34, 97/a, 1:address:number 5:number <- hash 2:foo return-unless 5:number - 6:address:shared:number <- new number:type - *6:address:shared:number <- copy 34 - 7:foo <- merge 34, 97/a, 6:address:shared:number + 6:address:number <- new number:type + *6:address:number <- copy 34 + 7:foo <- merge 34, 97/a, 6:address:number 10:number <- hash 7:foo return-unless 10:number 11:boolean <- equal 5:number, 10:number @@ -348,9 +349,9 @@ def main [ :(scenario hash_matches_old_version) def main [ - 1:address:shared:array:character <- new [abc] - 2:number <- hash 1:address:shared:array:character - 3:number <- hash_old 1:address:shared:array:character + 1:address:array:character <- new [abc] + 2:number <- hash 1:address:array:character + 3:number <- hash_old 1:address:array:character 4:boolean <- equal 2:number, 3:number ] +mem: storing 1 in location 4 @@ -366,7 +367,7 @@ case HASH_OLD: { break; } if (!is_mu_string(inst.ingredients.at(0))) { - raise << maybe(get(Recipe, r).name) << "'hash_old' currently only supports strings (address:shared:array:character), but got " << inst.ingredients.at(0).original_string << '\n' << end(); + raise << maybe(get(Recipe, r).name) << "'hash_old' currently only supports strings (address:array:character), but got " << inst.ingredients.at(0).original_string << '\n' << end(); break; } break; diff --git a/079table.mu b/079table.mu index 9040f6ce..40b3ff34 100644 --- a/079table.mu +++ b/079table.mu @@ -3,9 +3,9 @@ scenario table-read-write [ run [ - 1:address:shared:table:number:number <- new-table 30 - put 1:address:shared:table:number:number, 12, 34 - 2:number <- index 1:address:shared:table:number:number, 12 + 1:address:table:number:number <- new-table 30 + put 1:address:table:number:number, 12, 34 + 2:number <- index 1:address:table:number:number, 12 ] memory-should-contain [ 2 <- 34 @@ -14,10 +14,10 @@ scenario table-read-write [ scenario table-read-write-non-integer [ run [ - 1:address:shared:array:character <- new [abc def] - {2: (address shared table (address shared array character) number)} <- new-table 30 - put {2: (address shared table (address shared array character) number)}, 1:address:shared:array:character, 34 - 3:number <- index {2: (address shared table (address shared array character) number)}, 1:address:shared:array:character + 1:address:array:character <- new [abc def] + {2: (address table (address array character) number)} <- new-table 30 + put {2: (address table (address array character) number)}, 1:address:array:character, 34 + 3:number <- index {2: (address table (address array character) number)}, 1:address:array:character ] memory-should-contain [ 3 <- 34 @@ -27,7 +27,7 @@ scenario table-read-write-non-integer [ container table:_key:_value [ length:number capacity:number - data:address:shared:array:table_row:_key:_value + data:address:array:table_row:_key:_value ] container table_row:_key:_value [ @@ -36,15 +36,15 @@ container table_row:_key:_value [ value:_value ] -def new-table capacity:number -> result:address:shared:table:_key:_value [ +def new-table capacity:number -> result:address:table:_key:_value [ local-scope load-ingredients result <- new {(table _key _value): type} - data:address:shared:array:table_row:_key:_value <- new {(table_row _key _value): type}, capacity + data:address:array:table_row:_key:_value <- new {(table_row _key _value): type}, capacity *result <- merge 0/length, capacity, data ] -def put table:address:shared:table:_key:_value, key:_key, value:_value -> table:address:shared:table:_key:_value [ +def put table:address:table:_key:_value, key:_key, value:_value -> table:address:table:_key:_value [ local-scope load-ingredients hash:number <- hash key @@ -52,7 +52,7 @@ def put table:address:shared:table:_key:_value, key:_key, value:_value -> table: capacity:number <- get *table, capacity:offset _, hash <- divide-with-remainder hash, capacity hash <- abs hash # in case hash overflows into a negative integer - table-data:address:shared:array:table_row:_key:_value <- get *table, data:offset + table-data:address:array:table_row:_key:_value <- get *table, data:offset x:table_row:_key:_value <- index *table-data, hash occupied?:boolean <- get x, occupied?:offset not-occupied?:boolean <- not occupied?:boolean @@ -69,7 +69,7 @@ def abs n:number -> result:number [ result <- multiply n, -1 ] -def index table:address:shared:table:_key:_value, key:_key -> result:_value [ +def index table:address:table:_key:_value, key:_key -> result:_value [ local-scope load-ingredients hash:number <- hash key @@ -77,7 +77,7 @@ def index table:address:shared:table:_key:_value, key:_key -> result:_value [ capacity:number <- get *table, capacity:offset _, hash <- divide-with-remainder hash, capacity hash <- abs hash # in case hash overflows into a negative integer - table-data:address:shared:array:table_row:_key:_value <- get *table, data:offset + table-data:address:array:table_row:_key:_value <- get *table, data:offset x:table_row:_key:_value <- index *table-data, hash occupied?:boolean <- get x, occupied?:offset assert occupied?, [can't handle missing elements yet] diff --git a/081print.mu b/081print.mu index 21b0cfe4..fd5ed196 100644 --- a/081print.mu +++ b/081print.mu @@ -6,7 +6,7 @@ container screen [ num-columns:number cursor-row:number cursor-column:number - data:address:shared:array:screen-cell + data:address:array:screen-cell ] container screen-cell [ @@ -14,24 +14,24 @@ container screen-cell [ color:number ] -def new-fake-screen w:number, h:number -> result:address:shared:screen [ +def new-fake-screen w:number, h:number -> result:address:screen [ local-scope load-ingredients result <- new screen:type bufsize:number <- multiply w, h - data:address:shared:array:screen-cell <- new screen-cell:type, bufsize + data:address:array:screen-cell <- new screen-cell:type, bufsize *result <- merge h/num-rows, w/num-columns, 0/cursor-row, 0/cursor-column, data result <- clear-screen result ] -def clear-screen screen:address:shared:screen -> screen:address:shared:screen [ +def clear-screen screen:address:screen -> screen:address:screen [ local-scope load-ingredients # if x exists { break-unless screen # clear fake screen - buf:address:shared:array:screen-cell <- get *screen, data:offset + buf:address:array:screen-cell <- get *screen, data:offset max:number <- length *buf i:number <- copy 0 { @@ -51,7 +51,7 @@ def clear-screen screen:address:shared:screen -> screen:address:shared:screen [ clear-display ] -def sync-screen screen:address:shared:screen -> screen:address:shared:screen [ +def sync-screen screen:address:screen -> screen:address:screen [ local-scope load-ingredients { @@ -61,11 +61,11 @@ def sync-screen screen:address:shared:screen -> screen:address:shared:screen [ # do nothing for fake screens ] -def fake-screen-is-empty? screen:address:shared:screen -> result:boolean [ +def fake-screen-is-empty? screen:address:screen -> result:boolean [ local-scope load-ingredients return-unless screen, 1/true - buf:address:shared:array:screen-cell <- get *screen, data:offset + buf:address:array:screen-cell <- get *screen, data:offset i:number <- copy 0 len:number <- length *buf { @@ -81,7 +81,7 @@ def fake-screen-is-empty? screen:address:shared:screen -> result:boolean [ return 1/true ] -def print screen:address:shared:screen, c:character -> screen:address:shared:screen [ +def print screen:address:screen, c:character -> screen:address:screen [ local-scope load-ingredients color:number, color-found?:boolean <- next-ingredient @@ -135,7 +135,7 @@ def print screen:address:shared:screen, c:character -> screen:address:shared:scr # save character in fake screen index:number <- multiply row, width index <- add index, column - buf:address:shared:array:screen-cell <- get *screen, data:offset + buf:address:array:screen-cell <- get *screen, data:offset len:number <- length *buf # special-case: backspace { @@ -172,11 +172,11 @@ def print screen:address:shared:screen, c:character -> screen:address:shared:scr scenario print-character-at-top-left [ run [ - 1:address:shared:screen <- new-fake-screen 3/width, 2/height + 1:address:screen <- new-fake-screen 3/width, 2/height 11:character <- copy 97/a - 1:address:shared:screen <- print 1:address:shared:screen, 11:character/a - 2:address:shared:array:screen-cell <- get *1:address:shared:screen, data:offset - 3:array:screen-cell <- copy *2:address:shared:array:screen-cell + 1:address:screen <- print 1:address:screen, 11:character/a + 2:address:array:screen-cell <- get *1:address:screen, data:offset + 3:array:screen-cell <- copy *2:address:array:screen-cell ] memory-should-contain [ 3 <- 6 # width*height @@ -188,11 +188,11 @@ scenario print-character-at-top-left [ scenario print-character-in-color [ run [ - 1:address:shared:screen <- new-fake-screen 3/width, 2/height + 1:address:screen <- new-fake-screen 3/width, 2/height 11:character <- copy 97/a - 1:address:shared:screen <- print 1:address:shared:screen, 11:character/a, 1/red - 2:address:shared:array:screen-cell <- get *1:address:shared:screen, data:offset - 3:array:screen-cell <- copy *2:address:shared:array:screen-cell + 1:address:screen <- print 1:address:screen, 11:character/a, 1/red + 2:address:array:screen-cell <- get *1:address:screen, data:offset + 3:array:screen-cell <- copy *2:address:array:screen-cell ] memory-should-contain [ 3 <- 6 # width*height @@ -204,14 +204,14 @@ scenario print-character-in-color [ scenario print-backspace-character [ run [ - 1:address:shared:screen <- new-fake-screen 3/width, 2/height + 1:address:screen <- new-fake-screen 3/width, 2/height 11:character <- copy 97/a - 1:address:shared:screen <- print 1:address:shared:screen, 11:character/a + 1:address:screen <- print 1:address:screen, 11:character/a 12:character <- copy 8/backspace - 1:address:shared:screen <- print 1:address:shared:screen, 12:character/backspace - 2:number <- get *1:address:shared:screen, cursor-column:offset - 3:address:shared:array:screen-cell <- get *1:address:shared:screen, data:offset - 4:array:screen-cell <- copy *3:address:shared:array:screen-cell + 1:address:screen <- print 1:address:screen, 12:character/backspace + 2:number <- get *1:address:screen, cursor-column:offset + 3:address:array:screen-cell <- get *1:address:screen, data:offset + 4:array:screen-cell <- copy *3:address:array:screen-cell ] memory-should-contain [ 2 <- 0 # cursor column @@ -224,16 +224,16 @@ scenario print-backspace-character [ scenario print-extra-backspace-character [ run [ - 1:address:shared:screen <- new-fake-screen 3/width, 2/height + 1:address:screen <- new-fake-screen 3/width, 2/height 11:character <- copy 97/a - 1:address:shared:screen <- print 1:address:shared:screen, 11:character/a + 1:address:screen <- print 1:address:screen, 11:character/a 12:character <- copy 8/backspace - 1:address:shared:screen <- print 1:address:shared:screen, 12:character/backspace + 1:address:screen <- print 1:address:screen, 12:character/backspace 12:character <- copy 8/backspace - 1:address:shared:screen <- print 1:address:shared:screen, 12:character/backspace - 2:number <- get *1:address:shared:screen, cursor-column:offset - 3:address:shared:array:screen-cell <- get *1:address:shared:screen, data:offset - 4:array:screen-cell <- copy *3:address:shared:array:screen-cell + 1:address:screen <- print 1:address:screen, 12:character/backspace + 2:number <- get *1:address:screen, cursor-column:offset + 3:address:array:screen-cell <- get *1:address:screen, data:offset + 4:array:screen-cell <- copy *3:address:array:screen-cell ] memory-should-contain [ 2 <- 0 # cursor column @@ -246,16 +246,16 @@ scenario print-extra-backspace-character [ scenario print-character-at-right-margin [ run [ - 1:address:shared:screen <- new-fake-screen 2/width, 2/height + 1:address:screen <- new-fake-screen 2/width, 2/height 11:character <- copy 97/a - 1:address:shared:screen <- print 1:address:shared:screen, 11:character/a + 1:address:screen <- print 1:address:screen, 11:character/a 12:character <- copy 98/b - 1:address:shared:screen <- print 1:address:shared:screen, 12:character/b + 1:address:screen <- print 1:address:screen, 12:character/b 13:character <- copy 99/b - 1:address:shared:screen <- print 1:address:shared:screen, 13:character/c - 2:number <- get *1:address:shared:screen, cursor-column:offset - 3:address:shared:array:screen-cell <- get *1:address:shared:screen, data:offset - 4:array:screen-cell <- copy *3:address:shared:array:screen-cell + 1:address:screen <- print 1:address:screen, 13:character/c + 2:number <- get *1:address:screen, cursor-column:offset + 3:address:array:screen-cell <- get *1:address:screen, data:offset + 4:array:screen-cell <- copy *3:address:array:screen-cell ] memory-should-contain [ 2 <- 1 # cursor column @@ -270,15 +270,15 @@ scenario print-character-at-right-margin [ scenario print-newline-character [ run [ - 1:address:shared:screen <- new-fake-screen 3/width, 2/height + 1:address:screen <- new-fake-screen 3/width, 2/height 10:character <- copy 10/newline 11:character <- copy 97/a - 1:address:shared:screen <- print 1:address:shared:screen, 11:character/a - 1:address:shared:screen <- print 1:address:shared:screen, 10:character/newline - 2:number <- get *1:address:shared:screen, cursor-row:offset - 3:number <- get *1:address:shared:screen, cursor-column:offset - 4:address:shared:array:screen-cell <- get *1:address:shared:screen, data:offset - 5:array:screen-cell <- copy *4:address:shared:array:screen-cell + 1:address:screen <- print 1:address:screen, 11:character/a + 1:address:screen <- print 1:address:screen, 10:character/newline + 2:number <- get *1:address:screen, cursor-row:offset + 3:number <- get *1:address:screen, cursor-column:offset + 4:address:array:screen-cell <- get *1:address:screen, data:offset + 5:array:screen-cell <- copy *4:address:array:screen-cell ] memory-should-contain [ 2 <- 1 # cursor row @@ -292,13 +292,13 @@ scenario print-newline-character [ scenario print-newline-at-bottom-line [ run [ - 1:address:shared:screen <- new-fake-screen 3/width, 2/height + 1:address:screen <- new-fake-screen 3/width, 2/height 10:character <- copy 10/newline - 1:address:shared:screen <- print 1:address:shared:screen, 10:character/newline - 1:address:shared:screen <- print 1:address:shared:screen, 10:character/newline - 1:address:shared:screen <- print 1:address:shared:screen, 10:character/newline - 2:number <- get *1:address:shared:screen, cursor-row:offset - 3:number <- get *1:address:shared:screen, cursor-column:offset + 1:address:screen <- print 1:address:screen, 10:character/newline + 1:address:screen <- print 1:address:screen, 10:character/newline + 1:address:screen <- print 1:address:screen, 10:character/newline + 2:number <- get *1:address:screen, cursor-row:offset + 3:number <- get *1:address:screen, cursor-column:offset ] memory-should-contain [ 2 <- 1 # cursor row @@ -308,22 +308,22 @@ scenario print-newline-at-bottom-line [ scenario print-character-at-bottom-right [ run [ - 1:address:shared:screen <- new-fake-screen 2/width, 2/height + 1:address:screen <- new-fake-screen 2/width, 2/height 10:character <- copy 10/newline - 1:address:shared:screen <- print 1:address:shared:screen, 10:character/newline + 1:address:screen <- print 1:address:screen, 10:character/newline 11:character <- copy 97/a - 1:address:shared:screen <- print 1:address:shared:screen, 11:character/a + 1:address:screen <- print 1:address:screen, 11:character/a 12:character <- copy 98/b - 1:address:shared:screen <- print 1:address:shared:screen, 12:character/b + 1:address:screen <- print 1:address:screen, 12:character/b 13:character <- copy 99/c - 1:address:shared:screen <- print 1:address:shared:screen, 13:character/c - 1:address:shared:screen <- print 1:address:shared:screen, 10:character/newline + 1:address:screen <- print 1:address:screen, 13:character/c + 1:address:screen <- print 1:address:screen, 10:character/newline 14:character <- copy 100/d - 1:address:shared:screen <- print 1:address:shared:screen, 14:character/d - 2:number <- get *1:address:shared:screen, cursor-row:offset - 3:number <- get *1:address:shared:screen, cursor-column:offset - 4:address:shared:array:screen-cell <- get *1:address:shared:screen, data:offset - 20:array:screen-cell <- copy *4:address:shared:array:screen-cell + 1:address:screen <- print 1:address:screen, 14:character/d + 2:number <- get *1:address:screen, cursor-row:offset + 3:number <- get *1:address:screen, cursor-column:offset + 4:address:array:screen-cell <- get *1:address:screen, data:offset + 20:array:screen-cell <- copy *4:address:array:screen-cell ] memory-should-contain [ 2 <- 1 # cursor row @@ -341,7 +341,7 @@ scenario print-character-at-bottom-right [ ] ] -def clear-line screen:address:shared:screen -> screen:address:shared:screen [ +def clear-line screen:address:screen -> screen:address:screen [ local-scope load-ingredients space:character <- copy 0/nul @@ -368,7 +368,7 @@ def clear-line screen:address:shared:screen -> screen:address:shared:screen [ clear-line-on-display ] -def cursor-position screen:address:shared:screen -> row:number, column:number [ +def cursor-position screen:address:screen -> row:number, column:number [ local-scope load-ingredients # if x exists, lookup cursor in fake screen @@ -381,7 +381,7 @@ def cursor-position screen:address:shared:screen -> row:number, column:number [ row, column <- cursor-position-on-display ] -def move-cursor screen:address:shared:screen, new-row:number, new-column:number -> screen:address:shared:screen [ +def move-cursor screen:address:screen, new-row:number, new-column:number -> screen:address:screen [ local-scope load-ingredients # if x exists, move cursor in fake screen @@ -397,16 +397,16 @@ def move-cursor screen:address:shared:screen, new-row:number, new-column:number scenario clear-line-erases-printed-characters [ run [ - 1:address:shared:screen <- new-fake-screen 3/width, 2/height + 1:address:screen <- new-fake-screen 3/width, 2/height # print a character 10:character <- copy 97/a - 1:address:shared:screen <- print 1:address:shared:screen, 10:character/a + 1:address:screen <- print 1:address:screen, 10:character/a # move cursor to start of line - 1:address:shared:screen <- move-cursor 1:address:shared:screen, 0/row, 0/column + 1:address:screen <- move-cursor 1:address:screen, 0/row, 0/column # clear line - 1:address:shared:screen <- clear-line 1:address:shared:screen - 2:address:shared:array:screen-cell <- get *1:address:shared:screen, data:offset - 20:array:screen-cell <- copy *2:address:shared:array:screen-cell + 1:address:screen <- clear-line 1:address:screen + 2:address:array:screen-cell <- get *1:address:screen, data:offset + 20:array:screen-cell <- copy *2:address:array:screen-cell ] # screen should be blank memory-should-contain [ @@ -426,7 +426,7 @@ scenario clear-line-erases-printed-characters [ ] ] -def cursor-down screen:address:shared:screen -> screen:address:shared:screen [ +def cursor-down screen:address:screen -> screen:address:screen [ local-scope load-ingredients # if x exists, move cursor in fake screen @@ -448,7 +448,7 @@ def cursor-down screen:address:shared:screen -> screen:address:shared:screen [ move-cursor-down-on-display ] -def cursor-up screen:address:shared:screen -> screen:address:shared:screen [ +def cursor-up screen:address:screen -> screen:address:screen [ local-scope load-ingredients # if x exists, move cursor in fake screen @@ -468,7 +468,7 @@ def cursor-up screen:address:shared:screen -> screen:address:shared:screen [ move-cursor-up-on-display ] -def cursor-right screen:address:shared:screen -> screen:address:shared:screen [ +def cursor-right screen:address:screen -> screen:address:screen [ local-scope load-ingredients # if x exists, move cursor in fake screen @@ -490,7 +490,7 @@ def cursor-right screen:address:shared:screen -> screen:address:shared:screen [ move-cursor-right-on-display ] -def cursor-left screen:address:shared:screen -> screen:address:shared:screen [ +def cursor-left screen:address:screen -> screen:address:screen [ local-scope load-ingredients # if x exists, move cursor in fake screen @@ -510,7 +510,7 @@ def cursor-left screen:address:shared:screen -> screen:address:shared:screen [ move-cursor-left-on-display ] -def cursor-to-start-of-line screen:address:shared:screen -> screen:address:shared:screen [ +def cursor-to-start-of-line screen:address:screen -> screen:address:screen [ local-scope load-ingredients row:number <- cursor-position screen @@ -518,14 +518,14 @@ def cursor-to-start-of-line screen:address:shared:screen -> screen:address:share screen <- move-cursor screen, row, column ] -def cursor-to-next-line screen:address:shared:screen -> screen:address:shared:screen [ +def cursor-to-next-line screen:address:screen -> screen:address:screen [ local-scope load-ingredients screen <- cursor-down screen screen <- cursor-to-start-of-line screen ] -def screen-width screen:address:shared:screen -> width:number [ +def screen-width screen:address:screen -> width:number [ local-scope load-ingredients # if x exists, move cursor in fake screen @@ -538,7 +538,7 @@ def screen-width screen:address:shared:screen -> width:number [ width <- display-width ] -def screen-height screen:address:shared:screen -> height:number [ +def screen-height screen:address:screen -> height:number [ local-scope load-ingredients # if x exists, move cursor in fake screen @@ -551,7 +551,7 @@ def screen-height screen:address:shared:screen -> height:number [ height <- display-height ] -def hide-cursor screen:address:shared:screen -> screen:address:shared:screen [ +def hide-cursor screen:address:screen -> screen:address:screen [ local-scope load-ingredients # if x exists (not real display), do nothing @@ -563,7 +563,7 @@ def hide-cursor screen:address:shared:screen -> screen:address:shared:screen [ hide-cursor-on-display ] -def show-cursor screen:address:shared:screen -> screen:address:shared:screen [ +def show-cursor screen:address:screen -> screen:address:screen [ local-scope load-ingredients # if x exists (not real display), do nothing @@ -575,7 +575,7 @@ def show-cursor screen:address:shared:screen -> screen:address:shared:screen [ show-cursor-on-display ] -def hide-screen screen:address:shared:screen -> screen:address:shared:screen [ +def hide-screen screen:address:screen -> screen:address:screen [ local-scope load-ingredients # if x exists (not real display), do nothing @@ -588,7 +588,7 @@ def hide-screen screen:address:shared:screen -> screen:address:shared:screen [ hide-display ] -def show-screen screen:address:shared:screen -> screen:address:shared:screen [ +def show-screen screen:address:screen -> screen:address:screen [ local-scope load-ingredients # if x exists (not real display), do nothing @@ -601,7 +601,7 @@ def show-screen screen:address:shared:screen -> screen:address:shared:screen [ show-display ] -def print screen:address:shared:screen, s:address:shared:array:character -> screen:address:shared:screen [ +def print screen:address:screen, s:address:array:character -> screen:address:screen [ local-scope load-ingredients color:number, color-found?:boolean <- next-ingredient @@ -630,11 +630,11 @@ def print screen:address:shared:screen, s:address:shared:array:character -> scre scenario print-text-stops-at-right-margin [ run [ - 1:address:shared:screen <- new-fake-screen 3/width, 2/height - 2:address:shared:array:character <- new [abcd] - 1:address:shared:screen <- print 1:address:shared:screen, 2:address:shared:array:character - 3:address:shared:array:screen-cell <- get *1:address:shared:screen, data:offset - 4:array:screen-cell <- copy *3:address:shared:array:screen-cell + 1:address:screen <- new-fake-screen 3/width, 2/height + 2:address:array:character <- new [abcd] + 1:address:screen <- print 1:address:screen, 2:address:array:character + 3:address:array:screen-cell <- get *1:address:screen, data:offset + 4:array:screen-cell <- copy *3:address:array:screen-cell ] memory-should-contain [ 4 <- 6 # width*height @@ -648,7 +648,7 @@ scenario print-text-stops-at-right-margin [ ] ] -def print-integer screen:address:shared:screen, n:number -> screen:address:shared:screen [ +def print-integer screen:address:screen, n:number -> screen:address:screen [ local-scope load-ingredients color:number, color-found?:boolean <- next-ingredient @@ -664,12 +664,12 @@ def print-integer screen:address:shared:screen, n:number -> screen:address:share bg-color <- copy 0/black } # todo: other bases besides decimal - s:address:shared:array:character <- to-text n + s:address:array:character <- to-text n screen <- print screen, s, color, bg-color ] # for now, we can only print integers -def print screen:address:shared:screen, n:number -> screen:address:shared:screen [ +def print screen:address:screen, n:number -> screen:address:screen [ local-scope load-ingredients color:number, color-found?:boolean <- next-ingredient @@ -688,7 +688,7 @@ def print screen:address:shared:screen, n:number -> screen:address:shared:screen ] # addresses -def print screen:address:shared:screen, n:address:_elem -> screen:address:shared:screen [ +def print screen:address:screen, n:address:_elem -> screen:address:screen [ local-scope load-ingredients color:number, color-found?:boolean <- next-ingredient diff --git a/082scenario_screen.cc b/082scenario_screen.cc index 65cf4199..e1a8d1dc 100644 --- a/082scenario_screen.cc +++ b/082scenario_screen.cc @@ -10,7 +10,7 @@ scenario screen-in-scenario [ assume-screen 5/width, 3/height run [ 1:character <- copy 97/a - screen:address:shared:screen <- print screen:address:shared:screen, 1:character/a + screen:address:screen <- print screen:address:screen, 1:character/a ] screen-should-contain [ # 01234 @@ -25,9 +25,9 @@ scenario screen-in-scenario-unicode-color [ assume-screen 5/width, 3/height run [ 1:character <- copy 955/greek-small-lambda - screen:address:shared:screen <- print screen:address:shared:screen, 1:character/lambda, 1/red + screen:address:screen <- print screen:address:screen, 1:character/lambda, 1/red 2:character <- copy 97/a - screen:address:shared:screen <- print screen:address:shared:screen, 2:character/a + screen:address:screen <- print screen:address:screen, 2:character/a ] screen-should-contain [ # 01234 @@ -43,9 +43,9 @@ scenario screen-in-scenario-color [ assume-screen 5/width, 3/height run [ 1:character <- copy 955/greek-small-lambda - screen:address:shared:screen <- print screen:address:shared:screen, 1:character/lambda, 1/red + screen:address:screen <- print screen:address:screen, 1:character/lambda, 1/red 2:character <- copy 97/a - screen:address:shared:screen <- print screen:address:shared:screen, 2:character/a, 7/white + screen:address:screen <- print screen:address:screen, 2:character/a, 7/white ] # screen-should-contain shows everything screen-should-contain [ @@ -78,7 +78,7 @@ scenario screen-in-scenario-error [ assume-screen 5/width, 3/height run [ 1:character <- copy 97/a - screen:address:shared:screen <- print screen:address:shared:screen, 1:character/a + screen:address:screen <- print screen:address:screen, 1:character/a ] screen-should-contain [ # 01234 @@ -97,7 +97,7 @@ scenario screen-in-scenario-color [ assume-screen 5/width, 3/height run [ 1:character <- copy 97/a - screen:address:shared:screen <- print screen:address:shared:screen, 1:character/a, 1/red + screen:address:screen <- print screen:address:screen, 1:character/a, 1/red ] screen-should-contain-in-color 2/green, [ # 01234 @@ -145,11 +145,11 @@ Name[r]["screen"] = SCREEN; :(before "End Rewrite Instruction(curr, recipe result)") // rewrite `assume-screen width, height` to -// `screen:address:shared:screen <- new-fake-screen width, height` +// `screen:address:screen <- new-fake-screen width, height` if (curr.name == "assume-screen") { curr.name = "new-fake-screen"; assert(curr.products.empty()); - curr.products.push_back(reagent("screen:address:shared:screen")); + curr.products.push_back(reagent("screen:address:screen")); curr.products.at(0).set_value(SCREEN); } @@ -207,7 +207,7 @@ void check_screen(const string& expected_contents, const int color) { int screen_location = get_or_insert(Memory, SCREEN)+/*skip refcount*/1; int data_offset = find_element_name(get(Type_ordinal, "screen"), "data", ""); assert(data_offset >= 0); - int screen_data_location = screen_location+data_offset; // type: address:shared:array:character + int screen_data_location = screen_location+data_offset; // type: address:array:character int screen_data_start = get_or_insert(Memory, screen_data_location) + /*skip refcount*/1; // type: array:character int width_offset = find_element_name(get(Type_ordinal, "screen"), "num-columns", ""); int screen_width = get_or_insert(Memory, screen_location+width_offset); @@ -346,7 +346,7 @@ void dump_screen() { int screen_height = get_or_insert(Memory, screen_location+height_offset); int data_offset = find_element_name(get(Type_ordinal, "screen"), "data", ""); assert(data_offset >= 0); - int screen_data_location = screen_location+data_offset; // type: address:shared:array:character + int screen_data_location = screen_location+data_offset; // type: address:array:character int screen_data_start = get_or_insert(Memory, screen_data_location) + /*skip refcount*/1; // type: array:character assert(get_or_insert(Memory, screen_data_start) == screen_width*screen_height); int curr = screen_data_start+1; // skip length diff --git a/083scenario_screen_test.mu b/083scenario_screen_test.mu index a135984a..9679e9cf 100644 --- a/083scenario_screen_test.mu +++ b/083scenario_screen_test.mu @@ -4,7 +4,7 @@ scenario print-character-at-top-left-2 [ assume-screen 3/width, 2/height run [ 1:character <- copy 97/a - screen:address:shared:screen <- print screen:address:shared:screen, 1:character/a + screen:address:screen <- print screen:address:screen, 1:character/a ] screen-should-contain [ .a . @@ -17,11 +17,11 @@ scenario clear-line-erases-printed-characters-2 [ run [ # print a character 1:character <- copy 97/a - screen:address:shared:screen <- print screen:address:shared:screen, 1:character/a + screen:address:screen <- print screen:address:screen, 1:character/a # move cursor to start of line - screen:address:shared:screen <- move-cursor screen:address:shared:screen, 0/row, 0/column + screen:address:screen <- move-cursor screen:address:screen, 0/row, 0/column # clear line - screen:address:shared:screen <- clear-line screen:address:shared:screen + screen:address:screen <- clear-line screen:address:screen ] screen-should-contain [ . . diff --git a/084console.mu b/084console.mu index dab4be7d..d2259b65 100644 --- a/084console.mu +++ b/084console.mu @@ -22,28 +22,28 @@ container resize-event [ container console [ current-event-index:number - events:address:shared:array:event + events:address:array:event ] -def new-fake-console events:address:shared:array:event -> result:address:shared:console [ +def new-fake-console events:address:array:event -> result:address:console [ local-scope load-ingredients - result:address:shared:console <- new console:type + result:address:console <- new console:type *result <- put *result, events:offset, events ] -def read-event console:address:shared:console -> result:event, console:address:shared:console, found?:boolean, quit?:boolean [ +def read-event console:address:console -> result:event, console:address:console, found?:boolean, quit?:boolean [ local-scope load-ingredients { break-unless console current-event-index:number <- get *console, current-event-index:offset - buf:address:shared:array:event <- get *console, events:offset + buf:address:array:event <- get *console, events:offset { max:number <- length *buf done?:boolean <- greater-or-equal current-event-index, max break-unless done? - dummy:address:shared:event <- new event:type + dummy:address:event <- new event:type return *dummy, console/same-as-ingredient:0, 1/found, 1/quit } result <- index *buf, current-event-index @@ -59,7 +59,7 @@ def read-event console:address:shared:console -> result:event, console:address:s # variant of read-event for just keyboard events. Discards everything that # isn't unicode, so no arrow keys, page-up/page-down, etc. But you still get # newlines, tabs, ctrl-d.. -def read-key console:address:shared:console -> result:character, console:address:shared:console, found?:boolean, quit?:boolean [ +def read-key console:address:console -> result:character, console:address:console, found?:boolean, quit?:boolean [ local-scope load-ingredients x:event, console, found?:boolean, quit?:boolean <- read-event console @@ -70,7 +70,7 @@ def read-key console:address:shared:console -> result:character, console:address return c, console/same-as-ingredient:0, 1/found, 0/quit ] -def send-keys-to-channel console:address:shared:console, chan:address:shared:sink:character, screen:address:shared:screen -> console:address:shared:console, chan:address:shared:sink:character, screen:address:shared:screen [ +def send-keys-to-channel console:address:console, chan:address:sink:character, screen:address:screen -> console:address:console, chan:address:sink:character, screen:address:screen [ local-scope load-ingredients { @@ -84,7 +84,7 @@ def send-keys-to-channel console:address:shared:console, chan:address:shared:sin } ] -def wait-for-event console:address:shared:console -> console:address:shared:console [ +def wait-for-event console:address:console -> console:address:console [ local-scope load-ingredients { @@ -94,7 +94,7 @@ def wait-for-event console:address:shared:console -> console:address:shared:cons ] # use this helper to skip rendering if there's lots of other events queued up -def has-more-events? console:address:shared:console -> result:boolean [ +def has-more-events? console:address:console -> result:boolean [ local-scope load-ingredients { diff --git a/085scenario_console.cc b/085scenario_console.cc index d91d3ce4..e97f67f1 100644 --- a/085scenario_console.cc +++ b/085scenario_console.cc @@ -11,10 +11,10 @@ scenario keyboard-in-scenario [ type [abc] ] run [ - 1:character, console:address:shared:console, 2:boolean <- read-key console:address:shared:console - 3:character, console:address:shared:console, 4:boolean <- read-key console:address:shared:console - 5:character, console:address:shared:console, 6:boolean <- read-key console:address:shared:console - 7:character, console:address:shared:console, 8:boolean, 9:boolean <- read-key console:address:shared:console + 1:character, console:address:console, 2:boolean <- read-key console:address:console + 3:character, console:address:console, 4:boolean <- read-key console:address:console + 5:character, console:address:console, 6:boolean <- read-key console:address:console + 7:character, console:address:console, 8:boolean, 9:boolean <- read-key console:address:console ] memory-should-contain [ 1 <- 97 # 'a' @@ -194,15 +194,15 @@ scenario events-in-scenario [ ] run [ # 3 keyboard events; each event occupies 4 locations - 1:event <- read-event console:address:shared:console - 5:event <- read-event console:address:shared:console - 9:event <- read-event console:address:shared:console + 1:event <- read-event console:address:console + 5:event <- read-event console:address:console + 9:event <- read-event console:address:console # mouse click - 13:event <- read-event console:address:shared:console + 13:event <- read-event console:address:console # non-character keycode - 17:event <- read-event console:address:shared:console + 17:event <- read-event console:address:console # final keyboard event - 21:event <- read-event console:address:shared:console + 21:event <- read-event console:address:console ] memory-should-contain [ 1 <- 0 # 'text' diff --git a/086scenario_console_test.mu b/086scenario_console_test.mu index a11b0091..754f1166 100644 --- a/086scenario_console_test.mu +++ b/086scenario_console_test.mu @@ -7,10 +7,10 @@ scenario read-key-in-mu [ type [abc] ] run [ - 1:character, console:address:shared:console, 2:boolean <- read-key console:address:shared:console - 3:character, console:address:shared:console, 4:boolean <- read-key console:address:shared:console - 5:character, console:address:shared:console, 6:boolean <- read-key console:address:shared:console - 7:character, console:address:shared:console, 8:boolean <- read-key console:address:shared:console + 1:character, console:address:console, 2:boolean <- read-key console:address:console + 3:character, console:address:console, 4:boolean <- read-key console:address:console + 5:character, console:address:console, 6:boolean <- read-key console:address:console + 7:character, console:address:console, 8:boolean <- read-key console:address:console ] memory-should-contain [ 1 <- 97 # 'a' diff --git a/091run_interactive.cc b/091run_interactive.cc index 7f00acba..7ebc2e16 100644 --- a/091run_interactive.cc +++ b/091run_interactive.cc @@ -4,16 +4,16 @@ :(scenario run_interactive_code) def main [ 1:number/raw <- copy 0 - 2:address:shared:array:character <- new [1:number/raw <- copy 34] - run-interactive 2:address:shared:array:character + 2:address:array:character <- new [1:number/raw <- copy 34] + run-interactive 2:address:array:character 3:number/raw <- copy 1:number/raw ] +mem: storing 34 in location 3 :(scenario run_interactive_empty) def main [ - 1:address:shared:array:character <- copy 0/unsafe - 2:address:shared:array:character <- run-interactive 1:address:shared:array:character + 1:address:array:character <- copy 0/unsafe + 2:address:array:character <- run-interactive 1:address:array:character ] # result is null +mem: storing 0 in location 2 @@ -86,7 +86,7 @@ bool run_interactive(int address) { // call run(string) but without the scheduling load(string("recipe! interactive [\n") + "local-scope\n" + - "screen:address:shared:screen <- next-ingredient\n" + + "screen:address:screen <- next-ingredient\n" + "$start-tracking-products\n" + command + "\n" + "$stop-tracking-products\n" + @@ -168,15 +168,15 @@ load(string( "]\n" + "recipe sandbox [\n" + "local-scope\n" + - "screen:address:shared:screen <- new-fake-screen 30, 5\n" + + "screen:address:screen <- new-fake-screen 30, 5\n" + "r:number/routine_id <- start-running interactive, screen\n" + "limit-time r, 100000/instructions\n" + "wait-for-routine r\n" + "sandbox-state:number <- routine-state r/routine_id\n" + "completed?:boolean <- equal sandbox-state, 1/completed\n" + - "output:address:shared:array:character <- $most-recent-products\n" + - "errors:address:shared:array:character <- save-errors\n" + - "stashes:address:shared:array:character <- save-app-trace\n" + + "output:address:array:character <- $most-recent-products\n" + + "errors:address:array:character <- save-errors\n" + + "stashes:address:array:character <- save-app-trace\n" + "$cleanup-run-interactive\n" + "return output, errors, screen, stashes, completed?\n" + "]\n"); @@ -187,10 +187,10 @@ load(string( :(scenario run_interactive_comments) def main [ - 1:address:shared:array:character <- new [# ab + 1:address:array:character <- new [# ab add 2, 2] - 2:address:shared:array:character <- run-interactive 1:address:shared:array:character - 3:array:character <- copy *2:address:shared:array:character + 2:address:array:character <- run-interactive 1:address:array:character + 3:array:character <- copy *2:address:array:character ] +mem: storing 52 in location 4 @@ -284,9 +284,9 @@ case _CLEANUP_RUN_INTERACTIVE: { :(scenario "run_interactive_converts_result_to_text") def main [ # try to interactively add 2 and 2 - 1:address:shared:array:character <- new [add 2, 2] - 2:address:shared:array:character <- run-interactive 1:address:shared:array:character - 10:array:character <- copy 2:address:shared:array:character/lookup + 1:address:array:character <- new [add 2, 2] + 2:address:array:character <- run-interactive 1:address:array:character + 10:array:character <- copy 2:address:array:character/lookup ] # first letter in the output should be '4' in unicode +mem: storing 52 in location 11 @@ -294,13 +294,13 @@ def main [ :(scenario "run_interactive_returns_text") def main [ # try to interactively add 2 and 2 - 1:address:shared:array:character <- new [ - x:address:shared:array:character <- new [a] - y:address:shared:array:character <- new [b] - z:address:shared:array:character <- append x:address:shared:array:character, y:address:shared:array:character + 1:address:array:character <- new [ + x:address:array:character <- new [a] + y:address:array:character <- new [b] + z:address:array:character <- append x:address:array:character, y:address:array:character ] - 2:address:shared:array:character <- run-interactive 1:address:shared:array:character - 10:array:character <- copy 2:address:shared:array:character/lookup + 2:address:array:character <- run-interactive 1:address:array:character + 10:array:character <- copy 2:address:array:character/lookup ] # output contains "ab" +mem: storing 97 in location 11 @@ -309,10 +309,10 @@ def main [ :(scenario "run_interactive_returns_errors") def main [ # run a command that generates an error - 1:address:shared:array:character <- new [x:number <- copy 34 + 1:address:array:character <- new [x:number <- copy 34 get x:number, foo:offset] - 2:address:shared:array:character, 3:address:shared:array:character <- run-interactive 1:address:shared:array:character - 10:array:character <- copy 3:address:shared:array:character/lookup + 2:address:array:character, 3:address:array:character <- run-interactive 1:address:array:character + 10:array:character <- copy 3:address:array:character/lookup ] # error should be "unknown element foo in container number" +mem: storing 117 in location 11 @@ -324,10 +324,10 @@ get x:number, foo:offset] :(scenario run_interactive_with_comment) def main [ # 2 instructions, with a comment after the first - 1:address:shared:array:number <- new [a:number <- copy 0 # abc + 1:address:array:number <- new [a:number <- copy 0 # abc b:number <- copy 0 ] - 2:address:shared:array:character, 3:address:shared:array:character <- run-interactive 1:address:shared:array:character + 2:address:array:character, 3:address:array:character <- run-interactive 1:address:array:character ] # no errors +mem: storing 0 in location 3 @@ -476,7 +476,7 @@ case RELOAD: { :(scenario reload_continues_past_error) def main [ local-scope - x:address:shared:array:character <- new [recipe foo [ + x:address:array:character <- new [recipe foo [ get 1234:number, foo:offset ]] reload x @@ -488,7 +488,7 @@ def main [ # define a container and try to create it (merge requires knowing container size) def main [ local-scope - x:address:shared:array:character <- new [ + x:address:array:character <- new [ container foo [ x:number y:number diff --git a/channel.mu b/channel.mu index 1dbae8e0..d74cbcad 100644 --- a/channel.mu +++ b/channel.mu @@ -1,6 +1,6 @@ # example program: communicating between routines using channels -def producer chan:address:shared:channel:character -> chan:address:shared:channel:character [ +def producer sink:address:sink:character -> sink:address:sink:character [ # produce characters 1 to 5 on a channel local-scope load-ingredients @@ -12,19 +12,19 @@ def producer chan:address:shared:channel:character -> chan:address:shared:channe # other threads might get between these prints $print [produce: ], n, [ ] - chan <- write chan, n + sink <- write sink, n n <- add n, 1 loop } ] -def consumer chan:address:shared:channel:character -> chan:address:shared:channel:character [ +def consumer source:address:source:character -> source:address:source:character [ # consume and print integers from a channel local-scope load-ingredients { # read an integer from the channel - n:character, chan <- read chan + n:character, source <- read source # other threads might get between these prints $print [consume: ], n:character, [ ] @@ -34,10 +34,10 @@ def consumer chan:address:shared:channel:character -> chan:address:shared:channe def main [ local-scope - chan:address:shared:channel:character <- new-channel 3 + source:address:source:character, sink:address:sink:character <- new-channel 3/capacity # create two background 'routines' that communicate by a channel - routine1:number <- start-running producer, chan - routine2:number <- start-running consumer, chan + routine1:number <- start-running producer, sink + routine2:number <- start-running consumer, source wait-for-routine routine1 wait-for-routine routine2 ] diff --git a/chessboard.mu b/chessboard.mu index 91e2e3fd..0e13afce 100644 --- a/chessboard.mu +++ b/chessboard.mu @@ -33,7 +33,7 @@ scenario print-board-and-read-move [ ] ] run [ - screen:address:shared:screen, console:address:shared:console <- chessboard screen:address:shared:screen, console:address:shared:console + screen:address:screen, console:address:console <- chessboard screen:address:screen, console:address:console # icon for the cursor screen <- print screen, 9251/␣ ] @@ -65,15 +65,15 @@ scenario print-board-and-read-move [ ## Here's how 'chessboard' is implemented. -def chessboard screen:address:shared:screen, console:address:shared:console -> screen:address:shared:screen, console:address:shared:console [ +def chessboard screen:address:screen, console:address:console -> screen:address:screen, console:address:console [ local-scope load-ingredients - board:address:shared:array:address:shared:array:character <- initial-position + board:address:array:address:array:character <- initial-position # hook up stdin - stdin-in:address:shared:source:character, stdin-out:address:shared:sink:character <- new-channel 10/capacity + stdin-in:address:source:character, stdin-out:address:sink:character <- new-channel 10/capacity start-running send-keys-to-channel, console, stdin-out, screen # buffer lines in stdin - buffered-stdin-in:address:shared:source:character, buffered-stdin-out:address:shared:sink:character <- new-channel 10/capacity + buffered-stdin-in:address:source:character, buffered-stdin-out:address:sink:character <- new-channel 10/capacity start-running buffer-lines, stdin-in, buffered-stdin-out { print screen, [Stupid text-mode chessboard. White pieces in uppercase; black pieces in lowercase. No checking for legal moves. @@ -89,7 +89,7 @@ def chessboard screen:address:shared:screen, console:address:shared:console -> s { cursor-to-next-line screen screen <- print screen, [move: ] - m:address:shared:move, quit:boolean, error:boolean <- read-move buffered-stdin-in, screen + m:address:move, quit:boolean, error:boolean <- read-move buffered-stdin-in, screen break-if quit, +quit:label buffered-stdin-in <- clear buffered-stdin-in # cleanup after error. todo: test this? loop-if error @@ -103,7 +103,7 @@ def chessboard screen:address:shared:screen, console:address:shared:console -> s ## a board is an array of files, a file is an array of characters (squares) -def new-board initial-position:address:shared:array:character -> board:address:shared:array:address:shared:array:character [ +def new-board initial-position:address:array:character -> board:address:array:address:array:character [ local-scope load-ingredients # assert(length(initial-position) == 64) @@ -111,19 +111,19 @@ def new-board initial-position:address:shared:array:character -> board:address:s correct-length?:boolean <- equal len, 64 assert correct-length?, [chessboard had incorrect size] # board is an array of pointers to files; file is an array of characters - board <- new {(address shared array character): type}, 8 + board <- new {(address array character): type}, 8 col:number <- copy 0 { done?:boolean <- equal col, 8 break-if done? - file:address:shared:array:character <- new-file initial-position, col + file:address:array:character <- new-file initial-position, col *board <- put-index *board, col, file col <- add col, 1 loop } ] -def new-file position:address:shared:array:character, index:number -> result:address:shared:array:character [ +def new-file position:address:array:character, index:number -> result:address:array:character [ local-scope load-ingredients index <- multiply index, 8 @@ -140,7 +140,7 @@ def new-file position:address:shared:array:character, index:number -> result:add } ] -def print-board screen:address:shared:screen, board:address:shared:array:address:shared:array:character -> screen:address:shared:screen [ +def print-board screen:address:screen, board:address:array:address:array:character -> screen:address:screen [ local-scope load-ingredients row:number <- copy 7 # start printing from the top of the board @@ -158,7 +158,7 @@ def print-board screen:address:shared:screen, board:address:shared:array:address { done?:boolean <- equal col:number, 8 break-if done?:boolean - f:address:shared:array:character <- index *board, col + f:address:array:character <- index *board, col c:character <- index *f, row print screen, c print screen, space @@ -176,7 +176,7 @@ def print-board screen:address:shared:screen, board:address:shared:array:address cursor-to-next-line screen ] -def initial-position -> board:address:shared:array:address:shared:array:character [ +def initial-position -> board:address:array:address:array:character [ local-scope # layout in memory (in raster order): # R P _ _ _ _ p r @@ -187,7 +187,7 @@ def initial-position -> board:address:shared:array:address:shared:array:characte # B P _ _ _ _ p B # N P _ _ _ _ p n # R P _ _ _ _ p r - initial-position:address:shared:array:character <- new-array 82/R, 80/P, 32/blank, 32/blank, 32/blank, 32/blank, 112/p, 114/r, 78/N, 80/P, 32/blank, 32/blank, 32/blank, 32/blank, 112/p, 110/n, 66/B, 80/P, 32/blank, 32/blank, 32/blank, 32/blank, 112/p, 98/b, 81/Q, 80/P, 32/blank, 32/blank, 32/blank, 32/blank, 112/p, 113/q, 75/K, 80/P, 32/blank, 32/blank, 32/blank, 32/blank, 112/p, 107/k, 66/B, 80/P, 32/blank, 32/blank, 32/blank, 32/blank, 112/p, 98/b, 78/N, 80/P, 32/blank, 32/blank, 32/blank, 32/blank, 112/p, 110/n, 82/R, 80/P, 32/blank, 32/blank, 32/blank, 32/blank, 112/p, 114/r + initial-position:address:array:character <- new-array 82/R, 80/P, 32/blank, 32/blank, 32/blank, 32/blank, 112/p, 114/r, 78/N, 80/P, 32/blank, 32/blank, 32/blank, 32/blank, 112/p, 110/n, 66/B, 80/P, 32/blank, 32/blank, 32/blank, 32/blank, 112/p, 98/b, 81/Q, 80/P, 32/blank, 32/blank, 32/blank, 32/blank, 112/p, 113/q, 75/K, 80/P, 32/blank, 32/blank, 32/blank, 32/blank, 112/p, 107/k, 66/B, 80/P, 32/blank, 32/blank, 32/blank, 32/blank, 112/p, 98/b, 78/N, 80/P, 32/blank, 32/blank, 32/blank, 32/blank, 112/p, 110/n, 82/R, 80/P, 32/blank, 32/blank, 32/blank, 32/blank, 112/p, 114/r #? 82/R, 80/P, 32/blank, 32/blank, 32/blank, 32/blank, 112/p, 114/r, #? 78/N, 80/P, 32/blank, 32/blank, 32/blank, 32/blank, 112/p, 110/n, #? 66/B, 80/P, 32/blank, 32/blank, 32/blank, 32/blank, 112/p, 98/b, @@ -202,8 +202,8 @@ def initial-position -> board:address:shared:array:address:shared:array:characte scenario printing-the-board [ assume-screen 30/width, 12/height run [ - 1:address:shared:array:address:shared:array:character/board <- initial-position - screen:address:shared:screen <- print-board screen:address:shared:screen, 1:address:shared:array:address:shared:array:character/board + 1:address:array:address:array:character/board <- initial-position + screen:address:screen <- print-board screen:address:screen, 1:address:array:address:array:character/board ] screen-should-contain [ # 012345678901234567890123456789 @@ -233,14 +233,14 @@ container move [ ] # prints only error messages to screen -def read-move stdin:address:shared:source:character, screen:address:shared:screen -> result:address:shared:move, quit?:boolean, error?:boolean, stdin:address:shared:source:character, screen:address:shared:screen [ +def read-move stdin:address:source:character, screen:address:screen -> result:address:move, quit?:boolean, error?:boolean, stdin:address:source:character, screen:address:screen [ local-scope load-ingredients from-file:number, quit?:boolean, error?:boolean <- read-file stdin, screen return-if quit?, 0/dummy return-if error?, 0/dummy # construct the move object - result:address:shared:move <- new move:type + result:address:move <- new move:type *result <- put *result, from-file:offset, from-file from-rank:number, quit?, error? <- read-rank stdin, screen return-if quit?, 0/dummy @@ -261,7 +261,7 @@ def read-move stdin:address:shared:source:character, screen:address:shared:scree ] # valid values for file: 0-7 -def read-file stdin:address:shared:source:character, screen:address:shared:screen -> file:number, quit:boolean, error:boolean, stdin:address:shared:source:character, screen:address:shared:screen [ +def read-file stdin:address:source:character, screen:address:screen -> file:number, quit:boolean, error:boolean, stdin:address:source:character, screen:address:screen [ local-scope load-ingredients c:character, stdin <- read stdin @@ -307,7 +307,7 @@ def read-file stdin:address:shared:source:character, screen:address:shared:scree ] # valid values: 0-7, -1 (quit), -2 (error) -def read-rank stdin:address:shared:source:character, screen:address:shared:screen -> rank:number, quit?:boolean, error?:boolean, stdin:address:shared:source:character, screen:address:shared:screen [ +def read-rank stdin:address:source:character, screen:address:screen -> rank:number, quit?:boolean, error?:boolean, stdin:address:source:character, screen:address:screen [ local-scope load-ingredients c:character, stdin <- read stdin @@ -348,7 +348,7 @@ def read-rank stdin:address:shared:source:character, screen:address:shared:scree # read a character from the given channel and check that it's what we expect # return true on error -def expect-from-channel stdin:address:shared:source:character, expected:character, screen:address:shared:screen -> result:boolean, stdin:address:shared:source:character, screen:address:shared:screen [ +def expect-from-channel stdin:address:source:character, expected:character, screen:address:screen -> result:boolean, stdin:address:source:character, screen:address:screen [ local-scope load-ingredients c:character, stdin <- read stdin @@ -363,8 +363,8 @@ def expect-from-channel stdin:address:shared:source:character, expected:characte scenario read-move-blocking [ assume-screen 20/width, 2/height run [ - 1:address:shared:source:character, 2:address:shared:sink:character <- new-channel 2/capacity - 3:number/routine <- start-running read-move, 1:address:shared:source:character, screen:address:shared:screen + 1:address:source:character, 2:address:sink:character <- new-channel 2/capacity + 3:number/routine <- start-running read-move, 1:address:source:character, screen:address:screen # 'read-move' is waiting for input wait-for-routine 3:number 4:number <- routine-state 3:number/id @@ -372,7 +372,7 @@ scenario read-move-blocking [ assert 5:boolean/waiting?, [ F read-move-blocking: routine failed to pause after coming up (before any keys were pressed)] # press 'a' - 2:address:shared:sink:character <- write 2:address:shared:sink:character, 97/a + 2:address:sink:character <- write 2:address:sink:character, 97/a restart 3:number/routine # 'read-move' still waiting for input wait-for-routine 3:number @@ -381,7 +381,7 @@ F read-move-blocking: routine failed to pause after coming up (before any keys w assert 5:boolean/waiting?, [ F read-move-blocking: routine failed to pause after rank 'a'] # press '2' - 2:address:shared:sink:character <- write 2:address:shared:sink:character, 50/'2' + 2:address:sink:character <- write 2:address:sink:character, 50/'2' restart 3:number/routine # 'read-move' still waiting for input wait-for-routine 3:number @@ -390,7 +390,7 @@ F read-move-blocking: routine failed to pause after rank 'a'] assert 5:boolean/waiting?, [ F read-move-blocking: routine failed to pause after file 'a2'] # press '-' - 2:address:shared:sink:character <- write 2:address:shared:sink:character, 45/'-' + 2:address:sink:character <- write 2:address:sink:character, 45/'-' restart 3:number/routine # 'read-move' still waiting for input wait-for-routine 3:number @@ -399,7 +399,7 @@ F read-move-blocking: routine failed to pause after file 'a2'] assert 5:boolean/waiting?/routine-state, [ F read-move-blocking: routine failed to pause after hyphen 'a2-'] # press 'a' - 2:address:shared:sink:character <- write 2:address:shared:sink:character, 97/a + 2:address:sink:character <- write 2:address:sink:character, 97/a restart 3:number/routine # 'read-move' still waiting for input wait-for-routine 3:number @@ -408,7 +408,7 @@ F read-move-blocking: routine failed to pause after hyphen 'a2-'] assert 5:boolean/waiting?/routine-state, [ F read-move-blocking: routine failed to pause after rank 'a2-a'] # press '4' - 2:address:shared:sink:character <- write 2:address:shared:sink:character, 52/'4' + 2:address:sink:character <- write 2:address:sink:character, 52/'4' restart 3:number/routine # 'read-move' still waiting for input wait-for-routine 3:number @@ -417,7 +417,7 @@ F read-move-blocking: routine failed to pause after rank 'a2-a'] assert 5:boolean/waiting?, [ F read-move-blocking: routine failed to pause after file 'a2-a4'] # press 'newline' - 2:address:shared:sink:character <- write 2:address:shared:sink:character, 10 # newline + 2:address:sink:character <- write 2:address:sink:character, 10 # newline restart 3:number/routine # 'read-move' now completes wait-for-routine 3:number @@ -435,8 +435,8 @@ F read-move-blocking: routine failed to terminate on newline] scenario read-move-quit [ assume-screen 20/width, 2/height run [ - 1:address:shared:source:character, 2:address:shared:sink:character <- new-channel 2/capacity - 3:number/routine <- start-running read-move, 1:address:shared:channel:character, screen:address:shared:screen + 1:address:source:character, 2:address:sink:character <- new-channel 2/capacity + 3:number/routine <- start-running read-move, 1:address:channel:character, screen:address:screen # 'read-move' is waiting for input wait-for-routine 3:number 4:number <- routine-state 3:number/id @@ -444,7 +444,7 @@ scenario read-move-quit [ assert 5:boolean/waiting?, [ F read-move-quit: routine failed to pause after coming up (before any keys were pressed)] # press 'q' - 2:address:shared:sink:character <- write 2:address:shared:sink:character, 113/q + 2:address:sink:character <- write 2:address:sink:character, 113/q restart 3:number/routine # 'read-move' completes wait-for-routine 3:number @@ -462,15 +462,15 @@ F read-move-quit: routine failed to terminate on 'q'] scenario read-move-illegal-file [ assume-screen 20/width, 2/height run [ - 1:address:shared:source:character, 2:address:shared:sink:character <- new-channel 2/capacity - 3:number/routine <- start-running read-move, 1:address:shared:source:character, screen:address:shared:screen + 1:address:source:character, 2:address:sink:character <- new-channel 2/capacity + 3:number/routine <- start-running read-move, 1:address:source:character, screen:address:screen # 'read-move' is waiting for input wait-for-routine 3:number 4:number <- routine-state 3:number/id 5:boolean/waiting? <- equal 4:number/routine-state, 3/waiting assert 5:boolean/waiting?, [ F read-move-file: routine failed to pause after coming up (before any keys were pressed)] - 1:address:shared:sink:character <- write 1:address:shared:sink:character, 50/'2' + 1:address:sink:character <- write 1:address:sink:character, 50/'2' restart 3:number/routine wait-for-routine 3:number ] @@ -483,16 +483,16 @@ F read-move-file: routine failed to pause after coming up (before any keys were scenario read-move-illegal-rank [ assume-screen 20/width, 2/height run [ - 1:address:shared:source:character, 2:address:shared:sink:character <- new-channel 2/capacity - 3:number/routine <- start-running read-move, 1:address:shared:source:character, screen:address:shared:screen + 1:address:source:character, 2:address:sink:character <- new-channel 2/capacity + 3:number/routine <- start-running read-move, 1:address:source:character, screen:address:screen # 'read-move' is waiting for input wait-for-routine 3:number 4:number <- routine-state 3:number/id 5:boolean/waiting? <- equal 4:number/routine-state, 3/waiting assert 5:boolean/waiting?, [ F read-move-file: routine failed to pause after coming up (before any keys were pressed)] - 1:address:shared:sink:character <- write 1:address:shared:sink:character, 97/a - 1:address:shared:sink:character <- write 1:address:shared:sink:character, 97/a + 1:address:sink:character <- write 1:address:sink:character, 97/a + 1:address:sink:character <- write 1:address:sink:character, 97/a restart 3:number/routine wait-for-routine 3:number ] @@ -505,16 +505,16 @@ F read-move-file: routine failed to pause after coming up (before any keys were scenario read-move-empty [ assume-screen 20/width, 2/height run [ - 1:address:shared:source:character, 2:address:shared:sink:character <- new-channel 2/capacity - 3:number/routine <- start-running read-move, 1:address:shared:source:character, screen:address:shared:screen + 1:address:source:character, 2:address:sink:character <- new-channel 2/capacity + 3:number/routine <- start-running read-move, 1:address:source:character, screen:address:screen # 'read-move' is waiting for input wait-for-routine 3:number 4:number <- routine-state 3:number/id 5:boolean/waiting? <- equal 4:number/routine-state, 3/waiting assert 5:boolean/waiting?, [ F read-move-file: routine failed to pause after coming up (before any keys were pressed)] - 1:address:shared:sink:character <- write 1:address:shared:sink:character, 10/newline - 1:address:shared:sink:character <- write 1:address:shared:sink:character, 97/a + 1:address:sink:character <- write 1:address:sink:character, 10/newline + 1:address:sink:character <- write 1:address:sink:character, 97/a restart 3:number/routine wait-for-routine 3:number ] @@ -524,15 +524,15 @@ F read-move-file: routine failed to pause after coming up (before any keys were ] ] -def make-move board:address:shared:array:address:shared:array:character, m:address:shared:move -> board:address:shared:array:address:shared:array:character [ +def make-move board:address:array:address:array:character, m:address:move -> board:address:array:address:array:character [ local-scope load-ingredients from-file:number <- get *m, from-file:offset from-rank:number <- get *m, from-rank:offset to-file:number <- get *m, to-file:offset to-rank:number <- get *m, to-rank:offset - from-f:address:shared:array:character <- index *board, from-file - to-f:address:shared:array:character <- index *board, to-file + from-f:address:array:character <- index *board, from-file + to-f:address:array:character <- index *board, to-file src:character/square <- index *from-f, from-rank *to-f <- put-index *to-f, to-rank, src *from-f <- put-index *from-f, from-rank, 32/space @@ -541,11 +541,11 @@ def make-move board:address:shared:array:address:shared:array:character, m:addre scenario making-a-move [ assume-screen 30/width, 12/height run [ - 2:address:shared:array:address:shared:array:character/board <- initial-position - 3:address:shared:move <- new move:type - *3:address:shared:move <- merge 6/g, 1/'2', 6/g, 3/'4' - 2:address:shared:array:address:shared:array:character/board <- make-move 2:address:shared:array:address:shared:array:character/board, 3:address:shared:move - screen:address:shared:screen <- print-board screen:address:shared:screen, 2:address:shared:array:address:shared:array:character/board + 2:address:array:address:array:character/board <- initial-position + 3:address:move <- new move:type + *3:address:move <- merge 6/g, 1/'2', 6/g, 3/'4' + 2:address:array:address:array:character/board <- make-move 2:address:array:address:array:character/board, 3:address:move + screen:address:screen <- print-board screen:address:screen, 2:address:array:address:array:character/board ] screen-should-contain [ # 012345678901234567890123456789 diff --git a/counters.mu b/counters.mu index d3566ce0..fa2b998e 100644 --- a/counters.mu +++ b/counters.mu @@ -1,24 +1,24 @@ # example program: maintain multiple counters with isolated lexical scopes # (spaces) -def new-counter n:number -> default-space:address:shared:array:location [ +def new-counter n:number -> default-space:address:array:location [ default-space <- new location:type, 30 load-ingredients ] -def increment-counter outer:address:shared:array:location/names:new-counter, x:number -> n:number/space:1 [ +def increment-counter outer:address:array:location/names:new-counter, x:number -> n:number/space:1 [ local-scope load-ingredients - 0:address:shared:array:location/names:new-counter <- copy outer # setup outer space; it *must* come from 'new-counter' + 0:address:array:location/names:new-counter <- copy outer # setup outer space; it *must* come from 'new-counter' n/space:1 <- add n/space:1, x ] def main [ local-scope # counter A - a:address:shared:array:location <- new-counter 34 + a:address:array:location <- new-counter 34 # counter B - b:address:shared:array:location <- new-counter 23 + b:address:array:location <- new-counter 23 # increment both by 2 but in different ways increment-counter a, 1 b-value:number <- increment-counter b, 2 diff --git a/edit/001-editor.mu b/edit/001-editor.mu index 614608c2..06c5a8dc 100644 --- a/edit/001-editor.mu +++ b/edit/001-editor.mu @@ -2,7 +2,7 @@ # temporary main for this layer: just render the given text at the given # screen dimensions, then stop -def! main text:address:shared:array:character [ +def! main text:address:array:character [ local-scope load-ingredients open-console @@ -16,8 +16,8 @@ def! main text:address:shared:array:character [ scenario editor-initially-prints-text-to-screen [ assume-screen 10/width, 5/height run [ - 1:address:shared:array:character <- new [abc] - new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 1:address:array:character <- new [abc] + new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right ] screen-should-contain [ # top line of screen reserved for menu @@ -29,11 +29,11 @@ scenario editor-initially-prints-text-to-screen [ container editor-data [ # editable text: doubly linked list of characters (head contains a special sentinel) - data:address:shared:duplex-list:character - top-of-screen:address:shared:duplex-list:character - bottom-of-screen:address:shared:duplex-list:character + data:address:duplex-list:character + top-of-screen:address:duplex-list:character + bottom-of-screen:address:duplex-list:character # location before cursor inside data - before-cursor:address:shared:duplex-list:character + before-cursor:address:duplex-list:character # raw bounds of display area on screen # always displays from row 1 (leaving row 0 for a menu) and at most until bottom of screen @@ -48,7 +48,7 @@ container editor-data [ # creates a new editor widget and renders its initial appearance to screen # top/left/right constrain the screen area available to the new editor # right is exclusive -def new-editor s:address:shared:array:character, screen:address:shared:screen, left:number, right:number -> result:address:shared:editor-data, screen:address:shared:screen [ +def new-editor s:address:array:character, screen:address:screen, left:number, right:number -> result:address:editor-data, screen:address:screen [ local-scope load-ingredients # no clipping of bounds @@ -61,7 +61,7 @@ def new-editor s:address:shared:array:character, screen:address:shared:screen, l *result <- put *result, cursor-row:offset, 1/top *result <- put *result, cursor-column:offset, left # initialize empty contents - init:address:shared:duplex-list:character <- push 167/§, 0/tail + init:address:duplex-list:character <- push 167/§, 0/tail *result <- put *result, data:offset, init *result <- put *result, top-of-screen:offset, init *result <- put *result, before-cursor:offset, init @@ -71,7 +71,7 @@ def new-editor s:address:shared:array:character, screen:address:shared:screen, l <editor-initialization> ] -def insert-text editor:address:shared:editor-data, text:address:shared:array:character -> editor:address:shared:editor-data [ +def insert-text editor:address:editor-data, text:address:array:character -> editor:address:editor-data [ local-scope load-ingredients # early exit if text is empty @@ -80,7 +80,7 @@ def insert-text editor:address:shared:editor-data, text:address:shared:array:cha return-unless len, editor/same-as-ingredient:0 idx:number <- copy 0 # now we can start appending the rest, character by character - curr:address:shared:duplex-list:character <- get *editor, data:offset + curr:address:duplex-list:character <- get *editor, data:offset { done?:boolean <- greater-or-equal idx, len break-if done? @@ -97,8 +97,8 @@ def insert-text editor:address:shared:editor-data, text:address:shared:array:cha scenario editor-initializes-without-data [ assume-screen 5/width, 3/height run [ - 1:address:shared:editor-data <- new-editor 0/data, screen:address:shared:screen, 2/left, 5/right - 2:editor-data <- copy *1:address:shared:editor-data + 1:address:editor-data <- new-editor 0/data, screen:address:screen, 2/left, 5/right + 2:editor-data <- copy *1:address:editor-data ] memory-should-contain [ # 2 (data) <- just the § sentinel @@ -121,7 +121,7 @@ scenario editor-initializes-without-data [ # Assumes cursor should be at coordinates (cursor-row, cursor-column) and # updates before-cursor to match. Might also move coordinates if they're # outside text. -def render screen:address:shared:screen, editor:address:shared:editor-data -> last-row:number, last-column:number, screen:address:shared:screen, editor:address:shared:editor-data [ +def render screen:address:screen, editor:address:editor-data -> last-row:number, last-column:number, screen:address:screen, editor:address:editor-data [ local-scope load-ingredients return-unless editor, 1/top, 0/left, screen/same-as-ingredient:0, editor/same-as-ingredient:1 @@ -129,8 +129,8 @@ def render screen:address:shared:screen, editor:address:shared:editor-data -> la screen-height:number <- screen-height screen right:number <- get *editor, right:offset # traversing editor - curr:address:shared:duplex-list:character <- get *editor, top-of-screen:offset - prev:address:shared:duplex-list:character <- copy curr # just in case curr becomes null and we can't compute prev + curr:address:duplex-list:character <- get *editor, top-of-screen:offset + prev:address:duplex-list:character <- copy curr # just in case curr becomes null and we can't compute prev curr <- next curr # traversing screen +render-loop-initialization @@ -139,7 +139,7 @@ def render screen:address:shared:screen, editor:address:shared:editor-data -> la column:number <- copy left cursor-row:number <- get *editor, cursor-row:offset cursor-column:number <- get *editor, cursor-column:offset - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset screen <- move-cursor screen, row, column { +next-character @@ -222,7 +222,7 @@ def render screen:address:shared:screen, editor:address:shared:editor-data -> la return row, column, screen/same-as-ingredient:0, editor/same-as-ingredient:1 ] -def clear-line-delimited screen:address:shared:screen, column:number, right:number -> screen:address:shared:screen [ +def clear-line-delimited screen:address:screen, column:number, right:number -> screen:address:screen [ local-scope load-ingredients space:character <- copy 32/space @@ -241,7 +241,7 @@ def clear-line-delimited screen:address:shared:screen, column:number, right:numb } ] -def clear-screen-from screen:address:shared:screen, row:number, column:number, left:number, right:number -> screen:address:shared:screen [ +def clear-screen-from screen:address:screen, row:number, column:number, left:number, right:number -> screen:address:screen [ local-scope load-ingredients # if it's the real screen, use the optimized primitive @@ -257,7 +257,7 @@ def clear-screen-from screen:address:shared:screen, row:number, column:number, l return screen/same-as-ingredient:0 ] -def clear-rest-of-screen screen:address:shared:screen, row:number, left:number, right:number -> screen:address:shared:screen [ +def clear-rest-of-screen screen:address:screen, row:number, left:number, right:number -> screen:address:screen [ local-scope load-ingredients row <- add row, 1 @@ -276,9 +276,9 @@ def clear-rest-of-screen screen:address:shared:screen, row:number, left:number, scenario editor-initially-prints-multiple-lines [ assume-screen 5/width, 5/height run [ - s:address:shared:array:character <- new [abc + s:address:array:character <- new [abc def] - new-editor s:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + new-editor s:address:array:character, screen:address:screen, 0/left, 5/right ] screen-should-contain [ . . @@ -291,8 +291,8 @@ def] scenario editor-initially-handles-offsets [ assume-screen 5/width, 5/height run [ - s:address:shared:array:character <- new [abc] - new-editor s:address:shared:array:character, screen:address:shared:screen, 1/left, 5/right + s:address:array:character <- new [abc] + new-editor s:address:array:character, screen:address:screen, 1/left, 5/right ] screen-should-contain [ . . @@ -304,9 +304,9 @@ scenario editor-initially-handles-offsets [ scenario editor-initially-prints-multiple-lines-at-offset [ assume-screen 5/width, 5/height run [ - s:address:shared:array:character <- new [abc + s:address:array:character <- new [abc def] - new-editor s:address:shared:array:character, screen:address:shared:screen, 1/left, 5/right + new-editor s:address:array:character, screen:address:screen, 1/left, 5/right ] screen-should-contain [ . . @@ -319,8 +319,8 @@ def] scenario editor-initially-wraps-long-lines [ assume-screen 5/width, 5/height run [ - s:address:shared:array:character <- new [abc def] - new-editor s:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + s:address:array:character <- new [abc def] + new-editor s:address:array:character, screen:address:screen, 0/left, 5/right ] screen-should-contain [ . . @@ -339,8 +339,8 @@ scenario editor-initially-wraps-long-lines [ scenario editor-initially-wraps-barely-long-lines [ assume-screen 5/width, 5/height run [ - s:address:shared:array:character <- new [abcde] - new-editor s:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + s:address:array:character <- new [abcde] + new-editor s:address:array:character, screen:address:screen, 0/left, 5/right ] # still wrap, even though the line would fit. We need room to click on the # end of the line @@ -361,10 +361,10 @@ scenario editor-initially-wraps-barely-long-lines [ scenario editor-initializes-empty-text [ assume-screen 5/width, 5/height run [ - 1:address:shared:array:character <- new [] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 1:address:array:character <- new [] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] screen-should-contain [ . . @@ -382,10 +382,10 @@ scenario editor-initializes-empty-text [ scenario render-colors-comments [ assume-screen 5/width, 5/height run [ - s:address:shared:array:character <- new [abc + s:address:array:character <- new [abc # de f] - new-editor s:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + new-editor s:address:array:character, screen:address:screen, 0/left, 5/right ] screen-should-contain [ . . @@ -463,10 +463,10 @@ def get-color color:number, c:character -> color:number [ scenario render-colors-assignment [ assume-screen 8/width, 5/height run [ - s:address:shared:array:character <- new [abc + s:address:array:character <- new [abc d <- e f] - new-editor s:address:shared:array:character, screen:address:shared:screen, 0/left, 8/right + new-editor s:address:array:character, screen:address:screen, 0/left, 8/right ] screen-should-contain [ . . diff --git a/edit/002-typing.mu b/edit/002-typing.mu index d7624ccf..88079641 100644 --- a/edit/002-typing.mu +++ b/edit/002-typing.mu @@ -2,16 +2,16 @@ # temporary main: interactive editor # hit ctrl-c to exit -def! main text:address:shared:array:character [ +def! main text:address:array:character [ local-scope load-ingredients open-console - editor:address:shared:editor-data <- new-editor text, 0/screen, 5/left, 45/right + editor:address:editor-data <- new-editor text, 0/screen, 5/left, 45/right editor-event-loop 0/screen, 0/console, editor close-console ] -def editor-event-loop screen:address:shared:screen, console:address:shared:console, editor:address:shared:editor-data -> screen:address:shared:screen, console:address:shared:console, editor:address:shared:editor-data [ +def editor-event-loop screen:address:screen, console:address:console, editor:address:editor-data -> screen:address:screen, console:address:console, editor:address:editor-data [ local-scope load-ingredients { @@ -20,7 +20,7 @@ def editor-event-loop screen:address:shared:screen, console:address:shared:conso cursor-row:number <- get *editor, cursor-row:offset cursor-column:number <- get *editor, cursor-column:offset screen <- move-cursor screen, cursor-row, cursor-column - e:event, console:address:shared:console, found?:boolean, quit?:boolean <- read-event console + e:event, console:address:console, found?:boolean, quit?:boolean <- read-event console loop-unless found? break-if quit? # only in tests trace 10, [app], [next-event] @@ -45,7 +45,7 @@ def editor-event-loop screen:address:shared:screen, console:address:shared:conso ] # process click, return if it was on current editor -def move-cursor-in-editor screen:address:shared:screen, editor:address:shared:editor-data, t:touch-event -> in-focus?:boolean, editor:address:shared:editor-data [ +def move-cursor-in-editor screen:address:screen, editor:address:editor-data, t:touch-event -> in-focus?:boolean, editor:address:editor-data [ local-scope load-ingredients return-unless editor, 0/false @@ -70,7 +70,7 @@ def move-cursor-in-editor screen:address:shared:screen, editor:address:shared:ed # Variant of 'render' that only moves the cursor (coordinates and # before-cursor). If it's past the end of a line, it 'slides' it left. If it's # past the last line it positions at end of last line. -def snap-cursor screen:address:shared:screen, editor:address:shared:editor-data, target-row:number, target-column:number -> editor:address:shared:editor-data [ +def snap-cursor screen:address:screen, editor:address:editor-data, target-row:number, target-column:number -> editor:address:editor-data [ local-scope load-ingredients return-unless editor @@ -78,8 +78,8 @@ def snap-cursor screen:address:shared:screen, editor:address:shared:editor-data, right:number <- get *editor, right:offset screen-height:number <- screen-height screen # count newlines until screen row - curr:address:shared:duplex-list:character <- get *editor, top-of-screen:offset - prev:address:shared:duplex-list:character <- copy curr # just in case curr becomes null and we can't compute prev + curr:address:duplex-list:character <- get *editor, top-of-screen:offset + prev:address:duplex-list:character <- copy curr # just in case curr becomes null and we can't compute prev curr <- next curr row:number <- copy 1/top column:number <- copy left @@ -87,7 +87,7 @@ def snap-cursor screen:address:shared:screen, editor:address:shared:editor-data, cursor-row:number <- copy target-row *editor <- put *editor, cursor-column:offset, target-column cursor-column:number <- copy target-column - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset { +next-character break-unless curr @@ -161,7 +161,7 @@ def snap-cursor screen:address:shared:screen, editor:address:shared:editor-data, # Process an event 'e' and try to minimally update the screen. # Set 'go-render?' to true to indicate the caller must perform a non-minimal update. -def handle-keyboard-event screen:address:shared:screen, editor:address:shared:editor-data, e:event -> screen:address:shared:screen, editor:address:shared:editor-data, go-render?:boolean [ +def handle-keyboard-event screen:address:screen, editor:address:editor-data, e:event -> screen:address:screen, editor:address:editor-data, go-render?:boolean [ local-scope load-ingredients go-render? <- copy 0/false @@ -170,7 +170,7 @@ def handle-keyboard-event screen:address:shared:screen, editor:address:shared:ed screen-height:number <- screen-height screen left:number <- get *editor, left:offset right:number <- get *editor, right:offset - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset cursor-row:number <- get *editor, cursor-row:offset cursor-column:number <- get *editor, cursor-column:offset save-row:number <- copy cursor-row @@ -201,10 +201,10 @@ def handle-keyboard-event screen:address:shared:screen, editor:address:shared:ed return ] -def insert-at-cursor editor:address:shared:editor-data, c:character, screen:address:shared:screen -> editor:address:shared:editor-data, screen:address:shared:screen, go-render?:boolean [ +def insert-at-cursor editor:address:editor-data, c:character, screen:address:screen -> editor:address:editor-data, screen:address:screen, go-render?:boolean [ local-scope load-ingredients - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset insert c, before-cursor before-cursor <- next before-cursor *editor <- put *editor, before-cursor:offset, before-cursor @@ -221,7 +221,7 @@ def insert-at-cursor editor:address:shared:editor-data, c:character, screen:addr # but mostly we'll just move the cursor right cursor-column <- add cursor-column, 1 *editor <- put *editor, cursor-column:offset, cursor-column - next:address:shared:duplex-list:character <- next before-cursor + next:address:duplex-list:character <- next before-cursor { # at end of all text? no need to scroll? just print the character and leave at-end?:boolean <- equal next, 0/null @@ -241,7 +241,7 @@ def insert-at-cursor editor:address:shared:editor-data, c:character, screen:addr break-unless next at-right?:boolean <- greater-or-equal cursor-column, screen-width break-if at-right? - curr:address:shared:duplex-list:character <- copy before-cursor + curr:address:duplex-list:character <- copy before-cursor move-cursor screen, save-row, save-column curr-column:number <- copy save-column { @@ -267,7 +267,7 @@ def insert-at-cursor editor:address:shared:editor-data, c:character, screen:addr ] # helper for tests -def editor-render screen:address:shared:screen, editor:address:shared:editor-data -> screen:address:shared:screen, editor:address:shared:editor-data [ +def editor-render screen:address:screen, editor:address:editor-data -> screen:address:screen, editor:address:editor-data [ local-scope load-ingredients left:number <- get *editor, left:offset @@ -282,12 +282,12 @@ def editor-render screen:address:shared:screen, editor:address:shared:editor-dat scenario editor-handles-empty-event-queue [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [abc] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data assume-console [] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -299,17 +299,17 @@ scenario editor-handles-empty-event-queue [ scenario editor-handles-mouse-clicks [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [abc] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ left-click 1, 1 # on the 'b' ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] screen-should-contain [ . . @@ -326,16 +326,16 @@ scenario editor-handles-mouse-clicks [ scenario editor-handles-mouse-clicks-outside-text [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 1:address:array:character <- new [abc] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right $clear-trace assume-console [ left-click 1, 7 # last line, to the right of text ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 1 # cursor row @@ -346,17 +346,17 @@ scenario editor-handles-mouse-clicks-outside-text [ scenario editor-handles-mouse-clicks-outside-text-2 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right $clear-trace assume-console [ left-click 1, 7 # interior line, to the right of text ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 1 # cursor row @@ -367,17 +367,17 @@ def] scenario editor-handles-mouse-clicks-outside-text-3 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right $clear-trace assume-console [ left-click 3, 7 # below text ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 2 # cursor row @@ -388,19 +388,19 @@ def] scenario editor-handles-mouse-clicks-outside-column [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc] + 1:address:array:character <- new [abc] # editor occupies only left half of screen - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ # click on right half of screen left-click 3, 8 ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] screen-should-contain [ . . @@ -417,18 +417,18 @@ scenario editor-handles-mouse-clicks-outside-column [ scenario editor-handles-mouse-clicks-in-menu-area [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [abc] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ # click on first, 'menu' row left-click 0, 3 ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # no change to cursor memory-should-contain [ @@ -439,15 +439,15 @@ scenario editor-handles-mouse-clicks-in-menu-area [ scenario editor-inserts-characters-into-empty-editor [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ type [abc] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -460,9 +460,9 @@ scenario editor-inserts-characters-into-empty-editor [ scenario editor-inserts-characters-at-cursor [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [abc] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace # type two letters at different places assume-console [ @@ -471,7 +471,7 @@ scenario editor-inserts-characters-at-cursor [ type [d] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -484,16 +484,16 @@ scenario editor-inserts-characters-at-cursor [ scenario editor-inserts-characters-at-cursor-2 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [abc] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ left-click 1, 5 # right of last line type [d] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -506,17 +506,17 @@ scenario editor-inserts-characters-at-cursor-2 [ scenario editor-inserts-characters-at-cursor-5 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc d] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ left-click 1, 5 # right of non-last line type [e] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -530,16 +530,16 @@ d] scenario editor-inserts-characters-at-cursor-3 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [abc] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ left-click 3, 5 # below all text type [d] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -552,17 +552,17 @@ scenario editor-inserts-characters-at-cursor-3 [ scenario editor-inserts-characters-at-cursor-4 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc d] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ left-click 3, 5 # below all text type [e] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -576,17 +576,17 @@ d] scenario editor-inserts-characters-at-cursor-6 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc d] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ left-click 3, 5 # below all text type [ef] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -600,14 +600,14 @@ d] scenario editor-moves-cursor-after-inserting-characters [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [ab] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [ab] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right + editor-render screen, 2:address:editor-data assume-console [ type [01] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -621,15 +621,15 @@ scenario editor-moves-cursor-after-inserting-characters [ scenario editor-wraps-line-on-insert [ assume-screen 5/width, 5/height - 1:address:shared:array:character <- new [abc] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [abc] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right + editor-render screen, 2:address:editor-data # type a letter assume-console [ type [e] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # no wrap yet screen-should-contain [ @@ -644,7 +644,7 @@ scenario editor-wraps-line-on-insert [ type [f] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # now wrap screen-should-contain [ @@ -659,19 +659,19 @@ scenario editor-wraps-line-on-insert [ scenario editor-wraps-line-on-insert-2 [ # create an editor with some text assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abcdefg + 1:address:array:character <- new [abcdefg defg] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right + editor-render screen, 2:address:editor-data # type more text at the start assume-console [ left-click 3, 0 type [abc] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor is not wrapped memory-should-contain [ @@ -713,16 +713,16 @@ after <insert-character-special-case> [ scenario editor-wraps-cursor-after-inserting-characters [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abcde] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + 1:address:array:character <- new [abcde] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right assume-console [ left-click 1, 4 # line is full; no wrap icon yet type [f] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] screen-should-contain [ . . @@ -739,16 +739,16 @@ scenario editor-wraps-cursor-after-inserting-characters [ scenario editor-wraps-cursor-after-inserting-characters-2 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abcde] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + 1:address:array:character <- new [abcde] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right assume-console [ left-click 1, 3 # right before the wrap icon type [f] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] screen-should-contain [ . . @@ -765,16 +765,16 @@ scenario editor-wraps-cursor-after-inserting-characters-2 [ scenario editor-wraps-cursor-to-left-margin [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abcde] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 2/left, 7/right + 1:address:array:character <- new [abcde] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 2/left, 7/right assume-console [ left-click 1, 5 # line is full; no wrap icon yet type [01] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] screen-should-contain [ . . @@ -801,14 +801,14 @@ after <editor-initialization> [ scenario editor-moves-cursor-down-after-inserting-newline [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 1:address:array:character <- new [abc] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right assume-console [ type [0 1] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -831,12 +831,12 @@ after <handle-special-character> [ } ] -def insert-new-line-and-indent editor:address:shared:editor-data, screen:address:shared:screen -> editor:address:shared:editor-data, screen:address:shared:screen, go-render?:boolean [ +def insert-new-line-and-indent editor:address:editor-data, screen:address:screen -> editor:address:editor-data, screen:address:screen, go-render?:boolean [ local-scope load-ingredients cursor-row:number <- get *editor, cursor-row:offset cursor-column:number <- get *editor, cursor-column:offset - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset left:number <- get *editor, left:offset right:number <- get *editor, right:offset screen-height:number <- screen-height screen @@ -860,8 +860,8 @@ def insert-new-line-and-indent editor:address:shared:editor-data, screen:address # indent if necessary indent?:boolean <- get *editor, indent?:offset return-unless indent? - d:address:shared:duplex-list:character <- get *editor, data:offset - end-of-previous-line:address:shared:duplex-list:character <- prev before-cursor + d:address:duplex-list:character <- get *editor, data:offset + end-of-previous-line:address:duplex-list:character <- prev before-cursor indent:number <- line-indent end-of-previous-line, d i:number <- copy 0 { @@ -875,7 +875,7 @@ def insert-new-line-and-indent editor:address:shared:editor-data, screen:address # takes a pointer 'curr' into the doubly-linked list and its sentinel, counts # the number of spaces at the start of the line containing 'curr'. -def line-indent curr:address:shared:duplex-list:character, start:address:shared:duplex-list:character -> result:number [ +def line-indent curr:address:duplex-list:character, start:address:duplex-list:character -> result:number [ local-scope load-ingredients result:number <- copy 0 @@ -907,14 +907,14 @@ def line-indent curr:address:shared:duplex-list:character, start:address:shared: scenario editor-moves-cursor-down-after-inserting-newline-2 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 1/left, 10/right + 1:address:array:character <- new [abc] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 1/left, 10/right assume-console [ type [0 1] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -927,8 +927,8 @@ scenario editor-moves-cursor-down-after-inserting-newline-2 [ scenario editor-clears-previous-line-completely-after-inserting-newline [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abcde] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + 1:address:array:character <- new [abcde] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right assume-console [ press enter ] @@ -940,7 +940,7 @@ scenario editor-clears-previous-line-completely-after-inserting-newline [ . . ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # line should be fully cleared screen-should-contain [ @@ -954,10 +954,10 @@ scenario editor-clears-previous-line-completely-after-inserting-newline [ scenario editor-inserts-indent-after-newline [ assume-screen 10/width, 10/height - 1:address:shared:array:character <- new [ab + 1:address:array:character <- new [ab cd ef] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right # position cursor after 'cd' and hit 'newline' assume-console [ left-click 2, 8 @@ -965,9 +965,9 @@ ef] ] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor should be below start of previous line memory-should-contain [ @@ -978,10 +978,10 @@ ef] scenario editor-skips-indent-around-paste [ assume-screen 10/width, 10/height - 1:address:shared:array:character <- new [ab + 1:address:array:character <- new [ab cd ef] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right # position cursor after 'cd' and hit 'newline' surrounded by paste markers assume-console [ left-click 2, 8 @@ -990,9 +990,9 @@ ef] press 65506 # end paste ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor should be below start of previous line memory-should-contain [ @@ -1023,7 +1023,7 @@ after <handle-special-key> [ ## helpers -def draw-horizontal screen:address:shared:screen, row:number, x:number, right:number -> screen:address:shared:screen [ +def draw-horizontal screen:address:screen, row:number, x:number, right:number -> screen:address:screen [ local-scope load-ingredients style:character, style-found?:boolean <- next-ingredient diff --git a/edit/003-shortcuts.mu b/edit/003-shortcuts.mu index 8ed01de7..40956cb3 100644 --- a/edit/003-shortcuts.mu +++ b/edit/003-shortcuts.mu @@ -7,14 +7,14 @@ scenario editor-inserts-two-spaces-on-tab [ assume-screen 10/width, 5/height # just one character in final line - 1:address:shared:array:character <- new [ab + 1:address:array:character <- new [ab cd] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right assume-console [ press tab ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -40,18 +40,18 @@ after <handle-special-character> [ scenario editor-handles-backspace-key [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [abc] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ left-click 1, 1 press backspace ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 4:number <- get *2:address:shared:editor-data, cursor-row:offset - 5:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 4:number <- get *2:address:editor-data, cursor-row:offset + 5:number <- get *2:address:editor-data, cursor-column:offset ] screen-should-contain [ . . @@ -71,7 +71,7 @@ after <handle-special-character> [ delete-previous-character?:boolean <- equal c, 8/backspace break-unless delete-previous-character? <backspace-character-begin> - editor, screen, go-render?:boolean, backspaced-cell:address:shared:duplex-list:character <- delete-before-cursor editor, screen + editor, screen, go-render?:boolean, backspaced-cell:address:duplex-list:character <- delete-before-cursor editor, screen <backspace-character-end> return } @@ -80,19 +80,19 @@ after <handle-special-character> [ # return values: # go-render? - whether caller needs to update the screen # backspaced-cell - value deleted (or 0 if nothing was deleted) so we can save it for undo, etc. -def delete-before-cursor editor:address:shared:editor-data, screen:address:shared:screen -> editor:address:shared:editor-data, screen:address:shared:screen, go-render?:boolean, backspaced-cell:address:shared:duplex-list:character [ +def delete-before-cursor editor:address:editor-data, screen:address:screen -> editor:address:editor-data, screen:address:screen, go-render?:boolean, backspaced-cell:address:duplex-list:character [ local-scope load-ingredients - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset - data:address:shared:duplex-list:character <- get *editor, data:offset + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset + data:address:duplex-list:character <- get *editor, data:offset # if at start of text (before-cursor at § sentinel), return - prev:address:shared:duplex-list:character <- prev before-cursor + prev:address:duplex-list:character <- prev before-cursor go-render?, backspaced-cell <- copy 0/no-more-render, 0/nothing-deleted return-unless prev trace 10, [app], [delete-before-cursor] original-row:number <- get *editor, cursor-row:offset editor, scroll?:boolean <- move-cursor-coordinates-left editor - backspaced-cell:address:shared:duplex-list:character <- copy before-cursor + backspaced-cell:address:duplex-list:character <- copy before-cursor data <- remove before-cursor, data # will also neatly trim next/prev pointers in backspaced-cell/before-cursor before-cursor <- copy prev *editor <- put *editor, before-cursor:offset, before-cursor @@ -107,7 +107,7 @@ def delete-before-cursor editor:address:shared:editor-data, screen:address:share return-unless same-row? left:number <- get *editor, left:offset right:number <- get *editor, right:offset - curr:address:shared:duplex-list:character <- next before-cursor + curr:address:duplex-list:character <- next before-cursor screen <- move-cursor screen, cursor-row, cursor-column curr-column:number <- copy cursor-column { @@ -131,10 +131,10 @@ def delete-before-cursor editor:address:shared:editor-data, screen:address:share go-render? <- copy 0/false ] -def move-cursor-coordinates-left editor:address:shared:editor-data -> editor:address:shared:editor-data, go-render?:boolean [ +def move-cursor-coordinates-left editor:address:editor-data -> editor:address:editor-data, go-render?:boolean [ local-scope load-ingredients - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset cursor-row:number <- get *editor, cursor-row:offset cursor-column:number <- get *editor, cursor-column:offset left:number <- get *editor, left:offset @@ -168,7 +168,7 @@ def move-cursor-coordinates-left editor:address:shared:editor-data -> editor:add break-unless previous-character-is-newline? # compute length of previous line trace 10, [app], [switching to previous line] - d:address:shared:duplex-list:character <- get *editor, data:offset + d:address:duplex-list:character <- get *editor, data:offset end-of-line:number <- previous-line-length before-cursor, d right:number <- get *editor, right:offset width:number <- subtract right, left @@ -195,7 +195,7 @@ def move-cursor-coordinates-left editor:address:shared:editor-data -> editor:add # takes a pointer 'curr' into the doubly-linked list and its sentinel, counts # the length of the previous line before the 'curr' pointer. -def previous-line-length curr:address:shared:duplex-list:character, start:address:shared:duplex-list:character -> result:number [ +def previous-line-length curr:address:duplex-list:character, start:address:duplex-list:character -> result:number [ local-scope load-ingredients result:number <- copy 0 @@ -218,17 +218,17 @@ def previous-line-length curr:address:shared:duplex-list:character, start:addres scenario editor-clears-last-line-on-backspace [ assume-screen 10/width, 5/height # just one character in final line - 1:address:shared:array:character <- new [ab + 1:address:array:character <- new [ab cd] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right assume-console [ left-click 2, 0 # cursor at only character in final line press backspace ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 4:number <- get *2:address:shared:editor-data, cursor-row:offset - 5:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 4:number <- get *2:address:editor-data, cursor-row:offset + 5:number <- get *2:address:editor-data, cursor-column:offset ] screen-should-contain [ . . @@ -245,10 +245,10 @@ cd] scenario editor-joins-and-wraps-lines-on-backspace [ assume-screen 10/width, 5/height # initialize editor with two long-ish but non-wrapping lines - 1:address:shared:array:character <- new [abc def + 1:address:array:character <- new [abc def ghi jkl] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace # position the cursor at the start of the second and hit backspace assume-console [ @@ -256,7 +256,7 @@ ghi jkl] press backspace ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # resulting single line should wrap correctly screen-should-contain [ @@ -271,9 +271,9 @@ ghi jkl] scenario editor-wraps-long-lines-on-backspace [ assume-screen 10/width, 5/height # initialize editor in part of the screen with a long line - 1:address:shared:array:character <- new [abc def ghij] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 8/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [abc def ghij] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 8/right + editor-render screen, 2:address:editor-data # confirm that it wraps screen-should-contain [ . . @@ -288,7 +288,7 @@ scenario editor-wraps-long-lines-on-backspace [ press backspace ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # resulting single line should wrap correctly and not overflow its bounds screen-should-contain [ @@ -304,15 +304,15 @@ scenario editor-wraps-long-lines-on-backspace [ scenario editor-handles-delete-key [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [abc] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ press delete ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -326,7 +326,7 @@ scenario editor-handles-delete-key [ press delete ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -342,18 +342,18 @@ after <handle-special-key> [ delete-next-character?:boolean <- equal k, 65522/delete break-unless delete-next-character? <delete-character-begin> - editor, screen, go-render?:boolean, deleted-cell:address:shared:duplex-list:character <- delete-at-cursor editor, screen + editor, screen, go-render?:boolean, deleted-cell:address:duplex-list:character <- delete-at-cursor editor, screen <delete-character-end> return } ] -def delete-at-cursor editor:address:shared:editor-data, screen:address:shared:screen -> editor:address:shared:editor-data, screen:address:shared:screen, go-render?:boolean, deleted-cell:address:shared:duplex-list:character [ +def delete-at-cursor editor:address:editor-data, screen:address:screen -> editor:address:editor-data, screen:address:screen, go-render?:boolean, deleted-cell:address:duplex-list:character [ local-scope load-ingredients - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset - data:address:shared:duplex-list:character <- get *editor, data:offset - deleted-cell:address:shared:duplex-list:character <- next before-cursor + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset + data:address:duplex-list:character <- get *editor, data:offset + deleted-cell:address:duplex-list:character <- next before-cursor go-render? <- copy 0/false return-unless deleted-cell currc:character <- get *deleted-cell, value:offset @@ -362,7 +362,7 @@ def delete-at-cursor editor:address:shared:editor-data, screen:address:shared:sc go-render? <- copy 1/true return-if deleted-newline? # wasn't a newline? render rest of line - curr:address:shared:duplex-list:character <- next before-cursor # refresh after remove above + curr:address:duplex-list:character <- next before-cursor # refresh after remove above cursor-row:number <- get *editor, cursor-row:offset cursor-column:number <- get *editor, cursor-column:offset screen <- move-cursor screen, cursor-row, cursor-column @@ -393,16 +393,16 @@ def delete-at-cursor editor:address:shared:editor-data, screen:address:shared:sc scenario editor-moves-cursor-right-with-key [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [abc] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ press right-arrow type [0] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -418,7 +418,7 @@ after <handle-special-key> [ move-to-next-character?:boolean <- equal k, 65514/right-arrow break-unless move-to-next-character? # if not at end of text - next-cursor:address:shared:duplex-list:character <- next before-cursor + next-cursor:address:duplex-list:character <- next before-cursor break-unless next-cursor # scan to next character <move-cursor-begin> @@ -432,10 +432,10 @@ after <handle-special-key> [ } ] -def move-cursor-coordinates-right editor:address:shared:editor-data, screen-height:number -> editor:address:shared:editor-data, go-render?:boolean [ +def move-cursor-coordinates-right editor:address:editor-data, screen-height:number -> editor:address:editor-data, go-render?:boolean [ local-scope load-ingredients - before-cursor:address:shared:duplex-list:character <- get *editor before-cursor:offset + before-cursor:address:duplex-list:character <- get *editor before-cursor:offset cursor-row:number <- get *editor, cursor-row:offset cursor-column:number <- get *editor, cursor-column:offset left:number <- get *editor, left:offset @@ -465,7 +465,7 @@ def move-cursor-coordinates-right editor:address:shared:editor-data, screen-heig at-wrap?:boolean <- equal cursor-column, wrap-column break-unless at-wrap? # and if next character isn't newline - next:address:shared:duplex-list:character <- next before-cursor + next:address:duplex-list:character <- next before-cursor break-unless next next-character:character <- get *next, value:offset newline?:boolean <- equal next-character, 10/newline @@ -490,10 +490,10 @@ def move-cursor-coordinates-right editor:address:shared:editor-data, screen-heig scenario editor-moves-cursor-to-next-line-with-right-arrow [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc d] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace # type right-arrow a few times to get to start of second line assume-console [ @@ -503,7 +503,7 @@ d] press right-arrow # next line ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] check-trace-count-for-label 0, [print-character] # type something and ensure it goes where it should @@ -511,7 +511,7 @@ d] type [0] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -525,10 +525,10 @@ d] scenario editor-moves-cursor-to-next-line-with-right-arrow-2 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc d] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 1/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 1/left, 10/right + editor-render screen, 2:address:editor-data assume-console [ press right-arrow press right-arrow @@ -537,7 +537,7 @@ d] type [0] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -550,18 +550,18 @@ d] scenario editor-moves-cursor-to-next-wrapped-line-with-right-arrow [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abcdef] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [abcdef] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ left-click 1, 3 press right-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] screen-should-contain [ . . @@ -580,9 +580,9 @@ scenario editor-moves-cursor-to-next-wrapped-line-with-right-arrow [ scenario editor-moves-cursor-to-next-wrapped-line-with-right-arrow-2 [ assume-screen 10/width, 5/height # line just barely wrapping - 1:address:shared:array:character <- new [abcde] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [abcde] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right + editor-render screen, 2:address:editor-data $clear-trace # position cursor at last character before wrap and hit right-arrow assume-console [ @@ -590,9 +590,9 @@ scenario editor-moves-cursor-to-next-wrapped-line-with-right-arrow-2 [ press right-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 2 @@ -603,9 +603,9 @@ scenario editor-moves-cursor-to-next-wrapped-line-with-right-arrow-2 [ press right-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 2 @@ -616,18 +616,18 @@ scenario editor-moves-cursor-to-next-wrapped-line-with-right-arrow-2 [ scenario editor-moves-cursor-to-next-wrapped-line-with-right-arrow-3 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abcdef] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 1/left, 6/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [abcdef] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 1/left, 6/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ left-click 1, 4 press right-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] screen-should-contain [ . . @@ -645,10 +645,10 @@ scenario editor-moves-cursor-to-next-wrapped-line-with-right-arrow-3 [ scenario editor-moves-cursor-to-next-line-with-right-arrow-at-end-of-line [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc d] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace # move to end of line, press right-arrow, type a character assume-console [ @@ -657,7 +657,7 @@ d] type [0] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # new character should be in next line screen-should-contain [ @@ -676,9 +676,9 @@ d] scenario editor-moves-cursor-left-with-key [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [abc] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ left-click 1, 2 @@ -686,7 +686,7 @@ scenario editor-moves-cursor-left-with-key [ type [0] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -703,7 +703,7 @@ after <handle-special-key> [ break-unless move-to-previous-character? trace 10, [app], [left arrow] # if not at start of text (before-cursor at § sentinel) - prev:address:shared:duplex-list:character <- prev before-cursor + prev:address:duplex-list:character <- prev before-cursor go-render? <- copy 0/false return-unless prev <move-cursor-begin> @@ -719,10 +719,10 @@ after <handle-special-key> [ scenario editor-moves-cursor-to-previous-line-with-left-arrow-at-start-of-line [ assume-screen 10/width, 5/height # initialize editor with two lines - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc d] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace # position cursor at start of second line (so there's no previous newline) assume-console [ @@ -730,9 +730,9 @@ d] press left-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 1 @@ -744,11 +744,11 @@ d] scenario editor-moves-cursor-to-previous-line-with-left-arrow-at-start-of-line-2 [ assume-screen 10/width, 5/height # initialize editor with three lines - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def g] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace # position cursor further down (so there's a newline before the character at # the cursor) @@ -758,7 +758,7 @@ g] type [0] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -772,11 +772,11 @@ g] scenario editor-moves-cursor-to-previous-line-with-left-arrow-at-start-of-line-3 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def g] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace # position cursor at start of text, press left-arrow, then type a character assume-console [ @@ -785,7 +785,7 @@ g] type [0] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # left-arrow should have had no effect screen-should-contain [ @@ -801,11 +801,11 @@ g] scenario editor-moves-cursor-to-previous-line-with-left-arrow-at-start-of-line-4 [ assume-screen 10/width, 5/height # initialize editor with text containing an empty line - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc d] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace # position cursor right after empty line assume-console [ @@ -814,7 +814,7 @@ d] type [0] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -829,9 +829,9 @@ d] scenario editor-moves-across-screen-lines-across-wrap-with-left-arrow [ assume-screen 10/width, 5/height # initialize editor with a wrapping line - 1:address:shared:array:character <- new [abcdef] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [abcdef] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right + editor-render screen, 2:address:editor-data $clear-trace screen-should-contain [ . . @@ -846,9 +846,9 @@ scenario editor-moves-across-screen-lines-across-wrap-with-left-arrow [ press left-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 1 # previous row @@ -860,10 +860,10 @@ scenario editor-moves-across-screen-lines-across-wrap-with-left-arrow [ scenario editor-moves-across-screen-lines-to-wrapping-line-with-left-arrow [ assume-screen 10/width, 5/height # initialize editor with a wrapping line followed by a second line - 1:address:shared:array:character <- new [abcdef + 1:address:array:character <- new [abcdef g] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right + editor-render screen, 2:address:editor-data $clear-trace screen-should-contain [ . . @@ -878,9 +878,9 @@ g] press left-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 2 # previous row @@ -892,10 +892,10 @@ g] scenario editor-moves-across-screen-lines-to-non-wrapping-line-with-left-arrow [ assume-screen 10/width, 5/height # initialize editor with a line on the verge of wrapping, followed by a second line - 1:address:shared:array:character <- new [abcd + 1:address:array:character <- new [abcd e] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right + editor-render screen, 2:address:editor-data $clear-trace screen-should-contain [ . . @@ -910,9 +910,9 @@ e] press left-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 1 # previous row @@ -927,19 +927,19 @@ e] scenario editor-moves-to-previous-line-with-up-arrow [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ left-click 2, 1 press up-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 1 @@ -950,7 +950,7 @@ def] type [0] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -973,12 +973,12 @@ after <handle-special-key> [ } ] -def move-to-previous-line editor:address:shared:editor-data -> editor:address:shared:editor-data, go-render?:boolean [ +def move-to-previous-line editor:address:editor-data -> editor:address:editor-data, go-render?:boolean [ local-scope load-ingredients cursor-row:number <- get *editor, cursor-row:offset cursor-column:number <- get *editor, cursor-column:offset - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset left:number <- get *editor, left:offset right:number <- get *editor, right:offset already-at-top?:boolean <- lesser-or-equal cursor-row, 1/top @@ -988,13 +988,13 @@ def move-to-previous-line editor:address:shared:editor-data -> editor:address:sh # if not at newline, move to start of line (previous newline) # then scan back another line # if either step fails, give up without modifying cursor or coordinates - curr:address:shared:duplex-list:character <- copy before-cursor + curr:address:duplex-list:character <- copy before-cursor { - old:address:shared:duplex-list:character <- copy curr + old:address:duplex-list:character <- copy curr c2:character <- get *curr, value:offset at-newline?:boolean <- equal c2, 10/newline break-if at-newline? - curr:address:shared:duplex-list:character <- before-previous-line curr, editor + curr:address:duplex-list:character <- before-previous-line curr, editor no-motion?:boolean <- equal curr, old go-render? <- copy 0/false return-if no-motion? @@ -1017,7 +1017,7 @@ def move-to-previous-line editor:address:shared:editor-data -> editor:address:sh { done?:boolean <- greater-or-equal cursor-column, target-column break-if done? - curr:address:shared:duplex-list:character <- next before-cursor + curr:address:duplex-list:character <- next before-cursor break-unless curr currc:character <- get *curr, value:offset at-newline?:boolean <- equal currc, 10/newline @@ -1043,19 +1043,19 @@ def move-to-previous-line editor:address:shared:editor-data -> editor:address:sh scenario editor-adjusts-column-at-previous-line [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [ab + 1:address:array:character <- new [ab def] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ left-click 2, 3 press up-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 1 @@ -1066,7 +1066,7 @@ def] type [0] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -1079,19 +1079,19 @@ def] scenario editor-adjusts-column-at-empty-line [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [ + 1:address:array:character <- new [ def] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ left-click 2, 3 press up-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 1 @@ -1102,7 +1102,7 @@ def] type [0] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -1116,11 +1116,11 @@ def] scenario editor-moves-to-previous-line-from-left-margin [ assume-screen 10/width, 5/height # start out with three lines - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def ghi] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace # click on the third line and hit up-arrow, so you end up just after a newline assume-console [ @@ -1128,9 +1128,9 @@ ghi] press up-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 2 @@ -1141,7 +1141,7 @@ ghi] type [0] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -1156,19 +1156,19 @@ ghi] scenario editor-moves-to-next-line-with-down-arrow [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace # cursor starts out at (1, 0) assume-console [ press down-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # ..and ends at (2, 0) memory-should-contain [ @@ -1180,7 +1180,7 @@ def] type [0] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -1203,12 +1203,12 @@ after <handle-special-key> [ } ] -def move-to-next-line editor:address:shared:editor-data, screen-height:number -> editor:address:shared:editor-data, go-render?:boolean [ +def move-to-next-line editor:address:editor-data, screen-height:number -> editor:address:editor-data, go-render?:boolean [ local-scope load-ingredients cursor-row:number <- get *editor, cursor-row:offset cursor-column:number <- get *editor, cursor-column:offset - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset left:number <- get *editor, left:offset right:number <- get *editor, right:offset last-line:number <- subtract screen-height, 1 @@ -1218,7 +1218,7 @@ def move-to-next-line editor:address:shared:editor-data, screen-height:number -> break-if already-at-bottom? # scan to start of next line, then to right column or until end of line max:number <- subtract right, left - next-line:address:shared:duplex-list:character <- before-start-of-next-line before-cursor, max + next-line:address:duplex-list:character <- before-start-of-next-line before-cursor, max { # already at end of buffer? try to scroll up (so we can see more # warnings or sandboxes below) @@ -1239,7 +1239,7 @@ def move-to-next-line editor:address:shared:editor-data, screen-height:number -> { done?:boolean <- greater-or-equal cursor-column, target-column break-if done? - curr:address:shared:duplex-list:character <- next before-cursor + curr:address:duplex-list:character <- next before-cursor break-unless curr currc:character <- get *curr, value:offset at-newline?:boolean <- equal currc, 10/newline @@ -1261,19 +1261,19 @@ def move-to-next-line editor:address:shared:editor-data, screen-height:number -> scenario editor-adjusts-column-at-next-line [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc de] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ left-click 1, 3 press down-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 2 @@ -1284,7 +1284,7 @@ de] type [0] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -1299,10 +1299,10 @@ de] scenario editor-moves-to-start-of-line-with-ctrl-a [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [123 + 1:address:array:character <- new [123 456] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace # start on second line, press ctrl-a assume-console [ @@ -1310,9 +1310,9 @@ scenario editor-moves-to-start-of-line-with-ctrl-a [ press ctrl-a ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 4:number <- get *2:address:shared:editor-data, cursor-row:offset - 5:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 4:number <- get *2:address:editor-data, cursor-row:offset + 5:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves to start of line memory-should-contain [ @@ -1348,7 +1348,7 @@ after <handle-special-key> [ } ] -def move-to-start-of-line editor:address:shared:editor-data -> editor:address:shared:editor-data [ +def move-to-start-of-line editor:address:editor-data -> editor:address:editor-data [ local-scope load-ingredients # update cursor column @@ -1356,8 +1356,8 @@ def move-to-start-of-line editor:address:shared:editor-data -> editor:address:sh cursor-column:number <- copy left *editor <- put *editor, cursor-column:offset, cursor-column # update before-cursor - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset - init:address:shared:duplex-list:character <- get *editor, data:offset + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset + init:address:duplex-list:character <- get *editor, data:offset # while not at start of line, move { at-start-of-text?:boolean <- equal before-cursor, init @@ -1374,10 +1374,10 @@ def move-to-start-of-line editor:address:shared:editor-data -> editor:address:sh scenario editor-moves-to-start-of-line-with-ctrl-a-2 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [123 + 1:address:array:character <- new [123 456] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace # start on first line (no newline before), press ctrl-a assume-console [ @@ -1385,9 +1385,9 @@ scenario editor-moves-to-start-of-line-with-ctrl-a-2 [ press ctrl-a ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 4:number <- get *2:address:shared:editor-data, cursor-row:offset - 5:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 4:number <- get *2:address:editor-data, cursor-row:offset + 5:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves to start of line memory-should-contain [ @@ -1399,9 +1399,9 @@ scenario editor-moves-to-start-of-line-with-ctrl-a-2 [ scenario editor-moves-to-start-of-line-with-home [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [123 + 1:address:array:character <- new [123 456] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right $clear-trace # start on second line, press 'home' assume-console [ @@ -1409,9 +1409,9 @@ scenario editor-moves-to-start-of-line-with-home [ press home ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves to start of line memory-should-contain [ @@ -1423,10 +1423,10 @@ scenario editor-moves-to-start-of-line-with-home [ scenario editor-moves-to-start-of-line-with-home-2 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [123 + 1:address:array:character <- new [123 456] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace # start on first line (no newline before), press 'home' assume-console [ @@ -1434,9 +1434,9 @@ scenario editor-moves-to-start-of-line-with-home-2 [ press home ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves to start of line memory-should-contain [ @@ -1450,10 +1450,10 @@ scenario editor-moves-to-start-of-line-with-home-2 [ scenario editor-moves-to-end-of-line-with-ctrl-e [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [123 + 1:address:array:character <- new [123 456] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace # start on first line, press ctrl-e assume-console [ @@ -1461,9 +1461,9 @@ scenario editor-moves-to-end-of-line-with-ctrl-e [ press ctrl-e ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 4:number <- get *2:address:shared:editor-data, cursor-row:offset - 5:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 4:number <- get *2:address:editor-data, cursor-row:offset + 5:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves to end of line memory-should-contain [ @@ -1476,9 +1476,9 @@ scenario editor-moves-to-end-of-line-with-ctrl-e [ type [z] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 4:number <- get *2:address:shared:editor-data, cursor-row:offset - 5:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 4:number <- get *2:address:editor-data, cursor-row:offset + 5:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 4 <- 1 @@ -1520,14 +1520,14 @@ after <handle-special-key> [ } ] -def move-to-end-of-line editor:address:shared:editor-data -> editor:address:shared:editor-data [ +def move-to-end-of-line editor:address:editor-data -> editor:address:editor-data [ local-scope load-ingredients - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset cursor-column:number <- get *editor, cursor-column:offset # while not at start of line, move { - next:address:shared:duplex-list:character <- next before-cursor + next:address:duplex-list:character <- next before-cursor break-unless next # end of text nextc:character <- get *next, value:offset at-end-of-line?:boolean <- equal nextc, 10/newline @@ -1542,10 +1542,10 @@ def move-to-end-of-line editor:address:shared:editor-data -> editor:address:shar scenario editor-moves-to-end-of-line-with-ctrl-e-2 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [123 + 1:address:array:character <- new [123 456] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace # start on second line (no newline after), press ctrl-e assume-console [ @@ -1553,9 +1553,9 @@ scenario editor-moves-to-end-of-line-with-ctrl-e-2 [ press ctrl-e ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 4:number <- get *2:address:shared:editor-data, cursor-row:offset - 5:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 4:number <- get *2:address:editor-data, cursor-row:offset + 5:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves to end of line memory-should-contain [ @@ -1567,10 +1567,10 @@ scenario editor-moves-to-end-of-line-with-ctrl-e-2 [ scenario editor-moves-to-end-of-line-with-end [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [123 + 1:address:array:character <- new [123 456] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace # start on first line, press 'end' assume-console [ @@ -1578,9 +1578,9 @@ scenario editor-moves-to-end-of-line-with-end [ press end ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves to end of line memory-should-contain [ @@ -1592,10 +1592,10 @@ scenario editor-moves-to-end-of-line-with-end [ scenario editor-moves-to-end-of-line-with-end-2 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [123 + 1:address:array:character <- new [123 456] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace # start on second line (no newline after), press 'end' assume-console [ @@ -1603,9 +1603,9 @@ scenario editor-moves-to-end-of-line-with-end-2 [ press end ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves to end of line memory-should-contain [ @@ -1619,16 +1619,16 @@ scenario editor-moves-to-end-of-line-with-end-2 [ scenario editor-deletes-to-start-of-line-with-ctrl-u [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [123 + 1:address:array:character <- new [123 456] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right # start on second line, press ctrl-u assume-console [ left-click 2, 2 press ctrl-u ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # cursor deletes to start of line screen-should-contain [ @@ -1645,21 +1645,21 @@ after <handle-special-character> [ delete-to-start-of-line?:boolean <- equal c, 21/ctrl-u break-unless delete-to-start-of-line? <delete-to-start-of-line-begin> - deleted-cells:address:shared:duplex-list:character <- delete-to-start-of-line editor + deleted-cells:address:duplex-list:character <- delete-to-start-of-line editor <delete-to-start-of-line-end> go-render? <- copy 1/true return } ] -def delete-to-start-of-line editor:address:shared:editor-data -> result:address:shared:duplex-list:character, editor:address:shared:editor-data [ +def delete-to-start-of-line editor:address:editor-data -> result:address:duplex-list:character, editor:address:editor-data [ local-scope load-ingredients # compute range to delete - init:address:shared:duplex-list:character <- get *editor, data:offset - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset - start:address:shared:duplex-list:character <- copy before-cursor - end:address:shared:duplex-list:character <- next before-cursor + init:address:duplex-list:character <- get *editor, data:offset + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset + start:address:duplex-list:character <- copy before-cursor + end:address:duplex-list:character <- next before-cursor { at-start-of-text?:boolean <- equal start, init break-if at-start-of-text? @@ -1671,7 +1671,7 @@ def delete-to-start-of-line editor:address:shared:editor-data -> result:address: loop } # snip it out - result:address:shared:duplex-list:character <- next start + result:address:duplex-list:character <- next start remove-between start, end # adjust cursor before-cursor <- copy start @@ -1682,16 +1682,16 @@ def delete-to-start-of-line editor:address:shared:editor-data -> result:address: scenario editor-deletes-to-start-of-line-with-ctrl-u-2 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [123 + 1:address:array:character <- new [123 456] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right # start on first line (no newline before), press ctrl-u assume-console [ left-click 1, 2 press ctrl-u ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # cursor deletes to start of line screen-should-contain [ @@ -1705,16 +1705,16 @@ scenario editor-deletes-to-start-of-line-with-ctrl-u-2 [ scenario editor-deletes-to-start-of-line-with-ctrl-u-3 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [123 + 1:address:array:character <- new [123 456] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right # start past end of line, press ctrl-u assume-console [ left-click 1, 3 press ctrl-u ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # cursor deletes to start of line screen-should-contain [ @@ -1728,16 +1728,16 @@ scenario editor-deletes-to-start-of-line-with-ctrl-u-3 [ scenario editor-deletes-to-start-of-final-line-with-ctrl-u [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [123 + 1:address:array:character <- new [123 456] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right # start past end of final line, press ctrl-u assume-console [ left-click 2, 3 press ctrl-u ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # cursor deletes to start of line screen-should-contain [ @@ -1753,16 +1753,16 @@ scenario editor-deletes-to-start-of-final-line-with-ctrl-u [ scenario editor-deletes-to-end-of-line-with-ctrl-k [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [123 + 1:address:array:character <- new [123 456] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right # start on first line, press ctrl-k assume-console [ left-click 1, 1 press ctrl-k ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # cursor deletes to end of line screen-should-contain [ @@ -1779,19 +1779,19 @@ after <handle-special-character> [ delete-to-end-of-line?:boolean <- equal c, 11/ctrl-k break-unless delete-to-end-of-line? <delete-to-end-of-line-begin> - deleted-cells:address:shared:duplex-list:character <- delete-to-end-of-line editor + deleted-cells:address:duplex-list:character <- delete-to-end-of-line editor <delete-to-end-of-line-end> go-render? <- copy 1/true return } ] -def delete-to-end-of-line editor:address:shared:editor-data -> result:address:shared:duplex-list:character, editor:address:shared:editor-data [ +def delete-to-end-of-line editor:address:editor-data -> result:address:duplex-list:character, editor:address:editor-data [ local-scope load-ingredients # compute range to delete - start:address:shared:duplex-list:character <- get *editor, before-cursor:offset - end:address:shared:duplex-list:character <- next start + start:address:duplex-list:character <- get *editor, before-cursor:offset + end:address:duplex-list:character <- next start { at-end-of-text?:boolean <- equal end, 0/null break-if at-end-of-text? @@ -1808,16 +1808,16 @@ def delete-to-end-of-line editor:address:shared:editor-data -> result:address:sh scenario editor-deletes-to-end-of-line-with-ctrl-k-2 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [123 + 1:address:array:character <- new [123 456] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right # start on second line (no newline after), press ctrl-k assume-console [ left-click 2, 1 press ctrl-k ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # cursor deletes to end of line screen-should-contain [ @@ -1831,16 +1831,16 @@ scenario editor-deletes-to-end-of-line-with-ctrl-k-2 [ scenario editor-deletes-to-end-of-line-with-ctrl-k-3 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [123 + 1:address:array:character <- new [123 456] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right # start at end of line assume-console [ left-click 1, 2 press ctrl-k ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # cursor deletes just last character screen-should-contain [ @@ -1854,16 +1854,16 @@ scenario editor-deletes-to-end-of-line-with-ctrl-k-3 [ scenario editor-deletes-to-end-of-line-with-ctrl-k-4 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [123 + 1:address:array:character <- new [123 456] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right # start past end of line assume-console [ left-click 1, 3 press ctrl-k ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # cursor deletes nothing screen-should-contain [ @@ -1877,16 +1877,16 @@ scenario editor-deletes-to-end-of-line-with-ctrl-k-4 [ scenario editor-deletes-to-end-of-line-with-ctrl-k-5 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [123 + 1:address:array:character <- new [123 456] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right # start at end of text assume-console [ left-click 2, 2 press ctrl-k ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # cursor deletes just the final character screen-should-contain [ @@ -1900,16 +1900,16 @@ scenario editor-deletes-to-end-of-line-with-ctrl-k-5 [ scenario editor-deletes-to-end-of-line-with-ctrl-k-6 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [123 + 1:address:array:character <- new [123 456] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right # start past end of text assume-console [ left-click 2, 3 press ctrl-k ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # cursor deletes nothing screen-should-contain [ @@ -1927,11 +1927,11 @@ scenario editor-can-scroll-down-using-arrow-keys [ # screen has 1 line for menu + 3 lines assume-screen 10/width, 4/height # initialize editor with >3 lines - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b c d] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right screen-should-contain [ . . .a . @@ -1944,7 +1944,7 @@ d] press down-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen slides by one line screen-should-contain [ @@ -1957,11 +1957,11 @@ d] after <scroll-down> [ trace 10, [app], [scroll down] - top-of-screen:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + top-of-screen:address:duplex-list:character <- get *editor, top-of-screen:offset left:number <- get *editor, left:offset right:number <- get *editor, right:offset max:number <- subtract right, left - old-top:address:shared:duplex-list:character <- copy top-of-screen + old-top:address:duplex-list:character <- copy top-of-screen top-of-screen <- before-start-of-next-line top-of-screen, max *editor <- put *editor, top-of-screen:offset, top-of-screen no-movement?:boolean <- equal old-top, top-of-screen @@ -1972,11 +1972,11 @@ after <scroll-down> [ # takes a pointer into the doubly-linked list, scans ahead at most 'max' # positions until the next newline # beware: never return null pointer. -def before-start-of-next-line original:address:shared:duplex-list:character, max:number -> curr:address:shared:duplex-list:character [ +def before-start-of-next-line original:address:duplex-list:character, max:number -> curr:address:duplex-list:character [ local-scope load-ingredients count:number <- copy 0 - curr:address:shared:duplex-list:character <- copy original + curr:address:duplex-list:character <- copy original # skip the initial newline if it exists { c:character <- get *curr, value:offset @@ -2005,11 +2005,11 @@ scenario editor-scrolls-down-past-wrapped-line-using-arrow-keys [ assume-screen 10/width, 4/height # initialize editor with a long, wrapped line and more than a screen of # other lines - 1:address:shared:array:character <- new [abcdef + 1:address:array:character <- new [abcdef g h i] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right screen-should-contain [ . . .abcd↩ . @@ -2022,7 +2022,7 @@ i] press down-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen shows partial wrapped line screen-should-contain [ @@ -2037,18 +2037,18 @@ scenario editor-scrolls-down-past-wrapped-line-using-arrow-keys-2 [ # screen has 1 line for menu + 3 lines assume-screen 10/width, 4/height # editor starts with a long line wrapping twice - 1:address:shared:array:character <- new [abcdefghij + 1:address:array:character <- new [abcdefghij k l m] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right # position cursor at last line, then try to move further down assume-console [ left-click 3, 0 press down-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen shows partial wrapped line containing a wrap icon screen-should-contain [ @@ -2062,7 +2062,7 @@ m] press down-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen shows partial wrapped line screen-should-contain [ @@ -2077,19 +2077,19 @@ scenario editor-scrolls-down-when-line-wraps [ # screen has 1 line for menu + 3 lines assume-screen 5/width, 4/height # editor contains a long line in the third line - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b cdef] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right # position cursor at end, type a character assume-console [ left-click 3, 4 type [g] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # screen scrolls screen-should-contain [ @@ -2107,19 +2107,19 @@ cdef] scenario editor-scrolls-down-on-newline [ assume-screen 5/width, 4/height # position cursor after last line and type newline - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b c] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right assume-console [ left-click 3, 4 type [ ] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # screen scrolls screen-should-contain [ @@ -2138,19 +2138,19 @@ scenario editor-scrolls-down-on-right-arrow [ # screen has 1 line for menu + 3 lines assume-screen 5/width, 4/height # editor contains a wrapped line - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b cdefgh] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right # position cursor at end of screen and try to move right assume-console [ left-click 3, 3 press right-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # screen scrolls screen-should-contain [ @@ -2169,20 +2169,20 @@ scenario editor-scrolls-down-on-right-arrow-2 [ # screen has 1 line for menu + 3 lines assume-screen 5/width, 4/height # editor contains more lines than can fit on screen - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b c d] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right # position cursor at end of screen and try to move right assume-console [ left-click 3, 3 press right-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # screen scrolls screen-should-contain [ @@ -2199,10 +2199,10 @@ d] scenario editor-scrolls-at-end-on-down-arrow [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc de] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace # try to move down past end of text assume-console [ @@ -2210,9 +2210,9 @@ de] press down-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # screen should scroll, moving cursor to end of text memory-should-contain [ @@ -2223,7 +2223,7 @@ de] type [0] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -2238,9 +2238,9 @@ de] press down-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # screen stops scrolling because cursor is already at top memory-should-contain [ @@ -2252,7 +2252,7 @@ de] type [1] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -2266,14 +2266,14 @@ scenario editor-combines-page-and-line-scroll [ # screen has 1 line for menu + 3 lines assume-screen 10/width, 4/height # initialize editor with a few pages of lines - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b c d e f g] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right # scroll down one page and one line assume-console [ press page-down @@ -2281,7 +2281,7 @@ g] press down-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen scrolls down 3 lines screen-should-contain [ @@ -2298,11 +2298,11 @@ scenario editor-can-scroll-up-using-arrow-keys [ # screen has 1 line for menu + 3 lines assume-screen 10/width, 4/height # initialize editor with >3 lines - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b c d] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right screen-should-contain [ . . .a . @@ -2315,7 +2315,7 @@ d] press up-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen slides by one line screen-should-contain [ @@ -2328,8 +2328,8 @@ d] after <scroll-up> [ trace 10, [app], [scroll up] - top-of-screen:address:shared:duplex-list:character <- get *editor, top-of-screen:offset - old-top:address:shared:duplex-list:character <- copy top-of-screen + top-of-screen:address:duplex-list:character <- get *editor, top-of-screen:offset + old-top:address:duplex-list:character <- copy top-of-screen top-of-screen <- before-previous-line top-of-screen, editor *editor <- put *editor, top-of-screen:offset, top-of-screen no-movement?:boolean <- equal old-top, top-of-screen @@ -2340,10 +2340,10 @@ after <scroll-up> [ # takes a pointer into the doubly-linked list, scans back to before start of # previous *wrapped* line # beware: never return null pointer -def before-previous-line in:address:shared:duplex-list:character, editor:address:shared:editor-data -> out:address:shared:duplex-list:character [ +def before-previous-line in:address:duplex-list:character, editor:address:editor-data -> out:address:duplex-list:character [ local-scope load-ingredients - curr:address:shared:duplex-list:character <- copy in + curr:address:duplex-list:character <- copy in c:character <- get *curr, value:offset # compute max, number of characters to skip # 1 + len%(width-1) @@ -2351,12 +2351,12 @@ def before-previous-line in:address:shared:duplex-list:character, editor:address left:number <- get *editor, left:offset right:number <- get *editor, right:offset max-line-length:number <- subtract right, left, -1/exclusive-right, 1/wrap-icon - sentinel:address:shared:duplex-list:character <- get *editor, data:offset + sentinel:address:duplex-list:character <- get *editor, data:offset len:number <- previous-line-length curr, sentinel { break-if len # empty line; just skip this newline - prev:address:shared:duplex-list:character <- prev curr + prev:address:duplex-list:character <- prev curr return-unless prev, curr return prev } @@ -2372,7 +2372,7 @@ def before-previous-line in:address:shared:duplex-list:character, editor:address { done?:boolean <- greater-or-equal count, max break-if done? - prev:address:shared:duplex-list:character <- prev curr + prev:address:duplex-list:character <- prev curr break-unless prev curr <- copy prev count <- add count, 1 @@ -2386,11 +2386,11 @@ scenario editor-scrolls-up-past-wrapped-line-using-arrow-keys [ assume-screen 10/width, 4/height # initialize editor with a long, wrapped line and more than a screen of # other lines - 1:address:shared:array:character <- new [abcdef + 1:address:array:character <- new [abcdef g h i] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right screen-should-contain [ . . .abcd↩ . @@ -2402,7 +2402,7 @@ i] press page-down ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -2415,7 +2415,7 @@ i] press up-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen shows partial wrapped line screen-should-contain [ @@ -2430,17 +2430,17 @@ scenario editor-scrolls-up-past-wrapped-line-using-arrow-keys-2 [ # screen has 1 line for menu + 4 lines assume-screen 10/width, 5/height # editor starts with a long line wrapping twice, occupying 3 of the 4 lines - 1:address:shared:array:character <- new [abcdefghij + 1:address:array:character <- new [abcdefghij k l m] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right # position cursor at top of second page assume-console [ press page-down ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -2454,7 +2454,7 @@ m] press up-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen shows partial wrapped line screen-should-contain [ @@ -2469,7 +2469,7 @@ m] press up-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen shows partial wrapped line screen-should-contain [ @@ -2484,7 +2484,7 @@ m] press up-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen shows partial wrapped line screen-should-contain [ @@ -2503,11 +2503,11 @@ scenario editor-scrolls-up-past-wrapped-line-using-arrow-keys-3 [ assume-screen 10/width, 4/height # initialize editor with a long, wrapped line and more than a screen of # other lines - 1:address:shared:array:character <- new [abcdef + 1:address:array:character <- new [abcdef g h i] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 6/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 6/right screen-should-contain [ . . .abcde↩ . @@ -2519,7 +2519,7 @@ i] press page-down ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -2532,7 +2532,7 @@ i] press up-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen shows partial wrapped line screen-should-contain [ @@ -2547,18 +2547,18 @@ i] scenario editor-scrolls-up-past-wrapped-line-using-arrow-keys-4 [ assume-screen 10/width, 4/height # initialize editor with some lines around an empty line - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b c d e] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 6/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 6/right assume-console [ press page-down ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -2570,7 +2570,7 @@ e] press page-down ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -2582,7 +2582,7 @@ e] press page-up ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -2596,18 +2596,18 @@ scenario editor-scrolls-up-on-left-arrow [ # screen has 1 line for menu + 3 lines assume-screen 5/width, 4/height # editor contains >3 lines - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b c d e] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right # position cursor at top of second page assume-console [ press page-down ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -2620,9 +2620,9 @@ e] press left-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # screen scrolls screen-should-contain [ @@ -2641,11 +2641,11 @@ scenario editor-can-scroll-up-to-start-of-file [ # screen has 1 line for menu + 3 lines assume-screen 10/width, 4/height # initialize editor with >3 lines - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b c d] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right screen-should-contain [ . . .a . @@ -2660,7 +2660,7 @@ d] press up-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen slides by one line screen-should-contain [ @@ -2674,7 +2674,7 @@ d] press up-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen remains unchanged screen-should-contain [ @@ -2689,11 +2689,11 @@ d] scenario editor-can-scroll [ assume-screen 10/width, 4/height - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b c d] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right screen-should-contain [ . . .a . @@ -2705,7 +2705,7 @@ d] press page-down ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen shows next page screen-should-contain [ @@ -2720,12 +2720,12 @@ after <handle-special-character> [ { page-down?:boolean <- equal c, 6/ctrl-f break-unless page-down? - old-top:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + old-top:address:duplex-list:character <- get *editor, top-of-screen:offset <move-cursor-begin> page-down editor undo-coalesce-tag:number <- copy 0/never <move-cursor-end> - top-of-screen:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + top-of-screen:address:duplex-list:character <- get *editor, top-of-screen:offset no-movement?:boolean <- equal top-of-screen, old-top go-render? <- not no-movement? return @@ -2736,12 +2736,12 @@ after <handle-special-key> [ { page-down?:boolean <- equal k, 65518/page-down break-unless page-down? - old-top:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + old-top:address:duplex-list:character <- get *editor, top-of-screen:offset <move-cursor-begin> page-down editor undo-coalesce-tag:number <- copy 0/never <move-cursor-end> - top-of-screen:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + top-of-screen:address:duplex-list:character <- get *editor, top-of-screen:offset no-movement?:boolean <- equal top-of-screen, old-top go-render? <- not no-movement? return @@ -2750,15 +2750,15 @@ after <handle-special-key> [ # page-down skips entire wrapped lines, so it can't scroll past lines # taking up the entire screen -def page-down editor:address:shared:editor-data -> editor:address:shared:editor-data [ +def page-down editor:address:editor-data -> editor:address:editor-data [ local-scope load-ingredients # if editor contents don't overflow screen, do nothing - bottom-of-screen:address:shared:duplex-list:character <- get *editor, bottom-of-screen:offset + bottom-of-screen:address:duplex-list:character <- get *editor, bottom-of-screen:offset return-unless bottom-of-screen # if not, position cursor at final character - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset - before-cursor:address:shared:duplex-list:character <- prev bottom-of-screen + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset + before-cursor:address:duplex-list:character <- prev bottom-of-screen *editor <- put *editor, before-cursor:offset, before-cursor # keep one line in common with previous page { @@ -2776,10 +2776,10 @@ def page-down editor:address:shared:editor-data -> editor:address:shared:editor- scenario editor-does-not-scroll-past-end [ assume-screen 10/width, 4/height - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data screen-should-contain [ . . .a . @@ -2791,7 +2791,7 @@ b] press page-down ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen remains unmodified screen-should-contain [ @@ -2806,11 +2806,11 @@ scenario editor-starts-next-page-at-start-of-wrapped-line [ # screen has 1 line for menu + 3 lines for text assume-screen 10/width, 4/height # editor contains a long last line - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b cdefgh] # editor screen triggers wrap of last line - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 4/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 4/right # some part of last line is not displayed screen-should-contain [ . . @@ -2823,7 +2823,7 @@ cdefgh] press page-down ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen shows entire wrapped line screen-should-contain [ @@ -2839,9 +2839,9 @@ scenario editor-starts-next-page-at-start-of-wrapped-line-2 [ assume-screen 10/width, 4/height # editor contains a very long line that occupies last two lines of screen # and still has something left over - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a bcdefgh] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 4/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 4/right # some part of last line is not displayed screen-should-contain [ . . @@ -2854,7 +2854,7 @@ bcdefgh] press page-down ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen shows entire wrapped line screen-should-contain [ @@ -2869,11 +2869,11 @@ bcdefgh] scenario editor-can-scroll-up [ assume-screen 10/width, 4/height - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b c d] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right screen-should-contain [ . . .a . @@ -2885,7 +2885,7 @@ d] press page-down ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen shows next page screen-should-contain [ @@ -2899,7 +2899,7 @@ d] press page-up ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen shows original page again screen-should-contain [ @@ -2914,12 +2914,12 @@ after <handle-special-character> [ { page-up?:boolean <- equal c, 2/ctrl-b break-unless page-up? - old-top:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + old-top:address:duplex-list:character <- get *editor, top-of-screen:offset <move-cursor-begin> editor <- page-up editor, screen-height undo-coalesce-tag:number <- copy 0/never <move-cursor-end> - top-of-screen:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + top-of-screen:address:duplex-list:character <- get *editor, top-of-screen:offset no-movement?:boolean <- equal top-of-screen, old-top go-render? <- not no-movement? return @@ -2930,12 +2930,12 @@ after <handle-special-key> [ { page-up?:boolean <- equal k, 65519/page-up break-unless page-up? - old-top:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + old-top:address:duplex-list:character <- get *editor, top-of-screen:offset <move-cursor-begin> editor <- page-up editor, screen-height undo-coalesce-tag:number <- copy 0/never <move-cursor-end> - top-of-screen:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + top-of-screen:address:duplex-list:character <- get *editor, top-of-screen:offset no-movement?:boolean <- equal top-of-screen, old-top # don't bother re-rendering if nothing changed. todo: test this go-render? <- not no-movement? @@ -2943,16 +2943,16 @@ after <handle-special-key> [ } ] -def page-up editor:address:shared:editor-data, screen-height:number -> editor:address:shared:editor-data [ +def page-up editor:address:editor-data, screen-height:number -> editor:address:editor-data [ local-scope load-ingredients max:number <- subtract screen-height, 1/menu-bar, 1/overlapping-line count:number <- copy 0 - top-of-screen:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + top-of-screen:address:duplex-list:character <- get *editor, top-of-screen:offset { done?:boolean <- greater-or-equal count, max break-if done? - prev:address:shared:duplex-list:character <- before-previous-line top-of-screen, editor + prev:address:duplex-list:character <- before-previous-line top-of-screen, editor break-unless prev top-of-screen <- copy prev *editor <- put *editor, top-of-screen:offset, top-of-screen @@ -2965,7 +2965,7 @@ scenario editor-can-scroll-up-multiple-pages [ # screen has 1 line for menu + 3 lines assume-screen 10/width, 4/height # initialize editor with 8 lines - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b c d @@ -2973,7 +2973,7 @@ e f g h] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right screen-should-contain [ . . .a . @@ -2986,7 +2986,7 @@ h] press page-down ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen shows third page screen-should-contain [ @@ -3000,7 +3000,7 @@ h] press page-up ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen shows second page screen-should-contain [ @@ -3014,7 +3014,7 @@ h] press page-up ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen shows original page again screen-should-contain [ @@ -3029,7 +3029,7 @@ scenario editor-can-scroll-up-wrapped-lines [ # screen has 1 line for menu + 5 lines for text assume-screen 10/width, 6/height # editor contains a long line in the first page - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b cdefgh i @@ -3040,7 +3040,7 @@ m n o] # editor screen triggers wrap of last line - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 4/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 4/right # some part of last line is not displayed screen-should-contain [ . . @@ -3057,7 +3057,7 @@ o] press down-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen shows entire wrapped line screen-should-contain [ @@ -3073,7 +3073,7 @@ o] press page-up ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen resets screen-should-contain [ @@ -3091,9 +3091,9 @@ scenario editor-can-scroll-up-wrapped-lines-2 [ assume-screen 10/width, 4/height # editor contains a very long line that occupies last two lines of screen # and still has something left over - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a bcdefgh] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 4/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 4/right # some part of last line is not displayed screen-should-contain [ . . @@ -3106,7 +3106,7 @@ bcdefgh] press page-down ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen shows entire wrapped line screen-should-contain [ @@ -3120,7 +3120,7 @@ bcdefgh] press page-up ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen resets screen-should-contain [ @@ -3134,7 +3134,7 @@ bcdefgh] scenario editor-can-scroll-up-past-nonempty-lines [ assume-screen 10/width, 4/height # text with empty line in second screen - 1:address:shared:array:character <- new [axx + 1:address:array:character <- new [axx bxx cxx dxx @@ -3143,7 +3143,7 @@ fxx gxx hxx ] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 4/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 4/right screen-should-contain [ . . .axx . @@ -3154,7 +3154,7 @@ hxx press page-down ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -3166,7 +3166,7 @@ hxx press page-down ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -3179,7 +3179,7 @@ hxx press page-up ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -3192,7 +3192,7 @@ hxx scenario editor-can-scroll-up-past-empty-lines [ assume-screen 10/width, 4/height # text with empty line in second screen - 1:address:shared:array:character <- new [axy + 1:address:array:character <- new [axy bxy cxy @@ -3201,7 +3201,7 @@ exy fxy gxy ] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 4/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 4/right screen-should-contain [ . . .axy . @@ -3212,7 +3212,7 @@ gxy press page-down ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -3224,7 +3224,7 @@ gxy press page-down ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -3237,7 +3237,7 @@ gxy press page-up ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . diff --git a/edit/004-programming-environment.mu b/edit/004-programming-environment.mu index 3503f008..e7509bf7 100644 --- a/edit/004-programming-environment.mu +++ b/edit/004-programming-environment.mu @@ -6,22 +6,22 @@ def! main [ local-scope open-console - initial-recipe:address:shared:array:character <- restore [recipes.mu] - initial-sandbox:address:shared:array:character <- new [] + initial-recipe:address:array:character <- restore [recipes.mu] + initial-sandbox:address:array:character <- new [] hide-screen 0/screen - env:address:shared:programming-environment-data <- new-programming-environment 0/screen, initial-recipe, initial-sandbox + env:address:programming-environment-data <- new-programming-environment 0/screen, initial-recipe, initial-sandbox render-all 0/screen, env event-loop 0/screen, 0/console, env # never gets here ] container programming-environment-data [ - recipes:address:shared:editor-data - current-sandbox:address:shared:editor-data + recipes:address:editor-data + current-sandbox:address:editor-data sandbox-in-focus?:boolean # false => cursor in recipes; true => cursor in current-sandbox ] -def new-programming-environment screen:address:shared:screen, initial-recipe-contents:address:shared:array:character, initial-sandbox-contents:address:shared:array:character -> result:address:shared:programming-environment-data, screen:address:shared:screen [ +def new-programming-environment screen:address:screen, initial-recipe-contents:address:array:character, initial-sandbox-contents:address:array:character -> result:address:programming-environment-data, screen:address:screen [ local-scope load-ingredients width:number <- screen-width screen @@ -38,21 +38,21 @@ def new-programming-environment screen:address:shared:screen, initial-recipe-con divider:number, _ <- divide-with-remainder width, 2 draw-vertical screen, divider, 1/top, height, 9482/vertical-dotted # recipe editor on the left - recipes:address:shared:editor-data <- new-editor initial-recipe-contents, screen, 0/left, divider/right + recipes:address:editor-data <- new-editor initial-recipe-contents, screen, 0/left, divider/right # sandbox editor on the right sandbox-left:number <- add divider, 1 - current-sandbox:address:shared:editor-data <- new-editor initial-sandbox-contents, screen, sandbox-left, width/right + current-sandbox:address:editor-data <- new-editor initial-sandbox-contents, screen, sandbox-left, width/right *result <- put *result, recipes:offset, recipes *result <- put *result, current-sandbox:offset, current-sandbox *result <- put *result, sandbox-in-focus?:offset, 0/false <programming-environment-initialization> ] -def event-loop screen:address:shared:screen, console:address:shared:console, env:address:shared:programming-environment-data -> screen:address:shared:screen, console:address:shared:console, env:address:shared:programming-environment-data [ +def event-loop screen:address:screen, console:address:console, env:address:programming-environment-data -> screen:address:screen, console:address:console, env:address:programming-environment-data [ local-scope load-ingredients - recipes:address:shared:editor-data <- get *env, recipes:offset - current-sandbox:address:shared:editor-data <- get *env, current-sandbox:offset + recipes:address:editor-data <- get *env, recipes:offset + current-sandbox:address:editor-data <- get *env, current-sandbox:offset sandbox-in-focus?:boolean <- get *env, sandbox-in-focus?:offset # if we fall behind we'll stop updating the screen, but then we have to # render the entire screen when we catch up. @@ -182,21 +182,21 @@ def event-loop screen:address:shared:screen, console:address:shared:console, env } ] -def resize screen:address:shared:screen, env:address:shared:programming-environment-data -> env:address:shared:programming-environment-data, screen:address:shared:screen [ +def resize screen:address:screen, env:address:programming-environment-data -> env:address:programming-environment-data, screen:address:screen [ local-scope load-ingredients clear-screen screen # update screen dimensions width:number <- screen-width screen divider:number, _ <- divide-with-remainder width, 2 # update recipe editor - recipes:address:shared:editor-data <- get *env, recipes:offset + recipes:address:editor-data <- get *env, recipes:offset right:number <- subtract divider, 1 *recipes <- put *recipes, right:offset, right # reset cursor (later we'll try to preserve its position) *recipes <- put *recipes, cursor-row:offset, 1 *recipes <- put *recipes, cursor-column:offset, 0 # update sandbox editor - current-sandbox:address:shared:editor-data <- get *env, current-sandbox:offset + current-sandbox:address:editor-data <- get *env, current-sandbox:offset left:number <- add divider, 1 *current-sandbox <- put *current-sandbox, left:offset, left right:number <- subtract width, 1 @@ -210,9 +210,9 @@ scenario point-at-multiple-editors [ trace-until 100/app # trace too long assume-screen 30/width, 5/height # initialize both halves of screen - 1:address:shared:array:character <- new [abc] - 2:address:shared:array:character <- new [def] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character + 1:address:array:character <- new [abc] + 2:address:array:character <- new [def] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character # focus on both sides assume-console [ left-click 1, 1 @@ -220,11 +220,11 @@ scenario point-at-multiple-editors [ ] # check cursor column in each run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data - 4:address:shared:editor-data <- get *3:address:shared:programming-environment-data, recipes:offset - 5:number <- get *4:address:shared:editor-data, cursor-column:offset - 6:address:shared:editor-data <- get *3:address:shared:programming-environment-data, current-sandbox:offset - 7:number <- get *6:address:shared:editor-data, cursor-column:offset + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data + 4:address:editor-data <- get *3:address:programming-environment-data, recipes:offset + 5:number <- get *4:address:editor-data, cursor-column:offset + 6:address:editor-data <- get *3:address:programming-environment-data, current-sandbox:offset + 7:number <- get *6:address:editor-data, cursor-column:offset ] memory-should-contain [ 5 <- 1 @@ -236,10 +236,10 @@ scenario edit-multiple-editors [ trace-until 100/app # trace too long assume-screen 30/width, 5/height # initialize both halves of screen - 1:address:shared:array:character <- new [abc] - 2:address:shared:array:character <- new [def] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character - render-all screen, 3:address:shared:programming-environment-data + 1:address:array:character <- new [abc] + 2:address:array:character <- new [def] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character + render-all screen, 3:address:programming-environment-data # type one letter in each of them assume-console [ left-click 1, 1 @@ -248,11 +248,11 @@ scenario edit-multiple-editors [ type [1] ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data - 4:address:shared:editor-data <- get *3:address:shared:programming-environment-data, recipes:offset - 5:number <- get *4:address:shared:editor-data, cursor-column:offset - 6:address:shared:editor-data <- get *3:address:shared:programming-environment-data, current-sandbox:offset - 7:number <- get *6:address:shared:editor-data, cursor-column:offset + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data + 4:address:editor-data <- get *3:address:programming-environment-data, recipes:offset + 5:number <- get *4:address:editor-data, cursor-column:offset + 6:address:editor-data <- get *3:address:programming-environment-data, current-sandbox:offset + 7:number <- get *6:address:editor-data, cursor-column:offset ] screen-should-contain [ . run (F4) . # this line has a different background, but we don't test that yet @@ -267,7 +267,7 @@ scenario edit-multiple-editors [ # show the cursor at the right window run [ 8:character/cursor <- copy 9251/␣ - print screen:address:shared:screen, 8:character/cursor + print screen:address:screen, 8:character/cursor ] screen-should-contain [ . run (F4) . @@ -281,10 +281,10 @@ scenario multiple-editors-cover-only-their-own-areas [ trace-until 100/app # trace too long assume-screen 60/width, 10/height run [ - 1:address:shared:array:character <- new [abc] - 2:address:shared:array:character <- new [def] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character - render-all screen, 3:address:shared:programming-environment-data + 1:address:array:character <- new [abc] + 2:address:array:character <- new [def] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character + render-all screen, 3:address:programming-environment-data ] # divider isn't messed up screen-should-contain [ @@ -299,16 +299,16 @@ scenario multiple-editors-cover-only-their-own-areas [ scenario editor-in-focus-keeps-cursor [ trace-until 100/app # trace too long assume-screen 30/width, 5/height - 1:address:shared:array:character <- new [abc] - 2:address:shared:array:character <- new [def] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character - render-all screen, 3:address:shared:programming-environment-data + 1:address:array:character <- new [abc] + 2:address:array:character <- new [def] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character + render-all screen, 3:address:programming-environment-data # initialize programming environment and highlight cursor assume-console [] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data 4:character/cursor <- copy 9251/␣ - print screen:address:shared:screen, 4:character/cursor + print screen:address:screen, 4:character/cursor ] # is cursor at the right place? screen-should-contain [ @@ -322,9 +322,9 @@ scenario editor-in-focus-keeps-cursor [ type [z] ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data 4:character/cursor <- copy 9251/␣ - print screen:address:shared:screen, 4:character/cursor + print screen:address:screen, 4:character/cursor ] # cursor should still be right screen-should-contain [ @@ -339,11 +339,11 @@ scenario backspace-in-sandbox-editor-joins-lines [ trace-until 100/app # trace too long assume-screen 30/width, 5/height # initialize sandbox side with two lines - 1:address:shared:array:character <- new [] - 2:address:shared:array:character <- new [abc + 1:address:array:character <- new [] + 2:address:array:character <- new [abc def] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character - render-all screen, 3:address:shared:programming-environment-data + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character + render-all screen, 3:address:programming-environment-data screen-should-contain [ . run (F4) . . ┊abc . @@ -357,9 +357,9 @@ def] press backspace ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data 4:character/cursor <- copy 9251/␣ - print screen:address:shared:screen, 4:character/cursor + print screen:address:screen, 4:character/cursor ] # cursor moves to end of old line screen-should-contain [ @@ -370,7 +370,7 @@ def] ] ] -def render-all screen:address:shared:screen, env:address:shared:programming-environment-data -> screen:address:shared:screen, env:address:shared:programming-environment-data [ +def render-all screen:address:screen, env:address:programming-environment-data -> screen:address:screen, env:address:programming-environment-data [ local-scope load-ingredients trace 10, [app], [render all] @@ -394,19 +394,19 @@ def render-all screen:address:shared:screen, env:address:shared:programming-envi screen <- render-sandbox-side screen, env <render-components-end> # - recipes:address:shared:editor-data <- get *env, recipes:offset - current-sandbox:address:shared:editor-data <- get *env, current-sandbox:offset + recipes:address:editor-data <- get *env, recipes:offset + current-sandbox:address:editor-data <- get *env, current-sandbox:offset sandbox-in-focus?:boolean <- get *env, sandbox-in-focus?:offset screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env # show-screen screen ] -def render-recipes screen:address:shared:screen, env:address:shared:programming-environment-data -> screen:address:shared:screen, env:address:shared:programming-environment-data [ +def render-recipes screen:address:screen, env:address:programming-environment-data -> screen:address:screen, env:address:programming-environment-data [ local-scope load-ingredients trace 11, [app], [render recipes] - recipes:address:shared:editor-data <- get *env, recipes:offset + recipes:address:editor-data <- get *env, recipes:offset # render recipes left:number <- get *recipes, left:offset right:number <- get *recipes, right:offset @@ -421,10 +421,10 @@ def render-recipes screen:address:shared:screen, env:address:shared:programming- ] # replaced in a later layer -def render-sandbox-side screen:address:shared:screen, env:address:shared:programming-environment-data -> screen:address:shared:screen, env:address:shared:programming-environment-data [ +def render-sandbox-side screen:address:screen, env:address:programming-environment-data -> screen:address:screen, env:address:programming-environment-data [ local-scope load-ingredients - current-sandbox:address:shared:editor-data <- get *env, current-sandbox:offset + current-sandbox:address:editor-data <- get *env, current-sandbox:offset left:number <- get *current-sandbox, left:offset right:number <- get *current-sandbox, right:offset row:number, column:number, screen, current-sandbox <- render screen, current-sandbox @@ -436,7 +436,7 @@ def render-sandbox-side screen:address:shared:screen, env:address:shared:program clear-screen-from screen, row, left, left, right ] -def update-cursor screen:address:shared:screen, recipes:address:shared:editor-data, current-sandbox:address:shared:editor-data, sandbox-in-focus?:boolean, env:address:shared:programming-environment-data -> screen:address:shared:screen [ +def update-cursor screen:address:screen, recipes:address:editor-data, current-sandbox:address:editor-data, sandbox-in-focus?:boolean, env:address:programming-environment-data -> screen:address:screen [ local-scope load-ingredients <update-cursor-special-cases> @@ -455,7 +455,7 @@ def update-cursor screen:address:shared:screen, recipes:address:shared:editor-da # print a text 's' to 'editor' in 'color' starting at 'row' # clear rest of last line, move cursor to next line -def render screen:address:shared:screen, s:address:shared:array:character, left:number, right:number, color:number, row:number -> row:number, screen:address:shared:screen [ +def render screen:address:screen, s:address:array:character, left:number, right:number, color:number, row:number -> row:number, screen:address:screen [ local-scope load-ingredients return-unless s @@ -516,7 +516,7 @@ def render screen:address:shared:screen, s:address:shared:array:character, left: ] # like 'render' for texts, but with colorization for comments like in the editor -def render-code screen:address:shared:screen, s:address:shared:array:character, left:number, right:number, row:number -> row:number, screen:address:shared:screen [ +def render-code screen:address:screen, s:address:array:character, left:number, right:number, row:number -> row:number, screen:address:screen [ local-scope load-ingredients return-unless s @@ -584,7 +584,7 @@ after <global-type> [ { redraw-screen?:boolean <- equal c, 12/ctrl-l break-unless redraw-screen? - screen <- render-all screen, env:address:shared:programming-environment-data + screen <- render-all screen, env:address:programming-environment-data sync-screen screen loop +next-event:label } @@ -607,7 +607,7 @@ after <global-type> [ ## helpers -def draw-vertical screen:address:shared:screen, col:number, y:number, bottom:number -> screen:address:shared:screen [ +def draw-vertical screen:address:screen, col:number, y:number, bottom:number -> screen:address:screen [ local-scope load-ingredients style:character, style-found?:boolean <- next-ingredient diff --git a/edit/005-sandbox.mu b/edit/005-sandbox.mu index 89f52fb6..4d4b93ef 100644 --- a/edit/005-sandbox.mu +++ b/edit/005-sandbox.mu @@ -7,10 +7,10 @@ def! main [ local-scope open-console - initial-recipe:address:shared:array:character <- restore [recipes.mu] - initial-sandbox:address:shared:array:character <- new [] + initial-recipe:address:array:character <- restore [recipes.mu] + initial-sandbox:address:array:character <- new [] hide-screen 0/screen - env:address:shared:programming-environment-data <- new-programming-environment 0/screen, initial-recipe, initial-sandbox + env:address:programming-environment-data <- new-programming-environment 0/screen, initial-recipe, initial-sandbox env <- restore-sandboxes env render-all 0/screen, env event-loop 0/screen, 0/console, env @@ -18,7 +18,7 @@ def! main [ ] container programming-environment-data [ - sandbox:address:shared:sandbox-data # list of sandboxes, from top to bottom + sandbox:address:sandbox-data # list of sandboxes, from top to bottom render-from:number number-of-sandboxes:number ] @@ -28,30 +28,30 @@ after <programming-environment-initialization> [ ] container sandbox-data [ - data:address:shared:array:character - response:address:shared:array:character + data:address:array:character + response:address:array:character # coordinates to track clicks # constraint: will be 0 for sandboxes at positions before env.render-from starting-row-on-screen:number code-ending-row-on-screen:number # past end of code - screen:address:shared:screen # prints in the sandbox go here - next-sandbox:address:shared:sandbox-data + screen:address:screen # prints in the sandbox go here + next-sandbox:address:sandbox-data ] scenario run-and-show-results [ trace-until 100/app # trace too long assume-screen 100/width, 15/height # recipe editor is empty - 1:address:shared:array:character <- new [] + 1:address:array:character <- new [] # sandbox editor contains an instruction without storing outputs - 2:address:shared:array:character <- new [divide-with-remainder 11, 3] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character + 2:address:array:character <- new [divide-with-remainder 11, 3] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character # run the code in the editors assume-console [ press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] # check that screen prints the results screen-should-contain [ @@ -101,7 +101,7 @@ scenario run-and-show-results [ press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] # check that screen prints the results screen-should-contain [ @@ -139,23 +139,23 @@ after <global-keypress> [ } ] -def run-sandboxes env:address:shared:programming-environment-data, screen:address:shared:screen -> errors-found?:boolean, env:address:shared:programming-environment-data, screen:address:shared:screen [ +def run-sandboxes env:address:programming-environment-data, screen:address:screen -> errors-found?:boolean, env:address:programming-environment-data, screen:address:screen [ local-scope load-ingredients errors-found?:boolean, env, screen <- update-recipes env, screen return-if errors-found? # check contents of right editor (sandbox) <run-sandboxes-begin> - current-sandbox:address:shared:editor-data <- get *env, current-sandbox:offset + current-sandbox:address:editor-data <- get *env, current-sandbox:offset { - sandbox-contents:address:shared:array:character <- editor-contents current-sandbox + sandbox-contents:address:array:character <- editor-contents current-sandbox break-unless sandbox-contents # if contents exist, first save them # run them and turn them into a new sandbox-data - new-sandbox:address:shared:sandbox-data <- new sandbox-data:type + new-sandbox:address:sandbox-data <- new sandbox-data:type *new-sandbox <- put *new-sandbox, data:offset, sandbox-contents # push to head of sandbox list - dest:address:shared:sandbox-data <- get *env, sandbox:offset + dest:address:sandbox-data <- get *env, sandbox:offset *new-sandbox <- put *new-sandbox, next-sandbox:offset, dest *env <- put *env, sandbox:offset, new-sandbox # update sandbox count @@ -163,14 +163,14 @@ def run-sandboxes env:address:shared:programming-environment-data, screen:addres sandbox-count <- add sandbox-count, 1 *env <- put *env, number-of-sandboxes:offset, sandbox-count # clear sandbox editor - init:address:shared:duplex-list:character <- push 167/§, 0/tail + init:address:duplex-list:character <- push 167/§, 0/tail *current-sandbox <- put *current-sandbox, data:offset, init *current-sandbox <- put *current-sandbox, top-of-screen:offset, init } # save all sandboxes before running, just in case we die when running save-sandboxes env # run all sandboxes - curr:address:shared:sandbox-data <- get *env, sandbox:offset + curr:address:sandbox-data <- get *env, sandbox:offset idx:number <- copy 0 { break-unless curr @@ -184,45 +184,45 @@ def run-sandboxes env:address:shared:programming-environment-data, screen:addres # copy code from recipe editor, persist, load into mu # replaced in a later layer (whereupon errors-found? will actually be set) -def update-recipes env:address:shared:programming-environment-data, screen:address:shared:screen -> errors-found?:boolean, env:address:shared:programming-environment-data, screen:address:shared:screen [ +def update-recipes env:address:programming-environment-data, screen:address:screen -> errors-found?:boolean, env:address:programming-environment-data, screen:address:screen [ local-scope load-ingredients - recipes:address:shared:editor-data <- get *env, recipes:offset - in:address:shared:array:character <- editor-contents recipes + recipes:address:editor-data <- get *env, recipes:offset + in:address:array:character <- editor-contents recipes save [recipes.mu], in # newlayer: persistence reload in errors-found? <- copy 0/false ] # replaced in a later layer -def! update-sandbox sandbox:address:shared:sandbox-data, env:address:shared:programming-environment-data, idx:number -> sandbox:address:shared:sandbox-data, env:address:shared:programming-environment-data [ +def! update-sandbox sandbox:address:sandbox-data, env:address:programming-environment-data, idx:number -> sandbox:address:sandbox-data, env:address:programming-environment-data [ local-scope load-ingredients - data:address:shared:array:character <- get *sandbox, data:offset - response:address:shared:array:character, _, fake-screen:address:shared:screen <- run-interactive data + data:address:array:character <- get *sandbox, data:offset + response:address:array:character, _, fake-screen:address:screen <- run-interactive data *sandbox <- put *sandbox, response:offset, response *sandbox <- put *sandbox, screen:offset, fake-screen ] -def update-status screen:address:shared:screen, msg:address:shared:array:character, color:number -> screen:address:shared:screen [ +def update-status screen:address:screen, msg:address:array:character, color:number -> screen:address:screen [ local-scope load-ingredients screen <- move-cursor screen, 0, 2 screen <- print screen, msg, color, 238/grey/background ] -def save-sandboxes env:address:shared:programming-environment-data [ +def save-sandboxes env:address:programming-environment-data [ local-scope load-ingredients - current-sandbox:address:shared:editor-data <- get *env, current-sandbox:offset + current-sandbox:address:editor-data <- get *env, current-sandbox:offset # first clear previous versions, in case we deleted some sandbox $system [rm lesson/[0-9]* >/dev/null 2>/dev/null] # some shells can't handle '>&' - curr:address:shared:sandbox-data <- get *env, sandbox:offset + curr:address:sandbox-data <- get *env, sandbox:offset idx:number <- copy 0 { break-unless curr - data:address:shared:array:character <- get *curr, data:offset - filename:address:shared:array:character <- to-text idx + data:address:array:character <- get *curr, data:offset + filename:address:array:character <- to-text idx save filename, data <end-save-sandbox> idx <- add idx, 1 @@ -231,11 +231,11 @@ def save-sandboxes env:address:shared:programming-environment-data [ } ] -def! render-sandbox-side screen:address:shared:screen, env:address:shared:programming-environment-data -> screen:address:shared:screen, env:address:shared:programming-environment-data [ +def! render-sandbox-side screen:address:screen, env:address:programming-environment-data -> screen:address:screen, env:address:programming-environment-data [ local-scope load-ingredients trace 11, [app], [render sandbox side] - current-sandbox:address:shared:editor-data <- get *env, current-sandbox:offset + current-sandbox:address:editor-data <- get *env, current-sandbox:offset row:number, column:number <- copy 1, 0 left:number <- get *current-sandbox, left:offset right:number <- get *current-sandbox, right:offset @@ -250,12 +250,12 @@ def! render-sandbox-side screen:address:shared:screen, env:address:shared:progra } # render sandboxes draw-horizontal screen, row, left, right, 9473/horizontal-double - sandbox:address:shared:sandbox-data <- get *env, sandbox:offset + sandbox:address:sandbox-data <- get *env, sandbox:offset row, screen <- render-sandboxes screen, sandbox, left, right, row, render-from clear-rest-of-screen screen, row, left, right ] -def render-sandboxes screen:address:shared:screen, sandbox:address:shared:sandbox-data, left:number, right:number, row:number, render-from:number, idx:number -> row:number, screen:address:shared:screen, sandbox:address:shared:sandbox-data [ +def render-sandboxes screen:address:screen, sandbox:address:sandbox-data, left:number, right:number, row:number, render-from:number, idx:number -> row:number, screen:address:screen, sandbox:address:sandbox-data [ local-scope load-ingredients return-unless sandbox @@ -277,14 +277,14 @@ def render-sandboxes screen:address:shared:screen, sandbox:address:shared:sandbo # render sandbox contents row <- add row, 1 screen <- move-cursor screen, row, left - sandbox-data:address:shared:array:character <- get *sandbox, data:offset + sandbox-data:address:array:character <- get *sandbox, data:offset row, screen <- render-code screen, sandbox-data, left, right, row *sandbox <- put *sandbox, code-ending-row-on-screen:offset, row # render sandbox warnings, screen or response, in that order - sandbox-response:address:shared:array:character <- get *sandbox, response:offset + sandbox-response:address:array:character <- get *sandbox, response:offset <render-sandbox-results> { - sandbox-screen:address:shared:screen <- get *sandbox, screen:offset + sandbox-screen:address:screen <- get *sandbox, screen:offset empty-screen?:boolean <- fake-screen-is-empty? sandbox-screen break-if empty-screen? row, screen <- render-screen screen, sandbox-screen, left, right, row @@ -308,22 +308,22 @@ def render-sandboxes screen:address:shared:screen, sandbox:address:shared:sandbo <end-render-sandbox-reset-hidden> } # draw next sandbox - next-sandbox:address:shared:sandbox-data <- get *sandbox, next-sandbox:offset + next-sandbox:address:sandbox-data <- get *sandbox, next-sandbox:offset next-idx:number <- add idx, 1 row, screen <- render-sandboxes screen, next-sandbox, left, right, row, render-from, next-idx ] # assumes programming environment has no sandboxes; restores them from previous session -def restore-sandboxes env:address:shared:programming-environment-data -> env:address:shared:programming-environment-data [ +def restore-sandboxes env:address:programming-environment-data -> env:address:programming-environment-data [ local-scope load-ingredients # read all scenarios, pushing them to end of a list of scenarios idx:number <- copy 0 - curr:address:shared:sandbox-data <- copy 0 - prev:address:shared:sandbox-data <- copy 0 + curr:address:sandbox-data <- copy 0 + prev:address:sandbox-data <- copy 0 { - filename:address:shared:array:character <- to-text idx - contents:address:shared:array:character <- restore filename + filename:address:array:character <- to-text idx + contents:address:array:character <- restore filename break-unless contents # stop at first error; assuming file didn't exist # create new sandbox for file curr <- new sandbox-data:type @@ -351,7 +351,7 @@ def restore-sandboxes env:address:shared:programming-environment-data -> env:add # print the fake sandbox screen to 'screen' with appropriate delimiters # leave cursor at start of next line -def render-screen screen:address:shared:screen, sandbox-screen:address:shared:screen, left:number, right:number, row:number -> row:number, screen:address:shared:screen [ +def render-screen screen:address:screen, sandbox-screen:address:screen, left:number, right:number, row:number -> row:number, screen:address:screen [ local-scope load-ingredients return-unless sandbox-screen @@ -362,7 +362,7 @@ def render-screen screen:address:shared:screen, sandbox-screen:address:shared:sc column:number <- copy left s-width:number <- screen-width sandbox-screen s-height:number <- screen-height sandbox-screen - buf:address:shared:array:screen-cell <- get *sandbox-screen, data:offset + buf:address:array:screen-cell <- get *sandbox-screen, data:offset stop-printing:number <- add left, s-width, 3 max-column:number <- min stop-printing, right i:number <- copy 0 @@ -420,20 +420,20 @@ scenario run-updates-results [ trace-until 100/app # trace too long assume-screen 100/width, 12/height # define a recipe (no indent for the 'add' line below so column numbers are more obvious) - 1:address:shared:array:character <- new [ + 1:address:array:character <- new [ recipe foo [ local-scope z:number <- add 2, 2 reply z ]] # sandbox editor contains an instruction without storing outputs - 2:address:shared:array:character <- new [foo] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character + 2:address:array:character <- new [foo] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character # run the code in the editors assume-console [ press F4 ] - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data screen-should-contain [ . run (F4) . . ┊ . @@ -453,7 +453,7 @@ reply z press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] # check that screen updates the result on the right screen-should-contain [ @@ -473,16 +473,16 @@ scenario run-instruction-manages-screen-per-sandbox [ trace-until 100/app # trace too long assume-screen 100/width, 20/height # left editor is empty - 1:address:shared:array:character <- new [] + 1:address:array:character <- new [] # right editor contains an instruction - 2:address:shared:array:character <- new [print-integer screen, 4] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character + 2:address:array:character <- new [print-integer screen, 4] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character # run the code in the editor assume-console [ press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] # check that it prints a little toy screen screen-should-contain [ @@ -502,11 +502,11 @@ scenario run-instruction-manages-screen-per-sandbox [ ] ] -def editor-contents editor:address:shared:editor-data -> result:address:shared:array:character [ +def editor-contents editor:address:editor-data -> result:address:array:character [ local-scope load-ingredients - buf:address:shared:buffer <- new-buffer 80 - curr:address:shared:duplex-list:character <- get *editor, data:offset + buf:address:buffer <- new-buffer 80 + curr:address:duplex-list:character <- get *editor, data:offset # skip § sentinel assert curr, [editor without data is illegal; must have at least a sentinel] curr <- next curr @@ -523,16 +523,16 @@ def editor-contents editor:address:shared:editor-data -> result:address:shared:a scenario editor-provides-edited-contents [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 1:address:array:character <- new [abc] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right assume-console [ left-click 1, 2 type [def] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:address:shared:array:character <- editor-contents 2:address:shared:editor-data - 4:array:character <- copy *3:address:shared:array:character + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:address:array:character <- editor-contents 2:address:editor-data + 4:array:character <- copy *3:address:array:character ] memory-should-contain [ 4:array:character <- [abdefc] @@ -545,10 +545,10 @@ scenario scrolling-down-past-bottom-of-sandbox-editor [ trace-until 100/app # trace too long assume-screen 30/width, 10/height # initialize sandbox side - 1:address:shared:array:character <- new [] - 2:address:shared:array:character <- new [add 2, 2] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character - render-all screen, 3:address:shared:programming-environment-data + 1:address:array:character <- new [] + 2:address:array:character <- new [add 2, 2] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character + render-all screen, 3:address:programming-environment-data assume-console [ # create a sandbox press F4 @@ -558,9 +558,9 @@ scenario scrolling-down-past-bottom-of-sandbox-editor [ ] ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data 4:character/cursor <- copy 9251/␣ - print screen:address:shared:screen, 4:character/cursor + print screen:address:screen, 4:character/cursor ] screen-should-contain [ . . # minor: F4 clears menu tooltip in very narrow screens @@ -575,9 +575,9 @@ scenario scrolling-down-past-bottom-of-sandbox-editor [ press down-arrow ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data 4:character/cursor <- copy 9251/␣ - print screen:address:shared:screen, 4:character/cursor + print screen:address:screen, 4:character/cursor ] # sandbox editor hidden; first sandbox displayed # cursor moves to first sandbox @@ -595,9 +595,9 @@ scenario scrolling-down-past-bottom-of-sandbox-editor [ press up-arrow ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data 4:character/cursor <- copy 9251/␣ - print screen:address:shared:screen, 4:character/cursor + print screen:address:screen, 4:character/cursor ] # sandbox editor displays again screen-should-contain [ @@ -620,7 +620,7 @@ after <global-keypress> [ sandbox-cursor:number <- get *current-sandbox, cursor-row:offset sandbox-cursor-on-last-line?:boolean <- equal sandbox-bottom, sandbox-cursor break-unless sandbox-cursor-on-last-line? - sandbox:address:shared:sandbox-data <- get *env, sandbox:offset + sandbox:address:sandbox-data <- get *env, sandbox:offset break-unless sandbox # slide down if possible { @@ -672,12 +672,12 @@ after <global-keypress> [ # sandbox belonging to 'env' whose next-sandbox is 'in' # return 0 if there's no such sandbox, either because 'in' doesn't exist in 'env', or because it's the first sandbox -def previous-sandbox env:address:shared:programming-environment-data, in:address:shared:sandbox-data -> out:address:shared:sandbox-data [ +def previous-sandbox env:address:programming-environment-data, in:address:sandbox-data -> out:address:sandbox-data [ local-scope load-ingredients - curr:address:shared:sandbox-data <- get *env, sandbox:offset + curr:address:sandbox-data <- get *env, sandbox:offset return-unless curr, 0/nil - next:address:shared:sandbox-data <- get *curr, next-sandbox:offset + next:address:sandbox-data <- get *curr, next-sandbox:offset { return-unless next, 0/nil found?:boolean <- equal next, in @@ -693,24 +693,24 @@ scenario scrolling-down-on-recipe-side [ trace-until 100/app # trace too long assume-screen 30/width, 10/height # initialize sandbox side and create a sandbox - 1:address:shared:array:character <- new [ + 1:address:array:character <- new [ ] # create a sandbox - 2:address:shared:array:character <- new [add 2, 2] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character - render-all screen, 3:address:shared:programming-environment-data + 2:address:array:character <- new [add 2, 2] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character + render-all screen, 3:address:programming-environment-data assume-console [ press F4 ] - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data # hit 'down' in recipe editor assume-console [ press down-arrow ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data 4:character/cursor <- copy 9251/␣ - print screen:address:shared:screen, 4:character/cursor + print screen:address:screen, 4:character/cursor ] # cursor moves down on recipe side screen-should-contain [ @@ -729,10 +729,10 @@ scenario scrolling-through-multiple-sandboxes [ trace-until 100/app # trace too long assume-screen 30/width, 10/height # initialize environment - 1:address:shared:array:character <- new [] - 2:address:shared:array:character <- new [] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character - render-all screen, 3:address:shared:programming-environment-data + 1:address:array:character <- new [] + 2:address:array:character <- new [] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character + render-all screen, 3:address:programming-environment-data # create 2 sandboxes assume-console [ press ctrl-n @@ -741,9 +741,9 @@ scenario scrolling-through-multiple-sandboxes [ type [add 1, 1] press F4 ] - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data 4:character/cursor <- copy 9251/␣ - print screen:address:shared:screen, 4:character/cursor + print screen:address:screen, 4:character/cursor screen-should-contain [ . . . ┊␣ . @@ -761,9 +761,9 @@ scenario scrolling-through-multiple-sandboxes [ press down-arrow ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data 4:character/cursor <- copy 9251/␣ - print screen:address:shared:screen, 4:character/cursor + print screen:address:screen, 4:character/cursor ] # sandbox editor hidden; first sandbox displayed # cursor moves to first sandbox @@ -784,7 +784,7 @@ scenario scrolling-through-multiple-sandboxes [ press down-arrow ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] # just second sandbox displayed screen-should-contain [ @@ -802,7 +802,7 @@ scenario scrolling-through-multiple-sandboxes [ press down-arrow ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] # no change screen-should-contain [ @@ -820,7 +820,7 @@ scenario scrolling-through-multiple-sandboxes [ press up-arrow ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] # back to displaying both sandboxes without editor screen-should-contain [ @@ -840,9 +840,9 @@ scenario scrolling-through-multiple-sandboxes [ press up-arrow ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data 4:character/cursor <- copy 9251/␣ - print screen:address:shared:screen, 4:character/cursor + print screen:address:screen, 4:character/cursor ] # back to displaying both sandboxes as well as editor screen-should-contain [ @@ -862,7 +862,7 @@ scenario scrolling-through-multiple-sandboxes [ press up-arrow ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] # no change screen-should-contain [ @@ -883,17 +883,17 @@ scenario scrolling-manages-sandbox-index-correctly [ trace-until 100/app # trace too long assume-screen 30/width, 10/height # initialize environment - 1:address:shared:array:character <- new [] - 2:address:shared:array:character <- new [] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character - render-all screen, 3:address:shared:programming-environment-data + 1:address:array:character <- new [] + 2:address:array:character <- new [] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character + render-all screen, 3:address:programming-environment-data # create a sandbox assume-console [ press ctrl-n type [add 1, 1] press F4 ] - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data screen-should-contain [ . . . ┊ . @@ -909,7 +909,7 @@ scenario scrolling-manages-sandbox-index-correctly [ press down-arrow ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] # sandbox editor hidden; first sandbox displayed # cursor moves to first sandbox @@ -927,7 +927,7 @@ scenario scrolling-manages-sandbox-index-correctly [ press up-arrow ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] # back to displaying both sandboxes as well as editor screen-should-contain [ @@ -945,7 +945,7 @@ scenario scrolling-manages-sandbox-index-correctly [ press down-arrow ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] # sandbox editor hidden; first sandbox displayed # cursor moves to first sandbox diff --git a/edit/006-sandbox-edit.mu b/edit/006-sandbox-edit.mu index ebfac6ac..257aed22 100644 --- a/edit/006-sandbox-edit.mu +++ b/edit/006-sandbox-edit.mu @@ -4,17 +4,17 @@ scenario clicking-on-a-sandbox-moves-it-to-editor [ trace-until 100/app # trace too long assume-screen 40/width, 10/height # basic recipe - 1:address:shared:array:character <- new [ + 1:address:array:character <- new [ recipe foo [ reply 4 ]] # run it - 2:address:shared:array:character <- new [foo] + 2:address:array:character <- new [foo] assume-console [ press F4 ] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data screen-should-contain [ . run (F4) . . ┊ . @@ -30,7 +30,7 @@ recipe foo [ left-click 3, 30 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] # it pops back into editor screen-should-contain [ @@ -48,7 +48,7 @@ recipe foo [ type [0] ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] screen-should-contain [ . run (F4) . @@ -69,7 +69,7 @@ after <global-touch> [ click-column:number <- get t, column:offset on-sandbox-side?:boolean <- greater-or-equal click-column, sandbox-left-margin break-unless on-sandbox-side? - first-sandbox:address:shared:sandbox-data <- get *env, sandbox:offset + first-sandbox:address:sandbox-data <- get *env, sandbox:offset break-unless first-sandbox first-sandbox-begins:number <- get *first-sandbox, starting-row-on-screen:offset click-row:number <- get t, row:offset @@ -78,9 +78,9 @@ after <global-touch> [ empty-sandbox-editor?:boolean <- empty-editor? current-sandbox break-unless empty-sandbox-editor? # don't clobber existing contents # identify the sandbox to edit and remove it from the sandbox list - sandbox:address:shared:sandbox-data <- extract-sandbox env, click-row + sandbox:address:sandbox-data <- extract-sandbox env, click-row break-unless sandbox - text:address:shared:array:character <- get *sandbox, data:offset + text:address:array:character <- get *sandbox, data:offset current-sandbox <- insert-text current-sandbox, text *env <- put *env, render-from:offset, -1 hide-screen screen @@ -91,18 +91,18 @@ after <global-touch> [ } ] -def empty-editor? editor:address:shared:editor-data -> result:boolean [ +def empty-editor? editor:address:editor-data -> result:boolean [ local-scope load-ingredients - head:address:shared:duplex-list:character <- get *editor, data:offset - first:address:shared:duplex-list:character <- next head + head:address:duplex-list:character <- get *editor, data:offset + first:address:duplex-list:character <- next head result <- not first ] -def extract-sandbox env:address:shared:programming-environment-data, click-row:number -> result:address:shared:sandbox-data, env:address:shared:programming-environment-data [ +def extract-sandbox env:address:programming-environment-data, click-row:number -> result:address:sandbox-data, env:address:programming-environment-data [ local-scope load-ingredients - curr-sandbox:address:shared:sandbox-data <- get *env, sandbox:offset + curr-sandbox:address:sandbox-data <- get *env, sandbox:offset start:number <- get *curr-sandbox, starting-row-on-screen:offset in-editor?:boolean <- lesser-than click-row, start return-if in-editor?, 0 @@ -110,16 +110,16 @@ def extract-sandbox env:address:shared:programming-environment-data, click-row:n { # first sandbox? pop break-unless first-sandbox? - next-sandbox:address:shared:sandbox-data <- get *curr-sandbox, next-sandbox:offset + next-sandbox:address:sandbox-data <- get *curr-sandbox, next-sandbox:offset *env <- put *env, sandbox:offset, next-sandbox } { # not first sandbox? break-if first-sandbox? - prev-sandbox:address:shared:sandbox-data <- copy curr-sandbox + prev-sandbox:address:sandbox-data <- copy curr-sandbox curr-sandbox <- get *curr-sandbox, next-sandbox:offset { - next-sandbox:address:shared:sandbox-data <- get *curr-sandbox, next-sandbox:offset + next-sandbox:address:sandbox-data <- get *curr-sandbox, next-sandbox:offset break-unless next-sandbox # if click-row < sandbox.next-sandbox.starting-row-on-screen, break next-start:number <- get *next-sandbox, starting-row-on-screen:offset @@ -145,15 +145,15 @@ scenario sandbox-with-print-can-be-edited [ trace-until 100/app # trace too long assume-screen 100/width, 20/height # left editor is empty - 1:address:shared:array:character <- new [] + 1:address:array:character <- new [] # right editor contains an instruction - 2:address:shared:array:character <- new [print-integer screen, 4] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character + 2:address:array:character <- new [print-integer screen, 4] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character # run the sandbox assume-console [ press F4 ] - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data screen-should-contain [ . run (F4) . . ┊ . @@ -174,7 +174,7 @@ scenario sandbox-with-print-can-be-edited [ left-click 3, 70 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] screen-should-contain [ . run (F4) . @@ -189,10 +189,10 @@ scenario editing-sandbox-after-scrolling-resets-scroll [ trace-until 100/app # trace too long assume-screen 30/width, 10/height # initialize environment - 1:address:shared:array:character <- new [] - 2:address:shared:array:character <- new [] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character - render-all screen, 3:address:shared:programming-environment-data + 1:address:array:character <- new [] + 2:address:array:character <- new [] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character + render-all screen, 3:address:programming-environment-data # create 2 sandboxes and scroll to second assume-console [ press ctrl-n @@ -203,7 +203,7 @@ scenario editing-sandbox-after-scrolling-resets-scroll [ press down-arrow press down-arrow ] - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data screen-should-contain [ . . . ┊━━━━━━━━━━━━━━. @@ -218,7 +218,7 @@ scenario editing-sandbox-after-scrolling-resets-scroll [ left-click 2, 20 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] # second sandbox shows in editor; scroll resets to display first sandbox screen-should-contain [ @@ -237,10 +237,10 @@ scenario editing-sandbox-updates-sandbox-count [ trace-until 100/app # trace too long assume-screen 30/width, 10/height # initialize environment - 1:address:shared:array:character <- new [] - 2:address:shared:array:character <- new [] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character - render-all screen, 3:address:shared:programming-environment-data + 1:address:array:character <- new [] + 2:address:array:character <- new [] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character + render-all screen, 3:address:programming-environment-data # create 2 sandboxes assume-console [ press ctrl-n @@ -249,7 +249,7 @@ scenario editing-sandbox-updates-sandbox-count [ type [add 1, 1] press F4 ] - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data screen-should-contain [ . . . ┊ . @@ -266,7 +266,7 @@ scenario editing-sandbox-updates-sandbox-count [ press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] # no change in contents screen-should-contain [ @@ -286,7 +286,7 @@ scenario editing-sandbox-updates-sandbox-count [ press down-arrow ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] # screen should show just final sandbox screen-should-contain [ diff --git a/edit/007-sandbox-delete.mu b/edit/007-sandbox-delete.mu index aed22244..3df11a4a 100644 --- a/edit/007-sandbox-delete.mu +++ b/edit/007-sandbox-delete.mu @@ -3,9 +3,9 @@ scenario deleting-sandboxes [ trace-until 100/app # trace too long assume-screen 100/width, 15/height - 1:address:shared:array:character <- new [] - 2:address:shared:array:character <- new [] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character + 1:address:array:character <- new [] + 2:address:array:character <- new [] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character # run a few commands assume-console [ left-click 1, 80 @@ -14,7 +14,7 @@ scenario deleting-sandboxes [ type [add 2, 2] press F4 ] - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data screen-should-contain [ . run (F4) . . ┊ . @@ -35,7 +35,7 @@ scenario deleting-sandboxes [ left-click 7, 99 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] screen-should-contain [ . run (F4) . @@ -53,7 +53,7 @@ scenario deleting-sandboxes [ left-click 3, 99 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] screen-should-contain [ . run (F4) . @@ -77,29 +77,29 @@ after <global-touch> [ } ] -def delete-sandbox t:touch-event, env:address:shared:programming-environment-data -> was-delete?:boolean, env:address:shared:programming-environment-data [ +def delete-sandbox t:touch-event, env:address:programming-environment-data -> was-delete?:boolean, env:address:programming-environment-data [ local-scope load-ingredients click-column:number <- get t, column:offset - current-sandbox:address:shared:editor-data <- get *env, current-sandbox:offset + current-sandbox:address:editor-data <- get *env, current-sandbox:offset right:number <- get *current-sandbox, right:offset at-right?:boolean <- equal click-column, right return-unless at-right?, 0/false click-row:number <- get t, row:offset { - first:address:shared:sandbox-data <- get *env, sandbox:offset + first:address:sandbox-data <- get *env, sandbox:offset reply-unless first, 0/false target-row:number <- get *first, starting-row-on-screen:offset delete-first?:boolean <- equal target-row, click-row break-unless delete-first? - new-first:address:shared:sandbox-data <- get *first, next-sandbox:offset + new-first:address:sandbox-data <- get *first, next-sandbox:offset *env <- put *env, sandbox:offset, new-first env <- fixup-delete env, new-first return 1/true # force rerender } - prev:address:shared:sandbox-data <- get *env, sandbox:offset + prev:address:sandbox-data <- get *env, sandbox:offset assert prev, [failed to find any sandboxes!] - curr:address:shared:sandbox-data <- get *prev, next-sandbox:offset + curr:address:sandbox-data <- get *prev, next-sandbox:offset { break-unless curr # more sandboxes to check @@ -108,7 +108,7 @@ def delete-sandbox t:touch-event, env:address:shared:programming-environment-dat delete-curr?:boolean <- equal target-row, click-row break-unless delete-curr? # delete this sandbox - next:address:shared:sandbox-data <- get *curr, next-sandbox:offset + next:address:sandbox-data <- get *curr, next-sandbox:offset *prev <- put *prev, next-sandbox:offset, next env <- fixup-delete env, next return 1/true # force rerender @@ -120,7 +120,7 @@ def delete-sandbox t:touch-event, env:address:shared:programming-environment-dat return 0/false ] -def fixup-delete env:address:shared:programming-environment-data, next:address:shared:sandbox-data -> env:address:shared:programming-environment-data [ +def fixup-delete env:address:programming-environment-data, next:address:sandbox-data -> env:address:programming-environment-data [ local-scope load-ingredients # update sandbox count @@ -142,10 +142,10 @@ scenario deleting-sandbox-after-scroll [ trace-until 100/app # trace too long assume-screen 30/width, 10/height # initialize environment - 1:address:shared:array:character <- new [] - 2:address:shared:array:character <- new [] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character - render-all screen, 3:address:shared:programming-environment-data + 1:address:array:character <- new [] + 2:address:array:character <- new [] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character + render-all screen, 3:address:programming-environment-data # create 2 sandboxes and scroll to second assume-console [ press ctrl-n @@ -155,7 +155,7 @@ scenario deleting-sandbox-after-scroll [ press F4 press down-arrow ] - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data screen-should-contain [ . . . ┊━━━━━━━━━━━━━━. @@ -170,7 +170,7 @@ scenario deleting-sandbox-after-scroll [ left-click 6, 29 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] # second sandbox shows in editor; scroll resets to display first sandbox screen-should-contain [ @@ -188,10 +188,10 @@ scenario deleting-top-sandbox-after-scroll [ trace-until 100/app # trace too long assume-screen 30/width, 10/height # initialize environment - 1:address:shared:array:character <- new [] - 2:address:shared:array:character <- new [] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character - render-all screen, 3:address:shared:programming-environment-data + 1:address:array:character <- new [] + 2:address:array:character <- new [] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character + render-all screen, 3:address:programming-environment-data # create 2 sandboxes and scroll to second assume-console [ press ctrl-n @@ -201,7 +201,7 @@ scenario deleting-top-sandbox-after-scroll [ press F4 press down-arrow ] - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data screen-should-contain [ . . . ┊━━━━━━━━━━━━━━. @@ -216,7 +216,7 @@ scenario deleting-top-sandbox-after-scroll [ left-click 2, 29 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] # second sandbox shows in editor; scroll resets to display first sandbox screen-should-contain [ @@ -234,10 +234,10 @@ scenario deleting-final-sandbox-after-scroll [ trace-until 100/app # trace too long assume-screen 30/width, 10/height # initialize environment - 1:address:shared:array:character <- new [] - 2:address:shared:array:character <- new [] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character - render-all screen, 3:address:shared:programming-environment-data + 1:address:array:character <- new [] + 2:address:array:character <- new [] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character + render-all screen, 3:address:programming-environment-data # create 2 sandboxes and scroll to second assume-console [ press ctrl-n @@ -248,7 +248,7 @@ scenario deleting-final-sandbox-after-scroll [ press down-arrow press down-arrow ] - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data screen-should-contain [ . . . ┊━━━━━━━━━━━━━━. @@ -263,7 +263,7 @@ scenario deleting-final-sandbox-after-scroll [ left-click 2, 29 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] # implicitly scroll up to first sandbox screen-should-contain [ @@ -282,10 +282,10 @@ scenario deleting-updates-sandbox-count [ trace-until 100/app # trace too long assume-screen 30/width, 10/height # initialize environment - 1:address:shared:array:character <- new [] - 2:address:shared:array:character <- new [] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character - render-all screen, 3:address:shared:programming-environment-data + 1:address:array:character <- new [] + 2:address:array:character <- new [] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character + render-all screen, 3:address:programming-environment-data # create 2 sandboxes assume-console [ press ctrl-n @@ -294,7 +294,7 @@ scenario deleting-updates-sandbox-count [ type [add 1, 1] press F4 ] - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data screen-should-contain [ . . . ┊ . @@ -314,7 +314,7 @@ scenario deleting-updates-sandbox-count [ press down-arrow ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] # shouldn't go past last sandbox screen-should-contain [ diff --git a/edit/008-sandbox-test.mu b/edit/008-sandbox-test.mu index c35cf802..98d1bf57 100644 --- a/edit/008-sandbox-test.mu +++ b/edit/008-sandbox-test.mu @@ -4,17 +4,17 @@ scenario sandbox-click-on-result-toggles-color-to-green [ trace-until 100/app # trace too long assume-screen 40/width, 10/height # basic recipe - 1:address:shared:array:character <- new [ + 1:address:array:character <- new [ recipe foo [ reply 4 ]] # run it - 2:address:shared:array:character <- new [foo] + 2:address:array:character <- new [foo] assume-console [ press F4 ] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data screen-should-contain [ . run (F4) . . ┊ . @@ -30,7 +30,7 @@ recipe foo [ left-click 5, 21 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] # color toggles to green screen-should-contain-in-color 2/green, [ @@ -46,7 +46,7 @@ recipe foo [ # cursor should remain unmoved run [ 4:character/cursor <- copy 9251/␣ - print screen:address:shared:screen, 4:character/cursor + print screen:address:screen, 4:character/cursor ] screen-should-contain [ . run (F4) . @@ -67,7 +67,7 @@ recipe foo [ press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] # result turns red screen-should-contain-in-color 1/red, [ @@ -85,13 +85,13 @@ recipe foo [ # this requires tracking a couple more things container sandbox-data [ response-starting-row-on-screen:number - expected-response:address:shared:array:character + expected-response:address:array:character ] # include expected response when saving or restoring a sandbox before <end-save-sandbox> [ { - expected-response:address:shared:array:character <- get *curr, expected-response:offset + expected-response:address:array:character <- get *curr, expected-response:offset break-unless expected-response filename <- append filename, [.out] save filename, expected-response @@ -110,14 +110,14 @@ after <global-touch> [ click-column:number <- get t, column:offset on-sandbox-side?:boolean <- greater-or-equal click-column, sandbox-left-margin break-unless on-sandbox-side? - first-sandbox:address:shared:sandbox-data <- get *env, sandbox:offset + first-sandbox:address:sandbox-data <- get *env, sandbox:offset break-unless first-sandbox first-sandbox-begins:number <- get *first-sandbox, starting-row-on-screen:offset click-row:number <- get t, row:offset below-sandbox-editor?:boolean <- greater-or-equal click-row, first-sandbox-begins break-unless below-sandbox-editor? # identify the sandbox whose output is being clicked on - sandbox:address:shared:sandbox-data <- find-click-in-sandbox-output env, click-row + sandbox:address:sandbox-data <- find-click-in-sandbox-output env, click-row break-unless sandbox # toggle its expected-response, and save session sandbox <- toggle-expected-response sandbox @@ -131,17 +131,17 @@ after <global-touch> [ } ] -def find-click-in-sandbox-output env:address:shared:programming-environment-data, click-row:number -> sandbox:address:shared:sandbox-data [ +def find-click-in-sandbox-output env:address:programming-environment-data, click-row:number -> sandbox:address:sandbox-data [ local-scope load-ingredients # assert click-row >= sandbox.starting-row-on-screen - sandbox:address:shared:sandbox-data <- get *env, sandbox:offset + sandbox:address:sandbox-data <- get *env, sandbox:offset start:number <- get *sandbox, starting-row-on-screen:offset clicked-on-sandboxes?:boolean <- greater-or-equal click-row, start assert clicked-on-sandboxes?, [extract-sandbox called on click to sandbox editor] # while click-row < sandbox.next-sandbox.starting-row-on-screen { - next-sandbox:address:shared:sandbox-data <- get *sandbox, next-sandbox:offset + next-sandbox:address:sandbox-data <- get *sandbox, next-sandbox:offset break-unless next-sandbox next-start:number <- get *next-sandbox, starting-row-on-screen:offset found?:boolean <- lesser-than click-row, next-start @@ -157,10 +157,10 @@ def find-click-in-sandbox-output env:address:shared:programming-environment-data return sandbox ] -def toggle-expected-response sandbox:address:shared:sandbox-data -> sandbox:address:shared:sandbox-data [ +def toggle-expected-response sandbox:address:sandbox-data -> sandbox:address:sandbox-data [ local-scope load-ingredients - expected-response:address:shared:array:character <- get *sandbox, expected-response:offset + expected-response:address:array:character <- get *sandbox, expected-response:offset { # if expected-response is set, reset break-unless expected-response @@ -169,7 +169,7 @@ def toggle-expected-response sandbox:address:shared:sandbox-data -> sandbox:addr { # if not, set expected response to the current response break-if expected-response - response:address:shared:array:character <- get *sandbox, response:offset + response:address:array:character <- get *sandbox, response:offset *sandbox <- put *sandbox, expected-response:offset, response } ] @@ -179,7 +179,7 @@ after <render-sandbox-response> [ { break-unless sandbox-response *sandbox <- put *sandbox, response-starting-row-on-screen:offset, row - expected-response:address:shared:array:character <- get *sandbox, expected-response:offset + expected-response:address:array:character <- get *sandbox, expected-response:offset break-unless expected-response # fall-through to print in grey response-is-expected?:boolean <- equal expected-response, sandbox-response { diff --git a/edit/009-sandbox-trace.mu b/edit/009-sandbox-trace.mu index 71eb7cfb..bf6d9fb6 100644 --- a/edit/009-sandbox-trace.mu +++ b/edit/009-sandbox-trace.mu @@ -4,17 +4,17 @@ scenario sandbox-click-on-code-toggles-app-trace [ trace-until 100/app # trace too long assume-screen 40/width, 10/height # basic recipe - 1:address:shared:array:character <- new [ + 1:address:array:character <- new [ recipe foo [ stash [abc] ]] # run it - 2:address:shared:array:character <- new [foo] + 2:address:array:character <- new [foo] assume-console [ press F4 ] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data screen-should-contain [ . run (F4) . . ┊ . @@ -29,9 +29,9 @@ recipe foo [ left-click 4, 21 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data 4:character/cursor-icon <- copy 9251/␣ - print screen:address:shared:screen, 4:character/cursor-icon + print screen:address:screen, 4:character/cursor-icon ] # trace now printed and cursor shouldn't have budged screen-should-contain [ @@ -59,8 +59,8 @@ recipe foo [ left-click 4, 25 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data - print screen:address:shared:screen, 4:character/cursor-icon + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data + print screen:address:screen, 4:character/cursor-icon ] # trace hidden again screen-should-contain [ @@ -78,18 +78,18 @@ scenario sandbox-shows-app-trace-and-result [ trace-until 100/app # trace too long assume-screen 40/width, 10/height # basic recipe - 1:address:shared:array:character <- new [ + 1:address:array:character <- new [ recipe foo [ stash [abc] reply 4 ]] # run it - 2:address:shared:array:character <- new [foo] + 2:address:array:character <- new [foo] assume-console [ press F4 ] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data screen-should-contain [ . run (F4) . . ┊ . @@ -105,7 +105,7 @@ recipe foo [ left-click 4, 21 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] # trace now printed above result screen-should-contain [ @@ -122,16 +122,16 @@ recipe foo [ ] container sandbox-data [ - trace:address:shared:array:character + trace:address:array:character display-trace?:boolean ] # replaced in a later layer -def! update-sandbox sandbox:address:shared:sandbox-data, env:address:shared:programming-environment-data, idx:number -> sandbox:address:shared:sandbox-data, env:address:shared:programming-environment-data [ +def! update-sandbox sandbox:address:sandbox-data, env:address:programming-environment-data, idx:number -> sandbox:address:sandbox-data, env:address:programming-environment-data [ local-scope load-ingredients - data:address:shared:array:character <- get *sandbox, data:offset - response:address:shared:array:character, _, fake-screen:address:shared:screen, trace:address:shared:array:character <- run-interactive data + data:address:array:character <- get *sandbox, data:offset + response:address:array:character, _, fake-screen:address:screen, trace:address:array:character <- run-interactive data *sandbox <- put *sandbox, response:offset, response *sandbox <- put *sandbox, screen:offset, fake-screen *sandbox <- put *sandbox, trace:offset, trace @@ -145,14 +145,14 @@ after <global-touch> [ click-column:number <- get t, column:offset on-sandbox-side?:boolean <- greater-or-equal click-column, sandbox-left-margin break-unless on-sandbox-side? - first-sandbox:address:shared:sandbox-data <- get *env, sandbox:offset + first-sandbox:address:sandbox-data <- get *env, sandbox:offset break-unless first-sandbox first-sandbox-begins:number <- get *first-sandbox, starting-row-on-screen:offset click-row:number <- get t, row:offset below-sandbox-editor?:boolean <- greater-or-equal click-row, first-sandbox-begins break-unless below-sandbox-editor? # identify the sandbox whose code is being clicked on - sandbox:address:shared:sandbox-data <- find-click-in-sandbox-code env, click-row + sandbox:address:sandbox-data <- find-click-in-sandbox-code env, click-row break-unless sandbox # toggle its display-trace? property x:boolean <- get *sandbox, display-trace?:offset @@ -167,7 +167,7 @@ after <global-touch> [ } ] -def find-click-in-sandbox-code env:address:shared:programming-environment-data, click-row:number -> sandbox:address:shared:sandbox-data [ +def find-click-in-sandbox-code env:address:programming-environment-data, click-row:number -> sandbox:address:sandbox-data [ local-scope load-ingredients # assert click-row >= sandbox.starting-row-on-screen @@ -177,7 +177,7 @@ def find-click-in-sandbox-code env:address:shared:programming-environment-data, assert clicked-on-sandboxes?, [extract-sandbox called on click to sandbox editor] # while click-row < sandbox.next-sandbox.starting-row-on-screen { - next-sandbox:address:shared:sandbox-data <- get *sandbox, next-sandbox:offset + next-sandbox:address:sandbox-data <- get *sandbox, next-sandbox:offset break-unless next-sandbox next-start:number <- get *next-sandbox, starting-row-on-screen:offset found?:boolean <- lesser-than click-row, next-start @@ -203,7 +203,7 @@ after <render-sandbox-results> [ { display-trace?:boolean <- get *sandbox, display-trace?:offset break-unless display-trace? - sandbox-trace:address:shared:array:character <- get *sandbox, trace:offset + sandbox-trace:address:array:character <- get *sandbox, trace:offset break-unless sandbox-trace # nothing to print; move on row, screen <- render screen, sandbox-trace, left, right, 245/grey, row } diff --git a/edit/010-errors.mu b/edit/010-errors.mu index 494871e5..fcedc191 100644 --- a/edit/010-errors.mu +++ b/edit/010-errors.mu @@ -1,17 +1,17 @@ ## handling malformed programs container programming-environment-data [ - recipe-errors:address:shared:array:character + recipe-errors:address:array:character ] # copy code from recipe editor, persist, load into mu, save any errors -def! update-recipes env:address:shared:programming-environment-data, screen:address:shared:screen -> errors-found?:boolean, env:address:shared:programming-environment-data, screen:address:shared:screen [ +def! update-recipes env:address:programming-environment-data, screen:address:screen -> errors-found?:boolean, env:address:programming-environment-data, screen:address:screen [ local-scope load-ingredients - recipes:address:shared:editor-data <- get *env, recipes:offset - in:address:shared:array:character <- editor-contents recipes + recipes:address:editor-data <- get *env, recipes:offset + in:address:array:character <- editor-contents recipes save [recipes.mu], in - recipe-errors:address:shared:array:character <- reload in + recipe-errors:address:array:character <- reload in *env <- put *env, recipe-errors:offset, recipe-errors # if recipe editor has errors, stop { @@ -25,7 +25,7 @@ def! update-recipes env:address:shared:programming-environment-data, screen:addr before <render-components-end> [ trace 11, [app], [render status] - recipe-errors:address:shared:array:character <- get *env, recipe-errors:offset + recipe-errors:address:array:character <- get *env, recipe-errors:offset { break-unless recipe-errors update-status screen, [errors found ], 1/red @@ -34,7 +34,7 @@ before <render-components-end> [ before <render-recipe-components-end> [ { - recipe-errors:address:shared:array:character <- get *env, recipe-errors:offset + recipe-errors:address:array:character <- get *env, recipe-errors:offset break-unless recipe-errors row, screen <- render screen, recipe-errors, left, right, 1/red, row } @@ -67,21 +67,21 @@ before <render-components-end> [ error-index:number <- get *env, error-index:offset sandboxes-completed-successfully?:boolean <- equal error-index, -1 break-if sandboxes-completed-successfully? - error-index-text:address:shared:array:character <- to-text error-index - status:address:shared:array:character <- interpolate [errors found (_) ], error-index-text + error-index-text:address:array:character <- to-text error-index + status:address:array:character <- interpolate [errors found (_) ], error-index-text update-status screen, status, 1/red } ] container sandbox-data [ - errors:address:shared:array:character + errors:address:array:character ] -def! update-sandbox sandbox:address:shared:sandbox-data, env:address:shared:programming-environment-data, idx:number -> sandbox:address:shared:sandbox-data, env:address:shared:programming-environment-data [ +def! update-sandbox sandbox:address:sandbox-data, env:address:programming-environment-data, idx:number -> sandbox:address:sandbox-data, env:address:programming-environment-data [ local-scope load-ingredients - data:address:shared:array:character <- get *sandbox, data:offset - response:address:shared:array:character, errors:address:shared:array:character, fake-screen:address:shared:screen, trace:address:shared:array:character, completed?:boolean <- run-interactive data + data:address:array:character <- get *sandbox, data:offset + response:address:array:character, errors:address:array:character, fake-screen:address:screen, trace:address:array:character, completed?:boolean <- run-interactive data *sandbox <- put *sandbox, response:offset, response *sandbox <- put *sandbox, errors:offset, errors *sandbox <- put *sandbox, screen:offset, fake-screen @@ -105,7 +105,7 @@ def! update-sandbox sandbox:address:shared:sandbox-data, env:address:shared:prog # make sure we render any trace after <render-sandbox-trace-done> [ { - sandbox-errors:address:shared:array:character <- get *sandbox, errors:offset + sandbox-errors:address:array:character <- get *sandbox, errors:offset break-unless sandbox-errors *sandbox <- put *sandbox, response-starting-row-on-screen:offset, 0 # no response row, screen <- render screen, sandbox-errors, left, right, 1/red, row @@ -117,17 +117,17 @@ after <render-sandbox-trace-done> [ scenario run-shows-errors-in-get [ trace-until 100/app # trace too long assume-screen 100/width, 15/height - 1:address:shared:array:character <- new [ + 1:address:array:character <- new [ recipe foo [ get 123:number, foo:offset ]] - 2:address:shared:array:character <- new [foo] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character + 2:address:array:character <- new [foo] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character assume-console [ press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] screen-should-contain [ . errors found run (F4) . @@ -157,9 +157,9 @@ recipe foo [ scenario run-updates-status-with-first-erroneous-sandbox [ trace-until 100/app # trace too long assume-screen 100/width, 15/height - 1:address:shared:array:character <- new [] - 2:address:shared:array:character <- new [] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character + 1:address:array:character <- new [] + 2:address:array:character <- new [] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character assume-console [ left-click 3, 80 # create invalid sandbox 1 @@ -170,7 +170,7 @@ scenario run-updates-status-with-first-erroneous-sandbox [ press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] # status line shows that error is in first sandbox screen-should-contain [ @@ -181,9 +181,9 @@ scenario run-updates-status-with-first-erroneous-sandbox [ scenario run-updates-status-with-first-erroneous-sandbox-2 [ trace-until 100/app # trace too long assume-screen 100/width, 15/height - 1:address:shared:array:character <- new [] - 2:address:shared:array:character <- new [] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character + 1:address:array:character <- new [] + 2:address:array:character <- new [] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character assume-console [ left-click 3, 80 # create invalid sandbox 2 @@ -197,7 +197,7 @@ scenario run-updates-status-with-first-erroneous-sandbox-2 [ press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] # status line shows that error is in second sandbox screen-should-contain [ @@ -208,14 +208,14 @@ scenario run-updates-status-with-first-erroneous-sandbox-2 [ scenario run-hides-errors-from-past-sandboxes [ trace-until 100/app # trace too long assume-screen 100/width, 15/height - 1:address:shared:array:character <- new [] - 2:address:shared:array:character <- new [get foo, x:offset] # invalid - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character + 1:address:array:character <- new [] + 2:address:array:character <- new [get foo, x:offset] # invalid + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character assume-console [ press F4 # generate error ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] assume-console [ left-click 3, 80 @@ -224,7 +224,7 @@ scenario run-hides-errors-from-past-sandboxes [ press F4 # update sandbox ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] # error should disappear screen-should-contain [ @@ -243,18 +243,18 @@ scenario run-updates-errors-for-shape-shifting-recipes [ trace-until 100/app # trace too long assume-screen 100/width, 15/height # define a shape-shifting recipe with an error - 1:address:shared:array:character <- new [recipe foo x:_elem -> z:_elem [ + 1:address:array:character <- new [recipe foo x:_elem -> z:_elem [ local-scope load-ingredients y:address:number <- copy 0 z <- add x, y ]] - 2:address:shared:array:character <- new [foo 2] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character + 2:address:array:character <- new [foo 2] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character assume-console [ press F4 ] - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data screen-should-contain [ . errors found (0) run (F4) . .recipe foo x:_elem -> z:_elem [ ┊ . @@ -271,7 +271,7 @@ z <- add x, y press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] # error should remain unchanged screen-should-contain [ @@ -291,24 +291,24 @@ scenario run-avoids-spurious-errors-on-reloading-shape-shifting-recipes [ trace-until 100/app # trace too long assume-screen 100/width, 15/height # overload a well-known shape-shifting recipe - 1:address:shared:array:character <- new [recipe length l:address:shared:list:_elem -> n:number [ + 1:address:array:character <- new [recipe length l:address:list:_elem -> n:number [ ]] # call code that uses other variants of it, but not it itself - 2:address:shared:array:character <- new [x:address:shared:list:number <- copy 0 + 2:address:array:character <- new [x:address:list:number <- copy 0 to-text x] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character # run it once assume-console [ press F4 ] - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data # no errors anywhere on screen (can't check anything else, since to-text will return an address) screen-should-contain-in-color 1/red, [ . . . . . . . . - . <- . + . <- . . . . . . . @@ -325,7 +325,7 @@ to-text x] press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] # still no errors screen-should-contain-in-color 1/red, [ @@ -333,7 +333,7 @@ to-text x] . . . . . . - . <- . + . <- . . . . . . . @@ -350,17 +350,17 @@ to-text x] scenario run-shows-missing-type-errors [ trace-until 100/app # trace too long assume-screen 100/width, 15/height - 1:address:shared:array:character <- new [ + 1:address:array:character <- new [ recipe foo [ x <- copy 0 ]] - 2:address:shared:array:character <- new [foo] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character + 2:address:array:character <- new [foo] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character assume-console [ press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] screen-should-contain [ . errors found run (F4) . @@ -376,18 +376,18 @@ scenario run-shows-unbalanced-bracket-errors [ trace-until 100/app # trace too long assume-screen 100/width, 15/height # recipe is incomplete (unbalanced '[') - 1:address:shared:array:character <- new [ + 1:address:array:character <- new [ recipe foo « x <- copy 0 ] - replace 1:address:shared:array:character, 171/«, 91 # '[' - 2:address:shared:array:character <- new [foo] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character + replace 1:address:array:character, 171/«, 91 # '[' + 2:address:array:character <- new [foo] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character assume-console [ press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] screen-should-contain [ . errors found run (F4) . @@ -404,30 +404,30 @@ recipe foo « scenario run-shows-get-on-non-container-errors [ trace-until 100/app # trace too long assume-screen 100/width, 15/height - 1:address:shared:array:character <- new [ + 1:address:array:character <- new [ recipe foo [ local-scope - x:address:shared:point <- new point:type - get x:address:shared:point, 1:offset + x:address:point <- new point:type + get x:address:point, 1:offset ]] - 2:address:shared:array:character <- new [foo] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character + 2:address:array:character <- new [foo] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character assume-console [ press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] screen-should-contain [ . errors found run (F4) . . ┊foo . .recipe foo [ ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. . local-scope ┊ . - . x:address:shared:point <- new point:type ┊ . - . get x:address:shared:point, 1:offset ┊ . + . x:address:point <- new point:type ┊ . + . get x:address:point, 1:offset ┊ . .] ┊ . .foo: first ingredient of 'get' should be a contai↩┊ . - .ner, but got x:address:shared:point ┊ . + .ner, but got x:address:point ┊ . .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊ . . ┊ . ] @@ -436,20 +436,20 @@ recipe foo [ scenario run-shows-non-literal-get-argument-errors [ trace-until 100/app # trace too long assume-screen 100/width, 15/height - 1:address:shared:array:character <- new [ + 1:address:array:character <- new [ recipe foo [ local-scope x:number <- copy 0 - y:address:shared:point <- new point:type - get *y:address:shared:point, x:number + y:address:point <- new point:type + get *y:address:point, x:number ]] - 2:address:shared:array:character <- new [foo] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character + 2:address:array:character <- new [foo] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character assume-console [ press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] screen-should-contain [ . errors found run (F4) . @@ -457,8 +457,8 @@ recipe foo [ .recipe foo [ ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. . local-scope ┊ . . x:number <- copy 0 ┊ . - . y:address:shared:point <- new point:type ┊ . - . get *y:address:shared:point, x:number ┊ . + . y:address:point <- new point:type ┊ . + . get *y:address:point, x:number ┊ . .] ┊ . .foo: second ingredient of 'get' should have type ↩┊ . .'offset', but got x:number ┊ . @@ -471,17 +471,17 @@ scenario run-shows-errors-everytime [ trace-until 100/app # trace too long # try to run a file with an error assume-screen 100/width, 15/height - 1:address:shared:array:character <- new [ + 1:address:array:character <- new [ recipe foo [ local-scope x:number <- copy y:number ]] - 2:address:shared:array:character <- new [foo] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character + 2:address:array:character <- new [foo] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character assume-console [ press F4 ] - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data screen-should-contain [ . errors found run (F4) . . ┊foo . @@ -498,7 +498,7 @@ recipe foo [ press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] screen-should-contain [ . errors found run (F4) . @@ -517,16 +517,16 @@ scenario run-instruction-and-print-errors [ trace-until 100/app # trace too long assume-screen 100/width, 10/height # left editor is empty - 1:address:shared:array:character <- new [] + 1:address:array:character <- new [] # right editor contains an illegal instruction - 2:address:shared:array:character <- new [get 1234:number, foo:offset] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character + 2:address:array:character <- new [get 1234:number, foo:offset] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character # run the code in the editors assume-console [ press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] # check that screen prints error message in red screen-should-contain [ @@ -580,17 +580,17 @@ scenario run-instruction-and-print-errors-only-once [ trace-until 100/app # trace too long assume-screen 100/width, 10/height # left editor is empty - 1:address:shared:array:character <- new [] + 1:address:array:character <- new [] # right editor contains an illegal instruction - 2:address:shared:array:character <- new [get 1234:number, foo:offset] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character + 2:address:array:character <- new [get 1234:number, foo:offset] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character # run the code in the editors multiple times assume-console [ press F4 press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] # check that screen prints error message just once screen-should-contain [ @@ -611,20 +611,20 @@ scenario sandbox-can-handle-infinite-loop [ trace-until 100/app # trace too long assume-screen 100/width, 20/height # left editor is empty - 1:address:shared:array:character <- new [recipe foo [ + 1:address:array:character <- new [recipe foo [ { loop } ]] # right editor contains an instruction - 2:address:shared:array:character <- new [foo] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character + 2:address:array:character <- new [foo] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character # run the sandbox assume-console [ press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] screen-should-contain [ . errors found (0) run (F4) . @@ -642,7 +642,7 @@ scenario sandbox-with-errors-shows-trace [ trace-until 100/app # trace too long assume-screen 100/width, 10/height # generate a stash and a error - 1:address:shared:array:character <- new [recipe foo [ + 1:address:array:character <- new [recipe foo [ local-scope a:number <- next-ingredient b:number <- next-ingredient @@ -650,13 +650,13 @@ stash [dividing by], b _, c:number <- divide-with-remainder a, b reply b ]] - 2:address:shared:array:character <- new [foo 4, 0] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character + 2:address:array:character <- new [foo 4, 0] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character # run assume-console [ press F4 ] - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data # screen prints error message screen-should-contain [ . errors found (0) run (F4) . @@ -674,7 +674,7 @@ reply b left-click 4, 55 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] # screen should expand trace screen-should-contain [ diff --git a/edit/011-editor-undo.mu b/edit/011-editor-undo.mu index 94135346..5c9876d0 100644 --- a/edit/011-editor-undo.mu +++ b/edit/011-editor-undo.mu @@ -11,13 +11,13 @@ exclusive-container operation [ container insert-operation [ before-row:number before-column:number - before-top-of-screen:address:shared:duplex-list:character + before-top-of-screen:address:duplex-list:character after-row:number after-column:number - after-top-of-screen:address:shared:duplex-list:character + after-top-of-screen:address:duplex-list:character # inserted text is from 'insert-from' until 'insert-until'; list doesn't have to terminate - insert-from:address:shared:duplex-list:character - insert-until:address:shared:duplex-list:character + insert-from:address:duplex-list:character + insert-until:address:duplex-list:character tag:number # event causing this operation; might be used to coalesce runs of similar events # 0: no coalesce (enter+indent) # 1: regular alphanumeric characters @@ -26,10 +26,10 @@ container insert-operation [ container move-operation [ before-row:number before-column:number - before-top-of-screen:address:shared:duplex-list:character + before-top-of-screen:address:duplex-list:character after-row:number after-column:number - after-top-of-screen:address:shared:duplex-list:character + after-top-of-screen:address:duplex-list:character tag:number # event causing this operation; might be used to coalesce runs of similar events # 0: no coalesce (touch events, etc) # 1: left arrow @@ -41,13 +41,13 @@ container move-operation [ container delete-operation [ before-row:number before-column:number - before-top-of-screen:address:shared:duplex-list:character + before-top-of-screen:address:duplex-list:character after-row:number after-column:number - after-top-of-screen:address:shared:duplex-list:character - deleted-text:address:shared:duplex-list:character - delete-from:address:shared:duplex-list:character - delete-until:address:shared:duplex-list:character + after-top-of-screen:address:duplex-list:character + deleted-text:address:duplex-list:character + delete-from:address:duplex-list:character + delete-until:address:duplex-list:character tag:number # event causing this operation; might be used to coalesce runs of similar events # 0: no coalesce (ctrl-k, ctrl-u) # 1: backspace @@ -56,8 +56,8 @@ container delete-operation [ # every editor accumulates a list of operations to undo/redo container editor-data [ - undo:address:shared:list:address:shared:operation - redo:address:shared:list:address:shared:operation + undo:address:list:address:operation + redo:address:list:address:operation ] # ctrl-z - undo operation @@ -65,12 +65,12 @@ after <handle-special-character> [ { undo?:boolean <- equal c, 26/ctrl-z break-unless undo? - undo:address:shared:list:address:shared:operation <- get *editor, undo:offset + undo:address:list:address:operation <- get *editor, undo:offset break-unless undo - op:address:shared:operation <- first undo + op:address:operation <- first undo undo <- rest undo *editor <- put *editor, undo:offset, undo - redo:address:shared:list:address:shared:operation <- get *editor, redo:offset + redo:address:list:address:operation <- get *editor, redo:offset redo <- push op, redo *editor <- put *editor, redo:offset, redo <handle-undo> @@ -83,12 +83,12 @@ after <handle-special-character> [ { redo?:boolean <- equal c, 25/ctrl-y break-unless redo? - redo:address:shared:list:address:shared:operation <- get *editor, redo:offset + redo:address:list:address:operation <- get *editor, redo:offset break-unless redo - op:address:shared:operation <- first redo + op:address:operation <- first redo redo <- rest redo *editor <- put *editor, redo:offset, redo - undo:address:shared:list:address:shared:operation <- get *editor, undo:offset + undo:address:list:address:operation <- get *editor, undo:offset undo <- push op, undo *editor <- put *editor, undo:offset, undo <handle-redo> @@ -101,19 +101,19 @@ after <handle-special-character> [ scenario editor-can-undo-typing [ # create an editor and type a character assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data assume-console [ type [0] ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data # undo assume-console [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # character should be gone screen-should-contain [ @@ -127,7 +127,7 @@ scenario editor-can-undo-typing [ type [1] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -139,24 +139,24 @@ scenario editor-can-undo-typing [ # save operation to undo after <insert-character-begin> [ - top-before:address:shared:duplex-list:character <- get *editor, top-of-screen:offset - cursor-before:address:shared:duplex-list:character <- get *editor, before-cursor:offset + top-before:address:duplex-list:character <- get *editor, top-of-screen:offset + cursor-before:address:duplex-list:character <- get *editor, before-cursor:offset ] before <insert-character-end> [ - top-after:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + top-after:address:duplex-list:character <- get *editor, top-of-screen:offset cursor-row:number <- get *editor, cursor-row:offset cursor-column:number <- get *editor, cursor-column:offset - undo:address:shared:list:address:shared:operation <- get *editor, undo:offset + undo:address:list:address:operation <- get *editor, undo:offset { # if previous operation was an insert, coalesce this operation with it break-unless undo - op:address:shared:operation <- first undo + op:address:operation <- first undo typing:insert-operation, is-insert?:boolean <- maybe-convert *op, typing:variant break-unless is-insert? previous-coalesce-tag:number <- get typing, tag:offset break-unless previous-coalesce-tag - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset - insert-until:address:shared:duplex-list:character <- next before-cursor + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset + insert-until:address:duplex-list:character <- next before-cursor typing <- put typing, insert-until:offset, insert-until typing <- put typing, after-row:offset, cursor-row typing <- put typing, after-column:offset, cursor-column @@ -165,9 +165,9 @@ before <insert-character-end> [ break +done-adding-insert-operation:label } # if not, create a new operation - insert-from:address:shared:duplex-list:character <- next cursor-before - insert-to:address:shared:duplex-list:character <- next insert-from - op:address:shared:operation <- new operation:type + insert-from:address:duplex-list:character <- next cursor-before + insert-to:address:duplex-list:character <- next insert-from + op:address:operation <- new operation:type *op <- merge 0/insert-operation, save-row/before, save-column/before, top-before, cursor-row/after, cursor-column/after, top-after, insert-from, insert-to, 1/coalesce editor <- add-operation editor, op +done-adding-insert-operation @@ -177,18 +177,18 @@ before <insert-character-end> [ after <insert-enter-begin> [ cursor-row-before:number <- copy cursor-row cursor-column-before:number <- copy cursor-column - top-before:address:shared:duplex-list:character <- get *editor, top-of-screen:offset - cursor-before:address:shared:duplex-list:character <- get *editor, before-cursor:offset + top-before:address:duplex-list:character <- get *editor, top-of-screen:offset + cursor-before:address:duplex-list:character <- get *editor, before-cursor:offset ] before <insert-enter-end> [ - top-after:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + top-after:address:duplex-list:character <- get *editor, top-of-screen:offset cursor-row:number <- get *editor, cursor-row:offset cursor-column:number <- get *editor, cursor-row:offset # never coalesce - insert-from:address:shared:duplex-list:character <- next cursor-before - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset - insert-to:address:shared:duplex-list:character <- next before-cursor - op:address:shared:operation <- new operation:type + insert-from:address:duplex-list:character <- next cursor-before + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset + insert-to:address:duplex-list:character <- next before-cursor + op:address:operation <- new operation:type *op <- merge 0/insert-operation, cursor-row-before, cursor-column-before, top-before, cursor-row/after, cursor-column/after, top-after, insert-from, insert-to, 0/never-coalesce editor <- add-operation editor, op ] @@ -197,13 +197,13 @@ before <insert-enter-end> [ # redo stack, because it's now obsolete. # Beware: since we're counting cursor moves as operations, this means just # moving the cursor can lose work on the undo stack. -def add-operation editor:address:shared:editor-data, op:address:shared:operation -> editor:address:shared:editor-data [ +def add-operation editor:address:editor-data, op:address:operation -> editor:address:editor-data [ local-scope load-ingredients - undo:address:shared:list:address:shared:operation <- get *editor, undo:offset + undo:address:list:address:operation <- get *editor, undo:offset undo <- push op undo *editor <- put *editor, undo:offset, undo - redo:address:shared:list:address:shared:operation <- get *editor, redo:offset + redo:address:list:address:operation <- get *editor, redo:offset redo <- copy 0 *editor <- put *editor, redo:offset, redo return editor/same-as-ingredient:0 @@ -213,17 +213,17 @@ after <handle-undo> [ { typing:insert-operation, is-insert?:boolean <- maybe-convert *op, typing:variant break-unless is-insert? - start:address:shared:duplex-list:character <- get typing, insert-from:offset - end:address:shared:duplex-list:character <- get typing, insert-until:offset + start:address:duplex-list:character <- get typing, insert-from:offset + end:address:duplex-list:character <- get typing, insert-until:offset # assert cursor-row/cursor-column/top-of-screen match after-row/after-column/after-top-of-screen - before-cursor:address:shared:duplex-list:character <- prev start + before-cursor:address:duplex-list:character <- prev start *editor <- put *editor, before-cursor:offset, before-cursor remove-between before-cursor, end cursor-row <- get typing, before-row:offset *editor <- put *editor, cursor-row:offset, cursor-row cursor-column <- get typing, before-column:offset *editor <- put *editor, cursor-column:offset, cursor-column - top:address:shared:duplex-list:character <- get typing, before-top-of-screen:offset + top:address:duplex-list:character <- get typing, before-top-of-screen:offset *editor <- put *editor, top-of-screen:offset, top } ] @@ -231,19 +231,19 @@ after <handle-undo> [ scenario editor-can-undo-typing-multiple [ # create an editor and type multiple characters assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data assume-console [ type [012] ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data # undo assume-console [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # all characters must be gone screen-should-contain [ @@ -257,14 +257,14 @@ scenario editor-can-undo-typing-multiple [ scenario editor-can-undo-typing-multiple-2 [ # create an editor with some text assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [a] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [a] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # type some characters assume-console [ type [012] ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data screen-should-contain [ . . .012a . @@ -276,7 +276,7 @@ scenario editor-can-undo-typing-multiple-2 [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # back to original text screen-should-contain [ @@ -290,7 +290,7 @@ scenario editor-can-undo-typing-multiple-2 [ type [3] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -303,15 +303,15 @@ scenario editor-can-undo-typing-multiple-2 [ scenario editor-can-undo-typing-enter [ # create an editor with some text assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [ abc] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [ abc] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # new line assume-console [ left-click 1, 8 press enter ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data screen-should-contain [ . . . abc . @@ -320,8 +320,8 @@ scenario editor-can-undo-typing-enter [ . . ] # line is indented - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 2 4 <- 2 @@ -331,10 +331,10 @@ scenario editor-can-undo-typing-enter [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 5 @@ -351,7 +351,7 @@ scenario editor-can-undo-typing-enter [ type [1] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -366,14 +366,14 @@ scenario editor-can-undo-typing-enter [ scenario editor-redo-typing [ # create an editor, type something, undo assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [a] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [a] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data assume-console [ type [012] press ctrl-z ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data screen-should-contain [ . . .a . @@ -385,7 +385,7 @@ scenario editor-redo-typing [ press ctrl-y ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # all characters must be back screen-should-contain [ @@ -399,7 +399,7 @@ scenario editor-redo-typing [ type [3] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -414,7 +414,7 @@ after <handle-redo> [ typing:insert-operation, is-insert?:boolean <- maybe-convert *op, typing:variant break-unless is-insert? before-cursor <- get *editor, before-cursor:offset - insert-from:address:shared:duplex-list:character <- get typing, insert-from:offset # ignore insert-to because it's already been spliced away + insert-from:address:duplex-list:character <- get typing, insert-from:offset # ignore insert-to because it's already been spliced away # assert insert-to matches next(before-cursor) insert-range before-cursor, insert-from # assert cursor-row/cursor-column/top-of-screen match after-row/after-column/after-top-of-screen @@ -422,7 +422,7 @@ after <handle-redo> [ *editor <- put *editor, cursor-row:offset, cursor-row cursor-column <- get typing, after-column:offset *editor <- put *editor, cursor-column:offset, cursor-column - top:address:shared:duplex-list:character <- get typing, after-top-of-screen:offset + top:address:duplex-list:character <- get typing, after-top-of-screen:offset *editor <- put *editor, top-of-screen:offset, top } ] @@ -430,14 +430,14 @@ after <handle-redo> [ scenario editor-redo-typing-empty [ # create an editor, type something, undo assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data assume-console [ type [012] press ctrl-z ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data screen-should-contain [ . . . . @@ -449,7 +449,7 @@ scenario editor-redo-typing-empty [ press ctrl-y ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # all characters must be back screen-should-contain [ @@ -463,7 +463,7 @@ scenario editor-redo-typing-empty [ type [3] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -476,21 +476,21 @@ scenario editor-redo-typing-empty [ scenario editor-work-clears-redo-stack [ # create an editor with some text, do some work, undo assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def ghi] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data assume-console [ type [1] press ctrl-z ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data # do some more work assume-console [ type [0] ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data screen-should-contain [ . . .0abc . @@ -503,7 +503,7 @@ ghi] press ctrl-y ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # nothing should happen screen-should-contain [ @@ -518,9 +518,9 @@ ghi] scenario editor-can-redo-typing-and-enter-and-tab [ # create an editor assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # insert some text and tabs, hit enter, some more text and tabs assume-console [ press tab @@ -531,7 +531,7 @@ scenario editor-can-redo-typing-and-enter-and-tab [ press tab type [efg] ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data screen-should-contain [ . . . ab cd . @@ -539,8 +539,8 @@ scenario editor-can-redo-typing-and-enter-and-tab [ .┈┈┈┈┈┈┈┈┈┈. . . ] - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 2 4 <- 7 @@ -550,11 +550,11 @@ scenario editor-can-redo-typing-and-enter-and-tab [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # typing in second line deleted, but not indent - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 2 4 <- 2 @@ -571,11 +571,11 @@ scenario editor-can-redo-typing-and-enter-and-tab [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # indent and newline deleted - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 8 @@ -591,11 +591,11 @@ scenario editor-can-redo-typing-and-enter-and-tab [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # empty screen - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 0 @@ -611,11 +611,11 @@ scenario editor-can-redo-typing-and-enter-and-tab [ press ctrl-y ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # first line inserted - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 8 @@ -631,11 +631,11 @@ scenario editor-can-redo-typing-and-enter-and-tab [ press ctrl-y ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # newline and indent inserted - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 2 4 <- 2 @@ -652,11 +652,11 @@ scenario editor-can-redo-typing-and-enter-and-tab [ press ctrl-y ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # indent and newline deleted - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 2 4 <- 7 @@ -675,24 +675,24 @@ scenario editor-can-redo-typing-and-enter-and-tab [ scenario editor-can-undo-touch [ # create an editor with some text assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def ghi] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # move the cursor assume-console [ left-click 3, 1 ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data # undo assume-console [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # click undone memory-should-contain [ @@ -704,7 +704,7 @@ ghi] type [1] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -718,19 +718,19 @@ ghi] after <move-cursor-begin> [ cursor-row-before:number <- get *editor, cursor-row:offset cursor-column-before:number <- get *editor, cursor-column:offset - top-before:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + top-before:address:duplex-list:character <- get *editor, top-of-screen:offset ] before <move-cursor-end> [ - top-after:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + top-after:address:duplex-list:character <- get *editor, top-of-screen:offset cursor-row:number <- get *editor, cursor-row:offset cursor-column:number <- get *editor, cursor-column:offset { break-unless undo-coalesce-tag # if previous operation was also a move, and also had the same coalesce # tag, coalesce with it - undo:address:shared:list:address:shared:operation <- get *editor, undo:offset + undo:address:list:address:operation <- get *editor, undo:offset break-unless undo - op:address:shared:operation <- first undo + op:address:operation <- first undo move:move-operation, is-move?:boolean <- maybe-convert *op, move:variant break-unless is-move? previous-coalesce-tag:number <- get move, tag:offset @@ -742,7 +742,7 @@ before <move-cursor-end> [ *op <- merge 1/move-operation, move break +done-adding-move-operation:label } - op:address:shared:operation <- new operation:type + op:address:operation <- new operation:type *op <- merge 1/move-operation, cursor-row-before, cursor-column-before, top-before, cursor-row/after, cursor-column/after, top-after, undo-coalesce-tag editor <- add-operation editor, op +done-adding-move-operation @@ -757,7 +757,7 @@ after <handle-undo> [ *editor <- put *editor, cursor-row:offset, cursor-row cursor-column <- get move, before-column:offset *editor <- put *editor, cursor-column:offset, cursor-column - top:address:shared:duplex-list:character <- get move, before-top-of-screen:offset + top:address:duplex-list:character <- get move, before-top-of-screen:offset *editor <- put *editor, top-of-screen:offset, top } ] @@ -766,18 +766,18 @@ scenario editor-can-undo-scroll [ # screen has 1 line for menu + 3 lines assume-screen 5/width, 4/height # editor contains a wrapped line - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b cdefgh] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right # position cursor at end of screen and try to move right assume-console [ left-click 3, 3 press right-arrow ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset # screen scrolls screen-should-contain [ . . @@ -794,9 +794,9 @@ cdefgh] press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moved back memory-should-contain [ @@ -815,7 +815,7 @@ cdefgh] type [1] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -828,25 +828,25 @@ cdefgh] scenario editor-can-undo-left-arrow [ # create an editor with some text assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def ghi] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # move the cursor assume-console [ left-click 3, 1 press left-arrow ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data # undo assume-console [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves back memory-should-contain [ @@ -858,7 +858,7 @@ ghi] type [1] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -872,19 +872,19 @@ ghi] scenario editor-can-undo-up-arrow [ # create an editor with some text assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def ghi] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # move the cursor assume-console [ left-click 3, 1 press up-arrow ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 2 4 <- 1 @@ -894,9 +894,9 @@ ghi] press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves back memory-should-contain [ @@ -908,7 +908,7 @@ ghi] type [1] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -922,25 +922,25 @@ ghi] scenario editor-can-undo-down-arrow [ # create an editor with some text assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def ghi] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # move the cursor assume-console [ left-click 2, 1 press down-arrow ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data # undo assume-console [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves back memory-should-contain [ @@ -952,7 +952,7 @@ ghi] type [1] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -966,27 +966,27 @@ ghi] scenario editor-can-undo-ctrl-f [ # create an editor with multiple pages of text assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b c d e f] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # scroll the page assume-console [ press ctrl-f ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data # undo assume-console [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # screen should again show page 1 screen-should-contain [ @@ -1001,27 +1001,27 @@ f] scenario editor-can-undo-page-down [ # create an editor with multiple pages of text assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b c d e f] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # scroll the page assume-console [ press page-down ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data # undo assume-console [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # screen should again show page 1 screen-should-contain [ @@ -1036,28 +1036,28 @@ f] scenario editor-can-undo-ctrl-b [ # create an editor with multiple pages of text assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b c d e f] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # scroll the page down and up assume-console [ press page-down press ctrl-b ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data # undo assume-console [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # screen should again show page 2 screen-should-contain [ @@ -1072,28 +1072,28 @@ f] scenario editor-can-undo-page-up [ # create an editor with multiple pages of text assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b c d e f] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # scroll the page down and up assume-console [ press page-down press page-up ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data # undo assume-console [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # screen should again show page 2 screen-should-contain [ @@ -1108,25 +1108,25 @@ f] scenario editor-can-undo-ctrl-a [ # create an editor with some text assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def ghi] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # move the cursor, then to start of line assume-console [ left-click 2, 1 press ctrl-a ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data # undo assume-console [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves back memory-should-contain [ @@ -1138,7 +1138,7 @@ ghi] type [1] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -1152,25 +1152,25 @@ ghi] scenario editor-can-undo-home [ # create an editor with some text assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def ghi] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # move the cursor, then to start of line assume-console [ left-click 2, 1 press home ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data # undo assume-console [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves back memory-should-contain [ @@ -1182,7 +1182,7 @@ ghi] type [1] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -1196,25 +1196,25 @@ ghi] scenario editor-can-undo-ctrl-e [ # create an editor with some text assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def ghi] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # move the cursor, then to start of line assume-console [ left-click 2, 1 press ctrl-e ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data # undo assume-console [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves back memory-should-contain [ @@ -1226,7 +1226,7 @@ ghi] type [1] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -1240,25 +1240,25 @@ ghi] scenario editor-can-undo-end [ # create an editor with some text assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def ghi] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # move the cursor, then to start of line assume-console [ left-click 2, 1 press end ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data # undo assume-console [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves back memory-should-contain [ @@ -1270,7 +1270,7 @@ ghi] type [1] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -1284,11 +1284,11 @@ ghi] scenario editor-can-undo-multiple-arrows-in-the-same-direction [ # create an editor with some text assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def ghi] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # move the cursor assume-console [ left-click 2, 1 @@ -1296,9 +1296,9 @@ ghi] press right-arrow press up-arrow ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 3 @@ -1308,9 +1308,9 @@ ghi] press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # up-arrow is undone memory-should-contain [ @@ -1322,9 +1322,9 @@ ghi] press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # both right-arrows are undone memory-should-contain [ @@ -1338,24 +1338,24 @@ ghi] scenario editor-redo-touch [ # create an editor with some text, click on a character, undo assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def ghi] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data assume-console [ left-click 3, 1 press ctrl-z ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data # redo assume-console [ press ctrl-y ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves to left-click memory-should-contain [ @@ -1367,7 +1367,7 @@ ghi] type [1] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -1387,7 +1387,7 @@ after <handle-redo> [ *editor <- put *editor, cursor-row:offset, cursor-row cursor-column <- get move, after-column:offset *editor <- put *editor, cursor-column:offset, cursor-column - top:address:shared:duplex-list:character <- get move, after-top-of-screen:offset + top:address:duplex-list:character <- get move, after-top-of-screen:offset *editor <- put *editor, top-of-screen:offset, top } ] @@ -1395,17 +1395,17 @@ after <handle-redo> [ scenario editor-separates-undo-insert-from-undo-cursor-move [ # create an editor, type some text, move the cursor, type some more text assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data assume-console [ type [abc] left-click 1, 1 type [d] ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset screen-should-contain [ . . .adbc . @@ -1421,9 +1421,9 @@ scenario editor-separates-undo-insert-from-undo-cursor-move [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # last letter typed is deleted screen-should-contain [ @@ -1441,9 +1441,9 @@ scenario editor-separates-undo-insert-from-undo-cursor-move [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # no change to screen; cursor moves screen-should-contain [ @@ -1461,9 +1461,9 @@ scenario editor-separates-undo-insert-from-undo-cursor-move [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # screen empty screen-should-contain [ @@ -1481,9 +1481,9 @@ scenario editor-separates-undo-insert-from-undo-cursor-move [ press ctrl-y ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # first insert screen-should-contain [ @@ -1501,9 +1501,9 @@ scenario editor-separates-undo-insert-from-undo-cursor-move [ press ctrl-y ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves screen-should-contain [ @@ -1522,9 +1522,9 @@ scenario editor-separates-undo-insert-from-undo-cursor-move [ press ctrl-y ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # second insert screen-should-contain [ @@ -1544,24 +1544,24 @@ scenario editor-separates-undo-insert-from-undo-cursor-move [ scenario editor-can-undo-and-redo-backspace [ # create an editor assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # insert some text and hit backspace assume-console [ type [abc] press backspace press backspace ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data screen-should-contain [ . . .a . .┈┈┈┈┈┈┈┈┈┈. . . ] - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 1 @@ -1571,10 +1571,10 @@ scenario editor-can-undo-and-redo-backspace [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 3 @@ -1590,10 +1590,10 @@ scenario editor-can-undo-and-redo-backspace [ press ctrl-y ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 1 @@ -1608,27 +1608,27 @@ scenario editor-can-undo-and-redo-backspace [ # save operation to undo after <backspace-character-begin> [ - top-before:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + top-before:address:duplex-list:character <- get *editor, top-of-screen:offset ] before <backspace-character-end> [ { break-unless backspaced-cell # backspace failed; don't add an undo operation - top-after:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + top-after:address:duplex-list:character <- get *editor, top-of-screen:offset cursor-row:number <- get *editor, cursor-row:offset cursor-column:number <- get *editor, cursor-row:offset - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset - undo:address:shared:list:address:shared:operation <- get *editor, undo:offset + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset + undo:address:list:address:operation <- get *editor, undo:offset { # if previous operation was an insert, coalesce this operation with it break-unless *undo - op:address:shared:operation <- first undo + op:address:operation <- first undo deletion:delete-operation, is-delete?:boolean <- maybe-convert *op, delete:variant break-unless is-delete? previous-coalesce-tag:number <- get deletion, tag:offset coalesce?:boolean <- equal previous-coalesce-tag, 1/coalesce-backspace break-unless coalesce? deletion <- put deletion, delete-from:offset, before-cursor - backspaced-so-far:address:shared:duplex-list:character <- get deletion, deleted-text:offset + backspaced-so-far:address:duplex-list:character <- get deletion, deleted-text:offset insert-range backspaced-cell, backspaced-so-far deletion <- put deletion, deleted-text:offset, backspaced-cell deletion <- put deletion, after-row:offset, cursor-row @@ -1638,8 +1638,8 @@ before <backspace-character-end> [ break +done-adding-backspace-operation:label } # if not, create a new operation - op:address:shared:operation <- new operation:type - deleted-until:address:shared:duplex-list:character <- next before-cursor + op:address:operation <- new operation:type + deleted-until:address:duplex-list:character <- next before-cursor *op <- merge 2/delete-operation, save-row/before, save-column/before, top-before, cursor-row/after, cursor-column/after, top-after, backspaced-cell/deleted, before-cursor/delete-from, deleted-until, 1/coalesce-backspace editor <- add-operation editor, op +done-adding-backspace-operation @@ -1650,10 +1650,10 @@ after <handle-undo> [ { deletion:delete-operation, is-delete?:boolean <- maybe-convert *op, delete:variant break-unless is-delete? - anchor:address:shared:duplex-list:character <- get deletion, delete-from:offset + anchor:address:duplex-list:character <- get deletion, delete-from:offset break-unless anchor - deleted:address:shared:duplex-list:character <- get deletion, deleted-text:offset - old-cursor:address:shared:duplex-list:character <- last deleted + deleted:address:duplex-list:character <- get deletion, deleted-text:offset + old-cursor:address:duplex-list:character <- last deleted insert-range anchor, deleted # assert cursor-row/cursor-column/top-of-screen match after-row/after-column/after-top-of-screen before-cursor <- copy old-cursor @@ -1661,7 +1661,7 @@ after <handle-undo> [ *editor <- put *editor, cursor-row:offset, cursor-row cursor-column <- get deletion, before-column:offset *editor <- put *editor, cursor-column:offset, cursor-column - top:address:shared:duplex-list:character <- get deletion, before-top-of-screen:offset + top:address:duplex-list:character <- get deletion, before-top-of-screen:offset *editor <- put *editor, top-of-screen:offset, top } ] @@ -1670,16 +1670,16 @@ after <handle-redo> [ { deletion:delete-operation, is-delete?:boolean <- maybe-convert *op, delete:variant break-unless is-delete? - start:address:shared:duplex-list:character <- get deletion, delete-from:offset - end:address:shared:duplex-list:character <- get deletion, delete-until:offset - data:address:shared:duplex-list:character <- get *editor, data:offset + start:address:duplex-list:character <- get deletion, delete-from:offset + end:address:duplex-list:character <- get deletion, delete-until:offset + data:address:duplex-list:character <- get *editor, data:offset remove-between start, end # assert cursor-row/cursor-column/top-of-screen match after-row/after-column/after-top-of-screen cursor-row <- get deletion, after-row:offset *editor <- put *editor, cursor-row:offset, cursor-row cursor-column <- get deletion, after-column:offset *editor <- put *editor, cursor-column:offset, cursor-column - top:address:shared:duplex-list:character <- get deletion, before-top-of-screen:offset + top:address:duplex-list:character <- get deletion, before-top-of-screen:offset *editor <- put *editor, top-of-screen:offset, top } ] @@ -1689,9 +1689,9 @@ after <handle-redo> [ scenario editor-can-undo-and-redo-delete [ # create an editor assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # insert some text and hit delete and backspace a few times assume-console [ type [abcdef] @@ -1701,15 +1701,15 @@ scenario editor-can-undo-and-redo-delete [ press delete press delete ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data screen-should-contain [ . . .af . .┈┈┈┈┈┈┈┈┈┈. . . ] - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 1 @@ -1719,10 +1719,10 @@ scenario editor-can-undo-and-redo-delete [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 1 @@ -1738,10 +1738,10 @@ scenario editor-can-undo-and-redo-delete [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 2 @@ -1757,10 +1757,10 @@ scenario editor-can-undo-and-redo-delete [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 2 @@ -1776,11 +1776,11 @@ scenario editor-can-undo-and-redo-delete [ press ctrl-y ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # first line inserted - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 2 @@ -1796,11 +1796,11 @@ scenario editor-can-undo-and-redo-delete [ press ctrl-y ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # first line inserted - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 1 @@ -1816,11 +1816,11 @@ scenario editor-can-undo-and-redo-delete [ press ctrl-y ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # first line inserted - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 1 @@ -1834,28 +1834,28 @@ scenario editor-can-undo-and-redo-delete [ ] after <delete-character-begin> [ - top-before:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + top-before:address:duplex-list:character <- get *editor, top-of-screen:offset ] before <delete-character-end> [ { break-unless deleted-cell # delete failed; don't add an undo operation - top-after:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + top-after:address:duplex-list:character <- get *editor, top-of-screen:offset cursor-row:number <- get *editor, cursor-row:offset cursor-column:number <- get *editor, cursor-column:offset - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset - undo:address:shared:list:address:shared:operation <- get *editor, undo:offset + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset + undo:address:list:address:operation <- get *editor, undo:offset { # if previous operation was an insert, coalesce this operation with it break-unless undo - op:address:shared:operation <- first undo + op:address:operation <- first undo deletion:delete-operation, is-delete?:boolean <- maybe-convert *op, delete:variant break-unless is-delete? previous-coalesce-tag:number <- get deletion, tag:offset coalesce?:boolean <- equal previous-coalesce-tag, 2/coalesce-delete break-unless coalesce? - delete-until:address:shared:duplex-list:character <- next before-cursor + delete-until:address:duplex-list:character <- next before-cursor deletion <- put deletion, delete-until:offset, delete-until - deleted-so-far:address:shared:duplex-list:character <- get deletion, deleted-text:offset + deleted-so-far:address:duplex-list:character <- get deletion, deleted-text:offset deleted-so-far <- append deleted-so-far, deleted-cell deletion <- put deletion, deleted-text:offset, deleted-so-far deletion <- put deletion, after-row:offset, cursor-row @@ -1865,8 +1865,8 @@ before <delete-character-end> [ break +done-adding-delete-operation:label } # if not, create a new operation - op:address:shared:operation <- new operation:type - deleted-until:address:shared:duplex-list:character <- next before-cursor + op:address:operation <- new operation:type + deleted-until:address:duplex-list:character <- next before-cursor *op <- merge 2/delete-operation, save-row/before, save-column/before, top-before, cursor-row/after, cursor-column/after, top-after, deleted-cell/deleted, before-cursor/delete-from, deleted-until, 2/coalesce-delete editor <- add-operation editor, op +done-adding-delete-operation @@ -1878,16 +1878,16 @@ before <delete-character-end> [ scenario editor-can-undo-and-redo-ctrl-k [ # create an editor assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # insert some text and hit delete and backspace a few times assume-console [ left-click 1, 1 press ctrl-k ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data screen-should-contain [ . . .a . @@ -1895,8 +1895,8 @@ def] .┈┈┈┈┈┈┈┈┈┈. . . ] - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 1 @@ -1906,7 +1906,7 @@ def] press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -1915,8 +1915,8 @@ def] .┈┈┈┈┈┈┈┈┈┈. . . ] - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 1 @@ -1926,7 +1926,7 @@ def] press ctrl-y ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # first line inserted screen-should-contain [ @@ -1936,8 +1936,8 @@ def] .┈┈┈┈┈┈┈┈┈┈. . . ] - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 1 @@ -1947,7 +1947,7 @@ def] type [1] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -1959,16 +1959,16 @@ def] ] after <delete-to-end-of-line-begin> [ - top-before:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + top-before:address:duplex-list:character <- get *editor, top-of-screen:offset ] before <delete-to-end-of-line-end> [ { break-unless deleted-cells # delete failed; don't add an undo operation - top-after:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + top-after:address:duplex-list:character <- get *editor, top-of-screen:offset cursor-row:number <- get *editor, cursor-row:offset cursor-column:number <- get *editor, cursor-column:offset - deleted-until:address:shared:duplex-list:character <- next before-cursor - op:address:shared:operation <- new operation:type + deleted-until:address:duplex-list:character <- next before-cursor + op:address:operation <- new operation:type *op <- merge 2/delete-operation, save-row/before, save-column/before, top-before, cursor-row/after, cursor-column/after, top-after, deleted-cells/deleted, before-cursor/delete-from, deleted-until, 0/never-coalesce editor <- add-operation editor, op +done-adding-delete-operation @@ -1980,16 +1980,16 @@ before <delete-to-end-of-line-end> [ scenario editor-can-undo-and-redo-ctrl-u [ # create an editor assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # insert some text and hit delete and backspace a few times assume-console [ left-click 1, 2 press ctrl-u ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data screen-should-contain [ . . .c . @@ -1997,8 +1997,8 @@ def] .┈┈┈┈┈┈┈┈┈┈. . . ] - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 0 @@ -2008,7 +2008,7 @@ def] press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -2017,8 +2017,8 @@ def] .┈┈┈┈┈┈┈┈┈┈. . . ] - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 2 @@ -2028,7 +2028,7 @@ def] press ctrl-y ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # first line inserted screen-should-contain [ @@ -2038,8 +2038,8 @@ def] .┈┈┈┈┈┈┈┈┈┈. . . ] - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 0 @@ -2049,7 +2049,7 @@ def] type [1] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -2061,15 +2061,15 @@ def] ] after <delete-to-start-of-line-begin> [ - top-before:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + top-before:address:duplex-list:character <- get *editor, top-of-screen:offset ] before <delete-to-start-of-line-end> [ { break-unless deleted-cells # delete failed; don't add an undo operation - top-after:address:shared:duplex-list:character <- get *editor, top-of-screen:offset - op:address:shared:operation <- new operation:type - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset - deleted-until:address:shared:duplex-list:character <- next before-cursor + top-after:address:duplex-list:character <- get *editor, top-of-screen:offset + op:address:operation <- new operation:type + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset + deleted-until:address:duplex-list:character <- next before-cursor cursor-row:number <- get *editor, cursor-row:offset cursor-column:number <- get *editor, cursor-column:offset *op <- merge 2/delete-operation, save-row/before, save-column/before, top-before, cursor-row/after, cursor-column/after, top-after, deleted-cells/deleted, before-cursor/delete-from, deleted-until, 0/never-coalesce @@ -2081,16 +2081,16 @@ before <delete-to-start-of-line-end> [ scenario editor-can-undo-and-redo-ctrl-u-2 [ # create an editor assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # insert some text and hit delete and backspace a few times assume-console [ type [abc] press ctrl-u press ctrl-z ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data screen-should-contain [ . . .abc . diff --git a/global.mu b/global.mu index 7f117c0c..d4764fb8 100644 --- a/global.mu +++ b/global.mu @@ -2,7 +2,7 @@ def main [ # allocate 5 locations for globals - global-space:address:shared:array:location <- new location:type, 5 + global-space:address:array:location <- new location:type, 5 # read to globals by using /space:global 1:number/space:global <- copy 3 foo diff --git a/sandbox/001-editor.mu b/sandbox/001-editor.mu index 614608c2..06c5a8dc 100644 --- a/sandbox/001-editor.mu +++ b/sandbox/001-editor.mu @@ -2,7 +2,7 @@ # temporary main for this layer: just render the given text at the given # screen dimensions, then stop -def! main text:address:shared:array:character [ +def! main text:address:array:character [ local-scope load-ingredients open-console @@ -16,8 +16,8 @@ def! main text:address:shared:array:character [ scenario editor-initially-prints-text-to-screen [ assume-screen 10/width, 5/height run [ - 1:address:shared:array:character <- new [abc] - new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 1:address:array:character <- new [abc] + new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right ] screen-should-contain [ # top line of screen reserved for menu @@ -29,11 +29,11 @@ scenario editor-initially-prints-text-to-screen [ container editor-data [ # editable text: doubly linked list of characters (head contains a special sentinel) - data:address:shared:duplex-list:character - top-of-screen:address:shared:duplex-list:character - bottom-of-screen:address:shared:duplex-list:character + data:address:duplex-list:character + top-of-screen:address:duplex-list:character + bottom-of-screen:address:duplex-list:character # location before cursor inside data - before-cursor:address:shared:duplex-list:character + before-cursor:address:duplex-list:character # raw bounds of display area on screen # always displays from row 1 (leaving row 0 for a menu) and at most until bottom of screen @@ -48,7 +48,7 @@ container editor-data [ # creates a new editor widget and renders its initial appearance to screen # top/left/right constrain the screen area available to the new editor # right is exclusive -def new-editor s:address:shared:array:character, screen:address:shared:screen, left:number, right:number -> result:address:shared:editor-data, screen:address:shared:screen [ +def new-editor s:address:array:character, screen:address:screen, left:number, right:number -> result:address:editor-data, screen:address:screen [ local-scope load-ingredients # no clipping of bounds @@ -61,7 +61,7 @@ def new-editor s:address:shared:array:character, screen:address:shared:screen, l *result <- put *result, cursor-row:offset, 1/top *result <- put *result, cursor-column:offset, left # initialize empty contents - init:address:shared:duplex-list:character <- push 167/§, 0/tail + init:address:duplex-list:character <- push 167/§, 0/tail *result <- put *result, data:offset, init *result <- put *result, top-of-screen:offset, init *result <- put *result, before-cursor:offset, init @@ -71,7 +71,7 @@ def new-editor s:address:shared:array:character, screen:address:shared:screen, l <editor-initialization> ] -def insert-text editor:address:shared:editor-data, text:address:shared:array:character -> editor:address:shared:editor-data [ +def insert-text editor:address:editor-data, text:address:array:character -> editor:address:editor-data [ local-scope load-ingredients # early exit if text is empty @@ -80,7 +80,7 @@ def insert-text editor:address:shared:editor-data, text:address:shared:array:cha return-unless len, editor/same-as-ingredient:0 idx:number <- copy 0 # now we can start appending the rest, character by character - curr:address:shared:duplex-list:character <- get *editor, data:offset + curr:address:duplex-list:character <- get *editor, data:offset { done?:boolean <- greater-or-equal idx, len break-if done? @@ -97,8 +97,8 @@ def insert-text editor:address:shared:editor-data, text:address:shared:array:cha scenario editor-initializes-without-data [ assume-screen 5/width, 3/height run [ - 1:address:shared:editor-data <- new-editor 0/data, screen:address:shared:screen, 2/left, 5/right - 2:editor-data <- copy *1:address:shared:editor-data + 1:address:editor-data <- new-editor 0/data, screen:address:screen, 2/left, 5/right + 2:editor-data <- copy *1:address:editor-data ] memory-should-contain [ # 2 (data) <- just the § sentinel @@ -121,7 +121,7 @@ scenario editor-initializes-without-data [ # Assumes cursor should be at coordinates (cursor-row, cursor-column) and # updates before-cursor to match. Might also move coordinates if they're # outside text. -def render screen:address:shared:screen, editor:address:shared:editor-data -> last-row:number, last-column:number, screen:address:shared:screen, editor:address:shared:editor-data [ +def render screen:address:screen, editor:address:editor-data -> last-row:number, last-column:number, screen:address:screen, editor:address:editor-data [ local-scope load-ingredients return-unless editor, 1/top, 0/left, screen/same-as-ingredient:0, editor/same-as-ingredient:1 @@ -129,8 +129,8 @@ def render screen:address:shared:screen, editor:address:shared:editor-data -> la screen-height:number <- screen-height screen right:number <- get *editor, right:offset # traversing editor - curr:address:shared:duplex-list:character <- get *editor, top-of-screen:offset - prev:address:shared:duplex-list:character <- copy curr # just in case curr becomes null and we can't compute prev + curr:address:duplex-list:character <- get *editor, top-of-screen:offset + prev:address:duplex-list:character <- copy curr # just in case curr becomes null and we can't compute prev curr <- next curr # traversing screen +render-loop-initialization @@ -139,7 +139,7 @@ def render screen:address:shared:screen, editor:address:shared:editor-data -> la column:number <- copy left cursor-row:number <- get *editor, cursor-row:offset cursor-column:number <- get *editor, cursor-column:offset - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset screen <- move-cursor screen, row, column { +next-character @@ -222,7 +222,7 @@ def render screen:address:shared:screen, editor:address:shared:editor-data -> la return row, column, screen/same-as-ingredient:0, editor/same-as-ingredient:1 ] -def clear-line-delimited screen:address:shared:screen, column:number, right:number -> screen:address:shared:screen [ +def clear-line-delimited screen:address:screen, column:number, right:number -> screen:address:screen [ local-scope load-ingredients space:character <- copy 32/space @@ -241,7 +241,7 @@ def clear-line-delimited screen:address:shared:screen, column:number, right:numb } ] -def clear-screen-from screen:address:shared:screen, row:number, column:number, left:number, right:number -> screen:address:shared:screen [ +def clear-screen-from screen:address:screen, row:number, column:number, left:number, right:number -> screen:address:screen [ local-scope load-ingredients # if it's the real screen, use the optimized primitive @@ -257,7 +257,7 @@ def clear-screen-from screen:address:shared:screen, row:number, column:number, l return screen/same-as-ingredient:0 ] -def clear-rest-of-screen screen:address:shared:screen, row:number, left:number, right:number -> screen:address:shared:screen [ +def clear-rest-of-screen screen:address:screen, row:number, left:number, right:number -> screen:address:screen [ local-scope load-ingredients row <- add row, 1 @@ -276,9 +276,9 @@ def clear-rest-of-screen screen:address:shared:screen, row:number, left:number, scenario editor-initially-prints-multiple-lines [ assume-screen 5/width, 5/height run [ - s:address:shared:array:character <- new [abc + s:address:array:character <- new [abc def] - new-editor s:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + new-editor s:address:array:character, screen:address:screen, 0/left, 5/right ] screen-should-contain [ . . @@ -291,8 +291,8 @@ def] scenario editor-initially-handles-offsets [ assume-screen 5/width, 5/height run [ - s:address:shared:array:character <- new [abc] - new-editor s:address:shared:array:character, screen:address:shared:screen, 1/left, 5/right + s:address:array:character <- new [abc] + new-editor s:address:array:character, screen:address:screen, 1/left, 5/right ] screen-should-contain [ . . @@ -304,9 +304,9 @@ scenario editor-initially-handles-offsets [ scenario editor-initially-prints-multiple-lines-at-offset [ assume-screen 5/width, 5/height run [ - s:address:shared:array:character <- new [abc + s:address:array:character <- new [abc def] - new-editor s:address:shared:array:character, screen:address:shared:screen, 1/left, 5/right + new-editor s:address:array:character, screen:address:screen, 1/left, 5/right ] screen-should-contain [ . . @@ -319,8 +319,8 @@ def] scenario editor-initially-wraps-long-lines [ assume-screen 5/width, 5/height run [ - s:address:shared:array:character <- new [abc def] - new-editor s:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + s:address:array:character <- new [abc def] + new-editor s:address:array:character, screen:address:screen, 0/left, 5/right ] screen-should-contain [ . . @@ -339,8 +339,8 @@ scenario editor-initially-wraps-long-lines [ scenario editor-initially-wraps-barely-long-lines [ assume-screen 5/width, 5/height run [ - s:address:shared:array:character <- new [abcde] - new-editor s:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + s:address:array:character <- new [abcde] + new-editor s:address:array:character, screen:address:screen, 0/left, 5/right ] # still wrap, even though the line would fit. We need room to click on the # end of the line @@ -361,10 +361,10 @@ scenario editor-initially-wraps-barely-long-lines [ scenario editor-initializes-empty-text [ assume-screen 5/width, 5/height run [ - 1:address:shared:array:character <- new [] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 1:address:array:character <- new [] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] screen-should-contain [ . . @@ -382,10 +382,10 @@ scenario editor-initializes-empty-text [ scenario render-colors-comments [ assume-screen 5/width, 5/height run [ - s:address:shared:array:character <- new [abc + s:address:array:character <- new [abc # de f] - new-editor s:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + new-editor s:address:array:character, screen:address:screen, 0/left, 5/right ] screen-should-contain [ . . @@ -463,10 +463,10 @@ def get-color color:number, c:character -> color:number [ scenario render-colors-assignment [ assume-screen 8/width, 5/height run [ - s:address:shared:array:character <- new [abc + s:address:array:character <- new [abc d <- e f] - new-editor s:address:shared:array:character, screen:address:shared:screen, 0/left, 8/right + new-editor s:address:array:character, screen:address:screen, 0/left, 8/right ] screen-should-contain [ . . diff --git a/sandbox/002-typing.mu b/sandbox/002-typing.mu index d7624ccf..88079641 100644 --- a/sandbox/002-typing.mu +++ b/sandbox/002-typing.mu @@ -2,16 +2,16 @@ # temporary main: interactive editor # hit ctrl-c to exit -def! main text:address:shared:array:character [ +def! main text:address:array:character [ local-scope load-ingredients open-console - editor:address:shared:editor-data <- new-editor text, 0/screen, 5/left, 45/right + editor:address:editor-data <- new-editor text, 0/screen, 5/left, 45/right editor-event-loop 0/screen, 0/console, editor close-console ] -def editor-event-loop screen:address:shared:screen, console:address:shared:console, editor:address:shared:editor-data -> screen:address:shared:screen, console:address:shared:console, editor:address:shared:editor-data [ +def editor-event-loop screen:address:screen, console:address:console, editor:address:editor-data -> screen:address:screen, console:address:console, editor:address:editor-data [ local-scope load-ingredients { @@ -20,7 +20,7 @@ def editor-event-loop screen:address:shared:screen, console:address:shared:conso cursor-row:number <- get *editor, cursor-row:offset cursor-column:number <- get *editor, cursor-column:offset screen <- move-cursor screen, cursor-row, cursor-column - e:event, console:address:shared:console, found?:boolean, quit?:boolean <- read-event console + e:event, console:address:console, found?:boolean, quit?:boolean <- read-event console loop-unless found? break-if quit? # only in tests trace 10, [app], [next-event] @@ -45,7 +45,7 @@ def editor-event-loop screen:address:shared:screen, console:address:shared:conso ] # process click, return if it was on current editor -def move-cursor-in-editor screen:address:shared:screen, editor:address:shared:editor-data, t:touch-event -> in-focus?:boolean, editor:address:shared:editor-data [ +def move-cursor-in-editor screen:address:screen, editor:address:editor-data, t:touch-event -> in-focus?:boolean, editor:address:editor-data [ local-scope load-ingredients return-unless editor, 0/false @@ -70,7 +70,7 @@ def move-cursor-in-editor screen:address:shared:screen, editor:address:shared:ed # Variant of 'render' that only moves the cursor (coordinates and # before-cursor). If it's past the end of a line, it 'slides' it left. If it's # past the last line it positions at end of last line. -def snap-cursor screen:address:shared:screen, editor:address:shared:editor-data, target-row:number, target-column:number -> editor:address:shared:editor-data [ +def snap-cursor screen:address:screen, editor:address:editor-data, target-row:number, target-column:number -> editor:address:editor-data [ local-scope load-ingredients return-unless editor @@ -78,8 +78,8 @@ def snap-cursor screen:address:shared:screen, editor:address:shared:editor-data, right:number <- get *editor, right:offset screen-height:number <- screen-height screen # count newlines until screen row - curr:address:shared:duplex-list:character <- get *editor, top-of-screen:offset - prev:address:shared:duplex-list:character <- copy curr # just in case curr becomes null and we can't compute prev + curr:address:duplex-list:character <- get *editor, top-of-screen:offset + prev:address:duplex-list:character <- copy curr # just in case curr becomes null and we can't compute prev curr <- next curr row:number <- copy 1/top column:number <- copy left @@ -87,7 +87,7 @@ def snap-cursor screen:address:shared:screen, editor:address:shared:editor-data, cursor-row:number <- copy target-row *editor <- put *editor, cursor-column:offset, target-column cursor-column:number <- copy target-column - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset { +next-character break-unless curr @@ -161,7 +161,7 @@ def snap-cursor screen:address:shared:screen, editor:address:shared:editor-data, # Process an event 'e' and try to minimally update the screen. # Set 'go-render?' to true to indicate the caller must perform a non-minimal update. -def handle-keyboard-event screen:address:shared:screen, editor:address:shared:editor-data, e:event -> screen:address:shared:screen, editor:address:shared:editor-data, go-render?:boolean [ +def handle-keyboard-event screen:address:screen, editor:address:editor-data, e:event -> screen:address:screen, editor:address:editor-data, go-render?:boolean [ local-scope load-ingredients go-render? <- copy 0/false @@ -170,7 +170,7 @@ def handle-keyboard-event screen:address:shared:screen, editor:address:shared:ed screen-height:number <- screen-height screen left:number <- get *editor, left:offset right:number <- get *editor, right:offset - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset cursor-row:number <- get *editor, cursor-row:offset cursor-column:number <- get *editor, cursor-column:offset save-row:number <- copy cursor-row @@ -201,10 +201,10 @@ def handle-keyboard-event screen:address:shared:screen, editor:address:shared:ed return ] -def insert-at-cursor editor:address:shared:editor-data, c:character, screen:address:shared:screen -> editor:address:shared:editor-data, screen:address:shared:screen, go-render?:boolean [ +def insert-at-cursor editor:address:editor-data, c:character, screen:address:screen -> editor:address:editor-data, screen:address:screen, go-render?:boolean [ local-scope load-ingredients - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset insert c, before-cursor before-cursor <- next before-cursor *editor <- put *editor, before-cursor:offset, before-cursor @@ -221,7 +221,7 @@ def insert-at-cursor editor:address:shared:editor-data, c:character, screen:addr # but mostly we'll just move the cursor right cursor-column <- add cursor-column, 1 *editor <- put *editor, cursor-column:offset, cursor-column - next:address:shared:duplex-list:character <- next before-cursor + next:address:duplex-list:character <- next before-cursor { # at end of all text? no need to scroll? just print the character and leave at-end?:boolean <- equal next, 0/null @@ -241,7 +241,7 @@ def insert-at-cursor editor:address:shared:editor-data, c:character, screen:addr break-unless next at-right?:boolean <- greater-or-equal cursor-column, screen-width break-if at-right? - curr:address:shared:duplex-list:character <- copy before-cursor + curr:address:duplex-list:character <- copy before-cursor move-cursor screen, save-row, save-column curr-column:number <- copy save-column { @@ -267,7 +267,7 @@ def insert-at-cursor editor:address:shared:editor-data, c:character, screen:addr ] # helper for tests -def editor-render screen:address:shared:screen, editor:address:shared:editor-data -> screen:address:shared:screen, editor:address:shared:editor-data [ +def editor-render screen:address:screen, editor:address:editor-data -> screen:address:screen, editor:address:editor-data [ local-scope load-ingredients left:number <- get *editor, left:offset @@ -282,12 +282,12 @@ def editor-render screen:address:shared:screen, editor:address:shared:editor-dat scenario editor-handles-empty-event-queue [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [abc] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data assume-console [] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -299,17 +299,17 @@ scenario editor-handles-empty-event-queue [ scenario editor-handles-mouse-clicks [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [abc] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ left-click 1, 1 # on the 'b' ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] screen-should-contain [ . . @@ -326,16 +326,16 @@ scenario editor-handles-mouse-clicks [ scenario editor-handles-mouse-clicks-outside-text [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 1:address:array:character <- new [abc] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right $clear-trace assume-console [ left-click 1, 7 # last line, to the right of text ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 1 # cursor row @@ -346,17 +346,17 @@ scenario editor-handles-mouse-clicks-outside-text [ scenario editor-handles-mouse-clicks-outside-text-2 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right $clear-trace assume-console [ left-click 1, 7 # interior line, to the right of text ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 1 # cursor row @@ -367,17 +367,17 @@ def] scenario editor-handles-mouse-clicks-outside-text-3 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right $clear-trace assume-console [ left-click 3, 7 # below text ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 2 # cursor row @@ -388,19 +388,19 @@ def] scenario editor-handles-mouse-clicks-outside-column [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc] + 1:address:array:character <- new [abc] # editor occupies only left half of screen - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ # click on right half of screen left-click 3, 8 ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] screen-should-contain [ . . @@ -417,18 +417,18 @@ scenario editor-handles-mouse-clicks-outside-column [ scenario editor-handles-mouse-clicks-in-menu-area [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [abc] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ # click on first, 'menu' row left-click 0, 3 ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # no change to cursor memory-should-contain [ @@ -439,15 +439,15 @@ scenario editor-handles-mouse-clicks-in-menu-area [ scenario editor-inserts-characters-into-empty-editor [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ type [abc] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -460,9 +460,9 @@ scenario editor-inserts-characters-into-empty-editor [ scenario editor-inserts-characters-at-cursor [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [abc] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace # type two letters at different places assume-console [ @@ -471,7 +471,7 @@ scenario editor-inserts-characters-at-cursor [ type [d] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -484,16 +484,16 @@ scenario editor-inserts-characters-at-cursor [ scenario editor-inserts-characters-at-cursor-2 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [abc] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ left-click 1, 5 # right of last line type [d] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -506,17 +506,17 @@ scenario editor-inserts-characters-at-cursor-2 [ scenario editor-inserts-characters-at-cursor-5 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc d] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ left-click 1, 5 # right of non-last line type [e] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -530,16 +530,16 @@ d] scenario editor-inserts-characters-at-cursor-3 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [abc] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ left-click 3, 5 # below all text type [d] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -552,17 +552,17 @@ scenario editor-inserts-characters-at-cursor-3 [ scenario editor-inserts-characters-at-cursor-4 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc d] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ left-click 3, 5 # below all text type [e] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -576,17 +576,17 @@ d] scenario editor-inserts-characters-at-cursor-6 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc d] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ left-click 3, 5 # below all text type [ef] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -600,14 +600,14 @@ d] scenario editor-moves-cursor-after-inserting-characters [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [ab] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [ab] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right + editor-render screen, 2:address:editor-data assume-console [ type [01] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -621,15 +621,15 @@ scenario editor-moves-cursor-after-inserting-characters [ scenario editor-wraps-line-on-insert [ assume-screen 5/width, 5/height - 1:address:shared:array:character <- new [abc] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [abc] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right + editor-render screen, 2:address:editor-data # type a letter assume-console [ type [e] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # no wrap yet screen-should-contain [ @@ -644,7 +644,7 @@ scenario editor-wraps-line-on-insert [ type [f] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # now wrap screen-should-contain [ @@ -659,19 +659,19 @@ scenario editor-wraps-line-on-insert [ scenario editor-wraps-line-on-insert-2 [ # create an editor with some text assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abcdefg + 1:address:array:character <- new [abcdefg defg] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right + editor-render screen, 2:address:editor-data # type more text at the start assume-console [ left-click 3, 0 type [abc] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor is not wrapped memory-should-contain [ @@ -713,16 +713,16 @@ after <insert-character-special-case> [ scenario editor-wraps-cursor-after-inserting-characters [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abcde] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + 1:address:array:character <- new [abcde] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right assume-console [ left-click 1, 4 # line is full; no wrap icon yet type [f] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] screen-should-contain [ . . @@ -739,16 +739,16 @@ scenario editor-wraps-cursor-after-inserting-characters [ scenario editor-wraps-cursor-after-inserting-characters-2 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abcde] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + 1:address:array:character <- new [abcde] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right assume-console [ left-click 1, 3 # right before the wrap icon type [f] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] screen-should-contain [ . . @@ -765,16 +765,16 @@ scenario editor-wraps-cursor-after-inserting-characters-2 [ scenario editor-wraps-cursor-to-left-margin [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abcde] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 2/left, 7/right + 1:address:array:character <- new [abcde] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 2/left, 7/right assume-console [ left-click 1, 5 # line is full; no wrap icon yet type [01] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] screen-should-contain [ . . @@ -801,14 +801,14 @@ after <editor-initialization> [ scenario editor-moves-cursor-down-after-inserting-newline [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 1:address:array:character <- new [abc] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right assume-console [ type [0 1] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -831,12 +831,12 @@ after <handle-special-character> [ } ] -def insert-new-line-and-indent editor:address:shared:editor-data, screen:address:shared:screen -> editor:address:shared:editor-data, screen:address:shared:screen, go-render?:boolean [ +def insert-new-line-and-indent editor:address:editor-data, screen:address:screen -> editor:address:editor-data, screen:address:screen, go-render?:boolean [ local-scope load-ingredients cursor-row:number <- get *editor, cursor-row:offset cursor-column:number <- get *editor, cursor-column:offset - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset left:number <- get *editor, left:offset right:number <- get *editor, right:offset screen-height:number <- screen-height screen @@ -860,8 +860,8 @@ def insert-new-line-and-indent editor:address:shared:editor-data, screen:address # indent if necessary indent?:boolean <- get *editor, indent?:offset return-unless indent? - d:address:shared:duplex-list:character <- get *editor, data:offset - end-of-previous-line:address:shared:duplex-list:character <- prev before-cursor + d:address:duplex-list:character <- get *editor, data:offset + end-of-previous-line:address:duplex-list:character <- prev before-cursor indent:number <- line-indent end-of-previous-line, d i:number <- copy 0 { @@ -875,7 +875,7 @@ def insert-new-line-and-indent editor:address:shared:editor-data, screen:address # takes a pointer 'curr' into the doubly-linked list and its sentinel, counts # the number of spaces at the start of the line containing 'curr'. -def line-indent curr:address:shared:duplex-list:character, start:address:shared:duplex-list:character -> result:number [ +def line-indent curr:address:duplex-list:character, start:address:duplex-list:character -> result:number [ local-scope load-ingredients result:number <- copy 0 @@ -907,14 +907,14 @@ def line-indent curr:address:shared:duplex-list:character, start:address:shared: scenario editor-moves-cursor-down-after-inserting-newline-2 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 1/left, 10/right + 1:address:array:character <- new [abc] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 1/left, 10/right assume-console [ type [0 1] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -927,8 +927,8 @@ scenario editor-moves-cursor-down-after-inserting-newline-2 [ scenario editor-clears-previous-line-completely-after-inserting-newline [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abcde] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + 1:address:array:character <- new [abcde] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right assume-console [ press enter ] @@ -940,7 +940,7 @@ scenario editor-clears-previous-line-completely-after-inserting-newline [ . . ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # line should be fully cleared screen-should-contain [ @@ -954,10 +954,10 @@ scenario editor-clears-previous-line-completely-after-inserting-newline [ scenario editor-inserts-indent-after-newline [ assume-screen 10/width, 10/height - 1:address:shared:array:character <- new [ab + 1:address:array:character <- new [ab cd ef] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right # position cursor after 'cd' and hit 'newline' assume-console [ left-click 2, 8 @@ -965,9 +965,9 @@ ef] ] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor should be below start of previous line memory-should-contain [ @@ -978,10 +978,10 @@ ef] scenario editor-skips-indent-around-paste [ assume-screen 10/width, 10/height - 1:address:shared:array:character <- new [ab + 1:address:array:character <- new [ab cd ef] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right # position cursor after 'cd' and hit 'newline' surrounded by paste markers assume-console [ left-click 2, 8 @@ -990,9 +990,9 @@ ef] press 65506 # end paste ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor should be below start of previous line memory-should-contain [ @@ -1023,7 +1023,7 @@ after <handle-special-key> [ ## helpers -def draw-horizontal screen:address:shared:screen, row:number, x:number, right:number -> screen:address:shared:screen [ +def draw-horizontal screen:address:screen, row:number, x:number, right:number -> screen:address:screen [ local-scope load-ingredients style:character, style-found?:boolean <- next-ingredient diff --git a/sandbox/003-shortcuts.mu b/sandbox/003-shortcuts.mu index 8ed01de7..40956cb3 100644 --- a/sandbox/003-shortcuts.mu +++ b/sandbox/003-shortcuts.mu @@ -7,14 +7,14 @@ scenario editor-inserts-two-spaces-on-tab [ assume-screen 10/width, 5/height # just one character in final line - 1:address:shared:array:character <- new [ab + 1:address:array:character <- new [ab cd] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right assume-console [ press tab ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -40,18 +40,18 @@ after <handle-special-character> [ scenario editor-handles-backspace-key [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [abc] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ left-click 1, 1 press backspace ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 4:number <- get *2:address:shared:editor-data, cursor-row:offset - 5:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 4:number <- get *2:address:editor-data, cursor-row:offset + 5:number <- get *2:address:editor-data, cursor-column:offset ] screen-should-contain [ . . @@ -71,7 +71,7 @@ after <handle-special-character> [ delete-previous-character?:boolean <- equal c, 8/backspace break-unless delete-previous-character? <backspace-character-begin> - editor, screen, go-render?:boolean, backspaced-cell:address:shared:duplex-list:character <- delete-before-cursor editor, screen + editor, screen, go-render?:boolean, backspaced-cell:address:duplex-list:character <- delete-before-cursor editor, screen <backspace-character-end> return } @@ -80,19 +80,19 @@ after <handle-special-character> [ # return values: # go-render? - whether caller needs to update the screen # backspaced-cell - value deleted (or 0 if nothing was deleted) so we can save it for undo, etc. -def delete-before-cursor editor:address:shared:editor-data, screen:address:shared:screen -> editor:address:shared:editor-data, screen:address:shared:screen, go-render?:boolean, backspaced-cell:address:shared:duplex-list:character [ +def delete-before-cursor editor:address:editor-data, screen:address:screen -> editor:address:editor-data, screen:address:screen, go-render?:boolean, backspaced-cell:address:duplex-list:character [ local-scope load-ingredients - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset - data:address:shared:duplex-list:character <- get *editor, data:offset + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset + data:address:duplex-list:character <- get *editor, data:offset # if at start of text (before-cursor at § sentinel), return - prev:address:shared:duplex-list:character <- prev before-cursor + prev:address:duplex-list:character <- prev before-cursor go-render?, backspaced-cell <- copy 0/no-more-render, 0/nothing-deleted return-unless prev trace 10, [app], [delete-before-cursor] original-row:number <- get *editor, cursor-row:offset editor, scroll?:boolean <- move-cursor-coordinates-left editor - backspaced-cell:address:shared:duplex-list:character <- copy before-cursor + backspaced-cell:address:duplex-list:character <- copy before-cursor data <- remove before-cursor, data # will also neatly trim next/prev pointers in backspaced-cell/before-cursor before-cursor <- copy prev *editor <- put *editor, before-cursor:offset, before-cursor @@ -107,7 +107,7 @@ def delete-before-cursor editor:address:shared:editor-data, screen:address:share return-unless same-row? left:number <- get *editor, left:offset right:number <- get *editor, right:offset - curr:address:shared:duplex-list:character <- next before-cursor + curr:address:duplex-list:character <- next before-cursor screen <- move-cursor screen, cursor-row, cursor-column curr-column:number <- copy cursor-column { @@ -131,10 +131,10 @@ def delete-before-cursor editor:address:shared:editor-data, screen:address:share go-render? <- copy 0/false ] -def move-cursor-coordinates-left editor:address:shared:editor-data -> editor:address:shared:editor-data, go-render?:boolean [ +def move-cursor-coordinates-left editor:address:editor-data -> editor:address:editor-data, go-render?:boolean [ local-scope load-ingredients - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset cursor-row:number <- get *editor, cursor-row:offset cursor-column:number <- get *editor, cursor-column:offset left:number <- get *editor, left:offset @@ -168,7 +168,7 @@ def move-cursor-coordinates-left editor:address:shared:editor-data -> editor:add break-unless previous-character-is-newline? # compute length of previous line trace 10, [app], [switching to previous line] - d:address:shared:duplex-list:character <- get *editor, data:offset + d:address:duplex-list:character <- get *editor, data:offset end-of-line:number <- previous-line-length before-cursor, d right:number <- get *editor, right:offset width:number <- subtract right, left @@ -195,7 +195,7 @@ def move-cursor-coordinates-left editor:address:shared:editor-data -> editor:add # takes a pointer 'curr' into the doubly-linked list and its sentinel, counts # the length of the previous line before the 'curr' pointer. -def previous-line-length curr:address:shared:duplex-list:character, start:address:shared:duplex-list:character -> result:number [ +def previous-line-length curr:address:duplex-list:character, start:address:duplex-list:character -> result:number [ local-scope load-ingredients result:number <- copy 0 @@ -218,17 +218,17 @@ def previous-line-length curr:address:shared:duplex-list:character, start:addres scenario editor-clears-last-line-on-backspace [ assume-screen 10/width, 5/height # just one character in final line - 1:address:shared:array:character <- new [ab + 1:address:array:character <- new [ab cd] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right assume-console [ left-click 2, 0 # cursor at only character in final line press backspace ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 4:number <- get *2:address:shared:editor-data, cursor-row:offset - 5:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 4:number <- get *2:address:editor-data, cursor-row:offset + 5:number <- get *2:address:editor-data, cursor-column:offset ] screen-should-contain [ . . @@ -245,10 +245,10 @@ cd] scenario editor-joins-and-wraps-lines-on-backspace [ assume-screen 10/width, 5/height # initialize editor with two long-ish but non-wrapping lines - 1:address:shared:array:character <- new [abc def + 1:address:array:character <- new [abc def ghi jkl] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace # position the cursor at the start of the second and hit backspace assume-console [ @@ -256,7 +256,7 @@ ghi jkl] press backspace ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # resulting single line should wrap correctly screen-should-contain [ @@ -271,9 +271,9 @@ ghi jkl] scenario editor-wraps-long-lines-on-backspace [ assume-screen 10/width, 5/height # initialize editor in part of the screen with a long line - 1:address:shared:array:character <- new [abc def ghij] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 8/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [abc def ghij] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 8/right + editor-render screen, 2:address:editor-data # confirm that it wraps screen-should-contain [ . . @@ -288,7 +288,7 @@ scenario editor-wraps-long-lines-on-backspace [ press backspace ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # resulting single line should wrap correctly and not overflow its bounds screen-should-contain [ @@ -304,15 +304,15 @@ scenario editor-wraps-long-lines-on-backspace [ scenario editor-handles-delete-key [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [abc] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ press delete ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -326,7 +326,7 @@ scenario editor-handles-delete-key [ press delete ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -342,18 +342,18 @@ after <handle-special-key> [ delete-next-character?:boolean <- equal k, 65522/delete break-unless delete-next-character? <delete-character-begin> - editor, screen, go-render?:boolean, deleted-cell:address:shared:duplex-list:character <- delete-at-cursor editor, screen + editor, screen, go-render?:boolean, deleted-cell:address:duplex-list:character <- delete-at-cursor editor, screen <delete-character-end> return } ] -def delete-at-cursor editor:address:shared:editor-data, screen:address:shared:screen -> editor:address:shared:editor-data, screen:address:shared:screen, go-render?:boolean, deleted-cell:address:shared:duplex-list:character [ +def delete-at-cursor editor:address:editor-data, screen:address:screen -> editor:address:editor-data, screen:address:screen, go-render?:boolean, deleted-cell:address:duplex-list:character [ local-scope load-ingredients - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset - data:address:shared:duplex-list:character <- get *editor, data:offset - deleted-cell:address:shared:duplex-list:character <- next before-cursor + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset + data:address:duplex-list:character <- get *editor, data:offset + deleted-cell:address:duplex-list:character <- next before-cursor go-render? <- copy 0/false return-unless deleted-cell currc:character <- get *deleted-cell, value:offset @@ -362,7 +362,7 @@ def delete-at-cursor editor:address:shared:editor-data, screen:address:shared:sc go-render? <- copy 1/true return-if deleted-newline? # wasn't a newline? render rest of line - curr:address:shared:duplex-list:character <- next before-cursor # refresh after remove above + curr:address:duplex-list:character <- next before-cursor # refresh after remove above cursor-row:number <- get *editor, cursor-row:offset cursor-column:number <- get *editor, cursor-column:offset screen <- move-cursor screen, cursor-row, cursor-column @@ -393,16 +393,16 @@ def delete-at-cursor editor:address:shared:editor-data, screen:address:shared:sc scenario editor-moves-cursor-right-with-key [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [abc] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ press right-arrow type [0] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -418,7 +418,7 @@ after <handle-special-key> [ move-to-next-character?:boolean <- equal k, 65514/right-arrow break-unless move-to-next-character? # if not at end of text - next-cursor:address:shared:duplex-list:character <- next before-cursor + next-cursor:address:duplex-list:character <- next before-cursor break-unless next-cursor # scan to next character <move-cursor-begin> @@ -432,10 +432,10 @@ after <handle-special-key> [ } ] -def move-cursor-coordinates-right editor:address:shared:editor-data, screen-height:number -> editor:address:shared:editor-data, go-render?:boolean [ +def move-cursor-coordinates-right editor:address:editor-data, screen-height:number -> editor:address:editor-data, go-render?:boolean [ local-scope load-ingredients - before-cursor:address:shared:duplex-list:character <- get *editor before-cursor:offset + before-cursor:address:duplex-list:character <- get *editor before-cursor:offset cursor-row:number <- get *editor, cursor-row:offset cursor-column:number <- get *editor, cursor-column:offset left:number <- get *editor, left:offset @@ -465,7 +465,7 @@ def move-cursor-coordinates-right editor:address:shared:editor-data, screen-heig at-wrap?:boolean <- equal cursor-column, wrap-column break-unless at-wrap? # and if next character isn't newline - next:address:shared:duplex-list:character <- next before-cursor + next:address:duplex-list:character <- next before-cursor break-unless next next-character:character <- get *next, value:offset newline?:boolean <- equal next-character, 10/newline @@ -490,10 +490,10 @@ def move-cursor-coordinates-right editor:address:shared:editor-data, screen-heig scenario editor-moves-cursor-to-next-line-with-right-arrow [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc d] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace # type right-arrow a few times to get to start of second line assume-console [ @@ -503,7 +503,7 @@ d] press right-arrow # next line ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] check-trace-count-for-label 0, [print-character] # type something and ensure it goes where it should @@ -511,7 +511,7 @@ d] type [0] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -525,10 +525,10 @@ d] scenario editor-moves-cursor-to-next-line-with-right-arrow-2 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc d] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 1/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 1/left, 10/right + editor-render screen, 2:address:editor-data assume-console [ press right-arrow press right-arrow @@ -537,7 +537,7 @@ d] type [0] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -550,18 +550,18 @@ d] scenario editor-moves-cursor-to-next-wrapped-line-with-right-arrow [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abcdef] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [abcdef] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ left-click 1, 3 press right-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] screen-should-contain [ . . @@ -580,9 +580,9 @@ scenario editor-moves-cursor-to-next-wrapped-line-with-right-arrow [ scenario editor-moves-cursor-to-next-wrapped-line-with-right-arrow-2 [ assume-screen 10/width, 5/height # line just barely wrapping - 1:address:shared:array:character <- new [abcde] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [abcde] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right + editor-render screen, 2:address:editor-data $clear-trace # position cursor at last character before wrap and hit right-arrow assume-console [ @@ -590,9 +590,9 @@ scenario editor-moves-cursor-to-next-wrapped-line-with-right-arrow-2 [ press right-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 2 @@ -603,9 +603,9 @@ scenario editor-moves-cursor-to-next-wrapped-line-with-right-arrow-2 [ press right-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 2 @@ -616,18 +616,18 @@ scenario editor-moves-cursor-to-next-wrapped-line-with-right-arrow-2 [ scenario editor-moves-cursor-to-next-wrapped-line-with-right-arrow-3 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abcdef] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 1/left, 6/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [abcdef] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 1/left, 6/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ left-click 1, 4 press right-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] screen-should-contain [ . . @@ -645,10 +645,10 @@ scenario editor-moves-cursor-to-next-wrapped-line-with-right-arrow-3 [ scenario editor-moves-cursor-to-next-line-with-right-arrow-at-end-of-line [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc d] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace # move to end of line, press right-arrow, type a character assume-console [ @@ -657,7 +657,7 @@ d] type [0] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # new character should be in next line screen-should-contain [ @@ -676,9 +676,9 @@ d] scenario editor-moves-cursor-left-with-key [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [abc] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ left-click 1, 2 @@ -686,7 +686,7 @@ scenario editor-moves-cursor-left-with-key [ type [0] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -703,7 +703,7 @@ after <handle-special-key> [ break-unless move-to-previous-character? trace 10, [app], [left arrow] # if not at start of text (before-cursor at § sentinel) - prev:address:shared:duplex-list:character <- prev before-cursor + prev:address:duplex-list:character <- prev before-cursor go-render? <- copy 0/false return-unless prev <move-cursor-begin> @@ -719,10 +719,10 @@ after <handle-special-key> [ scenario editor-moves-cursor-to-previous-line-with-left-arrow-at-start-of-line [ assume-screen 10/width, 5/height # initialize editor with two lines - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc d] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace # position cursor at start of second line (so there's no previous newline) assume-console [ @@ -730,9 +730,9 @@ d] press left-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 1 @@ -744,11 +744,11 @@ d] scenario editor-moves-cursor-to-previous-line-with-left-arrow-at-start-of-line-2 [ assume-screen 10/width, 5/height # initialize editor with three lines - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def g] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace # position cursor further down (so there's a newline before the character at # the cursor) @@ -758,7 +758,7 @@ g] type [0] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -772,11 +772,11 @@ g] scenario editor-moves-cursor-to-previous-line-with-left-arrow-at-start-of-line-3 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def g] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace # position cursor at start of text, press left-arrow, then type a character assume-console [ @@ -785,7 +785,7 @@ g] type [0] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # left-arrow should have had no effect screen-should-contain [ @@ -801,11 +801,11 @@ g] scenario editor-moves-cursor-to-previous-line-with-left-arrow-at-start-of-line-4 [ assume-screen 10/width, 5/height # initialize editor with text containing an empty line - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc d] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace # position cursor right after empty line assume-console [ @@ -814,7 +814,7 @@ d] type [0] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -829,9 +829,9 @@ d] scenario editor-moves-across-screen-lines-across-wrap-with-left-arrow [ assume-screen 10/width, 5/height # initialize editor with a wrapping line - 1:address:shared:array:character <- new [abcdef] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [abcdef] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right + editor-render screen, 2:address:editor-data $clear-trace screen-should-contain [ . . @@ -846,9 +846,9 @@ scenario editor-moves-across-screen-lines-across-wrap-with-left-arrow [ press left-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 1 # previous row @@ -860,10 +860,10 @@ scenario editor-moves-across-screen-lines-across-wrap-with-left-arrow [ scenario editor-moves-across-screen-lines-to-wrapping-line-with-left-arrow [ assume-screen 10/width, 5/height # initialize editor with a wrapping line followed by a second line - 1:address:shared:array:character <- new [abcdef + 1:address:array:character <- new [abcdef g] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right + editor-render screen, 2:address:editor-data $clear-trace screen-should-contain [ . . @@ -878,9 +878,9 @@ g] press left-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 2 # previous row @@ -892,10 +892,10 @@ g] scenario editor-moves-across-screen-lines-to-non-wrapping-line-with-left-arrow [ assume-screen 10/width, 5/height # initialize editor with a line on the verge of wrapping, followed by a second line - 1:address:shared:array:character <- new [abcd + 1:address:array:character <- new [abcd e] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right + editor-render screen, 2:address:editor-data $clear-trace screen-should-contain [ . . @@ -910,9 +910,9 @@ e] press left-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 1 # previous row @@ -927,19 +927,19 @@ e] scenario editor-moves-to-previous-line-with-up-arrow [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ left-click 2, 1 press up-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 1 @@ -950,7 +950,7 @@ def] type [0] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -973,12 +973,12 @@ after <handle-special-key> [ } ] -def move-to-previous-line editor:address:shared:editor-data -> editor:address:shared:editor-data, go-render?:boolean [ +def move-to-previous-line editor:address:editor-data -> editor:address:editor-data, go-render?:boolean [ local-scope load-ingredients cursor-row:number <- get *editor, cursor-row:offset cursor-column:number <- get *editor, cursor-column:offset - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset left:number <- get *editor, left:offset right:number <- get *editor, right:offset already-at-top?:boolean <- lesser-or-equal cursor-row, 1/top @@ -988,13 +988,13 @@ def move-to-previous-line editor:address:shared:editor-data -> editor:address:sh # if not at newline, move to start of line (previous newline) # then scan back another line # if either step fails, give up without modifying cursor or coordinates - curr:address:shared:duplex-list:character <- copy before-cursor + curr:address:duplex-list:character <- copy before-cursor { - old:address:shared:duplex-list:character <- copy curr + old:address:duplex-list:character <- copy curr c2:character <- get *curr, value:offset at-newline?:boolean <- equal c2, 10/newline break-if at-newline? - curr:address:shared:duplex-list:character <- before-previous-line curr, editor + curr:address:duplex-list:character <- before-previous-line curr, editor no-motion?:boolean <- equal curr, old go-render? <- copy 0/false return-if no-motion? @@ -1017,7 +1017,7 @@ def move-to-previous-line editor:address:shared:editor-data -> editor:address:sh { done?:boolean <- greater-or-equal cursor-column, target-column break-if done? - curr:address:shared:duplex-list:character <- next before-cursor + curr:address:duplex-list:character <- next before-cursor break-unless curr currc:character <- get *curr, value:offset at-newline?:boolean <- equal currc, 10/newline @@ -1043,19 +1043,19 @@ def move-to-previous-line editor:address:shared:editor-data -> editor:address:sh scenario editor-adjusts-column-at-previous-line [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [ab + 1:address:array:character <- new [ab def] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ left-click 2, 3 press up-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 1 @@ -1066,7 +1066,7 @@ def] type [0] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -1079,19 +1079,19 @@ def] scenario editor-adjusts-column-at-empty-line [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [ + 1:address:array:character <- new [ def] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ left-click 2, 3 press up-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 1 @@ -1102,7 +1102,7 @@ def] type [0] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -1116,11 +1116,11 @@ def] scenario editor-moves-to-previous-line-from-left-margin [ assume-screen 10/width, 5/height # start out with three lines - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def ghi] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace # click on the third line and hit up-arrow, so you end up just after a newline assume-console [ @@ -1128,9 +1128,9 @@ ghi] press up-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 2 @@ -1141,7 +1141,7 @@ ghi] type [0] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -1156,19 +1156,19 @@ ghi] scenario editor-moves-to-next-line-with-down-arrow [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace # cursor starts out at (1, 0) assume-console [ press down-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # ..and ends at (2, 0) memory-should-contain [ @@ -1180,7 +1180,7 @@ def] type [0] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -1203,12 +1203,12 @@ after <handle-special-key> [ } ] -def move-to-next-line editor:address:shared:editor-data, screen-height:number -> editor:address:shared:editor-data, go-render?:boolean [ +def move-to-next-line editor:address:editor-data, screen-height:number -> editor:address:editor-data, go-render?:boolean [ local-scope load-ingredients cursor-row:number <- get *editor, cursor-row:offset cursor-column:number <- get *editor, cursor-column:offset - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset left:number <- get *editor, left:offset right:number <- get *editor, right:offset last-line:number <- subtract screen-height, 1 @@ -1218,7 +1218,7 @@ def move-to-next-line editor:address:shared:editor-data, screen-height:number -> break-if already-at-bottom? # scan to start of next line, then to right column or until end of line max:number <- subtract right, left - next-line:address:shared:duplex-list:character <- before-start-of-next-line before-cursor, max + next-line:address:duplex-list:character <- before-start-of-next-line before-cursor, max { # already at end of buffer? try to scroll up (so we can see more # warnings or sandboxes below) @@ -1239,7 +1239,7 @@ def move-to-next-line editor:address:shared:editor-data, screen-height:number -> { done?:boolean <- greater-or-equal cursor-column, target-column break-if done? - curr:address:shared:duplex-list:character <- next before-cursor + curr:address:duplex-list:character <- next before-cursor break-unless curr currc:character <- get *curr, value:offset at-newline?:boolean <- equal currc, 10/newline @@ -1261,19 +1261,19 @@ def move-to-next-line editor:address:shared:editor-data, screen-height:number -> scenario editor-adjusts-column-at-next-line [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc de] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace assume-console [ left-click 1, 3 press down-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 2 @@ -1284,7 +1284,7 @@ de] type [0] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -1299,10 +1299,10 @@ de] scenario editor-moves-to-start-of-line-with-ctrl-a [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [123 + 1:address:array:character <- new [123 456] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace # start on second line, press ctrl-a assume-console [ @@ -1310,9 +1310,9 @@ scenario editor-moves-to-start-of-line-with-ctrl-a [ press ctrl-a ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 4:number <- get *2:address:shared:editor-data, cursor-row:offset - 5:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 4:number <- get *2:address:editor-data, cursor-row:offset + 5:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves to start of line memory-should-contain [ @@ -1348,7 +1348,7 @@ after <handle-special-key> [ } ] -def move-to-start-of-line editor:address:shared:editor-data -> editor:address:shared:editor-data [ +def move-to-start-of-line editor:address:editor-data -> editor:address:editor-data [ local-scope load-ingredients # update cursor column @@ -1356,8 +1356,8 @@ def move-to-start-of-line editor:address:shared:editor-data -> editor:address:sh cursor-column:number <- copy left *editor <- put *editor, cursor-column:offset, cursor-column # update before-cursor - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset - init:address:shared:duplex-list:character <- get *editor, data:offset + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset + init:address:duplex-list:character <- get *editor, data:offset # while not at start of line, move { at-start-of-text?:boolean <- equal before-cursor, init @@ -1374,10 +1374,10 @@ def move-to-start-of-line editor:address:shared:editor-data -> editor:address:sh scenario editor-moves-to-start-of-line-with-ctrl-a-2 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [123 + 1:address:array:character <- new [123 456] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace # start on first line (no newline before), press ctrl-a assume-console [ @@ -1385,9 +1385,9 @@ scenario editor-moves-to-start-of-line-with-ctrl-a-2 [ press ctrl-a ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 4:number <- get *2:address:shared:editor-data, cursor-row:offset - 5:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 4:number <- get *2:address:editor-data, cursor-row:offset + 5:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves to start of line memory-should-contain [ @@ -1399,9 +1399,9 @@ scenario editor-moves-to-start-of-line-with-ctrl-a-2 [ scenario editor-moves-to-start-of-line-with-home [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [123 + 1:address:array:character <- new [123 456] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right $clear-trace # start on second line, press 'home' assume-console [ @@ -1409,9 +1409,9 @@ scenario editor-moves-to-start-of-line-with-home [ press home ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves to start of line memory-should-contain [ @@ -1423,10 +1423,10 @@ scenario editor-moves-to-start-of-line-with-home [ scenario editor-moves-to-start-of-line-with-home-2 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [123 + 1:address:array:character <- new [123 456] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace # start on first line (no newline before), press 'home' assume-console [ @@ -1434,9 +1434,9 @@ scenario editor-moves-to-start-of-line-with-home-2 [ press home ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves to start of line memory-should-contain [ @@ -1450,10 +1450,10 @@ scenario editor-moves-to-start-of-line-with-home-2 [ scenario editor-moves-to-end-of-line-with-ctrl-e [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [123 + 1:address:array:character <- new [123 456] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace # start on first line, press ctrl-e assume-console [ @@ -1461,9 +1461,9 @@ scenario editor-moves-to-end-of-line-with-ctrl-e [ press ctrl-e ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 4:number <- get *2:address:shared:editor-data, cursor-row:offset - 5:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 4:number <- get *2:address:editor-data, cursor-row:offset + 5:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves to end of line memory-should-contain [ @@ -1476,9 +1476,9 @@ scenario editor-moves-to-end-of-line-with-ctrl-e [ type [z] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 4:number <- get *2:address:shared:editor-data, cursor-row:offset - 5:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 4:number <- get *2:address:editor-data, cursor-row:offset + 5:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 4 <- 1 @@ -1520,14 +1520,14 @@ after <handle-special-key> [ } ] -def move-to-end-of-line editor:address:shared:editor-data -> editor:address:shared:editor-data [ +def move-to-end-of-line editor:address:editor-data -> editor:address:editor-data [ local-scope load-ingredients - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset cursor-column:number <- get *editor, cursor-column:offset # while not at start of line, move { - next:address:shared:duplex-list:character <- next before-cursor + next:address:duplex-list:character <- next before-cursor break-unless next # end of text nextc:character <- get *next, value:offset at-end-of-line?:boolean <- equal nextc, 10/newline @@ -1542,10 +1542,10 @@ def move-to-end-of-line editor:address:shared:editor-data -> editor:address:shar scenario editor-moves-to-end-of-line-with-ctrl-e-2 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [123 + 1:address:array:character <- new [123 456] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace # start on second line (no newline after), press ctrl-e assume-console [ @@ -1553,9 +1553,9 @@ scenario editor-moves-to-end-of-line-with-ctrl-e-2 [ press ctrl-e ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 4:number <- get *2:address:shared:editor-data, cursor-row:offset - 5:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 4:number <- get *2:address:editor-data, cursor-row:offset + 5:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves to end of line memory-should-contain [ @@ -1567,10 +1567,10 @@ scenario editor-moves-to-end-of-line-with-ctrl-e-2 [ scenario editor-moves-to-end-of-line-with-end [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [123 + 1:address:array:character <- new [123 456] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace # start on first line, press 'end' assume-console [ @@ -1578,9 +1578,9 @@ scenario editor-moves-to-end-of-line-with-end [ press end ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves to end of line memory-should-contain [ @@ -1592,10 +1592,10 @@ scenario editor-moves-to-end-of-line-with-end [ scenario editor-moves-to-end-of-line-with-end-2 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [123 + 1:address:array:character <- new [123 456] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace # start on second line (no newline after), press 'end' assume-console [ @@ -1603,9 +1603,9 @@ scenario editor-moves-to-end-of-line-with-end-2 [ press end ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves to end of line memory-should-contain [ @@ -1619,16 +1619,16 @@ scenario editor-moves-to-end-of-line-with-end-2 [ scenario editor-deletes-to-start-of-line-with-ctrl-u [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [123 + 1:address:array:character <- new [123 456] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right # start on second line, press ctrl-u assume-console [ left-click 2, 2 press ctrl-u ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # cursor deletes to start of line screen-should-contain [ @@ -1645,21 +1645,21 @@ after <handle-special-character> [ delete-to-start-of-line?:boolean <- equal c, 21/ctrl-u break-unless delete-to-start-of-line? <delete-to-start-of-line-begin> - deleted-cells:address:shared:duplex-list:character <- delete-to-start-of-line editor + deleted-cells:address:duplex-list:character <- delete-to-start-of-line editor <delete-to-start-of-line-end> go-render? <- copy 1/true return } ] -def delete-to-start-of-line editor:address:shared:editor-data -> result:address:shared:duplex-list:character, editor:address:shared:editor-data [ +def delete-to-start-of-line editor:address:editor-data -> result:address:duplex-list:character, editor:address:editor-data [ local-scope load-ingredients # compute range to delete - init:address:shared:duplex-list:character <- get *editor, data:offset - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset - start:address:shared:duplex-list:character <- copy before-cursor - end:address:shared:duplex-list:character <- next before-cursor + init:address:duplex-list:character <- get *editor, data:offset + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset + start:address:duplex-list:character <- copy before-cursor + end:address:duplex-list:character <- next before-cursor { at-start-of-text?:boolean <- equal start, init break-if at-start-of-text? @@ -1671,7 +1671,7 @@ def delete-to-start-of-line editor:address:shared:editor-data -> result:address: loop } # snip it out - result:address:shared:duplex-list:character <- next start + result:address:duplex-list:character <- next start remove-between start, end # adjust cursor before-cursor <- copy start @@ -1682,16 +1682,16 @@ def delete-to-start-of-line editor:address:shared:editor-data -> result:address: scenario editor-deletes-to-start-of-line-with-ctrl-u-2 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [123 + 1:address:array:character <- new [123 456] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right # start on first line (no newline before), press ctrl-u assume-console [ left-click 1, 2 press ctrl-u ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # cursor deletes to start of line screen-should-contain [ @@ -1705,16 +1705,16 @@ scenario editor-deletes-to-start-of-line-with-ctrl-u-2 [ scenario editor-deletes-to-start-of-line-with-ctrl-u-3 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [123 + 1:address:array:character <- new [123 456] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right # start past end of line, press ctrl-u assume-console [ left-click 1, 3 press ctrl-u ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # cursor deletes to start of line screen-should-contain [ @@ -1728,16 +1728,16 @@ scenario editor-deletes-to-start-of-line-with-ctrl-u-3 [ scenario editor-deletes-to-start-of-final-line-with-ctrl-u [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [123 + 1:address:array:character <- new [123 456] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right # start past end of final line, press ctrl-u assume-console [ left-click 2, 3 press ctrl-u ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # cursor deletes to start of line screen-should-contain [ @@ -1753,16 +1753,16 @@ scenario editor-deletes-to-start-of-final-line-with-ctrl-u [ scenario editor-deletes-to-end-of-line-with-ctrl-k [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [123 + 1:address:array:character <- new [123 456] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right # start on first line, press ctrl-k assume-console [ left-click 1, 1 press ctrl-k ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # cursor deletes to end of line screen-should-contain [ @@ -1779,19 +1779,19 @@ after <handle-special-character> [ delete-to-end-of-line?:boolean <- equal c, 11/ctrl-k break-unless delete-to-end-of-line? <delete-to-end-of-line-begin> - deleted-cells:address:shared:duplex-list:character <- delete-to-end-of-line editor + deleted-cells:address:duplex-list:character <- delete-to-end-of-line editor <delete-to-end-of-line-end> go-render? <- copy 1/true return } ] -def delete-to-end-of-line editor:address:shared:editor-data -> result:address:shared:duplex-list:character, editor:address:shared:editor-data [ +def delete-to-end-of-line editor:address:editor-data -> result:address:duplex-list:character, editor:address:editor-data [ local-scope load-ingredients # compute range to delete - start:address:shared:duplex-list:character <- get *editor, before-cursor:offset - end:address:shared:duplex-list:character <- next start + start:address:duplex-list:character <- get *editor, before-cursor:offset + end:address:duplex-list:character <- next start { at-end-of-text?:boolean <- equal end, 0/null break-if at-end-of-text? @@ -1808,16 +1808,16 @@ def delete-to-end-of-line editor:address:shared:editor-data -> result:address:sh scenario editor-deletes-to-end-of-line-with-ctrl-k-2 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [123 + 1:address:array:character <- new [123 456] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right # start on second line (no newline after), press ctrl-k assume-console [ left-click 2, 1 press ctrl-k ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # cursor deletes to end of line screen-should-contain [ @@ -1831,16 +1831,16 @@ scenario editor-deletes-to-end-of-line-with-ctrl-k-2 [ scenario editor-deletes-to-end-of-line-with-ctrl-k-3 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [123 + 1:address:array:character <- new [123 456] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right # start at end of line assume-console [ left-click 1, 2 press ctrl-k ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # cursor deletes just last character screen-should-contain [ @@ -1854,16 +1854,16 @@ scenario editor-deletes-to-end-of-line-with-ctrl-k-3 [ scenario editor-deletes-to-end-of-line-with-ctrl-k-4 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [123 + 1:address:array:character <- new [123 456] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right # start past end of line assume-console [ left-click 1, 3 press ctrl-k ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # cursor deletes nothing screen-should-contain [ @@ -1877,16 +1877,16 @@ scenario editor-deletes-to-end-of-line-with-ctrl-k-4 [ scenario editor-deletes-to-end-of-line-with-ctrl-k-5 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [123 + 1:address:array:character <- new [123 456] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right # start at end of text assume-console [ left-click 2, 2 press ctrl-k ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # cursor deletes just the final character screen-should-contain [ @@ -1900,16 +1900,16 @@ scenario editor-deletes-to-end-of-line-with-ctrl-k-5 [ scenario editor-deletes-to-end-of-line-with-ctrl-k-6 [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [123 + 1:address:array:character <- new [123 456] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right # start past end of text assume-console [ left-click 2, 3 press ctrl-k ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # cursor deletes nothing screen-should-contain [ @@ -1927,11 +1927,11 @@ scenario editor-can-scroll-down-using-arrow-keys [ # screen has 1 line for menu + 3 lines assume-screen 10/width, 4/height # initialize editor with >3 lines - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b c d] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right screen-should-contain [ . . .a . @@ -1944,7 +1944,7 @@ d] press down-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen slides by one line screen-should-contain [ @@ -1957,11 +1957,11 @@ d] after <scroll-down> [ trace 10, [app], [scroll down] - top-of-screen:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + top-of-screen:address:duplex-list:character <- get *editor, top-of-screen:offset left:number <- get *editor, left:offset right:number <- get *editor, right:offset max:number <- subtract right, left - old-top:address:shared:duplex-list:character <- copy top-of-screen + old-top:address:duplex-list:character <- copy top-of-screen top-of-screen <- before-start-of-next-line top-of-screen, max *editor <- put *editor, top-of-screen:offset, top-of-screen no-movement?:boolean <- equal old-top, top-of-screen @@ -1972,11 +1972,11 @@ after <scroll-down> [ # takes a pointer into the doubly-linked list, scans ahead at most 'max' # positions until the next newline # beware: never return null pointer. -def before-start-of-next-line original:address:shared:duplex-list:character, max:number -> curr:address:shared:duplex-list:character [ +def before-start-of-next-line original:address:duplex-list:character, max:number -> curr:address:duplex-list:character [ local-scope load-ingredients count:number <- copy 0 - curr:address:shared:duplex-list:character <- copy original + curr:address:duplex-list:character <- copy original # skip the initial newline if it exists { c:character <- get *curr, value:offset @@ -2005,11 +2005,11 @@ scenario editor-scrolls-down-past-wrapped-line-using-arrow-keys [ assume-screen 10/width, 4/height # initialize editor with a long, wrapped line and more than a screen of # other lines - 1:address:shared:array:character <- new [abcdef + 1:address:array:character <- new [abcdef g h i] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right screen-should-contain [ . . .abcd↩ . @@ -2022,7 +2022,7 @@ i] press down-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen shows partial wrapped line screen-should-contain [ @@ -2037,18 +2037,18 @@ scenario editor-scrolls-down-past-wrapped-line-using-arrow-keys-2 [ # screen has 1 line for menu + 3 lines assume-screen 10/width, 4/height # editor starts with a long line wrapping twice - 1:address:shared:array:character <- new [abcdefghij + 1:address:array:character <- new [abcdefghij k l m] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right # position cursor at last line, then try to move further down assume-console [ left-click 3, 0 press down-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen shows partial wrapped line containing a wrap icon screen-should-contain [ @@ -2062,7 +2062,7 @@ m] press down-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen shows partial wrapped line screen-should-contain [ @@ -2077,19 +2077,19 @@ scenario editor-scrolls-down-when-line-wraps [ # screen has 1 line for menu + 3 lines assume-screen 5/width, 4/height # editor contains a long line in the third line - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b cdef] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right # position cursor at end, type a character assume-console [ left-click 3, 4 type [g] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # screen scrolls screen-should-contain [ @@ -2107,19 +2107,19 @@ cdef] scenario editor-scrolls-down-on-newline [ assume-screen 5/width, 4/height # position cursor after last line and type newline - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b c] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right assume-console [ left-click 3, 4 type [ ] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # screen scrolls screen-should-contain [ @@ -2138,19 +2138,19 @@ scenario editor-scrolls-down-on-right-arrow [ # screen has 1 line for menu + 3 lines assume-screen 5/width, 4/height # editor contains a wrapped line - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b cdefgh] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right # position cursor at end of screen and try to move right assume-console [ left-click 3, 3 press right-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # screen scrolls screen-should-contain [ @@ -2169,20 +2169,20 @@ scenario editor-scrolls-down-on-right-arrow-2 [ # screen has 1 line for menu + 3 lines assume-screen 5/width, 4/height # editor contains more lines than can fit on screen - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b c d] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right # position cursor at end of screen and try to move right assume-console [ left-click 3, 3 press right-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # screen scrolls screen-should-contain [ @@ -2199,10 +2199,10 @@ d] scenario editor-scrolls-at-end-on-down-arrow [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc de] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data $clear-trace # try to move down past end of text assume-console [ @@ -2210,9 +2210,9 @@ de] press down-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # screen should scroll, moving cursor to end of text memory-should-contain [ @@ -2223,7 +2223,7 @@ de] type [0] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -2238,9 +2238,9 @@ de] press down-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # screen stops scrolling because cursor is already at top memory-should-contain [ @@ -2252,7 +2252,7 @@ de] type [1] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -2266,14 +2266,14 @@ scenario editor-combines-page-and-line-scroll [ # screen has 1 line for menu + 3 lines assume-screen 10/width, 4/height # initialize editor with a few pages of lines - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b c d e f g] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right # scroll down one page and one line assume-console [ press page-down @@ -2281,7 +2281,7 @@ g] press down-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen scrolls down 3 lines screen-should-contain [ @@ -2298,11 +2298,11 @@ scenario editor-can-scroll-up-using-arrow-keys [ # screen has 1 line for menu + 3 lines assume-screen 10/width, 4/height # initialize editor with >3 lines - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b c d] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right screen-should-contain [ . . .a . @@ -2315,7 +2315,7 @@ d] press up-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen slides by one line screen-should-contain [ @@ -2328,8 +2328,8 @@ d] after <scroll-up> [ trace 10, [app], [scroll up] - top-of-screen:address:shared:duplex-list:character <- get *editor, top-of-screen:offset - old-top:address:shared:duplex-list:character <- copy top-of-screen + top-of-screen:address:duplex-list:character <- get *editor, top-of-screen:offset + old-top:address:duplex-list:character <- copy top-of-screen top-of-screen <- before-previous-line top-of-screen, editor *editor <- put *editor, top-of-screen:offset, top-of-screen no-movement?:boolean <- equal old-top, top-of-screen @@ -2340,10 +2340,10 @@ after <scroll-up> [ # takes a pointer into the doubly-linked list, scans back to before start of # previous *wrapped* line # beware: never return null pointer -def before-previous-line in:address:shared:duplex-list:character, editor:address:shared:editor-data -> out:address:shared:duplex-list:character [ +def before-previous-line in:address:duplex-list:character, editor:address:editor-data -> out:address:duplex-list:character [ local-scope load-ingredients - curr:address:shared:duplex-list:character <- copy in + curr:address:duplex-list:character <- copy in c:character <- get *curr, value:offset # compute max, number of characters to skip # 1 + len%(width-1) @@ -2351,12 +2351,12 @@ def before-previous-line in:address:shared:duplex-list:character, editor:address left:number <- get *editor, left:offset right:number <- get *editor, right:offset max-line-length:number <- subtract right, left, -1/exclusive-right, 1/wrap-icon - sentinel:address:shared:duplex-list:character <- get *editor, data:offset + sentinel:address:duplex-list:character <- get *editor, data:offset len:number <- previous-line-length curr, sentinel { break-if len # empty line; just skip this newline - prev:address:shared:duplex-list:character <- prev curr + prev:address:duplex-list:character <- prev curr return-unless prev, curr return prev } @@ -2372,7 +2372,7 @@ def before-previous-line in:address:shared:duplex-list:character, editor:address { done?:boolean <- greater-or-equal count, max break-if done? - prev:address:shared:duplex-list:character <- prev curr + prev:address:duplex-list:character <- prev curr break-unless prev curr <- copy prev count <- add count, 1 @@ -2386,11 +2386,11 @@ scenario editor-scrolls-up-past-wrapped-line-using-arrow-keys [ assume-screen 10/width, 4/height # initialize editor with a long, wrapped line and more than a screen of # other lines - 1:address:shared:array:character <- new [abcdef + 1:address:array:character <- new [abcdef g h i] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right screen-should-contain [ . . .abcd↩ . @@ -2402,7 +2402,7 @@ i] press page-down ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -2415,7 +2415,7 @@ i] press up-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen shows partial wrapped line screen-should-contain [ @@ -2430,17 +2430,17 @@ scenario editor-scrolls-up-past-wrapped-line-using-arrow-keys-2 [ # screen has 1 line for menu + 4 lines assume-screen 10/width, 5/height # editor starts with a long line wrapping twice, occupying 3 of the 4 lines - 1:address:shared:array:character <- new [abcdefghij + 1:address:array:character <- new [abcdefghij k l m] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right # position cursor at top of second page assume-console [ press page-down ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -2454,7 +2454,7 @@ m] press up-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen shows partial wrapped line screen-should-contain [ @@ -2469,7 +2469,7 @@ m] press up-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen shows partial wrapped line screen-should-contain [ @@ -2484,7 +2484,7 @@ m] press up-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen shows partial wrapped line screen-should-contain [ @@ -2503,11 +2503,11 @@ scenario editor-scrolls-up-past-wrapped-line-using-arrow-keys-3 [ assume-screen 10/width, 4/height # initialize editor with a long, wrapped line and more than a screen of # other lines - 1:address:shared:array:character <- new [abcdef + 1:address:array:character <- new [abcdef g h i] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 6/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 6/right screen-should-contain [ . . .abcde↩ . @@ -2519,7 +2519,7 @@ i] press page-down ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -2532,7 +2532,7 @@ i] press up-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen shows partial wrapped line screen-should-contain [ @@ -2547,18 +2547,18 @@ i] scenario editor-scrolls-up-past-wrapped-line-using-arrow-keys-4 [ assume-screen 10/width, 4/height # initialize editor with some lines around an empty line - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b c d e] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 6/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 6/right assume-console [ press page-down ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -2570,7 +2570,7 @@ e] press page-down ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -2582,7 +2582,7 @@ e] press page-up ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -2596,18 +2596,18 @@ scenario editor-scrolls-up-on-left-arrow [ # screen has 1 line for menu + 3 lines assume-screen 5/width, 4/height # editor contains >3 lines - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b c d e] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right # position cursor at top of second page assume-console [ press page-down ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -2620,9 +2620,9 @@ e] press left-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # screen scrolls screen-should-contain [ @@ -2641,11 +2641,11 @@ scenario editor-can-scroll-up-to-start-of-file [ # screen has 1 line for menu + 3 lines assume-screen 10/width, 4/height # initialize editor with >3 lines - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b c d] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right screen-should-contain [ . . .a . @@ -2660,7 +2660,7 @@ d] press up-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen slides by one line screen-should-contain [ @@ -2674,7 +2674,7 @@ d] press up-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen remains unchanged screen-should-contain [ @@ -2689,11 +2689,11 @@ d] scenario editor-can-scroll [ assume-screen 10/width, 4/height - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b c d] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right screen-should-contain [ . . .a . @@ -2705,7 +2705,7 @@ d] press page-down ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen shows next page screen-should-contain [ @@ -2720,12 +2720,12 @@ after <handle-special-character> [ { page-down?:boolean <- equal c, 6/ctrl-f break-unless page-down? - old-top:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + old-top:address:duplex-list:character <- get *editor, top-of-screen:offset <move-cursor-begin> page-down editor undo-coalesce-tag:number <- copy 0/never <move-cursor-end> - top-of-screen:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + top-of-screen:address:duplex-list:character <- get *editor, top-of-screen:offset no-movement?:boolean <- equal top-of-screen, old-top go-render? <- not no-movement? return @@ -2736,12 +2736,12 @@ after <handle-special-key> [ { page-down?:boolean <- equal k, 65518/page-down break-unless page-down? - old-top:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + old-top:address:duplex-list:character <- get *editor, top-of-screen:offset <move-cursor-begin> page-down editor undo-coalesce-tag:number <- copy 0/never <move-cursor-end> - top-of-screen:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + top-of-screen:address:duplex-list:character <- get *editor, top-of-screen:offset no-movement?:boolean <- equal top-of-screen, old-top go-render? <- not no-movement? return @@ -2750,15 +2750,15 @@ after <handle-special-key> [ # page-down skips entire wrapped lines, so it can't scroll past lines # taking up the entire screen -def page-down editor:address:shared:editor-data -> editor:address:shared:editor-data [ +def page-down editor:address:editor-data -> editor:address:editor-data [ local-scope load-ingredients # if editor contents don't overflow screen, do nothing - bottom-of-screen:address:shared:duplex-list:character <- get *editor, bottom-of-screen:offset + bottom-of-screen:address:duplex-list:character <- get *editor, bottom-of-screen:offset return-unless bottom-of-screen # if not, position cursor at final character - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset - before-cursor:address:shared:duplex-list:character <- prev bottom-of-screen + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset + before-cursor:address:duplex-list:character <- prev bottom-of-screen *editor <- put *editor, before-cursor:offset, before-cursor # keep one line in common with previous page { @@ -2776,10 +2776,10 @@ def page-down editor:address:shared:editor-data -> editor:address:shared:editor- scenario editor-does-not-scroll-past-end [ assume-screen 10/width, 4/height - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data screen-should-contain [ . . .a . @@ -2791,7 +2791,7 @@ b] press page-down ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen remains unmodified screen-should-contain [ @@ -2806,11 +2806,11 @@ scenario editor-starts-next-page-at-start-of-wrapped-line [ # screen has 1 line for menu + 3 lines for text assume-screen 10/width, 4/height # editor contains a long last line - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b cdefgh] # editor screen triggers wrap of last line - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 4/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 4/right # some part of last line is not displayed screen-should-contain [ . . @@ -2823,7 +2823,7 @@ cdefgh] press page-down ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen shows entire wrapped line screen-should-contain [ @@ -2839,9 +2839,9 @@ scenario editor-starts-next-page-at-start-of-wrapped-line-2 [ assume-screen 10/width, 4/height # editor contains a very long line that occupies last two lines of screen # and still has something left over - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a bcdefgh] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 4/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 4/right # some part of last line is not displayed screen-should-contain [ . . @@ -2854,7 +2854,7 @@ bcdefgh] press page-down ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen shows entire wrapped line screen-should-contain [ @@ -2869,11 +2869,11 @@ bcdefgh] scenario editor-can-scroll-up [ assume-screen 10/width, 4/height - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b c d] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right screen-should-contain [ . . .a . @@ -2885,7 +2885,7 @@ d] press page-down ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen shows next page screen-should-contain [ @@ -2899,7 +2899,7 @@ d] press page-up ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen shows original page again screen-should-contain [ @@ -2914,12 +2914,12 @@ after <handle-special-character> [ { page-up?:boolean <- equal c, 2/ctrl-b break-unless page-up? - old-top:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + old-top:address:duplex-list:character <- get *editor, top-of-screen:offset <move-cursor-begin> editor <- page-up editor, screen-height undo-coalesce-tag:number <- copy 0/never <move-cursor-end> - top-of-screen:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + top-of-screen:address:duplex-list:character <- get *editor, top-of-screen:offset no-movement?:boolean <- equal top-of-screen, old-top go-render? <- not no-movement? return @@ -2930,12 +2930,12 @@ after <handle-special-key> [ { page-up?:boolean <- equal k, 65519/page-up break-unless page-up? - old-top:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + old-top:address:duplex-list:character <- get *editor, top-of-screen:offset <move-cursor-begin> editor <- page-up editor, screen-height undo-coalesce-tag:number <- copy 0/never <move-cursor-end> - top-of-screen:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + top-of-screen:address:duplex-list:character <- get *editor, top-of-screen:offset no-movement?:boolean <- equal top-of-screen, old-top # don't bother re-rendering if nothing changed. todo: test this go-render? <- not no-movement? @@ -2943,16 +2943,16 @@ after <handle-special-key> [ } ] -def page-up editor:address:shared:editor-data, screen-height:number -> editor:address:shared:editor-data [ +def page-up editor:address:editor-data, screen-height:number -> editor:address:editor-data [ local-scope load-ingredients max:number <- subtract screen-height, 1/menu-bar, 1/overlapping-line count:number <- copy 0 - top-of-screen:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + top-of-screen:address:duplex-list:character <- get *editor, top-of-screen:offset { done?:boolean <- greater-or-equal count, max break-if done? - prev:address:shared:duplex-list:character <- before-previous-line top-of-screen, editor + prev:address:duplex-list:character <- before-previous-line top-of-screen, editor break-unless prev top-of-screen <- copy prev *editor <- put *editor, top-of-screen:offset, top-of-screen @@ -2965,7 +2965,7 @@ scenario editor-can-scroll-up-multiple-pages [ # screen has 1 line for menu + 3 lines assume-screen 10/width, 4/height # initialize editor with 8 lines - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b c d @@ -2973,7 +2973,7 @@ e f g h] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right screen-should-contain [ . . .a . @@ -2986,7 +2986,7 @@ h] press page-down ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen shows third page screen-should-contain [ @@ -3000,7 +3000,7 @@ h] press page-up ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen shows second page screen-should-contain [ @@ -3014,7 +3014,7 @@ h] press page-up ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen shows original page again screen-should-contain [ @@ -3029,7 +3029,7 @@ scenario editor-can-scroll-up-wrapped-lines [ # screen has 1 line for menu + 5 lines for text assume-screen 10/width, 6/height # editor contains a long line in the first page - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b cdefgh i @@ -3040,7 +3040,7 @@ m n o] # editor screen triggers wrap of last line - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 4/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 4/right # some part of last line is not displayed screen-should-contain [ . . @@ -3057,7 +3057,7 @@ o] press down-arrow ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen shows entire wrapped line screen-should-contain [ @@ -3073,7 +3073,7 @@ o] press page-up ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen resets screen-should-contain [ @@ -3091,9 +3091,9 @@ scenario editor-can-scroll-up-wrapped-lines-2 [ assume-screen 10/width, 4/height # editor contains a very long line that occupies last two lines of screen # and still has something left over - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a bcdefgh] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 4/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 4/right # some part of last line is not displayed screen-should-contain [ . . @@ -3106,7 +3106,7 @@ bcdefgh] press page-down ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen shows entire wrapped line screen-should-contain [ @@ -3120,7 +3120,7 @@ bcdefgh] press page-up ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # screen resets screen-should-contain [ @@ -3134,7 +3134,7 @@ bcdefgh] scenario editor-can-scroll-up-past-nonempty-lines [ assume-screen 10/width, 4/height # text with empty line in second screen - 1:address:shared:array:character <- new [axx + 1:address:array:character <- new [axx bxx cxx dxx @@ -3143,7 +3143,7 @@ fxx gxx hxx ] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 4/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 4/right screen-should-contain [ . . .axx . @@ -3154,7 +3154,7 @@ hxx press page-down ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -3166,7 +3166,7 @@ hxx press page-down ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -3179,7 +3179,7 @@ hxx press page-up ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -3192,7 +3192,7 @@ hxx scenario editor-can-scroll-up-past-empty-lines [ assume-screen 10/width, 4/height # text with empty line in second screen - 1:address:shared:array:character <- new [axy + 1:address:array:character <- new [axy bxy cxy @@ -3201,7 +3201,7 @@ exy fxy gxy ] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 4/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 4/right screen-should-contain [ . . .axy . @@ -3212,7 +3212,7 @@ gxy press page-down ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -3224,7 +3224,7 @@ gxy press page-down ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -3237,7 +3237,7 @@ gxy press page-up ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . diff --git a/sandbox/004-programming-environment.mu b/sandbox/004-programming-environment.mu index 22fe6745..63c6df3c 100644 --- a/sandbox/004-programming-environment.mu +++ b/sandbox/004-programming-environment.mu @@ -3,12 +3,12 @@ def! main [ local-scope open-console - initial-sandbox:address:shared:array:character <- new [] + initial-sandbox:address:array:character <- new [] hide-screen 0/screen - env:address:shared:programming-environment-data <- new-programming-environment 0/screen, initial-sandbox + env:address:programming-environment-data <- new-programming-environment 0/screen, initial-sandbox env <- restore-sandboxes env render-sandbox-side 0/screen, env - current-sandbox:address:shared:editor-data <- get *env, current-sandbox:offset + current-sandbox:address:editor-data <- get *env, current-sandbox:offset update-cursor 0/screen, current-sandbox, env show-screen 0/screen event-loop 0/screen, 0/console, env @@ -16,10 +16,10 @@ def! main [ ] container programming-environment-data [ - current-sandbox:address:shared:editor-data + current-sandbox:address:editor-data ] -def new-programming-environment screen:address:shared:screen, initial-sandbox-contents:address:shared:array:character -> result:address:shared:programming-environment-data, screen:address:shared:screen [ +def new-programming-environment screen:address:screen, initial-sandbox-contents:address:array:character -> result:address:programming-environment-data, screen:address:screen [ local-scope load-ingredients width:number <- screen-width screen @@ -33,15 +33,15 @@ def new-programming-environment screen:address:shared:screen, initial-sandbox-co screen <- move-cursor screen, 0/row, button-start print screen, [ run (F4) ], 255/white, 161/reddish # sandbox editor - current-sandbox:address:shared:editor-data <- new-editor initial-sandbox-contents, screen, 0, width/right + current-sandbox:address:editor-data <- new-editor initial-sandbox-contents, screen, 0, width/right *result <- put *result, current-sandbox:offset, current-sandbox <programming-environment-initialization> ] -def event-loop screen:address:shared:screen, console:address:shared:console, env:address:shared:programming-environment-data -> screen:address:shared:screen, console:address:shared:console, env:address:shared:programming-environment-data [ +def event-loop screen:address:screen, console:address:console, env:address:programming-environment-data -> screen:address:screen, console:address:console, env:address:programming-environment-data [ local-scope load-ingredients - current-sandbox:address:shared:editor-data <- get *env, current-sandbox:offset + current-sandbox:address:editor-data <- get *env, current-sandbox:offset # if we fall behind we'll stop updating the screen, but then we have to # render the entire screen when we catch up. # todo: test this @@ -135,13 +135,13 @@ def event-loop screen:address:shared:screen, console:address:shared:console, env } ] -def resize screen:address:shared:screen, env:address:shared:programming-environment-data -> env:address:shared:programming-environment-data, screen:address:shared:screen [ +def resize screen:address:screen, env:address:programming-environment-data -> env:address:programming-environment-data, screen:address:screen [ local-scope load-ingredients clear-screen screen # update screen dimensions width:number <- screen-width screen # update sandbox editor - current-sandbox:address:shared:editor-data <- get *env, current-sandbox:offset + current-sandbox:address:editor-data <- get *env, current-sandbox:offset right:number <- subtract width, 1 *current-sandbox <- put *current-sandbox right:offset, right # reset cursor @@ -149,7 +149,7 @@ def resize screen:address:shared:screen, env:address:shared:programming-environm *current-sandbox <- put *current-sandbox, cursor-column:offset, 0 ] -def render-all screen:address:shared:screen, env:address:shared:programming-environment-data -> screen:address:shared:screen, env:address:shared:programming-environment-data [ +def render-all screen:address:screen, env:address:programming-environment-data -> screen:address:screen, env:address:programming-environment-data [ local-scope load-ingredients trace 10, [app], [render all] @@ -167,17 +167,17 @@ def render-all screen:address:shared:screen, env:address:shared:programming-envi screen <- render-sandbox-side screen, env <render-components-end> # - current-sandbox:address:shared:editor-data <- get *env, current-sandbox:offset + current-sandbox:address:editor-data <- get *env, current-sandbox:offset screen <- update-cursor screen, current-sandbox, env # show-screen screen ] # replaced in a later layer -def render-sandbox-side screen:address:shared:screen, env:address:shared:programming-environment-data -> screen:address:shared:screen, env:address:shared:programming-environment-data [ +def render-sandbox-side screen:address:screen, env:address:programming-environment-data -> screen:address:screen, env:address:programming-environment-data [ local-scope load-ingredients - current-sandbox:address:shared:editor-data <- get *env, current-sandbox:offset + current-sandbox:address:editor-data <- get *env, current-sandbox:offset left:number <- get *current-sandbox, left:offset right:number <- get *current-sandbox, right:offset row:number, column:number, screen, current-sandbox <- render screen, current-sandbox @@ -189,7 +189,7 @@ def render-sandbox-side screen:address:shared:screen, env:address:shared:program clear-screen-from screen, row, left, left, right ] -def update-cursor screen:address:shared:screen, current-sandbox:address:shared:editor-data, env:address:shared:programming-environment-data -> screen:address:shared:screen [ +def update-cursor screen:address:screen, current-sandbox:address:editor-data, env:address:programming-environment-data -> screen:address:screen [ local-scope load-ingredients <update-cursor-special-cases> @@ -200,7 +200,7 @@ def update-cursor screen:address:shared:screen, current-sandbox:address:shared:e # print a text 's' to 'editor' in 'color' starting at 'row' # clear rest of last line, move cursor to next line -def render screen:address:shared:screen, s:address:shared:array:character, left:number, right:number, color:number, row:number -> row:number, screen:address:shared:screen [ +def render screen:address:screen, s:address:array:character, left:number, right:number, color:number, row:number -> row:number, screen:address:screen [ local-scope load-ingredients return-unless s @@ -261,7 +261,7 @@ def render screen:address:shared:screen, s:address:shared:array:character, left: ] # like 'render' for texts, but with colorization for comments like in the editor -def render-code screen:address:shared:screen, s:address:shared:array:character, left:number, right:number, row:number -> row:number, screen:address:shared:screen [ +def render-code screen:address:screen, s:address:array:character, left:number, right:number, row:number -> row:number, screen:address:screen [ local-scope load-ingredients return-unless s @@ -329,13 +329,13 @@ after <global-type> [ { redraw-screen?:boolean <- equal c, 12/ctrl-l break-unless redraw-screen? - screen <- render-all screen, env:address:shared:programming-environment-data + screen <- render-all screen, env:address:programming-environment-data sync-screen screen loop +next-event:label } ] # dummy -def restore-sandboxes env:address:shared:programming-environment-data -> env:address:shared:programming-environment-data [ +def restore-sandboxes env:address:programming-environment-data -> env:address:programming-environment-data [ # do nothing; redefined later ] diff --git a/sandbox/005-sandbox.mu b/sandbox/005-sandbox.mu index 7297c768..c946fba2 100644 --- a/sandbox/005-sandbox.mu +++ b/sandbox/005-sandbox.mu @@ -5,7 +5,7 @@ # few other things. container programming-environment-data [ - sandbox:address:shared:sandbox-data # list of sandboxes, from top to bottom + sandbox:address:sandbox-data # list of sandboxes, from top to bottom render-from:number number-of-sandboxes:number ] @@ -15,28 +15,28 @@ after <programming-environment-initialization> [ ] container sandbox-data [ - data:address:shared:array:character - response:address:shared:array:character + data:address:array:character + response:address:array:character # coordinates to track clicks # constraint: will be 0 for sandboxes at positions before env.render-from starting-row-on-screen:number code-ending-row-on-screen:number # past end of code - screen:address:shared:screen # prints in the sandbox go here - next-sandbox:address:shared:sandbox-data + screen:address:screen # prints in the sandbox go here + next-sandbox:address:sandbox-data ] scenario run-and-show-results [ trace-until 100/app # trace too long assume-screen 50/width, 15/height # sandbox editor contains an instruction without storing outputs - 1:address:shared:array:character <- new [divide-with-remainder 11, 3] - 2:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character + 1:address:array:character <- new [divide-with-remainder 11, 3] + 2:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character # run the code in the editors assume-console [ press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data ] # check that screen prints the results screen-should-contain [ @@ -86,7 +86,7 @@ scenario run-and-show-results [ press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data ] # check that screen prints both sandboxes screen-should-contain [ @@ -112,7 +112,7 @@ after <global-keypress> [ do-run?:boolean <- equal k, 65532/F4 break-unless do-run? screen <- update-status screen, [running... ], 245/grey - test-recipes:address:shared:array:character, _/optional <- next-ingredient + test-recipes:address:array:character, _/optional <- next-ingredient error?:boolean, env, screen <- run-sandboxes env, screen, test-recipes #? test-recipes <- copy 0 # abandon # F4 might update warnings and results on both sides @@ -126,22 +126,22 @@ after <global-keypress> [ } ] -def run-sandboxes env:address:shared:programming-environment-data, screen:address:shared:screen, test-recipes:address:shared:array:character -> errors-found?:boolean, env:address:shared:programming-environment-data, screen:address:shared:screen [ +def run-sandboxes env:address:programming-environment-data, screen:address:screen, test-recipes:address:array:character -> errors-found?:boolean, env:address:programming-environment-data, screen:address:screen [ local-scope load-ingredients errors-found?:boolean, env, screen <- update-recipes env, screen, test-recipes # check contents of editor <run-sandboxes-begin> - current-sandbox:address:shared:editor-data <- get *env, current-sandbox:offset + current-sandbox:address:editor-data <- get *env, current-sandbox:offset { - sandbox-contents:address:shared:array:character <- editor-contents current-sandbox + sandbox-contents:address:array:character <- editor-contents current-sandbox break-unless sandbox-contents # if contents exist, first save them # run them and turn them into a new sandbox-data - new-sandbox:address:shared:sandbox-data <- new sandbox-data:type + new-sandbox:address:sandbox-data <- new sandbox-data:type *new-sandbox <- put *new-sandbox, data:offset, sandbox-contents # push to head of sandbox list - dest:address:shared:sandbox-data <- get *env, sandbox:offset + dest:address:sandbox-data <- get *env, sandbox:offset *new-sandbox <- put *new-sandbox, next-sandbox:offset, dest *env <- put *env, sandbox:offset, new-sandbox # update sandbox count @@ -149,14 +149,14 @@ def run-sandboxes env:address:shared:programming-environment-data, screen:addres sandbox-count <- add sandbox-count, 1 *env <- put *env, number-of-sandboxes:offset, sandbox-count # clear sandbox editor - init:address:shared:duplex-list:character <- push 167/§, 0/tail + init:address:duplex-list:character <- push 167/§, 0/tail *current-sandbox <- put *current-sandbox, data:offset, init *current-sandbox <- put *current-sandbox, top-of-screen:offset, init } # save all sandboxes before running, just in case we die when running save-sandboxes env # run all sandboxes - curr:address:shared:sandbox-data <- get *env, sandbox:offset + curr:address:sandbox-data <- get *env, sandbox:offset idx:number <- copy 0 { break-unless curr @@ -170,12 +170,12 @@ def run-sandboxes env:address:shared:programming-environment-data, screen:addres # load code from recipes.mu, or from test-recipes in tests # replaced in a later layer (whereupon errors-found? will actually be set) -def update-recipes env:address:shared:programming-environment-data, screen:address:shared:screen, test-recipes:address:shared:array:character -> errors-found?:boolean, env:address:shared:programming-environment-data, screen:address:shared:screen [ +def update-recipes env:address:programming-environment-data, screen:address:screen, test-recipes:address:array:character -> errors-found?:boolean, env:address:programming-environment-data, screen:address:screen [ local-scope load-ingredients { break-if test-recipes - in:address:shared:array:character <- restore [recipes.mu] # newlayer: persistence + in:address:array:character <- restore [recipes.mu] # newlayer: persistence reload in } { @@ -186,34 +186,34 @@ def update-recipes env:address:shared:programming-environment-data, screen:addre ] # replaced in a later layer -def! update-sandbox sandbox:address:shared:sandbox-data, env:address:shared:programming-environment-data, idx:number -> sandbox:address:shared:sandbox-data, env:address:shared:programming-environment-data [ +def! update-sandbox sandbox:address:sandbox-data, env:address:programming-environment-data, idx:number -> sandbox:address:sandbox-data, env:address:programming-environment-data [ local-scope load-ingredients - data:address:shared:array:character <- get *sandbox, data:offset - response:address:shared:array:character, _, fake-screen:address:shared:screen <- run-interactive data + data:address:array:character <- get *sandbox, data:offset + response:address:array:character, _, fake-screen:address:screen <- run-interactive data *sandbox <- put *sandbox, response:offset, response *sandbox <- put *sandbox, screen:offset, fake-screen ] -def update-status screen:address:shared:screen, msg:address:shared:array:character, color:number -> screen:address:shared:screen [ +def update-status screen:address:screen, msg:address:array:character, color:number -> screen:address:screen [ local-scope load-ingredients screen <- move-cursor screen, 0, 2 screen <- print screen, msg, color, 238/grey/background ] -def save-sandboxes env:address:shared:programming-environment-data [ +def save-sandboxes env:address:programming-environment-data [ local-scope load-ingredients - current-sandbox:address:shared:editor-data <- get *env, current-sandbox:offset + current-sandbox:address:editor-data <- get *env, current-sandbox:offset # first clear previous versions, in case we deleted some sandbox $system [rm lesson/[0-9]* >/dev/null 2>/dev/null] # some shells can't handle '>&' - curr:address:shared:sandbox-data <- get *env, sandbox:offset + curr:address:sandbox-data <- get *env, sandbox:offset idx:number <- copy 0 { break-unless curr - data:address:shared:array:character <- get *curr, data:offset - filename:address:shared:array:character <- to-text idx + data:address:array:character <- get *curr, data:offset + filename:address:array:character <- to-text idx save filename, data <end-save-sandbox> idx <- add idx, 1 @@ -222,11 +222,11 @@ def save-sandboxes env:address:shared:programming-environment-data [ } ] -def! render-sandbox-side screen:address:shared:screen, env:address:shared:programming-environment-data -> screen:address:shared:screen, env:address:shared:programming-environment-data [ +def! render-sandbox-side screen:address:screen, env:address:programming-environment-data -> screen:address:screen, env:address:programming-environment-data [ local-scope load-ingredients trace 11, [app], [render sandbox side] - current-sandbox:address:shared:editor-data <- get *env, current-sandbox:offset + current-sandbox:address:editor-data <- get *env, current-sandbox:offset row:number, column:number <- copy 1, 0 left:number <- get *current-sandbox, left:offset right:number <- get *current-sandbox, right:offset @@ -241,15 +241,15 @@ def! render-sandbox-side screen:address:shared:screen, env:address:shared:progra } # render sandboxes draw-horizontal screen, row, left, right, 9473/horizontal-double - sandbox:address:shared:sandbox-data <- get *env, sandbox:offset + sandbox:address:sandbox-data <- get *env, sandbox:offset row, screen <- render-sandboxes screen, sandbox, left, right, row, render-from, 0, env clear-rest-of-screen screen, row, left, right ] -def render-sandboxes screen:address:shared:screen, sandbox:address:shared:sandbox-data, left:number, right:number, row:number, render-from:number, idx:number -> row:number, screen:address:shared:screen, sandbox:address:shared:sandbox-data [ +def render-sandboxes screen:address:screen, sandbox:address:sandbox-data, left:number, right:number, row:number, render-from:number, idx:number -> row:number, screen:address:screen, sandbox:address:sandbox-data [ local-scope load-ingredients - env:address:shared:programming-environment-data, _/optional <- next-ingredient + env:address:programming-environment-data, _/optional <- next-ingredient return-unless sandbox screen-height:number <- screen-height screen at-bottom?:boolean <- greater-or-equal row, screen-height @@ -269,14 +269,14 @@ def render-sandboxes screen:address:shared:screen, sandbox:address:shared:sandbo # render sandbox contents row <- add row, 1 screen <- move-cursor screen, row, left - sandbox-data:address:shared:array:character <- get *sandbox, data:offset + sandbox-data:address:array:character <- get *sandbox, data:offset row, screen <- render-code screen, sandbox-data, left, right, row *sandbox <- put *sandbox, code-ending-row-on-screen:offset, row # render sandbox warnings, screen or response, in that order - sandbox-response:address:shared:array:character <- get *sandbox, response:offset + sandbox-response:address:array:character <- get *sandbox, response:offset <render-sandbox-results> { - sandbox-screen:address:shared:screen <- get *sandbox, screen:offset + sandbox-screen:address:screen <- get *sandbox, screen:offset empty-screen?:boolean <- fake-screen-is-empty? sandbox-screen break-if empty-screen? row, screen <- render-screen screen, sandbox-screen, left, right, row @@ -300,22 +300,22 @@ def render-sandboxes screen:address:shared:screen, sandbox:address:shared:sandbo <end-render-sandbox-reset-hidden> } # draw next sandbox - next-sandbox:address:shared:sandbox-data <- get *sandbox, next-sandbox:offset + next-sandbox:address:sandbox-data <- get *sandbox, next-sandbox:offset next-idx:number <- add idx, 1 row, screen <- render-sandboxes screen, next-sandbox, left, right, row, render-from, next-idx, env ] # assumes programming environment has no sandboxes; restores them from previous session -def! restore-sandboxes env:address:shared:programming-environment-data -> env:address:shared:programming-environment-data [ +def! restore-sandboxes env:address:programming-environment-data -> env:address:programming-environment-data [ local-scope load-ingredients # read all scenarios, pushing them to end of a list of scenarios idx:number <- copy 0 - curr:address:shared:sandbox-data <- copy 0 - prev:address:shared:sandbox-data <- copy 0 + curr:address:sandbox-data <- copy 0 + prev:address:sandbox-data <- copy 0 { - filename:address:shared:array:character <- to-text idx - contents:address:shared:array:character <- restore filename + filename:address:array:character <- to-text idx + contents:address:array:character <- restore filename break-unless contents # stop at first error; assuming file didn't exist # create new sandbox for file curr <- new sandbox-data:type @@ -343,7 +343,7 @@ def! restore-sandboxes env:address:shared:programming-environment-data -> env:ad # print the fake sandbox screen to 'screen' with appropriate delimiters # leave cursor at start of next line -def render-screen screen:address:shared:screen, sandbox-screen:address:shared:screen, left:number, right:number, row:number -> row:number, screen:address:shared:screen [ +def render-screen screen:address:screen, sandbox-screen:address:screen, left:number, right:number, row:number -> row:number, screen:address:screen [ local-scope load-ingredients return-unless sandbox-screen @@ -354,7 +354,7 @@ def render-screen screen:address:shared:screen, sandbox-screen:address:shared:sc column:number <- copy left s-width:number <- screen-width sandbox-screen s-height:number <- screen-height sandbox-screen - buf:address:shared:array:screen-cell <- get *sandbox-screen, data:offset + buf:address:array:screen-cell <- get *sandbox-screen, data:offset stop-printing:number <- add left, s-width, 3 max-column:number <- min stop-printing, right i:number <- copy 0 @@ -412,20 +412,20 @@ scenario run-updates-results [ trace-until 100/app # trace too long assume-screen 50/width, 12/height # define a recipe (no indent for the 'add' line below so column numbers are more obvious) - 1:address:shared:array:character <- new [ + 1:address:array:character <- new [ def foo [ local-scope z:number <- add 2, 2 return z ]] # sandbox editor contains an instruction without storing outputs - 2:address:shared:array:character <- new [foo] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 2:address:shared:array:character + 2:address:array:character <- new [foo] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 2:address:array:character # run the code in the editors assume-console [ press F4 ] - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data, 1:address:shared:array:character/recipes + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data, 1:address:array:character/recipes screen-should-contain [ . run (F4) . . . @@ -437,7 +437,7 @@ return z . . ] # make a change (incrementing one of the args to 'add'), then rerun - 1:address:shared:array:character <- new [ + 1:address:array:character <- new [ def foo [ local-scope z:number <- add 2, 3 @@ -447,7 +447,7 @@ return z press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data, 1:address:shared:array:character/recipes + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data, 1:address:array:character/recipes ] # check that screen updates the result on the right screen-should-contain [ @@ -466,14 +466,14 @@ scenario run-instruction-manages-screen-per-sandbox [ trace-until 100/app # trace too long assume-screen 50/width, 20/height # editor contains an instruction - 1:address:shared:array:character <- new [print-integer screen, 4] - 2:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character + 1:address:array:character <- new [print-integer screen, 4] + 2:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character # run the code in the editor assume-console [ press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data ] # check that it prints a little toy screen screen-should-contain [ @@ -493,11 +493,11 @@ scenario run-instruction-manages-screen-per-sandbox [ ] ] -def editor-contents editor:address:shared:editor-data -> result:address:shared:array:character [ +def editor-contents editor:address:editor-data -> result:address:array:character [ local-scope load-ingredients - buf:address:shared:buffer <- new-buffer 80 - curr:address:shared:duplex-list:character <- get *editor, data:offset + buf:address:buffer <- new-buffer 80 + curr:address:duplex-list:character <- get *editor, data:offset # skip § sentinel assert curr, [editor without data is illegal; must have at least a sentinel] curr <- next curr @@ -514,16 +514,16 @@ def editor-contents editor:address:shared:editor-data -> result:address:shared:a scenario editor-provides-edited-contents [ assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right + 1:address:array:character <- new [abc] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right assume-console [ left-click 1, 2 type [def] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:address:shared:array:character <- editor-contents 2:address:shared:editor-data - 4:array:character <- copy *3:address:shared:array:character + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:address:array:character <- editor-contents 2:address:editor-data + 4:array:character <- copy *3:address:array:character ] memory-should-contain [ 4:array:character <- [abdefc] @@ -536,9 +536,9 @@ scenario scrolling-down-past-bottom-of-sandbox-editor [ trace-until 100/app # trace too long assume-screen 50/width, 20/height # initialize - 1:address:shared:array:character <- new [add 2, 2] - 2:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character - render-all screen, 2:address:shared:programming-environment-data + 1:address:array:character <- new [add 2, 2] + 2:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character + render-all screen, 2:address:programming-environment-data assume-console [ # create a sandbox press F4 @@ -546,9 +546,9 @@ scenario scrolling-down-past-bottom-of-sandbox-editor [ type [abc ] ] - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data 3:character/cursor <- copy 9251/␣ - print screen:address:shared:screen, 3:character/cursor + print screen:address:screen, 3:character/cursor screen-should-contain [ . run (F4) . .abc . @@ -565,9 +565,9 @@ scenario scrolling-down-past-bottom-of-sandbox-editor [ press down-arrow ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data 3:character/cursor <- copy 9251/␣ - print screen:address:shared:screen, 3:character/cursor + print screen:address:screen, 3:character/cursor ] # sandbox editor hidden; first sandbox displayed # cursor moves to first sandbox @@ -585,9 +585,9 @@ scenario scrolling-down-past-bottom-of-sandbox-editor [ press up-arrow ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data 3:character/cursor <- copy 9251/␣ - print screen:address:shared:screen, 3:character/cursor + print screen:address:screen, 3:character/cursor ] # sandbox editor displays again screen-should-contain [ @@ -612,7 +612,7 @@ after <global-keypress> [ sandbox-cursor:number <- get *current-sandbox, cursor-row:offset sandbox-cursor-on-last-line?:boolean <- equal sandbox-bottom, sandbox-cursor break-unless sandbox-cursor-on-last-line? - sandbox:address:shared:sandbox-data <- get *env, sandbox:offset + sandbox:address:sandbox-data <- get *env, sandbox:offset break-unless sandbox # slide down if possible { @@ -662,12 +662,12 @@ after <global-keypress> [ # sandbox belonging to 'env' whose next-sandbox is 'in' # return 0 if there's no such sandbox, either because 'in' doesn't exist in 'env', or because it's the first sandbox -def previous-sandbox env:address:shared:programming-environment-data, in:address:shared:sandbox-data -> out:address:shared:sandbox-data [ +def previous-sandbox env:address:programming-environment-data, in:address:sandbox-data -> out:address:sandbox-data [ local-scope load-ingredients - curr:address:shared:sandbox-data <- get *env, sandbox:offset + curr:address:sandbox-data <- get *env, sandbox:offset return-unless curr, 0/nil - next:address:shared:sandbox-data <- get *curr, next-sandbox:offset + next:address:sandbox-data <- get *curr, next-sandbox:offset { return-unless next, 0/nil found?:boolean <- equal next, in @@ -683,9 +683,9 @@ scenario scrolling-through-multiple-sandboxes [ trace-until 100/app # trace too long assume-screen 50/width, 20/height # initialize environment - 1:address:shared:array:character <- new [] - 2:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character - render-all screen, 2:address:shared:programming-environment-data + 1:address:array:character <- new [] + 2:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character + render-all screen, 2:address:programming-environment-data # create 2 sandboxes assume-console [ press ctrl-n @@ -694,9 +694,9 @@ scenario scrolling-through-multiple-sandboxes [ type [add 1, 1] press F4 ] - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data 3:character/cursor <- copy 9251/␣ - print screen:address:shared:screen, 3:character/cursor + print screen:address:screen, 3:character/cursor screen-should-contain [ . run (F4) . .␣ . @@ -716,9 +716,9 @@ scenario scrolling-through-multiple-sandboxes [ press down-arrow ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data 3:character/cursor <- copy 9251/␣ - print screen:address:shared:screen, 3:character/cursor + print screen:address:screen, 3:character/cursor ] # sandbox editor hidden; first sandbox displayed # cursor moves to first sandbox @@ -740,7 +740,7 @@ scenario scrolling-through-multiple-sandboxes [ press down-arrow ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data ] # just second sandbox displayed screen-should-contain [ @@ -757,7 +757,7 @@ scenario scrolling-through-multiple-sandboxes [ press down-arrow ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data ] # no change screen-should-contain [ @@ -774,7 +774,7 @@ scenario scrolling-through-multiple-sandboxes [ press up-arrow ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data ] # back to displaying both sandboxes without editor screen-should-contain [ @@ -795,9 +795,9 @@ scenario scrolling-through-multiple-sandboxes [ press up-arrow ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data 3:character/cursor <- copy 9251/␣ - print screen:address:shared:screen, 3:character/cursor + print screen:address:screen, 3:character/cursor ] # back to displaying both sandboxes as well as editor screen-should-contain [ @@ -819,7 +819,7 @@ scenario scrolling-through-multiple-sandboxes [ press up-arrow ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data ] # no change screen-should-contain [ @@ -842,16 +842,16 @@ scenario scrolling-manages-sandbox-index-correctly [ trace-until 100/app # trace too long assume-screen 50/width, 20/height # initialize environment - 1:address:shared:array:character <- new [] - 2:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character - render-all screen, 2:address:shared:programming-environment-data + 1:address:array:character <- new [] + 2:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character + render-all screen, 2:address:programming-environment-data # create a sandbox assume-console [ press ctrl-n type [add 1, 1] press F4 ] - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data screen-should-contain [ . run (F4) . . . @@ -867,7 +867,7 @@ scenario scrolling-manages-sandbox-index-correctly [ press down-arrow ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data ] # sandbox editor hidden; first sandbox displayed # cursor moves to first sandbox @@ -885,7 +885,7 @@ scenario scrolling-manages-sandbox-index-correctly [ press up-arrow ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data ] # back to displaying both sandboxes as well as editor screen-should-contain [ @@ -903,7 +903,7 @@ scenario scrolling-manages-sandbox-index-correctly [ press down-arrow ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data ] # sandbox editor hidden; first sandbox displayed # cursor moves to first sandbox diff --git a/sandbox/006-sandbox-edit.mu b/sandbox/006-sandbox-edit.mu index 91c632ed..ae23c20b 100644 --- a/sandbox/006-sandbox-edit.mu +++ b/sandbox/006-sandbox-edit.mu @@ -4,12 +4,12 @@ scenario clicking-on-a-sandbox-moves-it-to-editor [ trace-until 100/app # trace too long assume-screen 40/width, 10/height # run something - 1:address:shared:array:character <- new [add 2, 2] + 1:address:array:character <- new [add 2, 2] assume-console [ press F4 ] - 2:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + 2:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data screen-should-contain [ . run (F4) . . . @@ -27,7 +27,7 @@ scenario clicking-on-a-sandbox-moves-it-to-editor [ left-click 3, 0 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data ] # it pops back into editor screen-should-contain [ @@ -47,7 +47,7 @@ scenario clicking-on-a-sandbox-moves-it-to-editor [ type [0] ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data ] screen-should-contain [ . run (F4) . @@ -70,7 +70,7 @@ after <global-touch> [ click-column:number <- get t, column:offset on-sandbox-side?:boolean <- greater-or-equal click-column, sandbox-left-margin break-unless on-sandbox-side? - first-sandbox:address:shared:sandbox-data <- get *env, sandbox:offset + first-sandbox:address:sandbox-data <- get *env, sandbox:offset break-unless first-sandbox first-sandbox-begins:number <- get *first-sandbox, starting-row-on-screen:offset click-row:number <- get t, row:offset @@ -79,9 +79,9 @@ after <global-touch> [ empty-sandbox-editor?:boolean <- empty-editor? current-sandbox break-unless empty-sandbox-editor? # don't clobber existing contents # identify the sandbox to edit and remove it from the sandbox list - sandbox:address:shared:sandbox-data <- extract-sandbox env, click-row + sandbox:address:sandbox-data <- extract-sandbox env, click-row break-unless sandbox - text:address:shared:array:character <- get *sandbox, data:offset + text:address:array:character <- get *sandbox, data:offset current-sandbox <- insert-text current-sandbox, text *env <- put *env, render-from:offset, -1 hide-screen screen @@ -92,18 +92,18 @@ after <global-touch> [ } ] -def empty-editor? editor:address:shared:editor-data -> result:boolean [ +def empty-editor? editor:address:editor-data -> result:boolean [ local-scope load-ingredients - head:address:shared:duplex-list:character <- get *editor, data:offset - first:address:shared:duplex-list:character <- next head + head:address:duplex-list:character <- get *editor, data:offset + first:address:duplex-list:character <- next head result <- not first ] -def extract-sandbox env:address:shared:programming-environment-data, click-row:number -> result:address:shared:sandbox-data, env:address:shared:programming-environment-data [ +def extract-sandbox env:address:programming-environment-data, click-row:number -> result:address:sandbox-data, env:address:programming-environment-data [ local-scope load-ingredients - curr-sandbox:address:shared:sandbox-data <- get *env, sandbox:offset + curr-sandbox:address:sandbox-data <- get *env, sandbox:offset start:number <- get *curr-sandbox, starting-row-on-screen:offset in-editor?:boolean <- lesser-than click-row, start return-if in-editor?, 0 @@ -111,16 +111,16 @@ def extract-sandbox env:address:shared:programming-environment-data, click-row:n { # first sandbox? pop break-unless first-sandbox? - next-sandbox:address:shared:sandbox-data <- get *curr-sandbox, next-sandbox:offset + next-sandbox:address:sandbox-data <- get *curr-sandbox, next-sandbox:offset *env <- put *env, sandbox:offset, next-sandbox } { # not first sandbox? break-if first-sandbox? - prev-sandbox:address:shared:sandbox-data <- copy curr-sandbox + prev-sandbox:address:sandbox-data <- copy curr-sandbox curr-sandbox <- get *curr-sandbox, next-sandbox:offset { - next-sandbox:address:shared:sandbox-data <- get *curr-sandbox, next-sandbox:offset + next-sandbox:address:sandbox-data <- get *curr-sandbox, next-sandbox:offset break-unless next-sandbox # if click-row < sandbox.next-sandbox.starting-row-on-screen, break next-start:number <- get *next-sandbox, starting-row-on-screen:offset @@ -144,13 +144,13 @@ scenario sandbox-with-print-can-be-edited [ trace-until 100/app # trace too long assume-screen 50/width, 20/height # run a print instruction - 1:address:shared:array:character <- new [print-integer screen, 4] - 2:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character + 1:address:array:character <- new [print-integer screen, 4] + 2:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character # run the sandbox assume-console [ press F4 ] - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data screen-should-contain [ . run (F4) . . . @@ -171,7 +171,7 @@ scenario sandbox-with-print-can-be-edited [ left-click 3, 70 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data ] screen-should-contain [ . run (F4) . @@ -186,9 +186,9 @@ scenario editing-sandbox-after-scrolling-resets-scroll [ trace-until 100/app # trace too long assume-screen 50/width, 20/height # initialize environment - 1:address:shared:array:character <- new [] - 2:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character - render-all screen, 2:address:shared:programming-environment-data + 1:address:array:character <- new [] + 2:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character + render-all screen, 2:address:programming-environment-data # create 2 sandboxes and scroll to second assume-console [ press ctrl-n @@ -199,7 +199,7 @@ scenario editing-sandbox-after-scrolling-resets-scroll [ press down-arrow press down-arrow ] - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data screen-should-contain [ . run (F4) . .━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. @@ -214,7 +214,7 @@ scenario editing-sandbox-after-scrolling-resets-scroll [ left-click 2, 20 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data ] # second sandbox shows in editor; scroll resets to display first sandbox screen-should-contain [ @@ -233,9 +233,9 @@ scenario editing-sandbox-updates-sandbox-count [ trace-until 100/app # trace too long assume-screen 50/width, 20/height # initialize environment - 1:address:shared:array:character <- new [] - 2:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character - render-all screen, 2:address:shared:programming-environment-data + 1:address:array:character <- new [] + 2:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character + render-all screen, 2:address:programming-environment-data # create 2 sandboxes and scroll to second assume-console [ press ctrl-n @@ -244,7 +244,7 @@ scenario editing-sandbox-updates-sandbox-count [ type [add 1, 1] press F4 ] - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data screen-should-contain [ . run (F4) . . . @@ -261,7 +261,7 @@ scenario editing-sandbox-updates-sandbox-count [ press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data ] # no change in contents screen-should-contain [ @@ -281,7 +281,7 @@ scenario editing-sandbox-updates-sandbox-count [ press down-arrow ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data ] # screen should show just final sandbox screen-should-contain [ diff --git a/sandbox/007-sandbox-delete.mu b/sandbox/007-sandbox-delete.mu index 2fed31cd..1f0f03b4 100644 --- a/sandbox/007-sandbox-delete.mu +++ b/sandbox/007-sandbox-delete.mu @@ -3,8 +3,8 @@ scenario deleting-sandboxes [ trace-until 100/app # trace too long assume-screen 50/width, 15/height - 1:address:shared:array:character <- new [] - 2:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character + 1:address:array:character <- new [] + 2:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character # run a few commands assume-console [ left-click 1, 0 @@ -13,7 +13,7 @@ scenario deleting-sandboxes [ type [add 2, 2] press F4 ] - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data screen-should-contain [ . run (F4) . . . @@ -34,7 +34,7 @@ scenario deleting-sandboxes [ left-click 7, 49 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data ] screen-should-contain [ . run (F4) . @@ -52,7 +52,7 @@ scenario deleting-sandboxes [ left-click 3, 49 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data ] screen-should-contain [ . run (F4) . @@ -76,29 +76,29 @@ after <global-touch> [ } ] -def delete-sandbox t:touch-event, env:address:shared:programming-environment-data -> was-delete?:boolean, env:address:shared:programming-environment-data [ +def delete-sandbox t:touch-event, env:address:programming-environment-data -> was-delete?:boolean, env:address:programming-environment-data [ local-scope load-ingredients click-column:number <- get t, column:offset - current-sandbox:address:shared:editor-data <- get *env, current-sandbox:offset + current-sandbox:address:editor-data <- get *env, current-sandbox:offset right:number <- get *current-sandbox, right:offset at-right?:boolean <- equal click-column, right return-unless at-right?, 0/false click-row:number <- get t, row:offset { - first:address:shared:sandbox-data <- get *env, sandbox:offset + first:address:sandbox-data <- get *env, sandbox:offset reply-unless first, 0/false target-row:number <- get *first, starting-row-on-screen:offset delete-first?:boolean <- equal target-row, click-row break-unless delete-first? - new-first:address:shared:sandbox-data <- get *first, next-sandbox:offset + new-first:address:sandbox-data <- get *first, next-sandbox:offset *env <- put *env, sandbox:offset, new-first env <- fixup-delete env, new-first return 1/true # force rerender } - prev:address:shared:sandbox-data <- get *env, sandbox:offset + prev:address:sandbox-data <- get *env, sandbox:offset assert prev, [failed to find any sandboxes!] - curr:address:shared:sandbox-data <- get *prev, next-sandbox:offset + curr:address:sandbox-data <- get *prev, next-sandbox:offset { break-unless curr # more sandboxes to check @@ -107,7 +107,7 @@ def delete-sandbox t:touch-event, env:address:shared:programming-environment-dat delete-curr?:boolean <- equal target-row, click-row break-unless delete-curr? # delete this sandbox - next:address:shared:sandbox-data <- get *curr, next-sandbox:offset + next:address:sandbox-data <- get *curr, next-sandbox:offset *prev <- put *prev, next-sandbox:offset, next env <- fixup-delete env, next return 1/true # force rerender @@ -119,7 +119,7 @@ def delete-sandbox t:touch-event, env:address:shared:programming-environment-dat return 0/false ] -def fixup-delete env:address:shared:programming-environment-data, next:address:shared:sandbox-data -> env:address:shared:programming-environment-data [ +def fixup-delete env:address:programming-environment-data, next:address:sandbox-data -> env:address:programming-environment-data [ local-scope load-ingredients # update sandbox count @@ -141,9 +141,9 @@ scenario deleting-sandbox-after-scroll [ trace-until 100/app # trace too long assume-screen 30/width, 10/height # initialize environment - 1:address:shared:array:character <- new [] - 2:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character - render-all screen, 2:address:shared:programming-environment-data + 1:address:array:character <- new [] + 2:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character + render-all screen, 2:address:programming-environment-data # create 2 sandboxes and scroll to second assume-console [ press ctrl-n @@ -153,7 +153,7 @@ scenario deleting-sandbox-after-scroll [ press F4 press down-arrow ] - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data screen-should-contain [ . . # menu .━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. @@ -171,7 +171,7 @@ scenario deleting-sandbox-after-scroll [ left-click 6, 29 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data ] # second sandbox shows in editor; scroll resets to display first sandbox screen-should-contain [ @@ -189,9 +189,9 @@ scenario deleting-top-sandbox-after-scroll [ trace-until 100/app # trace too long assume-screen 30/width, 10/height # initialize environment - 1:address:shared:array:character <- new [] - 2:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character - render-all screen, 2:address:shared:programming-environment-data + 1:address:array:character <- new [] + 2:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character + render-all screen, 2:address:programming-environment-data # create 2 sandboxes and scroll to second assume-console [ press ctrl-n @@ -201,7 +201,7 @@ scenario deleting-top-sandbox-after-scroll [ press F4 press down-arrow ] - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data screen-should-contain [ . . # menu .━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. @@ -219,7 +219,7 @@ scenario deleting-top-sandbox-after-scroll [ left-click 2, 29 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data ] # second sandbox shows in editor; scroll resets to display first sandbox screen-should-contain [ @@ -237,9 +237,9 @@ scenario deleting-final-sandbox-after-scroll [ trace-until 100/app # trace too long assume-screen 30/width, 10/height # initialize environment - 1:address:shared:array:character <- new [] - 2:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character - render-all screen, 2:address:shared:programming-environment-data + 1:address:array:character <- new [] + 2:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character + render-all screen, 2:address:programming-environment-data # create 2 sandboxes and scroll to second assume-console [ press ctrl-n @@ -250,7 +250,7 @@ scenario deleting-final-sandbox-after-scroll [ press down-arrow press down-arrow ] - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data screen-should-contain [ . . .━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. @@ -265,7 +265,7 @@ scenario deleting-final-sandbox-after-scroll [ left-click 2, 29 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data ] # implicitly scroll up to first sandbox screen-should-contain [ @@ -284,9 +284,9 @@ scenario deleting-updates-sandbox-count [ trace-until 100/app # trace too long assume-screen 30/width, 10/height # initialize environment - 1:address:shared:array:character <- new [] - 2:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character - render-all screen, 2:address:shared:programming-environment-data + 1:address:array:character <- new [] + 2:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character + render-all screen, 2:address:programming-environment-data # create 2 sandboxes assume-console [ press ctrl-n @@ -295,7 +295,7 @@ scenario deleting-updates-sandbox-count [ type [add 1, 1] press F4 ] - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data screen-should-contain [ . . . . @@ -315,7 +315,7 @@ scenario deleting-updates-sandbox-count [ press down-arrow ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data ] # shouldn't go past last sandbox screen-should-contain [ diff --git a/sandbox/008-sandbox-test.mu b/sandbox/008-sandbox-test.mu index 04a83ac6..61d12167 100644 --- a/sandbox/008-sandbox-test.mu +++ b/sandbox/008-sandbox-test.mu @@ -4,17 +4,17 @@ scenario sandbox-click-on-result-toggles-color-to-green [ trace-until 100/app # trace too long assume-screen 50/width, 20/height # basic recipe - 1:address:shared:array:character <- new [ + 1:address:array:character <- new [ def foo [ return 4 ]] # run it - 2:address:shared:array:character <- new [foo] + 2:address:array:character <- new [foo] assume-console [ press F4 ] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 2:address:shared:array:character - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data, 1:address:shared:array:character/test-recipes + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 2:address:array:character + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data, 1:address:array:character/test-recipes screen-should-contain [ . run (F4) . . . @@ -30,7 +30,7 @@ def foo [ left-click 5, 21 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data, 1:address:shared:array:character/test-recipes + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data, 1:address:array:character/test-recipes ] # color toggles to green screen-should-contain-in-color 2/green, [ @@ -45,7 +45,7 @@ def foo [ # cursor should remain unmoved run [ 4:character/cursor <- copy 9251/␣ - print screen:address:shared:screen, 4:character/cursor + print screen:address:screen, 4:character/cursor ] screen-should-contain [ . run (F4) . @@ -58,7 +58,7 @@ def foo [ . . ] # now change the result - 1:address:shared:array:character <- new [ + 1:address:array:character <- new [ def foo [ return 3 ]] @@ -67,7 +67,7 @@ def foo [ press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data, 1:address:shared:array:character/new-test-recipes + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data, 1:address:array:character/new-test-recipes ] # result turns red screen-should-contain-in-color 1/red, [ @@ -84,13 +84,13 @@ def foo [ # this requires tracking a couple more things container sandbox-data [ response-starting-row-on-screen:number - expected-response:address:shared:array:character + expected-response:address:array:character ] # include expected response when saving or restoring a sandbox before <end-save-sandbox> [ { - expected-response:address:shared:array:character <- get *curr, expected-response:offset + expected-response:address:array:character <- get *curr, expected-response:offset break-unless expected-response filename <- append filename, [.out] save filename, expected-response @@ -109,14 +109,14 @@ after <global-touch> [ click-column:number <- get t, column:offset on-sandbox-side?:boolean <- greater-or-equal click-column, sandbox-left-margin break-unless on-sandbox-side? - first-sandbox:address:shared:sandbox-data <- get *env, sandbox:offset + first-sandbox:address:sandbox-data <- get *env, sandbox:offset break-unless first-sandbox first-sandbox-begins:number <- get *first-sandbox, starting-row-on-screen:offset click-row:number <- get t, row:offset below-sandbox-editor?:boolean <- greater-or-equal click-row, first-sandbox-begins break-unless below-sandbox-editor? # identify the sandbox whose output is being clicked on - sandbox:address:shared:sandbox-data <- find-click-in-sandbox-output env, click-row + sandbox:address:sandbox-data <- find-click-in-sandbox-output env, click-row break-unless sandbox # toggle its expected-response, and save session sandbox <- toggle-expected-response sandbox @@ -130,17 +130,17 @@ after <global-touch> [ } ] -def find-click-in-sandbox-output env:address:shared:programming-environment-data, click-row:number -> sandbox:address:shared:sandbox-data [ +def find-click-in-sandbox-output env:address:programming-environment-data, click-row:number -> sandbox:address:sandbox-data [ local-scope load-ingredients # assert click-row >= sandbox.starting-row-on-screen - sandbox:address:shared:sandbox-data <- get *env, sandbox:offset + sandbox:address:sandbox-data <- get *env, sandbox:offset start:number <- get *sandbox, starting-row-on-screen:offset clicked-on-sandboxes?:boolean <- greater-or-equal click-row, start assert clicked-on-sandboxes?, [extract-sandbox called on click to sandbox editor] # while click-row < sandbox.next-sandbox.starting-row-on-screen { - next-sandbox:address:shared:sandbox-data <- get *sandbox, next-sandbox:offset + next-sandbox:address:sandbox-data <- get *sandbox, next-sandbox:offset break-unless next-sandbox next-start:number <- get *next-sandbox, starting-row-on-screen:offset found?:boolean <- lesser-than click-row, next-start @@ -156,10 +156,10 @@ def find-click-in-sandbox-output env:address:shared:programming-environment-data return sandbox ] -def toggle-expected-response sandbox:address:shared:sandbox-data -> sandbox:address:shared:sandbox-data [ +def toggle-expected-response sandbox:address:sandbox-data -> sandbox:address:sandbox-data [ local-scope load-ingredients - expected-response:address:shared:array:character <- get *sandbox, expected-response:offset + expected-response:address:array:character <- get *sandbox, expected-response:offset { # if expected-response is set, reset break-unless expected-response @@ -168,7 +168,7 @@ def toggle-expected-response sandbox:address:shared:sandbox-data -> sandbox:addr { # if not, set expected response to the current response break-if expected-response - response:address:shared:array:character <- get *sandbox, response:offset + response:address:array:character <- get *sandbox, response:offset *sandbox <- put *sandbox, expected-response:offset, response } ] @@ -178,7 +178,7 @@ after <render-sandbox-response> [ { break-unless sandbox-response *sandbox <- put *sandbox, response-starting-row-on-screen:offset, row - expected-response:address:shared:array:character <- get *sandbox, expected-response:offset + expected-response:address:array:character <- get *sandbox, expected-response:offset break-unless expected-response # fall-through to print in grey response-is-expected?:boolean <- equal expected-response, sandbox-response { diff --git a/sandbox/009-sandbox-trace.mu b/sandbox/009-sandbox-trace.mu index c5f96726..b759313e 100644 --- a/sandbox/009-sandbox-trace.mu +++ b/sandbox/009-sandbox-trace.mu @@ -4,12 +4,12 @@ scenario sandbox-click-on-code-toggles-app-trace [ trace-until 100/app # trace too long assume-screen 40/width, 10/height # run a stash instruction - 1:address:shared:array:character <- new [stash [abc]] + 1:address:array:character <- new [stash [abc]] assume-console [ press F4 ] - 2:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + 2:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data screen-should-contain [ . run (F4) . . . @@ -24,9 +24,9 @@ scenario sandbox-click-on-code-toggles-app-trace [ left-click 4, 21 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data 4:character/cursor-icon <- copy 9251/␣ - print screen:address:shared:screen, 4:character/cursor-icon + print screen:address:screen, 4:character/cursor-icon ] # trace now printed and cursor shouldn't have budged screen-should-contain [ @@ -54,8 +54,8 @@ scenario sandbox-click-on-code-toggles-app-trace [ left-click 4, 25 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data - print screen:address:shared:screen, 4:character/cursor-icon + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data + print screen:address:screen, 4:character/cursor-icon ] # trace hidden again screen-should-contain [ @@ -73,13 +73,13 @@ scenario sandbox-shows-app-trace-and-result [ trace-until 100/app # trace too long assume-screen 40/width, 10/height # run a stash instruction and some code - 1:address:shared:array:character <- new [stash [abc] + 1:address:array:character <- new [stash [abc] add 2, 2] assume-console [ press F4 ] - 2:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + 2:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data screen-should-contain [ . run (F4) . . . @@ -96,7 +96,7 @@ add 2, 2] left-click 4, 21 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data ] # trace now printed above result screen-should-contain [ @@ -114,16 +114,16 @@ add 2, 2] ] container sandbox-data [ - trace:address:shared:array:character + trace:address:array:character display-trace?:boolean ] # replaced in a later layer -def! update-sandbox sandbox:address:shared:sandbox-data, env:address:shared:programming-environment-data, idx:number -> sandbox:address:shared:sandbox-data, env:address:shared:programming-environment-data [ +def! update-sandbox sandbox:address:sandbox-data, env:address:programming-environment-data, idx:number -> sandbox:address:sandbox-data, env:address:programming-environment-data [ local-scope load-ingredients - data:address:shared:array:character <- get *sandbox, data:offset - response:address:shared:array:character, _, fake-screen:address:shared:screen, trace:address:shared:array:character <- run-interactive data + data:address:array:character <- get *sandbox, data:offset + response:address:array:character, _, fake-screen:address:screen, trace:address:array:character <- run-interactive data *sandbox <- put *sandbox, response:offset, response *sandbox <- put *sandbox, screen:offset, fake-screen *sandbox <- put *sandbox, trace:offset, trace @@ -137,14 +137,14 @@ after <global-touch> [ click-column:number <- get t, column:offset on-sandbox-side?:boolean <- greater-or-equal click-column, sandbox-left-margin break-unless on-sandbox-side? - first-sandbox:address:shared:sandbox-data <- get *env, sandbox:offset + first-sandbox:address:sandbox-data <- get *env, sandbox:offset break-unless first-sandbox first-sandbox-begins:number <- get *first-sandbox, starting-row-on-screen:offset click-row:number <- get t, row:offset below-sandbox-editor?:boolean <- greater-or-equal click-row, first-sandbox-begins break-unless below-sandbox-editor? # identify the sandbox whose code is being clicked on - sandbox:address:shared:sandbox-data <- find-click-in-sandbox-code env, click-row + sandbox:address:sandbox-data <- find-click-in-sandbox-code env, click-row break-unless sandbox # toggle its display-trace? property x:boolean <- get *sandbox, display-trace?:offset @@ -159,7 +159,7 @@ after <global-touch> [ } ] -def find-click-in-sandbox-code env:address:shared:programming-environment-data, click-row:number -> sandbox:address:shared:sandbox-data [ +def find-click-in-sandbox-code env:address:programming-environment-data, click-row:number -> sandbox:address:sandbox-data [ local-scope load-ingredients # assert click-row >= sandbox.starting-row-on-screen @@ -169,7 +169,7 @@ def find-click-in-sandbox-code env:address:shared:programming-environment-data, assert clicked-on-sandboxes?, [extract-sandbox called on click to sandbox editor] # while click-row < sandbox.next-sandbox.starting-row-on-screen { - next-sandbox:address:shared:sandbox-data <- get *sandbox, next-sandbox:offset + next-sandbox:address:sandbox-data <- get *sandbox, next-sandbox:offset break-unless next-sandbox next-start:number <- get *next-sandbox, starting-row-on-screen:offset found?:boolean <- lesser-than click-row, next-start @@ -195,7 +195,7 @@ after <render-sandbox-results> [ { display-trace?:boolean <- get *sandbox, display-trace?:offset break-unless display-trace? - sandbox-trace:address:shared:array:character <- get *sandbox, trace:offset + sandbox-trace:address:array:character <- get *sandbox, trace:offset break-unless sandbox-trace # nothing to print; move on row, screen <- render screen, sandbox-trace, left, right, 245/grey, row } diff --git a/sandbox/010-errors.mu b/sandbox/010-errors.mu index a25ade5d..e319932e 100644 --- a/sandbox/010-errors.mu +++ b/sandbox/010-errors.mu @@ -1,17 +1,17 @@ ## handling malformed programs container programming-environment-data [ - recipe-errors:address:shared:array:character + recipe-errors:address:array:character ] # copy code from recipe editor, persist, load into mu, save any errors # test-recipes is a hook for testing -def! update-recipes env:address:shared:programming-environment-data, screen:address:shared:screen, test-recipes:address:shared:array:character -> errors-found?:boolean, env:address:shared:programming-environment-data, screen:address:shared:screen [ +def! update-recipes env:address:programming-environment-data, screen:address:screen, test-recipes:address:array:character -> errors-found?:boolean, env:address:programming-environment-data, screen:address:screen [ local-scope load-ingredients { break-if test-recipes - recipe-errors:address:shared:array:character <- restore [recipes.mu] + recipe-errors:address:array:character <- restore [recipes.mu] } { break-unless test-recipes @@ -30,7 +30,7 @@ def! update-recipes env:address:shared:programming-environment-data, screen:addr before <render-components-end> [ trace 11, [app], [render status] - recipe-errors:address:shared:array:character <- get *env, recipe-errors:offset + recipe-errors:address:array:character <- get *env, recipe-errors:offset { break-unless recipe-errors update-status screen, [errors found ], 1/red @@ -64,27 +64,27 @@ before <render-components-end> [ error-index:number <- get *env, error-index:offset sandboxes-completed-successfully?:boolean <- equal error-index, -1 break-if sandboxes-completed-successfully? - error-index-text:address:shared:array:character <- to-text error-index - status:address:shared:array:character <- interpolate [errors found (_) ], error-index-text + error-index-text:address:array:character <- to-text error-index + status:address:array:character <- interpolate [errors found (_) ], error-index-text update-status screen, status, 1/red } ] container sandbox-data [ - errors:address:shared:array:character + errors:address:array:character ] -def! update-sandbox sandbox:address:shared:sandbox-data, env:address:shared:programming-environment-data, idx:number -> sandbox:address:shared:sandbox-data, env:address:shared:programming-environment-data [ +def! update-sandbox sandbox:address:sandbox-data, env:address:programming-environment-data, idx:number -> sandbox:address:sandbox-data, env:address:programming-environment-data [ local-scope load-ingredients { - recipe-errors:address:shared:array:character <- get *env, recipe-errors:offset + recipe-errors:address:array:character <- get *env, recipe-errors:offset break-unless recipe-errors *sandbox <- put *sandbox, errors:offset, recipe-errors return } - data:address:shared:array:character <- get *sandbox, data:offset - response:address:shared:array:character, errors:address:shared:array:character, fake-screen:address:shared:screen, trace:address:shared:array:character, completed?:boolean <- run-interactive data + data:address:array:character <- get *sandbox, data:offset + response:address:array:character, errors:address:array:character, fake-screen:address:screen, trace:address:array:character, completed?:boolean <- run-interactive data *sandbox <- put *sandbox, response:offset, response *sandbox <- put *sandbox, errors:offset, errors *sandbox <- put *sandbox, screen:offset, fake-screen @@ -108,12 +108,12 @@ def! update-sandbox sandbox:address:shared:sandbox-data, env:address:shared:prog # make sure we render any trace after <render-sandbox-trace-done> [ { - sandbox-errors:address:shared:array:character <- get *sandbox, errors:offset + sandbox-errors:address:array:character <- get *sandbox, errors:offset break-unless sandbox-errors *sandbox <- put *sandbox, response-starting-row-on-screen:offset, 0 # no response { break-unless env - recipe-errors:address:shared:array:character <- get *env, recipe-errors:offset + recipe-errors:address:array:character <- get *env, recipe-errors:offset row, screen <- render screen, recipe-errors, left, right, 1/red, row } row, screen <- render screen, sandbox-errors, left, right, 1/red, row @@ -125,17 +125,17 @@ after <render-sandbox-trace-done> [ scenario run-shows-errors-in-get [ trace-until 100/app # trace too long assume-screen 50/width, 20/height - 1:address:shared:array:character <- new [ + 1:address:array:character <- new [ def foo [ get 123:number, foo:offset ]] - 2:address:shared:array:character <- new [foo] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 2:address:shared:array:character + 2:address:array:character <- new [foo] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 2:address:array:character assume-console [ press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data, 1:address:shared:array:character/test-recipes + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data, 1:address:array:character/test-recipes ] screen-should-contain [ . errors found run (F4) . @@ -161,9 +161,9 @@ def foo [ scenario run-updates-status-with-first-erroneous-sandbox [ trace-until 100/app # trace too long assume-screen 50/width, 20/height - 1:address:shared:array:character <- new [] - 2:address:shared:array:character <- new [] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 2:address:shared:array:character + 1:address:array:character <- new [] + 2:address:array:character <- new [] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 2:address:array:character assume-console [ # create invalid sandbox 1 type [get foo, x:offset] @@ -173,7 +173,7 @@ scenario run-updates-status-with-first-erroneous-sandbox [ press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data, 1:address:shared:array:character/empty-test-recipes + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data, 1:address:array:character/empty-test-recipes ] # status line shows that error is in first sandbox screen-should-contain [ @@ -184,9 +184,9 @@ scenario run-updates-status-with-first-erroneous-sandbox [ scenario run-updates-status-with-first-erroneous-sandbox-2 [ trace-until 100/app # trace too long assume-screen 50/width, 20/height - 1:address:shared:array:character <- new [] - 2:address:shared:array:character <- new [] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 2:address:shared:array:character + 1:address:array:character <- new [] + 2:address:array:character <- new [] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 2:address:array:character assume-console [ # create invalid sandbox 2 type [get foo, x:offset] @@ -199,7 +199,7 @@ scenario run-updates-status-with-first-erroneous-sandbox-2 [ press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data, 1:address:shared:array:character/empty-test-recipes + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data, 1:address:array:character/empty-test-recipes ] # status line shows that error is in second sandbox screen-should-contain [ @@ -210,13 +210,13 @@ scenario run-updates-status-with-first-erroneous-sandbox-2 [ scenario run-hides-errors-from-past-sandboxes [ trace-until 100/app # trace too long assume-screen 50/width, 20/height - 1:address:shared:array:character <- new [] - 2:address:shared:array:character <- new [get foo, x:offset] # invalid - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 2:address:shared:array:character + 1:address:array:character <- new [] + 2:address:array:character <- new [get foo, x:offset] # invalid + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 2:address:array:character assume-console [ press F4 # generate error ] - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data, 1:address:shared:array:character/empty-test-recipes + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data, 1:address:array:character/empty-test-recipes assume-console [ left-click 3, 10 press ctrl-k @@ -224,7 +224,7 @@ scenario run-hides-errors-from-past-sandboxes [ press F4 # update sandbox ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data ] # error should disappear screen-should-contain [ @@ -243,18 +243,18 @@ scenario run-updates-errors-for-shape-shifting-recipes [ trace-until 100/app # trace too long assume-screen 50/width, 20/height # define a shape-shifting recipe with an error - 1:address:shared:array:character <- new [recipe foo x:_elem -> z:_elem [ + 1:address:array:character <- new [recipe foo x:_elem -> z:_elem [ local-scope load-ingredients y:address:number <- copy 0 z <- add x, y ]] - 2:address:shared:array:character <- new [foo 2] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 2:address:shared:array:character + 2:address:array:character <- new [foo 2] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 2:address:array:character assume-console [ press F4 ] - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data, 1:address:shared:array:character/test-recipes + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data, 1:address:array:character/test-recipes screen-should-contain [ . errors found (0) run (F4) . . . @@ -271,7 +271,7 @@ z <- add x, y press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data, 1:address:shared:array:character/test-recipes + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data, 1:address:array:character/test-recipes ] # error should remain unchanged screen-should-contain [ @@ -291,24 +291,24 @@ scenario run-avoids-spurious-errors-on-reloading-shape-shifting-recipes [ trace-until 100/app # trace too long assume-screen 50/width, 20/height # overload a well-known shape-shifting recipe - 1:address:shared:array:character <- new [recipe length l:address:shared:list:_elem -> n:number [ + 1:address:array:character <- new [recipe length l:address:list:_elem -> n:number [ ]] # call code that uses other variants of it, but not it itself - 2:address:shared:array:character <- new [x:address:shared:list:number <- copy 0 + 2:address:array:character <- new [x:address:list:number <- copy 0 to-text x] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 2:address:shared:array:character + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 2:address:array:character # run it once assume-console [ press F4 ] - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data, 1:address:shared:array:character/test-recipes + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data, 1:address:array:character/test-recipes # no errors anywhere on screen (can't check anything else, since to-text will return an address) screen-should-contain-in-color 1/red, [ . . . . . . . . - . <- . + . <- . . . . . . . @@ -319,7 +319,7 @@ to-text x] press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data, 1:address:shared:array:character/test-recipes + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data, 1:address:array:character/test-recipes ] # still no errors screen-should-contain-in-color 1/red, [ @@ -327,7 +327,7 @@ to-text x] . . . . . . - . <- . + . <- . . . . . . . @@ -338,17 +338,17 @@ to-text x] scenario run-shows-missing-type-errors [ trace-until 100/app # trace too long assume-screen 50/width, 20/height - 1:address:shared:array:character <- new [ + 1:address:array:character <- new [ def foo [ x <- copy 0 ]] - 2:address:shared:array:character <- new [foo] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 2:address:shared:array:character + 2:address:array:character <- new [foo] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 2:address:array:character assume-console [ press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data, 1:address:shared:array:character/test-recipes + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data, 1:address:array:character/test-recipes ] screen-should-contain [ . errors found run (F4) . @@ -369,18 +369,18 @@ scenario run-shows-unbalanced-bracket-errors [ trace-until 100/app # trace too long assume-screen 50/width, 20/height # recipe is incomplete (unbalanced '[') - 1:address:shared:array:character <- new [ + 1:address:array:character <- new [ def foo « x <- copy 0 ] - replace 1:address:shared:array:character, 171/«, 91 # '[' - 2:address:shared:array:character <- new [foo] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 2:address:shared:array:character + replace 1:address:array:character, 171/«, 91 # '[' + 2:address:array:character <- new [foo] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 2:address:array:character assume-console [ press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data, 1:address:shared:array:character/test-recipes + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data, 1:address:array:character/test-recipes ] screen-should-contain [ . errors found run (F4) . @@ -398,19 +398,19 @@ def foo « scenario run-shows-get-on-non-container-errors [ trace-until 100/app # trace too long assume-screen 50/width, 20/height - 1:address:shared:array:character <- new [ + 1:address:array:character <- new [ def foo [ local-scope - x:address:shared:point <- new point:type - get x:address:shared:point, 1:offset + x:address:point <- new point:type + get x:address:point, 1:offset ]] - 2:address:shared:array:character <- new [foo] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 2:address:shared:array:character + 2:address:array:character <- new [foo] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 2:address:array:character assume-console [ press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data, 1:address:shared:array:character/test-recipes + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data, 1:address:array:character/test-recipes ] screen-should-contain [ . errors found run (F4) . @@ -419,27 +419,27 @@ def foo [ .0 x. .foo . .foo: first ingredient of 'get' should be a contai↩. - .ner, but got x:address:shared:point . + .ner, but got x:address:point . ] ] scenario run-shows-non-literal-get-argument-errors [ trace-until 100/app # trace too long assume-screen 50/width, 20/height - 1:address:shared:array:character <- new [ + 1:address:array:character <- new [ def foo [ local-scope x:number <- copy 0 - y:address:shared:point <- new point:type - get *y:address:shared:point, x:number + y:address:point <- new point:type + get *y:address:point, x:number ]] - 2:address:shared:array:character <- new [foo] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 2:address:shared:array:character + 2:address:array:character <- new [foo] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 2:address:array:character assume-console [ press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data, 1:address:shared:array:character/test-recipes + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data, 1:address:array:character/test-recipes ] screen-should-contain [ . errors found run (F4) . @@ -456,17 +456,17 @@ scenario run-shows-errors-everytime [ trace-until 100/app # trace too long assume-screen 50/width, 20/height # try to run a file with an error - 1:address:shared:array:character <- new [ + 1:address:array:character <- new [ def foo [ local-scope x:number <- copy y:number ]] - 2:address:shared:array:character <- new [foo] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 2:address:shared:array:character + 2:address:array:character <- new [foo] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 2:address:array:character assume-console [ press F4 ] - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data, 1:address:shared:array:character/test-recipes + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data, 1:address:array:character/test-recipes screen-should-contain [ . errors found run (F4) . . . @@ -480,7 +480,7 @@ def foo [ press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data, 1:address:shared:array:character/test-recipes + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data, 1:address:array:character/test-recipes ] screen-should-contain [ . errors found run (F4) . @@ -495,22 +495,22 @@ def foo [ scenario run-instruction-and-print-errors [ trace-until 100/app # trace too long assume-screen 50/width, 15/height - 1:address:shared:array:character <- new [get 1:address:shared:point, 1:offset] - 2:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character + 1:address:array:character <- new [get 1:address:point, 1:offset] + 2:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character assume-console [ press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data ] screen-should-contain [ . errors found (0) run (F4) . . . .━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. .0 x. - .get 1:address:shared:point, 1:offset . + .get 1:address:point, 1:offset . .first ingredient of 'get' should be a container, ↩. - .but got 1:address:shared:point . + .but got 1:address:point . .━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. . . ] @@ -521,7 +521,7 @@ scenario run-instruction-and-print-errors [ . . . . .first ingredient of 'get' should be a container, . - .but got 1:address:shared:point . + .but got 1:address:point . . . . . ] @@ -531,15 +531,15 @@ scenario run-instruction-and-print-errors-only-once [ trace-until 100/app # trace too long assume-screen 50/width, 10/height # editor contains an illegal instruction - 1:address:shared:array:character <- new [get 1234:number, foo:offset] - 2:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character + 1:address:array:character <- new [get 1234:number, foo:offset] + 2:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character # run the code in the editors multiple times assume-console [ press F4 press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data ] # check that screen prints error message just once screen-should-contain [ @@ -560,16 +560,16 @@ scenario sandbox-can-handle-infinite-loop [ trace-until 100/app # trace too long assume-screen 50/width, 20/height # editor contains an infinite loop - 1:address:shared:array:character <- new [{ + 1:address:array:character <- new [{ loop }] - 2:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character + 2:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character # run the sandbox assume-console [ press F4 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data + event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data ] screen-should-contain [ . errors found (0) run (F4) . @@ -589,7 +589,7 @@ scenario sandbox-with-errors-shows-trace [ trace-until 100/app # trace too long assume-screen 50/width, 20/height # generate a stash and a error - 1:address:shared:array:character <- new [recipe foo [ + 1:address:array:character <- new [recipe foo [ local-scope a:number <- next-ingredient b:number <- next-ingredient @@ -597,13 +597,13 @@ stash [dividing by], b _, c:number <- divide-with-remainder a, b return b ]] - 2:address:shared:array:character <- new [foo 4, 0] - 3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 2:address:shared:array:character + 2:address:array:character <- new [foo 4, 0] + 3:address:programming-environment-data <- new-programming-environment screen:address:screen, 2:address:array:character # run assume-console [ press F4 ] - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data, 1:address:shared:array:character/test-recipes + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data, 1:address:array:character/test-recipes # screen prints error message screen-should-contain [ . errors found (0) run (F4) . @@ -621,7 +621,7 @@ return b left-click 4, 15 ] run [ - event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data, 1:address:shared:array:character/test-recipes + event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data, 1:address:array:character/test-recipes ] # screen should expand trace screen-should-contain [ diff --git a/sandbox/011-editor-undo.mu b/sandbox/011-editor-undo.mu index 94135346..5c9876d0 100644 --- a/sandbox/011-editor-undo.mu +++ b/sandbox/011-editor-undo.mu @@ -11,13 +11,13 @@ exclusive-container operation [ container insert-operation [ before-row:number before-column:number - before-top-of-screen:address:shared:duplex-list:character + before-top-of-screen:address:duplex-list:character after-row:number after-column:number - after-top-of-screen:address:shared:duplex-list:character + after-top-of-screen:address:duplex-list:character # inserted text is from 'insert-from' until 'insert-until'; list doesn't have to terminate - insert-from:address:shared:duplex-list:character - insert-until:address:shared:duplex-list:character + insert-from:address:duplex-list:character + insert-until:address:duplex-list:character tag:number # event causing this operation; might be used to coalesce runs of similar events # 0: no coalesce (enter+indent) # 1: regular alphanumeric characters @@ -26,10 +26,10 @@ container insert-operation [ container move-operation [ before-row:number before-column:number - before-top-of-screen:address:shared:duplex-list:character + before-top-of-screen:address:duplex-list:character after-row:number after-column:number - after-top-of-screen:address:shared:duplex-list:character + after-top-of-screen:address:duplex-list:character tag:number # event causing this operation; might be used to coalesce runs of similar events # 0: no coalesce (touch events, etc) # 1: left arrow @@ -41,13 +41,13 @@ container move-operation [ container delete-operation [ before-row:number before-column:number - before-top-of-screen:address:shared:duplex-list:character + before-top-of-screen:address:duplex-list:character after-row:number after-column:number - after-top-of-screen:address:shared:duplex-list:character - deleted-text:address:shared:duplex-list:character - delete-from:address:shared:duplex-list:character - delete-until:address:shared:duplex-list:character + after-top-of-screen:address:duplex-list:character + deleted-text:address:duplex-list:character + delete-from:address:duplex-list:character + delete-until:address:duplex-list:character tag:number # event causing this operation; might be used to coalesce runs of similar events # 0: no coalesce (ctrl-k, ctrl-u) # 1: backspace @@ -56,8 +56,8 @@ container delete-operation [ # every editor accumulates a list of operations to undo/redo container editor-data [ - undo:address:shared:list:address:shared:operation - redo:address:shared:list:address:shared:operation + undo:address:list:address:operation + redo:address:list:address:operation ] # ctrl-z - undo operation @@ -65,12 +65,12 @@ after <handle-special-character> [ { undo?:boolean <- equal c, 26/ctrl-z break-unless undo? - undo:address:shared:list:address:shared:operation <- get *editor, undo:offset + undo:address:list:address:operation <- get *editor, undo:offset break-unless undo - op:address:shared:operation <- first undo + op:address:operation <- first undo undo <- rest undo *editor <- put *editor, undo:offset, undo - redo:address:shared:list:address:shared:operation <- get *editor, redo:offset + redo:address:list:address:operation <- get *editor, redo:offset redo <- push op, redo *editor <- put *editor, redo:offset, redo <handle-undo> @@ -83,12 +83,12 @@ after <handle-special-character> [ { redo?:boolean <- equal c, 25/ctrl-y break-unless redo? - redo:address:shared:list:address:shared:operation <- get *editor, redo:offset + redo:address:list:address:operation <- get *editor, redo:offset break-unless redo - op:address:shared:operation <- first redo + op:address:operation <- first redo redo <- rest redo *editor <- put *editor, redo:offset, redo - undo:address:shared:list:address:shared:operation <- get *editor, undo:offset + undo:address:list:address:operation <- get *editor, undo:offset undo <- push op, undo *editor <- put *editor, undo:offset, undo <handle-redo> @@ -101,19 +101,19 @@ after <handle-special-character> [ scenario editor-can-undo-typing [ # create an editor and type a character assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data assume-console [ type [0] ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data # undo assume-console [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # character should be gone screen-should-contain [ @@ -127,7 +127,7 @@ scenario editor-can-undo-typing [ type [1] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -139,24 +139,24 @@ scenario editor-can-undo-typing [ # save operation to undo after <insert-character-begin> [ - top-before:address:shared:duplex-list:character <- get *editor, top-of-screen:offset - cursor-before:address:shared:duplex-list:character <- get *editor, before-cursor:offset + top-before:address:duplex-list:character <- get *editor, top-of-screen:offset + cursor-before:address:duplex-list:character <- get *editor, before-cursor:offset ] before <insert-character-end> [ - top-after:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + top-after:address:duplex-list:character <- get *editor, top-of-screen:offset cursor-row:number <- get *editor, cursor-row:offset cursor-column:number <- get *editor, cursor-column:offset - undo:address:shared:list:address:shared:operation <- get *editor, undo:offset + undo:address:list:address:operation <- get *editor, undo:offset { # if previous operation was an insert, coalesce this operation with it break-unless undo - op:address:shared:operation <- first undo + op:address:operation <- first undo typing:insert-operation, is-insert?:boolean <- maybe-convert *op, typing:variant break-unless is-insert? previous-coalesce-tag:number <- get typing, tag:offset break-unless previous-coalesce-tag - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset - insert-until:address:shared:duplex-list:character <- next before-cursor + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset + insert-until:address:duplex-list:character <- next before-cursor typing <- put typing, insert-until:offset, insert-until typing <- put typing, after-row:offset, cursor-row typing <- put typing, after-column:offset, cursor-column @@ -165,9 +165,9 @@ before <insert-character-end> [ break +done-adding-insert-operation:label } # if not, create a new operation - insert-from:address:shared:duplex-list:character <- next cursor-before - insert-to:address:shared:duplex-list:character <- next insert-from - op:address:shared:operation <- new operation:type + insert-from:address:duplex-list:character <- next cursor-before + insert-to:address:duplex-list:character <- next insert-from + op:address:operation <- new operation:type *op <- merge 0/insert-operation, save-row/before, save-column/before, top-before, cursor-row/after, cursor-column/after, top-after, insert-from, insert-to, 1/coalesce editor <- add-operation editor, op +done-adding-insert-operation @@ -177,18 +177,18 @@ before <insert-character-end> [ after <insert-enter-begin> [ cursor-row-before:number <- copy cursor-row cursor-column-before:number <- copy cursor-column - top-before:address:shared:duplex-list:character <- get *editor, top-of-screen:offset - cursor-before:address:shared:duplex-list:character <- get *editor, before-cursor:offset + top-before:address:duplex-list:character <- get *editor, top-of-screen:offset + cursor-before:address:duplex-list:character <- get *editor, before-cursor:offset ] before <insert-enter-end> [ - top-after:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + top-after:address:duplex-list:character <- get *editor, top-of-screen:offset cursor-row:number <- get *editor, cursor-row:offset cursor-column:number <- get *editor, cursor-row:offset # never coalesce - insert-from:address:shared:duplex-list:character <- next cursor-before - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset - insert-to:address:shared:duplex-list:character <- next before-cursor - op:address:shared:operation <- new operation:type + insert-from:address:duplex-list:character <- next cursor-before + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset + insert-to:address:duplex-list:character <- next before-cursor + op:address:operation <- new operation:type *op <- merge 0/insert-operation, cursor-row-before, cursor-column-before, top-before, cursor-row/after, cursor-column/after, top-after, insert-from, insert-to, 0/never-coalesce editor <- add-operation editor, op ] @@ -197,13 +197,13 @@ before <insert-enter-end> [ # redo stack, because it's now obsolete. # Beware: since we're counting cursor moves as operations, this means just # moving the cursor can lose work on the undo stack. -def add-operation editor:address:shared:editor-data, op:address:shared:operation -> editor:address:shared:editor-data [ +def add-operation editor:address:editor-data, op:address:operation -> editor:address:editor-data [ local-scope load-ingredients - undo:address:shared:list:address:shared:operation <- get *editor, undo:offset + undo:address:list:address:operation <- get *editor, undo:offset undo <- push op undo *editor <- put *editor, undo:offset, undo - redo:address:shared:list:address:shared:operation <- get *editor, redo:offset + redo:address:list:address:operation <- get *editor, redo:offset redo <- copy 0 *editor <- put *editor, redo:offset, redo return editor/same-as-ingredient:0 @@ -213,17 +213,17 @@ after <handle-undo> [ { typing:insert-operation, is-insert?:boolean <- maybe-convert *op, typing:variant break-unless is-insert? - start:address:shared:duplex-list:character <- get typing, insert-from:offset - end:address:shared:duplex-list:character <- get typing, insert-until:offset + start:address:duplex-list:character <- get typing, insert-from:offset + end:address:duplex-list:character <- get typing, insert-until:offset # assert cursor-row/cursor-column/top-of-screen match after-row/after-column/after-top-of-screen - before-cursor:address:shared:duplex-list:character <- prev start + before-cursor:address:duplex-list:character <- prev start *editor <- put *editor, before-cursor:offset, before-cursor remove-between before-cursor, end cursor-row <- get typing, before-row:offset *editor <- put *editor, cursor-row:offset, cursor-row cursor-column <- get typing, before-column:offset *editor <- put *editor, cursor-column:offset, cursor-column - top:address:shared:duplex-list:character <- get typing, before-top-of-screen:offset + top:address:duplex-list:character <- get typing, before-top-of-screen:offset *editor <- put *editor, top-of-screen:offset, top } ] @@ -231,19 +231,19 @@ after <handle-undo> [ scenario editor-can-undo-typing-multiple [ # create an editor and type multiple characters assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data assume-console [ type [012] ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data # undo assume-console [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # all characters must be gone screen-should-contain [ @@ -257,14 +257,14 @@ scenario editor-can-undo-typing-multiple [ scenario editor-can-undo-typing-multiple-2 [ # create an editor with some text assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [a] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [a] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # type some characters assume-console [ type [012] ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data screen-should-contain [ . . .012a . @@ -276,7 +276,7 @@ scenario editor-can-undo-typing-multiple-2 [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # back to original text screen-should-contain [ @@ -290,7 +290,7 @@ scenario editor-can-undo-typing-multiple-2 [ type [3] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -303,15 +303,15 @@ scenario editor-can-undo-typing-multiple-2 [ scenario editor-can-undo-typing-enter [ # create an editor with some text assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [ abc] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [ abc] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # new line assume-console [ left-click 1, 8 press enter ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data screen-should-contain [ . . . abc . @@ -320,8 +320,8 @@ scenario editor-can-undo-typing-enter [ . . ] # line is indented - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 2 4 <- 2 @@ -331,10 +331,10 @@ scenario editor-can-undo-typing-enter [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 5 @@ -351,7 +351,7 @@ scenario editor-can-undo-typing-enter [ type [1] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -366,14 +366,14 @@ scenario editor-can-undo-typing-enter [ scenario editor-redo-typing [ # create an editor, type something, undo assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [a] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [a] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data assume-console [ type [012] press ctrl-z ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data screen-should-contain [ . . .a . @@ -385,7 +385,7 @@ scenario editor-redo-typing [ press ctrl-y ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # all characters must be back screen-should-contain [ @@ -399,7 +399,7 @@ scenario editor-redo-typing [ type [3] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -414,7 +414,7 @@ after <handle-redo> [ typing:insert-operation, is-insert?:boolean <- maybe-convert *op, typing:variant break-unless is-insert? before-cursor <- get *editor, before-cursor:offset - insert-from:address:shared:duplex-list:character <- get typing, insert-from:offset # ignore insert-to because it's already been spliced away + insert-from:address:duplex-list:character <- get typing, insert-from:offset # ignore insert-to because it's already been spliced away # assert insert-to matches next(before-cursor) insert-range before-cursor, insert-from # assert cursor-row/cursor-column/top-of-screen match after-row/after-column/after-top-of-screen @@ -422,7 +422,7 @@ after <handle-redo> [ *editor <- put *editor, cursor-row:offset, cursor-row cursor-column <- get typing, after-column:offset *editor <- put *editor, cursor-column:offset, cursor-column - top:address:shared:duplex-list:character <- get typing, after-top-of-screen:offset + top:address:duplex-list:character <- get typing, after-top-of-screen:offset *editor <- put *editor, top-of-screen:offset, top } ] @@ -430,14 +430,14 @@ after <handle-redo> [ scenario editor-redo-typing-empty [ # create an editor, type something, undo assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data assume-console [ type [012] press ctrl-z ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data screen-should-contain [ . . . . @@ -449,7 +449,7 @@ scenario editor-redo-typing-empty [ press ctrl-y ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # all characters must be back screen-should-contain [ @@ -463,7 +463,7 @@ scenario editor-redo-typing-empty [ type [3] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -476,21 +476,21 @@ scenario editor-redo-typing-empty [ scenario editor-work-clears-redo-stack [ # create an editor with some text, do some work, undo assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def ghi] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data assume-console [ type [1] press ctrl-z ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data # do some more work assume-console [ type [0] ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data screen-should-contain [ . . .0abc . @@ -503,7 +503,7 @@ ghi] press ctrl-y ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # nothing should happen screen-should-contain [ @@ -518,9 +518,9 @@ ghi] scenario editor-can-redo-typing-and-enter-and-tab [ # create an editor assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # insert some text and tabs, hit enter, some more text and tabs assume-console [ press tab @@ -531,7 +531,7 @@ scenario editor-can-redo-typing-and-enter-and-tab [ press tab type [efg] ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data screen-should-contain [ . . . ab cd . @@ -539,8 +539,8 @@ scenario editor-can-redo-typing-and-enter-and-tab [ .┈┈┈┈┈┈┈┈┈┈. . . ] - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 2 4 <- 7 @@ -550,11 +550,11 @@ scenario editor-can-redo-typing-and-enter-and-tab [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # typing in second line deleted, but not indent - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 2 4 <- 2 @@ -571,11 +571,11 @@ scenario editor-can-redo-typing-and-enter-and-tab [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # indent and newline deleted - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 8 @@ -591,11 +591,11 @@ scenario editor-can-redo-typing-and-enter-and-tab [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # empty screen - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 0 @@ -611,11 +611,11 @@ scenario editor-can-redo-typing-and-enter-and-tab [ press ctrl-y ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # first line inserted - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 8 @@ -631,11 +631,11 @@ scenario editor-can-redo-typing-and-enter-and-tab [ press ctrl-y ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # newline and indent inserted - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 2 4 <- 2 @@ -652,11 +652,11 @@ scenario editor-can-redo-typing-and-enter-and-tab [ press ctrl-y ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # indent and newline deleted - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 2 4 <- 7 @@ -675,24 +675,24 @@ scenario editor-can-redo-typing-and-enter-and-tab [ scenario editor-can-undo-touch [ # create an editor with some text assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def ghi] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # move the cursor assume-console [ left-click 3, 1 ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data # undo assume-console [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # click undone memory-should-contain [ @@ -704,7 +704,7 @@ ghi] type [1] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -718,19 +718,19 @@ ghi] after <move-cursor-begin> [ cursor-row-before:number <- get *editor, cursor-row:offset cursor-column-before:number <- get *editor, cursor-column:offset - top-before:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + top-before:address:duplex-list:character <- get *editor, top-of-screen:offset ] before <move-cursor-end> [ - top-after:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + top-after:address:duplex-list:character <- get *editor, top-of-screen:offset cursor-row:number <- get *editor, cursor-row:offset cursor-column:number <- get *editor, cursor-column:offset { break-unless undo-coalesce-tag # if previous operation was also a move, and also had the same coalesce # tag, coalesce with it - undo:address:shared:list:address:shared:operation <- get *editor, undo:offset + undo:address:list:address:operation <- get *editor, undo:offset break-unless undo - op:address:shared:operation <- first undo + op:address:operation <- first undo move:move-operation, is-move?:boolean <- maybe-convert *op, move:variant break-unless is-move? previous-coalesce-tag:number <- get move, tag:offset @@ -742,7 +742,7 @@ before <move-cursor-end> [ *op <- merge 1/move-operation, move break +done-adding-move-operation:label } - op:address:shared:operation <- new operation:type + op:address:operation <- new operation:type *op <- merge 1/move-operation, cursor-row-before, cursor-column-before, top-before, cursor-row/after, cursor-column/after, top-after, undo-coalesce-tag editor <- add-operation editor, op +done-adding-move-operation @@ -757,7 +757,7 @@ after <handle-undo> [ *editor <- put *editor, cursor-row:offset, cursor-row cursor-column <- get move, before-column:offset *editor <- put *editor, cursor-column:offset, cursor-column - top:address:shared:duplex-list:character <- get move, before-top-of-screen:offset + top:address:duplex-list:character <- get move, before-top-of-screen:offset *editor <- put *editor, top-of-screen:offset, top } ] @@ -766,18 +766,18 @@ scenario editor-can-undo-scroll [ # screen has 1 line for menu + 3 lines assume-screen 5/width, 4/height # editor contains a wrapped line - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b cdefgh] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right # position cursor at end of screen and try to move right assume-console [ left-click 3, 3 press right-arrow ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset # screen scrolls screen-should-contain [ . . @@ -794,9 +794,9 @@ cdefgh] press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moved back memory-should-contain [ @@ -815,7 +815,7 @@ cdefgh] type [1] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -828,25 +828,25 @@ cdefgh] scenario editor-can-undo-left-arrow [ # create an editor with some text assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def ghi] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # move the cursor assume-console [ left-click 3, 1 press left-arrow ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data # undo assume-console [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves back memory-should-contain [ @@ -858,7 +858,7 @@ ghi] type [1] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -872,19 +872,19 @@ ghi] scenario editor-can-undo-up-arrow [ # create an editor with some text assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def ghi] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # move the cursor assume-console [ left-click 3, 1 press up-arrow ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 2 4 <- 1 @@ -894,9 +894,9 @@ ghi] press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves back memory-should-contain [ @@ -908,7 +908,7 @@ ghi] type [1] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -922,25 +922,25 @@ ghi] scenario editor-can-undo-down-arrow [ # create an editor with some text assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def ghi] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # move the cursor assume-console [ left-click 2, 1 press down-arrow ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data # undo assume-console [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves back memory-should-contain [ @@ -952,7 +952,7 @@ ghi] type [1] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -966,27 +966,27 @@ ghi] scenario editor-can-undo-ctrl-f [ # create an editor with multiple pages of text assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b c d e f] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # scroll the page assume-console [ press ctrl-f ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data # undo assume-console [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # screen should again show page 1 screen-should-contain [ @@ -1001,27 +1001,27 @@ f] scenario editor-can-undo-page-down [ # create an editor with multiple pages of text assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b c d e f] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # scroll the page assume-console [ press page-down ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data # undo assume-console [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # screen should again show page 1 screen-should-contain [ @@ -1036,28 +1036,28 @@ f] scenario editor-can-undo-ctrl-b [ # create an editor with multiple pages of text assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b c d e f] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # scroll the page down and up assume-console [ press page-down press ctrl-b ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data # undo assume-console [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # screen should again show page 2 screen-should-contain [ @@ -1072,28 +1072,28 @@ f] scenario editor-can-undo-page-up [ # create an editor with multiple pages of text assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [a + 1:address:array:character <- new [a b c d e f] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # scroll the page down and up assume-console [ press page-down press page-up ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data # undo assume-console [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # screen should again show page 2 screen-should-contain [ @@ -1108,25 +1108,25 @@ f] scenario editor-can-undo-ctrl-a [ # create an editor with some text assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def ghi] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # move the cursor, then to start of line assume-console [ left-click 2, 1 press ctrl-a ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data # undo assume-console [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves back memory-should-contain [ @@ -1138,7 +1138,7 @@ ghi] type [1] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -1152,25 +1152,25 @@ ghi] scenario editor-can-undo-home [ # create an editor with some text assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def ghi] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # move the cursor, then to start of line assume-console [ left-click 2, 1 press home ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data # undo assume-console [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves back memory-should-contain [ @@ -1182,7 +1182,7 @@ ghi] type [1] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -1196,25 +1196,25 @@ ghi] scenario editor-can-undo-ctrl-e [ # create an editor with some text assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def ghi] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # move the cursor, then to start of line assume-console [ left-click 2, 1 press ctrl-e ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data # undo assume-console [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves back memory-should-contain [ @@ -1226,7 +1226,7 @@ ghi] type [1] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -1240,25 +1240,25 @@ ghi] scenario editor-can-undo-end [ # create an editor with some text assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def ghi] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # move the cursor, then to start of line assume-console [ left-click 2, 1 press end ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data # undo assume-console [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves back memory-should-contain [ @@ -1270,7 +1270,7 @@ ghi] type [1] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -1284,11 +1284,11 @@ ghi] scenario editor-can-undo-multiple-arrows-in-the-same-direction [ # create an editor with some text assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def ghi] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # move the cursor assume-console [ left-click 2, 1 @@ -1296,9 +1296,9 @@ ghi] press right-arrow press up-arrow ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 3 @@ -1308,9 +1308,9 @@ ghi] press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # up-arrow is undone memory-should-contain [ @@ -1322,9 +1322,9 @@ ghi] press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # both right-arrows are undone memory-should-contain [ @@ -1338,24 +1338,24 @@ ghi] scenario editor-redo-touch [ # create an editor with some text, click on a character, undo assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def ghi] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data assume-console [ left-click 3, 1 press ctrl-z ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data # redo assume-console [ press ctrl-y ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves to left-click memory-should-contain [ @@ -1367,7 +1367,7 @@ ghi] type [1] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -1387,7 +1387,7 @@ after <handle-redo> [ *editor <- put *editor, cursor-row:offset, cursor-row cursor-column <- get move, after-column:offset *editor <- put *editor, cursor-column:offset, cursor-column - top:address:shared:duplex-list:character <- get move, after-top-of-screen:offset + top:address:duplex-list:character <- get move, after-top-of-screen:offset *editor <- put *editor, top-of-screen:offset, top } ] @@ -1395,17 +1395,17 @@ after <handle-redo> [ scenario editor-separates-undo-insert-from-undo-cursor-move [ # create an editor, type some text, move the cursor, type some more text assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data assume-console [ type [abc] left-click 1, 1 type [d] ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset screen-should-contain [ . . .adbc . @@ -1421,9 +1421,9 @@ scenario editor-separates-undo-insert-from-undo-cursor-move [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # last letter typed is deleted screen-should-contain [ @@ -1441,9 +1441,9 @@ scenario editor-separates-undo-insert-from-undo-cursor-move [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # no change to screen; cursor moves screen-should-contain [ @@ -1461,9 +1461,9 @@ scenario editor-separates-undo-insert-from-undo-cursor-move [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # screen empty screen-should-contain [ @@ -1481,9 +1481,9 @@ scenario editor-separates-undo-insert-from-undo-cursor-move [ press ctrl-y ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # first insert screen-should-contain [ @@ -1501,9 +1501,9 @@ scenario editor-separates-undo-insert-from-undo-cursor-move [ press ctrl-y ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves screen-should-contain [ @@ -1522,9 +1522,9 @@ scenario editor-separates-undo-insert-from-undo-cursor-move [ press ctrl-y ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset ] # second insert screen-should-contain [ @@ -1544,24 +1544,24 @@ scenario editor-separates-undo-insert-from-undo-cursor-move [ scenario editor-can-undo-and-redo-backspace [ # create an editor assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # insert some text and hit backspace assume-console [ type [abc] press backspace press backspace ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data screen-should-contain [ . . .a . .┈┈┈┈┈┈┈┈┈┈. . . ] - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 1 @@ -1571,10 +1571,10 @@ scenario editor-can-undo-and-redo-backspace [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 3 @@ -1590,10 +1590,10 @@ scenario editor-can-undo-and-redo-backspace [ press ctrl-y ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 1 @@ -1608,27 +1608,27 @@ scenario editor-can-undo-and-redo-backspace [ # save operation to undo after <backspace-character-begin> [ - top-before:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + top-before:address:duplex-list:character <- get *editor, top-of-screen:offset ] before <backspace-character-end> [ { break-unless backspaced-cell # backspace failed; don't add an undo operation - top-after:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + top-after:address:duplex-list:character <- get *editor, top-of-screen:offset cursor-row:number <- get *editor, cursor-row:offset cursor-column:number <- get *editor, cursor-row:offset - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset - undo:address:shared:list:address:shared:operation <- get *editor, undo:offset + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset + undo:address:list:address:operation <- get *editor, undo:offset { # if previous operation was an insert, coalesce this operation with it break-unless *undo - op:address:shared:operation <- first undo + op:address:operation <- first undo deletion:delete-operation, is-delete?:boolean <- maybe-convert *op, delete:variant break-unless is-delete? previous-coalesce-tag:number <- get deletion, tag:offset coalesce?:boolean <- equal previous-coalesce-tag, 1/coalesce-backspace break-unless coalesce? deletion <- put deletion, delete-from:offset, before-cursor - backspaced-so-far:address:shared:duplex-list:character <- get deletion, deleted-text:offset + backspaced-so-far:address:duplex-list:character <- get deletion, deleted-text:offset insert-range backspaced-cell, backspaced-so-far deletion <- put deletion, deleted-text:offset, backspaced-cell deletion <- put deletion, after-row:offset, cursor-row @@ -1638,8 +1638,8 @@ before <backspace-character-end> [ break +done-adding-backspace-operation:label } # if not, create a new operation - op:address:shared:operation <- new operation:type - deleted-until:address:shared:duplex-list:character <- next before-cursor + op:address:operation <- new operation:type + deleted-until:address:duplex-list:character <- next before-cursor *op <- merge 2/delete-operation, save-row/before, save-column/before, top-before, cursor-row/after, cursor-column/after, top-after, backspaced-cell/deleted, before-cursor/delete-from, deleted-until, 1/coalesce-backspace editor <- add-operation editor, op +done-adding-backspace-operation @@ -1650,10 +1650,10 @@ after <handle-undo> [ { deletion:delete-operation, is-delete?:boolean <- maybe-convert *op, delete:variant break-unless is-delete? - anchor:address:shared:duplex-list:character <- get deletion, delete-from:offset + anchor:address:duplex-list:character <- get deletion, delete-from:offset break-unless anchor - deleted:address:shared:duplex-list:character <- get deletion, deleted-text:offset - old-cursor:address:shared:duplex-list:character <- last deleted + deleted:address:duplex-list:character <- get deletion, deleted-text:offset + old-cursor:address:duplex-list:character <- last deleted insert-range anchor, deleted # assert cursor-row/cursor-column/top-of-screen match after-row/after-column/after-top-of-screen before-cursor <- copy old-cursor @@ -1661,7 +1661,7 @@ after <handle-undo> [ *editor <- put *editor, cursor-row:offset, cursor-row cursor-column <- get deletion, before-column:offset *editor <- put *editor, cursor-column:offset, cursor-column - top:address:shared:duplex-list:character <- get deletion, before-top-of-screen:offset + top:address:duplex-list:character <- get deletion, before-top-of-screen:offset *editor <- put *editor, top-of-screen:offset, top } ] @@ -1670,16 +1670,16 @@ after <handle-redo> [ { deletion:delete-operation, is-delete?:boolean <- maybe-convert *op, delete:variant break-unless is-delete? - start:address:shared:duplex-list:character <- get deletion, delete-from:offset - end:address:shared:duplex-list:character <- get deletion, delete-until:offset - data:address:shared:duplex-list:character <- get *editor, data:offset + start:address:duplex-list:character <- get deletion, delete-from:offset + end:address:duplex-list:character <- get deletion, delete-until:offset + data:address:duplex-list:character <- get *editor, data:offset remove-between start, end # assert cursor-row/cursor-column/top-of-screen match after-row/after-column/after-top-of-screen cursor-row <- get deletion, after-row:offset *editor <- put *editor, cursor-row:offset, cursor-row cursor-column <- get deletion, after-column:offset *editor <- put *editor, cursor-column:offset, cursor-column - top:address:shared:duplex-list:character <- get deletion, before-top-of-screen:offset + top:address:duplex-list:character <- get deletion, before-top-of-screen:offset *editor <- put *editor, top-of-screen:offset, top } ] @@ -1689,9 +1689,9 @@ after <handle-redo> [ scenario editor-can-undo-and-redo-delete [ # create an editor assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # insert some text and hit delete and backspace a few times assume-console [ type [abcdef] @@ -1701,15 +1701,15 @@ scenario editor-can-undo-and-redo-delete [ press delete press delete ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data screen-should-contain [ . . .af . .┈┈┈┈┈┈┈┈┈┈. . . ] - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 1 @@ -1719,10 +1719,10 @@ scenario editor-can-undo-and-redo-delete [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 1 @@ -1738,10 +1738,10 @@ scenario editor-can-undo-and-redo-delete [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 2 @@ -1757,10 +1757,10 @@ scenario editor-can-undo-and-redo-delete [ press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 2 @@ -1776,11 +1776,11 @@ scenario editor-can-undo-and-redo-delete [ press ctrl-y ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # first line inserted - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 2 @@ -1796,11 +1796,11 @@ scenario editor-can-undo-and-redo-delete [ press ctrl-y ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # first line inserted - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 1 @@ -1816,11 +1816,11 @@ scenario editor-can-undo-and-redo-delete [ press ctrl-y ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # first line inserted - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 1 @@ -1834,28 +1834,28 @@ scenario editor-can-undo-and-redo-delete [ ] after <delete-character-begin> [ - top-before:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + top-before:address:duplex-list:character <- get *editor, top-of-screen:offset ] before <delete-character-end> [ { break-unless deleted-cell # delete failed; don't add an undo operation - top-after:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + top-after:address:duplex-list:character <- get *editor, top-of-screen:offset cursor-row:number <- get *editor, cursor-row:offset cursor-column:number <- get *editor, cursor-column:offset - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset - undo:address:shared:list:address:shared:operation <- get *editor, undo:offset + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset + undo:address:list:address:operation <- get *editor, undo:offset { # if previous operation was an insert, coalesce this operation with it break-unless undo - op:address:shared:operation <- first undo + op:address:operation <- first undo deletion:delete-operation, is-delete?:boolean <- maybe-convert *op, delete:variant break-unless is-delete? previous-coalesce-tag:number <- get deletion, tag:offset coalesce?:boolean <- equal previous-coalesce-tag, 2/coalesce-delete break-unless coalesce? - delete-until:address:shared:duplex-list:character <- next before-cursor + delete-until:address:duplex-list:character <- next before-cursor deletion <- put deletion, delete-until:offset, delete-until - deleted-so-far:address:shared:duplex-list:character <- get deletion, deleted-text:offset + deleted-so-far:address:duplex-list:character <- get deletion, deleted-text:offset deleted-so-far <- append deleted-so-far, deleted-cell deletion <- put deletion, deleted-text:offset, deleted-so-far deletion <- put deletion, after-row:offset, cursor-row @@ -1865,8 +1865,8 @@ before <delete-character-end> [ break +done-adding-delete-operation:label } # if not, create a new operation - op:address:shared:operation <- new operation:type - deleted-until:address:shared:duplex-list:character <- next before-cursor + op:address:operation <- new operation:type + deleted-until:address:duplex-list:character <- next before-cursor *op <- merge 2/delete-operation, save-row/before, save-column/before, top-before, cursor-row/after, cursor-column/after, top-after, deleted-cell/deleted, before-cursor/delete-from, deleted-until, 2/coalesce-delete editor <- add-operation editor, op +done-adding-delete-operation @@ -1878,16 +1878,16 @@ before <delete-character-end> [ scenario editor-can-undo-and-redo-ctrl-k [ # create an editor assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # insert some text and hit delete and backspace a few times assume-console [ left-click 1, 1 press ctrl-k ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data screen-should-contain [ . . .a . @@ -1895,8 +1895,8 @@ def] .┈┈┈┈┈┈┈┈┈┈. . . ] - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 1 @@ -1906,7 +1906,7 @@ def] press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -1915,8 +1915,8 @@ def] .┈┈┈┈┈┈┈┈┈┈. . . ] - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 1 @@ -1926,7 +1926,7 @@ def] press ctrl-y ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # first line inserted screen-should-contain [ @@ -1936,8 +1936,8 @@ def] .┈┈┈┈┈┈┈┈┈┈. . . ] - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 1 @@ -1947,7 +1947,7 @@ def] type [1] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -1959,16 +1959,16 @@ def] ] after <delete-to-end-of-line-begin> [ - top-before:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + top-before:address:duplex-list:character <- get *editor, top-of-screen:offset ] before <delete-to-end-of-line-end> [ { break-unless deleted-cells # delete failed; don't add an undo operation - top-after:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + top-after:address:duplex-list:character <- get *editor, top-of-screen:offset cursor-row:number <- get *editor, cursor-row:offset cursor-column:number <- get *editor, cursor-column:offset - deleted-until:address:shared:duplex-list:character <- next before-cursor - op:address:shared:operation <- new operation:type + deleted-until:address:duplex-list:character <- next before-cursor + op:address:operation <- new operation:type *op <- merge 2/delete-operation, save-row/before, save-column/before, top-before, cursor-row/after, cursor-column/after, top-after, deleted-cells/deleted, before-cursor/delete-from, deleted-until, 0/never-coalesce editor <- add-operation editor, op +done-adding-delete-operation @@ -1980,16 +1980,16 @@ before <delete-to-end-of-line-end> [ scenario editor-can-undo-and-redo-ctrl-u [ # create an editor assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [abc + 1:address:array:character <- new [abc def] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # insert some text and hit delete and backspace a few times assume-console [ left-click 1, 2 press ctrl-u ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data screen-should-contain [ . . .c . @@ -1997,8 +1997,8 @@ def] .┈┈┈┈┈┈┈┈┈┈. . . ] - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 0 @@ -2008,7 +2008,7 @@ def] press ctrl-z ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -2017,8 +2017,8 @@ def] .┈┈┈┈┈┈┈┈┈┈. . . ] - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 2 @@ -2028,7 +2028,7 @@ def] press ctrl-y ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] # first line inserted screen-should-contain [ @@ -2038,8 +2038,8 @@ def] .┈┈┈┈┈┈┈┈┈┈. . . ] - 3:number <- get *2:address:shared:editor-data, cursor-row:offset - 4:number <- get *2:address:shared:editor-data, cursor-column:offset + 3:number <- get *2:address:editor-data, cursor-row:offset + 4:number <- get *2:address:editor-data, cursor-column:offset memory-should-contain [ 3 <- 1 4 <- 0 @@ -2049,7 +2049,7 @@ def] type [1] ] run [ - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data ] screen-should-contain [ . . @@ -2061,15 +2061,15 @@ def] ] after <delete-to-start-of-line-begin> [ - top-before:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + top-before:address:duplex-list:character <- get *editor, top-of-screen:offset ] before <delete-to-start-of-line-end> [ { break-unless deleted-cells # delete failed; don't add an undo operation - top-after:address:shared:duplex-list:character <- get *editor, top-of-screen:offset - op:address:shared:operation <- new operation:type - before-cursor:address:shared:duplex-list:character <- get *editor, before-cursor:offset - deleted-until:address:shared:duplex-list:character <- next before-cursor + top-after:address:duplex-list:character <- get *editor, top-of-screen:offset + op:address:operation <- new operation:type + before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset + deleted-until:address:duplex-list:character <- next before-cursor cursor-row:number <- get *editor, cursor-row:offset cursor-column:number <- get *editor, cursor-column:offset *op <- merge 2/delete-operation, save-row/before, save-column/before, top-before, cursor-row/after, cursor-column/after, top-after, deleted-cells/deleted, before-cursor/delete-from, deleted-until, 0/never-coalesce @@ -2081,16 +2081,16 @@ before <delete-to-start-of-line-end> [ scenario editor-can-undo-and-redo-ctrl-u-2 [ # create an editor assume-screen 10/width, 5/height - 1:address:shared:array:character <- new [] - 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right - editor-render screen, 2:address:shared:editor-data + 1:address:array:character <- new [] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + editor-render screen, 2:address:editor-data # insert some text and hit delete and backspace a few times assume-console [ type [abc] press ctrl-u press ctrl-z ] - editor-event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:editor-data + editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data screen-should-contain [ . . .abc . |