Skip to content
This repository has been archived by the owner on Mar 14, 2018. It is now read-only.

Classes #5

Open
thosakwe opened this issue Feb 15, 2017 · 5 comments
Open

Classes #5

thosakwe opened this issue Feb 15, 2017 · 5 comments

Comments

@thosakwe
Copy link
Collaborator

No description provided.

@thosakwe thosakwe changed the title Structs Classes Feb 16, 2017
@thosakwe
Copy link
Collaborator Author

thosakwe commented Feb 16, 2017

class Foo {
  let x = 2;
  mut a:string;

  constructor() {
    this("<no message>");
  }

  constructor(this.message);

  factory hello() => new Foo("Hello, world!");

  bar():void => printf "Message: %s%n", message;
}

class Bar extends Foo {
  @override()
  bar():void {
    this.message = "Polymorphism... rules!";
    super.bar();
  }
}

Resolving class members without this will require adding a BonoboType thisContext to Scope.

There always will need to be a check to ensure that factory constructors are not called via super.

Overrides will also have to make sure that their signatures match.

@thosakwe
Copy link
Collaborator Author

In the future, abstract classes can be added. implementing them will require a re-definition of all methods.

abstract class Reason {
  get name:string; // Requires getter
  set name(value:int); // Require setter
  precedence:int; // Require both

  explain():string;
}

class BaseReason implements Reason {
  _name:string;

  constructor(this._name);

  @override()
  get name => _name;

  // ...
}

@thosakwe
Copy link
Collaborator Author

thosakwe commented Feb 17, 2017

classDefinition:
  classModifier* 'class' name=ID ('extends' parentType=type)?
  ((implementedTypes+=type ',')* implementedTypes+=type)?
  '{' classMemberDefinition* '}'
;

classMemberDefinition:
  'constructor' '(' ((constructorParameter)* constructorParameter)? ')' #ConstructorDefinition
  | specifier=('let'|'mut') (variableDeclaration ',')* variableDeclaration #PropertyDefinition
  | funcSignature ';' #AbstractMethodDefinition
  | funcSignature block #MethodDefinition
;

constructorParameter:
  'this' '.' ID #PropertyConstructorParameter
  | ID (':' type)? #RegularConstructorParameter
;

classModifier: 'abstract' | 'final';

@thosakwe
Copy link
Collaborator Author

Eventually, classes will need to add annotations (#9).

@thosakwe
Copy link
Collaborator Author

#15

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant