1
0
Fork 0
mirror of https://github.com/ganelson/inform.git synced 2024-06-26 04:00:43 +03:00

Completed noncontiguous enumerations

This commit is contained in:
Graham Nelson 2023-06-24 12:06:10 +01:00
parent a9350acc83
commit 41964775e1
22 changed files with 261 additions and 7 deletions

View file

@ -165,8 +165,7 @@ such newcomers are graphed too.
=
build_vertex *Copies::construct_project_graph(inbuild_copy *C) {
build_vertex *V = C->vertex;
VOID_METHOD_CALL(C->edition->work->genre, GENRE_BUILDING_SOON_MTID, C, &V);
build_vertex *V = Copies::building_soon(C);
Copies::graph_everything();
return V;
}
@ -176,6 +175,12 @@ void Copies::graph_everything(void) {
LOOP_OVER(C, inbuild_copy) Copies::construct_graph(C);
}
build_vertex *Copies::building_soon(inbuild_copy *C) {
build_vertex *V = C->vertex;
VOID_METHOD_CALL(C->edition->work->genre, GENRE_BUILDING_SOON_MTID, C, &V);
return V;
}
@h Sorting.
The command-line //inbuild// uses this when sorting search results.

View file

@ -241,7 +241,8 @@ void ExtensionManager::ensure_graphed(inbuild_copy *C) {
Extensions::construct_graph(ExtensionManager::from_copy(C));
build_vertex *V;
LOOP_OVER_LINKED_LIST(V, build_vertex, C->vertex->use_edges)
ExtensionManager::ensure_graphed(V->as_copy);
if (ExtensionManager::from_copy(V->as_copy))
ExtensionManager::ensure_graphed(V->as_copy);
}
@h Source text.

View file

@ -778,6 +778,14 @@ void Extensions::construct_graph(inform_extension *E) {
Copies::get_source_text(E->as_copy);
Sentences::set_start_of_source(sfsm, -1);
Inclusions::traverse(E->as_copy, E->syntax_tree);
linked_list *L = NEW_LINKED_LIST(inbuild_nest);
inbuild_nest *N = Extensions::materials_nest(E);
ADD_TO_LINKED_LIST(N, inbuild_nest, L);
inbuild_requirement *req;
LOOP_OVER_LINKED_LIST(req, inbuild_requirement, E->kits) {
inform_kit *K = Kits::find_by_name(req->work->raw_title, L, NULL);
if (K) Graphs::need_this_to_use(E->as_copy->vertex, K->as_copy->vertex);
}
}
@h Read source text.

View file

@ -734,7 +734,9 @@ Section 1 - Enumerations
To decide which number is number of (S - description of values)
(documented at ph_numberof):
(- {-primitive-definition:number-of} -).
To decide what number is the numerical value of (V - enumerated value): (- {V} -).
To decide what number is the numerical value of (X - enumerated value): (- {X} -).
To decide what number is the sequence number of (X - enumerated value of kind K):
(- {-indexing-routine:K}({X}) -).
To decide which K is (name of kind of enumerated value K) after (X - K)
(documented at ph_enumafter):
(- {-next-routine:K}({X}) -).

View file

@ -209,6 +209,14 @@ the number of valid instances. This is guaranteed to be at least 1.
return instances-->(a_index + random(b_index - a_index + 1) - 1);
];
[ IndexOfEnumVal instances a count c;
count = instances-->0;
for (c = 1: c <= count: c++)
if (instances-->c == a)
return c;
return 0;
];
@h GenerateRandomNumber.
The following uses the virtual machine's RNG (via the I6 built-in function
|random|) to produce a uniformly random integer in the range $n$ to $m$

View file

@ -0,0 +1,9 @@
Title: TestKit
Author: Araminta Intest
Purpose: Testing.
Language: Inform 6
Licence: Artistic License 2.0
Web Syntax Version: 2
Sections
Test

View file

