FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
daScript/examples/uncategorized/describe_function.das at master · WhyNot135/daScript · GitHub
WhyNot135
/
daScript
Public
forked from
GaijinEntertainment/daScript
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
daScript
/
examples
/
uncategorized
/
describe_function.das
Copy path
More file actions
More file actions
Latest commit
History
History
History
54 lines (50 loc) · 1.56 KB
Breadcrumbs
daScript
/
examples
/
uncategorized
/
describe_function.das
Copy path
File metadata and controls
54 lines (50 loc) · 1.56 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
options
gen2
// describe_function demo — pretty-prints a compiled function back to source.
//
// `describe_function` (daslib/ast) renders an AST Function node as daslang
// source. It always emits gen2 syntax: braces on every block, parens on
// control flow. We compile a small program at runtime, grab its module, and
// print each user function. Run standalone to see the round-tripped source:
//
// daslang.exe describe_function.das
//
// The same pattern works for `describe(expr)` on any Expression and
// `describe(prog)` on a whole Program.
require
daslib
/
ast
require
daslib
/
rtti
// The embedded source is gen2; its literal { } braces are escaped as \{ \} so
// they are not read as "{interpolation}" inside this string literal.
let
SAMPLE_SRC
=
"
options gen2
def demo(x : int; var arr : array<int>) : int
\{
var total = 0
for (i in range(x))
\{
if (i % 2 == 0)
\{
total += i
\}
else
\{
total -= i
\}
\}
while (total > 100)
\{
total -= 10
\}
return total
\}
"
[
export
]
def
main
() {
compile
(
"demo_module"
,
SAMPLE_SRC
,
CodeOfPolicies
())
$
(ok;
prog
;
errors
) {
if
(
!
ok
) {
print
(
"compile failed:
\n
{
errors
}
\n
"
)
return
}
let
thisMod
=
get_this_module
(
prog
)
for_each_function
(
thisMod
,
""
)
$
(var func) {
if
(
func
.
flags
.
builtIn
||
func
.
flags
.
generated
||
func
.
flags
.
_lambda
) {
return
}
print
(
"// describe_function(
{
func
.
name
}
) ->
\n
"
)
print
(
"
{
describe_function
(
func
)
}
\n
"
)
}
}
}
Back
|
FazBrowse Home
|
New Git URL