Programmer's Wiki
Advertisement

Twilight is a general purpose, imperative, object-oriented programming language. Twilight supports both untyped and typed variable declarations, operator overloading, method overloading, exception handling, and namespaces. At runtime Twilight is compiled to native code and features automatic memory management via garbage collection. Twilight also supports multi-threading and concurrency built upon operating system primitives for each supported platform.

Philosophy[]

Twilight is a simple, orthogonal language. It is intended to allow a developer to build reusable functionality without the need to learn a complex language feature set or multiple specialized syntaxes. It is designed with source level portability in mind and with the minimal abstraction necessary to allow cross-platform development. Twilight also allows for the inline inclusion of C or C++ code, although its use is intended to be limited to base language functionality or integration with existing libraries and applications.

Implementation[]

Twilight is presently implemented as a self-hosting parser-generator which generates platform independent C code which is then compiled to native executables. Care has been taken to avoid specific compiler lock-in, at present various versions of the gcc compiler, specifically those in the 3 and 4 range, have been tested along with the Microsoft Visual C++ compiler.

Licensing[]

The present implemetation of Twilight is dually licensed under the Mozilla and LGPL licenses in the hope that it will be available from a licensing perspective for use on a wide range of both open source and commercial projects

Status[]

As of this writing Twilight is in a late alpha state. It is self-hosting, the base classes are reasonably well tested although somewhat limited in scope. Multithreading, garbage collection, exception handling, introspection, dynamic invocation, and the runtime are well tested and solid but no doubt not without bugs. The primary platforms are Linux and Windows although Mac OS X and FreeBSD builds have been successfully tested as well. Of the intended core functionalities only Unicode support is incomplete. Once it is completed the language and library will enter a Beta state prior to release.

Characteristics[]

Twilight is an object oriented language with some support for other paradigms available from within an object oriented syntax. It has a relatively small set of keywords for the purposes of declaration, instance construction, iteration, and flow control.

Object references and life cycle[]

In Twilight all variables are passed by reference and all refer to objects, specifically, class instances. There are no static variables or static methods as such. At initialization, the class defined at compilation time as the "main" class is instantiated with a no argument constructor and it's main method is invoked. To facilitate shared data and procedural programming paradigms Twilight includes special class declarations, the "singleton" and the "factory". Each of these are guaranteed to only have a single instance constructed during the lifetime of a running process and so they and their members effectively allow for global references. Singletons and factories differ in that the constructor for a singleton is only invoked once and thereafter the instance is returned without invocation of the constructor. In the case of factories the constructor is invoked each time it is called but the object returned from the factory is returned to the caller instead of the factory instance itself.

See Twilight/Object life cycle for more detail regarding construction, destruction, and overall lifecycle of a class instance.

Operators and methods[]

Statements involving operators are translated into appropriate method calls, operator overloading is supported (and is the basis for all operations, including those which are generally thought of as "built in"). Optimizations do allow for certain operations to occur at runtime without function call overhead, such as the addition of typed integers.

See Twilight/Operators and methods for more information regarding method declaration, special method names, and operator and method overloading.

Inheritance[]

Twilight supports single inheritance of member and method declarations, including constructors and destructors, and has a single inheritance root in System:Object. Twilight does not support member or method access control, all members and methods are effectively "public".

See Twilight/Inheritance for more detail regarding class construction and the details of inheritance.

Namespaces[]

Runtime functionality is organized into "compilation units", which are similar shared libraries with additional information required to allow use and extension from other compilation units. A compilation unit has a unique name and file system path which is referenced by other compilation units at compile time. Twilight supports name spaces with steps separated by ":", example class names include System:Object, Container:Map, IO:File:Path. Explicit import of a class is not required for access from other class, only reference by name. The "use" keyword allows import of a name for convenience, so "use IO:File:Path;" will thereafter allow for the single term "Path" to stand in anywhere you might use "IO:File:Path".

See Twilight/Namespaces for more detail regarding name spaces and compilation units.

Static and dynamic typing[]

Twilight supports both untyped and typed variable declarations which result in completely late binding (untyped) or partial or complete early binding (typed, depending on finality of method) of calls made on instances assigned to those variables. For typed variables many correctness checks will occur at compilation time including availability of method calls and member accesses as called. Return and argument types for methods can be declared. There is no explicit type casting in Twilight, for any assignment to a typed variable a determination is made whether a type check is required for correctness and that type check occurs at runtime. Assignments which cannot be correct due to the types involved are caught at compilation time, assignments which may or may not be correct (uncluding untyped to typed variables) are automatically checked at runtime, and assignments which can never be incorrect (type to same type or parent by inheritance) are not checked at run time.

See Twilight/Typing for more detail regarding untyped and typed declaration and automatic casts.

Members and accessors[]

All object members have automatically generated accessor methods for get and set operations. These can be overriden by defining appropriately named methods which will then intercept the get and set operations. Optimizations for member access where the accessors are generated do occur so that no-call access is possible.

See Twilight/Accessors for more detail regarding member access syntax and overridng generated defaults.

Standard library[]

Twilight has a library of simple and complex classes included in it's base functionality. These include primitive numeric and character types, containers, file system and command execution and other operating system interfaces, threading and concurrency primitives, classes to support dynamic invocation and introspection, among other things.

See Twilight/Library Twilight/Numbers Twilight/Text Twilight/Containers Twilight/OS interfaces and Twilight/Threading for more information on these.

Under the hood[]

TODO: Include details regarding generated code and the runtime.

Advertisement