Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/codegen/llvm-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3996,6 +3996,8 @@ export class LLVMGenerator extends BaseGenerator implements IGeneratorContext {
this.controlFlowGen.generateThrowStatement(item as Statement, []);
} else if (itemType === "try") {
this.controlFlowGen.generateTryStatement(item as Statement, []);
} else if (itemType === "switch") {
this.controlFlowGen.generateSwitchStatement(item as Statement, []);
} else {
this.generateExpression(item as Expression, []);
}
Expand Down
15 changes: 14 additions & 1 deletion src/parser-ts/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,13 @@ function transformTopLevelStatement(
if (stmt.type === "variable_declaration") {
ast.topLevelStatements.push(stmt);
ast.topLevelItems!.push(stmt);
ast.topLevelItemTypes!.push("variable_declaration");
}
}
} else {
ast.topLevelStatements.push(result);
ast.topLevelItems!.push(result);
ast.topLevelItemTypes!.push(result.type);
}
}
break;
Expand All @@ -275,6 +277,7 @@ function transformTopLevelStatement(
};
ast.topLevelStatements.push(assignment);
ast.topLevelItems!.push(assignment);
ast.topLevelItemTypes!.push("assignment");
} else if (
expr.type === "call" ||
expr.type === "new" ||
Expand All @@ -283,6 +286,7 @@ function transformTopLevelStatement(
) {
ast.topLevelExpressions.push(expr as CallNode | NewNode | MethodCallNode);
ast.topLevelItems!.push(expr as TopLevelItem);
ast.topLevelItemTypes!.push(expr.type);
} else if (expr.type === "unary") {
throw new Error(
"Increment/decrement (++/--) at global scope is not supported. Use x = x + 1 instead, or wrap in a function.",
Expand All @@ -293,6 +297,7 @@ function transformTopLevelStatement(
if (assignment) {
ast.topLevelStatements.push(assignment);
ast.topLevelItems!.push(assignment);
ast.topLevelItemTypes!.push("assignment");
}
}
break;
Expand All @@ -302,49 +307,57 @@ function transformTopLevelStatement(
const forStmt = transformStatement(node, checker) as ForStatement;
ast.topLevelExpressions.push(forStmt);
ast.topLevelItems!.push(forStmt);
ast.topLevelItemTypes!.push("for");
break;
}

case ts.SyntaxKind.ForOfStatement: {
const forOfStmt = transformStatement(node, checker) as ForOfStatement;
ast.topLevelExpressions.push(forOfStmt);
ast.topLevelItems!.push(forOfStmt);
ast.topLevelItemTypes!.push("for_of");
break;
}

case ts.SyntaxKind.WhileStatement: {
const whileStmt = transformStatement(node, checker) as WhileStatement;
ast.topLevelExpressions.push(whileStmt);
ast.topLevelItems!.push(whileStmt);
ast.topLevelItemTypes!.push("while");
break;
}

case ts.SyntaxKind.DoStatement: {
const doWhileStmt = transformStatement(node, checker) as DoWhileStatement;
ast.topLevelExpressions.push(doWhileStmt);
ast.topLevelItems!.push(doWhileStmt);
ast.topLevelItemTypes!.push("do_while");
break;
}

case ts.SyntaxKind.IfStatement: {
const ifStmt = transformStatement(node, checker) as IfStatement;
ast.topLevelExpressions.push(ifStmt);
ast.topLevelItems!.push(ifStmt);
ast.topLevelItemTypes!.push("if");
break;
}

case ts.SyntaxKind.TryStatement: {
const tryStmt = transformStatement(node, checker) as TryStatement;
ast.topLevelExpressions.push(tryStmt);
ast.topLevelItems!.push(tryStmt);
ast.topLevelItemTypes!.push("try");
break;
}

case ts.SyntaxKind.SwitchStatement:
case ts.SyntaxKind.SwitchStatement: {
const switchAsIf = transformStatement(node, checker) as IfStatement;
ast.topLevelExpressions.push(switchAsIf);
ast.topLevelItems!.push(switchAsIf);
ast.topLevelItemTypes!.push(switchAsIf.type);
break;
}

default:
break;
Expand Down
Loading