Skip to content

Commit 39a9d8b

Browse files
committed
token as bytes
1 parent 694fa2d commit 39a9d8b

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/main.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,13 +1106,13 @@ fn search_dictionary<'a>(dict: &'a Dictionary, name: &Name) -> Option<&'a Dictio
11061106
dict.iter().find(|&item| item.name == *name)
11071107
}
11081108

1109-
fn parse_number(default_base: u32, word: &str) -> Option<Cell> {
1109+
fn parse_number(default_base: u32, word: &[Byte]) -> Option<Cell> {
11101110
if word.is_empty() {
11111111
return None;
11121112
}
11131113

11141114
let mut has_base_indicator = true;
1115-
let base = match word.as_bytes().first()? {
1115+
let base = match word.first()? {
11161116
b'#' => 10,
11171117
b'$' => 16,
11181118
b'%' => 2,
@@ -1124,7 +1124,7 @@ fn parse_number(default_base: u32, word: &str) -> Option<Cell> {
11241124

11251125
let digits = word.split_at(if has_base_indicator { 1 } else { 0 }).1;
11261126

1127-
match Cell::from_str_radix(digits, base) {
1127+
match Cell::from_str_radix(core::str::from_utf8(digits).unwrap(), base) {
11281128
Ok(x) => Some(x),
11291129
Err(e) => match e.kind() {
11301130
std::num::IntErrorKind::PosOverflow | std::num::IntErrorKind::NegOverflow => {
@@ -1278,19 +1278,19 @@ impl<'a> Environment<'a> {
12781278
self.input_buffer[line.len()..].fill(0);
12791279

12801280
'empty_input_buffer: loop {
1281-
let token = self.next_token(USUAL_LEADING_DELIMITERS_TO_IGNORE, b' ');
1281+
let token = self
1282+
.next_token(USUAL_LEADING_DELIMITERS_TO_IGNORE, b' ')
1283+
.to_owned();
12821284

12831285
if token.is_empty() {
12841286
break 'empty_input_buffer;
12851287
}
12861288

1287-
let token = core::str::from_utf8(token).unwrap().to_owned();
1288-
12891289
self.handle_token(&token);
12901290
}
12911291
}
12921292

1293-
fn handle_token(&mut self, token: &str) {
1293+
fn handle_token(&mut self, token: &[Byte]) {
12941294
match parse_number(self.base as u32, token) {
12951295
Some(number) => self.handle_number_token(number),
12961296
_ => self.handle_text_token(token),
@@ -1306,9 +1306,8 @@ impl<'a> Environment<'a> {
13061306
}
13071307
}
13081308

1309-
fn handle_text_token(&mut self, token: &str) {
1310-
let dict_entry =
1311-
search_dictionary(&self.dictionary, &Name::from_ascii(token.as_bytes())).unwrap();
1309+
fn handle_text_token(&mut self, token: &[Byte]) {
1310+
let dict_entry = search_dictionary(&self.dictionary, &Name::from_ascii(token)).unwrap();
13121311

13131312
if self.compile_mode() && !dict_entry.immediate {
13141313
let operation = ForthOperation::CallEntry(dict_entry);

0 commit comments

Comments
 (0)