ampliphi 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ampliphi-0.1.0/PKG-INFO +19 -0
- ampliphi-0.1.0/README.md +6 -0
- ampliphi-0.1.0/pyproject.toml +29 -0
- ampliphi-0.1.0/src/ampliphi/__init__.py +2 -0
- ampliphi-0.1.0/src/ampliphi/ast_nodes.py +101 -0
- ampliphi-0.1.0/src/ampliphi/codegen.py +596 -0
- ampliphi-0.1.0/src/ampliphi/exceptions.py +27 -0
- ampliphi-0.1.0/src/ampliphi/ir.py +129 -0
- ampliphi-0.1.0/src/ampliphi/lexer.py +123 -0
- ampliphi-0.1.0/src/ampliphi/main.py +135 -0
- ampliphi-0.1.0/src/ampliphi/opt/__init__.py +11 -0
- ampliphi-0.1.0/src/ampliphi/opt/constant_folding.py +199 -0
- ampliphi-0.1.0/src/ampliphi/opt/dead_code_elimination.py +33 -0
- ampliphi-0.1.0/src/ampliphi/opt/ir_pass.py +7 -0
- ampliphi-0.1.0/src/ampliphi/opt/temp_reduction.py +51 -0
- ampliphi-0.1.0/src/ampliphi/opt/utils.py +171 -0
- ampliphi-0.1.0/src/ampliphi/parser.py +248 -0
- ampliphi-0.1.0/src/ampliphi/ply/__init__.py +0 -0
- ampliphi-0.1.0/src/ampliphi/ply/lex.py +901 -0
- ampliphi-0.1.0/src/ampliphi/ply/yacc.py +2482 -0
- ampliphi-0.1.0/src/ampliphi/utils.py +242 -0
- ampliphi-0.1.0/src/ampliphi/visitors/ast_printer.py +98 -0
- ampliphi-0.1.0/src/ampliphi/visitors/ir_lowering.py +196 -0
- ampliphi-0.1.0/src/ampliphi/visitors/node_visitor.py +72 -0
- ampliphi-0.1.0/src/ampliphi/visitors/type_check.py +282 -0
- ampliphi-0.1.0/src/ampliphi/visitors/xml_printer.py +163 -0
ampliphi-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: ampliphi
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A compiler for Ampliphi with target Varphi.
|
|
5
|
+
Author: Hassan El-Sheikha, Kevin Thevara, Youssef Abouzied
|
|
6
|
+
Author-email: Hassan El-Sheikha <hassan.elsheikha@utoronto.ca>, Kevin Thevara <kevin.thevara@mail.utoronto.ca>, Youssef Abouzied <youssef.abouzied@mail.utoronto.ca>
|
|
7
|
+
Requires-Dist: questionary>=2.1.1
|
|
8
|
+
Requires-Dist: rich>=14.3.2
|
|
9
|
+
Requires-Dist: typer>=0.21.1
|
|
10
|
+
Requires-Dist: varphi-python>=2.0.6
|
|
11
|
+
Requires-Python: >=3.13
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# Ampliphi
|
|
15
|
+
|
|
16
|
+
Ampliphi is a high-level programming language that compiles down to Varphi.
|
|
17
|
+
|
|
18
|
+
For more information, documentation, and details about the language, please visit our website:
|
|
19
|
+
[varphi-lang.com/ampliphi](https://varphi-lang.com/ampliphi)
|
ampliphi-0.1.0/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "ampliphi"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "A compiler for Ampliphi with target Varphi."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{ name = "Hassan El-Sheikha", email = "hassan.elsheikha@utoronto.ca" },
|
|
8
|
+
{ name = "Kevin Thevara", email = "kevin.thevara@mail.utoronto.ca" },
|
|
9
|
+
{ name = "Youssef Abouzied", email = "youssef.abouzied@mail.utoronto.ca" }
|
|
10
|
+
]
|
|
11
|
+
requires-python = ">=3.13"
|
|
12
|
+
dependencies = [
|
|
13
|
+
"questionary>=2.1.1",
|
|
14
|
+
"rich>=14.3.2",
|
|
15
|
+
"typer>=0.21.1",
|
|
16
|
+
"varphi-python>=2.0.6",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[project.scripts]
|
|
20
|
+
ampliphi = "ampliphi.main:main"
|
|
21
|
+
|
|
22
|
+
[build-system]
|
|
23
|
+
requires = ["uv_build>=0.9.18,<0.10.0"]
|
|
24
|
+
build-backend = "uv_build"
|
|
25
|
+
|
|
26
|
+
[dependency-groups]
|
|
27
|
+
dev = [
|
|
28
|
+
"pytest>=9.0.2",
|
|
29
|
+
]
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
from abc import ABC
|
|
2
|
+
from enum import Enum
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import Sequence
|
|
5
|
+
|
|
6
|
+
class BinaryOperationType(str, Enum):
|
|
7
|
+
ADD = "+"
|
|
8
|
+
SUB = "-"
|
|
9
|
+
GT = ">"
|
|
10
|
+
LT = "<"
|
|
11
|
+
EQ = "=="
|
|
12
|
+
AND = "&&"
|
|
13
|
+
OR = "||"
|
|
14
|
+
|
|
15
|
+
class UnaryOperationType(str, Enum):
|
|
16
|
+
NOT = "!"
|
|
17
|
+
|
|
18
|
+
class VariableType(str, Enum):
|
|
19
|
+
INT = "int"
|
|
20
|
+
BOOL = "bool"
|
|
21
|
+
|
|
22
|
+
@dataclass(frozen=True, slots=True)
|
|
23
|
+
class ASTNode(ABC):
|
|
24
|
+
"""Base class for all AST nodes."""
|
|
25
|
+
lineno: int
|
|
26
|
+
colno: int
|
|
27
|
+
|
|
28
|
+
class ExpressionASTNode(ASTNode):
|
|
29
|
+
pass
|
|
30
|
+
|
|
31
|
+
class StatementASTNode(ASTNode):
|
|
32
|
+
pass
|
|
33
|
+
|
|
34
|
+
@dataclass(frozen=True, slots=True)
|
|
35
|
+
class IdentifierNode(ExpressionASTNode):
|
|
36
|
+
contents: str
|
|
37
|
+
|
|
38
|
+
@dataclass(frozen=True, slots=True)
|
|
39
|
+
class BooleanLiteralNode(ExpressionASTNode):
|
|
40
|
+
value: bool
|
|
41
|
+
|
|
42
|
+
@dataclass(frozen=True, slots=True)
|
|
43
|
+
class IntegerLiteralNode(ExpressionASTNode):
|
|
44
|
+
value: int
|
|
45
|
+
|
|
46
|
+
@dataclass(frozen=True, slots=True)
|
|
47
|
+
class BinaryOperationNode(ExpressionASTNode):
|
|
48
|
+
left: ExpressionASTNode
|
|
49
|
+
op: BinaryOperationType
|
|
50
|
+
right: ExpressionASTNode
|
|
51
|
+
|
|
52
|
+
@dataclass(frozen=True, slots=True)
|
|
53
|
+
class UnaryOperationNode(ExpressionASTNode):
|
|
54
|
+
op: UnaryOperationType
|
|
55
|
+
operand: ExpressionASTNode
|
|
56
|
+
|
|
57
|
+
@dataclass(frozen=True, slots=True)
|
|
58
|
+
class VariableDeclarationNode(ASTNode):
|
|
59
|
+
variable_type: VariableType
|
|
60
|
+
identifier: IdentifierNode
|
|
61
|
+
|
|
62
|
+
@dataclass(frozen=True, slots=True)
|
|
63
|
+
class ArrayDeclarationNode(ASTNode):
|
|
64
|
+
element_type: VariableType
|
|
65
|
+
size: int
|
|
66
|
+
identifier: IdentifierNode
|
|
67
|
+
|
|
68
|
+
@dataclass(frozen=True, slots=True)
|
|
69
|
+
class ArrayAccessNode(ExpressionASTNode):
|
|
70
|
+
array_name: IdentifierNode
|
|
71
|
+
index: ExpressionASTNode
|
|
72
|
+
|
|
73
|
+
@dataclass(frozen=True, slots=True)
|
|
74
|
+
class AssignmentStatementNode(StatementASTNode):
|
|
75
|
+
target: IdentifierNode | ArrayAccessNode
|
|
76
|
+
expression: ExpressionASTNode
|
|
77
|
+
|
|
78
|
+
@dataclass(frozen=True, slots=True)
|
|
79
|
+
class InvokeStatementNode(StatementASTNode):
|
|
80
|
+
procedure_name: IdentifierNode
|
|
81
|
+
|
|
82
|
+
@dataclass(frozen=True, slots=True)
|
|
83
|
+
class IfStatementNode(StatementASTNode):
|
|
84
|
+
condition: IdentifierNode
|
|
85
|
+
then_block: Sequence[StatementASTNode]
|
|
86
|
+
else_block: Sequence[StatementASTNode]
|
|
87
|
+
|
|
88
|
+
@dataclass(frozen=True, slots=True)
|
|
89
|
+
class WhileStatementNode(StatementASTNode):
|
|
90
|
+
condition: IdentifierNode
|
|
91
|
+
body: Sequence[StatementASTNode]
|
|
92
|
+
|
|
93
|
+
@dataclass(frozen=True, slots=True)
|
|
94
|
+
class ProcedureNode(ASTNode):
|
|
95
|
+
name: IdentifierNode
|
|
96
|
+
statements: Sequence[StatementASTNode]
|
|
97
|
+
|
|
98
|
+
@dataclass(frozen=True, slots=True)
|
|
99
|
+
class ProgramNode(ASTNode):
|
|
100
|
+
declarations: Sequence[VariableDeclarationNode | ArrayDeclarationNode]
|
|
101
|
+
procedures: Sequence[ProcedureNode]
|