about summary refs log tree commit diff stats
path: root/046global.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 /046global.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 '046global.cc')
-rw-r--r--046global.cc16
1 files changed, 9 insertions, 7 deletions
diff --git a/046global.cc b/046global.cc
index bd433af7..3393ed31 100644
--- a/046global.cc
+++ b/046global.cc
@@ -9,8 +9,8 @@ recipe main [
   10:number <- copy 5
   20:number <- copy 5
   # actual start of this recipe
-  global-space:address:array:location <- copy 20/unsafe
-  default-space:address:array:location <- copy 10/unsafe
+  global-space:address:shared:array:location <- copy 20/unsafe
+  default-space:address:shared:array:location <- copy 10/unsafe
   1:number <- copy 23
   1:number/space:global <- copy 24
 ]
@@ -35,11 +35,13 @@ global_space = 0;
         || !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()) << "'global-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()) << "'global-space' should be of type address:shared:array:location, but tried to write " << to_string(data) << '\n' << end();
     }
     if (Current_routine->global_space)
       raise_error << "routine already has a global-space; you can't over-write your globals" << end();
@@ -61,7 +63,7 @@ global_space = 0;
 :(scenario global_space_with_names)
 % Hide_errors = true;
 recipe main [
-  global-space:address:array:location <- new location:type, 10
+  global-space:address:shared:array:location <- new location:type, 10
   x:number <- copy 23
   1:number/space:global <- copy 24
 ]
='#n230'>230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380