Macro expander integrated in binder

This commit is contained in:
Michael Schimmel
2025-10-04 22:41:01 +02:00
parent 7c48e9e203
commit 54bf350c70
12 changed files with 480 additions and 73 deletions
+118
View File
@@ -81,5 +81,123 @@
"Name": "c"
}
}
},
"repeat": {
"NodeType": "MacroDef",
"Name": {
"NodeType": "Identifier",
"Name": "repeat"
},
"Parameters": [
{
"NodeType": "Identifier",
"Name": "n"
},
{
"NodeType": "Identifier",
"Name": "body"
}
],
"Body": {
"NodeType": "Quasiquote",
"Expression": {
"NodeType": "Block",
"Expressions": [
{
"NodeType": "VarDecl",
"Identifier": {
"NodeType": "Identifier",
"Name": "loop"
},
"Initializer": {
"NodeType": "LambdaExpr",
"Parameters": [
{
"NodeType": "Identifier",
"Name": "counter"
}
],
"Body": {
"NodeType": "IfExpr",
"Condition": {
"NodeType": "BinaryExpr",
"Operator": ">",
"Left": {
"NodeType": "Identifier",
"Name": "counter"
},
"Right": {
"NodeType": "Constant",
"Value": {
"Kind": "Scalar",
"Value": {
"Kind": "Ordinal",
"Value": 0
}
}
}
},
"ThenBranch": {
"NodeType": "Block",
"Expressions": [
{
"NodeType": "Unquote",
"Expression": {
"NodeType": "Identifier",
"Name": "body"
}
},
{
"NodeType": "Recur",
"Arguments": [
{
"NodeType": "BinaryExpr",
"Operator": "-",
"Left": {
"NodeType": "Identifier",
"Name": "counter"
},
"Right": {
"NodeType": "Constant",
"Value": {
"Kind": "Scalar",
"Value": {
"Kind": "Ordinal",
"Value": 1
}
}
}
}
]
}
]
},
"ElseBranch": {
"NodeType": "Block",
"Expressions": [
]
}
}
}
},
{
"NodeType": "FunctionCall",
"Callee": {
"NodeType": "Identifier",
"Name": "loop"
},
"Arguments": [
{
"NodeType": "Unquote",
"Expression": {
"NodeType": "Identifier",
"Name": "n"
}
}
]
}
]
}
}
}
}