functionalscript 0.0.563 → 0.0.564
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/doc/byte-code.md +60 -0
- package/package.json +1 -1
package/doc/byte-code.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Byte Code
|
|
2
|
+
|
|
3
|
+
This format is designed for fast and straightforward serialization and doesn't depend on a particular VM implementation.
|
|
4
|
+
|
|
5
|
+
**Requirements:**
|
|
6
|
+
- VM serializer/deserializer should be very simple.
|
|
7
|
+
- string: UTF16
|
|
8
|
+
- number: in a binary format
|
|
9
|
+
- bigint: in a binary format
|
|
10
|
+
- len: u32
|
|
11
|
+
- the byte code doesn't know anything about importing modules or I/O functions.
|
|
12
|
+
- the byte code shouldn't contain syntax sugar.
|
|
13
|
+
- serialized in a byte array so we can save it into a file. One byte is one unit.
|
|
14
|
+
- least-significant byte first.
|
|
15
|
+
|
|
16
|
+
```rust
|
|
17
|
+
struct Array<T> {
|
|
18
|
+
len: u32,
|
|
19
|
+
array: [T; self.len],
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type String = Array<u16>;
|
|
23
|
+
|
|
24
|
+
// LSB first.
|
|
25
|
+
type BigUInt = Array<u64>;
|
|
26
|
+
|
|
27
|
+
type Object = Array<(String, Any)>;
|
|
28
|
+
|
|
29
|
+
// This is the main structure for serialization.
|
|
30
|
+
type Code = Array<u8>;
|
|
31
|
+
|
|
32
|
+
struct Function {
|
|
33
|
+
length: u32
|
|
34
|
+
code: Code
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// This structure is not for serialization because
|
|
38
|
+
// a serialized module should resolve all imports.
|
|
39
|
+
struct Module {
|
|
40
|
+
import: Array<String>
|
|
41
|
+
code: Code
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
|type|any |tag| | |
|
|
46
|
+
|----|--------------|---|-----------------------|-----------------------------|
|
|
47
|
+
|JSON|null | 00| | |
|
|
48
|
+
| |number | 01|u64 | |
|
|
49
|
+
| |false | 02| | |
|
|
50
|
+
| |true | 03| | |
|
|
51
|
+
| |string | 04|String | |
|
|
52
|
+
| |object | 05|Object | |
|
|
53
|
+
| |array | 06|Array<Any> | |
|
|
54
|
+
|DJS |bigint+ | 07|BigUInt | |
|
|
55
|
+
| |bigint- | 08|BigUInt | |
|
|
56
|
+
| |local_ref | 09|u32 |consts[i] |
|
|
57
|
+
|FJS |arg_ref | 0A|u32 |args[i] |
|
|
58
|
+
| |undefined | 0B| | |
|
|
59
|
+
| |function | 0C|Function |the last constant is a return|
|
|
60
|
+
| |... | | | |
|