天天看點

【Rust日報】 2020-01-06 tomaka / redshirt:在0環中運作的WASM二進制的作業系統原型

tomaka / redshirt:在0環中運作的WASM二進制的作業系統原型

redshirt作業系統是建立某種形式與作業系統類似環境的實驗,其中的可執行檔案都在WASM并從類似IPFS的去中心化網絡被加載。

此存儲庫中有兩種二進制檔案:

  • “托管核心”是執行WASM程式并使用主機作業系統的正常二進制檔案。
  • 獨立式核心是相容multiboot2的核心,可以與GRUB2或任何相容的引導程式一起加載。

對于托管核心:

# You need the WASI target installed:
rustup target add wasm32-wasi

# Then:
cargo run
           

複制

對于獨立核心:

rustup target add wasm32-wasi

# From the root directory of this repository (where the `arm-freestanding.json` file is located):
RUST_TARGET_PATH=`pwd` cargo +nightly build -Z build-std=core,alloc --target arm-freestanding --package redshirt-standalone-kernel

# You now have a `target/arm-freestanding/debug/redshirt-standalone-kernel`.
# It can be loaded directly by QEMU:
qemu-system-arm -M raspi2 -m 2048 -serial stdio -kernel ./target/arm-freestanding/debug/redshirt-standalone-kernel
           

複制

支援x86_64的獨立核心:

RUST_TARGET_PATH=`pwd` cargo +nightly build -Z build-std=core,alloc --target x86_64-multiboot2 --package redshirt-standalone-kernel
           

複制

前往GitHub了解更多。

Rust官方釋出:任務螢幕擴充task_scope

task_scope crates是一個運作時用于向現有運作時添加對結構化并發的支援的擴充。

什麼是結構化并發?

結構化并發是一種程式設計範例,它允許異步操作僅在特定範圍内運作,以便它們像正常函數調用堆棧一樣形成操作堆棧。當父操作等待所有子代完成時,結構化并發有助于并發程式的本地引導。

可撤回點

task_scope

要求任務定期通過一個可撤回點才能有效地工作。

use tokio::io::*;

let mut read = repeat(42); // very fast input
let mut write = sink(); // very fast output

copy(&mut read, &mut write).await.unwrap();
           

複制

實際上,該程式回進入無限循環,因為

read

并且

write

永遠不會終止。更糟糕的是,程式無法從外部關閉,因為I / O操作始終會成功,并且

copy

功能會嘗試盡可能繼續。是以,産生的任務必須協同檢查取消或定期循環執行以保持結構良好。

task_scope

提供便利功能

cancelable

以自動處理取消。它封裝給特定的

Future

/

AsyncRead

/

AsyncWrite

并在進行内部計算之前檢查取消。

use futures::pin_mut;
use tokio::io::*;

use task_scope::cancelable;

let read = cancelable(repeat(42)); // very fast, but cancelable input
pin_mut!(read); // needed for Unpin bound of copy
let mut write = sink(); // very fast output

// this will terminate with an error on cancellation
copy(&mut read, &mut write).await.unwrap();
           

複制

如果這個取消邏輯比較複雜,則可以使用

Cancellation

手動輪詢以檢查取消信号。

詳細資訊前往Rust官方部落格浏覽

新版本sysinfo(OSX性能改進)

sysinfo用于建立系統資訊(支援Linux,Windows,OSX,Android和raspberry pi)。

此版本是性能改進系列的最後一個版本,專注于OSX。

關于sysinfo前往GitHub了解更多。

前往https://blog.guillaume-gomez.fr/articles/2020-01-06+New+sysinfo+release+(OSX+performance+improvements) 檢視更新日志。

restq-一種适用于rest api的緊湊型查詢語言

/person?age=lt.42&(student=eq.true|gender=eq.'M')&group_by=sum(age),grade,gender&having=min(age)=gt.42&order_by=age.desc,height.asc&page=20&page_size=100
           

複制

大緻轉換成sql即為:

SELECT * FROM person
WHERE age < 42
    AND (student = true OR gender = 'M')
GROUP BY sum(age), grade, gender
HAVING min(age) > 42
ORDER BY age DESC, height ASC
LIMIT 100 OFFSET 1900 ROWS
           

複制

RestQ的語句/文法

create  = table, column_def_list, "\n", csv

select = table, [join_table], column_list, [ "?", condition]

delete = table, [ "?", condition ]

update = table, set_expr_list, [ "?", condition]

drop = "-", table

alter = table, { drop_column | add_column | alter_column }

drop_column = "-", column

add_column = "+", column_def

alter_column = column, "=", column_def


column_def_list =  "{", { column_def }, "}"
        | "(", { column_def }, ")"

column_def = [ { column_attributes } ], column, [ "(" foreign ")" ], ":", data_type, [ "(" default_value ")" ]

column_attributes = primary | index | unique

primary = "*"

index = "@"

unique = "&"

data_type = "bool" | "s8" | "s16" | "s32" | "s64" | "u8" | "u16", etc

default_value  = value

value = number | string | bool ,..etc

column = string, ".", string
        | string

table = string

foreign = table

insert = table, column_list ,"\n", csv

column_list = "{", { column }, "}"
        | "(", { column }, ")"


join_table = table, join_type, table

join_type = right_join | left_join | inner_join | full_join

right_join = "->" | "-^"

left_join = "<-"  | "^-"

inner_join = "-><-" | "-^^-"

full_join = "<-->"  | "^--^"

condition = expr

expr =  column | value | binary_operation

binary_operation = expr, operator, expr

operator = "and" | "or" | "eq" | "gte" | "lte" ,..etc
           

複制

更多詳細功能與用法前往GitHub檢視