Skip to content

Commit 83151bf

Browse files
committed
Escape HTML correctly
1 parent 6aa74cf commit 83151bf

File tree

9 files changed

+55
-72
lines changed

9 files changed

+55
-72
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
with:
1818
components: clippy
1919
profile: minimal
20-
toolchain: 1.78.0
20+
toolchain: 1.85.0
2121
- name: Install Rust (nightly)
2222
uses: actions-rs/toolchain@v1
2323
with:

Cargo.lock

+15-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ authors = [
55
]
66
categories = ["development-tools"]
77
description = "A compiler, VM, language server, and online playground for the Lox programming language"
8-
edition = "2021"
8+
edition = "2024"
99
keywords = [
1010
"cli",
1111
"compiler",
@@ -24,7 +24,7 @@ keywords = [
2424
license = "MIT"
2525
name = "loxcraft"
2626
repository = "https://github.com/ajeetdsouza/loxcraft"
27-
rust-version = "1.70.0"
27+
rust-version = "1.85.0"
2828
version = "0.1.1"
2929

3030
[badges]
@@ -75,7 +75,7 @@ warp-embed = { version = "0.5.0", optional = true }
7575
webbrowser = { version = "1.0.2", optional = true }
7676

7777
[target.'cfg(target_family = "wasm")'.dependencies]
78-
wasm-bindgen = "0.2.67"
78+
wasm-bindgen = "0.2.100"
7979

8080
[target.'cfg(not(any(miri, target_family = "wasm")))'.dependencies]
8181
mimalloc = { version = "0.1.27", default-features = false }

playground/rust/lox-wasm/Cargo.lock

+20-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

playground/rust/lox-wasm/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "lox-wasm"
33
version = "0.1.0"
4-
edition = "2021"
4+
edition = "2024"
55

66
[lib]
77
crate-type = ["cdylib"]

playground/rust/lox-wasm/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ use wasm_bindgen::prelude::*;
1010
#[wasm_bindgen]
1111
#[allow(non_snake_case)]
1212
pub fn loxRun(source: &str) {
13-
let output = &mut Output::new();
14-
match VM::default().run(source, output) {
13+
let writer = Output::new();
14+
let mut writer = HtmlWriter::new(writer);
15+
match VM::default().run(source, &mut writer) {
1516
Ok(()) => postMessage(&Message::ExitSuccess.to_string()),
1617
Err(errors) => {
17-
let mut writer = HtmlWriter::new(output);
1818
for e in errors.iter() {
1919
report_error(&mut writer, source, e);
2020
}

src/vm/allocator.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,21 @@ impl<T> Allocator<T> {
2828
unsafe impl<T: GlobalAlloc> GlobalAlloc for Allocator<T> {
2929
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
3030
self.allocated_bytes.fetch_add(layout.size(), Ordering::Relaxed);
31-
self.inner.alloc(layout)
31+
unsafe { self.inner.alloc(layout) }
3232
}
3333

3434
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
3535
self.allocated_bytes.fetch_sub(layout.size(), Ordering::Relaxed);
36-
self.inner.dealloc(ptr, layout)
36+
unsafe { self.inner.dealloc(ptr, layout) }
3737
}
3838

3939
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
4040
self.allocated_bytes.fetch_add(layout.size(), Ordering::Relaxed);
41-
self.inner.alloc_zeroed(layout)
41+
unsafe { self.inner.alloc_zeroed(layout) }
4242
}
4343

4444
unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
4545
self.allocated_bytes.fetch_add(new_size.wrapping_sub(layout.size()), Ordering::Relaxed);
46-
self.inner.realloc(ptr, layout, new_size)
46+
unsafe { self.inner.realloc(ptr, layout, new_size) }
4747
}
4848
}

src/vm/util.rs

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub fn now() -> f64 {
2323
.as_secs_f64()
2424
}
2525

26+
#[inline(always)]
2627
pub const fn unreachable() -> ! {
2728
if cfg!(debug_assertions) { unreachable!() } else { unsafe { hint::unreachable_unchecked() } }
2829
}

src/vm/value.rs

+7-32
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,13 @@ impl Debug for Value {
2424

2525
impl Display for Value {
2626
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
27-
if self.is_nil() {
28-
write!(f, "nil")
29-
} else if self.is_true() {
30-
write!(f, "true")
31-
} else if self.is_false() {
32-
write!(f, "false")
33-
} else if self.is_number() {
34-
write!(f, "{}", self.as_number())
35-
} else if self.is_object() {
36-
write!(f, "{}", self.as_object())
37-
} else {
38-
util::unreachable()
27+
match *self {
28+
Self::NIL => write!(f, "nil"),
29+
Self::TRUE => write!(f, "true"),
30+
Self::FALSE => write!(f, "false"),
31+
_ if self.is_number() => write!(f, "{}", self.as_number()),
32+
_ if self.is_object() => write!(f, "{}", self.as_object()),
33+
_ => util::unreachable(),
3934
}
4035
}
4136
}
@@ -104,20 +99,6 @@ impl Value {
10499
self.0 & (Self::QNAN | Self::SIGN_BIT) == (Self::QNAN | Self::SIGN_BIT)
105100
}
106101

107-
pub fn is_false(self) -> bool {
108-
Self(self.0) == Self::FALSE
109-
}
110-
111-
pub fn is_true(self) -> bool {
112-
Self(self.0) == Self::TRUE
113-
}
114-
115-
/// # Safety
116-
/// This is undefined behavior if the [`Value`] is not of type [`ValueType::Bool`].
117-
pub fn as_bool(self) -> bool {
118-
self == Self::TRUE
119-
}
120-
121102
/// # Safety
122103
/// This is undefined behavior if the [`Value`] is not of type [`ValueType::Number`].
123104
pub fn as_number(self) -> f64 {
@@ -169,12 +150,6 @@ mod tests {
169150

170151
#[test]
171152
fn convert_to_and_from_values() {
172-
let value = false;
173-
assert_eq!(Value::from(value).as_bool(), value);
174-
175-
let value = true;
176-
assert_eq!(Value::from(value).as_bool(), value);
177-
178153
let value = 0.0;
179154
assert_eq!(Value::from(value).as_number(), value);
180155

0 commit comments

Comments
 (0)