Skip to content

Objects

Nikitin Ilya edited this page Mar 24, 2019 · 7 revisions

Objects

Axion has 3 types of data handling structures, they are inspired by Scala language.

Class

A usual container of data, compared by reference in memory, with known powerful possibilities.

# Example:
class Human
    name: String
    surname: String
    age: DateTime

    fn init (self.name, self.surname, self.age) { }

    fn greet
        Console.print(f"Hello, {name} {surname}!")

And, shortened:

class Human (name: String, surname: String, age: DateTime)
    fn greet
        Console.print(f"Hello, {name} {surname}!")

Inheritance:

class Student (course: Int, specialty: String) <= Human
    # here, student has name, surname and age,
    # because code declared inheritance from 'Human' class.
    pass

Object

Single instance of it's own definition, and meant as singleton class.

object IdFactory
    [private]
    counter = 0

    fn create => Int:
        counter += 1
        counter

Case class

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.print(f"{point} and {point2} are the same.")
else
    Console.print(f"{point} and {point2} are different.")

# Point(1,2) and Point(1,2) are the same.

if point == point3
    Console.print(f"{point} and {point3} are the same.")
else
    Console.print(f"{point} and {point3} are different.")

# Point(1,2) and Point(2,2) are different.

Introduction to language syntax

Expressions

Toolset architecture

Public compiler interface

  • Units & Modules - TODO
  • Compiler class

Backend

  • Lexer (Tokenizer)
  • Syntax tree
  • Traversing

Miscellaneous

Clone this wiki locally