Skip to content

Commit fadec95

Browse files
committed
formatting and lint fixes, entry point for new llvm backend
1 parent 000ad4e commit fadec95

File tree

14 files changed

+178
-115
lines changed

14 files changed

+178
-115
lines changed

compiler/builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def __init__(self, name: str):
55
self.indentation = 0
66

77
def newLine(self, line=""):
8-
self.lines.append((self.indentation*" ") + line)
8+
self.lines.append((self.indentation * " ") + line)
99
return self
1010

1111
# returns a reference to the child builder

compiler/cil_backend.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ def currentBuilder(self):
4141

4242
def newLabelName(self) -> str:
4343
self.counter += 1
44-
return "IL_"+str(self.counter)
44+
return "IL_" + str(self.counter)
4545

4646
def label(self, name: str) -> str:
4747
self.builder.unindent()
48-
self.instr(name+": nop")
48+
self.instr(name + ": nop")
4949
self.builder.indent()
5050

5151
def store(self, name: str):
@@ -212,7 +212,7 @@ def constructor(superclass: str, func: FuncDef):
212212
# method
213213
d.type = d.type.dropFirstParam()
214214
self.FuncDef(d, "virtual instance")
215-
if constructor_def == None:
215+
if constructor_def is None:
216216
# give a default constructor if none exists
217217
funcDef = node.getDefaultConstructor()
218218
constructor(superclass, funcDef)

compiler/compiler.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,6 @@ def emitWASM(self, main: str, ast: Node):
8282
wasm_backend = WasmBackend(main, self.transformer.ts)
8383
wasm_backend.visit(ast)
8484
return wasm_backend.builder
85+
86+
def emitLLVM(self, main: str, ast: Node):
87+
pass

compiler/empty_list_typer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def AssignStmt(self, node: AssignStmt):
5959
self.expectedType = node.targets[0].inferredType
6060

6161
def ListExpr(self, node: ListExpr):
62-
if self.expectedType == None:
62+
if self.expectedType is None:
6363
return
6464
expType = self.expectedType
6565
if isinstance(self.expectedType, ListValueType) and len(node.elements) == 0:

compiler/jvm_backend.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ def currentBuilder(self):
2525

2626
def newLabelName(self) -> str:
2727
self.counter += 1
28-
return "L"+str(self.counter)
28+
return "L" + str(self.counter)
2929

3030
def label(self, name: str) -> str:
3131
self.currentBuilder().unindent()
32-
self.instr(name+":")
32+
self.instr(name + ":")
3333
self.currentBuilder().indent()
3434

3535
def returnInstr(self, exprType: ValueType):
@@ -186,7 +186,7 @@ def ClassDef(self, node: ClassDef):
186186
self.constructor(superclass, d)
187187
else:
188188
self.method(d)
189-
if constructor_def == None:
189+
if constructor_def is None:
190190
funcDef = node.getDefaultConstructor()
191191
self.constructor(superclass, funcDef)
192192
self.instr(".end class")
@@ -671,7 +671,8 @@ def emit_input(self):
671671
"invokespecial Method java/util/Scanner <init> (Ljava/io/InputStream;)V")
672672
l = self.newLocal()
673673
self.instr(f"aload {l}")
674-
self.instr("invokevirtual Method java/util/Scanner nextLine ()Ljava/lang/String;")
674+
self.instr(
675+
"invokevirtual Method java/util/Scanner nextLine ()Ljava/lang/String;")
675676

676677
def emit_len(self, arg: Expr):
677678
t = arg.inferredType

compiler/parser.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def visit_Module(self, node):
7474
if (isinstance(body[i], GlobalDecl) or isinstance(body[i], NonLocalDecl)):
7575
raise ParseError(
7676
"Expected function, class, or variable declaration", node.body[i])
77-
if decl == False:
77+
if not decl:
7878
raise ParseError(
7979
"All declarations must come before statements", node.body[i])
8080
declarations.append(b)
@@ -105,7 +105,7 @@ def visit_FunctionDef(self, node):
105105
if isinstance(b, ClassDef):
106106
raise ParseError(
107107
"Inner classes are unsupported", node.body[i])
108-
if decl == False:
108+
if not decl:
109109
raise ParseError(
110110
"All declarations must come before statements", node.body[i])
111111
declarations.append(b)
@@ -143,7 +143,7 @@ def visit_ClassDef(self, node):
143143
node.decorator_list[0])
144144
body = [self.visit(b) for b in node.body]
145145
# allow class bodies that only contain a single pass
146-
if len(body) == 1 and body[0] == None:
146+
if len(body) == 1 and body[0] is None:
147147
body = []
148148
else:
149149
for i in range(len(body)):
@@ -156,7 +156,7 @@ def visit_ClassDef(self, node):
156156

157157
def visit_Return(self, node):
158158
location = self.getLocation(node)
159-
if node.value == None:
159+
if node.value is None:
160160
return ReturnStmt(location, None)
161161
else:
162162
return ReturnStmt(location, self.visit(node.value))
@@ -288,7 +288,7 @@ def visit_Constant(self, node):
288288
return BooleanLiteral(location, node.value)
289289
elif isinstance(node.value, int):
290290
return IntegerLiteral(location, node.value)
291-
elif isinstance(node.value, str) and node.kind == None:
291+
elif isinstance(node.value, str) and node.kind is None:
292292
return StringLiteral(location, node.value)
293293
elif node.value is None:
294294
return NoneLiteral(location)
@@ -335,7 +335,7 @@ def visit_List(self, node):
335335

336336
def visit_NameConstant(self, node):
337337
location = self.getLocation(node)
338-
if node.value == None:
338+
if node.value is None:
339339
return NoneLiteral(location)
340340
elif isinstance(node.value, bool):
341341
return BooleanLiteral(location, node.value)

compiler/typechecker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def AssignStmt(self, node: AssignStmt):
283283
else:
284284
for t in node.targets:
285285
if isinstance(t, IndexExpr) and t.list.inferredType == StrType():
286-
self.addError(t, F"Cannot assign to index of string")
286+
self.addError(t, "Cannot assign to index of string")
287287
return
288288
if isinstance(t, Identifier) and not self.defInCurrentScope(t.name):
289289
self.addError(

compiler/types/classvaluetype.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def getCILName(self):
8686
elif self.className == "int":
8787
return "int64"
8888
else:
89-
return "class "+self.className
89+
return "class " + self.className
9090

9191
def getWasmName(self):
9292
# bools are i32, ints are i64

compiler/types/functype.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ def getWasmSignature(self, names=None) -> str:
6161
sig = f"(param {paramName} {p.getWasmName()})"
6262
params.append(sig)
6363
params = " ".join(params)
64-
result = "" if self.returnType.isNone() else f" (result {self.returnType.getWasmName()})"
64+
result = "" if self.returnType.isNone(
65+
) else f" (result {self.returnType.getWasmName()})"
6566
return params + result
6667

6768
def methodEquals(self, other):

compiler/types/listvaluetype.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ def __eq__(self, other):
1212
return False
1313

1414
def getJavaSignature(self, _=False):
15-
return "["+self.elementType.getJavaSignature(True)
15+
return "[" + self.elementType.getJavaSignature(True)
1616

1717
def getJavaName(self, _=False):
18-
return "["+self.elementType.getJavaSignature(True)
18+
return "[" + self.elementType.getJavaSignature(True)
1919

2020
def getCILName(self, _=False):
2121
return self.elementType.getCILName() + "[]"

0 commit comments

Comments
 (0)