Browse Source

Updated language docs.

Mark Sibly 9 years ago
parent
commit
196f710c67

+ 1 - 0
modules/monkey/docs/language/expressions.md

@@ -180,3 +180,4 @@ End
 </pre>
 </pre>
 
 
 If you have already written an Operator+ (as is the case here) this is not strictly necessary, as monkey2 will generate the code for Operator+= for you. However, you may still want to provide a custom version for Operator+= if your code can do so in a more efficient way.
 If you have already written an Operator+ (as is the case here) this is not strictly necessary, as monkey2 will generate the code for Operator+= for you. However, you may still want to provide a custom version for Operator+= if your code can do so in a more efficient way.
+

+ 0 - 29
modules/monkey/docs/language/native-code.md

@@ -54,32 +54,3 @@ However, you can override this by declaring an extern class that extends `Void`.
 * A native object is not memory managed in any way. It is up to you to 'delete' or otherwise destroy it.
 * A native object is not memory managed in any way. It is up to you to 'delete' or otherwise destroy it.
 
 
 * A native object has no runtime type information, so it cannot be downcast using the `Cast<>` operator.
 * A native object has no runtime type information, so it cannot be downcast using the `Cast<>` operator.
- 
- ---
-
-### The mx2cc tool
-
-mx2cc is the command line compiler for monkey2. The actual executable is named differently depending on the OS:
-
-/bin/mx2cc_windows.exe
-/bin/mx2cc_macos
-/bin/mx2cc_linux
-
-The command line options for mx2cc are:
-
-`mx2cc` _command_ _options_ _input_
-
-Valid commands are:
-
-* `makeapp` - make an app. _input_ should be a monkey2 file path.
-* `makemods` - make a set of modules. _input_ should be a space separated list of module names in dependency order.
-* `makedocs` - make the documentation for a set of modules. _input_ should be a space separated list of module names in dependency order.
-
-Valid options are:
-
-* `clean` - rebuilds everything from scratch.
-* `verbose` - provides more information while building.
-* `target=`_target_ - set target to `desktop` (the default) or `emscripten`.
-*  `config=`_config_ - set config to `debug` (the default) or `release`.
-* `apptype`=_apptype_ set apptype to `gui` (the default) or `console`.
-

+ 72 - 21
modules/monkey/docs/language/user-types.md

@@ -5,17 +5,17 @@
 
 
 To declare a class:
 To declare a class:
 
 
-`Class` _Identifier_ [ `Extends` _SuperClass_ ] [ `Implements` _Interfaces_ ] [ _Modifiers_ ]
-```
-	...Class members...
-```
+<div class=syntax>
+`Class` _Identifier_ [ `<` _GenericTypeIdents_ `>` ] [ `Extends` _SuperClass_ ] [ `Implements` _Interfaces_ ] [ _Modifier_ ]  
+	...Class Members...
 `End`
 `End`
+</div>
 
 
 _SuperClass_ defaults to `Object` if omitted.
 _SuperClass_ defaults to `Object` if omitted.
  
  
 _Interfaces_ is a comma separated list of interface types.
 _Interfaces_ is a comma separated list of interface types.
  
  
-_Modifiers_ can be one of:
+_Modifier_ can be one of:
 
 
 * `Abstract` - class cannot be instantiated with 'New', it must be extended.
 * `Abstract` - class cannot be instantiated with 'New', it must be extended.
 * `Final` - class cannot be extended.
 * `Final` - class cannot be extended.
@@ -26,11 +26,11 @@ Classes can contain consts, globals, fields, methods, functions and other user d
 
 
 To declare a struct:
 To declare a struct:
 
 
-`Struct` _Identifier_ 
-```
+<div class=syntax>
+`Struct` _Identifier_ [ `<` _GenericTypeIdents_ `>` ]
 	...Struct members...
 	...Struct members...
-```	
 `End`
 `End`
+</div>
 
 
 A struct can contain consts, globals, fields, methods, functions and other user defined types.
 A struct can contain consts, globals, fields, methods, functions and other user defined types.
 
 
@@ -48,26 +48,32 @@ Structs are similar to classes, but differ in several important ways:
 
 
 To declare an interface:
 To declare an interface:
 
 
-`Interface` _Identifier_ [ `Extends` _Interfaces_ ]
-```
+<div class=syntax>
+`Interface` _Identifier_ [ `<` _GenericTypeIdents_ `>` ] [ `Extends` _Interfaces_ ]
 	...Interface members...
 	...Interface members...
-```
 `End`
 `End`
+</div>
 
 
 _Interfaces_ is a comma separated list of interface types. 
 _Interfaces_ is a comma separated list of interface types. 
 
 
 An interface can contain consts, globals, fields, methods, functions and other user defined types.
 An interface can contain consts, globals, fields, methods, functions and other user defined types.
 
 
-Interface methods are always 'abstract' and cannot declared any code.
+Interface methods are always 'abstract' and cannot declare any code.
 
 
 
 
 #### Fields
 #### Fields
 
 
 Fields are variables that live inside the memory allocated for an instance of a class or struct. To declare a field variable:
 Fields are variables that live inside the memory allocated for an instance of a class or struct. To declare a field variable:
 
 
+<div class=syntax>
 `Field` _identifier_ `:` _Type_ [ `=` _Expression_ ]
 `Field` _identifier_ `:` _Type_ [ `=` _Expression_ ]
+</div>
+
 ...or...
 ...or...
+
+<div class=syntax>
 `Field` _identifier_ `:=` _Expression_
 `Field` _identifier_ `:=` _Expression_
+</div>
 
 
 For struct fields, _Expression_ must not contain any code that has side effects.
 For struct fields, _Expression_ must not contain any code that has side effects.
 
 
