-
Notifications
You must be signed in to change notification settings - Fork 2
Objects
Nikitin Ilya edited this page Apr 29, 2020
·
7 revisions
A usual container of data, compared by reference in memory, with known powerful possibilities.
Example:
class Human
name: string
surname: string
age: date
fn init (self.name, self.surname, self.age) { }
fn greet
Console.write-line(f"Hello, {name} {surname}!")
Shorthand "dataclass" syntax:
class Human (name: string, surname: string, age: date)
fn greet
Console.write-line(f"Hello, {name} {surname}!")
Inheritance:
# Here student has name, surname and age,
# because code declared inheritance from 'Human' class.
class Student `(course: int, specialty: string) <- Human
Single instance of it's own definition. Meant as singleton class.
object IdFactory
@private counter = 0
fn create -> int
counter += 1
return counter
A lightweight storage of data, cannot be inherited or polymorphed.
@case class Point (x: int, y: int)
Case classes are compared by value:
point = Point(1, 2)
point2 = Point(1, 2)
point3 = Point(2, 2)
if point == point2
Console.write-line(f"{point} and {point2} are the same.")
else
Console.write-line(f"{point} and {point2} are different.")
# Point(1,2) and Point(1,2) are the same.
if point == point3
Console.write-line(f"{point} and {point3} are the same.")
else
Console.write-line(f"{point} and {point3} are different.")
# Point(1,2) and Point(2,2) are different.
Expressions
Public compiler interface
-
Units & Modules
- TODO -
Compiler
class
Backend
- Lexer (Tokenizer)
- Syntax tree
- Traversing