Skip to content

Commit

Permalink
fix grammar lex
Browse files Browse the repository at this point in the history
  • Loading branch information
limuy2022 committed Feb 5, 2024
1 parent d0e64d2 commit 3aa9bd5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
14 changes: 9 additions & 5 deletions rust/derive/src/def_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ pub fn lex_arrow(
left_name = TokenStream::new();
right_name = TokenStream::new();
control_which_put = false;
} else if x == "]" {
left_push.push(syn::parse(left_name).expect("left push break"));
right_push.push(syn::parse(right_name).expect("right push break"));
break;
} else {
panic!("{}", errormsg);
}
} else {
if !control_which_put {
Expand All @@ -44,6 +42,8 @@ pub fn lex_arrow(
}
}
}
left_push.push(syn::parse(left_name).expect("left push break"));
right_push.push(syn::parse(right_name).expect("right push break"));
}
_ => {
panic!("{}", errormsg);
Expand Down Expand Up @@ -147,15 +147,19 @@ pub fn def_impl(content: TokenStream) -> TokenStream {
use std::collections::hash_map::HashMap;
let mut functions = HashMap::new();
let mut classes = HashMap::new();
let mut submodules = HashMap::new();
#(
functions.insert(stringify!(#right_func).to_string(), #left_func());
)*
#(
classes.insert(stringify!(#right_class).to_string(), #left_class::export_info());
)*
#(
submodules.insert(stringify!(#submodules).to_string(), #submodules::init());
)*
Stdlib::new(
stringify!(#module_ident),
HashMap::new(),
submodules,
functions,
classes
)
Expand Down
12 changes: 11 additions & 1 deletion rust/src/compiler/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,17 @@ mod tests {
t.staticdata.inst,
vec![
Inst::new(Opcode::LoadString, 0),
Inst::new(Opcode::CallNative, 0),
Inst::new(
Opcode::CallNative,
STDLIB_ROOT
.sub_modules
.get("prelude")
.unwrap()
.functions
.get("print")
.unwrap()
.buildin_id
),
]
)
}
Expand Down
6 changes: 5 additions & 1 deletion rust/src/tvm/stdlib/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use super::super::types::*;
use crate::base::stdlib::*;
use crate::{base::error::*, tvm::DynaData};
use derive::{def_module, trc_function};
Expand All @@ -13,5 +14,8 @@ pub fn println(obj: any) -> void {
}

def_module!(module_name = prelude, functions = [print => print, println => print], classes = [
Trcint => int
TrcInt => int,
TrcStr => str,
TrcBool => bool,
TrcFloat => float
]);
5 changes: 5 additions & 0 deletions rust/src/tvm/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ pub mod trcfloat;
pub mod trcint;
pub mod trcstr;

pub use trcbool::TrcBool;
pub use trcfloat::TrcFloat;
pub use trcint::TrcInt;
pub use trcstr::TrcStr;

/// help to generate the same error reporter functions
macro_rules! batch_unsupported_operators {
($($traie_name:ident => $oper_name:expr),*) => {
Expand Down

0 comments on commit 3aa9bd5

Please sign in to comment.