Przeglądaj źródła

Add eberon documentation.

Vladislav Folts 11 lat temu
rodzic
commit
c5825baea5
5 zmienionych plików z 86 dodań i 2 usunięć
  1. 2 1
      README.md
  2. 4 1
      browser/oberonjs.html
  3. 57 0
      doc/wiki/eberon-methods.md
  4. 5 0
      doc/wiki/eberon.md
  5. 18 0
      doc/wiki/home.md

+ 2 - 1
README.md

@@ -1,6 +1,7 @@
 # Oberon 07 compiler
 
-Written in JavaScript and transaltes Oberon to JavaScript code so it can be run in web browser.
+Written in JavaScript (and partially on oberon itself) and transaltes Oberon to JavaScript code so it can be run in web browser.
+Supports both "pure" and "plus extensions" mode. Pure mode is a strict implementation of original Oberon language report. Language [extensions](/vladfolts/oberonjs/wiki/Eberon) implemented in my own way and available as a separate compiler mode.
 
 ## Quick start
 You can try the compiler online [here](http://oberspace.dyndns.org/oberonjs.html).

+ 4 - 1
browser/oberonjs.html

@@ -21,7 +21,10 @@
 <form action="">
 Oberon module(s):
 <input type="radio" name="compiler" value="oberon" checked>Oberon
-<input type="radio" name="compiler" value="eberon" id="eberon">Eberon
+<input type="radio" name="compiler" value="eberon" id="eberon">
+    <a href="https://github.com/vladfolts/oberonjs/wiki/Eberon">
+    Eberon
+    </a>
 </form>
 </p>
 

+ 57 - 0
doc/wiki/eberon-methods.md

@@ -0,0 +1,57 @@
+Methods are introduced to support OOP polymorphism for a data type (RECORD in case of oberon). Wirth suggests to achieve such polymorphism using procedure fields. This approach is not reliable nor efficient, also it produces a lot of garbage code. So Eberon supports methods natively.
+
+### Syntax
+Methods are declared similary to record fields. Original oberon record declaration modified to:
+
+    RecordType = RECORD ["(" BaseType ")"] [FieldListSequence] END.
+    FieldListSequence = FieldList {";" FieldList}.
+    FieldList = MethodHeading | (IdentList ":" type).
+
+*MethodHeading* is a new syntax for methods declaration:
+
+    MethodHeading = PROCEDURE identdef [formalParameters].
+
+Example:
+
+    Figure = RECORD
+        PROCEDURE draw(color: INTEGER)
+    END;
+
+Declared methods may be defined later using the same syntax as for ordinary procedures but having type name as a prefix to method name:
+
+    ProcedureDeclaration = ProcedureHeading ";" ProcedureBody ident ["." ident].
+    ProcedureHeading = PROCEDURE [ident "."] identdef [FormalParameters].
+
+Example:
+
+    PROCEDURE Figure.draw(color: INTEGER);
+    END Figure.draw;
+
+New keywords **SELF** and **SUPER** were introduced to reference record instance in method definition and to call base type method.
+
+Example:
+
+    Triangle = RECORD(Figure)
+        border: BOOLEAN
+    END;
+
+    PROCEDURE Triangle.draw(color: INTEGER);
+    BEGIN
+        SUPER(color);
+
+        IF SELF.border THEN
+            drawTriangleBorder(SELF);
+        END;
+    END Triangle.draw;
+
+
+### Semantics
+Methods semantics basically the same as in popular OOP languages (Java, C#, C++).
+
+Each particular method is declared once (in RECORD declaration). Method declaration with the same name is not allowed in type extensions. Type extensions then can define this method in the way specific for a particular extension type. Method definition should:
+* have the same signature as a method declaration
+* be placed in the same scope (module or procedure) as the extension type declaration
+
+Method definition may be missed for a particular type. In this case the type is *abstract*. Abstract type cannot be *instantiated* - variable of this type cannot be declared or pointer to this type allocated using NEW. Method should be defined at least once in inheritance chain for a type to be non-abstract.
+
+SUPER cannot be used to call an abstract method.

+ 5 - 0
doc/wiki/eberon.md

@@ -0,0 +1,5 @@
+**Eberon** is Experimental oBERON. It is my attempt to make a programming language in the right way (in my humble opinion of cause) taking Wirth's Oberon as a start point.
+
+Eberon extends original Oberon so any valid oberon program is also a valid eberon program. A new syntax was introduced for extensions but I tried to maintain the original syntax flavor (e.g. CAPS).
+
+* [Methods](/vladfolts/oberonjs/wiki/eberon-methods)

+ 18 - 0
doc/wiki/home.md

@@ -0,0 +1,18 @@
+### The goal of the project
+I could formulate the goal as "to have traditional static-typed language on the Web". But more realistically it is: to built my own compiler (never did it before but always wanted). Also I wanted to [experiment](/vladfolts/oberonjs/wiki/Eberon) with my own language.
+
+### How to use
+You can use the project as any other JavaScript library. There is no third-party dependencies. The project is developing using nodejs so you may have some additional operations to accommodate nodejs source modules in your project. All source code is under src/ folder. Compiler entry point is oc.js.
+
+### Usage examples
+You can try the compiler online [here](http://oberspace.dyndns.org/oberonjs.html). You can compile more than one module at a time: modules should be separated by spaces or new lines and imported modules should be placed before dependent ones. 
+To build a test html page locally and see how it works run build.cmd (Python 2.x or 3.x is required). It will make _out/os.js (glued nodejs modules) and _out/oberonjs.html. Open oberonjs.html in the browser and try the compiler!
+
+### State of development
+* Proof of concept: Oberon modules compile to JavaScript and can be executed in web browser.
+* No SYSTEM module.
+* All included tests are passing.
+* Please report bugs or any deviations from language report.
+
+### [Implementation details](/vladfolts/oberonjs/wiki/Original-report-refinements)
+### [Experiments](/vladfolts/oberonjs/wiki/Eberon)