A little bit further.
This commit is contained in:
parent
21250ea695
commit
3edb00ceb0
@ -70,9 +70,7 @@ fn main() {
|
|||||||
let unsafe_pointer_impl_rc = Rc::new(pointer_impl);
|
let unsafe_pointer_impl_rc = Rc::new(pointer_impl);
|
||||||
|
|
||||||
mem_lib.interfaces.push(pointer_int_rc.clone());
|
mem_lib.interfaces.push(pointer_int_rc.clone());
|
||||||
mem_lib
|
mem_lib.implementations.push(unsafe_pointer_impl_rc.clone());
|
||||||
.implementations
|
|
||||||
.push(unsafe_pointer_impl_rc.clone());
|
|
||||||
|
|
||||||
// std::unsafe::alloc(
|
// std::unsafe::alloc(
|
||||||
// r0: size Long
|
// r0: size Long
|
||||||
@ -169,7 +167,10 @@ fn main() {
|
|||||||
|
|
||||||
// std::core::String
|
// std::core::String
|
||||||
let mut string_lib = DmLib::new("std/core/string");
|
let mut string_lib = DmLib::new("std/core/string");
|
||||||
let mut string_impl = DmImplementation::new("std::core::String", "String", None);
|
|
||||||
|
let string_int = DmInterface::new("std::core::String", "String");
|
||||||
|
|
||||||
|
let mut string_impl = DmImplementation::new("std::core::StringImpl", "StringImpl", None);
|
||||||
|
|
||||||
let bytes_field = DmField::new("bytes", DmType::Pointer, 0);
|
let bytes_field = DmField::new("bytes", DmType::Pointer, 0);
|
||||||
|
|
||||||
@ -186,7 +187,7 @@ fn main() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let string_ctor_0_fn = DmFn::new(
|
let string_ctor_0_fn = DmFn::new(
|
||||||
"std::core::String::_ctor_0",
|
"std::core::StringImpl::_ctor_0",
|
||||||
"_ctor_0",
|
"_ctor_0",
|
||||||
string_ctor_0_bytecode,
|
string_ctor_0_bytecode,
|
||||||
2,
|
2,
|
||||||
@ -199,6 +200,7 @@ fn main() {
|
|||||||
string_impl.methods.push(Rc::new(string_ctor_0_method));
|
string_impl.methods.push(Rc::new(string_ctor_0_method));
|
||||||
let core_string_impl_size = string_impl.size_in_bytes();
|
let core_string_impl_size = string_impl.size_in_bytes();
|
||||||
|
|
||||||
|
string_lib.interfaces.push(Rc::new(string_int));
|
||||||
string_lib.implementations.push(Rc::new(string_impl));
|
string_lib.implementations.push(Rc::new(string_impl));
|
||||||
|
|
||||||
// greeting lib
|
// greeting lib
|
||||||
@ -217,7 +219,7 @@ fn main() {
|
|||||||
&mut main_byte_code,
|
&mut main_byte_code,
|
||||||
0,
|
0,
|
||||||
core_string_impl_size as u32,
|
core_string_impl_size as u32,
|
||||||
"std::core::String",
|
"std::core::StringImpl",
|
||||||
);
|
);
|
||||||
add_mov_const(&mut main_byte_code, 1, "greeting", 0);
|
add_mov_const(&mut main_byte_code, 1, "greeting", 0);
|
||||||
add_invoke_fn(
|
add_invoke_fn(
|
||||||
@ -234,7 +236,12 @@ fn main() {
|
|||||||
|
|
||||||
let mut state = DvmState::new();
|
let mut state = DvmState::new();
|
||||||
let mut context = DvmContext::new();
|
let mut context = DvmContext::new();
|
||||||
context.load_functions(&vec![greeting_lib, string_lib, mem_lib]);
|
context.load(vec![
|
||||||
|
Rc::new(greeting_lib),
|
||||||
|
Rc::new(string_lib),
|
||||||
|
Rc::new(array_lib),
|
||||||
|
Rc::new(mem_lib)
|
||||||
|
]);
|
||||||
|
|
||||||
let main_fn = context.fn_by_fqn("main").unwrap();
|
let main_fn = context.fn_by_fqn("main").unwrap();
|
||||||
call_fn(&mut state, &context, &main_fn, vec![]);
|
call_fn(&mut state, &context, &main_fn, vec![]);
|
||||||
|
@ -18,7 +18,7 @@ impl DvmValue {
|
|||||||
if let DvmValue::Long(l) = self {
|
if let DvmValue::Long(l) = self {
|
||||||
*l
|
*l
|
||||||
} else {
|
} else {
|
||||||
panic!("Expected DvmValue::long, but found {:?}", self)
|
panic!("Expected DvmValue::Long, but found {:?}", self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ struct CallFrameInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct DvmContext {
|
pub struct DvmContext {
|
||||||
libs: Vec<DmLib>,
|
libs: Vec<Rc<DmLib>>,
|
||||||
functions: HashMap<String, Rc<DmFn>>,
|
functions: HashMap<String, Rc<DmFn>>,
|
||||||
platform_functions: HashMap<String, Rc<PlatformFunction>>,
|
platform_functions: HashMap<String, Rc<PlatformFunction>>,
|
||||||
}
|
}
|
||||||
@ -43,8 +43,9 @@ impl DvmContext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_functions(&mut self, libs: &Vec<DmLib>) {
|
pub fn load(&mut self, libs: Vec<Rc<DmLib>>) {
|
||||||
for lib in libs {
|
for lib in libs {
|
||||||
|
self.libs.push(lib.clone());
|
||||||
for lib_fn in &lib.functions {
|
for lib_fn in &lib.functions {
|
||||||
self.functions
|
self.functions
|
||||||
.insert(lib_fn.fqn().to_string(), lib_fn.clone());
|
.insert(lib_fn.fqn().to_string(), lib_fn.clone());
|
||||||
@ -69,6 +70,16 @@ impl DvmContext {
|
|||||||
implementation_function.clone(),
|
implementation_function.clone(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
for method in lib
|
||||||
|
.implementations
|
||||||
|
.iter()
|
||||||
|
.flat_map(|implementation| &implementation.methods)
|
||||||
|
{
|
||||||
|
self.functions.insert(
|
||||||
|
method.dm_fn().fqn().to_string(),
|
||||||
|
method.dm_fn().clone(),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -527,7 +538,7 @@ pub fn run_byte_code(state: &mut DvmState, context: &DvmContext, byte_code: &[u8
|
|||||||
.expect(&format!("Could not find method: {}", symbol_name));
|
.expect(&format!("Could not find method: {}", symbol_name));
|
||||||
let dm_fn = method.dm_fn();
|
let dm_fn = method.dm_fn();
|
||||||
|
|
||||||
let call_result = call_fn(state, context, dm_fn, args);
|
let call_result = call_fn(state, context, &dm_fn, args);
|
||||||
state.registers.insert(return_register, call_result);
|
state.registers.insert(return_register, call_result);
|
||||||
}
|
}
|
||||||
INVOKE_DYNAMIC => {
|
INVOKE_DYNAMIC => {
|
||||||
|
@ -82,8 +82,8 @@ impl DmMethod {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dm_fn(&self) -> &DmFn {
|
pub fn dm_fn(&self) -> Rc<DmFn> {
|
||||||
&self.dm_fn
|
self.dm_fn.clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user