Skip to content

Instantly share code, notes, and snippets.

@raymyers
Last active August 9, 2024 15:24
Show Gist options
  • Save raymyers/72d82720d20848d99dd7350b4d29a6a1 to your computer and use it in GitHub Desktop.
Save raymyers/72d82720d20848d99dd7350b4d29a6a1 to your computer and use it in GitHub Desktop.
Roc AST Attempt 1
LetNonRec(
Def {
loc_pattern: @0-5 Identifier(
`Test.birds`,
),
loc_expr: @8-9 Num(
63,
"3",
I128(
[
3,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
],
),
AtLeastIntOrFloat {
sign: NoDemand,
width: I8,
},
),
expr_var: 64,
pattern_vars: {
`Test.birds`: 64,
},
annotation: None,
},
@10-151 LetNonRec(
Def {
loc_pattern: @10-17 Identifier(
`Test.iguanas`,
),
loc_expr: @20-21 Num(
65,
"2",
I128(
[
2,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
],
),
AtLeastIntOrFloat {
sign: NoDemand,
width: I8,
},
),
expr_var: 66,
pattern_vars: {
`Test.iguanas`: 66,
},
annotation: None,
},
@61-151 LetNonRec(
Def {
loc_pattern: @61-76 Identifier(
`Test.addAndStringify`,
),
loc_expr: @79-121 Closure(
ClosureData {
function_type: 95,
closure_type: 96,
return_type: 97,
name: `Test.addAndStringify`,
captured_symbols: [],
recursive: NotRecursive,
arguments: [
(
76,
AnnotatedMark {
annotation_var: 77,
exhaustive: ExhaustiveMark(
78,
),
},
@80-84 Identifier(
`Test.IdentId(4)`,
),
),
(
79,
AnnotatedMark {
annotation_var: 80,
exhaustive: ExhaustiveMark(
81,
),
},
@86-90 Identifier(
`Test.IdentId(5)`,
),
),
],
loc_body: @98-121 Call(
(
92,
@98-107 Var(
`Num.toStr`,
91,
),
93,
94,
),
[
(
90,
@109-120 Call(
(
87,
@114-115 Var(
`Num.add`,
86,
),
88,
89,
),
[
(
83,
@109-113 Var(
`Test.IdentId(4)`,
82,
),
),
(
85,
@116-120 Var(
`Test.IdentId(5)`,
84,
),
),
],
BinOp(
Plus,
),
),
),
],
Space,
),
},
),
expr_var: 98,
pattern_vars: {
`Test.addAndStringify`: 98,
},
annotation: None,
},
@22-151 LetNonRec(
Def {
loc_pattern: @22-27 Identifier(
`Test.total`,
),
loc_expr: @30-59 Call(
(
72,
@30-45 Var(
`Test.addAndStringify`,
71,
),
73,
74,
),
[
(
68,
@46-51 Var(
`Test.birds`,
67,
),
),
(
70,
@52-59 Var(
`Test.iguanas`,
69,
),
),
],
Space,
),
expr_var: 75,
pattern_vars: {
`Test.total`: 75,
},
annotation: None,
},
@122-151 Call(
(
107,
Var(
`Str.concat`,
106,
),
108,
109,
),
[
(
110,
Str(
"There are ",
),
),
(
111,
Call(
(
101,
Var(
`Str.concat`,
100,
),
102,
103,
),
[
(
104,
@135-140 Var(
`Test.total`,
99,
),
),
(
105,
Str(
" animals.",
),
),
],
StringInterpolation,
),
),
],
StringInterpolation,
),
),
),
),
)
(LetNonRec ("Test.birds" (Num 3)) (LetNonRec ("Test.iguanas" (Num 2)) (LetNonRec ("Test.addAndStringify" (Closure ("Test.IdentId(4)" "Test.IdentId(5)") (Call (Var "Num.toStr") (Call (Var "Num.add") (Var "Test.IdentId(4)") (Var "Test.IdentId(5)"))))) (LetNonRec ("Test.total" (Call (Var "Test.addAndStringify") (Var "Test.birds") (Var "Test.iguanas"))) (Call (Var "Str.concat") (Str "There are ") (Call (Var "Str.concat") (Var "Test.total") (Str " animals.")))))))
iguanas = 2
total = addAndStringify birds iguanas
addAndStringify = \num1, num2 ->
Num.toStr (num1 + num2)
"There are $(total) animals."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment