Différences
Ci-dessous, les différences entre deux révisions de la page.
| Prochaine révision | Révision précédente | ||
| en:presentation [2025/08/27 20:02] – créée root | en:presentation [2026/04/03 12:13] (Version actuelle) – root | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| - | ===== W Presentation | + | ===== W Language Description |
| - | W is a new language, | + | The W language |
| + | ==== 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. | ||
| + | Empty lines are considered comments. | ||
| + | <code wlang> | ||
| + | ; First comment | ||
| + | ; Other comment | ||
| + | |||
| + | ; That's it! | ||
| + | |||
| + | </ | ||
| + | ==== Program Structure ==== | ||
| + | The W language supports only ONE instruction per line, except for the comment, which can appear at the end of the line after the instruction. | ||
| + | A program consists of the start instruction, | ||
| + | In each line (= instruction), | ||
| + | Comments can be written anywhere as indicated above. | ||
| + | Each program can call subroutines, | ||
| + | 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 '' | ||
| + | Let's revisit the classic //Hello world// example : | ||
| + | <code wlang hello.w> | ||
| + | ; classic example... | ||
| + | |||
| + | begin hello ; start instruction, | ||
| + | ; processing block | ||
| + | echonl "Hello world!" | ||
| + | ; Here, the process skips to the end (end) | ||
| + | except ; instruction marking the beginning of the exception block | ||
| + | ; exception block | ||
| + | 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 '' | ||
| + | |||
| + | ==== Include and External Calls ==== | ||
| + | The //include// statement allows you to include another source in the current source stream. Recursion is not allowed and will throw an exception. | ||
| + | |||
| + | The source file to be included must be located in the [[w: | ||
| + | <code wlang> | ||
| + | include " | ||
| + | </ | ||
| + | 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: '' | ||
| + | All passages of Parameters are passed by reference: in called subroutines, | ||
| + | |||
| + | ==== 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; | ||
| + | <code wlang> | ||
| + | ; declaration of 3 variables | ||
| + | declare x, y, tmp | ||
| + | </ | ||
| + | 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 = " | ||
| + | |||
| + | ; h will contain 2 variables of type Number, x and y, which are not declared with " | ||
| + | let h.x = 10 | ||
| + | let h.y = 20 | ||
| + | |||
| + | </ | ||
| + | ==== Exceptions ==== | ||
| + | Every program and subroutine must contain an instruction [[w: | ||
| + | |||
| + | Finally, the system variable `[w: | ||
| + | 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/ | ||
| + | |||
| + | The binary format of p-code is big-endian, allowing the same W binary file to be used on any type of operating system and architecture. | ||
| + | |||
| + | Expressions only concern variables of type Dynamic and Number and are managed in a stack using Reverse Polish Notation. | ||
| + | |||
| + | List of instructions in W. | ||
| + | |||
| + | Compilation rules for transforming W source code into p-code (W assembler). | ||