Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
| en:presentation [2025/12/24 16:32] – root | en:presentation [2026/04/03 12:13] (Version actuelle) – root | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| ===== W Language Description ===== | ===== W Language Description ===== | ||
| - | The W language is a procedural, loosely typed language with flexible and powerful data structures. | + | The W language is a procedural language, with dynamic typing and with flexible and powerful data structures. |
| ==== Comments ==== | ==== Comments ==== | ||
| Comments are written after the semicolon (;). They can appear either alone on a line or at the end of a line after an instruction. | Comments are written after the semicolon (;). They can appear either alone on a line or at the end of a line after an instruction. | ||
| Empty lines are considered comments. | Empty lines are considered comments. | ||
| - | + | < | |
| - | < | + | |
| ; First comment | ; First comment | ||
| - | + | ; Other comment | |
| - | ; Other comment | + | |
| ; That's it! | ; That's it! | ||
| Ligne 20: | Ligne 18: | ||
| Each program can call subroutines, | Each program can call subroutines, | ||
| The language' | The language' | ||
| - | During execution, any exception automatically causes a jump to the beginning of the exception block of the current program or subroutine. This is the equivalent of a systematic | + | During execution, any exception automatically causes a jump to the beginning of the exception block of the current program or subroutine. This is the equivalent of a systematic |
| - | Let's revisit the classic //Hello world// example: | + | Let's revisit the classic //Hello world// example : |
| - | < | + | < |
| ; classic example... | ; classic example... | ||
| begin hello ; start instruction, | begin hello ; start instruction, | ||
| - | + | | |
| - | ; processing block | + | echonl "Hello world!" |
| - | + | ; Here, the process skips to the end (end) | |
| - | echonl "Hello world!" | + | |
| - | + | ||
| - | ; Here, the process skips to the end (end) | + | |
| except ; instruction marking the beginning of the exception block | except ; instruction marking the beginning of the exception block | ||
| - | + | | |
| - | ; exception block | + | |
| end ; end of the hello program | end ; end of the hello program | ||
| - | + | </ | |
| - | At runtime, the process starts at the beginning instruction of the main block, then executes all instructions up to the //except// instruction. At that point, the process goes directly to the end instruction and then terminates. The second possible start instruction is ' | + | At runtime, the process starts at the beginning instruction of the main block, then executes all instructions up to the //except// instruction. At that point, the process goes directly to the end instruction and then terminates. The second possible start instruction is '' |
| ==== Include and External Calls ==== | ==== Include and External Calls ==== | ||
| Ligne 43: | Ligne 37: | ||
| The source file to be included must be located in the [[w: | The source file to be included must be located in the [[w: | ||
| - | + | < | |
| - | < | + | |
| include " | include " | ||
| + | </ | ||
| Library and method calls are made using the //do// //call// //invoke// instructions: | Library and method calls are made using the //do// //call// //invoke// instructions: | ||
| - | + | | |
| - | * Library call, external to the current source code: '' | + | * Module call, plugin type: '' |
| - | + | * Object sub/method call: '' | |
| - | * Module call, plugin type: '' | + | |
| - | + | ||
| - | * Object sub/method call: '' | + | |
| All passages of Parameters are passed by reference: in called subroutines, | All passages of Parameters are passed by reference: in called subroutines, | ||
| ==== Data Types ==== | ==== Data Types ==== | ||
| Variables must be declared, but without a type, and can be declared anywhere in the code. They only become usable after their declaration; | Variables must be declared, but without a type, and can be declared anywhere in the code. They only become usable after their declaration; | ||
| - | + | < | |
| - | < | + | |
| ; declaration of 3 variables | ; declaration of 3 variables | ||
| declare x, y, tmp | declare x, y, tmp | ||
| + | </ | ||
| The typing of each variable is done when it is assigned. There are 7 usable types: | The typing of each variable is done when it is assigned. There are 7 usable types: | ||
| + | * Null: a declared but unused variable | ||
| + | * Number: a fixed-point number with 13 digits before the decimal point and 5 decimal places | ||
| + | * Dynamic: stores structured strings or any binary content | ||
| + | * Hashtable: a key/value map, where each value is itself another variable from among the available types, including Hashtable | ||
| + | * Subroutine: stores the address of a subroutine | ||
| + | * Object: identical to Hashtable and allows storing/ | ||
| + | * Param: Since parameters passed to subroutines are all by reference, each parameter is of this type, pointing to the actual variable: each action on the parameter will actually act on the variable passed as a parameter. | ||
| + | |||
| + | An 8th type, Buffer, is used only internally by the W executor (for managing the expression and call stack). | ||
| + | |||
| + | === Scope === | ||
| + | Variables declared in the main block (begin/ | ||
| + | Variables declared in libraries and subroutines have local scope to the subroutine. | ||
| + | Subroutines, | ||
| + | Variables belonging to a hashtable are only accessible via the hashtable, except for classes and objects stored globally. | ||
| + | |||
| + | === Usage === | ||
| + | Variables are assigned using the //let// statement. It is possible to // | ||
| + | <code wlang> | ||
| + | declare h, n, d | ||
| + | |||
| + | let h = {} ; h is a Hashtable | ||
| + | let n = -12.34 ; n is a Number | ||
| + | let d = " | ||
| - | * Null: a declared | + | ; h will contain 2 variables of type Number, x and y, which are not declared |
| + | let h.x = 10 | ||
| + | let h.y = 20 | ||
| + | |||
| + | </ | ||
| + | ==== Exceptions ==== | ||
| + | Every program and subroutine must contain an instruction [[w: | ||
| + | |||
| + | Finally, the system | ||
| + | At any time, the `[w: | ||
| + | |||
| + | Example | ||
| + | <code wlang> | ||
| + | begin test | ||
| + | declare x | ||
| + | let x = 10 | ||
| + | let y = 20 ; => raises an EX_NOVAR exception (undeclared variable " | ||
| + | echo "Not displayed"; | ||
| + | except | ||
| + | catch; => exits the program without error | ||
| + | echo " | ||
| + | end | ||
| + | </ | ||
| + | ===== List of instructions ===== | ||
| + | In alphabetical order | ||
| + | ===== Internal operation ===== | ||
| + | The W source code is compiled into // | ||
| + | This p-code is a series of elementary instructions specific to the W language.\\ | ||
| + | It is the same program that analyzes the W source code and breaks it down into p-code instructions: | ||
| + | * in interpreted mode, the instructions are then executed directly | ||
| + | * in compiled mode, the instructions are written to the output assembler file. Finally, this assembler file is converted into binary, a digital translation of the p-code instructions. | ||
| + | The p-code executor can also be called from another process, with p-code serving as a plugin-type language/ | ||
| - | * Number: a fixed-point number with 13 digits before | + | The binary format of p-code is big-endian, allowing |
| - | * Dynamic: stores structured strings or any binary content | + | Expressions only concern variables of type Dynamic |
| - | * Hashtable: | + | |
| - | * Subroutine: stores the address | + | List of instructions in W. |
| - | * Object: identical to Hashtable and allows storing/ | + | Compilation rules for transforming W source code into p-code (W assembler). |