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

More organised idea of copy scanning

This commit is contained in:
Graham Nelson 2020-02-18 19:57:31 +00:00
parent fb40729621
commit 4d9d263343
16 changed files with 127 additions and 190 deletions

1
inbuild/.gitignore vendored
View file

@ -13,4 +13,5 @@ Tests/_Results_Actual/
inbuild.mk
Tests/Units/_Results_Actual/
Tests/Miscellany/_Results_Actual/

View file

@ -0,0 +1 @@
kit: CastrovalvaKit v2.7.1 (not for 32 or 32d) at path inbuild/Tests/Zoo/Inter/CastrovalvaKit

View file

@ -0,0 +1 @@
-inspect -matching all

View file

@ -1,143 +0,0 @@
schema
alpha.beta()
end
schema
alpha.beta(x)
end
schema
routine.call(x)
end
schema
(alpha.beta)(x)
end
schema
debug_rules = 2; say__p = 1;
"Rules tracing now switched to ~all~. Type ~rules off~ to switch it off again.";
end
schema
@erase_window -1;
end
schema
restore Somewhere;
.Somewhere; print "Here!";
end
schema
"Hello, this
is a multiline string literal";
end
schema
for (n=0:((n<RE_Subexpressions-->10) && (n<10)): n++)
print n;
end
schema
spaces j;
print (I7_string) str;
end
schema
if (i == 1) print "Okay";
else "*** Arrcpy doesn't support this ***";
end
schema
a-1
end
schema
do {
print "Hi!";
} until (x);
end
schema
do {
if (a) return wd;
} until (a);
end
schema
do {
if (line_tdata-->index == wd) return wd;
index++;
} until ((line_token-->index == ENDIT_TOKEN) || (((line_token-->index)->0 & $10) == 0));
end
schema
print "<string ~", (string) o, "~>";
end
schema
switch (Y) {
X: print "A ", (string) o;
}
end
schema
#ifdef RANKING_TABLE;
ANNOUNCE_SCORE_RM('B');
j = TableRows(RANKING_TABLE);
for (i=j:i>=1:i--)
if (score >= TableLookUpEntry(RANKING_TABLE, 1, i)) {
v = TableLookUpEntry(RANKING_TABLE, 2, i);
TEXT_TY_Say(v);
".";
}
#endif;
".";'
end
schema
if (B) if (A) { print "Yes"; }
print "No";
end
schema
switch (scope_stage) {
2: objectloop (obj)
PlaceInScope(obj, true);
}
end
schema
while (token ~= NULL) {
switch (token-->RE_CCLASS) {
DISJUNCTION_RE_CC: token-->RE_CONSTRAINT = -1;
QUANTIFIER_RE_CC: token-->RE_CONSTRAINT = -1;
}
if (token-->RE_DOWN) TEXT_TY_RE_EraseConstraints(token-->RE_DOWN);
token = token-->RE_NEXT;
}
end
schema
if (b) print 1; else print 2;
end
schema
a: if (b) print 1; else print 2;
end
schema
print_ret "This is ", (char) X, ".";
end
schema
@jl y 0 ?X;
@jl y 0 ?~X;
@jl y 0 ?rtrue;
@jl y 0 ?rfalse;
@jl y 0 ?~rtrue;
@jl y 0 ?~rfalse;
end
schema
switch (token-->RE_CCLASS) {
! Should never happen
CHOICE_RE_CC: return "internal error";
! Mode switches
SENSITIVITY_RE_CC:
if (token-->RE_PAR1) mode_flags = mode_flags | CIS_MFLAG;
else mode_flags = mode_flags & (~CIS_MFLAG);
outcome = true;
! Zero-length positional markers
ALWAYS_RE_CC:
outcome = true;
NEVER_RE_CC:
START_RE_CC:
if (ipos == 0) outcome = true;
END_RE_CC:
if (BlkValueRead(txt, ipos) == 0) outcome = true;
SOMETIMES_RE_CC:
outcome = true;
}
end

View file

