1
0
This commit is contained in:
Jeff 2025-02-08 17:52:54 -05:00
parent 3af1b64820
commit a5d2e7d869
5 changed files with 20 additions and 54 deletions

View File

@ -20,20 +20,19 @@ mod scope;
pub use disassembler::Disassembler; pub use disassembler::Disassembler;
pub use local::Local; pub use local::Local;
pub use scope::Scope; pub use scope::Scope;
use serde::ser::SerializeStruct;
use std::fmt::{self, Debug, Display, Formatter, Write as FmtWrite}; use std::fmt::{self, Debug, Display, Formatter, Write as FmtWrite};
use std::io::Write; use std::io::Write;
use std::sync::Arc; use std::sync::Arc;
use serde::{Deserialize, Serialize, Serializer}; use serde::{Deserialize, Serialize};
use crate::{ConcreteValue, DustString, Function, FunctionType, Instruction, Span}; use crate::{ConcreteValue, DustString, Function, FunctionType, Instruction, Span};
/// Representation of a Dust program or function. /// Representation of a Dust program or function.
/// ///
/// See the [module-level documentation](index.html) for more information. /// See the [module-level documentation](index.html) for more information.
#[derive(Clone, Default, PartialOrd, Deserialize)] #[derive(Clone, Default, PartialOrd, Serialize, Deserialize)]
pub struct Chunk { pub struct Chunk {
pub name: Option<DustString>, pub name: Option<DustString>,
pub r#type: FunctionType, pub r#type: FunctionType,
@ -44,14 +43,14 @@ pub struct Chunk {
pub locals: Vec<Local>, pub locals: Vec<Local>,
pub prototypes: Vec<Arc<Chunk>>, pub prototypes: Vec<Arc<Chunk>>,
pub boolean_register_count: usize, pub boolean_register_count: u16,
pub byte_register_count: usize, pub byte_register_count: u16,
pub character_register_count: usize, pub character_register_count: u16,
pub float_register_count: usize, pub float_register_count: u16,
pub integer_register_count: usize, pub integer_register_count: u16,
pub string_register_count: usize, pub string_register_count: u16,
pub list_register_count: usize, pub list_register_count: u16,
pub function_register_count: usize, pub function_register_count: u16,
pub prototype_index: u16, pub prototype_index: u16,
} }
@ -116,28 +115,3 @@ impl PartialEq for Chunk {
&& self.prototypes == other.prototypes && self.prototypes == other.prototypes
} }
} }
impl Serialize for Chunk {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut state = serializer.serialize_struct("Chunk", 11)?;
state.serialize_field("name", &self.name)?;
state.serialize_field("boolean_register_count", &self.boolean_register_count)?;
state.serialize_field("byte_register_count", &self.byte_register_count)?;
state.serialize_field("character_register_count", &self.character_register_count)?;
state.serialize_field("float_register_count", &self.float_register_count)?;
state.serialize_field("integer_register_count", &self.integer_register_count)?;
state.serialize_field("string_register_count", &self.string_register_count)?;
state.serialize_field("list_register_count", &self.list_register_count)?;
state.serialize_field("function_register_count", &self.function_register_count)?;
state.serialize_field("prototype_index", &self.prototype_index)?;
state.serialize_field("instructions", &self.instructions)?;
state.serialize_field("positions", &self.positions)?;
state.serialize_field("prototypes", &self.prototypes)?;
state.serialize_field("locals", &self.locals)?;
state.serialize_field("constants", &self.constants)?;
state.serialize_field("type", &self.r#type)?;
state.end()
}
}

View File

@ -32,7 +32,7 @@ use std::{mem::replace, sync::Arc};
use crate::{ use crate::{
Chunk, ConcreteValue, DustError, DustString, FunctionType, Instruction, Lexer, Local, Chunk, ConcreteValue, DustError, DustString, FunctionType, Instruction, Lexer, Local,
NativeFunction, Operand, Operation, Scope, Span, Token, TokenKind, Type, NativeFunction, Operand, Operation, Scope, Span, Token, TokenKind, Type,
instruction::{CallNative, Jump, Point, Return, TypeCode}, instruction::{Jump, Point, Return, TypeCode},
}; };
/// Compiles the input and returns a chunk. /// Compiles the input and returns a chunk.
@ -222,14 +222,14 @@ impl<'src> Compiler<'src> {
/// will allow [`Compiler::function_name`] to be both the name used for recursive calls and the /// will allow [`Compiler::function_name`] to be both the name used for recursive calls and the
/// name of the function when it is compiled. The name can later be seen in the VM's call stack. /// name of the function when it is compiled. The name can later be seen in the VM's call stack.
pub fn finish(mut self) -> Chunk { pub fn finish(mut self) -> Chunk {
let boolean_register_count = self.next_boolean_register() as usize; let boolean_register_count = self.next_boolean_register();
let byte_register_count = self.next_byte_register() as usize; let byte_register_count = self.next_byte_register();
let character_register_count = self.next_character_register() as usize; let character_register_count = self.next_character_register();
let float_register_count = self.next_float_register() as usize; let float_register_count = self.next_float_register();
let integer_register_count = self.next_integer_register() as usize; let integer_register_count = self.next_integer_register();
let string_register_count = self.next_string_register() as usize; let string_register_count = self.next_string_register();
let list_register_count = self.next_list_register() as usize; let list_register_count = self.next_list_register();
let function_register_count = self.next_function_register() as usize; let function_register_count = self.next_function_register();
let (instructions, positions): (Vec<Instruction>, Vec<Span>) = self let (instructions, positions): (Vec<Instruction>, Vec<Span>) = self
.instructions .instructions
.into_iter() .into_iter()

View File

@ -5,7 +5,6 @@
mod assert; mod assert;
mod io; mod io;
mod random; mod random;
mod string;
mod thread; mod thread;
use std::{ use std::{

View File

@ -1,7 +0,0 @@
use std::ops::Range;
use crate::vm::Thread;
pub fn to_string(_thread: &mut Thread, _destination: usize, _argument_range: Range<usize>) {
todo!()
}

View File

@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
use smartstring::{LazyCompact, SmartString}; use smartstring::{LazyCompact, SmartString};
use tracing::trace; use tracing::trace;
use crate::{Type, Value, ValueError, instruction::TypeCode}; use crate::{Type, Value, instruction::TypeCode};
use super::RangeValue; use super::RangeValue;