1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), feature(alloc))]

#[cfg(not(feature = "std"))]
#[macro_use]
extern crate alloc;

extern crate byteorder;
extern crate xwasm;
#[macro_use] extern crate log;
#[cfg(test)] #[macro_use] extern crate indoc;


pub mod rules;

mod build;
mod ext;
mod gas;
mod optimizer;
mod pack;
mod runtime_type;
mod graph;
mod ref_list;
mod symbols;

pub mod stack_height;

pub use build::{build, Error as BuildError, SourceTarget};
pub use ext::{
    externalize, externalize_mem, shrink_unknown_stack, underscore_funcs, ununderscore_funcs,
};
pub use gas::inject_gas_counter;
pub use optimizer::{optimize, Error as OptimizerError};
pub use pack::{pack_instance, Error as PackingError};
pub use runtime_type::inject_runtime_type;
pub use graph::{Module, parse as graph_parse, generate as graph_generate};
pub use ref_list::{RefList, Entry, EntryRef, DeleteTransaction};

pub struct TargetSymbols {
    pub create: &'static str,
    pub call: &'static str,
    pub ret: &'static str,
}

pub enum TargetRuntime {
    Higgsfield(TargetSymbols),
    PWasm(TargetSymbols),
}

impl TargetRuntime {

    pub fn higgsfield() -> TargetRuntime {
        TargetRuntime::Higgsfield(TargetSymbols {
            create: "deploy",
            call: "call",
            ret: "ext_return",
        })
    }

    pub fn pxwasm() -> TargetRuntime {
        TargetRuntime::PWasm(TargetSymbols {
            create: "deploy",
            call: "call",
            ret: "ret",
        })
    }

    pub fn symbols(&self) -> &TargetSymbols {
        match self {
			TargetRuntime::Higgsfield(s) => s,
			TargetRuntime::PWasm(s) => s,
		}
    }

}

#[cfg(not(feature = "std"))]
mod std {
    pub use alloc::{borrow, boxed, string, vec};
    pub use core::*;

	pub mod rc {
		pub use alloc::rc::Rc;
	}

	pub mod collections {
		pub use alloc::collections::{BTreeMap, BTreeSet};
	}
}