Clean up ppp_stdlib.py

This commit is contained in:
germax26 2024-10-01 14:37:23 +10:00
parent 04fff7514e
commit 9e68c529bf
Signed by: germax26
SSH Key Fingerprint: SHA256:N3w+8798IMWBt7SYH8G1C0iJlIa2HIIcRCXwILT5FvM
2 changed files with 9 additions and 4 deletions

View File

@ -1,5 +1,3 @@
# This file exists because I wanted to keep ppp_stdlib.py and ppp_interpreter.py seperate but they both rely on this one class.
from abc import ABC, abstractmethod
from dataclasses import dataclass
from typing import Callable, Dict, List as List_, Tuple as Tuple_

View File

@ -42,7 +42,13 @@ def len_impl(list_: Object) -> Object:
assert False
# TODO: Use polymorphism to make this work for both list<T> and str
# Len = PythonFunction("len", [('list', UnionType([ListType(VariableType("")), StrType]))], IntType, len_impl)
Len = PythonFunction("len", [('list', ListType(VariableType("")))], IntType, len_impl)
def str_len_impl(str_: Object) -> Object:
assert isinstance(str_, Str)
return Int(len(str_.str))
StrLen = PythonFunction("strlen", [('string', StrType)], IntType, str_len_impl)
def str_to_int_impl(str_: Object) -> Object:
assert isinstance(str_, Str)
@ -100,7 +106,8 @@ variables: Dict[str, Object] = {
'void': VoidTypeObj,
'debug_print': DebugPrint,
'read': Read,
# 'len': Len,
'len': Len,
'str_len': StrLen,
'str_to_int': StrToInt,
'none': NoneObj,
'range': Range,