Minore additions to the text

This commit is contained in:
2020-08-29 21:01:21 +03:00
parent df6aa422e9
commit a4b94a467b
2 changed files with 19 additions and 14 deletions

View File

@@ -81,6 +81,7 @@ This is a very basic program written in Onyx:
```text ```text
import "stdio.h" import "stdio.h"
# Outputs "Hello, world!"
export int main() { export int main() {
final msg = "Hello, world!\0" final msg = "Hello, world!\0"
unsafe! $puts(&msg as $char*) unsafe! $puts(&msg as $char*)
@@ -100,6 +101,7 @@ Imported entities are referenced with preceding `$` symbol to distinguish them f
The `final` statement defines a constant named `msg`. The `final` statement defines a constant named `msg`.
The type of `msg` is inferred to be `String<UTF8, 14>`, i.e. a [UTF-8](https://en.wikipedia.org/wiki/UTF-8)-encoded array of [code units](https://en.wikipedia.org/wiki/Code_unit) containing 14 elements. The type of `msg` is inferred to be `String<UTF8, 14>`, i.e. a [UTF-8](https://en.wikipedia.org/wiki/UTF-8)-encoded array of [code units](https://en.wikipedia.org/wiki/Code_unit) containing 14 elements.
Note that this is not a pointer, but a real array, probably allocated on stack.
Then, the address of the `msg` constant is taken. Then, the address of the `msg` constant is taken.
The resulting object of taking an address would be `String<UTF8, 14>*lr0`, which is a shortcut to `Pointer<Type: String<UTF8, 14>, Scope: :local, Readable: true, Writeable: false, Space: 0>`. The resulting object of taking an address would be `String<UTF8, 14>*lr0`, which is a shortcut to `Pointer<Type: String<UTF8, 14>, Scope: :local, Readable: true, Writeable: false, Space: 0>`.
@@ -122,7 +124,7 @@ But in return, it makes the emitted code predictable and portable.
#### Using a standard library #### Using a standard library
An Onyx compiler is not required to implement any sort of OS-specific standard library. An Onyx compiler is not required to implement any sort of OS-dependent standard library.
Instead, the standard library Standard is specified elsewhere (spoiler alert: by [the Onyx Software Foundation](#the-onyx-software-foundation)). Instead, the standard library Standard is specified elsewhere (spoiler alert: by [the Onyx Software Foundation](#the-onyx-software-foundation)).
A standard library ought to be used as a typical package and required like any other from your code. A standard library ought to be used as a typical package and required like any other from your code.
@@ -145,9 +147,10 @@ export void main() {
``` ```
Now, the code is perfectly safe. Now, the code is perfectly safe.
Even passing of `&msg` is allowed, because `Std.puts` has an overload accepting a `String*cr`, i.e. a read-only pointer with _caller_ scope, and a pointer with _local_ scope may be safely cast to _caller_ scope upon passing to a function! Even passing of `&msg` is allowed, because `Std.puts` has an overload accepting a `String*cr`, i.e. a read-only pointer with _caller_ scope, and a pointer with _local_ scope may be safely cast to _caller_ scope upon passing to a function.
This is where the full power of pointer scope harnesses!
Also note that `msg` is now a variable, as it is defined with `let` statement. Also note that `msg` is now a **variable** instead of a constant, as it is defined with `let` statement.
Taking the address of `msg` would return `String<UTF8, 14>*lrw0`. Taking the address of `msg` would return `String<UTF8, 14>*lrw0`.
Notice the `w` part? Notice the `w` part?
The pointer is now writeable. The pointer is now writeable.
@@ -160,7 +163,7 @@ The cause is that an `export`ed function must guarantee never to throw an except
The `Std.exit` function is declared as `nothrow`, so we can leave it as-is. The `Std.exit` function is declared as `nothrow`, so we can leave it as-is.
But what if we wanted to inspect the backtrace of the possible exception? But what if we wanted to inspect the backtrace of the possible exception?
Well, the language Standard states that a backtrace object must implement `Endful<Location>` trait. Well, the language Standard states that a backtrace object must implement the `Endful<Location>` trait.
This is truncated source code of the trait: This is truncated source code of the trait:
```text ```text
@@ -178,7 +181,7 @@ end
Let's implement some `Stack` type to hold the backtrace. Let's implement some `Stack` type to hold the backtrace.
::: spoiler ⚠️ A big chunk of code! ::: spoiler ⚠️ A big chunk of non-trivial code!
```text ```text
# A stack growing upwards in memory. # A stack growing upwards in memory.
@@ -352,7 +355,8 @@ export int main () {
while final loc = backtrace.pop?() while final loc = backtrace.pop?()
Std.cout << "At " << Std.cout << "At " <<
loc.path << ":" << loc.path << ":" <<
loc.row << ":" << "\n" loc.row << ":" <<
loc.col << "\n"
end end
Std.exit(1) Std.exit(1)
@@ -516,7 +520,7 @@ require "gen_class"
@gen_class("user") @gen_class("user")
``` ```
Which would result in: Which would possibly result in:
```text ```text
require "gen_class" require "gen_class"
@@ -535,6 +539,7 @@ end
::: :::
Nuff said.
For example: For example:
```text ```text
@@ -594,12 +599,12 @@ reopen Int&lt;Base: 2, Signed: S, Size: Z> forall S, Z
end end
``` ```
This is a fairly complex example making use of inline assembly feature. This is a fairly complex example making use of the inline assembly feature.
But this is what the language is capable of. But this is what the language is capable of.
Notice that delayed macro blocks, i.e. those beginning with `{{`, are evaluated on every specialization, so the contents of the `add` function would be different for `Int<Base: 2, Signed: true, Size: 16>` (a.k.a. `SBin16`) and `Int<Base: 2, Signed: false, Size: 32>` (a.k.a. `UBin32`). Notice that delayed macro blocks, i.e. those beginning with `{{`, are evaluated on every specialization, so the contents of the `add` function would be different for `Int<Base: 2, Signed: true, Size: 16>` (a.k.a. `SBin16`) and `Int<Base: 2, Signed: false, Size: 32>` (a.k.a. `UBin32`).
There were other features of Onyx mentioned in the example: 1) reopening certain, even broad (the `forall` thing), specializations, 2) and aliasing. There were other features of Onyx mentioned in the example: 1) reopening certain or broad (the `forall` thing), specializations, 2) aliasing.
In fact, this is how integer aliasing looks like in the Core API: In fact, this is how integer aliasing looks like in the Core API:
```text ```text
@@ -801,7 +806,7 @@ Apart from funding packages, the Foundation will sponsor projects and events rel
Onyx is the perfect balance between productivity and performance, a language understandable well both by humans and machines. Onyx is the perfect balance between productivity and performance, a language understandable well both by humans and machines.
Thanks to powerful abstraction mechanisms and inference, the areas of the appliance are truly endless. Thanks to powerful abstraction mechanisms and inference, the areas of the appliance are truly endless.
I heartfully believe that Onyx may be that new lingua franca for decades until humanity learns to transfer thoughts directly into machines. I heartfully believe that Onyx may become a new lingua franca for decades until humanity learns to transfer thoughts directly into machines.
Visit [nxsf.org](https://nxsf.org) to stay updated, and... Visit [nxsf.org](https://nxsf.org) to stay updated, and...

View File

@@ -7,7 +7,7 @@ ogType: article
--- ---
Standardizing and implementing a system programming language is hard, but you can help! Standardizing and implementing a system programming language is hard, but you can help!
Find out how you can sponsor the future, and many hours does it take to create a language mascot, in this post. Find out how you can sponsor the future, and how many hours does it take to create a language mascot, in this post.
<h2>TL; DR;</h2> <h2>TL; DR;</h2>
@@ -32,7 +32,7 @@ By the way, I assume you've read my recent [post on System Programming](/posts/2
## Deeds Already Done ## Deeds Already Done
The onyxlang.com domain name was registered on June 20^th^ 2019. The onyxlang.org domain name was registered on June 20^th^ 2019.
As I have a sin of registering domains as soon as I have a solid idea, the day may be treated as the Onyx birthday. As I have a sin of registering domains as soon as I have a solid idea, the day may be treated as the Onyx birthday.
Today is August 27^th^ 2020, and I've already spent a plethora of time on Onyx. Today is August 27^th^ 2020, and I've already spent a plethora of time on Onyx.
@@ -134,7 +134,7 @@ Nothing is publicly stable, work-in-progress etcetera.
Note that theoretically I could've tried applying to Open Collective right now, but: Note that theoretically I could've tried applying to Open Collective right now, but:
1. It implies free-will donations, but what I'm proposing here is clearly purchase of placement in history; 1. It implies free-will donations, but what I'm proposing here is clearly a purchase;
1. I don't think Onyx is currently "popular" enough; 1. I don't think Onyx is currently "popular" enough;
@@ -149,7 +149,7 @@ And as I haven't got a real job for a long, long time, my financial cushion is r
As a copyright holder, I'm planning on licensing the Onyx Standard Specification and auxiliary standards with a free, open-source license requiring attribution. As a copyright holder, I'm planning on licensing the Onyx Standard Specification and auxiliary standards with a free, open-source license requiring attribution.
Therefore, I can offer you, a potential sponsor, a **perpetual**\* attribution in the standards I'll be working on during the pre-alpha development stage. Therefore, I can offer you, a potential sponsor, a **perpetual**\* attribution in the standards I'll be working on <u>during the pre-alpha development stage</u>.
Your name or company logo with an optional link would be put into according "early contributors" sections of the standards. Your name or company logo with an optional link would be put into according "early contributors" sections of the standards.
\* As long as my attribution is required. \* As long as my attribution is required.