1
0
Fork 0
mirror of https://github.com/ganelson/inform.git synced 2024-07-02 23:14:57 +03:00

Groundwork for code elimination

This commit is contained in:
Graham Nelson 2019-06-10 08:30:20 +01:00
parent 877a04db5a
commit a9accccf9e
12 changed files with 2437 additions and 1671 deletions

View file

@ -65,17 +65,9 @@ void Hierarchy::establish(void) {
@e RNG_SEED_AT_START_OF_PLAY_HL
@<Establish basics@> =
location_requirement veneer = HierarchyLocations::this_package(Hierarchy::veneer());
HierarchyLocations::con(SELF_HL, I"self", Translation::same(), veneer);
submodule_identity *basics = Packaging::register_submodule(I"basics");
location_requirement generic_basics = HierarchyLocations::generic_submodule(basics);
HierarchyLocations::con(DEBUG_HL, I"DEBUG", Translation::same(), generic_basics);
HierarchyLocations::con(TARGET_ZCODE_HL, I"TARGET_ZCODE", Translation::same(), generic_basics);
HierarchyLocations::con(TARGET_GLULX_HL, I"TARGET_GLULX", Translation::same(), generic_basics);
HierarchyLocations::con(DICT_WORD_SIZE_HL, I"DICT_WORD_SIZE", Translation::same(), generic_basics);
HierarchyLocations::con(WORDSIZE_HL, I"WORDSIZE", Translation::same(), generic_basics);
HierarchyLocations::con(NULL_HL, I"NULL", Translation::same(), generic_basics);
HierarchyLocations::con(WORD_HIGHBIT_HL, I"WORD_HIGHBIT", Translation::same(), generic_basics);
HierarchyLocations::con(WORD_NEXTTOHIGHBIT_HL, I"WORD_NEXTTOHIGHBIT", Translation::same(), generic_basics);
@ -91,13 +83,21 @@ void Hierarchy::establish(void) {
HierarchyLocations::con(NO_VERB_VERB_DEFINED_HL, I"NO_VERB_VERB_DEFINED", Translation::same(), generic_basics);
HierarchyLocations::con(NO_TEST_SCENARIOS_HL, I"NO_TEST_SCENARIOS", Translation::same(), generic_basics);
HierarchyLocations::con(MEMORY_HEAP_SIZE_HL, I"MEMORY_HEAP_SIZE", Translation::same(), generic_basics);
HierarchyLocations::con(INDIV_PROP_START_HL, I"INDIV_PROP_START", Translation::same(), generic_basics);
location_requirement synoptic_basics = HierarchyLocations::synoptic_submodule(basics);
HierarchyLocations::con(CCOUNT_QUOTATIONS_HL, I"CCOUNT_QUOTATIONS", Translation::same(), synoptic_basics);
HierarchyLocations::con(MAX_FRAME_SIZE_NEEDED_HL, I"MAX_FRAME_SIZE_NEEDED", Translation::same(), synoptic_basics);
HierarchyLocations::con(RNG_SEED_AT_START_OF_PLAY_HL, I"RNG_SEED_AT_START_OF_PLAY", Translation::same(), synoptic_basics);
location_requirement veneer = HierarchyLocations::this_package(Hierarchy::veneer());
HierarchyLocations::con(SELF_HL, I"self", Translation::same(), veneer);
HierarchyLocations::con(DEBUG_HL, I"DEBUG", Translation::same(), veneer);
HierarchyLocations::con(TARGET_ZCODE_HL, I"TARGET_ZCODE", Translation::same(), veneer);
HierarchyLocations::con(TARGET_GLULX_HL, I"TARGET_GLULX", Translation::same(), veneer);
HierarchyLocations::con(DICT_WORD_SIZE_HL, I"DICT_WORD_SIZE", Translation::same(), veneer);
HierarchyLocations::con(WORDSIZE_HL, I"WORDSIZE", Translation::same(), veneer);
HierarchyLocations::con(INDIV_PROP_START_HL, I"INDIV_PROP_START", Translation::same(), veneer);
@h Modules.
@e EXT_TITLE_HMD from 0
@ -1593,6 +1593,12 @@ package_request *Hierarchy::template(void) {
if (template_pr == NULL) {
module_package *T = Packaging::get_module(I"template");
template_pr = T->the_package;
submodule_identity *actions = Packaging::register_submodule(I"actions");
package_request *template_actions = Packaging::template_submodule(actions);
packaging_state save = Packaging::enter(template_actions);
inter_reading_state bubble = Packaging::bubble();
CodeGen::Assimilate::divert(ACTION_ASSIM_BM, bubble);
Packaging::exit(save);
}
return template_pr;
}
@ -1615,7 +1621,6 @@ inter_reading_state *Hierarchy::veneer_booknark(void) {
}
inter_symbol *Hierarchy::veneer_symbol(int ix) {
inter_symbol *symb = Veneer::find_by_index(Packaging::incarnate(Hierarchy::veneer()), Hierarchy::veneer_booknark(), ix, Emit::kind_to_symbol(NULL));
LOG("VS is $3\n", symb);
return symb;
}

View file

@ -333,7 +333,11 @@ typedef struct submodule_identity {
} submodule_identity;
submodule_identity *Packaging::register_submodule(text_stream *name) {
submodule_identity *sid = CREATE(submodule_identity);
submodule_identity *sid;
LOOP_OVER(sid, submodule_identity)
if (Str::eq(sid->submodule_name, name))
return sid;
sid = CREATE(submodule_identity);
sid->submodule_name = Str::duplicate(name);
return sid;
}
@ -359,6 +363,10 @@ package_request *Packaging::synoptic_submodule(submodule_identity *sid) {
return Packaging::new_submodule_inner(Packaging::get_module(I"synoptic"), sid);
}
package_request *Packaging::template_submodule(submodule_identity *sid) {
return Packaging::new_submodule_inner(Packaging::get_module(I"template"), sid);
}
@ Those in turn all make use of this back-end function:
=

View file

@ -80,19 +80,6 @@ Test: parse schema from:
* (expr)
DQUOTED Here!
=========
Test: parse schema from:
@jl y 0 ?~rtrue;
* (assembly)
* (expr)
OPCODE @jl
* (expr)
IDENTIFIER y
* (expr)
NUMBER 0
* (expr)
NEGASM_LABEL rtrue
=========
Test: parse schema from:
"Hello, this
is a multiline string literal";
@ -151,3 +138,623 @@ Test: parse schema from:
* (expr)
IDENTIFIER str
=========
Test: parse schema from:
if (i == 1) print "Okay";
else "*** Arrcpy doesn't support this ***";
* (statement) !ifelse
* (subexpression)
* (operation) !eq
* (expr)
IDENTIFIER i
* (expr)
NUMBER 1
* (code)
* (statement) !print
* (expr)
DQUOTED Okay
* (code)
* (expr) ;
DQUOTED *** Arrcpy doesn't support this ***
=========
Test: parse schema from:
a-1
* (operation) !minus
* (expr)
IDENTIFIER a
* (expr)
NUMBER 1
=========
Test: parse schema from:
do {
print "Hi!";
} until (x);
* (statement) !do
* (subexpression)
* (expr)
IDENTIFIER x
* (code)
* (statement) !print
* (expr)
DQUOTED Hi!
=========
Test: parse schema from:
do {
if (a) return wd;
} until (a);
* (statement) !do
* (subexpression)
* (expr)
IDENTIFIER a
* (code)
* (statement) !if
* (subexpression)
* (expr)
IDENTIFIER a
* (code)
* (statement) !return
* (expr)
IDENTIFIER wd
=========
Test: parse schema from:
do {
if (line_tdata-->index == wd) return wd;
index++;
} until ((line_token-->index == ENDIT_TOKEN) || (((line_token-->index)->0 & $10) == 0));
* (statement) !do
* (subexpression)
* (operation) !or
* (subexpression)
* (operation) !eq
* (operation) !lookup
* (expr)
IDENTIFIER line_token
* (expr)
IDENTIFIER index
* (expr)
IDENTIFIER ENDIT_TOKEN
* (subexpression)
* (operation) !eq
* (subexpression)
* (operation) !bitwiseand
* (operation) !lookupbyte
* (subexpression)
* (operation) !lookup
* (expr)
IDENTIFIER line_token
* (expr)
IDENTIFIER index
* (expr)
NUMBER 0
* (expr)
HEX_NUMBER $10
* (expr)
NUMBER 0
* (code)
* (statement) !if
* (subexpression)
* (operation) !eq
* (operation) !lookup
* (expr)
IDENTIFIER line_tdata
* (expr)
IDENTIFIER index
* (expr)
IDENTIFIER wd
* (code)
* (statement) !return
* (expr)
IDENTIFIER wd
* (operation) !postincrement
* (expr)
IDENTIFIER index
=========
Test: parse schema from:
print "<string ~", (string) o, "~>";
* (statement) !print
* (expr)
DQUOTED <string "
* (statement) !printstring
* (expr)
IDENTIFIER o
* (statement) !print
* (expr)
DQUOTED ">
=========
Test: parse schema from:
switch (Y) {
X: print "A ", (string) o;
}
* (statement) !switch
* (subexpression)
* (expr)
IDENTIFIER Y
* (code)
* (statement) !case
* (expr)
IDENTIFIER X
* (code)
* (statement) !print
* (expr)
DQUOTED A
* (statement) !printstring
* (expr)
IDENTIFIER o
=========
Test: parse schema from:
#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;
".";'
* (directive) #ifdef
* (expr)
IDENTIFIER RANKING_TABLE
* (call)
* (expr)
IDENTIFIER ANNOUNCE_SCORE_RM
* (expr)
SQUOTED B
* (operation) !store
* (expr)
IDENTIFIER j
* (call)
* (expr)
IDENTIFIER TableRows
* (expr)
IDENTIFIER RANKING_TABLE
* (statement) !for
* (eval)
* (operation) !store
* (expr)
IDENTIFIER i
* (expr)
IDENTIFIER j
* (eval)
* (operation) !ge
* (expr)
IDENTIFIER i
* (expr)
NUMBER 1
* (eval)
* (operation) !postdecrement
* (expr)
IDENTIFIER i
* (code)
* (statement) !if
* (subexpression)
* (operation) !ge
* (expr)
IDENTIFIER score
* (call)
* (expr)
IDENTIFIER TableLookUpEntry
* (expr)
IDENTIFIER RANKING_TABLE
* (expr)
NUMBER 1
* (expr)
IDENTIFIER i
* (code)
* (operation) !store
* (expr)
IDENTIFIER v
* (call)
* (expr)
IDENTIFIER TableLookUpEntry
* (expr)
IDENTIFIER RANKING_TABLE
* (expr)
NUMBER 2
* (expr)
IDENTIFIER i
* (call)
* (expr)
IDENTIFIER TEXT_TY_Say
* (expr)
IDENTIFIER v
* (expr) ;
DQUOTED .
* (directive) #endif
* (expr) ;
DQUOTED .
* (expr)
SQUOTED
=========
Test: parse schema from:
if (B) if (A) { print "Yes"; }
print "No";
* (statement) !if
* (subexpression)
* (expr)
IDENTIFIER B
* (code)
* (statement) !if
* (subexpression)
* (expr)
IDENTIFIER A
* (code)
* (statement) !print
* (expr)
DQUOTED Yes
* (statement) !print
* (expr)
DQUOTED No
=========
Test: parse schema from:
switch (scope_stage) {
2: objectloop (obj)
PlaceInScope(obj, true);
}
* (statement) !switch
* (subexpression)
* (expr)
IDENTIFIER scope_stage
* (code) <
* (statement) !case
* (expr)
NUMBER 2
* (code) <
* (statement) !objectloop
* (subexpression)
* (expr)
IDENTIFIER obj
* (code)
* (call)
* (expr)
IDENTIFIER PlaceInScope
* (expr)
IDENTIFIER obj
* (expr)
NUMBER true
=========
Test: parse schema from:
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;
}
* (statement) !while
* (subexpression)
* (operation) !ne
* (expr)
IDENTIFIER token
* (expr)
IDENTIFIER NULL
* (code)
* (statement) !switch
* (subexpression)
* (operation) !lookup
* (expr)
IDENTIFIER token
* (expr)
IDENTIFIER RE_CCLASS
* (code)
* (statement) !case
* (expr)
IDENTIFIER DISJUNCTION_RE_CC
* (code)
* (operation) !store
* (operation) !lookup
* (expr)
IDENTIFIER token
* (expr)
IDENTIFIER RE_CONSTRAINT
* (expr)
NUMBER -1
* (statement) !case
* (expr)
IDENTIFIER QUANTIFIER_RE_CC
* (code)
* (operation) !store
* (operation) !lookup
* (expr)
IDENTIFIER token
* (expr)
IDENTIFIER RE_CONSTRAINT
* (expr)
NUMBER -1
* (statement) !if
* (subexpression)
* (operation) !lookup
* (expr)
IDENTIFIER token
* (expr)
IDENTIFIER RE_DOWN
* (code)
* (call)
* (expr)
IDENTIFIER TEXT_TY_RE_EraseConstraints
* (operation) !lookup
* (expr)
IDENTIFIER token
* (expr)
IDENTIFIER RE_DOWN
* (operation) !store
* (expr)
IDENTIFIER token
* (operation) !lookup
* (expr)
IDENTIFIER token
* (expr)
IDENTIFIER RE_NEXT
=========
Test: parse schema from:
if (b) print 1; else print 2;
* (statement) !ifelse
* (subexpression)
* (expr)
IDENTIFIER b
* (code)
* (statement) !printnumber
* (expr)
NUMBER 1
* (code)
* (statement) !printnumber
* (expr)
NUMBER 2
=========
Test: parse schema from:
a: if (b) print 1; else print 2;
* (statement) !case
* (expr)
IDENTIFIER a
* (code) <
* (statement) !ifelse
* (subexpression)
* (expr)
IDENTIFIER b
* (code)
* (statement) !printnumber
* (expr)
NUMBER 1
* (code)
* (statement) !printnumber
* (expr)
NUMBER 2
=========
Test: parse schema from:
print_ret "This is ", (char) X, ".";
* (statement) !print
* (expr)
DQUOTED This is
* (statement) !printchar
* (expr)
IDENTIFIER X
* (statement) !print
* (expr)
DQUOTED .
* (statement) !print
* (expr)
DQUOTED
* (statement) !return
* (expr)
NUMBER 1
=========
Test: parse schema from:
@jl y 0 ?X;
@jl y 0 ?~X;
@jl y 0 ?rtrue;
@jl y 0 ?rfalse;
@jl y 0 ?~rtrue;
@jl y 0 ?~rfalse;
* (assembly)
* (expr)
OPCODE @jl
* (expr)
IDENTIFIER y
* (expr)
NUMBER 0
* (expr)
ASM_LABEL X
* (assembly)
* (expr)
OPCODE @jl
* (expr)
IDENTIFIER y
* (expr)
NUMBER 0
* (expr)
NEGASM_LABEL X
* (assembly)
* (expr)
OPCODE @jl
* (expr)
IDENTIFIER y
* (expr)
NUMBER 0
* (expr)
ASM_LABEL rtrue
* (assembly)
* (expr)
OPCODE @jl
* (expr)
IDENTIFIER y
* (expr)
NUMBER 0
* (expr)
ASM_LABEL rfalse
* (assembly)
* (expr)
OPCODE @jl
* (expr)
IDENTIFIER y
* (expr)
NUMBER 0
* (expr)
NEGASM_LABEL rtrue
* (assembly)
* (expr)
OPCODE @jl
* (expr)
IDENTIFIER y
* (expr)
NUMBER 0
* (expr)
NEGASM_LABEL rfalse
=========
Test: parse schema from:
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;
}
* (statement) !switch
* (subexpression)
* (operation) !lookup
* (expr)
IDENTIFIER token
* (expr)
IDENTIFIER RE_CCLASS
* (code)
* (statement) !case
* (expr)
IDENTIFIER CHOICE_RE_CC
* (code)
* (statement) !return
* (expr)
DQUOTED internal error
* (statement) !case
* (expr)
IDENTIFIER SENSITIVITY_RE_CC
* (code)
* (statement) !ifelse
* (subexpression)
* (operation) !lookup
* (expr)
IDENTIFIER token
* (expr)
IDENTIFIER RE_PAR1
* (code)
* (operation) !store
* (expr)
IDENTIFIER mode_flags
* (operation) !bitwiseor
* (expr)
IDENTIFIER mode_flags
* (expr)
IDENTIFIER CIS_MFLAG
* (code)
* (operation) !store
* (expr)
IDENTIFIER mode_flags
* (operation) !bitwiseand
* (expr)
IDENTIFIER mode_flags
* (subexpression)
* (operation) !bitwisenot
* (expr)
IDENTIFIER CIS_MFLAG
* (operation) !store
* (expr)
IDENTIFIER outcome
* (expr)
NUMBER true
* (statement) !case
* (expr)
IDENTIFIER ALWAYS_RE_CC
* (code)
* (operation) !store
* (expr)
IDENTIFIER outcome
* (expr)
NUMBER true
* (statement) !case
* (expr)
IDENTIFIER NEVER_RE_CC
* (code)
* (statement) !case
* (expr)
IDENTIFIER START_RE_CC
* (code)
* (statement) !if
* (subexpression)
* (operation) !eq
* (expr)
IDENTIFIER ipos
* (expr)
NUMBER 0
* (code)
* (operation) !store
* (expr)
IDENTIFIER outcome
* (expr)
NUMBER true
* (statement) !case
* (expr)
IDENTIFIER END_RE_CC
* (code)
* (statement) !if
* (subexpression)
* (operation) !eq
* (call)
* (expr)
IDENTIFIER BlkValueRead
* (expr)
IDENTIFIER txt
* (expr)
IDENTIFIER ipos
* (expr)
NUMBER 0
* (code)
* (operation) !store
* (expr)
IDENTIFIER outcome
* (expr)
NUMBER true
* (statement) !case
* (expr)
IDENTIFIER SOMETIMES_RE_CC
* (code)
* (operation) !store
* (expr)
IDENTIFIER outcome
* (expr)
NUMBER true
=========

