about summary refs log tree commit diff stats
path: root/subx/examples/ex1
Commit message (Expand)AuthorAgeFilesLines
* 4661Kartik Agaram2018-10-041-0/+0
* 4529 - move examples to a sub-directoryKartik Agaram2018-09-011-0/+0
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
//: A few literal constants.

:(before "End Mu Types Initialization")
put(Type_ordinal, "literal-boolean", 0);

//: 'true'

:(scenario true)
def main [
  1:boolean <- copy true
]
+mem: storing 1 in location 1

:(before "End Parsing reagent")
if (name == "true") {
  if (type != NULL) {
    raise << "'true' is a literal and can't take a type\n" << end();
    return;
  }
  type = new type_tree("literal-boolean");
  set_value(1);
}
:(before "End Literal types_match Special-cases")
if (is_mu_boolean(to)) return from.name == "false" || from.name == "true";

//: 'false'

:(scenario false)
def main [
  1:boolean <- copy false
]
+mem: storing 0 in location 1

:(before "End Parsing reagent")
if (name == "false") {
  if (type != NULL) {
    raise << "'false' is a literal and can't take a type\n" << end();
    return;
  }
  type = new type_tree("literal-boolean");
  set_value(0);
}

//: 'null'

:(scenario null)
def main [
  1:address:number <- copy null
]
+mem: storing 0 in location 1

:(scenario null_has_wildcard_type)
def main [
  1:address:boolean <- copy null
]
+mem: storing 0 in location 1

:(before "End Mu Types Initialization")
put(Type_ordinal, "literal-address", 0);

:(before "End Parsing reagent")
if (name == "null") {
  if (type != NULL) {
    raise << "'null' is a literal and can't take a type\n" << end();
    return;
  }
  type = new type_tree("literal-address");
  set_value(0);
}

:(before "End Literal->Address types_match(from) Special-cases")
// allow writing null to any address
if (from.name == "null") return true;

//: scenarios for type abbreviations that we couldn't write until now

:(scenario type_abbreviation_for_compound)
type foo = address:number
def main [
  1:foo <- copy null
]
+transform: product type after expanding abbreviations: ("address" "number")

:(scenario use_type_abbreviations_when_declaring_type_abbreviations)
type foo = &:num
def main [
  1:foo <- copy null
]
+transform: product type after expanding abbreviations: ("address" "number")