Update README.md

Dibyendu Majumdar 9 years ago
parent fb917c0d75
commit a6bd75b0b0

@ -32,7 +32,7 @@ I hope to enhance the language to enable static typing of following:
* double
* string
* table
* array (see below)
* array (this will be an optimisation of the array usage of a table)
* bool
* functions and closures
@ -73,8 +73,6 @@ local func_table : array<function> = {
end
}
```
Above the array of functions allows various function types.
When a typed function is called the inputs and return value can be validated. Consider the function below:
```
@ -86,6 +84,10 @@ When this function is called the compiler can validate that `b` is an int and `c
Return statements in typed functions can also be validated.
Mixture of compile time and runtime checks
------------------------------------------
To keep with Lua's dynamic nature I plan a mix of static type checking and runtime type checks. Runtime type checks may be used for example when a function is called or values from a function call are saved into variables. Also on entry into functions the parameters may be subject to runtime checks.
Implementation Strategy
-----------------------
I do not want to introduce any new types to the Lua system as the types I need already exist and I quite like the minimalist nature of Lua. However, to make the execution efficient I want to approach this by adding new type specific opcodes, and by enhancing the Lua parser/code generator to encode these opcodes only when types are known. The new opcodes will execute more efficiently as they will not need to perform type checks. In reality the performance gain may be offset by the increase in the instruction decoding / branching - so it remains to be seen whether this approach is beneficial. However, I am hoping that type specific instructions will lend themselves to more efficient JIT at a later stage.
@ -108,6 +110,29 @@ New OpCodes
-----------
The new instructions are specialised for types, and also for register/versus constant. So for example `OP_RAVI_ADDFIKK` means add `float` and `int` where both values are constants. And `OP_RAVI_ADDFFRR` means add `float` and `float` - both obtained from registers. The existing Lua opcodes that these are based on define which operands are used.
Example:
--------
```
> local i=0; i=i+1
```
Above standard Lua code compiles to:
```
[0] LOADK A=0 Bx=-1
[1] ADD A=0 B=0 C=-2
[2] RETURN A=0 B=1
```
We add type info using Ravi extensions:
```
> local i:int=0; i=i+1
```
Now the code compiles to:
```
[0] LOADK A=0 Bx=-1
[1] ADDIIRK A=0 B=0 C=-2
[2] RETURN A=0 B=1
```
Above uses type specialised opcode `OP_RAVI_ADDIIRK`.
Documentation
-------------
As I progress I will add documentation in the Wiki.

Loading…
Cancel
Save