changed the compiler to set source_file and source_line into moo_method_t

This commit is contained in:
hyunghwan.chung 2019-07-06 09:44:29 +00:00
parent c334b0af28
commit 81a1785c35
2 changed files with 29 additions and 3 deletions

View File

@ -6778,6 +6778,7 @@ static int add_compiled_method (moo_t* moo)
#else #else
moo_oop_byte_t code; moo_oop_byte_t code;
#endif #endif
moo_oop_t source_file;
moo_oow_t tmp_count = 0; moo_oow_t tmp_count = 0;
moo_oow_t i; moo_oow_t i;
moo_ooi_t preamble_code, preamble_index, preamble_flags; moo_ooi_t preamble_code, preamble_index, preamble_flags;
@ -6810,6 +6811,20 @@ static int add_compiled_method (moo_t* moo)
moo_pushvolat (moo, (moo_oop_t*)&code); tmp_count++; moo_pushvolat (moo, (moo_oop_t*)&code); tmp_count++;
#endif #endif
if (cc->mth.code_start_loc.file)
{
/* TODO: make file names like symbols at least in this compiler. can also make it readonly.
don't want to make it a symbol */
source_file = moo_makestring(moo, cc->mth.code_start_loc.file, moo_count_oocstr(cc->mth.code_start_loc.file));
if (!source_file) goto oops;
moo_pushvolat (moo, (moo_oop_t*)&source_file); tmp_count++;
}
else
{
/* the method has been read in from the main souce stream */
source_file = moo->_nil;
}
preamble_code = MOO_METHOD_PREAMBLE_NONE; preamble_code = MOO_METHOD_PREAMBLE_NONE;
preamble_index = 0; preamble_index = 0;
preamble_flags = 0; preamble_flags = 0;
@ -6971,6 +6986,17 @@ static int add_compiled_method (moo_t* moo)
MOO_STORE_OOP (moo, (moo_oop_t*)&mth->code, (moo_oop_t)code); MOO_STORE_OOP (moo, (moo_oop_t*)&mth->code, (moo_oop_t)code);
#endif #endif
MOO_STORE_OOP (moo, &mth->source_file, source_file);
if (cc->mth.code_start_loc.line <= MOO_SMOOI_MAX)
{
mth->source_line = MOO_SMOOI_TO_OOP(cc->mth.code_start_loc.line);
}
else
{
/* the source line is too large to be held as a SmallInteger.
* Just set it to 0 to indicate that the information is not available */
mth->source_line = MOO_SMOOI_TO_OOP(0);
}
/*TODO: preserve source??? mth->text = cc->mth.text /*TODO: preserve source??? mth->text = cc->mth.text
the compiler must collect all source method string collected so far. the compiler must collect all source method string collected so far.
need to write code to collect string. need to write code to collect string.

View File

@ -585,9 +585,9 @@ struct moo_method_t
moo_oop_byte_t code; /* ByteArray */ moo_oop_byte_t code; /* ByteArray */
#endif #endif
moo_oop_t source; /* TODO: what should I put? */ moo_oop_t source_text; /* source text. String if available. nil if not */
moo_oop_t source_file; /* source file that contains the definition of this method. nil if unavailable */ moo_oop_t source_file; /* source file path that contains the definition of this method. String if available. nil for the main source stream */
moo_oow_t source_line; /* line of the source file where the method definition begins. valid only if source_file is not nil */ moo_oop_t source_line; /* SmallInteger. line of the source file where the method definition begins. valid only if source_file is not nil */
/* == variable indexed part == */ /* == variable indexed part == */
moo_oop_t literal_frame[1]; /* it stores literals */ moo_oop_t literal_frame[1]; /* it stores literals */