Skip to content

Commit 7cbd7e4

Browse files
committed
pd-vm: stdlib: add a lrucache and update collections module
1 parent fe548d4 commit 7cbd7e4

8 files changed

Lines changed: 592 additions & 37 deletions

File tree

.github/workflows/release.selfhosted.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- name: Build wasm linter and bundle for WebUI
3737
shell: bash
3838
run: |
39-
cargo build -p pd-vm-lint-wasm --target wasm32-unknown-unknown --release --locked
39+
cargo build -p pd-vm-wasm --target wasm32-unknown-unknown --release --locked
4040
mkdir -p pd-controller/webui/public/wasm
4141
cp target/wasm32-unknown-unknown/release/pd_vm_lint_wasm.wasm pd-controller/webui/public/wasm/pd_vm_lint_wasm.wasm
4242
@@ -47,7 +47,7 @@ jobs:
4747
bun install --frozen-lockfile
4848
bun run tsc --noEmit
4949
bun run vite build
50-
test -f dist/wasm/pd_vm_lint_wasm.wasm
50+
test -f dist/wasm/pd_vm_wasm.wasm
5151
5252
- name: Compute git build metadata
5353
shell: bash

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ jobs:
3636
- name: Build wasm linter and bundle for WebUI
3737
shell: bash
3838
run: |
39-
cargo build -p pd-vm-lint-wasm --target wasm32-unknown-unknown --release --locked
39+
cargo build -p pd-vm-wasm --target wasm32-unknown-unknown --release --locked
4040
mkdir -p pd-controller/webui/public/wasm
41-
cp target/wasm32-unknown-unknown/release/pd_vm_lint_wasm.wasm pd-controller/webui/public/wasm/pd_vm_lint_wasm.wasm
41+
cp target/wasm32-unknown-unknown/release/pd_vm_wasm.wasm pd-controller/webui/public/wasm/pd_vm_wasm.wasm
4242
4343
- name: Build WebUI assets
4444
shell: bash

pd-vm/examples/example_complex.rss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ let matched = match profile?.stats?.score {
4343
_ => 0,
4444
};
4545

46+
let a=[1, "a"];
47+
let b=a[1];
48+
49+
4650
let regex_ok = re::match("(?i)^rustscript$", "RUSTSCRIPT");
4751
let payload = {
4852
lang: "rustscript",

pd-vm/stdlib/rss/collections.rss

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
// Collection helpers implemented in pure RustScript.
22

3-
fn map_has_key(map, key) {
4-
let keys = (&map).keys;
5-
let mut found = false;
6-
for (let mut key_index = 0; key_index < (&keys).length; key_index = key_index + 1) {
7-
if (&keys)[key_index] == key {
8-
found = true;
9-
break;
10-
}
11-
}
12-
found;
13-
}
14-
153
pub fn append(lhs, rhs) {
164
lhs + rhs;
175
}
@@ -55,7 +43,7 @@ pub fn dedup(values) {
5543
}
5644

5745
pub fn has(map, key) {
58-
map_has_key(map, key);
46+
map.has(key)
5947
}
6048

6149
pub fn get_or(map, key, fallback) {
@@ -111,8 +99,8 @@ pub fn deep_compare(lhs, rhs) {
11199

112100
while (&left_pending).length > 0 {
113101
let next_index = (&left_pending).length - 1;
114-
let left = (&left_pending)[next_index].copy();
115-
let right = (&right_pending)[next_index].copy();
102+
let left = (&left_pending)[next_index];
103+
let right = (&right_pending)[next_index];
116104
left_pending = left_pending[0:next_index];
117105
right_pending = right_pending[0:next_index];
118106
let lhs_type = type(left);
@@ -130,35 +118,25 @@ pub fn deep_compare(lhs, rhs) {
130118
}
131119
let mut index = (&left).length - 1;
132120
while index > -1 {
133-
left_pending[left_pending.length] = (&left)[index].copy();
134-
right_pending[right_pending.length] = (&right)[index].copy();
121+
left_pending[left_pending.length] = (&left)[index];
122+
right_pending[right_pending.length] = (&right)[index];
135123
index = index - 1;
136124
}
137125
} else if lhs_type == "map" {
138126
let lhs_keys = (&left).keys;
139-
let rhs_keys = (&right).keys;
140-
if (&lhs_keys).length != (&rhs_keys).length {
127+
if (&lhs_keys).length != (&((&right).keys)).length {
141128
out = false;
142129
break;
143130
}
144131
let mut index = (&lhs_keys).length - 1;
145132
while index > -1 {
146133
let key = (&lhs_keys)[index];
147-
let mut key_found = false;
148-
let mut rhs_index = (&rhs_keys).length - 1;
149-
while rhs_index > -1 {
150-
if (&rhs_keys)[rhs_index] == key {
151-
key_found = true;
152-
break;
153-
}
154-
rhs_index = rhs_index - 1;
155-
}
156-
if key_found == false {
134+
if (&right).has(key) == false {
157135
out = false;
158136
break;
159137
}
160-
left_pending[left_pending.length] = (&left)[key].copy();
161-
right_pending[right_pending.length] = (&right)[key].copy();
138+
left_pending[left_pending.length] = (&left)[key];
139+
right_pending[right_pending.length] = (&right)[key];
162140
index = index - 1;
163141
}
164142
if out == false {

0 commit comments

Comments
 (0)