Skip to content

Commit

Permalink
Merge pull request #76 from y21/intern-strings-vm-2
Browse files Browse the repository at this point in the history
dynamically intern strings at runtime
  • Loading branch information
y21 authored Dec 27, 2023
2 parents 8e092ad + b71cd5c commit 5f16bec
Show file tree
Hide file tree
Showing 89 changed files with 2,704 additions and 2,110 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions cli/src/cmd/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ pub fn eval(args: &ArgMatches) -> anyhow::Result<()> {

match scope.eval(source, opt) {
Ok(value) => println!("{}", format_value(value.root(&mut scope), &mut scope).unwrap()),
Err((EvalError::Exception(value), _)) => {
Err(EvalError::Exception(value)) => {
println!("{}", format_value(value.root(&mut scope), &mut scope).unwrap())
}
Err((EvalError::Middle(errs), _)) => println!("{}", errs.formattable(source, true)),
Err(EvalError::Middle(errs)) => println!("{}", errs.formattable(source, true)),
};

scope.process_async_tasks();
Expand Down
4 changes: 2 additions & 2 deletions cli/src/cmd/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ pub fn repl() -> anyhow::Result<()> {

match scope.eval(&input, OptLevel::Aggressive) {
Ok(value) => println!("{}", format_value(value.root(&mut scope), &mut scope).unwrap()),
Err((EvalError::Exception(value), _)) => {
Err(EvalError::Exception(value)) => {
println!("{}", format_value(value.root(&mut scope), &mut scope).unwrap())
}
Err((EvalError::Middle(errs), _)) => println!("{}", errs.formattable(&input, true)),
Err(EvalError::Middle(errs)) => println!("{}", errs.formattable(&input, true)),
}

scope.process_async_tasks();
Expand Down
4 changes: 2 additions & 2 deletions cli/src/cmd/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ async fn inner(source: String, opt: OptLevel, quiet: bool, initial_gc_threshold:
let mut scope = rt.vm_mut().scope();
let value = match scope.eval(&source, opt) {
Ok(val) => val.root(&mut scope),
Err((EvalError::Exception(val), _)) => val.root(&mut scope),
Err((EvalError::Middle(errs), _)) => {
Err(EvalError::Exception(val)) => val.root(&mut scope),
Err(EvalError::Middle(errs)) => {
println!("{}", errs.formattable(&source, true));
return Ok(());
}
Expand Down
18 changes: 8 additions & 10 deletions crates/dash_compiler/src/instruction.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::convert::TryInto;
use std::rc::Rc;

use dash_middle::compiler::constant::{Constant, LimitExceededError};
use dash_middle::compiler::instruction::{AssignKind, Instruction, IntrinsicOperation};
use dash_middle::compiler::{FunctionCallMetadata, ObjectMemberKind as CompilerObjectMemberKind, StaticImportKind};
use dash_middle::interner::Symbol;
use dash_middle::parser::error::Error;
use dash_middle::parser::expr::ObjectMemberKind;
use dash_middle::sourcemap::Span;
Expand Down Expand Up @@ -96,13 +96,13 @@ impl<'cx, 'interner> InstructionBuilder<'cx, 'interner> {
compile_local_load_into(&mut self.current_function_mut().buf, index, is_extern);
}

pub fn build_global_load(&mut self, ident: Rc<str>) -> Result<(), LimitExceededError> {
pub fn build_global_load(&mut self, ident: Symbol) -> Result<(), LimitExceededError> {
let id = self.current_function_mut().cp.add(Constant::Identifier(ident))?;
self.write_wide_instr(Instruction::LdGlobal, Instruction::LdGlobalW, id);
Ok(())
}

pub fn build_global_store(&mut self, kind: AssignKind, ident: Rc<str>) -> Result<(), LimitExceededError> {
pub fn build_global_store(&mut self, kind: AssignKind, ident: Symbol) -> Result<(), LimitExceededError> {
let id = self.current_function_mut().cp.add(Constant::Identifier(ident))?;
self.write_wide_instr(Instruction::StoreGlobal, Instruction::StoreGlobalW, id);
self.write(kind as u8);
Expand Down Expand Up @@ -178,7 +178,7 @@ impl<'cx, 'interner> InstructionBuilder<'cx, 'interner> {
self.build_jmp_header(label, is_local_label);
}

pub fn build_static_prop_access(&mut self, ident: Rc<str>, preserve_this: bool) -> Result<(), LimitExceededError> {
pub fn build_static_prop_access(&mut self, ident: Symbol, preserve_this: bool) -> Result<(), LimitExceededError> {
let id = self.current_function_mut().cp.add(Constant::Identifier(ident))?;
self.write_wide_instr(Instruction::StaticPropAccess, Instruction::StaticPropAccessW, id);
self.write(preserve_this.into());
Expand All @@ -191,7 +191,7 @@ impl<'cx, 'interner> InstructionBuilder<'cx, 'interner> {
self.write(preserve_this.into());
}

pub fn build_static_prop_assign(&mut self, kind: AssignKind, ident: Rc<str>) -> Result<(), LimitExceededError> {
pub fn build_static_prop_assign(&mut self, kind: AssignKind, ident: Symbol) -> Result<(), LimitExceededError> {
let id = self.current_function_mut().cp.add(Constant::Identifier(ident))?;
self.write_instr(Instruction::StaticPropAssign);
self.write(kind as u8);
Expand Down Expand Up @@ -220,7 +220,7 @@ impl<'cx, 'interner> InstructionBuilder<'cx, 'interner> {
fn compile_object_member_kind(
ib: &mut InstructionBuilder,
span: Span, // TODO: this should not be the span of the obj literal but the member kind
name: Rc<str>,
name: Symbol,
kind_id: u8,
) -> Result<(), Error> {
let id = ib
Expand All @@ -239,12 +239,10 @@ impl<'cx, 'interner> InstructionBuilder<'cx, 'interner> {
let kind_id = CompilerObjectMemberKind::from(&member) as u8;
match member {
ObjectMemberKind::Dynamic(..) => self.write(kind_id),
ObjectMemberKind::Static(name) => {
compile_object_member_kind(self, span, self.interner.resolve(name).clone(), kind_id)?
}
ObjectMemberKind::Static(name) => compile_object_member_kind(self, span, name, kind_id)?,
ObjectMemberKind::Spread => self.write(kind_id),
ObjectMemberKind::Getter(name) | ObjectMemberKind::Setter(name) => {
compile_object_member_kind(self, span, self.interner.resolve(name).clone(), kind_id)?
compile_object_member_kind(self, span, name, kind_id)?
}
}
}
Expand Down
Loading

0 comments on commit 5f16bec

Please sign in to comment.