-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(docs): add debugging documentation
- Loading branch information
1 parent
c2a3414
commit fcc71fe
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
### Debugging | ||
|
||
|
||
|
||
#### Call Stack | ||
|
||
We can use the function `Stack` to output the call stack information of the current coroutine. | ||
|
||
``` | ||
Stack(); | ||
``` | ||
|
||
Currently, tracing of function names set by the function `Watch` is **not** supported. | ||
|
||
##### Example | ||
|
||
``` | ||
@foo() { | ||
Stack(); | ||
} | ||
foo(); | ||
``` | ||
|
||
The output is: | ||
|
||
``` | ||
1: foo a.m:2 | ||
2: __main__ a.m:5 | ||
``` | ||
|
||
The name of the function is not accurate because in Melang, everything is a variable, and the definition of a function is only the value of a variable. Therefore, the function name output here is actually the variable name. However, the subsequent file and line numbers are accurate. | ||
|
||
|
||
|
||
#### Dump | ||
|
||
We can use the function `Dump` to output the information of the given variable. | ||
|
||
``` | ||
Dump(var); | ||
``` | ||
|
||
|
||
|
||
##### Example | ||
|
||
``` | ||
Human { | ||
run; | ||
} | ||
@run() { | ||
return 'running...'; | ||
} | ||
Tom = $Human; | ||
Tom.run = run; | ||
Dump(Tom.run); | ||
``` | ||
|
||
The output is: | ||
|
||
``` | ||
var <Var> Refer Alias name: var valueRef: 2, udata <0x0>, func <0x0>, not_modify: false | ||
<FUNCTION> a.m:6 NARGS:0 | ||
``` | ||
|
||
`Dump` can output the name and line number of the file where the first statement of the currently invoked function is located. This is very helpful for us to trace function calls within certain complex structures. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters