Skip to content

Commit

Permalink
switch more things to Text
Browse files Browse the repository at this point in the history
  • Loading branch information
dragazo committed Oct 13, 2024
1 parent 05e4c2f commit 09f724f
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl BasicType {
enum InternalInstruction<'a> {
/// Triggers an error when encountered.
/// This is an internal value that is only used to denote incomplete linking results for better testing.
/// Properly-linked byte code should not contain this value.
/// Successfully-linked byte code cannot contain this value.
Illegal,
/// A valid instruction that will be present in the resulting binary.
Valid(Instruction<'a>),
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ fn main() {
};

let mut opts = OpenOptions::new();
match mode.as_ref() {
match mode.as_str() {
"r" => { opts.read(true); }
"w" => { opts.write(true).create(true).truncate(true); }
"a" => { opts.write(true).create(true).append(true); }
Expand All @@ -132,15 +132,15 @@ fn main() {
}
}

let file = match opts.open(path.as_ref()) {
let file = match opts.open(path.as_str()) {
Ok(x) => x,
Err(e) => {
key.complete(Err(format_compact!("syscall open - file open error: {e:?}")));
return RequestStatus::Handled;
}
};

let res = match mode.as_ref() {
let res = match mode.as_str() {
"r" => NativeValue::InputFile { handle: RefCell::new(Some(BufReader::new(file))) },
"w" | "a" => NativeValue::OutputFile { handle: RefCell::new(Some(BufWriter::new(file))) },
_ => unreachable!(),
Expand Down
10 changes: 5 additions & 5 deletions src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub struct ErrorSummary {
impl ErrorSummary {
pub fn extract<C: CustomTypes<S>, S: System<C>>(error: &ExecError<C, S>, process: &Process<C, S>, locations: &Locations) -> Self {
let raw_entity = process.call_stack.last().unwrap().entity;
let entity = raw_entity.borrow().name.as_ref().clone();
let entity = raw_entity.borrow().name.as_str().into();
let cause = format_compact!("{:?}", error.cause);

fn summarize_symbols<C: CustomTypes<S>, S: System<C>>(symbols: &SymbolTable<'_, C, S>) -> Vec<VarEntry> {
Expand Down Expand Up @@ -865,7 +865,7 @@ impl<'gc, C: CustomTypes<S>, S: System<C>> Process<'gc, C, S> {
[_] => return Err(ErrorCause::UpvarAtRoot),
[.., x, y] => (x, y),
};
let parent_def = match parent_scope.locals.lookup_mut(target.as_ref()) {
let parent_def = match parent_scope.locals.lookup_mut(target.as_str()) {
Some(x) => x,
None => return Err(ErrorCause::UndefinedVariable { name: var.into() }),
};
Expand Down Expand Up @@ -1740,7 +1740,7 @@ mod ops {
fn process_vector<C: CustomTypes<S>, S: System<C>>(res: &mut CompactString, value: &VecDeque<Value<C, S>>) -> Result<(), ErrorCause<C, S>> {
for (i, x) in value.iter().enumerate() {
if i != 0 { res.push(','); }
process_scalar(res, x.as_text()?.as_ref())
process_scalar(res, x.as_text()?.as_str())
}
Ok(())
}
Expand Down Expand Up @@ -1827,7 +1827,7 @@ mod ops {
}),
BinaryOp::SplitBy => binary_op_impl(mc, system, a, b, true, &mut cache, |mc, _, a, b| {
let (text, pattern) = (a.as_text()?, b.as_text()?);
Ok(Gc::new(mc, RefLock::new(text.split(pattern.as_ref()).map(|x| Text::from(x).into()).collect::<VecDeque<_>>())).into())
Ok(Gc::new(mc, RefLock::new(text.split(pattern.as_str()).map(|x| Text::from(x).into()).collect::<VecDeque<_>>())).into())
}),

BinaryOp::Range => binary_op_impl(mc, system, a, b, true, &mut cache, |mc, _, a, b| {
Expand Down Expand Up @@ -1931,7 +1931,7 @@ mod ops {
Ok(Gc::new(mc, RefLock::new(x.as_text()?.lines().map(|x| Text::from(x).into()).collect::<VecDeque<_>>())).into())
}),
UnaryOp::SplitCsv => unary_op_impl(mc, system, x, &mut cache, OpType::Deterministic, &|mc, _, x| {
let value = from_csv(mc, x.as_text()?.as_ref())?;
let value = from_csv(mc, x.as_text()?.as_str())?;
Ok(Gc::new(mc, RefLock::new(value)).into())
}),
UnaryOp::SplitJson => unary_op_impl(mc, system, x, &mut cache, OpType::Deterministic, &|mc, _, x| {
Expand Down
4 changes: 2 additions & 2 deletions src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl<'gc, C: CustomTypes<S>, S: System<C>> Project<'gc, C, S> {
let mut project = Self::new(Gc::new(mc, RefLock::new(global_context)));

for entity_info in init_info.entities.iter() {
let entity = *project.state.global_context.borrow().entities.get(&entity_info.name).unwrap();
let entity = *project.state.global_context.borrow().entities.get(entity_info.name.as_str()).unwrap();
for (event, pos) in entity_info.scripts.iter() {
project.add_script(*pos, entity, event.clone());
}
Expand Down Expand Up @@ -362,7 +362,7 @@ impl<'gc, C: CustomTypes<S>, S: System<C>> Project<'gc, C, S> {
ProcessStep::Broadcast { msg_type, barrier, targets } => {
for i in 0..self.scripts.len() {
if let Event::LocalMessage { msg_type: recv_type } = &self.scripts[i].event.0 {
if recv_type.as_ref().map(|x| *x == msg_type).unwrap_or(true) {
if recv_type.as_deref().map(|x| x == msg_type).unwrap_or(true) {
if let Some(targets) = &targets {
if !targets.iter().any(|&target| Gc::ptr_eq(self.scripts[i].entity, target)) {
continue
Expand Down
12 changes: 6 additions & 6 deletions src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ pub struct ProcessKind<'gc, 'a, C: CustomTypes<S>, S: System<C>> {
#[derive(Collect)]
#[collect(no_drop, bound = "")]
pub struct Entity<'gc, C: CustomTypes<S>, S: System<C>> {
#[collect(require_static)] pub name: Rc<CompactString>,
#[collect(require_static)] pub name: Text,
#[collect(require_static)] pub sound_list: Rc<VecMap<CompactString, Rc<Audio>, false>>,
#[collect(require_static)] pub costume_list: Rc<VecMap<CompactString, Rc<Image>, false>>,
#[collect(require_static)] pub costume: Option<Rc<Image>>,
Expand Down Expand Up @@ -1368,9 +1368,9 @@ pub struct GlobalContext<'gc, C: CustomTypes<S>, S: System<C>> {
#[collect(require_static)] pub settings: Settings,
#[collect(require_static)] pub system: Rc<S>,
#[collect(require_static)] pub timer_start: u64,
#[collect(require_static)] pub proj_name: CompactString,
#[collect(require_static)] pub proj_name: Text,
pub globals: SymbolTable<'gc, C, S>,
pub entities: VecMap<CompactString, Gc<'gc, RefLock<Entity<'gc, C, S>>>, false>,
pub entities: VecMap<Text, Gc<'gc, RefLock<Entity<'gc, C, S>>>, false>,
}
impl<'gc, C: CustomTypes<S>, S: System<C>> GlobalContext<'gc, C, S> {
pub fn from_init(mc: &Mutation<'gc>, init_info: &InitInfo, bytecode: Rc<ByteCode>, settings: Settings, system: Rc<S>) -> Self {
Expand Down Expand Up @@ -1457,12 +1457,12 @@ impl<'gc, C: CustomTypes<S>, S: System<C>> GlobalContext<'gc, C, S> {
props.pen_color_t = Number::new((1.0 - a as f64) * 100.0).unwrap();

let state = C::EntityState::from(if i == 0 { EntityKind::Stage { props } } else { EntityKind::Sprite { props } });
let name = Rc::new(entity_info.name.clone());
let name = Text::from(entity_info.name.as_str());

entities.insert((*name).clone(), Gc::new(mc, RefLock::new(Entity { original: None, name, fields, sound_list, costume_list, costume, state })));
entities.insert(name.clone(), Gc::new(mc, RefLock::new(Entity { original: None, name, fields, sound_list, costume_list, costume, state })));
}

let proj_name = init_info.proj_name.clone();
let proj_name = init_info.proj_name.as_str().into();
let timer_start = system.time(Precision::Medium).to_arbitrary_ms::<C, S>().unwrap_or(0);

Self { proj_name, globals, entities, timer_start, system, settings, bytecode }
Expand Down
8 changes: 8 additions & 0 deletions src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ fn test_sizes() {
}
}

#[test]
fn test_send() {
fn assert_send<T: Send>() {}
assert_send::<SimpleValue>();
assert_send::<OutgoingMessage>();
assert_send::<IncomingMessage>();
}

#[test]
fn test_note() {
for i in 0..=127 {
Expand Down

0 comments on commit 09f724f

Please sign in to comment.