You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: specs/future/platform_files.md
+54-12Lines changed: 54 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,33 +1,39 @@
1
1
# The Platform File Specification (tentative)
2
2
3
-
This document describes how **platform files** will work in a future version of OmniScript (v0.2.0 or v0.3.0)
3
+
This document describes how **platform files** will work in a future version of OmniScript (v0.2.0 or v0.3.0).
4
+
5
+
This is the second revision of this document.
4
6
5
7
## What are Platform Files
6
8
7
-
Platfom Files will be a way to port OmniScript to a new runtime. They will describe where functions and runtime values will live, describe macros that can output completely custom bytecode, and also requirements.
9
+
Platform Files will be a way to port OmniScript to a new runtime. They will describe where functions and runtime values will live, describe macros that can output completely custom bytecode, and also requirements.
8
10
9
-
In other words, Platform Files are basically a blueprint for the compiler.
11
+
In other words, Platform Files are basically a blueprint for the compiler, or a machine-readable spec.
10
12
11
13
## Syntax
12
14
13
15
Here is some self-describing syntax
14
-
<aid='syntax-ex'></a>
16
+
15
17
```omp
16
18
@ver 1 # These are explained in the section `Version System`
17
19
func foo(1) 13 # A function with one argument, living at index 13 in the builtin pool
18
20
func bar(1, 3) # A function with 1 to 3 arguments, auto-incremented to 14
19
21
@ver 2
20
22
func baz(1, .) 16 # A function with 1 or more arguments at 16
21
23
func qux(., 5) # A function with up to 5 arguments
22
-
func quux(1) requires corge # A function which requires grault to work
24
+
func quux(1) requires corge # A function which requires corge to work
23
25
run grault 18 # A runtime value (similar to _name), which can perhaps change during runtime, at index 18
24
26
attr garply(1) on str # A method for strings with one argument (syntax tentative)
25
27
@ver 3
26
28
attr waldo on str # An attribute for strings (syntax tentative)
29
+
30
+
const TEST = 'any_type' # These get ignored by the version system, as it just replaces these with the actual value.
27
31
# The macro syntax isn't developed yet
28
32
```
29
33
30
-
These rules will be stored in `.omp` files, and imported through `@platform <name>`. Note that these files have no implementation, just definitons.
34
+
These rules will be stored in `.omp` files, and imported through `@platform <name>`. Note that these files have no implementation, just definitions.
35
+
36
+
These can also be imported using a standard import, like `import std::random`, so that you can have FFI libraries that are just defined via platform files. They would be used as regular modules.
31
37
32
38
The search paths will be the same as modules.
33
39
@@ -39,40 +45,76 @@ While the syntax hasn't been decided yet, here is how the versioning of these fi
39
45
40
46
There will be 3 numbers: a file version, feature versions, and a used version.
41
47
42
-
A set of symbols will get a feature version. For instance, lets say that in the example[here](#syntax-ex), the first 2 functions (`foo` and `bar`) will get a feature version of 1, the next 2 get 2, and so on. Note that the version and blocks will get decorated with a syntax similar to `@ver <num>`.
48
+
A set of symbols will get a feature version. For instance, lets say that in [this example](#syntax), the first 2 functions (`foo` and `bar`) will get a feature version of 1, the next 2 get 2, and so on. Note that the version and blocks will get decorated with a syntax similar to `@ver <num>`.
43
49
44
50
The whole file will get a number as well, say 2.
45
51
46
52
The compiler will parse the platform file, and see which items have been used. For instance, let's say we only used `foo` and `bar`. Since those have a number of `1`, the compiler will output a used version of `1`. On the other hand, if we also use `baz`, the compiler will output a used version of `2`, which will be found out with `max(<used versions>)`.
47
53
48
54
When someone adds an item to the platform file, all what will happen is that they will decorate that new item with an ***incremented feature version***.
49
55
50
-
When someone __removes__ an item, the whole platform file's version will get incremented.
56
+
When someone **removes** an item, the whole platform file's version will get incremented.
57
+
58
+
When someone **updates** an item with a different backend implementation, that specific item will get a new feature version that is 1 greater than the highest version.
59
+
60
+
The runtime will receive the file version and used version. It will check if the file version is **equal to** it's stored supported version, and will check if the used version is **less than or equal to** it's stored version.
51
61
52
-
The runtime will recieve the file version and used version. It will check if the file version is **equal to** it's stored supported version, and will check if the used version is **less than or equal to** it's stored version.
62
+
The runtime would receive this structure (tentative):
53
63
54
-
The runtime would recieve this structure (tentative):
55
64
```omc
56
65
.platform
57
66
<name>.<file_version>.<used_version>
58
67
```
59
68
60
69
A practical example would be:
61
70
62
-
```
71
+
```omc
63
72
.platform
64
73
prelude.1.4
65
74
arduino.3.2
66
75
```
76
+
67
77
(see [the next section](#refactors) for more info on `prelude`)
68
78
69
79
If the runtime sees a platform or a version number it doesn't support, it will crash in a very similar fashion to how unsupported requirements crash. The VM will also emit an error code of `13` (CompatibilityError)
70
80
71
81
The compiler will also detect env clashes (ex. `prelude` defines a function at idx `5`, but `arduino` also does the same)
72
82
83
+
## Importing Platform Files
84
+
85
+
Platform files can be used in 2 ways:
86
+
87
+
### `@platform`
88
+
89
+
This method allows one to use items directly.
90
+
91
+
```omniscript
92
+
@platform arduino
93
+
94
+
pin_mode(13, HIGH)
95
+
```
96
+
97
+
If you use 2 platform files that have a symbol with the same name, the compiler will throw a warning. If you try using one of those, the compiler will error out.
98
+
99
+
### `import`
100
+
101
+
This method allows one to use a symbol as if it is in a library.
102
+
103
+
This method will be used for certain libraries that should be implemented in a native language.
104
+
105
+
If a library can be implemented in OmniScript, but could also seek performance gains in native code, there would be 2 suffixes:
106
+
107
+
-`_uni`: Implemented in OmniScript. Hence, it is *uni*versal, working on (almost) all runtimes, provided they support any requirements used by it.
108
+
-`_native`: Implemented in the runtime's language, so it would only work on platforms that adhere to that platform file.
109
+
110
+
```omniscript
111
+
import std::json_native
112
+
json_native::load("{'foo': 'bar'}")
113
+
```
114
+
73
115
## Refactors
74
116
75
-
There really is going to be one refactor, and it's for the good, which is replacing the hardcoded indexes for the prelude (`print()` (to be renamed `println()`), `input()`, etc.) to a platform file.
117
+
There really is going to be one refactor, and it's for the good, which is replacing the hardcoded indexes for the prelude (`println()`, `input()`, etc.) to a platform file.
76
118
77
119
In order to disable the `prelude.omp` file, you will add `@nostd` to your script.
0 commit comments