2284
This commit is contained in:
parent
ae256ea13e
commit
72d5d0185c
8
010vm.cc
8
010vm.cc
|
@ -165,9 +165,9 @@ atexit(teardown_types);
|
|||
// with different properties for each, that may require an exclusive container
|
||||
// whose variants are individual-account and joint-account containers.
|
||||
enum kind_of_type {
|
||||
primitive,
|
||||
container,
|
||||
exclusive_container
|
||||
PRIMITIVE,
|
||||
CONTAINER,
|
||||
EXCLUSIVE_CONTAINER
|
||||
};
|
||||
|
||||
struct type_info {
|
||||
|
@ -177,7 +177,7 @@ struct type_info {
|
|||
vector<type_tree*> elements;
|
||||
vector<string> element_names;
|
||||
// End type_info Fields
|
||||
type_info() :kind(primitive), size(0) {}
|
||||
type_info() :kind(PRIMITIVE), size(0) {}
|
||||
};
|
||||
|
||||
enum primitive_recipes {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
//: We'll use this container as a running example, with two number elements.
|
||||
type_ordinal point = Type_ordinal["point"] = Next_type_ordinal++;
|
||||
Type[point].size = 2;
|
||||
Type[point].kind = container;
|
||||
Type[point].kind = CONTAINER;
|
||||
Type[point].name = "point";
|
||||
Type[point].elements.push_back(new type_tree(number));
|
||||
Type[point].element_names.push_back("x");
|
||||
|
@ -39,7 +39,7 @@ recipe main [
|
|||
// elements.
|
||||
type_ordinal point_number = Type_ordinal["point-number"] = Next_type_ordinal++;
|
||||
Type[point_number].size = 2;
|
||||
Type[point_number].kind = container;
|
||||
Type[point_number].kind = CONTAINER;
|
||||
Type[point_number].name = "point-number";
|
||||
Type[point_number].elements.push_back(new type_tree(point));
|
||||
Type[point_number].element_names.push_back("xy");
|
||||
|
@ -88,7 +88,7 @@ if (type->value == 0) {
|
|||
return 1;
|
||||
}
|
||||
type_info t = Type[type->value];
|
||||
if (t.kind == container) {
|
||||
if (t.kind == CONTAINER) {
|
||||
// size of a container is the sum of the sizes of its elements
|
||||
long long int result = 0;
|
||||
for (long long int i = 0; i < SIZE(t.elements); ++i) {
|
||||
|
@ -133,7 +133,7 @@ case GET: {
|
|||
}
|
||||
reagent base = inst.ingredients.at(0);
|
||||
// Update GET base in Check
|
||||
if (!base.type || !base.type->value || Type[base.type->value].kind != container) {
|
||||
if (!base.type || !base.type->value || Type[base.type->value].kind != CONTAINER) {
|
||||
raise_error << maybe(Recipe[r].name) << "first ingredient of 'get' should be a container, but got " << inst.ingredients.at(0).original_string << '\n' << end();
|
||||
break;
|
||||
}
|
||||
|
@ -252,7 +252,7 @@ case GET_ADDRESS: {
|
|||
}
|
||||
reagent base = inst.ingredients.at(0);
|
||||
// Update GET_ADDRESS base in Check
|
||||
if (!base.type || Type[base.type->value].kind != container) {
|
||||
if (!base.type || Type[base.type->value].kind != CONTAINER) {
|
||||
raise_error << maybe(Recipe[r].name) << "first ingredient of 'get-address' should be a container, but got " << inst.ingredients.at(0).original_string << '\n' << end();
|
||||
break;
|
||||
}
|
||||
|
@ -374,7 +374,7 @@ container bar [
|
|||
|
||||
:(before "End Command Handlers")
|
||||
else if (command == "container") {
|
||||
insert_container(command, container, in);
|
||||
insert_container(command, CONTAINER, in);
|
||||
}
|
||||
|
||||
:(code)
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
{
|
||||
type_ordinal tmp = Type_ordinal["number-or-point"] = Next_type_ordinal++;
|
||||
Type[tmp].size = 2;
|
||||
Type[tmp].kind = exclusive_container;
|
||||
Type[tmp].kind = EXCLUSIVE_CONTAINER;
|
||||
Type[tmp].name = "number-or-point";
|
||||
Type[tmp].elements.push_back(new type_tree(number));
|
||||
Type[tmp].element_names.push_back("i");
|
||||
|
@ -33,7 +33,7 @@ recipe main [
|
|||
+mem: storing 35 in location 6
|
||||
|
||||
:(before "End size_of(type) Cases")
|
||||
if (t.kind == exclusive_container) {
|
||||
if (t.kind == EXCLUSIVE_CONTAINER) {
|
||||
// size of an exclusive container is the size of its largest variant
|
||||
// (So like containers, it can't contain arrays.)
|
||||
long long int result = 0;
|
||||
|
@ -85,7 +85,7 @@ case MAYBE_CONVERT: {
|
|||
}
|
||||
reagent base = inst.ingredients.at(0);
|
||||
canonize_type(base);
|
||||
if (!base.type || !base.type->value || Type[base.type->value].kind != exclusive_container) {
|
||||
if (!base.type || !base.type->value || Type[base.type->value].kind != EXCLUSIVE_CONTAINER) {
|
||||
raise_error << maybe(Recipe[r].name) << "first ingredient of 'maybe-convert' should be an exclusive-container, but got " << base.original_string << '\n' << end();
|
||||
break;
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ exclusive-container foo [
|
|||
|
||||
:(before "End Command Handlers")
|
||||
else if (command == "exclusive-container") {
|
||||
insert_container(command, exclusive_container, in);
|
||||
insert_container(command, EXCLUSIVE_CONTAINER, in);
|
||||
}
|
||||
|
||||
//:: To construct exclusive containers out of variant types, use 'merge'.
|
||||
|
@ -160,7 +160,7 @@ if (current_instruction().operation == MERGE
|
|||
&& current_instruction().products.at(0).type) {
|
||||
reagent x = current_instruction().products.at(0);
|
||||
canonize(x);
|
||||
if (Type[x.type->value].kind == exclusive_container) {
|
||||
if (Type[x.type->value].kind == EXCLUSIVE_CONTAINER) {
|
||||
return size_of(x) < SIZE(data);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user