mirror of
https://github.com/voltrevo/ValueScript.git
synced 2026-04-18 03:00:27 -04:00
More deduping of builtins, fix todo
This commit is contained in:
@@ -6,3 +6,4 @@ edition = "2021"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
valuescript_common = { path = "../valuescript_common" }
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use valuescript_common::BUILTIN_COUNT;
|
||||
|
||||
use crate::number_builtin::NUMBER_BUILTIN;
|
||||
use crate::string_builtin::STRING_BUILTIN;
|
||||
|
||||
@@ -5,14 +7,5 @@ use super::debug::DEBUG;
|
||||
use super::math::MATH;
|
||||
use super::vs_value::ValTrait;
|
||||
|
||||
// TODO: Investigate whether a static array can be used for this and why rust
|
||||
// seems to not like it when I try.
|
||||
pub fn get_builtin(index: usize) -> &'static dyn ValTrait {
|
||||
return match index {
|
||||
0 => &MATH,
|
||||
1 => &DEBUG,
|
||||
2 => &STRING_BUILTIN,
|
||||
3 => &NUMBER_BUILTIN,
|
||||
_ => std::panic!(""),
|
||||
};
|
||||
}
|
||||
pub static BUILTIN_VALS: [&'static (dyn ValTrait + Sync); BUILTIN_COUNT] =
|
||||
[&DEBUG, &MATH, &STRING_BUILTIN, &NUMBER_BUILTIN];
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use std::collections::BTreeMap;
|
||||
use std::rc::Rc;
|
||||
|
||||
use super::builtins::get_builtin;
|
||||
use crate::builtins::BUILTIN_VALS;
|
||||
|
||||
use super::instruction::Instruction;
|
||||
use super::vs_array::VsArray;
|
||||
use super::vs_class::VsClass;
|
||||
@@ -127,7 +128,7 @@ impl BytecodeDecoder {
|
||||
BytecodeType::Function => self.decode_function_header(),
|
||||
BytecodeType::Pointer => self.decode_pointer(),
|
||||
BytecodeType::Register => registers[self.decode_register_index().unwrap()].clone(),
|
||||
BytecodeType::Builtin => Val::Static(get_builtin(self.decode_varsize_uint())),
|
||||
BytecodeType::Builtin => Val::Static(BUILTIN_VALS[self.decode_varsize_uint()]),
|
||||
BytecodeType::Class => Val::Class(Rc::new(VsClass {
|
||||
constructor: self.decode_val(registers),
|
||||
instance_prototype: self.decode_val(registers),
|
||||
|
||||
Reference in New Issue
Block a user