Oxygene (programming language)
≈ 8 min read
Names in other languages
No names in other languages are held for this entry yet.
Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.
Oxygene (formerly named Chrome) is a programming language developed by RemObjects Software for Microsoft's Common Language Infrastructure (CLI), the Java platform, and Cocoa. Oxygene is based on the language Delphi Object Pascal, and influences from C#, Eiffel, Java, F#, and others. Compared to the now deprecated Delphi.NET, Oxygene does not emphasize total backward compatibility, but is designed to be a "reinvention" of the language, leverage all the features and technologies provided by the .NET and Java virtual machine runtimes.
Impact
Oxygene is a commercial product and offers full integration into Microsoft's Visual Studio integrated development environment (IDE) on Windows, and its own IDE called Fire for use on macOS. Oxygene is one of six languages supported by the underlying Elements compiler toolchain, next to C#, Swift, Java, Go and Mercury (based on Visual Basic (.NET)). From 2008 to 2012, RemObjects Software licensed its compiler and IDE technology to Embarcadero to be used as the backend compiler in their Embarcadero Prism product.
Starting in the Fall of 2011, Oxygene became available in two separate editions, with the second edition adding support for the Java and Android runtimes. Starting with the release of XE4, Embarcadero Prism is no longer part of the RAD Studio SKU. Numerous support and upgrade paths for Prism customers exist to migrate to Oxygene.…
Oxygene (formerly named Chrome) is a programming language developed by RemObjects Software for Microsoft's Common Language Infrastructure (CLI), the Java platform, and Cocoa. Oxygene is based on the language Delphi Object Pascal, and influences from C#, Eiffel, Java, F#, and others. Compared to the now deprecated Delphi.NET, Oxygene does not emphasize total backward compatibility, but is designed to be a "reinvention" of the language, leverage all the features and technologies provided by the .NET and Java virtual machine runtimes.
Oxygene is a commercial product and offers full integration into Microsoft's Visual Studio integrated development environment (IDE) on Windows, and its own IDE called Fire for use on macOS. Oxygene is one of six languages supported by the underlying Elements compiler toolchain, next to C#, Swift, Java, Go and Mercury (based on Visual Basic (.NET)). From 2008 to 2012, RemObjects Software licensed its compiler and IDE technology to Embarcadero to be used as the backend compiler in their Embarcadero Prism product.
Starting in the Fall of 2011, Oxygene became available in two separate editions, with the second edition adding support for the Java and Android runtimes. Starting with the release of XE4, Embarcadero Prism is no longer part of the RAD Studio SKU. Numerous support and upgrade paths for Prism customers exist to migrate to Oxygene.
How it works
As of 2016, there is only one edition of Oxygene, which allows development on Windows or macOS, and which can create executables for Windows, Linux, WebAssembly .NET, iOS, Android, Java and macOS. class operator implicit(i : Integer) : MyClass; Note, that for operator overloading each operator has a name, that has to be used in the operator overloading syntax, because for example "+" would not be a valid method name in Oxygene. uses System.Linq; Imported namespaces must be in the project itself or in referenced assemblies.
Unlike in C#, in Oxygene alias names cannot be defined for namespaces, only for single type names (see below). Following the uses clause a file contains type declarations, like they are known from Delphi: interface type ConsoleApp = class public class method Main; end; As in C#, the Main method is the entry point for every program. It can have a parameter args : Array of String for passing command line arguments to the program. More types can be declared without repeating the type keyword.
The implementation of the declared methods is placed in the implementation section: implementation class method ConsoleApp.Main; begin // add your own code here Console.WriteLine('Hello World.'); end; end. Files are always ended with end. type MyClass = public class end; The visibility can be set for every type defined (classes, interfaces, records, ...).
An alias name can be defined for types, which can be used locally or in other Oxygene assemblies. type IntList = public List ; //visible in other Oxygene-assemblies SecretEnumerable = IEnumerable ; //not visible in other assemblies Public type aliases won't be visible for other languages. type MyRecord = record method Foo; end; As they're just .NET structs, records can have fields, methods and properties, but do not have inheritance and cannot implement interfaces. type MyInterface = public interface method MakeItSo : IEnumerable; property Bar : String read write; end; Please notice, that for properties the getter and setter are not explicitly specified. method MainForm.MainForm_Load(sender: System.Object; e: System.EventArgs); begin Invoke(@DoSomething); end; An anonymous delegate with the signature of the method DoSomething will be created by the compiler.
Oxygene supports polymorphic delegates, which means, that delegates which have parameters of descending types are assignment compatible.
Assume two classes MyClass and MyClassEx = class(MyClass) , then in the following code BlubbEx is assignment compatible to Blubb . type delegate Blubb(sender : Object; m : MyClass); delegate BlubbEx(sender : Object; mx : MyClassEx); Fields can be used to delegate the implementation of an interface, if the type they're of implements this interface: Implementor = public class(IMyInterface) // ... implement interface ... end; MyClass = public class(IMyInterface) fSomeImplementor : Implementor; public implements IMyInterface; //takes care of implementing the interface end; In this example the compiler will create public methods and properties in MyClass , which call the methods / properties of fSomeImplementor , to implement the members of IMyInterface.
This can be used to provide mixin-like functionality. method Window1.PredictNearFuture; //declared as async in the interface begin // ... Calculate result here, store in variable "theFuture" Dispatcher.Invoke(DispatcherPriority.ApplicationIdle, method; begin theFutureTextBox.Text := theFuture; end); end; Anonymous methods can have parameters, too: method Window1.PredictNearFuture; //declared as async in the interface begin // ...
Calculate result here, store in variable "theFuture" Dispatcher.Invoke(DispatcherPriority.ApplicationIdle, method(aFuture : String); begin theFutureTextBox.Text := aFuture ; end, theFuture); end; Both source codes use anonymous delegates. property Foo : String read fFoo write SetFoo; notify; property Bar : String; notify 'Blubb'; //will notify that property "Blubb" was changed instead of "Bar" The modifier can be used on properties which have a setter method.
The code to raise the events will then be added to this method during compile time. namespace HelloWorld; interface type HelloClass = class public class method Main; end; implementation class method HelloClass.Main; begin writeLn('Hello World!'); end; end. namespace GenericContainer; interface type TestApp = class public class method Main; end; Person = class public property FirstName: String; property LastName: String; end; implementation uses System.Collections.Generic; class method TestApp.Main; begin var myList := new List ; //type inference myList.Add(new Person(FirstName := 'John', LastName := 'Doe')); myList.Add(new Person(FirstName := 'Jane', LastName := 'Doe')); myList.Add(new Person(FirstName := 'James', LastName := 'Doe')); Console.WriteLine(myList[1].FirstName); //No casting needed Console.ReadLine; end; end. namespace GenericMethodTest; interface type GenericMethodTest = static class public class method Main; private class method Swap (var left, right : T); class method DoSwap (left, right : T); end; implementation class method GenericMethodTest.DoSwap (left, right : T); begin var a := left; var b := right; Console.WriteLine('Type: {0}', typeof(T)); Console.WriteLine('-> a = {0}, b = {1}', a , b); Swap (var a, var b); Console.WriteLine('-> a = {0}, b = {1}', a , b); end; class method GenericMethodTest.Main; begin var a := 23;// type inference var b := 15; DoSwap (a, b); // no downcasting to Object in this method. var aa := 'abc';// type inference var bb := 'def'; DoSwap (aa, bb); // no downcasting to Object in this method.
DoSwap(1.1, 1.2); // type inference for generic parameters Console.ReadLine(); end; class method GenericMethodTest.Swap (var left, right : T); begin var temp := left; left:= right; right := temp; end; end. Program output: Type: System.Int32 -> a = 23, b = 15 -> a = 15, b = 23 Type: System.String -> a = abc, b = def -> a = def, b = abc Type: System.Double -> a = 1,1, b = 1,2 -> a = 1,2, b = 1,1
Text derived from https://en.wikipedia.org/w/index.php?oldid=1366310232 under CC BY-SA 4.0; modifications have been made.