File diff suppressed because it is too large Load diff

View file

@ -4,10 +4,40 @@ To generate the initial state of storage for variables.
@h Parsing.
@e ACTION_ASSIM_BM from 0
@d NO_ASSIM_BOOKMARKS 1
=
int assimilation_diversions_set = FALSE;
inter_reading_state assim_bookmarks[NO_ASSIM_BOOKMARKS];
inter_reading_state *assim_bookmark_pointers[NO_ASSIM_BOOKMARKS];
void CodeGen::Assimilate::ensure_bms(void) {
if (assimilation_diversions_set == FALSE) {
assimilation_diversions_set = TRUE;
for (int i=0; i<NO_ASSIM_BOOKMARKS; i++) assim_bookmark_pointers[i] = NULL;
}
}
void CodeGen::Assimilate::divert(int cause, inter_reading_state IBS) {
CodeGen::Assimilate::ensure_bms();
assim_bookmarks[cause] = IBS;
assim_bookmark_pointers[cause] = &(assim_bookmarks[cause]);
}
inter_reading_state *CodeGen::Assimilate::diversion(int cause) {
return assim_bookmark_pointers[cause];
}
int assim_verb_count = 0;
inter_reading_state assimilated_actions_b;
inter_reading_state *assimilated_actions;
void CodeGen::Assimilate::assimilate(inter_reading_state *IRS) {
inter_repository *I = IRS->read_into;
assimilated_actions = IRS;
inter_frame P;
LOOP_THROUGH_FRAMES(P, I) {
inter_package *outer = Inter::Packages::container(P);
@ -79,6 +109,7 @@ void CodeGen::Assimilate::assimilate(inter_reading_state *IRS) {
@d MAX_ASSIMILATED_ARRAY_ENTRIES 2048
@<Assimilate definition@> =
text_stream *outer_housing = NULL;
text_stream *identifier = NULL;
text_stream *value = NULL;
match_results mr = Regexp::create_mr();
@ -96,8 +127,10 @@ void CodeGen::Assimilate::assimilate(inter_reading_state *IRS) {
identifier = mr.exp[0]; value = mr.exp[1];
} else LOG("Stuck on this! %S\n", S);
} else {
outer_housing = Str::new();
WRITE_TO(outer_housing, "assim_command%d", assim_verb_count);
identifier = Str::new();
WRITE_TO(identifier, "assim_verb_%d", ++assim_verb_count);
WRITE_TO(identifier, "assim_gv%d", ++assim_verb_count);
if (Regexp::match(&mr, S, L" *%C+ (%c*?) *;%c*")) {
value = mr.exp[0];
} else LOG("Stuck on this! %S\n", S);
@ -106,6 +139,23 @@ void CodeGen::Assimilate::assimilate(inter_reading_state *IRS) {
inter_reading_state ib = Inter::Bookmarks::snapshot(IRS);
ib.in_frame_list = &(I->sequence);
ib.pos = P_entry;
inter_package *housing_package = NULL;
inter_symbols_table *save_into_scope = NULL;
if (outer_housing) {
LOG("Housing in %S\n", outer_housing);
inter_symbol *housing_symbol = Inter::SymbolsTables::create_with_unique_name(into_scope, outer_housing);
inter_symbol *ptype = plain_packagetype;
#ifdef CORE_MODULE
ptype = PackageTypes::get(I"_command");
#endif
CodeGen::Link::guard(Inter::Package::new_package(&ib, housing_symbol,
ptype, baseline, NULL, &housing_package));
Inter::Defn::set_current_package(&ib, housing_package);
outer = housing_package;
save_into_scope = into_scope;
into_scope = Inter::Packages::scope(outer);
}
if ((identifier) && (unchecked_kind_symbol)) {
Str::trim_all_white_space_at_end(identifier);
@ -220,14 +270,7 @@ void CodeGen::Assimilate::assimilate(inter_reading_state *IRS) {
if (next_is_action) WRITE_TO(value, "##");
@<Extract a token@>;
if ((next_is_action) && (action_kind_symbol)) {
if (CodeGen::Link::find_name(I, value, TRUE) == NULL) {
inter_symbol *asymb = CodeGen::Assimilate::maybe_extern(I, value, into_scope);
CodeGen::Link::guard(Inter::Constant::new_numerical(&ib,
Inter::SymbolsTables::id_from_symbol(I, outer, asymb),
Inter::SymbolsTables::id_from_symbol(I, outer, action_kind_symbol),
LITERAL_IVAL, 10000, baseline, NULL));
Inter::Symbols::annotate_i(I, asymb, ACTION_IANN, 1);
}
CodeGen::Assimilate::ensure_action(I, IRS, value);
}
next_is_action = FALSE;
if (P.data[PLM_SPLAT_IFLD] == ARRAY_PLM) {
@ -276,6 +319,11 @@ void CodeGen::Assimilate::assimilate(inter_reading_state *IRS) {
}
Inter::Nop::nop_out(I, P);
}
if (outer_housing) {
LOG("Exit!\n");
Inter::Defn::unset_current_package(&ib, housing_package, 0);
into_scope = save_into_scope;
}
@<Extract a token@> =
int squoted = FALSE, dquoted = FALSE, bracketed = 0;
@ -430,8 +478,58 @@ inter_symbol *CodeGen::Assimilate::maybe_extern(inter_repository *I, text_stream
return rsymb;
}
@ =
int no_assimilated_actions = 0;
void CodeGen::Assimilate::ensure_action(inter_repository *I, inter_reading_state *IRS, text_stream *value) {
LOG("NIA %S\n", value);
if (CodeGen::Link::find_name(I, value, TRUE) == NULL) {
#ifdef CORE_MODULE_XXXXXXX
if (no_assimilated_actions == 0) {
assimilated_actions_b = Packaging::bubble_at(IRS);
assimilated_actions = &assimilated_actions_b;
inter_package *apack = NULL;
inter_package *tpack = Inter::Packages::template(I);
Inter::Defn::set_current_package(&assimilated_actions_b, tpack);
inter_symbol *apack_name = Inter::SymbolsTables::create_with_unique_name(Inter::Packages::scope(tpack), I"actions");
CodeGen::Link::guard(Inter::Package::new_package(&assimilated_actions_b, apack_name,
plain_packagetype, (inter_t) assimilated_actions->latest_indent, NULL, &apack));
Inter::Defn::set_current_package(&assimilated_actions_b, apack);
}
#endif
assimilated_actions = CodeGen::Assimilate::diversion(ACTION_ASSIM_BM);
assimilated_actions->cp_indent = 1;
LOG("AA is $5 indent %d\n", assimilated_actions, assimilated_actions->cp_indent);
inter_symbols_table *scope = Inter::Packages::scope(assimilated_actions->current_package);
LOG("scope is $4\n", scope);
TEMPORARY_TEXT(an);
WRITE_TO(an, "assim_action%d", no_assimilated_actions++);
inter_symbol *housing_symbol = Inter::SymbolsTables::create_with_unique_name(scope, an);
DISCARD_TEXT(an);
inter_package *housing_package = NULL;
inter_symbol *ptype = plain_packagetype;
#ifdef CORE_MODULE
ptype = PackageTypes::get(I"_action");
#endif
CodeGen::Link::guard(Inter::Package::new_package(assimilated_actions, housing_symbol,
ptype, (inter_t) assimilated_actions->cp_indent + 2, NULL, &housing_package));
Inter::Defn::set_current_package(assimilated_actions, housing_package);
inter_symbol *asymb = CodeGen::Assimilate::maybe_extern(I, value, Inter::Packages::scope(housing_package));
LOG("Asymb $3\n", asymb);
CodeGen::Link::guard(Inter::Constant::new_numerical(assimilated_actions,
Inter::SymbolsTables::id_from_symbol(I, assimilated_actions->current_package, asymb),
Inter::SymbolsTables::id_from_symbol(I, assimilated_actions->current_package, action_kind_symbol),
LITERAL_IVAL, 10000, (inter_t) assimilated_actions->cp_indent + 3, NULL));
Inter::Symbols::annotate_i(I, asymb, ACTION_IANN, 1);
Inter::Defn::unset_current_package(assimilated_actions, housing_package, 0);
CodeGen::Link::build_r(housing_package);
}
}
@ =
void CodeGen::Assimilate::value(inter_repository *I, inter_package *pack, inter_reading_state *IRS, text_stream *S, inter_t *val1, inter_t *val2, int Verbal) {
LOG("Assum val %S verbal %d\n", S, Verbal);
int sign = 1, base = 10, from = 0, to = Str::len(S)-1, bad = FALSE;
if ((Str::get_at(S, from) == '\'') && (Str::get_at(S, to) == '\'')) {
from++;
@ -500,6 +598,7 @@ void CodeGen::Assimilate::value(inter_repository *I, inter_package *pack, inter_
if (Str::eq(S, I"false")) {
*val1 = LITERAL_IVAL; *val2 = 0; return;
}
LOG("Still assym\n");
if (Verbal) {
if ((Str::eq(S, I"*")) && (verb_directive_divider_symbol)) {
Inter::Symbols::to_data(I, pack, verb_directive_divider_symbol, val1, val2); return;

View file

@ -5,89 +5,77 @@ To reconcile clashes between assimilated and originally generated verbs.
@h Parsing.
=
void CodeGen::Eliminate::require(inter_package *pack, inter_symbol *witness) {
if ((pack->package_flags) & USED_PACKAGE_FLAG) return;
pack->package_flags |= USED_PACKAGE_FLAG;
if (witness) LOG("Need $6 because of $3\n", pack, witness); else LOG("Need $6\n", pack);
inter_symbols_table *tab = Inter::Packages::scope(pack);
for (int i=0; i<tab->size; i++) {
inter_symbol *symb = tab->symbol_array[i];
if ((symb) && (symb->equated_to)) {
inter_symbol *to = symb->equated_to;
CodeGen::Eliminate::require(to->owning_table->owning_package, to);
}
}
inter_symbol *ptype = Inter::Packages::type(pack);
if ((ptype) && (Str::eq(ptype->symbol_name, I"_function"))) {
for (inter_package *P = pack->child_package; P; P = P->next_package) {
CodeGen::Eliminate::require(P, NULL);
}
}
if ((ptype) && (Str::eq(ptype->symbol_name, I"_action"))) {
for (inter_package *P = pack->child_package; P; P = P->next_package) {
CodeGen::Eliminate::require(P, NULL);
}
}
}
int notes_made = 0, log_elims = FALSE;
int elims_made = FALSE;
void CodeGen::Eliminate::go(inter_repository *I) {
CodeGen::Eliminate::keep(I, I"Main");
CodeGen::Eliminate::keep(I, I"DefArt");
CodeGen::Eliminate::keep(I, I"CDefArt");
CodeGen::Eliminate::keep(I, I"IndefArt");
CodeGen::Eliminate::keep(I, I"I7_String");
CodeGen::Eliminate::keep(I, I"R_Process");
inter_repository *repos[MAX_REPOS_AT_ONCE];
int no_repos = CodeGen::repo_list(I, repos);
for (int j=0; j<no_repos; j++) {
inter_repository *J = repos[j];
inter_frame P;
LOOP_THROUGH_FRAMES(P, J) {
Inter::Defn::callback_dependencies(P, &(CodeGen::Eliminate::note), I);
}
LOOP_THROUGH_FRAMES(P, J) {
if (P.data[ID_IFLD] == CONSTANT_IST) {
inter_symbol *con_name = Inter::SymbolsTables::symbol_from_frame_data(P, DEFN_CONST_IFLD);
if ((con_name) && (Inter::Symbols::get_flag(con_name, USED_MARK_BIT)) &&
(Inter::Symbols::read_annotation(con_name, ACTION_IANN) == 1)) {
TEMPORARY_TEXT(blurg);
WRITE_TO(blurg, "%SSub", con_name->symbol_name);
Str::delete_first_character(blurg);
Str::delete_first_character(blurg);
inter_symbol *IS = Inter::SymbolsTables::symbol_from_name(Inter::Packages::scope_of(P), blurg);
if (IS) Inter::Symbols::set_flag(IS, USED_MARK_BIT);
DISCARD_TEXT(blurg);
elims_made = TRUE;
inter_symbol *Main_block = Inter::SymbolsTables::symbol_from_name_in_template(I, I"Main_B");
inter_package *Main_package = Inter::Package::which(Main_block);
if (Main_package == NULL) {
LOG("Eliminate failed: can't find Main code block\n");
return;
}
CodeGen::Eliminate::require(Main_package, NULL);
inter_frame P;
LOOP_THROUGH_FRAMES(P, I) {
if (P.data[ID_IFLD] == PACKAGE_IST) {
inter_symbol *package_name = Inter::SymbolsTables::symbol_from_frame_data(P, DEFN_PACKAGE_IFLD);
inter_package *which = Inter::Package::which(package_name);
if (which) {
inter_symbol *ptype = Inter::Packages::type(which);
if ((ptype) && (Str::eq(ptype->symbol_name, I"_action"))) {
CodeGen::Eliminate::require(which, NULL);
}
if ((ptype) && (Str::eq(ptype->symbol_name, I"_command"))) {
CodeGen::Eliminate::require(which, NULL);
}
}
}
}
if (log_elims) LOG("notes_made = %d\n", notes_made);
if (log_elims) LOG("The following routines are unnecessary:\n");
for (int j=0; j<no_repos; j++) {
inter_repository *J = repos[j];
inter_frame P;
LOOP_THROUGH_FRAMES(P, J) {
if (P.data[ID_IFLD] == CONSTANT_IST) {
inter_symbol *con_name = Inter::SymbolsTables::symbol_from_frame_data(P, DEFN_CONST_IFLD);
if ((con_name) && (Inter::Constant::is_routine(con_name)) &&
(Inter::Symbols::get_flag(con_name, USED_MARK_BIT) == FALSE)) {
int consecutives = 0, keep_me = FALSE;
LOOP_THROUGH_TEXT(pos, con_name->symbol_name) {
if (Str::get(pos) == '_') consecutives++;
else if (consecutives >= 2) keep_me = TRUE;
else consecutives = 0;
}
if (keep_me == FALSE) {
if (log_elims) LOG("-- %S %08x\n", con_name->symbol_name, con_name);
Inter::Nop::nop_out(J, P);
}
LOOP_THROUGH_FRAMES(P, I) {
if (P.data[ID_IFLD] == PACKAGE_IST) {
inter_symbol *package_name = Inter::SymbolsTables::symbol_from_frame_data(P, DEFN_PACKAGE_IFLD);
inter_package *which = Inter::Package::which(package_name);
if (which) {
if ((which->package_flags & USED_PACKAGE_FLAG) == 0) {
LOG("Not used: $6\n", which);
}
}
}
}
}
if (log_elims) LOG("The following table arrays are unnecessary:\n");
for (int j=0; j<no_repos; j++) {
inter_repository *J = repos[j];
inter_frame P;
LOOP_THROUGH_FRAMES(P, J) {
if (P.data[ID_IFLD] == CONSTANT_IST) {
inter_symbol *con_name = Inter::SymbolsTables::symbol_from_frame_data(P, DEFN_CONST_IFLD);
if ((con_name) && (P.data[FORMAT_CONST_IFLD] == CONSTANT_INDIRECT_LIST) &&
(Inter::Symbols::read_annotation(con_name, VERBARRAY_IANN) == FALSE) &&
(Inter::Symbols::get_flag(con_name, USED_MARK_BIT) == FALSE)) {
int consecutives = 0, keep_me = FALSE;
LOOP_THROUGH_TEXT(pos, con_name->symbol_name) {
if (Str::get(pos) == '_') consecutives++;
else if (consecutives >= 2) keep_me = TRUE;
else consecutives = 0;
}
if (keep_me == FALSE) {
if (log_elims) LOG("-- %S\n", con_name->symbol_name);
Inter::Nop::nop_out(J, P);
}
}
}
}
}
int CodeGen::Eliminate::gone(inter_symbol *code_block) {
inter_package *which = Inter::Package::which(code_block);
if ((elims_made) && (which) && ((which->package_flags & USED_PACKAGE_FLAG) == 0))
return TRUE;
return FALSE;
}
void CodeGen::Eliminate::keep(inter_repository *I, text_stream *N) {

View file

@ -79,10 +79,16 @@ void CodeGen::Link::build_r(inter_package *P) {
inter_symbol *CodeGen::Link::find_name(inter_repository *I, text_stream *S, int deeply) {
for (int i=0; i<link_search_list_len; i++) {
LOG("Look for %S in %d: $4\n", S, i, link_search_list[i]);
inter_symbol *symb = Inter::SymbolsTables::symbol_from_name_not_equating(link_search_list[i], S);
if (symb) return symb;
}
if (deeply) return CodeGen::Link::find_in_namespace(I, S);
if (deeply) {
LOG("Look for %S deeper\n", S);
inter_symbol *symb = CodeGen::Link::find_in_namespace(I, S);
if (symb) return symb;
}
LOG("Failed\n");
return NULL;
}

View file

@ -281,7 +281,15 @@ void CodeGen::constant(OUTPUT_STREAM, inter_repository *I, inter_frame P) {
return;
}
int ifndef_me = FALSE;
if (Inter::Symbols::read_annotation(con_name, VENEER_IANN) == 1) return;
if ((Str::eq(con_name->symbol_name, I"WORDSIZE")) ||
(Str::eq(con_name->symbol_name, I"TARGET_ZCODE")) ||
(Str::eq(con_name->symbol_name, I"INDIV_PROP_START")) ||
(Str::eq(con_name->symbol_name, I"TARGET_GLULX")) ||
(Str::eq(con_name->symbol_name, I"DICT_WORD_SIZE")) ||
(Str::eq(con_name->symbol_name, I"DEBUG")))
ifndef_me = TRUE;
if (Str::eq(con_name->symbol_name, I"thedark")) {
// WRITE("Object thedark \"(darkness object)\";\n");
@ -336,19 +344,11 @@ void CodeGen::constant(OUTPUT_STREAM, inter_repository *I, inter_frame P) {
return;
}
int ifndef_me = FALSE;
if ((Str::eq(con_name->symbol_name, I"WORDSIZE")) ||
(Str::eq(con_name->symbol_name, I"TARGET_ZCODE")) ||
(Str::eq(con_name->symbol_name, I"INDIV_PROP_START")) ||
(Str::eq(con_name->symbol_name, I"TARGET_GLULX")) ||
(Str::eq(con_name->symbol_name, I"DICT_WORD_SIZE")) ||
(Str::eq(con_name->symbol_name, I"DEBUG")))
ifndef_me = TRUE;
if (Inter::Constant::is_routine(con_name)) {
WRITE("[ %S", CodeGen::name(con_name));
inter_symbol *code_block = Inter::Constant::code_block(con_name);
void_level = Inter::Defn::get_level(P) + 2;
if (code_block) {
if (CodeGen::Eliminate::gone(code_block) == FALSE) {
WRITE("[ %S", CodeGen::name(con_name));
void_level = Inter::Defn::get_level(P) + 2;
inter_frame D = Inter::Symbols::defining_frame(code_block);
CodeGen::frame(OUT, I, D);
}

View file

@ -30,6 +30,13 @@ int Inter::Frame::valid(inter_frame *F) {
return TRUE;
}
int Inter::Frame::included(inter_frame *F) {
if (F == NULL) return FALSE;
inter_package *pack = Inter::Packages::container_p(F);
if ((pack) && (((pack->package_flags) & (EXCLUDE_PACKAGE_FLAG)))) return FALSE;
return TRUE;
}
int Inter::Frame::eq(inter_frame *F1, inter_frame *F2) {
if ((F1 == NULL) || (F2 == NULL)) {
if (F1 == F2) return TRUE;
@ -237,6 +244,13 @@ inter_t Inter::Frame::get_package(inter_frame F) {
return 0;
}
inter_t Inter::Frame::get_package_p(inter_frame *F) {
if (F->repo_segment) {
return F->repo_segment->bytecode[F->index + PREFRAME_PACKAGE];
}
return 0;
}
void Inter::Frame::attach_package(inter_frame F, inter_t ID) {
if ((ID) && (F.repo_segment)) {
F.repo_segment->bytecode[F.index + PREFRAME_PACKAGE] = ID;

View file

@ -254,11 +254,13 @@ inter_t Inter::create_frame_list(inter_repository *I) {
@d LOOP_THROUGH_INTER_FRAME_LIST(F, ifl)
for (inter_frame_list_entry *F##_entry = ifl->first_in_ifl; F##_entry; F##_entry = F##_entry->next_in_ifl)
if (Inter::Frame::valid(((F = F##_entry->listed_frame), &F)))
if ((Inter::Frame::valid(((F = F##_entry->listed_frame), &F))) &&
(Inter::Frame::included(((F = F##_entry->listed_frame), &F))))
@d LOOP_THROUGH_INTER_FRAME_LIST_FROM(F, ifl, entry)
for (inter_frame_list_entry *F##_entry = entry; F##_entry; F##_entry = F##_entry->next_in_ifl)
if (Inter::Frame::valid(((F = F##_entry->listed_frame), &F)))
if ((Inter::Frame::valid(((F = F##_entry->listed_frame), &F))) &&
(Inter::Frame::included(((F = F##_entry->listed_frame), &F))))
=
inter_frame_list *Inter::find_frame_list(inter_repository *I, inter_t N) {

View file

@ -15,15 +15,22 @@ typedef struct inter_package {
struct inter_symbols_table *package_scope;
int codelike_package;
inter_t I7_baseline;
int package_flags;
MEMORY_MANAGEMENT
} inter_package;
@
@d EXCLUDE_PACKAGE_FLAG 1
@d USED_PACKAGE_FLAG 2
@ =
inter_package *Inter::Packages::new(inter_package *par, inter_repository *I, inter_t n) {
inter_package *pack = CREATE(inter_package);
pack->stored_in = I;
pack->package_scope = NULL;
pack->package_name = NULL;
pack->package_flags = 0;
pack->parent_package = par;
if (par) {
if (par->child_package == NULL) par->child_package = pack;
@ -73,6 +80,18 @@ inter_package *Inter::Packages::basics(inter_repository *I) {
return NULL;
}
inter_package *Inter::Packages::veneer(inter_repository *I) {
inter_symbol *S = Inter::Packages::search_main_exhaustively(I, I"veneer");
if (S) return Inter::Package::which(S);
return NULL;
}
inter_package *Inter::Packages::template(inter_repository *I) {
inter_symbol *S = Inter::Packages::search_main_exhaustively(I, I"template");
if (S) return Inter::Package::which(S);
return NULL;
}
inter_symbol *Inter::Packages::search_exhaustively(inter_package *P, text_stream *S) {
inter_symbol *found = Inter::SymbolsTables::symbol_from_name(Inter::Packages::scope(P), S);
if (found) return found;
@ -110,6 +129,11 @@ inter_package *Inter::Packages::container(inter_frame P) {
return Inter::Packages::from_PID(P.repo_segment->owning_repo, Inter::Frame::get_package(P));
}
inter_package *Inter::Packages::container_p(inter_frame *P) {
if (P->repo_segment == NULL) return NULL;
return Inter::Packages::from_PID(P->repo_segment->owning_repo, Inter::Frame::get_package_p(P));
}
inter_symbols_table *Inter::Packages::scope(inter_package *pack) {
if (pack == NULL) return NULL;
return pack->package_scope;

View file

@ -124,8 +124,21 @@ inter_symbol *Inter::SymbolsTables::symbol_from_name_in_basics(inter_repository
return Inter::SymbolsTables::symbol_from_name(Inter::Packages::scope(P), S);
}
inter_symbol *Inter::SymbolsTables::symbol_from_name_in_veneer(inter_repository *I, text_stream *S) {
inter_package *P = Inter::Packages::veneer(I);
if (P == NULL) return NULL;
return Inter::SymbolsTables::symbol_from_name(Inter::Packages::scope(P), S);
}
inter_symbol *Inter::SymbolsTables::symbol_from_name_in_template(inter_repository *I, text_stream *S) {
inter_package *P = Inter::Packages::template(I);
if (P == NULL) return NULL;
return Inter::SymbolsTables::symbol_from_name(Inter::Packages::scope(P), S);
}
inter_symbol *Inter::SymbolsTables::symbol_from_name_in_main_or_basics(inter_repository *I, text_stream *S) {
inter_symbol *symbol = Inter::SymbolsTables::symbol_from_name_in_basics(I, S);
if (symbol == NULL) symbol = Inter::SymbolsTables::symbol_from_name_in_veneer(I, S);
if (symbol == NULL) symbol = Inter::SymbolsTables::symbol_from_name_in_main(I, S);
return symbol;
}