@ -0,0 +1,8 @@
Title: CastrovalvaKit
Author: M. C. Escher
Purpose: A confusing middle-European town of a bygone age.
Language: Inform 6
Licence: Artistic License 2.0
Sections
Staircases

View file

@ -0,0 +1,11 @@
Staircases.
These lead in surprising directions.
@h Functions.
=
[ UpOrDown;
print "Both!^";
rfalse;
];

View file

@ -0,0 +1,3 @@
version: 2.7.1
compatibility: not for 32 or 32d
priority: 1

View file

@ -1,4 +1,5 @@
-cases [Units] 'inbuild/Tests/Units'
-cases [Miscellany] 'inbuild/Tests/Miscellany'
-recipe [Units]
set: $A = $PATH/_Results_Actual/$CASE.txt
@ -7,8 +8,25 @@
mkdir: $PATH/_Results_Actual
mkdir: $PATH/_Results_Ideal
debugger: llvm -f inbuild/Tangled/inbuild -- -unit-test $CASE
step: inbuild/Tangled/inbuild -unit-test $CASE >$A 2>&1
debugger: llvm -f inbuild/Tangled/inbuild -- -nest inbuild/Tests/Zoo -unit-test $CASE
step: inbuild/Tangled/inbuild -nest inbuild/Tests/Zoo -unit-test $CASE >$A 2>&1
or: 'failed to produce output' $A
show: $A
match text: $A $I
or: 'produced incorrect output'
-end
-recipe [Miscellany]
set: $A = $PATH/_Results_Actual/$CASE.txt
set: $I = $PATH/_Results_Ideal/$CASE.txt
mkdir: $PATH/_Results_Actual
mkdir: $PATH/_Results_Ideal
debugger: llvm -f inbuild/Tangled/inbuild -- -nest inbuild/Tests/Zoo $[$PATH/$CASE.txt$]
step: inbuild/Tangled/inbuild -nest inbuild/Tests/Zoo $[$PATH/$CASE.txt$] >$A 2>&1
or: 'failed to produce output' $A
show: $A

View file

@ -3,3 +3,4 @@
inbuild.mk
Tests/Units/_Results_Actual/
Tests/Miscellany/_Results_Actual/

View file

