feat: add basic class instance
This commit is contained in:
@@ -8,4 +8,6 @@ class Breakfast {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print(Breakfast)
|
print(Breakfast)
|
||||||
|
let bf = Breakfast()
|
||||||
|
print(bf)
|
||||||
14
src/core/instance.py
Normal file
14
src/core/instance.py
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from src.core.klass import PebbleClass
|
||||||
|
|
||||||
|
|
||||||
|
class PebbleInstance:
|
||||||
|
def __init__(self, klass: PebbleClass):
|
||||||
|
self.klass: PebbleClass = klass
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"<instance of {self.klass}>"
|
||||||
@@ -1,6 +1,24 @@
|
|||||||
class PebbleClass:
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any, TYPE_CHECKING
|
||||||
|
|
||||||
|
from src.core.callable import PebbleCallable
|
||||||
|
from src.core.instance import PebbleInstance
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from src.interpreter.interpreter import Interpreter
|
||||||
|
|
||||||
|
|
||||||
|
class PebbleClass(PebbleCallable):
|
||||||
def __init__(self, name: str):
|
def __init__(self, name: str):
|
||||||
self.name: str = name
|
self.name: str = name
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
def arity(self) -> int:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def call(self, interpreter: Interpreter, arguments: list[Any]) -> Any:
|
||||||
|
instance: PebbleInstance = PebbleInstance(self)
|
||||||
|
return instance
|
||||||
|
|||||||
Reference in New Issue
Block a user