@@ -76,11 +82,11 @@ For struct fields, _Expression_ must not contain any code that has side effects.
 
 
 To declare a method:
 To declare a method:
 
 
-`Method` _Identifier_ [ `:` _ReturnType_ ] `(` _Arguments_ `)` [ _Modifiers_ ]
-```
+<div class=syntax>
+`Method` _Identifier_ [ `<` _GenericTypeIdents_ `>` ] [ `:` _ReturnType_ ] `(` _Arguments_ `)` [ _Modifiers_ ]
 	...Statements...
 	...Statements...
-```
 `End`
 `End`
+</div>
 
 
 _ReturnType_ defaults to `Void` if omitted.
 _ReturnType_ defaults to `Void` if omitted.
 
 
@@ -101,20 +107,65 @@ Methods are 'Final' by default.
 
 
 To declare a read/write property:
 To declare a read/write property:
 
 
+<div class=syntax>
 `Property` _Identifier_ `:` _Type_ `()`
 `Property` _Identifier_ `:` _Type_ `()`
-...getter code...
-`Setter` `(` _Identifier `:` _Type_ `)`
-...setter code...
+	...getter code...
+`Setter` `(` _Identifier_ `:` _Type_ `)`
+	...setter code...
 `End`
 `End`
+</div>
 
 
 To declare a read only property:
 To declare a read only property:
 
 
+<div class=syntax>
 `Property` _Identifier_ `:` _Type_ `()`
 `Property` _Identifier_ `:` _Type_ `()`
-...getter code...
+	...getter code...
 `End`
 `End`
+</div>
 
 
 To declare a write only property:
 To declare a write only property:
 
 
-`property` `(` _Identifier `:` _Type_ `)`
-...setter code...
+<div class=syntax>
+`Property` `(` _Identifier_ `:` _Type_ `)`
+	...setter code...
+`End`
+</div>
+
+#### Conversion Operators
+
+You can also add 'conversion operators' to classes and structs. These allow you to convert from a custom class or struct type to an
+unrelated type, such as another class or struct type, or a primitive type such as String.
+
+The syntax for declaring a conversion operator is:
+
+<div class=syntax>
+`Operator To` [ `<` GenericTypeIdents `>` ] `:` _Type_ `()`
+	...Statements...
 `End`
 `End`
+</div>
+
+Conversion operators cannot be used to convert a class type to a base class type, or from any type to bool.
+
+For example, we can add a string conversion operator to the above Vec2 class like this:
+
+```
+Struct Vec2
+
+	...as above...
+	
+	Operator To:String()
+		Return "Vec2("+x+","+y+")"
+	End
+End
+```
+
+This will allow Vec2 values to be implictly converted to strings where possible, for example:
+
+```
+Local v:=New Vec2
+
+Print v
+```
+
+We no longer need to use '.ToString()' when printing the string. Since Print() takes a string argument, and Vec2 has
+a conversion operator that returns a string, the conversion  operator is automatically called for you.

+ 21 - 4
modules/monkey/docs/language/variables.md

@@ -5,24 +5,41 @@
 
 
 Local variables live on the stack. To declare a local variable:
 Local variables live on the stack. To declare a local variable:
 
 
+<div class=syntax>
 `Local` _identifier_ `:` _Type_ [ `=` _Expression_ ]
 `Local` _identifier_ `:` _Type_ [ `=` _Expression_ ]
+</div>
+
 ...or...
 ...or...
+
+<div class=syntax>
 `Local` _identifier_ `:=` _Expression_
 `Local` _identifier_ `:=` _Expression_
+</div>
 
 
 
 
 #### Global variables
 #### Global variables
 
 
 Global variables live in global memory and exist for the lifetime of the application. To declare a global variable:
 Global variables live in global memory and exist for the lifetime of the application. To declare a global variable:
 
 
-`Global` _identifier_ `:` _Type_ [ `=` _Expression_ ]
+<div class=syntax>
+`Global` _Identifier_ `:` _Type_ [ `=` _Expression_ ]
+</div>
+
 ...or...
 ...or...
-`Global` _identifier_ `:=` _Expression_
 
 
+<div class=syntax>
+`Global` _Identifier_ `:=` _Expression_
+</div>
 
 
 #### Consts
 #### Consts
 
 
 Consts are stored in the same way as globals, but cannot be modified after they are initialized. To declare a const:
 Consts are stored in the same way as globals, but cannot be modified after they are initialized. To declare a const:
 
 
-`Const` _identifier_ `:` _Type_ `=` _Expression_
+<div class=syntax>
+`Const` _Identifier_ `:` _Type_ `=` _Expression_
+</div>
+
 ...or...
 ...or...
-`Const` _identifier_ `:=` _Expression_
+
+<div class=syntax>
+`Const` _Identifier_ `:=` _Expression_
+</div>

+ 6 - 4
modules/monkey/docs/mx2cc.md

@@ -1,15 +1,17 @@
 
 
-@manpage The mx2cc compiler
+# The mx2cc compiler
 
 
 Mx2cc is the command line compiler for monkey2. The actual executable is named differently depending on the OS:
 Mx2cc is the command line compiler for monkey2. The actual executable is named differently depending on the OS:
 
 
-/bin/mx2cc_windows.exe  
-/bin/mx2cc_macos  
-/bin/mx2cc_linux  
+* Windows: /bin/mx2cc_windows.exe  
+* MacOS: /bin/mx2cc_macos  
+* Linux: /bin/mx2cc_linux  
 
 
 The command line options for mx2cc are:
 The command line options for mx2cc are:
 
 
+<div class=syntax>
 `mx2cc` _command_ _options_ _input_
 `mx2cc` _command_ _options_ _input_
+</div>
 
 
 Valid commands are:
 Valid commands are: