From bee0c845a834669f0f21ebc6b9df9c38bcc9cce0 Mon Sep 17 00:00:00 2001 From: "Johan B.W. de Vries" Date: Fri, 2 May 2025 21:12:25 +0200 Subject: [PATCH] Removes UnaryOp It was no longer used. --- TODO.md | 1 - phasm/codestyle.py | 3 --- phasm/compiler.py | 7 ------- phasm/ourlang.py | 15 --------------- phasm/parser.py | 16 +--------------- phasm/type3/constraintsgenerator.py | 3 --- 6 files changed, 1 insertion(+), 44 deletions(-) diff --git a/TODO.md b/TODO.md index a6b450c..a7b370d 100644 --- a/TODO.md +++ b/TODO.md @@ -29,7 +29,6 @@ - Implemented Bounded: https://hackage.haskell.org/package/base-4.21.0.0/docs/Prelude.html#t:Bounded - Try to implement the min and max functions using select - Filter out methods that aren't used; other the other way around (easier?) only add __ methods when needed -- Move UnaryOp.operator into type class methods - Move foldr into type class methods - PrimitiveType is just the type, nothing primitive about it (change the name). u32 are still basic types or something. - Clean up Subscript implementation - it's half implemented in the compiler. Makes more sense to move more parts to stdlib_types. diff --git a/phasm/codestyle.py b/phasm/codestyle.py index 5ac0efe..d36d60f 100644 --- a/phasm/codestyle.py +++ b/phasm/codestyle.py @@ -75,9 +75,6 @@ def expression(inp: ourlang.Expression) -> str: if isinstance(inp, ourlang.VariableReference): return str(inp.variable.name) - if isinstance(inp, ourlang.UnaryOp): - return f'{inp.operator}{expression(inp.right)}' - if isinstance(inp, ourlang.BinaryOp): return f'{expression(inp.left)} {inp.operator.name} {expression(inp.right)}' diff --git a/phasm/compiler.py b/phasm/compiler.py index 33b1499..9903011 100644 --- a/phasm/compiler.py +++ b/phasm/compiler.py @@ -479,13 +479,6 @@ def expression(wgn: WasmGenerator, inp: ourlang.Expression) -> None: raise NotImplementedError(inp.operator, instance_key) - if isinstance(inp, ourlang.UnaryOp): - expression(wgn, inp.right) - - assert isinstance(inp.type3, type3types.Type3), type3placeholders.TYPE3_ASSERTION_ERROR - - raise NotImplementedError(expression, inp.type3, inp.operator) - if isinstance(inp, ourlang.FunctionCall): for arg in inp.arguments: expression(wgn, arg) diff --git a/phasm/ourlang.py b/phasm/ourlang.py index c08496e..b462a41 100644 --- a/phasm/ourlang.py +++ b/phasm/ourlang.py @@ -127,21 +127,6 @@ class VariableReference(Expression): super().__init__() self.variable = variable -class UnaryOp(Expression): - """ - A unary operator expression within a statement - """ - __slots__ = ('operator', 'right', ) - - operator: str - right: Expression - - def __init__(self, operator: str, right: Expression) -> None: - super().__init__() - - self.operator = operator - self.right = right - class BinaryOp(Expression): """ A binary operator expression within a statement diff --git a/phasm/parser.py b/phasm/parser.py index 1d4404f..06a0b6f 100644 --- a/phasm/parser.py +++ b/phasm/parser.py @@ -29,7 +29,6 @@ from .ourlang import ( StructDefinition, Subscript, TupleInstantiation, - UnaryOp, VariableReference, ) from .prelude import PRELUDE_METHODS, PRELUDE_OPERATORS, PRELUDE_TYPES @@ -389,19 +388,6 @@ class OurVisitor: self.visit_Module_FunctionDef_expr(module, function, our_locals, node.right), ) - if isinstance(node, ast.UnaryOp): - if isinstance(node.op, ast.UAdd): - operator = '+' - elif isinstance(node.op, ast.USub): - operator = '-' - else: - raise NotImplementedError(f'Operator {node.op}') - - return UnaryOp( - operator, - self.visit_Module_FunctionDef_expr(module, function, our_locals, node.operand), - ) - if isinstance(node, ast.Compare): if 1 < len(node.ops): raise NotImplementedError('Multiple operators') @@ -476,7 +462,7 @@ class OurVisitor: raise NotImplementedError(f'{node} as expr in FunctionDef') - def visit_Module_FunctionDef_Call(self, module: Module, function: Function, our_locals: OurLocals, node: ast.Call) -> Union[Fold, FunctionCall, UnaryOp]: + def visit_Module_FunctionDef_Call(self, module: Module, function: Function, our_locals: OurLocals, node: ast.Call) -> Union[Fold, FunctionCall]: if node.keywords: _raise_static_error(node, 'Keyword calling not supported') # Yet? diff --git a/phasm/type3/constraintsgenerator.py b/phasm/type3/constraintsgenerator.py index 9138984..217bec3 100644 --- a/phasm/type3/constraintsgenerator.py +++ b/phasm/type3/constraintsgenerator.py @@ -48,9 +48,6 @@ def expression(ctx: Context, inp: ourlang.Expression) -> ConstraintGenerator: comment=f'typeOf("{inp.variable.name}") == typeOf({inp.variable.name})') return - if isinstance(inp, ourlang.UnaryOp): - raise NotImplementedError(expression, inp, inp.operator) - if isinstance(inp, ourlang.BinaryOp) or isinstance(inp, ourlang.FunctionCall): signature = inp.operator.signature if isinstance(inp, ourlang.BinaryOp) else inp.function.signature arguments = [inp.left, inp.right] if isinstance(inp, ourlang.BinaryOp) else inp.arguments