Add string concatenation
This commit is contained in:
parent
4775d425a0
commit
5662ba3d08
@ -9,7 +9,7 @@ pub fn panic(data: &mut Thread, _: usize, argument_range: Range<usize>) {
|
||||
for register_index in argument_range {
|
||||
let string = data.get_string_register(register_index);
|
||||
|
||||
message.push_str(&string);
|
||||
message.push_str(string);
|
||||
message.push('\n');
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ use std::ops::Range;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
use crate::{Value, vm::Thread};
|
||||
use crate::vm::Thread;
|
||||
|
||||
pub fn random_int(data: &mut Thread, destination: usize, argument_range: Range<usize>) {
|
||||
let mut argument_range_iter = argument_range.into_iter();
|
||||
|
@ -120,11 +120,43 @@ pub fn add(instruction: InstructionBuilder, thread: &mut Thread) {
|
||||
};
|
||||
let result = left_value + right_value;
|
||||
|
||||
println!("{left} + {right} = {destination}");
|
||||
println!("{left_value} + {right_value} = {result}");
|
||||
|
||||
thread.set_integer_register(destination, result);
|
||||
}
|
||||
(TypeCode::STRING, TypeCode::STRING) => {
|
||||
let left_value = if left_is_constant {
|
||||
if cfg!(debug_assertions) {
|
||||
thread.get_constant(left).as_string().unwrap().clone()
|
||||
} else {
|
||||
unsafe {
|
||||
thread
|
||||
.get_constant(left)
|
||||
.as_string()
|
||||
.unwrap_unchecked()
|
||||
.clone()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
thread.get_string_register(left).clone()
|
||||
};
|
||||
let right_value = if right_is_constant {
|
||||
if cfg!(debug_assertions) {
|
||||
thread.get_constant(right).as_string().unwrap().clone()
|
||||
} else {
|
||||
unsafe {
|
||||
thread
|
||||
.get_constant(right)
|
||||
.as_string()
|
||||
.unwrap_unchecked()
|
||||
.clone()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
thread.get_string_register(right).clone()
|
||||
};
|
||||
let result = left_value + &right_value;
|
||||
|
||||
thread.set_string_register(destination, result);
|
||||
}
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ pub struct Thread {
|
||||
chunk: Arc<Chunk>,
|
||||
call_stack: Vec<CallFrame>,
|
||||
pub return_value: Option<Option<Value>>,
|
||||
spawned_threads: Vec<JoinHandle<()>>,
|
||||
_spawned_threads: Vec<JoinHandle<()>>,
|
||||
}
|
||||
|
||||
impl Thread {
|
||||
@ -24,7 +24,7 @@ impl Thread {
|
||||
chunk,
|
||||
call_stack,
|
||||
return_value: None,
|
||||
spawned_threads: Vec::new(),
|
||||
_spawned_threads: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user