Skip to content

Commit eda9680

Browse files
Update platform files
Update platform files
2 parents 45b6aba + 2182b6a commit eda9680

2 files changed

Lines changed: 59 additions & 12 deletions

File tree

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"colorama",
1717
"colorchoice",
1818
"condv",
19+
"corge",
1920
"ctypes",
2021
"datas",
2122
"endlocal",
@@ -25,7 +26,9 @@
2526
"FOPEN",
2627
"FREAD",
2728
"funcs",
29+
"garply",
2830
"GETATTR",
31+
"grault",
2932
"hibye",
3033
"hiddenimports",
3134
"hooksconfig",
@@ -43,13 +46,15 @@
4346
"modpath",
4447
"mypy",
4548
"noarchive",
49+
"nostd",
4650
"Nuitka",
4751
"omvm",
4852
"onefile",
4953
"pathex",
5054
"peekable",
5155
"pefile",
5256
"pluggy",
57+
"println",
5358
"pycache",
5459
"pygments",
5560
"pyinstaller",

specs/future/platform_files.md

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,39 @@
11
# The Platform File Specification (tentative)
22

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.
46

57
## What are Platform Files
68

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.
810

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.
1012

1113
## Syntax
1214

1315
Here is some self-describing syntax
14-
<a id='syntax-ex'></a>
16+
1517
```omp
1618
@ver 1 # These are explained in the section `Version System`
1719
func foo(1) 13 # A function with one argument, living at index 13 in the builtin pool
1820
func bar(1, 3) # A function with 1 to 3 arguments, auto-incremented to 14
1921
@ver 2
2022
func baz(1, .) 16 # A function with 1 or more arguments at 16
2123
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
2325
run grault 18 # A runtime value (similar to _name), which can perhaps change during runtime, at index 18
2426
attr garply(1) on str # A method for strings with one argument (syntax tentative)
2527
@ver 3
2628
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.
2731
# The macro syntax isn't developed yet
2832
```
2933

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.
3137

3238
The search paths will be the same as modules.
3339

@@ -39,40 +45,76 @@ While the syntax hasn't been decided yet, here is how the versioning of these fi
3945

4046
There will be 3 numbers: a file version, feature versions, and a used version.
4147

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>`.
4349

4450
The whole file will get a number as well, say 2.
4551

4652
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>)`.
4753

4854
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***.
4955

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.
5161

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):
5363

54-
The runtime would recieve this structure (tentative):
5564
``` omc
5665
.platform
5766
<name>.<file_version>.<used_version>
5867
```
5968

6069
A practical example would be:
6170

62-
```
71+
```omc
6372
.platform
6473
prelude.1.4
6574
arduino.3.2
6675
```
76+
6777
(see [the next section](#refactors) for more info on `prelude`)
6878

6979
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)
7080

7181
The compiler will also detect env clashes (ex. `prelude` defines a function at idx `5`, but `arduino` also does the same)
7282

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+
73115
## Refactors
74116

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.
76118

77119
In order to disable the `prelude.omp` file, you will add `@nostd` to your script.
78120

0 commit comments

Comments
 (0)