Skip to content

Commit 3aa9bd5

Browse files
committed
fix grammar lex
1 parent d0e64d2 commit 3aa9bd5

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

rust/derive/src/def_module.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ pub fn lex_arrow(
3131
left_name = TokenStream::new();
3232
right_name = TokenStream::new();
3333
control_which_put = false;
34-
} else if x == "]" {
35-
left_push.push(syn::parse(left_name).expect("left push break"));
36-
right_push.push(syn::parse(right_name).expect("right push break"));
37-
break;
34+
} else {
35+
panic!("{}", errormsg);
3836
}
3937
} else {
4038
if !control_which_put {
@@ -44,6 +42,8 @@ pub fn lex_arrow(
4442
}
4543
}
4644
}
45+
left_push.push(syn::parse(left_name).expect("left push break"));
46+
right_push.push(syn::parse(right_name).expect("right push break"));
4747
}
4848
_ => {
4949
panic!("{}", errormsg);
@@ -147,15 +147,19 @@ pub fn def_impl(content: TokenStream) -> TokenStream {
147147
use std::collections::hash_map::HashMap;
148148
let mut functions = HashMap::new();
149149
let mut classes = HashMap::new();
150+
let mut submodules = HashMap::new();
150151
#(
151152
functions.insert(stringify!(#right_func).to_string(), #left_func());
152153
)*
153154
#(
154155
classes.insert(stringify!(#right_class).to_string(), #left_class::export_info());
155156
)*
157+
#(
158+
submodules.insert(stringify!(#submodules).to_string(), #submodules::init());
159+
)*
156160
Stdlib::new(
157161
stringify!(#module_ident),
158-
HashMap::new(),
162+
submodules,
159163
functions,
160164
classes
161165
)

rust/src/compiler/ast.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,17 @@ mod tests {
638638
t.staticdata.inst,
639639
vec![
640640
Inst::new(Opcode::LoadString, 0),
641-
Inst::new(Opcode::CallNative, 0),
641+
Inst::new(
642+
Opcode::CallNative,
643+
STDLIB_ROOT
644+
.sub_modules
645+
.get("prelude")
646+
.unwrap()
647+
.functions
648+
.get("print")
649+
.unwrap()
650+
.buildin_id
651+
),
642652
]
643653
)
644654
}

rust/src/tvm/stdlib/prelude.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use super::super::types::*;
12
use crate::base::stdlib::*;
23
use crate::{base::error::*, tvm::DynaData};
34
use derive::{def_module, trc_function};
@@ -13,5 +14,8 @@ pub fn println(obj: any) -> void {
1314
}
1415

1516
def_module!(module_name = prelude, functions = [print => print, println => print], classes = [
16-
Trcint => int
17+
TrcInt => int,
18+
TrcStr => str,
19+
TrcBool => bool,
20+
TrcFloat => float
1721
]);

rust/src/tvm/types.rs

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ pub mod trcfloat;
1010
pub mod trcint;
1111
pub mod trcstr;
1212

13+
pub use trcbool::TrcBool;
14+
pub use trcfloat::TrcFloat;
15+
pub use trcint::TrcInt;
16+
pub use trcstr::TrcStr;
17+
1318
/// help to generate the same error reporter functions
1419
macro_rules! batch_unsupported_operators {
1520
($($traie_name:ident => $oper_name:expr),*) => {

0 commit comments

Comments
 (0)