Skip to content

Commit

Permalink
chore(docs): add debugging documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Water-Melon committed Dec 13, 2023
1 parent c2a3414 commit fcc71fe
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
69 changes: 69 additions & 0 deletions docs/debug.md
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.
2 changes: 2 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ Now, let's start our journey.

[Pipe](https://water-melon.github.io/Melang/pipe.html)

[Debugging](https://water-melon.github.io/Melang/debug.html)

[Library](https://water-melon.github.io/Melang/library.html)


Expand Down

0 comments on commit fcc71fe

Please sign in to comment.