Skip to content

Commit

Permalink
switch to socialism
Browse files Browse the repository at this point in the history
  • Loading branch information
dragazo committed Oct 11, 2024
1 parent 7d7f10e commit 05e4c2f
Show file tree
Hide file tree
Showing 12 changed files with 181 additions and 206 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ typed-arena = { version = "2.0.2", default-features = false }
xmlparser = { version = "0.13.6", default-features = false }
base64 = { version = "0.22.1", default-features = false, features = ["alloc"] }
compact_str = { version = "0.8.0", default-features = false, features = ["serde"] }
our-string = { version = "0.1.4", default-features = false }
ryu = { version = "1.0", default-features = false }
unicode-segmentation = { version = "1.11.0", default-features = false }

Expand Down
10 changes: 5 additions & 5 deletions src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@ impl BinaryWrite for VariadicLen {
#[derive(Clone, Copy, Debug, FromPrimitive)]
#[repr(u8)]
pub(crate) enum BasicType {
Number, String, Bool, List, Entity, Image, Audio,
Number, Text, Bool, List, Entity, Image, Audio,
}
impl BasicType {
pub fn to_type<C: CustomTypes<S>, S: System<C>>(self) -> Type<C, S> {
match self {
BasicType::Number => Type::Number,
BasicType::String => Type::String,
BasicType::Text => Type::Text,
BasicType::Bool => Type::Bool,
BasicType::List => Type::List,
BasicType::Entity => Type::Entity,
Expand Down Expand Up @@ -1143,7 +1143,7 @@ pub(crate) enum RefValue {
List(Vec<InitValue>),
Image(Vec<u8>, Option<(Number, Number)>, CompactString),
Audio(Vec<u8>, CompactString),
String(CompactString),
Text(CompactString),
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub(crate) struct EntityInitInfo {
Expand Down Expand Up @@ -1610,7 +1610,7 @@ impl<'a: 'b, 'b> ByteCodeBuilder<'a, 'b> {
self.append_expr(value, entity)?;
let ty = match ty {
ast::ValueType::Number => BasicType::Number,
ast::ValueType::Text => BasicType::String,
ast::ValueType::Text => BasicType::Text,
ast::ValueType::Bool => BasicType::Bool,
ast::ValueType::List => BasicType::List,
ast::ValueType::Sprite => BasicType::Entity,
Expand Down Expand Up @@ -2562,7 +2562,7 @@ impl ByteCode {
}
ast::Value::String(x) => {
let idx = *string_refs.entry(x).or_insert_with(|| {
ref_values.push((Some(RefValue::String(x.clone())), value));
ref_values.push((Some(RefValue::Text(x.clone())), value));
ref_values.len() - 1
});
InitValue::Ref(idx)
Expand Down
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ fn run_proj_tty<C: CustomTypes<StdSystem<C>>>(project_name: &str, server: Compac
}
RawKeyCode::Backspace => if in_input_mode() && input_value.pop().is_some() { update_flag.set(true) }
RawKeyCode::Enter => if let Some((_, res_key)) = input_queries.borrow_mut().pop_front() {
res_key.complete(Ok(SimpleValue::String(mem::take(&mut input_value)).into()));
res_key.complete(Ok(SimpleValue::Text(mem::take(&mut input_value)).into()));
update_flag.set(true);
}
RawKeyCode::Up => if !in_input_mode() { input_sequence.push(Input::KeyDown { key: KeyCode::Up }) }
Expand Down
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ pub mod compact_str {
/// The re-exported version of the `netsblox-ast` crate.
pub use netsblox_ast as ast;

macro_rules! format_text {
($($t:tt)*) => {{
$crate::runtime::Text::from(format!($($t)*).as_str())
}};
}

pub mod bytecode;
pub mod slotmap;
pub mod vecmap;
Expand Down
12 changes: 6 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ fn main() {
Request::Syscall { name, args } => match name.as_str() {
"open" => {
let (path, mode) = match args.as_slice() {
[path, mode] => match (path.as_string(), mode.as_string()) {
[path, mode] => match (path.as_text(), mode.as_text()) {
(Ok(path), Ok(mode)) => (path, mode),
_ => {
key.complete(Err(format_compact!("syscall open - expected 2 string args, received {:?} and {:?}", path.get_type(), mode.get_type())));
Expand Down Expand Up @@ -156,7 +156,7 @@ fn main() {
NativeValue::InputFile { handle } => *handle.borrow_mut() = None,
NativeValue::OutputFile { handle } => *handle.borrow_mut() = None,
}
key.complete(Ok(SimpleValue::String("OK".into()).into()));
key.complete(Ok(SimpleValue::Text("OK".into()).into()));
RequestStatus::Handled
}
_ => {
Expand All @@ -180,7 +180,7 @@ fn main() {
return RequestStatus::Handled;
}

key.complete(Ok(SimpleValue::String(res.into()).into()));
key.complete(Ok(SimpleValue::Text(res.into()).into()));
RequestStatus::Handled
}
None => {
Expand Down Expand Up @@ -209,7 +209,7 @@ fn main() {
NativeValue::OutputFile { handle } => match handle.borrow_mut().as_mut() {
Some(handle) => match writeln!(*handle, "{content}") {
Ok(_) => {
key.complete(Ok(SimpleValue::String("OK".into()).into()));
key.complete(Ok(SimpleValue::Text("OK".into()).into()));
RequestStatus::Handled
}
Err(e) => {
Expand All @@ -223,12 +223,12 @@ fn main() {
}
}
_ => {
key.complete(Err(format_compact!("syscall writeLine - expected types {:?} and {:?}. received types {:?} and {:?}", NativeType::OutputFile, Type::<C, StdSystem<C>>::String, file.get_type(), Type::<C, StdSystem<C>>::String)));
key.complete(Err(format_compact!("syscall writeLine - expected types {:?} and {:?}. received types {:?} and {:?}", NativeType::OutputFile, Type::<C, StdSystem<C>>::Text, file.get_type(), Type::<C, StdSystem<C>>::Text)));
RequestStatus::Handled
}
}
_ => {
key.complete(Err(format_compact!("syscall writeLine - expected types {:?} and {:?}. received types {:?} and {:?}", NativeType::OutputFile, Type::<C, StdSystem<C>>::String, file.get_type(), content.get_type())));
key.complete(Err(format_compact!("syscall writeLine - expected types {:?} and {:?}. received types {:?} and {:?}", NativeType::OutputFile, Type::<C, StdSystem<C>>::Text, file.get_type(), content.get_type())));
RequestStatus::Handled
}
}
Expand Down
Loading

0 comments on commit 05e4c2f

Please sign in to comment.