diff --git a/moo/kernel/System.moo b/moo/kernel/System.moo index 23825e3..1dc357d 100644 --- a/moo/kernel/System.moo +++ b/moo/kernel/System.moo @@ -218,17 +218,35 @@ TODO: how to pass all variadic arguments to another variadic methods??? { | ctx | // 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 ==". //ctx := thisContext. ctx := thisContext sender. // skip the current context. skip to the caller context. while (ctx notNil) { + // if (ctx sender isNil) { break }. // to skip the fake top level call context... + if (ctx class == MethodContext) { - System logNl: (" " & ctx method owner name & ">>" & ctx method name & - " (" & ctx method sourceFile & " " & (ctx method ipSourceLine: (ctx pc)) asString & ")"). - // TODO: get location of the current pc and include it... (ctx method sourceLine: ctx pc) asString dump. + System log: " "; + log: ctx method owner name; + 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??? ctx := ctx sender. diff --git a/moo/lib/comp.c b/moo/lib/comp.c index 1911fc3..e751300 100644 --- a/moo/lib/comp.c +++ b/moo/lib/comp.c @@ -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; 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; } else @@ -6981,7 +6981,7 @@ static int add_compiled_method (moo_t* moo) moo_oow_t method_offset; 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 (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); /* 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 */ 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->name.len = 0; 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->tmprs.len = 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->blk_depth = 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) @@ -7356,7 +7356,6 @@ static int __compile_method_definition (moo_t* moo) return -1; } - cc->mth.code_start_loc = *TOKEN_LOC(moo); /* set it to the location of the opening brace */ GET_TOKEN (moo); 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 */ cc->mth.active = 1; reset_method_data (moo, &cc->mth); + cc->mth.start_loc = *TOKEN_LOC(moo); n = __compile_method_definition(moo); @@ -7522,9 +7522,9 @@ static int make_getters_and_setters (moo_t* moo) /* the following two function calls must not fail unless the compiler * is buggy. */ - x = fetch_word_from_string (&cc->var[var_type].str, i, &var_name); + x = fetch_word_from_string(&cc->var[var_type].str, i, &var_name); MOO_ASSERT (moo, x >= 0); - x = get_variable_info (moo, &var_name, &fake_loc, 0, &var_info); + x = get_variable_info(moo, &var_name, &fake_loc, 0, &var_info); MOO_ASSERT (moo, x >= 0); MOO_ASSERT (moo, var_info.type == var_type); @@ -7532,7 +7532,7 @@ static int make_getters_and_setters (moo_t* moo) if (cc->var[var_type].initv[i].flags & VARACC_GETTER) { /* the method data has been reset above. */ - if (make_getter_method (moo, &var_name, &var_info) <= -1) return -1; + if (make_getter_method(moo, &var_name, &var_info) <= -1) return -1; } if (cc->var[var_type].initv[i].flags & VARACC_SETTER) @@ -7549,7 +7549,7 @@ static int make_getters_and_setters (moo_t* moo) cc->mth.tmpr_nargs = 1; MOO_ASSERT (moo, var_info.type == var_type); - if (make_setter_method (moo, &var_name, &var_info) <= -1) return -1; + if (make_setter_method(moo, &var_name, &var_info) <= -1) return -1; } } } diff --git a/moo/lib/moo-prv.h b/moo/lib/moo-prv.h index 634f5d1..2c306ef 100644 --- a/moo/lib/moo-prv.h +++ b/moo/lib/moo-prv.h @@ -505,6 +505,7 @@ struct moo_method_data_t moo_oocs_t name; moo_oow_t name_capa; moo_ioloc_t name_loc; + moo_ioloc_t start_loc; /* location where the method definition begins */ /* is the unary method followed by parameter list? */ int variadic; @@ -533,7 +534,6 @@ struct moo_method_data_t /* byte 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;