Clean up ppp_stdlib.py
This commit is contained in:
		
							parent
							
								
									04fff7514e
								
							
						
					
					
						commit
						9e68c529bf
					
				| @ -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 abc import ABC, abstractmethod | ||||||
| from dataclasses import dataclass | from dataclasses import dataclass | ||||||
| from typing import Callable, Dict, List as List_, Tuple as Tuple_ | from typing import Callable, Dict, List as List_, Tuple as Tuple_ | ||||||
|  | |||||||
| @ -42,7 +42,13 @@ def len_impl(list_: Object) -> Object: | |||||||
| 	assert False | 	assert False | ||||||
| 
 | 
 | ||||||
| # TODO: Use polymorphism to make this work for both list<T> and str | # 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: | def str_to_int_impl(str_: Object) -> Object: | ||||||
| 	assert isinstance(str_, Str) | 	assert isinstance(str_, Str) | ||||||
| @ -100,7 +106,8 @@ variables: Dict[str, Object] = { | |||||||
| 	'void': VoidTypeObj, | 	'void': VoidTypeObj, | ||||||
| 	'debug_print': DebugPrint, | 	'debug_print': DebugPrint, | ||||||
| 	'read': Read, | 	'read': Read, | ||||||
| 	# 'len': Len, | 	'len': Len, | ||||||
|  | 	'str_len': StrLen, | ||||||
| 	'str_to_int': StrToInt, | 	'str_to_int': StrToInt, | ||||||
| 	'none': NoneObj, | 	'none': NoneObj, | ||||||
| 	'range': Range, | 	'range': Range, | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user