removed code_start_loc from moo_method_data_t and added start_loc

This commit is contained in:
hyunghwan.chung 2019-07-12 08:05:44 +00:00
parent 3e506cbcfb
commit 1533c42dbf
3 changed files with 32 additions and 14 deletions

View File

@ -218,17 +218,35 @@ TODO: how to pass all variadic arguments to another variadic methods???
{ {
| ctx | | ctx |
// TOOD: IMPROVE THIS EXPERIMENTAL BACKTRACE... MOVE THIS TO System>>backtrace and skip the first method context for backtrace itself. // TOOD: IMPROVE THIS EXPERIMENTAL BACKTRACE... MOVE THIS TO System>>backtrace and skip the first method context for backtrace itself.
// TODO: make this method atomic? no other process should get scheduled while this function is running?
// possible imementation methods:
// 1. disable task switching? ->
// 2. use a global lock.
// 3. make this a primitive function. -> natually no callback.
// 4. introduce a new method attribute. e.g. #atomic -> vm disables task switching or uses a lock to achieve atomicity.
// >>>> i think it should not be atomic as a while. only logging output should be produeced at one go.
System logNl: "== BACKTRACE ==". System logNl: "== BACKTRACE ==".
//ctx := thisContext. //ctx := thisContext.
ctx := thisContext sender. // skip the current context. skip to the caller context. ctx := thisContext sender. // skip the current context. skip to the caller context.
while (ctx notNil) while (ctx notNil)
{ {
// if (ctx sender isNil) { break }. // to skip the fake top level call context...
if (ctx class == MethodContext) if (ctx class == MethodContext)
{ {
System logNl: (" " & ctx method owner name & ">>" & ctx method name & System log: " ";
" (" & ctx method sourceFile & " " & (ctx method ipSourceLine: (ctx pc)) asString & ")"). log: ctx method owner name;
// TODO: get location of the current pc and include it... (ctx method sourceLine: ctx pc) asString dump. log: ">>";
log: ctx method name;
log: " (";
log: ctx method sourceFile;
log: " ";
log: (ctx method ipSourceLine: (ctx pc)) asString;
logNl: ")".
//System logNl: (" " & ctx method owner name & ">>" & ctx method name &
// " (" & ctx method sourceFile & " " & (ctx method ipSourceLine: (ctx pc)) asString & ")").
}. }.
// TODO: include blockcontext??? // TODO: include blockcontext???
ctx := ctx sender. ctx := ctx sender.

View File

@ -2518,9 +2518,9 @@ static MOO_INLINE int emit_byte_instruction (moo_t* moo, moo_oob_t code, const m
cc->mth.code.ptr[cc->mth.code.len] = code; cc->mth.code.ptr[cc->mth.code.len] = code;
if (srcloc) if (srcloc)
{ {
if (srcloc->file == cc->mth.code_start_loc.file && srcloc->line >= cc->mth.code_start_loc.line) if (srcloc->file == cc->mth.start_loc.file && srcloc->line >= cc->mth.start_loc.line)
{ {
/*cc->mth.code.locptr[cc->mth.code.len] = srcloc->line - cc->mth.code_start_loc.line;*/ /*cc->mth.code.locptr[cc->mth.code.len] = srcloc->line - cc->mth.start_loc.line; // relative within the method? */
cc->mth.code.locptr[cc->mth.code.len] = srcloc->line; cc->mth.code.locptr[cc->mth.code.len] = srcloc->line;
} }
else else
@ -6981,7 +6981,7 @@ static int add_compiled_method (moo_t* moo)
moo_oow_t method_offset; moo_oow_t method_offset;
const moo_ooch_t* file_name; const moo_ooch_t* file_name;
file_name = cc->mth.code_start_loc.file; file_name = cc->mth.start_loc.file;
if (!file_name) file_name = &_nul; if (!file_name) file_name = &_nul;
if (moo_addfiletodbgi(moo, file_name, &file_offset) <= -1) if (moo_addfiletodbgi(moo, file_name, &file_offset) <= -1)
@ -6997,7 +6997,7 @@ static int add_compiled_method (moo_t* moo)
mth->dbgi_file_offset = MOO_SMOOI_TO_OOP(file_offset); mth->dbgi_file_offset = MOO_SMOOI_TO_OOP(file_offset);
/* TODO: preserve source text... */ /* TODO: preserve source text... */
if (moo_addmethodtodbgi(moo, file_offset, cc->dbgi_class_offset, cc->mth.name.ptr, cc->mth.code_start_loc.line, cc->mth.code.locptr, cc->mth.code.len, MOO_NULL, 0, &method_offset) <= -1) if (moo_addmethodtodbgi(moo, file_offset, cc->dbgi_class_offset, cc->mth.name.ptr, cc->mth.start_loc.line, cc->mth.code.locptr, cc->mth.code.len, MOO_NULL, 0, &method_offset) <= -1)
{ {
/* TODO: warning. no debug information about this method will be available */ /* TODO: warning. no debug information about this method will be available */
method_offset = 0; method_offset = 0;
@ -7072,6 +7072,7 @@ static void reset_method_data (moo_t* moo, moo_method_data_t* mth)
mth->kwsels.len = 0; mth->kwsels.len = 0;
mth->name.len = 0; mth->name.len = 0;
MOO_MEMSET (&mth->name_loc, 0, MOO_SIZEOF(mth->name_loc)); MOO_MEMSET (&mth->name_loc, 0, MOO_SIZEOF(mth->name_loc));
MOO_MEMSET (&mth->start_loc, 0, MOO_SIZEOF(mth->start_loc));
mth->variadic = 0; mth->variadic = 0;
mth->tmprs.len = 0; mth->tmprs.len = 0;
mth->tmpr_count = 0; mth->tmpr_count = 0;
@ -7081,7 +7082,6 @@ static void reset_method_data (moo_t* moo, moo_method_data_t* mth)
mth->pfnum = 0; mth->pfnum = 0;
mth->blk_depth = 0; mth->blk_depth = 0;
mth->code.len = 0; mth->code.len = 0;
MOO_MEMSET (&mth->code_start_loc, 0, MOO_SIZEOF(mth->code_start_loc));
} }
static int process_method_modifiers (moo_t* moo, moo_method_data_t* mth) static int process_method_modifiers (moo_t* moo, moo_method_data_t* mth)
@ -7356,7 +7356,6 @@ static int __compile_method_definition (moo_t* moo)
return -1; return -1;
} }
cc->mth.code_start_loc = *TOKEN_LOC(moo); /* set it to the location of the opening brace */
GET_TOKEN (moo); GET_TOKEN (moo);
if (compile_method_temporaries(moo) <= -1 || if (compile_method_temporaries(moo) <= -1 ||
@ -7390,6 +7389,7 @@ static int compile_method_definition (moo_t* moo)
/* clear data required to compile a method */ /* clear data required to compile a method */
cc->mth.active = 1; cc->mth.active = 1;
reset_method_data (moo, &cc->mth); reset_method_data (moo, &cc->mth);
cc->mth.start_loc = *TOKEN_LOC(moo);
n = __compile_method_definition(moo); n = __compile_method_definition(moo);

View File

@ -505,6 +505,7 @@ struct moo_method_data_t
moo_oocs_t name; moo_oocs_t name;
moo_oow_t name_capa; moo_oow_t name_capa;
moo_ioloc_t name_loc; moo_ioloc_t name_loc;
moo_ioloc_t start_loc; /* location where the method definition begins */
/* is the unary method followed by parameter list? */ /* is the unary method followed by parameter list? */
int variadic; int variadic;
@ -533,7 +534,6 @@ struct moo_method_data_t
/* byte code */ /* byte code */
moo_code_t code; moo_code_t code;
moo_ioloc_t code_start_loc; /* source location of the method body opening brace */
}; };
typedef struct moo_cunit_class_t moo_cunit_class_t; typedef struct moo_cunit_class_t moo_cunit_class_t;