8000 opslangのバイト列リテラルに対応する by kobkaz · Pull Request #203 · arkedge/gaia · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

opslangのバイト列リテラルに対応する #203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ structpack = "1.0"
gaia-stub = "1.0"
gaia-ccsds-c2a = "1.0"
gaia-tmtc = "1.0"
c2a-devtools-frontend = "1.0"
c2a-devtools-frontend = { path = "devtools-frontend" }
8 changes: 4 additions & 4 deletions devtools-frontend/crates/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 0 additions & 17 deletions devtools-frontend/crates/Cargo.toml

This file was deleted.

4 changes: 2 additions & 2 deletions devtools-frontend/crates/opslang-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ default = ["console_error_panic_hook"]
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3.69", features = ["console"] }
opslang-ast = "0.2.1"
opslang-parser = "0.2.1"
opslang-ast = "0.3.0-alpha.1"
opslang-parser = "0.3.0-alpha.1"
async-recursion = "1.1.0"

# The `console_error_panic_hook` crate provides better debugging of panics by
Expand Down
2 changes: 2 additions & 0 deletions devtools-frontend/crates/opslang-wasm/js/union.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const asInt = asKind("integer");
export const asDouble = asKind("double");
export const asBool = asKind("bool");
export const asArray = asKind("array");
export const asBytes = asKind("bytes");
export const asString = asKind("string");
export const asDuration = asKind("duration");
export const asDateTime = asKind("datetime");
Expand All @@ -29,6 +30,7 @@ export const makeInt = make("integer");
export const makeDouble = make("double");
export const makeBool = make("bool");
export const makeArray = make("array");
export const makeBytes = make("bytes");
export const makeString = make("string");
export const makeDuration = make("duration");
export const makeDateTime = make("datetime");
4 changes: 3 additions & 1 deletion devtools-frontend/crates/opslang-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ impl Runner {
.collect::<Result<_, _>>()
.map(Value::Array),
Numeric(num, s) => self.numeric(num, s),
Bytes(b) => Ok(Value::Bytes(b.clone())),
String(s) => Ok(Value::String((*s).to_owned())),
DateTime(d) => Ok(Value::DateTime(*d)),
TlmId(tlm_id) => {
Expand Down Expand Up @@ -386,7 +387,7 @@ impl Runner {
Double(x) => Ok(Double(-x)),
Bool(x) => Ok(Bool(!x)),
Duration(x) => Ok(Duration(-x)),
Array(_) | String(_) | DateTime(_) => {
Array(_) | String(_) | DateTime(_) | Bytes(_) => {
type_err("numeric, bool, or duration", &v)
}
}
Expand All @@ -401,6 +402,7 @@ impl Runner {
Double(x) => x.partial_cmp(&right.double()?),
Bool(x) => Some(x.cmp(&right.bool()?)),
Array(_) => return type_err("comparable", left),
Bytes(_) => return type_err("comparable", left),
String(x) => Some(x[..].cmp(right.string()?)),
Duration(x) => Some(x.cmp(&right.duration()?)),
DateTime(x) => Some(x.cmp(&right.datetime()?)),
Expand Down
8 changes: 8 additions & 0 deletions devtools-frontend/crates/opslang-wasm/src/union_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type Value =
{kind : "double", value : number} |
{kind : "bool", value : boolean } |
{kind: "array", value : Value[] } |
{kind: "bytes", value : Uint8Array } |
{kind: "string", value: string } |
{kind: "duration", value: bigint } |
{kind: "datetime", value: bigint }
Expand All @@ -24,6 +25,8 @@ extern "C" {
fn as_bool(_: &UnionValue) -> Option<bool>;
#[wasm_bindgen(js_name = "asArray")]
fn as_array(_: &UnionValue) -> Option<Vec<UnionValue>>;
#[wasm_bindgen(js_name = "asBytes")]
fn as_bytes(_: &UnionValue) -> Option<Vec<u8>>;
#[wasm_bindgen(js_name = "asString")]
fn as_string(_: &UnionValue) -> Option<std::string::String>;
#[wasm_bindgen(js_name = "asDuration")]
Expand All @@ -39,6 +42,8 @@ extern "C" {
fn make_bool(_: bool) -> UnionValue;
#[wasm_bindgen(js_name = "makeArray")]
fn make_array(_: Vec<UnionValue>) -> UnionValue;
#[wasm_bindgen(js_name = "makeBytes")]
fn make_bytes(_: Vec<u8>) -> UnionValue;
#[wasm_bindgen(js_name = "makeString")]
fn make_string(_: std::string::String) -> UnionValue;
#[wasm_bindgen(js_name = "makeDuration")]
Expand All @@ -61,6 +66,8 @@ impl From<UnionValue> for Value {
} else if let Some(vs) = as_array(&v) {
let vs = vs.into_iter().map(Into::into).collect();
Array(vs)
} else if let Some(v) = as_bytes(&v) {
Bytes(v)
} else if let Some(v) = as_string(&v) {
String(v)
} else if let Some(v) = as_duration(&v) {
Expand All @@ -83,6 +90,7 @@ impl From<Value> for UnionValue {
let vs = vs.into_iter().map(Into::into).collect();
make_array(vs)
}
Bytes(v) => make_bytes(v),
String(v) => make_string(v),
Duration(v) => make_duration(v.num_milliseconds()),
DateTime(v) => make_datetime(v.timestamp_millis()),
Expand Down
9 changes: 9 additions & 0 deletions devtools-frontend/crates/opslang-wasm/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub(crate) enum Value {
Double(f64),
Bool(bool),
Array(Vec<Value>),
Bytes(Vec<u8>),
String(String),
Duration(chrono::Duration),
DateTime(chrono::DateTime<chrono::Utc>),
Expand Down Expand Up @@ -50,6 +51,7 @@ impl Value {
Double(_) => "double",
Bool(_) => "bool",
Array(_) => "array",
Bytes(_) => "bytes",
String(_) => "string",
Duration(_) => "duration",
DateTime(_) => "datetime",
Expand Down Expand Up @@ -82,6 +84,13 @@ impl Value {
}
}

pub fn bytes(&self) -> Result<&[u8]> {
match self {
Value::Bytes(x) => Ok(x),
_ => type_err("bytes", self),
}
}

pub fn duration(&self) -> Result<chrono::Duration> {
self.cast()
}
Expand Down
1 change: 1 addition & 0 deletions devtools-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@protobuf-ts/grpcweb-transport": "^2.8.2",
"@protobuf-ts/runtime": "^2.9.3",
"@protobuf-ts/runtime-rpc": "^2.9.3",
"c2a-devtools": "link:",
"monaco-editor": "^0.48.0",
"react": "18.3.0",
"react-dom": "18.3.0",
Expand Down
3 changes: 3 additions & 0 deletions devtools-frontend/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion devtools-frontend/src/components/CommandView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class Driver implements opslang.Driver {
executorComponent,
command,
},
parameters: fullParams.map((arg): ParameterValue => {
parameters: fullParams.map((arg: opslang.Value): ParameterValue => {
if (arg.kind === "integer") {
return {
type: "integer",
Expand All @@ -272,6 +272,12 @@ class Driver implements opslang.Driver {
type: "double",
double: arg.value,
};
} else if (arg.kind === "bytes") {
return {
type: "bytes",
bytes: arg.value,
bigint: BigInt(0), // dummy ???
};
} else if (arg.kind === "datetime") {
const datetimeOrigin = this.datetimeOrigin.get(receiverComponent);
if (datetimeOrigin === undefined) {
Expand Down
0