@ -47,6 +47,10 @@ inbuild_copy *Copies::new_in_path(inbuild_edition *edition, pathname *P, general
return copy;
}
void Copies::set_content(inbuild_copy *C, general_pointer ref) {
C->content = ref;
}
void Copies::write_copy(OUTPUT_STREAM, inbuild_copy *C) {
Editions::write(OUT, C->edition);
}
@ -55,6 +59,10 @@ void Copies::go_operational(inbuild_copy *C) {
VMETHOD_CALL(C->edition->work->genre, GENRE_GO_OPERATIONAL_MTID, C);
}
void Copies::scan(inbuild_copy *C) {
VMETHOD_CALL(C->edition->work->genre, GENRE_SCAN_COPY_MTID, C);
}
wording Copies::read_source_text_for(inbuild_copy *C) {
if (C->source_text_read == FALSE) {
C->source_text_read = TRUE;
@ -117,6 +125,7 @@ extension files but have a mangled identification line. Each copy structure
therefore has a list attached of errors which occurred in reading it.
@e OPEN_FAILED_CE from 1
@e KIT_MISWORDED_CE
@e EXT_MISWORDED_CE
@e EXT_TITLE_TOO_LONG_CE
@e EXT_AUTHOR_TOO_LONG_CE
@ -177,6 +186,7 @@ void Copies::list_problems_arising(OUTPUT_STREAM, inbuild_copy *C) {
switch (CE->error_category) {
case OPEN_FAILED_CE: WRITE("unable to open file %f", CE->file); break;
case EXT_MISWORDED_CE: WRITE("extension misworded: %S", CE->notes); break;
case KIT_MISWORDED_CE: WRITE("kit has incorrect metadata: %S", CE->notes); break;
case EXT_TITLE_TOO_LONG_CE: WRITE("title too long: %d characters (max is %d)",
CE->details_N, MAX_EXTENSION_TITLE_LENGTH); break;
case EXT_AUTHOR_TOO_LONG_CE: WRITE("author name too long: %d characters (max is %d)",

View file

@ -33,6 +33,7 @@ text_stream *Genres::name(inbuild_genre *G) {
@e GENRE_WRITE_WORK_MTID
@e GENRE_CLAIM_AS_COPY_MTID
@e GENRE_SCAN_COPY_MTID
@e GENRE_SEARCH_NEST_FOR_MTID
@e GENRE_COPY_TO_NEST_MTID
@e GENRE_GO_OPERATIONAL_MTID
@ -44,6 +45,8 @@ VMETHOD_TYPE(GENRE_WRITE_WORK_MTID,
VMETHOD_TYPE(GENRE_CLAIM_AS_COPY_MTID,
inbuild_genre *gen, inbuild_copy **C, text_stream *arg, text_stream *ext,
int directory_status)
VMETHOD_TYPE(GENRE_SCAN_COPY_MTID,
inbuild_genre *gen, inbuild_copy *C)
VMETHOD_TYPE(GENRE_SEARCH_NEST_FOR_MTID,
inbuild_genre *gen, inbuild_nest *N, inbuild_requirement *req,
linked_list *search_results)

View file

@ -308,8 +308,10 @@ void ExtensionManager::search_nest_for_r(pathname *P, inbuild_nest *N,
while (Directories::next(D, LEAFNAME)) {
if (Str::get_last_char(LEAFNAME) == FOLDER_SEPARATOR) {
Str::delete_last_character(LEAFNAME);
pathname *Q = Pathnames::subfolder(P, LEAFNAME);
ExtensionManager::search_nest_for_r(Q, N, req, search_results);
if (Str::ne(LEAFNAME, I"Reserved")) {
pathname *Q = Pathnames::subfolder(P, LEAFNAME);
ExtensionManager::search_nest_for_r(Q, N, req, search_results);
}
} else {
filename *F = Filenames::in_folder(P, LEAFNAME);
ExtensionManager::search_nest_for_single_file(F, N, req, search_results);

View file

@ -10,6 +10,7 @@ void KitManager::start(void) {
kit_genre = Genres::new(I"kit");
METHOD_ADD(kit_genre, GENRE_WRITE_WORK_MTID, KitManager::write_work);
METHOD_ADD(kit_genre, GENRE_CLAIM_AS_COPY_MTID, KitManager::claim_as_copy);
METHOD_ADD(kit_genre, GENRE_SCAN_COPY_MTID, Kits::scan);
METHOD_ADD(kit_genre, GENRE_SEARCH_NEST_FOR_MTID, KitManager::search_nest_for);
METHOD_ADD(kit_genre, GENRE_COPY_TO_NEST_MTID, KitManager::copy_to_nest);
METHOD_ADD(kit_genre, GENRE_GO_OPERATIONAL_MTID, KitManager::go_operational);
@ -47,11 +48,10 @@ inbuild_copy *KitManager::new_copy(text_stream *name, pathname *P) {
if (Dictionaries::find(kit_copy_cache, key))
C = Dictionaries::read_value(kit_copy_cache, key);
if (C == NULL) {
inform_kit *K = Kits::new_ik(name, P);
inbuild_work *work = Works::new_raw(kit_genre, Str::duplicate(name), NULL);
inbuild_edition *edition = Editions::new(work, K->version);
C = Copies::new_in_path(edition, P, STORE_POINTER_inform_kit(K));
K->as_copy = C;
inbuild_edition *edition = Editions::new(work, VersionNumbers::null());
C = Copies::new_in_path(edition, P, NULL_GENERAL_POINTER);
Copies::scan(C);
Dictionaries::create(kit_copy_cache, key);
Dictionaries::write_value(kit_copy_cache, key, C);
}

View file

@ -7,7 +7,6 @@ A kit is a combination of Inter code with an Inform 7 extension.
=
typedef struct inform_kit {
struct inbuild_copy *as_copy;
struct text_stream *name;
struct text_stream *attachment_point;
struct text_stream *early_source;
struct linked_list *ittt; /* of |inform_kit_ittt| */
@ -15,7 +14,6 @@ typedef struct inform_kit {
struct linked_list *extensions; /* of |inbuild_requirement| */
struct linked_list *activations; /* of |element_activation| */
struct text_stream *index_template;
struct inbuild_version_number version;
int defines_Main;
int supports_inform_language;
int priority;
@ -46,12 +44,13 @@ pathname *Kits::find(text_stream *name, linked_list *nest_list) {
return NULL;
}
inform_kit *Kits::new_ik(text_stream *name, pathname *P) {
void Kits::scan(inbuild_genre *G, inbuild_copy *C) {
if (C == NULL) internal_error("no copy to scan");
inform_kit *K = CREATE(inform_kit);
K->as_copy = NULL;
K->name = Str::duplicate(name);
K->as_copy = C;
Copies::set_content(C, STORE_POINTER_inform_kit(K));
K->attachment_point = Str::new();
WRITE_TO(K->attachment_point, "/main/%S", name);
K->early_source = NULL;
K->priority = 10;
K->ittt = NEW_LINKED_LIST(inform_kit_ittt);
@ -61,44 +60,31 @@ inform_kit *Kits::new_ik(text_stream *name, pathname *P) {
K->defines_Main = FALSE;
K->supports_inform_language = FALSE;
K->index_template = NULL;
K->version = VersionNumbers::null();
filename *F = Filenames::in_folder(P, I"kit_metadata.txt");
filename *F = Filenames::in_folder(C->location_if_path, I"kit_metadata.txt");
TextFiles::read(F, FALSE,
NULL, FALSE, Kits::read_metadata, NULL, (void *) K);
return K;
}
NULL, FALSE, Kits::read_metadata, NULL, (void *) C);
inform_kit *Kits::load(text_stream *name, linked_list *nest_list) {
pathname *P = Kits::find(name, nest_list);
if (P == NULL) Errors::fatal_with_text("cannot find kit", name);
inbuild_copy *C = KitManager::new_copy(name, P);
if (C->vertex == NULL) KitManager::build_vertex(C);
return KitManager::from_copy(C);
}
void Kits::dependency(inform_kit *K, text_stream *if_text, int inc, text_stream *then_text) {
inform_kit_ittt *ITTT = CREATE(inform_kit_ittt);
ITTT->if_name = Str::duplicate(if_text);
ITTT->if_included = inc;
ITTT->then_name = Str::duplicate(then_text);
ADD_TO_LINKED_LIST(ITTT, inform_kit_ittt, K->ittt);
}
void Kits::activation(inform_kit *K, text_stream *name, int act) {
element_activation *EA = CREATE(element_activation);
EA->element_name = Str::duplicate(name);
EA->activate = act;
ADD_TO_LINKED_LIST(EA, element_activation, K->activations);
WRITE_TO(K->attachment_point, "/main/%S", C->edition->work->title);
}
void Kits::read_metadata(text_stream *text, text_file_position *tfp, void *state) {
inform_kit *K = (inform_kit *) state;
inbuild_copy *C = (inbuild_copy *) state;
inform_kit *K = KitManager::from_copy(C);
match_results mr = Regexp::create_mr();
if ((Str::is_whitespace(text)) || (Regexp::match(&mr, text, L" *#%c*"))) {
;
} else if (Regexp::match(&mr, text, L"version: (%C+)")) {
K->version = VersionNumbers::from_text(mr.exp[0]);
C->edition->version = VersionNumbers::from_text(mr.exp[0]);
} else if (Regexp::match(&mr, text, L"compatibility: (%c+)")) {
compatibility_specification *CS = Compatibility::from_text(mr.exp[0]);
if (CS) C->edition->compatibility = CS;
else {
TEMPORARY_TEXT(err);
WRITE_TO(err, "cannot read compatibility '%S'", mr.exp[0]);
Copies::attach(C, Copies::new_error(KIT_MISWORDED_CE, err));
DISCARD_TEXT(err);
}
} else if (Regexp::match(&mr, text, L"defines Main: yes")) {
K->defines_Main = TRUE;
} else if (Regexp::match(&mr, text, L"defines Main: no")) {
@ -129,12 +115,37 @@ void Kits::read_metadata(text_stream *text, text_file_position *tfp, void *state
} else if (Regexp::match(&mr, text, L"index from: (%c*)")) {
K->index_template = Str::duplicate(mr.exp[0]);
} else {
Errors::in_text_file("illegible line in kit metadata file", tfp);
WRITE_TO(STDERR, "'%S'\n", text);
TEMPORARY_TEXT(err);
WRITE_TO(err, "unreadable instruction '%S'", text);
Copies::attach(C, Copies::new_error(KIT_MISWORDED_CE, err));
DISCARD_TEXT(err);
}
Regexp::dispose_of(&mr);
}
inform_kit *Kits::load(text_stream *name, linked_list *nest_list) {
pathname *P = Kits::find(name, nest_list);
if (P == NULL) Errors::fatal_with_text("cannot find kit", name);
inbuild_copy *C = KitManager::new_copy(name, P);
if (C->vertex == NULL) KitManager::build_vertex(C);
return KitManager::from_copy(C);
}
void Kits::dependency(inform_kit *K, text_stream *if_text, int inc, text_stream *then_text) {
inform_kit_ittt *ITTT = CREATE(inform_kit_ittt);
ITTT->if_name = Str::duplicate(if_text);
ITTT->if_included = inc;
ITTT->then_name = Str::duplicate(then_text);
ADD_TO_LINKED_LIST(ITTT, inform_kit_ittt, K->ittt);
}
void Kits::activation(inform_kit *K, text_stream *name, int act) {
element_activation *EA = CREATE(element_activation);
EA->element_name = Str::duplicate(name);
EA->activate = act;
ADD_TO_LINKED_LIST(EA, element_activation, K->activations);
}
int Kits::perform_ittt(inform_kit *K, inform_project *project, int parity) {
int changes_made = FALSE;
inform_kit_ittt *ITTT;

View file

@ -129,7 +129,7 @@ void Projects::add_kit_dependency(inform_project *project, text_stream *kit_name
int Projects::uses_kit(inform_project *project, text_stream *name) {
inform_kit *K;
LOOP_OVER_LINKED_LIST(K, inform_kit, project->kits_to_include)
if (Str::eq(K->name, name))
if (Str::eq(K->as_copy->edition->work->title, name))
return TRUE;
return FALSE;
}
@ -161,7 +161,7 @@ void Projects::finalise_kit_dependencies(inform_project *project) {
project->kits_to_include = sorted;
inform_kit *K;
LOOP_OVER_LINKED_LIST(K, inform_kit, project->kits_to_include)
LOG("Using Inform kit '%S' (priority %d).\n", K->name, K->priority);
LOG("Using Inform kit '%S' (priority %d).\n", K->as_copy->edition->work->title, K->priority);
}
@<Perform if-this-then-that@> =

View file

@ -42,6 +42,16 @@ void SourceFiles::issue_problems_arising(inbuild_copy *C) {
"Specifically, %2.");
Problems::issue_problem_end();
break;
case KIT_MISWORDED_CE:
Problems::quote_work(1, CE->copy->found_by->work);
Problems::quote_stream(2, CE->notes);
Problems::Issue::handmade_problem(_p_(Untestable));
Problems::issue_problem_segment(
"The kit %1, which your source text makes use of, seems to be "
"damaged or incorrect: its identifying opening line is wrong. "
"Specifically, %2.");
Problems::issue_problem_end();
break;
case EXT_TITLE_TOO_LONG_CE: {
int max = MAX_EXTENSION_TITLE_LENGTH;
int overage = CE->details_N - MAX_EXTENSION_TITLE_LENGTH;