WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.7% of users enabled 2FA.

Commit 9b28c4c3 authored by qinsoon's avatar qinsoon
Browse files

[wip] unfinished work on API. Kunshan is gonna work on it

parent 815f10b1
use ast::ir::*;
use ast::ptr::*;
use ast::types::*;
use ir::*;
use ptr::*;
use types::*;
use std::collections::HashMap;
......@@ -37,13 +37,13 @@ impl MuBundle {
#[derive(Copy, Clone, Debug)]
pub struct MuValue {
pub struct APIMuValue {
pub id: MuID,
pub v: MuValueKind
pub v: APIMuValueKind
#[derive(Copy, Clone, Debug)]
pub enum MuValueKind {
pub enum APIMuValueKind {
......@@ -88,9 +88,9 @@ pub enum MuValueKind {
macro_rules! handle_constructor {
($fn_name: ident, $kind: ident) => {
pub fn $fn_name(id: MuID) -> MuValue {
id: id, v: MuValueKind::$kind
pub fn $fn_name(id: MuID) -> APIMuValue {
id: id, v: APIMuValueKind::$kind
......@@ -38,7 +38,7 @@ macro_rules! select_value {
pub mod ir;
pub mod bundle;
pub mod inst;
pub mod types;
pub mod ir_semantics;
use ast::ptr::*;
use ast::ir::*;
use ast::types::*;
use vm::api;
use vm::VM;
use vm::bundle::*;
use ast::bundle::*;
use std::mem;
use std::os::raw;
use std::collections::HashMap;
use std::sync::Arc;
use std::ffi::CStr;
use std::os::raw::c_int;
use std::os::raw::c_char;
use ast::ir::MuID;
pub type APIMuName = *const c_char;
macro_rules! unimplemented_api {
() => {
// cast fn to usize before transmute, see: https://github.com/rust-lang/rust/issues/19925
......@@ -19,7 +20,7 @@ macro_rules! unimplemented_api {
macro_rules! api {
($func: expr) => {
unsafe {mem::transmute($func as usize)}
mem::transmute($func as usize)
......@@ -34,46 +35,47 @@ pub struct MuVM {
pub new_context: fn (mvm: *mut MuVM) -> *mut MuCtx,
id_of: fn (mvm: *const MuVM, name: MuName) -> MuID,
name_of : fn (mvm: *const MuVM, id: MuID) -> MuName,
id_of: fn (mvm: *const MuVM, name: APIMuName) -> MuID,
name_of : fn (mvm: *const MuVM, id: MuID) -> APIMuName,
// set_trap_handler: fn(mvm: *mut MuVM, trap_handler: MuTrapHandler, user_data: MuCPtr)
// unimplemented api
set_trap_handler: fn () -> ()
impl MuVM {
pub fn new() -> *mut MuVM {
let vm = Box::new(MuVM {
internal: Arc::new(VM::new()),
new_context: api!(MuVM::new_context),
id_of: api!(MuVM::id_of),
name_of: api!(MuVM::name_of)
new_context: unsafe{api!(MuVM::new_context)},
id_of: unsafe{api!(MuVM::id_of)},
name_of: unsafe{api!(MuVM::name_of)},
set_trap_handler: unimplemented_api!()
pub fn new_context(&mut self) -> *mut MuCtx {
let ctx = Box::new(MuCtx::new(self.internal.clone()));
pub fn new_context(*mut self) -> *mut MuCtx {
let a : &mut self = self.as_mut().unwarp()
pub fn id_of(&self, name: &str) -> MuID {
pub fn id_of(&self, name: APIMuName) -> MuID {
let name = unsafe {CStr::from_ptr(name)}.to_str().unwrap();
pub fn name_of(&self, id: MuID) -> MuName {
pub fn name_of(&self, id: MuID) -> APIMuName {
self.internal.name_of(id).as_ptr() as *const c_char
pub struct MuCtx {
// void* header - current not planed to use this
internal: Box<MuCtxInternal>,
struct MuCtxInternal {
vm: Arc<VM>,
cur_bundles: HashMap<MuID, MuBundle>
// void* header
internal: Arc<VM>,
\ No newline at end of file
......@@ -3,10 +3,8 @@
use ast::ptr::*;
use ast::ir::*;
use ast::types::*;
use vm::api;
use ast::bundle::*;
use vm::VM;
use vm::bundle::*;
use std::mem;
use std::os::raw;
......@@ -75,23 +73,23 @@ impl MuVM {
pub type MuArraySize = usize;
pub type MuIntValue = MuValue;
pub type MuIntValue = APIMuValue;
pub type MuBundleNode = MuValue;
pub type MuChildNode = MuValue;
pub type MuTypeNode = MuValue;
pub type MuFuncSigNode= MuValue;
pub type MuConstNode = MuValue;
pub type MuGlobalNode = MuValue;
pub type MuFuncNode = MuValue;
pub type MuFuncVerNode= MuValue;
pub type MuBBNode = MuValue;
pub type MuNorParamNode = MuValue;
pub type MuExcParamNode = MuValue;
pub type MuInstNode = MuValue;
pub type MuInstResNode = MuValue;
pub type MuLocalVarNode = MuValue;
pub type MuVarNode = MuValue;
pub type MuBundleNode = APIMuValue;
pub type MuChildNode = APIMuValue;
pub type MuTypeNode = APIMuValue;
pub type MuFuncSigNode= APIMuValue;
pub type MuConstNode = APIMuValue;
pub type MuGlobalNode = APIMuValue;
pub type MuFuncNode = APIMuValue;
pub type MuFuncVerNode= APIMuValue;
pub type MuBBNode = APIMuValue;
pub type MuNorParamNode = APIMuValue;
pub type MuExcParamNode = APIMuValue;
pub type MuInstNode = APIMuValue;
pub type MuInstResNode = APIMuValue;
pub type MuLocalVarNode = APIMuValue;
pub type MuVarNode = APIMuValue;
pub type MuFlag = usize;
pub type MuDestKind = MuFlag;
......@@ -2,7 +2,6 @@ mod vm;
mod vm_options;
mod machine_code;
pub mod api;
pub mod bundle;
pub use vm::vm::VM;
pub use vm::vm_options::VMOptions;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment