Skip to content

Commit

Permalink
pmacs in progress at 2020/10/16. debug information fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchan0321 committed Oct 14, 2020
1 parent ecbd2b8 commit 8fdb16c
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 48 deletions.
16 changes: 14 additions & 2 deletions eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ toy_eval(Toy_Interp* interp, Toy_Type *statement, Toy_Env** env) {
trace_info = GC_MALLOC(sizeof(Toy_Func_Trace_Info));
ALLOC_SAFE(trace_info);
trace_info->line = statement->u.statement.trace_info->line;
if (interp->cur_func_stack >= 0) {
trace_info->func_name_caller = interp->func_stack[interp->cur_func_stack]->trace_info->func_name;
} else {
trace_info->func_name_caller = new_symbol(L"(unknown)");
}
trace_info->func_name = list_get_item(l);
trace_info->object_name = const_Nil;
trace_info->statement = statement;
Expand Down Expand Up @@ -282,7 +287,7 @@ toy_eval(Toy_Interp* interp, Toy_Type *statement, Toy_Env** env) {
}

if (trace_info->func_name) {
list_append(cmd, trace_info->func_name);
list_append(cmd, trace_info->func_name_caller);
} else {
list_append(cmd, const_Nil);
}
Expand All @@ -297,7 +302,14 @@ toy_eval(Toy_Interp* interp, Toy_Type *statement, Toy_Env** env) {
list_append(cmd, new_integer_si(interp->cur_func_stack));
list_append(cmd, interp->func_stack[interp->cur_func_stack]->trace_info->func_name);

toy_eval_script(interp, new_script(new_list(new_statement(cmd, trace_info->line))));
/* for save trace_info for command functions */
{
Toy_Func_Trace_Info *orig_trace_info;
orig_trace_info = interp->trace_info;
interp->trace_info = trace_info;
toy_eval_script(interp, new_script(new_list(new_statement(cmd, trace_info->line))));
interp->trace_info = orig_trace_info;
}

interp->debug_in = 0;
}
Expand Down
3 changes: 2 additions & 1 deletion interp.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ interp_setup(Toy_Interp* interp, int argc, char **argv, char **envp) {
ALLOC_SAFE(trace_info);
trace_info->line = 0;
trace_info->object_name = obj;
trace_info->func_name = new_symbol(L"Main");
trace_info->func_name = new_symbol(L"main");
trace_info->func_name_caller = new_symbol(L"toplevel");
trace_info->statement = new_statement(new_list(new_symbol(L"(perfumesh)")), 0);
interp->trace_info = trace_info;

Expand Down
9 changes: 4 additions & 5 deletions tests/024.res
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
may be ok.
<MyErr># err
024.prfm:5: throw $x "err"; in self::a
024.prfm:9: a $x; in self::a
024.prfm:14: b $x; in self::b
024.prfm:19: c $x; in self::c
024.prfm:24: d MyErr; in self::d
-:0: (perfumesh); in (object)Main::Main
024.prfm:9: a $x; in self::b
024.prfm:14: b $x; in self::c
024.prfm:19: c $x; in self::d
-:24: d MyErr; in (object)Main::main

22 changes: 10 additions & 12 deletions tests/025.res
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
025.prfm:9: stack-trace; in self::g
025.prfm:8: g; in self::g
025.prfm:7: f; in self::f
025.prfm:6: e; in self::e
025.prfm:5: d; in self::d
025.prfm:4: c; in self::c
025.prfm:3: b; in self::b
025.prfm:11: a; in self::a
-:0: (perfumesh); in (object)Main::Main
025.prfm:8: g; in self::f
025.prfm:7: f; in self::e
025.prfm:6: e; in self::d
025.prfm:5: d; in self::c
025.prfm:4: c; in self::b
025.prfm:3: b; in self::a
-:11: a; in (object)Main::main

025.prfm:21: stack-trace; in (object)C::m
025.prfm:23: $x m; in (object)C::m
025.prfm:25: $x m; in (object)B::m
025.prfm:28: $x m; in (object)A::m
-:0: (perfumesh); in (object)Main::Main
025.prfm:23: $x m; in (object)B::m
025.prfm:25: $x m; in (object)A::m
-:28: $x m; in (object)Main::main

47 changes: 19 additions & 28 deletions tests/027.res
Original file line number Diff line number Diff line change
@@ -1,46 +1,37 @@
./027_d.t:17: stack-trace; in self::baz
./027_d.t:4: baz; in self::baz
./027_d.t:10: bar (x); in self::bar
./027_d.t:5: foo 10; in self::foo
-:0: (perfumesh); in (object)Main::Main
./027_d.t:4: baz; in self::bar
./027_d.t:10: bar (x); in self::foo
-:5: foo 10; in (object)Main::main

./027_d.t:5: stack-trace; in self::bar
./027_d.t:10: bar (x); in self::bar
./027_d.t:5: foo 10; in self::foo
-:0: (perfumesh); in (object)Main::Main
./027_d.t:10: bar (x); in self::foo
-:5: foo 10; in (object)Main::main

./027_d.t:17: stack-trace; in self::baz
./027_d.t:6: baz; in self::baz
./027_d.t:10: bar (x); in self::bar
./027_d.t:5: foo 10; in self::foo
-:0: (perfumesh); in (object)Main::Main
./027_d.t:6: baz; in self::bar
./027_d.t:10: bar (x); in self::foo
-:5: foo 10; in (object)Main::main

./027_d.t:11: stack-trace; in self::foo
./027_d.t:5: foo 10; in self::foo
-:0: (perfumesh); in (object)Main::Main
-:5: foo 10; in (object)Main::main

./027_d.t:17: stack-trace; in self::baz
./027_d.t:4: baz; in self::baz
./027_d.t:12: bar (x); in self::bar
./027_d.t:5: foo 10; in self::foo
-:0: (perfumesh); in (object)Main::Main
./027_d.t:4: baz; in self::bar
./027_d.t:12: bar (x); in self::foo
-:5: foo 10; in (object)Main::main

./027_d.t:5: stack-trace; in self::bar
./027_d.t:12: bar (x); in self::bar
./027_d.t:5: foo 10; in self::foo
-:0: (perfumesh); in (object)Main::Main
./027_d.t:12: bar (x); in self::foo
-:5: foo 10; in (object)Main::main

./027_d.t:17: stack-trace; in self::baz
./027_d.t:6: baz; in self::baz
./027_d.t:12: bar (x); in self::bar
./027_d.t:5: foo 10; in self::foo
-:0: (perfumesh); in (object)Main::Main
./027_d.t:6: baz; in self::bar
./027_d.t:12: bar (x); in self::foo
-:5: foo 10; in (object)Main::main

./027_d.t:13: stack-trace; in self::foo
./027_d.t:5: foo 10; in self::foo
-:0: (perfumesh); in (object)Main::Main
-:5: foo 10; in (object)Main::main

./027_d.t:22: stack-trace; in self::bazz
./027_d.t:6: bazz; in self::bazz
-:0: (perfumesh); in (object)Main::Main
-:6: bazz; in (object)Main::main

1 change: 1 addition & 0 deletions types.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
typedef struct _toy_func_trace_info {
int line;
struct _toy_type *object_name;
struct _toy_type *func_name_caller;
struct _toy_type *func_name;
struct _toy_type *statement;
} Toy_Func_Trace_Info;
Expand Down

0 comments on commit 8fdb16c

Please sign in to comment.