Skip to content

Commit 829667c

Browse files
committed
compare sigs
1 parent e48e4bb commit 829667c

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

rasm/src/ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::parser;
22
use super::tokens;
33

44
// #[derive(Serialize, Deserialize, Debug, Clone)]
5-
#[derive(Clone, Debug, Copy)]
5+
#[derive(Clone, Debug, Copy, PartialEq, Eq)]
66
pub enum WasmPrimitives {
77
i32,
88
i64,

rasm/src/compiler.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::ast;
22

3+
#[derive(PartialEq, Eq)]
34
struct Sig<'a> {
45
params: &'a [ast::WasmPrimitives],
56
result: ast::WasmPrimitives,
@@ -59,12 +60,15 @@ pub fn compiler(ast: ast::Ast) -> Vec<u8> {
5960
sig.write(&mut bytes);
6061
}
6162
bytes.push(0x03);
62-
bytes.push((funcs.len() + 1).try_into().unwrap());
63-
bytes.push(funcs.len().try_into().unwrap());
64-
let mut sig = 0;
65-
while sig < funcs.len() {
66-
bytes.push(sig.try_into().unwrap());
67-
sig += 1;
63+
let num_of_funcs = funcs.len() as u8;
64+
bytes.push(num_of_funcs + 1);
65+
bytes.push(num_of_funcs);
66+
for func in funcs {
67+
for (i, sig) in sigs.iter().enumerate() {
68+
if sig == &Sig::new(&func) {
69+
bytes.push(i as u8);
70+
}
71+
}
6872
}
6973

7074
let num_of_exports = funcs.into_iter()

0 commit comments

Comments
 (0)