diff --git a/rust/derive/src/def_module.rs b/rust/derive/src/def_module.rs index 81484716..2dbc2677 100644 --- a/rust/derive/src/def_module.rs +++ b/rust/derive/src/def_module.rs @@ -59,9 +59,9 @@ pub fn check_next_iter(iter: &mut IntoIter, check_str: &str) { } } -pub fn def_impl(content: TokenStream) -> TokenStream { +pub fn def_impl(context: TokenStream) -> TokenStream { let mut module_ident = None; - let mut iter = content.into_iter(); + let mut iter = context.into_iter(); let mut left_func = vec![]; let mut right_func = vec![]; let mut left_class = vec![]; diff --git a/rust/locales/zh-CN.toml b/rust/locales/zh-CN.toml index 651c6b11..fdbce773 100644 --- a/rust/locales/zh-CN.toml +++ b/rust/locales/zh-CN.toml @@ -37,7 +37,7 @@ operator_unsupport = "操作符%{0}不支持类型%{1}" type_not_same = "类型%{0}和%{1}不同" [compiler.report] -error_in_line = "错误在第%{line}行" +error_in_line = "在第%{line}行发生了错误" in_module = "在模块%{name}中" [compiler.numberoverflowerror] diff --git a/rust/src/base/error.rs b/rust/src/base/error.rs index 01819c90..dc40fc00 100644 --- a/rust/src/base/error.rs +++ b/rust/src/base/error.rs @@ -49,7 +49,7 @@ impl ErrorInfo { } } -pub trait ErrorContent: Debug + Send + Sync { +pub trait ErrorContext: Debug + Send + Sync { fn get_module_name(&self) -> &str; fn get_line(&self) -> usize; @@ -57,7 +57,7 @@ pub trait ErrorContent: Debug + Send + Sync { #[derive(Debug)] pub struct RuntimeError { - content: Box, + context: Box, info: ErrorInfo, } @@ -72,8 +72,8 @@ impl Display for RuntimeError { r#"{} {} {}:{}"#, - t!(ERROR_IN_LINE, line = self.content.get_line()), - t!(IN_MODULE, name = self.content.get_module_name()), + t!(ERROR_IN_LINE, line = self.context.get_line()), + t!(IN_MODULE, name = self.context.get_module_name()), self.info.error_type.clone().red(), self.info.message.red() ); @@ -82,11 +82,11 @@ impl Display for RuntimeError { } impl RuntimeError { - pub fn new(content: Box, info: ErrorInfo) -> RuntimeError { + pub fn new(context: Box, info: ErrorInfo) -> RuntimeError { // if info.message != "" { // panic!("develop debug use"); // } - RuntimeError { content, info } + RuntimeError { context, info } } } @@ -108,9 +108,9 @@ impl LightFakeError { } #[derive(Default)] -pub struct LightFakeContent {} +pub struct LightFakeContext {} -impl ErrorContent for LightFakeError { +impl ErrorContext for LightFakeError { fn get_module_name(&self) -> &str { "" } @@ -119,9 +119,9 @@ impl ErrorContent for LightFakeError { } } -impl LightFakeContent { - pub fn new() -> LightFakeContent { - LightFakeContent {} +impl LightFakeContext { + pub fn new() -> LightFakeContext { + LightFakeContext {} } } diff --git a/rust/src/compiler.rs b/rust/src/compiler.rs index 0b0b043d..608b1fc4 100644 --- a/rust/src/compiler.rs +++ b/rust/src/compiler.rs @@ -30,12 +30,12 @@ pub struct Option { } #[derive(Debug, Clone)] -pub struct Content { +pub struct Context { module_name: String, line: usize, } -impl ErrorContent for Content { +impl ErrorContext for Context { fn get_module_name(&self) -> &str { &self.module_name } @@ -45,7 +45,7 @@ impl ErrorContent for Content { } } -impl Content { +impl Context { pub fn new(module_name: &str) -> Self { Self { module_name: String::from(module_name), @@ -330,7 +330,7 @@ pub struct Compiler { input: Box>, pub const_pool: ValuePool, option: Option, - content: Content, + context: Context, } impl Compiler { @@ -348,7 +348,7 @@ impl Compiler { input: Box::new(FileSource::new(f)), const_pool: ValuePool::new(), option, - content: Content::new(cfg::MAIN_MODULE_NAME), + context: Context::new(cfg::MAIN_MODULE_NAME), } } _ => { @@ -362,7 +362,7 @@ impl Compiler { input: Box::new(StringSource::new(String::from(source))), const_pool: ValuePool::new(), option, - content: Content::new(cfg::MAIN_MODULE_NAME), + context: Context::new(cfg::MAIN_MODULE_NAME), } } @@ -375,7 +375,7 @@ impl Compiler { #[inline] pub fn report_compiler_error(&self, info: ErrorInfo) -> RunResult { - Err(RuntimeError::new(Box::new(self.content.clone()), info)) + Err(RuntimeError::new(Box::new(self.context.clone()), info)) } } diff --git a/rust/src/compiler/ast.rs b/rust/src/compiler/ast.rs index c6b30481..3a69c1f4 100644 --- a/rust/src/compiler/ast.rs +++ b/rust/src/compiler/ast.rs @@ -534,7 +534,7 @@ impl<'a> AstBuilder<'a> { let var = self.self_scope.as_ref().borrow().get_sym_idx(name); if var.is_none() { return Err(RuntimeError::new( - Box::new(self.token_lexer.compiler_data.content.clone()), + Box::new(self.token_lexer.compiler_data.context.clone()), ErrorInfo::new( t!( SYMBOL_NOT_FOUND, @@ -552,7 +552,7 @@ impl<'a> AstBuilder<'a> { TokenType::Store => { if self.self_scope.as_ref().borrow().has_sym(name) { return Err(RuntimeError::new( - Box::new(self.token_lexer.compiler_data.content.clone()), + Box::new(self.token_lexer.compiler_data.context.clone()), ErrorInfo::new( t!( SYMBOL_REDEFINED, @@ -600,7 +600,7 @@ impl<'a> AstBuilder<'a> { // 不生成行号表了 self.staticdata .line_table - .push(self.token_lexer.compiler_data.content.get_line()) + .push(self.token_lexer.compiler_data.context.get_line()) } } } diff --git a/rust/src/compiler/token.rs b/rust/src/compiler/token.rs index 14f104fc..16a73dfb 100644 --- a/rust/src/compiler/token.rs +++ b/rust/src/compiler/token.rs @@ -1,4 +1,4 @@ -use super::{Compiler, Content, Float}; +use super::{Compiler, Context, Float}; use crate::{base::error::*, cfg::FLOAT_OVER_FLOW_LIMIT, hash_map}; use rust_i18n::t; use std::{collections::HashMap, fmt::Display, process::exit, sync::OnceLock}; @@ -237,7 +237,7 @@ macro_rules! check_braces_match { $front_brace => { if $should_be_matched != $after_brace { return $sself.report_error_with_context(RuntimeError::new( - Box::new(Content::new_line(&$sself.compiler_data.content.module_name, $brace_record.line)), + Box::new(Context::new_line(&$sself.compiler_data.context.module_name, $brace_record.line)), ErrorInfo::new( t!(UNMATCHED_BRACE, "0"=$brace_record.c), t!(SYNTAX_ERROR), @@ -393,7 +393,7 @@ impl TokenLex<'_> { ',' => Token::new(TokenType::Comma, None), '{' => { self.braces_check - .push(BraceRecord::new(c, self.compiler_data.content.get_line())); + .push(BraceRecord::new(c, self.compiler_data.context.get_line())); Token::new(TokenType::LeftBigBrace, None) } '}' => { @@ -402,7 +402,7 @@ impl TokenLex<'_> { } '[' => { self.braces_check - .push(BraceRecord::new(c, self.compiler_data.content.get_line())); + .push(BraceRecord::new(c, self.compiler_data.context.get_line())); Token::new(TokenType::LeftMiddleBrace, None) } ']' => { @@ -411,7 +411,7 @@ impl TokenLex<'_> { } '(' => { self.braces_check - .push(BraceRecord::new(c, self.compiler_data.content.get_line())); + .push(BraceRecord::new(c, self.compiler_data.context.get_line())); Token::new(TokenType::LeftSmallBrace, None) } ')' => { @@ -456,7 +456,7 @@ impl TokenLex<'_> { t!(SYNTAX_ERROR), )); } else if c == '\n' { - self.compiler_data.content.add_line(); + self.compiler_data.context.add_line(); } } } @@ -773,7 +773,7 @@ impl TokenLex<'_> { return self.next_token(); } '\n' => { - self.compiler_data.content.add_line(); + self.compiler_data.context.add_line(); return self.next_token(); } '#' => { @@ -781,7 +781,7 @@ impl TokenLex<'_> { loop { let c = self.compiler_data.input.read(); if c == '\n' { - self.compiler_data.content.add_line(); + self.compiler_data.context.add_line(); return self.next_token(); } if c == '\0' { @@ -815,8 +815,8 @@ impl TokenLex<'_> { let unmatch_char = self.braces_check.pop().unwrap(); self.clear_error(); return self.report_error_with_context(RuntimeError::new( - Box::new(Content::new_line( - &self.compiler_data.content.module_name, + Box::new(Context::new_line( + &self.compiler_data.context.module_name, unmatch_char.line, )), ErrorInfo::new(t!(UNMATCHED_BRACE, "0" = unmatch_char.c), t!(SYNTAX_ERROR)), diff --git a/rust/src/tvm.rs b/rust/src/tvm.rs index 744ba066..d8c0b346 100644 --- a/rust/src/tvm.rs +++ b/rust/src/tvm.rs @@ -45,19 +45,19 @@ impl<'a> DynaData<'a> { } pub struct Vm<'a> { - run_contnet: Content, + run_context: Context, dynadata: DynaData<'a>, pc: usize, static_data: StaticData, } #[derive(Debug, Clone)] -struct Content { +struct Context { module_name: String, line_pos: usize, } -impl ErrorContent for Content { +impl ErrorContext for Context { fn get_module_name(&self) -> &str { &self.module_name } @@ -67,9 +67,9 @@ impl ErrorContent for Content { } } -impl Content { +impl Context { fn new(module_name: &str) -> Self { - Content { + Context { module_name: String::from(module_name), line_pos: 0, } @@ -133,7 +133,7 @@ macro_rules! operator_opcode { let ret = types::$trait_used(&mut $sself.dynadata); match ret { Err(e) => { - return Err(RuntimeError::new(Box::new($sself.run_contnet.clone()), e)); + return Err(RuntimeError::new(Box::new($sself.run_context.clone()), e)); } Ok(_) => {} } @@ -166,7 +166,7 @@ impl<'a> Vm<'a> { Self { pc: 0, dynadata: DynaData::new(), - run_contnet: Content::new(cfg::MAIN_MODULE_NAME), + run_context: Context::new(cfg::MAIN_MODULE_NAME), static_data: StaticData::new(false), } } @@ -175,7 +175,7 @@ impl<'a> Vm<'a> { Self { pc: 0, dynadata: DynaData::new(), - run_contnet: Content::new(cfg::MAIN_MODULE_NAME), + run_context: Context::new(cfg::MAIN_MODULE_NAME), static_data, } } @@ -187,14 +187,14 @@ impl<'a> Vm<'a> { fn throw_err_info(&self, info: RuntimeResult) -> RunResult { match info { Ok(data) => Ok(data), - Err(e) => Err(RuntimeError::new(Box::new(self.run_contnet.clone()), e)), + Err(e) => Err(RuntimeError::new(Box::new(self.run_context.clone()), e)), } } pub fn run(&mut self) -> Result<(), RuntimeError> { while self.pc < self.static_data.inst.len() { if self.static_data.has_line_table { - self.run_contnet + self.run_context .set_line(self.static_data.line_table[self.pc]); } match self.static_data.inst[self.pc].opcode { @@ -222,7 +222,7 @@ impl<'a> Vm<'a> { let ret = self.dynadata.frames_stack.pop(); if ret.is_none() { return Err(RuntimeError::new( - Box::new(self.run_contnet.clone()), + Box::new(self.run_context.clone()), ErrorInfo::new(t!(VM_FRAME_EMPTY), t!(VM_ERROR)), )); } diff --git a/rust/src/tvm/function.rs b/rust/src/tvm/function.rs index e8ebba43..c5d47283 100644 --- a/rust/src/tvm/function.rs +++ b/rust/src/tvm/function.rs @@ -1,6 +1,6 @@ use crate::base::func; -/// A content structure which hold the running info of the function +/// A context structure which hold the running info of the function pub struct Frame<'a> { name: &'a str, }