@ -0,0 +1,13 @@
Test Template.
Stuff.
@h Misc.
=
Constant TEST_TEMPLATE_CONSTANT = 13;
[ TestFunction;
print "The red is ", RED_COL, "^";
print "The mauve is ", MAUVE_COL, "^";
];

View file

@ -0,0 +1,9 @@
new base COLOUR_TY {
conforms-to: ENUMERATED_VALUE_TY
singular: colour
plural: colours
instance: red = RED_COL = 7
instance: purple = PURPLE_COL = 31
instance: chartreusey lavender = MAUVE_COL = 101
}

View file

@ -0,0 +1,9 @@
{
"is": {
"type": "kit",
"title": "TestKit"
},
"kit-details": {
"provides-kinds": [ "Testy.neptune" ]
}
}

View file

@ -0,0 +1,6 @@
Version 2.7 of Directorial Testing by Araminta Intest begins here.
When play begins:
say "This rule originated from the extension source."
Directorial Testing ends here.

View file

@ -0,0 +1,14 @@
{
"is": {
"type": "extension",
"title": "Directorial Testing",
"author": "Araminta Intest",
"version": "2.7"
},
"needs": [ {
"need": {
"type": "kit",
"title": "TestKit"
}
} ]
}

View file

@ -0,0 +1,45 @@
Include Directorial Testing by Araminta Intest.
Laboratory is a room.
A room has a colour called colour scheme.
After looking: say "The wallpaper has a somewhat [colour scheme of the location] tint."
Definition: A colour (called C) is valid if the sequence number of C is not 0.
When play begins:
say "This is an uninitialised colour variable - ";
let C be a colour;
showme C;
say "Iterating...";
repeat with D running through colours:
showme D;
showme the colour after D;
showme the colour before D;
showme the sequence number of D;
showme the numerical value of D;
showme whether or not D is valid;
say "Done.";
say "Now for a limited-span repeat...";
repeat with D running from red to purple:
showme D;
say "Done.";
showme the list of colours;
showme the first value of colour;
showme the last value of colour;
showme the colour scheme of the Laboratory;
say "This tests bracket-plus...";
test out bracket-plus;
say "Now for some random values...";
repeat with N running from 1 to 100:
say "[a random colour]; ";
say "... enough!";
repeat with N running from 1 to 100:
say "[a random colour from red to purple]; ";
say "... enough!";
To test out bracket-plus: (-
TestFunction();
print MAUVE_COL, " = ", (+ chartreusey lavender +), "^";
-).

View file

