| | 1 | Example "class": |
|---|
| | 2 | |
|---|
| | 3 | {{{ |
|---|
| | 4 | module Example; |
|---|
| | 5 | |
|---|
| | 6 | thread watcher(self) = |
|---|
| | 7 | begin |
|---|
| | 8 | lock self.mutex do |
|---|
| | 9 | wait self.signal, self.mutex; |
|---|
| | 10 | :$Signaled.$ |
|---|
| | 11 | end; |
|---|
| | 12 | end watcher; |
|---|
| | 13 | |
|---|
| | 14 | var |
|---|
| | 15 | T: array const := { |
|---|
| | 16 | "watcher" := watcher |
|---|
| | 17 | }; |
|---|
| | 18 | |
|---|
| | 19 | begin |
|---|
| | 20 | end Example. |
|---|
| | 21 | }}} |
|---|
| | 22 | |
|---|
| | 23 | As XL procedures are procedures __or__ threads, depending on keyword used, so are XL methods. Above example illustrates this. |
|---|
| | 24 | |
|---|
| | 25 | Client code for this example: |
|---|
| | 26 | |
|---|
| | 27 | {{{ |
|---|
| | 28 | module Test; |
|---|
| | 29 | |
|---|
| | 30 | import |
|---|
| | 31 | Example; |
|---|
| | 32 | |
|---|
| | 33 | proc Main() = |
|---|
| | 34 | var |
|---|
| | 35 | e := clone(Example.T); |
|---|
| | 36 | i; |
|---|
| | 37 | begin |
|---|
| | 38 | e.watcher(); |
|---|
| | 39 | |
|---|
| | 40 | for i:=1 to 3 do |
|---|
| | 41 | delay(1); |
|---|
| | 42 | signal e.signal; |
|---|
| | 43 | delay(1); |
|---|
| | 44 | end; |
|---|
| | 45 | end Main; |
|---|
| | 46 | |
|---|
| | 47 | begin |
|---|
| | 48 | end Test. |
|---|
| | 49 | }}} |
|---|
| | 50 | |
|---|
| | 51 | Inheritance is single, but it will be multiple if rationale found. It is done like this: |
|---|
| | 52 | |
|---|
| | 53 | {{{ |
|---|
| | 54 | module Inherited; |
|---|
| | 55 | |
|---|
| | 56 | proc another(self) = |
|---|
| | 57 | begin |
|---|
| | 58 | :... |
|---|
| | 59 | end another; |
|---|
| | 60 | |
|---|
| | 61 | var |
|---|
| | 62 | T: array const := Example.T + { |
|---|
| | 63 | "another" := another |
|---|
| | 64 | }; |
|---|
| | 65 | |
|---|
| | 66 | begin |
|---|
| | 67 | end Inherited. |
|---|
| | 68 | |
|---|
| | 69 | }}} |
|---|
| | 70 | |
|---|
| | 71 | As all of this is prototype based, methods with same name in supertype (Example.T) would not be overriden with above syntax. To override them, one will use: |
|---|
| | 72 | |
|---|
| | 73 | {{{ |
|---|
| | 74 | var |
|---|
| | 75 | T: array const := { |
|---|
| | 76 | "another" := another |
|---|
| | 77 | } + Example.T; |
|---|
| | 78 | }}} |
|---|
| | 79 | |
|---|
| | 80 | Few things are on wish-list for now. First, some syntax sugar for object declarations. Right now, we use ''array const'' to store our prototype in and it works, with it's limitiations. |
|---|
| | 81 | |
|---|
| | 82 | Runtime object of another order is needed here, and it is right place to introduce some ''XLClass'' object, to store "class" data into. New object mandates new syntax, maybe one where content is given by XLVarList, like: |
|---|
| | 83 | |
|---|
| | 84 | {{{ |
|---|
| | 85 | module Render; |
|---|
| | 86 | |
|---|
| | 87 | class |
|---|
| | 88 | T = Render.T { |
|---|
| | 89 | id: text; |
|---|
| | 90 | attrs: array := {}; |
|---|
| | 91 | } methods { |
|---|
| | 92 | traverse(); |
|---|
| | 93 | print(); |
|---|
| | 94 | }; |
|---|
| | 95 | }}} |
|---|
| | 96 | |
|---|
| | 97 | Currently, only type system present in XL runtime is Modula-3 one, used through [source:trunk/m3/xl/src/modules/XLModuleRTI.m3 RTI]. Another type system we evaluate for ''in vivo'' integration is Gtk 2.x [http://developer.gnome.org/doc/API/2.0/gobject/ch02.html The Glib Dynamic Type System]. |
|---|
| | 98 | |
|---|
| | 99 | Emerging XL type system will mostly be aligned towards Modula-3 system, but Glib's is not to be ignored. It would be a boon to fully integrate emerging XL type system with existing Modula-3 and Glib systems. We can inherit multiple object types, even Modula-3/Glib mix. But, for obvious reasons, only one runtime layout can be used and that only for classes with single inheritance. Currently, with [source:trunk/m3/xl/src/modules/XLModuleRTI.m3 RTI] fully enabling read/write access to Modula-3 objects and plans to dynamically add/remove new object types to Modula-3 runtime, Modula-3 runtime layout is clear choice. |