diff --git a/phasm/ourlang.py b/phasm/ourlang.py index 4200f2f..696cf9e 100644 --- a/phasm/ourlang.py +++ b/phasm/ourlang.py @@ -224,22 +224,20 @@ class FunctionParam: """ A parameter for a Function """ - __slots__ = ('name', 'type3', 'type_str', ) + __slots__ = ('name', 'type3', ) name: str - type3: Type3 - type_str: str + type3: Type3OrPlaceholder - def __init__(self, name: str, type3: Type3) -> None: + def __init__(self, name: str, type3: Optional[Type3]) -> None: self.name = name - self.type3 = type3 - self.type_str = type3.name + self.type3 = PlaceholderForType([self]) if type3 is None else type3 class Function: """ A function processes input and produces output """ - __slots__ = ('name', 'lineno', 'exported', 'imported', 'statements', 'returns_type3', 'returns_str', 'posonlyargs', ) + __slots__ = ('name', 'lineno', 'exported', 'imported', 'statements', 'returns_type3', 'posonlyargs', ) name: str lineno: int @@ -247,7 +245,6 @@ class Function: imported: bool statements: List[Statement] returns_type3: Type3 - returns_str: str posonlyargs: List[FunctionParam] def __init__(self, name: str, lineno: int) -> None: @@ -256,8 +253,7 @@ class Function: self.exported = False self.imported = False self.statements = [] - self.returns_type3 = type3types.none - self.returns_str = 'None' + self.returns_type3 = type3types.none # FIXME: This could be a placeholder self.posonlyargs = [] class StructDefinition: @@ -319,12 +315,11 @@ class ModuleConstantDef: """ A constant definition within a module """ - __slots__ = ('name', 'lineno', 'type3', 'type_str', 'constant', 'data_block', ) + __slots__ = ('name', 'lineno', 'type3', 'constant', 'data_block', ) name: str lineno: int type3: Type3 - type_str: str constant: Constant data_block: Optional['ModuleDataBlock'] @@ -332,7 +327,6 @@ class ModuleConstantDef: self.name = name self.lineno = lineno self.type3 = type3 - self.type_str = type3.name self.constant = constant self.data_block = data_block diff --git a/phasm/parser.py b/phasm/parser.py index 3cadcdc..3f0afbb 100644 --- a/phasm/parser.py +++ b/phasm/parser.py @@ -119,12 +119,9 @@ class OurVisitor: _not_implemented(not node.args.posonlyargs, 'FunctionDef.args.posonlyargs') for arg in node.args.args: - if not arg.annotation: - _raise_static_error(node, 'Type is required') - function.posonlyargs.append(FunctionParam( arg.arg, - self.visit_type(module, arg.annotation), + self.visit_type(module, arg.annotation) if arg.annotation else None, )) _not_implemented(not node.args.vararg, 'FunctionDef.args.vararg') @@ -147,9 +144,11 @@ class OurVisitor: else: function.imported = True - if node.returns: + if node.returns is not None: # Note: `-> None` would be a ast.Constant function.returns_type3 = self.visit_type(module, node.returns) - function.returns_str = function.returns_type3.name + else: + # Mostly works already, needs to fix Function.returns_type3 and have it updated + raise NotImplementedError('Function without an explicit return type') _not_implemented(not node.type_comment, 'FunctionDef.type_comment')