@ -0,0 +1,50 @@
Laboratory
This rule originated from the extension source.
This is an uninitialised colour variable - "C" = colour: red
Iterating...
"D" = colour: red
"colour after D" = colour: purple
"colour before D" = colour: chartreusey lavender
"sequence number of D" = number: 1
"numerical value of D" = number: 7
"whether or not D is valid" = truth state: true
"D" = colour: purple
"colour after D" = colour: chartreusey lavender
"colour before D" = colour: red
"sequence number of D" = number: 2
"numerical value of D" = number: 31
"whether or not D is valid" = truth state: true
"D" = colour: chartreusey lavender
"colour after D" = colour: red
"colour before D" = colour: purple
"sequence number of D" = number: 3
"numerical value of D" = number: 101
"whether or not D is valid" = truth state: true
Done.
Now for a limited-span repeat...
"D" = colour: red
"D" = colour: purple
Done.
"list of colours" = list of colours: {red, purple, chartreusey lavender}
"first value of colour" = colour: red
"last value of colour" = colour: chartreusey lavender
"colour scheme of the Laboratory" = colour: red
This tests bracket-plus...
The red is 7
The mauve is 101
101 = 101
Now for some random values...
purple; purple; chartreusey lavender; purple; red; red; chartreusey lavender; purple; chartreusey lavender; red; purple; chartreusey lavender; chartreusey lavender; purple; chartreusey lavender; red; purple; purple; red; purple; red; chartreusey lavender; purple; chartreusey lavender; chartreusey lavender; chartreusey lavender; purple; red; red; red; purple; purple; purple; red; purple; chartreusey lavender; red; purple; purple; purple; chartreusey lavender; purple; chartreusey lavender; chartreusey lavender; red; purple; red; red; red; red; chartreusey lavender; purple; purple; chartreusey lavender; purple; purple; chartreusey lavender; red; red; purple; purple; chartreusey lavender; chartreusey lavender; red; red; red; red; red; red; purple; red; chartreusey lavender; purple; red; purple; red; chartreusey lavender; purple; purple; chartreusey lavender; red; red; chartreusey lavender; chartreusey lavender; chartreusey lavender; chartreusey lavender; purple; purple; purple; purple;
chartreusey lavender; chartreusey lavender; purple; red; red; red; purple; chartreusey lavender; red; red; ... enough!
red; purple; red; purple; red; red; purple; red; purple; purple; red; red; purple; red; purple; purple; red; purple; red; red; purple; red; red; purple; purple; purple; purple; red; red; purple; red; purple; red; red; red; red; purple; purple; red; red; purple; purple; red; purple; purple; purple; purple; red; purple; purple; purple; red; red; red; purple; red; red; purple; purple; purple; purple; purple; red; red; purple; red; red; purple; purple; red; red; purple; red; red; purple; red; purple; purple; red; red; purple; red; red; red; purple; red; purple; red; purple; red; red; purple; red; purple; purple; purple; red; purple; purple; purple; ... enough!
Welcome
An Interactive Fiction
Release 1 / Serial number 160428 / Inform 7 v10.2.0 / D
Laboratory
The wallpaper has a somewhat red tint.
> > Laboratory
> Are you sure you want to quit?

View file

@ -915,7 +915,9 @@ Section 1 - Enumerations
To decide which number is number of (S - description of values)
(documented at ph_numberof):
(- {-primitive-definition:number-of} -).
To decide what number is the numerical value of (V - enumerated value): (- {V} -).
To decide what number is the numerical value of (X - enumerated value): (- {X} -).
To decide what number is the sequence number of (X - enumerated value of kind K):
(- {-indexing-routine:K}({X}) -).
To decide which K is (name of kind of enumerated value K) after (X - K)
(documented at ph_enumafter):
(- {-next-routine:K}({X}) -).

View file

@ -667,6 +667,7 @@ We'll start with a suite of details about kinds:
if (C == new_list_of_ISINC) @<Inline command "new-list-of"@>;
if (C == printing_routine_ISINC) @<Inline command "printing-routine"@>;
if (C == ranger_routine_ISINC) @<Inline command "ranger-routine"@>;
if (C == indexing_routine_ISINC) @<Inline command "indexing-routine"@>;
if (C == next_routine_ISINC) @<Inline command "next-routine"@>;
if (C == previous_routine_ISINC) @<Inline command "previous-routine"@>;
if (C == strong_kind_ISINC) @<Inline command "strong-kind"@>;
@ -742,6 +743,13 @@ proposition.
else @<Issue an inline no-such-kind problem@>;
return;
@<Inline command "indexing-routine"@> =
kind *K = CSIInline::parse_bracing_operand_as_kind(ist->operand,
Node::get_kind_variable_declarations(inv));
if (K) EmitCode::val_iname(K_value, RTKindConstructors::get_indexing_iname(K));
else @<Issue an inline no-such-kind problem@>;
return;
@<Inline command "strong-kind"@> =
kind *K = CSIInline::parse_bracing_operand_as_kind(ist->operand,
Node::get_kind_variable_declarations(inv));

View file

