Programming languages
No-code
Rust
Rust basics
Graydon Hoare created Rust as a personal project while working at Mozilla Research in 2006. Mozilla officially sponsored the project in 2009. In December 2022, it became the first language other than C and assembly to be supported in the development of the Linux kernel.
Rust is syntactically similar to C++, but can guarantee memory safety by using a borrow checker to validate references. Rust achieves memory safety without garbage collection, and reference counting is optional.
- Rust - Wikipedia
- Rust - official website sponsored by Mozilla Research, a "safe, concurrent, practical language", supporting functional and imperative-procedural paradigms, syntactically similar to C++, but its designers intend it to provide better memory safety whilst maintaining performance
- Rust book - online or $ rustup docs --book
- Cargo doc
Essentials:
- Compiler is rustc
- Package manager and build system is cargo, which by default uses crates.io
- Executables and libraries are called crates
- Compilation is by cargo build, compile and run by cargo run
-
Rust installation
See LTK.
Rust hello_world.rs
On GrayTiger, create directory /home/marc/Rustprojects, with subdir hello_world. There create a file hello_world.rs with contents
fn main() {
println!("Hello, world!");
}
Observation: println! calls a Rust macro. If it had called a function instead, it would be entered as println (without the !).
Then
- $ rustc -h // to see possible options -v for verbose, -V for version
- $ rustc main.rs
- $ ./main
- Hello, world! // OK
Observation: simple compilation without makefile. More complicated builds use cargo.
Rust hello_cargo.rs
Go to your Rustprojects directory, then
- $ cargo new hello_cargo // creates directory and project hello_cargo
- $ cd hello_cargo
Results in
- Cargo.toml file describing config information for the compiler, such as package and dependencies
- /src directory with a main.rs file - cargo expects sources to be in /src
It also initialised a new Git repository along with a .gitignore file. Git files won’t be generated if you run cargo new within an existing Git repository.
From your hello_cargo directory, build your project by entering $ cargo build. This creates an executable in /target/debug/hello_cargo rather than in the current directory. Because the default build is a debug build, Cargo puts the binary in a directory named debug. To run it: $ ./target/debug/hello_cargo .
If all goes well, Hello, world! should print to the terminal.
Running cargo build for the first time also causes Cargo to create a new file at the top level: Cargo.lock. This file keeps track of dependencies. Cargo manages its contents for you.
We just built a project with cargo build and ran it with ./target/debug/hello_cargo, but we can also use cargo run to compile the code and then run the resultant executable all in one command.
This is more convenient than remembering to run cargo build and then use the whole path to the binary, so most developers use cargo run.
Cargo also provides cargo check which checks code to make sure it compiles but doesn’t produce an executable:
To compile with optimisations. use cargo build --release. The executable goes to target/release instead of target/debug.
Tip: to see how cargo calls rustc, you can do cargo build --verbose, and it will print out each rustc invocation.
To work on any existing projects, the following commands check out the code using Git, change to that project’s directory, and build:
- $ git clone example.org/someproject
- $ cd someproject
- $ cargo build
Regarding cargo and crates:
- Recall that crates.io is the Rust's central package registry and cargo is configured to use it by default.
- Cargo establishes a local registry of crates in /home/marc/.cargo/registry, where you find json info files about each crate
- If you run into dependency problems, it may help to delete the registry folder
Selective Cargo stuff
Selective Rust stuff
TBD
Rust and TEE
For info on TEEs refer to local info. Importance of 'bindgen'.
Fortanix Enclave Development platform
Arm TrustZone, Rust and OP-TEE
- Eric Evenchick's Rustzone (intro) POC for running a Rust Trusted Application (TA) within Arm TrustZone/OP-TEE
- OP-TEE with Rust
- how to build OP-TEE client, and
- trusted applications written in Rust with Teaclave TrustZone SDK, compatible with QEMUv8 (aarch64)
- Apache Teaclave TrustZone SDK
- Runs on platforms such as QEMU for Armv8-A (QEMUv8), see 'Quick start with the OP-TEE Repo for QEMUv8'
- The aarch64 Rust examples are built and installed into OP-TEE's default filesystem for QEMUv8.
- For information on QEMU refer to Architecture and emulation.
- Approach (see LTK): do the Quick start with the OP-TEE Repo for QEMUv8, then initialise the building environment in Teaclave TrustZone SDK, build Rust applications and copy them into the target's filesystem.
Intel SGX and Rust
Go, Erlang
- Go - - often referred to as golang, created at Google in 2009, a compiled, statically typed language in the tradition of Algol and C, with garbage collection, limited structural typing, memory safety features and CSP-style concurrent programming features added
- beego - open source application framework the Go way
- RESTful HTTP framework for the rapid development of Go applications including APIs, web apps and backend services with integrated Go specific features such as interfaces and struct embedding
- Erlang - for massively scalable soft real-time systems with requirements on high availability
Reactive Programming
RP basics
RP is a declarative programming paradigm concerned with data streams and the propagation of change.
With this paradigm it is possible to express static (e.g., arrays) or dynamic (e.g., event emitters) data streams with ease,
and also communicate that an inferred dependency within the associated execution model exists,
which facilitates the automatic propagation of the changed data flow.
DSL
- Rosetta DSL - designed for the financial industry,
which purpose is to consolidate market standards and operational practices into a cohesive domain model
- Rosetta DSL Components
- Syntax. The syntax is used to express the model for the financial industry domain,
which is referred to as a Common Domain Model (CDM). Available here.
Examples from the ISDA CDM are used to illustrate the possible artefacts. Can express five types of modelling artefacts:
- Data Representation (class, attribute, ...),
- Mapping ('synonym'),
- Data Integrity (data rule, choice rule),
- Object Qualification (product qualification, event qualification),
- Function
- Code generators provided by default as Java
- TalkPython courses (cheap but not free)
Python
Python basics
iPython
Ada
Rooted in language design competition sponsored by US DOD, principal design was Jean Ichbiah (then @ Honeywell Bull France)
Ada is a GP language that can be used for real-time, as opposed to a specialised real-time language. Used in avionics, aerospace, atc, steel mill control, trains, communications and nuclear reactor control.
Ada standards:
- ANSI standard in 1983
- ISO standard in 1987, with Ada 9x project started in 1988
- Ada 95 - ISO revision published in 1995 - introducing OOP
- Ada 2005
-