about summary refs log tree commit diff stats
path: root/043space.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-01-19 23:18:03 -0800
committerKartik K. Agaram <vc@akkartik.com>2016-01-19 23:18:03 -0800
commit455fbac64f101b05f7eaca89b84470569e4df3fd (patch)
tree32cfd5b092ad86086e4d15992bb10fd06a12bf13 /043space.cc
parent7163e18a774781c62f0c0542e4cb9037f6a71d22 (diff)
downloadmu-455fbac64f101b05f7eaca89b84470569e4df3fd.tar.gz
2576 - distinguish allocated addresses from others
This is the one major refinement on the C programming model I'm planning
to introduce in mu. Instead of Rust's menagerie of pointer types and
static checking, I want to introduce just one new type, and use it to
perform ref-counting at runtime.

So far all we're doing is updating new's interface. The actual
ref-counting implementation is next.

One implication: I might sometimes need duplicate implementations for a
recipe with allocated vs vanilla addresses of the same type. So far it
seems I can get away with just always passing in allocated addresses;
the situations when you want to pass an unallocated address to a recipe
should be few and far between.
Diffstat (limited to '043space.cc')
-rw-r--r--043space.cc28
1 files changed, 15 insertions, 13 deletions
diff --git a/043space.cc b/043space.cc
index 4f57ebd5..85db1840 100644
--- a/043space.cc
+++ b/043space.cc
@@ -7,7 +7,7 @@
 # then location 0 is really location 11, location 1 is really location 12, and so on.
 recipe main [
   10:number <- copy 5  # pretend array; in practice we'll use new
-  default-space:address:array:location <- copy 10/unsafe
+  default-space:address:shared:array:location <- copy 10/unsafe
   1:number <- copy 23
 ]
 +mem: storing 23 in location 12
@@ -19,7 +19,7 @@ recipe main [
   # pretend array
   1000:number <- copy 5
   # actual start of this recipe
-  default-space:address:array:location <- copy 1000/unsafe
+  default-space:address:shared:array:location <- copy 1000/unsafe
   1:address:number <- copy 3/unsafe
   8:number/raw <- copy *1:address:number
 ]
@@ -70,7 +70,7 @@ recipe main [
   # pretend array
   1000:number <- copy 5
   # actual start of this recipe
-  default-space:address:array:location <- copy 1000/unsafe
+  default-space:address:shared:array:location <- copy 1000/unsafe
   1:address:point <- copy 12/unsafe
   9:number/raw <- get *1:address:point, 1:offset
 ]
@@ -90,7 +90,7 @@ recipe main [
   # pretend array
   1000:number <- copy 5
   # actual start of this recipe
-  default-space:address:array:location <- copy 1000/unsafe
+  default-space:address:shared:array:location <- copy 1000/unsafe
   1:address:array:number <- copy 12/unsafe
   9:number/raw <- index *1:address:array:number, 1
 ]
@@ -119,7 +119,7 @@ if (s == "number-of-locals") return true;
 
 :(before "End Rewrite Instruction(curr, recipe result)")
 // rewrite `new-default-space` to
-//   `default-space:address:array:location <- new location:type, number-of-locals:literal`
+//   `default-space:address:shared: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);
@@ -150,7 +150,7 @@ recipe main [
 recipe foo [
   local-scope
   x:number <- copy 34
-  reply default-space:address:array:location
+  reply default-space:address:shared:array:location
 ]
 # both calls to foo should have received the same default-space
 +mem: storing 1 in location 3
@@ -186,7 +186,7 @@ void rewrite_default_space_instruction(instruction& curr) {
   curr.ingredients.push_back(reagent("number-of-locals:literal"));
   if (!curr.products.empty())
     raise_error << "new-default-space can't take any results\n" << end();
-  curr.products.push_back(reagent("default-space:address:array:location"));
+  curr.products.push_back(reagent("default-space:address:shared:array:location"));
 }
 
 //:: helpers
@@ -212,11 +212,13 @@ long long int address(long long int offset, long long int base) {
         || !x.type
         || x.type->value != get(Type_ordinal, "address")
         || !x.type->right
-        || x.type->right->value != get(Type_ordinal, "array")
+        || x.type->right->value != get(Type_ordinal, "shared")
         || !x.type->right->right
-        || x.type->right->right->value != get(Type_ordinal, "location")
-        || x.type->right->right->right) {
-      raise_error << maybe(current_recipe_name()) << "'default-space' should be of type address:array:location, but tried to write " << to_string(data) << '\n' << end();
+        || 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_error << maybe(current_recipe_name()) << "'default-space' should be of type address:shared:array:location, but tried to write " << to_string(data) << '\n' << end();
     }
     current_call().default_space = data.at(0);
     return;
@@ -224,8 +226,8 @@ long long int address(long long int offset, long long int base) {
 
 :(scenario get_default_space)
 recipe main [
-  default-space:address:array:location <- copy 10/unsafe
-  1:address:array:location/raw <- copy default-space:address:array:location
+  default-space:address:shared:array:location <- copy 10/unsafe
+  1:address:shared:array:location/raw <- copy default-space:address:shared:array:location
 ]
 +mem: storing 10 in location 1