@ -1217,6 +1217,7 @@ void Hierarchy::establish(void) {
@e PRINT_DASH_FN_HL
@e MKDEF_FN_HL
@e RANGER_FN_HL
@e INDEXING_FN_HL
@e DEFAULT_CLOSURE_FN_HL
@e GPR_FN_HL
@e SHOWME_FN_HL
@ -1327,6 +1328,7 @@ void Hierarchy::establish(void) {
H_F_U(PRINT_FN_HL, I"print_fn")
H_F_G(PRINT_DASH_FN_HL, I"print_fn", I"E")
H_F_U(RANGER_FN_HL, I"ranger_fn")
H_F_U(INDEXING_FN_HL, I"indexing_fn")
H_F_U(DEFAULT_CLOSURE_FN_HL, I"default_closure_fn")
H_F_U(GPR_FN_HL, I"gpr_fn")
H_F_U(INSTANCE_GPR_FN_HL, I"instance_gpr_fn")

View file

@ -345,6 +345,7 @@ void RTInstances::set_translation(instance *I, text_stream *identifier) {
inter_name *iname = RTInstances::value_iname(I);
InterNames::set_translation(iname, identifier);
InterNames::clear_flag(iname, MAKE_NAME_UNIQUE_ISYMF);
Hierarchy::make_available(iname);
}
@ When names are abbreviated for use on the World Index map (for instance,

View file

@ -22,6 +22,7 @@ typedef struct kind_constructor_compilation_data {
struct inter_name *dec_iname;
struct inter_name *mkdef_iname;
struct inter_name *ranger_iname;
struct inter_name *indexing_iname;
struct inter_name *debug_print_fn_iname;
struct package_request *usage_package;
int declaration_sequence_number;
@ -46,6 +47,7 @@ kind_constructor_compilation_data RTKindConstructors::new_compilation_data(kind_
kccd.dec_iname = NULL;
kccd.mkdef_iname = NULL;
kccd.ranger_iname = NULL;
kccd.indexing_iname = NULL;
kccd.debug_print_fn_iname = NULL;
kccd.usage_package = NULL;
kccd.declaration_sequence_number = -1;
@ -369,6 +371,13 @@ inter_name *RTKindConstructors::get_ranger_iname(kind *K) {
K->construct->compilation_data.ranger_iname = Hierarchy::make_iname_in(RANGER_FN_HL, R);
return K->construct->compilation_data.ranger_iname;
}
inter_name *RTKindConstructors::get_indexing_iname(kind *K) {
if (K == NULL) internal_error("null kind has no indexing fn");
if (K->construct->compilation_data.indexing_iname) return K->construct->compilation_data.indexing_iname;
package_request *R = RTKindConstructors::kind_package(K);
K->construct->compilation_data.indexing_iname = Hierarchy::make_iname_in(INDEXING_FN_HL, R);
return K->construct->compilation_data.indexing_iname;
}
inter_name *RTKindConstructors::get_mkdef_iname(kind_constructor *kc) {
if (kc->compilation_data.mkdef_iname == NULL)
kc->compilation_data.mkdef_iname =
@ -1021,6 +1030,7 @@ void RTKindConstructors::compile_permissions(void) {
@<Compile I6 printing routine for an enumerated kind@>;
@<Compile the A and B routines for an enumerated kind@>;
@<Compile random-ranger routine for this kind@>;
@<Compile indexing routine for this kind@>;
}
if ((Kinds::Behaviour::is_built_in(K) == FALSE) &&
(Kinds::Behaviour::is_subkind_of_object(K) == FALSE) &&
@ -1391,3 +1401,48 @@ and |b| inclusive.
EmitCode::up();
EmitCode::up();
@<Compile indexing routine for this kind@> =
inter_name *iname_r = RTKindConstructors::get_indexing_iname(K);
packaging_state save = Functions::begin(iname_r);
inter_symbol *a_s = LocalVariables::new_other_as_symbol(I"a");
if (RTKindConstructors::is_nonstandard_enumeration(K)) {
EmitCode::inv(RETURN_BIP);
EmitCode::down();
EmitCode::call(Hierarchy::find(INDEX_OF_ENUM_VAL_HL));
EmitCode::down();
EmitCode::val_iname(K_value, RTKindConstructors::instances_array_iname(K));
EmitCode::val_symbol(K_value, a_s);
EmitCode::up();
EmitCode::up();
} else {
EmitCode::inv(IF_BIP);
EmitCode::down();
EmitCode::inv(OR_BIP);
EmitCode::down();
EmitCode::inv(LT_BIP);
EmitCode::down();
EmitCode::val_symbol(K_value, a_s);
EmitCode::val_number(0);
EmitCode::up();
EmitCode::inv(GT_BIP);
EmitCode::down();
EmitCode::val_symbol(K_value, a_s);
EmitCode::val_number((inter_ti) RTKindConstructors::get_highest_valid_value_as_integer(K));
EmitCode::up();
EmitCode::up();
EmitCode::code();
EmitCode::down();
EmitCode::inv(RETURN_BIP);
EmitCode::down();
EmitCode::val_number(0);
EmitCode::up();
EmitCode::up();
EmitCode::up();
EmitCode::inv(RETURN_BIP);
EmitCode::down();
EmitCode::val_symbol(K_value, a_s);
EmitCode::up();
}
Functions::end(save);

View file

@ -326,6 +326,7 @@ inter_schema_token *InterSchemas::new_token(int type, text_stream *material,
@e next_routine_ISINC
@e previous_routine_ISINC
@e ranger_routine_ISINC
@e indexing_routine_ISINC
@e strong_kind_ISINC
@e weak_kind_ISINC
@e backspace_ISINC

View file

@ -247,6 +247,8 @@ a bracing.
c = printing_routine_ISINC;
} else if (Str::eq_wide_string(t->command, L"ranger-routine")) {
c = ranger_routine_ISINC;
} else if (Str::eq_wide_string(t->command, L"indexing-routine")) {
c = indexing_routine_ISINC;
} else if (Str::eq_wide_string(t->command, L"next-routine")) {
c = next_routine_ISINC;
} else if (Str::eq_wide_string(t->command, L"previous-routine")) {

View file

@ -22,7 +22,8 @@ these words would be 5, 2 and 4 respectively.
=
int BinaryInter::test_file(filename *F) {
int verdict = TRUE;
FILE *fh = BinaryFiles::open_for_reading(F);
FILE *fh = BinaryFiles::try_to_open_for_reading(F);
if (fh == NULL) return FALSE;
unsigned int X = 0;
if ((BinaryFiles::read_int32(fh, &X) == FALSE) ||
((inter_ti) X != INTER_SHIBBOLETH)) verdict = FALSE;
@ -37,7 +38,8 @@ file, or else a null semver if the file isn't binary Inter:
=
semantic_version_number BinaryInter::test_file_version(filename *F) {
FILE *fh = BinaryFiles::open_for_reading(F);
FILE *fh = BinaryFiles::try_to_open_for_reading(F);
if (fh == NULL) return VersionNumbers::null();
unsigned int X = 0;
if ((BinaryFiles::read_int32(fh, &X) == FALSE) ||
((inter_ti) X != INTER_SHIBBOLETH) ||

View file

@ -94,6 +94,7 @@ comprehensive list of what is there.)
@e GPROPERTY_HL
@e HASHLISTRELATIONHANDLER_HL
@e I7SFRAME_HL
@e INDEX_OF_ENUM_VAL_HL
@e INTEGERDIVIDE_HL
@e INTEGERREMAINDER_HL
@e KINDATOMIC_HL
@ -240,6 +241,7 @@ comprehensive list of what is there.)
KIT_PROVIDED(GPROPERTY_HL, I"GProperty")
KIT_PROVIDED(HASHLISTRELATIONHANDLER_HL, I"HashListRelationHandler")
KIT_PROVIDED(I7SFRAME_HL, I"I7SFRAME")
KIT_PROVIDED(INDEX_OF_ENUM_VAL_HL, I"IndexOfEnumVal");
KIT_PROVIDED(INTEGERDIVIDE_HL, I"IntegerDivide")
KIT_PROVIDED(INTEGERREMAINDER_HL, I"IntegerRemainder")
KIT_PROVIDED(KINDATOMIC_HL, I"KindAtomic")